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] [day] [month] [year] [list]
Message-ID: <701cbcb6-136c-457d-9b1d-8ae9581a3182@fujitsu.com>
Date: Wed, 28 Jan 2026 01:18:45 +0000
From: "Zhijian Li (Fujitsu)" <lizhijian@...itsu.com>
To: "Pawel Mielimonka (Fujitsu)" <pawel.mielimonka@...itsu.com>,
	"dan.j.williams@...el.com" <dan.j.williams@...el.com>,
	"alison.schofield@...el.com" <alison.schofield@...el.com>
CC: "Smita.KoralahalliChannabasappa@....com"
	<Smita.KoralahalliChannabasappa@....com>, "linux-cxl@...r.kernel.org"
	<linux-cxl@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "dave@...olabs.net" <dave@...olabs.net>,
	"jonathan.cameron@...wei.com" <jonathan.cameron@...wei.com>,
	"dave.jiang@...el.com" <dave.jiang@...el.com>, "vishal.l.verma@...el.com"
	<vishal.l.verma@...el.com>, "ira.weiny@...el.com" <ira.weiny@...el.com>
Subject: Re: [PATCH v3 1/1] cxl/cli: enforce HPA-descending teardown order for
 destroy-region

Hi Pawel,


On 26/01/2026 22:14, Pawel Mielimonka wrote:
> Note: This revision collapses the previous 2-patch series into a single
> patch.
> 

The commit log for the patch itself is missing the detailed description. Please note
that generally the cover letter (patch 0/1) will not appear in the final git log,
so the problem description, your proposed solution, and other details
should be included here.


Additionally, for future submissions, please use the "ndctl PATCH" prefix in
the subject line, as per our contribution guidelines. You can find more details here:

https://github.com/pmem/ndctl/blob/main/CONTRIBUTING.md


Thanks
Zhijian


> Signed-off-by: Pawel Mielimonka <pawel.mielimonka@...itsu.com>
> ---
>   cxl/region.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 113 insertions(+), 3 deletions(-)
> 
> diff --git a/cxl/region.c b/cxl/region.c
> index 207cf2d..5ab9f4e 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -831,6 +831,60 @@ out:
>   	return cxl_region_disable(region);
>   }
>   
> +static int cmp_region_hpa(const void *l, const void *r)
> +{
> +	const struct cxl_region *const *left = l;
> +	const struct cxl_region *const *right = r;
> +	u64 hpa1 = cxl_region_get_resource((struct cxl_region *) *left);
> +	u64 hpa2 = cxl_region_get_resource((struct cxl_region *) *right);
> +
> +	return (hpa1 > hpa2) - (hpa1 < hpa2);
> +}
> +
> +static int collect_regions_sorted(struct cxl_decoder *root,
> +	struct cxl_region ***out,
> +	int *out_nr)
> +{
> +	struct cxl_region *region;
> +	struct cxl_region **list = NULL;
> +	int nr = 0, alloc = 0;
> +
> +		struct cxl_port *port = cxl_decoder_get_port(root);
> +		struct cxl_decoder *decoder;
> +
> +		cxl_decoder_foreach(port, decoder) {
> +			if (!cxl_port_is_root(port))
> +				continue;
> +			cxl_region_foreach(decoder, region) {
> +				if (nr == alloc) {
> +					int new_alloc = alloc ? alloc * 2 : 8;
> +					size_t new_size = (size_t)new_alloc * sizeof(*list);
> +					struct cxl_region **tmp;
> +
> +					tmp = realloc(list, new_size);
> +					if (!tmp) {
> +						free(list);
> +						return -ENOMEM;
> +					}
> +					list = tmp;
> +					alloc = new_alloc;
> +				}
> +				list[nr++] = region;
> +			}
> +
> +			if (!nr) {
> +				free(list);
> +				*out = NULL;
> +				*out_nr = 0;
> +				return 0;
> +		}
> +	}
> +	qsort(list, nr, sizeof(*list), cmp_region_hpa);
> +	*out = list;
> +	*out_nr = nr;
> +	return 0;
> +}
> +
>   static int destroy_region(struct cxl_region *region)
>   {
>   	const char *devname = cxl_region_get_devname(region);
> @@ -895,6 +949,59 @@ static int destroy_region(struct cxl_region *region)
>   	return cxl_region_delete(region);
>   }
>   
> +static int destroy_multiple_regions(
> +	struct parsed_params *p,
> +	struct cxl_decoder *decoder,
> +	int *count)
> +{
> +	struct cxl_region **list;
> +	int nr, rc, i;
> +	bool skipped = false;
> +
> +	rc = collect_regions_sorted(decoder, &list, &nr);
> +	if (rc) {
> +		log_err(&rl, "failed to allocate region list: %s\n", strerror(-rc));
> +		return rc;
> +	}
> +
> +	for (i = nr - 1; i >= 0; --i) {
> +		struct cxl_region *region = NULL;
> +
> +		for (int j = 0; j < p->argc; j++) {
> +			region = util_cxl_region_filter(list[i], p->argv[j]);
> +			if (region)
> +				break;
> +		}
> +
> +		if (!region) {
> +			skipped = true;
> +			continue;
> +		}
> +
> +		/*
> +		 * If current region matches filter, but previous didn't, destroying would
> +		 * result in breaking HPA continuity
> +		 */
> +		if (skipped) {
> +			log_err(&rl, "failed to destroy %s: out of order %s reset\n",
> +				cxl_region_get_devname(region),
> +				cxl_decoder_get_devname(decoder));
> +			rc = -EINVAL;
> +			break;
> +		}
> +
> +		rc = destroy_region(region);
> +		if (rc) {
> +			log_err(&rl, "%s: failed: %s\n",
> +				cxl_region_get_devname(region), strerror(-rc));
> +			break;
> +		}
> +		++(*count);
> +	}
> +	free(list);
> +	return rc;
> +}
> +
>   static int do_region_xable(struct cxl_region *region, enum region_actions action)
>   {
>   	switch (action) {
> @@ -902,8 +1009,6 @@ static int do_region_xable(struct cxl_region *region, enum region_actions action
>   		return cxl_region_enable(region);
>   	case ACTION_DISABLE:
>   		return disable_region(region);
> -	case ACTION_DESTROY:
> -		return destroy_region(region);
>   	default:
>   		return -EINVAL;
>   	}
> @@ -971,7 +1076,12 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,
>   			if (!util_cxl_decoder_filter(decoder,
>   						     param.root_decoder))
>   				continue;
> -			rc = decoder_region_action(p, decoder, action, count);
> +
> +			if (action == ACTION_DESTROY)
> +				rc = destroy_multiple_regions(p, decoder, count);
> +			else
> +				rc = decoder_region_action(p, decoder, action, count);
> +
>   			if (rc)
>   				err_rc = rc;
>   		}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