Linux CXL
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Lukas Wunner <lukas@wunner.de>, <linux-pci@vger.kernel.org>,
	<linux-cxl@vger.kernel.org>
Cc: <linuxarm@huawei.com>, Dan Williams <dan.j.williams@intel.com>,
	"Adam Manzanares" <a.manzanares@samsung.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Christoph Hellwig <hch@infradead.org>, Ben W <ben@bwidawsk.net>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	David E Box <david.e.box@intel.com>,
	Chuck Lever <chuck.lever@oracle.com>, <kw@linux.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Joerg Roedel <joro@8bytes.org>,
	Eric Biggers <ebiggers@google.com>
Subject: [RFC PATCH v3 4/4] cxl/pci: Add really basic CMA authentication support.
Date: Tue, 6 Sep 2022 12:15:56 +0100	[thread overview]
Message-ID: <20220906111556.1544-5-Jonathan.Cameron@huawei.com> (raw)
In-Reply-To: <20220906111556.1544-1-Jonathan.Cameron@huawei.com>

This is just for purposes of poking the CMA / SPDM code.
What exactly the model in the driver looks like is still to
be worked out.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
  May still need to force non async probe as done in earlier versions.

 drivers/cxl/Kconfig    |  1 +
 drivers/cxl/core/pci.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlpci.h   |  1 +
 drivers/cxl/port.c     |  1 +
 4 files changed, 50 insertions(+)

diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig
index 768ced3d6fe8..a5d9589dd7a7 100644
--- a/drivers/cxl/Kconfig
+++ b/drivers/cxl/Kconfig
@@ -3,6 +3,7 @@ menuconfig CXL_BUS
 	tristate "CXL (Compute Express Link) Devices Support"
 	depends on PCI
 	select PCI_DOE
+	select PCI_CMA
 	help
 	  CXL is a bus that is electrically compatible with PCI Express, but
 	  layers three protocols on that signalling (CXL.io, CXL.cache, and
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index 9240df53ed87..dfc9fc670be5 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -4,7 +4,9 @@
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/pci.h>
+#include <linux/pci-cma.h>
 #include <linux/pci-doe.h>
+#include <linux/spdm.h>
 #include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
@@ -625,3 +627,48 @@ void read_cdat_data(struct cxl_port *port)
 	}
 }
 EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);
+
+/* Make a generic find routine that take the VID / Protocol */
+static struct pci_doe_mb *find_cma_doe(struct device *uport)
+{
+	struct cxl_memdev *cxlmd;
+	struct cxl_dev_state *cxlds;
+	unsigned long index;
+	void *entry;
+
+	cxlmd = to_cxl_memdev(uport);
+	cxlds = cxlmd->cxlds;
+
+	xa_for_each(&cxlds->doe_mbs, index, entry) {
+		struct pci_doe_mb *cur = entry;
+
+		if (pci_doe_supports_prot(cur, PCI_VENDOR_ID_PCI_SIG, 1))
+			return cur;
+	}
+
+	return NULL;
+}
+
+void cxl_cma_init(struct cxl_port *port)
+{
+	struct spdm_state *spdm_state;
+	struct pci_doe_mb *cma_doe;
+	struct device *dev = &port->dev;
+	struct device *uport = port->uport;
+	int rc;
+
+	cma_doe = find_cma_doe(uport);
+	if (!cma_doe) {
+		dev_info(dev, "No CDAT mailbox\n");
+		return;
+	}
+
+	spdm_state = pci_cma_create(dev, cma_doe);
+	rc = pci_cma_authenticate(spdm_state);
+	if (rc)
+		dev_info(dev, "No CMA support\n");
+	else
+		dev_info(dev, "Attestation passed\n");
+	pci_cma_destroy(spdm_state);
+}
+EXPORT_SYMBOL_NS_GPL(cxl_cma_init, CXL);
diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h
index eec597dbe763..36d619563df1 100644
--- a/drivers/cxl/cxlpci.h
+++ b/drivers/cxl/cxlpci.h
@@ -75,4 +75,5 @@ int devm_cxl_port_enumerate_dports(struct cxl_port *port);
 struct cxl_dev_state;
 int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm);
 void read_cdat_data(struct cxl_port *port);
+void cxl_cma_init(struct cxl_port *port);
 #endif /* __CXL_PCI_H__ */
diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c
index 5453771bf330..9c6880e8c1f4 100644
--- a/drivers/cxl/port.c
+++ b/drivers/cxl/port.c
@@ -55,6 +55,7 @@ static int cxl_port_probe(struct device *dev)
 
 		/* Cache the data early to ensure is_visible() works */
 		read_cdat_data(port);
+		cxl_cma_init(port);
 
 		get_device(&cxlmd->dev);
 		rc = devm_add_action_or_reset(dev, schedule_detach, cxlmd);
-- 
2.32.0


      parent reply	other threads:[~2022-09-06 11:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 11:15 [RFC PATCH v3 0/4] PCI/CMA and SPDM Library - Device attestation etc Jonathan Cameron
2022-09-06 11:15 ` [RFC PATCH v3 1/4] lib/asn1_encoder: Add a function to encode many byte integer values Jonathan Cameron
2022-09-06 11:15 ` [RFC PATCH v3 2/4] spdm: Introduce a library for DMTF SPDM Jonathan Cameron
2022-09-06 11:15 ` [RFC PATCH v3 3/4] PCI/CMA: Initial support for Component Measurement and Authentication ECN Jonathan Cameron
2022-09-23 21:36   ` Bjorn Helgaas
2022-09-24  5:39     ` Lukas Wunner
2022-09-24 23:19       ` Dan Williams
2022-09-06 11:15 ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220906111556.1544-5-Jonathan.Cameron@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=a.manzanares@samsung.com \
    --cc=ben@bwidawsk.net \
    --cc=bhelgaas@google.com \
    --cc=chuck.lever@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=david.e.box@intel.com \
    --cc=ebiggers@google.com \
    --cc=hch@infradead.org \
    --cc=ira.weiny@intel.com \
    --cc=joro@8bytes.org \
    --cc=kw@linux.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=lukas@wunner.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox