Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4059412iog; Tue, 28 Jun 2022 08:12:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sd6cy10mfUQzVHFJ+S0aFNmAjJF10MQC3ag+6ewfDVyFetC83nX+MphQzQ41pPs9zUceAx X-Received: by 2002:a17:90a:4f0a:b0:1ec:89bd:725c with SMTP id p10-20020a17090a4f0a00b001ec89bd725cmr104110pjh.172.1656429149445; Tue, 28 Jun 2022 08:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656429149; cv=none; d=google.com; s=arc-20160816; b=MA+BUxfq/yxbVTmsYr+Tnn8TDKNOQwxXT1M9jSFmQMmphooJ8+1lacvBoTQGHlz13S sraOW9rjnLSZDtmZNNqj9WaUcxB5NgIZu+cXbADyGCHbV/+5fAopo1td1WcQZrV684Dv iVRfTqs/WtdXnPew56Q8/A4I3pVGyFgl2p6oQ72FuWpK5VZ95913Xd/Cac+ZSLsOjj/2 MiDaY/rFeXU6Lbfb7EJ39yysPvQdxi2C+T+P0nZ9fpW6Uyrxgytv+xH08NLdGwGuYUWN Y2kda/TtE7T429oam3y24zRhiCa++aK8PNlW3yUy0rd9fMtTaeiZSoHEoO535ASl1o8R dkCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=YSELLwsMD6B96KUV5ADw6c0C7k0VNh8Q2INb0EOki5Q=; b=ihjOIMFea9QVzQe0bCKLXIUrlBp/WX1fyOVDC3zXpcwM9WGRsEJaypRjWB1AeZkRio LC/P+RSzbwUPGu8OFAbo92vi8LOT8FlaSRDkuovPV/ol7Gy0UnrSaYLBW+qexGr0J7g+ 8nFUqi3TiJoOWsz2Llg3dljQTiXZ3Gpnw85TVYtlhvnb3Kb0e/MBUC0W73CnIOV95COG WxqSYviSdT3/PUorYD1C7zc8//x09X6hs97foqeu4aUY6taXHkAZzloc1H0dAyU6oowk KTFB2i7BNbNM3WW21+IsNB54mAFlP6cu5xN8M9jneUXTBGmNsa3NoZj9DZhvwzI71RzH +Ikw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a170902f60500b0016a573b9b45si18570413plg.447.2022.06.28.08.12.08; Tue, 28 Jun 2022 08:12:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347572AbiF1Otx (ORCPT + 99 others); Tue, 28 Jun 2022 10:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347570AbiF1Otu (ORCPT ); Tue, 28 Jun 2022 10:49:50 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27053139A; Tue, 28 Jun 2022 07:49:48 -0700 (PDT) Received: from fraeml745-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LXS9s3pcfz6H6pP; Tue, 28 Jun 2022 22:47:29 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml745-chm.china.huawei.com (10.206.15.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 28 Jun 2022 16:49:46 +0200 Received: from localhost (10.202.226.42) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 28 Jun 2022 15:49:46 +0100 Date: Tue, 28 Jun 2022 15:49:42 +0100 From: Jonathan Cameron To: CC: Dan Williams , Bjorn Helgaas , Lukas Wunner , Alison Schofield , Vishal Verma , "Dave Jiang" , Ben Widawsky , , , Subject: Re: [PATCH V12 7/9] cxl/port: Introduce cxl_cdat_valid() Message-ID: <20220628154942.00002064@Huawei.com> In-Reply-To: <20220628041527.742333-8-ira.weiny@intel.com> References: <20220628041527.742333-1-ira.weiny@intel.com> <20220628041527.742333-8-ira.weiny@intel.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.42] X-ClientProxiedBy: lhreml712-chm.china.huawei.com (10.201.108.63) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Jun 2022 21:15:25 -0700 ira.weiny@intel.com wrote: > From: Ira Weiny > > The CDAT data is protected by a checksum and should be the proper > length. > > Introduce cxl_cdat_valid() to validate the data. While at it check and > store the sequence number. > > Signed-off-by: Ira Weiny > Minor ordering comment. With that tidied up Reviewed-by: Jonathan Cameron > diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c > index 4bd479ec0253..6d775cc3dca1 100644 > --- a/drivers/cxl/core/pci.c > +++ b/drivers/cxl/core/pci.c > @@ -532,6 +532,40 @@ static int cxl_cdat_get_length(struct device *dev, > return rc; > } > > +static bool cxl_cdat_valid(struct device *dev, struct cxl_cdat *cdat) > +{ > + u32 *table = cdat->table; > + u8 *data8 = cdat->table; > + u32 length, seq; > + u8 check; > + int i; > + > + length = FIELD_GET(CDAT_HEADER_DW0_LENGTH, table[0]); > + if ((length < CDAT_HEADER_LENGTH_BYTES) || (length > cdat->length)) { > + dev_err(dev, "CDAT Invalid length %u (%zu-%zu)\n", length, > + CDAT_HEADER_LENGTH_BYTES, cdat->length); > + return false; > + } > + > + for (check = 0, i = 0; i < length; i++) > + check += data8[i]; > + > + dev_dbg(dev, "CDAT length %u CS %u\n", length, check); > + if (check != 0) { > + dev_err(dev, "CDAT Invalid checksum %u\n", check); > + return false; > + } > + > + seq = FIELD_GET(CDAT_HEADER_DW3_SEQUENCE, table[3]); > + /* Store the sequence for now. */ > + if (cdat->seq != seq) { > + dev_info(dev, "CDAT seq change %x -> %x\n", cdat->seq, seq); > + cdat->seq = seq; > + } > + > + return true; > +} > + > static int cxl_cdat_read_table(struct device *dev, > struct pci_doe_mb *cdat_mb, > struct cxl_cdat *cdat) > @@ -579,6 +613,8 @@ static int cxl_cdat_read_table(struct device *dev, > > } while (entry_handle != CXL_DOE_TABLE_ACCESS_LAST_ENTRY); > > + if (!rc && !cxl_cdat_valid(dev, cdat)) > + return -EIO; I'd prefer those handled separately as flow is more readable if error handling always out of line. if (rc) return rc; if (!cxl_cdata_valid) return -EIO; return 0; > return rc; > } >