[RFC: DMA_PMD 10/22] driver core: Add per-device dma_pmd_* sysfs attributes

From: Luigi Rizzo

Date: Sat Oct 03 2026 - 17:31:05 EST


Add four boolean attributes to struct device exposed under
/sys/devices/*/*/dma_pmd_*:
- dma_pmd_rxbuf: enable DMA_PMD pools for RX buffers / page_pool
- dma_pmd_tx_hdrs: enable DMA_PMD pools for TX header bounce buffers
- dma_pmd_rings: enable DMA_PMD arena for coherent rings
- dma_pmd_debug: log coherent DMA alloc timing and arena usage

These can be used by device drivers to selectively enable DMA_PMD for
their allocations.

Signed-off-by: Luigi Rizzo <lrizzo@xxxxxxxxxx>
---
drivers/base/core.c | 51 ++++++++++++++++++++++++++++++++++++++++++
include/linux/device.h | 5 +++++
2 files changed, 56 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 4c0c373998a19..f8c3c42d84b8d 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2905,6 +2905,43 @@ static ssize_t removable_show(struct device *dev, const struct device_attribute
}
static const DEVICE_ATTR_RO(removable);

+/* Per-device configuration to selectively enable DMA_PMD */
+#define DMA_PMD_BOOL_ATTR(name) \
+static ssize_t name##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ return sysfs_emit(buf, "%u\n", READ_ONCE(dev->name)); \
+} \
+static ssize_t name##_store(struct device *dev, \
+ struct device_attribute *attr, \
+ const char *buf, size_t count) \
+{ \
+ bool val; \
+ int ret = kstrtobool(buf, &val); \
+ if (ret < 0) \
+ return ret; \
+ WRITE_ONCE(dev->name, val); \
+ return count; \
+} \
+static DEVICE_ATTR_RW(name)
+
+DMA_PMD_BOOL_ATTR(dma_pmd_rxbuf);
+DMA_PMD_BOOL_ATTR(dma_pmd_tx_hdrs);
+DMA_PMD_BOOL_ATTR(dma_pmd_rings);
+DMA_PMD_BOOL_ATTR(dma_pmd_debug);
+
+static struct attribute *dev_attr_dma_pmd[] = {
+ &dev_attr_dma_pmd_rxbuf.attr,
+ &dev_attr_dma_pmd_tx_hdrs.attr,
+ &dev_attr_dma_pmd_rings.attr,
+ &dev_attr_dma_pmd_debug.attr,
+ NULL,
+};
+
+static const struct attribute_group dev_attr_dma_pmd_group = {
+ .attrs = dev_attr_dma_pmd,
+};
+
int device_add_groups(struct device *dev,
const struct attribute_group *const *groups)
{
@@ -3012,8 +3049,20 @@ static int device_add_attrs(struct device *dev)
goto err_remove_dev_removable;
}

+ if (dev->dma_mask) {
+ error = device_add_group(dev, &dev_attr_dma_pmd_group);
+ if (error)
+ goto err_remove_dev_physical_location;
+ }
+
return 0;

+ err_remove_dev_physical_location:
+ if (dev->physical_location) {
+ device_remove_group(dev, &dev_attr_physical_location_group);
+ kfree(dev->physical_location);
+ dev->physical_location = NULL;
+ }
err_remove_dev_removable:
device_remove_file(dev, &dev_attr_removable);
err_remove_dev_waiting_for_supplier:
@@ -3037,6 +3086,8 @@ static void device_remove_attrs(struct device *dev)
const struct class *class = dev->class;
const struct device_type *type = dev->type;

+ device_remove_group(dev, &dev_attr_dma_pmd_group);
+
if (dev->physical_location) {
device_remove_group(dev, &dev_attr_physical_location_group);
kfree(dev->physical_location);
diff --git a/include/linux/device.h b/include/linux/device.h
index aee79fd6b32b4..52aa4a7e1cc45 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -794,6 +794,11 @@ struct device {

enum device_removable removable;

+ bool dma_pmd_rxbuf;
+ bool dma_pmd_tx_hdrs;
+ bool dma_pmd_rings;
+ bool dma_pmd_debug;
+
DECLARE_BITMAP(flags, DEV_FLAG_COUNT);
};

--
2.56.0.rc1.315.gc6ed9934b7-goog