From nobody Sun Sep 28 17:05:21 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=1756366061; cv=none; d=zohomail.com; s=zohoarc; b=IW1bGiXUJJbTWTkCBhVkbDwwdH0BN4UDKvP5O8/O8v61CJnLvahwRLvWvGLVCe23Oynvvo5WTtoD91yri9N08RxvA1EWKD5yyJ44i1uYR3DQvykM+B5CsNWQK9Ofn2OStra1keXJefydq24TxSTCM6zFIhx1KkLvvdcwn0kB1Y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756366061; 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=rVc3ZDMgKX2lqgZgsOWCoFWzd0mHTx09FG8yv2UWhzY=; b=aLbWF9bwKhBiVf8f4wkgcAlQLSfWh3+uTB9j9JTHlZ84HhQaYNPlktybyEV/Cck++46sBt6fl0/BJMo5mNSDL/sFxZ6kEzFzC9/5hgnRmVYdjfrcSqoQTZxUcBw9iKgUJwvgWL8f12S/u5sqiagdp4O/+f4NKqTC6temX6JEvzg= 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 1756366061358337.0521905631307; Thu, 28 Aug 2025 00:27:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1urX1x-0004XP-PN; Thu, 28 Aug 2025 03:26:45 -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 1urX1i-0004T7-JU; Thu, 28 Aug 2025 03:26:31 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1urX1e-0005PF-JT; Thu, 28 Aug 2025 03:26:29 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-248e3ef1641so1290445ad.3; Thu, 28 Aug 2025 00:26:25 -0700 (PDT) Received: from fedora ([159.196.5.243]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-24884a629fcsm51009775ad.19.2025.08.28.00.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Aug 2025 00:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756365985; x=1756970785; 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=rVc3ZDMgKX2lqgZgsOWCoFWzd0mHTx09FG8yv2UWhzY=; b=Tt8ZlVlyUCTvHclsZiOHst24rX0rRWx6PT+zQfJRgSkQFWvQ+LEaQoc0BdBjMsYinI VnZMOheC3qHFxkN2UfCTUsHryI4TD/pTdmx5fgY2OIk146sHbA/o971S4bCHEjaGRyMY m3cRU9SJ2+4mEUHMDbJqRwKKZdUkONJ7o9Aog9vT4QRv5c7bAZ6lq5XyV/UtAw2Uxalg yCPrv6Ch1j16bxAmu5k5gkp8HIPWFutv5p2SHHAywdZ13kEfvrCdaSCpWJUgiTN75dv0 Iuqxq7zniTkXBS4a0n7t1iJpFZtnp829OXwjwC1+MPuqBtOBXWaeIV7aBkGpevLbnZym dPoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756365985; x=1756970785; 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=rVc3ZDMgKX2lqgZgsOWCoFWzd0mHTx09FG8yv2UWhzY=; b=pqi2U6ylrMXy9j96nTopJD2DA4yXFTaO2cXxUah4O23SsYOSP5I6Ze29r4bg4uPbTX 0R7MXg42CPfmGth6QAjMuF37OXBUcILvMVDeuVDT6mO6eY5MQlkeH3dkbEWyUx6P2eS5 iOOat2v1mjS3yvKDYAgcUgEtWyOYKyPgLNapDyJ/whXODYNEPw6sqWfqavCljQrgSMR9 gN/rcCcS9pH2ng5EwzhIwg6JC3fvvQYD1jkdUlIVHP4K6QkHg+Zg9AzFZT580B7eFS2D XvuoQLQrV1E+hv6rF6vV4EYdUNuhwFhQ28ibn7uEXPOvMP/0EemL5WENKLP1ytyuurA2 knsQ== X-Forwarded-Encrypted: i=1; AJvYcCUZTymvAVqYq9LMfN3cg7/1IZY3N3rWCOl4HfkmMD5Hz2Q4TYUqTLkoMOEk5dXjQFk84jXAvLQsW3xi@nongnu.org, AJvYcCXvReQ3+qSGQ8GJda+Mod/B1s5u0TunwQ1sssHmG3lvEb2jekepSXFxg3Vr+p/5hDyYP2ZbBaShNcGXQg==@nongnu.org X-Gm-Message-State: AOJu0Yzwx3jiU1hMBQpAuxb9qMuoOkmpB7sqxp8kgLkyD/1hNKFj2vY7 BtIotq+qUswPYOBIEZ4EGHJ3+6M3Ot54u7ANytNCOeuB0c/spvz1Qjyc X-Gm-Gg: ASbGncvCBTq61odcJRfYUHQMjdRTxDM/hIY74DX/Jela1g3fLkXquzKID4ejIfuw/RG 8She7WpnXLRSTc5ExWRRrmw5fOM6Y8FCC1cU1Crc/a3j6L5QgBQHfnl6Y+Z0P7rVwW1FP94OzAi ooXeqGOeJcoN076ycdzRyf6GIeb05Kn/ShV/pq91OK81kuJpT4e488SD86VuaZ+fZ9yrGRWG8Ru AuuoZhxo6Uj6zom3GLkSjhqx2A4yfOHINHcCiNOAX0gejYC+X6sFNK2XB9Imufa8mbIh3Bullr3 TQh4PoFUBbRM+x9YoHCq5XU3X6sFqETZuBX4nk9jzs1KSaFHAjOFFxByQxxD7Rn0fLpRltr5dcY C+p5d/OtepaAKwq2GC2/ehmgyAIwKwJOurYmv X-Google-Smtp-Source: AGHT+IH2xSp3bvAWurtxpJuguxYbJ5Swhjwn8WQp6JHft+eIg///HbPRYJeIC6SqU7lFuHBlk5T7yA== X-Received: by 2002:a17:902:db0e:b0:246:edc9:3a80 with SMTP id d9443c01a7336-246edc93d95mr178979595ad.5.1756365984717; Thu, 28 Aug 2025 00:26:24 -0700 (PDT) From: Wilfred Mallawa To: Alistair Francis Cc: 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 , qemu-devel@nongnu.org, qemu-block@nongnu.org, Jonathan Cameron , Wilfred Mallawa Subject: [PATCH v2 5/5] hw/nvme: connect SPDM over NVMe Security Send/Recv Date: Thu, 28 Aug 2025 17:25:33 +1000 Message-ID: <20250828072532.425592-7-wilfred.opensource@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250828072532.425592-2-wilfred.opensource@gmail.com> References: <20250828072532.425592-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::634; envelope-from=wilfred.opensource@gmail.com; helo=mail-pl1-x634.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: 1756366062270124100 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 --- docs/specs/spdm.rst | 10 +++++++-- hw/nvme/ctrl.c | 45 ++++++++++++++++++++++++++++--------- include/hw/pci/pci_device.h | 2 ++ 3 files changed, 44 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 9358c9e540..3ddaea6cd5 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -8932,19 +8932,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; } } @@ -9235,11 +9247,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 > 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); } @@ -9292,6 +9310,7 @@ 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_NODEFAULT("spdm_trans", PCIDevice, spdm_trans), 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), @@ -9367,7 +9386,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); @@ -9378,7 +9399,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