From patchwork Fri Feb 10 09:06:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13135557 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 532F5C636CD for ; Fri, 10 Feb 2023 09:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E78D66B0125; Fri, 10 Feb 2023 04:06:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E031C6B0127; Fri, 10 Feb 2023 04:06:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC9AE6B0128; Fri, 10 Feb 2023 04:06:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9C8606B0125 for ; Fri, 10 Feb 2023 04:06:25 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D48941526 for ; Fri, 10 Feb 2023 09:06:25 +0000 (UTC) X-FDA: 80450801130.20.3F1320A Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf24.hostedemail.com (Postfix) with ESMTP id 14EFD180002 for ; Fri, 10 Feb 2023 09:06:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="DOw/R0nU"; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676019983; 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=R9IdUqZqUxZIFEXVIPczGCz0YkXfxkHqRn8UN4DeZdo=; b=2Lea1+hr12enuoEnBgjoQJ5O/YHwBrg+cxmI7LSeoHf7g2zRLHewMNEtNI/Br1MTNiIUUo Nq6wt6Kc8bEeUR9Hpc/bdNIrZL1RtAqgbi9q2GiG4AtlIBYifWEGDEO/xXt/FC9XJhmyiI qFwsTpUqz+hphHKqc2xYOG+NfKmUYs0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="DOw/R0nU"; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676019983; a=rsa-sha256; cv=none; b=nJYmLCUAwClGxHWJrN3DPaZF/xMOuu6CE6grIlF04GUR3hAyr9/4tHo2znN+5n1M89pelu B0ILOPqWiwl0e8zmHtw1eewuJ44U3J4y+1E8msOu48N/cisUk2zkdo0EmPVuQ2BTARr+7o gGCR1k3OxEbODlgB1KUeQQdKjoiptu0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676019983; x=1707555983; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8q/1cNxswZmepEnA6xfwY56HjCTVePeFSsIba+FKR6Y=; b=DOw/R0nUF9DorjxeXGLtVECIWcqagkUPm/VDTElnT0j///4Vh2r+3vRd wINVuTpqXuKiqd6fRHkvjCn2SokTUcTO2Sy6MfNVy2u4gtaBD1i8mEXfi tCcI/HI1PalcIy5Hg8Ck1ofUFSABTchhU2Upi9gdPvq9U1gDu6nBpIdRN 4omGyeSScUtw511ZtgmatCzf+jI0DRt6Jyc6hcDITuD+4UyKa95XXJhKo qqGT9/J+s4q+Ak0JIuqtX0u6MHwLX2IQcgUVxcQv0vVxGr8gSQFSnGSIP 8ure2TMjxiJcD4R0471t2yDS/Pm9MswXmWIZgmd5b5pIR/z2XCVSCK3xa A==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="329003052" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="329003052" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:22 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="913463813" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="913463813" Received: from hrchavan-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.46.42]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:22 -0800 Subject: [PATCH v2 10/20] kernel/range: Uplevel the cxl subsystem's range_contains() helper From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Kees Cook , Vishal Verma , Jonathan Cameron , Dave Jiang , Gregory Price , Ira Weiny , Fan Ni , dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-acpi@vger.kernel.org Date: Fri, 10 Feb 2023 01:06:21 -0800 Message-ID: <167601998163.1924368.6067392174077323935.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> References: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspamd-Queue-Id: 14EFD180002 X-Stat-Signature: fssqjshhcdpkedenf9ns6kkg5e46eb3z X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 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ge06+HbLSjuQIQxY3Cs3MAWEO5fsrUc4M9IYkBhDjs/4/Q55WWfCHL0B5tDYBWXBhQZ2Ui5/Z6gfuXuk0invSVQbaeXAzM7/oXrbVptDY89dEaHbnZNgbEPBgFT8Ks6sN/GSrhQMaVhbUw+Nk1LA8jmADj1KKfGwCuaKKHmFZ+AfJK2SMP7VI5PDm8NKwP0LxIRDTzmlICeYng2zC11j+8L1AjzMki9CzjvMFNiN0r9ecN3kDk0W8X8M058omPJxPIauaqmsq649FoBFVYHkOH+bs+XXLVg5sRMVX7VhzN4lt4JDcJOC0oJ5IY57ovigm0+S/bij2UBO3DeDsrjOlOrnbQFC0SRxiWpRCGkJ+wlUuoAhdhI6NqSn4uXJTTiwU= 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 Reviewed-by: Vishal Verma Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Reviewed-by: Gregory Price Reviewed-by: Ira Weiny Tested-by: Fan Ni Link: https://lore.kernel.org/r/167564539327.847146.788601375229324484.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams --- 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", \