All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: dan.j.williams@intel.com, jonathan.cameron@huawei.com,
	ira.weiny@intel.com, fan.ni@samsung.com,
	a.manzanares@samsung.com, linux-cxl@vger.kernel.org
Subject: Re: [PATCH 3/7] cxl/region: Add cxl_memdev_active_region()
Date: Sun, 26 Feb 2023 19:46:43 -0800	[thread overview]
Message-ID: <Y/wno8C4bK3XNoUD@aschofie-mobl2> (raw)
In-Reply-To: <20230224194652.1990604-4-dave@stgolabs.net>

On Fri, Feb 24, 2023 at 11:46:48AM -0800, Davidlohr Bueso wrote:
> Track all regions associated to a memdev in order to
> tell if the device might be in active use.

Hi David,

I took a look here as I've been poked around in this space when looking
for 'region' names to associate with memdev poison trace events. [1]

How does the list created get used?

If we only need to know that this memdev is mapped in any region,
so don't touch it, we can look at it's port->commit_end. If that
commit_end >= 0, we can look at each endpoint to find the regions
it's mapped to.

Not sure if any of that is useful for what you need to do, but
it sounded familiar.

[1] https://lore.kernel.org/linux-cxl/62d24b380514c8c39b651aca79c81a424f0b5b37.1676685180.git.alison.schofield@intel.com/

Alison

> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
> ---
>  drivers/cxl/core/memdev.c |  1 +
>  drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++--
>  drivers/cxl/cxl.h         |  6 ++++++
>  drivers/cxl/cxlmem.h      |  4 ++++
>  4 files changed, 42 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index 47cc625bb1b0..68c0ab06b999 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -306,6 +306,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
>  	dev->type = &cxl_memdev_type;
>  	device_set_pm_not_required(dev);
>  	INIT_WORK(&cxlmd->detach_work, detach_memdev);
> +	INIT_LIST_HEAD(&cxlmd->region_list);
>  
>  	cdev = &cxlmd->cdev;
>  	cdev_init(cdev, fops);
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index f29028148806..cea9de6457b9 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1730,7 +1730,10 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled)
>  {
>  	down_write(&cxl_region_rwsem);
>  	cxled->mode = CXL_DECODER_DEAD;
> -	cxl_region_detach(cxled);
> +	if (!cxl_region_detach(cxled)) {
> +		struct cxl_region *cxlr = cxled->cxld.region;
> +		list_del(&cxlr->node);
> +	}
>  	up_write(&cxl_region_rwsem);
>  }
>  
> @@ -1749,8 +1752,12 @@ static int attach_target(struct cxl_region *cxlr,
>  
>  	down_read(&cxl_dpa_rwsem);
>  	rc = cxl_region_attach(cxlr, cxled, pos);
> -	if (rc == 0)
> +	if (rc == 0) {
> +		struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> +
>  		set_bit(CXL_REGION_F_INCOHERENT, &cxlr->flags);
> +		list_add_tail(&cxlr->node, &cxlmd->region_list);
> +	}
>  	up_read(&cxl_dpa_rwsem);
>  	up_write(&cxl_region_rwsem);
>  	return rc;
> @@ -1778,6 +1785,8 @@ static int detach_target(struct cxl_region *cxlr, int pos)
>  	}
>  
>  	rc = cxl_region_detach(p->targets[pos]);
> +	if (rc == 0)
> +		list_del(&cxlr->node);
>  out:
>  	up_write(&cxl_region_rwsem);
>  	return rc;
> @@ -2654,6 +2663,26 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
>  }
>  EXPORT_SYMBOL_NS_GPL(cxl_add_to_region, CXL);
>  
> +bool cxl_memdev_active_region(struct cxl_memdev *cxlmd)
> +{
> +	bool ret = false;
> +	struct cxl_region *cxlr;
> +
> +	down_read(&cxl_region_rwsem);
> +	list_for_each_entry(cxlr, &cxlmd->region_list, node) {
> +		struct cxl_region_params *p = &cxlr->params;
> +
> +		if (p->state >= CXL_CONFIG_ACTIVE) {
> +			ret = true;
> +			break;
> +		}
> +	}
> +	up_read(&cxl_region_rwsem);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_memdev_active_region, CXL);
> +
>  static int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
>  {
>  	if (!test_bit(CXL_REGION_F_INCOHERENT, &cxlr->flags))
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index b834e55375e3..e211241b079b 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -502,6 +502,7 @@ struct cxl_region {
>  	struct cxl_pmem_region *cxlr_pmem;
>  	unsigned long flags;
>  	struct cxl_region_params params;
> +	struct list_head node;
>  };
>  
>  struct cxl_nvdimm_bridge {
> @@ -773,6 +774,7 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev);
>  int cxl_add_to_region(struct cxl_port *root,
>  		      struct cxl_endpoint_decoder *cxled);
>  struct cxl_dax_region *to_cxl_dax_region(struct device *dev);
> +bool cxl_memdev_active_region(struct cxl_memdev *cxlmd);
>  #else
>  static inline bool is_cxl_pmem_region(struct device *dev)
>  {
> @@ -791,6 +793,10 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev)
>  {
>  	return NULL;
>  }
> +static inline bool cxl_memdev_active_region(struct cxl_memdev *cxlmd)
> +{
> +	return false;
> +}
>  #endif
>  
>  /*
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 934076254d52..4e31f3234519 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -5,6 +5,7 @@
>  #include <uapi/linux/cxl_mem.h>
>  #include <linux/cdev.h>
>  #include <linux/uuid.h>
> +#include <linux/list.h>
>  #include "cxl.h"
>  
>  /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
> @@ -40,6 +41,8 @@
>   * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
>   * @id: id number of this memdev instance.
>   * @depth: endpoint port depth
> + * @region_list: List of regions that have as target the endpoint
> + *               decoder associated with this memdev
>   */
>  struct cxl_memdev {
>  	struct device dev;
> @@ -50,6 +53,7 @@ struct cxl_memdev {
>  	struct cxl_nvdimm *cxl_nvd;
>  	int id;
>  	int depth;
> +	struct list_head region_list;
>  };
>  
>  static inline struct cxl_memdev *to_cxl_memdev(struct device *dev)
> -- 
> 2.39.2
> 

  reply	other threads:[~2023-02-27  3:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 19:46 [PATCH v3 0/7] cxl: Background cmds and device sanitation Davidlohr Bueso
2023-02-24 19:25 ` Davidlohr Bueso
2023-02-24 19:46 ` [PATCH 1/7] cxl/mbox: Add background cmd handling machinery Davidlohr Bueso
2023-02-28 16:27   ` Dave Jiang
2023-02-28 20:18     ` Davidlohr Bueso
2023-02-28 23:35       ` Dave Jiang
2023-03-27 21:57   ` Dan Williams
2023-02-24 19:46 ` [PATCH 2/7] cxl/security: Add security state sysfs ABI Davidlohr Bueso
2023-02-28 16:47   ` Dave Jiang
2023-03-28  1:11   ` Dan Williams
2023-02-24 19:46 ` [PATCH 3/7] cxl/region: Add cxl_memdev_active_region() Davidlohr Bueso
2023-02-27  3:46   ` Alison Schofield [this message]
2023-02-28 20:26     ` Davidlohr Bueso
2023-02-28 23:20       ` Fan Ni
2023-03-28  1:15       ` Dan Williams
2023-02-24 19:46 ` [PATCH 4/7] cxl/mem: Support Sanitation Davidlohr Bueso
2023-02-28 17:28   ` Dave Jiang
2023-02-28 20:22     ` Davidlohr Bueso
2023-03-28  6:26   ` Dan Williams
2023-04-05 21:06     ` Davidlohr Bueso
2023-04-05 22:24       ` Dan Williams
2023-02-24 19:46 ` [PATCH 5/7] cxl/test: Add "Sanitize" opcode support Davidlohr Bueso
2023-02-28 18:03   ` Dave Jiang
2023-02-24 19:46 ` [PATCH 6/7] cxl/mem: Support Secure Erase Davidlohr Bueso
2023-02-28 18:31   ` Dave Jiang
2023-02-24 19:46 ` [PATCH 7/7] cxl/test: Add "Secure Erase" opcode support Davidlohr Bueso
2023-02-28 18:36   ` Dave Jiang
2023-03-22  0:05 ` [PATCH v3 0/7] cxl: Background cmds and device sanitation Davidlohr Bueso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y/wno8C4bK3XNoUD@aschofie-mobl2 \
    --to=alison.schofield@intel.com \
    --cc=a.manzanares@samsung.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave@stgolabs.net \
    --cc=fan.ni@samsung.com \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.