Skip to contentSkip to conversation

Arm: device.c is init-only when OVERLAY_DTB=n

PATCH In review Jan Beulich 3 participants 4 messages Feb 26 – Apr 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Arm: device.c is init-only when OVERLAY_DTB=n

Introduce an annotation similar to __hwdom_init and use it througout the file. All external callers are either themselves __init or are limited to OVERLAY_DTB=y. Adjust the Makefile accordingly to also have string literals moved into .init.rodata.

xen/arch/arm/Makefile +3 -1
@@ -15,7 +15,9 @@ obj-$(CONFIG_HAS_ALTERNATIVE) += alterna
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
-obj-y += device.o
+device-y := device.init.o
+device-$(CONFIG_OVERLAY_DTB) := device.o
+obj-y += $(device-y)
 obj-$(CONFIG_IOREQ_SERVER) += dm.o
 obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-build.init.o
 obj-y += domain.o
xen/arch/arm/device.c +18 -15
@@ -9,6 +9,7 @@
  */
 
 #include <xen/device_tree.h>
+#include <xen/dt-overlay.h>
 #include <xen/errno.h>
 #include <xen/iocap.h>
 #include <xen/lib.h>
@@ -16,8 +17,8 @@
 #include <asm/firmware/sci.h>
 #include <asm/setup.h>
 
