[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <914285f708739992f14c16fb3be336c6e8afed52.1759312886.git.epetron@amazon.de>
Date: Fri, 3 Oct 2025 09:00:46 +0000
From: Evangelos Petrongonas <epetron@...zon.de>
To: Bjorn Helgaas <bhelgaas@...gle.com>, Alex Williamson
<alex.williamson@...hat.com>, "Rafael J . Wysocki" <rafael@...nel.org>, "Len
Brown" <lenb@...nel.org>
CC: Evangelos Petrongonas <epetron@...zon.de>, Pasha Tatashin
<pasha.tatashin@...een.com>, David Matlack <dmatlack@...gle.com>, "Vipin
Sharma" <vipinsh@...gle.com>, Chris Li <chrisl@...nel.org>, Jason Miu
<jasonmiu@...gle.com>, Pratyush Yadav <pratyush@...nel.org>, "Stanislav
Spassov" <stanspas@...zon.de>, <linux-pci@...r.kernel.org>,
<linux-acpi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<nh-open-source@...zon.com>
Subject: [RFC PATCH 10/13] pci: pcsc: Use contiguous pages for the cache data
This patch refactors PCSC to use a single contiguous memory block for
all per-device data. This improves memory allocation efficiency.
This is a preparatory step for KHO persistence support, as it is easier
to manipulate physically continuous pages.
Signed-off-by: Evangelos Petrongonas <epetron@...zon.de>
---
drivers/pci/pcsc.c | 28 ++++++++++++++++++++++++----
include/linux/pcsc.h | 32 ++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/pcsc.c b/drivers/pci/pcsc.c
index 304239b7ff8a..18d508f76649 100644
--- a/drivers/pci/pcsc.c
+++ b/drivers/pci/pcsc.c
@@ -725,6 +725,7 @@ int pcsc_add_device(struct pci_dev *dev)
{
struct pcsc_node *node;
struct pci_bus *bus;
+ size_t data_size;
if (WARN_ON(!dev))
return -EINVAL;
@@ -741,12 +742,27 @@ int pcsc_add_device(struct pci_dev *dev)
* nodes for these devices, as it simplifies the code flow
*/
if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
- dev->pcsc->cfg_space = kzalloc(PCSC_CFG_SPC_SIZE, GFP_KERNEL);
- if (!dev->pcsc->cfg_space)
+ /* Allocate contiguous, page aligned data block. This will be
+ * needed for persisting the data with KHO.
+ */
+ data_size = sizeof(struct pcsc_data);
+
+ dev->pcsc->data =
+ (struct pcsc_data *)__get_free_pages(
+ GFP_KERNEL | __GFP_ZERO, get_order(data_size));
+ if (!dev->pcsc->data)
+
goto err_free_node;
+ dev->pcsc->cachable_bitmask = dev->pcsc->data->cachable_bitmask;
+ dev->pcsc->cached_bitmask = dev->pcsc->data->cached_bitmask;
+ dev->pcsc->cfg_space = dev->pcsc->data->cfg_space;
+
infer_cacheability(dev);
} else {
+ dev->pcsc->data = NULL;
+ dev->pcsc->cachable_bitmask = NULL;
+ dev->pcsc->cached_bitmask = NULL;
dev->pcsc->cfg_space = NULL;
}
@@ -771,8 +787,12 @@ int pcsc_remove_device(struct pci_dev *dev)
atomic_dec(&num_nodes);
- if (dev->pcsc && dev->pcsc->cfg_space) {
- kfree(dev->pcsc->cfg_space);
+ if (dev->pcsc && dev->pcsc->data) {
+ size_t data_size = sizeof(struct pcsc_data);
+ size_t total_size = PAGE_ALIGN(data_size);
+
+ free_pages((unsigned long)dev->pcsc->data,
+ get_order(total_size));
kfree(dev->pcsc);
}
dev->pcsc = NULL;
diff --git a/include/linux/pcsc.h b/include/linux/pcsc.h
index 85471273c0a9..88894f641257 100644
--- a/include/linux/pcsc.h
+++ b/include/linux/pcsc.h
@@ -18,12 +18,40 @@
#define PCSC_CFG_SPC_SIZE 256
#endif
-struct pcsc_node {
- u8 *cfg_space;
+/*
+ * struct pcsc__data - Continuous data block for PCSC
+ *
+ * This structure contains all the PCSC data in a single continuous
+ * memory block.
+ *
+ * @cfg_space: Configuration space cache
+ * @cachable_bitmask: Bitmap of cacheable configuration space offsets
+ * @cached_bitmask: Bitmap of cached configuration space offsets
+ */
+struct pcsc_data {
+ u8 cfg_space[PCSC_CFG_SPC_SIZE];
DECLARE_BITMAP(cachable_bitmask, PCSC_CFG_SPC_SIZE);
DECLARE_BITMAP(cached_bitmask, PCSC_CFG_SPC_SIZE);
};
+/*
+ * struct pcsc_node - PCSC node structure
+ *
+ * This structure represents a PCSC node for a PCI device.
+ * It contains pointers into the data block for convenient access.
+ *
+ * @data: Pointer to the continuous data block
+ * @cachable_bitmask: Pointer to cachable_bitmask in data
+ * @cached_bitmask: Pointer to cached_bitmask in data
+ * @cfg_space: Pointer to cfg_space in data
+ */
+struct pcsc_node {
+ struct pcsc_data *data; /* Pointer to continuous data block */
+ unsigned long *cachable_bitmask; /* Convenience pointer into data */
+ unsigned long *cached_bitmask; /* Convenience pointer into data */
+ u8 *cfg_space; /* Convenience pointer into data */
+};
+
/**
* pcsc_hw_config_read - Direct hardware PCI config space read
* @bus: PCI bus
--
2.47.3
Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christian Schlaeger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597
Powered by blists - more mailing lists