xen/keyhandler: Move key_table[] into __ro_after_init
PATCH 1/1 xen/keyhandler: Move key_table[] into __ro_after_init
All registration is done at boot. Almost...
iommu_dump_page_tables() is registered in iommu_hwdom_init(), which is called twice when LATE_HWDOM is in use.
register_irq_keyhandler() has an ASSERT() guarding againt multiple registration attempts, and the absence of bug reports hints at how many configurations use LATE_HWDOM in practice.
Move the registration into iommu_setup() just after printing the overall status of the IOMMU. For starters, the hardware domain is specifically excluded by iommu_dump_page_tables().
ept_dump_p2m_table is registered in setup_ept_dump() which is non-__init, but whose sole caller, start_vmx(), is __init. Move setup_ept_dump() to match.
With these two tweeks, all keyhandler reigstration is from __init functions, so register_{,irq_}keyhandler() can move, and key_table[] can become __ro_after_init.
No practical change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Daniel Smith <[email protected]>
CC: Jason Andryuk <[email protected]>
CC'ing some OpenXT folks just FYI.
--- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/common/keyhandler.c | 10 +++++----- xen/drivers/passthrough/iommu.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -1497,7 +1497,7 @@ static void cf_check ept_dump_p2m_table(unsigned char key)rcu_read_unlock (&domlist_read_lock); } -void setup_ept_dump (void ) +void __init setup_ept_dump (void ) {register_keyhandler ('D' , ept_dump_p2m_table,"dump VT-x EPT tables" ,0 ); }
xen/common/keyhandler.c +5 -5
@@ -40,7 +40,7 @@ static struct keyhandler {const char *desc;/* Description for help message. */ bool irq_callback,/* Call in irq context? if not, tasklet context. */ diagnostic;/* Include in 'dump all' handler. */ -} key_table[128] __read_mostly = +} key_table[128] __ro_after_init = {#define KEYHANDLER (k, f, desc, diag) \ [k] = { { .fn = (f) }, desc, 0, diag }
@@ -99,8 +99,8 @@ void handle_keypress(unsigned char key, bool need_context) } } -void register_keyhandler (unsigned char key,keyhandler_fn_t *fn, -const char *desc,bool diagnostic) +void __init register_keyhandler (unsigned char key,keyhandler_fn_t *fn, +const char *desc,bool diagnostic) {BUG_ON (key >=ARRAY_SIZE (key_table));/* Key in range? */ ASSERT (!key_table[key].fn);/* Clobbering something else? */
@@ -111,8 +111,8 @@ void register_keyhandler(unsigned char key, keyhandler_fn_t *fn, key_table[key].diagnostic = diagnostic; } -void register_irq_keyhandler (unsigned char key,irq_keyhandler_fn_t *fn, -const char *desc,bool diagnostic) +void __init register_irq_keyhandler (unsigned char key,irq_keyhandler_fn_t *fn, +const char *desc,bool diagnostic) {BUG_ON (key >=ARRAY_SIZE (key_table));/* Key in range? */ ASSERT (!key_table[key].irq_fn);/* Clobbering something else? */
xen/drivers/passthrough/iommu.c +2 -2
@@ -271,8 +271,6 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)if ( !is_iommu_enabled (d) )return ; -register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); -iommu_vcall (hd->platform_ops, hwdom_init, d); }
@@ -596,6 +594,8 @@ int __init iommu_setup(void) }else { +register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); +if (iommu_quarantine_init () )panic ("Could not set up quarantine\n" );
base-commit: 221f2748e8dabe8361b8cdfcffbeab9102c4c899
Signature · 1 line
2.39.2
Quoted 16 lines · Andrew Cooper
All registration is done at boot. Almost...
iommu_dump_page_tables()is registered iniommu_hwdom_init(), which is called twice whenLATE_HWDOMis in use.
register_irq_keyhandler()has anASSERT()guarding againt multiple registration attempts, and the absence of bug reports hints at how many configurations useLATE_HWDOMin practice.Move the registration into
iommu_setup()just after printing the overall status of the IOMMU. For starters, the hardware domain is specifically excluded byiommu_dump_page_tables().
ept_dump_p2m_tableis registered insetup_ept_dump()which is non-__init, but whose sole caller,start_vmx(), is__init. Movesetup_ept_dump()to match.
Quoted 7 lines
With these two tweeks, all keyhandler reigstration is from
__initfunctions, so register_{,irq_}keyhandler() can move, and key_table[] can become__ro_after_init.No practical change.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 18 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Daniel Smith <[email protected]>
CC: Jason Andryuk <[email protected]>CC'ing some OpenXT folks just FYI.
--- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/common/keyhandler.c | 10 +++++----- xen/drivers/passthrough/iommu.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)xen/arch/x86/mm/p2m-ept.c +0
-0
xen/arch/x86/mm/p2m-ept.c static void cf_check ept_dump_p2m_table(unsigned char key) · line 1500
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1
-1@@ -1497,7 +1497,7 @@ static void cf_check ept_dump_p2m_table(unsigned char key)rcu_read_unlock (&domlist_read_lock); } -void setup_ept_dump (void ) +void __init setup_ept_dump (void )
I would be tempted to just drop this function altogether and open-code the call to register_keyhandler().
Thanks, Roger.
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Andrew Cooper
All registration is done at boot. Almost...
iommu_dump_page_tables()is registered iniommu_hwdom_init(), which is called twice whenLATE_HWDOMis in use.
register_irq_keyhandler()has anASSERT()guarding againt multiple registration attempts, and the absence of bug reports hints at how many configurations useLATE_HWDOMin practice.Move the registration into
iommu_setup()just after printing the overall status of the IOMMU. For starters, the hardware domain is specifically excluded byiommu_dump_page_tables().
ept_dump_p2m_tableis registered insetup_ept_dump()which is non-__init, but whose sole caller,start_vmx(), is__init. Movesetup_ept_dump()to match.
Quoted 8 lines
Quoted 7 lines
With these two tweeks, all keyhandler reigstration is from
__initfunctions, so register_{,irq_}keyhandler() can move, and key_table[] can become__ro_after_init.No practical change.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Roger Pau Monné <[email protected]>
Thanks.
Quoted 22 lines
Quoted 22 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Daniel Smith <[email protected]>
CC: Jason Andryuk <[email protected]>CC'ing some OpenXT folks just FYI.
--- xen/arch/x86/mm/p2m-ept.c | 2 +- xen/common/keyhandler.c | 10 +++++----- xen/drivers/passthrough/iommu.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)xen/arch/x86/mm/p2m-ept.c +0
-0@@ -1497,7 +1497,7 @@ static void cf_check ept_dump_p2m_table(unsigned char key)rcu_read_unlock (&domlist_read_lock); }
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c static void cf_check ept_dump_p2m_table(unsigned char key) · line 1500
Quoted 2 lines
xen/arch/x86/mm/p2m-ept.c +1
-1-void setup_ept_dump (void ) +void __init setup_ept_dump (void )I would be tempted to just drop this function altogether and open-code the call to
register_keyhandler().
That would involve exporting ept_dump_p2m_table(), and quickly started detracting from the main purpose of the patch.
There are a whole bunch of keyhandler registration which are unconditional out of an initcall. I'd like to do something better, but there's nothing completely obvious.
~Andrew
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 600
Quoted 8 lines · Andrew Cooper
xen/drivers/passthrough/iommu.c +2
-0@@ -596,6 +594,8 @@ int __init iommu_setup(void) }else { +register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); +if (iommu_quarantine_init () )panic ("Could not set up quarantine\n" );
It's a little odd to have this immediately ahead of something that can panic(), but not a big deal of course. The line wants wrapping though, to stay within 80 cols.
Jan
Quoted 12 lines · Jan Beulich
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 600
Quoted 8 lines · Andrew Cooper
xen/drivers/passthrough/iommu.c +2
-0@@ -596,6 +594,8 @@ int __init iommu_setup(void) }else { +register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); +if (iommu_quarantine_init () )panic ("Could not set up quarantine\n" );It's a little odd to have this immediately ahead of something that can
panic(), but not a big deal of course. The line wants wrapping though, to stay within 80 cols.
I'm happy to put it somewhere else if you can suggest somewhere better.
I was just looking for somewhere which was clearly behind an iommu_enabled check, as it was in iommu_hwdom_init().
~Andrew
Quoted 14 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 600
Quoted 8 lines · Andrew Cooper
xen/drivers/passthrough/iommu.c +2
-0@@ -596,6 +594,8 @@ int __init iommu_setup(void) }else { +register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); +if (iommu_quarantine_init () )panic ("Could not set up quarantine\n" );It's a little odd to have this immediately ahead of something that can
panic(), but not a big deal of course. The line wants wrapping though, to stay within 80 cols.
Quoted 1 line
I'm happy to put it somewhere else if you can suggest somewhere better.
Just at the bottom of this very else block?
Jan
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 600
Quoted 8 lines · Andrew Cooper
xen/drivers/passthrough/iommu.c +2
-0@@ -596,6 +594,8 @@ int __init iommu_setup(void) }else { +register_keyhandler ('o' , &iommu_dump_page_tables,"dump iommu page tables" ,0 ); +if (iommu_quarantine_init () )panic ("Could not set up quarantine\n" );It's a little odd to have this immediately ahead of something that can
panic(), but not a big deal of course. The line wants wrapping though, to stay within 80 cols.
Quoted 2 lines
Quoted 1 line
I'm happy to put it somewhere else if you can suggest somewhere better.
Just at the bottom of this very else block?
Done.
~Andrew