-int map_irq_to_domain(struct domain *d, unsigned int irq,
-                      bool need_mapping, const char *devname)
+int __overlay_init map_irq_to_domain(struct domain *d, unsigned int irq,
+                                     bool need_mapping, const char *devname)
 {
     int res;
 
@@ -49,8 +50,8 @@ int map_irq_to_domain(struct domain *d,
     return 0;
 }
 
-int map_range_to_domain(const struct dt_device_node *dev,
-                        uint64_t addr, uint64_t len, void *data)
+int __overlay_init map_range_to_domain(const struct dt_device_node *dev,
+                                       uint64_t addr, uint64_t len, void *data)
 {
     struct map_range_data *mr_data = data;
     struct domain *d = mr_data->d;
@@ -124,10 +125,10 @@ int map_range_to_domain(const struct dt_
  *   < 0 error
  *   0   success
  */
-int map_device_irqs_to_domain(struct domain *d,
-                              struct dt_device_node *dev,
-                              bool need_mapping,
-                              struct rangeset *irq_ranges)
+int __overlay_init map_device_irqs_to_domain(struct domain *d,
+                                             struct dt_device_node *dev,
+                                             bool need_mapping,
+                                             struct rangeset *irq_ranges)
 {
     unsigned int i, nirq;
     int res, irq;
@@ -180,9 +181,9 @@ int map_device_irqs_to_domain(struct dom
     return 0;
 }
 
-static int map_dt_irq_to_domain(const struct dt_device_node *dev,
-                                const struct dt_irq *dt_irq,
-                                void *data)
+static int __overlay_init map_dt_irq_to_domain(const struct dt_device_node *dev,
+                                               const struct dt_irq *dt_irq,
+                                               void *data)
 {
     struct map_range_data *mr_data = data;
     struct domain *d = mr_data->d;
@@ -219,8 +220,8 @@ static int map_dt_irq_to_domain(const st
  * then we may need to perform additional mappings in order to make
  * the child resources available to domain 0.
  */
-static int map_device_children(const struct dt_device_node *dev,
-                               struct map_range_data *mr_data)
+static int __overlay_init map_device_children(const struct dt_device_node *dev,
+                                              struct map_range_data *mr_data)
 {
     if ( dt_device_type_is_equal(dev, "pci") )
     {
@@ -250,8 +251,10 @@ static int map_device_children(const str
  *  - Assign the device to the guest if it's protected by an IOMMU
  *  - Map the IRQs and iomem regions to DOM0
  */
-int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
-                  struct rangeset *iomem_ranges, struct rangeset *irq_ranges)
+int __overlay_init handle_device(struct domain *d, struct dt_device_node *dev,
+                                 p2m_type_t p2mt,
+                                 struct rangeset *iomem_ranges,
+                                 struct rangeset *irq_ranges)
 {
     unsigned int naddr;
     unsigned int i;
xen/include/xen/dt-overlay.h +8 -0
@@ -42,10 +42,18 @@ struct xen_sysctl_dt_overlay;
 struct xen_domctl_dt_overlay;
 
 #ifdef CONFIG_OVERLAY_DTB
+
+#define __overlay_init
+
 long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op);
 long dt_overlay_domctl(struct domain *d, struct xen_domctl_dt_overlay *op);
+
 #else
+
 #include <xen/errno.h>
+
+#define __overlay_init __init
+
 static inline long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op)
 {
     return -EOPNOTSUPP;
#1 lore raw

xen/arch/arm/Makefile obj-$(CONFIG_HAS_ALTERNATIVE) += alterna · line 20

Quoted 10 lines · Jan Beulich
xen/arch/arm/Makefile +3 -1
@@ -15,7 +15,9 @@ obj-$(CONFIG_HAS_ALTERNATIVE) += alterna
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
-obj-y += device.o
+device-y := device.init.o
+device-$(CONFIG_OVERLAY_DTB) := device.o
+obj-y += $(device-y)

I know we've argued over this before and not come to a conclusion, but I still firmly believe this to be an anti-pattern we should expunge.

obj-y += $(if $(CONFIG_OVERLAY_DTB),device.o,device.init.o)

conveys the meaning more clearly and succinctly.

~Andrew

#2 lore raw
Quoted 15 lines · Andrew Cooper

xen/arch/arm/Makefile obj-$(CONFIG_HAS_ALTERNATIVE) += alterna · line 20

Quoted 10 lines · Jan Beulich
xen/arch/arm/Makefile +3 -1
@@ -15,7 +15,9 @@ obj-$(CONFIG_HAS_ALTERNATIVE) += alterna
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
-obj-y += device.o
+device-y := device.init.o
+device-$(CONFIG_OVERLAY_DTB) := device.o
+obj-y += $(device-y)

I know we've argued over this before and not come to a conclusion, but I still firmly believe this to be an anti-pattern we should expunge.

Quoted 1 line

obj-y += $(if $(CONFIG_OVERLAY_DTB),device.o,device.init.o)

Whereas I think this one (in its adjusted form to really only accept 'y') is, firmly believing that the "lists everywhere" approach is the more readable and, more importantly, more scalable one. The form you suggest quickly gets to its limits when multiple CONFIG_* need dealing with.

Jan

Reviewed-by
#3 lore raw
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper

xen/arch/arm/Makefile obj-$(CONFIG_HAS_ALTERNATIVE) += alterna · line 20

Quoted 10 lines · Jan Beulich
xen/arch/arm/Makefile +3 -1
@@ -15,7 +15,9 @@ obj-$(CONFIG_HAS_ALTERNATIVE) += alterna
 obj-y += cpuerrata.o
 obj-y += cpufeature.o
 obj-y += decode.o
-obj-y += device.o
+device-y := device.init.o
+device-$(CONFIG_OVERLAY_DTB) := device.o
+obj-y += $(device-y)

I know we've argued over this before and not come to a conclusion, but I still firmly believe this to be an anti-pattern we should expunge.

Quoted 6 lines
Quoted 1 line

obj-y += $(if $(CONFIG_OVERLAY_DTB),device.o,device.init.o)

Whereas I think this one (in its adjusted form to really only accept 'y') is, firmly believing that the "lists everywhere" approach is the more readable and, more importantly, more scalable one. The form you suggest quickly gets to its limits when multiple CONFIG_* need dealing with.

I must admit that I prefer Andrew approach. It took me less time to understand what the line does compared to your solution. I don't want to get involved in a discussion about consistency here (for me we can use both depending on number of CONFIG_ options), but with the line changed to what Andrew suggests:

~Michal