From: Joerg Roedel <joro@8bytes.org>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Joerg Roedel <jroedel@suse.de>
Subject: Re: [PATCH 3/4] KVM: SVM: Add GHCB Accessor functions
Date: Thu, 30 Jul 2020 15:05:31 +0200 [thread overview]
Message-ID: <20200730130531.GC3257@8bytes.org> (raw)
In-Reply-To: <20200729154328.GC27751@linux.intel.com>
On Wed, Jul 29, 2020 at 08:43:28AM -0700, Sean Christopherson wrote:
> Rather than manually calculate the byte/bit indices just use __set_bit()
> and test_bit(). That will also solve the variable declaration issue.
>
> E.g.
>
> #define GHB_BITMAP_IDX(field) \
> (offsetof(struct vmcb_save_area, (field)) / sizeof(u64))
>
> #define GHCB_SET_VALID(ghcb, field) \
> __set_bit(GHCB_BITMAP_IDX(field), (unsigned long *)&ghcb->save.valid_bitmap)
>
> Or alternatively drop GHCB_SET_VALID() and just open code the two users.
Thanks for your suggestions, I updated the patch and will do some
testing before re-posting.
Regards,
Joerg
>
> > + }
> > +
> > +#define DEFINE_GHCB_SETTER(field) \
> > + static inline void \
> > + ghcb_set_##field(struct ghcb *ghcb, u64 value) \
> > + { \
> > + GHCB_SET_VALID(ghcb, field) \
> > + (ghcb)->save.field = value; \
>
>
> The ghcb doesn't need to be wrapped in (), it's a parameter to a function.
> Same comment for the below usage.
>
> > + }
> > +
> > +#define DEFINE_GHCB_ACCESSORS(field) \
> > + static inline bool ghcb_is_valid_##field(const struct ghcb *ghcb) \
>
> I'd prefer to follow the naming of the arch reg accessors, i.e.
>
> static inline bool ghcb_##field##_is_valid(...)
>
> to pair with
>
> kvm_##lname##_read
> kvm_##lname##_write
>
> And because ghcb_is_valid_rip() reads a bit weird, e.g. IMO is more likely
> to be read as "does the RIP in the GHCB hold a valid (canonical) value",
> versus ghcb_rip_is_valid() reading as "is RIP valid in the GHCB".
>
> > + { \
> > + DEFINE_GHCB_INDICES(field) \
> > + return !!((ghcb)->save.valid_bitmap[byte_idx] \
> > + & BIT(bit_idx)); \
> > + } \
> > + \
> > + static inline void \
> > + ghcb_set_##field(struct ghcb *ghcb, u64 value) \
> > + { \
> > + GHCB_SET_VALID(ghcb, field) \
> > + (ghcb)->save.field = value; \
>
> > + }
> > +
> > +DEFINE_GHCB_ACCESSORS(cpl)
> > +DEFINE_GHCB_ACCESSORS(rip)
> > +DEFINE_GHCB_ACCESSORS(rsp)
> > +DEFINE_GHCB_ACCESSORS(rax)
> > +DEFINE_GHCB_ACCESSORS(rcx)
> > +DEFINE_GHCB_ACCESSORS(rdx)
> > +DEFINE_GHCB_ACCESSORS(rbx)
> > +DEFINE_GHCB_ACCESSORS(rbp)
> > +DEFINE_GHCB_ACCESSORS(rsi)
> > +DEFINE_GHCB_ACCESSORS(rdi)
> > +DEFINE_GHCB_ACCESSORS(r8)
> > +DEFINE_GHCB_ACCESSORS(r9)
> > +DEFINE_GHCB_ACCESSORS(r10)
> > +DEFINE_GHCB_ACCESSORS(r11)
> > +DEFINE_GHCB_ACCESSORS(r12)
> > +DEFINE_GHCB_ACCESSORS(r13)
> > +DEFINE_GHCB_ACCESSORS(r14)
> > +DEFINE_GHCB_ACCESSORS(r15)
> > +DEFINE_GHCB_ACCESSORS(sw_exit_code)
> > +DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
> > +DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
> > +DEFINE_GHCB_ACCESSORS(sw_scratch)
> > +DEFINE_GHCB_ACCESSORS(xcr0)
> > +
> > #endif
> > --
> > 2.17.1
> >
next prev parent reply other threads:[~2020-07-30 13:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 13:22 [PATCH 0/4] KVM: SVM: SEV-ES groundwork Joerg Roedel
2020-07-29 13:22 ` [PATCH 1/4] KVM: SVM: nested: Don't allocate VMCB structures on stack Joerg Roedel
2020-07-29 15:14 ` Sean Christopherson
2020-07-30 12:38 ` Joerg Roedel
2020-07-29 13:22 ` [PATCH 2/4] KVM: SVM: Add GHCB definitions Joerg Roedel
2020-07-29 13:22 ` [PATCH 3/4] KVM: SVM: Add GHCB Accessor functions Joerg Roedel
2020-07-29 15:43 ` Sean Christopherson
2020-07-30 13:05 ` Joerg Roedel [this message]
2020-07-29 13:22 ` [PATCH 4/4] KVM: SVM: Use __packed shorthand Joerg Roedel
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=20200730130531.GC3257@8bytes.org \
--to=joro@8bytes.org \
--cc=jmattson@google.com \
--cc=jroedel@suse.de \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).