lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBwA_CI5-eNll6Iz@aschofie-mobl2.lan>
Date: Wed, 7 May 2025 17:55:24 -0700
From: Alison Schofield <alison.schofield@...el.com>
To: <alejandro.lucero-palau@....com>
CC: <linux-cxl@...r.kernel.org>, <netdev@...r.kernel.org>,
	<dan.j.williams@...el.com>, <edward.cree@....com>, <davem@...emloft.net>,
	<kuba@...nel.org>, <pabeni@...hat.com>, <edumazet@...gle.com>,
	<dave.jiang@...el.com>, Alejandro Lucero <alucerop@....com>, Jonathan Cameron
	<Jonathan.Cameron@...wei.com>
Subject: Re: [PATCH v14 04/22] cxl: move register/capability check to driver

On Thu, Apr 17, 2025 at 10:29:07PM +0100, alejandro.lucero-palau@....com wrote:
> From: Alejandro Lucero <alucerop@....com>
> 
> Type3 has some mandatory capabilities which are optional for Type2.
> 
> In order to support same register/capability discovery code for both
> types, avoid any assumption about what capabilities should be there, and
> export the capabilities found for the caller doing the capabilities
> check based on the expected ones.
> 
> Add a function for facilitating the report of capabiities missing the
sp. capabilities

> expected ones.
> 
> Signed-off-by: Alejandro Lucero <alucerop@....com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
> ---
>  drivers/cxl/core/pci.c  | 35 +++++++++++++++++++++++++++++++++--
>  drivers/cxl/core/port.c |  8 ++++----
>  drivers/cxl/core/regs.c | 35 +++++++++++++++++++----------------
>  drivers/cxl/cxl.h       |  6 +++---
>  drivers/cxl/cxlpci.h    |  2 +-
>  drivers/cxl/pci.c       | 24 +++++++++++++++++++++---
>  include/cxl/cxl.h       | 24 ++++++++++++++++++++++++
>  7 files changed, 105 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
> index 0b8dc34b8300..ed18260ff1c9 100644
> --- a/drivers/cxl/core/pci.c
> +++ b/drivers/cxl/core/pci.c
> @@ -1061,7 +1061,7 @@ static int cxl_rcrb_get_comp_regs(struct pci_dev *pdev,
>  }
>  
>  int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
> -		       struct cxl_register_map *map)
> +		       struct cxl_register_map *map, unsigned long *caps)
>  {
>  	int rc;
>  
> @@ -1091,7 +1091,7 @@ int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
>  		return rc;
>  	}
>  
> -	return cxl_setup_regs(map);
> +	return cxl_setup_regs(map, caps);
>  }
>  EXPORT_SYMBOL_NS_GPL(cxl_pci_setup_regs, "CXL");
>  
> @@ -1214,3 +1214,34 @@ int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
>  
>  	return 0;
>  }
> +
> +int cxl_check_caps(struct pci_dev *pdev, unsigned long *expected,
> +		   unsigned long *found)
> +{
> +	DECLARE_BITMAP(missing, CXL_MAX_CAPS);
> +
> +	if (bitmap_subset(expected, found, CXL_MAX_CAPS))
> +		/* all good */
> +		return 0;
> +
> +	bitmap_andnot(missing, expected, found, CXL_MAX_CAPS);
> +
> +	if (test_bit(CXL_DEV_CAP_RAS, missing))
> +		dev_err(&pdev->dev, "RAS capability not found\n");
> +
> +	if (test_bit(CXL_DEV_CAP_HDM, missing))
> +		dev_err(&pdev->dev, "HDM decoder capability not found\n");
> +
> +	if (test_bit(CXL_DEV_CAP_DEV_STATUS, missing))
> +		dev_err(&pdev->dev, "Device Status capability not found\n");
> +
> +	if (test_bit(CXL_DEV_CAP_MAILBOX_PRIMARY, missing))
> +		dev_err(&pdev->dev, "Primary Mailbox capability not found\n");
> +
> +	if (test_bit(CXL_DEV_CAP_MEMDEV, missing))
> +		dev_err(&pdev->dev,
> +			"Memory Device Status capability not found\n");
> +
> +	return -1;
> +}

Prefer using an array to map the enums to strings, like -

	static const char * const cap_names[CXL_MAX_CAPS] = {
		[CXL_DEV_CAP_RAS]	= "CXL_DEV_CAP_RAS",
		.
		.
		.
	};

and then loop thru that, like: 

	for (int i = 0; i < CXL_MAX_CAPS; i++) {
		if (!test-bit(i, missing))
	 		dev_err(&pdev->dev,"%s capability not found\n",
	 	 		cap_names[i];
	}



snip
>  }
> diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c
> index be0ae9aca84a..e409ea06af0b 100644
> --- a/drivers/cxl/core/regs.c
> +++ b/drivers/cxl/core/regs.c
> @@ -4,6 +4,7 @@
>  #include <linux/device.h>
>  #include <linux/slab.h>
>  #include <linux/pci.h>
> +#include <cxl/cxl.h>
>  #include <cxl/pci.h>
>  #include <cxlmem.h>
>  #include <cxlpci.h>
> @@ -11,6 +12,9 @@
>  
>  #include "core.h"
>  
> +#define cxl_cap_set_bit(bit, caps) \
> +	do { if ((caps)) set_bit((bit), (caps)); } while (0)
> +

Prefer a readable and type safe simple fcn:

static void cxl_cap_set_bit(int bit, unsigned long *caps)
{
	if (caps)
		set_bit(bit, caps);
}


snip


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