From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Anthony PERARD <anthony@xenproject.org>,
Juergen Gross <jgross@suse.com>, Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v3 1/2] tools/xg: Streamline cpu policy serialise/deserialise calls
Date: Fri, 24 May 2024 13:02:48 +0200 [thread overview]
Message-ID: <ZlBz2HSAjvNWJ41B@macbook> (raw)
In-Reply-To: <de256e4b-fdc4-48a8-9173-38092ab90716@cloud.com>
On Fri, May 24, 2024 at 11:32:50AM +0100, Alejandro Vallejo wrote:
> On 23/05/2024 11:21, Roger Pau Monné wrote:
> > On Thu, May 23, 2024 at 10:41:29AM +0100, Alejandro Vallejo wrote:
> >> -int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t *p,
> >> - xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves,
> >> - xen_msr_entry_t *msrs, uint32_t *nr_msrs)
> >> +int xc_cpu_policy_serialise(xc_interface *xch, xc_cpu_policy_t *p)
> >> {
> >> + unsigned int nr_leaves = ARRAY_SIZE(p->leaves);
> >> + unsigned int nr_msrs = ARRAY_SIZE(p->msrs);
> >> int rc;
> >>
> >> - if ( leaves )
> >> + rc = x86_cpuid_copy_to_buffer(&p->policy, p->leaves, &nr_leaves);
> >> + if ( rc )
> >> {
> >> - rc = x86_cpuid_copy_to_buffer(&p->policy, leaves, nr_leaves);
> >> - if ( rc )
> >> - {
> >> - ERROR("Failed to serialize CPUID policy");
> >> - errno = -rc;
> >> - return -1;
> >> - }
> >> + ERROR("Failed to serialize CPUID policy");
> >> + errno = -rc;
> >> + return -1;
> >> }
> >>
> >> - if ( msrs )
> >> + p->nr_leaves = nr_leaves;
> >
> > Nit: FWIW, I think you could avoid having to introduce local
> > nr_{leaves,msrs} variables and just use p->nr_{leaves,msrs}? By
> > setting them to ARRAY_SIZE() at the top of the function and then
> > letting x86_{cpuid,msr}_copy_to_buffer() adjust as necessary.
> >
> > Thanks, Roger.
>
> The intent was to avoid mutating the policy object in the error cases
> during deserialise. Then I adjusted the serialise case to have symmetry.
It's currently unavoidable for the policy to be likely mutated even in
case of error, as x86_{cpuid,msr}_copy_to_buffer() are two separate
operations, and hence the first succeeding but the second failing will
already result in the policy being mutated on error.
> It's true the preservation is not meaningful in the serialise case
> because at that point the serialised form is already corrupted.
>
> I don't mind either way. Seeing how I'm sending one final version with
> the comments of patch2 I'll just adjust as you proposed.
I'm fine either way (hence why prefix it with "nit:") albeit I have a
preference for not introducing the local variables if they are not
needed.
Thanks, Roger.
next prev parent reply other threads:[~2024-05-24 11:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 9:41 [PATCH v3 0/2] Clean the policy manipulation path in domain creation Alejandro Vallejo
2024-05-23 9:41 ` [PATCH v3 1/2] tools/xg: Streamline cpu policy serialise/deserialise calls Alejandro Vallejo
2024-05-23 10:21 ` Roger Pau Monné
2024-05-24 10:32 ` Alejandro Vallejo
2024-05-24 11:02 ` Roger Pau Monné [this message]
2024-05-23 9:41 ` [PATCH v3 2/2] tools/xg: Clean up xend-style overrides for CPU policies Alejandro Vallejo
2024-05-23 10:47 ` Roger Pau Monné
2024-05-24 10:31 ` Alejandro Vallejo
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=ZlBz2HSAjvNWJ41B@macbook \
--to=roger.pau@citrix.com \
--cc=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony@xenproject.org \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--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.