* [PATCH v2 0/3] Cleanup resource_alignment parameter
@ 2019-08-22 16:10 Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 1/3] PCI: Clean up resource_alignment parameter to not require static buffer Logan Gunthorpe
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Logan Gunthorpe @ 2019-08-22 16:10 UTC (permalink / raw)
To: linux-kernel, linux-pci; +Cc: Bjorn Helgaas, Logan Gunthorpe
As requested, this is a refresh of this series. I rebased it on v5.3-rc5
without any other changes.
This is a cleanup of the resource_alignment parameter after finding
an improved way to handle the static buffer for the disable_acs_redir
parameter. So this patchset allows us to drop a significant chunk
of static data.
Thanks,
Logan
--
Logan Gunthorpe (3):
PCI: Clean up resource_alignment parameter to not require static
buffer
PCI: Move pci_[get|set]_resource_alignment_param() into their callers
PCI: Force trailing new line to resource_alignment_param in sysfs
drivers/pci/pci.c | 65 +++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 30 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] PCI: Clean up resource_alignment parameter to not require static buffer
2019-08-22 16:10 [PATCH v2 0/3] Cleanup resource_alignment parameter Logan Gunthorpe
@ 2019-08-22 16:10 ` Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 2/3] PCI: Move pci_[get|set]_resource_alignment_param() into their callers Logan Gunthorpe
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Logan Gunthorpe @ 2019-08-22 16:10 UTC (permalink / raw)
To: linux-kernel, linux-pci; +Cc: Bjorn Helgaas, Logan Gunthorpe
Clean up the 'resource_alignment' parameter code to use kstrdup
in the initcall routine instead of a static buffer that wastes memory
regardless of whether the feature is used. This allows us to drop
'COMMAND_LINE_SIZE' bytes (typically 256-4096 depending on architecture)
of static data.
This is similar to what has been done for the 'disable_acs_redir'
parameter.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/pci.c | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1b27b5af3d55..489fff757833 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5923,8 +5923,7 @@ resource_size_t __weak pcibios_default_alignment(void)
return 0;
}
-#define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE
-static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0};
+static char *resource_alignment_param;
static DEFINE_SPINLOCK(resource_alignment_lock);
/**
@@ -5945,7 +5944,7 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev,
spin_lock(&resource_alignment_lock);
p = resource_alignment_param;
- if (!*p && !align)
+ if (!p || !*p)
goto out;
if (pci_has_flag(PCI_PROBE_ONLY)) {
align = 0;
@@ -6111,21 +6110,25 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
{
- if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1)
- count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1;
spin_lock(&resource_alignment_lock);
- strncpy(resource_alignment_param, buf, count);
- resource_alignment_param[count] = '\0';
+
+ kfree(resource_alignment_param);
+ resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
+
spin_unlock(&resource_alignment_lock);
- return count;
+
+ return resource_alignment_param ? count : -ENOMEM;
}
static ssize_t pci_get_resource_alignment_param(char *buf, size_t size)
{
- size_t count;
+ size_t count = 0;
+
spin_lock(&resource_alignment_lock);
- count = snprintf(buf, size, "%s", resource_alignment_param);
+ if (resource_alignment_param)
+ count = snprintf(buf, size, "%s", resource_alignment_param);
spin_unlock(&resource_alignment_lock);
+
return count;
}
@@ -6266,8 +6269,7 @@ static int __init pci_setup(char *str)
} else if (!strncmp(str, "cbmemsize=", 10)) {
pci_cardbus_mem_size = memparse(str + 10, &str);
} else if (!strncmp(str, "resource_alignment=", 19)) {
- pci_set_resource_alignment_param(str + 19,
- strlen(str + 19));
+ resource_alignment_param = str + 19;
} else if (!strncmp(str, "ecrc=", 5)) {
pcie_ecrc_get_policy(str + 5);
} else if (!strncmp(str, "hpiosize=", 9)) {
@@ -6302,15 +6304,18 @@ static int __init pci_setup(char *str)
early_param("pci", pci_setup);
/*
- * 'disable_acs_redir_param' is initialized in pci_setup(), above, to point
- * to data in the __initdata section which will be freed after the init
- * sequence is complete. We can't allocate memory in pci_setup() because some
- * architectures do not have any memory allocation service available during
- * an early_param() call. So we allocate memory and copy the variable here
- * before the init section is freed.
+ * 'resource_alignment_param' and 'disable_acs_redir_param' are initialized
+ * in pci_setup(), above, to point to data in the __initdata section which
+ * will be freed after the init sequence is complete. We can't allocate memory
+ * in pci_setup() because some architectures do not have any memory allocation
+ * service available during an early_param() call. So we allocate memory and
+ * copy the variable here before the init section is freed.
+ *
*/
static int __init pci_realloc_setup_params(void)
{
+ resource_alignment_param = kstrdup(resource_alignment_param,
+ GFP_KERNEL);
disable_acs_redir_param = kstrdup(disable_acs_redir_param, GFP_KERNEL);
return 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] PCI: Move pci_[get|set]_resource_alignment_param() into their callers
2019-08-22 16:10 [PATCH v2 0/3] Cleanup resource_alignment parameter Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 1/3] PCI: Clean up resource_alignment parameter to not require static buffer Logan Gunthorpe
@ 2019-08-22 16:10 ` Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 3/3] PCI: Force trailing new line to resource_alignment_param in sysfs Logan Gunthorpe
2019-08-28 20:52 ` [PATCH v2 0/3] Cleanup resource_alignment parameter Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Logan Gunthorpe @ 2019-08-22 16:10 UTC (permalink / raw)
To: linux-kernel, linux-pci; +Cc: Bjorn Helgaas, Logan Gunthorpe
Both the functions pci_get_resource_alignment_param() and
pci_set_resource_alignment_param() are now only called in one place:
resource_alignment_show() and resource_alignment_store() respectively.
There is no value in this extra set of functions so we move both into
their callers respectively.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/pci.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 489fff757833..5e00371149b1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6108,39 +6108,29 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
}
}
-static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
-{
- spin_lock(&resource_alignment_lock);
-
- kfree(resource_alignment_param);
- resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
-
- spin_unlock(&resource_alignment_lock);
-
- return resource_alignment_param ? count : -ENOMEM;
-}
-
-static ssize_t pci_get_resource_alignment_param(char *buf, size_t size)
+static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
{
size_t count = 0;
spin_lock(&resource_alignment_lock);
if (resource_alignment_param)
- count = snprintf(buf, size, "%s", resource_alignment_param);
+ count = snprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
spin_unlock(&resource_alignment_lock);
return count;
}
-static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
-{
- return pci_get_resource_alignment_param(buf, PAGE_SIZE);
-}
-
static ssize_t resource_alignment_store(struct bus_type *bus,
const char *buf, size_t count)
{
- return pci_set_resource_alignment_param(buf, count);
+ spin_lock(&resource_alignment_lock);
+
+ kfree(resource_alignment_param);
+ resource_alignment_param = kstrndup(buf, count, GFP_KERNEL);
+
+ spin_unlock(&resource_alignment_lock);
+
+ return resource_alignment_param ? count : -ENOMEM;
}
static BUS_ATTR_RW(resource_alignment);
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] PCI: Force trailing new line to resource_alignment_param in sysfs
2019-08-22 16:10 [PATCH v2 0/3] Cleanup resource_alignment parameter Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 1/3] PCI: Clean up resource_alignment parameter to not require static buffer Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 2/3] PCI: Move pci_[get|set]_resource_alignment_param() into their callers Logan Gunthorpe
@ 2019-08-22 16:10 ` Logan Gunthorpe
2019-08-28 20:52 ` [PATCH v2 0/3] Cleanup resource_alignment parameter Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Logan Gunthorpe @ 2019-08-22 16:10 UTC (permalink / raw)
To: linux-kernel, linux-pci; +Cc: Bjorn Helgaas, Logan Gunthorpe
When 'pci=resource_alignment=' is specified on the command line, there
is no trailing new line. Then, when it's read through the corresponding
sysfs attribute, there will be no newline and a cat command will not
show correctly in a shell. If the parameter is set through sysfs
a new line will be stored and it will 'cat' correctly.
To solve this, append a new line character in the show function if
one does not already exist.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/pci.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 5e00371149b1..4748362d6a49 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6117,6 +6117,16 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
count = snprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
spin_unlock(&resource_alignment_lock);
+ /*
+ * When set by the command line, resource_alignment_param will not
+ * have a trailing line feed, which is ugly. So conditionally add
+ * it here.
+ */
+ if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) {
+ buf[count - 1] = '\n';
+ buf[count++] = 0;
+ }
+
return count;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] Cleanup resource_alignment parameter
2019-08-22 16:10 [PATCH v2 0/3] Cleanup resource_alignment parameter Logan Gunthorpe
` (2 preceding siblings ...)
2019-08-22 16:10 ` [PATCH v2 3/3] PCI: Force trailing new line to resource_alignment_param in sysfs Logan Gunthorpe
@ 2019-08-28 20:52 ` Bjorn Helgaas
3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2019-08-28 20:52 UTC (permalink / raw)
To: Logan Gunthorpe; +Cc: linux-kernel, linux-pci
On Thu, Aug 22, 2019 at 10:10:10AM -0600, Logan Gunthorpe wrote:
> As requested, this is a refresh of this series. I rebased it on v5.3-rc5
> without any other changes.
>
> This is a cleanup of the resource_alignment parameter after finding
> an improved way to handle the static buffer for the disable_acs_redir
> parameter. So this patchset allows us to drop a significant chunk
> of static data.
>
> Thanks,
>
> Logan
>
> --
>
> Logan Gunthorpe (3):
> PCI: Clean up resource_alignment parameter to not require static
> buffer
> PCI: Move pci_[get|set]_resource_alignment_param() into their callers
> PCI: Force trailing new line to resource_alignment_param in sysfs
>
> drivers/pci/pci.c | 65 +++++++++++++++++++++++++----------------------
> 1 file changed, 35 insertions(+), 30 deletions(-)
Applied to pci/misc for v5.4, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-08-28 20:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 16:10 [PATCH v2 0/3] Cleanup resource_alignment parameter Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 1/3] PCI: Clean up resource_alignment parameter to not require static buffer Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 2/3] PCI: Move pci_[get|set]_resource_alignment_param() into their callers Logan Gunthorpe
2019-08-22 16:10 ` [PATCH v2 3/3] PCI: Force trailing new line to resource_alignment_param in sysfs Logan Gunthorpe
2019-08-28 20:52 ` [PATCH v2 0/3] Cleanup resource_alignment parameter Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).