Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cxl/region: Add support to indicate region has extended linear cache

Add a region sysfs attribute to show the size of the extended linear
cache if there is any. The attribute is invisible when the cache
size is 0, which indicates it does not exist.

Moved the cxl_region_visible() location in order to pick up the
new sysfs attribute definition.

[ dj: Fixed spelling errors noted by Benjamin ]

Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20251022203052.4078527-1-dave.jiang@intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

+54 -16
+10 -1
Documentation/ABI/testing/sysfs-bus-cxl
··· 496 496 changed, only freed by writing 0. The kernel makes no guarantees 497 497 that data is maintained over an address space freeing event, and 498 498 there is no guarantee that a free followed by an allocate 499 - results in the same address being allocated. 499 + results in the same address being allocated. If extended linear 500 + cache is present, the size indicates extended linear cache size 501 + plus the CXL region size. 500 502 503 + What: /sys/bus/cxl/devices/regionZ/extended_linear_cache_size 504 + Date: October, 2025 505 + KernelVersion: v6.19 506 + Contact: linux-cxl@vger.kernel.org 507 + Description: 508 + (RO) The size of extended linear cache, if there is an extended 509 + linear cache. Otherwise the attribute will not be visible. 501 510 502 511 What: /sys/bus/cxl/devices/regionZ/mode 503 512 Date: January, 2023
+44 -15
drivers/cxl/core/region.c
··· 461 461 } 462 462 static DEVICE_ATTR_RW(commit); 463 463 464 - static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a, 465 - int n) 466 - { 467 - struct device *dev = kobj_to_dev(kobj); 468 - struct cxl_region *cxlr = to_cxl_region(dev); 469 - 470 - /* 471 - * Support tooling that expects to find a 'uuid' attribute for all 472 - * regions regardless of mode. 473 - */ 474 - if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM) 475 - return 0444; 476 - return a->mode; 477 - } 478 - 479 464 static ssize_t interleave_ways_show(struct device *dev, 480 465 struct device_attribute *attr, char *buf) 481 466 { ··· 739 754 } 740 755 static DEVICE_ATTR_RW(size); 741 756 757 + static ssize_t extended_linear_cache_size_show(struct device *dev, 758 + struct device_attribute *attr, 759 + char *buf) 760 + { 761 + struct cxl_region *cxlr = to_cxl_region(dev); 762 + struct cxl_region_params *p = &cxlr->params; 763 + ssize_t rc; 764 + 765 + ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region); 766 + if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem))) 767 + return rc; 768 + return sysfs_emit(buf, "%#llx\n", p->cache_size); 769 + } 770 + static DEVICE_ATTR_RO(extended_linear_cache_size); 771 + 742 772 static struct attribute *cxl_region_attrs[] = { 743 773 &dev_attr_uuid.attr, 744 774 &dev_attr_commit.attr, ··· 762 762 &dev_attr_resource.attr, 763 763 &dev_attr_size.attr, 764 764 &dev_attr_mode.attr, 765 + &dev_attr_extended_linear_cache_size.attr, 765 766 NULL, 766 767 }; 768 + 769 + static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a, 770 + int n) 771 + { 772 + struct device *dev = kobj_to_dev(kobj); 773 + struct cxl_region *cxlr = to_cxl_region(dev); 774 + 775 + /* 776 + * Support tooling that expects to find a 'uuid' attribute for all 777 + * regions regardless of mode. 778 + */ 779 + if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_PARTMODE_PMEM) 780 + return 0444; 781 + 782 + /* 783 + * Don't display extended linear cache attribute if there is no 784 + * extended linear cache. 785 + */ 786 + if (a == &dev_attr_extended_linear_cache_size.attr && 787 + cxlr->params.cache_size == 0) 788 + return 0; 789 + 790 + return a->mode; 791 + } 767 792 768 793 static const struct attribute_group cxl_region_group = { 769 794 .attrs = cxl_region_attrs, ··· 3503 3478 dev_warn(cxlmd->dev.parent, 3504 3479 "Extended linear cache calculation failed rc:%d\n", rc); 3505 3480 } 3481 + 3482 + rc = sysfs_update_group(&cxlr->dev.kobj, &cxl_region_group); 3483 + if (rc) 3484 + return rc; 3506 3485 3507 3486 rc = insert_resource(cxlrd->res, res); 3508 3487 if (rc) {