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 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm