limit passing around of cpu_user_regs
cover limit passing around of cpu_user_regs
Unlike (synchronous) exception handlers, interrupt handlers don't normally have a need to know the outer context's register state. Similarly, the vast majority of key handlers has no need for such.
1: keyhandler: don't pass cpu_user_regs around
2: IRQ: generalize [gs]et_irq_regs()
3: serial: drop serial_rx_fn's regs parameter
4: PV-shim: drop pv_console_rx()'s regs parameter
5: serial: drop serial_[rt]x_interrupt()'s regs parameter 6: IRQ: drop regs parameter from handler functions
7: x86/vPMU: drop regs parameter from interrupt functions 8: x86/APIC: drop regs parameter from direct vector handler functions
Jan
PATCH 1/8 limit passing around of cpu_user_regs
There are exactly two handlers which care about the registers. Have handle_keypress() make the pointer available via a per-CPU variable, thus eliminating the need to pass it to all IRQ key handlers, making sure that a console-invoked key's handling can still nest inside a sysctl-invoked one's.
---
Subsequently we may want to eliminate the fn/irq_fn union as well, along with dropping the now redundant irq_keyhandler_fn_t.
xen/common/keyhandler.c +21 -15
@@ -80,6 +80,7 @@ static void cf_check keypress_action(voi } static DECLARE_TASKLET(keypress_tasklet, keypress_action, NULL); +static DEFINE_PER_CPU(struct cpu_user_regs *, keypress_regs);void handle_keypress (unsigned char key,struct cpu_user_regs *regs) {
@@ -91,7 +92,16 @@ void handle_keypress(unsigned char key,if ( !in_irq () || h->irq_callback ) {console_start_log_everything (); - h->irq_callback ? h->irq_fn (key, regs) : h->fn (key); +if ( h->irq_callback ) + { +struct cpu_user_regs *old =this_cpu (keypress_regs); + +this_cpu (keypress_regs) = regs; + h->irq_fn (key); +this_cpu (keypress_regs) = old; + } +else + h->fn (key);console_end_log_everything (); }else
@@ -171,8 +181,7 @@ void cf_check dump_execstate(struct cpu_watchdog_enable (); } -static void cf_check dump_registers( -unsigned char key,struct cpu_user_regs *regs) +static void cf_check dump_registers(unsigned char key) {unsigned int cpu;
@@ -185,8 +194,8 @@ static void cf_check dump_registers(cpumask_copy (&dump_execstate_mask, &cpu_online_map);/* Get local execution state out immediately, in case we get stuck. */ -if ( regs ) -dump_execstate (regs); +if (this_cpu (keypress_regs) ) +dump_execstate (this_cpu (keypress_regs));else run_in_exception_handler (dump_execstate);
@@ -248,8 +257,7 @@ static void cf_check dump_hwdom_register } } -static void cf_check reboot_machine( -unsigned char key,struct cpu_user_regs *regs) +static void cf_check reboot_machine(unsigned char key) {printk ("'%c' pressed -> rebooting machine\n" , key);machine_restart (0 );
@@ -477,8 +485,7 @@ static void cf_check run_all_nonirq_keyh static DECLARE_TASKLET(run_all_keyhandlers_tasklet, run_all_nonirq_keyhandlers, NULL); -static void cf_check run_all_keyhandlers( -unsigned char key,struct cpu_user_regs *regs) +static void cf_check run_all_keyhandlers(unsigned char key) {struct keyhandler *h;unsigned int k;
@@ -494,7 +501,7 @@ static void cf_check run_all_keyhandlersif ( !h->irq_fn || !h->diagnostic || !h->irq_callback )continue ;printk ("[%c: %s]\n" , k, h->desc); - h->irq_fn (k, regs); + h->irq_fn (k); }watchdog_enable ();
@@ -511,17 +518,16 @@ static void cf_check do_debugger_trap_fabarrier (); } -static void cf_check do_debug_key(unsigned char key, struct cpu_user_regs *regs) +static void cf_check do_debug_key(unsigned char key) {printk ("'%c' pressed -> trapping into debugger\n" , key); -if ( regs ) -do_debugger_trap_fatal (regs); +if (this_cpu (keypress_regs) ) +do_debugger_trap_fatal (this_cpu (keypress_regs));else run_in_exception_handler (do_debugger_trap_fatal); } -static void cf_check do_toggle_alt_key( -unsigned char key,struct cpu_user_regs *regs) +static void cf_check do_toggle_alt_key(unsigned char key) { alt_key_handling = !alt_key_handling; printk("'%c' pressed -> using %s key handling\n", key,
xen/drivers/char/console.c +3 -3
@@ -280,7 +280,7 @@ static int *__read_mostly upper_thresh_astatic int *__read_mostly lower_thresh_adj = &xenlog_lower_thresh;static const char *__read_mostly thresh_adj ="standard" ; -static void cf_check do_toggle_guest(unsigned char key, struct cpu_user_regs *regs) +static void cf_check do_toggle_guest(unsigned char key) {if ( upper_thresh_adj == &xenlog_upper_thresh ) {
@@ -307,13 +307,13 @@ static void do_adj_thresh(unsigned char loglvl_str(*upper_thresh_adj)); } -static void cf_check do_inc_thresh(unsigned char key, struct cpu_user_regs *regs) +static void cf_check do_inc_thresh(unsigned char key) { ++*lower_thresh_adj;do_adj_thresh (key); } -static void cf_check do_dec_thresh(unsigned char key, struct cpu_user_regs *regs) +static void cf_check do_dec_thresh(unsigned char key) {if ( *lower_thresh_adj ) --*lower_thresh_adj;
xen/include/xen/keyhandler.h +2 -3
@@ -24,9 +24,7 @@ typedef void (keyhandler_fn_t)(unsigned* * Called in hardirq context with interrupts disabled. */ -struct cpu_user_regs ; -typedef void (irq_keyhandler_fn_t )(unsigned char key, -struct cpu_user_regs *regs); +typedef void irq_keyhandler_fn_t (unsigned char key);/* Initialize keytable with default handlers. */ void initialize_keytable (void );
@@ -46,6 +44,7 @@ void register_irq_keyhandler(unsigned ch bool diagnostic);/* Inject a keypress into the key-handling subsystem. */ +struct cpu_user_regs ;extern void handle_keypress (unsigned char key,struct cpu_user_regs *regs);enum crash_reason {
PATCH 2/8 IRQ: drop register parameter from handler functions
In reply to Jan BeulichIt's simply not needed anymore. Note how Linux made this change many years ago already, in 2.6.19 (late 2006, see [1]).
xen/arch/arm/gic.c +1 -1
@@ -397,7 +397,7 @@ void gic_interrupt(struct cpu_user_regs }while (1 ); } -static void maintenance_interrupt (int irq,void *dev_id,struct cpu_user_regs *regs) +static void maintenance_interrupt (int irq,void *dev_id) {/* * This is a dummy interrupt handler.
xen/arch/arm/irq.c +2 -3
@@ -182,8 +182,7 @@ void irq_set_affinity(struct irq_desc *d }int request_irq (unsigned int irq,unsigned int irqflags, -void (*handler)(int irq,void *dev_id, -struct cpu_user_regs *regs), +void (*handler)(int irq,void *dev_id),const char *devname,void *dev_id) {struct irqaction *action;
@@ -276,7 +275,7 @@ void do_IRQ(struct cpu_user_regs *regs,do { - action->handler (irq, action->dev_id, regs); + action->handler (irq, action->dev_id); action = action->next; }while ( action );
xen/arch/arm/time.c +2 -2
@@ -241,7 +241,7 @@ int reprogram_timer(s_time_t timeout) }/* Handle the firing timer */ -static void htimer_interrupt (int irq,void *dev_id,struct cpu_user_regs *regs) +static void htimer_interrupt (int irq,void *dev_id) {if (unlikely (!(READ_SYSREG (CNTHP_CTL_EL2 ) & CNTx_CTL_PENDING)) )return ;
@@ -255,7 +255,7 @@ static void htimer_interrupt(int irq, voWRITE_SYSREG (0 ,CNTHP_CTL_EL2 ); } -static void vtimer_interrupt (int irq,void *dev_id,struct cpu_user_regs *regs) +static void vtimer_interrupt (int irq,void *dev_id) {/* * Edge-triggered interrupts can be used for the virtual timer. Even
xen/arch/x86/irq.c +2 -2
@@ -962,7 +962,7 @@ static int __init cf_check irq_ratelimit__initcall (irq_ratelimit_init);int __init request_irq (unsigned int irq,unsigned int irqflags, -void (*handler)(int irq,void *dev_id,struct cpu_user_regs *regs), +void (*handler)(int irq,void *dev_id),const char * devname,void *dev_id) {struct irqaction * action;
@@ -2009,7 +2009,7 @@ void do_IRQ(struct cpu_user_regs *regs)spin_unlock_irq (&desc->lock); tsc_in = tb_init_done ?get_cycles () :0 ; - action->handler (irq, action->dev_id, regs); + action->handler (irq, action->dev_id);TRACE_3D (TRC_HW_IRQ_HANDLED , irq, tsc_in,get_cycles ());spin_lock_irq (&desc->lock);
xen/arch/x86/hpet.c +1 -2
@@ -237,8 +237,7 @@ again: } } -static void cf_check hpet_interrupt_handler( -int irq,void *data,struct cpu_user_regs *regs) +static void cf_check hpet_interrupt_handler(int irq, void *data) {struct hpet_event_channel *ch = data;
xen/arch/x86/time.c +1 -2
@@ -198,8 +198,7 @@ static void smp_send_timer_broadcast_ipi } } -static void cf_check timer_interrupt( -int irq,void *dev_id,struct cpu_user_regs *regs) +static void cf_check timer_interrupt(int irq, void *dev_id) {ASSERT (local_irq_is_enabled ());
xen/common/irq.c +1 -1
@@ -29,7 +29,7 @@ int init_one_irq_desc(struct irq_desc *dreturn err; } -void cf_check no_action(int cpl, void *dev_id, struct cpu_user_regs *regs) +void cf_check no_action(int cpl, void *dev_id) { }
xen/drivers/char/cadence-uart.c +1 -1
@@ -40,7 +40,7 @@ static struct cuart {#define cuart_read (uart, off) readl((uart)->regs + (off))#define cuart_write (uart, off,val) writel((val), (uart)->regs + (off)) -static void cuart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +static void cuart_interrupt (int irq,void *data) {struct serial_port *port = data;struct cuart *uart = port->uart;
xen/drivers/char/exynos4210-uart.c +1 -1
@@ -45,7 +45,7 @@ static struct exynos4210_uart {#define exynos4210_read (uart, off) readl((uart)->regs + off)#define exynos4210_write (uart, off, val) writel(val, (uart->regs) + off) -static void exynos4210_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +static void exynos4210_uart_interrupt (int irq,void *data) {struct serial_port *port = data;struct exynos4210_uart *uart = port->uart;
xen/drivers/char/imx-lpuart.c +1 -2
@@ -37,8 +37,7 @@ static struct imx_lpuart {struct vuart_info vuart; } imx8_com; -static void imx_lpuart_interrupt (int irq,void *data, -struct cpu_user_regs *regs) +static void imx_lpuart_interrupt (int irq,void *data) {struct serial_port *port = data;struct imx_lpuart *uart = port->uart;
xen/drivers/char/meson-uart.c +1 -2
@@ -61,8 +61,7 @@ static struct meson_uart {struct vuart_info vuart; } meson_com; -static void meson_uart_interrupt (int irq,void *data, -struct cpu_user_regs *regs) +static void meson_uart_interrupt (int irq,void *data) {struct serial_port *port = data;struct meson_uart *uart = port->uart;
xen/drivers/char/mvebu-uart.c +1 -2
@@ -67,8 +67,7 @@ static struct mvebu3700_uart {#define mvebu3700_read (uart, off) readl((uart)->regs + (off))#define mvebu3700_write (uart, off, val) writel(val, (uart)->regs + (off)) -static void mvebu3700_uart_interrupt (int irq,void *data, -struct cpu_user_regs *regs) +static void mvebu3700_uart_interrupt (int irq,void *data) {struct serial_port *port = data;struct mvebu3700_uart *uart = port->uart;
xen/drivers/char/ns16550.c +1 -2
@@ -175,8 +175,7 @@ static void handle_dw_usr_busy_quirk(str } } -static void cf_check ns16550_interrupt( -int irq,void *dev_id,struct cpu_user_regs *regs) +static void cf_check ns16550_interrupt(int irq, void *dev_id) {struct serial_port *port = dev_id;struct ns16550 *uart = port->uart;
xen/drivers/char/omap-uart.c +1 -1
@@ -59,7 +59,7 @@ static struct omap_uart {struct vuart_info vuart; } omap_com = {0}; -static void omap_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +static void omap_uart_interrupt (int irq,void *data) {struct serial_port *port = data;struct omap_uart *uart = port->uart;
xen/drivers/char/pl011.c +1 -1
@@ -82,7 +82,7 @@ static unsigned int pl011_intr_status(streturn (pl011_read (uart,RIS ) &pl011_read (uart,IMSC )); } -static void pl011_interrupt (int irq,void *data,struct cpu_user_regs *regs) +static void pl011_interrupt (int irq,void *data) {struct serial_port *port = data;struct pl011 *uart = port->uart;
xen/drivers/char/scif-uart.c +1 -1
@@ -102,7 +102,7 @@ static const struct port_params port_par }, }; -static void scif_uart_interrupt (int irq,void *data,struct cpu_user_regs *regs) +static void scif_uart_interrupt (int irq,void *data) {struct serial_port *port = data;struct scif_uart *uart = port->uart;
xen/drivers/passthrough/amd/iommu_init.c +1 -2
@@ -718,8 +718,7 @@ static void cf_check do_amd_iommu_irq(vo static DECLARE_SOFTIRQ_TASKLET(amd_iommu_irq_tasklet, do_amd_iommu_irq, NULL); -static void cf_check iommu_interrupt_handler( -int irq,void *dev_id,struct cpu_user_regs *regs) +static void cf_check iommu_interrupt_handler(int irq, void *dev_id) {unsigned long flags;struct amd_iommu *iommu = dev_id;
xen/drivers/passthrough/arm/smmu.c +2 -4
@@ -1097,16 +1097,14 @@ static irqreturn_t arm_smmu_global_fault }/* Xen: Interrupt handlers wrapper */ -static void arm_smmu_context_fault_xen (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_context_fault_xen (int irq,void *dev) {arm_smmu_context_fault (irq, dev); }#define arm_smmu_context_fault arm_smmu_context_fault_xen -static void arm_smmu_global_fault_xen (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_global_fault_xen (int irq,void *dev) {arm_smmu_global_fault (irq, dev); }
xen/drivers/passthrough/arm/smmu-v3.c +4 -8
@@ -880,8 +880,7 @@ static void arm_smmu_priq_tasklet(void *static int arm_smmu_device_disable (struct arm_smmu_device *smmu); -static void arm_smmu_gerror_handler (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_gerror_handler (int irq,void *dev) {u32 gerror, gerrorn, active;struct arm_smmu_device *smmu = dev;
@@ -926,8 +925,7 @@ static void arm_smmu_gerror_handler(intwritel (gerror, smmu->base +ARM_SMMU_GERRORN ); } -static void arm_smmu_combined_irq_handler (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_combined_irq_handler (int irq,void *dev) {struct arm_smmu_device *smmu = dev;
@@ -945,16 +943,14 @@ static void arm_smmu_combined_irq_tasklearm_smmu_priq_tasklet (dev); } -static void arm_smmu_evtq_irq_tasklet (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_evtq_irq_tasklet (int irq,void *dev) {struct arm_smmu_device *smmu = dev;tasklet_schedule (&(smmu->evtq_irq_tasklet)); } -static void arm_smmu_priq_irq_tasklet (int irq,void *dev, -struct cpu_user_regs *regs) +static void arm_smmu_priq_irq_tasklet (int irq,void *dev) {struct arm_smmu_device *smmu = dev;
xen/drivers/passthrough/vtd/iommu.c +1 -2
@@ -1119,8 +1119,7 @@ static void cf_check do_iommu_page_fault__do_iommu_page_fault (drhd->iommu); } -static void cf_check iommu_page_fault( -int irq,void *dev_id,struct cpu_user_regs *regs) +static void cf_check iommu_page_fault(int irq, void *dev_id) {/* * Just flag the tasklet as runnable. This is fine, according to VT-d
xen/include/xen/irq.h +3 -4
@@ -18,7 +18,7 @@ ASSERT(!in_irq() && (local_irq_is_enabled() || num_online_cpus() <= 1))struct irqaction { -void (*handler)(int irq,void *dev_id,struct cpu_user_regs *regs); +void (*handler)(int irq,void *dev_id);const char *name;void *dev_id;bool free_on_release;
@@ -119,12 +119,11 @@ extern int setup_irq(unsigned int irq, u struct irqaction *new);extern void release_irq (unsigned int irq,const void *dev_id);extern int request_irq (unsigned int irq,unsigned int irqflags, -void (*handler)(int irq,void *dev_id, -struct cpu_user_regs *regs), +void (*handler)(int irq,void *dev_id),const char *devname,void *dev_id);extern hw_irq_controller no_irq_type; -void cf_check no_action(int cpl, void *dev_id, struct cpu_user_regs *regs); +void cf_check no_action(int cpl, void *dev_id); unsigned int cf_check irq_startup_none(struct irq_desc *desc); void cf_check irq_actor_none(struct irq_desc *desc);#define irq_shutdown_none irq_actor_none
PATCH 3/8 serial: drop serial_rx_fn's regs parameter
In reply to Jan BeulichIn the one place where it's needed, get_irq_regs() can be used instead. This is in preparation of dropping the register parameters from IRQ handler functions.
xen/drivers/char/console.c +5 -5
@@ -527,12 +527,12 @@ static void switch_serial_input(void)printk ("\n" ); } -static void __serial_rx (char c,struct cpu_user_regs *regs) +static void __serial_rx (char c) {switch ( console_rx ) {case 0 : -return handle_keypress (c, regs); +return handle_keypress (c,get_irq_regs ());case 1 :/*
@@ -579,7 +579,7 @@ static void __serial_rx(char c, struct c#endif } -static void cf_check serial_rx(char c, struct cpu_user_regs *regs) +static void cf_check serial_rx(char c) {static int switch_code_count =0 ;
@@ -595,10 +595,10 @@ static void cf_check serial_rx(char c, s }for ( ; switch_code_count !=0 ; switch_code_count-- ) -__serial_rx (switch_code, regs); +__serial_rx (switch_code);/* Finally process the just-received character. */ -__serial_rx (c, regs); +__serial_rx (c); } static void cf_check notify_dom0_con_ring(void *unused)
xen/drivers/char/serial.c +1 -1
@@ -68,7 +68,7 @@ void serial_rx_interrupt(struct serial_pspin_unlock_irqrestore (&port->rx_lock, flags);if ( fn !=NULL ) - (*fn)(c &0x7f , regs); +fn (c &0x7f ); }void serial_tx_interrupt (struct serial_port *port,struct cpu_user_regs *regs)
xen/drivers/char/xen_pv_console.c +1 -1
@@ -118,7 +118,7 @@ size_t pv_console_rx(struct cpu_user_reg { c = cons_ring->in[MASK_XENCONS_IDX (cons++, cons_ring->in)];if ( cons_rx_handler ) -cons_rx_handler (c, regs); +cons_rx_handler (c); recv++; }
xen/include/xen/serial.h +1 -1
@@ -15,7 +15,7 @@struct cpu_user_regs ;/* Register a character-receive hook on the specified COM port. */ -typedef void (*serial_rx_fn )(char c,struct cpu_user_regs *regs); +typedef void (*serial_rx_fn )(char c);void serial_set_rx_handler (int handle,serial_rx_fn fn);/* Number of characters we buffer for a polling receiver. */
PATCH 4/8 PV-shim: drop pv_console_rx()'s regs parameter
In reply to Jan BeulichIt's not needed anymore. This is in preparation of dropping the register parameters from IRQ handler functions.
xen/arch/x86/guest/xen/xen.c +1 -1
@@ -181,7 +181,7 @@ static void cf_check xen_evtchn_upcall(s port += l1 *BITS_PER_LONG ;if ( pv_console && port ==pv_console_evtchn () ) -pv_console_rx (regs); +pv_console_rx ();else if ( pv_shim )pv_shim_inject_evtchn (port); }
xen/drivers/char/xen_pv_console.c +1 -1
@@ -94,7 +94,7 @@ evtchn_port_t pv_console_evtchn(void)return cons_evtchn; } -size_t pv_console_rx (struct cpu_user_regs *regs) +size_t pv_console_rx (void ) {char c;XENCONS_RING_IDX cons, prod;
xen/include/xen/pv_console.h +2 -2
@@ -9,7 +9,7 @@ void pv_console_init(void);void pv_console_set_rx_handler (serial_rx_fn fn);void pv_console_init_postirq (void );void pv_console_puts (const char *buf,size_t nr); -size_t pv_console_rx (struct cpu_user_regs *regs); +size_t pv_console_rx (void );evtchn_port_t pv_console_evtchn (void );#else
@@ -18,7 +18,7 @@ static inline void pv_console_init(void)static inline void pv_console_set_rx_handler (serial_rx_fn fn) { }static inline void pv_console_init_postirq (void ) { }static inline void pv_console_puts (const char *buf,size_t nr) { } -static inline size_t pv_console_rx (struct cpu_user_regs *regs) {return 0 ; } +static inline size_t pv_console_rx (void ) {return 0 ; }#endif /* !CONFIG_XEN_GUEST */ #endif /* __XEN_PV_CONSOLE_H__ */
Quoted 4 lines · Jan Beulich
Unlike (synchronous) exception handlers, interrupt handlers don't normally have a need to know the outer context's register state. Similarly, the vast majority of key handlers has no need for such.
Quoted 8 lines
1: keyhandler: don't pass
cpu_user_regsaround
2: IRQ: generalize [gs]et_irq_regs()
3: serial: drop serial_rx_fn's regs parameter
4: PV-shim: drop pv_console_rx()'s regs parameter
5: serial: drop serial_[rt]x_interrupt()'s regs parameter 6: IRQ: drop regs parameter from handler functions
7: x86/vPMU: drop regs parameter from interrupt functions 8: x86/APIC: drop regs parameter from direct vector handler functions
I'm sorry, I need to start over - somehow ordering got confused in the reply-to-s sent so far.
Jan