Patch "cxl/region: Recycle region ids" has been added to the 6.0-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    cxl/region: Recycle region ids

to the 6.0-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     cxl-region-recycle-region-ids.patch
and it can be found in the queue-6.0 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 20ea2397d389b510ccc3c5166a66c5d7601711b5
Author: Dan Williams <dan.j.williams@xxxxxxxxx>
Date:   Thu Nov 3 17:31:00 2022 -0700

    cxl/region: Recycle region ids
    
    [ Upstream commit 8f401ec1c8975eabfe4c089de91cbe058deabf71 ]
    
    At region creation time the next region-id is atomically cached so that
    there is predictability of region device names. If that region is
    destroyed and then a new one is created the region id increments. That
    ends up looking like a memory leak, or is otherwise surprising that
    identifiers roll forward even after destroying all previously created
    regions.
    
    Try to reuse rather than free old region ids at region release time.
    
    While this fixes a cosmetic issue, the needlessly advancing memory
    region-id gives the appearance of a memory leak, hence the "Fixes" tag,
    but no "Cc: stable" tag.
    
    Cc: Ben Widawsky <bwidawsk@xxxxxxxxxx>
    Cc: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
    Fixes: 779dd20cfb56 ("cxl/region: Add region creation support")
    Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
    Reviewed-by: Vishal Verma <vishal.l.verma@xxxxxxxxx>
    Link: https://lore.kernel.org/r/166752186062.947915.13200195701224993317.stgit@xxxxxxxxxxxxxxxxxxxxxxxxx
    Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 6b7fb955a05a..78344e4d4215 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1533,9 +1533,24 @@ static const struct attribute_group *region_groups[] = {
 
 static void cxl_region_release(struct device *dev)
 {
+	struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent);
 	struct cxl_region *cxlr = to_cxl_region(dev);
+	int id = atomic_read(&cxlrd->region_id);
+
+	/*
+	 * Try to reuse the recently idled id rather than the cached
+	 * next id to prevent the region id space from increasing
+	 * unnecessarily.
+	 */
+	if (cxlr->id < id)
+		if (atomic_try_cmpxchg(&cxlrd->region_id, &id, cxlr->id)) {
+			memregion_free(id);
+			goto out;
+		}
 
 	memregion_free(cxlr->id);
+out:
+	put_device(dev->parent);
 	kfree(cxlr);
 }
 
@@ -1597,6 +1612,11 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i
 	device_initialize(dev);
 	lockdep_set_class(&dev->mutex, &cxl_region_key);
 	dev->parent = &cxlrd->cxlsd.cxld.dev;
+	/*
+	 * Keep root decoder pinned through cxl_region_release to fixup
+	 * region id allocations
+	 */
+	get_device(dev->parent);
 	device_set_pm_not_required(dev);
 	dev->bus = &cxl_bus_type;
 	dev->type = &cxl_region_type;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux