From nobody Sun Sep 28 17:03:47 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1757392541; cv=none; d=zohomail.com; s=zohoarc; b=Pgj+8Jbt3+NakZBNKpd/GiITUX+28OfIqnBsF1I1fK2LyJsYt9dsgTXYz7S4cBREEBN2CJ8nG0o2/FSnOGldjzvh536ABnm6E2dUwRy3mgfBCayjg8rZ+56TXyzp1lhLXcxjuXpTWetqa2Jc/8kIZ5A40gtvDCUTNKB1FWUrpkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757392541; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vaeExwVGOVV/kW0JCGTlDJdwyrSQrvISoe6gs6Lc/zE=; b=m3zNDq8wzQKuo7UK1AC4LfP3BR/84/SdUWsKZbnulx2eiXmpVfHnd4uPSvdmaoBRs416TrBGsiViGmtkHM0AN6KC4lX/iQEXPh5ZoVk822KFTwNPSWpZZLHQ44gdLSAuSvIqHMurS+dr9NDGnRQ167b1+iW/R3/SvTimaRQP88g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757392541639138.80402868938518; Mon, 8 Sep 2025 21:35:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uvq3v-0006L9-5S; Tue, 09 Sep 2025 00:34:35 -0400 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 1uvq3u-0006Kr-1j; Tue, 09 Sep 2025 00:34:34 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uvq3o-0003HK-R4; Tue, 09 Sep 2025 00:34:33 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7725147ec88so2182809b3a.0; Mon, 08 Sep 2025 21:34:27 -0700 (PDT) Received: from fedora ([159.196.5.243]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-774661247cdsm606534b3a.33.2025.09.08.21.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Sep 2025 21:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757392466; x=1757997266; 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=vaeExwVGOVV/kW0JCGTlDJdwyrSQrvISoe6gs6Lc/zE=; b=i7dVJs8s2Mi4AWXLNmB2NRk7NA/UYM+8McDoiTpOkYol9sH/PSGEhsz80yw/9dXUB8 bh+EtcUOmaEo8D+nuueflK0DRQON7EVvedtrVhhcHFfFhWiXZZkHB822YtzPlZysgrBh 9d4rMb2uwBBBG/4JDdE+ffdHxkPdkc1Vk0AgErXlKS/Y4q/wBpOwCXlWjsJHOp3qRfz7 EdDd8Lx58OgftojZSLf9JWw7cCgIRhUigarvNQ0ffaEppykuUKFsha6cBSTHVWA5bMVy be0VZbBYJMghKbBSpSiKRh9JVqOSuTepOUmVQzW3Ru7AdKRNICA2DYYJdNsA1+Vycn27 IxMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757392466; x=1757997266; 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=vaeExwVGOVV/kW0JCGTlDJdwyrSQrvISoe6gs6Lc/zE=; b=bTwL5O/7joG96RS+95CaKyxc1RT2rdgjtNQUHoZmdYYTDLWZFoKxkEeMA9srs2rcej vDwA8VI2zCrZwfKNi3wN8VL0sDzkjzV9Hifk2cYhpSaZAqVBovS+DBM17c+wKoTWM5O7 Aez1LGFa4oRhyqNBzMDAjfaP03569iIC1b2ID9C1rpA2/fGNF/vCy9JjeqW66oGgIzEF mu0Z2EPIN4c1n9lwzOhtpfD0n+Lt8U2DZKrfG/SuVTyUxGwkmHUhOkw4kiL0+3+MDHjz 8MqwpslQEGCyZ+eZ2FL9giGcoGC5s59jNCLcgpzBdUAYMOlZvtCjOOWVIUvGWdkorE3f AIEg== X-Forwarded-Encrypted: i=1; AJvYcCUBwIg/DgM5tQ2O3u59FYhXMWjSc5S0Vl6Bp/fEH4naDtkQC21afpm5LRvWcOlJySR0JsEEsqxRSPgq@nongnu.org X-Gm-Message-State: AOJu0YwzYEHgoVSBUKfS1GDKAIuRxuAp7uUOcDEJQFk98hDyT5+m0iKQ 4HKxUKqdDYC0WeH7zvUFYSp0rnAeEd5BZNVT0BUy0qQENxjAlKiJhZCs X-Gm-Gg: ASbGncsni2MLSmFg0fxnvGMeF46Nq2zk5jVT418EJtdjjF0czBVwDJLWOetfZEfzi/2 VLHAl6gKM2HwRa3vokx/wxfz9LYlATJ8VBbLz7jiNOmn6ta8W+spNsu2bmhb50pSMXLf0g4qiKT XdFJ4tWh61R8mksikq4HPaFuUQ0BXdITZKICJS///h3a34KHhlKvAlcOP5FNVS3OZVYSCbkvTeM 8NeoWFPb633WJUhPdseKfH/5CSHcilY9chLPXlIE8ICnLMwkENYDFpztW3MZsIJB0jSpYcCzdEP My8oCtbPBqrwtvGPZtqwn7le72QIrhZ5bf86zJUHMS3WO7Yph2638zY432atVHWo/1b6JKHUvxH ImxwQa6TZSpjBbHwsy3XHlrwr/3j4ueHuIPHSV8ej8Q== X-Google-Smtp-Source: AGHT+IGQKbb6IwSj0dYPTn1TVe874Hwz76JC3Ma1lp67i+jYd+oBBS8Bqt+7fQGS3Mr2o1yUmFwSBQ== X-Received: by 2002:a05:6a00:2188:b0:772:2bcc:d2d7 with SMTP id d2e1a72fcca58-7741bebeab3mr17700719b3a.2.1757392465810; Mon, 08 Sep 2025 21:34:25 -0700 (PDT) From: Wilfred Mallawa To: Alistair Francis , Keith Busch , Klaus Jensen , Jesper Devantier , Stefan Hajnoczi , Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Hanna Reitz , "Michael S . Tsirkin" , Marcel Apfelbaum Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Jonathan Cameron , Wilfred Mallawa Subject: [PATCH v5 5/5] hw/nvme: connect SPDM over NVMe Security Send/Recv Date: Tue, 9 Sep 2025 14:33:00 +1000 Message-ID: <20250909043259.93140-7-wilfred.opensource@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250909043259.93140-2-wilfred.opensource@gmail.com> References: <20250909043259.93140-2-wilfred.opensource@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=wilfred.opensource@gmail.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1757392541894116600 Content-Type: text/plain; charset="utf-8" From: Wilfred Mallawa This patch extends the existing support we have for NVMe with only DoE to also add support to SPDM over the NVMe Security Send/Recv commands. With the new definition of the `spdm-trans` argument, users can specify `spdm_trans=3Dnvme` or `spdm_trans=3Ddoe`. This allows us to select the SPDM transport respectively. SPDM over the NVMe Security Send/Recv commands are defined in the DMTF DSP0286. Signed-off-by: Wilfred Mallawa Reviewed-by: Jonathan Cameron --- docs/specs/spdm.rst | 10 ++++++-- hw/nvme/ctrl.c | 46 ++++++++++++++++++++++++++++--------- include/hw/pci/pci_device.h | 2 ++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/docs/specs/spdm.rst b/docs/specs/spdm.rst index f7de080ff0..dd6cfbbd68 100644 --- a/docs/specs/spdm.rst +++ b/docs/specs/spdm.rst @@ -98,7 +98,7 @@ Then you can add this to your QEMU command line: .. code-block:: shell =20 -drive file=3Dblknvme,if=3Dnone,id=3Dmynvme,format=3Draw \ - -device nvme,drive=3Dmynvme,serial=3Ddeadbeef,spdm_port=3D2323 + -device nvme,drive=3Dmynvme,serial=3Ddeadbeef,spdm_port=3D2323,spd= m_trans=3Ddoe =20 At which point QEMU will try to connect to the SPDM server. =20 @@ -113,7 +113,13 @@ of the default. So the entire QEMU command might look = like this -append "root=3D/dev/vda console=3DttyS0" \ -net none -nographic \ -drive file=3Dblknvme,if=3Dnone,id=3Dmynvme,format=3Draw \ - -device nvme,drive=3Dmynvme,serial=3Ddeadbeef,spdm_port=3D2323 + -device nvme,drive=3Dmynvme,serial=3Ddeadbeef,spdm_port=3D2323,spd= m_trans=3Ddoe + +The `spdm_trans` argument defines the underlying transport type that is em= ulated +by QEMU. For an PCIe NVMe controller, both "doe" and "nvme" are supported.= Where, +"doe" does SPDM transport over the PCIe extended capability Data Object Ex= change +(DOE), and "nvme" uses the NVMe Admin Security Send/Receive commands to +implement the SPDM transport. =20 .. _DMTF: https://www.dmtf.org/standards/SPDM diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index ad52e8f569..8a610f57f2 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8947,19 +8947,31 @@ static bool nvme_init_pci(NvmeCtrl *n, PCIDevice *p= ci_dev, Error **errp) =20 pcie_cap_deverr_init(pci_dev); =20 - /* DOE Initialisation */ + /* SPDM Initialisation */ if (pci_dev->spdm_port) { - uint16_t doe_offset =3D n->params.sriov_max_vfs ? - PCI_CONFIG_SPACE_SIZE + PCI_ARI_SIZEOF - : PCI_CONFIG_SPACE_SIZE; + switch (pci_dev->spdm_trans) { + case SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE: + uint16_t doe_offset =3D n->params.sriov_max_vfs ? + PCI_CONFIG_SPACE_SIZE + PCI_ARI_SIZEOF + : PCI_CONFIG_SPACE_SIZE; =20 - pcie_doe_init(pci_dev, &pci_dev->doe_spdm, doe_offset, - doe_spdm_prot, true, 0); + pcie_doe_init(pci_dev, &pci_dev->doe_spdm, doe_offset, + doe_spdm_prot, true, 0); =20 - pci_dev->doe_spdm.spdm_socket =3D spdm_socket_connect(pci_dev->spd= m_port, - errp); + pci_dev->doe_spdm.spdm_socket =3D + spdm_socket_connect(pci_dev->spdm_port, errp); =20 - if (pci_dev->doe_spdm.spdm_socket < 0) { + if (pci_dev->doe_spdm.spdm_socket < 0) { + return false; + } + break; + case SPDM_SOCKET_TRANSPORT_TYPE_NVME: + n->spdm_socket =3D spdm_socket_connect(pci_dev->spdm_port, err= p); + if (n->spdm_socket < 0) { + return false; + } + break; + default: return false; } } @@ -9250,11 +9262,17 @@ static void nvme_exit(PCIDevice *pci_dev) g_free(n->cmb.buf); } =20 + /* Only one of the `spdm_socket` below would have been setup */ if (pci_dev->doe_spdm.spdm_socket > 0) { spdm_socket_close(pci_dev->doe_spdm.spdm_socket, SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE); } =20 + if (n->spdm_socket >=3D 0) { + spdm_socket_close(pci_dev->doe_spdm.spdm_socket, + SPDM_SOCKET_TRANSPORT_TYPE_NVME); + } + if (n->pmr.dev) { host_memory_backend_set_mapped(n->pmr.dev, false); } @@ -9307,6 +9325,8 @@ static const Property nvme_props[] =3D { false), DEFINE_PROP_UINT16("mqes", NvmeCtrl, params.mqes, 0x7ff), DEFINE_PROP_UINT16("spdm_port", PCIDevice, spdm_port, 0), + DEFINE_PROP_SPDM_TRANS("spdm_trans", PCIDevice, spdm_trans, + SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE), DEFINE_PROP_BOOL("ctratt.mem", NvmeCtrl, params.ctratt.mem, false), DEFINE_PROP_BOOL("atomic.dn", NvmeCtrl, params.atomic_dn, 0), DEFINE_PROP_UINT16("atomic.awun", NvmeCtrl, params.atomic_awun, 0), @@ -9382,7 +9402,9 @@ static void nvme_pci_write_config(PCIDevice *dev, uin= t32_t address, { uint16_t old_num_vfs =3D pcie_sriov_num_vfs(dev); =20 - if (pcie_find_capability(dev, PCI_EXT_CAP_ID_DOE)) { + /* DOE is only initialised if SPDM over DOE is used */ + if (pcie_find_capability(dev, PCI_EXT_CAP_ID_DOE) && + dev->spdm_trans =3D=3D SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE) { pcie_doe_write_config(&dev->doe_spdm, address, val, len); } pci_default_write_config(dev, address, val, len); @@ -9393,7 +9415,9 @@ static void nvme_pci_write_config(PCIDevice *dev, uin= t32_t address, static uint32_t nvme_pci_read_config(PCIDevice *dev, uint32_t address, int= len) { uint32_t val; - if (dev->spdm_port && pcie_find_capability(dev, PCI_EXT_CAP_ID_DOE)) { + + if (dev->spdm_port && pcie_find_capability(dev, PCI_EXT_CAP_ID_DOE) && + (dev->spdm_trans =3D=3D SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE)) { if (pcie_doe_read_config(&dev->doe_spdm, address, len, &val)) { return val; } diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index eee0338568..88ccea5011 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -4,6 +4,7 @@ #include "hw/pci/pci.h" #include "hw/pci/pcie.h" #include "hw/pci/pcie_doe.h" +#include "system/spdm-socket.h" =20 #define TYPE_PCI_DEVICE "pci-device" typedef struct PCIDeviceClass PCIDeviceClass; @@ -166,6 +167,7 @@ struct PCIDevice { =20 /* SPDM */ uint16_t spdm_port; + SpdmTransportType spdm_trans; =20 /* DOE */ DOECap doe_spdm; --=20 2.51.0