xen/console: introduce console_{get,put}_domain()
PATCH 1/1 xen/console: introduce console_{get,put}_domain()
From: Denis Mukhin <[email protected]>
console_input_domain() takes an RCU lock to protect domain structure. That implies call to rcu_unlock_domain() after use.
Introduce a pair of console_get_domain() / console_put_domain() to highlight the correct use of the call within the code interacting with Xen console driver.
The new calls used in __serial_rx(), which also fixed console forwarding to late hardware domains which run with domain IDs different from 0.
---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/
--- xen/arch/arm/vpl011.c | 6 ++--- xen/drivers/char/console.c | 53 +++++++++++++++++++------------------- xen/include/xen/console.h | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-)
xen/arch/arm/vpl011.c +3 -3
@@ -78,7 +78,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)unsigned long flags;struct vpl011 *vpl011 = &d->arch.vpl011;struct vpl011_xen_backend *intf = vpl011->backend.xen; -struct domain *input =console_input_domain (); +struct domain *input =console_get_domain ();VPL011_LOCK (d, flags);
@@ -123,8 +123,8 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)vpl011_update_interrupt_status (d);VPL011_UNLOCK (d, flags); -if ( input !=NULL ) -rcu_unlock_domain (input); + +console_put_domain (input); }/*
xen/drivers/char/console.c +27 -26
85 lines not on this page · raw message
xen/include/xen/console.h +2 -1
@@ -32,7 +32,8 @@ void console_end_sync(void);void console_start_log_everything (void );void console_end_log_everything (void ); -struct domain *console_input_domain (void ); +struct domain *console_get_domain (void ); +void console_put_domain (struct domain *d);/* * Steal output from the console. Returns +ve identifier, else -ve error.
Signature · 1 line
2.34.1
Quoted 27 lines · On 18.02.2025 09:31, [email protected] wrote:
xen/drivers/char/console.c +4
-17@@ -546,31 +555,23 @@ static void __serial_rx(char c)* getting stuck. */ send_global_virq (VIRQ_CONSOLE ); -break ; - + }#ifdef CONFIG_SBSA_VUART_CONSOLE -default : - { -struct domain *d =rcu_lock_domain_by_id (console_rx -1 ); - -if ( d ) - { -int rc =vpl011_rx_char_xen (d, c); -if ( rc ) -guest_printk (d,XENLOG_G_WARNING -"failed to process console input: %d\n" , rc); -rcu_unlock_domain (d); - } - -break ; - } + else +/* Deliver input to the emulated UART. */ + rc =vpl011_rx_char_xen (d, c);#endif
xen/drivers/char/console.c static void __serial_rx(char c) · line 572
Quoted 10 lines
xen/drivers/char/console.c +4
-1- }#ifdef CONFIG_X86 if ( pv_shim && pv_console )consoled_guest_tx (c);#endif + +if ( rc ) +guest_printk (d,XENLOG_G_WARNING +"failed to process console input: %d\n" , rc);
Wouldn't this better live ahead of the four shim related lines?
Also please correct the log level specifier here. I realize you only move what was there before, but I consider i bad practice to move buggy code. gprintk() already prepends XENLOG_GUEST, so instead of XENLOG_G_WARNING is should just be XENLOG_WARNING. (Line wrapping is also odd here, at least according to my taste. But since that's not written down anywhere, I wouldn't insist on adjusting that as well.)
With both adjustments (provided you agree, of course)
Given they're reasonably simple to make, I could once again offer to adjust while committing (provided an Arm ack also arrives).
Jan
Stefano Stabellini
Acked-byQuoted 48 lines · Jan Beulich
Quoted 27 lines · On 18.02.2025 09:31, [email protected] wrote:
xen/drivers/char/console.c +4
-17@@ -546,31 +555,23 @@ static void __serial_rx(char c)* getting stuck. */ send_global_virq (VIRQ_CONSOLE ); -break ; - + }#ifdef CONFIG_SBSA_VUART_CONSOLE -default : - { -struct domain *d =rcu_lock_domain_by_id (console_rx -1 ); - -if ( d ) - { -int rc =vpl011_rx_char_xen (d, c); -if ( rc ) -guest_printk (d,XENLOG_G_WARNING -"failed to process console input: %d\n" , rc); -rcu_unlock_domain (d); - } - -break ; - } + else +/* Deliver input to the emulated UART. */ + rc =vpl011_rx_char_xen (d, c);#endif xen/drivers/char/console.c static void __serial_rx(char c) · line 572
Quoted 10 lines
xen/drivers/char/console.c +4
-1- }#ifdef CONFIG_X86 if ( pv_shim && pv_console )consoled_guest_tx (c);#endif + +if ( rc ) +guest_printk (d,XENLOG_G_WARNING +"failed to process console input: %d\n" , rc);Wouldn't this better live ahead of the four shim related lines?
Also please correct the log level specifier here. I realize you only move what was there before, but I consider i bad practice to move buggy code.
gprintk()already prependsXENLOG_GUEST, so instead ofXENLOG_G_WARNINGis should just beXENLOG_WARNING. (Line wrapping is also odd here, at least according to my taste. But since that's not written down anywhere, I wouldn't insist on adjusting that as well.)
Quoted 4 lines
With both adjustments (provided you agree, of course)
Reviewed-by Jan Beulich <[email protected]>Given they're reasonably simple to make, I could once again offer to adjust while committing (provided an Arm ack also arrives).
Quoted 53 lines · Stefano Stabellini
Quoted 49 lines · Jan Beulich
Quoted 27 lines · On 18.02.2025 09:31, [email protected] wrote:
xen/drivers/char/console.c +4
-17@@ -546,31 +555,23 @@ static void __serial_rx(char c)* getting stuck. */ send_global_virq (VIRQ_CONSOLE ); -break ; - + }#ifdef CONFIG_SBSA_VUART_CONSOLE -default : - { -struct domain d =rcu_lock_domain_by_id (console_rx -1 ); - -if ( d ) - { -int rc =vpl011_rx_char_xen (d, c); -if ( rc ) -guest_printk (d,XENLOG_G_WARNING -"failed to process console input: %d\n" , rc); -rcu_unlock_domain (d); - } - -break ; - } + else + / Deliver input to the emulated UART. */ + rc =vpl011_rx_char_xen (d, c);#endif xen/drivers/char/console.c static void __serial_rx(char c) · line 572
Quoted 10 lines
xen/drivers/char/console.c +4
-1- }#ifdef CONFIG_X86 if ( pv_shim && pv_console )consoled_guest_tx (c);#endif + +if ( rc ) +guest_printk (d,XENLOG_G_WARNING +"failed to process console input: %d\n" , rc);Wouldn't this better live ahead of the four shim related lines?
Also please correct the log level specifier here. I realize you only move what was there before, but I consider i bad practice to move buggy code.
gprintk()already prependsXENLOG_GUEST, so instead ofXENLOG_G_WARNINGis should just beXENLOG_WARNING. (Line wrapping is also odd here, at least according to my taste. But since that's not written down anywhere, I wouldn't insist on adjusting that as well.)
Quoted 7 lines
Quoted 4 lines
With both adjustments (provided you agree, of course)
Reviewed-by Jan Beulich [email protected]Given they're reasonably simple to make, I could once again offer to adjust while committing (provided an Arm ack also arrives).
Acked-by Stefano Stabellini [email protected]
Thank you!
Quoted 45 lines · Jan Beulich
Quoted 27 lines · On 18.02.2025 09:31, [email protected] wrote:
xen/drivers/char/console.c +4
-17@@ -546,31 +555,23 @@ static void __serial_rx(char c)* getting stuck. */ send_global_virq (VIRQ_CONSOLE ); -break ; - + }#ifdef CONFIG_SBSA_VUART_CONSOLE -default : - { -struct domain d =rcu_lock_domain_by_id (console_rx -1 ); - -if ( d ) - { -int rc =vpl011_rx_char_xen (d, c); -if ( rc ) -guest_printk (d,XENLOG_G_WARNING -"failed to process console input: %d\n" , rc); -rcu_unlock_domain (d); - } - -break ; - } + else + / Deliver input to the emulated UART. */ + rc =vpl011_rx_char_xen (d, c);#endif xen/drivers/char/console.c static void __serial_rx(char c) · line 572
Quoted 10 lines
xen/drivers/char/console.c +4
-1- }#ifdef CONFIG_X86 if ( pv_shim && pv_console )consoled_guest_tx (c);#endif + +if ( rc ) +guest_printk (d,XENLOG_G_WARNING +"failed to process console input: %d\n" , rc);Wouldn't this better live ahead of the four shim related lines?
Quoted 8 lines
Also please correct the log level specifier here. I realize you only move what was there before, but I consider i bad practice to move buggy code.
gprintk()already prependsXENLOG_GUEST, so instead ofXENLOG_G_WARNINGis should just beXENLOG_WARNING. (Line wrapping is also odd here, at least according to my taste. But since that's not written down anywhere, I wouldn't insist on adjusting that as well.)With both adjustments (provided you agree, of course)
Thanks a lot for help and review!
Quoted 6 lines
Reviewed-by Jan Beulich [email protected]Given they're reasonably simple to make, I could once again offer to adjust while committing (provided an Arm ack also arrives).
Jan
Quoted 13 lines · On 18.02.2025 09:31, [email protected] wrote:
From: Denis Mukhin <[email protected]>
console_input_domain()takes an RCU lock to protect domain structure. That implies call torcu_unlock_domain()after use.Introduce a pair of
console_get_domain()/console_put_domain()to highlight the correct use of the call within the code interacting with Xen console driver.The new calls used in
__serial_rx(), which also fixed console forwarding to late hardware domains which run with domain IDs different from 0.Signed-off-by Denis Mukhin <[email protected]>
Quoted 9 lines
---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/--- xen/arch/arm/vpl011.c | 6 ++--- xen/drivers/char/console.c | 53 +++++++++++++++++++------------------- xen/include/xen/console.h | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-)
This patch doesn't apply to staging. Looks like it depends on "arm/vuart:
move vpl011-related code to vpl011 emulator" without this being said anywhere.
Jan
Quoted 27 lines · Jan Beulich
Quoted 13 lines · On 18.02.2025 09:31, [email protected] wrote:
From: Denis Mukhin [email protected]
console_input_domain()takes an RCU lock to protect domain structure. That implies call torcu_unlock_domain()after use.Introduce a pair of
console_get_domain()/console_put_domain()to highlight the correct use of the call within the code interacting with Xen console driver.The new calls used in
__serial_rx(), which also fixed console forwarding to late hardware domains which run with domain IDs different from 0.Signed-off-by Denis Mukhin [email protected]Quoted 8 lines
---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/
---xen/arch/arm/vpl011.c| 6 ++---xen/drivers/char/console.c| 53 +++++++++++++++++++-------------------xen/include/xen/console.h| 3 ++-3 files changed, 32 insertions(+), 30 deletions(-)
Quoted 2 lines
This patch doesn't apply to staging. Looks like it depends on "arm/vuart:
move vpl011-related code to vpl011 emulator" without this being said anywhere.
Correct, this patch depends on
https://lore.kernel.org/xen-devel/[email protected]/
and I have R-b:
https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2502121412500.619090@ubuntu-linux-20-04-desktop/
Quoted 2 lines
Jan
Quoted 29 lines · Denis Mukhin
Quoted 27 lines · Jan Beulich
Quoted 21 lines · On 18.02.2025 09:31, [email protected] wrote:
From: Denis Mukhin [email protected]
console_input_domain()takes an RCU lock to protect domain structure. That implies call torcu_unlock_domain()after use.Introduce a pair of
console_get_domain()/console_put_domain()to highlight the correct use of the call within the code interacting with Xen console driver.The new calls used in
__serial_rx(), which also fixed console forwarding to late hardware domains which run with domain IDs different from 0.Signed-off-by Denis Mukhin [email protected]---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/
---xen/arch/arm/vpl011.c| 6 ++---xen/drivers/char/console.c| 53 +++++++++++++++++++-------------------xen/include/xen/console.h| 3 ++-3 files changed, 32 insertions(+), 30 deletions(-)
Quoted 7 lines
Quoted 2 lines
This patch doesn't apply to staging. Looks like it depends on "arm/vuart:
move vpl011-related code to vpl011 emulator" without this being said anywhere.Correct, this patch depends on
https://lore.kernel.org/xen-devel/[email protected]/
and I have R-b:
https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2502121412500.619090@ubuntu-linux-20-04-desktop/
I'm aware of that. Yet that other patch is too intrusive for my taste to put in an only half-open tree. Plus you should never make assumptions about the order in which patches may make it in; if there are dependencies, they need to be stated (prominently).
Jan