On Mon, Oct 9, 2023 at 7:30 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Mon, Oct 09, 2023 at 06:57:40PM +0200, Max Kellermann wrote:
> > This moves those variables to the ".rodata" section which reduces the
> > kernel size a bit and protects the variables by putting them on
> > read-only pages at runtime.
>
> The kernel size should still be the same overall, you are just moving
> pointers from one section to another, right?
>
> If not, what are the numbers, show them please.
Before this patch series:
text data bss dec hex filename
10645342 6836166 12476420 29957928 1c91f28 vmlinux
After:
text data bss dec hex filename
10645342 6835398 12476420 29957160 1c91c28 vmlinux
(Config attached if you wish to reproduce. I'm using stock GCC from
Debian Bookworm.)
It's only a few hundred bytes, and I havn't really dug deep enough to
explain to you why this is - my goal was (semantic) const-correctness
and .rodata protection, but those numbers are a side effect that
exists.
> But step back, are you SURE you can make these attribute group pointers
> const? They are modified by some subsystems by adding or removing items
> from the lists, so why does the core need to change for that?
Some few do modify them, but they do not modify those pointers; they
allocate a new one (the 3 I sbumitted a patch for) or they modify
global variables (arch/pmu) which I'm not going to make "const". But
most globals can indeed be made "const".
@@ -699,12 +699,12 @@ static umode_t blk_mq_queue_attr_visible(struct kobject *kobj,
return attr->mode;
}
-static struct attribute_group queue_attr_group = {
+static const struct attribute_group queue_attr_group = {
.attrs = queue_attrs,
.is_visible = queue_attr_visible,
};
-static struct attribute_group blk_mq_queue_attr_group = {
+static const struct attribute_group blk_mq_queue_attr_group = {
.attrs = blk_mq_queue_attrs,
.is_visible = blk_mq_queue_attr_visible,
};
@@ -750,7 +750,7 @@ static const struct sysfs_ops queue_sysfs_ops = {
.store = queue_attr_store,
};
-static const struct attribute_group *blk_queue_attr_groups[] = {
+static const struct attribute_group *const blk_queue_attr_groups[] = {
&queue_attr_group,
&blk_mq_queue_attr_group,
NULL
@@ -1115,12 +1115,12 @@ static umode_t disk_visible(struct kobject *kobj, struct attribute *a, int n)
return a->mode;
}
-static struct attribute_group disk_attr_group = {
+static const struct attribute_group disk_attr_group = {
.attrs = disk_attrs,
.is_visible = disk_visible,
};
-static const struct attribute_group *disk_attr_groups[] = {
+static const struct attribute_group *const disk_attr_groups[] = {
&disk_attr_group,
#ifdef CONFIG_BLK_DEV_IO_TRACE
&blk_trace_attr_group,
@@ -232,7 +232,7 @@ static const struct attribute_group part_attr_group = {
.attrs = part_attrs,
};
-static const struct attribute_group *part_attr_groups[] = {
+static const struct attribute_group *const part_attr_groups[] = {
&part_attr_group,
#ifdef CONFIG_BLK_DEV_IO_TRACE
&blk_trace_attr_group,
@@ -786,7 +786,7 @@ static const struct attribute_group cache_default_group = {
.is_visible = cache_default_attrs_is_visible,
};
-static const struct attribute_group *cache_default_groups[] = {
+static const struct attribute_group *const cache_default_groups[] = {
&cache_default_group,
NULL,
};
@@ -736,7 +736,7 @@ static struct attribute *loop_attrs[] = {
NULL,
};
-static struct attribute_group loop_attribute_group = {
+static const struct attribute_group loop_attribute_group = {
.name = "loop",
.attrs= loop_attrs,
};
@@ -5246,11 +5246,11 @@ static struct attribute *rbd_attrs[] = {
NULL
};
-static struct attribute_group rbd_attr_group = {
+static const struct attribute_group rbd_attr_group = {
.attrs = rbd_attrs,
};
-static const struct attribute_group *rbd_attr_groups[] = {
+static const struct attribute_group *const rbd_attr_groups[] = {
&rbd_attr_group,
NULL
};
@@ -1597,7 +1597,7 @@ static const struct attribute_group input_dev_caps_attr_group = {
.attrs = input_dev_caps_attrs,
};
-static const struct attribute_group *input_dev_attr_groups[] = {
+static const struct attribute_group *const input_dev_attr_groups[] = {
&input_dev_attr_group,
&input_dev_id_attr_group,
&input_dev_caps_attr_group,
@@ -474,7 +474,7 @@ static const struct attribute_group serio_device_attr_group = {
.attrs = serio_device_attrs,
};
-static const struct attribute_group *serio_device_attr_groups[] = {
+static const struct attribute_group *const serio_device_attr_groups[] = {
&serio_id_attr_group,
&serio_device_attr_group,
NULL
@@ -455,7 +455,7 @@ static const struct attribute_group pci_bus_group = {
.attrs = pci_bus_attrs,
};
-const struct attribute_group *pci_bus_groups[] = {
+const struct attribute_group *const pci_bus_groups[] = {
&pci_bus_group,
NULL,
};
@@ -647,7 +647,7 @@ static const struct attribute_group pcibus_group = {
.attrs = pcibus_attrs,
};
-const struct attribute_group *pcibus_groups[] = {
+const struct attribute_group *const pcibus_groups[] = {
&pcibus_group,
NULL,
};
@@ -1604,7 +1604,7 @@ static const struct attribute_group pci_dev_group = {
.attrs = pci_dev_attrs,
};
-const struct attribute_group *pci_dev_groups[] = {
+const struct attribute_group *const pci_dev_groups[] = {
&pci_dev_group,
&pci_dev_config_attr_group,
&pci_dev_rom_attr_group,
@@ -1641,7 +1641,7 @@ static const struct attribute_group pcie_dev_attr_group = {
.is_visible = pcie_dev_attrs_are_visible,
};
-static const struct attribute_group *pci_dev_attr_groups[] = {
+static const struct attribute_group *const pci_dev_attr_groups[] = {
&pci_dev_attr_group,
&pci_dev_hp_attr_group,
#ifdef CONFIG_PCI_IOV
@@ -182,10 +182,10 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
return (dev->no_d1d2 || parent_dstates);
}
-extern const struct attribute_group *pci_dev_groups[];
-extern const struct attribute_group *pcibus_groups[];
+extern const struct attribute_group *const pci_dev_groups[];
+extern const struct attribute_group *const pcibus_groups[];
extern const struct device_type pci_dev_type;
-extern const struct attribute_group *pci_bus_groups[];
+extern const struct attribute_group *const pci_bus_groups[];
extern unsigned long pci_hotplug_io_size;
extern unsigned long pci_hotplug_mmio_size;
@@ -93,7 +93,7 @@ static const struct attribute_group pps_group = {
.attrs = pps_attrs,
};
-const struct attribute_group *pps_groups[] = {
+const struct attribute_group *const pps_groups[] = {
&pps_group,
NULL,
};
@@ -303,7 +303,7 @@ static struct attribute_group rtc_attr_group = {
.attrs = rtc_attrs,
};
-static const struct attribute_group *rtc_attr_groups[] = {
+static const struct attribute_group *const rtc_attr_groups[] = {
&rtc_attr_group,
NULL
};
@@ -3187,7 +3187,7 @@ static struct attribute *serial8250_dev_attrs[] = {
NULL
};
-static struct attribute_group serial8250_dev_attr_group = {
+static const struct attribute_group serial8250_dev_attr_group = {
.attrs = serial8250_dev_attrs,
};
@@ -31,7 +31,7 @@ static struct attribute *o2cb_attrs[] = {
NULL,
};
-static struct attribute_group o2cb_attr_group = {
+static const struct attribute_group o2cb_attr_group = {
.attrs = o2cb_attrs,
};
@@ -5,7 +5,7 @@
#include <linux/sched/coredump.h> /* MMF_VM_HUGEPAGE */
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-extern struct attribute_group khugepaged_attr_group;
+extern const struct attribute_group khugepaged_attr_group;
extern int khugepaged_init(void);
extern void khugepaged_destroy(void);
@@ -66,7 +66,7 @@ struct pps_device {
* Global variables
*/
-extern const struct attribute_group *pps_groups[];
+extern const struct attribute_group *const pps_groups[];
/*
* Internal functions.
@@ -339,7 +339,7 @@ static struct attribute *khugepaged_attr[] = {
NULL,
};
-struct attribute_group khugepaged_attr_group = {
+const struct attribute_group khugepaged_attr_group = {
.attrs = khugepaged_attr,
.name = "khugepaged",
};