From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0487C77B73 for ; Thu, 20 Apr 2023 09:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbjDTJAu (ORCPT ); Thu, 20 Apr 2023 05:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234068AbjDTJAE (ORCPT ); Thu, 20 Apr 2023 05:00:04 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C173C05; Thu, 20 Apr 2023 01:56:24 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Q2BL65LXTz67lH6; Thu, 20 Apr 2023 16:54:38 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 20 Apr 2023 09:55:47 +0100 Date: Thu, 20 Apr 2023 09:55:46 +0100 From: Jonathan Cameron To: Dave Jiang CC: , , Ira Weiny , , , , , Subject: Re: [PATCH v4 02/23] cxl: Add checksum verification to CDAT from CXL Message-ID: <20230420095546.00005def@Huawei.com> In-Reply-To: <168193567363.1178687.9185773070266307121.stgit@djiang5-mobl3> References: <168193556660.1178687.15477509915255912089.stgit@djiang5-mobl3> <168193567363.1178687.9185773070266307121.stgit@djiang5-mobl3> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml500003.china.huawei.com (7.191.162.67) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org On Wed, 19 Apr 2023 13:21:13 -0700 Dave Jiang wrote: > 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 > Signed-off-by: Dave Jiang Reviewed-by: Jonathan Cameron > > --- > v3: > - Just return the final sum. (Alison) > v2: > - Drop ACPI checksum export and just use local verification. (Dan) > --- > drivers/cxl/core/pci.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c > index 25b7e8125d5d..9c7e2f69d9ca 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 > @@ -573,6 +583,12 @@ void read_cdat_data(struct cxl_port *port) > } > > port->cdat.table = cdat_table + sizeof(__le32); > + if (cdat_checksum(port->cdat.table, cdat_length)) { > + /* Don't leave table data allocated on error */ > + devm_kfree(dev, cdat_table); > + dev_err(dev, "CDAT data checksum error\n"); > + } > + > port->cdat.length = cdat_length; > } > EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL); > >