From: George Spelvin <lkml@sdf.org>
To: lkml@sdf.org, paul.burton@mips.com
Cc: jhogan@kernel.org, linux-mips@vger.kernel.org
Subject: Re: [PATCH] arch/mips/kvm/emulate.c: Don't waste /dev/random emulating TLBWR
Date: Fri, 22 Mar 2019 05:22:45 GMT [thread overview]
Message-ID: <201903220522.x2M5MjTm026260@sdf.org> (raw)
In-Reply-To: <20190322000043.krzxo7coqibbxi6c@pburton-laptop>
On Fri, 22 Mar 2019 at 00:00:45 +0000, Paul Burton wrote:
> On Thu, Mar 21, 2019 at 06:04:24AM +0000, George Spelvin wrote:
>> KVM_MIPS_GUEST_TLB_SIZE is 64, so we only need one random byte,
>> not 4.
>>
>> A more complex question is whether we need crypto-grade random
>> numbers at all. If safe, we could use prandom_u32(). If not,
>> we could seed a private PRNG and use prandom_u32_state().
>>
>> Or could we just use asm("mfc0 %0, Random" : "=r" (index))?
> Thanks for the patch. I expect we should be fine with:
>
> index = prandom_u32_max(KVM_MIPS_GUEST_TLB_SIZE);
>
> We certainly don't need crypto-grade randomness here. Using the cp0
> Random register would be an option for configurations prior to MIPSr6,
> where the Random register was deprecated & we shouldn't rely on its
> presence. So we could do:
>
> if (MIPS_ISA_REV < 6)
> index = read_c0_random() % KVM_MIPS_GUEST_TLB_SIZE;
> else
> index = prandom_u32_max(KVM_MIPS_GUEST_TLB_SIZE);
>
> Though whether that micro-optimization is worth the extra code is
> questionable.
I'm also not sure if you *want* to use the random register, because
that's a source of /dev/random entropy (arch/mips/include/asm/timex.h),
and maybe exposing it to VM guests would be a bad thing.
There's no need to get too fancy; prandom_u32_max is fine. (And
gcc optimizes it to a shift if the argument is a compie-time power
of 2.)
Anyway, thank you for the response, and I'm assuming there's no need
for revised patch from me; as it's less work for you to write your own.
prev parent reply other threads:[~2019-03-22 5:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-21 6:04 [PATCH] arch/mips/kvm/emulate.c: Don't waste /dev/random emulating TLBWR George Spelvin
2019-03-22 0:00 ` Paul Burton
2019-03-22 5:22 ` George Spelvin [this message]
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=201903220522.x2M5MjTm026260@sdf.org \
--to=lkml@sdf.org \
--cc=jhogan@kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=paul.burton@mips.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).