From patchwork Sat Nov 18 01:14:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13459804 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aE3YjKoT" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E299D7E; Fri, 17 Nov 2023 17:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700270072; x=1731806072; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=oIqFPPpoTHQs4xq99OVhu029UoVsLXPhd+E7X5IVh3o=; b=aE3YjKoTg1kAnAN+Wu0A3MwZGNEC3vsOz9plqPuewJBqQoRVUWo3nstO Ghea1QWWvKXPWn0opJ/8Lq9t6Xto6VeHDHoXDaxG56tbehrgNzQZ2ca1V l9836SeljUrAy45FWMAA0eU7pjkhIFwitktv4Bhuy58E30IzIdxAuwA8P EVV6qTEGMKqrJJlvvkkYyoEND2rDc2Rlj7HiB6QHFbbw6237HpfXJ4jhp oz5Vu6LVQxvfOJNqgJ4+UZ2hwYT/YpXYBGzCRFufx85fW/1ZmjLKTTgxw XWkdk9PD5EvNm1npgI4lVdq2po7MNEUYwO08kmb3aSXSIvR/Ggh4iZWTn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10897"; a="390256193" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="390256193" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2023 17:14:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10897"; a="889406625" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="889406625" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.213.174.178]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2023 17:14:31 -0800 From: Ira Weiny Date: Fri, 17 Nov 2023 17:14:21 -0800 Subject: [PATCH 1/2] cxl/cdat: Handle cdat table build errors Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231117-fix-cdat-cs-v1-1-ffc2b116ca6c@intel.com> References: <20231117-fix-cdat-cs-v1-0-ffc2b116ca6c@intel.com> In-Reply-To: <20231117-fix-cdat-cs-v1-0-ffc2b116ca6c@intel.com> To: Jonathan Cameron , Fan Ni Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700270069; l=1101; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=oIqFPPpoTHQs4xq99OVhu029UoVsLXPhd+E7X5IVh3o=; b=xj+akvU9k2Rgms457NSCfkr8e0jOgcHBlBnyCxkkz1QCa6T/ronilXiJqoB2Bg2WF5XOsQqSI 7HC/IfMg0gZDxMje9fOiQnli/bq1qo65/b33yTZghL7FZz8GpAxeWV5 X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= The callback for building CDAT tables may return negative error codes. This was previously unhandled and will result in potentially huge allocations later on in ct3_build_cdat() Detect the negative error code and defer cdat building. Signed-off-by: Ira Weiny Reviewed-by: Dave Jiang --- This likely needs to have some more robust error handling in the event of errors. But this at least prevents more errors down the line with invalid allocations. --- hw/cxl/cxl-cdat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/cxl/cxl-cdat.c b/hw/cxl/cxl-cdat.c index 639a2db3e17b..24829cf2428d 100644 --- a/hw/cxl/cxl-cdat.c +++ b/hw/cxl/cxl-cdat.c @@ -63,7 +63,7 @@ static void ct3_build_cdat(CDATObject *cdat, Error **errp) cdat->built_buf_len = cdat->build_cdat_table(&cdat->built_buf, cdat->private); - if (!cdat->built_buf_len) { + if (cdat->built_buf_len <= 0) { /* Build later as not all data available yet */ cdat->to_update = true; return; From patchwork Sat Nov 18 01:14:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13459805 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gFzeXnYt" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FCC310C6; Fri, 17 Nov 2023 17:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700270073; x=1731806073; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=KY6Trv4Z4Ss7v75GlFvhDLJZq876VbvgUNG6vb3DWIM=; b=gFzeXnYtXbjujeTjB6gX5FivL0L7eIpuJZvHETJsDJeP7zA/40WyKDCV hndJP5ouy1wCCL20QRpv1cdkqU6vTGzrp1w15sExF0ehs6YURAvbdXGTE Sxvi8FTparggQCslUevKnOpOdLS+0Xlwd/tIg0qqd3x8u7MtLLWH/DNpI +wzfyX2Iv8Pfxk1dprR2nIKXO9gsvyIKDQPY3Zj7syqK0TgqFKY8DH4RF fH/mC5KmnfTkTdgfGdZ+eLeXm7COXKc5Qcw9WMJ7J4KwQ7/Entiv5d93K 1VfkECdcs1d9GkhOMXq/lA8kG3xrh5uGRfiuY8wXcueLXIUhI0YCMHwgI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10897"; a="390256200" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="390256200" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2023 17:14:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10897"; a="889406632" X-IronPort-AV: E=Sophos;i="6.04,206,1695711600"; d="scan'208";a="889406632" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.213.174.178]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2023 17:14:32 -0800 From: Ira Weiny Date: Fri, 17 Nov 2023 17:14:22 -0800 Subject: [PATCH 2/2] cxl/cdat: Fix header sum value in CDAT checksum Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231117-fix-cdat-cs-v1-2-ffc2b116ca6c@intel.com> References: <20231117-fix-cdat-cs-v1-0-ffc2b116ca6c@intel.com> In-Reply-To: <20231117-fix-cdat-cs-v1-0-ffc2b116ca6c@intel.com> To: Jonathan Cameron , Fan Ni Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny X-Mailer: b4 0.13-dev-c6835 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700270069; l=1439; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=KY6Trv4Z4Ss7v75GlFvhDLJZq876VbvgUNG6vb3DWIM=; b=jqARDpOM2gS8EEBlFN8o2CMOCfoDHYZeJn8FlrS/jOBezFk9NeTm3Ih2OGwCpc9eqw4o6Ot6H sFV4Ip8Qwq5DcoH5VG9rx9ZA6g71CcZmoBxyXb7bMpnPabn40NVNd1X X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= 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/ Signed-off-by: Ira Weiny --- hw/cxl/cxl-cdat.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/cxl/cxl-cdat.c b/hw/cxl/cxl-cdat.c index 24829cf2428d..d93e2e4e64f2 100644 --- a/hw/cxl/cxl-cdat.c +++ b/hw/cxl/cxl-cdat.c @@ -95,8 +95,15 @@ 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; + + do { + uint8_t *buf = (uint8_t *)cdat_header; + + for (i = 0; i < sizeof(*cdat_header); i++) { + sum += buf[i]; + } + } while (0); + /* Sum of all bytes including checksum must be 0 */ cdat_header->checksum = ~sum + 1;