lkml.org 
[lkml]   [2022]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] powerpc/kvm: don't crash on missing rng, and use darn
Hi Fabiano,

On Fri, Jun 24, 2022 at 3:43 PM Fabiano Rosas <farosas@linux.ibm.com> wrote:
>
> "Jason A. Donenfeld" <Jason@zx2c4.com> writes:
>
> > On POWER8 systems that don't have ibm,power-rng available, a guest that
> > ignores the KVM_CAP_PPC_HWRNG flag and calls H_RANDOM anyway will
> > dereference a NULL pointer. And on machines with darn instead of
> > ibm,power-rng, H_RANDOM won't work at all.
> >
> > This patch kills two birds with one stone, by routing H_RANDOM calls to
> > ppc_md.get_random_seed, and doing the real mode check inside of it.
> >
> > Cc: stable@vger.kernel.org # v4.1+
> > Cc: Michael Ellerman <mpe@ellerman.id.au>
> > Fixes: e928e9cb3601 ("KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM implementation.")
> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > ---
> >
> > This patch must be applied ontop of:
> > 1) https://github.com/linuxppc/linux/commit/f3eac426657d985b97c92fa5f7ae1d43f04721f3
> > 2) https://lore.kernel.org/all/20220622102532.173393-1-Jason@zx2c4.com/
> >
> >
> > arch/powerpc/include/asm/archrandom.h | 5 ----
> > arch/powerpc/kvm/book3s_hv_builtin.c | 5 ++--
> > arch/powerpc/platforms/powernv/rng.c | 33 +++++++--------------------
> > 3 files changed, 11 insertions(+), 32 deletions(-)
> >
> > diff --git a/arch/powerpc/include/asm/archrandom.h b/arch/powerpc/include/asm/archrandom.h
> > index 11d4815841ab..3af27bb84a3d 100644
> > --- a/arch/powerpc/include/asm/archrandom.h
> > +++ b/arch/powerpc/include/asm/archrandom.h
> > @@ -38,12 +38,7 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
> > #endif /* CONFIG_ARCH_RANDOM */
> >
> > #ifdef CONFIG_PPC_POWERNV
> > -int pnv_hwrng_present(void);
> > int pnv_get_random_long(unsigned long *v);
> > -int pnv_get_random_real_mode(unsigned long *v);
> > -#else
> > -static inline int pnv_hwrng_present(void) { return 0; }
> > -static inline int pnv_get_random_real_mode(unsigned long *v) { return 0; }
> > #endif
> >
> > #endif /* _ASM_POWERPC_ARCHRANDOM_H */
> > diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
> > index 799d40c2ab4f..1c6672826db5 100644
> > --- a/arch/powerpc/kvm/book3s_hv_builtin.c
> > +++ b/arch/powerpc/kvm/book3s_hv_builtin.c
> > @@ -176,13 +176,14 @@ EXPORT_SYMBOL_GPL(kvmppc_hcall_impl_hv_realmode);
> >
> > int kvmppc_hwrng_present(void)
> > {
> > - return pnv_hwrng_present();
> > + return ppc_md.get_random_seed != NULL;
> > }
> > EXPORT_SYMBOL_GPL(kvmppc_hwrng_present);
> >
> > long kvmppc_rm_h_random(struct kvm_vcpu *vcpu)
> > {
> > - if (pnv_get_random_real_mode(&vcpu->arch.regs.gpr[4]))
> > + if (ppc_md.get_random_seed &&
> > + ppc_md.get_random_seed(&vcpu->arch.regs.gpr[4]))
> > return H_SUCCESS;
>
> This is the same as arch_get_random_seed_long, perhaps you could use it
> instead.

Sure, why not. Will send a v2.

Jason

\
 
 \ /
  Last update: 2022-06-24 16:16    [W:0.053 / U:1.696 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site