Skip to contentSkip to conversation

xen/arch: Simplify virtual_region setup

PATCH In review Andrew Cooper 4 participants 12 messages Apr 10, 2024 – Apr 12, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arch: Simplify virtual_region setup

There is nothing that setup_virtual_regions() does which can't be done at build time. Make this happen.

Importantly, this removes logic from needed prior to setting up exceptions.

v2:
* Only minor changes in patches 3 and 4.

Andrew Cooper (4):
xen/link: Introduce a common BUGFRAMES definition xen/virtual-region: Rework how bugframe linkage works xen/virtual-region: Link the list build time xen/virtual-region: Drop setup_virtual_regions()

 xen/arch/arm/setup.c             |   1 -
 xen/arch/arm/traps.c             |   5 +-
 xen/arch/arm/xen.lds.S           |  13 +---
 xen/arch/ppc/xen.lds.S           |  13 +---
 xen/arch/riscv/xen.lds.S         |  13 +---
 xen/arch/x86/setup.c             |   2 -
 xen/arch/x86/xen.lds.S           |  11 +---
 xen/common/bug.c                 |   5 +-
 xen/common/livepatch.c           |   7 +--
 xen/common/virtual_region.c      | 101 ++++++++++++++++---------------
 xen/include/xen/bug.h            |   6 --
 xen/include/xen/virtual_region.h |   7 +--
 xen/include/xen/xen.lds.h        |  17 ++++++
 13 files changed, 90 insertions(+), 111 deletions(-)

base-commit: 0e7ea8ca5fc9bce9248414f6aaf2dc861abd45d9

Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/4 xen/link: Introduce a common BUGFRAMES definition

Bugframe linkage is identical in all architectures. This is not surprising given that it is (now) only consumed by common/virtual_region.c

Introduce a common BUGFRAMES define in xen.lds.h ahead of rearranging their structure.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

---
 xen/arch/arm/xen.lds.S    | 13 +++----------
 xen/arch/ppc/xen.lds.S    | 13 +++----------
 xen/arch/riscv/xen.lds.S  | 13 +++----------
 xen/arch/x86/xen.lds.S    | 11 +----------
 xen/include/xen/xen.lds.h | 11 +++++++++++
 5 files changed, 21 insertions(+), 40 deletions(-)
