From nobody Wed Nov 27 04:32:52 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=1700708391; cv=none; d=zohomail.com; s=zohoarc; b=Q0iB00uod4TsYp/Ju6k51FjbYtgWj8GDWz88px3jMrh+qgAZu8Fwx+4lfvh+vJ68/1nuYRu2TTmtGgNEvGNgfgYib6cLUiYkIUwlmYO+W4bwwLhWEd7vYCnz8DPCD6BZ0zpcI+8zaFyz9B0v/0RWxvj+ls+3fUCWVcuAi4NbiU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700708391; 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=dIQzh+3gCVOtxJ46zfLPVv885EzLo4sOUWMLMpKf7c4=; b=POwKIzckZ1AT/ZXrqBhjDhvmxddDz6L7KQk7CnRDypj9VtsCWXjbLCGqLFdrzZGthTtlDAa7aSvZepCeSrep+SWSf3HaD1HcBrcOuLNXGErWTGsON3Q9bHjZXPHlNlVE6FDBmgTEyW+nzQEe1Qq6n7gb60/heKujzUthaNDLIeM= 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 1700708391211767.7917117182093; Wed, 22 Nov 2023 18:59:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5zvp-0001QR-NJ; Wed, 22 Nov 2023 21:59:09 -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 1r5zvo-0001Ox-IG; Wed, 22 Nov 2023 21:59:08 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5zvn-0000QT-6P; Wed, 22 Nov 2023 21:59:08 -0500 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-282fcf7eef9so343297a91.1; Wed, 22 Nov 2023 18:59:05 -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 br17-20020a17090b0f1100b0027909a8994fsm476743pjb.13.2023.11.22.18.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 18:59:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700708345; x=1701313145; 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=dIQzh+3gCVOtxJ46zfLPVv885EzLo4sOUWMLMpKf7c4=; b=L3tgWFpHY1r0lYyHAXhvKDK/CRFntl55NXameGrr8g7Yfog8FFoh73UHKaHZ1xRuQE gK8K194H6dcswNVwPZmtiaC5slDh/U8t84oYI2MHeYvMxBfgsonQqhZDQmY+LCH89SiZ sUOdAB8e6XYHYZH7htxZltRuN5CH9EeV7hySlSWm4RSr0afmHeYl/XWYHIUoePcxX4UH +1FUwrJqXAu0VabwdRgn30aFqjxoUp0qMTr3Me4WmWe7Ojj1h1OrWd7YKZ1iDO+BWtM0 eTMQR+WpJzX2YZ9K7pHyQxN6JtNBuiBjvubYeF6FjET/z0TBfZCjpJzPZP3d2eqtY5oV CDbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700708345; x=1701313145; 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=dIQzh+3gCVOtxJ46zfLPVv885EzLo4sOUWMLMpKf7c4=; b=gsnP8su8hlYhU/iX9WhtPH37+O0oIUXMqS1Gtq3FyMh5wDp+HEXaPDgoaFFMpfdQXq 7pTZfM/PkW5tuP9FcbUlcMnTJzL3FR4q8afPqrdWZKnVAt8ztGCWwDMEhMps0HmbOoUz Ii0GpSQTfdwjPXxsgS57YgyHe6aBVcQU7VuOjAnMZ/jBmScnGDPH4LS50FAG5XimkDIX l25NRXuPFSESJWwA8JP22M8Rmq6cNey6PaFeM555GEPQwHnCuUYwRASq2q7YBhIBWYix eIWvpcE7s/w4tnwuozjGA66shnoHxtW9ZRx4toCKF+pw/+auPhQrsn6vi9Ozgdj4Pe/s tf/g== X-Gm-Message-State: AOJu0YyLOZpOYdtOmLYyRz0pkxpq7d+dD1t3jm3udhSspCTWlN7IJJgQ /v2UDutH9Tuu+PikT3hPFQI= X-Google-Smtp-Source: AGHT+IGpvz6Fcs7RKjE0cyg89kUdIMLPL1dbiDpKoCPyna/OJu99UQqaRIArpFkStNOoHima6RO/Jg== X-Received: by 2002:a17:90b:38d1:b0:280:a6a6:9b1b with SMTP id nn17-20020a17090b38d100b00280a6a69b1bmr4239439pjb.19.1700708344981; Wed, 22 Nov 2023 18:59:04 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: marcel.apfelbaum@gmail.com, cbrowy@avery-design.com, its@irrelevant.dk, jiewen.yao@intel.com, wilfred.mallawa@wdc.com, Jonathan.Cameron@Huawei.com, lukas@wunner.de, hchkuo@avery-design.com.tw, kbusch@kernel.org, qemu-devel@nongnu.org, mst@redhat.com Cc: qemu-block@nongnu.org, alistair23@gmail.com, Paolo Bonzini , Alistair Francis , Jonathan Cameron Subject: [PATCH v3 1/3] hw/pci: Add all Data Object Types defined in PCIe r6.0 Date: Thu, 23 Nov 2023 12:58:45 +1000 Message-ID: <20231123025847.2538863-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231123025847.2538863-1-alistair.francis@wdc.com> References: <20231123025847.2538863-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::102a; envelope-from=alistair23@gmail.com; helo=mail-pj1-x102a.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: 1700708392784100005 Content-Type: text/plain; charset="utf-8" Add all of the defined protocols/features from the PCIe-SIG r6.0 "Table 6-32 PCI-SIG defined Data Object Types (Vendor ID =3D 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) =20 /* 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 =20 #define PCI_DOE_DW_SIZE_MAX (1 << 18) #define PCI_DOE_PROTOCOL_NUM_MAX 256 --=20 2.42.0 From nobody Wed Nov 27 04:32:52 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=1700708391; cv=none; d=zohomail.com; s=zohoarc; b=fUMzETqcm3QcKzteMucgeq5AOOPpy43Vw5eKD3nIXV2e1EEwZ33NqIrNnEjuRQLAAQbuXuDpAk5UIe/A0l1K6IAVzCHygxcVIuKGIsGYM4S031Hkjcv8Evgha7YLhQG73k5+SbIQxMOuBNyPvuylm8/ESHQhyPf77YZF1bSoA6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700708391; 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=83SQt3W6AQgNci/+XFKsfNNylqPiwaHIBR/GEEgqfuE=; b=VjT1H8nXNe1XoEGNvr7iYyrltKwTip70H6+E8T8VMGemRegRfqN1mxgq4iDgv/MQupKFRiUpUDB4CnpCcMnnoKAPK7w6S2cMS7kPQzYwAd5dDkmFU51YzFseeHrnSfPd86mOXi1HgbeGDD7jXM29PwkLHHZQXAu+3FA67nTHXkg= 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 170070839141474.98143252548573; Wed, 22 Nov 2023 18:59:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5zvw-0001Y7-HH; Wed, 22 Nov 2023 21:59:16 -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 1r5zvv-0001Xk-Q2; Wed, 22 Nov 2023 21:59:15 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5zvt-0000Sm-LZ; Wed, 22 Nov 2023 21:59:15 -0500 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-280200949c3so360260a91.0; Wed, 22 Nov 2023 18:59:13 -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 br17-20020a17090b0f1100b0027909a8994fsm476743pjb.13.2023.11.22.18.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 18:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700708352; x=1701313152; 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=83SQt3W6AQgNci/+XFKsfNNylqPiwaHIBR/GEEgqfuE=; b=A7dcC06R1n3Ct793txGGXUp8ApCTKPZ7x909ObKy9+HiOBr0hC3K+C3XMitmjt3Kxu cWgasq5hrDrqb64SiFkaYvXFcgFiNzKSnQhKofgV+hbdkkZAzWOOmjEchXCIY9WiziTS a95TPZ1iw3CL/xSlUrDeopLa4xsfExHBCSbgbdJ65rlEmmgMrA4vjbIeA1TOZXqKFsnE l2SKV8sKrv/Bv6gRzBWsedPWkLi1grYG2CfMS0g3KCaLVbm83YzjLFCW38pzogXWK8Hq h9Z03BBCLP0BZeg3Apf6d2ADpIOAP7sBjJdMhswmtjgoPIqCUvIuH/ghSG526ioQ90Jk jp0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700708352; x=1701313152; 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=83SQt3W6AQgNci/+XFKsfNNylqPiwaHIBR/GEEgqfuE=; b=gPXO7QDnigIePkgfW42vcY+1qcVnGBrnnHpJUYpl0nBklw01vmUsOdRbWnAfzZ9K/g MR+Kqo228OjfqNHItiWQ/gd4GlHoiUjxC00clU24xozKT2EQ7dAIgCj96DHfRcJrevsf pokjgGSS8d2zxUIVZd6SIS+QaikzexZ55qvl3BgI3xyVGN1+x2G3NLEOnib40NLyUyxG iEbHNDndOulLiA9ETyphY5+B6BpxX4N6y5plyZdwhL/iqxNt6yXzw13L+YCzHAlW1Frq F3kJjjyuUnzqdccg3lmMHcGcdPoD3I0uhLqqR3tPKyQbnoAn9tiW4o+M7Pmqcts8wTri MF0g== X-Gm-Message-State: AOJu0YxUByLxSgUZGoImZ6smgVsajHw7Av9LEfLUcFy5iXqxojFq6EtV k6Heh6LPG0Ic7moyt4E1gSk= X-Google-Smtp-Source: AGHT+IFMDNHRws6wuTWHGZxolNXUole61pbduwFyHmyPQcuob9xeEK+dRXk/2Tpkx0tMYlOFVMasBQ== X-Received: by 2002:a17:90b:1803:b0:285:6722:ac91 with SMTP id lw3-20020a17090b180300b002856722ac91mr205841pjb.30.1700708351899; Wed, 22 Nov 2023 18:59:11 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: marcel.apfelbaum@gmail.com, cbrowy@avery-design.com, its@irrelevant.dk, jiewen.yao@intel.com, wilfred.mallawa@wdc.com, Jonathan.Cameron@Huawei.com, lukas@wunner.de, hchkuo@avery-design.com.tw, kbusch@kernel.org, qemu-devel@nongnu.org, mst@redhat.com Cc: qemu-block@nongnu.org, alistair23@gmail.com, Paolo Bonzini , Jonathan Cameron , Jonathan Cameron , Alistair Francis Subject: [PATCH v3 2/3] backends: Initial support for SPDM socket support Date: Thu, 23 Nov 2023 12:58:46 +1000 Message-ID: <20231123025847.2538863-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231123025847.2538863-1-alistair.francis@wdc.com> References: <20231123025847.2538863-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::1029; envelope-from=alistair23@gmail.com; helo=mail-pj1-x1029.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: 1700708392837100007 Content-Type: text/plain; charset="utf-8" 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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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/07c0a838bcc1c6207c656ac75885c0603= e344b6f/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 =3D 0; + ssize_t result; + + while (number_received < number_of_bytes) { + result =3D recv(socket, buffer + number_received, + number_of_bytes - number_received, 0); + if (result <=3D 0) { + return false; + } + number_received +=3D result; + } + return true; +} + +static bool read_data32(const int socket, uint32_t *data) +{ + bool result; + + result =3D read_bytes(socket, (uint8_t *)data, sizeof(uint32_t)); + if (!result) { + return result; + } + *data =3D 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 =3D read_data32(socket, &length); + if (!result) { + return result; + } + + if (length > max_buffer_length) { + return false; + } + + if (bytes_received) { + *bytes_received =3D length; + } + + if (length =3D=3D 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 =3D read_data32(socket, &response); + if (!result) { + return result; + } + *command =3D response; + + result =3D read_data32(socket, &transport_type); + if (!result) { + return result; + } + + bytes_received =3D 0; + result =3D read_multiple_bytes(socket, receive_buffer, &bytes_received, + *bytes_to_receive); + if (!result) { + return result; + } + *bytes_to_receive =3D bytes_received; + + return result; +} + +static bool write_bytes(const int socket, const uint8_t *buffer, + uint32_t number_of_bytes) +{ + ssize_t number_sent =3D 0; + ssize_t result; + + while (number_sent < number_of_bytes) { + result =3D send(socket, buffer + number_sent, + number_of_bytes - number_sent, 0); + if (result =3D=3D -1) { + return false; + } + number_sent +=3D result; + } + return true; +} + +static bool write_data32(const int socket, uint32_t data) +{ + data =3D 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 =3D 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 =3D write_data32(socket, command); + if (!result) { + return result; + } + + result =3D 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 =3D 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 =3D AF_INET; + server_addr.sin_addr.s_addr =3D htonl(INADDR_LOOPBACK); + server_addr.sin_port =3D 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 =3D send_platform_data(socket, transport_type, + SPDM_SOCKET_COMMAND_NORMAL, + req, req_len); + if (!result) { + return 0; + } + + result =3D receive_platform_data(socket, transport_type, &command, + (uint8_t *)rsp, &rsp_len); + if (!result) { + return 0; + } + + assert(command !=3D 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 f35abc1609..648e58a9b3 100644 --- a/backends/Kconfig +++ b/backends/Kconfig @@ -1 +1,5 @@ source tpm/Kconfig + +config SPDM_SOCKET + bool + default y diff --git a/backends/meson.build b/backends/meson.build index 914c7c4afb..77d48ffdaa 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -26,4 +26,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')) =20 +system_ss.add(when: 'CONFIG_SPDM_SOCKET', if_true: files('spdm-socket.c')) + subdir('tpm') --=20 2.42.0 From nobody Wed Nov 27 04:32:52 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=1700708403; cv=none; d=zohomail.com; s=zohoarc; b=ikD7zWVJF7t/uaWEiw4ezqHRJ1TCSOC333MeatkQrZeIhaMWSqKFpK6V+Jow+zU+0R+sZRU7buVWCVUKCDI6yxseWmNxFclPoqq5aibL/RFlBu+aUzvFpKp2NSnlF5tjWy1j6FuiTwWu4A5Qe8aPdFb54hgjNruRSMd+orTHgsw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700708403; 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=B/sF2esx1nv3kRKas+A7isr9yLRf7C3aduwkHtK926A=; b=FWcXUqZ1uFaG7Chy0oFpMjDFnq1B1D4ZURoKt+PRzyCltCI7ojg8ORCAa3VxKCJkmM1yt8kGO+lQoG0ZKQPBjhwzHADebbxSijTwT8JXBWYnN5HnO3F1MAkSZL7Vbkb4adtfN3d2bwc0q+HbQVvcESMB7FzkYRC6kbeWGkWKlhs= 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 1700708403701137.37871533058603; Wed, 22 Nov 2023 19:00:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5zwB-00020V-3R; Wed, 22 Nov 2023 21:59:31 -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 1r5zw9-0001wO-JS; Wed, 22 Nov 2023 21:59:29 -0500 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5zw2-0000Xg-FC; Wed, 22 Nov 2023 21:59:29 -0500 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6ce2eaf7c2bso299970a34.0; Wed, 22 Nov 2023 18:59:21 -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 br17-20020a17090b0f1100b0027909a8994fsm476743pjb.13.2023.11.22.18.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 18:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700708359; x=1701313159; 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=B/sF2esx1nv3kRKas+A7isr9yLRf7C3aduwkHtK926A=; b=f8cSGEYQyPdp00YGHqJRdhHsoEVYXWOYE5vYww5XMFsE2HY/dS0NxXMQSELFaix9tg IzT4ZhvOKdx6T+xSVm/GKR/Wzw1RvEfUrb/zWYmKkewKG0q1hefLf8pbh4QX8/vXvYFz TjMH1X2OQEa4WQpToKjMJnnVu3g2NR+Q6mo7bKMFLHld3E0lVfzYCRdZVWzSFvYT1nKt svk2odu2IsC1YRaComx1qF3NdN+okaIO/VZmSuA9FLnkoKTFM3YTLGYw4HPdWAwCPUYA sk9cDsx5qEOI8nj88qVNNdl2Y7id3zpoGsZa4Br07jYZhYv8rel79nVMF1o3FmffILp7 hJSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700708359; x=1701313159; 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=B/sF2esx1nv3kRKas+A7isr9yLRf7C3aduwkHtK926A=; b=QNxcOYEKQsX641/gzqZADC/L1qYqSyZZWD3bZ997TVLVdWisfz3/FneX4weRioWsMo kuhkh77/DPPepPYz0Nk8wn9ecnX0wVAjfizb8OnYY3VDPcBMHJ+qtCyfyZEkfy2cgSvW 6IXv+U6/9TMTwHgzJxa3+VM6fpxmSK/q43nQm7zC92dnXzcVzCuZanDuxtuId41Zeumd UafNtTRPValQd+RKDZd2aNOdr/Vi4P0Sf06skDAFxL8BsX2h91RIdWKJ3zh9T1+AZQ2u irziy3kzMGc1JD/KksqxUwulEncZY0/vgQDroq7TsMWXRwUI6fjOYQ+7UMjdOdLfdABa pKrQ== X-Gm-Message-State: AOJu0Yz7D8KqSLMUvx4Kua6gB/GaJ2vevBaScuoJy9IoLePfH6aNzojz DJ7KLsL/3kH3bf6JhfeGluE= X-Google-Smtp-Source: AGHT+IEWfZd/DloWj48vH8N994MC213eOo/C6VJKATwsW8cpZv8/gm5xhZDooyn0XdiMFV1pjmvmyA== X-Received: by 2002:a05:6870:c98f:b0:1e1:e36a:fb74 with SMTP id hi15-20020a056870c98f00b001e1e36afb74mr5684348oab.26.1700708359128; Wed, 22 Nov 2023 18:59:19 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: marcel.apfelbaum@gmail.com, cbrowy@avery-design.com, its@irrelevant.dk, jiewen.yao@intel.com, wilfred.mallawa@wdc.com, Jonathan.Cameron@Huawei.com, lukas@wunner.de, hchkuo@avery-design.com.tw, kbusch@kernel.org, qemu-devel@nongnu.org, mst@redhat.com Cc: qemu-block@nongnu.org, alistair23@gmail.com, Paolo Bonzini , Alistair Francis , Jonathan Cameron , Klaus Jensen Subject: [PATCH v3 3/3] hw/nvme: Add SPDM over DOE support Date: Thu, 23 Nov 2023 12:58:47 +1000 Message-ID: <20231123025847.2538863-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231123025847.2538863-1-alistair.francis@wdc.com> References: <20231123025847.2538863-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::330; envelope-from=alistair23@gmail.com; helo=mail-ot1-x330.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: 1700708404392100003 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 | 121 ++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_device.h | 5 ++ include/hw/pci/pcie_doe.h | 3 + hw/nvme/ctrl.c | 53 ++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 docs/specs/spdm.rst diff --git a/docs/specs/index.rst b/docs/specs/index.rst index b3f482b0aa..fbbb702c7d 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -28,6 +28,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..a592181c7e --- /dev/null +++ b/docs/specs/spdm.rst @@ -0,0 +1,121 @@ +=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. + +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: + + 1. `Build SPDM Utils`_ + 2. `Generate the certificates`_ + 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 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" =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.42.0