diff mbox series

[08/18] kernel/range: Uplevel the cxl subsystem's range_contains() helper

Message ID 167564539327.847146.788601375229324484.stgit@dwillia2-xfh.jf.intel.com
State Accepted
Commit 93c177fd6ff0655a5fa43ec945a57d7b0200ad80
Headers show
Series CXL RAM and the 'Soft Reserved' => 'System RAM' default | expand

Commit Message

Dan Williams Feb. 6, 2023, 1:03 a.m. UTC
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>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/cxl/core/pci.c |    5 -----
 include/linux/range.h  |    5 +++++
 lib/stackinit_kunit.c  |    6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

Comments

Gregory Price Feb. 6, 2023, 5:02 p.m. UTC | #1
On Sun, Feb 05, 2023 at 05:03:13PM -0800, Dan Williams wrote:
> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  drivers/cxl/core/pci.c |    5 -----
>  include/linux/range.h  |    5 +++++
>  lib/stackinit_kunit.c  |    6 +++---
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 

Only question is whether this should be upstreamed separate/ahead since
it's only tacitly related to the commit line, and the stackinit naming
seems overly-broad enough to cause issues.

Either way:


Reviewed-by: Gregory Price <gregory.price@memverge.com>
Ira Weiny Feb. 6, 2023, 7:28 p.m. UTC | #2
Dan Williams wrote:
> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Dan Williams Feb. 6, 2023, 10:01 p.m. UTC | #3
Gregory Price wrote:
> On Sun, Feb 05, 2023 at 05:03:13PM -0800, Dan Williams wrote:
> > 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>
> > Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> > ---
> >  drivers/cxl/core/pci.c |    5 -----
> >  include/linux/range.h  |    5 +++++
> >  lib/stackinit_kunit.c  |    6 +++---
> >  3 files changed, 8 insertions(+), 8 deletions(-)
> > 
> 
> Only question is whether this should be upstreamed separate/ahead since
> it's only tacitly related to the commit line, and the stackinit naming
> seems overly-broad enough to cause issues.

It's easier for me if it gets an ack and goes through the CXL tree.
Otherwise I need to delay the patch that introduces range_contains() as
a global symbol.
Dave Jiang Feb. 6, 2023, 11:41 p.m. UTC | #4
On 2/5/23 6:03 PM, Dan Williams wrote:
> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

I can use this in my QTG series for DPA matching.
> ---
>   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",	\
>
Jonathan Cameron Feb. 8, 2023, 12:32 p.m. UTC | #5
On Sun, 05 Feb 2023 17:03:13 -0800
Dan Williams <dan.j.williams@intel.com> wrote:

> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Seems reasonable.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  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",	\
>
Verma, Vishal L Feb. 9, 2023, 7:47 p.m. UTC | #6
On Sun, 2023-02-05 at 17:03 -0800, Dan Williams wrote:
> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  drivers/cxl/core/pci.c |    5 -----
>  include/linux/range.h  |    5 +++++
>  lib/stackinit_kunit.c  |    6 +++---
>  3 files changed, 8 insertions(+), 8 deletions(-)

Looks good,

Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

> 
> 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",       \
> 
>
diff mbox series

Patch

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",	\