xen/arch/arm/xen.lds.S +3 -10
index 2266c9536f05..bd884664adf6 100644
@@ -55,16 +55,9 @@ SECTIONS
   . = ALIGN(PAGE_SIZE);
   .rodata : {
         _srodata = .;          /* Read-only data */
-        /* Bug frames table */
-       __start_bug_frames = .;
-       *(.bug_frames.0)
-       __stop_bug_frames_0 = .;
-       *(.bug_frames.1)
-       __stop_bug_frames_1 = .;
-       *(.bug_frames.2)
-       __stop_bug_frames_2 = .;
-       *(.bug_frames.3)
-       __stop_bug_frames_3 = .;
+
+        BUGFRAMES
+
        *(.rodata)
        *(.rodata.*)
        *(.data.rel.ro)
xen/arch/ppc/xen.lds.S +3 -10
index 8840a0044666..38cd857187e2 100644
@@ -45,16 +45,9 @@ SECTIONS
     . = ALIGN(PAGE_SIZE);
     DECL_SECTION(.rodata) {
         _srodata = .;          /* Read-only data */
-        /* Bug frames table */
-        __start_bug_frames = .;
-        *(.bug_frames.0)
-        __stop_bug_frames_0 = .;
-        *(.bug_frames.1)
-        __stop_bug_frames_1 = .;
-        *(.bug_frames.2)
-        __stop_bug_frames_2 = .;
-        *(.bug_frames.3)
-        __stop_bug_frames_3 = .;
+
+        BUGFRAMES
+
         *(.rodata)
         *(.rodata.*)
         *(.data.rel.ro)
xen/arch/riscv/xen.lds.S +3 -10
index ace6f49c579c..070b19d91503 100644
@@ -42,16 +42,9 @@ SECTIONS
     . = ALIGN(PAGE_SIZE);
     .rodata : {
         _srodata = .;          /* Read-only data */
-        /* Bug frames table */
-        __start_bug_frames = .;
-        *(.bug_frames.0)
-        __stop_bug_frames_0 = .;
-        *(.bug_frames.1)
-        __stop_bug_frames_1 = .;
-        *(.bug_frames.2)
-        __stop_bug_frames_2 = .;
-        *(.bug_frames.3)
-        __stop_bug_frames_3 = .;
+
+        BUGFRAMES
+
         *(.rodata)
         *(.rodata.*)
         *(.data.rel.ro)
xen/arch/x86/xen.lds.S +1 -10
index 1ef6645128b2..9a1dfe1b340a 100644
@@ -127,16 +127,7 @@ SECTIONS
        . = ALIGN(PAGE_SIZE);
        __ro_after_init_end = .;
 
-       /* Bug frames table */
-       __start_bug_frames = .;
-       *(.bug_frames.0)
-       __stop_bug_frames_0 = .;
-       *(.bug_frames.1)
-       __stop_bug_frames_1 = .;
-       *(.bug_frames.2)
-       __stop_bug_frames_2 = .;
-       *(.bug_frames.3)
-       __stop_bug_frames_3 = .;
+       BUGFRAMES
 
        *(.rodata)
        *(.rodata.*)
xen/include/xen/xen.lds.h +11 -0
index be90f5ca0fdb..7ab7aa567872 100644
@@ -114,6 +114,17 @@
 
 /* List of constructs other than *_SECTIONS in alphabetical order. */
 
+#define BUGFRAMES                               \
+    __start_bug_frames = .;                     \
+    *(.bug_frames.0)                            \
+    __stop_bug_frames_0 = .;                    \
+    *(.bug_frames.1)                            \
+    __stop_bug_frames_1 = .;                    \
+    *(.bug_frames.2)                            \
+    __stop_bug_frames_2 = .;                    \
+    *(.bug_frames.3)                            \
+    __stop_bug_frames_3 = .;
+
 #ifdef CONFIG_HYPFS
 #define HYPFS_PARAM              \
        . = ALIGN(POINTER_ALIGN); \
Signature · 1 line
2.30.2
Acked-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] xen/link: Introduce a common BUGFRAMES definition

Hi Andrew,

Quoted 5 lines · Andrew Cooper

Bugframe linkage is identical in all architectures. This is not surprising given that it is (now) only consumed by common/virtual_region.c

Quoted 7 lines

Introduce a common BUGFRAMES define in xen.lds.h ahead of rearranging their structure.

No functional change.

For Arm:

~Michal

Acked-by on v2 1/4
#3 lore raw

Re: [PATCH v2 1/4] xen/link: Introduce a common BUGFRAMES definition

In reply to Andrew Cooper

Hi Andrew,

Quoted 10 lines · Andrew Cooper

Bugframe linkage is identical in all architectures. This is not surprising given that it is (now) only consumed by common/virtual_region.c

Introduce a common BUGFRAMES define in xen.lds.h ahead of rearranging their structure.

No functional change.

Thanks,
Shawn

#4 lore raw

PATCH v2 2/4 xen/virtual-region: Rework how bugframe linkage works

In reply to Andrew Cooper

The start/stop1/etc linkage scheme predates struct virtual_region, and as setup_virtual_regions() shows, it's awkward to express in the new scheme.

Change the linker to provide explicit start/stop symbols for each bugframe type, and change virtual_region to have a stop pointer rather than a count.

This marginly simplifies both do_bug_frame()s and prepare_payload(), but it massively simplifies setup_virtual_regions() by allowing the compiler to initialise the .frame[] array at build time.

virtual_region.c is the only user of the linker symbols, and this is unlikely to change given the purpose of struct virtual_region, so move their externs out of bug.h

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

---
 xen/arch/arm/traps.c             |  5 ++--
 xen/common/bug.c                 |  5 ++--
 xen/common/livepatch.c           |  7 +++--
 xen/common/virtual_region.c      | 45 ++++++++++++++------------------
 xen/include/xen/bug.h            |  6 -----
 xen/include/xen/virtual_region.h |  3 +--
 xen/include/xen/xen.lds.h        |  8 +++++-
 7 files changed, 35 insertions(+), 44 deletions(-)
xen/arch/arm/traps.c +2 -3
index 9cffe7f79005..a8039087c805 100644
@@ -1226,10 +1226,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc)
         for ( id = 0; id < BUGFRAME_NR; id++ )
         {
             const struct bug_frame *b;
-            unsigned int i;
 
-            for ( i = 0, b = region->frame[id].bugs;
-                  i < region->frame[id].n_bugs; b++, i++ )
+            for ( b = region->frame[id].start;
+                  b < region->frame[id].stop; b++ )
             {
                 if ( ((vaddr_t)bug_loc(b)) == pc )
                 {
xen/common/bug.c +2 -3
index c43e7c439735..b7c5d8fd4d4a 100644
@@ -25,10 +25,9 @@ int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc)
     for ( id = 0; id < BUGFRAME_NR; id++ )
     {
         const struct bug_frame *b;
-        size_t i;
 
-        for ( i = 0, b = region->frame[id].bugs;
-              i < region->frame[id].n_bugs; b++, i++ )
+        for ( b = region->frame[id].start;
+              b < region->frame[id].stop; b++ )
         {
             if ( bug_loc(b) == pc )
             {
xen/common/livepatch.c +3 -4
index cabfb6391117..351a3e0b9a60 100644
@@ -804,12 +804,11 @@ static int prepare_payload(struct payload *payload,
         if ( !sec )
             continue;
 
-        if ( !section_ok(elf, sec, sizeof(*region->frame[i].bugs)) )
+        if ( !section_ok(elf, sec, sizeof(*region->frame[i].start)) )
             return -EINVAL;
 
-        region->frame[i].bugs = sec->load_addr;
-        region->frame[i].n_bugs = sec->sec->sh_size /
-                                  sizeof(*region->frame[i].bugs);
+        region->frame[i].start = sec->load_addr;
+        region->frame[i].stop  = sec->load_addr + sec->sec->sh_size;
     }
 
     sec = livepatch_elf_sec_by_name(elf, ".altinstructions");
xen/common/virtual_region.c +20 -25

69 lines not on this page · raw message

xen/include/xen/bug.h +0 -6
index 77fe1e1ba840..99814c4bef36 100644
@@ -155,12 +155,6 @@ int do_bug_frame(const struct cpu_user_regs *regs, unsigned long pc);
 
 #endif /* CONFIG_GENERIC_BUG_FRAME */
 
-extern const struct bug_frame __start_bug_frames[],
-                              __stop_bug_frames_0[],
-                              __stop_bug_frames_1[],
-                              __stop_bug_frames_2[],
-                              __stop_bug_frames_3[];
-
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __XEN_BUG_H__ */
xen/include/xen/virtual_region.h +1 -2
index dcdc95ba494c..c8a90e3ef26d 100644
@@ -29,8 +29,7 @@ struct virtual_region
     symbols_lookup_t *symbols_lookup;
 
     struct {
-        const struct bug_frame *bugs; /* The pointer to array of bug frames. */
-        size_t n_bugs;          /* The number of them. */
+        const struct bug_frame *start, *stop; /* Pointers to array of bug frames. */
     } frame[BUGFRAME_NR];
 
     const struct exception_table_entry *ex;
xen/include/xen/xen.lds.h +7 -1
index 7ab7aa567872..a17810bb286f 100644
@@ -115,13 +115,19 @@
 /* List of constructs other than *_SECTIONS in alphabetical order. */
 
 #define BUGFRAMES                               \
-    __start_bug_frames = .;                     \
+    __start_bug_frames_0 = .;                   \
     *(.bug_frames.0)                            \
     __stop_bug_frames_0 = .;                    \
+                                                \
+    __start_bug_frames_1 = .;                   \
     *(.bug_frames.1)                            \
     __stop_bug_frames_1 = .;                    \
+                                                \
+    __start_bug_frames_2 = .;                   \
     *(.bug_frames.2)                            \
     __stop_bug_frames_2 = .;                    \
+                                                \
+    __start_bug_frames_3 = .;                   \
     *(.bug_frames.3)                            \
     __stop_bug_frames_3 = .;
 
Signature · 1 line
2.30.2
Acked-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] xen/virtual-region: Rework how bugframe linkage works

Hi Andrew,

Quoted 9 lines · Andrew Cooper

The start/stop1/etc linkage scheme predates struct virtual_region, and as setup_virtual_regions() shows, it's awkward to express in the new scheme.

Change the linker to provide explicit start/stop symbols for each bugframe type, and change virtual_region to have a stop pointer rather than a count.

This marginly simplifies both do_bug_frame()s and prepare_payload(), but it

NIT: s/marginly/marginally

Quoted 7 lines

massively simplifies setup_virtual_regions() by allowing the compiler to initialise the .frame[] array at build time.

virtual_region.c is the only user of the linker symbols, and this is unlikely to change given the purpose of struct virtual_region, so move their externs out of bug.h

Quoted 5 lines

No functional change.

For Arm:

~Michal

#6 lore raw

Re: [PATCH v2 2/4] xen/virtual-region: Rework how bugframe linkage works

Quoted 4 lines · Michal Orzel

Hi Andrew,

Quoted 1 line · Andrew Cooper
Quoted 8 lines
Quoted 7 lines

The start/stop1/etc linkage scheme predates struct virtual_region, and as setup_virtual_regions() shows, it's awkward to express in the new scheme.

Change the linker to provide explicit start/stop symbols for each bugframe type, and change virtual_region to have a stop pointer rather than a count.

This marginly simplifies both do_bug_frame()s and prepare_payload(), but it

NIT: s/marginly/marginally

Fixed.

Quoted 8 lines
Quoted 8 lines

massively simplifies setup_virtual_regions() by allowing the compiler to initialise the .frame[] array at build time.

virtual_region.c is the only user of the linker symbols, and this is unlikely to change given the purpose of struct virtual_region, so move their externs out of bug.h

Quoted 7 lines
Quoted 5 lines

No functional change.

For Arm:

Thanks.

~Andrew

#7 lore raw

PATCH v2 3/4 xen/virtual-region: Link the list build time

In reply to Andrew Cooper

Given 3 statically initialised objects, its easy to link the list at build time. There's no need to do it during runtime at boot (and with IRQs-off, even).

As a consequence, register_virtual_region() can now move inside ifdef CONFIG_LIVEPATCH like unregister_virtual_region().

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

v2:
* Collect the initialisers togoether too.

---
 xen/common/virtual_region.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
xen/common/virtual_region.c +22 -15
index 7d8bdeb61282..db3e0dc9fe74 100644
@@ -15,8 +15,18 @@ extern const struct bug_frame
     __start_bug_frames_2[], __stop_bug_frames_2[],
     __start_bug_frames_3[], __stop_bug_frames_3[];
 
+/*
+ * For the built-in regions, the double linked list can be constructed at
+ * build time.  Forward-declare the elements and their initialisers.
+ */
+static struct list_head virtual_region_list;
+static struct virtual_region core, core_init;
+#define LIST_ENTRY_HEAD() { .next = &core.list,           .prev = &core_init.list }
+#define LIST_ENTRY_CORE() { .next = &core_init.list,      .prev = &virtual_region_list }
+#define LIST_ENTRY_INIT() { .next = &virtual_region_list, .prev = &core.list }
+
 static struct virtual_region core = {
-    .list = LIST_HEAD_INIT(core.list),
+    .list = LIST_ENTRY_CORE(),
     .text_start = _stext,
     .text_end = _etext,
     .rodata_start = _srodata,
@@ -32,7 +42,7 @@ static struct virtual_region core = {
 
 /* Becomes irrelevant when __init sections are cleared. */
 static struct virtual_region core_init __initdata = {
-    .list = LIST_HEAD_INIT(core_init.list),
+    .list = LIST_ENTRY_INIT(),
     .text_start = _sinittext,
     .text_end = _einittext,
 
@@ -50,7 +60,7 @@ static struct virtual_region core_init __initdata = {
  *
  * All readers of virtual_region_list MUST use list_for_each_entry_rcu.
  */
-static LIST_HEAD(virtual_region_list);
+static struct list_head virtual_region_list = LIST_ENTRY_HEAD();
 static DEFINE_SPINLOCK(virtual_region_lock);
 static DEFINE_RCU_READ_LOCK(rcu_virtual_region_lock);
 
@@ -73,15 +83,6 @@ const struct virtual_region *find_text_region(unsigned long addr)
     return region;
 }
 
-void register_virtual_region(struct virtual_region *r)
-{
-    unsigned long flags;
-
-    spin_lock_irqsave(&virtual_region_lock, flags);
-    list_add_tail_rcu(&r->list, &virtual_region_list);
-    spin_unlock_irqrestore(&virtual_region_lock, flags);
-}
-
 /*
  * Suggest inline so when !CONFIG_LIVEPATCH the function is not left
  * unreachable after init code is removed.
@@ -96,6 +97,15 @@ static void inline remove_virtual_region(struct virtual_region *r)
 }
 
 #ifdef CONFIG_LIVEPATCH
+void register_virtual_region(struct virtual_region *r)
+{
+    unsigned long flags;
+
+    spin_lock_irqsave(&virtual_region_lock, flags);
+    list_add_tail_rcu(&r->list, &virtual_region_list);
+    spin_unlock_irqrestore(&virtual_region_lock, flags);
+}
+
 void unregister_virtual_region(struct virtual_region *r)
 {
     remove_virtual_region(r);
@@ -155,9 +165,6 @@ void __init setup_virtual_regions(const struct exception_table_entry *start,
 {
     core_init.ex = core.ex = start;
     core_init.ex_end = core.ex_end = end;
-
-    register_virtual_region(&core_init);
-    register_virtual_region(&core);
 }
 
 /*
Signature · 1 line
2.30.2
Reviewed-by on v2 3/4
#8 lore raw

Re: [PATCH v2 3/4] xen/virtual-region: Link the list build time

Hi Andrew,

Quoted 10 lines · Andrew Cooper

Given 3 statically initialised objects, its easy to link the list at build time. There's no need to do it during runtime at boot (and with IRQs-off, even).

As a consequence, register_virtual_region() can now move inside ifdef CONFIG_LIVEPATCH like unregister_virtual_region().

Maybe with ...

Quoted 25 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

v2:
* Collect the initialisers togoether too.

---
 xen/common/virtual_region.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
xen/common/virtual_region.c +0 -0
index 7d8bdeb61282..db3e0dc9fe74 100644

xen/common/virtual_region.c extern const struct bug_frame · line 23

Quoted 9 lines
xen/common/virtual_region.c +6 -0
@@ -15,8 +15,18 @@ extern const struct bug_frame
     __start_bug_frames_2[], __stop_bug_frames_2[],
     __start_bug_frames_3[], __stop_bug_frames_3[];
 
+/*
+ * For the built-in regions, the double linked list can be constructed at
+ * build time.  Forward-declare the elements and their initialisers.
+ */
+static struct list_head virtual_region_list;
+static struct virtual_region core, core_init;

... empty line here for better readability

xen/common/virtual_region.c extern const struct bug_frame · line 26

Quoted 3 lines
xen/common/virtual_region.c +3 -0
+#define LIST_ENTRY_HEAD() { .next = &core.list,           .prev = &core_init.list }
+#define LIST_ENTRY_CORE() { .next = &core_init.list,      .prev = &virtual_region_list }
+#define LIST_ENTRY_INIT() { .next = &virtual_region_list, .prev = &core.list }

~Michal

#9 lore raw

Re: [PATCH v2 3/4] xen/virtual-region: Link the list build time

Quoted 11 lines · Michal Orzel

Hi Andrew,

Quoted 8 lines · Andrew Cooper
xen/common/virtual_region.c +0 -0
index 7d8bdeb61282..db3e0dc9fe74 100644
@@ -15,8 +15,18 @@ extern const struct bug_frame
     __start_bug_frames_2[], __stop_bug_frames_2[],
     __start_bug_frames_3[], __stop_bug_frames_3[];
 
Quoted 7 lines

xen/common/virtual_region.c extern const struct bug_frame · line 23

Quoted 6 lines
xen/common/virtual_region.c +6 -0
+/*
+ * For the built-in regions, the double linked list can be constructed at
+ * build time.  Forward-declare the elements and their initialisers.
+ */
+static struct list_head virtual_region_list;
+static struct virtual_region core, core_init;

... empty line here for better readability

Will do.  Thanks.

~Andrew

#10 lore raw

PATCH v2 4/4 xen/virtual-region: Drop setup_virtual_regions()

In reply to Andrew Cooper

All other actions it used to perform have been converted to build-time initialisation. The extable setup can done at build time too.

This is one fewer setup step required to get exceptions working.

Take the opportunity to move 'core' into read_mostly, where it probably should have lived all along.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

v2:
* Use CONFIG_HAS_EX_TABLE

---
 xen/arch/arm/setup.c             |  1 -
 xen/arch/x86/setup.c             |  2 --
 xen/common/virtual_region.c      | 19 +++++++++++--------
 xen/include/xen/virtual_region.h |  4 ++--
 4 files changed, 13 insertions(+), 13 deletions(-)
xen/arch/arm/setup.c +0 -1
index 424744ad5e1a..b9a7f61f73ef 100644
@@ -719,7 +719,6 @@ void asmlinkage __init start_xen(unsigned long boot_phys_offset,
     percpu_init_areas();
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
-    setup_virtual_regions(NULL, NULL);
     /* Initialize traps early allow us to get backtrace when an error occurred */
     init_traps();
 
xen/arch/x86/setup.c +0 -2
index ac983ddc6977..86cd8b999774 100644
@@ -1014,8 +1014,6 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
     smp_prepare_boot_cpu();
     sort_exception_tables();
 
-    setup_virtual_regions(__start___ex_table, __stop___ex_table);
-
     /* Full exception support from here on in. */
 
     rdmsrl(MSR_EFER, this_cpu(efer));
xen/common/virtual_region.c +11 -8
index db3e0dc9fe74..0d0a3df0b669 100644
@@ -25,7 +25,7 @@ static struct virtual_region core, core_init;
 #define LIST_ENTRY_CORE() { .next = &core_init.list,      .prev = &virtual_region_list }
 #define LIST_ENTRY_INIT() { .next = &virtual_region_list, .prev = &core.list }
 
-static struct virtual_region core = {
+static struct virtual_region core __read_mostly = {
     .list = LIST_ENTRY_CORE(),
     .text_start = _stext,
     .text_end = _etext,
@@ -38,6 +38,11 @@ static struct virtual_region core = {
         { __start_bug_frames_2, __stop_bug_frames_2 },
         { __start_bug_frames_3, __stop_bug_frames_3 },
     },
+
+#ifdef CONFIG_HAS_EX_TABLE
+    .ex = __start___ex_table,
+    .ex_end = __stop___ex_table,
+#endif
 };
 
 /* Becomes irrelevant when __init sections are cleared. */
@@ -52,6 +57,11 @@ static struct virtual_region core_init __initdata = {
         { __start_bug_frames_2, __stop_bug_frames_2 },
         { __start_bug_frames_3, __stop_bug_frames_3 },
     },
+
+#ifdef CONFIG_HAS_EX_TABLE
+    .ex = __start___ex_table,
+    .ex_end = __stop___ex_table,
+#endif
 };
 
 /*
@@ -160,13 +170,6 @@ void __init unregister_init_virtual_region(void)
     remove_virtual_region(&core_init);
 }
 
-void __init setup_virtual_regions(const struct exception_table_entry *start,
-                                  const struct exception_table_entry *end)
-{
-    core_init.ex = core.ex = start;
-    core_init.ex_end = core.ex_end = end;
-}
-
 /*
  * Local variables:
  * mode: C
xen/include/xen/virtual_region.h +2 -2
index c8a90e3ef26d..a18dfb6fb05e 100644
@@ -32,13 +32,13 @@ struct virtual_region
         const struct bug_frame *start, *stop; /* Pointers to array of bug frames. */
     } frame[BUGFRAME_NR];
 
+#ifdef CONFIG_HAS_EX_TABLE
     const struct exception_table_entry *ex;
     const struct exception_table_entry *ex_end;
+#endif
 };
 
 const struct virtual_region *find_text_region(unsigned long addr);
-void setup_virtual_regions(const struct exception_table_entry *start,
-                           const struct exception_table_entry *end);
 void unregister_init_virtual_region(void);
 void register_virtual_region(struct virtual_region *r);
 void unregister_virtual_region(struct virtual_region *r);
Signature · 1 line
2.30.2
Reviewed-by Tested-by on v2 4/4
#11 lore raw

Re: [PATCH v2 4/4] xen/virtual-region: Drop setup_virtual_regions()

Quoted 7 lines · Andrew Cooper

All other actions it used to perform have been converted to build-time initialisation. The extable setup can done at build time too.

Quoted 6 lines

This is one fewer setup step required to get exceptions working.

Take the opportunity to move 'core' into read_mostly, where it probably should have lived all along.

For the arm part:

I’ve also tested the serie on arm32 and arm64 on qemu