From: Sean Christopherson <seanjc@google.com>
To: Colton Lewis <coltonlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, maz@kernel.org,
dmatlack@google.com, oupton@google.com, ricarkol@google.com,
andrew.jones@linux.dev
Subject: Re: [PATCH v6 3/3] KVM: selftests: randomize page access order
Date: Tue, 11 Oct 2022 22:50:35 +0000 [thread overview]
Message-ID: <Y0XzO/MZjMICCjt3@google.com> (raw)
In-Reply-To: <gsnt7d162e2i.fsf@coltonlewis-kvm.c.googlers.com>
On Tue, Oct 11, 2022, Colton Lewis wrote:
> Sean Christopherson <seanjc@google.com> writes:
>
> > On Tue, Oct 11, 2022, Colton Lewis wrote:
> > > Sean Christopherson <seanjc@google.com> writes:
> > > > Ya, I'm trippling (quadrupling?) down on my suggestion to improve the
> > > > APIs. Users
> > > > should not be able to screw up like this, i.e. shouldn't need comments
> > > > to warn
> > > > readers, and adding another call to get a random number shouldn't
> > > affect
> > > > unrelated
> > > > code.
>
> > > Previous calls to PRNGs always affect later calls to PRNGs. That's how
> > > they work.
>
> > Ya, that's not the type of bugs I'm worried about.
>
> > > This "screw up" would be equally likely with any API because the caller
> > > always needs to decide if they should reuse the same random number
> > > or need a
> > > new one.
>
> > I disagree, the in/out parameter _requires_ the calling code to store
> > the random
> > number in a variable. Returning the random number allows consuming the
> > number
> > without needing an intermediate variable, e.g.
>
> > if (random_bool())
> > <do stuff>
>
> > which makes it easy to avoid an entire class of bugs.
>
> Yes, but it's impossible to do this without hidden global state at the
> implementation level. That sacrifices reentrancy and thread-safety.
The above is super quick pseudocode that wasn't intended to be taken verbatim.
From my original suggestion in patch one[*], throw the seed/metadata in a opaque
struct, e.g. ksft_pseudo_rng (or kvm_pseudo_rng if the code ends up being KVM-only).
The intent is to hide the details of the rng, both so that the caller doesn't have
to worry about those details, but also so that the guts can be changed at will
without having to update callers.
[*] https://lore.kernel.org/all/20220912195849.3989707-2-coltonlewis@google.com
next prev parent reply other threads:[~2022-10-11 22:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-12 19:58 [PATCH v6 0/3] KVM: selftests: randomize memory access of dirty_log_perf_test Colton Lewis
2022-09-12 19:58 ` [PATCH v6 1/3] KVM: selftests: implement random number generation for guest code Colton Lewis
2022-10-07 20:41 ` Sean Christopherson
2022-10-11 18:11 ` Colton Lewis
2022-10-11 18:39 ` Sean Christopherson
2022-10-11 22:24 ` Colton Lewis
2022-10-11 23:47 ` Sean Christopherson
2022-10-12 21:11 ` Colton Lewis
2022-10-12 23:34 ` Sean Christopherson
2022-10-10 18:03 ` Sean Christopherson
2022-10-11 18:13 ` Colton Lewis
2022-10-11 18:26 ` Sean Christopherson
2022-10-11 22:33 ` Colton Lewis
2022-09-12 19:58 ` [PATCH v6 2/3] KVM: selftests: randomize which pages are written vs read Colton Lewis
2022-10-07 20:55 ` Sean Christopherson
2022-10-07 21:07 ` David Matlack
2022-10-08 9:50 ` Andrew Jones
2022-10-10 14:46 ` Sean Christopherson
2022-10-10 16:38 ` Andrew Jones
2022-09-12 19:58 ` [PATCH v6 3/3] KVM: selftests: randomize page access order Colton Lewis
2022-10-07 21:09 ` Sean Christopherson
2022-10-11 18:12 ` Colton Lewis
2022-10-11 18:22 ` Sean Christopherson
2022-10-11 22:25 ` Colton Lewis
2022-10-11 22:50 ` Sean Christopherson [this message]
2022-09-19 22:36 ` [PATCH v6 0/3] KVM: selftests: randomize memory access of dirty_log_perf_test David Matlack
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=Y0XzO/MZjMICCjt3@google.com \
--to=seanjc@google.com \
--cc=andrew.jones@linux.dev \
--cc=coltonlewis@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=ricarkol@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.