xen/console: group pbuf under console field
PATCH 1/1 xen/console: group pbuf under console field
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
No functional change.
--- xen/arch/x86/hvm/hvm.c | 14 +++++++------- xen/common/domain.c | 8 ++++---- xen/drivers/char/console.c | 19 +++++++++++-------- xen/include/xen/sched.h | 12 ++++++------ 4 files changed, 28 insertions(+), 25 deletions(-)
xen/arch/x86/hvm/hvm.c +7 -7
@@ -571,16 +571,16 @@ static int cf_check hvm_print_line(if ( !is_console_printable (c) )return X86EMUL_OKAY ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock);if ( c !='\n' ) - cd->pbuf[cd->pbuf_idx++] = c; -if ( (cd->pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) + cd->console.pbuf[cd->console.pbuf_idx++] = c; +if ( (cd->console.pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->pbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->console.pbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock);return X86EMUL_OKAY ; }
xen/common/domain.c +4 -4
@@ -669,7 +669,7 @@ static void _domain_destroy(struct domain *d)BUG_ON (!d->is_dying);BUG_ON (atomic_read (&d->refcnt) !=DOMAIN_DESTROYED ); -xfree (d->pbuf); +xfree (d->console.pbuf);argo_destroy (d);
@@ -862,7 +862,7 @@ struct domain *domain_create(domid_t domid,spin_lock_init (&d->shutdown_lock); d->shutdown_code =SHUTDOWN_CODE_INVALID ; -spin_lock_init (&d->pbuf_lock); +spin_lock_init (&d->console.pbuf_lock);rwlock_init (&d->vnuma_rwlock);
@@ -956,8 +956,8 @@ struct domain *domain_create(domid_t domid, goto fail; err = -ENOMEM ; - d->pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); -if ( !d->pbuf ) + d->console.pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); +if ( !d->console.pbuf ) goto fail;if ( (err =sched_init_domain (d, config->cpupool_id)) !=0 )
xen/drivers/char/console.c +11 -8
@@ -769,22 +769,25 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, }while ( --kcount >0 ); *kout ='\0' ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock); kcount = kin - kbuf;if ( c !='\n' && - (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE -1 )) ) + cd->console.pbuf_idx + kout - kbuf <DOMAIN_PBUF_SIZE -1 ) {/* buffer the output until a newline */ -memcpy (cd->pbuf + cd->pbuf_idx, kbuf, kout - kbuf); - cd->pbuf_idx += (kout - kbuf); +memcpy (cd->console.pbuf + cd->console.pbuf_idx, + kbuf, + kout - kbuf); + cd->console.pbuf_idx += (kout - kbuf); }else { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s%s\n" , cd->pbuf, kbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd, +XENLOG_G_DEBUG "%s%s\n" , cd->console.pbuf, kbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock); }guest_handle_add_offset (buffer, kcount);
xen/include/xen/sched.h +6 -6
@@ -562,12 +562,6 @@ struct domain/* Control-plane tools handle for this domain. */ xen_domain_handle_t handle; -/* hvm_print_line() and guest_console_write() logging. */ -#define DOMAIN_PBUF_SIZE 200 -char *pbuf; -unsigned int pbuf_idx; -spinlock_t pbuf_lock; -/* OProfile support. */ struct xenoprof *xenoprof;
@@ -654,6 +648,12 @@ struct domain/* Console settings. */ struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;
Signature · 1 line
2.34.1
Hello,
Le 06/06/2025 à 21:51, [email protected] a écrit :
Quoted 80 lines
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
No functional change.
Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/hvm/hvm.c | 14 +++++++------- xen/common/domain.c | 8 ++++---- xen/drivers/char/console.c | 19 +++++++++++-------- xen/include/xen/sched.h | 12 ++++++------ 4 files changed, 28 insertions(+), 25 deletions(-)xen/arch/x86/hvm/hvm.c +7
-7@@ -571,16 +571,16 @@ static int cf_check hvm_print_line(if ( !is_console_printable (c) )return X86EMUL_OKAY ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock);if ( c !='\n' ) - cd->pbuf[cd->pbuf_idx++] = c; -if ( (cd->pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) + cd->console.pbuf[cd->console.pbuf_idx++] = c; +if ( (cd->console.pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->pbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->console.pbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock);return X86EMUL_OKAY ; }xen/common/domain.c +4
-4@@ -669,7 +669,7 @@ static void _domain_destroy(struct domain *d)BUG_ON (!d->is_dying);BUG_ON (atomic_read (&d->refcnt) !=DOMAIN_DESTROYED ); -xfree (d->pbuf); +xfree (d->console.pbuf);argo_destroy (d);@@ -862,7 +862,7 @@ struct domain *domain_create(domid_t domid,spin_lock_init (&d->shutdown_lock); d->shutdown_code =SHUTDOWN_CODE_INVALID ; -spin_lock_init (&d->pbuf_lock); +spin_lock_init (&d->console.pbuf_lock);rwlock_init (&d->vnuma_rwlock);@@ -956,8 +956,8 @@ struct domain *domain_create(domid_t domid, goto fail; err = -ENOMEM ; - d->pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); -if ( !d->pbuf ) + d->console.pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); +if ( !d->console.pbuf ) goto fail;if ( (err =sched_init_domain (d, config->cpupool_id)) !=0 )xen/drivers/char/console.c +0
-0
xen/drivers/char/console.c static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, · line 775
Quoted 9 lines
xen/drivers/char/console.c +2
-2@@ -769,22 +769,25 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, }while ( --kcount >0 ); *kout ='\0' ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock); kcount = kin - kbuf;if ( c !='\n' && - (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE -1 )) ) + cd->console.pbuf_idx + kout - kbuf <DOMAIN_PBUF_SIZE -1 )
I don't think we want to drop the parentheses here.
Quoted 44 lines
xen/drivers/char/console.c +9
-6{/* buffer the output until a newline */ -memcpy (cd->pbuf + cd->pbuf_idx, kbuf, kout - kbuf); - cd->pbuf_idx += (kout - kbuf); +memcpy (cd->console.pbuf + cd->console.pbuf_idx, + kbuf, + kout - kbuf); + cd->console.pbuf_idx += (kout - kbuf); } else { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s%s\n" , cd->pbuf, kbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd, +XENLOG_G_DEBUG "%s%s\n" , cd->console.pbuf, kbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock); }guest_handle_add_offset (buffer, kcount);xen/include/xen/sched.h +0
-6@@ -562,12 +562,6 @@ struct domain/* Control-plane tools handle for this domain. */ xen_domain_handle_t handle; -/* hvm_print_line() and guest_console_write() logging. */ -#define DOMAIN_PBUF_SIZE 200 -char *pbuf; -unsigned int pbuf_idx; -spinlock_t pbuf_lock; -/* OProfile support. */ struct xenoprof *xenoprof;@@ -654,6 +648,12 @@ struct domain/* Console settings. */
xen/include/xen/sched.h struct domain · line 659
Quoted 10 lines
xen/include/xen/sched.h +6
-0struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Quoted 85 lines · Teddy Astie
Hello,
Le 06/06/2025 à 21:51, [email protected] a écrit :
Quoted 82 lines
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
No functional change.
Signed-off-by Denis Mukhin <[email protected]>--- xen/arch/x86/hvm/hvm.c | 14 +++++++------- xen/common/domain.c | 8 ++++---- xen/drivers/char/console.c | 19 +++++++++++-------- xen/include/xen/sched.h | 12 ++++++------ 4 files changed, 28 insertions(+), 25 deletions(-)xen/arch/x86/hvm/hvm.c +7
-7@@ -571,16 +571,16 @@ static int cf_check hvm_print_line(if ( !is_console_printable (c) )return X86EMUL_OKAY ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock);if ( c !='\n' ) - cd->pbuf[cd->pbuf_idx++] = c; -if ( (cd->pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) + cd->console.pbuf[cd->console.pbuf_idx++] = c; +if ( (cd->console.pbuf_idx == (DOMAIN_PBUF_SIZE -1 )) || (c =='\n' ) ) { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->pbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd,XENLOG_G_DEBUG "%s\n" , cd->console.pbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock);return X86EMUL_OKAY ; }xen/common/domain.c +4
-4@@ -669,7 +669,7 @@ static void _domain_destroy(struct domain *d)BUG_ON (!d->is_dying);BUG_ON (atomic_read (&d->refcnt) !=DOMAIN_DESTROYED ); -xfree (d->pbuf); +xfree (d->console.pbuf);argo_destroy (d);@@ -862,7 +862,7 @@ struct domain *domain_create(domid_t domid,spin_lock_init (&d->shutdown_lock); d->shutdown_code =SHUTDOWN_CODE_INVALID ; -spin_lock_init (&d->pbuf_lock); +spin_lock_init (&d->console.pbuf_lock);rwlock_init (&d->vnuma_rwlock);@@ -956,8 +956,8 @@ struct domain *domain_create(domid_t domid, goto fail; err = -ENOMEM ; - d->pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); -if ( !d->pbuf ) + d->console.pbuf =xzalloc_array (char,DOMAIN_PBUF_SIZE ); +if ( !d->console.pbuf ) goto fail;if ( (err =sched_init_domain (d, config->cpupool_id)) !=0 )xen/drivers/char/console.c +0
-0@@ -769,22 +769,25 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, }while ( --kcount >0 );
Quoted 9 lines
xen/drivers/char/console.c static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, · line 775
Quoted 7 lines
xen/drivers/char/console.c +2
-2*kout ='\0' ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock); kcount = kin - kbuf;if ( c !='\n' && - (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE -1 )) ) + cd->console.pbuf_idx + kout - kbuf <DOMAIN_PBUF_SIZE -1 )I don't think we want to drop the parentheses here.
The line will will exceed 80 chars if I keep parentheses.
Will something like the following work:
- (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE - 1)) )
+ (cd->console.pbuf_idx + (kout - kbuf) <
+ (DOMAIN_PBUF_SIZE - 1)) )
?
Quoted 64 lines
Quoted 45 lines
xen/drivers/char/console.c +9
-6{/* buffer the output until a newline */ -memcpy (cd->pbuf + cd->pbuf_idx, kbuf, kout - kbuf); - cd->pbuf_idx += (kout - kbuf); +memcpy (cd->console.pbuf + cd->console.pbuf_idx, + kbuf, + kout - kbuf); + cd->console.pbuf_idx += (kout - kbuf); } else { - cd->pbuf[cd->pbuf_idx] ='\0' ; -guest_printk (cd,XENLOG_G_DEBUG "%s%s\n" , cd->pbuf, kbuf); - cd->pbuf_idx =0 ; + cd->console.pbuf[cd->console.pbuf_idx] ='\0' ; +guest_printk (cd, +XENLOG_G_DEBUG "%s%s\n" , cd->console.pbuf, kbuf); + cd->console.pbuf_idx =0 ; } -spin_unlock (&cd->pbuf_lock); +spin_unlock (&cd->console.pbuf_lock); }guest_handle_add_offset (buffer, kcount);xen/include/xen/sched.h +0
-6@@ -562,12 +562,6 @@ struct domain/* Control-plane tools handle for this domain. */ xen_domain_handle_t handle; -/* hvm_print_line() and guest_console_write() logging. */ -#define DOMAIN_PBUF_SIZE 200 -char *pbuf; -unsigned int pbuf_idx; -spinlock_t pbuf_lock; -/* OProfile support. */ struct xenoprof *xenoprof;@@ -654,6 +648,12 @@ struct domain/* Console settings. */ xen/include/xen/sched.h struct domain · line 659
Quoted 10 lines
xen/include/xen/sched.h +6
-0struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Quoted 7 lines · On 07.06.2025 01:06, [email protected] wrote:
Quoted 6 lines · Teddy Astie
Le 06/06/2025 à 21:51, [email protected] a écrit :
Quoted 5 lines
xen/drivers/char/console.c +0
-0@@ -769,22 +769,25 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, }while ( --kcount >0 );
Quoted 9 lines
Quoted 9 lines
xen/drivers/char/console.c static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, · line 775
Quoted 7 lines
xen/drivers/char/console.c +2
-2*kout ='\0' ; -spin_lock (&cd->pbuf_lock); +spin_lock (&cd->console.pbuf_lock); kcount = kin - kbuf;if ( c !='\n' && - (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE -1 )) ) + cd->console.pbuf_idx + kout - kbuf <DOMAIN_PBUF_SIZE -1 )I don't think we want to drop the parentheses here.
I don't see any issue with doing so - they don't serve much of a purpose here.
Quoted 9 lines
The line will will exceed 80 chars if I keep parentheses.
Will something like the following work:
(quoted diff) +2
-1- (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE - 1)) ) + (cd->console.pbuf_idx + (kout - kbuf) < + (DOMAIN_PBUF_SIZE - 1)) )?
Well, indentation of the latter of the two new lines is two too deep, as it looks.
Jan
Quoted 3 lines · On 06.06.2025 21:49, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
Fine with me in principle, as I was indeed wondering about the lack of grouping when the sub-struct was introduced, but ...
xen/include/xen/sched.h struct domain · line 659
Quoted 13 lines
xen/include/xen/sched.h +6
-0@@ -654,6 +648,12 @@ struct domain/* Console settings. */ struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;
... since all uses of the fields need touching anyway, can we perhaps think of giving the fields better names? I never understood what the 'p' in "pbuf" actually stands for, for example. My suggestion would be to replace "pbuf" by "glog" (for "guest logging"), but surely there are alternatives.
Jan
Quoted 9 lines · Jan Beulich
Quoted 3 lines · On 06.06.2025 21:49, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
Fine with me in principle, as I was indeed wondering about the lack of grouping when the sub-struct was introduced, but ...
Quoted 2 lines
(quoted diff) +0
-0@@ -654,6 +648,12 @@ struct domain
Quoted 14 lines
xen/include/xen/sched.h struct domain · line 659
Quoted 11 lines
xen/include/xen/sched.h +6
-0/* Console settings. */ struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;... since all uses of the fields need touching anyway, can we perhaps think of giving the fields better names? I never understood what the 'p' in "pbuf" actually stands for, for example.
I always assumed it was Hungarian notation, so pointer.
As it's namespaced within .console, plain .buf, .idx and .lock names work fine.
Separately, 200 is a silly and arbitrary number. Furthermore the allocation is unconditional, despite the fact that in !VERSBOSE builds, domUs can't use this facility. Also, where's the input buffer?
~Andrew
Quoted 25 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 3 lines · On 06.06.2025 21:49, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
Fine with me in principle, as I was indeed wondering about the lack of grouping when the sub-struct was introduced, but ...
Quoted 2 lines
(quoted diff) +0
-0@@ -654,6 +648,12 @@ struct domainQuoted 14 lines
xen/include/xen/sched.h struct domain · line 659
Quoted 11 lines
xen/include/xen/sched.h +6
-0/* Console settings. */ struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */ bool input_allowed; } console;... since all uses of the fields need touching anyway, can we perhaps think of giving the fields better names? I never understood what the 'p' in "pbuf" actually stands for, for example.
Quoted 4 lines
I always assumed it was Hungarian notation, so pointer.
As it's namespaced within .console, plain .buf, .idx and .lock names work fine.
Ack.
Quoted 4 lines
Separately, 200 is a silly and arbitrary number. Furthermore the allocation is unconditional, despite the fact that in !VERSBOSE builds, domUs can't use this facility. Also, where's the input buffer?
Thanks!
I will try to address those under individual changes.
re: arbitrary number: Will bumping the buffer size to the next power of 2 == 256 work?
re: input buffer: Looks like there's only global serial_rx_ring buffer in current design. My guess - because the input buffer is shared between domains and Xen itself which does not have domain struct associated with it.
Quoted 2 lines
~Andrew
Quoted 11 lines · On 10.06.2025 20:02, [email protected] wrote:
Quoted 3 lines · Andrew Cooper
Separately, 200 is a silly and arbitrary number. Furthermore the allocation is unconditional, despite the fact that in !VERSBOSE builds, domUs can't use this facility. Also, where's the input buffer?
Thanks!
I will try to address those under individual changes.
re: arbitrary number: Will bumping the buffer size to the next power of 2 == 256 work?
Any other number would work, but would be as arbitrary. Since the buffer is dynamically allocated, one non-arbitrary aspect of the selection may want to be to make the number such that including allocation overhead it's an even multiple of cache line size.
Jan
Quoted 19 lines · Jan Beulich
Quoted 3 lines · On 06.06.2025 21:49, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Group all pbuf-related data structures under domain's console field.
Fine with me in principle, as I was indeed wondering about the lack of grouping when the sub-struct was introduced, but ...
Quoted 11 lines
xen/include/xen/sched.h +6
-0@@ -654,6 +648,12 @@ struct domain/* Console settings. */ struct { +/* hvm_print_line() and guest_console_write() logging. */ +#define DOMAIN_PBUF_SIZE 200 +char *pbuf; +unsigned int pbuf_idx; +spinlock_t pbuf_lock; +/* Permission to take ownership of the physical console input. */
Quoted 8 lines
xen/include/xen/sched.h struct domain · line 659
Quoted 2 lines
xen/include/xen/sched.h +0
-0bool input_allowed; } console;... since all uses of the fields need touching anyway, can we perhaps think of giving the fields better names? I never understood what the 'p' in "pbuf" actually stands for, for example. My suggestion would be to replace "pbuf" by "glog" (for "guest logging"), but surely there are alternatives.
Sounds good to me.
I can do renaming in v2.
Quoted 3 lines
Jan