From: George Spelvin <lkml@sdf.org>
To: jhogan@kernel.org, linux-mips@vger.kernel.org
Cc: lkml@sdf.org
Subject: [PATCH] arch/mips/kvm/emulate.c: Don't waste /dev/random emulating TLBWR
Date: Thu, 21 Mar 2019 06:04:24 GMT [thread overview]
Message-ID: <201903210604.x2L64Ord018045@sdf.org> (raw)
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))?
Signed-off-by: George Spelvin <lkml@sdf.org>
---
I ran across this whie doing some other cleanups, and thought
I'd pass it on.
get_random_bytes() is quite an expensive function call.
Is it needed at all?
arch/mips/kvm/emulate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index ec9ed23bca7f..a689f3db3094 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1139,8 +1139,9 @@ enum emulation_result kvm_mips_emul_tlbwr(struct kvm_vcpu *vcpu)
struct mips_coproc *cop0 = vcpu->arch.cop0;
struct kvm_mips_tlb *tlb = NULL;
unsigned long pc = vcpu->arch.pc;
- int index;
+ unsigned char index;
+ /* Do we need this quality of random numbers? Would prandom_u32 do? */
get_random_bytes(&index, sizeof(index));
index &= (KVM_MIPS_GUEST_TLB_SIZE - 1);
--
2.20.1
next reply other threads:[~2019-03-21 6:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-21 6:04 George Spelvin [this message]
2019-03-22 0:00 ` [PATCH] arch/mips/kvm/emulate.c: Don't waste /dev/random emulating TLBWR Paul Burton
2019-03-22 5:22 ` George Spelvin
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=201903210604.x2L64Ord018045@sdf.org \
--to=lkml@sdf.org \
--cc=jhogan@kernel.org \
--cc=linux-mips@vger.kernel.org \
/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).