All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: dan.j.willimans@intel.com
Cc: Ira Weiny <ira.weiny@intel.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	linux-cxl@vger.kernel.org
Subject: [PATCH v3] cxl: Add checksum verification to CDAT from CXL
Date: Fri, 12 May 2023 15:01:24 -0700	[thread overview]
Message-ID: <168392888452.286187.18112582667622962209.stgit@djiang5-mobl3> (raw)
In-Reply-To: <645eb1bd61964_1e6f29419@dwillia2-xfh.jf.intel.com.notmuch>

A CDAT table is available from a CXL device. The table is read by the
driver and cached in software. With the CXL subsystem needing to parse the
CDAT table, the checksum should be verified. Add checksum verification
after the CDAT table is read from device.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

---
Post patch series split:
v3:
- Use single error out path. (Dan)
v2:
- Split out fix for cdat_read() error path return. (Davidlohr)
- Make port->cdat consistent. (Davidlohr)

___
v5:
- Return on CDAT errors. (Dan)
v3:
- Just return the final sum. (Alison)
v2:
- Drop ACPI checksum export and just use local verification. (Dan)
---
 drivers/cxl/core/pci.c |   30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index f332fe7af92b..103c27f5e2a9 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -528,6 +528,16 @@ static int cxl_cdat_read_table(struct device *dev,
 	return 0;
 }
 
+static unsigned char cdat_checksum(void *buf, size_t size)
+{
+	unsigned char sum, *data = buf;
+	size_t i;
+
+	for (sum = 0, i = 0; i < size; i++)
+		sum += data[i];
+	return sum;
+}
+
 /**
  * read_cdat_data - Read the CDAT data on this port
  * @port: Port to read data from
@@ -567,15 +577,21 @@ void read_cdat_data(struct cxl_port *port)
 		return;
 
 	rc = cxl_cdat_read_table(dev, cdat_doe, cdat_table, &cdat_length);
-	if (rc) {
-		/* Don't leave table data allocated on error */
-		devm_kfree(dev, cdat_table);
-		dev_err(dev, "CDAT data read error\n");
-		return;
-	}
+	if (rc)
+		goto err;
 
-	port->cdat.table = cdat_table + sizeof(__le32);
+	cdat_table = cdat_table + sizeof(__le32);
+	if (cdat_checksum(cdat_table, cdat_length))
+		goto err;
+
+	port->cdat.table = cdat_table;
 	port->cdat.length = cdat_length;
+	return;
+
+err:
+	/* Don't leave table data allocated on error */
+	devm_kfree(dev, cdat_table);
+	dev_err(dev, "Failed to read/validate CDAT.\n");
 }
 EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);
 



  reply	other threads:[~2023-05-12 22:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 17:58 [PATCH v2 0/4] cxl: Prep for QoS class support Dave Jiang
2023-05-11 17:58 ` [PATCH v2 1/4] cxl: Export QTG ids from CFMWS to sysfs as qos_class attribute Dave Jiang
2023-05-11 23:56   ` Dan Williams
2023-05-11 17:58 ` [PATCH v2 2/4] cxl: add missing return to cdat read error path Dave Jiang
2023-05-11 23:59   ` Dan Williams
2023-05-15 10:03     ` Jonathan Cameron
2023-05-11 17:59 ` [PATCH v2 3/4] cxl: Add checksum verification to CDAT from CXL Dave Jiang
2023-05-12 21:38   ` Dan Williams
2023-05-12 22:01     ` Dave Jiang [this message]
2023-05-11 17:59 ` [PATCH v2 4/4] cxl: Add support for reading CXL switch CDAT table Dave Jiang
2023-05-12 21:39   ` Dan Williams
2023-05-12 19:00 ` [PATCH v2 0/4] cxl: Prep for QoS class support Davidlohr Bueso

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=168392888452.286187.18112582667622962209.stgit@djiang5-mobl3 \
    --to=dave.jiang@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=dan.j.willimans@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.