All of lore.kernel.org
 help / color / mirror / Atom feed
From: dmkhn@proton.me
To: Teddy Astie <teddy.astie@vates.tech>
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
	anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
	michal.orzel@amd.com, roger.pau@citrix.com,
	sstabellini@kernel.org, dmukhin@ford.com
Subject: Re: [PATCH v1] xen/console: group pbuf under console field
Date: Fri, 06 Jun 2025 23:06:57 +0000	[thread overview]
Message-ID: <aEN0i6tD3humMN3a@kraken> (raw)
In-Reply-To: <00ffcc4b-b63e-4b4d-8b8f-8d02fb7ef234@vates.tech>

On Fri, Jun 06, 2025 at 08:24:44PM +0000, Teddy Astie wrote:
> Hello,
> 
> Le 06/06/2025 à 21:51, dmkhn@proton.me a écrit :
> > From: Denis Mukhin <dmukhin@ford.com>
> >
> > Group all pbuf-related data structures under domain's console field.
> >
> > No functional change.
> >
> > Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> > ---
> >   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(-)
> >
> > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> > index 4cb2e13046..17d1fd42ce 100644
> > --- a/xen/arch/x86/hvm/hvm.c
> > +++ b/xen/arch/x86/hvm/hvm.c
> > @@ -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;
> >   }
> > diff --git a/xen/common/domain.c b/xen/common/domain.c
> > index 153cd75340..dd1867b2fe 100644
> > --- a/xen/common/domain.c
> > +++ b/xen/common/domain.c
> > @@ -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 )
> > diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> > index 616f4968b0..3855962af7 100644
> > --- a/xen/drivers/char/console.c
> > +++ b/xen/drivers/char/console.c
> > @@ -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.

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)) )

?

> 
> >               {
> >                   /* 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);
> > diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
> > index fe53d4fab7..637aa09ec4 100644
> > --- a/xen/include/xen/sched.h
> > +++ b/xen/include/xen/sched.h
> > @@ -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;
> 
> 
> Teddy Astie | Vates XCP-ng Developer
> 
> XCP-ng & Xen Orchestra - Vates solutions
> 
> web: https://vates.tech
> 
> 



  reply	other threads:[~2025-06-06 23:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06 19:49 [PATCH v1] xen/console: group pbuf under console field dmkhn
2025-06-06 20:24 ` Teddy Astie
2025-06-06 23:06   ` dmkhn [this message]
2025-06-10  7:21     ` Jan Beulich
2025-06-10  8:10 ` Jan Beulich
2025-06-10 11:24   ` Andrew Cooper
2025-06-10 18:02     ` dmkhn
2025-06-11  5:26       ` Jan Beulich
2025-06-10 17:37   ` dmkhn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aEN0i6tD3humMN3a@kraken \
    --to=dmkhn@proton.me \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmukhin@ford.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=teddy.astie@vates.tech \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.