Re: [PATCH v2 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
Hi Joe, [...] > Ideally, the additional newline check below this would use sysfs_emit_at > > drivers/pci/pci.c- /* > drivers/pci/pci.c: * When set by the command line, > resource_alignment_param will not > drivers/pci/pci.c- * have a trailing line feed, which is ugly. So > conditionally add > drivers/pci/pci.c- * it here. > drivers/pci/pci.c- */ > drivers/pci/pci.c- if (count >= 2 && buf[count - 2] != '\n' && count < > PAGE_SIZE - 1) { > drivers/pci/pci.c- buf[count - 1] = '\n'; > drivers/pci/pci.c- buf[count++] = 0; > drivers/pci/pci.c- } > drivers/pci/pci.c- > drivers/pci/pci.c- return count; I found some inconsistencies with adding newline this way, and decided to change the code slightly, see: https://lore.kernel.org/linux-pci/20210515052434.1413236-12...@linux.com/ Krzysztof
Re: [PATCH v2 04/14] PCI/MSI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
On Sat, 2021-05-15 at 05:24 +, Krzysztof Wilczyński wrote: > The sysfs_emit() and sysfs_emit_at() functions were introduced to make > it less ambiguous which function is preferred when writing to the output > buffer in a device attribute's "show" callback [1]. > > Convert the PCI sysfs object "show" functions from sprintf(), snprintf() > and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the > latter is aware of the PAGE_SIZE buffer and correctly returns the number > of bytes written into the buffer. > > No functional change intended. [] > diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c [] > @@ -465,8 +465,8 @@ static ssize_t msi_mode_show(struct device *dev, struct > device_attribute *attr, > > entry = irq_get_msi_desc(irq); > if (entry) > - return sprintf(buf, "%s\n", > - entry->msi_attrib.is_msix ? "msix" : "msi"); > + return sysfs_emit(buf, "%s\n", > + entry->msi_attrib.is_msix ? "msix" : "msi"); > > > return -ENODEV; > } trivia: reversing the test would be more common style if (!entry) return -ENODEV; return sysfs_emit(...); }
Re: [PATCH v2 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
On Sat, 2021-05-15 at 05:24 +, Krzysztof Wilczyński wrote: > The sysfs_emit() and sysfs_emit_at() functions were introduced to make > it less ambiguous which function is preferred when writing to the output > buffer in a device attribute's "show" callback [1]. > > Convert the PCI sysfs object "show" functions from sprintf(), snprintf() > and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the > latter is aware of the PAGE_SIZE buffer and correctly returns the number > of bytes written into the buffer. [] > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c [] > @@ -6439,7 +6439,7 @@ static ssize_t resource_alignment_show(struct bus_type > *bus, char *buf) > > > spin_lock(_alignment_lock); > if (resource_alignment_param) > - count = scnprintf(buf, PAGE_SIZE, "%s", > resource_alignment_param); > + count = sysfs_emit(buf, "%s", resource_alignment_param); > spin_unlock(_alignment_lock); Ideally, the additional newline check below this would use sysfs_emit_at drivers/pci/pci.c- /* drivers/pci/pci.c: * When set by the command line, resource_alignment_param will not drivers/pci/pci.c- * have a trailing line feed, which is ugly. So conditionally add drivers/pci/pci.c- * it here. drivers/pci/pci.c- */ drivers/pci/pci.c- if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) { drivers/pci/pci.c- buf[count - 1] = '\n'; drivers/pci/pci.c- buf[count++] = 0; drivers/pci/pci.c- } drivers/pci/pci.c- drivers/pci/pci.c- return count;
Re: [PATCH v2 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
Hello, [...] > Reviewed-by: Logan Gunthorpe Please disregard this "Reviewed-by" from Logan for this version, as I've forgotten to remove it before sending v2 after pulling patches using b4. Apologies. Krzysztof
[PATCH v2 14/14] PCI/sysfs: Only show value when driver_override is not NULL
Only expose the value of the "driver_override" variable through the corresponding sysfs object when a value is actually set. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d63df7c1820..4e9f582ca10f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -580,10 +580,11 @@ static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); - ssize_t len; + ssize_t len = 0; device_lock(dev); - len = sysfs_emit(buf, "%s\n", pdev->driver_override); + if (pdev->driver_override) + len = sysfs_emit(buf, "%s\n", pdev->driver_override); device_unlock(dev); return len; } -- 2.31.1
[PATCH v2 13/14] PCI/sysfs: Add missing trailing newline to devspec_show()
At the moment, when the value of the "devspec" sysfs object is read from the user space there will be no newline present, and the utilities such as the "cat" command won't display the result of the read correctly in a shell, as the trailing newline is currently missing. To fix this, append a newline character in the show() function. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index beb8d1f4fafe..5d63df7c1820 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -537,7 +537,7 @@ static ssize_t devspec_show(struct device *dev, if (np == NULL) return 0; - return sysfs_emit(buf, "%pOF", np); + return sysfs_emit(buf, "%pOF\n", np); } static DEVICE_ATTR_RO(devspec); #endif -- 2.31.1
[PATCH v2 12/14] PCI: Fix trailing newline handling of resource_alignment_param
The value of the "resource_alignment" can be specified using a kernel command-line argument (using the "pci=resource_alignment=") or through the corresponding sysfs object under the /sys/bus/pci path. Currently, when the value is set via the kernel command-line argument, and then subsequently accessed through sysfs object, the value read back will not be correct, as per: # grep -oE 'pci=resource_alignment.+' /proc/cmdline pci=resource_alignment=20@00:1f.2 # cat /sys/bus/pci/resource_alignment 20@00:1f. This is also true when the value is set through the sysfs object, but the trailing newline has not been included, as per: # echo -n 20@00:1f.2 > /sys/bus/pci/resource_alignment # cat /sys/bus/pci/resource_alignment 20@00:1f. When the value set through the sysfs object includes the trailing newline, then reading it back will work as intended, as per: # echo 20@00:1f.2 > /sys/bus/pci/resource_alignment # cat /sys/bus/pci/resource_alignment 20@00:1f.2 To fix this inconsistency, append a trailing newline in the show() function and strip the trailing line in the store() function if one is present. Also, allow for the value previously set using either a command-line argument or through the sysfs object to be cleared at run-time. Fixes: e499081da1a2 ("PCI: Force trailing new line to resource_alignment_param in sysfs") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci.c | 31 +-- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5ed316ea5831..7cde86bdcc8e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6439,34 +6439,37 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) spin_lock(_alignment_lock); if (resource_alignment_param) - count = sysfs_emit(buf, "%s", resource_alignment_param); + count = sysfs_emit(buf, "%s\n", resource_alignment_param); spin_unlock(_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; } static ssize_t resource_alignment_store(struct bus_type *bus, const char *buf, size_t count) { - char *param = kstrndup(buf, count, GFP_KERNEL); + char *param, *old, *end; + param = kstrndup(buf, count, GFP_KERNEL); if (!param) return -ENOMEM; + end = strchr(param, '\n'); + if (end) + *end = '\0'; + spin_lock(_alignment_lock); - kfree(resource_alignment_param); - resource_alignment_param = param; + old = resource_alignment_param; + if (strlen(param)) { + resource_alignment_param = param; + } else { + kfree(resource_alignment_param); + resource_alignment_param = NULL; + } spin_unlock(_alignment_lock); + + kfree(old); + return count; } -- 2.31.1
[PATCH v2 11/14] PCI: shpchp: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/shpchp_sysfs.c | 38 +- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c index 45658bb5c554..64beed7a26be 100644 --- a/drivers/pci/hotplug/shpchp_sysfs.c +++ b/drivers/pci/hotplug/shpchp_sysfs.c @@ -24,50 +24,54 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) { struct pci_dev *pdev; - char *out = buf; int index, busnr; struct resource *res; struct pci_bus *bus; + size_t len = 0; pdev = to_pci_dev(dev); bus = pdev->subordinate; - out += sprintf(buf, "Free resources: memory\n"); + len += sysfs_emit_at(buf, len, "Free resources: memory\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_MEM) && !(res->flags & IORESOURCE_PREFETCH)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, +"start = %8.8llx, length = %8.8llx\n", +(unsigned long long)res->start, +(unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: prefetchable memory\n"); + len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_MEM) && (res->flags & IORESOURCE_PREFETCH)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, +"start = %8.8llx, length = %8.8llx\n", +(unsigned long long)res->start, +(unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: IO\n"); + len += sysfs_emit_at(buf, len, "Free resources: IO\n"); pci_bus_for_each_resource(bus, res, index) { if (res && (res->flags & IORESOURCE_IO)) { - out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", - (unsigned long long)res->start, - (unsigned long long)resource_size(res)); + len += sysfs_emit_at(buf, len, +"start = %8.8llx, length = %8.8llx\n", +(unsigned long long)res->start, +(unsigned long long)resource_size(res)); } } - out += sprintf(out, "Free resources: bus numbers\n"); + len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n"); for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) { if (!pci_find_bus(pci_domain_nr(bus), busnr)) break; } if (busnr < bus->busn_res.end) - out += sprintf(out, "start = %8.8x, length = %8.8x\n", - busnr, (int)(bus->busn_res.end - busnr)); + len += sysfs_emit_at(buf, len, +"start = %8.8x, length = %8.8x\n", +busnr, (int)(bus->busn_res.end - busnr)); - return out - buf; + return len; } static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL); -- 2.31.1
[PATCH v2 10/14] PCI: hotplug: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/pci_hotplug_core.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index 5ac31f683b85..058d5937d8a9 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -73,7 +73,7 @@ static ssize_t power_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, @@ -130,7 +130,7 @@ static ssize_t attention_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf, @@ -175,7 +175,7 @@ static ssize_t latch_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static struct pci_slot_attribute hotplug_slot_attr_latch = { @@ -192,7 +192,7 @@ static ssize_t presence_read_file(struct pci_slot *pci_slot, char *buf) if (retval) return retval; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static struct pci_slot_attribute hotplug_slot_attr_presence = { -- 2.31.1
[PATCH v2 09/14] PCI: rpadlpar: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/hotplug/rpadlpar_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c index dbfa0b55d31a..068b7810a574 100644 --- a/drivers/pci/hotplug/rpadlpar_sysfs.c +++ b/drivers/pci/hotplug/rpadlpar_sysfs.c @@ -50,7 +50,7 @@ static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, static ssize_t add_slot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "0\n"); + return sysfs_emit(buf, "0\n"); } static ssize_t remove_slot_store(struct kobject *kobj, @@ -80,7 +80,7 @@ static ssize_t remove_slot_store(struct kobject *kobj, static ssize_t remove_slot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - return sprintf(buf, "0\n"); + return sysfs_emit(buf, "0\n"); } static struct kobj_attribute add_slot_attr = -- 2.31.1
[PATCH v2 08/14] PCI: switchtec: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/switch/switchtec.c | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c index ba52459928f7..0b301f8be9ed 100644 --- a/drivers/pci/switch/switchtec.c +++ b/drivers/pci/switch/switchtec.c @@ -280,7 +280,7 @@ static ssize_t device_version_show(struct device *dev, ver = ioread32(>mmio_sys_info->device_version); - return sprintf(buf, "%x\n", ver); + return sysfs_emit(buf, "%x\n", ver); } static DEVICE_ATTR_RO(device_version); @@ -292,7 +292,7 @@ static ssize_t fw_version_show(struct device *dev, ver = ioread32(>mmio_sys_info->firmware_version); - return sprintf(buf, "%08x\n", ver); + return sysfs_emit(buf, "%08x\n", ver); } static DEVICE_ATTR_RO(fw_version); @@ -344,7 +344,7 @@ static ssize_t component_vendor_show(struct device *dev, /* component_vendor field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "none\n"); + return sysfs_emit(buf, "none\n"); return io_string_show(buf, >gen3.component_vendor, sizeof(si->gen3.component_vendor)); @@ -359,9 +359,9 @@ static ssize_t component_id_show(struct device *dev, /* component_id field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "none\n"); + return sysfs_emit(buf, "none\n"); - return sprintf(buf, "PM%04X\n", id); + return sysfs_emit(buf, "PM%04X\n", id); } static DEVICE_ATTR_RO(component_id); @@ -373,9 +373,9 @@ static ssize_t component_revision_show(struct device *dev, /* component_revision field not supported after gen3 */ if (stdev->gen != SWITCHTEC_GEN3) - return sprintf(buf, "255\n"); + return sysfs_emit(buf, "255\n"); - return sprintf(buf, "%d\n", rev); + return sysfs_emit(buf, "%d\n", rev); } static DEVICE_ATTR_RO(component_revision); @@ -384,7 +384,7 @@ static ssize_t partition_show(struct device *dev, { struct switchtec_dev *stdev = to_stdev(dev); - return sprintf(buf, "%d\n", stdev->partition); + return sysfs_emit(buf, "%d\n", stdev->partition); } static DEVICE_ATTR_RO(partition); @@ -393,7 +393,7 @@ static ssize_t partition_count_show(struct device *dev, { struct switchtec_dev *stdev = to_stdev(dev); - return sprintf(buf, "%d\n", stdev->partition_count); + return sysfs_emit(buf, "%d\n", stdev->partition_count); } static DEVICE_ATTR_RO(partition_count); -- 2.31.1
[PATCH v2 07/14] PCI/ASPM: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pcie/aspm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index ac0557a305af..013a47f587ce 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1208,7 +1208,7 @@ static ssize_t aspm_attr_show_common(struct device *dev, struct pci_dev *pdev = to_pci_dev(dev); struct pcie_link_state *link = pcie_aspm_get_link(pdev); - return sprintf(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0); + return sysfs_emit(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0); } static ssize_t aspm_attr_store_common(struct device *dev, @@ -1265,7 +1265,7 @@ static ssize_t clkpm_show(struct device *dev, struct pci_dev *pdev = to_pci_dev(dev); struct pcie_link_state *link = pcie_aspm_get_link(pdev); - return sprintf(buf, "%d\n", link->clkpm_enabled); + return sysfs_emit(buf, "%d\n", link->clkpm_enabled); } static ssize_t clkpm_store(struct device *dev, -- 2.31.1
[PATCH v2 06/14] PCI/P2PDMA: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/p2pdma.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 196382630363..a1351b3e2c4c 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -53,7 +53,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr, if (pdev->p2pdma->pool) size = gen_pool_size(pdev->p2pdma->pool); - return scnprintf(buf, PAGE_SIZE, "%zd\n", size); + return sysfs_emit(buf, "%zd\n", size); } static DEVICE_ATTR_RO(size); @@ -66,7 +66,7 @@ static ssize_t available_show(struct device *dev, struct device_attribute *attr, if (pdev->p2pdma->pool) avail = gen_pool_avail(pdev->p2pdma->pool); - return scnprintf(buf, PAGE_SIZE, "%zd\n", avail); + return sysfs_emit(buf, "%zd\n", avail); } static DEVICE_ATTR_RO(available); @@ -75,8 +75,7 @@ static ssize_t published_show(struct device *dev, struct device_attribute *attr, { struct pci_dev *pdev = to_pci_dev(dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", -pdev->p2pdma->p2pmem_published); + return sysfs_emit(buf, "%d\n", pdev->p2pdma->p2pmem_published); } static DEVICE_ATTR_RO(published); -- 2.31.1
[PATCH v2 05/14] PCI/IOV: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/iov.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index afc06e6ce115..a71258347323 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -346,7 +346,7 @@ static ssize_t sriov_totalvfs_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); + return sysfs_emit(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); } static ssize_t sriov_numvfs_show(struct device *dev, @@ -361,7 +361,7 @@ static ssize_t sriov_numvfs_show(struct device *dev, num_vfs = pdev->sriov->num_VFs; device_unlock(>dev); - return sprintf(buf, "%u\n", num_vfs); + return sysfs_emit(buf, "%u\n", num_vfs); } /* @@ -435,7 +435,7 @@ static ssize_t sriov_offset_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->offset); + return sysfs_emit(buf, "%u\n", pdev->sriov->offset); } static ssize_t sriov_stride_show(struct device *dev, @@ -444,7 +444,7 @@ static ssize_t sriov_stride_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->stride); + return sysfs_emit(buf, "%u\n", pdev->sriov->stride); } static ssize_t sriov_vf_device_show(struct device *dev, @@ -453,7 +453,7 @@ static ssize_t sriov_vf_device_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%x\n", pdev->sriov->vf_device); + return sysfs_emit(buf, "%x\n", pdev->sriov->vf_device); } static ssize_t sriov_drivers_autoprobe_show(struct device *dev, @@ -462,7 +462,7 @@ static ssize_t sriov_drivers_autoprobe_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe); + return sysfs_emit(buf, "%u\n", pdev->sriov->drivers_autoprobe); } static ssize_t sriov_drivers_autoprobe_store(struct device *dev, -- 2.31.1
[PATCH v2 04/14] PCI/MSI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 217dc9f0231f..dbfec59dfe41 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -465,8 +465,8 @@ static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr, entry = irq_get_msi_desc(irq); if (entry) - return sprintf(buf, "%s\n", - entry->msi_attrib.is_msix ? "msix" : "msi"); + return sysfs_emit(buf, "%s\n", + entry->msi_attrib.is_msix ? "msix" : "msi"); return -ENODEV; } -- 2.31.1
[PATCH v2 03/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. Modify the function dsm_label_utf16s_to_utf8s() to directly return the number of bytes written into the buffer so that the strlen() used later to calculate the length of the buffer can be removed as it would no longer be needed. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-label.c | 18 ++ drivers/pci/slot.c | 16 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c index c32f3b7540e8..000e169c7197 100644 --- a/drivers/pci/pci-label.c +++ b/drivers/pci/pci-label.c @@ -139,14 +139,17 @@ enum acpi_attr_enum { ACPI_ATTR_INDEX_SHOW, }; -static void dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf) +static int dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf) { int len; + len = utf16s_to_utf8s((const wchar_t *)obj->buffer.pointer, obj->buffer.length, UTF16_LITTLE_ENDIAN, buf, PAGE_SIZE); buf[len] = '\n'; + + return len; } static int dsm_get_label(struct device *dev, char *buf, @@ -154,7 +157,7 @@ static int dsm_get_label(struct device *dev, char *buf, { acpi_handle handle = ACPI_HANDLE(dev); union acpi_object *obj, *tmp; - int len = -1; + int len = 0; if (!handle) return -1; @@ -175,20 +178,19 @@ static int dsm_get_label(struct device *dev, char *buf, * this entry must return a null string. */ if (attr == ACPI_ATTR_INDEX_SHOW) { - scnprintf(buf, PAGE_SIZE, "%llu\n", tmp->integer.value); + len = sysfs_emit(buf, "%llu\n", tmp->integer.value); } else if (attr == ACPI_ATTR_LABEL_SHOW) { if (tmp[1].type == ACPI_TYPE_STRING) - scnprintf(buf, PAGE_SIZE, "%s\n", - tmp[1].string.pointer); + len = sysfs_emit(buf, "%s\n", +tmp[1].string.pointer); else if (tmp[1].type == ACPI_TYPE_BUFFER) - dsm_label_utf16s_to_utf8s(tmp + 1, buf); + len = dsm_label_utf16s_to_utf8s(tmp + 1, buf); } - len = strlen(buf) > 0 ? strlen(buf) : -1; } ACPI_FREE(obj); - return len; + return len > 0 ? len : -1; } static ssize_t label_show(struct device *dev, struct device_attribute *attr, diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c index d627dd9179b4..7487e8f8f13f 100644 --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -39,19 +39,19 @@ static const struct sysfs_ops pci_slot_sysfs_ops = { static ssize_t address_read_file(struct pci_slot *slot, char *buf) { if (slot->number == 0xff) - return sprintf(buf, "%04x:%02x\n", - pci_domain_nr(slot->bus), - slot->bus->number); + return sysfs_emit(buf, "%04x:%02x\n", + pci_domain_nr(slot->bus), + slot->bus->number); else - return sprintf(buf, "%04x:%02x:%02x\n", - pci_domain_nr(slot->bus), - slot->bus->number, - slot->number); + return sysfs_emit(buf, "%04x:%02x:%02x\n", + pci_domain_nr(slot->bus), + slot->bus->number, + slot->number); } static ssize_t bus_speed_read(enum pci_bus_speed speed, char *buf) { - return sprintf(buf, "%s\n", pci_speed_string(speed)); + return sysfs_emit(buf, "%s\n", pci_speed_string(speed)); } static ssize_t max_speed_read_file(struct pci_slot *slot, char *buf) -- 2.31.1
[PATCH v2 02/14] PCI/AER: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pcie/aer.c | 20 +++- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index ec943cee5ecc..40ef7bed7a77 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -529,21 +529,23 @@ static const char *aer_agent_string[] = { char *buf) \ { \ unsigned int i; \ - char *str = buf;\ struct pci_dev *pdev = to_pci_dev(dev); \ u64 *stats = pdev->aer_stats->stats_array; \ + size_t len = 0; \ \ for (i = 0; i < ARRAY_SIZE(strings_array); i++) { \ if (strings_array[i]) \ - str += sprintf(str, "%s %llu\n",\ - strings_array[i], stats[i]); \ + len += sysfs_emit_at(buf, len, "%s %llu\n", \ +strings_array[i], \ +stats[i]); \ else if (stats[i]) \ - str += sprintf(str, #stats_array "_bit[%d] %llu\n",\ - i, stats[i]);\ + len += sysfs_emit_at(buf, len, \ +#stats_array "_bit[%d] %llu\n",\ +i, stats[i]); \ } \ - str += sprintf(str, "TOTAL_%s %llu\n", total_string,\ - pdev->aer_stats->total_field); \ - return str-buf; \ + len += sysfs_emit_at(buf, len, "TOTAL_%s %llu\n", total_string, \ +pdev->aer_stats->total_field); \ + return len; \ } \ static DEVICE_ATTR_RO(name) @@ -563,7 +565,7 @@ aer_stats_dev_attr(aer_dev_nonfatal, dev_nonfatal_errs, char *buf) \ { \ struct pci_dev *pdev = to_pci_dev(dev); \ - return sprintf(buf, "%llu\n", pdev->aer_stats->field); \ + return sysfs_emit(buf, "%llu\n", pdev->aer_stats->field); \ } \ static DEVICE_ATTR_RO(name) -- 2.31.1
[PATCH v2 01/14] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions
The sysfs_emit() and sysfs_emit_at() functions were introduced to make it less ambiguous which function is preferred when writing to the output buffer in a device attribute's "show" callback [1]. Convert the PCI sysfs object "show" functions from sprintf(), snprintf() and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly returns the number of bytes written into the buffer. No functional change intended. [1] Documentation/filesystems/sysfs.rst Related to: commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions") Signed-off-by: Krzysztof Wilczyński Reviewed-by: Logan Gunthorpe --- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b717680377a9..5ed316ea5831 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6439,7 +6439,7 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) spin_lock(_alignment_lock); if (resource_alignment_param) - count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param); + count = sysfs_emit(buf, "%s", resource_alignment_param); spin_unlock(_alignment_lock); /* -- 2.31.1
Re: [PATCH] arm64: Define only {pud/pmd}_{set/clear}_huge when usefull
On Fri, May 14, 2021 at 02:42:00PM -0700, Andrew Morton wrote: > On Fri, 14 May 2021 11:08:53 + (UTC) Christophe Leroy > wrote: > > > When PUD and/or PMD are folded, those functions are useless > > and we now have a stub in linux/pgtable.h > > OK, help me out here please. What patch does this fix? > Naresh's original report is here it seems: https://lore.kernel.org/r/ca+g9fyv79t0+2w4rt3wdkbshc4ey3m3utc5bhquggdwmyex...@mail.gmail.com/ I can reproduce the failure that he reported with ARCH=arm64 allmodconfig and this patch resolves it for me. Cheers, Nathan
[powerpc:next-test] BUILD SUCCESS 4572be3694e6e0f9ee6b669df8e4b5bbc040791e
allyesconfig sparcallyesconfig sparc defconfig i386defconfig mips allyesconfig mips allmodconfig powerpc allyesconfig powerpc allmodconfig powerpc allnoconfig x86_64 randconfig-a004-20210514 x86_64 randconfig-a003-20210514 x86_64 randconfig-a001-20210514 x86_64 randconfig-a005-20210514 x86_64 randconfig-a002-20210514 x86_64 randconfig-a006-20210514 i386 randconfig-a003-20210514 i386 randconfig-a001-20210514 i386 randconfig-a004-20210514 i386 randconfig-a005-20210514 i386 randconfig-a002-20210514 i386 randconfig-a006-20210514 x86_64 randconfig-a012-20210515 x86_64 randconfig-a015-20210515 x86_64 randconfig-a011-20210515 x86_64 randconfig-a013-20210515 x86_64 randconfig-a016-20210515 x86_64 randconfig-a014-20210515 i386 randconfig-a016-20210515 i386 randconfig-a014-20210515 i386 randconfig-a011-20210515 i386 randconfig-a012-20210515 i386 randconfig-a015-20210515 i386 randconfig-a013-20210515 i386 randconfig-a016-20210514 i386 randconfig-a014-20210514 i386 randconfig-a011-20210514 i386 randconfig-a012-20210514 i386 randconfig-a015-20210514 i386 randconfig-a013-20210514 riscvnommu_k210_defconfig riscvallyesconfig riscvnommu_virt_defconfig riscv allnoconfig riscvallmodconfig um allmodconfig umallnoconfig um allyesconfig x86_64 allyesconfig x86_64rhel-8.3-kselftests x86_64 defconfig x86_64 rhel-8.3 x86_64 rhel-8.3-kbuiltin x86_64 kexec clang tested configs: x86_64 randconfig-a004-20210515 x86_64 randconfig-a003-20210515 x86_64 randconfig-a001-20210515 x86_64 randconfig-a005-20210515 x86_64 randconfig-a002-20210515 x86_64 randconfig-a006-20210515 x86_64 randconfig-a015-20210514 x86_64 randconfig-a012-20210514 x86_64 randconfig-a011-20210514 x86_64 randconfig-a013-20210514 x86_64 randconfig-a016-20210514 x86_64 randconfig-a014-20210514 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org
[powerpc:merge] BUILD SUCCESS b68d19e1abdbafef9481c7c0b0bcaff34d7af17d
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git merge branch HEAD: b68d19e1abdbafef9481c7c0b0bcaff34d7af17d Automatic merge of 'master' into merge (2021-05-10 08:23) elapsed time: 723m configs tested: 109 configs skipped: 3 The following configs have been built successfully. More configs may be tested in the coming days. gcc tested configs: arm defconfig arm64allyesconfig arm64 defconfig arm allyesconfig arm allmodconfig mips rm200_defconfig arm pxa255-idp_defconfig armmini2440_defconfig powerpc eiger_defconfig xtensa cadence_csp_defconfig powerpc ps3_defconfig m68km5307c3_defconfig m68k m5275evb_defconfig arm iop32x_defconfig powerpc mpc8315_rdb_defconfig sh landisk_defconfig m68k amcore_defconfig shapsh4ad0a_defconfig armkeystone_defconfig um alldefconfig shedosk7705_defconfig arm imx_v4_v5_defconfig powerpc tqm5200_defconfig sh sh7770_generic_defconfig h8300 defconfig shsh7785lcr_defconfig arc defconfig m68k m5249evb_defconfig m68k sun3_defconfig powerpc mpc512x_defconfig openrisc simple_smp_defconfig mips ip22_defconfig arc axs101_defconfig m68k hp300_defconfig powerpc wii_defconfig riscv rv32_defconfig xtensa nommu_kc705_defconfig x86_64allnoconfig ia64 allmodconfig ia64defconfig ia64 allyesconfig m68k allmodconfig m68kdefconfig m68k allyesconfig nds32 defconfig nios2allyesconfig cskydefconfig alpha defconfig alphaallyesconfig xtensa allyesconfig h8300allyesconfig sh allmodconfig parisc defconfig s390 allyesconfig s390 allmodconfig parisc allyesconfig s390defconfig i386 allyesconfig sparcallyesconfig sparc defconfig i386defconfig nios2 defconfig arc allyesconfig nds32 allnoconfig mips allyesconfig mips allmodconfig powerpc allyesconfig powerpc allmodconfig powerpc allnoconfig x86_64 randconfig-a004-20210514 x86_64 randconfig-a003-20210514 x86_64 randconfig-a001-20210514 x86_64 randconfig-a005-20210514 x86_64 randconfig-a002-20210514 x86_64 randconfig-a006-20210514 i386 randconfig-a003-20210514 i386 randconfig-a001-20210514 i386 randconfig-a004-20210514 i386 randconfig-a005-20210514 i386 randconfig-a002-20210514 i386 randconfig-a006-20210514 i386 randconfig-a016-20210514 i386 randconfig-a014-20210514 i386 randconfig-a011-20210514 i386 randconfig-a012-20210514 i386 randconfig-a015-20210514 i386 randconfig-a013-20210514 riscvnommu_k210_defconfig riscvallyesconfig riscvnommu_virt_defconfig riscv allnoconfig riscv defconfig riscvallmodconfig um allmodconfig umallnoconfig um allyesconfig um defconfig x86_64 allyesconfig x86_64rhel-8.3-kselftests x86_64 defconfig x86_64
[powerpc:fixes-test] BUILD SUCCESS c6ac667b07996929835b512de0e9a988977e6abc
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git fixes-test branch HEAD: c6ac667b07996929835b512de0e9a988977e6abc powerpc/64e/interrupt: Fix nvgprs being clobbered elapsed time: 726m configs tested: 114 configs skipped: 31 The following configs have been built successfully. More configs may be tested in the coming days. gcc tested configs: arm defconfig arm64allyesconfig arm64 defconfig arm allyesconfig arm allmodconfig mips rm200_defconfig arm pxa255-idp_defconfig armmini2440_defconfig powerpc eiger_defconfig xtensa cadence_csp_defconfig powerpc ps3_defconfig m68km5307c3_defconfig m68k m5275evb_defconfig arm iop32x_defconfig powerpc mpc8315_rdb_defconfig sh landisk_defconfig m68k amcore_defconfig shapsh4ad0a_defconfig armkeystone_defconfig um alldefconfig shedosk7705_defconfig arm davinci_all_defconfig mips tb0219_defconfig sh sh2007_defconfig m68km5272c3_defconfig powerpc mpc836x_mds_defconfig arm imx_v4_v5_defconfig powerpc tqm5200_defconfig sh sh7770_generic_defconfig h8300 defconfig shsh7785lcr_defconfig arc defconfig m68k m5249evb_defconfig m68k sun3_defconfig powerpc mpc512x_defconfig openrisc simple_smp_defconfig mips ip22_defconfig arc axs101_defconfig m68k hp300_defconfig powerpc wii_defconfig riscv rv32_defconfig xtensa nommu_kc705_defconfig x86_64allnoconfig ia64 allmodconfig ia64defconfig ia64 allyesconfig m68k allmodconfig m68kdefconfig m68k allyesconfig nds32 defconfig nios2allyesconfig cskydefconfig alpha defconfig alphaallyesconfig nios2 defconfig arc allyesconfig nds32 allnoconfig xtensa allyesconfig h8300allyesconfig sh allmodconfig parisc defconfig s390 allyesconfig s390 allmodconfig parisc allyesconfig s390defconfig i386 allyesconfig sparcallyesconfig sparc defconfig i386defconfig mips allyesconfig mips allmodconfig powerpc allyesconfig powerpc allmodconfig powerpc allnoconfig i386 randconfig-a003-20210514 i386 randconfig-a001-20210514 i386 randconfig-a004-20210514 i386 randconfig-a005-20210514 i386 randconfig-a002-20210514 i386 randconfig-a006-20210514 x86_64 randconfig-a004-20210514 x86_64 randconfig-a003-20210514 x86_64 randconfig-a001-20210514 x86_64 randconfig-a005-20210514 x86_64 randconfig-a002-20210514 x86_64 randconfig-a006-20210514 i386 randconfig-a016-20210514 i386 randconfig-a014-20210514 i386 randconfig-a011-20210514 i386 randconfig-a012-20210514 i386 randconfig-a015-20210514 i386 randconfig-a013-20210514 riscvnommu_k210_defconfig riscvallyesconfig riscvnommu_virt_defconfig riscv allnoconfig riscv defconfig riscvallmodconfig um allmodconfig umallnoconfig um
Re: [PATCH] lockdown,selinux: fix bogus SELinux lockdown permission checks
On 5/14/2021 8:12 AM, Ondrej Mosnacek wrote: > On Wed, May 12, 2021 at 7:12 PM Casey Schaufler > wrote: >> On 5/12/2021 9:44 AM, Ondrej Mosnacek wrote: >>> On Wed, May 12, 2021 at 6:18 PM Casey Schaufler >>> wrote: On 5/12/2021 6:21 AM, Ondrej Mosnacek wrote: > On Sat, May 8, 2021 at 12:17 AM Casey Schaufler > wrote: >> On 5/7/2021 4:40 AM, Ondrej Mosnacek wrote: >>> Commit 59438b46471a ("security,lockdown,selinux: implement SELinux >>> lockdown") added an implementation of the locked_down LSM hook to >>> SELinux, with the aim to restrict which domains are allowed to perform >>> operations that would breach lockdown. >>> >>> However, in several places the security_locked_down() hook is called in >>> situations where the current task isn't doing any action that would >>> directly breach lockdown, leading to SELinux checks that are basically >>> bogus. >>> >>> Since in most of these situations converting the callers such that >>> security_locked_down() is called in a context where the current task >>> would be meaningful for SELinux is impossible or very non-trivial (and >>> could lead to TOCTOU issues for the classic Lockdown LSM >>> implementation), fix this by adding a separate hook >>> security_locked_down_globally() >> This is a poor solution to the stated problem. Rather than adding >> a new hook you should add the task as a parameter to the existing hook >> and let the security modules do as they will based on its value. >> If the caller does not have an appropriate task it should pass NULL. >> The lockdown LSM can ignore the task value and SELinux can make its >> own decision based on the task value passed. > The problem with that approach is that all callers would then need to > be updated and I intended to keep the patch small as I'd like it to go > to stable kernels as well. > > But it does seem to be a better long-term solution - would it work for > you (and whichever maintainer would be taking the patch(es)) if I just > added another patch that refactors it to use the task parameter? I can't figure out what you're suggesting. Are you saying that you want to add a new hook *and* add the task parameter? >>> No, just to keep this patch as-is (and let it go to stable in this >>> form) and post another (non-stable) patch on top of it that undoes the >>> new hook and re-implements the fix using your suggestion. (Yeah, it'll >>> look weird, but I'm not sure how better to handle such situation - I'm >>> open to doing it whatever different way the maintainers prefer.) >> James gets to make the call on this one. If it was my call I would >> tell you to make the task parameter change and accept the backport >> pain. I think that as a security developer community we spend way too >> much time and effort trying to avoid being noticed in source trees. > Hm... actually, what about this attached patch? It switches to a > single hook with a cred argument (I figured cred makes more sense than > task_struct, since the rest of task_struct should be irrelevant for > the LSM, anyway...) right from the start and keeps the original > security_locked_down() function only as a simple wrapper around the > main hook. > > At that point I think converting the other callers to call > security_cred_locked_down() directly isn't really worth it, since the > resulting calls would just be more verbose without much benefit. So > I'm tempted to just leave the security_locked_down() helper as is, so > that the more common pattern can be still achieved with a simpler > call. > > What do you think? It's still a bit kludgy, but a big improvement over the previous version. I wouldn't object to this approach. > > -- > Ondrej Mosnacek > Software Engineer, Linux Security - SELinux kernel > Red Hat, Inc.
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On 5/14/21 12:22 PM, Linus Torvalds wrote: > On Fri, May 14, 2021 at 11:52 AM Vineet Gupta > wrote: >> Wasn't the new zlib code slated for 5.14. I don't see it in your master yet > You're right, I never actually committed it, since it was specific to > ARC and -O3 Well, not really, the issue manifested in ARC O3 testing, but I showed the problem existed for arm64 gcc too. > and I wasn't entirely happy with the amount of testing it > got (with Heiko pointing out that the s390 stuff needed more fixes for > the change). With his addon patch everything seemed hunky dory. > The patch below is required on top of your patch to make it compile > for s390 as well. > Tested with kernel image decompression, and also btrfs with file > compression; both software and hardware compression. > Everything seems to work. > So in fact it's not even queued up for 5.14 due to this all, I just dropped > it. But Why. Can't we throw it in linux-next for 5.14. I promise to test it - and will likely hit any corner cases. Also for the time being we could force just that file/files to build for -O3 to stress test the aspects that were fragile. >>>and the biggy >>> case didn't even use "get_unaligned()"). >> Indeed this series is sort of orthogonal to that bug, but IMO that bug >> still exists in 5.13 for -O3 build, granted that is not enabled for !ARC. > Right, the zlib bug is still there. > > But Arnd's series wouldn't even fix it: right now inffast has its own > - ugly and slow - special 2-byte-only version of "get_unaligned()", > called "get_unaligned16()". I know that's why said they are orthogonal. > And because it's ugly and slow, it's not actually used for > CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. > > Vineet - maybe the fix is to not take my patch to update to a newer > zlib, but to just fix inffast to use the proper get_unaligned(). Then > Arnd's series _would_ actually fix all this.. OK if you say so. -Vineet
[Bug 213069] New: kernel BUG at arch/powerpc/include/asm/book3s/64/hash-4k.h:147! Oops: Exception in kernel mode, sig: 5 [#1]
https://bugzilla.kernel.org/show_bug.cgi?id=213069 Bug ID: 213069 Summary: kernel BUG at arch/powerpc/include/asm/book3s/64/hash-4k.h:147! Oops: Exception in kernel mode, sig: 5 [#1] Product: Platform Specific/Hardware Version: 2.5 Kernel Version: 5.13-rc1 Hardware: PPC-64 OS: Linux Tree: Mainline Status: NEW Severity: normal Priority: P1 Component: PPC-64 Assignee: platform_ppc...@kernel-bugs.osdl.org Reporter: erhar...@mailbox.org Regression: No Created attachment 296753 --> https://bugzilla.kernel.org/attachment.cgi?id=296753=edit kernel .config (5.13-rc1, PowerMac G5 11,2) Got this on my PowerMac G5 11,2 with v5.13-rc1 + few debug options on. The bug was too early for netconsole to kick in so I took a photo and transcribed it. [...] kmemleak: Kernel memory leak detector initialized (mem pool available: 15805) kmemleak: Automatic memory scanning thread started debug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers [ cut here ] kernel BUG at arch/powerpc/include/asm/book3s/64/hash-4k.h:147! Oops: Exception in kernel mode, sig: 5 [#1] BE PAGE_SIZE=4K MMU=Hash SMP NR_CPUS=4 NUMA PowerMac Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Tainted: GW 5.13.0-rc1-PowerMacG5 #2 NIP: c003d6fc LR: c1024bc8 CTR: c00f778c REGS: c25f7840 TRAP: 0700 Tainted: GW (5.13.0-rc1-PowerMacG5) MSR: 90029032 CR: 44002448 XER: IRQMASK: 0 GPR00: c1024a5c c25f7ae0 c129f800 c25f7b58 GPR04: 1000 8108 0001 GPR08: 0008 0200 GPR12: 24002440 c2366000 c001003c GPR16: GPR20: c11b3388 c0b013e8 c11b3108 4006 GPR24: 4280 011b3000 8105 GPR28: 1000 ff7f c0b01460 811b3108 NIP [c003d6fc] .pfn_pmd+x0x/0x4 LR [c1024bc8] .debug_vm_pgtable+0x3f4/0x51c Call Trace: [c25f7ae0] [c1024a5c] .debug_vm_pgtable+0x288/0x51c (unreliable) [c25f7bd0] [c000fa58] .do_one_initcall+0x104/0x2c4 [c25f7cb0] [c1003dec] .kernel_init_freeable+0x3d4/0x410 [c25f7da0] [c001004c] .kernel_init+0x10/0x15c [c25f7e10] [c000bbf4] .ret_from_kernel_thread+0x58/0x64 Instruction dump: 4bffcd05 6000 e9210078 e94d0370 7d295279 3940 4182000c 487d3829 6000 38210090 7fe3fb78 487dacf4 <0fe0> 7c0802a6 f8010010 f821ff71 ---[ end trace 21fc0fb84dac9a9b ]--- Kernel panic - not syncing: Attempted to kill init! exitcode=0x0005 Rebooting in 120 seconds.. -- You may reply to this email to add a comment. You are receiving this mail because: You are watching the assignee of the bug.
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On 5/14/21 10:32 AM, Linus Torvalds wrote: > On Fri, May 14, 2021 at 3:02 AM Arnd Bergmann wrote: >> I've included this version in the asm-generic tree for 5.14 already, >> addressing the few issues that were pointed out in the RFC. If there >> are any remaining problems, I hope those can be addressed as follow-up >> patches. > This continues to look great to me, and now has the even simpler > remaining implementation. > > I'd be tempted to just pull it in for 5.13, but I guess we don't > actually have any _outstanding_ bug in this area (the bug was in our > zlib code, required -O3 to trigger, has been fixed now, Wasn't the new zlib code slated for 5.14. I don't see it in your master yet > and the biggy > case didn't even use "get_unaligned()"). Indeed this series is sort of orthogonal to that bug, but IMO that bug still exists in 5.13 for -O3 build, granted that is not enabled for !ARC. -Vineet > > So I guess your 5.14 timing is the right thing to do. > > Linus
[PATCH] powerpc/udbg_hvc: retry putc on -EAGAIN
hvterm_raw_put_chars() calls hvc_put_chars(), which may return -EAGAIN when the underlying hcall returns a "busy" status, but udbg_hvc_putc() doesn't handle this. When using xmon on a PowerVM guest, this can result in incomplete or garbled output when printing relatively large amounts of data quickly, such as when dumping the kernel log buffer. Call again on -EAGAIN. Signed-off-by: Nathan Lynch --- drivers/tty/hvc/hvc_vio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c index 798f27f40cc2..76d2a7038095 100644 --- a/drivers/tty/hvc/hvc_vio.c +++ b/drivers/tty/hvc/hvc_vio.c @@ -249,7 +249,7 @@ static void udbg_hvc_putc(char c) count = hvterm_hvsi_put_chars(0, , 1); break; } - } while(count == 0); + } while(count == 0 || count == -EAGAIN); } static int udbg_hvc_getc_poll(void) -- 2.30.2
Re: [PATCH] arm64: Define only {pud/pmd}_{set/clear}_huge when usefull
On Fri, 14 May 2021 11:08:53 + (UTC) Christophe Leroy wrote: > When PUD and/or PMD are folded, those functions are useless > and we now have a stub in linux/pgtable.h OK, help me out here please. What patch does this fix?
Re: [PATCH -next] powerpc/pseries/memhotplug: Remove unused inline function dlpar_memory_remove()
On 5/14/21 4:10 AM, YueHaibing wrote: dlpar_memory_remove() is never used, so can be removed. Signed-off-by: YueHaibing --- Reviewed-by: Daniel Henrique Barboza arch/powerpc/platforms/pseries/hotplug-memory.c | 4 1 file changed, 4 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 8377f1f7c78e..3d93f1c48e23 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -585,10 +585,6 @@ static inline int pseries_remove_mem_node(struct device_node *np) { return 0; } -static inline int dlpar_memory_remove(struct pseries_hp_errorlog *hp_elog) -{ - return -EOPNOTSUPP; -} static int dlpar_remove_lmb(struct drmem_lmb *lmb) { return -EOPNOTSUPP;
Re: [PATCH 15/31] KVM: PPC: Book3S HV: XIVE: Fix mapping of passthrough interrupts
On Fri, Apr 30 2021 at 10:03, Cédric Le Goater wrote: CC: +Marc > PCI MSI interrupt numbers are now mapped in a PCI-MSI domain but the > underlying calls handling the passthrough of the interrupt in the > guest need a number in the XIVE IRQ domain. > > Use the IRQ data mapped in the XIVE IRQ domain and not the one in the > PCI-MSI domain. > > Exporting irq_get_default_host() might not be the best solution. > > Cc: Thomas Gleixner > Cc: Paul Mackerras > Signed-off-by: Cédric Le Goater > --- > arch/powerpc/kvm/book3s_xive.c | 3 ++- > kernel/irq/irqdomain.c | 1 + > 2 files changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c > index 3a7da42bed57..81b9f4fc3978 100644 > --- a/arch/powerpc/kvm/book3s_xive.c > +++ b/arch/powerpc/kvm/book3s_xive.c > @@ -861,7 +861,8 @@ int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long > guest_irq, > struct kvmppc_xive *xive = kvm->arch.xive; > struct kvmppc_xive_src_block *sb; > struct kvmppc_xive_irq_state *state; > - struct irq_data *host_data = irq_get_irq_data(host_irq); > + struct irq_data *host_data = > + irq_domain_get_irq_data(irq_get_default_host(), host_irq); > unsigned int hw_irq = (unsigned int)irqd_to_hwirq(host_data); > u16 idx; > u8 prio; > diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c > index d10ab1d689d5..8a073d1ce611 100644 > --- a/kernel/irq/irqdomain.c > +++ b/kernel/irq/irqdomain.c > @@ -481,6 +481,7 @@ struct irq_domain *irq_get_default_host(void) > { > return irq_default_domain; > } > +EXPORT_SYMBOL_GPL(irq_get_default_host); > > static void irq_domain_clear_mapping(struct irq_domain *domain, >irq_hw_number_t hwirq)
Re: [PATCH 31/31] genirq: Improve "hwirq" output in /proc and /sys/
On Fri, Apr 30 2021 at 10:04, Cédric Le Goater wrote: > The HW IRQ numbers generated by the PCI MSI layer can be quite large > on a pSeries machine when running under the IBM Hypervisor and they > appear as negative. Use '%u' to show them correctly. > > Cc: Thomas Gleixner > Signed-off-by: Cédric Le Goater > --- > kernel/irq/irqdesc.c | 2 +- > kernel/irq/proc.c| 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c > index cc1a09406c6e..85054eb2ae51 100644 > --- a/kernel/irq/irqdesc.c > +++ b/kernel/irq/irqdesc.c > @@ -188,7 +188,7 @@ static ssize_t hwirq_show(struct kobject *kobj, > > raw_spin_lock_irq(>lock); > if (desc->irq_data.domain) > - ret = sprintf(buf, "%d\n", (int)desc->irq_data.hwirq); > + ret = sprintf(buf, "%u\n", (int)desc->irq_data.hwirq); Which makes the (int) cast pointless, right? > raw_spin_unlock_irq(>lock); > > return ret; > diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c > index 98138788cb04..e2392f05da04 100644 > --- a/kernel/irq/proc.c > +++ b/kernel/irq/proc.c > @@ -513,7 +513,7 @@ int show_interrupts(struct seq_file *p, void *v) > seq_printf(p, " %8s", "None"); > } > if (desc->irq_data.domain) > - seq_printf(p, " %*d", prec, (int) desc->irq_data.hwirq); > + seq_printf(p, " %*u", prec, (int)desc->irq_data.hwirq); ditto. Thanks, tglx
Re: [PATCH 07/31] powerpc/xive: Fix xive_irq_set_affinity for MSI
On Fri, Apr 30 2021 at 10:03, Cédric Le Goater wrote: > The MSI affinity is automanaged and it can be set before starting the > associated IRQ. > > ( Should we simply remove the irqd_is_started() test ? ) If the hardware can handle it properly. But see: cffb717ceb8e ("powerpc/xive: Ensure active irqd when setting affinity") which introduced that condition. It mutters something about migration of shutdown interrupts: [ 123.053037264,3] XIVE[ IC 00 ] ISN 2 lead to invalid IVE ! [ 77.885859] xive: Error -6 reconfiguring irq 17 [ 77.885862] IRQ17: set affinity failed(-6). Not that I can decode that :) Non-managed interrupts have the sequence: startup() set_affinity() which is historical and an earlier attempt to flip it caused havoc in some places. With managed we needed to make sure that the affinity is set correctly right at start. So it needs to be done the other way round and it turned out that for MSI this works. I have no idea, whether that might make the above issue reappear or not. If so, then we need some extra state to make it work. The root cause which triggered the problem got fixed, so there should be no issue _if_ this was specifically related to that CPU unplug case. > diff --git a/arch/powerpc/sysdev/xive/common.c > b/arch/powerpc/sysdev/xive/common.c > index 96737938e8e3..3485baf9ec8c 100644 > --- a/arch/powerpc/sysdev/xive/common.c > +++ b/arch/powerpc/sysdev/xive/common.c > @@ -710,7 +710,7 @@ static int xive_irq_set_affinity(struct irq_data *d, > return -EINVAL; > > /* Don't do anything if the interrupt isn't started */ > - if (!irqd_is_started(d)) > + if (!irqd_is_started(d) && !irqd_affinity_is_managed(d)) > return IRQ_SET_MASK_OK; > > /* Thanks, tglx
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On Fri, May 14, 2021 at 12:45 PM Vineet Gupta wrote: > > Well, not really, the issue manifested in ARC O3 testing, but I showed > the problem existed for arm64 gcc too. .. but not with a supported kernel configuration. > > So in fact it's not even queued up for 5.14 due to this all, I just dropped > > it. > > But Why. I just didn't have time to deal with it during the merge window. If you keep it alive, that's all fine and good. Linus
Re: [PATCH v3] powerpc/64: Option to use ELFv2 ABI for big-endian kernels
On Wed, May 05, 2021 at 10:07:29PM +1000, Michael Ellerman wrote: > Michal Suchánek writes: > > On Mon, May 03, 2021 at 01:37:57PM +0200, Andreas Schwab wrote: > >> Should this add a tag to the module vermagic? > > > > Would the modues link even if the vermagic was not changed? > > Most modules will require some symbols from the kernel, and those will > be dot symbols, which won't resolve. > > But there are a few small modules that don't rely on any kernel symbols, > which can load. > > > I suppose something like this might do it. > > It would, but I feel like we should be handling this at the ELF level. > ie. we don't allow loading modules with a different ELF machine type, so > neither should we allow loading a module with the wrong ELF ABI. > > And you can build the kernel without MODVERSIONS, so relying on > MODVERSIONS still leaves a small exposure (same kernel version > with/without ELFv2). > > I don't see an existing hook that would do what we want. There's > elf_check_arch(), but that also applies to userspace binaries, which is > not what we want. > > Maybe something like below. The below patch works for me. Tested-by: Michal Suchánek Built a Hello World module for both v1 and v2 ABI, and kernels built with v1 and v2 ABI rejected module with the other ABI. [ 100.602943] Module has invalid ELF structures insmod: ERROR: could not insert module moin_v1.ko: Invalid module format Thanks Michal > > cheers > > > diff --git a/arch/powerpc/include/asm/module.h > b/arch/powerpc/include/asm/module.h > index 857d9ff24295..d0e9368982d8 100644 > --- a/arch/powerpc/include/asm/module.h > +++ b/arch/powerpc/include/asm/module.h > @@ -83,5 +83,28 @@ static inline int module_finalize_ftrace(struct module > *mod, const Elf_Shdr *sec > } > #endif > > +#ifdef CONFIG_PPC64 > +static inline bool elf_check_module_arch(Elf_Ehdr *hdr) > +{ > + unsigned long flags; > + > + if (!elf_check_arch(hdr)) > + return false; > + > + flags = hdr->e_flags & 0x3; > + > +#ifdef CONFIG_PPC64_BUILD_ELF_V2_ABI > + if (flags == 2) > + return true; > +#else > + if (flags < 2) > + return true; > +#endif > + return false; > +} > + > +#define elf_check_module_arch elf_check_module_arch > +#endif /* CONFIG_PPC64 */ > + > #endif /* __KERNEL__ */ > #endif /* _ASM_POWERPC_MODULE_H */ > diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h > index 9e09d11ffe5b..fdc042a84562 100644 > --- a/include/linux/moduleloader.h > +++ b/include/linux/moduleloader.h > @@ -13,6 +13,11 @@ > * must be implemented by each architecture. > */ > > +// Allow arch to optionally do additional checking of module ELF header > +#ifndef elf_check_module_arch > +#define elf_check_module_arch elf_check_arch > +#endif > + > /* Adjust arch-specific sections. Return 0 on success. */ > int module_frob_arch_sections(Elf_Ehdr *hdr, > Elf_Shdr *sechdrs, > diff --git a/kernel/module.c b/kernel/module.c > index b5dd92e35b02..c71889107226 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -2941,7 +2941,7 @@ static int elf_validity_check(struct load_info *info) > > if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0 > || info->hdr->e_type != ET_REL > - || !elf_check_arch(info->hdr) > + || !elf_check_module_arch(info->hdr) > || info->hdr->e_shentsize != sizeof(Elf_Shdr)) > return -ENOEXEC; >
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On Fri, May 14, 2021 at 7:32 PM Linus Torvalds wrote: > > On Fri, May 14, 2021 at 3:02 AM Arnd Bergmann wrote: > > > > I've included this version in the asm-generic tree for 5.14 already, > > addressing the few issues that were pointed out in the RFC. If there > > are any remaining problems, I hope those can be addressed as follow-up > > patches. > > This continues to look great to me, and now has the even simpler > remaining implementation. > > I'd be tempted to just pull it in for 5.13, but I guess we don't > actually have any _outstanding_ bug in this area (the bug was in our > zlib code, required -O3 to trigger, has been fixed now, and the biggy > case didn't even use "get_unaligned()"). > > So I guess your 5.14 timing is the right thing to do. Yes, I think that's best, just in case something does come up. While all the object code I looked at does appear better, this is one of those areas that can be hard to pinpoint if we hit a regression in a particular combination of architecture+compiler+source file. I have pushed a signed tag to https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git asm-generic-unaligned-5.14 and plan to send that in the 5.14 merge window unless you decide to take it now after all. Arnd
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On Fri, May 14, 2021 at 11:52 AM Vineet Gupta wrote: > > Wasn't the new zlib code slated for 5.14. I don't see it in your master yet You're right, I never actually committed it, since it was specific to ARC and -O3 and I wasn't entirely happy with the amount of testing it got (with Heiko pointing out that the s390 stuff needed more fixes for the change). So in fact it's not even queued up for 5.14 due to this all, I just dropped it. > > and the biggy > > case didn't even use "get_unaligned()"). > > Indeed this series is sort of orthogonal to that bug, but IMO that bug > still exists in 5.13 for -O3 build, granted that is not enabled for !ARC. Right, the zlib bug is still there. But Arnd's series wouldn't even fix it: right now inffast has its own - ugly and slow - special 2-byte-only version of "get_unaligned()", called "get_unaligned16()". And because it's ugly and slow, it's not actually used for CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. Vineet - maybe the fix is to not take my patch to update to a newer zlib, but to just fix inffast to use the proper get_unaligned(). Then Arnd's series _would_ actually fix all this.. Linus
Re: [PATCH v2 00/13] Unify asm/unaligned.h around struct helper
On Fri, May 14, 2021 at 3:02 AM Arnd Bergmann wrote: > > I've included this version in the asm-generic tree for 5.14 already, > addressing the few issues that were pointed out in the RFC. If there > are any remaining problems, I hope those can be addressed as follow-up > patches. This continues to look great to me, and now has the even simpler remaining implementation. I'd be tempted to just pull it in for 5.13, but I guess we don't actually have any _outstanding_ bug in this area (the bug was in our zlib code, required -O3 to trigger, has been fixed now, and the biggy case didn't even use "get_unaligned()"). So I guess your 5.14 timing is the right thing to do. Linus
[PATCH] powerpc/xmon: make dumping log buffer contents more reliable
Log buffer entries that are too long for dump_log_buf()'s small local buffer are: * silently discarded when a single-line entry is too long; kmsg_dump_get_line() returns true but sets to 0. * silently truncated to the last fitting new line when a multi-line entry is too long, e.g. register dumps from __show_regs(); this seems undetectable via the kmsg_dump API. xmon_printf()'s internal buffer is already 1KB; enlarge dump_log_buf()'s own buffer to match and make it statically allocated. Verified that this allows complete printing of register dumps on ppc64le with both CONFIG_PRINTK_TIME=y and CONFIG_PRINTK_CALLER=y. Signed-off-by: Nathan Lynch --- arch/powerpc/xmon/xmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index c8173e92f19d..f73c10869e64 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -2975,7 +2975,7 @@ static void dump_log_buf(void) { struct kmsg_dump_iter iter; - unsigned char buf[128]; + static unsigned char buf[1024]; size_t len; if (setjmp(bus_error_jmp) != 0) { -- 2.30.2
Re: [PATCH] lockdown, selinux: fix bogus SELinux lockdown permission checks
On Wed, May 12, 2021 at 7:12 PM Casey Schaufler wrote: > > On 5/12/2021 9:44 AM, Ondrej Mosnacek wrote: > > On Wed, May 12, 2021 at 6:18 PM Casey Schaufler > > wrote: > >> On 5/12/2021 6:21 AM, Ondrej Mosnacek wrote: > >>> On Sat, May 8, 2021 at 12:17 AM Casey Schaufler > >>> wrote: > On 5/7/2021 4:40 AM, Ondrej Mosnacek wrote: > > Commit 59438b46471a ("security,lockdown,selinux: implement SELinux > > lockdown") added an implementation of the locked_down LSM hook to > > SELinux, with the aim to restrict which domains are allowed to perform > > operations that would breach lockdown. > > > > However, in several places the security_locked_down() hook is called in > > situations where the current task isn't doing any action that would > > directly breach lockdown, leading to SELinux checks that are basically > > bogus. > > > > Since in most of these situations converting the callers such that > > security_locked_down() is called in a context where the current task > > would be meaningful for SELinux is impossible or very non-trivial (and > > could lead to TOCTOU issues for the classic Lockdown LSM > > implementation), fix this by adding a separate hook > > security_locked_down_globally() > This is a poor solution to the stated problem. Rather than adding > a new hook you should add the task as a parameter to the existing hook > and let the security modules do as they will based on its value. > If the caller does not have an appropriate task it should pass NULL. > The lockdown LSM can ignore the task value and SELinux can make its > own decision based on the task value passed. > >>> The problem with that approach is that all callers would then need to > >>> be updated and I intended to keep the patch small as I'd like it to go > >>> to stable kernels as well. > >>> > >>> But it does seem to be a better long-term solution - would it work for > >>> you (and whichever maintainer would be taking the patch(es)) if I just > >>> added another patch that refactors it to use the task parameter? > >> I can't figure out what you're suggesting. Are you saying that you > >> want to add a new hook *and* add the task parameter? > > No, just to keep this patch as-is (and let it go to stable in this > > form) and post another (non-stable) patch on top of it that undoes the > > new hook and re-implements the fix using your suggestion. (Yeah, it'll > > look weird, but I'm not sure how better to handle such situation - I'm > > open to doing it whatever different way the maintainers prefer.) > > James gets to make the call on this one. If it was my call I would > tell you to make the task parameter change and accept the backport > pain. I think that as a security developer community we spend way too > much time and effort trying to avoid being noticed in source trees. Hm... actually, what about this attached patch? It switches to a single hook with a cred argument (I figured cred makes more sense than task_struct, since the rest of task_struct should be irrelevant for the LSM, anyway...) right from the start and keeps the original security_locked_down() function only as a simple wrapper around the main hook. At that point I think converting the other callers to call security_cred_locked_down() directly isn't really worth it, since the resulting calls would just be more verbose without much benefit. So I'm tempted to just leave the security_locked_down() helper as is, so that the more common pattern can be still achieved with a simpler call. What do you think? -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc. From 792a131a5619450babf636c7ddb29921e071f2a1 Mon Sep 17 00:00:00 2001 From: Ondrej Mosnacek Date: Tue, 4 May 2021 14:43:01 +0200 Subject: [PATCH] lockdown,selinux: avoid bogus SELinux lockdown permission checks Commit 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown") added an implementation of the locked_down LSM hook to SELinux, with the aim to restrict which domains are allowed to perform operations that would breach lockdown. However, in several places the security_locked_down() hook is called in situations where the current task isn't doing any action that would directly breach lockdown, leading to SELinux checks that are basically bogus. Since in most of these situations converting the callers such that security_locked_down() is called in a context where the current task would be meaningful for SELinux is impossible or very non-trivial (and could lead to TOCTOU issues for the classic Lockdown LSM implementation), fix this by modifying the hook to accept a struct cred pointer as argument, where NULL will be interpreted as a request for a "global", task-independent lockdown decision only. Then modify SELinux to ignore calls with cred == NULL. Since most callers will just want to pass current_cred() as the cred parameter, rename the hook to
[PATCH] powerpc: Don't handle ALTIVEC/SPE in ASM in _switch(). Do it in C.
_switch() saves and restores ALTIVEC and SPE status. For altivec this is redundant with what __switch_to() does with save_sprs() and restore_sprs() and giveup_all() before calling _switch(). Add support for SPI in save_sprs() and restore_sprs() and remove things from _switch(). Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/asm-offsets.c | 2 -- arch/powerpc/kernel/entry_32.S| 35 --- arch/powerpc/kernel/process.c | 9 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 28af4efb4587..5573da9a20d1 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -119,7 +119,6 @@ int main(void) #ifdef CONFIG_ALTIVEC OFFSET(THREAD_VRSTATE, thread_struct, vr_state.vr); OFFSET(THREAD_VRSAVEAREA, thread_struct, vr_save_area); - OFFSET(THREAD_VRSAVE, thread_struct, vrsave); OFFSET(THREAD_USED_VR, thread_struct, used_vr); OFFSET(VRSTATE_VSCR, thread_vr_state, vscr); OFFSET(THREAD_LOAD_VEC, thread_struct, load_vec); @@ -150,7 +149,6 @@ int main(void) #ifdef CONFIG_SPE OFFSET(THREAD_EVR0, thread_struct, evr[0]); OFFSET(THREAD_ACC, thread_struct, acc); - OFFSET(THREAD_SPEFSCR, thread_struct, spefscr); OFFSET(THREAD_USED_SPE, thread_struct, used_spe); #endif /* CONFIG_SPE */ #endif /* CONFIG_PPC64 */ diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S index 9160285cb2f4..6c09ebb853ec 100644 --- a/arch/powerpc/kernel/entry_32.S +++ b/arch/powerpc/kernel/entry_32.S @@ -176,28 +176,6 @@ _GLOBAL(_switch) /* r3-r12 are caller saved -- Cort */ SAVE_NVGPRS(r1) stw r0,_NIP(r1) /* Return to switch caller */ - mfmsr r11 - li r0,MSR_FP /* Disable floating-point */ -#ifdef CONFIG_ALTIVEC -BEGIN_FTR_SECTION - orisr0,r0,MSR_VEC@h /* Disable altivec */ - mfspr r12,SPRN_VRSAVE /* save vrsave register value */ - stw r12,THREAD+THREAD_VRSAVE(r2) -END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) -#endif /* CONFIG_ALTIVEC */ -#ifdef CONFIG_SPE -BEGIN_FTR_SECTION - orisr0,r0,MSR_SPE@h /* Disable SPE */ - mfspr r12,SPRN_SPEFSCR /* save spefscr register value */ - stw r12,THREAD+THREAD_SPEFSCR(r2) -END_FTR_SECTION_IFSET(CPU_FTR_SPE) -#endif /* CONFIG_SPE */ - and.r0,r0,r11 /* FP or altivec or SPE enabled? */ - beq+1f - andcr11,r11,r0 - mtmsr r11 - isync -1: stw r11,_MSR(r1) mfcrr10 stw r10,_CCR(r1) stw r1,KSP(r3) /* Set old stack pointer */ @@ -218,19 +196,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_SPE) mr r3,r2 addir2,r4,-THREAD /* Update current */ -#ifdef CONFIG_ALTIVEC -BEGIN_FTR_SECTION - lwz r0,THREAD+THREAD_VRSAVE(r2) - mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */ -END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) -#endif /* CONFIG_ALTIVEC */ -#ifdef CONFIG_SPE -BEGIN_FTR_SECTION - lwz r0,THREAD+THREAD_SPEFSCR(r2) - mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */ -END_FTR_SECTION_IFSET(CPU_FTR_SPE) -#endif /* CONFIG_SPE */ - lwz r0,_CCR(r1) mtcrf 0xFF,r0 /* r3-r12 are destroyed -- Cort */ diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 89e34aa273e2..2bd30acc843c 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1129,6 +1129,10 @@ static inline void save_sprs(struct thread_struct *t) if (cpu_has_feature(CPU_FTR_ALTIVEC)) t->vrsave = mfspr(SPRN_VRSAVE); #endif +#ifdef CONFIG_SPE + if (cpu_has_feature(CPU_FTR_SPE)) + t->spefscr = mfspr(SPRN_SPEFSCR); +#endif #ifdef CONFIG_PPC_BOOK3S_64 if (cpu_has_feature(CPU_FTR_DSCR)) t->dscr = mfspr(SPRN_DSCR); @@ -1159,6 +1163,11 @@ static inline void restore_sprs(struct thread_struct *old_thread, old_thread->vrsave != new_thread->vrsave) mtspr(SPRN_VRSAVE, new_thread->vrsave); #endif +#ifdef CONFIG_SPE + if (cpu_has_feature(CPU_FTR_SPE) && + old_thread->spefscr != new_thread->spefscr) + mtspr(SPRN_SPEFSCR, new_thread->spefscr); +#endif #ifdef CONFIG_PPC_BOOK3S_64 if (cpu_has_feature(CPU_FTR_DSCR)) { u64 dscr = get_paca()->dscr_default; -- 2.25.0
Re: [PATCH v2 05/13] powerpc: use linux/unaligned/le_struct.h on LE power7
On Fri, May 14, 2021 at 1:48 PM Segher Boessenkool wrote: > On Fri, May 14, 2021 at 12:00:53PM +0200, Arnd Bergmann wrote: > > Little-endian POWER7 kernels disable > > CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS because that is not supported on > > the hardware, but the kernel still uses direct load/store for explicti > > get_unaligned()/put_unaligned(). > > > > I assume this is a mistake that leads to power7 having to trap and fix > > up all these unaligned accesses at a noticeable performance cost. > > > > The fix is completely trivial, just remove the file and use the > > generic version that gets it right. > > LE p7 isn't supported (it requires special firmware), and no one uses it > anymore, also not for development. It was used for powerpc64le-linux > development before p8 was widely available. Ok, thanks for the clarification. Should we just remove the Kconfig option for it then as further cleanup? Is there any other code such as alignment trap handling that could be removed if LE POWER7 gets dropped? Arnd
Re: [PATCH v2 05/13] powerpc: use linux/unaligned/le_struct.h on LE power7
Hi Arnd, On Fri, May 14, 2021 at 12:00:53PM +0200, Arnd Bergmann wrote: > Little-endian POWER7 kernels disable > CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS because that is not supported on > the hardware, but the kernel still uses direct load/store for explicti > get_unaligned()/put_unaligned(). > > I assume this is a mistake that leads to power7 having to trap and fix > up all these unaligned accesses at a noticeable performance cost. > > The fix is completely trivial, just remove the file and use the > generic version that gets it right. LE p7 isn't supported (it requires special firmware), and no one uses it anymore, also not for development. It was used for powerpc64le-linux development before p8 was widely available. Segher
Re: [RFC 1/4] drivers/nvdimm: Add perf interface to expose nvdimm performance stats
On Thu, May 13, 2021 at 05:56:14PM +0530, kajoljain wrote: > But yes the current read/add/del functions are not adding value. We > could add an arch/platform specific function which could handle the > capturing of the counter data and do the rest of the operation here, > is this approach better? Right; have your register_nvdimm_pmu() set pmu->{add,del,read} to nd_pmu->{add,del,read} directly, don't bother with these intermediates. Also you can WARN_ON_ONCE() if any of them are NULL and fail registration at that point.
Re: [PATCH] cxl: Fix an error message
On Wed, May 05, 2021 at 09:38:49PM +0200, Christophe JAILLET wrote: > 'rc' is known to be 0 here. > Initialize 'rc' with the expected error code before using it. > > While at it, avoid the affectation of 'rc' in a 'if' to make things more > obvious and linux style. > > Fixes: f204e0b8ce ("cxl: Driver code for powernv PCIe based cards for > userspace access") You need a full 12 digits for the SHA1, otherwise our scripts complain about it :( I'll fix it up here, but please fix your tools. thanks, greg k-h
Re: [PATCH -next] crypto: nx842: add missing MODULE_DEVICE_TABLE
On Sat, May 08, 2021 at 11:14:55AM +0800, Bixuan Cui wrote: > This patch adds missing MODULE_DEVICE_TABLE definition which generates > correct modalias for automatic loading of this driver when it is built > as an external module. > > Reported-by: Hulk Robot > Signed-off-by: Bixuan Cui > --- > drivers/crypto/nx/nx-842-pseries.c | 1 + > 1 file changed, 1 insertion(+) Patch applied. Thanks. -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[PATCH] arm64: Define only {pud/pmd}_{set/clear}_huge when usefull
When PUD and/or PMD are folded, those functions are useless and we now have a stub in linux/pgtable.h Reported-by: Naresh Kamboju Signed-off-by: Christophe Leroy --- arch/arm64/mm/mmu.c | 20 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6dd9369e3ea0..98af085afe90 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1337,6 +1337,7 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) return dt_virt; } +#if CONFIG_PGTABLE_LEVELS > 3 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) { pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot)); @@ -1351,6 +1352,16 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) return 1; } +int pud_clear_huge(pud_t *pudp) +{ + if (!pud_sect(READ_ONCE(*pudp))) + return 0; + pud_clear(pudp); + return 1; +} +#endif + +#if CONFIG_PGTABLE_LEVELS > 2 int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) { pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot)); @@ -1365,14 +1376,6 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) return 1; } -int pud_clear_huge(pud_t *pudp) -{ - if (!pud_sect(READ_ONCE(*pudp))) - return 0; - pud_clear(pudp); - return 1; -} - int pmd_clear_huge(pmd_t *pmdp) { if (!pmd_sect(READ_ONCE(*pmdp))) @@ -1380,6 +1383,7 @@ int pmd_clear_huge(pmd_t *pmdp) pmd_clear(pmdp); return 1; } +#endif int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) { -- 2.25.0
Re : mm/mremap: use range flush that does TLB and page walk cache flush
The LKFT build system detected these build warnings and errors. Regressions found on parisc: - build/gcc-9-defconfig - build/gcc-9-tinyconfig - build/gcc-10-allnoconfig - build/gcc-10-tinyconfig - build/gcc-9-allnoconfig - build/gcc-10-defconfig make --silent --keep-going --jobs=8 O=/home/tuxbuild/.cache/tuxmake/builds/current ARCH=parisc CROSS_COMPILE=hppa-linux-gnu- 'CC=sccache hppa-linux-gnu-gcc' 'HOSTCC=sccache gcc' In file included from /builds/linux/arch/parisc/include/asm/cacheflush.h:7, from /builds/linux/include/linux/highmem.h:12, from /builds/linux/include/linux/pagemap.h:11, from /builds/linux/include/linux/ksm.h:13, from /builds/linux/mm/mremap.c:14: /builds/linux/mm/mremap.c: In function 'flush_pte_tlb_pwc_range': /builds/linux/arch/parisc/include/asm/tlbflush.h:20:2: error: 'return' with a value, in function returning void [-Werror=return-type] 20 | __flush_tlb_range((vma)->vm_mm->context, start, end) | ^~~~ /builds/linux/mm/mremap.c:219:9: note: in expansion of macro 'flush_tlb_range' 219 | return flush_tlb_range(vma, start, end); | ^~~ /builds/linux/mm/mremap.c:214:33: note: declared here 214 | #define flush_pte_tlb_pwc_range flush_pte_tlb_pwc_range | ^~~ /builds/linux/mm/mremap.c:215:20: note: in expansion of macro 'flush_pte_tlb_pwc_range' 215 | static inline void flush_pte_tlb_pwc_range(struct vm_area_struct *vma, |^~~ cc1: some warnings being treated as errors make[2]: *** [/builds/linux/scripts/Makefile.build:273: mm/mremap.o] Error 1 Reported-by: Naresh Kamboju steps to reproduce: --- #!/bin/sh # TuxMake is a command line tool and Python library that provides # portable and repeatable Linux kernel builds across a variety of # architectures, toolchains, kernel configurations, and make targets. # # TuxMake supports the concept of runtimes. # See https://docs.tuxmake.org/runtimes/, for that to work it requires # that you install podman or docker on your system. # # To install tuxmake on your system globally: # sudo pip3 install -U tuxmake # # See https://docs.tuxmake.org/ for complete documentation. tuxmake --runtime podman --target-arch parisc --toolchain gcc-9 --kconfig allnoconfig -- Linaro LKFT https://lkft.linaro.org
[PATCH v2 05/13] powerpc: use linux/unaligned/le_struct.h on LE power7
From: Arnd Bergmann Little-endian POWER7 kernels disable CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS because that is not supported on the hardware, but the kernel still uses direct load/store for explicti get_unaligned()/put_unaligned(). I assume this is a mistake that leads to power7 having to trap and fix up all these unaligned accesses at a noticeable performance cost. The fix is completely trivial, just remove the file and use the generic version that gets it right. Signed-off-by: Arnd Bergmann --- arch/powerpc/include/asm/unaligned.h | 22 -- 1 file changed, 22 deletions(-) delete mode 100644 arch/powerpc/include/asm/unaligned.h diff --git a/arch/powerpc/include/asm/unaligned.h b/arch/powerpc/include/asm/unaligned.h deleted file mode 100644 index ce69c5eff95e.. --- a/arch/powerpc/include/asm/unaligned.h +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_POWERPC_UNALIGNED_H -#define _ASM_POWERPC_UNALIGNED_H - -#ifdef __KERNEL__ - -/* - * The PowerPC can do unaligned accesses itself based on its endian mode. - */ -#include -#include - -#ifdef __LITTLE_ENDIAN__ -#define get_unaligned __get_unaligned_le -#define put_unaligned __put_unaligned_le -#else -#define get_unaligned __get_unaligned_be -#define put_unaligned __put_unaligned_be -#endif - -#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_UNALIGNED_H */ -- 2.29.2
[PATCH v2 00/13] Unify asm/unaligned.h around struct helper
From: Arnd Bergmann The get_unaligned()/put_unaligned() helpers are traditionally architecture specific, with the two main variants being the "access-ok.h" version that assumes unaligned pointer accesses always work on a particular architecture, and the "le-struct.h" version that casts the data to a byte aligned type before dereferencing, for architectures that cannot always do unaligned accesses in hardware. Based on the discussion linked below, it appears that the access-ok version is not realiable on any architecture, but the struct version probably has no downsides. This series changes the code to use the same implementation on all architectures, addressing the few exceptions separately. I've included this version in the asm-generic tree for 5.14 already, addressing the few issues that were pointed out in the RFC. If there are any remaining problems, I hope those can be addressed as follow-up patches. Arnd Link: https://lore.kernel.org/lkml/75d07691-1e4f-741f-9852-38c0b4f52...@synopsys.com/ Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100363 Link: https://lore.kernel.org/lkml/20210507220813.365382-14-a...@kernel.org/ Link: git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git unaligned-rework-v2 Arnd Bergmann (13): asm-generic: use asm-generic/unaligned.h for most architectures openrisc: always use unaligned-struct header sh: remove unaligned access for sh4a m68k: select CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS powerpc: use linux/unaligned/le_struct.h on LE power7 asm-generic: unaligned: remove byteshift helpers asm-generic: unaligned always use struct helpers partitions: msdos: fix one-byte get_unaligned() apparmor: use get_unaligned() only for multi-byte words mwifiex: re-fix for unaligned accesses netpoll: avoid put_unaligned() on single character asm-generic: uaccess: 1-byte access is always aligned asm-generic: simplify asm/unaligned.h arch/alpha/include/asm/unaligned.h | 12 -- arch/arm/include/asm/unaligned.h| 27 --- arch/ia64/include/asm/unaligned.h | 12 -- arch/m68k/Kconfig | 1 + arch/m68k/include/asm/unaligned.h | 26 --- arch/microblaze/include/asm/unaligned.h | 27 --- arch/mips/crypto/crc32-mips.c | 2 +- arch/openrisc/include/asm/unaligned.h | 47 - arch/parisc/include/asm/unaligned.h | 6 +- arch/powerpc/include/asm/unaligned.h| 22 --- arch/sh/include/asm/unaligned-sh4a.h| 199 arch/sh/include/asm/unaligned.h | 13 -- arch/sparc/include/asm/unaligned.h | 11 -- arch/x86/include/asm/unaligned.h| 15 -- arch/xtensa/include/asm/unaligned.h | 29 --- block/partitions/ldm.h | 2 +- block/partitions/msdos.c| 2 +- drivers/net/wireless/marvell/mwifiex/pcie.c | 10 +- include/asm-generic/uaccess.h | 4 +- include/asm-generic/unaligned.h | 141 +++--- include/linux/unaligned/access_ok.h | 68 --- include/linux/unaligned/be_byteshift.h | 71 --- include/linux/unaligned/be_memmove.h| 37 include/linux/unaligned/be_struct.h | 37 include/linux/unaligned/generic.h | 115 --- include/linux/unaligned/le_byteshift.h | 71 --- include/linux/unaligned/le_memmove.h| 37 include/linux/unaligned/le_struct.h | 37 include/linux/unaligned/memmove.h | 46 - net/core/netpoll.c | 4 +- security/apparmor/policy_unpack.c | 2 +- 31 files changed, 131 insertions(+), 1002 deletions(-) delete mode 100644 arch/alpha/include/asm/unaligned.h delete mode 100644 arch/arm/include/asm/unaligned.h delete mode 100644 arch/ia64/include/asm/unaligned.h delete mode 100644 arch/m68k/include/asm/unaligned.h delete mode 100644 arch/microblaze/include/asm/unaligned.h delete mode 100644 arch/openrisc/include/asm/unaligned.h delete mode 100644 arch/powerpc/include/asm/unaligned.h delete mode 100644 arch/sh/include/asm/unaligned-sh4a.h delete mode 100644 arch/sh/include/asm/unaligned.h delete mode 100644 arch/sparc/include/asm/unaligned.h delete mode 100644 arch/x86/include/asm/unaligned.h delete mode 100644 arch/xtensa/include/asm/unaligned.h delete mode 100644 include/linux/unaligned/access_ok.h delete mode 100644 include/linux/unaligned/be_byteshift.h delete mode 100644 include/linux/unaligned/be_memmove.h delete mode 100644 include/linux/unaligned/be_struct.h delete mode 100644 include/linux/unaligned/generic.h delete mode 100644 include/linux/unaligned/le_byteshift.h delete mode 100644 include/linux/unaligned/le_memmove.h delete mode 100644 include/linux/unaligned/le_struct.h delete mode 100644 include/linux/unaligned/memmove.h -- 2.29.2 Cc: Amitkumar Karwar Cc: Arnd Bergmann Cc: Benjamin Herrenschmidt Cc:
Re: [PATCH kernel v3] powerpc/makefile: Do not redefine $(CPP) for preprocessor
Hi! On Fri, May 14, 2021 at 11:42:32AM +0900, Masahiro Yamada wrote: > In my best guess, the reason why powerpc adding the endian flag to CPP > is this line in arch/powerpc/kernel/vdso64/vdso64.lds.S > > #ifdef __LITTLE_ENDIAN__ > OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle") > #else > OUTPUT_FORMAT("elf64-powerpc", "elf64-powerpc", "elf64-powerpc") > #endif Which is equivalent to #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf64-powerpcle") #else OUTPUT_FORMAT("elf64-powerpc") #endif so please change that at the same time if you touch this :-) > __LITTLE_ENDIAN__ is defined by powerpc gcc and clang. This predefined macro is required by the newer ABIs, but all older compilers have it as well. _LITTLE_ENDIAN is not supported on all platforms (but it is if your compiler targets Linux, which you cannot necessarily rely on). These macros are PowerPC-specific. For GCC, for all targets, you can say #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ You do not need any of the other *ORDER__ macros in most cases. See "info cpp" for the sordid details. > [2] powerpc-linux-gnu-gcc + -mlittle-endian-> __LITTLE_ENDIAN__ is defined You can just write -mbig and -mlittle btw. Those aren't available on all targets, but neither are the long-winded -m{big,little}-endian option names. Pet peeve, I know :-) HtH, Segher
[PATCH 2/2] powerpc/interrupt: Use msr instead of regs->msr
interrupt_exit_user_prepare() and interrupt_exit_kernel_prepare() get msr as second parameter from ASM. Use it instead of reading it again. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/interrupt.c | 26 +- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c index d896fc6ed0be..9541328a97b1 100644 --- a/arch/powerpc/kernel/interrupt.c +++ b/arch/powerpc/kernel/interrupt.c @@ -231,8 +231,8 @@ static notrace void booke_load_dbcr0(void) #endif } -static notrace unsigned long __interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long ret, - bool is_not_scv) +static notrace unsigned long __interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr, + unsigned long ret, bool is_not_scv) { unsigned long ti_flags; @@ -281,7 +281,7 @@ static notrace unsigned long __interrupt_exit_user_prepare(struct pt_regs *regs, * may decide to restore them (to avoid taking an FP * fault). */ - if ((regs->msr & mathflags) != mathflags) + if ((msr & mathflags) != mathflags) restore_math(regs); } } @@ -297,7 +297,7 @@ static notrace unsigned long __interrupt_exit_user_prepare(struct pt_regs *regs, } #ifdef CONFIG_PPC_TRANSACTIONAL_MEM - local_paca->tm_scratch = regs->msr; + local_paca->tm_scratch = msr; #endif booke_load_dbcr0(); @@ -357,17 +357,17 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, ret |= _TIF_RESTOREALL; } - return __interrupt_exit_user_prepare(regs, ret, is_not_scv); + return __interrupt_exit_user_prepare(regs, regs->msr, ret, is_not_scv); } notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr) { if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x)) - BUG_ON(!(regs->msr & MSR_RI)); - BUG_ON(!(regs->msr & MSR_PR)); + BUG_ON(!(msr & MSR_RI)); + BUG_ON(!(msr & MSR_PR)); BUG_ON(arch_irq_disabled_regs(regs)); - return __interrupt_exit_user_prepare(regs, 0, true); + return __interrupt_exit_user_prepare(regs, msr, 0, true); } void preempt_schedule_irq(void); @@ -379,9 +379,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign unsigned long kuap; if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x) && - unlikely(!(regs->msr & MSR_RI))) + unlikely(!(msr & MSR_RI))) unrecoverable_exception(regs); - BUG_ON(regs->msr & MSR_PR); + BUG_ON(msr & MSR_PR); /* * CT_WARN_ON comes here via program_check_exception, * so avoid recursion. @@ -400,7 +400,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign if (!arch_irq_disabled_regs(regs)) { /* Returning to a kernel context with local irqs enabled. */ - WARN_ON_ONCE(!(regs->msr & MSR_EE)); + WARN_ON_ONCE(!(msr & MSR_EE)); again: if (IS_ENABLED(CONFIG_PREEMPT)) { /* Return to preemptible kernel context */ @@ -416,14 +416,14 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign /* Returning to a kernel context with local irqs disabled. */ __hard_EE_RI_disable(); #ifdef CONFIG_PPC64 - if (regs->msr & MSR_EE) + if (msr & MSR_EE) local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS; #endif } #ifdef CONFIG_PPC_TRANSACTIONAL_MEM - local_paca->tm_scratch = regs->msr; + local_paca->tm_scratch = msr; #endif /* -- 2.25.0
[PATCH 1/2] powerpc/interrupt: Refactor interrupt_exit_user_prepare() and syscall_exit_prepare()
Last part of interrupt_exit_user_prepare() and syscall_exit_prepare() are identical. Create a __interrupt_exit_user_prepare() function that is called by both. Note that it replaces a local_irq_save(flags) by local_irq_disable(). This is similar because the flags are never used. On ppc 8xx it is more efficient because it doesn't require reading MSR. Signed-off-by: Christophe Leroy --- It requires the following commits that are in powerpc/fixes-test: 5d510ed78bcf powerpc/syscall: Calling kuap_save_and_lock() is wrong a78339698ab1 powerpc/interrupts: Fix kuep_unlock() call Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/interrupt.c | 147 ++-- 1 file changed, 44 insertions(+), 103 deletions(-) diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c index e0938ba298f2..d896fc6ed0be 100644 --- a/arch/powerpc/kernel/interrupt.c +++ b/arch/powerpc/kernel/interrupt.c @@ -231,56 +231,15 @@ static notrace void booke_load_dbcr0(void) #endif } -/* - * This should be called after a syscall returns, with r3 the return value - * from the syscall. If this function returns non-zero, the system call - * exit assembly should additionally load all GPR registers and CTR and XER - * from the interrupt frame. - * - * The function graph tracer can not trace the return side of this function, - * because RI=0 and soft mask state is "unreconciled", so it is marked notrace. - */ -notrace unsigned long syscall_exit_prepare(unsigned long r3, - struct pt_regs *regs, - long scv) +static notrace unsigned long __interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long ret, + bool is_not_scv) { unsigned long ti_flags; - unsigned long ret = 0; - bool is_not_scv = !IS_ENABLED(CONFIG_PPC_BOOK3S_64) || !scv; CT_WARN_ON(ct_state() == CONTEXT_USER); kuap_assert_locked(); - regs->result = r3; - - /* Check whether the syscall is issued inside a restartable sequence */ - rseq_syscall(regs); - - ti_flags = current_thread_info()->flags; - - if (unlikely(r3 >= (unsigned long)-MAX_ERRNO) && is_not_scv) { - if (likely(!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL { - r3 = -r3; - regs->ccr |= 0x1000; /* Set SO bit in CR */ - } - } - - if (unlikely(ti_flags & _TIF_PERSYSCALL_MASK)) { - if (ti_flags & _TIF_RESTOREALL) - ret = _TIF_RESTOREALL; - else - regs->gpr[3] = r3; - clear_bits(_TIF_PERSYSCALL_MASK, _thread_info()->flags); - } else { - regs->gpr[3] = r3; - } - - if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) { - do_syscall_trace_leave(regs); - ret |= _TIF_RESTOREALL; - } - local_irq_disable(); again: @@ -303,7 +262,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, ti_flags = READ_ONCE(current_thread_info()->flags); } - if (IS_ENABLED(CONFIG_PPC_BOOK3S) && IS_ENABLED(CONFIG_PPC_FPU)) { + if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) { if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && unlikely((ti_flags & _TIF_RESTORE_TM))) { restore_tm_state(regs); @@ -352,81 +311,63 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, return ret; } -notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigned long msr) +/* + * This should be called after a syscall returns, with r3 the return value + * from the syscall. If this function returns non-zero, the system call + * exit assembly should additionally load all GPR registers and CTR and XER + * from the interrupt frame. + * + * The function graph tracer can not trace the return side of this function, + * because RI=0 and soft mask state is "unreconciled", so it is marked notrace. + */ +notrace unsigned long syscall_exit_prepare(unsigned long r3, + struct pt_regs *regs, + long scv) { unsigned long ti_flags; - unsigned long flags; unsigned long ret = 0; + bool is_not_scv = !IS_ENABLED(CONFIG_PPC_BOOK3S_64) || !scv; - if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x)) - BUG_ON(!(regs->msr & MSR_RI)); - BUG_ON(!(regs->msr & MSR_PR)); - BUG_ON(arch_irq_disabled_regs(regs)); - CT_WARN_ON(ct_state() == CONTEXT_USER); + regs->result = r3; - /* -* We don't need to restore AMR on the way back to userspace for KUAP. -* AMR can only have been unlocked if we interrupted the kernel. -*/ -
[FSL P50x0] KVM HV doesn't work anymore
Hi All, The RC1 of kernel 5.13 doesn't boot in a virtual e5500 QEMU machine with KVM HV anymore. I see in the serial console that the uImage doesn't load. I use the following QEMU command for booting: qemu-system-ppc64 -M ppce500 -cpu e5500 -enable-kvm -m 1024 -kernel uImage-5.13 -drive format=raw,file=MintPPC32-X5000.img,index=0,if=virtio -netdev user,id=mynet0 -device e1000,netdev=mynet0 -append "rw root=/dev/vda" -device virtio-vga -device virtio-mouse-pci -device virtio-keyboard-pci -device pci-ohci,id=newusb -device usb-audio,bus=newusb.0 -smp 4 The kernel boots without KVM HV. Have you already tested KVM HV with the kernel 5.13? Thanks, Christian
[PATCH -next] powerpc/pseries/memhotplug: Remove unused inline function dlpar_memory_remove()
dlpar_memory_remove() is never used, so can be removed. Signed-off-by: YueHaibing --- arch/powerpc/platforms/pseries/hotplug-memory.c | 4 1 file changed, 4 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 8377f1f7c78e..3d93f1c48e23 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -585,10 +585,6 @@ static inline int pseries_remove_mem_node(struct device_node *np) { return 0; } -static inline int dlpar_memory_remove(struct pseries_hp_errorlog *hp_elog) -{ - return -EOPNOTSUPP; -} static int dlpar_remove_lmb(struct drmem_lmb *lmb) { return -EOPNOTSUPP; -- 2.17.1
Re: [PATCH bpf-next 1/2] bpf: Remove bpf_jit_enable=2 debugging mode
Le 23/04/2021 à 12:26, Quentin Monnet a écrit : 2021-04-23 09:19 UTC+0200 ~ Christophe Leroy [...] I finally managed to cross compile bpftool with libbpf, libopcodes, readline, ncurses, libcap, libz and all needed stuff. Was not easy but I made it. Libcap is optional and bpftool does not use readline or ncurses. May I ask how you tried to build it? Now, how do I use it ? Let say I want to dump the jitted code generated from a call to 'tcpdump'. How do I do that with 'bpftool prog dump jited' ? I thought by calling this line I would then get programs dumped in a way or another just like when setting 'bpf_jit_enable=2', but calling that line just provides me some bpftool help text. Well the purpose of this text is to help you find the way to call bpftool to do what you want :). For dumping your programs' instructions, you need to tell bpftool what program to dump: Bpftool isn't waiting until you load a program to dump it, instead you need to load your program first and then tell bpftool to retrieve the instructions from the kernel. To reference your program you could use a pinned path, or first list the programs on your system with "bpftool prog show": # bpftool prog show 138: tracing name foo tag e54c922dfa54f65f gpl loaded_at 2021-02-25T01:32:30+ uid 0 xlated 256B jited 154B memlock 4096B map_ids 64 btf_id 235 Got the following error: root@vgoip:~# ./bpftool prog show libbpf: elf: endianness mismatch in pid_iter_bpf. libbpf: failed to initialize skeleton BPF object 'pid_iter_bpf': -4003 Error: failed to open PID iterator skeleton Christophe