From: Will Deacon <will@kernel.org>
To: Marc Zyngier <maz@kernel.org>
Cc: Steven Price <steven.price@arm.com>,
netdev@vger.kernel.org, yangbo.lu@nxp.com,
john.stultz@linaro.org, tglx@linutronix.de, pbonzini@redhat.com,
seanjc@google.com, richardcochran@gmail.com,
Mark.Rutland@arm.com, suzuki.poulose@arm.com,
Andre.Przywara@arm.com, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
Steve.Capper@arm.com, justin.he@arm.com, jianyong.wu@arm.com,
kernel-team@android.com
Subject: Re: [PATCH v17 1/7] arm/arm64: Probe for the presence of KVM hypervisor
Date: Fri, 5 Feb 2021 17:00:06 +0000 [thread overview]
Message-ID: <20210205170005.GC22665@willie-the-truck> (raw)
In-Reply-To: <e2eefee823f6a8e448f6d477cef315d4@kernel.org>
On Fri, Feb 05, 2021 at 04:50:27PM +0000, Marc Zyngier wrote:
> On 2021-02-05 11:19, Will Deacon wrote:
> > On Fri, Feb 05, 2021 at 09:11:00AM +0000, Steven Price wrote:
> > > On 02/02/2021 14:11, Marc Zyngier wrote:
> > > > + for (i = 0; i < 32; ++i) {
> > > > + if (res.a0 & (i))
> > > > + set_bit(i + (32 * 0), __kvm_arm_hyp_services);
> > > > + if (res.a1 & (i))
> > > > + set_bit(i + (32 * 1), __kvm_arm_hyp_services);
> > > > + if (res.a2 & (i))
> > > > + set_bit(i + (32 * 2), __kvm_arm_hyp_services);
> > > > + if (res.a3 & (i))
> > > > + set_bit(i + (32 * 3), __kvm_arm_hyp_services);
> > >
> > > The bit shifts are missing, the tests should be of the form:
> > >
> > > if (res.a0 & (1 << i))
> > >
> > > Or indeed using a BIT() macro.
> >
> > Maybe even test_bit()?
>
> Actually, maybe not doing things a-bit-at-a-time is less error prone.
> See below what I intend to fold in.
>
> Thanks,
>
> M.
>
> diff --git a/drivers/firmware/smccc/kvm_guest.c
> b/drivers/firmware/smccc/kvm_guest.c
> index 00bf3c7969fc..08836f2f39ee 100644
> --- a/drivers/firmware/smccc/kvm_guest.c
> +++ b/drivers/firmware/smccc/kvm_guest.c
> @@ -2,8 +2,8 @@
>
> #define pr_fmt(fmt) "smccc: KVM: " fmt
>
> -#include <linux/init.h>
> #include <linux/arm-smccc.h>
> +#include <linux/bitmap.h>
> #include <linux/kernel.h>
> #include <linux/string.h>
>
> @@ -13,8 +13,8 @@ static DECLARE_BITMAP(__kvm_arm_hyp_services,
> ARM_SMCCC_KVM_NUM_FUNCS) __ro_afte
>
> void __init kvm_init_hyp_services(void)
> {
> - int i;
> struct arm_smccc_res res;
> + u32 val[4];
>
> if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
> return;
> @@ -28,16 +28,13 @@ void __init kvm_init_hyp_services(void)
>
> memset(&res, 0, sizeof(res));
> arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID, &res);
> - for (i = 0; i < 32; ++i) {
> - if (res.a0 & (i))
> - set_bit(i + (32 * 0), __kvm_arm_hyp_services);
> - if (res.a1 & (i))
> - set_bit(i + (32 * 1), __kvm_arm_hyp_services);
> - if (res.a2 & (i))
> - set_bit(i + (32 * 2), __kvm_arm_hyp_services);
> - if (res.a3 & (i))
> - set_bit(i + (32 * 3), __kvm_arm_hyp_services);
> - }
> +
> + val[0] = lower_32_bits(res.a0);
> + val[1] = lower_32_bits(res.a1);
> + val[2] = lower_32_bits(res.a2);
> + val[3] = lower_32_bits(res.a3);
> +
> + bitmap_from_arr32(__kvm_arm_hyp_services, val, ARM_SMCCC_KVM_NUM_FUNCS);
Nice! That's loads better.
Will
next prev parent reply other threads:[~2021-02-05 20:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 14:11 [PATCH v17 0/7] KVM: arm64: Add host/guest KVM-PTP support Marc Zyngier
2021-02-02 14:11 ` [PATCH v17 1/7] arm/arm64: Probe for the presence of KVM hypervisor Marc Zyngier
2021-02-05 9:11 ` Steven Price
2021-02-05 11:19 ` Will Deacon
2021-02-05 11:23 ` Marc Zyngier
2021-02-05 16:50 ` Marc Zyngier
2021-02-05 17:00 ` Will Deacon [this message]
2021-02-02 14:11 ` [PATCH v17 2/7] KVM: arm64: Advertise KVM UID to guests via SMCCC Marc Zyngier
2021-02-02 14:12 ` [PATCH v17 3/7] ptp: Reorganize ptp_kvm.c to make it arch-independent Marc Zyngier
2021-02-02 14:12 ` [PATCH v17 4/7] time: Add mechanism to recognize clocksource in time_get_snapshot Marc Zyngier
2021-02-02 14:12 ` [PATCH v17 5/7] clocksource: Add clocksource id for arm arch counter Marc Zyngier
2021-02-02 14:12 ` [PATCH v17 6/7] KVM: arm64: Add support for the KVM PTP service Marc Zyngier
2021-02-02 14:12 ` [PATCH v17 7/7] ptp: arm/arm64: Enable ptp_kvm for arm/arm64 Marc Zyngier
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=20210205170005.GC22665@willie-the-truck \
--to=will@kernel.org \
--cc=Andre.Przywara@arm.com \
--cc=Mark.Rutland@arm.com \
--cc=Steve.Capper@arm.com \
--cc=jianyong.wu@arm.com \
--cc=john.stultz@linaro.org \
--cc=justin.he@arm.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=richardcochran@gmail.com \
--cc=seanjc@google.com \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=tglx@linutronix.de \
--cc=yangbo.lu@nxp.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).