xen/arch: Simplify virtual_region setup
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.
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 | 107 +++++++++++++++++-------------- xen/include/xen/bug.h | 6 -- xen/include/xen/virtual_region.h | 5 +- xen/include/xen/xen.lds.h | 17 +++++ 13 files changed, 95 insertions(+), 110 deletions(-)
base-commit: d638e304f13a5ef7d125de5ace5f7828a7b25bac
Signature · 1 line
2.30.2
PATCH 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
@@ -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
@@ -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/riscv/xen.lds.S +3 -10
@@ -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
@@ -131,16 +131,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
@@ -104,6 +104,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
Re: [PATCH 1/4] xen/link: Introduce a common BUGFRAMES definition
Quoted 9 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.cIntroduce a common BUGFRAMES define in
xen.lds.hahead of rearranging their structure.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 2/4 xen/virtual-region: Rework how bugframe linkage works
In reply to Andrew CooperThe 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -29,8 +29,7 @@ struct virtual_regionsymbols_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
@@ -105,13 +105,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
Re: [PATCH 2/4] xen/virtual-region: Rework how bugframe linkage works
Quoted 10 lines · Andrew Cooper
The start/stop1/etc linkage scheme predates struct
virtual_region, and assetup_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_regionto have a stop pointer rather than a count.This marginly simplifies both do_bug_frame()s and
prepare_payload(), but it massively simplifiessetup_virtual_regions()by allowing the compiler to initialise the .frame[] array at build time.
Quoted 7 lines
virtual_region.cis the only user of the linker symbols, and this is unlikely to change given the purpose of structvirtual_region, so move their externs out ofbug.hNo functional change.
Signed-off-by Andrew Cooper <[email protected]>
Of course ...
Quoted 30 lines
xen/common/virtual_region.c +13
-0@@ -9,12 +9,25 @@#include <xen/spinlock.h> #include <xen/virtual_region.h> +extern const struct bug_frame + __start_bug_frames_0[], __stop_bug_frames_0[], + __start_bug_frames_1[], __stop_bug_frames_1[], + __start_bug_frames_2[], __stop_bug_frames_2[], + __start_bug_frames_3[], __stop_bug_frames_3[]; +static struct virtual_region core = { .list =LIST_HEAD_INIT (core.list), .text_start = _stext, .text_end = _etext, .rodata_start = _srodata, .rodata_end = _erodata, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };/* Becomes irrelevant when __init sections are cleared. */ @@ -22,6 +35,13 @@ static struct virtual_region core_init __initdata = { .list = LIST_HEAD_INIT(core_init.list),
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 45
Quoted 10 lines
xen/common/virtual_region.c +7
-0.text_start = _sinittext, .text_end = _einittext, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };
... this is now calling yet louder for splitting runtime from init bug frame records.
Jan
Re: [PATCH 2/4] xen/virtual-region: Rework how bugframe linkage works
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
The start/stop1/etc linkage scheme predates struct
virtual_region, and assetup_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_regionto have a stop pointer rather than a count.This marginly simplifies both do_bug_frame()s and
prepare_payload(), but it massively simplifiessetup_virtual_regions()by allowing the compiler to initialise the .frame[] array at build time.
Quoted 8 lines
Quoted 7 lines
virtual_region.cis the only user of the linker symbols, and this is unlikely to change given the purpose of structvirtual_region, so move their externs out ofbug.hNo functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 30 lines
Of course ...
Quoted 27 lines
xen/common/virtual_region.c +13
-0@@ -9,12 +9,25 @@#include <xen/spinlock.h> #include <xen/virtual_region.h> +extern const struct bug_frame + __start_bug_frames_0[], __stop_bug_frames_0[], + __start_bug_frames_1[], __stop_bug_frames_1[], + __start_bug_frames_2[], __stop_bug_frames_2[], + __start_bug_frames_3[], __stop_bug_frames_3[]; +static struct virtual_region core = { .list =LIST_HEAD_INIT (core.list), .text_start = _stext, .text_end = _etext, .rodata_start = _srodata, .rodata_end = _erodata, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };
Quoted 15 lines
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 45
Quoted 13 lines
xen/common/virtual_region.c +7
-0/* Becomes irrelevant when __init sections are cleared. */ @@ -22,6 +35,13 @@ static struct virtual_region core_init __initdata = { .list = LIST_HEAD_INIT(core_init.list), .text_start = _sinittext, .text_end = _einittext, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };... this is now calling yet louder for splitting runtime from init bug frame records.
How do you propose we do this?
We can probably do it for *.init.o objects by renaming the bugframe sections too, but unless we can do it for *every* bugframe emitted in all init code, splitting this will break things.
~Andrew
Re: [PATCH 2/4] xen/virtual-region: Rework how bugframe linkage works
Quoted 45 lines · Andrew Cooper
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Andrew Cooper
xen/common/virtual_region.c +13
-0@@ -9,12 +9,25 @@#include <xen/spinlock.h> #include <xen/virtual_region.h> +extern const struct bug_frame + __start_bug_frames_0[], __stop_bug_frames_0[], + __start_bug_frames_1[], __stop_bug_frames_1[], + __start_bug_frames_2[], __stop_bug_frames_2[], + __start_bug_frames_3[], __stop_bug_frames_3[]; +static struct virtual_region core = { .list =LIST_HEAD_INIT (core.list), .text_start = _stext, .text_end = _etext, .rodata_start = _srodata, .rodata_end = _erodata, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };Quoted 15 lines
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 45
Quoted 13 lines
xen/common/virtual_region.c +7
-0/* Becomes irrelevant when __init sections are cleared. */ @@ -22,6 +35,13 @@ static struct virtual_region core_init __initdata = { .list = LIST_HEAD_INIT(core_init.list), .text_start = _sinittext, .text_end = _einittext, + + .frame = { + { __start_bug_frames_0, __stop_bug_frames_0 }, + { __start_bug_frames_1, __stop_bug_frames_1 }, + { __start_bug_frames_2, __stop_bug_frames_2 }, + { __start_bug_frames_3, __stop_bug_frames_3 }, + }, };... this is now calling yet louder for splitting runtime from init bug frame records.
Quoted 5 lines
How do you propose we do this?
We can probably do it for *.init.o objects by renaming the bugframe sections too, but unless we can do it for *every* bugframe emitted in all init code, splitting this will break things.
On halfway recent toolchains we can pass -Wa,--sectname-subst and then construct section names derived from the containing text ones.
Jan
Re: [PATCH 2/4] xen/virtual-region: Rework how bugframe linkage works
In reply to Andrew CooperQuoted 11 lines · Andrew Cooper
The start/stop1/etc linkage scheme predates struct
virtual_region, and assetup_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_regionto have a stop pointer rather than a count.This marginly simplifies both do_bug_frame()s and
prepare_payload(), but it massively simplifiessetup_virtual_regions()by allowing the compiler to initialise the .frame[] array at build time.
Quoted 7 lines
virtual_region.cis the only user of the linker symbols, and this is unlikely to change given the purpose of structvirtual_region, so move their externs out ofbug.hNo functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 3/4 xen/virtual-region: Link the list build time
In reply to Andrew CooperGiven 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]>
--- xen/common/virtual_region.c | 45 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-)
xen/common/virtual_region.c +30 -15
@@ -15,8 +15,19 @@ 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. +*/ +static struct list_head virtual_region_list; +static struct virtual_region core, core_init; +static struct virtual_region core = { - .list =LIST_HEAD_INIT (core.list), + .list = { + .next = &core_init.list, + .prev = &virtual_region_list, + }, + .text_start = _stext, .text_end = _etext, .rodata_start = _srodata,
@@ -32,7 +43,11 @@ 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 = { + .next = &virtual_region_list, + .prev = &core.list, + }, + .text_start = _sinittext, .text_end = _einittext,
@@ -50,7 +65,10 @@ 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 = { + .next = &core.list, + .prev = &core_init.list, +};static DEFINE_SPINLOCK (virtual_region_lock);static DEFINE_RCU_READ_LOCK (rcu_virtual_region_lock);
@@ -73,15 +91,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 +105,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 +173,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
Re: [PATCH 3/4] xen/virtual-region: Link the list build time
Quoted 3 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).
Hmm, technically that's correct, but isn't the overall result more fragile, in being more error prone if going forward someone found a need to alter things? Kind of supporting that view is also ...
Quoted 3 lines
--- xen/common/virtual_region.c | 45 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-)
... the diffstat of the change. It's perhaps also for a reason that ...
Quoted 37 lines
xen/common/virtual_region.c +17
-2@@ -15,8 +15,19 @@ 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. +*/ +static struct list_head virtual_region_list; +static struct virtual_region core, core_init; +static struct virtual_region core = { - .list =LIST_HEAD_INIT (core.list), + .list = { + .next = &core_init.list, + .prev = &virtual_region_list, + }, + .text_start = _stext, .text_end = _etext, .rodata_start = _srodata,@@ -32,7 +43,11 @@ 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 = { + .next = &virtual_region_list, + .prev = &core.list, + }, + .text_start = _sinittext, .text_end = _einittext,
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 71
Quoted 8 lines
xen/common/virtual_region.c +4
-1@@ -50,7 +65,10 @@ 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 = { + .next = &core.list, + .prev = &core_init.list, +};
... there's no pre-cooked construct to avoid any open-coding at least here.
To clarify up front: I'm willing to be convinced otherwise, and I therefore might subsequently provide an ack. I'm also specifically not meaning this to be treated as "pending objection"; if another maintainer provides an ack, that's okay(ish) with me.
Jan
Re: [PATCH 3/4] xen/virtual-region: Link the list build time
Quoted 61 lines · Jan Beulich
Quoted 3 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).
Hmm, technically that's correct, but isn't the overall result more fragile, in being more error prone if going forward someone found a need to alter things? Kind of supporting that view is also ...
Quoted 3 lines
--- xen/common/virtual_region.c | 45 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-)... the diffstat of the change. It's perhaps also for a reason that ...
Quoted 37 lines
xen/common/virtual_region.c +17
-2@@ -15,8 +15,19 @@ 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. +*/ +static struct list_head virtual_region_list; +static struct virtual_region core, core_init; +static struct virtual_region core = { - .list =LIST_HEAD_INIT (core.list), + .list = { + .next = &core_init.list, + .prev = &virtual_region_list, + }, + .text_start = _stext, .text_end = _etext, .rodata_start = _srodata,@@ -32,7 +43,11 @@ 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 = { + .next = &virtual_region_list, + .prev = &core.list, + }, + .text_start = _sinittext, .text_end = _einittext,xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 71
Quoted 8 lines
xen/common/virtual_region.c +4
-1@@ -50,7 +65,10 @@ 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 = { + .next = &core.list, + .prev = &core_init.list, +};... there's no pre-cooked construct to avoid any open-coding at least here.
Quoted 4 lines
To clarify up front: I'm willing to be convinced otherwise, and I therefore might subsequently provide an ack. I'm also specifically not meaning this to be treated as "pending objection"; if another maintainer provides an ack, that's okay(ish) with me.
I think it's a very small price to pay in order to allow patch 4 to exist.
If you can think of a nice way to express this with a pre-cooked construct then suggestions welcome, but it's a really complicated piece of metaprogramming to express in a nice way.
~Andrew
Re: [PATCH 3/4] xen/virtual-region: Link the list build time
Quoted 67 lines · Andrew Cooper
Quoted 61 lines · Jan Beulich
Quoted 3 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).
Hmm, technically that's correct, but isn't the overall result more fragile, in being more error prone if going forward someone found a need to alter things? Kind of supporting that view is also ...
Quoted 3 lines
--- xen/common/virtual_region.c | 45 ++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-)... the diffstat of the change. It's perhaps also for a reason that ...
Quoted 37 lines
xen/common/virtual_region.c +17
-2@@ -15,8 +15,19 @@ 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. +*/ +static struct list_head virtual_region_list; +static struct virtual_region core, core_init; +static struct virtual_region core = { - .list =LIST_HEAD_INIT (core.list), + .list = { + .next = &core_init.list, + .prev = &virtual_region_list, + }, + .text_start = _stext, .text_end = _etext, .rodata_start = _srodata,@@ -32,7 +43,11 @@ 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 = { + .next = &virtual_region_list, + .prev = &core.list, + }, + .text_start = _sinittext, .text_end = _einittext,xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 71
Quoted 8 lines
xen/common/virtual_region.c +4
-1@@ -50,7 +65,10 @@ 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 = { + .next = &core.list, + .prev = &core_init.list, +};... there's no pre-cooked construct to avoid any open-coding at least here.
Quoted 4 lines
To clarify up front: I'm willing to be convinced otherwise, and I therefore might subsequently provide an ack. I'm also specifically not meaning this to be treated as "pending objection"; if another maintainer provides an ack, that's okay(ish) with me.
Quoted 5 lines
I think it's a very small price to pay in order to allow patch 4 to exist.
If you can think of a nice way to express this with a pre-cooked construct then suggestions welcome, but it's a really complicated piece of metaprogramming to express in a nice way.
I don't see any suitable pre-cooked construct, but something custom just for this file might be to have
/*
* For the built-in regions, the double linked list can be constructed at
* build time. Forward-declare the elements.
*/
static struct list_head virtual_region_list;
static struct virtual_region core, core_init;
#define ENTRY1() { .next = &core_init.list, .prev = &virtual_region_list } #define ENTRY2() { .next = &virtual_region_list, .prev = &core.list } #define ENTRY3() { .next = &core.list, .prev = &core_init.list }
such that they're all close together and hence the list arrangement can be easily seen. Sure, that'll still require each of the macros to be used exactly once. Maybe instead of numeric suffixes the name of the struct the macro is to be used in might help:
#define ENTRY_HEAD() { .next = &core.list, .prev = &core_init.list } #define ENTRY_CORE() { .next = &core_init.list, .prev = &virtual_region_list } #define ENTRY_INIT() { .next = &virtual_region_list, .prev = &core.list }
This way entries also come in list order.
Jan
PATCH 4/4 xen/virtual-region: Drop setup_virtual_regions()
In reply to Andrew CooperAll 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.
---
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/setup.c | 1 - xen/arch/x86/setup.c | 2 -- xen/common/virtual_region.c | 17 ++++++++++------- xen/include/xen/virtual_region.h | 2 -- 4 files changed, 10 insertions(+), 12 deletions(-)
xen/arch/arm/setup.c +0 -1
@@ -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
@@ -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 +10 -7
@@ -39,6 +39,11 @@ static struct virtual_region core = { { __start_bug_frames_2, __stop_bug_frames_2 }, { __start_bug_frames_3, __stop_bug_frames_3 }, }, + +#ifdef CONFIG_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };/* Becomes irrelevant when __init sections are cleared. */
@@ -57,6 +62,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_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };/*
@@ -168,13 +178,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 +0 -2
@@ -37,8 +37,6 @@ struct virtual_region };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
Re: [PATCH 4/4] xen/virtual-region: Drop setup_virtual_regions()
Quoted 15 lines · Andrew Cooper
xen/common/virtual_region.c +5
-0@@ -39,6 +39,11 @@ static struct virtual_region core = { { __start_bug_frames_2, __stop_bug_frames_2 }, { __start_bug_frames_3, __stop_bug_frames_3 }, }, + +#ifdef CONFIG_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };/* Becomes irrelevant when __init sections are cleared. */
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 70
Quoted 9 lines
xen/common/virtual_region.c +5
-0@@ -57,6 +62,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_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };
My main reservation here is this x86-specific code in a common file. Are we certain both RISC-V and PPC will get away without needing to touch this? If so, I might consider ack-ing. But really I'd prefer if this could be minimally abstracted, via e.g. CONFIG_HAS_EXTABLE (selected by x86 only for now).
Jan
Re: [PATCH 4/4] xen/virtual-region: Drop setup_virtual_regions()
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
xen/common/virtual_region.c +5
-0@@ -39,6 +39,11 @@ static struct virtual_region core = { { __start_bug_frames_2, __stop_bug_frames_2 }, { __start_bug_frames_3, __stop_bug_frames_3 }, }, + +#ifdef CONFIG_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };
Quoted 16 lines
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 70
Quoted 11 lines
xen/common/virtual_region.c +5
-0/* Becomes irrelevant when __init sections are cleared. */ @@ -57,6 +62,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_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };My main reservation here is this x86-specific code in a common file. Are we certain both RISC-V and PPC will get away without needing to touch this? If so, I might consider ack-ing. But really I'd prefer if this could be minimally abstracted, via e.g.
CONFIG_HAS_EXTABLE(selected by x86 only for now).
This isn't the first bit of CONFIG_X86 in this file. However, I'd not spotted that we have CONFIG_HAS_EX_TABLE already. I can swap.
As to extable on other architectures, that's not something I can answer, although it's not something I can see in Oleksii's or Shawn's series so far.
~Andrew
Jan Beulich
Reviewed-byRe: [PATCH 4/4] xen/virtual-region: Drop setup_virtual_regions()
Quoted 32 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
xen/common/virtual_region.c +5
-0@@ -39,6 +39,11 @@ static struct virtual_region core = { { __start_bug_frames_2, __stop_bug_frames_2 }, { __start_bug_frames_3, __stop_bug_frames_3 }, }, + +#ifdef CONFIG_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };Quoted 16 lines
xen/common/virtual_region.c static struct virtual_region core_init __initdata = { · line 70
Quoted 11 lines
xen/common/virtual_region.c +5
-0/* Becomes irrelevant when __init sections are cleared. */ @@ -57,6 +62,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_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };My main reservation here is this x86-specific code in a common file. Are we certain both RISC-V and PPC will get away without needing to touch this? If so, I might consider ack-ing. But really I'd prefer if this could be minimally abstracted, via e.g.
CONFIG_HAS_EXTABLE(selected by x86 only for now).
Quoted 2 lines
This isn't the first bit of
CONFIG_X86in this file. However, I'd not spotted that we haveCONFIG_HAS_EX_TABLEalready. I can swap.
At which point:
Jan
Re: [PATCH 4/4] xen/virtual-region: Drop setup_virtual_regions()
In reply to Andrew CooperQuoted 35 lines · Andrew Cooper
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Andrew Cooper
xen/common/virtual_region.c +5
-0@@ -39,6 +39,11 @@ static struct virtual_region core = { { __start_bug_frames_2, __stop_bug_frames_2 }, { __start_bug_frames_3, __stop_bug_frames_3 }, }, + +#ifdef CONFIG_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endif };
/* Becomes irrelevant when__initsections are cleared. */xen/common/virtual_region.c +5
-0@@ -57,6 +62,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_X86 + .ex = __start___ex_table, + .ex_end = __stop___ex_table, +#endifQuoted 8 lines
xen/common/virtual_region.c static struct virtual_region core_init · line 71
Quoted 1 line
xen/common/virtual_region.c +0
-0};My main reservation here is this x86-specific code in a common file.
Are we certain both RISC-V and PPC will get away without needing to touch this? If so, I might consider ack-ing. But really I'd prefer if
this could be minimally abstracted, via e.g.CONFIG_HAS_EXTABLE(selected by x86 only for now).
Quoted 8 lines
This isn't the first bit of
CONFIG_X86in this file. However, I'd not
spotted that we haveCONFIG_HAS_EX_TABLEalready. I can swap.As to extable on other architectures, that's not something I can answer,
although it's not something I can see in Oleksii's or Shawn's series so far.
That's correct for RISC-V. Currently, I'm not utilizing __start___ex_table/__stop___ex_table, and setup_virtual_regions() is called with setup_virtual_regions(NULL, NULL).
~ Oleksii