Introduce NS8250 UART emulator
Subsystems (2)
v2 cover Introduce NS8250 UART emulator
The patch series introduces initial in-hypervisor emulator for NS8250/NS16x50-compatible UARTs under CONFIG_HAS_VUART_NS8250.
In parallel domain creation scenario (hyperlaunch), NS8520 emulator helps early guest OS bringup debugging, because it eliminates dependency on the external emulator being operational by the time domains are created. Also, there's no early console facility similar to vpl011 to support x86 guest OS bring up.
The NS8250 emulator is disabled by default.
Series
======
- patches 1-11: preparation fixes for xen console and NS8250 emulator.
- patches 12-27: xen console driver cleanup, fixes and preparation for enabling physical serial console focus assignment to the guest VM w/ virtual NS8250.
- patches 28-35: initial NS8250 emulator. That adds the I/O port emulator for legacy PC COM UARTs, Kconfig option, enabling emulator and libxl plumbing.
Limitations
===========
- Only x86;
- Only Linux guest tested so far;
- Only legacy COM{1,2,3,4} resources, no customization;
- Only Xen console as a backend, no inter-domain communication (similar to vpl011 on Arm);
- Only 8-bit characters;
- Baud rate is not emulated;
- FIFO-less mode is not emulated properly;
- RX FIFO interrupt moderation (FCR) is not emulated properly, TL16C750 has special FCR handling;
- No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and friends);
- Assumes no ISA-device IRQ sharing;
- MMIO-based UART is not supported.
Testing
=======
Gitlab CI:
https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/1576164352
I tested boot of HVM linux guest w/ OVMF as the virtual firmware.
The emulator, if enabled via CONFIG_HAS_VUART_NS8250=y, will use COM1 (0x3f8) resources by default.
To test w/ virtual COM1, the guest kernel parameters should contain
earlycon=uart,io,0x3f8,115200n8 console=uart,io,0x3f8,115200n8
Xen is able to forward physical console input to the domain w/ virtual NS8250. To switch the console focus press Ctrl+aaa. If console= is given to the HVM kernel, then the user shall be able to see the login prompt on xen console once console focus is switched to the HVM guest.
Luca Fancellu helped big time w/ verifying the patch series on arm{32,64} w/ FVP Linux as a guest OS.
---
Changes in v2:
- dropped kmalloc/kfree aliases
- fixed ECLAIR jobs (thanks Andrew Cooper)
- addressed console forwarding on arm32 and arm64 (thanks to Luca Fancellu)
- moved NS8250 debugging stubs into its own patch
- added fix for https://gitlab.com/xen-project/xen/-/issues/184
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Denis Mukhin (35):
xen: introduce resource.h
xen/irq: introduce NO_IRQ
xen/ctype: introduce isconsole()
arm/vuart: use guest_printk()
arm/vuart: make domain_has_vuart() public riscv/domain: introduce domain_has_vuart()
ppc/domain: introduce domain_has_vuart()
x86/domain: introduce domain_has_vuart()
x86/domain: print emulation_flags
xen/domain: add get_initial_domain_id()
xen/domain: enable max_init_domid for all architectures xen/console: move vpl011-related code to vpl011 emulator xen/console: rename console_input_domain
xen/console: rename switch_serial_input() to console_find_owner() xen/console: rename console_rx to console_owner xen/console: introduce printk_common()
xen/console: introduce consoled_is_enabled() xen/console: introduce use of 'is_console' flag xen/console: introduce console_set_owner() xen/console: introduce console_owner_domid() xen/console: introduce console_init_owner() xen/console: introduce handle_keypress_in_domain() xen/console: introduce console_write()
xen/console: introduce hwdom_crashconsole= xen/console: simplify console owner switch hint xen/console: make console buffer size configurable xen/console: flush console ring to physical console xen/8250-uart: add missing definitions
x86/hvm: add HVM-specific Kconfig
x86/hvm: add helpers for raising guest IRQs
x86/hvm: introduce NS8250 UART emulator
x86/hvm: add debugging facility to NS8250 UART emulator x86/domain: implement domain_has_vuart()
xen/console: enable console owners w/ emulated NS8250 docs/misc: update console documentation
automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- docs/misc/console.txt | 50 +- docs/misc/xen-command-line.pandoc | 5 + tools/libs/light/libxl_x86.c | 6 +- tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + tools/python/xen/lowlevel/xc/xc.c | 4 +- xen/arch/arm/dom0less-build.c | 4 +- xen/arch/arm/domain.c | 20 +- xen/arch/arm/domctl.c | 5 +- xen/arch/arm/include/asm/domain.h | 9 + xen/arch/arm/include/asm/setup.h | 2 - xen/arch/arm/include/asm/vpl011.h | 2 +- xen/arch/arm/setup.c | 2 - xen/arch/arm/vpl011.c | 19 +- xen/arch/arm/vuart.c | 7 +- xen/arch/ppc/include/asm/domain.h | 2 + xen/arch/ppc/include/asm/setup.h | 2 - xen/arch/riscv/include/asm/domain.h | 2 + xen/arch/riscv/include/asm/setup.h | 2 - xen/arch/x86/Kconfig | 66 +- xen/arch/x86/dom0_build.c | 2 + xen/arch/x86/domain.c | 16 +- xen/arch/x86/hvm/Kconfig | 77 ++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 16 +- xen/arch/x86/hvm/irq.c | 24 + xen/arch/x86/hvm/vuart_ns8250.c | 1008 ++++++++++++++++++++++ xen/arch/x86/include/asm/domain.h | 8 +- xen/arch/x86/include/asm/hvm/domain.h | 5 + xen/arch/x86/include/asm/hvm/irq.h | 3 + xen/arch/x86/include/asm/hvm/vuart_ns8250.h | 75 ++ xen/arch/x86/include/asm/pv/shim.h | 4 +- xen/arch/x86/include/asm/setup.h | 2 - xen/arch/x86/pv/shim.c | 6 +- xen/common/device-tree/device-tree.c | 21 +- xen/common/domain.c | 35 +- xen/drivers/char/Kconfig | 23 + xen/drivers/char/console.c | 394 +++++---- xen/drivers/char/consoled.c | 18 +- xen/drivers/passthrough/arm/smmu.c | 15 +- xen/include/public/arch-x86/xen.h | 14 +- xen/include/xen/8250-uart.h | 81 +- xen/include/xen/console.h | 4 +- xen/include/xen/consoled.h | 35 +- xen/include/xen/ctype.h | 3 + xen/include/xen/domain.h | 5 + xen/include/xen/irq.h | 1 + xen/include/xen/lib.h | 3 + xen/include/xen/resource.h | 40 + 50 files changed, 1799 insertions(+), 353 deletions(-)
---
base-commit: dc8e1b33a525d31989c0d1ffe6ae7794484e1d99
change-id: 20241205-vuart-ns8250-45847bc04140
Best regards,
Signature · 1 line
Denis Mukhin <[email protected]>
PATCH v2 1/35 xen: introduce resource.h
Move resource definitions to a new architecture-agnostic shared header file.
It will be used in follow on NS8250 emulator code to describe legacy PC COM resources.
--- xen/common/device-tree/device-tree.c | 21 +------------------ xen/drivers/passthrough/arm/smmu.c | 15 +------------- xen/include/xen/resource.h | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-)
xen/common/device-tree/device-tree.c +1 -20
@@ -24,6 +24,7 @@#include <xen/ctype.h> #include <asm/setup.h> #include <xen/err.h> +#include <xen/resource.h> const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;
@@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent)return __dt_n_size_cells (parent, true); } -/* -* These are defined in Linux where much of this code comes from, but -* are currently unused outside this file in the context of Xen. -*/ -#define IORESOURCE_BITS 0x000000ff/* Bus-specific bits */ - -#define IORESOURCE_TYPE_BITS 0x00001f00/* Resource type */ -#define IORESOURCE_IO 0x00000100/* PCI/ISA I/O ports */ -#define IORESOURCE_MEM 0x00000200 -#define IORESOURCE_REG 0x00000300/* Register offsets */ -#define IORESOURCE_IRQ 0x00000400 -#define IORESOURCE_DMA 0x00000800 -#define IORESOURCE_BUS 0x00001000 - -#define IORESOURCE_PREFETCH 0x00002000/* No side effects */ -#define IORESOURCE_READONLY 0x00004000 -#define IORESOURCE_CACHEABLE 0x00008000 -#define IORESOURCE_RANGELENGTH 0x00010000 -#define IORESOURCE_SHADOWABLE 0x00020000 -/* * Default translator (generic bus) */
xen/drivers/passthrough/arm/smmu.c +1 -14
@@ -50,6 +50,7 @@#include <xen/rbtree.h> #include <xen/sched.h> #include <xen/sizes.h> +#include <xen/resource.h> #include <asm/atomic.h> #include <asm/device.h> #include <asm/io.h>
@@ -70,22 +71,8 @@#define of_property_read_u32 (np, pname, out) (!dt_property_read_u32(np, pname, out))#define of_property_read_bool dt_property_read_bool#define of_parse_phandle_with_args dt_parse_phandle_with_args - -/* Xen: Helpers to get device MMIO and IRQs */ -struct resource -{ -paddr_t addr; -paddr_t size; -unsigned int type; -}; - -#define resource_size (res) (res)->size; -#define platform_device dt_device_node -#define IORESOURCE_MEM 0 -#define IORESOURCE_IRQ 1 -static struct resource *platform_get_resource (struct platform_device *pdev,unsigned int type,unsigned int num)
xen/include/xen/resource.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* System resource description. +* +* Reference: +* include/linux/ioport.h +*/ +#if !defined(XEN__RESOURCE_H ) +#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU/* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00001F00U/* Resource type */ +#define IORESOURCE_IO 0x00000100U/* PCI/ISA I/O ports */ +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U/* Register offsets */ +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U/* No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN (~0U) + +struct resource { +paddr_t addr; +paddr_t size; +unsigned int type; +}; + +#define resource_size (res) (res)->size; + +#define foreach_resource (res) \ + for (; res && res->type != IORESOURCE_UNKNOWN; res++) + +#endif /* #if !defined(XEN__RESOURCE_H) */
Signature · 1 line
2.34.1
Re: [PATCH v2 01/35] xen: introduce resource.h
xen/include/xen/resource.h line 1
Quoted 4 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/include/xen/resource.h new file +1
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */
GPL-2.0-only
xen/include/xen/resource.h line 6
Quoted 5 lines
xen/include/xen/resource.h new file +5
-0+/* +* System resource description. +* +* Reference: +* include/linux/ioport.h
I'm unsure of the usefulness of such a reference.
xen/include/xen/resource.h line 8
Quoted 2 lines
xen/include/xen/resource.h new file +2
-0+*/ +#if !defined(XEN__RESOURCE_H )
Nit: #ifdef / #ifndef please whenever possible (as long as not inconsistent with adjacent code).
Quoted 17 lines
xen/include/xen/resource.h new file +17
-0+#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU/* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00001F00U/* Resource type */ +#define IORESOURCE_IO 0x00000100U/* PCI/ISA I/O ports */ +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U/* Register offsets */ +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U/* No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U
xen/include/xen/resource.h line 35
Quoted 10 lines
xen/include/xen/resource.h new file +10
-0+ +#define IORESOURCE_UNKNOWN (~0U) + +struct resource { +paddr_t addr; +paddr_t size; +unsigned int type; +}; + +#define resource_size (res) (res)->size;
The semicolon surely was wrong before and is wrong now. Plus Misra demands that such macro expansions be parenthesized, I think.
xen/include/xen/resource.h line 38
Quoted 2 lines
xen/include/xen/resource.h new file +2
-0+#define foreach_resource (res) \ + for (; res && res->type != IORESOURCE_UNKNOWN; res++)
This one isn't being moved, but is being added. It's not used here, which makes it difficult to judge its correctness. Perhaps better to introduce this when its first needed, and then right away with the required parentheses around uses of the macro parameter.
xen/include/xen/resource.h line 40
Quoted 1 line
xen/include/xen/resource.h new file +1
-0+#endif /* #if !defined(XEN__RESOURCE_H) */
Just the guard identifier in the comment please.
Jan
Re: [PATCH v2 01/35] xen: introduce resource.h
Quoted 11 lines · Jan Beulich
xen/include/xen/resource.h line 1
Quoted 4 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/include/xen/resource.h new file +1
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ GPL-2.0-only
Fixed.
Quoted 9 lines
xen/include/xen/resource.h line 6
Quoted 6 lines
xen/include/xen/resource.h new file +5
-0+/* +* System resource description. +* +* Reference: +* include/linux/ioport.h I'm unsure of the usefulness of such a reference.
These definitions are taken from Linux'es
include/linux/ioport.h
I think reference to the original code may help developers to borrow more missing declarations in the future.
But sure, removed.
Quoted 7 lines
xen/include/xen/resource.h line 8
Quoted 3 lines
xen/include/xen/resource.h new file +2
-0+*/ +#if !defined(XEN__RESOURCE_H )Nit: #ifdef / #ifndef please whenever possible (as long as not inconsistent with adjacent code).
Sure.
Quoted 24 lines
Quoted 24 lines
xen/include/xen/resource.h new file +23
-0+#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU/* Bus-specific bits / + +#define IORESOURCE_TYPE_BITS 0x00001F00U / Resource type / +#define IORESOURCE_IO 0x00000100U / PCI/ISA I/O ports / +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U / Register offsets / +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U / No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN (~0U) + +struct resource { +paddr_t addr; +paddr_t size;
Quoted 8 lines
xen/include/xen/resource.h line 35
Quoted 4 lines
xen/include/xen/resource.h new file +4
-0+unsigned int type; +}; + +#define resource_size (res) (res)->size;The semicolon surely was wrong before and is wrong now. Plus Misra demands that such macro expansions be parenthesized, I think.
Fixed.
Quoted 9 lines
xen/include/xen/resource.h line 38
Quoted 3 lines
xen/include/xen/resource.h new file +2
-0+#define foreach_resource (res) \ + for (; res && res->type != IORESOURCE_UNKNOWN; res++)This one isn't being moved, but is being added. It's not used here, which makes it difficult to judge its correctness. Perhaps better to introduce this when its first needed, and then right away with the required parentheses around uses of the macro parameter.
I moved that hunk into the place where it is first used (the emulator patch).
Quoted 5 lines
xen/include/xen/resource.h line 40
Quoted 2 lines
xen/include/xen/resource.h new file +1
-0+#endif /* #if !defined(XEN__RESOURCE_H) */ Just the guard identifier in the comment please.
Done.
Quoted 2 lines
Jan
Re: [PATCH v2 01/35] xen: introduce resource.h
In reply to Denis MukhinQuoted 121 lines · On Thu, Dec 05, 2024 at 08:41:31PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Move resource definitions to a new architecture-agnostic shared header file.
It will be used in follow on NS8250 emulator code to describe legacy PC COM resources.
Signed-off-by Denis Mukhin <[email protected]>--- xen/common/device-tree/device-tree.c | 21 +------------------ xen/drivers/passthrough/arm/smmu.c | 15 +------------- xen/include/xen/resource.h | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-)xen/common/device-tree/device-tree.c +1
-20@@ -24,6 +24,7 @@#include <xen/ctype.h> #include <asm/setup.h> #include <xen/err.h> +#include <xen/resource.h> const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;@@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent)return __dt_n_size_cells (parent, true); } -/* -* These are defined in Linux where much of this code comes from, but -* are currently unused outside this file in the context of Xen. -*/ -#define IORESOURCE_BITS 0x000000ff/* Bus-specific bits */ - -#define IORESOURCE_TYPE_BITS 0x00001f00/* Resource type */ -#define IORESOURCE_IO 0x00000100/* PCI/ISA I/O ports */ -#define IORESOURCE_MEM 0x00000200 -#define IORESOURCE_REG 0x00000300/* Register offsets */ -#define IORESOURCE_IRQ 0x00000400 -#define IORESOURCE_DMA 0x00000800 -#define IORESOURCE_BUS 0x00001000 - -#define IORESOURCE_PREFETCH 0x00002000/* No side effects */ -#define IORESOURCE_READONLY 0x00004000 -#define IORESOURCE_CACHEABLE 0x00008000 -#define IORESOURCE_RANGELENGTH 0x00010000 -#define IORESOURCE_SHADOWABLE 0x00020000 -/* * Default translator (generic bus) */ xen/drivers/passthrough/arm/smmu.c +1
-14@@ -50,6 +50,7 @@#include <xen/rbtree.h> #include <xen/sched.h> #include <xen/sizes.h> +#include <xen/resource.h> #include <asm/atomic.h> #include <asm/device.h> #include <asm/io.h> @@ -70,22 +71,8 @@#define of_property_read_u32 (np, pname, out) (!dt_property_read_u32(np, pname, out))#define of_property_read_bool dt_property_read_bool#define of_parse_phandle_with_args dt_parse_phandle_with_args - -/* Xen: Helpers to get device MMIO and IRQs */ -struct resource -{ -paddr_t addr; -paddr_t size; -unsigned int type; -}; - -#define resource_size (res) (res)->size; -#define platform_device dt_device_node -#define IORESOURCE_MEM 0 -#define IORESOURCE_IRQ 1 -static struct resource *platform_get_resource (struct platform_device *pdev,unsigned int type,unsigned int num)xen/include/xen/resource.h new file +27
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* System resource description. +* +* Reference: +* include/linux/ioport.h +*/ +#if !defined(XEN__RESOURCE_H ) +#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU/* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00001F00U/* Resource type */ +#define IORESOURCE_IO 0x00000100U/* PCI/ISA I/O ports */ +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U/* Register offsets */ +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U/* No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN (~0U)
xen/include/xen/resource.h line 37
Quoted 10 lines
xen/include/xen/resource.h new file +10
-0+ +struct resource { +paddr_t addr; +paddr_t size; +unsigned int type; +}; + +#define resource_size (res) (res)->size; + +#define foreach_resource (res) \
Nit: we usually name those for_each_foo instead of foreach_foo.
xen/include/xen/resource.h line 38
Quoted 1 line
xen/include/xen/resource.h new file +1
-0+for (; res && res->type !=IORESOURCE_UNKNOWN ; res++)
Missing spaces between parentheses:
for ( ; res && res->type != IORESOURCE_UNKNOWN; res++ )
Note that this macro will modify (advance) the res pointer, which is maybe unexpected by the caller?
Also, the current logic forces the array of resources to always have a trailing IORESOURCE_UNKNOWN element in order to break the loop, it might be better to pass an explicit number of elements to iterate against if possible?
As Jan said, it would be helpful to have an example usage of the macro.
Thanks, Roger.
Re: [PATCH v2 01/35] xen: introduce resource.h
Quoted 130 lines · Roger Pau Monné
Quoted 126 lines · On Thu, Dec 05, 2024 at 08:41:31PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Move resource definitions to a new architecture-agnostic shared header file.
It will be used in follow on NS8250 emulator code to describe legacy PC COM resources.
Signed-off-by Denis Mukhin [email protected]---
xen/common/device-tree/device-tree.c| 21 +------------------xen/drivers/passthrough/arm/smmu.c| 15 +-------------xen/include/xen/resource.h| 40 ++++++++++++++++++++++++++++++++++++3 files changed, 42 insertions(+), 34 deletions(-)xen/common/device-tree/device-tree.c +1
-20@@ -24,6 +24,7 @@#include <xen/ctype.h> #include <asm/setup.h> #include <xen/err.h> +#include <xen/resource.h> const void *device_tree_flattened;dt_irq_xlate_func dt_irq_xlate;@@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent)return __dt_n_size_cells (parent, true); } -/* -* These are defined in Linux where much of this code comes from, but -* are currently unused outside this file in the context of Xen. -/ -#define IORESOURCE_BITS 0x000000ff / Bus-specific bits / - -#define IORESOURCE_TYPE_BITS 0x00001f00 / Resource type / -#define IORESOURCE_IO 0x00000100 / PCI/ISA I/O ports / -#define IORESOURCE_MEM 0x00000200 -#define IORESOURCE_REG 0x00000300 / Register offsets / -#define IORESOURCE_IRQ 0x00000400 -#define IORESOURCE_DMA 0x00000800 -#define IORESOURCE_BUS 0x00001000 - -#define IORESOURCE_PREFETCH 0x00002000 / No side effects / -#define IORESOURCE_READONLY 0x00004000 -#define IORESOURCE_CACHEABLE 0x00008000 -#define IORESOURCE_RANGELENGTH 0x00010000 -#define IORESOURCE_SHADOWABLE 0x00020000 -/
* Default translator (generic bus)
/xen/drivers/passthrough/arm/smmu.c +1
-14@@ -50,6 +50,7 @@#include <xen/rbtree.h> #include <xen/sched.h> #include <xen/sizes.h> +#include <xen/resource.h> #include <asm/atomic.h> #include <asm/device.h> #include <asm/io.h> @@ -70,22 +71,8 @@#define of_property_read_u32 (np, pname, out) (!dt_property_read_u32(np, pname, out))#define of_property_read_bool dt_property_read_bool#define of_parse_phandle_with_args dt_parse_phandle_with_args - -/ Xen: Helpers to get device MMIO and IRQs */ -struct resource -{ -paddr_t addr; -paddr_t size; -unsigned int type; -}; - -#define resource_size (res) (res)->size; -#define platform_device dt_device_node -#define IORESOURCE_MEM 0 -#define IORESOURCE_IRQ 1 -static struct resource *platform_get_resource (struct platform_device pdev,unsigned int type,unsigned int num)xen/include/xen/resource.h new file +32
-0@@ -0,0 +1,40 @@ +/ SPDX-License-Identifier: GPL-2.0 / +/ +* System resource description. +* +* Reference: +* include/linux/ioport.h +/ +#if !defined(XEN__RESOURCE_H) +#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU / Bus-specific bits / + +#define IORESOURCE_TYPE_BITS 0x00001F00U / Resource type / +#define IORESOURCE_IO 0x00000100U / PCI/ISA I/O ports / +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U / Register offsets / +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U / No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN (~0U) + +struct resource { +paddr_t addr; +paddr_t size; + unsigned int type;
Quoted 8 lines
xen/include/xen/resource.h line 37
Quoted 5 lines
xen/include/xen/resource.h new file +5
-0+}; + +#define resource_size (res) (res)->size; + +#define foreach_resource (res) \Nit: we usually name those
for_each_fooinstead offoreach_foo.
Fixed.
Quoted 7 lines
xen/include/xen/resource.h line 38
Quoted 2 lines
xen/include/xen/resource.h new file +1
-0+for (; res && res->type !=IORESOURCE_UNKNOWN ; res++)Missing spaces between parentheses:
for ( ; res &&
res->type!=IORESOURCE_UNKNOWN; res++ )
Fixed.
Quoted 4 lines
Note that this macro will modify (advance) the res pointer, which is maybe unexpected by the caller?
For my use case I rely on res pointer advance.
Quoted 5 lines
Also, the current logic forces the array of resources to always have a trailing
IORESOURCE_UNKNOWNelement in order to break the loop, it might be better to pass an explicit number of elements to iterate against if possible?
Current use is pretty simple, I think I will keep it as is for now.
Quoted 3 lines
As Jan said, it would be helpful to have an example usage of the macro.
I moved this definition into the patch where it is first used in v3 (UART emulator patch).
Quoted 2 lines
Thanks, Roger.
PATCH v2 2/35 xen/irq: introduce NO_IRQ
In reply to Denis MukhinIntroduce definition for IRQ resource checks.
--- xen/include/xen/irq.h | 1 + 1 file changed, 1 insertion(+)
xen/include/xen/irq.h +1 -0
@@ -53,6 +53,7 @@ struct irqaction {#define AUTO_ASSIGN_IRQ (-1)#define NEVER_ASSIGN_IRQ (-2)#define FREE_TO_ASSIGN_IRQ (-3) +#define NO_IRQ (-4)struct irq_desc ;
Signature · 1 line
2.34.1
Re: [PATCH v2 02/35] xen/irq: introduce NO_IRQ
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce definition for IRQ resource checks.
How does this fit ...
xen/include/xen/irq.h struct irqaction { · line 56
Quoted 7 lines
xen/include/xen/irq.h +1
-0@@ -53,6 +53,7 @@ struct irqaction {#define AUTO_ASSIGN_IRQ (-1)#define NEVER_ASSIGN_IRQ (-2)#define FREE_TO_ASSIGN_IRQ (-3) +#define NO_IRQ (-4)
... the grouping here? The constants in context aren't used anywhere, so it's hard to see whether / how the new one fits here (and doesn't instead belong into the new resource.h you introduce in patch 1). Once again likely best to have this in the patch where it's first needed, thus providing at least some context.
Jan
Re: [PATCH v2 02/35] xen/irq: introduce NO_IRQ
Quoted 11 lines · Jan Beulich
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Introduce definition for IRQ resource checks.
How does this fit ...
Quoted 14 lines
xen/include/xen/irq.h struct irqaction { · line 56
Quoted 7 lines
xen/include/xen/irq.h +1
-0@@ -53,6 +53,7 @@ struct irqaction {#define AUTO_ASSIGN_IRQ (-1)#define NEVER_ASSIGN_IRQ (-2)#define FREE_TO_ASSIGN_IRQ (-3) +#define NO_IRQ (-4)... the grouping here? The constants in context aren't used anywhere, so it's hard to see whether / how the new one fits here (and doesn't instead belong into the new
resource.hyou introduce in patch 1). Once again likely best to have this in the patch where it's first needed, thus providing at least some context.
I ended up dropping this change.
Quoted 2 lines
Jan
PATCH v2 3/35 xen/ctype: introduce isconsole()
In reply to Denis MukhinThere are several console drivers which have same checks w.r.t. printable characters. The check is moved to new isconsole() macro and re-used in the console drivers.
--- xen/arch/arm/vuart.c | 3 +-- xen/arch/x86/hvm/hvm.c | 3 +-- xen/drivers/char/console.c | 2 +- xen/include/xen/ctype.h | 3 +++ 4 files changed, 6 insertions(+), 5 deletions(-)
xen/arch/arm/vuart.c +1 -2
@@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c)struct domain *d = v->domain;struct vuart *uart = &d->arch.vuart; -/* Accept only printable characters, newline, and horizontal tab. */ -if ( !isprint (c) && (c !='\n' ) && (c !='\t' ) ) +if ( !isconsole (c) )return ;spin_lock (&uart->lock);
xen/arch/x86/hvm/hvm.c +1 -2
@@ -561,8 +561,7 @@ static int cf_check hvm_print_line(if ( dir !=IOREQ_WRITE )return X86EMUL_UNHANDLEABLE ; -/* Accept only printable characters, newline, and horizontal tab. */ -if ( !isprint (c) && (c !='\n' ) && (c !='\t' ) ) +if ( !isconsole (c) )return X86EMUL_OKAY ;spin_lock (&cd->pbuf_lock);
xen/drivers/char/console.c +1 -1
@@ -674,7 +674,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, c = *kin++;if ( c =='\n' )break ; -if (isprint (c) || c =='\t' ) +if (isconsole (c) ) *kout++ = c; }while ( --kcount >0 );
xen/include/xen/ctype.h +3 -0
@@ -4,6 +4,8 @@/* * NOTE! This ctype does not handle EOF like the standard C * library is required to. +* +* See Rule 21.13 in docs/misra/rules.rst. */ #define _U 0x01/* upper */
@@ -30,6 +32,7 @@ extern const unsigned char _ctype[];#define isspace (c) ((__ismask(c)&(_S)) != 0)#define isupper (c) ((__ismask(c)&(_U)) != 0)#define isxdigit (c) ((__ismask(c)&(_D|_X)) != 0) +#define isconsole (c) (isprint(c) || (c) == '\n' || (c) == '\t')#define isascii (c) (((unsigned char)(c))<=0x7f)#define toascii (c) (((unsigned char)(c))&0x7f)
Signature · 1 line
2.34.1
Re: [PATCH v2 03/35] xen/ctype: introduce isconsole()
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
There are several console drivers which have same checks w.r.t. printable characters. The check is moved to new
isconsole()macro and re-used in the console drivers.
Something named isconsole() imo can't be expected to do what is checked for
...
xen/arch/arm/vuart.c static void vuart_print_char(struct vcpu *v, char c) · line 83
Quoted 10 lines
xen/arch/arm/vuart.c +1
-2@@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c)struct domain *d = v->domain;struct vuart *uart = &d->arch.vuart; -/* Accept only printable characters, newline, and horizontal tab. */ -if ( !isprint (c) && (c !='\n' ) && (c !='\t' ) ) +if ( !isconsole (c) )return ;
... e.g. here. If we really want such a further abstraction (of which I'm unconvinced), then maybe isprintable() or (getting ling-ish) is_console_printable().
xen/include/xen/ctype.h line 9
Quoted 9 lines
xen/include/xen/ctype.h +2
-0@@ -4,6 +4,8 @@/* * NOTE! This ctype does not handle EOF like the standard C * library is required to. +* +* See Rule 21.13 in docs/misra/rules.rst. */
How's this change related to the purpose of the patch?
xen/include/xen/ctype.h extern const unsigned char _ctype[]; · line 35
Quoted 5 lines
xen/include/xen/ctype.h +1
-0@@ -30,6 +32,7 @@ extern const unsigned char _ctype[];#define isspace (c) ((__ismask(c)&(_S)) != 0)#define isupper (c) ((__ismask(c)&(_U)) != 0)#define isxdigit (c) ((__ismask(c)&(_D|_X)) != 0) +#define isconsole (c) (isprint(c) || (c) == '\n' || (c) == '\t')
In a pretty general purpose macro like this one I'm afraid I view it as risky to evaluate the parameter more than once.
Jan
Re: [PATCH v2 03/35] xen/ctype: introduce isconsole()
Quoted 10 lines · Jan Beulich
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
There are several console drivers which have same checks w.r.t. printable characters. The check is moved to new
isconsole()macro and re-used in the console drivers.Something named
isconsole()imo can't be expected to do what is checked for
I tried to follow the "short" naming notation in ctype.h.
I agree; changed the name to is_console_printable() as per below suggestion.
Quoted 8 lines
...
Quoted 6 lines
xen/arch/arm/vuart.c +0
-0@@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c)struct domain *d = v->domain;struct vuart *uart = &d->arch.vuart;
Quoted 9 lines
xen/arch/arm/vuart.c static void vuart_print_char(struct vcpu *v, char c) · line 83
Quoted 4 lines
xen/arch/arm/vuart.c +1
-2-/* Accept only printable characters, newline, and horizontal tab. */ -if ( !isprint (c) && (c !='\n' ) && (c !='\t' ) ) +if ( !isconsole (c) )return ;... e.g. here. If we really want such a further abstraction (of which I'm unconvinced), then maybe
isprintable()or (getting ling-ish)is_console_printable().
Reworked to is_console_printable()
Quoted 13 lines
xen/include/xen/ctype.h line 9
Quoted 10 lines
xen/include/xen/ctype.h +2
-0@@ -4,6 +4,8 @@/* * NOTE! This ctype does not handle EOF like the standard C * library is required to. +* +* See Rule 21.13 in docs/misra/rules.rst. */ How's this change related to the purpose of the patch?
Only because the very first version of the macro was failing an ECLAIR job for me because of Rule 21.13 violation.
Updated the commit message (v3).
Quoted 10 lines
xen/include/xen/ctype.h extern const unsigned char _ctype[]; · line 35
Quoted 6 lines
xen/include/xen/ctype.h +1
-0@@ -30,6 +32,7 @@ extern const unsigned char _ctype[];#define isspace (c) ((__ismask(c)&(_S)) != 0)#define isupper (c) ((__ismask(c)&(_U)) != 0)#define isxdigit (c) ((__ismask(c)&(_D|_X)) != 0) +#define isconsole (c) (isprint(c) || (c) == '\n' || (c) == '\t')In a pretty general purpose macro like this one I'm afraid I view it as risky to evaluate the parameter more than once.
Fixed.
Quoted 2 lines
Jan
Re: [PATCH v2 03/35] xen/ctype: introduce isconsole()
Quoted 15 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
xen/include/xen/ctype.h line 9
Quoted 9 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/include/xen/ctype.h +2
-0@@ -4,6 +4,8 @@/* * NOTE! This ctype does not handle EOF like the standard C * library is required to. +* +* See Rule 21.13 in docs/misra/rules.rst. */ How's this change related to the purpose of the patch?
Quoted 4 lines
Only because the very first version of the macro was failing an ECLAIR job for me because of Rule 21.13 violation.
Updated the commit message (v3).
Well, no, in such an event please drop this comment change. Or else we end up with Misra related comments about everywhere. After all _all_ Misra rules need to be follow everywhere anyway.
Jan
PATCH v2 4/35 arm/vuart: use guest_printk()
In reply to Denis MukhinUse guest_printk() in all current in-hypervisor UART emulators.
That slightly improves the logging as guest_printk() already prints the domain ID.
--- xen/arch/arm/vpl011.c | 2 +- xen/arch/arm/vuart.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/vpl011.c +1 -1
@@ -107,7 +107,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)if ( data !='\n' ) intf->out[intf->out_prod++] ='\n' ; intf->out[intf->out_prod++] ='\0' ; -printk ("DOM%u: %s" , d->domain_id, intf->out); +guest_printk (d,"%s" , intf->out); intf->out_prod =0 ; } }
xen/arch/arm/vuart.c +1 -1
@@ -89,7 +89,7 @@ static void vuart_print_char(struct vcpu *v, char c)if ( c !='\n' ) uart->buf[uart->idx++] ='\n' ; uart->buf[uart->idx] ='\0' ; -printk (XENLOG_G_DEBUG "DOM%u: %s" , d->domain_id, uart->buf); +guest_printk (d,"%s" , uart->buf); uart->idx =0 ; }spin_unlock (&uart->lock);
Signature · 1 line
2.34.1
PATCH v2 5/35 arm/vuart: make domain_has_vuart() public
In reply to Denis MukhinMove domain_has_vuart() to arch namespace as preparation code change for architecture-agnostic way of forwarding physical console to the guest OS w/ in-hypervisor UART emulator.
--- xen/arch/arm/dom0less-build.c | 2 ++ xen/arch/arm/domain.c | 19 ++++++++++++------- xen/arch/arm/domctl.c | 4 +++- xen/arch/arm/include/asm/domain.h | 9 +++++++++ xen/arch/arm/vuart.c | 2 -- 5 files changed, 26 insertions(+), 10 deletions(-)
xen/arch/arm/dom0less-build.c +2 -0
@@ -831,6 +831,8 @@ static int __init construct_domU(struct domain *d, rc =domain_vpl011_init (d,NULL );if ( rc <0 )return rc; + + d->arch.emulation_flags |=ARM_EMU_VUART ; } rc =prepare_dtb_domU (d, &kinfo);
xen/arch/arm/domain.c +12 -7
@@ -769,14 +769,19 @@ int arch_domain_create(struct domain *d,if ( !vgic_reserve_virq (d,GUEST_EVTCHN_PPI ) )BUG (); } +else + { +/* +* Virtual UART is only used by linux early printk and decompress code. +* Only use it for the hardware domain because the linux kernel may not +* support multi-platform. +*/ + rc =domain_vuart_init (d); +if ( rc ) + goto fail; -/* -* Virtual UART is only used by linux early printk and decompress code. -* Only use it for the hardware domain because the linux kernel may not -* support multi-platform. -*/ -if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) - goto fail; + d->arch.emulation_flags |=ARM_EMU_VUART ; + }if ( (rc =domain_vpci_init (d)) !=0 ) goto fail;
xen/arch/arm/domctl.c +3 -1
@@ -42,9 +42,11 @@ static int handle_vuart_init(struct domain *d,return -EOPNOTSUPP ; rc =domain_vpl011_init (d, &info); -if ( !rc ) + { vuart_op->evtchn = info.evtchn; + d->arch.emulation_flags |=ARM_EMU_VUART ; + }return rc; }
xen/arch/arm/include/asm/domain.h +9 -0
@@ -119,8 +119,17 @@ struct arch_domainvoid *tee;#endif +/* Emulated devices enabled bitmap. */ +uint32_t emulation_flags; + } __cacheline_aligned; +enum { +ARM_EMU_VUART =BIT (0 ,U ), +}; + +#define domain_has_vuart (d) (!!((d)->arch.emulation_flags & ARM_EMU_VUART)) + struct arch_vcpu { struct {
xen/arch/arm/vuart.c +0 -2
@@ -31,8 +31,6 @@#include "vuart.h" -#define domain_has_vuart (d) ((d)->arch.vuart.info != NULL) -static int vuart_mmio_read (struct vcpu *v,mmio_info_t *info,register_t *r,void *priv); static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info,
Signature · 1 line
2.34.1
PATCH v2 6/35 riscv/domain: introduce domain_has_vuart()
In reply to Denis MukhinIntroduce domain_has_vuart() for RISC-V port to be used in the console driver.
--- xen/arch/riscv/include/asm/domain.h | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/riscv/include/asm/domain.h +2 -0
@@ -10,6 +10,8 @@ struct hvm_domainuint64_t params[HVM_NR_PARAMS ]; }; +#define domain_has_vuart (d) false +struct arch_vcpu_io { };
Signature · 1 line
2.34.1
PATCH v2 7/35 ppc/domain: introduce domain_has_vuart()
In reply to Denis MukhinIntroduce domain_has_vuart() for PPC port to be used in the console driver.
--- xen/arch/ppc/include/asm/domain.h | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/ppc/include/asm/domain.h +2 -0
@@ -10,6 +10,8 @@ struct hvm_domainuint64_t params[HVM_NR_PARAMS ]; }; +#define domain_has_vuart (d) false +/* TODO: Implement */ #define guest_mode (r) ({ (void)(r); BUG_ON("unimplemented"); 0; })
Signature · 1 line
2.34.1
Re: [PATCH v2 07/35] ppc/domain: introduce domain_has_vuart()
Quoted 8 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce
domain_has_vuart()for PPC port to be used in the console driver.Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/ppc/include/asm/domain.h | 2 ++ 1 file changed, 2 insertions(+)
Please be sure to Cc the maintainer(s) of the file(s) you change. Else it may be pretty unlikely that you'll ever get an ack.
Jan
Quoted 12 lines
xen/arch/ppc/include/asm/domain.h +2
-0@@ -10,6 +10,8 @@ struct hvm_domainuint64_t params[HVM_NR_PARAMS ]; }; +#define domain_has_vuart (d) false +/* TODO: Implement */ #define guest_mode (r) ({ (void)(r); BUG_ON("unimplemented"); 0; })
PATCH v2 8/35 x86/domain: introduce domain_has_vuart()
In reply to Denis MukhinIntroduce domain_has_vuart() for x86 port to be used in the console driver.
--- xen/arch/x86/include/asm/domain.h | 3 +++ 1 file changed, 3 insertions(+)
xen/arch/x86/include/asm/domain.h +3 -0
@@ -506,6 +506,9 @@ struct arch_domain#define has_pirq (d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))#define has_vpci (d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI)) +/* NB: same symbol as in Arm port */ +#define domain_has_vuart (d) false +#define gdt_ldt_pt_idx (v) \ ((v)->vcpu_id >> (PAGETABLE_ORDER - GDT_LDT_VCPU_SHIFT))#define pv_gdt_ptes (v) \
Signature · 1 line
2.34.1
Re: [PATCH v2 08/35] x86/domain: introduce domain_has_vuart()
xen/arch/x86/include/asm/domain.h struct arch_domain · line 510
Quoted 8 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/arch/x86/include/asm/domain.h +2
-0@@ -506,6 +506,9 @@ struct arch_domain#define has_pirq (d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))#define has_vpci (d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI)) +/* NB: same symbol as in Arm port */ +#define domain_has_vuart (d) false
This being the 3rd effectively identical patch, perhaps instead we want to default domain_has_vuart() to false unless an arch provides its own definition? Much like we do for a few other such items?
Jan
Re: [PATCH v2 08/35] x86/domain: introduce domain_has_vuart()
Quoted 10 lines · Jan Beulich
Quoted 6 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/arch/x86/include/asm/domain.h +0
-0@@ -506,6 +506,9 @@ struct arch_domain#define has_pirq (d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))#define has_vpci (d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI))
Quoted 7 lines
xen/arch/x86/include/asm/domain.h struct arch_domain · line 510
Quoted 2 lines
xen/arch/x86/include/asm/domain.h +2
-0+/* NB: same symbol as in Arm port */ +#define domain_has_vuart (d) falseThis being the 3rd effectively identical patch, perhaps instead we want to default
domain_has_vuart()to false unless an arch provides its own definition? Much like we do for a few other such items?
Ideally, domain_has_vuart() should depend on build flags and d->arch.emulation_flags only. I have reworked the code, so that domain_has_vuart() is defined for all architectures uniformly.
To do that, I plumbed d->arch.emulation_flags to all arch domain structures and made arch-independent emulation flags declarations in v3.
Quoted 2 lines
Jan
Re: [PATCH v2 08/35] x86/domain: introduce domain_has_vuart()
In reply to Denis MukhinQuoted 14 lines · On Thu, Dec 05, 2024 at 08:41:38PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce
domain_has_vuart()for x86 port to be used in the console driver.Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/include/asm/domain.h | 3 +++ 1 file changed, 3 insertions(+)xen/arch/x86/include/asm/domain.h +0
-0
xen/arch/x86/include/asm/domain.h struct arch_domain · line 510
Quoted 5 lines
xen/arch/x86/include/asm/domain.h +2
-0@@ -506,6 +506,9 @@ struct arch_domain#define has_pirq (d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))#define has_vpci (d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI)) +/* NB: same symbol as in Arm port */ +#define domain_has_vuart (d) false
Don't you need to consume d in the macro, ie:
#define domain_has_vuart(d) ((void)(d), false)
Thanks, Roger.
Re: [PATCH v2 08/35] x86/domain: introduce domain_has_vuart()
Quoted 21 lines · Roger Pau Monné
Quoted 17 lines · On Thu, Dec 05, 2024 at 08:41:38PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Introduce
domain_has_vuart()for x86 port to be used in the console driver.Signed-off-by Denis Mukhin [email protected]---
xen/arch/x86/include/asm/domain.h| 3 +++1 file changed, 3 insertions(+)xen/arch/x86/include/asm/domain.h +0
-0@@ -506,6 +506,9 @@ struct arch_domain#define has_pirq (d) (!!((d)->arch.emulation_flags & X86_EMU_USE_PIRQ))#define has_vpci (d) (!!((d)->arch.emulation_flags & X86_EMU_VPCI))
Quoted 7 lines
xen/arch/x86/include/asm/domain.h struct arch_domain · line 510
Quoted 2 lines
xen/arch/x86/include/asm/domain.h +2
-0+/* NB: same symbol as in Arm port */ +#define domain_has_vuart (d) falseDon't you need to consume d in the macro, ie:
#define
domain_has_vuart(d)((void)(d), false)
I reworked that code and merged per-arch domain_has_vuart() patches into one arch-independent domain_has_vuart().
Quoted 2 lines
Thanks, Roger.
PATCH v2 9/35 x86/domain: print emulation_flags
In reply to Denis MukhinPrint d->arch.emulation_flags on the console for better traceability while debugging in-hypervisor hardware emulators.
--- xen/arch/x86/domain.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/x86/domain.c +6 -2
@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { -printk (XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " +printk (XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation " "with the current selection of emulators: %#x\n" , - d->domain_id,is_hvm_domain (d) ?"HVM" :"PV" , emflags); + d->domain_id, +is_hvm_domain (d) ?"HVM" :"PV" , +is_hardware_domain (d) ?"(hardware) " :"" , + emflags);return -EOPNOTSUPP ; } +printk (XENLOG_G_INFO "d%d: emulation_flags %#x\n" , d->domain_id, emflags); d->arch.emulation_flags = emflags;#ifdef CONFIG_PV32
Signature · 1 line
2.34.1
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
d->arch.emulation_flagson the console for better traceability while debugging in-hypervisor hardware emulators.
Personally I disagree with such extra printing. And that would in this case even apply if you used dprintk() or gdprintk(). However, if others support the idea, I don't mean to stand in the way. Just that ...
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 823
Quoted 11 lines
xen/arch/x86/domain.c +2
-2@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { -printk (XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation " "with the current selection of emulators: %#x\n", - d->domain_id,is_hvm_domain (d) ?"HVM" :"PV" , emflags); + d->domain_id,
... if already you touch this, please switch to %pd and also ...
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 829
Quoted 6 lines
xen/arch/x86/domain.c +4
-0+is_hvm_domain (d) ?"HVM" :"PV" , +is_hardware_domain (d) ?"(hardware) " :"" , + emflags);return -EOPNOTSUPP ; } +printk (XENLOG_G_INFO "d%d: emulation_flags %#x\n" , d->domain_id, emflags);
.. use that here.
Jan
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
Quoted 9 lines · Jan Beulich
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
d->arch.emulation_flagson the console for better traceability while debugging in-hypervisor hardware emulators.Personally I disagree with such extra printing. And that would in this case
I plumbed this printout into 'q' keyhandler which looks much better place to host this printout.
Quoted 26 lines
even apply if you used
dprintk()orgdprintk(). However, if others support the idea, I don't mean to stand in the way. Just that ...xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 823
Quoted 11 lines
xen/arch/x86/domain.c +2
-2@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { -printk (XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation " "with the current selection of emulators: %#x\n", - d->domain_id,is_hvm_domain (d) ?"HVM" :"PV" , emflags); + d->domain_id,... if already you touch this, please switch to %pd and also ...
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 829
Quoted 6 lines
xen/arch/x86/domain.c +4
-0+is_hvm_domain (d) ?"HVM" :"PV" , +is_hardware_domain (d) ?"(hardware) " :"" , + emflags);return -EOPNOTSUPP ; } +printk (XENLOG_G_INFO "d%d: emulation_flags %#x\n" , d->domain_id, emflags);
Quoted 1 line
.. use that here.
Oh, that's nice! Thank you.
Fixed.
Quoted 2 lines
Jan
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
In reply to Denis MukhinQuoted 15 lines · On Thu, Dec 05, 2024 at 08:41:39PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
d->arch.emulation_flagson the console for better traceability while debugging in-hypervisor hardware emulators.Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/domain.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/x86/domain.c +0
-0
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 821
Quoted 5 lines
xen/arch/x86/domain.c +1
-1@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation "
gprintk(XENLOG_ERR, "...
Might be more natural now that we have the macro (together with Jan's suggestion to use %pd (same below).
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 829
Quoted 9 lines
xen/arch/x86/domain.c +5
-1"with the current selection of emulators: %#x\n" , - d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags); + d->domain_id, +is_hvm_domain (d) ?"HVM" :"PV" , +is_hardware_domain (d) ?"(hardware) " :"" , + emflags);return -EOPNOTSUPP ; } +printk (XENLOG_G_INFO "d%d: emulation_flags %#x\n" , d->domain_id, emflags);
This would need to be a dprintk at least, and the log level should be XENLOG_DEBUG.
Maybe it would be better if you could print this information as part of some debug key, for not having to print it for every guest creation. Maybe as part of the 'q' debug key?
Thanks, Roger.
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
Quoted 12 lines · Roger Pau Monné
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 821
Quoted 8 lines · On Thu, Dec 05, 2024 at 08:41:39PM -0800, Denis Mukhin via B4 Relay wrote:
xen/arch/x86/domain.c +1
-1@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation "gprintk(XENLOG_ERR, "...
Quoted 2 lines
Might be more natural now that we have the macro (together with Jan's suggestion to use %pd (same below).
Yet why would we want to log current here, as gprintk() does?
Jan
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 821
Quoted 8 lines · On Thu, Dec 05, 2024 at 08:41:39PM -0800, Denis Mukhin via B4 Relay wrote:
xen/arch/x86/domain.c +1
-1@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation "gprintk(XENLOG_ERR, "...
Quoted 4 lines
Quoted 2 lines
Might be more natural now that we have the macro (together with Jan's suggestion to use %pd (same below).
Yet why would we want to log current here, as
gprintk()does?
Right - I've forgotten that gprintk already prepends %pd.
Thanks, Roger.
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
Quoted 14 lines · Roger Pau Monné
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 821
Quoted 8 lines · On Thu, Dec 05, 2024 at 08:41:39PM -0800, Denis Mukhin via B4 Relay wrote:
xen/arch/x86/domain.c +1
-1@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation "gprintk(XENLOG_ERR, "...
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Might be more natural now that we have the macro (together with Jan's suggestion to use %pd (same below).
Yet why would we want to log current here, as
gprintk()does?Right - I've forgotten that gprintk already prepends %pd.
FTAOD: It's %pv and logging current, which isn't what is being logged here (an incoming struct domain *).
Jan
Re: [PATCH v2 09/35] x86/domain: print emulation_flags
In reply to Roger Pau MonnéQuoted 42 lines · Roger Pau Monné
Quoted 15 lines · On Thu, Dec 05, 2024 at 08:41:39PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
d->arch.emulation_flagson the console for better traceability while debugging in-hypervisor hardware emulators.Signed-off-by Denis Mukhin [email protected]---
xen/arch/x86/domain.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/x86/domain.c +0
-0xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 821
Quoted 5 lines
xen/arch/x86/domain.c +1
-1@@ -818,11 +818,15 @@ int arch_domain_create(struct domain *d,if ( !emulation_flags_ok (d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "d%d: Xen does not allow %s %sdomain creation "gprintk(XENLOG_ERR, "...
Might be more natural now that we have the macro (together with Jan's suggestion to use %pd (same below).
xen/arch/x86/domain.c int arch_domain_create(struct domain *d, · line 829
Quoted 9 lines
xen/arch/x86/domain.c +5
-1"with the current selection of emulators: %#x\n" , - d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags); + d->domain_id, +is_hvm_domain (d) ?"HVM" :"PV" , +is_hardware_domain (d) ?"(hardware) " :"" , + emflags);return -EOPNOTSUPP ; } +printk (XENLOG_G_INFO "d%d: emulation_flags %#x\n" , d->domain_id, emflags);
Quoted 2 lines
This would need to be a dprintk at least, and the log level should be
XENLOG_DEBUG.
I moved emulation_flags printout to 'q' handler.
Quoted 4 lines
Maybe it would be better if you could print this information as part of some debug key, for not having to print it for every guest creation. Maybe as part of the 'q' debug key?
Thank you for suggestion!
Fixed.
Quoted 2 lines
Thanks, Roger.
PATCH v2 10/35 xen/domain: add get_initial_domain_id()
In reply to Denis MukhinMove get_initial_domain_id() to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.
--- xen/arch/x86/include/asm/pv/shim.h | 4 ++-- xen/arch/x86/pv/shim.c | 4 ++-- xen/common/domain.c | 10 ++++++++++ xen/include/xen/domain.h | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/pv/shim.h +2 -2
@@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data);long cf_check pv_shim_cpu_down (void *data);void pv_shim_online_memory (unsigned int nr,unsigned int order);void pv_shim_offline_memory (unsigned int nr,unsigned int order); -domid_t get_initial_domain_id (void ); +domid_t pv_shim_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail);void pv_shim_fixup_e820 (void );const struct platform_bad_page *pv_shim_reserved_pages (unsigned int *size);
@@ -76,7 +76,7 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order) {ASSERT_UNREACHABLE (); } -static inline domid_t get_initial_domain_id (void ) +static inline domid_t pv_shim_initial_domain_id (void ) {return 0 ; }
xen/arch/x86/pv/shim.c +2 -2
@@ -328,7 +328,7 @@ int pv_shim_shutdown(uint8_t reason) }/* Update domain id. */ - d->domain_id =get_initial_domain_id (); + d->domain_id =pv_shim_initial_domain_id ();/* Clean the iomem range. */ BUG_ON (iomem_deny_access (d,0 , ~0UL ));
@@ -1016,7 +1016,7 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order) } } -domid_t get_initial_domain_id (void ) +domid_t pv_shim_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;
xen/common/domain.c +10 -0
@@ -45,6 +45,7 @@#ifdef CONFIG_X86 #include <asm/guest.h> +#include <asm/pv/shim.h> #endif /* Linux config option: propageted to domain0 */
@@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu(return 0 ; } +domid_t get_initial_domain_id (void ) +{ +#ifdef CONFIG_X86 +return pv_shim_initial_domain_id (); +#else +return 0 ; +#endif +} +/* * Local variables: * mode: C
xen/include/xen/domain.h +2 -0
@@ -171,4 +171,6 @@ extern bool vmtrace_available;extern bool vpmu_is_available; +domid_t get_initial_domain_id (void ); +#endif /* __XEN_DOMAIN_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v2 10/35] xen/domain: add get_initial_domain_id()
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Move
get_initial_domain_id()to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.
Yet then how does this fit with dom0less, let alone hyperlaunch, where multiple domains may be created right when Xen starts?
Plus, if you make this generic, shouldn't Arm also be adjusted to use this function (if nothing else then to avoid things going out of sync later on)?
xen/common/domain.c int continue_hypercall_on_cpu( · line 2240
Quoted 12 lines
xen/common/domain.c +8
-0@@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu(return 0 ; } +domid_t get_initial_domain_id (void ) +{ +#ifdef CONFIG_X86 +return pv_shim_initial_domain_id (); +#else +return 0 ; +#endif +}
Imo this either wants to use CONFIG_PV_SHIM instead, eliminating the need for the pv_shim_initial_domain_id() stub.
Jan
Re: [PATCH v2 10/35] xen/domain: add get_initial_domain_id()
Quoted 10 lines · Jan Beulich
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Move
get_initial_domain_id()to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.Yet then how does this fit with dom0less, let alone hyperlaunch, where multiple domains may be created right when Xen starts?
I see it now, thanks; fixed in v3.
Quoted 4 lines
Plus, if you make this generic, shouldn't Arm also be adjusted to use this function (if nothing else then to avoid things going out of sync later on)?
Yes, Arm port should have been adjusted; thanks a lot! Addressed.
Quoted 5 lines
Quoted 5 lines
xen/common/domain.c +0
-0@@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu(return 0 ; }
Quoted 12 lines
xen/common/domain.c int continue_hypercall_on_cpu( · line 2240
Quoted 8 lines
xen/common/domain.c +8
-0+domid_t get_initial_domain_id (void ) +{ +#ifdef CONFIG_X86 +return pv_shim_initial_domain_id (); +#else +return 0 ; +#endif +}Imo this either wants to use
CONFIG_PV_SHIMinstead, eliminating the need for thepv_shim_initial_domain_id()stub.
Fixed.
Quoted 2 lines
Jan
Re: [PATCH v2 10/35] xen/domain: add get_initial_domain_id()
In reply to Denis MukhinQuoted 40 lines · On Thu, Dec 05, 2024 at 08:41:40PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Move
get_initial_domain_id()to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/include/asm/pv/shim.h | 4 ++-- xen/arch/x86/pv/shim.c | 4 ++-- xen/common/domain.c | 10 ++++++++++ xen/include/xen/domain.h | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-)xen/arch/x86/include/asm/pv/shim.h +2
-2@@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data);long cf_check pv_shim_cpu_down (void *data);void pv_shim_online_memory (unsigned int nr,unsigned int order);void pv_shim_offline_memory (unsigned int nr,unsigned int order); -domid_t get_initial_domain_id (void ); +domid_t pv_shim_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail);void pv_shim_fixup_e820 (void );const struct platform_bad_page *pv_shim_reserved_pages (unsigned int *size);@@ -76,7 +76,7 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order) {ASSERT_UNREACHABLE (); } -static inline domid_t get_initial_domain_id (void ) +static inline domid_t pv_shim_initial_domain_id (void ) {return 0 ; }xen/arch/x86/pv/shim.c +0
-0
xen/arch/x86/pv/shim.c int pv_shim_shutdown(uint8_t reason) · line 331
Quoted 5 lines
xen/arch/x86/pv/shim.c +1
-1@@ -328,7 +328,7 @@ int pv_shim_shutdown(uint8_t reason) }/* Update domain id. */ - d->domain_id =get_initial_domain_id (); + d->domain_id =pv_shim_initial_domain_id ();
Can't you leave this instance using get_initial_domain_id(), it should DTRT when running in pv-shim mode.
Quoted 26 lines
xen/arch/x86/pv/shim.c +1
-1/* Clean the iomem range. */ BUG_ON (iomem_deny_access (d,0 , ~0UL ));@@ -1016,7 +1016,7 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order) } } -domid_t get_initial_domain_id (void ) +domid_t pv_shim_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;xen/common/domain.c +1
-0@@ -45,6 +45,7 @@#ifdef CONFIG_X86 #include <asm/guest.h> +#include <asm/pv/shim.h> #endif /* Linux config option: propageted to domain0 */ @@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu(return 0 ;
xen/common/domain.c int continue_hypercall_on_cpu( · line 2240
Quoted 10 lines
xen/common/domain.c +8
-0} +domid_t get_initial_domain_id (void ) +{ +#ifdef CONFIG_X86 +return pv_shim_initial_domain_id (); +#else +return 0 ; +#endif +}
Maybe there are further changes that make this a not suitable option, but won't it be better to maybe do something like:
#ifndef HAS_ARCH_INITIAL_DOMID
static inline domid_t get_initial_domain_id(void) { return 0; } #elsedomid_t get_initial_domain_id(void);
#endif
In a generic header, and then in an x86 header you just
#define HAS_ARCH_INITIAL_DOMID
The ifdefary in get_initial_domain_id() if other arches need different implementations seems undesirable.
Thanks, Roger.
Re: [PATCH v2 10/35] xen/domain: add get_initial_domain_id()
Quoted 46 lines · Roger Pau Monné
Quoted 42 lines · On Thu, Dec 05, 2024 at 08:41:40PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Move
get_initial_domain_id()to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.Signed-off-by Denis Mukhin [email protected]---
xen/arch/x86/include/asm/pv/shim.h| 4 ++--xen/arch/x86/pv/shim.c| 4 ++--xen/common/domain.c| 10 ++++++++++xen/include/xen/domain.h| 2 ++4 files changed, 16 insertions(+), 4 deletions(-)xen/arch/x86/include/asm/pv/shim.h +2
-2@@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data);long cf_check pv_shim_cpu_down (void *data);void pv_shim_online_memory (unsigned int nr,unsigned int order);void pv_shim_offline_memory (unsigned int nr,unsigned int order); -domid_t get_initial_domain_id (void ); +domid_t pv_shim_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail);void pv_shim_fixup_e820 (void );const struct platform_bad_page *pv_shim_reserved_pages (unsigned int *size);@@ -76,7 +76,7 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order) {ASSERT_UNREACHABLE (); } -static inline domid_t get_initial_domain_id (void ) +static inline domid_t pv_shim_initial_domain_id (void ) {return 0 ; }xen/arch/x86/pv/shim.c +0
-0@@ -328,7 +328,7 @@ int pv_shim_shutdown(uint8_t reason) }
Quoted 7 lines
xen/arch/x86/pv/shim.c int pv_shim_shutdown(uint8_t reason) · line 331
Quoted 3 lines
xen/arch/x86/pv/shim.c +1
-1/* Update domain id. */ - d->domain_id =get_initial_domain_id (); + d->domain_id =pv_shim_initial_domain_id ();Can't you leave this instance using
get_initial_domain_id(), it should DTRT when running in pv-shim mode.
Reverted.
Quoted 47 lines
Quoted 26 lines
xen/arch/x86/pv/shim.c +1
-1/* Clean the iomem range. */ BUG_ON (iomem_deny_access (d,0 , ~0UL ));@@ -1016,7 +1016,7 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order) } } -domid_t get_initial_domain_id (void ) +domid_t pv_shim_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;xen/common/domain.c +1
-0@@ -45,6 +45,7 @@#ifdef CONFIG_X86 #include <asm/guest.h> +#include <asm/pv/shim.h> #endif /* Linux config option: propageted to domain0 */ @@ -2229,6 +2230,15 @@ int continue_hypercall_on_cpu(return 0 ;xen/common/domain.c int continue_hypercall_on_cpu( · line 2240
Quoted 10 lines
xen/common/domain.c +8
-0} +domid_t get_initial_domain_id (void ) +{ +#ifdef CONFIG_X86 +return pv_shim_initial_domain_id (); +#else +return 0 ; +#endif +}Maybe there are further changes that make this a not suitable option, but won't it be better to maybe do something like:
#ifndef
HAS_ARCH_INITIAL_DOMID
static inlinedomid_tget_initial_domain_id(void){ return 0; } #elsedomid_tget_initial_domain_id(void);
#endif
Quoted 6 lines
In a generic header, and then in an x86 header you just
#define
HAS_ARCH_INITIAL_DOMIDThe ifdefary in
get_initial_domain_id()if other arches need different implementations seems undesirable.
IMO, existing implementation of get_initial_domain_id() looks like a layering violation: global get_initial_domain_id() does not belong to PV shim layer.
The current equivalent of HAS_ARCH_INITIAL_DOMID is CONFIG_PV_SHIM, so I think there's no need to define another config flag.
After addressing Jan's feedback and then moving the code around, I kept pv_shim_get_initial_domain_id() in PV shim and #ifdefs in common/domain.c (similar to domain_shutdown()).
Also, I switched to using hardware_domid instead of open-coded 0.
Quoted 2 lines
Thanks, Roger.
PATCH v2 11/35 xen/domain: enable max_init_domid for all architectures
In reply to Denis MukhinMove max_init_domid to a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.
max_init_domid is updated in domain_create().
--- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 2 -- xen/arch/ppc/include/asm/setup.h | 2 -- xen/arch/riscv/include/asm/setup.h | 2 -- xen/arch/x86/include/asm/setup.h | 2 -- xen/common/domain.c | 9 +++++++++ xen/include/xen/domain.h | 2 ++ 7 files changed, 11 insertions(+), 10 deletions(-)
xen/arch/arm/include/asm/setup.h +0 -2
@@ -19,8 +19,6 @@ struct map_range_datastruct rangeset *irq_ranges; }; -extern domid_t max_init_domid; -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);
xen/arch/arm/setup.c +0 -2
@@ -58,8 +58,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;bool __read_mostly acpi_disabled;#endif -domid_t __read_mostly max_init_domid; -static __used void init_done (void ) {int rc;
xen/arch/ppc/include/asm/setup.h +0 -2
@@ -1,6 +1,4 @@#ifndef __ASM_PPC_SETUP_H__#define __ASM_PPC_SETUP_H__ -#define max_init_domid (0) -#endif /* __ASM_PPC_SETUP_H__ */
xen/arch/riscv/include/asm/setup.h +0 -2
@@ -3,8 +3,6 @@#ifndef ASM__RISCV__SETUP_H #define ASM__RISCV__SETUP_H -#define max_init_domid (0) -void setup_mm (void );#endif /* ASM__RISCV__SETUP_H */
xen/arch/x86/include/asm/setup.h +0 -2
@@ -69,6 +69,4 @@ extern bool opt_dom0_verbose;extern bool opt_dom0_cpuid_faulting;extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) -#endif
xen/common/domain.c +9 -0
@@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid; +/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc.
@@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid,memcpy (d->handle, config->handle,sizeof (d->handle)); +/* +* Housekeeping for physical console forwarding to the domain. +*/ +if ( !is_system_domain (d) && max_init_domid < domid ) + max_init_domid = domid; +return d; fail:
xen/include/xen/domain.h +2 -0
@@ -171,6 +171,8 @@ extern bool vmtrace_available;extern bool vpmu_is_available; +extern domid_t max_init_domid; +domid_t get_initial_domain_id (void );#endif /* __XEN_DOMAIN_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures
Quoted 13 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/common/domain.c +3
-0@@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid; +/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc.
xen/common/domain.c struct domain *domain_create(domid_t domid, · line 825
Quoted 8 lines
xen/common/domain.c +5
-0@@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid,memcpy (d->handle, config->handle,sizeof (d->handle)); +/* +* Housekeeping for physical console forwarding to the domain. +*/ +if ( !is_system_domain (d) && max_init_domid < domid ) + max_init_domid = domid;
Yet this affects all domains, not just init ones. Either the variable name is wrong then, or the updating logic needs adjustment. The comment in the earlier hunk suggests the former, yet then this is a behavioral change for Arm, correctness of which needs explaining.
Jan
Re: [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures
Quoted 20 lines · Jan Beulich
Quoted 16 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/common/domain.c +3
-0@@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +/* Last known non-system domain ID. / +domid_t __read_mostly max_init_domid; +/
* Insert a domain into the domlist/hash. This allows the domain to be looked
* up by domid, and therefore to be the subject of hypercalls/etc.xen/common/domain.c +0
-0@@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid,memcpy (d->handle, config->handle,sizeof (d->handle));
Quoted 11 lines
xen/common/domain.c struct domain *domain_create(domid_t domid, · line 825
Quoted 5 lines
xen/common/domain.c +5
-0+/* +* Housekeeping for physical console forwarding to the domain. +*/ +if ( !is_system_domain (d) && max_init_domid < domid ) + max_init_domid = domid;Yet this affects all domains, not just init ones. Either the variable name is wrong then, or the updating logic needs adjustment. The comment in the earlier hunk suggests the former, yet then this is a behavioral change for Arm, correctness of which needs explaining.
Thanks, I have reworked that part.
Quoted 2 lines
Jan
Re: [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures
In reply to Denis MukhinQuoted 84 lines · On Thu, Dec 05, 2024 at 08:41:41PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Move
max_init_domidto a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.
max_init_domidis updated indomain_create().Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 2 -- xen/arch/ppc/include/asm/setup.h | 2 -- xen/arch/riscv/include/asm/setup.h | 2 -- xen/arch/x86/include/asm/setup.h | 2 -- xen/common/domain.c | 9 +++++++++ xen/include/xen/domain.h | 2 ++ 7 files changed, 11 insertions(+), 10 deletions(-)xen/arch/arm/include/asm/setup.h +0
-2@@ -19,8 +19,6 @@ struct map_range_datastruct rangeset *irq_ranges; }; -extern domid_t max_init_domid; -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);xen/arch/arm/setup.c +0
-2@@ -58,8 +58,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;bool __read_mostly acpi_disabled;#endif -domid_t __read_mostly max_init_domid; -static __used void init_done (void ) {int rc;xen/arch/ppc/include/asm/setup.h +0
-2@@ -1,6 +1,4 @@#ifndef __ASM_PPC_SETUP_H__#define __ASM_PPC_SETUP_H__ -#define max_init_domid (0) -#endif /* __ASM_PPC_SETUP_H__ */ xen/arch/riscv/include/asm/setup.h +0
-2@@ -3,8 +3,6 @@#ifndef ASM__RISCV__SETUP_H #define ASM__RISCV__SETUP_H -#define max_init_domid (0) -void setup_mm (void );#endif /* ASM__RISCV__SETUP_H */ xen/arch/x86/include/asm/setup.h +0
-2@@ -69,6 +69,4 @@ extern bool opt_dom0_verbose;extern bool opt_dom0_cpuid_faulting;extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) -#endif xen/common/domain.c +0
-0
xen/common/domain.c DEFINE_RCU_READ_LOCK(domlist_read_lock); · line 69
Quoted 5 lines
xen/common/domain.c +2
-0@@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid;
The comment (and implementation below) seems to differ from what Arm dom0less code currently uses the variable for.
xen/common/domain.c struct domain *domain_create(domid_t domid, · line 825
Quoted 13 lines
xen/common/domain.c +6
-0+/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc. @@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid,memcpy (d->handle, config->handle,sizeof (d->handle)); +/* +* Housekeeping for physical console forwarding to the domain. +*/ +if ( !is_system_domain (d) && max_init_domid < domid ) + max_init_domid = domid;
Don't you need to adjust the ARM dom0-less logic that deal with increasing max_init_domid in create_domUs().
Also max_init_domid likely only wants to be updated for domains created before the control domain is started, and hence could be __ro_after_init instead of __read_mostly?
Thanks, Roger.
Re: [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures
Quoted 91 lines · Roger Pau Monné
Quoted 87 lines · On Thu, Dec 05, 2024 at 08:41:41PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Move
max_init_domidto a public API and enable for all architectures. That is pre-requisite change for console focus switch logic cleanup.
max_init_domidis updated indomain_create().Signed-off-by Denis Mukhin [email protected]---
xen/arch/arm/include/asm/setup.h| 2 --xen/arch/arm/setup.c| 2 --xen/arch/ppc/include/asm/setup.h| 2 --xen/arch/riscv/include/asm/setup.h| 2 --xen/arch/x86/include/asm/setup.h| 2 --xen/common/domain.c| 9 +++++++++xen/include/xen/domain.h| 2 ++7 files changed, 11 insertions(+), 10 deletions(-)xen/arch/arm/include/asm/setup.h +0
-2@@ -19,8 +19,6 @@ struct map_range_datastruct rangeset *irq_ranges; }; -extern domid_t max_init_domid; -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);xen/arch/arm/setup.c +0
-2@@ -58,8 +58,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;bool __read_mostly acpi_disabled;#endif -domid_t __read_mostly max_init_domid; -static __used void init_done (void ) {int rc;xen/arch/ppc/include/asm/setup.h +0
-2@@ -1,6 +1,4 @@#ifndef ASM_PPC_SETUP_H #define ASM_PPC_SETUP_H -#define max_init_domid (0) -#endif /* ASM_PPC_SETUP_H */ xen/arch/riscv/include/asm/setup.h +0
-2@@ -3,8 +3,6 @@#ifndef ASM__RISCV__SETUP_H #define ASM__RISCV__SETUP_H -#define max_init_domid (0) -void setup_mm (void );#endif /* ASM__RISCV__SETUP_H */ xen/arch/x86/include/asm/setup.h +0
-2@@ -69,6 +69,4 @@ extern bool opt_dom0_verbose;extern bool opt_dom0_cpuid_faulting;extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) -#endif xen/common/domain.c +0
-0@@ -65,6 +65,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list;
Quoted 6 lines
xen/common/domain.c DEFINE_RCU_READ_LOCK(domlist_read_lock); · line 69
Quoted 2 lines
xen/common/domain.c +2
-0+/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid;The comment (and implementation below) seems to differ from what Arm dom0less code currently uses the variable for.
Yep, thanks.
I realized that after receiving Jan's feedback.
Reworked.
Quoted 19 lines
Quoted 6 lines
xen/common/domain.c +1
-0+/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc. xen/common/domain.c struct domain *domain_create(domid_t domid, · line 825
Quoted 8 lines
xen/common/domain.c +5
-0@@ -815,6 +818,12 @@ struct domain *domain_create(domid_t domid,memcpy (d->handle, config->handle,sizeof (d->handle)); +/* +* Housekeeping for physical console forwarding to the domain. +*/ +if ( !is_system_domain (d) && max_init_domid < domid ) + max_init_domid = domid;Don't you need to adjust the ARM dom0-less logic that deal with increasing
max_init_domidincreate_domUs().
Quoted 3 lines
Also
max_init_domidlikely only wants to be updated for domains created before the control domain is started, and hence could be__ro_after_initinstead of__read_mostly?
I addressed that in v3, thanks!
Quoted 2 lines
Thanks, Roger.
PATCH v2 12/35 xen/console: move vpl011-related code to vpl011 emulator
In reply to Denis MukhinXen console driver has vpl011-related logic which shall belong vpl011 emulator code. Move vpl011-related to vpl011.c.
--- xen/arch/arm/include/asm/vpl011.h | 2 +- xen/arch/arm/vpl011.c | 15 +++++++++++---- xen/drivers/char/console.c | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-)
xen/arch/arm/include/asm/vpl011.h +1 -1
@@ -69,7 +69,7 @@ struct vpl011_init_info {int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info);void domain_vpl011_deinit (struct domain *d); -void vpl011_rx_char_xen (struct domain *d,char c); +int vpl011_rx_char_xen (struct domain *d,char c);#else static inline int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info)
xen/arch/arm/vpl011.c +11 -4
@@ -567,16 +567,21 @@ static void vpl011_data_avail(struct domain *d,/* * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer. -* It is only used when the vpl011 backend is in Xen. */ -void vpl011_rx_char_xen (struct domain *d,char c) +int vpl011_rx_char_xen (struct domain *d,char c) {unsigned long flags;struct vpl011 *vpl011 = &d->arch.vpl011;struct vpl011_xen_backend *intf = vpl011->backend.xen;XENCONS_RING_IDX in_cons, in_prod, in_fifo_level; -ASSERT (!vpl011->backend_in_domain); +/* Forward input iff the vpl011 backend is in Xen. */ +if ( vpl011->backend_in_domain ) +return -ENODEV ; + +if ( intf ==NULL ) +return -ENODEV ; +VPL011_LOCK (d, flags); in_cons = intf->in_cons;
@@ -584,7 +589,7 @@ void vpl011_rx_char_xen(struct domain *d, char c)if (xencons_queued (in_prod, in_cons,sizeof (intf->in)) ==sizeof (intf->in) ) {VPL011_UNLOCK (d, flags); -return ; +return -ENOSPC ; } intf->in[xencons_mask (in_prod,sizeof (intf->in))] = c;
@@ -596,6 +601,8 @@ void vpl011_rx_char_xen(struct domain *d, char c)vpl011_data_avail (d, in_fifo_level,sizeof (intf->in),0 ,SBSA_UART_FIFO_SIZE );VPL011_UNLOCK (d, flags); + +return 0 ; }static void vpl011_notification (struct vcpu *v,unsigned int port)
xen/drivers/char/console.c +1 -3
@@ -559,9 +559,7 @@ static void __serial_rx(char c)* domain, without a full PV ring to Dom0 (in that case input * comes from the PV ring), then send the character to it. */ -if ( d !=NULL && - !d->arch.vpl011.backend_in_domain && - d->arch.vpl011.backend.xen !=NULL ) +if ( d !=NULL )vpl011_rx_char_xen (d, c);else printk("Cannot send chars to Dom%d: no UART available\n",
Signature · 1 line
2.34.1
Re: [PATCH v2 12/35] xen/console: move vpl011-related code to vpl011 emulator
xen/arch/arm/include/asm/vpl011.h struct vpl011_init_info { · line 72
Quoted 8 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/arch/arm/include/asm/vpl011.h +1
-1@@ -69,7 +69,7 @@ struct vpl011_init_info {int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info);void domain_vpl011_deinit (struct domain *d); -void vpl011_rx_char_xen (struct domain *d,char c); +int vpl011_rx_char_xen (struct domain *d,char c);
If you make the function return an error indicator, ...
Quoted 4 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 565
Quoted 10 lines
xen/drivers/char/console.c +1
-3@@ -559,9 +559,7 @@ static void __serial_rx(char c)* domain, without a full PV ring to Dom0 (in that case input * comes from the PV ring), then send the character to it. */ -if ( d !=NULL && - !d->arch.vpl011.backend_in_domain && - d->arch.vpl011.backend.xen !=NULL ) +if ( d !=NULL )vpl011_rx_char_xen (d, c);else printk("Cannot send chars to Dom%d: no UART available\n",
... how come that return value then isn't used anywhere?
Jan
Re: [PATCH v2 12/35] xen/console: move vpl011-related code to vpl011 emulator
Quoted 16 lines · Jan Beulich
xen/arch/arm/include/asm/vpl011.h struct vpl011_init_info { · line 72
Quoted 8 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/arch/arm/include/asm/vpl011.h +1
-1@@ -69,7 +69,7 @@ struct vpl011_init_info {int domain_vpl011_init (struct domain *d,struct vpl011_init_info *info);void domain_vpl011_deinit (struct domain *d); -void vpl011_rx_char_xen (struct domain *d,char c); +int vpl011_rx_char_xen (struct domain *d,char c);If you make the function return an error indicator, ...
Quoted 16 lines
Quoted 11 lines
xen/drivers/char/console.c +1
-3@@ -559,9 +559,7 @@ static void __serial_rx(char c)* domain, without a full PV ring to Dom0 (in that case input * comes from the PV ring), then send the character to it. */ -if ( d !=NULL && - !d->arch.vpl011.backend_in_domain && - d->arch.vpl011.backend.xen !=NULL ) +if ( d !=NULL )vpl011_rx_char_xen (d, c);Quoted 2 lines
else
printk("Cannot send chars to Dom%d: no UART available\n",... how come that return value then isn't used anywhere?
That I overlooked; fixed.
Quoted 2 lines
Jan
PATCH v2 13/35 xen/console: rename console_input_domain
In reply to Denis Mukhinconsole_input_domain() takes an RCU lock to protect domain structure. That implies call to rcu_unlock_domain() after use.
Rename console_input_domain() to rcu_lock_domain_console_owner() to highlight the need of calling rcu_unlock_domain().
--- xen/arch/arm/vpl011.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/xen/console.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/arm/vpl011.c +1 -1
@@ -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 =rcu_lock_domain_console_owner ();VPL011_LOCK (d, flags);
xen/drivers/char/console.c +1 -1
@@ -477,7 +477,7 @@ static unsigned int __read_mostly console_rx = 0;#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ -struct domain *console_input_domain (void ) +struct domain *rcu_lock_domain_console_owner (void ) {if ( console_rx ==0 )return NULL ;
xen/include/xen/console.h +1 -1
@@ -31,7 +31,7 @@ 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 *rcu_lock_domain_console_owner (void );/* * Steal output from the console. Returns +ve identifier, else -ve error.
Signature · 1 line
2.34.1
Re: [PATCH v2 13/35] xen/console: rename console_input_domain
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
console_input_domain()takes an RCU lock to protect domain structure. That implies call torcu_unlock_domain()after use.Rename
console_input_domain()torcu_lock_domain_console_owner()to highlight the need of callingrcu_unlock_domain().
While I can see where you're coming from, ...
xen/drivers/char/console.c static unsigned int __read_mostly console_rx = 0; · line 483
Quoted 11 lines
xen/drivers/char/console.c +1
-1@@ -477,7 +477,7 @@ static unsigned int __read_mostly console_rx = 0;#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ -struct domain *console_input_domain (void ) +struct domain *rcu_lock_domain_console_owner (void ) {if ( console_rx ==0 )return NULL ;
... the new name no longer expresses that a domain pointer is being returned (out of thin air). I'm uncertain this is an improvement.
Jan
Re: [PATCH v2 13/35] xen/console: rename console_input_domain
Quoted 17 lines · Jan Beulich
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
console_input_domain()takes an RCU lock to protect domain structure. That implies call torcu_unlock_domain()after use.Rename
console_input_domain()torcu_lock_domain_console_owner()to highlight the need of callingrcu_unlock_domain().While I can see where you're coming from, ...
Quoted 4 lines
xen/drivers/char/console.c +0
-0@@ -477,7 +477,7 @@ static unsigned int __read_mostly console_rx = 0;
Quoted 11 lines
xen/drivers/char/console.c static unsigned int __read_mostly console_rx = 0; · line 483
Quoted 7 lines
xen/drivers/char/console.c +1
-1#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ -struct domain *console_input_domain (void ) +struct domain *rcu_lock_domain_console_owner (void ) {if ( console_rx ==0 )return NULL ;... the new name no longer expresses that a domain pointer is being returned (out of thin air). I'm uncertain this is an improvement.
I introduced console_{get,put}_domain() in v3 as per Roger's suggestion.
Quoted 2 lines
Jan
Re: [PATCH v2 13/35] xen/console: rename console_input_domain
In reply to Denis MukhinQuoted 20 lines · On Thu, Dec 05, 2024 at 08:41:43PM -0800, Denis Mukhin via B4 Relay 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.Rename
console_input_domain()torcu_lock_domain_console_owner()to highlight the need of callingrcu_unlock_domain().Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/arm/vpl011.c | 2 +- xen/drivers/char/console.c | 2 +- xen/include/xen/console.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)xen/arch/arm/vpl011.c +0
-0
xen/arch/arm/vpl011.c static void vpl011_write_data_xen(struct domain *d, uint8_t data) · line 81
Quoted 5 lines
xen/arch/arm/vpl011.c +1
-1@@ -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 =rcu_lock_domain_console_owner ();
May I suggest console_get_domain() and then introducing a console_put_domain() which is just a wrapper around rcu_unlock_domain()?
Thanks, Roger.
Re: [PATCH v2 13/35] xen/console: rename console_input_domain
Quoted 19 lines · Roger Pau Monné
Quoted 15 lines · On Thu, Dec 05, 2024 at 08:41:43PM -0800, Denis Mukhin via B4 Relay 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.Rename
console_input_domain()torcu_lock_domain_console_owner()to highlight the need of callingrcu_unlock_domain().Signed-off-by Denis Mukhin [email protected]---
xen/arch/arm/vpl011.c| 2 +-xen/drivers/char/console.c| 2 +-xen/include/xen/console.h| 2 +-3 files changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
xen/arch/arm/vpl011.c static void vpl011_write_data_xen(struct domain *d, uint8_t data) · line 81
Quoted 10 lines
xen/arch/arm/vpl011.c +1
-1@@ -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 =rcu_lock_domain_console_owner ();May I suggest
console_get_domain()and then introducing aconsole_put_domain()which is just a wrapper aroundrcu_unlock_domain()?
Agreed, that looks even better! Thanks.
Fixed.
Quoted 2 lines
Thanks, Roger.
PATCH v2 14/35 xen/console: rename switch_serial_input() to console_find_owner()
In reply to Denis MukhinUpdated the name to highlight the logic of selection the physical console
owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall).
--- xen/drivers/char/console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +3 -3
@@ -485,7 +485,7 @@ struct domain *rcu_lock_domain_console_owner(void) }#endif -static void switch_serial_input (void ) +static void console_find_owner (void ) {unsigned int next_rx = console_rx;
@@ -588,7 +588,7 @@ static void cf_check serial_rx(char c)/* We eat CTRL-<switch_char> in groups of 3 to switch console input. */ if ( ++switch_code_count ==3 ) { -switch_serial_input (); +console_find_owner (); switch_code_count =0 ; }return ;
@@ -1128,7 +1128,7 @@ void __init console_endboot(void) "toggle host/guest log level adjustment", 0);/* Serial input is directed to DOM0 by default. */ -switch_serial_input (); +console_find_owner (); }int __init console_has (const char *device)
Signature · 1 line
2.34.1
Re: [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner()
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Updated the name to highlight the logic of selection the physical console
owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall).
I'm especially surprised you mention "video console" here. Afaics all of this is only about console _input_, and no input comes from a video device. Arguably "serial" in the original name is too narrow now. Yet "input" continues to be quite appropriate.
Jan
Re: [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner()
Quoted 11 lines · Jan Beulich
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Updated the name to highlight the logic of selection the physical console
owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall).I'm especially surprised you mention "video console" here. Afaics all of this is only about console _input_, and no input comes from a video device. Arguably "serial" in the original name is too narrow now. Yet "input" continues to be quite appropriate.
switch_console_input() maybe? switch_console_input_target() even?
I think the switch is also relevant, as it shuffles the input around, console_find_owner() doesn't seem to convey that meaning.
Thanks, Roger.
Re: [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner()
Quoted 18 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Quoted 8 lines
Quoted 3 lines
Updated the name to highlight the logic of selection the physical console
owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall).I'm especially surprised you mention "video console" here. Afaics all of this is only about console input, and no input comes from a video device. Arguably "serial" in the original name is too narrow now. Yet "input" continues to be quite appropriate.
Quoted 4 lines
switch_console_input()maybe?switch_console_input_target()even?I think the switch is also relevant, as it shuffles the input around,
console_find_owner()doesn't seem to convey that meaning.
Renamed to console_switch_input() in v3
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner()
In reply to Jan BeulichQuoted 11 lines · Jan Beulich
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Updated the name to highlight the logic of selection the physical console
owner: existing code does not switch only serial console, it also switches video console and debugging console (debug I/O port and console hypercall).
Quoted 4 lines
I'm especially surprised you mention "video console" here. Afaics all of this is only about console input, and no input comes from a video device. Arguably "serial" in the original name is too narrow now. Yet "input" continues to be quite appropriate.
Yes, sorry, the explanation is wrong.
Fixed.
Quoted 2 lines
Jan
PATCH v2 15/35 xen/console: rename console_rx to console_owner
In reply to Denis MukhinPreparation for the follow on change to switch console_owner to domid_t address space.
--- xen/drivers/char/console.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
xen/drivers/char/console.c +13 -13
@@ -467,11 +467,11 @@ static void cf_check dump_console_ring_key(unsigned char key)*/ #define switch_code (opt_conswitch[0]-'a'+1)/* -* console_rx=0 => input to xen -* console_rx=1 => input to dom0 (or the sole shim domain) -* console_rx=N => input to dom(N-1) +* console_owner=0 => input to xen +* console_owner=1 => input to dom0 (or the sole shim domain) +* console_owner=N => input to dom(N-1) */ -static unsigned int __read_mostly console_rx =0 ; +static unsigned int __read_mostly console_owner =0 ;#define max_console_rx (max_init_domid + 1)
@@ -479,15 +479,15 @@ static unsigned int __read_mostly console_rx = 0;/* Make sure to rcu_unlock_domain after use */ struct domain *rcu_lock_domain_console_owner (void ) { -if ( console_rx ==0 ) +if ( console_owner ==0 )return NULL ; -return rcu_lock_domain_by_id (console_rx -1 ); +return rcu_lock_domain_by_id (console_owner -1 ); }#endif static void console_find_owner (void ) { -unsigned int next_rx = console_rx; +unsigned int next_rx = console_owner;/* * Rotate among Xen, dom0 and boot-time created domUs while skipping
@@ -500,7 +500,7 @@ static void console_find_owner(void)if ( next_rx++ >= max_console_rx ) { - console_rx =0 ; + console_owner =0 ;printk ("*** Serial input to Xen" );break ; }
@@ -515,7 +515,7 @@ static void console_find_owner(void)if ( d ) {rcu_unlock_domain (d); - console_rx = next_rx; + console_owner = next_rx;printk ("*** Serial input to DOM%u" , domid);break ; }
@@ -529,7 +529,7 @@ static void console_find_owner(void)static void __serial_rx (char c) { -switch ( console_rx ) +switch ( console_owner ) {case 0 :return handle_keypress (c, false);
@@ -552,7 +552,7 @@ static void __serial_rx(char c)#ifdef CONFIG_SBSA_VUART_CONSOLE default : { -struct domain *d =rcu_lock_domain_by_id (console_rx -1 ); +struct domain *d =rcu_lock_domain_by_id (console_owner -1 );/* * If we have a properly initialized vpl011 console for the
@@ -563,7 +563,7 @@ static void __serial_rx(char c)vpl011_rx_char_xen (d, c); else printk("Cannot send chars to Dom%d: no UART available\n", - console_rx - 1); + console_owner - 1);if ( d !=NULL )rcu_unlock_domain (d);
@@ -1116,7 +1116,7 @@ void __init console_endboot(void)* a useful 'how to switch' message. */ if ( opt_conswitch[1 ] =='x' ) - console_rx = max_console_rx; + console_owner = max_console_rx;register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 );
Signature · 1 line
2.34.1
Re: [PATCH v2 15/35] xen/console: rename console_rx to console_owner
Quoted 2 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Preparation for the follow on change to switch
console_ownertodomid_taddress space.
As with the earlier change - it's one thing to (plan to) change the number space, and another to go from input only to general console.
Jan
Re: [PATCH v2 15/35] xen/console: rename console_rx to console_owner
In reply to Denis MukhinQuoted 4 lines · On Thu, Dec 05, 2024 at 08:41:45PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Preparation for the follow on change to switch
console_ownertodomid_taddress space.
I'm a bit confused, is the plan to assign the console (so both RX and TX) exclusively to a domain?
Otherwise this would better be named console_input_target or similar, if you think console_rx is not clear enough (FWIW, I'm OK with the name given the current usage).
Thanks, Roger.
Re: [PATCH v2 15/35] xen/console: rename console_rx to console_owner
Quoted 4 lines · Roger Pau Monné
On Thu, Dec 05, 2024 at 08:41:45PM -0800, Denis Mukhin via B4 Relay wrote:
Quoted 8 lines
Quoted 4 lines
From: Denis Mukhin [email protected]
Preparation for the follow on change to switch
console_ownertodomid_taddress space.I'm a bit confused, is the plan to assign the console (so both RX and TX) exclusively to a domain?
The name change is because semantics of console_rx will be changed. It will be pointing to domain ID instead of an integer number mapped to domain ID.
I think "console owner" should be easier to follow.
Quoted 6 lines
Otherwise this would better be named
console_input_targetor similar, if you thinkconsole_rxis not clear enough (FWIW, I'm OK with the name given the current usage).Thanks, Roger.
PATCH v2 16/35 xen/console: introduce printk_common()
In reply to Denis MukhinIntroduce new printk() variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- xen/drivers/char/console.c | 8 ++++++++ xen/include/xen/lib.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +1 -1
@@ -522,7 +522,7 @@ safe." -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(^.*printf\\(.*\\)$)))"} -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(panic)&&kind(function))))"} -config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(elf_call_log_callback)&&kind(function))))"} --config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(vprintk_common)&&kind(function))))"} +-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(^v?printk_common)&&kind(function))))"} -config=MC3R1.R17.1,macros+={hide , "^va_(arg|start|copy|end)$"} -doc_end
xen/drivers/char/console.c +8 -0
@@ -968,6 +968,14 @@ void printk(const char *fmt, ...)va_end (args); } +void printk_common (const char *fmt, ...) +{ +va_list args; +va_start (args, fmt); +vprintk_common ("" , fmt, args); +va_end (args); +} +void guest_printk (const struct domain *d,const char *fmt, ...) {va_list args;
xen/include/xen/lib.h +3 -0
@@ -61,6 +61,9 @@ debugtrace_printk(const char *fmt, ...) {}extern void printk (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ), cold)); +extern void printk_common (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 ))); + #define printk_once(fmt, args...) \ ({ \ static bool __read_mostly once_; \
Signature · 1 line
2.34.1
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.
Imo it should still be guest_printk() which is then used from there.
xen/include/xen/lib.h debugtrace_printk(const char *fmt, ...) {} · line 65
Quoted 8 lines
xen/include/xen/lib.h +2
-0@@ -61,6 +61,9 @@ debugtrace_printk(const char *fmt, ...) {}extern void printk (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ), cold)); +extern void printk_common (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 )));
No "cold" attribute, compared to printk()?
Jan
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 10 lines · Jan Beulich
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.Imo it should still be
guest_printk()which is then used from there.
I ended up w/ printk_noprefix(): vprintk_common() expects user-defined prefix, while original printk_common() does not expect prefix. Such inconsistency may be confusing because both functions are named xxx_common().
Quoted 7 lines
Quoted 7 lines
xen/include/xen/lib.h +0
-0@@ -61,6 +61,9 @@ debugtrace_printk(const char *fmt, ...) {} extern void printk(const char *fmt, ...) attribute ((format (printf, 1, 2), cold));
Quoted 5 lines
xen/include/xen/lib.h debugtrace_printk(const char *fmt, ...) {} · line 65
Quoted 2 lines
xen/include/xen/lib.h +2
-0+extern void printk_common(const char *fmt, ...) + attribute ((format (printf, 1, 2)));No "cold" attribute, compared to
printk()?
Thanks, fixed.
Quoted 2 lines
Jan
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 8 lines · Denis Mukhin
Quoted 7 lines · Jan Beulich
Quoted 3 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.
Quoted 5 lines
Quoted 1 line
Imo it should still be
guest_printk()which is then used from there.I ended up w/
printk_noprefix():vprintk_common()expects user-defined prefix, while originalprintk_common()does not expect prefix. Such inconsistency may be confusing because both functions are namedxxx_common().
Your reply at best partly addresses my comment: I didn't suggest a new name for the new function, but I rather suggested that you use an existing one instead.
Jan
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
In reply to Denis MukhinQuoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.
IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
For the hardware domain we explicitly don't buffer writes to the console (see guest_console_write() hardware domain special handling).
I wonder however how you deal with domains that don't have the console focus (ie: != console_rx), as for those I think you still want to use the (d<domid>) prefix?
Thanks, Roger.
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 11 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
Quoted 6 lines
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?
Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
Jan
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).
Quoted 6 lines
Quoted 3 lines
I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
WE don't do that currently for the hardware domain, because we avoid doing any kind of line processing, as characters from the hardware domain are send straight to the console without waiting for the newline terminator (like we do for other domains).
Are you suggesting that in case of the console input being shared between multiple domains they should all be treated as plain domUs and thus lines should be buffered?
Thanks, Roger.
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 20 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 17 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?
Quoted 7 lines
Quoted 2 lines
Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
WE don't do that currently for the hardware domain, because we avoid doing any kind of line processing, as characters from the hardware domain are send straight to the console without waiting for the newline terminator (like we do for other domains).
Right, and that's kind of special, and aiui intentionally so. These are the only un-prefixed lines logged.
Quoted 3 lines
Are you suggesting that in case of the console input being shared between multiple domains they should all be treated as plain domUs and thus lines should be buffered?
No, I'm actually not suggesting anything here beyond perhaps reducing the scope of this series to just what the equivalent of vpl011 would be for the 8250 / 16550 case.
Jan
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 32 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 17 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?Quoted 7 lines
Quoted 2 lines
Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
WE don't do that currently for the hardware domain, because we avoid doing any kind of line processing, as characters from the hardware domain are send straight to the console without waiting for the newline terminator (like we do for other domains).
Right, and that's kind of special, and aiui intentionally so. These are the only un-prefixed lines logged.
Quoted 7 lines
Quoted 3 lines
Are you suggesting that in case of the console input being shared between multiple domains they should all be treated as plain domUs and thus lines should be buffered?
No, I'm actually not suggesting anything here beyond perhaps reducing the scope of this series to just what the equivalent of vpl011 would be for the 8250 / 16550 case.
Indeed, reducing the scope would make it easier to get the actual feature reviewed. There's a huge amount of pre-patching that will possibly take some time to get agreement on (if suitable).
Thanks, Roger.
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
In reply to Jan BeulichQuoted 24 lines · Jan Beulich
Quoted 23 lines · Roger Pau Monné
Quoted 21 lines · Jan Beulich
Quoted 11 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
Quoted 6 lines
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
Quoted 7 lines
Quoted 4 lines
WE don't do that currently for the hardware domain, because we avoid doing any kind of line processing, as characters from the hardware domain are send straight to the console without waiting for the newline terminator (like we do for other domains).
Right, and that's kind of special, and aiui intentionally so. These are the only un-prefixed lines logged.
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix
It is OK to change this behavior, but in that case I would ask that we change it consistently also for ARM.
Quoted 7 lines
Quoted 3 lines
Are you suggesting that in case of the console input being shared between multiple domains they should all be treated as plain domUs and thus lines should be buffered?
No, I'm actually not suggesting anything here beyond perhaps reducing the scope of this series to just what the equivalent of vpl011 would be for the 8250 / 16550 case.
I agree with this
Re: [PATCH v2 16/35] xen/console: introduce printk_common()
Quoted 41 lines · Stefano Stabellini
Quoted 28 lines · Jan Beulich
Quoted 26 lines · Roger Pau Monné
Quoted 23 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:46PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Introduce new
printk()variant for convenient printouts which skip '(XEN)' prefix on xen console. This is needed for the case when physical console is owned by a domain w/ in-hypervisor UART emulation enabled.IIRC the ns8250 can only send or receive one byte (character) at a time, so you should likely put that on the console as soon as it's received?
Quoted 6 lines
For the hardware domain we explicitly don't buffer writes to the console (see
guest_console_write()hardware domain special handling).I wonder however how you deal with domains that don't have the console focus (ie: !=
console_rx), as for those I think you still want to use the (d<domid>) prefix?Imo no matter what domain has the focus, the (d<domid>) prefix should always be logged. Just to avoid possible confusion.
Quoted 7 lines
Quoted 4 lines
WE don't do that currently for the hardware domain, because we avoid doing any kind of line processing, as characters from the hardware domain are send straight to the console without waiting for the newline terminator (like we do for other domains).
Right, and that's kind of special, and aiui intentionally so. These are the only un-prefixed lines logged.
Quoted 8 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefixIt is OK to change this behavior, but in that case I would ask that we change it consistently also for ARM.
Addressed in v3.
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Are you suggesting that in case of the console input being shared between multiple domains they should all be treated as plain domUs and thus lines should be buffered?
No, I'm actually not suggesting anything here beyond perhaps reducing the scope of this series to just what the equivalent of vpl011 would be for the 8250 / 16550 case.
I agree with this
PATCH v2 17/35 xen/console: introduce consoled_is_enabled()
In reply to Denis MukhinThere are few places which check pv_shim console under CONFIG_PV_SHIM in xen console driver. Instead of #ifdef-ing, use new consoled_is_enabled() to customize the logic.
Header file now can be included w/o CONFIG_X86.
Signature of consoled_guest_{rx,tx} has changed to account for follow-on console switch logic cleanup.
--- xen/drivers/char/console.c | 10 +++------- xen/drivers/char/consoled.c | 18 ++++++++++++++---- xen/include/xen/consoled.h | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 13 deletions(-)
xen/drivers/char/console.c +3 -7
@@ -33,9 +33,9 @@#include <xen/pv_console.h> #include <asm/setup.h> #include <xen/sections.h> +#include <xen/consoled.h> #ifdef CONFIG_X86 -#include <xen/consoled.h> #include <asm/guest.h> #endif #ifdef CONFIG_SBSA_VUART_CONSOLE
@@ -505,11 +505,9 @@ static void console_find_owner(void)break ; } -#ifdef CONFIG_PV_SHIM -if ( next_rx ==1 ) +if (consoled_is_enabled () && next_rx ==1 ) domid =get_initial_domain_id ();else -#endif domid = next_rx -1 ; d =rcu_lock_domain_by_id (domid);if ( d )
@@ -573,10 +571,8 @@ static void __serial_rx(char c)#endif } -#ifdef CONFIG_X86 -if ( pv_shim && pv_console ) +if (consoled_is_enabled () )consoled_guest_tx (c); -#endif } static void cf_check serial_rx(char c)
xen/drivers/char/consoled.c +14 -4
@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);
@@ -91,15 +91,17 @@ void consoled_guest_rx(void) out:spin_unlock (&rx_lock); + +return 0 ; }/* Sends a character into a domain's PV console */ -void consoled_guest_tx (char c) +int consoled_guest_tx (char c) {XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ; cons =ACCESS_ONCE (cons_ring->in_cons); prod = cons_ring->in_prod;
@@ -118,6 +120,7 @@ void consoled_guest_tx(char c) cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer */ smp_wmb ();ACCESS_ONCE (cons_ring->in_prod) = prod;
@@ -125,6 +128,13 @@ void consoled_guest_tx(char c) notify:/* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn (pv_console_evtchn ()); + +return 0 ; +} + +bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console; }/*
xen/include/xen/consoled.h +33 -2
@@ -3,10 +3,41 @@#include <public/io/console.h> +#if defined(CONFIG_PV_SHIM ) +void consoled_set_ring_addr (struct xencons_interface *ring);struct xencons_interface *consoled_get_ring_addr (void ); -void consoled_guest_rx (void ); -void consoled_guest_tx (char c); +int consoled_guest_rx (void ); +int consoled_guest_tx (char c); +bool consoled_is_enabled (void ); + +#else + +static inline void consoled_set_ring_addr (struct xencons_interface *ring) +{ +} + +static inline struct xencons_interface *consoled_get_ring_addr (void ) +{ +return NULL ; +} + +static inline int consoled_guest_rx (void ) +{ +return 0 ; +} + +static inline int consoled_guest_tx (char c) +{ +return 0 ; +} + +static inline bool consoled_is_enabled (void ) +{ +return false; +} + +#endif /* #if defined(CONFIG_PV_SHIM) */ #endif /* __XEN_CONSOLED_H__ */ /*
Signature · 1 line
2.34.1
Re: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled()
Quoted 39 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/consoled.c +6
-4@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);@@ -91,15 +91,17 @@ void consoled_guest_rx(void) out:spin_unlock (&rx_lock); + +return 0 ; }/* Sends a character into a domain's PV console */ -void consoled_guest_tx (char c) +int consoled_guest_tx (char c) {XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ; cons =ACCESS_ONCE (cons_ring->in_cons); prod = cons_ring->in_prod;
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 124
Quoted 5 lines
xen/drivers/char/consoled.c +1
-0@@ -118,6 +120,7 @@ void consoled_guest_tx(char c) cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer */
No excess blank lines please.
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 133
Quoted 7 lines
xen/drivers/char/consoled.c +3
-0@@ -125,6 +128,13 @@ void consoled_guest_tx(char c) notify:/* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn (pv_console_evtchn ()); + +return 0 ; +}
For both of the functions - what use is it to make the functions return a value, when all they'd ever return is zero (and callers don't care)? I'm also having a hard time seeing how this adjustment is related to ...
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 138
Quoted 4 lines
xen/drivers/char/consoled.c +3
-0+bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console; }
... the introduction of this function (which by itself is probably fine).
Jan
Re: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled()
Quoted 44 lines · Jan Beulich
Quoted 40 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/consoled.c +2
-2@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);@@ -91,15 +91,17 @@ void consoled_guest_rx(void)out:
spin_unlock(&rx_lock);
+
+ return 0;
}/* Sends a character into a domain's PV console */
xen/drivers/char/consoled.c +1
-1-void consoled_guest_tx (char c) +int consoled_guest_tx (char c){
XENCONS_RING_IDXcons, prod;if ( !cons_ring )
- return;
+ return 0;cons =
ACCESS_ONCE(cons_ring->in_cons);
prod =cons_ring->in_prod;xen/drivers/char/consoled.c +0
-0@@ -118,6 +120,7 @@ void consoled_guest_tx(char c)
Quoted 7 lines
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 124
Quoted 4 lines
xen/drivers/char/consoled.c +1
-0cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer */ No excess blank lines please.
Fixed.
Quoted 12 lines
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 133
Quoted 8 lines
xen/drivers/char/consoled.c +0
-0@@ -125,6 +128,13 @@ void consoled_guest_tx(char c)notify:
/* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn());xen/drivers/char/consoled.c +3
-0+ +return 0 ; +}For both of the functions - what use is it to make the functions return a value, when all they'd ever return is zero (and callers don't care)?
Fixed.
Quoted 9 lines
I'm also having a hard time seeing how this adjustment is related to ...
Quoted 4 lines
xen/drivers/char/consoled.c +3
-0+bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console;}
... the introduction of this function (which by itself is probably fine).
That will be a cleanup in console driver on the code path I touched wrt console focus switch.
Quoted 2 lines
Jan
Re: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled()
Quoted 81 lines · Denis Mukhin
Quoted 44 lines · Jan Beulich
Quoted 40 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/consoled.c +2
-2@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);@@ -91,15 +91,17 @@ void consoled_guest_rx(void)out:
spin_unlock(&rx_lock);
+
+ return 0;
}/* Sends a character into a domain's PV console */
xen/drivers/char/consoled.c +1
-1-void consoled_guest_tx (char c) +int consoled_guest_tx (char c){
XENCONS_RING_IDXcons, prod;if ( !cons_ring )
- return;
+ return 0;cons =
ACCESS_ONCE(cons_ring->in_cons);
prod =cons_ring->in_prod;xen/drivers/char/consoled.c +0
-0@@ -118,6 +120,7 @@ void consoled_guest_tx(char c)Quoted 7 lines
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 124
Quoted 4 lines
xen/drivers/char/consoled.c +1
-0cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer */ No excess blank lines please.
Fixed.
Quoted 12 lines
xen/drivers/char/consoled.c void consoled_guest_tx(char c) · line 133
Quoted 8 lines
xen/drivers/char/consoled.c +0
-0@@ -125,6 +128,13 @@ void consoled_guest_tx(char c)notify:
/* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn());xen/drivers/char/consoled.c +3
-0+ +return 0 ; +}For both of the functions - what use is it to make the functions return a value, when all they'd ever return is zero (and callers don't care)?
Fixed.
Quoted 9 lines
I'm also having a hard time seeing how this adjustment is related to ...
Quoted 4 lines
xen/drivers/char/consoled.c +3
-0+bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console;}
... the introduction of this function (which by itself is probably fine).
Quoted 2 lines
That will be a cleanup in console driver on the code path I touched wrt console focus switch.
Yet then please don't mix entirely independent things in a single patch.
Jan
Re: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled()
In reply to Denis MukhinQuoted 143 lines · On Thu, Dec 05, 2024 at 08:41:47PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
There are few places which check
pv_shimconsole underCONFIG_PV_SHIMin xen console driver. Instead of #ifdef-ing, use newconsoled_is_enabled()to customize the logic.Header file now can be included w/o
CONFIG_X86.Signature of consoled_guest_{rx,tx} has changed to account for follow-on console switch logic cleanup.
Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 10 +++------- xen/drivers/char/consoled.c | 18 ++++++++++++++---- xen/include/xen/consoled.h | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 13 deletions(-)xen/drivers/char/console.c +3
-7@@ -33,9 +33,9 @@#include <xen/pv_console.h> #include <asm/setup.h> #include <xen/sections.h> +#include <xen/consoled.h> #ifdef CONFIG_X86 -#include <xen/consoled.h> #include <asm/guest.h> #endif #ifdef CONFIG_SBSA_VUART_CONSOLE @@ -505,11 +505,9 @@ static void console_find_owner(void)break ; } -#ifdef CONFIG_PV_SHIM -if ( next_rx ==1 ) +if (consoled_is_enabled () && next_rx ==1 ) domid =get_initial_domain_id ();else -#endif domid = next_rx -1 ; d =rcu_lock_domain_by_id (domid);if ( d )@@ -573,10 +571,8 @@ static void __serial_rx(char c)#endif } -#ifdef CONFIG_X86 -if ( pv_shim && pv_console ) +if (consoled_is_enabled () )consoled_guest_tx (c); -#endif } static void cf_check serial_rx(char c)xen/drivers/char/consoled.c +14
-4@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);@@ -91,15 +91,17 @@ void consoled_guest_rx(void) out:spin_unlock (&rx_lock); + +return 0 ; }/* Sends a character into a domain's PV console */ -void consoled_guest_tx (char c) +int consoled_guest_tx (char c) {XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ; cons =ACCESS_ONCE (cons_ring->in_cons); prod = cons_ring->in_prod;@@ -118,6 +120,7 @@ void consoled_guest_tx(char c) cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer */ smp_wmb ();ACCESS_ONCE (cons_ring->in_prod) = prod;@@ -125,6 +128,13 @@ void consoled_guest_tx(char c) notify:/* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn (pv_console_evtchn ()); + +return 0 ; +} + +bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console; }/* xen/include/xen/consoled.h +11
-2@@ -3,10 +3,41 @@#include <public/io/console.h> +#if defined(CONFIG_PV_SHIM ) +void consoled_set_ring_addr (struct xencons_interface *ring);struct xencons_interface *consoled_get_ring_addr (void ); -void consoled_guest_rx (void ); -void consoled_guest_tx (char c); +int consoled_guest_rx (void ); +int consoled_guest_tx (char c); +bool consoled_is_enabled (void ); + +#else + +static inline void consoled_set_ring_addr (struct xencons_interface *ring) +{ +}
xen/include/xen/consoled.h line 28
Quoted 10 lines
xen/include/xen/consoled.h +10
-0+ +static inline struct xencons_interface *consoled_get_ring_addr (void ) +{ +return NULL ; +} + +static inline int consoled_guest_rx (void ) +{ +return 0 ; +}
You don't need to provide dummy implementations of consoled_{set,get}_ring_addr() and consoled_guest_rx(), they are only called from code that's build when CONFIG_PV_SHIM is selected.
xen/include/xen/consoled.h line 32
Quoted 3 lines
xen/include/xen/consoled.h +3
-0+static inline int consoled_guest_tx (char c) +{ +return 0 ;
For consoled_guest_tx() you want to add an ASSERT_UNREACHABLE(), as it should never be called if !CONFIG_PV_SHIM?
Thanks, Roger.
Re: [PATCH v2 17/35] xen/console: introduce consoled_is_enabled()
Quoted 154 lines · Roger Pau Monné
Quoted 150 lines · On Thu, Dec 05, 2024 at 08:41:47PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
There are few places which check
pv_shimconsole underCONFIG_PV_SHIMin xen console driver. Instead of #ifdef-ing, use newconsoled_is_enabled()to customize the logic.Header file now can be included w/o
CONFIG_X86.Signature of consoled_guest_{rx,tx} has changed to account for follow-on console switch logic cleanup.
Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 10 +++-------xen/drivers/char/consoled.c| 18 ++++++++++++++----xen/include/xen/consoled.h| 35 +++++++++++++++++++++++++++++++++--3 files changed, 50 insertions(+), 13 deletions(-)xen/drivers/char/console.c +2
-3@@ -33,9 +33,9 @@#include <xen/pv_console.h> #include <asm/setup.h> #include <xen/sections.h> +#include <xen/consoled.h> #ifdef CONFIG_X86 -#include <xen/consoled.h> #include <asm/guest.h> #endif #ifdef CONFIG_SBSA_VUART_CONSOLE @@ -505,11 +505,9 @@ static void console_find_owner(void)break ; } -#ifdef CONFIG_PV_SHIM -if ( next_rx ==1 ) +if (consoled_is_enabled () && next_rx ==1 ) domid =get_initial_domain_id ();else
-#endif
domid =next_rx- 1;
d =rcu_lock_domain_by_id(domid);
if ( d )xen/drivers/char/console.c +1
-3@@ -573,10 +571,8 @@ static void __serial_rx(char c)#endif } -#ifdef CONFIG_X86 -if ( pv_shim && pv_console ) +if (consoled_is_enabled () )consoled_guest_tx (c); -#endif } static void cf_check serial_rx(char c)xen/drivers/char/consoled.c +2
-2@@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void)static char buf[BUF_SZ +1 ];/* Receives characters from a domain's PV console */ -void consoled_guest_rx (void ) +int consoled_guest_rx (void ) {size_t idx =0 ;XENCONS_RING_IDX cons, prod;if ( !cons_ring ) -return ; +return 0 ;spin_lock (&rx_lock);@@ -91,15 +91,17 @@ void consoled_guest_rx(void)out:
spin_unlock(&rx_lock);
+
+ return 0;
}/* Sends a character into a domain's PV console */
xen/drivers/char/consoled.c +1
-1-void consoled_guest_tx (char c) +int consoled_guest_tx (char c){
XENCONS_RING_IDXcons, prod;if ( !cons_ring )
- return;
+ return 0;cons =
ACCESS_ONCE(cons_ring->in_cons);
prod =cons_ring->in_prod;xen/drivers/char/consoled.c +1
-0@@ -118,6 +120,7 @@ void consoled_guest_tx(char c) cons_ring->in[MASK_XENCONS_IDX (prod++, cons_ring->in)] = c; +/* Write to the ring before updating the pointer / smp_wmb(); ACCESS_ONCE(cons_ring->in_prod) = prod; @@ -125,6 +128,13 @@ void consoled_guest_tx(char c)notify:
/ Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn());xen/drivers/char/consoled.c +7
-0+ +return 0 ; +} + +bool consoled_is_enabled (void ) +{ +return pv_shim && pv_console;}
/*
xen/include/xen/consoled.h +18
-2@@ -3,10 +3,41 @@#include <public/io/console.h> +#if defined(CONFIG_PV_SHIM ) +void consoled_set_ring_addr (struct xencons_interface *ring);struct xencons_interface *consoled_get_ring_addr (void ); -void consoled_guest_rx (void ); -void consoled_guest_tx (char c); +int consoled_guest_rx (void ); +int consoled_guest_tx (char c); +bool consoled_is_enabled (void ); + +#else + +static inline void consoled_set_ring_addr (struct xencons_interface *ring) +{ +} + +static inline struct xencons_interface *consoled_get_ring_addr (void ) +{ +return NULL ; +} + +static inline int consoled_guest_rx (void )
Quoted 8 lines
xen/include/xen/consoled.h line 28
Quoted 3 lines
xen/include/xen/consoled.h +3
-0+{ +return 0 ; +}You don't need to provide dummy implementations of consoled_{set,get}_ring_addr() and
consoled_guest_rx(), they are only called from code that's build whenCONFIG_PV_SHIMis selected.
Thanks; fixed.
Quoted 8 lines
xen/include/xen/consoled.h line 32
Quoted 4 lines
xen/include/xen/consoled.h +3
-0+static inline int consoled_guest_tx (char c) +{ +return 0 ;For
consoled_guest_tx()you want to add anASSERT_UNREACHABLE(), as it should never be called if !CONFIG_PV_SHIM?
Fixed.
Quoted 2 lines
Thanks, Roger.
PATCH v2 18/35 xen/console: introduce use of 'is_console' flag
In reply to Denis MukhinThe code now inspects d->is_console flag to decide whether the console focus should move to the domain w/ console after administrator presses <Ctrl+aaa>.
Console owner domain switch logic updated accordingly.
--- xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain.c | 1 + xen/arch/arm/domctl.c | 1 + xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 14 ++++++++++---- 6 files changed, 17 insertions(+), 5 deletions(-)
xen/arch/arm/dom0less-build.c +1 -1
@@ -833,6 +833,7 @@ static int __init construct_domU(struct domain *d,return rc; d->arch.emulation_flags |=ARM_EMU_VUART ; + d->is_console = true; } rc =prepare_dtb_domU (d, &kinfo);
@@ -1015,7 +1016,6 @@ void __init create_domUs(void)panic ("Error creating domain %s (rc = %ld)\n" ,dt_node_name (node),PTR_ERR (d)); - d->is_console = true;dt_device_set_used_by (node, d->domain_id); rc =construct_domU (d, node);
xen/arch/arm/domain.c +1 -0
@@ -781,6 +781,7 @@ int arch_domain_create(struct domain *d, goto fail; d->arch.emulation_flags |=ARM_EMU_VUART ; + d->is_console = true; }if ( (rc =domain_vpci_init (d)) !=0 )
xen/arch/arm/domctl.c +1 -0
@@ -46,6 +46,7 @@ static int handle_vuart_init(struct domain *d, { vuart_op->evtchn = info.evtchn; d->arch.emulation_flags |=ARM_EMU_VUART ; + d->is_console = true; }return rc;
xen/arch/x86/pv/shim.c +2 -0
@@ -238,6 +238,8 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,* guest from depleting the shim memory pool. */ d->max_pages =domain_tot_pages (d); + + d->is_console = true; }static void write_start_info (struct domain *d)
xen/common/domain.c +2 -0
@@ -682,6 +682,8 @@ struct domain *domain_create(domid_t domid, old_hwdom = hardware_domain; hardware_domain = d; + + d->is_console = true; }TRACE_TIME (TRC_DOM0_DOM_ADD , d->domain_id);
xen/drivers/char/console.c +10 -4
@@ -1,8 +1,8 @@/****************************************************************************** * console.c -* +* * Emergency console I/O for Xen and the domain-0 guest OS. -* +* * Copyright (c) 2002-2004, K A Fraser. * * Added printf_ratelimit
@@ -509,14 +509,20 @@ static void console_find_owner(void) domid =get_initial_domain_id (); else domid = next_rx -1 ; + d =rcu_lock_domain_by_id (domid); -if ( d ) +if ( d ==NULL ) +continue ; + +if ( d->is_console ) {rcu_unlock_domain (d); console_owner = next_rx;printk ("*** Serial input to DOM%u" , domid);break ; } + +rcu_unlock_domain (d); }if ( switch_code )
@@ -814,7 +820,7 @@ static int printk_prefix_check(char *p, char **pp)return ((atomic_read (&print_everything) !=0 ) || (loglvl < lower_thresh) || ((loglvl < upper_thresh) &&printk_ratelimit ())); -} +} static int cf_check parse_console_timestamps(const char *s) {
Signature · 1 line
2.34.1
Re: [PATCH v2 18/35] xen/console: introduce use of 'is_console' flag
Quoted 8 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
The code now inspects
d->is_consoleflag to decide whether the console focus should move to the domain w/ console after administrator presses <Ctrl+aaa>.Console owner domain switch logic updated accordingly.
Signed-off-by Denis Mukhin <[email protected]>
Just as a remark, as it's a pre-existing problem: I'm unconvinced that "is_console" is a good name here.
xen/drivers/char/console.c static void console_find_owner(void) · line 514
Quoted 8 lines
xen/drivers/char/console.c +2
-1@@ -509,14 +509,20 @@ static void console_find_owner(void) domid =get_initial_domain_id (); else domid = next_rx -1 ; + d =rcu_lock_domain_by_id (domid); -if ( d ) +if ( d ==NULL )
Seeing the original code, the more "natural" transformation would be to !d (as we use elsewhere as well, to keep code short).
Jan
Re: [PATCH v2 18/35] xen/console: introduce use of 'is_console' flag
Quoted 9 lines · Jan Beulich
Quoted 5 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
The code now inspects
d->is_consoleflag to decide whether the console focus should move to the domain w/ console after administrator presses <Ctrl+aaa>.
Quoted 7 lines
Quoted 3 lines
Console owner domain switch logic updated accordingly.
Signed-off-by Denis Mukhin [email protected]Just as a remark, as it's a pre-existing problem: I'm unconvinced that "
is_console" is a good name here.
I think it should be called something like console_perm. I kept name as is for now, but I can make a change.
Quoted 13 lines
Quoted 9 lines
xen/drivers/char/console.c +0
-0@@ -509,14 +509,20 @@ static void console_find_owner(void) domid =get_initial_domain_id ();else
domid =next_rx- 1;
+
d =rcu_lock_domain_by_id(domid);
- if ( d )
+ if ( d == NULL )Seeing the original code, the more "natural" transformation would be to !d (as we use elsewhere as well, to keep code short).
Fixed.
Quoted 2 lines
Jan
PATCH v2 19/35 xen/console: introduce console_set_owner()
In reply to Denis Mukhinconsole_set_owner() is introduced for setting the new console owner.
Switches console owner to domain ID vs range of integer numbers mapped to domain IDs.
This a public API to console driver, will be used in the follow on code change.
--- xen/drivers/char/console.c | 122 ++++++++++++++++++++++++++------------------- xen/include/xen/console.h | 1 + 2 files changed, 71 insertions(+), 52 deletions(-)
xen/drivers/char/console.c +70 -52
@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. */ #define switch_code (opt_conswitch[0]-'a'+1) +/* -* console_owner=0 => input to xen -* console_owner=1 => input to dom0 (or the sole shim domain) -* console_owner=N => input to dom(N-1) +* Current console owner domain ID: either Xen or domain w/ d->is_console == +* true. +* +* Initialized in console_endboot(). */ -static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner; -#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); + +if ( d ==NULL ) +return NULL ; + +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ struct domain *rcu_lock_domain_console_owner (void ) { -if ( console_owner ==0 ) -return NULL ; -return rcu_lock_domain_by_id (console_owner -1 ); +return rcu_lock_domain_console_by_id (console_owner); } -#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid) { -unsigned int next_rx = console_owner; - -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -*/ -for ( ; ; ) - { -domid_t domid; -struct domain *d; - -if ( next_rx++ >= max_console_rx ) - { - console_owner =0 ; -printk ("*** Serial input to Xen" ); -break ; - } - -if (consoled_is_enabled () && next_rx ==1 ) - domid =get_initial_domain_id (); -else - domid = next_rx -1 ; - - d =rcu_lock_domain_by_id (domid); -if ( d ==NULL ) -continue ; - -if ( d->is_console ) - { -rcu_unlock_domain (d); - console_owner = next_rx; -printk ("*** Serial input to DOM%u" , domid); -break ; - } +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )rcu_unlock_domain (d); - } + +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if ( switch_code )printk (" (type 'CTRL-%c' three times to switch input)" , opt_conswitch[0 ]);printk ("\n" ); + +return 0 ; +} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ; + +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_owner (i) ) +break ; +if ( i == n ) +console_set_owner (DOMID_XEN ); }static void __serial_rx (char c) {switch ( console_owner ) { -case 0 : +case DOMID_XEN :return handle_keypress (c, false); -case 1 : +case 0 :/* * Deliver input to the hardware domain buffer, unless it is * already full.
@@ -556,7 +574,7 @@ static void __serial_rx(char c)#ifdef CONFIG_SBSA_VUART_CONSOLE default : { -struct domain *d =rcu_lock_domain_by_id (console_owner -1 ); +struct domain *d =rcu_lock_domain_by_id (console_owner);/* * If we have a properly initialized vpl011 console for the
@@ -567,7 +585,7 @@ static void __serial_rx(char c)vpl011_rx_char_xen (d, c); else printk("Cannot send chars to Dom%d: no UART available\n", - console_owner - 1); + console_owner);if ( d !=NULL )rcu_unlock_domain (d);
@@ -1126,7 +1144,7 @@ void __init console_endboot(void)* a useful 'how to switch' message. */ if ( opt_conswitch[1 ] =='x' ) - console_owner = max_console_rx; + console_owner =DOMID_XEN ;register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 );
xen/include/xen/console.h +1 -0
@@ -32,6 +32,7 @@ void console_start_log_everything(void);void console_end_log_everything (void );struct domain *rcu_lock_domain_console_owner (void ); +int console_set_owner (domid_t );/* * Steal output from the console. Returns +ve identifier, else -ve error.
Signature · 1 line
2.34.1
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +0
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot.
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 472
Quoted 10 lines
xen/drivers/char/console.c +4
-3+* and the DomUs. */ #define switch_code (opt_conswitch[0]-'a'+1) +/* -* console_owner=0 => input to xen -* console_owner=1 => input to dom0 (or the sole shim domain) -* console_owner=N => input to dom(N-1) +* Current console owner domain ID: either Xen or domain w/ d->is_console == +* true.
The switching of number space may better have been a separate patch. Albeit maybe I'm just not seeing why it wants combining with the introduction of console_set_owner().
Actually, is this switching actually complete? What about late hwdom, which has a non-zero domain ID?
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 478
Quoted 7 lines
xen/drivers/char/console.c +3
-2+* Initialized in console_endboot(). */ -static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner; -#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid)
I think "domain" and "console" want switching in the name, as it's a domain you're locking, not a console.
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 512
Quoted 1 line
xen/drivers/char/console.c +1
-0+int console_set_owner (domid_t domid)
static? Iirc Misra doesn't like non-static functions which aren't called from any other CU.
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 18 lines · Jan Beulich
Quoted 14 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +1
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)
+
/
- * console_owner=0 => input to xen
- * console_owner=1 => input to dom0 (or the sole shim domain)
Quoted 8 lines
Quoted 3 lines
- * console_owner=N => input to dom(N-1)
+ * Current console owner domain ID: either Xen or domain w/d->is_console==
+ * true.The switching of number space may better have been a separate patch. Albeit maybe I'm just not seeing why it wants combining with the introduction of
console_set_owner().
This is the part I tried in different variations and finally ended up w/ plumbing new console owner IDs "address space"
here: console_set_owner() takes domid_t and I decided against intermediate patch, since it is not a big (in term of lines of code) change.
Quoted 3 lines
Actually, is this switching actually complete? What about late hwdom, which has a non-zero domain ID?
I did reworks for max_init_domid in v3, I believe it should address late hwdom scenario.
Quoted 6 lines
Quoted 6 lines
+ * Initialized in
console_endboot().
*/xen/drivers/char/console.c +1
-1-static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;
Quoted 6 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 478
Quoted 2 lines
xen/drivers/char/console.c +1
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid)I think "domain" and "console" want switching in the name, as it's a domain you're locking, not a console.
Renamed to "console_get_domain_by_id".
Quoted 6 lines
Quoted 2 lines
+int
console_set_owner(domid_t domid)static? Iirc Misra doesn't like non-static functions which aren't called from any other CU.
Yes, but there's a follow on patch which will undo static - hwdom_crashconsole= patch - to drop the user to xen console once dom0 has crashed.
So since there's a need in globally visible symbol, I decided to get rid of static right away.
Quoted 2 lines
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 5 lines · Denis Mukhin
Quoted 4 lines · Jan Beulich
Quoted 1 line · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
+int
console_set_owner(domid_t domid)
Quoted 7 lines
Quoted 2 lines
static? Iirc Misra doesn't like non-static functions which aren't called from any other CU.
Yes, but there's a follow on patch which will undo static - hwdom_crashconsole= patch - to drop the user to xen console once dom0 has crashed.
So since there's a need in globally visible symbol, I decided to get rid of static right away.
Yet you realize that any series may go in piecemeal, and therefore no Misra rule may be violated at any patch boundary?
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
In reply to Denis MukhinQuoted 29 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_set_owner()is introduced for setting the new console owner.Switches console owner to domain ID vs range of integer numbers mapped to domain IDs.
This a public API to console driver, will be used in the follow on code change.
Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 122 ++++++++++++++++++++++++++------------------- xen/include/xen/console.h | 1 + 2 files changed, 71 insertions(+), 52 deletions(-)xen/drivers/char/console.c +2
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. */ #define switch_code (opt_conswitch[0]-'a'+1) +/*
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 476
Quoted 10 lines
xen/drivers/char/console.c +5
-4-* console_owner=0 => input to xen -* console_owner=1 => input to dom0 (or the sole shim domain) -* console_owner=N => input to dom(N-1) +* Current console owner domain ID: either Xen or domain w/ d->is_console == +* true. +* +* Initialized in console_endboot(). */ -static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;
Should this be initialized to DOMID_XEN? I assume it doesn't make much difference because the variable is not checked before console_endboot() anyway, but it might be safer to initialize to a value that assigns the console to Xen.
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 8 lines
xen/drivers/char/console.c +6
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +
Nit: I would remove this newline.
Quoted 86 lines
xen/drivers/char/console.c +31
-41+if ( d ==NULL ) +return NULL ; + +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to rcu_unlock_domain after use */ struct domain *rcu_lock_domain_console_owner (void ) { -if ( console_owner ==0 ) -return NULL ; -return rcu_lock_domain_by_id (console_owner -1 ); +return rcu_lock_domain_console_by_id (console_owner); } -#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid) { -unsigned int next_rx = console_owner; - -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -*/ -for ( ; ; ) - { -domid_t domid; -struct domain *d; - -if ( next_rx++ >= max_console_rx ) - { - console_owner =0 ; -printk ("*** Serial input to Xen" ); -break ; - } - -if (consoled_is_enabled () && next_rx ==1 ) - domid =get_initial_domain_id (); -else - domid = next_rx -1 ; - - d =rcu_lock_domain_by_id (domid); -if ( d ==NULL ) -continue ; - -if ( d->is_console ) - { -rcu_unlock_domain (d); - console_owner = next_rx; -printk ("*** Serial input to DOM%u" , domid); -break ; - } +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )rcu_unlock_domain (d); - } + +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if ( switch_code )printk (" (type 'CTRL-%c' three times to switch input)" , opt_conswitch[0 ]);printk ("\n" ); + +return 0 ;
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 538
Quoted 10 lines
xen/drivers/char/console.c +10
-0+} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ;
n can be made const, I would even rename to nr for clarity, but that's personal taste.
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 547
Quoted 9 lines
xen/drivers/char/console.c +9
-0+ +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_owner (i) ) +break ;
Hm, that could be a non-trivial amount of iteration if max_init_domid is bumped for every domain created as you have it in patch 11/35 (albeit I'm not sure that was intended?)
Quoted 4 lines
xen/drivers/char/console.c +2
-0+if ( i == n ) +console_set_owner (DOMID_XEN ); }
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 559
Quoted 10 lines
xen/drivers/char/console.c +2
-2static void __serial_rx (char c) {switch ( console_owner ) { -case 0 : +case DOMID_XEN :return handle_keypress (c, false); -case 1 : +case 0 :
If console_owner now strictly contains a domid you cannot assume that domid 0 is the hardware domain, you will need to handle this differently and check whether the domain pointed by console_owner passes the is_hardware_domain() check.
Quoted 22 lines
xen/drivers/char/console.c +2
-2/* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -556,7 +574,7 @@ static void __serial_rx(char c)#ifdef CONFIG_SBSA_VUART_CONSOLE default : { -struct domain *d =rcu_lock_domain_by_id (console_owner -1 ); +struct domain *d =rcu_lock_domain_by_id (console_owner);/* * If we have a properly initialized vpl011 console for the @@ -567,7 +585,7 @@ static void __serial_rx(char c)vpl011_rx_char_xen (d, c); else printk("Cannot send chars to Dom%d: no UART available\n", - console_owner - 1); + console_owner);if ( d !=NULL )rcu_unlock_domain (d);
xen/drivers/char/console.c void __init console_endboot(void) · line 1147
Quoted 5 lines
xen/drivers/char/console.c +1
-1@@ -1126,7 +1144,7 @@ void __init console_endboot(void)* a useful 'how to switch' message. */ if ( opt_conswitch[1 ] =='x' ) - console_owner = max_console_rx; + console_owner =DOMID_XEN ;
Hm, are you sure this still works as expected? Setting console_owner == DOMID_XEN will cause the call to switch_serial_input() below to switch the console back to the first domain in the system. Also initializing console_owner to 0 by default would also cause the call to switch_serial_input() to possibly switch it to the first domain after domid 0 (or back to Xen).
Thanks, Roger.
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 9 lines · Roger Pau Monné
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 6 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +6
-0+static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Or even better make the function call the variable's initializer.
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 6 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +6
-0+static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Quoted 1 line
Or even better make the function call the variable's initializer.
Indeed, didn't catch that one.
Thanks, Roger.
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
In reply to Jan BeulichQuoted 16 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monné
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 6 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +6
-0+static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Quoted 1 line
Or even better make the function call the variable's initializer.
Fixed.
Quoted 2 lines
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
In reply to Roger Pau MonnéQuoted 41 lines · Roger Pau Monné
Quoted 37 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_set_owner()is introduced for setting the new console owner.Switches console owner to domain ID vs range of integer numbers mapped to domain IDs.
This a public API to console driver, will be used in the follow on code change.
Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 122 ++++++++++++++++++++++++++-------------------xen/include/xen/console.h| 1 +2 files changed, 71 insertions(+), 52 deletions(-)xen/drivers/char/console.c +1
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)
+
/
- * console_owner=0 => input to xen
- * console_owner=1 => input to dom0 (or the sole shim domain)
- * console_owner=N => input to dom(N-1)
+ * Current console owner domain ID: either Xen or domain w/d->is_console==
+ * true.
+ *
+ * Initialized inconsole_endboot().
*/
Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 476
Quoted 2 lines
xen/drivers/char/console.c +1
-1-static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;Should this be initialized to
DOMID_XEN? I assume it doesn't make much difference because the variable is not checked beforeconsole_endboot()anyway, but it might be safer to initialize to a value that assigns the console to Xen.
Fixed.
Quoted 11 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 8 lines
xen/drivers/char/console.c +6
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Fixed.
Quoted 93 lines
Quoted 93 lines
+ if ( d == NULL )
+ return NULL;xen/drivers/char/console.c +8
-1+ +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to
rcu_unlock_domainafter use */ struct domain*rcu_lock_domain_console_owner(void){
- if (console_owner== 0 )
- return NULL;
- returnrcu_lock_domain_by_id(console_owner - 1);
+ returnrcu_lock_domain_console_by_id(console_owner); }xen/drivers/char/console.c +1
-2-#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid){
- unsigned intnext_rx=console_owner;xen/drivers/char/console.c +3
-33- -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -/ -for ( ; ; ) -{ -domid_t domid; -struct domain d; - -if ( next_rx++ >= max_console_rx ) -{ -console_owner = 0; -printk("* Serial input to Xen"); -break; -} - -if ( consoled_is_enabled() && next_rx == 1 ) -domid = get_initial_domain_id(); -else -domid = next_rx - 1; - -d = rcu_lock_domain_by_id(domid); -if ( d == NULL ) -continue; - -if ( d->is_console ) -{ -rcu_unlock_domain(d); -console_owner = next_rx; -printk("*** Serial input to DOM%u", domid); -break; -} +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )
rcu_unlock_domain(d);
- }xen/drivers/char/console.c +14
-0+ +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if (
switch_code)printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]);printk("\n");xen/drivers/char/console.c +8
-0+ +return 0 ; +} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains.
Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 538
Quoted 4 lines
+ */
xen/drivers/char/console.c +3
-0+static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ;n can be made const, I would even rename to nr for clarity, but that's personal taste.
max_init_domid can change at run-time actually (e.g. after xl create). I kept n as is.
Quoted 15 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 547
Quoted 10 lines
xen/drivers/char/console.c +9
-0+ +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_owner (i) ) +break ;Hm, that could be a non-trivial amount of iteration if
max_init_domidis bumped for every domain created as you have it in patch 11/35 (albeit I'm not sure that was intended?)
Yes, max_init_domid is advanced on each domain creation (v3).
Quoted 13 lines
Quoted 13 lines
+ if ( i == n )
+console_set_owner(DOMID_XEN);
}static void
__serial_rx(char c)
{
switch (console_owner)
{
- case 0:
+ caseDOMID_XEN:
returnhandle_keypress(c, false);
Quoted 8 lines
Quoted 2 lines
- case 1:
+ case 0:If
console_ownernow strictly contains a domid you cannot assume that domid 0 is the hardware domain, you will need to handle this differently and check whether the domain pointed byconsole_ownerpasses theis_hardware_domain()check.
Fixed.
Quoted 20 lines
Quoted 20 lines
/*
* Deliver input to the hardware domain buffer, unless it is
* already full.xen/drivers/char/console.c +0
-0@@ -556,7 +574,7 @@ static void __serial_rx(char c)#ifdef CONFIG_SBSA_VUART_CONSOLE default:
{
- struct domain *d =rcu_lock_domain_by_id(console_owner - 1);
+ struct domain *d =rcu_lock_domain_by_id(console_owner);/*
* If we have a properly initialized vpl011 console for thexen/drivers/char/console.c +0
-0@@ -567,7 +585,7 @@ static void __serial_rx(char c)vpl011_rx_char_xen (d, c);else
printk("Cannot send chars to Dom%d: no UART available\n",
-console_owner- 1);
+console_owner);
Quoted 16 lines
xen/drivers/char/console.c void __init console_endboot(void) · line 1147
Quoted 8 lines
if ( d != NULL )
rcu_unlock_domain(d);xen/drivers/char/console.c +1
-1@@ -1126,7 +1144,7 @@ void __init console_endboot(void)* a useful 'how to switch' message. */ if ( opt_conswitch[1 ] =='x' ) - console_owner = max_console_rx; + console_owner =DOMID_XEN ;Hm, are you sure this still works as expected? Setting
console_owner==DOMID_XENwill cause the call toswitch_serial_input()below to switch the console back to the first domain in the system. Also initializingconsole_ownerto 0 by default would also cause the call toswitch_serial_input()to possibly switch it to the first domain after domid 0 (or back to Xen).
TBH, I did not test w/ conswitch=x originally, but after addressing your other feedback that is now fixed.
Thank you.
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 149 lines · Denis Mukhin
Quoted 21 lines · Roger Pau Monné
Quoted 20 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +1
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)
+
/
- * console_owner=0 => input to xen
- * console_owner=1 => input to dom0 (or the sole shim domain)
- * console_owner=N => input to dom(N-1)
+ * Current console owner domain ID: either Xen or domain w/d->is_console==
+ * true.
+ *
+ * Initialized inconsole_endboot().
*/Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 476
Quoted 2 lines
xen/drivers/char/console.c +1
-1-static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;Should this be initialized to
DOMID_XEN? I assume it doesn't make much difference because the variable is not checked beforeconsole_endboot()anyway, but it might be safer to initialize to a value that assigns the console to Xen.Fixed.
Quoted 11 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 8 lines
xen/drivers/char/console.c +6
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Fixed.
Quoted 93 lines
Quoted 93 lines
+ if ( d == NULL )
+ return NULL;xen/drivers/char/console.c +8
-1+ +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to
rcu_unlock_domainafter use */ struct domain*rcu_lock_domain_console_owner(void){
- if (console_owner== 0 )
- return NULL;
- returnrcu_lock_domain_by_id(console_owner - 1);
+ returnrcu_lock_domain_console_by_id(console_owner); }xen/drivers/char/console.c +1
-2-#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid){
- unsigned intnext_rx=console_owner;xen/drivers/char/console.c +3
-33- -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -/ -for ( ; ; ) -{ -domid_t domid; -struct domain d; - -if ( next_rx++ >= max_console_rx ) -{ -console_owner = 0; -printk("* Serial input to Xen"); -break; -} - -if ( consoled_is_enabled() && next_rx == 1 ) -domid = get_initial_domain_id(); -else -domid = next_rx - 1; - -d = rcu_lock_domain_by_id(domid); -if ( d == NULL ) -continue; - -if ( d->is_console ) -{ -rcu_unlock_domain(d); -console_owner = next_rx; -printk("*** Serial input to DOM%u", domid); -break; -} +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )
rcu_unlock_domain(d);
- }xen/drivers/char/console.c +14
-0+ +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if (
switch_code)printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]);printk("\n");xen/drivers/char/console.c +8
-0+ +return 0 ; +} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 538
Quoted 4 lines
+ */
xen/drivers/char/console.c +3
-0+static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ;n can be made const, I would even rename to nr for clarity, but that's personal taste.
Quoted 2 lines
max_init_domidcan change at run-time actually (e.g. afterxl create). I keptnas is.
How does max_init_domid potentially changing affect (possible) const-ness of n?
However it changing, ...
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/drivers/char/console.c +6
-0+ +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; +Quoted 8 lines
Quoted 3 lines
+ for ( ; i < n; i++ )
+ if ( !console_set_owner(i) )
+ break;Hm, that could be a non-trivial amount of iteration if
max_init_domidis bumped for every domain created as you have it in patch 11/35 (albeit I'm not sure that was intended?)
Quoted 1 line
Yes,
max_init_domidis advanced on each domain creation (v3).
... as you confirm here, undermines what it's used for right now (if I'm not mistaken), and would render the variable misnamed.
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 150 lines · Jan Beulich
Quoted 146 lines · Denis Mukhin
Quoted 21 lines · On Thursday, December 12th, 2024 at 2:12 AM, Roger Pau Monné…
Quoted 19 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +1
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)
+
/
- * console_owner=0 => input to xen
- * console_owner=1 => input to dom0 (or the sole shim domain)
- * console_owner=N => input to dom(N-1)
+ * Current console owner domain ID: either Xen or domain w/d->is_console==
+ * true.
+ *
+ * Initialized inconsole_endboot().Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 476
Quoted 3 lines
*/
xen/drivers/char/console.c +1
-1-static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;Should this be initialized to
DOMID_XEN? I assume it doesn't make much difference because the variable is not checked beforeconsole_endboot()anyway, but it might be safer to initialize to a value that assigns the console to Xen.Fixed.
Quoted 9 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 7 lines
xen/drivers/char/console.c +6
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Fixed.
Quoted 99 lines
Quoted 86 lines
+ if ( d == NULL )
+ return NULL;xen/drivers/char/console.c +8
-1+ +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to
rcu_unlock_domainafter use */ struct domain*rcu_lock_domain_console_owner(void){
- if (console_owner== 0 )
- return NULL;
- returnrcu_lock_domain_by_id(console_owner - 1);
+ returnrcu_lock_domain_console_by_id(console_owner); }xen/drivers/char/console.c +1
-2-#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid){
- unsigned intnext_rx=console_owner;xen/drivers/char/console.c +3
-33- -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -/ -for ( ; ; ) -{ -domid_t domid; -struct domain d; - -if ( next_rx++ >= max_console_rx ) -{ -console_owner = 0; -printk("* Serial input to Xen"); -break; -} - -if ( consoled_is_enabled() && next_rx == 1 ) -domid = get_initial_domain_id(); -else -domid = next_rx - 1; - -d = rcu_lock_domain_by_id(domid); -if ( d == NULL ) -continue; - -if ( d->is_console ) -{ -rcu_unlock_domain(d); -console_owner = next_rx; -printk("*** Serial input to DOM%u", domid); -break; -} +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )
rcu_unlock_domain(d);
- }xen/drivers/char/console.c +14
-0+ +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if (
switch_code)printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]);printk("\n");xen/drivers/char/console.c +2
-0+ +return 0 ;xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 538
Quoted 10 lines
xen/drivers/char/console.c +10
-0+} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ;n can be made const, I would even rename to nr for clarity, but that's personal taste.
Quoted 5 lines
Quoted 2 lines
max_init_domidcan change at run-time actually (e.g. afterxl create). I keptnas is.How does
max_init_domidpotentially changing affect (possible) const-ness of n?
Sorry, what I meant is I kept the original name as is in v3. Forgot to address const.
Quoted 17 lines
However it changing, ...
Quoted 14 lines
Quoted 13 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 547
Quoted 9 lines
xen/drivers/char/console.c +9
-0+ +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_owner (i) ) +break ;Hm, that could be a non-trivial amount of iteration if
max_init_domidis bumped for every domain created as you have it in patch 11/35 (albeit I'm not sure that was intended?)
Quoted 5 lines
Quoted 1 line
Yes,
max_init_domidis advanced on each domain creation (v3).... as you confirm here, undermines what it's used for right now (if I'm not mistaken), and would render the variable misnamed.
Yes, the name will be a bit confusing.
Will something like last_domid work?
Quoted 2 lines
Jan
Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Quoted 179 lines · Denis Mukhin
Quoted 150 lines · Jan Beulich
Quoted 146 lines · Denis Mukhin
Quoted 21 lines · On Thursday, December 12th, 2024 at 2:12 AM, Roger Pau Monné…
Quoted 19 lines · On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +1
-1@@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)
+
/
- * console_owner=0 => input to xen
- * console_owner=1 => input to dom0 (or the sole shim domain)
- * console_owner=N => input to dom(N-1)
+ * Current console owner domain ID: either Xen or domain w/d->is_console==
+ * true.
+ *
+ * Initialized inconsole_endboot().Quoted 8 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 476
Quoted 3 lines
*/
xen/drivers/char/console.c +1
-1-static unsigned int __read_mostly console_owner =0 ; +static domid_t __read_mostly console_owner;Should this be initialized to
DOMID_XEN? I assume it doesn't make much difference because the variable is not checked beforeconsole_endboot()anyway, but it might be safer to initialize to a value that assigns the console to Xen.Fixed.
Quoted 9 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 483
Quoted 7 lines
xen/drivers/char/console.c +6
-1-#define max_console_rx (max_init_domid + 1) +static struct domain *rcu_lock_domain_console_by_id (domid_t domid) +{ +struct domain *d; + + d =rcu_lock_domain_by_id (domid); +Nit: I would remove this newline.
Fixed.
Quoted 99 lines
Quoted 86 lines
+ if ( d == NULL )
+ return NULL;xen/drivers/char/console.c +8
-1+ +if ( d->is_console ) +return d; + +rcu_unlock_domain (d); + +return NULL ; +} -#ifdef CONFIG_SBSA_VUART_CONSOLE /* Make sure to
rcu_unlock_domainafter use */ struct domain*rcu_lock_domain_console_owner(void){
- if (console_owner== 0 )
- return NULL;
- returnrcu_lock_domain_by_id(console_owner - 1);
+ returnrcu_lock_domain_console_by_id(console_owner); }xen/drivers/char/console.c +1
-2-#endif -static void console_find_owner (void ) +static bool console_owner_possible (domid_t domid){
- unsigned intnext_rx=console_owner;xen/drivers/char/console.c +3
-33- -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -/ -for ( ; ; ) -{ -domid_t domid; -struct domain d; - -if ( next_rx++ >= max_console_rx ) -{ -console_owner = 0; -printk("* Serial input to Xen"); -break; -} - -if ( consoled_is_enabled() && next_rx == 1 ) -domid = get_initial_domain_id(); -else -domid = next_rx - 1; - -d = rcu_lock_domain_by_id(domid); -if ( d == NULL ) -continue; - -if ( d->is_console ) -{ -rcu_unlock_domain(d); -console_owner = next_rx; -printk("*** Serial input to DOM%u", domid); -break; -} +struct domain *d; + d =rcu_lock_domain_console_by_id (domid); +if ( d !=NULL )
rcu_unlock_domain(d);
- }xen/drivers/char/console.c +14
-0+ +return d !=NULL ; +} + +int console_set_owner (domid_t domid) +{ +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_owner_possible (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; + + console_owner = domid;if (
switch_code)printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]);printk("\n");xen/drivers/char/console.c +2
-0+ +return 0 ;xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 538
Quoted 10 lines
xen/drivers/char/console.c +10
-0+} + +/* +* Switch console input focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_find_owner (void ) +{ +domid_t i, n = max_init_domid +1 ;n can be made const, I would even rename to nr for clarity, but that's personal taste.
Quoted 5 lines
Quoted 2 lines
max_init_domidcan change at run-time actually (e.g. afterxl create). I keptnas is.How does
max_init_domidpotentially changing affect (possible) const-ness of n?Sorry, what I meant is I kept the original name as is in v3. Forgot to address
const.Quoted 17 lines
However it changing, ...
Quoted 14 lines
Quoted 13 lines
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 547
Quoted 9 lines
xen/drivers/char/console.c +9
-0+ +if ( console_owner ==DOMID_XEN ) + i =get_initial_domain_id (); +else + i = console_owner +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_owner (i) ) +break ;Hm, that could be a non-trivial amount of iteration if
max_init_domidis bumped for every domain created as you have it in patch 11/35 (albeit I'm not sure that was intended?)
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Yes,
max_init_domidis advanced on each domain creation (v3).... as you confirm here, undermines what it's used for right now (if I'm not mistaken), and would render the variable misnamed.
Yes, the name will be a bit confusing.
Will something likelast_domidwork?
Well. First and foremost you need to make sure that existing uses of the variable will continue to function as-is. Aiui that contradicts your re-purposing of it. Which in turn would eliminate the question of how to best rename it.
Jan
PATCH v2 20/35 xen/console: introduce console_owner_domid()
In reply to Denis Mukhinconsole_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
--- xen/drivers/char/console.c | 5 +++++ xen/include/xen/console.h | 1 + 2 files changed, 6 insertions(+)
xen/drivers/char/console.c +5 -0
@@ -498,6 +498,11 @@ struct domain *rcu_lock_domain_console_owner(void)return rcu_lock_domain_console_by_id (console_owner); } +domid_t console_owner_domid (void ) +{ +return console_owner; +} +static bool console_owner_possible (domid_t domid) {struct domain *d;
xen/include/xen/console.h +1 -0
@@ -33,6 +33,7 @@ void console_end_log_everything(void);struct domain *rcu_lock_domain_console_owner (void );int console_set_owner (domid_t ); +domid_t console_owner_domid (void );/* * Steal output from the console. Returns +ve identifier, else -ve error.
Signature · 1 line
2.34.1
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 9 lines · On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Signed-off-by Denis Mukhin <[email protected]>
I expected this to be used immediately by patch 21, but it is not. You might want to re-order it directly before its first use is introduced. I haven't gotten far enough to know when that is.
Regards,
Jason
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 9 lines · Jason Andryuk
Quoted 8 lines · On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 7 lines
Quoted 1 line
Signed-off-by Denis Mukhin <[email protected]>Reviewed-by Jason Andryuk <[email protected]>I expected this to be used immediately by patch 21, but it is not. You might want to re-order it directly before its first use is introduced. I haven't gotten far enough to know when that is.
Plus, no matter how far in the future it is, there'll be a window where the Misra rule of not having unreachable code in the project is violated. New functions now really need introducing when their first caller appears.
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 18 lines · Jan Beulich
Quoted 14 lines · Jason Andryuk
Quoted 9 lines · On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Signed-off-by Denis Mukhin [email protected]Reviewed-by Jason Andryuk [email protected]
Quoted 8 lines
Quoted 3 lines
I expected this to be used immediately by patch 21, but it is not. You might want to re-order it directly before its first use is introduced. I haven't gotten far enough to know when that is.
Plus, no matter how far in the future it is, there'll be a window where the Misra rule of not having unreachable code in the project is violated. New functions now really need introducing when their first caller appears.
I see, thank you for the explanation.
Quoted 2 lines
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
In reply to Jason AndryukQuoted 15 lines · Jason Andryuk
Quoted 9 lines · On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Signed-off-by Denis Mukhin [email protected]
Quoted 6 lines
Reviewed-by Jason Andryuk [email protected]I expected this to be used immediately by patch 21, but it is not. You might want to re-order it directly before its first use is introduced. I haven't gotten far enough to know when that is.
Yeah, sorry for that.
I ended up dropping this patch from the series.
Quoted 3 lines
Regards,
Jason
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
In reply to Denis MukhinQuoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Such messages ought to be processed through guest_printk(), which wants a domain pointer, not a domid_t anyway. Plus isn't that going to be current->domain anyway at the callsite, eliminating the need for such a helper altogether?
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 2 lines
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 20 lines · Denis Mukhin
Quoted 17 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such a
Quoted 5 lines
Quoted 1 line
helper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Denis Mukhin
Quoted 18 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
Quoted 8 lines
Quoted 3 lines
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
Hi Jan,
It looks like we are aligned on the desired behavior, but for clarity, see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix
It is OK to change this behavior, but in that case I would ask that we change it consistently also for ARM.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 9 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix
... view this model as a desirable one. It leaves room for ambiguity.
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 42 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:
Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 53 lines · Stefano Stabellini
Quoted 42 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
Quoted 7 lines
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with guest_printk() today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 60 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 42 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Thanks, Roger.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 70 lines · Roger Pau Monné
Quoted 60 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 42 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.
Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 85 lines · Jan Beulich
Quoted 70 lines · Roger Pau Monné
Quoted 60 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 42 lines · Jan Beulich
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Jan Beulich
Quoted 25 lines · Denis Mukhin
Quoted 13 lines · Jan Beulich
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Thanks, Roger.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 92 lines · Roger Pau Monné
Quoted 88 lines · Jan Beulich
Quoted 72 lines · Roger Pau Monné
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 41 lines · Jan Beulich
Quoted 26 lines · Stefano Stabellini
Quoted 24 lines · Jan Beulich
Quoted 21 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 8 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 91 lines · Denis Mukhin
Quoted 81 lines · Roger Pau Monné
Quoted 80 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 8 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]
Roger, Jan, you should use Xen Dom0less more :-) This is the way it already works on ARM. Let me expand on my earlier message that was too terse.
At boot time, Xen prints messages with the (XEN) prefix as usual:
(XEN) Brought up 4 CPUs
When Dom0 starts, it has not prefix (and has input by default):
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
When a DomU starts, it has the following prefix (and doesn't have input):
(XEN) DOM1: [ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
Eventually, both Linuxes finish booting, you can login into Dom0 as usual. Messages from Dom1, if any, are still printed with (XEN) DOM1 as prefix.
You can switch input to Dom1 with Ctrx-aaa, the same way that you do today to switch between Xen and Dom0. Xen prints a message:
(XEN) *** Serial input to DOM1 (type 'CTRL-a' three times to switch input)
Now, as you type, you send characters to Dom1. And Dom1 doesn't have the DOM1 prefix any longer, while it is still has (XEN) because the message is printed by Xen on behalf of the domain:
(XEN) / # echo hello world
(XEN) hello world
If Dom0 prints anything in the backgrounds, it shows without prefixes:
hello world from dom0
If another domain, dom2, prints anything in the background, it shows with (XEN) DOM2 prefix:
(XEN) DOM2: hello from dom2
I think it makes sense to be consistent across architectures and we should default to the same behavior on x86 too. If we want to make improvements, the one thing I could potentially see changing is adding a DOM0 prefix to Dom0 messages when Dom0 does not have input. If we do that, let's do it on both ARM and x86 architectures.
Cheers,
Stefano
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 102 lines · Stefano Stabellini
Quoted 91 lines · Denis Mukhin
Quoted 81 lines · Roger Pau Monné
Quoted 80 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen
console focus is owned by the domain w/ NS8250 emulator, in which case,
messages from guest OS are formatted w/o '(XEN)' prefix.Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 8 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]
Quoted 3 lines
Roger, Jan, you should use Xen Dom0less more :-) This is the way it already works on ARM. Let me expand on my earlier message that was too terse.
Hehe, I should use ARM more in general I think :).
Quoted 37 lines
At boot time, Xen prints messages with the (XEN) prefix as usual:
(XEN) Brought up 4 CPUs
When Dom0 starts, it has not prefix (and has input by default):
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]When a DomU starts, it has the following prefix (and doesn't have input):
(XEN) DOM1: [ 0.000000] Booting Linux on physical CPU
0x0000000000[0x410fd034]Eventually, both Linuxes finish booting, you can login into Dom0 as usual. Messages from Dom1, if any, are still printed with (XEN) DOM1 as prefix.
You can switch input to Dom1 with Ctrx-aaa, the same way that you do today to switch between Xen and Dom0. Xen prints a message:
(XEN) *** Serial input to DOM1 (type 'CTRL-a' three times to switch input)
Now, as you type, you send characters to Dom1. And Dom1 doesn't have the DOM1 prefix any longer, while it is still has (XEN) because the message is printed by Xen on behalf of the domain:
(XEN) / # echo hello world
(XEN) hello worldIf Dom0 prints anything in the backgrounds, it shows without prefixes:
hello world from dom0
If another domain, dom2, prints anything in the background, it shows with (XEN) DOM2 prefix:
Quoted 7 lines
(XEN) DOM2: hello from dom2
I think it makes sense to be consistent across architectures and we should default to the same behavior on x86 too. If we want to make improvements, the one thing I could potentially see changing is adding a DOM0 prefix to Dom0 messages when Dom0 does not have input. If we do that, let's do it on both ARM and x86 architectures.
The usual prefix is (d<domid>) IIRC, that's what guest_printk() uses, is there any reason dom0less uses "(XEN) DOM<domid>:" instead of the guest_printk() prefix?
My preference would be use to (d<domid>) prefix for any guest output that doesn't belong to the domain that's the recipient of the input (iow: not in console input focus). And drop the (XEN) prefix from guest output.
The rest looks all sensible to me. I think we should avoid adding any prefixes to guest output when it has the console focus, as otherwise interactive applications might not work correctly.
Thanks, Roger.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 158 lines · Roger Pau Monné
Quoted 102 lines · Stefano Stabellini
Quoted 91 lines · Denis Mukhin
Quoted 81 lines · Roger Pau Monné
Quoted 80 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Denis Mukhin
Quoted 15 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen
console focus is owned by the domain w/ NS8250 emulator, in which case,
messages from guest OS are formatted w/o '(XEN)' prefix.Such messages ought to be processed through guest_printk(), which wants a
domain pointer, not a domid_t anyway. Plus isn't that going to be
current->domain anyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 8 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]Quoted 3 lines
Roger, Jan, you should use Xen Dom0less more :-) This is the way it already works on ARM. Let me expand on my earlier message that was too terse.
Hehe, I should use ARM more in general I think :).
Quoted 37 lines
At boot time, Xen prints messages with the (XEN) prefix as usual:
(XEN) Brought up 4 CPUs
When Dom0 starts, it has not prefix (and has input by default):
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]When a DomU starts, it has the following prefix (and doesn't have input):
(XEN) DOM1: [ 0.000000] Booting Linux on physical CPU
0x0000000000[0x410fd034]Eventually, both Linuxes finish booting, you can login into Dom0 as usual. Messages from Dom1, if any, are still printed with (XEN) DOM1 as prefix.
You can switch input to Dom1 with Ctrx-aaa, the same way that you do today to switch between Xen and Dom0. Xen prints a message:
(XEN) *** Serial input to DOM1 (type 'CTRL-a' three times to switch input)
Now, as you type, you send characters to Dom1. And Dom1 doesn't have the DOM1 prefix any longer, while it is still has (XEN) because the message is printed by Xen on behalf of the domain:
(XEN) / # echo hello world
(XEN) hello worldIf Dom0 prints anything in the backgrounds, it shows without prefixes:
hello world from dom0
If another domain, dom2, prints anything in the background, it shows with (XEN) DOM2 prefix:
Quoted 7 lines
(XEN) DOM2: hello from dom2
I think it makes sense to be consistent across architectures and we should default to the same behavior on x86 too. If we want to make improvements, the one thing I could potentially see changing is adding a DOM0 prefix to Dom0 messages when Dom0 does not have input. If we do that, let's do it on both ARM and x86 architectures.
The usual prefix is (d<domid>) IIRC, that's what
guest_printk()uses, is there any reason dom0less uses "(XEN) DOM<domid>:" instead of theguest_printk()prefix?
Quoted 8 lines
My preference would be use to (d<domid>) prefix for any guest output that doesn't belong to the domain that's the recipient of the input (iow: not in console input focus). And drop the (XEN) prefix from guest output.
The rest looks all sensible to me. I think we should avoid adding any prefixes to guest output when it has the console focus, as otherwise interactive applications might not work correctly.
I am OK with what you describe, I would kindly ask Denis to also modify ARM vpl011 to match. Looking at the code, I don't know where the (XEN) prefix is coming from, but for the DOM<domid> to d<domid> change, it would be probably something like this:
xen/arch/arm/vpl011.c +4 -1
@@ -107,7 +107,10 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)if ( data !='\n' ) intf->out[intf->out_prod++] ='\n' ; intf->out[intf->out_prod++] ='\0' ; -printk ("DOM%u: %s" , d->domain_id, intf->out); +if (in_focus (d) ) +printk ("%s" , intf->out); +else +guest_printk ("%s" , d, intf->out); intf->out_prod =0 ; } }
There is also one additional change needed to add the (d<domid>) prefix for dom0 when not in focus. The Dom0 print typically comes from do_console_io, so in pseudocode we would need something like:
xen/drivers/char/console.c +3 -0
@@ -643,6 +643,9 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,/* Use direct console output as it could be interactive */ nrspin_lock_irq (&console_lock); +if ( !in_focus (cd) ) +add_prefix (kbuf,"(d0) " ); +console_serial_puts (kbuf, kcount);video_puts (kbuf, kcount);
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 176 lines · Stefano Stabellini
Quoted 172 lines · Roger Pau Monné
Quoted 111 lines · Stefano Stabellini
Quoted 100 lines · Denis Mukhin
Quoted 90 lines · On Wednesday, January 8th, 2025 at 12:35 AM, Roger Pau Monné…
Quoted 88 lines · Jan Beulich
Quoted 72 lines · Roger Pau Monné
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 41 lines · Jan Beulich
Quoted 26 lines · Stefano Stabellini
Quoted 24 lines · Jan Beulich
Quoted 21 lines · Denis Mukhin
On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected] wrote:
On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen
console focus is owned by the domain w/ NS8250 emulator, in which case,
messages from guest OS are formatted w/o '(XEN)' prefix.Such messages ought to be processed through guest_printk(), which wants a
domain pointer, not a domid_t anyway. Plus isn't that going to be
current->domain anyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux
login prompt, there's no need to add "(XEN)" for every printout; adding timestamps
can be disabled from Xen command line.Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 7 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]Quoted 3 lines
Roger, Jan, you should use Xen Dom0less more :-) This is the way it already works on ARM. Let me expand on my earlier message that was too terse.
Hehe, I should use ARM more in general I think :).
Quoted 36 lines
At boot time, Xen prints messages with the (XEN) prefix as usual:
(XEN) Brought up 4 CPUs
When Dom0 starts, it has not prefix (and has input by default):
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]When a DomU starts, it has the following prefix (and doesn't have input):
(XEN) DOM1: [ 0.000000] Booting Linux on physical CPU
0x0000000000[0x410fd034]Eventually, both Linuxes finish booting, you can login into Dom0 as usual. Messages from Dom1, if any, are still printed with (XEN) DOM1 as prefix.
You can switch input to Dom1 with Ctrx-aaa, the same way that you do today to switch between Xen and Dom0. Xen prints a message:
(XEN) *** Serial input to DOM1 (type 'CTRL-a' three times to switch input)
Now, as you type, you send characters to Dom1. And Dom1 doesn't have the DOM1 prefix any longer, while it is still has (XEN) because the message is printed by Xen on behalf of the domain:
(XEN) / # echo hello world
(XEN) hello worldIf Dom0 prints anything in the backgrounds, it shows without prefixes:
hello world from dom0
If another domain, dom2, prints anything in the background, it shows with (XEN) DOM2 prefix:
Quoted 7 lines
(XEN) DOM2: hello from dom2
I think it makes sense to be consistent across architectures and we should default to the same behavior on x86 too. If we want to make improvements, the one thing I could potentially see changing is adding a DOM0 prefix to Dom0 messages when Dom0 does not have input. If we do that, let's do it on both ARM and x86 architectures.
The usual prefix is (d<domid>) IIRC, that's what
guest_printk()uses, is there any reason dom0less uses "(XEN) DOM<domid>:" instead of theguest_printk()prefix?My preference would be use to (d<domid>) prefix for any guest output that doesn't belong to the domain that's the recipient of the input (iow: not in console input focus). And drop the (XEN) prefix from guest output.
Quoted 8 lines
Quoted 3 lines
The rest looks all sensible to me. I think we should avoid adding any prefixes to guest output when it has the console focus, as otherwise interactive applications might not work correctly.
I am OK with what you describe, I would kindly ask Denis to also modify ARM vpl011 to match. Looking at the code, I don't know where the (XEN) prefix is coming from, but for the DOM<domid> to d<domid> change, it
Yep, I implemented such logic in v3 iteration of the series:
https://lore.kernel.org/xen-devel/[email protected]/
printk() adds "(XEN)" prefix (drivers/char/console.c)
Quoted 21 lines
would be probably something like this:
xen/arch/arm/vpl011.c +4
-1@@ -107,7 +107,10 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)if ( data !='\n' ) intf->out[intf->out_prod++] ='\n' ; intf->out[intf->out_prod++] ='\0' ; -printk ("DOM%u: %s" , d->domain_id, intf->out); +if (in_focus (d) ) +printk ("%s" , intf->out); +else +guest_printk ("%s" , d, intf->out);
Quoted 8 lines
intf->out_prod= 0;}
}There is also one additional change needed to add the (d<domid>) prefix
for dom0 when not in focus. The Dom0 print typically comes from
This change I missed. Thanks!
Quoted 15 lines
do_console_io, so in pseudocode we would need something like:xen/drivers/char/console.c +3
-0@@ -643,6 +643,9 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,/* Use direct console output as it could be interactive */ nrspin_lock_irq (&console_lock); +if ( !in_focus (cd) ) +add_prefix (kbuf,"(d0) " ); +console_serial_puts (kbuf, kcount);video_puts (kbuf, kcount);
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
In reply to Stefano StabelliniQuoted 110 lines · Stefano Stabellini
Quoted 91 lines · Denis Mukhin
Quoted 81 lines · Roger Pau Monné
Quoted 80 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Stefano Stabellini
Quoted 37 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen
console focus is owned by the domain w/ NS8250 emulator, in which case,
messages from guest OS are formatted w/o '(XEN)' prefix.Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 8 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]Roger, Jan, you should use Xen Dom0less more :-) This is the way it already works on ARM. Let me expand on my earlier message that was too terse.
At boot time, Xen prints messages with the (XEN) prefix as usual:
(XEN) Brought up 4 CPUs
Quoted 8 lines
When Dom0 starts, it has not prefix (and has input by default):
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]When a DomU starts, it has the following prefix (and doesn't have input):
(XEN) DOM1: [ 0.000000] Booting Linux on physical CPU
0x0000000000[0x410fd034]
Which is wrong - this isn't a Xen message. Such messages imo want prefixing (d<N>), as guest_printk() does.
Jan
Quoted 33 lines
Eventually, both Linuxes finish booting, you can login into Dom0 as usual. Messages from Dom1, if any, are still printed with (XEN) DOM1 as prefix.
You can switch input to Dom1 with Ctrx-aaa, the same way that you do today to switch between Xen and Dom0. Xen prints a message:
(XEN) *** Serial input to DOM1 (type 'CTRL-a' three times to switch input)
Now, as you type, you send characters to Dom1. And Dom1 doesn't have the DOM1 prefix any longer, while it is still has (XEN) because the message is printed by Xen on behalf of the domain:
(XEN) / # echo hello world
(XEN) hello worldIf Dom0 prints anything in the backgrounds, it shows without prefixes:
hello world from dom0
If another domain, dom2, prints anything in the background, it shows with (XEN) DOM2 prefix:
(XEN) DOM2: hello from dom2
I think it makes sense to be consistent across architectures and we should default to the same behavior on x86 too. If we want to make improvements, the one thing I could potentially see changing is adding a DOM0 prefix to Dom0 messages when Dom0 does not have input. If we do that, let's do it on both ARM and x86 architectures.
Cheers,
Stefano
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
In reply to Denis MukhinQuoted 102 lines · Denis Mukhin
Quoted 92 lines · Roger Pau Monné
Quoted 88 lines · Jan Beulich
Quoted 72 lines · Roger Pau Monné
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 41 lines · Jan Beulich
Quoted 26 lines · Stefano Stabellini
Quoted 24 lines · Jan Beulich
Quoted 21 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 7 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]
And just to double check: These messages aren't affected by "loglvl=" settings, i.e. they're _always_ there (as asked for earlier; see context above)?
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 114 lines · Jan Beulich
Quoted 100 lines · Denis Mukhin
Quoted 90 lines · On Wednesday, January 8th, 2025 at 12:35 AM, Roger Pau Monné…
Quoted 88 lines · Jan Beulich
Quoted 72 lines · Roger Pau Monné
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Stefano Stabellini
Quoted 41 lines · Jan Beulich
Quoted 26 lines · Stefano Stabellini
Quoted 24 lines · Jan Beulich
Quoted 21 lines · Denis Mukhin
Quoted 10 lines · On Tuesday, December 10th, 2024 at 11:28 PM, Jan Beulich [email protected]…
Quoted 7 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid() is introduced to obtain the "console owner" domain ID.
The call is used in NS8250 emulator to identify the case when physical xen
console focus is owned by the domain w/ NS8250 emulator, in which case,
messages from guest OS are formatted w/o '(XEN)' prefix.Quoted 5 lines
Such messages ought to be processed through
guest_printk(), which wants a domain pointer, not adomid_tanyway. Plus isn't that going to becurrent->domainanyway at the callsite, eliminating the need for such ahelper altogether?
If the current domain is owning the physical console and printing, say, Linux login prompt, there's no need to add "(XEN)" for every printout; adding timestamps can be disabled from Xen command line.
Quoted 6 lines
Quoted 4 lines
Surely there shouldn't be (XEN), but without (d<N>) it'll be ambiguous in a log which domain a message came from. As long as only Dom0 messages are left un- prefixed, that's likely fine. Yet as soon as multiple domains can issue such messages (and have console "focus") I think the prefix needs to be there.
It looks like we are aligned on the desired behavior,
Hmm, no, I don't think we are. I don't ...
Quoted 4 lines
but for clarity,
see https://marc.info/?l=xen-devel&m=173405161613716, also copy/pasted here:Quoted 7 lines
Quoted 5 lines
I think we should provide a consistent behavior across architectures. The current behavior with vpl011 and dom0less on ARM is the following:
- no prefix for Dom0 output
- DOM$NUM for DomUs when not in focus, otherwise no prefix... view this model as a desirable one. It leaves room for ambiguity.
Adding a few more people in CC for feedback.
My priority is to keep the architectures aligned. It might be OK to change output format, but then let's do it uniformly on ARM as well.
Jan, please clarify what you think would be better than the above. Is it the following? I don't think I understood your preference.
Quoted 8 lines
Quoted 1 line
- DOM$NUM for Dom0 and DomUs when not in focus, otherwise no prefix
No, I mean like we have it with
guest_printk()today. (XEN) for Xen's own messages, (d<N>) for ordinary domains' ones, and no prefix exclusively for the hardware/control domain. What is best to do when hardware and control domains are distinct I'm uncertain - I'd be inclined to suggest that the hardware domain then stay the one without any prefix.Quoted 5 lines
One concern I have with this approach is whether the addition of the (d<N>) prefixes will skew output of interactive applications. So far the prefix is added to output from all domains different than dom0 because the console is not interactive for them, and hence no input can be consumed.
Hmm, that's an aspect I have to admit I didn't think of.
Quoted 5 lines
If that changes however, and domains different than dom0 can get input from the Xen console then I wonder how much the added prefix will skew output. Another possible option would be to not print the prefix for the domain that has the console input assigned (current target), and print it for all other domains (even for dom0 when not in focus).
Quoted 7 lines
Quoted 4 lines
That's largely what aiui was proposed. My extra requirement there would then be that we make sure a log message is always emitted when console focus shifts, so it's possible to identify the owner for any part of the log.
Indeed, printing console input shifting should be a requirement regardless of how we decide to print the prefix.
Quoted 8 lines
Console input focus switch is indicated after pressing Crtl+aaa, e.g.:
[[
...
(XEN) [15359.353038] *** Serial input to Xen (type 'CTRL-aaa' to switch input) (XEN) [15361.176754] *** Serial input to DOM0 (type 'CTRL-aaa' to switch input) (XEN) [15711.297202] *** Serial input to DOM1 (type 'CTRL-aaa' to switch input)
...
]]
Quoted 2 lines
And just to double check: These messages aren't affected by "loglvl=" settings, i.e. they're always there (as asked for earlier; see context above)?
loglvl=none disables console switch indication (even w/o my patches). I will fix that.
Thanks!
Quoted 2 lines
Jan
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
In reply to Denis MukhinQuoted 7 lines · On Thu, Dec 05, 2024 at 08:41:50PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_owner_domid()is introduced to obtain the "console owner" domain ID.The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Nit: it would be better to not use abbreviations such as w/ or w/o in commit messages.
Quoted 28 lines
Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 5 +++++ xen/include/xen/console.h | 1 + 2 files changed, 6 insertions(+)xen/drivers/char/console.c +5
-0@@ -498,6 +498,11 @@ struct domain *rcu_lock_domain_console_owner(void)return rcu_lock_domain_console_by_id (console_owner); } +domid_t console_owner_domid (void ) +{ +return console_owner; +} +static bool console_owner_possible (domid_t domid) {struct domain *d;xen/include/xen/console.h +0
-0
xen/include/xen/console.h void console_end_log_everything(void); · line 36
Quoted 4 lines
xen/include/xen/console.h +1
-0@@ -33,6 +33,7 @@ void console_end_log_everything(void);struct domain *rcu_lock_domain_console_owner (void );int console_set_owner (domid_t ); +domid_t console_owner_domid (void );
I would expect that either the caller already has a domain locked, or uses rcu_lock_domain_console_owner() to obtain the domain and then get the domid? (d->domain_id?)
It's hard to tell why you need such way to get the console input target domid in such a way without seeing a caller to the function.
Thanks, Roger.
Re: [PATCH v2 20/35] xen/console: introduce console_owner_domid()
Quoted 8 lines · Roger Pau Monné
Quoted 4 lines · On Thu, Dec 05, 2024 at 08:41:50PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_owner_domid()is introduced to obtain the "console owner" domain ID.
Quoted 7 lines
Quoted 3 lines
The call is used in NS8250 emulator to identify the case when physical xen console focus is owned by the domain w/ NS8250 emulator, in which case, messages from guest OS are formatted w/o '(XEN)' prefix.
Nit: it would be better to not use abbreviations such as w/ or w/o in commit messages.
Muscle memory; cleaned up in v3.
Quoted 29 lines
Quoted 29 lines
Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 5 +++++xen/include/xen/console.h| 1 +2 files changed, 6 insertions(+)xen/drivers/char/console.c +5
-0@@ -498,6 +498,11 @@ struct domain *rcu_lock_domain_console_owner(void)return rcu_lock_domain_console_by_id (console_owner); } +domid_t console_owner_domid (void ) +{ +return console_owner; +} +static bool console_owner_possible (domid_t domid) {struct domain *d;xen/include/xen/console.h +0
-0@@ -33,6 +33,7 @@ void console_end_log_everything(void);
Quoted 8 lines
xen/include/xen/console.h void console_end_log_everything(void); · line 36
Quoted 3 lines
xen/include/xen/console.h +1
-0struct domain *rcu_lock_domain_console_owner (void );int console_set_owner (domid_t ); +domid_t console_owner_domid (void );I would expect that either the caller already has a domain locked, or uses
rcu_lock_domain_console_owner()to obtain the domain and then get the domid? (d->domain_id?)
If the console focus in the guest, there's no need to prefix each guest OS printout w/ "(XEN)" and a timestamp. To identify that current ns8250 emulator is the one who's printing to the physical UART, I introduced this call.
I think ideally, domain should have a flag saying "currently has console focus" which is set by the console focus switch logic in console driver.
Quoted 4 lines
It's hard to tell why you need such way to get the console input target domid in such a way without seeing a caller to the function.
Sorry for that, addressed in v3.
I ended up dropping the patch after addressing all the feedback.
Quoted 2 lines
Thanks, Roger.
PATCH v2 21/35 xen/console: introduce console_init_owner()
In reply to Denis Mukhinconsole_init_owner() is introduced for selecting the boot-time console owner.
--- xen/drivers/char/console.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
xen/drivers/char/console.c +17 -10
@@ -554,6 +554,22 @@ static void console_find_owner(void)console_set_owner (DOMID_XEN ); } +static void console_init_owner (void ) +{ +domid_t domid; + +/* +* If user specifies so, we fool the switch routine to redirect input +* straight back to Xen. +*/ +if ( opt_conswitch[1 ] =='x' ) + domid =DOMID_XEN ; +else + domid =get_initial_domain_id (); + +console_set_owner (domid); +} +static void __serial_rx (char c) { switch ( console_owner )
@@ -1143,14 +1159,6 @@ void __init console_endboot(void)video_endboot (); -/* -* If user specifies so, we fool the switch routine to redirect input -* straight back to Xen. I use this convoluted method so we still print -* a useful 'how to switch' message. -*/ -if ( opt_conswitch[1 ] =='x' ) - console_owner =DOMID_XEN ; -register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,
@@ -1160,8 +1168,7 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_find_owner (); +console_init_owner (); }int __init console_has (const char *device)
Signature · 1 line
2.34.1
Re: [PATCH v2 21/35] xen/console: introduce console_init_owner()
Quoted 5 lines · On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_init_owner()is introduced for selecting the boot-time console owner.Signed-off-by Denis Mukhin <[email protected]>
Re: [PATCH v2 21/35] xen/console: introduce console_init_owner()
In reply to Denis MukhinQuoted 11 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +5
-0@@ -554,6 +554,22 @@ static void console_find_owner(void)console_set_owner (DOMID_XEN ); } +static void console_init_owner (void ) +{ +domid_t domid; + +/*
xen/drivers/char/console.c static void console_find_owner(void) · line 571
Quoted 10 lines
xen/drivers/char/console.c +10
-0+* If user specifies so, we fool the switch routine to redirect input +* straight back to Xen. +*/ +if ( opt_conswitch[1 ] =='x' ) + domid =DOMID_XEN ; +else + domid =get_initial_domain_id (); + +console_set_owner (domid); +}
Is this function meant to gain a 2nd user? If not, what exactly is the goal of introducing this new function?
If the function's addition is warranted, it wants to be __init, matching ...
xen/drivers/char/console.c void __init console_endboot(void) · line 1172
Quoted 8 lines
xen/drivers/char/console.c +1
-2@@ -1160,8 +1168,7 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_find_owner (); +console_init_owner (); }
... sole caller.
Jan
Re: [PATCH v2 21/35] xen/console: introduce console_init_owner()
Quoted 21 lines · Jan Beulich
Quoted 17 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/drivers/char/console.c +11
-0@@ -554,6 +554,22 @@ static void console_find_owner(void)console_set_owner (DOMID_XEN ); } +static void console_init_owner (void ) +{ +domid_t domid; + +/* +* If user specifies so, we fool the switch routine to redirect input +* straight back to Xen. +*/ +if ( opt_conswitch[1 ] =='x' ) + domid =DOMID_XEN ; +else
Quoted 8 lines
xen/drivers/char/console.c static void console_find_owner(void) · line 571
Quoted 4 lines
xen/drivers/char/console.c +4
-0+ domid =get_initial_domain_id (); + +console_set_owner (domid); +}Is this function meant to gain a 2nd user? If not, what exactly is the goal of introducing this new function?
I cannot foresee the second user.
My rationale was moving all console ownership initialization into one place so the code is better localized.
Quoted 2 lines
If the function's addition is warranted, it wants to be
__init, matching ...
I ended up dropping the patch in v3.
Quoted 14 lines
xen/drivers/char/console.c void __init console_endboot(void) · line 1172
Quoted 9 lines
xen/drivers/char/console.c +1
-2@@ -1160,8 +1168,7 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_find_owner (); +console_init_owner (); }... sole caller.
Jan
Re: [PATCH v2 21/35] xen/console: introduce console_init_owner()
In reply to Denis MukhinQuoted 14 lines · On Thu, Dec 05, 2024 at 08:41:51PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
console_init_owner()is introduced for selecting the boot-time console owner.Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)xen/drivers/char/console.c +0
-0
xen/drivers/char/console.c static void console_find_owner(void) · line 557
Quoted 4 lines
xen/drivers/char/console.c +1
-0@@ -554,6 +554,22 @@ static void console_find_owner(void)console_set_owner (DOMID_XEN ); } +static void console_init_owner (void )
__init attribute missing (given current call context), but see below.
Quoted 34 lines
xen/drivers/char/console.c +15
-8+{ +domid_t domid; + +/* +* If user specifies so, we fool the switch routine to redirect input +* straight back to Xen. +*/ +if ( opt_conswitch[1 ] =='x' ) + domid =DOMID_XEN ; +else + domid =get_initial_domain_id (); + +console_set_owner (domid); +} +static void __serial_rx (char c) { switch ( console_owner )@@ -1143,14 +1159,6 @@ void __init console_endboot(void)video_endboot (); -/* -* If user specifies so, we fool the switch routine to redirect input -* straight back to Xen. I use this convoluted method so we still print -* a useful 'how to switch' message. -*/ -if ( opt_conswitch[1 ] =='x' ) - console_owner =DOMID_XEN ; -register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,
xen/drivers/char/console.c void __init console_endboot(void) · line 1171
Quoted 6 lines
xen/drivers/char/console.c +1
-2@@ -1160,8 +1168,7 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_find_owner (); +console_init_owner ();
Oh, so this is what fixes the regression introduced in patch 19/35. THB I'm not sure it's worth introducing the console_init_owner() helper if it's just for this usage. You could do:
console_set_owner(opt_conswitch[1] == 'x' ? DOMID_XEN
: get_initial_domain_id());
Thanks, Roger.
Re: [PATCH v2 21/35] xen/console: introduce console_init_owner()
Quoted 72 lines · Roger Pau Monné
Quoted 14 lines · On Thu, Dec 05, 2024 at 08:41:51PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
console_init_owner()is introduced for selecting the boot-time console owner.Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 27 +++++++++++++++++----------1 file changed, 17 insertions(+), 10 deletions(-)xen/drivers/char/console.c +0
-0xen/drivers/char/console.c static void console_find_owner(void) · line 557
Quoted 4 lines
xen/drivers/char/console.c +1
-0@@ -554,6 +554,22 @@ static void console_find_owner(void)console_set_owner (DOMID_XEN ); } +static void console_init_owner (void )
__initattribute missing (given current call context), but see below.Quoted 34 lines
xen/drivers/char/console.c +15
-8+{ +domid_t domid; + +/* +* If user specifies so, we fool the switch routine to redirect input +* straight back to Xen. +*/ +if ( opt_conswitch[1 ] =='x' ) + domid =DOMID_XEN ; +else + domid =get_initial_domain_id (); + +console_set_owner (domid); +} +static void __serial_rx (char c) { switch ( console_owner )@@ -1143,14 +1159,6 @@ void __init console_endboot(void)video_endboot (); -/* -* If user specifies so, we fool the switch routine to redirect input -* straight back to Xen. I use this convoluted method so we still print -* a useful 'how to switch' message. -*/ -if ( opt_conswitch[1 ] =='x' ) - console_owner =DOMID_XEN ; -register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,xen/drivers/char/console.c void __init console_endboot(void) · line 1171
Quoted 6 lines
xen/drivers/char/console.c +1
-2@@ -1160,8 +1168,7 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_find_owner (); +console_init_owner ();Oh, so this is what fixes the regression introduced in patch 19/35. THB I'm not sure it's worth introducing the
console_init_owner()helper if it's just for this usage. You could do:
Quoted 2 lines
console_set_owner(opt_conswitch[1] == 'x' ? DOMID_XEN : get_initial_domain_id());
Right, thank you.
Addressed in v3.
Quoted 2 lines
Thanks, Roger.
PATCH v2 22/35 xen/console: introduce handle_keypress_in_domain()
In reply to Denis MukhinWith introduction of NS8250 emulator for x86, the logic of switching console focus gets more convoluted: HVM domain w/ NS8205 must be able to receive the physical console input for guest VM debugging.
Also, existing code does not honor hardware_dom= xen command line parameter (hardware domain ID does _not_ necessarily starts from 0).
Introduce handle_keypress_in_domain() to account for all scenarios of console input forwarding.
--- xen/drivers/char/console.c | 72 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-)
xen/drivers/char/console.c +42 -30
@@ -570,14 +570,16 @@ static void console_init_owner(void)console_set_owner (domid); } -static void __serial_rx (char c) +static void handle_keypress_in_domain (struct domain *d,char c) { -switch ( console_owner ) - { -case DOMID_XEN : -return handle_keypress (c, false); +int rc =0 ; -case 0 : +/* +* Deliver input to the hardware domain buffer. +* NB: must be the first check: hardware domain may have emulated UART. +*/ +if ( d == hardware_domain ) + {/* * Deliver input to the hardware domain buffer, unless it is * already full.
@@ -590,34 +592,44 @@ 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_owner); - -/* -* If we have a properly initialized vpl011 console for the -* domain, without a full PV ring to Dom0 (in that case input -* comes from the PV ring), then send the character to it. -*/ -if ( d !=NULL ) -vpl011_rx_char_xen (d, c); -else -printk ("Cannot send chars to Dom%d: no UART available\n" , - console_owner); - -if ( d !=NULL ) -rcu_unlock_domain (d); - -break ; } +/* +* Deliver input to the emulated UART. +*/ +else if (domain_has_vuart (d) ) + { +#if defined(CONFIG_SBSA_VUART_CONSOLE ) + rc =vpl011_rx_char_xen (d, c);#endif } - +/* +* Deliver input to the PV shim console. +*/ if (consoled_is_enabled () ) -consoled_guest_tx (c); + rc =consoled_guest_tx (c); + +if ( rc && rc != -ENODEV ) +printk (KERN_WARNING "console input domain %d: not ready: %d\n" , + d->domain_id, rc); +} + +static void __serial_rx (char c) +{ +struct domain *d; + +if ( console_owner ==DOMID_XEN ) + { +handle_keypress (c, false); +return ; + } + + d =rcu_lock_domain_console_owner (); +if ( d ==NULL ) +return ; + +handle_keypress_in_domain (d, c); + +rcu_unlock_domain (d); } static void cf_check serial_rx(char c)
Signature · 1 line
2.34.1
Re: [PATCH v2 22/35] xen/console: introduce handle_keypress_in_domain()
Quoted 30 lines · On Thu, Dec 05, 2024 at 08:41:52PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
With introduction of NS8250 emulator for x86, the logic of switching console focus gets more convoluted: HVM domain w/ NS8205 must be able to receive the physical console input for guest VM debugging.
Also, existing code does not honor
hardware_dom=xen command line parameter (hardware domain ID does _not_ necessarily starts from 0).Introduce
handle_keypress_in_domain()to account for all scenarios of console input forwarding.Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 72 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-)xen/drivers/char/console.c +1
-3@@ -570,14 +570,16 @@ static void console_init_owner(void)console_set_owner (domid); } -static void __serial_rx (char c) +static void handle_keypress_in_domain (struct domain *d,char c) { -switch ( console_owner ) - {
xen/drivers/char/console.c static void console_init_owner(void) · line 581
Quoted 10 lines
xen/drivers/char/console.c +6
-3-case DOMID_XEN : -return handle_keypress (c, false); +int rc =0 ; -case 0 : +/* +* Deliver input to the hardware domain buffer. +* NB: must be the first check: hardware domain may have emulated UART. +*/ +if ( d == hardware_domain )
is_hardware_domain(d)
Quoted 24 lines
xen/drivers/char/console.c +1
-16+ {/* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -590,34 +592,44 @@ 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_owner); - -/* -* If we have a properly initialized vpl011 console for the -* domain, without a full PV ring to Dom0 (in that case input -* comes from the PV ring), then send the character to it. -*/ -if ( d !=NULL ) -vpl011_rx_char_xen (d, c); -else - printk("Cannot send chars to Dom%d: no UART available\n",
xen/drivers/char/console.c static void __serial_rx(char c) · line 598
Quoted 10 lines
xen/drivers/char/console.c +3
-6- console_owner); - -if ( d !=NULL ) -rcu_unlock_domain (d); - -break ; } +/* +* Deliver input to the emulated UART. +*/
For one-line comments you can use:
/* Deliver input to the emulated UART. */
I would however place the comment inside the if body.
xen/drivers/char/console.c static void __serial_rx(char c) · line 603
Quoted 5 lines
xen/drivers/char/console.c +4
-0+else if (domain_has_vuart (d) ) + { +#if defined(CONFIG_SBSA_VUART_CONSOLE ) + rc =vpl011_rx_char_xen (d, c);#endif
You can possibly make the preprocessor conditional also contain the if condition itself? As otherwise the if condition is dead code.
xen/drivers/char/console.c static void __serial_rx(char c) · line 613
Quoted 12 lines
xen/drivers/char/console.c +8
-2} - +/* +* Deliver input to the PV shim console. +*/ if (consoled_is_enabled () ) -consoled_guest_tx (c); + rc =consoled_guest_tx (c); + +if ( rc && rc != -ENODEV ) +printk (KERN_WARNING "console input domain %d: not ready: %d\n" , + d->domain_id, rc);
XENLOG_ERR instead of KERN_WARNING, and use %pd to print domains, ie:
printk(XENLOG_ERR "%pd: delivery of console input failed: %d\n",
d, rc);
And I wonder whether this should be printed just once per domain, or whether the domain should be marked as not having a console (is_console = false) after delivery of input keys failed.
Otherwise you could spam the console with such error messages on every serial key press.
Quoted 7 lines
xen/drivers/char/console.c +7
-0+} + +static void __serial_rx (char c) +{ +struct domain *d; + +if ( console_owner ==DOMID_XEN )
xen/drivers/char/console.c static void __serial_rx(char c) · line 630
Quoted 10 lines
xen/drivers/char/console.c +10
-0+ { +handle_keypress (c, false); +return ; + } + + d =rcu_lock_domain_console_owner (); +if ( d ==NULL ) +return ; + +handle_keypress_in_domain (d, c);
Is __serial_rx() the only caller of handle_keypress_in_domain() after the series? If so, I'm not sure it's worth placing this logic in a separate function.
Thanks, Roger.
Re: [PATCH v2 22/35] xen/console: introduce handle_keypress_in_domain()
Quoted 38 lines · Roger Pau Monné
Quoted 34 lines · On Thu, Dec 05, 2024 at 08:41:52PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
With introduction of NS8250 emulator for x86, the logic of switching console focus gets more convoluted: HVM domain w/ NS8205 must be able to receive the physical console input for guest VM debugging.
Also, existing code does not honor
hardware_dom=xen command line parameter (hardware domain ID does not necessarily starts from 0).Introduce
handle_keypress_in_domain()to account for all scenarios of console input forwarding.Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 72 +++++++++++++++++++++++++++-------------------1 file changed, 42 insertions(+), 30 deletions(-)xen/drivers/char/console.c +2
-5@@ -570,14 +570,16 @@ static void console_init_owner(void)console_set_owner (domid); } -static void __serial_rx (char c) +static void handle_keypress_in_domain (struct domain *d,char c) { -switch ( console_owner ) - { -case DOMID_XEN : -return handle_keypress (c, false); +int rc =0 ;
Quoted 9 lines
xen/drivers/char/console.c static void console_init_owner(void) · line 581
Quoted 6 lines
xen/drivers/char/console.c +5
-1-case 0 : +/* +* Deliver input to the hardware domain buffer. +* NB: must be the first check: hardware domain may have emulated UART. +*/ +if ( d == hardware_domain )
is_hardware_domain(d)
Fixed.
Quoted 31 lines
Quoted 31 lines
xen/drivers/char/console.c +1
-22+ {/* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -590,34 +592,44 @@ 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_owner); - - / - * If we have a properly initialized vpl011 console for the - * domain, without a full PV ring to Dom0 (in that case input - * comes from the PV ring), then send the character to it. - / - if ( d != NULL ) - vpl011_rx_char_xen(d, c); - else - printk("Cannot send chars to Dom%d: no UART available\n", - console_owner); - -if ( d !=NULL ) -rcu_unlock_domain (d); - -break ;
Quoted 8 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 598
Quoted 4 lines
xen/drivers/char/console.c +3
-0} +/ +* Deliver input to the emulated UART. +*/ For one-line comments you can use:
/* Deliver input to the emulated UART. */
Fixed.
Quoted 2 lines
I would however place the comment inside the
ifbody.
Sure, no problem. Fixed.
Quoted 10 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 603
Quoted 6 lines
xen/drivers/char/console.c +4
-0+else if (domain_has_vuart (d) ) + { +#if defined(CONFIG_SBSA_VUART_CONSOLE ) + rc =vpl011_rx_char_xen (d, c);#endif You can possibly make the preprocessor conditional also contain the if condition itself? As otherwise the if condition is dead code.
I removed the ifdef in v3 and reworked domain_has_vuart()
so that it checks build flag and d->arch.emulated_flags under the hood.
Quoted 16 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 613
Quoted 13 lines
xen/drivers/char/console.c +8
-2} - +/* +* Deliver input to the PV shim console. +*/ if (consoled_is_enabled () ) -consoled_guest_tx (c); + rc =consoled_guest_tx (c); + +if ( rc && rc != -ENODEV ) +printk (KERN_WARNING "console input domain %d: not ready: %d\n" , + d->domain_id, rc);
XENLOG_ERRinstead ofKERN_WARNING, and use %pd to print domains, ie:
Addressed.
Quoted 10 lines
printk(XENLOG_ERR "%pd: delivery of console input failed: %d\n", d, rc);And I wonder whether this should be printed just once per domain, or whether the domain should be marked as not having a console (
is_console= false) after delivery of input keys failed.Otherwise you could spam the console with such error messages on every serial key press.
Thanks; fixed.
Quoted 15 lines
Quoted 15 lines
xen/drivers/char/console.c +14
-0+} + +static void __serial_rx (char c) +{ +struct domain *d; + +if ( console_owner ==DOMID_XEN ) + { +handle_keypress (c, false); +return ; + } + + d =rcu_lock_domain_console_owner (); +if ( d ==NULL )
Quoted 8 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 630
Quoted 3 lines
xen/drivers/char/console.c +3
-0+return ; + +handle_keypress_in_domain (d, c);Is
__serial_rx()the only caller ofhandle_keypress_in_domain()after the series? If so, I'm not sure it's worth placing this logic in a separate function.
Yep, that is the only caller; fixed.
Quoted 2 lines
Thanks, Roger.
PATCH v2 23/35 xen/console: introduce console_write()
In reply to Denis MukhinPV Linux kernel uses HYPERVISOR_console_io hypercall for early console which ends up being handled by Xen's console driver's guest_console_write().
guest_console_write() duplicates the code from __putstr(), elimitate code duplication.
--- xen/drivers/char/console.c | 97 +++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 44 deletions(-)
xen/drivers/char/console.c +53 -44
@@ -63,6 +63,8 @@ static const char __initconst warning_sync_console[] ="However it can introduce SIGNIFICANT latencies and affect\n" "timekeeping. It is NOT recommended for production use!\n" ; +/* Flag: use conring for early console; switches to opt_console_to_ring */ +static bool __read_mostly use_conring = true;/* console_to_ring: send guest (incl. dom 0) console data to console ring. */ static bool __read_mostly opt_console_to_ring;boolean_param ("console_to_ring" , opt_console_to_ring);
@@ -661,6 +663,16 @@ static void cf_check notify_dom0_con_ring(void *unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, NULL); +static bool console_locks_busted; + +static void conring_write (const char *str,size_t len) +{ +conring_puts (str, len); + +if ( !console_locks_busted ) +tasklet_schedule (¬ify_dom0_con_ring_tasklet); +} +#ifdef CONFIG_X86 static inline void xen_console_write_debug_port (const char *buf,size_t len) {
@@ -669,8 +681,44 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) : "=&S" (tmp), "=&c" (tmp) : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) ); } + +static void xen_console_write (const char *str,size_t len) +{ +if ( xen_guest ) +xen_hypercall_console_write (str, len); +else +xen_console_write_debug_port (str, len); +} +#else +static inline void xen_console_write (const char *str,size_t len) +{ +}#endif +/* +* Write characters to console. +* +* That will handle all possible scenarios working w/ console +* - serial console; +* - video output; +* - __HYPERVISOR_console_io hypercall (x86 only); +* - debug I/O port (x86 only); +* - forward to Xen event channel. +*/ +static void console_write (const char *str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); + +if ( opt_console_xen ) +xen_console_write (str, len); + +if ( use_conring ) +conring_write (str, len); +} +static long guest_console_write (XEN_GUEST_HANDLE_PARAM (char ) buffer,unsigned int count) {
@@ -691,28 +739,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,if (is_hardware_domain (cd) ) { -/* Use direct console output as it could be interactive */ nrspin_lock_irq (&console_lock); - -console_serial_puts (kbuf, kcount); -video_puts (kbuf, kcount); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (kbuf, kcount); -else -xen_console_write_debug_port (kbuf, kcount); - } -#endif - -if ( opt_console_to_ring ) - { -conring_puts (kbuf, kcount); -tasklet_schedule (¬ify_dom0_con_ring_tasklet); - } - +console_write (kbuf, kcount);nrspin_unlock_irq (&console_lock); }else
@@ -813,31 +841,9 @@ long do_console_io(* ***************************************************** */ -static bool console_locks_busted; -static void __putstr (const char *str) { -size_t len =strlen (str); - -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (str, len); -else -xen_console_write_debug_port (str, len); - } -#endif - -conring_puts (str, len); - -if ( !console_locks_busted ) -tasklet_schedule (¬ify_dom0_con_ring_tasklet); +console_write (str,strlen (str)); }static int printk_prefix_check (char *p,char **pp)
@@ -1171,6 +1177,9 @@ void __init console_endboot(void)video_endboot (); + use_conring = opt_console_to_ring; +smp_wmb (); +register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,
Signature · 1 line
2.34.1
Re: [PATCH v2 23/35] xen/console: introduce console_write()
Quoted 7 lines · On Thu, Dec 05, 2024 at 08:41:53PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
PV Linux kernel uses
HYPERVISOR_console_iohypercall for early console which ends up being handled by Xen's console driver'sguest_console_write().
guest_console_write()duplicates the code from__putstr(), elimitate code duplication.
It might be better to split the code that unifies guest_console_write() and __putstr() as a non-functional change. While the introduction of use_conring is likely a functional change.
Quoted 10 lines
Signed-off-by Denis Mukhin <[email protected]>--- xen/drivers/char/console.c | 97 +++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 44 deletions(-)xen/drivers/char/console.c +0
-0
xen/drivers/char/console.c static const char __initconst warning_sync_console[] = · line 67
Quoted 5 lines
xen/drivers/char/console.c +2
-0@@ -63,6 +63,8 @@ static const char __initconst warning_sync_console[] ="However it can introduce SIGNIFICANT latencies and affect\n" "timekeeping. It is NOT recommended for production use!\n" ; +/* Flag: use conring for early console; switches to opt_console_to_ring */ +static bool __read_mostly use_conring = true;
__ro_after_init instead of __read_mostly.
Quoted 25 lines
xen/drivers/char/console.c +11
-0/* console_to_ring: send guest (incl. dom 0) console data to console ring. */ static bool __read_mostly opt_console_to_ring;boolean_param ("console_to_ring" , opt_console_to_ring);@@ -661,6 +663,16 @@ static void cf_check notify_dom0_con_ring(void *unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, NULL); +static bool console_locks_busted; + +static void conring_write (const char *str,size_t len) +{ +conring_puts (str, len); + +if ( !console_locks_busted ) +tasklet_schedule (¬ify_dom0_con_ring_tasklet); +} +#ifdef CONFIG_X86 static inline void xen_console_write_debug_port (const char *buf,size_t len) {@@ -669,8 +681,44 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) : "=&S" (tmp), "=&c" (tmp) : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) ); } +
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 694
Quoted 10 lines
xen/drivers/char/console.c +10
-0+static void xen_console_write (const char *str,size_t len) +{ +if ( xen_guest ) +xen_hypercall_console_write (str, len); +else +xen_console_write_debug_port (str, len); +} +#else +static inline void xen_console_write (const char *str,size_t len) +{
opt_console_xen would only be set on x86 with the current command line parsing done in console_init_preirq(), so you could add an ASSERT_UNREACHABLE() here.
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 706
Quoted 12 lines
xen/drivers/char/console.c +10
-0+}#endif +/* +* Write characters to console. +* +* That will handle all possible scenarios working w/ console +* - serial console; +* - video output; +* - __HYPERVISOR_console_io hypercall (x86 only); +* - debug I/O port (x86 only); +* - forward to Xen event channel.
"Xen event channel" is not the correct term. I would use "PV console". The event channel is just used to send the notification.
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 716
Quoted 10 lines
xen/drivers/char/console.c +10
-0+*/ +static void console_write (const char *str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); + +if ( opt_console_xen ) +xen_console_write (str, len);
Are you sure this builds? opt_console_xen is only defined on x86, and AFAICT console_write() is generic. AFAICT you need to keep the X86 preprocessor guards, or alternatively do something like:
#define opt_console_xen false
For non-x86 arches in xen/console.h
Quoted 72 lines
xen/drivers/char/console.c +7
-44+ +if ( use_conring ) +conring_write (str, len); +} +static long guest_console_write (XEN_GUEST_HANDLE_PARAM (char ) buffer,unsigned int count) {@@ -691,28 +739,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,if (is_hardware_domain (cd) ) { -/* Use direct console output as it could be interactive */ nrspin_lock_irq (&console_lock); - -console_serial_puts (kbuf, kcount); -video_puts (kbuf, kcount); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (kbuf, kcount); -else -xen_console_write_debug_port (kbuf, kcount); - } -#endif - -if ( opt_console_to_ring ) - { -conring_puts (kbuf, kcount); -tasklet_schedule (¬ify_dom0_con_ring_tasklet); - } - +console_write (kbuf, kcount);nrspin_unlock_irq (&console_lock); }else @@ -813,31 +841,9 @@ long do_console_io(* ***************************************************** */ -static bool console_locks_busted; -static void __putstr (const char *str) { -size_t len =strlen (str); - -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (str, len); -else -xen_console_write_debug_port (str, len); - } -#endif - -conring_puts (str, len); - -if ( !console_locks_busted ) -tasklet_schedule (¬ify_dom0_con_ring_tasklet); +console_write (str,strlen (str)); }static int printk_prefix_check (char *p,char **pp)
xen/drivers/char/console.c void __init console_endboot(void) · line 1181
Quoted 5 lines
xen/drivers/char/console.c +2
-0@@ -1171,6 +1177,9 @@ void __init console_endboot(void)video_endboot (); + use_conring = opt_console_to_ring; +smp_wmb ();
Do you really need the barrier? If so it would need a comment describing exactly why it's needed. I don't think it's possible for the write to be reordered past the return of the function, which would be enough to ensure correctness?
Thanks, Roger.
Re: [PATCH v2 23/35] xen/console: introduce console_write()
Quoted 9 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:41:53PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
PV Linux kernel uses
HYPERVISOR_console_iohypercall for early console which ends up being handled by Xen's console driver'sguest_console_write().
Quoted 7 lines
Quoted 2 lines
guest_console_write()duplicates the code from__putstr(), elimitate code duplication.It might be better to split the code that unifies
guest_console_write()and__putstr()as a non-functional change. While the introduction ofuse_conringis likely a functional change.
Actually use_conring is not needed.guest_console_write() depends on opt_console_to_ring to call conring_puts() while __putstr() has unconditional call to conring_puts(). I solved this by adding another parameter to console_write().
Quoted 14 lines
Quoted 14 lines
Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 97 +++++++++++++++++++++++++---------------------1 file changed, 53 insertions(+), 44 deletions(-)xen/drivers/char/console.c +0
-0@@ -63,6 +63,8 @@ static const char __initconst warning_sync_console[] ="However it can introduce SIGNIFICANT latencies and affect\n" "timekeeping. It is NOT recommended for production use!\n";
Quoted 5 lines
xen/drivers/char/console.c static const char __initconst warning_sync_console[] = · line 67
Quoted 2 lines
xen/drivers/char/console.c +2
-0+/* Flag: use conring for early console; switches to opt_console_to_ring */ +static bool __read_mostly use_conring = true;
__ro_after_initinstead of__read_mostly.
I dropped use_conring.
Quoted 33 lines
Quoted 33 lines
/*
console_to_ring: send guest (incl. dom 0) console data to console ring. */ static bool__read_mostlyopt_console_to_ring;boolean_param("console_to_ring", opt_console_to_ring);xen/drivers/char/console.c +18
-0@@ -661,6 +663,16 @@ static void cf_check notify_dom0_con_ring(void *unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, NULL); +static bool console_locks_busted; + +static void conring_write (const char *str,size_t len) +{ +conring_puts (str, len); + +if ( !console_locks_busted ) +tasklet_schedule (¬ify_dom0_con_ring_tasklet); +} +#ifdef CONFIG_X86 static inline void xen_console_write_debug_port (const char *buf,size_t len) {@@ -669,8 +681,44 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) : "=&S" (tmp), "=&c" (tmp) : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) ); } + +static void xen_console_write (const char *str,size_t len) +{ +if ( xen_guest ) +xen_hypercall_console_write (str, len); +else +xen_console_write_debug_port (str, len); +}
Quoted 8 lines
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 694
Quoted 3 lines
xen/drivers/char/console.c +3
-0+#else +static inline void xen_console_write (const char *str,size_t len) +{
opt_console_xenwould only be set on x86 with the current command line parsing done inconsole_init_preirq(), so you could add anASSERT_UNREACHABLE()here.
I re-arranged the code, static inline variant is not needed.
Quoted 4 lines
Quoted 4 lines
xen/drivers/char/console.c +1
-0+}#endif
Quoted 13 lines
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 706
Quoted 9 lines
xen/drivers/char/console.c +9
-0+/* +* Write characters to console. +* +* That will handle all possible scenarios working w/ console +* - serial console; +* - video output; +* - __HYPERVISOR_console_io hypercall (x86 only); +* - debug I/O port (x86 only); +* - forward to Xen event channel. "Xen event channel" is not the correct term. I would use "PV console". The event channel is just used to send the notification.
Thank you; fixed.
Quoted 16 lines
xen/drivers/char/console.c static inline void xen_console_write_debug_port(const char *buf, size_t len) · line 716
Quoted 11 lines
xen/drivers/char/console.c +10
-0+*/ +static void console_write (const char *str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); + +if ( opt_console_xen ) +xen_console_write (str, len);Are you sure this builds?
opt_console_xenis only defined on x86, and AFAICTconsole_write()is generic. AFAICT you need to keep the X86 preprocessor guards, or alternatively do something like:
This is strange; CI did pass on that:
https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/1576164352
Fixed.
Quoted 80 lines
#define
opt_console_xenfalseFor non-x86 arches in
xen/console.hQuoted 75 lines
xen/drivers/char/console.c +6
-21+ +if ( use_conring ) +conring_write (str, len); +} +static long guest_console_write (XEN_GUEST_HANDLE_PARAM (char ) buffer,unsigned int count) {@@ -691,28 +739,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,if (is_hardware_domain (cd) ) { -/* Use direct console output as it could be interactive */ nrspin_lock_irq (&console_lock); - -console_serial_puts (kbuf, kcount); -video_puts (kbuf, kcount); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (kbuf, kcount); -else -xen_console_write_debug_port (kbuf, kcount); - } -#endif - -if ( opt_console_to_ring ) - { -conring_puts (kbuf, kcount); -tasklet_schedule (¬ify_dom0_con_ring_tasklet); - } - +console_write (kbuf, kcount);nrspin_unlock_irq (&console_lock); }else
xen/drivers/char/console.c +1
-23@@ -813,31 +841,9 @@ long do_console_io(* ***************************************************** */ -static bool console_locks_busted; -static void __putstr (const char *str) { -size_t len =strlen (str); - -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); - -#ifdef CONFIG_X86 -if ( opt_console_xen ) - { -if ( xen_guest ) -xen_hypercall_console_write (str, len); -else -xen_console_write_debug_port (str, len); - } -#endif - -conring_puts (str, len); - -if ( !console_locks_busted ) -tasklet_schedule (¬ify_dom0_con_ring_tasklet); +console_write (str,strlen (str)); }static int printk_prefix_check (char *p,char **pp)@@ -1171,6 +1177,9 @@ void __init console_endboot(void)video_endboot ();
Quoted 8 lines
xen/drivers/char/console.c void __init console_endboot(void) · line 1181
Quoted 2 lines
xen/drivers/char/console.c +2
-0+ use_conring = opt_console_to_ring; +smp_wmb ();Do you really need the barrier? If so it would need a comment describing exactly why it's needed. I don't think it's possible for the write to be reordered past the return of the function, which would be enough to ensure correctness?
I see where I got confused: the right place to add this initialization was console_init_postirq(). I dropped the barrier and of use_conring altogether.
Quoted 2 lines
Thanks, Roger.
PATCH v2 24/35 xen/console: introduce hwdom_crashconsole=
In reply to Denis MukhinThe new command line switch hwdom_crashconsole=BOOL allows to switch serial console input focus to xen for machine state inspection using keyhandler mechanism after the hardware domain crashes.
The new command line switch is aliased via dom0=...,crashconsole knob.
Such functionality can be useful while debugging dom0 bringup.
--- docs/misc/xen-command-line.pandoc | 5 +++++ xen/arch/x86/dom0_build.c | 2 ++ xen/common/domain.c | 14 +++++++++++++- xen/include/xen/domain.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.pandoc +5 -0
@@ -806,6 +806,7 @@ Specify the bit width of the DMA heap. ### dom0 = List of [ pv | pvh, shadow=<bool>, verbose=<bool>, + crashconsole=<bool>, cpuid-faulting=<bool>, msr-relaxed=<bool> ] (x86) = List of [ sve=<integer> ] (Arm64)
@@ -839,6 +840,10 @@ Controls for how dom0 is constructed on x86 systems. information during the dom0 build. It defaults to the compile time choice of `CONFIG_VERBOSE_DEBUG`. +* The `crashconsole` boolean instructs Xen to drop into emergency console + in case of dom0 crash. May be useful for dom0 bringup on a custom + hardware. + * The `cpuid-faulting` boolean is an interim option, is only applicable to PV dom0, and defaults to true.
xen/arch/x86/dom0_build.c +2 -0
@@ -286,6 +286,8 @@ int __init parse_arch_dom0_param(const char *s, const char *e) opt_dom0_cpuid_faulting = val; else if ( (val = parse_boolean("msr-relaxed", s, e)) >= 0 ) opt_dom0_msr_relaxed = val; + else if ( (val = parse_boolean("crashconsole", s, e)) >= 0 ) + opt_hwdom_crashconsole = !!val; else return -EINVAL;
xen/common/domain.c +13 -1
@@ -56,6 +56,13 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX;bool opt_dom0_vcpus_pin;boolean_param ("dom0_vcpus_pin" , opt_dom0_vcpus_pin); +/* +* Hardware domain crash handler: if true, do not halt machine, but switch to +* Xen console for debugging. +*/ +bool opt_hwdom_crashconsole; +boolean_param ("hwdom_crashconsole" , opt_hwdom_crashconsole); +/* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK (domlist_update_lock);DEFINE_RCU_READ_LOCK (domlist_read_lock);
@@ -1138,7 +1145,12 @@ int domain_shutdown(struct domain *d, u8 reason) reason = d->shutdown_code;if (is_hardware_domain (d) ) -hwdom_shutdown (reason); + { +if ( opt_hwdom_crashconsole ) +console_set_owner (DOMID_XEN ); +else +hwdom_shutdown (reason); + }if ( d->is_shutting_down ) {
xen/include/xen/domain.h +1 -0
@@ -150,6 +150,7 @@ extern unsigned int xen_processor_pmbits;extern bool opt_dom0_vcpus_pin;extern cpumask_t dom0_cpus;extern bool dom0_affinity_relaxed; +extern bool opt_hwdom_crashconsole;/* vnuma topology per domain. */ struct vnuma_info {
Signature · 1 line
2.34.1
Re: [PATCH v2 24/35] xen/console: introduce hwdom_crashconsole=
Quoted 31 lines · On Thu, Dec 05, 2024 at 08:41:54PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
The new command line switch
hwdom_crashconsole=BOOLallows to switch serial console input focus to xen for machine state inspection using keyhandler mechanism after the hardware domain crashes.The new command line switch is aliased via
dom0=...,crashconsoleknob.Such functionality can be useful while debugging dom0 bringup.
Signed-off-by Denis Mukhin <[email protected]>--- docs/misc/xen-command-line.pandoc | 5 +++++ xen/arch/x86/dom0_build.c | 2 ++ xen/common/domain.c | 14 +++++++++++++- xen/include/xen/domain.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-)docs/misc/xen-command-line.pandoc +1
-0@@ -806,6 +806,7 @@ Specify the bit width of the DMA heap. ### dom0 = List of [ pv | pvh, shadow=<bool>, verbose=<bool>, + crashconsole=<bool>, cpuid-faulting=<bool>, msr-relaxed=<bool> ] (x86) = List of [ sve=<integer> ] (Arm64)
docs/misc/xen-command-line.pandoc Controls for how dom0 is constructed on x86 systems. · line 844
Quoted 5 lines
docs/misc/xen-command-line.pandoc +2
-0@@ -839,6 +840,10 @@ Controls for how dom0 is constructed on x86 systems. information during the dom0 build. It defaults to the compile time choice of `CONFIG_VERBOSE_DEBUG`. +* The `crashconsole` boolean instructs Xen to drop into emergency console + in case of dom0 crash. May be useful for dom0 bringup on a custom
I think the 'a' is unneeded -> "on custom hardware."
I think however this would be clearer as:
"The crashconsole boolean instructs Xen to switch input console focus to the hypervisor when dom0 shuts down and avoid performing dom0 domain destruction. Should only be used for debugging purposes."
It's IMO not clear what "instructs Xen to drop into emergency console" implies for Xen.
Quoted 23 lines
docs/misc/xen-command-line.pandoc +2
-0+ hardware. + * The `cpuid-faulting` boolean is an interim option, is only applicable to PV dom0, and defaults to true.xen/arch/x86/dom0_build.c +2
-0@@ -286,6 +286,8 @@ int __init parse_arch_dom0_param(const char *s, const char *e) opt_dom0_cpuid_faulting = val; else if ( (val = parse_boolean("msr-relaxed", s, e)) >= 0 ) opt_dom0_msr_relaxed = val; + else if ( (val = parse_boolean("crashconsole", s, e)) >= 0 ) + opt_hwdom_crashconsole = !!val; else return -EINVAL;xen/common/domain.c +0
-0
xen/common/domain.c unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; · line 63
Quoted 8 lines
xen/common/domain.c +5
-0@@ -56,6 +56,13 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX;bool opt_dom0_vcpus_pin;boolean_param ("dom0_vcpus_pin" , opt_dom0_vcpus_pin); +/* +* Hardware domain crash handler: if true, do not halt machine, but switch to +* Xen console for debugging. +*/ +bool opt_hwdom_crashconsole;
__ro_after_init.
xen/common/domain.c unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; · line 64
Quoted 1 line
xen/common/domain.c +1
-0+boolean_param ("hwdom_crashconsole" , opt_hwdom_crashconsole);
This option doesn't seem to be documented at all in xen-command-line.pandoc?
xen/common/domain.c int domain_shutdown(struct domain *d, u8 reason) · line 1150
Quoted 12 lines
xen/common/domain.c +4
-1+/* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK (domlist_update_lock);DEFINE_RCU_READ_LOCK (domlist_read_lock);@@ -1138,7 +1145,12 @@ int domain_shutdown(struct domain *d, u8 reason) reason = d->shutdown_code;if (is_hardware_domain (d) ) -hwdom_shutdown (reason); + { +if ( opt_hwdom_crashconsole ) +console_set_owner (DOMID_XEN );
Don't you need to pause all domain vCPUs and return early here to avoid executing the rest of the function, that will likely destroy the domain?
Maybe there's something I'm missing that prevents the hardware domain destruction.
Thanks, Roger.
Re: [PATCH v2 24/35] xen/console: introduce hwdom_crashconsole=
Quoted 38 lines · Roger Pau Monné
Quoted 34 lines · On Thu, Dec 05, 2024 at 08:41:54PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
The new command line switch
hwdom_crashconsole=BOOLallows to switch serial console input focus to xen for machine state inspection using keyhandler mechanism after the hardware domain crashes.The new command line switch is aliased via
dom0=...,crashconsoleknob.Such functionality can be useful while debugging dom0 bringup.
Signed-off-by Denis Mukhin [email protected]---
docs/misc/xen-command-line.pandoc | 5 +++++xen/arch/x86/dom0_build.c| 2 ++xen/common/domain.c| 14 +++++++++++++-xen/include/xen/domain.h| 1 +4 files changed, 21 insertions(+), 1 deletion(-)docs/misc/xen-command-line.pandoc +1
-0@@ -806,6 +806,7 @@ Specify the bit width of the DMA heap. ### dom0 = List of [ pv | pvh, shadow=<bool>, verbose=<bool>, + crashconsole=<bool>, cpuid-faulting=<bool>, msr-relaxed=<bool> ] (x86) = List of [ sve=<integer> ] (Arm64)@@ -839,6 +840,10 @@ Controls for how dom0 is constructed on x86 systems.information during the dom0 build. It defaults to the compile time choice of
CONFIG_VERBOSE_DEBUG.
Quoted 5 lines
Quoted 2 lines
+* The
crashconsoleboolean instructs Xen to drop into emergency console
+ in case of dom0 crash. May be useful for dom0 bringup on a customI think the 'a' is unneeded -> "on custom hardware."
Yep. Thank you.
Quoted 8 lines
I think however this would be clearer as:
"The
crashconsoleboolean instructs Xen to switch input console focus to the hypervisor when dom0 shuts down and avoid performing dom0 domain destruction. Should only be used for debugging purposes."
Fixed.
Quoted 30 lines
It's IMO not clear what "instructs Xen to drop into emergency console" implies for Xen.
Quoted 26 lines
+ hardware.
+
* Thecpuid-faultingboolean is an interim option, is only applicable to PV dom0, and defaults to true.xen/arch/x86/dom0_build.c +2
-0@@ -286,6 +286,8 @@ int __init parse_arch_dom0_param(const char *s, const char *e) opt_dom0_cpuid_faulting = val; else if ( (val = parse_boolean("msr-relaxed", s, e)) >= 0 ) opt_dom0_msr_relaxed = val; + else if ( (val = parse_boolean("crashconsole", s, e)) >= 0 ) + opt_hwdom_crashconsole = !!val;else
return-EINVAL;xen/common/domain.c +0
-0@@ -56,6 +56,13 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX;bool opt_dom0_vcpus_pin;boolean_param ("dom0_vcpus_pin" , opt_dom0_vcpus_pin);
Quoted 8 lines
xen/common/domain.c unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; · line 63
Quoted 5 lines
xen/common/domain.c +5
-0+/* +* Hardware domain crash handler: if true, do not halt machine, but switch to +* Xen console for debugging. +*/ +bool opt_hwdom_crashconsole;
__ro_after_init.
Done.
Quoted 6 lines
xen/common/domain.c unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; · line 64
Quoted 2 lines
xen/common/domain.c +1
-0+boolean_param ("hwdom_crashconsole" , opt_hwdom_crashconsole);This option doesn't seem to be documented at all in xen-command-line.pandoc?
Thanks; fixed.
Quoted 19 lines
xen/common/domain.c int domain_shutdown(struct domain *d, u8 reason) · line 1150
Quoted 13 lines
xen/common/domain.c +4
-1+/* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK (domlist_update_lock);DEFINE_RCU_READ_LOCK (domlist_read_lock);@@ -1138,7 +1145,12 @@ int domain_shutdown(struct domain *d, u8 reason) reason = d->shutdown_code;if (is_hardware_domain (d) ) -hwdom_shutdown (reason); + { +if ( opt_hwdom_crashconsole ) +console_set_owner (DOMID_XEN );Don't you need to pause all domain vCPUs and return early here to avoid executing the rest of the function, that will likely destroy the domain?
Quoted 2 lines
Maybe there's something I'm missing that prevents the hardware domain destruction.
The point of this change is to drop the user to Xen console on crash instead of unconditional system restart. TBH, I did not plan for "freezing" the domain state. I also tested w/ non-hyperlaunch PV dom0 only (I used kexec to start PV dom0 which was crashing).
My understanding, if I followed the code correctly, all is fine. domain_destroy() is not called because asm_domain_crash_synchronous(), which handles the crash, just spins around do_softirq():
void asm_domain_crash_synchronous(unsigned long addr) {
...
__domain_crash(current->domain); // that will call domain_crash()
for ( ; ; )
do_softirq();
}Quoted 2 lines
Thanks, Roger.
PATCH v2 25/35 xen/console: simplify console owner switch hint
In reply to Denis MukhinUpdate the hint w/ the combination of keys to press to switch physical console to the next owner.
--- xen/drivers/char/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/char/console.c +2 -2
@@ -528,8 +528,8 @@ int console_set_owner(domid_t domid) console_owner = domid;if ( switch_code ) -printk (" (type 'CTRL-%c' three times to switch input)" , - opt_conswitch[0 ]); +printk (" (type 'CTRL-%c%c%c' to switch input)" , + opt_conswitch[0 ], opt_conswitch[0 ], opt_conswitch[0 ]);printk ("\n" );return 0 ;
Signature · 1 line
2.34.1
PATCH v2 26/35 xen/console: make console buffer size configurable
In reply to Denis MukhinAdd new CONRING_LOG_SHIFT Kconfig parameter to specify the boot console buffer size as a power of 2.
Bump default size to 32 KiB.
--- xen/drivers/char/Kconfig | 23 +++++++++++++++++++++++ xen/drivers/char/console.c | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-)
xen/drivers/char/Kconfig +23 -0
@@ -96,6 +96,29 @@ config SERIAL_TX_BUFSIZE Default value is 32768 (32KiB). +config CONRING_LOG_SHIFT + int "Console buffer size" + range 14 25 + default 15 + help + Select the boot console buffer size as a power of 2. + Run-time console buffer size is the same as the boot console size, + unless enforced via 'conring_size=' boot parameter. + + Examples: + 25 => 32 MiB + 24 => 16 MiB + 23 => 8 MiB + 22 => 4 MiB + 21 => 2 MiB + 20 => 1 MiB + 19 => 512 KiB + 18 => 256 KiB + 17 => 128 KiB + 16 => 64 KiB + 15 => 32 KiB + 14 => 16 KiB + config XHCI bool "XHCI DbC UART driver" depends on X86
xen/drivers/char/console.c +2 -2
@@ -104,11 +104,11 @@ static int cf_check parse_console_timestamps(const char *s);custom_runtime_param ("console_timestamps" , parse_console_timestamps, con_timestamp_mode_upd); -/* conring_size: allows a large console ring than default (16kB). */ +/* conring_size: allows a large console ring than default (32 KiB). */ static uint32_t __initdata opt_conring_size;size_param ("conring_size" , opt_conring_size); -#define _CONRING_SIZE 16384 +#define _CONRING_SIZE (1U << CONFIG_CONRING_LOG_SHIFT)#define CONRING_IDX_MASK (i) ((i)&(conring_size-1))static char __initdata _conring[_CONRING_SIZE];static char *__read_mostly conring = _conring;
Signature · 1 line
2.34.1
Re: [PATCH v2 26/35] xen/console: make console buffer size configurable
Quoted 9 lines · On Thu, Dec 05, 2024 at 08:41:56PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Add new
CONRING_LOG_SHIFTKconfigparameter to specify the boot console buffer size as a power of 2.Bump default size to 32 KiB.
Thanks for taking care of this.
Quoted 25 lines
--- xen/drivers/char/Kconfig | 23 +++++++++++++++++++++++ xen/drivers/char/console.c | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-)xen/drivers/char/Kconfig +12
-0@@ -96,6 +96,29 @@ config SERIAL_TX_BUFSIZE Default value is 32768 (32KiB). +config CONRING_LOG_SHIFT + int "Console buffer size" + range 14 25 + default 15 + help + Select the boot console buffer size as a power of 2. + Run-time console buffer size is the same as the boot console size, + unless enforced via 'conring_size=' boot parameter. + + Examples: + 25 => 32 MiB + 24 => 16 MiB
xen/drivers/char/Kconfig config SERIAL_TX_BUFSIZE · line 120
Quoted 10 lines
xen/drivers/char/Kconfig +10
-0+ 23 => 8 MiB + 22 => 4 MiB + 21 => 2 MiB + 20 => 1 MiB + 19 => 512 KiB + 18 => 256 KiB + 17 => 128 KiB + 16 => 64 KiB + 15 => 32 KiB + 14 => 16 KiB
It might be better to do something similar to what we do in SERIAL_TX_BUFSIZE, that the user provides a value in KiB which is rounded down to the nearest power of 2?
Quoted 9 lines
xen/drivers/char/Kconfig +1
-0+ config XHCI bool "XHCI DbC UART driver" depends on X86xen/drivers/char/console.c +0
-0
xen/drivers/char/console.c static int cf_check parse_console_timestamps(const char *s); · line 109
Quoted 7 lines
xen/drivers/char/console.c +1
-1@@ -104,11 +104,11 @@ static int cf_check parse_console_timestamps(const char *s);custom_runtime_param ("console_timestamps" , parse_console_timestamps, con_timestamp_mode_upd); -/* conring_size: allows a large console ring than default (16kB). */ +/* conring_size: allows a large console ring than default (32 KiB). */ static uint32_t __initdata opt_conring_size;size_param ("conring_size" , opt_conring_size);
You also need to update xen-command-line.pandoc to mention the default size is now set in Kconfig. And here I would mention CONFIG_CONRING_SIZE rather than explicit 32 KiB, because that's just the default in Kconfig, but might not be the default in the build itself.
FWIW, you could define:
#define _CONRING_SIZE (CONFIG_CONRING_SIZE & (CONFIG_CONRING_SIZE - 1))
Thanks, Roger.
Re: [PATCH v2 26/35] xen/console: make console buffer size configurable
Quoted 49 lines · Roger Pau Monné
Quoted 9 lines · On Thu, Dec 05, 2024 at 08:41:56PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Add new
CONRING_LOG_SHIFTKconfigparameter to specify the boot console buffer size as a power of 2.Bump default size to 32 KiB.
Thanks for taking care of this.
Quoted 32 lines
---
xen/drivers/char/Kconfig | 23 +++++++++++++++++++++++xen/drivers/char/console.c| 4 ++--2 files changed, 25 insertions(+), 2 deletions(-)xen/drivers/char/Kconfig +0
-0@@ -96,6 +96,29 @@ config SERIAL_TX_BUFSIZEDefault value is 32768 (32KiB).
xen/drivers/char/Kconfig +19
-0+config CONRING_LOG_SHIFT + int "Console buffer size" + range 14 25 + default 15 + help + Select the boot console buffer size as a power of 2. + Run-time console buffer size is the same as the boot console size, + unless enforced via 'conring_size=' boot parameter. + + Examples: + 25 => 32 MiB + 24 => 16 MiB + 23 => 8 MiB + 22 => 4 MiB + 21 => 2 MiB + 20 => 1 MiB + 19 => 512 KiB + 18 => 256 KiB + 17 => 128 KiB
Quoted 8 lines
Quoted 3 lines
+ 16 => 64 KiB
+ 15 => 32 KiB
+ 14 => 16 KiBIt might be better to do something similar to what we do in
SERIAL_TX_BUFSIZE, that the user provides a value in KiB which is rounded down to the nearest power of 2?
TBH, I do not think there should be a way for the user to allow reserving huge amounts of RAM for the console ring. Plus, using logarithmic scale may avoid confusion, w/o it user-defined CONFIG_CONRING_SIZE will not necessarily match the real _CONRING_SIZE value.
But I see your point: Kconfig should match existing conring_size= spec which defines number of bytes.
Quoted 13 lines
Quoted 13 lines
+
config XHCI
bool "XHCI DbC UART driver"
depends on X86xen/drivers/char/console.c +0
-0@@ -104,11 +104,11 @@ static int cf_check parse_console_timestamps(const char *s);custom_runtime_param ("console_timestamps" , parse_console_timestamps, con_timestamp_mode_upd);
Quoted 11 lines
xen/drivers/char/console.c static int cf_check parse_console_timestamps(const char *s); · line 109
Quoted 4 lines
xen/drivers/char/console.c +1
-1-/* conring_size: allows a large console ring than default (16kB). / +/ conring_size: allows a large console ring than default (32 KiB). */ static uint32_t __initdata opt_conring_size;size_param ("conring_size" , opt_conring_size);You also need to update xen-command-line.pandoc to mention the default size is now set in
Kconfig. And here I would mentionCONFIG_CONRING_SIZErather than explicit 32 KiB, because that's just the default inKconfig, but might not be the default in the build itself.
Done.
Quoted 4 lines
FWIW, you could define:
#define
_CONRING_SIZE(CONFIG_CONRING_SIZE& (CONFIG_CONRING_SIZE- 1))
Done.
Quoted 2 lines
Thanks, Roger.
PATCH v2 27/35 xen/console: flush console ring to physical console
In reply to Denis MukhinMessages printed before the serial and VGA consoles are initialized end up in the internal console buffer (conring). Flush contents of conring to all external consoles after external consoles are fully initialied.
--- xen/drivers/char/console.c | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-)
xen/drivers/char/console.c +39 -15
@@ -426,23 +426,35 @@ void console_serial_puts(const char *s, size_t nr)pv_console_puts (s, nr); } -static void cf_check dump_console_ring_key(unsigned char key) +/* +* Write characters to physical console(s). +* That covers: +* - serial console; +* - video output. +*/ +static void console_puts (const char *str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); +} + +/* +* Flush contents of the conring to the physical console devices. +*/ +static int console_flush (void ) {uint32_t idx, len, sofar, c;unsigned int order;char *buf; -printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); - -/* create a buffer in which we'll copy the ring in the correct -order and NUL terminate */ order =get_order_from_bytes (conring_size +1 ); buf =alloc_xenheap_pages (order,0 );if ( buf ==NULL ) - { -printk ("unable to allocate memory!\n" ); -return ; - } +return -ENOMEM ; + +nrspin_lock_irq (&console_lock); c = conringc; sofar =0 ;
@@ -457,10 +469,23 @@ static void cf_check dump_console_ring_key(unsigned char key) c += len; } -console_serial_puts (buf, sofar); -video_puts (buf, sofar); +console_puts (buf, sofar); + +nrspin_unlock_irq (&console_lock);free_xenheap_pages (buf, order); + +return 0 ; +} + +static void cf_check dump_console_ring_key(unsigned char key) +{ +int rc; + +printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); + rc =console_flush (); +if ( rc ) +printk ("failed to dump console ring buffer: %d\n" , rc); }/*
@@ -707,10 +732,7 @@ static inline void xen_console_write(const char *str, size_t len)*/ static void console_write (const char *str,size_t len) { -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); +console_puts (str, len);if ( opt_console_xen )xen_console_write (str, len);
@@ -1177,6 +1199,8 @@ void __init console_endboot(void)video_endboot (); +/* NB: send conring contents to all enabled physical consoles, if any */ +console_flush (); use_conring = opt_console_to_ring;smp_wmb ();
Signature · 1 line
2.34.1
Re: [PATCH v2 27/35] xen/console: flush console ring to physical console
Quoted 100 lines · On Thu, Dec 05, 2024 at 08:41:57PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Messages printed before the serial and VGA consoles are initialized end up in the internal console buffer (conring). Flush contents of conring to all external consoles after external consoles are fully initialied.
--- xen/drivers/char/console.c | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-)xen/drivers/char/console.c +37
-15@@ -426,23 +426,35 @@ void console_serial_puts(const char *s, size_t nr)pv_console_puts (s, nr); } -static void cf_check dump_console_ring_key(unsigned char key) +/* +* Write characters to physical console(s). +* That covers: +* - serial console; +* - video output. +*/ +static void console_puts (const char *str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); +} + +/* +* Flush contents of the conring to the physical console devices. +*/ +static int console_flush (void ) {uint32_t idx, len, sofar, c;unsigned int order;char *buf; -printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); - -/* create a buffer in which we'll copy the ring in the correct -order and NUL terminate */ order =get_order_from_bytes (conring_size +1 ); buf =alloc_xenheap_pages (order,0 );if ( buf ==NULL ) - { -printk ("unable to allocate memory!\n" ); -return ; - } +return -ENOMEM ; + +nrspin_lock_irq (&console_lock); c = conringc; sofar =0 ;@@ -457,10 +469,23 @@ static void cf_check dump_console_ring_key(unsigned char key) c += len; } -console_serial_puts (buf, sofar); -video_puts (buf, sofar); +console_puts (buf, sofar); + +nrspin_unlock_irq (&console_lock);free_xenheap_pages (buf, order); + +return 0 ; +} + +static void cf_check dump_console_ring_key(unsigned char key) +{ +int rc; + +printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); + rc =console_flush (); +if ( rc ) +printk ("failed to dump console ring buffer: %d\n" , rc); }/* @@ -707,10 +732,7 @@ static inline void xen_console_write(const char *str, size_t len)*/ static void console_write (const char *str,size_t len) { -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); +console_puts (str, len);if ( opt_console_xen )xen_console_write (str, len);
xen/drivers/char/console.c void __init console_endboot(void) · line 1203
Quoted 5 lines
xen/drivers/char/console.c +2
-0@@ -1177,6 +1199,8 @@ void __init console_endboot(void)video_endboot (); +/* NB: send conring contents to all enabled physical consoles, if any */ +console_flush ();
This is way too late: at this point Xen has already finished booting, and is about to handover execution to dom0. Flushing here will result in duplicating almost all Xen output already printed?
The flush needs to be done inside of console_init_preirq(), just before printing xen_banner() I think. This sequentially after the console has been initialized. Otherwise you are just duplicating messages.
Thanks, Roger.
Re: [PATCH v2 27/35] xen/console: flush console ring to physical console
Quoted 107 lines · Roger Pau Monné
Quoted 103 lines · On Thu, Dec 05, 2024 at 08:41:57PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Messages printed before the serial and VGA consoles are initialized end up in the internal console buffer (conring). Flush contents of conring to all external consoles after external consoles are fully initialied.
---
xen/drivers/char/console.c| 54 +++++++++++++++++++++++++++++++++-------------1 file changed, 39 insertions(+), 15 deletions(-)xen/drivers/char/console.c +37
-15@@ -426,23 +426,35 @@ void console_serial_puts(const char *s, size_t nr)pv_console_puts(s, nr); } -static void cf_check dump_console_ring_key(unsigned char key) +/* +* Write characters to physical console(s). +* That covers: +* - serial console; +* - video output. +*/ +static void console_puts (const char str,size_t len) +{ +ASSERT (rspin_is_locked (&console_lock)); + +console_serial_puts (str, len); +video_puts (str, len); +} + +/ + * Flush contents of the conring to the physical console devices. + */ +static int console_flush(void) {uint32_t idx, len, sofar, c;unsigned int order;char *buf; -printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); - -/* create a buffer in which we'll copy the ring in the correct -order and NUL terminate */ order =get_order_from_bytes (conring_size +1 ); buf =alloc_xenheap_pages (order,0 );if ( buf ==NULL ) - { -printk ("unable to allocate memory!\n" ); -return ; - } +return -ENOMEM ; + +nrspin_lock_irq (&console_lock); c = conringc; sofar =0 ;@@ -457,10 +469,23 @@ static void cf_check dump_console_ring_key(unsigned char key) c += len; } -console_serial_puts (buf, sofar); -video_puts (buf, sofar); +console_puts (buf, sofar); + +nrspin_unlock_irq (&console_lock);free_xenheap_pages (buf, order); + +return 0 ; +} + +static void cf_check dump_console_ring_key(unsigned char key) +{ +int rc; + +printk ("'%c' pressed -> dumping console ring buffer (dmesg)\n" , key); + rc =console_flush (); +if ( rc ) +printk ("failed to dump console ring buffer: %d\n" , rc); }/* @@ -707,10 +732,7 @@ static inline void xen_console_write(const char *str, size_t len)*/ static void console_write (const char *str,size_t len) { -ASSERT (rspin_is_locked (&console_lock)); - -console_serial_puts (str, len); -video_puts (str, len); +console_puts (str, len);if ( opt_console_xen )xen_console_write (str, len);@@ -1177,6 +1199,8 @@ void __init console_endboot(void)video_endboot ();
Quoted 7 lines
xen/drivers/char/console.c void __init console_endboot(void) · line 1203
Quoted 2 lines
xen/drivers/char/console.c +2
-0+/* NB: send conring contents to all enabled physical consoles, if any */ +console_flush ();This is way too late: at this point Xen has already finished booting, and is about to handover execution to dom0. Flushing here will result in duplicating almost all Xen output already printed?
Yes, indeed; fixed.
Quoted 5 lines
The flush needs to be done inside of
console_init_preirq(), just before printingxen_banner()I think. This sequentially after the console has been initialized. Otherwise you are just duplicating messages.
Fixed.
Quoted 2 lines
Thanks, Roger.
PATCH v2 28/35 xen/8250-uart: add missing definitions
In reply to Denis MukhinAdded missing definitions needed for NS8250 UART emulator.
--- xen/include/xen/8250-uart.h | 81 +++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 21 deletions(-)
xen/include/xen/8250-uart.h +60 -21
@@ -32,16 +32,22 @@#define UART_MCR 0x04/* Modem control */ #define UART_LSR 0x05/* line status */ #define UART_MSR 0x06/* Modem status */ +#define UART_SCR 0x07/* Scratch pad */ #define UART_USR 0x1f/* Status register (DW) */ #define UART_DLL 0x00/* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01/* divisor latch (ms) (DLAB=1) */ #define UART_XR_EFR 0x09/* Enhanced function register (Exar) */ +/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] */ +#define UART_MAX (UART_SCR + 1) +/* Interrupt Enable Register */ #define UART_IER_ERDAI 0x01/* rx data recv'd */ #define UART_IER_ETHREI 0x02/* tx reg. empty */ #define UART_IER_ELSI 0x04/* rx line status */ #define UART_IER_EMSI 0x08/* MODEM status */ +#define UART_IER_MASK \ + (UART_IER_ERDAI | UART_IER_ETHREI | UART_IER_ELSI | UART_IER_EMSI)/* Interrupt Identification Register */ #define UART_IIR_NOINT 0x01/* no interrupt pending */
@@ -51,12 +57,21 @@#define UART_IIR_THR 0x02/* - tx reg. empty */ #define UART_IIR_MSI 0x00/* - MODEM status */ #define UART_IIR_BSY 0x07/* - busy detect (DW) */ +#define UART_IIR_FE0 BIT(6, U)/* FIFO enable #0 */ +#define UART_IIR_FE1 BIT(7, U)/* FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1)/* FIFO Control Register */ -#define UART_FCR_ENABLE 0x01/* enable FIFO */ -#define UART_FCR_CLRX 0x02/* clear Rx FIFO */ -#define UART_FCR_CLTX 0x04/* clear Tx FIFO */ -#define UART_FCR_DMA 0x10/* enter DMA mode */ +#define UART_FCR_ENABLE BIT(0, U)/* enable FIFO */ +#define UART_FCR_CLRX BIT(1, U)/* clear Rx FIFO */ +#define UART_FCR_CLTX BIT(2, U)/* clear Tx FIFO */ +#define UART_FCR_DMA BIT(3, U)/* enter DMA mode */ +#define UART_FCR_RESERVED0 BIT(4, U)/* reserved; always 0 */ +#define UART_FCR_RESERVED1 BIT(5, U)/* reserved; always 0 */ +#define UART_FCR_RTB0 BIT(6, U)/* receiver trigger bit #0 */ +#define UART_FCR_RTB1 BIT(7, U)/* receiver trigger bit #1 */ +#define UART_FCR_TRG_MASK (UART_FCR_RTB0 | UART_FCR_RTB1) +#define UART_FCR_TRG1 0x00/* Rx FIFO trig lev 1 */ #define UART_FCR_TRG4 0x40/* Rx FIFO trig lev 4 */ #define UART_FCR_TRG8 0x80/* Rx FIFO trig lev 8 */
@@ -64,17 +79,17 @@/* * Note: The FIFO trigger levels are chip specific: -* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 -* PC16550D: 1 4 8 14 xx xx xx xx -* TI16C550A: 1 4 8 14 xx xx xx xx -* TI16C550C: 1 4 8 14 xx xx xx xx -* ST16C550: 1 4 8 14 xx xx xx xx -* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 -* NS16C552: 1 4 8 14 xx xx xx xx -* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 -* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 -* TI16C752: 8 16 56 60 8 16 32 56 -* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA */ #define UART_FCR_R_TRIG_00 0x00#define UART_FCR_R_TRIG_01 0x40
@@ -96,11 +111,31 @@#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ /* Modem Control Register */ -#define UART_MCR_DTR 0x01/* Data Terminal Ready */ -#define UART_MCR_RTS 0x02/* Request to Send */ -#define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ -#define UART_MCR_LOOP 0x10/* Enable loopback test mode */ -#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_DTR BIT(0, U)/* Data Terminal Ready */ +#define UART_MCR_RTS BIT(1, U)/* Request to Send */ +#define UART_MCR_OUT1 BIT(2, U)/* OUT1: interrupt mask */ +#define UART_MCR_OUT2 BIT(3, U)/* OUT2: interrupt mask */ +#define UART_MCR_LOOP BIT(4, U)/* Enable loopback test mode */ +#define UART_MCR_RESERVED0 BIT(5, U)/* Reserved #0 */ +#define UART_MCR_RESERVED1 BIT(6, U)/* Reserved #1 */ +#define UART_MCR_TCRTLR BIT(6, U)/* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_RESERVED2 BIT(7, U)/* Reserved #2 */ +#define UART_MCR_MASK \ + (UART_MCR_DTR | UART_MCR_RTS | \ + UART_MCR_OUT1 | UART_MCR_OUT2 | \ + UART_MCR_LOOP) + +/* Modem Status Register */ +#define UART_MSR_DCTS BIT(0, U)/* Change in CTS */ +#define UART_MSR_DDSR BIT(1, U)/* Change in DSR */ +#define UART_MSR_TERI BIT(2, U)/* Change in RI */ +#define UART_MSR_DDCD BIT(3, U)/* Change in CTS */ +#define UART_MSR_CTS BIT(4, U) +#define UART_MSR_DSR BIT(5, U) +#define UART_MSR_RI BIT(6, U) +#define UART_MSR_DCD BIT(7, U) +#define UART_MSR_DELTA \ + (UART_MSR_DCTS | UART_MSR_DDSR | UART_MSR_TERI | UART_MSR_DDCD)/* Line Status Register */ #define UART_LSR_DR 0x01/* Data ready */
@@ -111,6 +146,7 @@#define UART_LSR_THRE 0x20/* Xmit hold reg empty */ #define UART_LSR_TEMT 0x40/* Xmitter empty */ #define UART_LSR_ERR 0x80/* Error */ +#define UART_LSR_MASK (UART_LSR_OE | UART_LSR_BI)/* These parity settings can be ORed directly into the LCR. */ #define UART_PARITY_NONE (0<<3)
@@ -119,7 +155,10 @@#define UART_PARITY_MARK (5<<3)#define UART_PARITY_SPACE (7<<3) -/* Frequency of external clock source. This definition assumes PC platform. */ +/* +* Frequency of external UART clock source. +* Same as IBM PC master input clock frequency. +*/ #define UART_CLOCK_HZ 1843200/* Bits in Exar specific UART_XR_EFR register */
Signature · 1 line
2.34.1
Re: [PATCH v2 28/35] xen/8250-uart: add missing definitions
Quoted 45 lines · On Thu, Dec 05, 2024 at 08:41:58PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Added missing definitions needed for NS8250 UART emulator.
Signed-off-by Denis Mukhin <[email protected]>--- xen/include/xen/8250-uart.h | 81 +++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 21 deletions(-)xen/include/xen/8250-uart.h +9
-0@@ -32,16 +32,22 @@#define UART_MCR 0x04/* Modem control */ #define UART_LSR 0x05/* line status */ #define UART_MSR 0x06/* Modem status */ +#define UART_SCR 0x07/* Scratch pad */ #define UART_USR 0x1f/* Status register (DW) */ #define UART_DLL 0x00/* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01/* divisor latch (ms) (DLAB=1) */ #define UART_XR_EFR 0x09/* Enhanced function register (Exar) */ +/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] */ +#define UART_MAX (UART_SCR + 1) +/* Interrupt Enable Register */ #define UART_IER_ERDAI 0x01/* rx data recv'd */ #define UART_IER_ETHREI 0x02/* tx reg. empty */ #define UART_IER_ELSI 0x04/* rx line status */ #define UART_IER_EMSI 0x08/* MODEM status */ +#define UART_IER_MASK \ + (UART_IER_ERDAI | UART_IER_ETHREI | UART_IER_ELSI | UART_IER_EMSI)/* Interrupt Identification Register */ #define UART_IIR_NOINT 0x01/* no interrupt pending */ @@ -51,12 +57,21 @@#define UART_IIR_THR 0x02/* - tx reg. empty */ #define UART_IIR_MSI 0x00/* - MODEM status */ #define UART_IIR_BSY 0x07/* - busy detect (DW) */ +#define UART_IIR_FE0 BIT(6, U)/* FIFO enable #0 */ +#define UART_IIR_FE1 BIT(7, U)/* FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1)/* FIFO Control Register */
xen/include/xen/8250-uart.h line 70
Quoted 10 lines
xen/include/xen/8250-uart.h +6
-4-#define UART_FCR_ENABLE 0x01/* enable FIFO */ -#define UART_FCR_CLRX 0x02/* clear Rx FIFO */ -#define UART_FCR_CLTX 0x04/* clear Tx FIFO */ -#define UART_FCR_DMA 0x10/* enter DMA mode */ +#define UART_FCR_ENABLE BIT(0, U)/* enable FIFO */ +#define UART_FCR_CLRX BIT(1, U)/* clear Rx FIFO */ +#define UART_FCR_CLTX BIT(2, U)/* clear Tx FIFO */ +#define UART_FCR_DMA BIT(3, U)/* enter DMA mode */ +#define UART_FCR_RESERVED0 BIT(4, U)/* reserved; always 0 */ +#define UART_FCR_RESERVED1 BIT(5, U)/* reserved; always 0 */
We don't usually define reserved bits I think, as I assume those won't be used by the code?
Maybe a reserved mask for the hole register, to ensure the access to the register doesn't attempt to set reserved bits? But even then the best we can do when emulating is print a warning message.
Thanks, Roger.
Re: [PATCH v2 28/35] xen/8250-uart: add missing definitions
Quoted 48 lines · Roger Pau Monné
Quoted 44 lines · On Thu, Dec 05, 2024 at 08:41:58PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Added missing definitions needed for NS8250 UART emulator.
Signed-off-by Denis Mukhin [email protected]---
xen/include/xen/8250-uart.h| 81 +++++++++++++++++++++++++++++++++------------1 file changed, 60 insertions(+), 21 deletions(-)xen/include/xen/8250-uart.h +4
-0@@ -32,16 +32,22 @@#define UART_MCR 0x04/* Modem control / #define UART_LSR 0x05 / line status / #define UART_MSR 0x06 / Modem status / +#define UART_SCR 0x07 / Scratch pad / #define UART_USR 0x1f / Status register (DW) / #define UART_DLL 0x00 / divisor latch (ls) (DLAB=1) / #define UART_DLM 0x01 / divisor latch (ms) (DLAB=1) / #define UART_XR_EFR 0x09 / Enhanced function register (Exar) */ +/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] / +#define UART_MAX (UART_SCR + 1) +/ Interrupt Enable Register /
#defineUART_IER_ERDAI0x01/ rx data recv'd /
#defineUART_IER_ETHREI0x02/ tx reg. empty /
#defineUART_IER_ELSI0x04/ rx line status /
#defineUART_IER_EMSI0x08/ MODEM status */
+#defineUART_IER_MASK\
+ (UART_IER_ERDAI|UART_IER_ETHREI|UART_IER_ELSI|UART_IER_EMSI)/* Interrupt Identification Register / #define
UART_IIR_NOINT0x01/ no interrupt pending /xen/include/xen/8250-uart.h +3
-0@@ -51,12 +57,21 @@#define UART_IIR_THR 0x02 / - tx reg. empty / #define UART_IIR_MSI 0x00 / - MODEM status / #define UART_IIR_BSY 0x07 / - busy detect (DW) / +#define UART_IIR_FE0 BIT(6, U) / FIFO enable #0 / +#define UART_IIR_FE1 BIT(7, U) / FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1)
Quoted 15 lines
xen/include/xen/8250-uart.h line 70
Quoted 11 lines
xen/include/xen/8250-uart.h +6
-4/* FIFO Control Register / -#define UART_FCR_ENABLE 0x01 / enable FIFO / -#define UART_FCR_CLRX 0x02 / clear Rx FIFO / -#define UART_FCR_CLTX 0x04 / clear Tx FIFO / -#define UART_FCR_DMA 0x10 / enter DMA mode / +#define UART_FCR_ENABLE BIT(0, U) / enable FIFO / +#define UART_FCR_CLRX BIT(1, U) / clear Rx FIFO / +#define UART_FCR_CLTX BIT(2, U) / clear Tx FIFO / +#define UART_FCR_DMA BIT(3, U) / enter DMA mode / +#define UART_FCR_RESERVED0 BIT(4, U) / reserved; always 0 / +#define UART_FCR_RESERVED1 BIT(5, U) / reserved; always 0 */ We don't usually define reserved bits I think, as I assume those won't be used by the code?
I found examples of reserved bits being defined and not used in the code base, e.g. PCI_PM_CAP_RESERVED.
IMO marking reserved bits in the code will immediately explain readers the purpose of those bits.
Quoted 4 lines
Maybe a reserved mask for the hole register, to ensure the access to the register doesn't attempt to set reserved bits? But even then the best we can do when emulating is print a warning message.
Added warning messages in the emulator code (v3).
Quoted 2 lines
Thanks, Roger.
Re: [PATCH v2 28/35] xen/8250-uart: add missing definitions
In reply to Denis MukhinQuoted 4 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/include/xen/8250-uart.h +0
-0@@ -32,16 +32,22 @@#define UART_MCR 0x04/* Modem control */
xen/include/xen/8250-uart.h line 42
Quoted 10 lines
xen/include/xen/8250-uart.h +3
-0#define UART_LSR 0x05/* line status */ #define UART_MSR 0x06/* Modem status */ +#define UART_SCR 0x07/* Scratch pad */ #define UART_USR 0x1f/* Status register (DW) */ #define UART_DLL 0x00/* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01/* divisor latch (ms) (DLAB=1) */ #define UART_XR_EFR 0x09/* Enhanced function register (Exar) */ +/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] */ +#define UART_MAX (UART_SCR + 1)
There are two issues here: "max" means "highest within range", yet you define it as "first invalid", i.e. something we'd normally call "_NR" or "_NUM". And then, as the comment says, this is a limit the emulation is going to expose, not something generally applicable to UARTs of this kind. Hence the UART_ prefix alone isn't quite correct either.
xen/include/xen/8250-uart.h line 62
Quoted 7 lines
xen/include/xen/8250-uart.h +3
-0@@ -51,12 +57,21 @@#define UART_IIR_THR 0x02/* - tx reg. empty */ #define UART_IIR_MSI 0x00/* - MODEM status */ #define UART_IIR_BSY 0x07/* - busy detect (DW) */ +#define UART_IIR_FE0 BIT(6, U)/* FIFO enable #0 */ +#define UART_IIR_FE1 BIT(7, U)/* FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1)
Much like BSY is a 3-bit field, aiui this is a 2-bit one.
Quoted 4 lines
xen/include/xen/8250-uart.h +0
-3/* FIFO Control Register */ -#define UART_FCR_ENABLE 0x01/* enable FIFO */ -#define UART_FCR_CLRX 0x02/* clear Rx FIFO */ -#define UART_FCR_CLTX 0x04/* clear Tx FIFO */
xen/include/xen/8250-uart.h line 73
Quoted 10 lines
xen/include/xen/8250-uart.h +9
-1-#define UART_FCR_DMA 0x10/* enter DMA mode */ +#define UART_FCR_ENABLE BIT(0, U)/* enable FIFO */ +#define UART_FCR_CLRX BIT(1, U)/* clear Rx FIFO */ +#define UART_FCR_CLTX BIT(2, U)/* clear Tx FIFO */ +#define UART_FCR_DMA BIT(3, U)/* enter DMA mode */ +#define UART_FCR_RESERVED0 BIT(4, U)/* reserved; always 0 */ +#define UART_FCR_RESERVED1 BIT(5, U)/* reserved; always 0 */ +#define UART_FCR_RTB0 BIT(6, U)/* receiver trigger bit #0 */ +#define UART_FCR_RTB1 BIT(7, U)/* receiver trigger bit #1 */ +#define UART_FCR_TRG_MASK (UART_FCR_RTB0 | UART_FCR_RTB1)
Much like the top two bits here are, and - as Roger has said - the reserved bits probably also should be.
Quoted 17 lines
xen/include/xen/8250-uart.h +2
-11@@ -64,17 +79,17 @@/* * Note: The FIFO trigger levels are chip specific: -* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 -* PC16550D: 1 4 8 14 xx xx xx xx -* TI16C550A: 1 4 8 14 xx xx xx xx -* TI16C550C: 1 4 8 14 xx xx xx xx -* ST16C550: 1 4 8 14 xx xx xx xx -* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 -* NS16C552: 1 4 8 14 xx xx xx xx -* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 -* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 -* TI16C752: 8 16 56 60 8 16 32 56 -* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx
xen/include/xen/8250-uart.h line 93
Quoted 10 lines
xen/include/xen/8250-uart.h +9
-0+* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56 +* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA */
While perhaps okay, the adjustment of this table still looks unrelated. It wants at least mentioning in the description, to clarify it's an intentional change (as opposed to e.g. being an effect of how your editor is configured).
Quoted 22 lines
xen/include/xen/8250-uart.h +13
-5@@ -96,11 +111,31 @@#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ /* Modem Control Register */ -#define UART_MCR_DTR 0x01/* Data Terminal Ready */ -#define UART_MCR_RTS 0x02/* Request to Send */ -#define UART_MCR_OUT2 0x08/* OUT2: interrupt mask */ -#define UART_MCR_LOOP 0x10/* Enable loopback test mode */ -#define UART_MCR_TCRTLR 0x40/* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_DTR BIT(0, U)/* Data Terminal Ready */ +#define UART_MCR_RTS BIT(1, U)/* Request to Send */ +#define UART_MCR_OUT1 BIT(2, U)/* OUT1: interrupt mask */ +#define UART_MCR_OUT2 BIT(3, U)/* OUT2: interrupt mask */ +#define UART_MCR_LOOP BIT(4, U)/* Enable loopback test mode */ +#define UART_MCR_RESERVED0 BIT(5, U)/* Reserved #0 */ +#define UART_MCR_RESERVED1 BIT(6, U)/* Reserved #1 */ +#define UART_MCR_TCRTLR BIT(6, U)/* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_RESERVED2 BIT(7, U)/* Reserved #2 */ +#define UART_MCR_MASK \ + (UART_MCR_DTR | UART_MCR_RTS | \ + UART_MCR_OUT1 | UART_MCR_OUT2 | \ + UART_MCR_LOOP)
xen/include/xen/8250-uart.h line 136
Quoted 10 lines
xen/include/xen/8250-uart.h +10
-0+ +/* Modem Status Register */ +#define UART_MSR_DCTS BIT(0, U)/* Change in CTS */ +#define UART_MSR_DDSR BIT(1, U)/* Change in DSR */ +#define UART_MSR_TERI BIT(2, U)/* Change in RI */ +#define UART_MSR_DDCD BIT(3, U)/* Change in CTS */ +#define UART_MSR_CTS BIT(4, U) +#define UART_MSR_DSR BIT(5, U) +#define UART_MSR_RI BIT(6, U) +#define UART_MSR_DCD BIT(7, U)
As you introduce these constants, I think you also want to switch the sole MSR read we have to actually use them.
Jan
Re: [PATCH v2 28/35] xen/8250-uart: add missing definitions
Quoted 16 lines · Jan Beulich
Quoted 12 lines · On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
xen/include/xen/8250-uart.h +1
-0@@ -32,16 +32,22 @@#define UART_MCR 0x04/* Modem control / #define UART_LSR 0x05 / line status / #define UART_MSR 0x06 / Modem status / +#define UART_SCR 0x07 / Scratch pad / #define UART_USR 0x1f / Status register (DW) / #define UART_DLL 0x00 / divisor latch (ls) (DLAB=1) / #define UART_DLM 0x01 / divisor latch (ms) (DLAB=1) / #define UART_XR_EFR 0x09 / Enhanced function register (Exar) */
Quoted 10 lines
xen/include/xen/8250-uart.h line 42
Quoted 2 lines
xen/include/xen/8250-uart.h +2
-0+/* ns8250 emulator: range of emulated registers [0..UART_MAX-1] */ +#define UART_MAX (UART_SCR + 1)There are two issues here: "max" means "highest within range", yet you define it as "first invalid", i.e. something we'd normally call "
_NR" or "NUM". And then, as the comment says, this is a limit the emulation is going to expose, not something generally applicable to UARTs of this kind. Hence the UART prefix alone isn't quite correct either.
I did renaming and moved declaration to the UART emulator code.
Quoted 11 lines
xen/include/xen/8250-uart.h line 62
Quoted 8 lines
xen/include/xen/8250-uart.h +3
-0@@ -51,12 +57,21 @@#define UART_IIR_THR 0x02/* - tx reg. empty / #define UART_IIR_MSI 0x00 / - MODEM status / #define UART_IIR_BSY 0x07 / - busy detect (DW) / +#define UART_IIR_FE0 BIT(6, U) / FIFO enable #0 / +#define UART_IIR_FE1 BIT(7, U) / FIFO enable #1 */ +#define UART_IIR_FE_MASK (UART_IIR_FE0 | UART_IIR_FE1)Much like BSY is a 3-bit field, aiui this is a 2-bit one.
Updated to 2-bit mask.
Quoted 11 lines
Quoted 11 lines
xen/include/xen/8250-uart.h +5
-4/* FIFO Control Register / -#define UART_FCR_ENABLE 0x01 / enable FIFO / -#define UART_FCR_CLRX 0x02 / clear Rx FIFO / -#define UART_FCR_CLTX 0x04 / clear Tx FIFO / -#define UART_FCR_DMA 0x10 / enter DMA mode / +#define UART_FCR_ENABLE BIT(0, U) / enable FIFO / +#define UART_FCR_CLRX BIT(1, U) / clear Rx FIFO / +#define UART_FCR_CLTX BIT(2, U) / clear Tx FIFO / +#define UART_FCR_DMA BIT(3, U) / enter DMA mode / +#define UART_FCR_RESERVED0 BIT(4, U) / reserved; always 0 /
Quoted 8 lines
xen/include/xen/8250-uart.h line 72
Quoted 4 lines
xen/include/xen/8250-uart.h +4
-0+#define UART_FCR_RESERVED1 BIT(5, U) / reserved; always 0 / +#define UART_FCR_RTB0 BIT(6, U) / receiver trigger bit #0 / +#define UART_FCR_RTB1 BIT(7, U) / receiver trigger bit #1 */ +#define UART_FCR_TRG_MASK (UART_FCR_RTB0 | UART_FCR_RTB1)Much like the top two bits here are, and - as Roger has said - the reserved bits probably also should be.
I kept reserved bits as is.
I think that will help to avoid confusion whether support for those bits is missing in the driver code or those are reserved.
There are other examples, e.g. PCI_PM_CAP_RESERVED when reserved bits declared and not necessarily used in the code base.
Quoted 26 lines
Quoted 26 lines
xen/include/xen/8250-uart.h +10
-11@@ -64,17 +79,17 @@/* * Note: The FIFO trigger levels are chip specific: -* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 -* PC16550D: 1 4 8 14 xx xx xx xx -* TI16C550A: 1 4 8 14 xx xx xx xx -* TI16C550C: 1 4 8 14 xx xx xx xx -* ST16C550: 1 4 8 14 xx xx xx xx -* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 -* NS16C552: 1 4 8 14 xx xx xx xx -* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 -* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 -* TI16C752: 8 16 56 60 8 16 32 56 -* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA +* RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 +* PC16550D: 1 4 8 14 xx xx xx xx +* TI16C550A: 1 4 8 14 xx xx xx xx +* TI16C550C: 1 4 8 14 xx xx xx xx +* ST16C550: 1 4 8 14 xx xx xx xx +* ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 +* NS16C552: 1 4 8 14 xx xx xx xx +* ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 +* TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 +* TI16C752: 8 16 56 60 8 16 32 56
Quoted 8 lines
xen/include/xen/8250-uart.h line 93
Quoted 2 lines
xen/include/xen/8250-uart.h +1
-0+* Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA */ While perhaps okay, the adjustment of this table still looks unrelated. It wants at least mentioning in the description, to clarify it's an intentional change (as opposed to e.g. being an effect of how your editor is configured).
Thanks, I updated the commit message.
Quoted 29 lines
Quoted 29 lines
xen/include/xen/8250-uart.h +19
-5@@ -96,11 +111,31 @@#define UART_LCR_CONF_MODE_B 0xBF/* Configuration mode B */ /* Modem Control Register / -#define UART_MCR_DTR 0x01 / Data Terminal Ready / -#define UART_MCR_RTS 0x02 / Request to Send / -#define UART_MCR_OUT2 0x08 / OUT2: interrupt mask / -#define UART_MCR_LOOP 0x10 / Enable loopback test mode / -#define UART_MCR_TCRTLR 0x40 / Access TCR/TLR (TI16C752, EFR[4]=1) / +#define UART_MCR_DTR BIT(0, U) / Data Terminal Ready / +#define UART_MCR_RTS BIT(1, U) / Request to Send / +#define UART_MCR_OUT1 BIT(2, U) / OUT1: interrupt mask / +#define UART_MCR_OUT2 BIT(3, U) / OUT2: interrupt mask / +#define UART_MCR_LOOP BIT(4, U) / Enable loopback test mode / +#define UART_MCR_RESERVED0 BIT(5, U) / Reserved #0 / +#define UART_MCR_RESERVED1 BIT(6, U) / Reserved #1 / +#define UART_MCR_TCRTLR BIT(6, U) / Access TCR/TLR (TI16C752, EFR[4]=1) / +#define UART_MCR_RESERVED2 BIT(7, U) / Reserved #2 / +#define UART_MCR_MASK \ +(UART_MCR_DTR | UART_MCR_RTS | \ +UART_MCR_OUT1 | UART_MCR_OUT2 | \ +UART_MCR_LOOP) + +/ Modem Status Register / +#define UART_MSR_DCTS BIT(0, U) / Change in CTS / +#define UART_MSR_DDSR BIT(1, U) / Change in DSR / +#define UART_MSR_TERI BIT(2, U) / Change in RI / +#define UART_MSR_DDCD BIT(3, U) / Change in CTS */
Quoted 8 lines
xen/include/xen/8250-uart.h line 136
Quoted 4 lines
xen/include/xen/8250-uart.h +4
-0+#define UART_MSR_CTS BIT(4, U) +#define UART_MSR_DSR BIT(5, U) +#define UART_MSR_RI BIT(6, U) +#define UART_MSR_DCD BIT(7, U)As you introduce these constants, I think you also want to switch the sole MSR read we have to actually use them.
Sure, no problem; fixed.
Quoted 2 lines
Jan
PATCH v2 29/35 x86/hvm: add HVM-specific Kconfig
In reply to Denis MukhinAdd separate menu for configuring HVM build-time settings. That will help organizing HVM-specific options under a separate menu.
--- xen/arch/x86/Kconfig | 66 +++--------------------------------------------- xen/arch/x86/hvm/Kconfig | 63 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 63 deletions(-)
xen/arch/x86/Kconfig +3 -63
@@ -107,42 +107,9 @@ config PV_LINEAR_PT If unsure, say Y. -config HVM - bool "HVM support" - depends on !PV_SHIM_EXCLUSIVE - default !PV_SHIM - select COMPAT - select IOREQ_SERVER - select MEM_ACCESS_ALWAYS_ON - help - Interfaces to support HVM domains. HVM domains require hardware - virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot - guests which have no specific Xen knowledge. - - This option is needed if you want to run HVM or PVH domains. - - If unsure, say Y. - -config AMD_SVM - bool "AMD-V" if EXPERT - depends on HVM - default y - help - Enables virtual machine extensions on platforms that implement the - AMD Virtualization Technology (AMD-V). - If your system includes a processor with AMD-V support, say Y. - If in doubt, say Y. - -config INTEL_VMX - bool "Intel VT-x" if EXPERT - depends on HVM - default y - select ARCH_VCPU_IOREQ_COMPLETION - help - Enables virtual machine extensions on platforms that implement the - Intel Virtualization Technology (Intel VT-x). - If your system includes a processor with Intel VT-x support, say Y. - If in doubt, say Y. +menu "HVM Support" +source "arch/x86/hvm/Kconfig" +endmenu config XEN_SHSTK bool "Supervisor Shadow Stacks"
@@ -201,25 +168,6 @@ config BIGMEM If unsure, say N. -config HVM_FEP - bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED - default DEBUG - depends on HVM - help - - Compiles in a feature that allows HVM guest to arbitrarily - exercise the instruction emulator. - - This feature can only be enabled during boot time with - appropriate hypervisor command line option. Please read - hypervisor command line documentation before trying to use - this feature. - - This is strictly for testing purposes, and not appropriate - for use in production. - - If unsure, say N. - config TBOOT bool "Xen tboot support (UNSUPPORTED)" depends on INTEL && UNSUPPORTED
@@ -348,14 +296,6 @@ config HYPERV_GUEST endif -config MEM_PAGING - bool "Xen memory paging support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - -config MEM_SHARING - bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - config REQUIRE_NX bool "Require NX (No eXecute) support" help
xen/arch/x86/hvm/Kconfig new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 29/35] x86/hvm: add HVM-specific Kconfig
Quoted 4 lines · On Thu, Dec 05, 2024 at 08:41:59PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Add separate menu for configuring HVM build-time settings. That will help organizing HVM-specific options under a separate menu.
Instead of being a separate menu, which feels a bit odd under default settings because there's just an "HVM support" option inside, could you make it look like the PV support menu, that indents PV specific options:
[*] PV support
[ ] Support for 32bit PV guests
[*] Support for PV linear pagetables
Thanks, Roger.
Re: [PATCH v2 29/35] x86/hvm: add HVM-specific Kconfig
Quoted 10 lines · Roger Pau Monné
Quoted 4 lines · On Thu, Dec 05, 2024 at 08:41:59PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Add separate menu for configuring HVM build-time settings. That will help organizing HVM-specific options under a separate menu.
Quoted 8 lines
Instead of being a separate menu, which feels a bit odd under default settings because there's just an "HVM support" option inside, could you make it look like the PV support menu, that indents PV specific options:
[] PV support
[ ] Support for 32bit PV guests
[] Support for PV linear pagetables
My rationale is that code base at arch/x86/hvm deserves its own Kconfig because there a bunch of configuration options just for arch/x86/hvm.
I think that will also help managing configuration since they all in dedicated location.
I enabled "HVM menu" using correct Kconfig syntax in v3.
Quoted 2 lines
Thanks, Roger.
PATCH v2 30/35 x86/hvm: add helpers for raising guest IRQs
In reply to Denis MukhinAdded convenience wrappers for asserting/de-asserting interrupts in the hardware emulation code.
That will be used for PCI-based NS8250 emulator.
--- xen/arch/x86/hvm/irq.c | 24 ++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/irq.h | 3 +++ 2 files changed, 27 insertions(+)
xen/arch/x86/hvm/irq.c +24 -0
@@ -242,6 +242,30 @@ void hvm_isa_irq_deassert(spin_unlock (&d->arch.hvm.irq_lock); } +void hvm_irq_raise (struct domain *d,unsigned int irq) +{ +if ( irq <NR_ISAIRQS ) + { +hvm_isa_irq_assert (d, irq,NULL ); + } +else + { +hvm_gsi_assert (d, irq); + } +} + +void hvm_irq_lower (struct domain *d,unsigned int irq) +{ +if ( irq <NR_ISAIRQS ) + { +hvm_isa_irq_deassert (d, irq); + } +else + { +hvm_gsi_deassert (d, irq); + } +} +static void hvm_set_callback_irq_level (struct vcpu *v) {struct domain *d = v->domain;
xen/arch/x86/include/asm/hvm/irq.h +3 -0
@@ -210,6 +210,9 @@ void hvm_maybe_deassert_evtchn_irq(void);void hvm_assert_evtchn_irq (struct vcpu *v);void hvm_set_callback_via (struct domain *d,uint64_t via); +void hvm_irq_raise (struct domain *d,unsigned int irq); +void hvm_irq_lower (struct domain *d,unsigned int irq); +struct pirq ;bool hvm_domain_use_pirq (const struct domain *d,const struct pirq *pirq);
Signature · 1 line
2.34.1
Re: [PATCH v2 30/35] x86/hvm: add helpers for raising guest IRQs
Quoted 6 lines · On Thu, Dec 05, 2024 at 08:42:00PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin <[email protected]>
Added convenience wrappers for asserting/de-asserting interrupts in the hardware emulation code.
That will be used for PCI-based NS8250 emulator.
Strictly speaking the ns8250 uart should only generate ISA interrupts as I understand it, as it only uses IRQs 3 and 4? IOW from that code you should only need to use hvm_isa_irq_assert().
Quoted 18 lines
Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/hvm/irq.c | 24 ++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/irq.h | 3 +++ 2 files changed, 27 insertions(+)xen/arch/x86/hvm/irq.c +3
-0@@ -242,6 +242,30 @@ void hvm_isa_irq_deassert(spin_unlock (&d->arch.hvm.irq_lock); } +void hvm_irq_raise (struct domain *d,unsigned int irq) +{ +if ( irq <NR_ISAIRQS )
xen/arch/x86/hvm/irq.c void hvm_isa_irq_deassert( · line 257
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+ { +hvm_isa_irq_assert (d, irq,NULL ); + } + else + { +hvm_gsi_assert (d, irq); + } +} + +void hvm_irq_lower (struct domain *d,unsigned int irq)
It would be better to use the assert/deassert nomenclature, like it's used for the functions that are called.
xen/arch/x86/hvm/irq.c void hvm_isa_irq_deassert( · line 267
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+{ +if ( irq <NR_ISAIRQS ) + { +hvm_isa_irq_deassert (d, irq); + } +else + { +hvm_gsi_deassert (d, irq); + } +}
The parameter to thins function is kind of fuzzy, as I understand it, if the parameter is < NR_ISAIRQS it's an ISA IRQ, while if it's >= NR_ISAIRQS it's a GSI?
It would also be helpul to mention that hvm_isa_irq_deassert() will already do the ISA IRQ -> GSI conversion in case there are any source overrides.
Thanks, Roger.
Re: [PATCH v2 30/35] x86/hvm: add helpers for raising guest IRQs
Quoted 9 lines · Roger Pau Monné
Quoted 5 lines · On Thu, Dec 05, 2024 at 08:42:00PM -0800, Denis Mukhin via B4 Relay wrote:
From: Denis Mukhin [email protected]
Added convenience wrappers for asserting/de-asserting interrupts in the hardware emulation code.
Quoted 6 lines
Quoted 1 line
That will be used for PCI-based NS8250 emulator.
Strictly speaking the ns8250 uart should only generate ISA interrupts as I understand it, as it only uses IRQs 3 and 4? IOW from that code you should only need to use
hvm_isa_irq_assert().
Correct, current code uses IRQ#3 and IRQ#4 only.
I dropped the patch from the series for now.
Quoted 48 lines
Quoted 18 lines
Signed-off-by Denis Mukhin [email protected]---
xen/arch/x86/hvm/irq.c| 24 ++++++++++++++++++++++++xen/arch/x86/include/asm/hvm/irq.h| 3 +++2 files changed, 27 insertions(+)xen/arch/x86/hvm/irq.c +3
-0@@ -242,6 +242,30 @@ void hvm_isa_irq_deassert(spin_unlock (&d->arch.hvm.irq_lock); } +void hvm_irq_raise (struct domain *d,unsigned int irq) +{ +if ( irq <NR_ISAIRQS )xen/arch/x86/hvm/irq.c void hvm_isa_irq_deassert( · line 257
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+ { +hvm_isa_irq_assert (d, irq,NULL ); + } + else + { +hvm_gsi_assert (d, irq); + } +} + +void hvm_irq_lower (struct domain *d,unsigned int irq)It would be better to use the assert/deassert nomenclature, like it's used for the functions that are called.
xen/arch/x86/hvm/irq.c void hvm_isa_irq_deassert( · line 267
Quoted 10 lines
xen/arch/x86/hvm/irq.c +10
-0+{ +if ( irq <NR_ISAIRQS ) + { +hvm_isa_irq_deassert (d, irq); + } +else + { +hvm_gsi_deassert (d, irq); + } +}The parameter to thins function is kind of fuzzy, as I understand it, if the parameter is <
NR_ISAIRQSit's an ISA IRQ, while if it's >=
Quoted 1 line
NR_ISAIRQSit's a GSI?
Yes, agree, mixing two address spaces is at least confusing. I dropped the patch from the series.
Quoted 7 lines
It would also be helpul to mention that
hvm_isa_irq_deassert()will already do the ISA IRQ -> GSI conversion in case there are any sourceoverrides.
Thanks, Roger.
PATCH v2 31/35 x86/hvm: introduce NS8250 UART emulator
In reply to Denis MukhinAdd initial in-hypervisor emulator for NS8250/NS16x50-compatible UARTs under CONFIG_HAS_VUART_NS8250.
In parallel domain creation scenario (hyperlaunch), NS8520 emulator helps early guest OS bringup debugging, because it eliminates dependency on the external emulator being operational by the time domains are created. Also, there's no early console facility similar to vpl011 to support x86 guest OS bring up.
By default, CONFIG_HAS_VUART_NS8250 enables emulatio of NS8250 at I/O port 0x3f8, IRQ#4 in guest OS.
Limitations:
- Only x86;
- Only Linux guest tested so far;
- Only legacy COM{1,2,3,4} resources, no customization;
- Only Xen console as a backend, no inter-domain communication (similar to vpl011 on Arm);
- Only 8-bit characters;
- Baud rate is not emulated;
- FIFO-less mode is not emulated properly;
- RX FIFO interrupt moderation (FCR) is not emulated properly, TL16C750 has special FCR handling;
- No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and friends);
- Assumes no ISA-device IRQ sharing;
- MMIO-based UART is not supported.
--- xen/arch/x86/hvm/Kconfig | 14 + xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 13 + xen/arch/x86/hvm/vuart_ns8250.c | 886 ++++++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/domain.h | 5 + xen/arch/x86/include/asm/hvm/vuart_ns8250.h | 75 +++ 6 files changed, 994 insertions(+)
xen/arch/x86/hvm/Kconfig +14 -0
@@ -61,3 +61,17 @@ config HVM_FEP for use in production. If unsure, say N. + +config HAS_VUART_NS8250 + bool "NS8250-compatible UART Emulation" + depends on HVM && HAS_IOPORTS + default n + help + In-hypervisor NS8250/NS16x50 UART emulation. + + Only legacy PC I/O ports are emulated. + + This is strictly for testing purposes (early HVM guest console), and not + appropriate for use in production. + + If unsure, say N.
xen/arch/x86/hvm/Makefile +1 -0
@@ -29,3 +29,4 @@ obj-y += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o +obj-$(CONFIG_HAS_VUART_NS8250) += vuart_ns8250.o
xen/arch/x86/hvm/hvm.c +13 -0
@@ -55,6 +55,7 @@#include <asm/hvm/monitor.h> #include <asm/hvm/viridian.h> #include <asm/hvm/vm_event.h> +#include <asm/hvm/vuart_ns8250.h> #include <asm/altp2m.h> #include <asm/mtrr.h> #include <asm/apic.h>
@@ -679,6 +680,15 @@ int hvm_domain_initialise(struct domain *d,if ( rc !=0 ) goto fail1; +if (domain_has_vuart (d) ) + { + rc =domain_vuart_init (d); +if ( rc ==0 ) + d->is_console = true; +else if ( rc != -ENODEV ) + goto out_vioapic_deinit; + } +stdvga_init (d);rtc_init (d);
@@ -699,6 +709,9 @@ int hvm_domain_initialise(struct domain *d,return 0 ; fail2: +if (domain_has_vuart (d) ) +domain_vuart_free (d); + out_vioapic_deinit:vioapic_deinit (d); fail1:if (is_hardware_domain (d) )
xen/arch/x86/hvm/vuart_ns8250.c new file +886 -0
886 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/domain.h +5 -0
@@ -16,6 +16,7 @@#include <asm/hvm/io.h> #include <asm/hvm/vmx/vmcs.h> #include <asm/hvm/svm/vmcb.h> +#include <asm/hvm/vuart_ns8250.h> #ifdef CONFIG_MEM_SHARING struct mem_sharing_domain
@@ -73,6 +74,10 @@ struct hvm_domain {struct hvm_vioapic **vioapic;unsigned int nr_vioapics; +#if defined(CONFIG_HAS_VUART_NS8250 ) +struct vuart_ns8250 vuart; +#endif +/* * hvm_hw_pmtimer is a publicly-visible name. We will defer renaming * it to the more appropriate hvm_hw_acpi until the expected
xen/arch/x86/include/asm/hvm/vuart_ns8250.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.34.1