From patchwork Mon Feb 6 01:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13129233 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46560C636CD for ; Mon, 6 Feb 2023 01:03:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E234B6B007D; Sun, 5 Feb 2023 20:03:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD3006B0080; Sun, 5 Feb 2023 20:03:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9B7F6B0081; Sun, 5 Feb 2023 20:03:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BD1276B007D for ; Sun, 5 Feb 2023 20:03:25 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 84423160927 for ; Mon, 6 Feb 2023 01:03:25 +0000 (UTC) X-FDA: 80435068770.29.C1F62E1 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf02.hostedemail.com (Postfix) with ESMTP id 7B1338000D for ; Mon, 6 Feb 2023 01:03:23 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QNceDMpx; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675645403; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DyqHyyZT2lU9emCKE6Q5ouwqYz48kTemZ1q+V82QNnw=; b=hL6F9Xotcw3Z8U7IS/NZyFfX6ODp/MP5FmPNPffiwgAvhZFjwoleePKWsnn94A7qW5vhgl OllWw+AP5WFTRC5v3Bbl989vxVGBPfu+vVDyaexZ82hkXTqFZQY0jBVHo1gUUTNLV2rjhs mkAIWaLjA1L09mxiVxZ4tuK0KGG93u8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QNceDMpx; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf02.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675645403; a=rsa-sha256; cv=none; b=6XvBcj6GiAFhA+3hQVh0tlgVFCvfAFW6LPHLjuvvd68FZN1s1vDyjrD3I0tI2avZRg+7p3 q967TWsUorExj9n/OO/YKILGwJRXTfVWVLU0+7xvhX3+LZA0BbqPgsVst/goun8CTfD2NR XNArWrDOkUCOElcB3pThelZqvrpW2vM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675645403; x=1707181403; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AeIQeRHiJX+pQkHKAuoYi54yr8qg0sN4RL762t1p8Jc=; b=QNceDMpxKiEMBZ+4me7vlQjZkeOPixd9VRv31S72dgMKE2lFbuzQwe5B mdJnzXE5dh+jdKkElO0PoTDbKX6aUOmHYQAvIF1u28CRD76cwNLl+Qykd xIEFFXxSaRMSpl0fZBnlsAUq9HDKqIgWRUYdZIIzFc0UDaOp8IDCOjg2v o1zMxWweCY9SJWDQaBJQ5MsVW4G3bE3yazj4TwfiyZIhdR2W6R5Co3yub SvURQVuDs3XaAlDDem0LiX7KI5J6cf90KgbOtKrBM+g2x1TQ2TIGkPwH8 xM/MClSaN4sEzifokUN2kIHuxlKItnqg0qMPEbhdIf+j6Q6M8gap5UxXi A==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="312763199" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="312763199" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 17:03:13 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="616291316" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="616291316" Received: from mkrysak-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.212.255.187]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2023 17:03:13 -0800 Subject: [PATCH 08/18] kernel/range: Uplevel the cxl subsystem's range_contains() helper From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Kees Cook , dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-acpi@vger.kernel.org Date: Sun, 05 Feb 2023 17:03:13 -0800 Message-ID: <167564539327.847146.788601375229324484.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <167564534874.847146.5222419648551436750.stgit@dwillia2-xfh.jf.intel.com> References: <167564534874.847146.5222419648551436750.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspamd-Queue-Id: 7B1338000D X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: eeb567nyu7gfzgu48p1cwyo1yykq4xm9 X-HE-Tag: 1675645403-150389 X-HE-Meta: U2FsdGVkX18LpE7nptaiUo+FlshJjgzDkMesDlXoMGP5WhRqVSGqiHBuBG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dGWgsYRHq2JmwsViX5isC3PmcKSZyXZ/1DRgkCyiC5RFxKv9INwXCKVhdEQ4IBIEJXXj//aKUDg9wb/g/5nyW1S5b5c1t2GzBLLNWoJV64R1fZLf7CvHNkXzqhY0/ld9Rd/LF2TPmQ5cUiJP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In support of the CXL subsystem's use of 'struct range' to track decode address ranges, add a common range_contains() implementation with identical semantics as resource_contains(); The existing 'range_contains()' in lib/stackinit_kunit.c is namespaced with a 'stackinit_' prefix. Cc: Kees Cook Signed-off-by: Dan Williams Reviewed-by: Gregory Price Reviewed-by: Ira Weiny Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Reviewed-by: Vishal Verma --- drivers/cxl/core/pci.c | 5 ----- include/linux/range.h | 5 +++++ lib/stackinit_kunit.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 1d1492440287..9ed2120dbf8a 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -214,11 +214,6 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds) return devm_add_action_or_reset(host, clear_mem_enable, cxlds); } -static bool range_contains(struct range *r1, struct range *r2) -{ - return r1->start <= r2->start && r1->end >= r2->end; -} - /* require dvsec ranges to be covered by a locked platform window */ static int dvsec_range_allowed(struct device *dev, void *arg) { diff --git a/include/linux/range.h b/include/linux/range.h index 274681cc3154..7efb6a9b069b 100644 --- a/include/linux/range.h +++ b/include/linux/range.h @@ -13,6 +13,11 @@ static inline u64 range_len(const struct range *range) return range->end - range->start + 1; } +static inline bool range_contains(struct range *r1, struct range *r2) +{ + return r1->start <= r2->start && r1->end >= r2->end; +} + int add_range(struct range *range, int az, int nr_range, u64 start, u64 end); diff --git a/lib/stackinit_kunit.c b/lib/stackinit_kunit.c index 4591d6cf5e01..05947a2feb93 100644 --- a/lib/stackinit_kunit.c +++ b/lib/stackinit_kunit.c @@ -31,8 +31,8 @@ static volatile u8 forced_mask = 0xff; static void *fill_start, *target_start; static size_t fill_size, target_size; -static bool range_contains(char *haystack_start, size_t haystack_size, - char *needle_start, size_t needle_size) +static bool stackinit_range_contains(char *haystack_start, size_t haystack_size, + char *needle_start, size_t needle_size) { if (needle_start >= haystack_start && needle_start + needle_size <= haystack_start + haystack_size) @@ -175,7 +175,7 @@ static noinline void test_ ## name (struct kunit *test) \ \ /* Validate that compiler lined up fill and target. */ \ KUNIT_ASSERT_TRUE_MSG(test, \ - range_contains(fill_start, fill_size, \ + stackinit_range_contains(fill_start, fill_size, \ target_start, target_size), \ "stack fill missed target!? " \ "(fill %zu wide, target offset by %d)\n", \