From: Oliver Upton <oliver.upton@linux.dev>
To: Ricardo Koller <ricarkol@google.com>
Cc: Reiji Watanabe <reijiw@google.com>,
kvm@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
Andrew Jones <andrew.jones@linux.dev>,
Paolo Bonzini <pbonzini@redhat.com>,
kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/9] KVM: arm64: selftests: Add helpers to extract a field of an ID register
Date: Thu, 25 Aug 2022 09:58:09 -0700 [thread overview]
Message-ID: <YweqIefFbP107fe+@google.com> (raw)
In-Reply-To: <Yweo5cmA6D0pxwmJ@google.com>
On Thu, Aug 25, 2022 at 09:52:53AM -0700, Ricardo Koller wrote:
> On Thu, Aug 25, 2022 at 09:48:35AM -0700, Oliver Upton wrote:
> > Hi Reiji,
> >
> > On Wed, Aug 24, 2022 at 10:08:38PM -0700, Reiji Watanabe wrote:
> > > Introduce helpers to extract a field of an ID register.
> > > Subsequent patches will use those helpers.
> > >
> > > Signed-off-by: Reiji Watanabe <reijiw@google.com>
> > > ---
> > > .../selftests/kvm/include/aarch64/processor.h | 2 ++
> > > .../testing/selftests/kvm/lib/aarch64/processor.c | 15 +++++++++++++++
> > > 2 files changed, 17 insertions(+)
> > >
> > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> > > index a8124f9dd68a..a9b4b4e0e592 100644
> > > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> > > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> > > @@ -193,4 +193,6 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1,
> > >
> > > uint32_t guest_get_vcpuid(void);
> > >
> > > +int cpuid_get_sfield(uint64_t val, int field_shift);
> > > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift);
> > > #endif /* SELFTEST_KVM_PROCESSOR_H */
> > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > > index 6f5551368944..0b2ad46e7ff5 100644
> > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> > > @@ -528,3 +528,18 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1,
> > > [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6)
> > > : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7");
> > > }
> > > +
> > > +/* Helpers to get a signed/unsigned feature field from ID register value */
> > > +int cpuid_get_sfield(uint64_t val, int field_shift)
> > > +{
> > > + int width = 4;
> > > +
> > > + return (int64_t)(val << (64 - width - field_shift)) >> (64 - width);
> > > +}
> >
> > I don't believe this helper is ever used.
> >
> > > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift)
> > > +{
> > > + int width = 4;
> > > +
> > > + return (uint64_t)(val << (64 - width - field_shift)) >> (64 - width);
> > > +}
> >
> > I would recommend not open-coding this and instead make use of
> > ARM64_FEATURE_MASK(). You could pull in linux/bitfield.h to tools, or do
> > something like this:
> >
> > #define ARM64_FEATURE_GET(ftr, val) \
> > ((ARM64_FEATURE_MASK(ftr) & val) >> ftr##_SHIFT)
> >
> > Slight preference for FIELD_{GET,SET}() as it matches the field
> > extraction in the kernel as well.
>
> Was doing that with this commit:
>
> [PATCH v5 05/13] tools: Copy bitfield.h from the kernel sources
>
> Maybe you could just use it given that it's already reviewed.
Oops, thanks for the reminder Ricardo! Yeah, let's go that route then.
--
Thanks,
Oliver
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-08-25 16:59 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 5:08 [PATCH 0/9] KVM: arm64: selftests: Test linked {break,watch}points Reiji Watanabe
2022-08-25 5:08 ` [PATCH 1/9] KVM: arm64: selftests: Add helpers to extract a field of an ID register Reiji Watanabe
2022-08-25 16:48 ` Oliver Upton
2022-08-25 16:52 ` Ricardo Koller
2022-08-25 16:58 ` Oliver Upton [this message]
2022-08-26 0:50 ` Reiji Watanabe
2022-08-25 5:08 ` [PATCH 2/9] KVM: arm64: selftests: Add write_dbg{b,w}{c,v}r helpers in debug-exceptions Reiji Watanabe
2022-09-09 19:40 ` Ricardo Koller
2022-08-25 5:08 ` [PATCH 3/9] KVM: arm64: selftests: Remove the hard-coded {b,w}pn#0 from debug-exceptions Reiji Watanabe
2022-08-25 16:55 ` Oliver Upton
2022-08-26 0:53 ` Reiji Watanabe
2022-09-09 19:46 ` Ricardo Koller
2022-09-10 4:15 ` Reiji Watanabe
2022-08-25 5:08 ` [PATCH 4/9] KVM: arm64: selftests: Add helpers to enable debug exceptions Reiji Watanabe
2022-08-25 17:21 ` Oliver Upton
2022-08-26 0:55 ` Reiji Watanabe
2022-09-09 19:57 ` Ricardo Koller
2022-08-25 5:08 ` [PATCH 5/9] KVM: arm64: selftests: Have debug_version() use cpuid_get_ufield() helper Reiji Watanabe
2022-08-25 17:29 ` Oliver Upton
2022-08-26 0:59 ` Reiji Watanabe
2022-08-25 5:08 ` [PATCH 6/9] KVM: arm64: selftests: Change debug_version() to take ID_AA64DFR0_EL1 Reiji Watanabe
2022-08-25 5:08 ` [PATCH 7/9] KVM: arm64: selftests: Add a test case for a linked breakpoint Reiji Watanabe
2022-08-26 1:29 ` Reiji Watanabe
2022-09-09 20:18 ` Ricardo Koller
2022-09-09 20:26 ` Ricardo Koller
2022-09-10 5:22 ` Reiji Watanabe
2022-09-09 21:01 ` Ricardo Koller
2022-09-10 5:19 ` Reiji Watanabe
2022-08-25 5:08 ` [PATCH 8/9] KVM: arm64: selftests: Add a test case for a linked watchpoint Reiji Watanabe
2022-08-25 5:08 ` [PATCH 9/9] KVM: arm64: selftests: Test with every breakpoint/watchpoint Reiji Watanabe
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=YweqIefFbP107fe+@google.com \
--to=oliver.upton@linux.dev \
--cc=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=reijiw@google.com \
--cc=ricarkol@google.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).