kernel/range: Uplevel the cxl subsystem's range_contains() helper
authorDan Williams <dan.j.williams@intel.com>
Fri, 10 Feb 2023 09:06:21 +0000 (01:06 -0800)
committerDan Williams <dan.j.williams@intel.com>
Sat, 11 Feb 2023 01:32:37 +0000 (17:32 -0800)
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 <keescook@chromium.org>
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
Link: https://lore.kernel.org/r/167601998163.1924368.6067392174077323935.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/core/pci.c
include/linux/range.h
lib/stackinit_kunit.c

index 1d1492440287c9762829d3a603d35663a42c1e81..9ed2120dbf8ad22277e44dc924fd60420b05f78b 100644 (file)
@@ -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)
 {
index 274681cc3154809cad3d5c715bca693a608a8b9c..7efb6a9b069b3d50e79e8a3f7ac70ba4129e81e1 100644 (file)
@@ -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);
 
index 4591d6cf5e01800aa14e980c231695b6682f0b91..05947a2feb93c0fe41441c5252eb3b0d67fad9fd 100644 (file)
@@ -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",       \