From nobody Tue Nov 26 08:49:30 2024 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=1709773241; cv=none; d=zohomail.com; s=zohoarc; b=eg96Q0KCXO7U4if6y5w5yoX3Bi9W9MiFbrCJL2YXGCs/DjHYdQHlIjih+Ac5XN0AeYjA1O74w0vdQyVJE5yt+ml/EiZv8a8AMp+Vz2FPUfv2ZUjcn6TRuQjxnv7Z9NEOudC7C3XPTsqiQMQsYVozJZ5w8PtbEs5pj/pok/0q79I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709773241; 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=s9/1mdln9FYDENEIkWEufUZtqQyXG+2Q8vpPpAXGkJ0=; b=U7mrttJckoUe7gq+PVgZf3OfOMNRlC8d0UA8k/c3nVzfAGGj0FNKZ5j+GT6kQZH3GkoaPiq9sXRh/6EG7TbhZ8QMg4bh98w/3FUR7or1AXlSkOitGyC0HC+vgqWcxlLijqjsogbx1ev9+UcgYRyPgKFysPuFSKnoSdlCzVOHegM= 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 1709773241618976.6525587276211; Wed, 6 Mar 2024 17:00:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ri26p-0000k1-2s; Wed, 06 Mar 2024 19:59:43 -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 1ri26m-0000jh-Ch; Wed, 06 Mar 2024 19:59:40 -0500 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ri26k-00085R-94; Wed, 06 Mar 2024 19:59:40 -0500 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5a17274193eso136278eaf.3; Wed, 06 Mar 2024 16:59:37 -0800 (PST) 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 n21-20020a63f815000000b005dbd0facb4dsm11420276pgh.61.2024.03.06.16.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 16:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709773177; x=1710377977; 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=s9/1mdln9FYDENEIkWEufUZtqQyXG+2Q8vpPpAXGkJ0=; b=AHH+xiCAEzpkCndooLzxdoRMq40NydsIlDWEJH7ce6IzFLHuNpxSI/tJ6EU5XGIi0r HaAsNKIXIFzfi7LYgmy7Y2FogLdZVypyin5iZ7BmGnMpk+TFWsPbk7i/XUh2ZtQDadw8 77Z7oG4WcWskhgLmSPB4yfQuUqjhz6kTU8Lp4jSjHyJmSF+s5zMnkHGKNitbNNZcNxVf H9nVlUM5F3/ZidouPUn7ZJh3gYYsRGS1QvFRDiDaWQ07r+ayLWDyVuSXpqMRpW/Ac/IY GlTOEF6M1jw84HgsBD4fQE7T8E+dPF20s+H4ifUPwBkNXwpl/LZdyeCTW3SYSWbzUw66 4vxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709773177; x=1710377977; 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=s9/1mdln9FYDENEIkWEufUZtqQyXG+2Q8vpPpAXGkJ0=; b=GlOdTKbzzo6m7Xmxu77/ukVOBfiZDgZxw9qKhTAPLS7Lt04QbB/SexNRdv7ZY/DDYW NIlonhjBudW3g3ILiycH2/+qYFOIP0ev9h+AJnkjlTNut5qKm38n2ru9e7ZaU3fobogC ECzwv09vp8a7Y05+ezLgGm7W6cyAQa/qHw81VG2Vs08tRewAqteJltUrrqscaAFyZbkG 4VTO3T4zJOg1JDUR8l4MbZJPfE7IdRoveGt2GMbHCsS5a+SB8nvhf/0OBXlk6pMAep/W 7Ml3Ls+kUAXe1Gj4gLXbU/D3T0yhy6BuSFR5HYVhgCcp5XCvtHbAhQJcx+yQ1fMXZXPm 1nEQ== X-Forwarded-Encrypted: i=1; AJvYcCXne3MeXWJHf4WK03wpHQ4hB099yVDPurn8IBIP/jVKhXNyi3dzH/FIxHVIxx8xrH18LUNvJ7X8dqxSSk5EefhupHcPrm7Itq+5HrZTsytOpAA/jX6fUAUUAnYwPw== X-Gm-Message-State: AOJu0YzKrnivtfEpn9OuSMY7INBFivtbfXFXQ1HqfH3o9El1uK82qrWc 4SvBkOvy/tf6OI8SLgNb41SrEb+9b/pWfeFMQMKrsRG9Bo+ZAslw X-Google-Smtp-Source: AGHT+IEE5FiM3wNLdQj0kPDP4dPpxZO1lhU+TTJZDfhhFbyfLiQDrvUfnmZMHMS84HPE32sa9mWB8w== X-Received: by 2002:a05:6358:5e08:b0:17b:f881:6649 with SMTP id q8-20020a0563585e0800b0017bf8816649mr5510428rwn.26.1709773176645; Wed, 06 Mar 2024 16:59:36 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: marcel.apfelbaum@gmail.com, Jonathan.Cameron@Huawei.com, its@irrelevant.dk, mst@redhat.com, hchkuo@avery-design.com.tw, wilfred.mallawa@wdc.com, cbrowy@avery-design.com, kbusch@kernel.org, lukas@wunner.de, jiewen.yao@intel.com, qemu-devel@nongnu.org Cc: Alistair Francis , qemu-block@nongnu.org, Paolo Bonzini , alistair23@gmail.com, Jonathan Cameron , Klaus Jensen Subject: [PATCH v5 3/3] hw/nvme: Add SPDM over DOE support Date: Thu, 7 Mar 2024 10:58:59 +1000 Message-ID: <20240307005859.356555-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240307005859.356555-1-alistair.francis@wdc.com> References: <20240307005859.356555-1-alistair.francis@wdc.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::c32; envelope-from=alistair23@gmail.com; helo=mail-oo1-xc32.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1709773243738100011 Content-Type: text/plain; charset="utf-8" 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 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +QEMU Security Protocols and Data Models (SPDM) Support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +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 devic= e. + +Setting up a SPDM server +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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 met= hod. + +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 inc= luded +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=3Dx64 -DTOOLCHAIN=3DGCC -DTARGET=3DDebug -DCRYPTO=3Dope= nssl .. + $ make -j32 + $ make copy_sample_key # Build certificates, required for SPDM authent= ication. + +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 =3D otherName:2.23.147;UTF8:Vendor=3D1b36:Device=3D0010= :CC=3D010802:REV=3D02:SSVID=3D1af4:SSID=3D1100 + 2.23.147 =3D 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=3DDMTF 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_respo= nder.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 +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +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=3D/dev/zero of=3Dblknvme bs=3D1M count=3D2096 # 2GB NNMe Drive + +Then you can add this to your QEMU command line: + +.. code-block:: shell + + -drive file=3Dblknvme,if=3Dnone,id=3Dmynvme,format=3Draw \ + -device nvme,drive=3Dmynvme,serial=3Ddeadbeef,spdm=3D2323 + +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-mutabl= e-certificates + +.. _Run it as a server: + https://github.com/westerndigitalcorporation/spdm-utils#qemu-spdm-devic= e-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 @@ =20 #include "hw/pci/pci.h" #include "hw/pci/pcie.h" +#include "hw/pci/pcie_doe.h" =20 #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; =20 + /* 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; }; =20 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 76fe039704..0f89988c6f 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" =20 #include "nvme.h" @@ -8070,6 +8071,28 @@ static int nvme_add_pm_capability(PCIDevice *pci_dev= , uint8_t offset) return 0; } =20 +static bool pcie_doe_spdm_rsp(DOECap *doe_cap) +{ + void *req =3D pcie_doe_get_write_mbox_ptr(doe_cap); + uint32_t req_len =3D pcie_doe_get_obj_len(req) * 4; + void *rsp =3D doe_cap->read_mbox; + uint32_t rsp_len =3D SPDM_SOCKET_MAX_MESSAGE_BUFFER_SIZE; + uint32_t recvd; + + recvd =3D spdm_socket_rsp(doe_cap->socket, + SPDM_SOCKET_TRANSPORT_TYPE_PCI_DOE, + req, req_len, rsp, rsp_len); + doe_cap->read_mbox_len +=3D DIV_ROUND_UP(recvd, 4); + + return recvd !=3D 0; +} + +static DOEProtocol doe_spdm_prot[] =3D { + { 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 *pc= i_dev, Error **errp) =20 nvme_update_msixcap_ts(pci_dev, n->conf_msix_qsize); =20 + pcie_cap_deverr_init(pci_dev); + + /* DOE 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; + + pcie_doe_init(pci_dev, &pci_dev->doe_spdm, doe_offset, doe_spdm_pr= ot, true, 0); + + pci_dev->doe_spdm.socket =3D spdm_socket_connect(pci_dev->spdm_por= t, 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[] =3D { 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(), }; =20 @@ -8494,10 +8536,20 @@ static void nvme_pci_write_config(PCIDevice *dev, u= int32_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); } =20 +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 =3D { .name =3D "nvme", .unmigratable =3D 1, @@ -8510,6 +8562,7 @@ static void nvme_class_init(ObjectClass *oc, void *da= ta) =20 pc->realize =3D nvme_realize; pc->config_write =3D nvme_pci_write_config; + pc->config_read =3D nvme_pci_read_config; pc->exit =3D nvme_exit; pc->class_id =3D PCI_CLASS_STORAGE_EXPRESS; pc->revision =3D 2; --=20 2.44.0