Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2760rdb; Wed, 29 Nov 2023 17:33:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj7FIdA5PRSTjptT+qfFlYvopyGADtNFXsauxSELbAzYBG/G89qX7EhbUEv/RkMKXSRx9I X-Received: by 2002:a05:6a00:1496:b0:6cb:4d36:5d07 with SMTP id v22-20020a056a00149600b006cb4d365d07mr19809908pfu.10.1701307998404; Wed, 29 Nov 2023 17:33:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701307998; cv=none; d=google.com; s=arc-20160816; b=z3g0OtPe8mlaxFR8a5C1NxGXRdyzqhHmMXbp2/lSa9eiMOqhGEvVkWhaSKRnVnHDwi v1Ru3FO9W4SCFC8BQjaMlWpFbZC4sS3LJ4JRvQUV9l3OZ4D4k0G7ZuTyRIDbJi9kEm3N XRcyJe2UNclptc3GNQUVB4CQ5sFvFtLNvCikMUt4Xp7Ly7ZRoEygtb2my8ql9uNL7+P4 jtTes3iqL8D4tcQd2tcgq734EqGjQdjBHs0d51CIpIXUCpJF/WQ1fwAE9Hgt/EQPBRlr 73qWmxuH6NYemKzEMaNVmftHYixJ8yZTf5sDPDHPXpHVgVeQ6BV5gMTHMfACaCfU+H8E JJTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=/hCquaQm0D7Abv30MkV0mf5sTm+ffVk07U/CHRoWEq0=; fh=GZbsnpAEnp+pJCwMMV4zhLpa3Ei2NcTeFazlN5YjFhY=; b=tYdETmB3gciEfNo//uz9OoLjZ7uIi27byGko/Gkvm7KjtcayVy2rdzB3feoLS7I9o0 8HgNphhihRkKQjPJFDU8SmcyxHF7G9/bcq62/36ZKHu44C4n4oVmISMJRdNdDituGiqj atcPkyDMiBWxp1p3TukPO7hB/9fcZrkIZoEXxcMNwwgFT4C8ECvGnoOpcqyxKEzcW4sY /JN0YQMcmg6p2Sy9OzTtJ0rN+NKmID0Dphbn09vvHY9M5DZeMbOwqz3EojpJdWnU8Vkm 0Jp6ofyriHkxqqUDzzq8indBoOy5nGAnUEQi3z2rxfaIKKe3GH7zNr0SkrtadpFoWOW+ VZcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ljP6y29Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b12-20020a056a000ccc00b006cd82b4d0c4si92277pfv.89.2023.11.29.17.33.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 17:33:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ljP6y29Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 415DB805800A; Wed, 29 Nov 2023 17:33:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344014AbjK3BdC (ORCPT + 99 others); Wed, 29 Nov 2023 20:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjK3BdA (ORCPT ); Wed, 29 Nov 2023 20:33:00 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49D8810C9; Wed, 29 Nov 2023 17:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701307987; x=1732843987; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=biVFyY2ZTRVvjAGgkWkvryJWLterO+Gec8l2ksefpWo=; b=ljP6y29ZjVVjuSSKA9MqbfXcK5nxCI+PUk26ZDpIBb/Gt/vKPE3hz0N2 Fx12GonHAhjyoKEgo/PaJM901quIRsGRXNsZAkD6+lM/6/5IMqMYyjQ0U +0cwjQj7egt9Tj2ZmnKf9pdzZlql73lhudowySkxGLX4VWbB5YErp3BwA 9u2sVnvhimUaf+7ZDnbIZHazaIhoGlDzjPvRFbn71Z2X5GDUhc7WHT+/3 Y9pNYF2hoxvrC7YxTpPcYTJDPDxoXr8/uK4rpaJRJ4wsFiQptjCsIU6WD v6huLyRUWW1XmhWDYDXjK+xw/c/0o93qrkKQThfRn4F99floihpran9sE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="131554" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="131554" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 17:33:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="1016467458" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="1016467458" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.213.173.40]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 17:33:05 -0800 From: Ira Weiny Date: Wed, 29 Nov 2023 17:33:04 -0800 Subject: [PATCH v2 2/2] cxl/cdat: Fix header sum value in CDAT checksum MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231117-fix-cdat-cs-v2-2-715399976d4d@intel.com> References: <20231117-fix-cdat-cs-v2-0-715399976d4d@intel.com> In-Reply-To: <20231117-fix-cdat-cs-v2-0-715399976d4d@intel.com> To: Jonathan Cameron , Fan Ni Cc: Dave Jiang , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny , Huai-Cheng Kuo X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701307983; l=1857; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=biVFyY2ZTRVvjAGgkWkvryJWLterO+Gec8l2ksefpWo=; b=/VUqKgmQlOysVLm7W9CszCTDQGTWnKoKE2hLzoFNsDwL6Ui9sFi8wmrQKCuaP/Zzmgw28CCvv X5foAbf+1CgD9LRkoGboAgxq43glhLTWP9LZBr0bI6cd6qxPS+2TPcd X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 17:33:17 -0800 (PST) The addition of the DCD support for CXL type-3 devices extended the CDAT table large enough that the checksum being returned was incorrect.[1] This was because the checksum value was using the header length field rather than each of the 4 bytes of the length field. This was previously not seen because the length of the CDAT data was less than 256 thus resulting in an equivalent checksum value. Properly calculate the checksum for the CDAT header. [1] https://lore.kernel.org/all/20231116-fix-cdat-devm-free-v1-1-b148b40707d7@intel.com/ Fixes: aba578bdace5 ("hw/cxl/cdat: CXL CDAT Data Object Exchange implementation") Cc: Huai-Cheng Kuo Signed-off-by: Ira Weiny --- Changes from V1: [djiang: Remove do {} while (0);] --- hw/cxl/cxl-cdat.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/cxl/cxl-cdat.c b/hw/cxl/cxl-cdat.c index 24829cf2428d..67e44a4f992a 100644 --- a/hw/cxl/cxl-cdat.c +++ b/hw/cxl/cxl-cdat.c @@ -49,6 +49,7 @@ static void ct3_build_cdat(CDATObject *cdat, Error **errp) g_autofree CDATTableHeader *cdat_header = NULL; g_autofree CDATEntry *cdat_st = NULL; uint8_t sum = 0; + uint8_t *buf; int ent, i; /* Use default table if fopen == NULL */ @@ -95,8 +96,12 @@ static void ct3_build_cdat(CDATObject *cdat, Error **errp) /* For now, no runtime updates */ cdat_header->sequence = 0; cdat_header->length += sizeof(CDATTableHeader); - sum += cdat_header->revision + cdat_header->sequence + - cdat_header->length; + + buf = (uint8_t *)cdat_header; + for (i = 0; i < sizeof(*cdat_header); i++) { + sum += buf[i]; + } + /* Sum of all bytes including checksum must be 0 */ cdat_header->checksum = ~sum + 1; -- 2.42.0