From patchwork Tue Feb 13 02:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1898035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hkL0Obxa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYm085RGVz23yF for ; Tue, 13 Feb 2024 13:45:28 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZima-0002HP-8x; Mon, 12 Feb 2024 21:44:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZimW-0002Gg-5v; Mon, 12 Feb 2024 21:44:24 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZimU-0003IU-NQ; Mon, 12 Feb 2024 21:44:23 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d7858a469aso25066475ad.2; Mon, 12 Feb 2024 18:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707792261; x=1708397061; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oO1eGS8vQqb3cNVWcWEItaqKYVE/z0nIVNxgdlxi/zc=; b=hkL0Obxaf2AWMjqX178LJeOmCBkKKSPoRcrMSWXYCg6WBc+EOmqZsvDvpU22YwFvZX KgXZHNVTu+iOGfA7z6pa0hmYmj+ZZ/iaCXsiHpbj6nN1TNSI0J6DvbflcvNnhDGoeH7v KSDkLLTf/ph5SmGa+eHN8tC/rPWhlJN4nZoQ6WyEH852K7Vik8QQZ7UUPH7cljnQYsdn iFU2aEXmbkMwco9SFF8gSaTiaI4C6Zm1qSSZPS0rFTJVjezkjYBsIq+CVhHwegrYumwk X7VPTqclnKCgTqpftKUxnG8tbm5MmQgi6SGNkt6y3W+rIvhiGBNltLkIGmpmmHZXK+jc 5q3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707792261; x=1708397061; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oO1eGS8vQqb3cNVWcWEItaqKYVE/z0nIVNxgdlxi/zc=; b=r+6VAmYzH+KdgleVViMYt7FaMb7yZtu3C1EE2tfw4RDo1ZVrAXgHnlbURl51lFgmvi e8np5JCPDLsaei7neTau5jxrdF5medl7snoHBSTMtnrSOUA9uDl+Lnx/UaLQ9TkGSfU2 QfWJkFZVsSJO3N/2itO9CJlP0eyeQSLau59m1CPQzacmG8hKyHfeUx9ZRG7TSmmz2JmH qSNEYcyVPt3Qp0FbEKjIEPeFELK1735hZdqS9Ckjf9QiOtWE5mrCN/0Pkfzxh6anoDJV Cn9R18YX8nu25cDGCKw2IXK82sJPKrWp2g8urz408+/vfT5InqHMSDehepDdb7h9Skzp 1ZpA== X-Forwarded-Encrypted: i=1; AJvYcCXdefeJMngaGsVt7jkoAPvOP0d0dZXfkjzns7K9wWHuJyWn6XspRjPxwKn/YBI3E6/8GWKbBYzjdYQXTDGgqLwhH2dJbGbDHvGHq4IZs3rjJOhJ5d2kMH5D/BwOjQ== X-Gm-Message-State: AOJu0Yyb45RLV3PLx2DRh5mVxfqyuJ2FcYOCmOXgqh+E/UGrK/Zmw0/E jfiXGsgTGRvJihVYZTZHl3WyjPUIUFfwR/rdVhux64muo4uAwWdF X-Google-Smtp-Source: AGHT+IE60bpGjDk7roFnhjuVigsjAxbtK7hwB71OscIM/rjU9BHlub4g5w4DbnHtXRJIOkz5SQbWeQ== X-Received: by 2002:a17:902:7ed0:b0:1da:23bb:3728 with SMTP id p16-20020a1709027ed000b001da23bb3728mr5201922plb.48.1707792261110; Mon, 12 Feb 2024 18:44:21 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV5ygFKkep1jyjoXuyBwaUgJChDFXUC1qAwtB5icRC6IzR6bkC0u4oe48xRvCsVKduVaPE7K5zrQnITunHY3iIjLgGjyauBnBuOg1Bp5VSIGiAD5mTdXq+HKcBq/NQRupa/5jR2xAKb5yGzXX1hmBiFOVKwJojoPSylna7VbT1b7Xmoxi3OY9Ofwszg20pa05XbieJF7/E5RvT2Qqo4JES8s2Sn5dLoMUKk13qIXED6I+y/2reS/pzyZpY7UvLfEawEJy4jCRteBszEn76tsRnspTnqAPGdnHygVih70aAnXKZEcdHlouM6h0XooIcolT5rk3hvxBS0DciAzFMerlgat6hRxzlpaOI7e/R/vWCYBve+oEGLhOnqxcwmaNjLR4QDNhpLyRZizEEW6WkA2szqbXAACvrQ/qkCoUkhWupsm7Te4KDAvlMA++IFLZYdALzjdpq5 Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h12-20020a170902f2cc00b001da0a698095sm22852plc.282.2024.02.12.18.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:44:20 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: hchkuo@avery-design.com.tw, kbusch@kernel.org, lukas@wunner.de, Jonathan.Cameron@Huawei.com, its@irrelevant.dk, marcel.apfelbaum@gmail.com, wilfred.mallawa@wdc.com, cbrowy@avery-design.com, mst@redhat.com, qemu-devel@nongnu.org, jiewen.yao@intel.com Cc: Paolo Bonzini , qemu-block@nongnu.org, alistair23@gmail.com, Alistair Francis , Jonathan Cameron Subject: [PATCH v4 1/3] hw/pci: Add all Data Object Types defined in PCIe r6.0 Date: Tue, 13 Feb 2024 12:44:01 +1000 Message-ID: <20240213024403.1060188-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213024403.1060188-1-alistair.francis@wdc.com> References: <20240213024403.1060188-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=alistair23@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add all of the defined protocols/features from the PCIe-SIG r6.0 "Table 6-32 PCI-SIG defined Data Object Types (Vendor ID = 0001h)" table. Signed-off-by: Alistair Francis Reviewed-by: Jonathan Cameron --- include/hw/pci/pcie_doe.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/hw/pci/pcie_doe.h b/include/hw/pci/pcie_doe.h index 87dc17dcef..15d94661f9 100644 --- a/include/hw/pci/pcie_doe.h +++ b/include/hw/pci/pcie_doe.h @@ -46,6 +46,8 @@ REG32(PCI_DOE_CAP_STATUS, 0) /* PCI-SIG defined Data Object Types - r6.0 Table 6-32 */ #define PCI_SIG_DOE_DISCOVERY 0x00 +#define PCI_SIG_DOE_CMA 0x01 +#define PCI_SIG_DOE_SECURED_CMA 0x02 #define PCI_DOE_DW_SIZE_MAX (1 << 18) #define PCI_DOE_PROTOCOL_NUM_MAX 256 From patchwork Tue Feb 13 02:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1898037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JvzLrt4n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYm0J1SCJz23hT for ; Tue, 13 Feb 2024 13:45:36 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZimi-0002In-IB; Mon, 12 Feb 2024 21:44:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZime-0002I9-E4; Mon, 12 Feb 2024 21:44:32 -0500 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZimc-0003Iu-A5; Mon, 12 Feb 2024 21:44:32 -0500 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso3064194a12.3; Mon, 12 Feb 2024 18:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707792268; x=1708397068; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6xvCyPHEdUBhpQIIp0i3JOi6BgiSzbvr4Es3Z5MfHBo=; b=JvzLrt4nJ10e7RgShdqE1opjRihwav99ZQTtHQpxBp/5I+OXVcfm6Bjn9Uiovvqlen SNRqtb+Myt8QXHrwxIpp0744GubT3k20+R0JHw3imCY+X3tr4HBWQ6RACpgJQw8fs5dM dClewBGi69Ha96iJI8Ly0yKxEopD3SXJ5Wmgd3zfwFgGUqzIeNeErFQ7HTjivEOCjfYA Wg8XbYwf/mczm5Z1dKsXhV/B3yZwxVOCd3cdScfHBDn2ZeHPG5DiMASrCb/htai2Wi1X 7mE+oRyQe/FKHkWLTqsAulrTJOriUJFcdMVjbmLtSfqFjqBrCAvgl8mfGtDxU/HJAQPy lJ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707792268; x=1708397068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6xvCyPHEdUBhpQIIp0i3JOi6BgiSzbvr4Es3Z5MfHBo=; b=i38jEQp8DU/dr9xbEEErQxLFIsUX/1yC571mAaG90q3VBhZm8qNirr+KVm4NCLHqMC yJzXXOnvj029iJsl0tGTmDdXomHS7IrUCYLjZRV0Q96/nSV3G5bkRcpRANRIVF7UwIW8 oORIZelvjwVZXdMLybWPZt+O5CGEdOCoiJGT+a/WORF454NyhbTNsB78Fa2A0jaiCqs/ iFQCzWM/Rlno6v/axRs+6Cl3XA5zOGrBFTr+bm1c3TxSvFXKckE8jiRu6lt6WJIIPsjq 6Nmekdom+FMB88sPgNO7bnhWBSIBeNCPwvhsd1DEuGr/MgeVZ5vEfXJ8EP+U8GcBlf8G +z8A== X-Forwarded-Encrypted: i=1; AJvYcCXs8XStBWe+K8Q8xW9vgsR9J4Oi4FousxEZ1DElrV8p0gjHseZ/y3KhGHyrDMh9uUdPkPr1LvZDeT9LILJ8IbeC8bBC9041vJc6xRrJUY2H2E5saPNQCR3ChZpB7Q== X-Gm-Message-State: AOJu0YwJMV4oKCnkb0SG0zoE5Eo+Vrp3d27ujdPuJ7QlLS7XSWcy2tqV FlUandxDSlHsQzJnmFKVX9NAFQDz2sorwAeEn18CXJHFfXvLG0iE X-Google-Smtp-Source: AGHT+IFdS0h3Z0CKp4GmTGbdHUU0CO3unY3N6HuiPK8Yu8yGW4Exe9yzY9fhMc/Cv/TXcisF1Pj+Bg== X-Received: by 2002:a05:6a20:2d21:b0:19e:5683:e8d0 with SMTP id g33-20020a056a202d2100b0019e5683e8d0mr13903610pzl.12.1707792268260; Mon, 12 Feb 2024 18:44:28 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXcXvwTF1s/US/ghnKr199wu9KaMwr+U9qV9Lcc6A4nKX/KYvdiUWNrMruQIaQcLQ76ByYgegihALBaYi0Np90AdfExZ8fGLfohaVs2zqZd6uRyKHin/FMHEAuhbFTne2fLO6TnWuJrS1Hc2e4JOcAyE9Tx1PXpIkyQZW/CbEmLkhRWMSYHYiVtbfLiRco4Pv6GTA1BO4PN3KagAE3rNywvqjTbEnNeDQjq1iDfrYAK8aeM1kkF37K7ifzHfh1RkHTWAL+F+GluueRRnwy1+W4y0wAlz+2MfOXtObPNK6nfv61909UUlWF8hQTWtSSSrOqRxL+2BHbCIZoHkK5ZsHDvTpvIZvPyn8BARcPWaFb3Q2ztgQOKaOK7TH8sAKNOvDtiEPg048HieKxnWL1YtE7Psf4C+IW2b/TMhdEJm+RC2bO7joKGkfSQ2iNctz1vPhJoC84pdtYPYKlL7FS625xOdi9zEdC0FnRGXZ1iz2ZbgFM= Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h12-20020a170902f2cc00b001da0a698095sm22852plc.282.2024.02.12.18.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:44:27 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: hchkuo@avery-design.com.tw, kbusch@kernel.org, lukas@wunner.de, Jonathan.Cameron@Huawei.com, its@irrelevant.dk, marcel.apfelbaum@gmail.com, wilfred.mallawa@wdc.com, cbrowy@avery-design.com, mst@redhat.com, qemu-devel@nongnu.org, jiewen.yao@intel.com Cc: Paolo Bonzini , qemu-block@nongnu.org, alistair23@gmail.com, Jonathan Cameron , Jonathan Cameron , Alistair Francis Subject: [PATCH v4 2/3] backends: Initial support for SPDM socket support Date: Tue, 13 Feb 2024 12:44:02 +1000 Message-ID: <20240213024403.1060188-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213024403.1060188-1-alistair.francis@wdc.com> References: <20240213024403.1060188-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=alistair23@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Huai-Cheng Kuo SPDM enables authentication, attestation and key exchange to assist in providing infrastructure security enablement. It's a standard published by the DMTF [1]. SPDM supports multiple transports, including PCIe DOE and MCTP. This patch adds support to QEMU to connect to an external SPDM instance. SPDM support can be added to any QEMU device by exposing a TCP socket to a SPDM server. The server can then implement the SPDM decoding/encoding support, generally using libspdm [2]. This is similar to how the current TPM implementation works and means that the heavy lifting of setting up certificate chains, capabilities, measurements and complex crypto can be done outside QEMU by a well supported and tested library. 1: https://www.dmtf.org/standards/SPDM 2: https://github.com/DMTF/libspdm Signed-off-by: Huai-Cheng Kuo Signed-off-by: Chris Browy Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron [ Changes by WM - Bug fixes from testing ] Signed-off-by: Wilfred Mallawa [ Changes by AF: - Convert to be more QEMU-ified - Move to backends as it isn't PCIe specific ] Signed-off-by: Alistair Francis --- include/sysemu/spdm-socket.h | 44 +++++++ backends/spdm-socket.c | 216 +++++++++++++++++++++++++++++++++++ backends/Kconfig | 4 + backends/meson.build | 2 + 4 files changed, 266 insertions(+) create mode 100644 include/sysemu/spdm-socket.h create mode 100644 backends/spdm-socket.c diff --git a/include/sysemu/spdm-socket.h b/include/sysemu/spdm-socket.h new file mode 100644 index 0000000000..24e6fccb83 --- /dev/null +++ b/include/sysemu/spdm-socket.h @@ -0,0 +1,44 @@ +/* + * QEMU SPDM socket support + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef SPDM_REQUESTER_H +#define SPDM_REQUESTER_H + +int spdm_socket_connect(uint16_t port, Error **errp); +uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type, + void *req, uint32_t req_len, + void *rsp, uint32_t rsp_len); +void spdm_socket_close(const int socket, uint32_t transport_type); + +#define SPDM_SOCKET_COMMAND_NORMAL 0x0001 +#define SPDM_SOCKET_COMMAND_OOB_ENCAP_KEY_UPDATE 0x8001 +#define SPDM_SOCKET_COMMAND_CONTINUE 0xFFFD +#define SPDM_SOCKET_COMMAND_SHUTDOWN 0xFFFE +#define SPDM_SOCKET_COMMAND_UNKOWN 0xFFFF +#define SPDM_SOCKET_COMMAND_TEST 0xDEAD + +#define SPDM_SOCKET_TRANSPORT_TYPE_MCTP 0x01 +#define SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE 0x02 + +#define SPDM_SOCKET_MAX_MESSAGE_BUFFER_SIZE 0x1200 + +#endif diff --git a/backends/spdm-socket.c b/backends/spdm-socket.c new file mode 100644 index 0000000000..d0663d696c --- /dev/null +++ b/backends/spdm-socket.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * QEMU SPDM socket support + * + * This is based on: + * https://github.com/DMTF/spdm-emu/blob/07c0a838bcc1c6207c656ac75885c0603e344b6f/spdm_emu/spdm_emu_common/command.c + * but has been re-written to match QEMU style + * + * Copyright (c) 2021, DMTF. All rights reserved. + * Copyright (c) 2023. Western Digital Corporation or its affiliates. + */ + +#include "qemu/osdep.h" +#include "sysemu/spdm-socket.h" +#include "qapi/error.h" + +static bool read_bytes(const int socket, uint8_t *buffer, + size_t number_of_bytes) +{ + ssize_t number_received = 0; + ssize_t result; + + while (number_received < number_of_bytes) { + result = recv(socket, buffer + number_received, + number_of_bytes - number_received, 0); + if (result <= 0) { + return false; + } + number_received += result; + } + return true; +} + +static bool read_data32(const int socket, uint32_t *data) +{ + bool result; + + result = read_bytes(socket, (uint8_t *)data, sizeof(uint32_t)); + if (!result) { + return result; + } + *data = ntohl(*data); + return true; +} + +static bool read_multiple_bytes(const int socket, uint8_t *buffer, + uint32_t *bytes_received, + uint32_t max_buffer_length) +{ + uint32_t length; + bool result; + + result = read_data32(socket, &length); + if (!result) { + return result; + } + + if (length > max_buffer_length) { + return false; + } + + if (bytes_received) { + *bytes_received = length; + } + + if (length == 0) { + return true; + } + + return read_bytes(socket, buffer, length); +} + +static bool receive_platform_data(const int socket, + uint32_t transport_type, + uint32_t *command, + uint8_t *receive_buffer, + uint32_t *bytes_to_receive) +{ + bool result; + uint32_t response; + uint32_t bytes_received; + + result = read_data32(socket, &response); + if (!result) { + return result; + } + *command = response; + + result = read_data32(socket, &transport_type); + if (!result) { + return result; + } + + bytes_received = 0; + result = read_multiple_bytes(socket, receive_buffer, &bytes_received, + *bytes_to_receive); + if (!result) { + return result; + } + *bytes_to_receive = bytes_received; + + return result; +} + +static bool write_bytes(const int socket, const uint8_t *buffer, + uint32_t number_of_bytes) +{ + ssize_t number_sent = 0; + ssize_t result; + + while (number_sent < number_of_bytes) { + result = send(socket, buffer + number_sent, + number_of_bytes - number_sent, 0); + if (result == -1) { + return false; + } + number_sent += result; + } + return true; +} + +static bool write_data32(const int socket, uint32_t data) +{ + data = htonl(data); + return write_bytes(socket, (uint8_t *)&data, sizeof(uint32_t)); +} + +static bool write_multiple_bytes(const int socket, const uint8_t *buffer, + uint32_t bytes_to_send) +{ + bool result; + + result = write_data32(socket, bytes_to_send); + if (!result) { + return result; + } + + return write_bytes(socket, buffer, bytes_to_send); +} + +static bool send_platform_data(const int socket, + uint32_t transport_type, uint32_t command, + const uint8_t *send_buffer, size_t bytes_to_send) +{ + bool result; + + result = write_data32(socket, command); + if (!result) { + return result; + } + + result = write_data32(socket, transport_type); + if (!result) { + return result; + } + + return write_multiple_bytes(socket, send_buffer, bytes_to_send); +} + +int spdm_socket_connect(uint16_t port, Error **errp) +{ + int client_socket; + struct sockaddr_in server_addr; + + client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (client_socket < 0) { + error_setg(errp, "cannot create socket: %s", strerror(errno)); + return -1; + } + + memset((char *)&server_addr, 0, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + server_addr.sin_port = htons(port); + + + if (connect(client_socket, (struct sockaddr *)&server_addr, + sizeof(server_addr)) < 0) { + error_setg(errp, "cannot connect: %s", strerror(errno)); + close(client_socket); + return -1; + } + + return client_socket; +} + +uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type, + void *req, uint32_t req_len, + void *rsp, uint32_t rsp_len) +{ + uint32_t command; + bool result; + + result = send_platform_data(socket, transport_type, + SPDM_SOCKET_COMMAND_NORMAL, + req, req_len); + if (!result) { + return 0; + } + + result = receive_platform_data(socket, transport_type, &command, + (uint8_t *)rsp, &rsp_len); + if (!result) { + return 0; + } + + assert(command != 0); + + return rsp_len; +} + +void spdm_socket_close(const int socket, uint32_t transport_type) +{ + send_platform_data(socket, transport_type, + SPDM_SOCKET_COMMAND_SHUTDOWN, NULL, 0); +} diff --git a/backends/Kconfig b/backends/Kconfig index 2cb23f62fa..d3dbe19868 100644 --- a/backends/Kconfig +++ b/backends/Kconfig @@ -3,3 +3,7 @@ source tpm/Kconfig config IOMMUFD bool depends on VFIO + +config SPDM_SOCKET + bool + default y diff --git a/backends/meson.build b/backends/meson.build index 8b2b111497..e5d4db7971 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -31,4 +31,6 @@ endif system_ss.add(when: gio, if_true: files('dbus-vmstate.c')) system_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c')) +system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c')) + subdir('tpm') From patchwork Tue Feb 13 02:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1898038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lezvASRG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYm0M03X2z23hT for ; Tue, 13 Feb 2024 13:45:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZimm-0002K2-Rx; Mon, 12 Feb 2024 21:44:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZiml-0002Jj-CZ; Mon, 12 Feb 2024 21:44:39 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZimj-0003J7-55; Mon, 12 Feb 2024 21:44:39 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d953fa3286so30088325ad.2; Mon, 12 Feb 2024 18:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707792275; x=1708397075; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZKkr5+DQKGp6erkKh1K3GEPolXV7PYCCwVRgNyLgHro=; b=lezvASRGELoyiqGRd7CWjoFsVqjr+nVxoobSOGuPBCg8GRBnzIRDvy7r2ZIvE9V9ED HWRkW/ACRgjj1XUme72l3/nm9MjibUPI0xye0T4c56DnPrhlMXtfIs3Dzu5KKicyeMW1 JNQ+3BJ2eyvrVNNiIOWuYj/I+ZgWYmPB+HN5YCTqyLQ+ZOW7E54ERw6MTwjcJonWug5d k0nPG5vSxmn9H8oRS8qvJyXLF3hpu8LQWjXbwQsksJ12/B8rRXeQYRSL4H1mpu1Cyxgf 5nwYS5ewpsmm5DU+QlxlOLJsgU3qKQAbTWtqkpxx+iuniFh/iRVBfHFjRSsslwGZnGzV Tm+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707792275; x=1708397075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZKkr5+DQKGp6erkKh1K3GEPolXV7PYCCwVRgNyLgHro=; b=QY9mxf68z/grnzjxIIXKviEzz01/kbvUoPkTkOLNxo6eJfylEcVE/UJeNzYcdd26Jf SaX2pjCzMfZQgjN2V6gvmJEjgJBiKB7otwMjAa2BJCoKxDMsa7bvPcKxx7xUhXRdvubE oaBPN9aHJAY2f8F8gXhGSxf9oD723q7zsjJ2byQCjTluNcQElHW3Yw+JlzLh/sZBvCMN UgGHXKh9fOwtulP8Z52hUbi8VREqK5iJd0W9GXC8zi6PtnsUPnr3lke3M/5zvS80R+z1 OZBlxR5VumREztz/2MC/Bjbcunm+lCha2T3HFeTY/7sqTE8w71AWSv6QFHrTEDxut9lw bpaA== X-Forwarded-Encrypted: i=1; AJvYcCU/NGPJYGUSVX6xT/CBIslUVUcmjowVl9rtxQSjhF+GgeOGwmLumLhFcHFIZQhgMajJ71bs4riRJfEfMkMDLqP6GQfcDVxugzPmjQB5itMftFw01H7qhK2ki51YGA== X-Gm-Message-State: AOJu0YwZPuQHegxKboPBgbd70O2f20VldEDZl4sQFAe1kdhwJ32Ir0Eq FmzCf7U4So8NDsvG8inL2pLHOcxRJtoHGWA9ksCZcRrdMTVYjSAt X-Google-Smtp-Source: AGHT+IEildF3BQvgT2IAB/XCQlRIFN8G71MTOo8pT6qhQ8e0zh8QA6ljPVVP6VbEFovlAldakMrFrw== X-Received: by 2002:a17:902:ce90:b0:1d8:fc65:b601 with SMTP id f16-20020a170902ce9000b001d8fc65b601mr11463893plg.38.1707792275288; Mon, 12 Feb 2024 18:44:35 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUHGkT6lMhcte9mM9j+0NIuGZicxowrC9NMf08hGLXHDTfDzyJmbjbnhLiuv/CS40Gj8XuH4uYlM9XaalzFRMIi7arWCjodMyOiVdiqj2nG5WvOnrSbOVFQU/6QMBbDAXOF/UnS8euiRfYPWnoJWb6fo87W5E+Ua8L5Cx5qgT+z3Kx1BCjMXxUr65LuWipA3mHz93IwL64dPLUedNevGGa2xJu7o181wrG5CiSX4/tF2xoQHpP0nBePBGr5z8lRsU/LkdfJ4hOGz9gVA3QHLkgJ0P9HXvJxAeOf98sr/pAviFwQvjagFlXgc8FhOe7qeYmqTH1zlV1muwQEuepbMI86n/1Lh7WbrelQof8/xxKFcVgOxuy8ymK7E/IxjebtnCMb8WddP9enNgtsth9LTSKw0Nhs9NGO0pFxCSpMaiG0lmhuWa6nylM0XAIU+gtp7EEySBa/ExfoutHz3wBwKJafHJOVuxNlIJL9Mg== Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id h12-20020a170902f2cc00b001da0a698095sm22852plc.282.2024.02.12.18.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 18:44:34 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: hchkuo@avery-design.com.tw, kbusch@kernel.org, lukas@wunner.de, Jonathan.Cameron@Huawei.com, its@irrelevant.dk, marcel.apfelbaum@gmail.com, wilfred.mallawa@wdc.com, cbrowy@avery-design.com, mst@redhat.com, qemu-devel@nongnu.org, jiewen.yao@intel.com Cc: Paolo Bonzini , qemu-block@nongnu.org, alistair23@gmail.com, Alistair Francis , Jonathan Cameron , Klaus Jensen Subject: [PATCH v4 3/3] hw/nvme: Add SPDM over DOE support Date: Tue, 13 Feb 2024 12:44:03 +1000 Message-ID: <20240213024403.1060188-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213024403.1060188-1-alistair.francis@wdc.com> References: <20240213024403.1060188-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=alistair23@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Wilfred Mallawa Setup Data Object Exchance (DOE) as an extended capability for the NVME controller and connect SPDM to it (CMA) to it. Signed-off-by: Wilfred Mallawa Signed-off-by: Alistair Francis Reviewed-by: Jonathan Cameron Acked-by: Klaus Jensen --- docs/specs/index.rst | 1 + docs/specs/spdm.rst | 122 ++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_device.h | 5 ++ include/hw/pci/pcie_doe.h | 3 + hw/nvme/ctrl.c | 53 ++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 docs/specs/spdm.rst diff --git a/docs/specs/index.rst b/docs/specs/index.rst index 1484e3e760..e2d907959a 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -29,6 +29,7 @@ guest hardware that is specific to QEMU. edu ivshmem-spec pvpanic + spdm standard-vga virt-ctlr vmcoreinfo diff --git a/docs/specs/spdm.rst b/docs/specs/spdm.rst new file mode 100644 index 0000000000..4d0942c1ad --- /dev/null +++ b/docs/specs/spdm.rst @@ -0,0 +1,122 @@ +====================================================== +QEMU Security Protocols and Data Models (SPDM) Support +====================================================== + +SPDM enables authentication, attestation and key exchange to assist in +providing infrastructure security enablement. It's a standard published +by the `DMTF`_. + +QEMU supports connecting to a SPDM responder implementation. This allows an +external application to emulate the SPDM responder logic for an SPDM device. + +Setting up a SPDM server +======================== + +When using QEMU with SPDM devices QEMU will connect to a server which +implements the SPDM functionality. + +SPDM-Utils +---------- + +You can use `SPDM Utils`_ to emulate a responder. This is the simplest method. + +SPDM-Utils is a Linux applications to manage, test and develop devices +supporting DMTF Security Protocol and Data Model (SPDM). It is written in Rust +and utilises libspdm. + +To use SPDM-Utils you will need to do the following steps. Details are included +in the SPDM-Utils README. + + 1. `Build libspdm`_ + 2. `Build SPDM Utils using Cargo`_ + 3. `Run it as a server`_ + +spdm-emu +-------- + +You can use `spdm emu`_ to model the +SPDM responder. + +.. code-block:: shell + + $ cd spdm-emu + $ git submodule init; git submodule update --recursive + $ mkdir build; cd build + $ cmake -DARCH=x64 -DTOOLCHAIN=GCC -DTARGET=Debug -DCRYPTO=openssl .. + $ make -j32 + $ make copy_sample_key # Build certificates, required for SPDM authentication. + +It is worth noting that the certificates should be in compliance with +PCIe r6.1 sec 6.31.3. This means you will need to add the following to +openssl.cnf + +.. code-block:: + + subjectAltName = otherName:2.23.147;UTF8:Vendor=1b36:Device=0010:CC=010802:REV=02:SSVID=1af4:SSID=1100 + 2.23.147 = ASN1:OID:2.23.147 + +and then manually regenerate some certificates with: + +.. code-block:: shell + + $ openssl req -nodes -newkey ec:param.pem -keyout end_responder.key \ + -out end_responder.req -sha384 -batch \ + -subj "/CN=DMTF libspdm ECP384 responder cert" + + $ openssl x509 -req -in end_responder.req -out end_responder.cert \ + -CA inter.cert -CAkey inter.key -sha384 -days 3650 -set_serial 3 \ + -extensions v3_end -extfile ../openssl.cnf + + $ openssl asn1parse -in end_responder.cert -out end_responder.cert.der + + $ cat ca.cert.der inter.cert.der end_responder.cert.der > bundle_responder.certchain.der + +You can use SPDM-Utils instead as it will generate the correct certificates +automatically. + +The responder can then be launched with + +.. code-block:: shell + + $ cd bin + $ ./spdm_responder_emu --trans PCI_DOE + +Connecting an SPDM NVMe device +============================== + +Once a SPDM server is running we can start QEMU and connect to the server. + +For an NVMe device first let's setup a block we can use + +.. code-block:: shell + + $ cd qemu-spdm/linux/image + $ dd if=/dev/zero of=blknvme bs=1M count=2096 # 2GB NNMe Drive + +Then you can add this to your QEMU command line: + +.. code-block:: shell + + -drive file=blknvme,if=none,id=mynvme,format=raw \ + -device nvme,drive=mynvme,serial=deadbeef,spdm=2323 + +At which point QEMU will try to connect to the SPDM server. + + +.. _DMTF: + https://www.dmtf.org/standards/SPDM + +.. _SPDM Utils: + https://github.com/westerndigitalcorporation/spdm-utils + +.. _spdm emu: + https://github.com/dmtf/spdm-emu + +.. _Build SPDM Utils: + https://github.com/westerndigitalcorporation/spdm-utils#building + +.. _Generate the certificates: + https://github.com/westerndigitalcorporation/spdm-utils#generate-mutable-certificates + +.. _Run it as a server: + https://github.com/westerndigitalcorporation/spdm-utils#qemu-spdm-device-emulation diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b2..b8379c78f1 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -3,6 +3,7 @@ #include "hw/pci/pci.h" #include "hw/pci/pcie.h" +#include "hw/pci/pcie_doe.h" #define TYPE_PCI_DEVICE "pci-device" typedef struct PCIDeviceClass PCIDeviceClass; @@ -157,6 +158,10 @@ struct PCIDevice { MSIVectorReleaseNotifier msix_vector_release_notifier; MSIVectorPollNotifier msix_vector_poll_notifier; + /* DOE */ + DOECap doe_spdm; + uint16_t spdm_port; + /* ID of standby device in net_failover pair */ char *failover_pair_id; uint32_t acpi_index; diff --git a/include/hw/pci/pcie_doe.h b/include/hw/pci/pcie_doe.h index 15d94661f9..eb8f4e393d 100644 --- a/include/hw/pci/pcie_doe.h +++ b/include/hw/pci/pcie_doe.h @@ -108,6 +108,9 @@ struct DOECap { /* Protocols and its callback response */ DOEProtocol *protocols; uint16_t protocol_num; + + /* Used for spdm-socket */ + int socket; }; void pcie_doe_init(PCIDevice *pdev, DOECap *doe_cap, uint16_t offset, diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f026245d1e..661ebe3725 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -203,6 +203,7 @@ #include "sysemu/hostmem.h" #include "hw/pci/msix.h" #include "hw/pci/pcie_sriov.h" +#include "sysemu/spdm-socket.h" #include "migration/vmstate.h" #include "nvme.h" @@ -8070,6 +8071,28 @@ static int nvme_add_pm_capability(PCIDevice *pci_dev, uint8_t offset) return 0; } +static bool pcie_doe_spdm_rsp(DOECap *doe_cap) +{ + void *req = pcie_doe_get_write_mbox_ptr(doe_cap); + uint32_t req_len = pcie_doe_get_obj_len(req) * 4; + void *rsp = doe_cap->read_mbox; + uint32_t rsp_len = SPDM_SOCKET_MAX_MESSAGE_BUFFER_SIZE; + uint32_t recvd; + + recvd = spdm_socket_rsp(doe_cap->socket, + SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE, + req, req_len, rsp, rsp_len); + doe_cap->read_mbox_len += DIV_ROUND_UP(recvd, 4); + + return recvd != 0; +} + +static DOEProtocol doe_spdm_prot[] = { + { PCI_VENDOR_ID_PCI_SIG, PCI_SIG_DOE_CMA, pcie_doe_spdm_rsp }, + { PCI_VENDOR_ID_PCI_SIG, PCI_SIG_DOE_SECURED_CMA, pcie_doe_spdm_rsp }, + { } +}; + static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) { ERRP_GUARD(); @@ -8126,6 +8149,24 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp) nvme_update_msixcap_ts(pci_dev, n->conf_msix_qsize); + pcie_cap_deverr_init(pci_dev); + + /* DOE Initialisation */ + if (pci_dev->spdm_port) { + uint16_t doe_offset = n->params.sriov_max_vfs ? + PCI_CONFIG_SPACE_SIZE + PCI_ARI_SIZEOF + : PCI_CONFIG_SPACE_SIZE; + + pcie_doe_init(pci_dev, &pci_dev->doe_spdm, doe_offset, doe_spdm_prot, true, 0); + + pci_dev->doe_spdm.socket = spdm_socket_connect(pci_dev->spdm_port, errp); + + if (pci_dev->doe_spdm.socket < 0 ) { + error_setg(errp, "Failed to connect to SPDM socket"); + return -ENOTSUP; + } + } + if (n->params.cmb_size_mb) { nvme_init_cmb(n, pci_dev); } @@ -8412,6 +8453,7 @@ static Property nvme_props[] = { params.sriov_max_vi_per_vf, 0), DEFINE_PROP_UINT8("sriov_max_vq_per_vf", NvmeCtrl, params.sriov_max_vq_per_vf, 0), + DEFINE_PROP_UINT16("spdm", PCIDevice, spdm_port, 0), DEFINE_PROP_END_OF_LIST(), }; @@ -8494,10 +8536,20 @@ static void nvme_pci_write_config(PCIDevice *dev, uint32_t address, uint32_t val, int len) { nvme_sriov_pre_write_ctrl(dev, address, val, len); + pcie_doe_write_config(&dev->doe_spdm, address, val, len); pci_default_write_config(dev, address, val, len); pcie_cap_flr_write_config(dev, address, val, len); } +static uint32_t nvme_pci_read_config(PCIDevice *dev, uint32_t address, int len) +{ + uint32_t val; + if (pcie_doe_read_config(&dev->doe_spdm, address, len, &val)) { + return val; + } + return pci_default_read_config(dev, address, len); +} + static const VMStateDescription nvme_vmstate = { .name = "nvme", .unmigratable = 1, @@ -8510,6 +8562,7 @@ static void nvme_class_init(ObjectClass *oc, void *data) pc->realize = nvme_realize; pc->config_write = nvme_pci_write_config; + pc->config_read = nvme_pci_read_config; pc->exit = nvme_exit; pc->class_id = PCI_CLASS_STORAGE_EXPRESS; pc->revision = 2;