From: Sean Christopherson <seanjc@google.com>
To: Vipin Sharma <vipinsh@google.com>
Cc: pbonzini@redhat.com, dmatlack@google.com, andrew.jones@linux.dev,
wei.w.wang@intel.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 4/5] KVM: selftests: Add atoi_positive() and atoi_non_negative() for input validation
Date: Tue, 1 Nov 2022 19:20:32 +0000 [thread overview]
Message-ID: <Y2FxgNCw11tA7yDz@google.com> (raw)
In-Reply-To: <CAHVum0fhangxMp5ysYdyoKVY+CKWeBAadMFX1V8MgqryRGHQrw@mail.gmail.com>
On Tue, Nov 01, 2022, Vipin Sharma wrote:
> On Mon, Oct 31, 2022 at 12:48 PM Sean Christopherson <seanjc@google.com> wrote:
> >
> > On Mon, Oct 31, 2022, Vipin Sharma wrote:
> > > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> > > index ec0f070a6f21..210e98a49a83 100644
> > > --- a/tools/testing/selftests/kvm/lib/test_util.c
> > > +++ b/tools/testing/selftests/kvm/lib/test_util.c
> > > @@ -353,3 +353,19 @@ int atoi_paranoid(const char *num_str)
> > >
> > > return num;
> > > }
> > > +
> > > +uint32_t atoi_positive(const char *num_str)
> >
> > I think it makes sense to inline atoi_positive() and atoi_non_negative() in
> > test_util.h. Depending on developer's setups, it might be one less layer to jump
> > through to look at the implementation.
> >
>
> I am not sure if this makes life much easier for developers, as
> "inline" can totally be ignored by the compiler. Also, not sure how
> much qualitative improvement it will add in the developer's code
> browsing journey. Anyways, I will add "inline" in the next version.
To be clear, it's not about adding "inline", it's about not having separate
declarations and definitions. E.g. I've yet to achieve a setup that has 100%
accuracy when it comes to navigating to a definition versus a declaration. And
when poking around code, seeing a "static inline" function provides a hint that
a function is likely a simple wrapper without even having to look at the
implementation.
These are all small things, but I can't think of a reason _not_ to inline these
trivial wrappers.
> > Last thought: my vote would be to ignore the 80 char soft limit when adding the
> > "name" to these calls, in every case except nr_memslot_modifications the overrun
> > is relatively minor and not worth wrapping. See below for my thougts on that one.
> >
> > > break;
> > > case 'm':
> > > - max_mem = atoi_paranoid(optarg) * size_1gb;
> > > + max_mem = atoi_positive(optarg) * size_1gb;
> > > TEST_ASSERT(max_mem > 0, "memory size must be >0");
> >
> > This assert can be dropped, max_mem is a uint64_t so wrapping to '0' is impossible.
> >
>
> I intentionally kept it, as it is also protecting against having
> accidently making size_1gb to 0.
Heh, the test has far, far bigger problems if it screws up size_1gb. And that's
an orthogonal concern as the test would be horrifically broken regardless of
whether or not the user specified '-m' and/or '-s'.
A better approach is to replace the homebrewed size_1gb with SZ_1G from
tools/include/linux/sizes.h. I, and many others, completely overlooked size.h.
next prev parent reply other threads:[~2022-11-01 19:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 17:38 [PATCH v7 0/5] dirty_log_perf_test vCPU pinning Vipin Sharma
2022-10-31 17:38 ` [PATCH v7 1/5] KVM: selftests: Add missing break between -e and -g option in dirty_log_perf_test Vipin Sharma
2022-10-31 18:46 ` Sean Christopherson
2022-10-31 17:38 ` [PATCH v7 2/5] KVM: selftests: Put command line options in alphabetical order " Vipin Sharma
2022-10-31 18:47 ` Sean Christopherson
2022-10-31 17:38 ` [PATCH v7 3/5] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi() Vipin Sharma
2022-10-31 18:49 ` Sean Christopherson
2022-10-31 19:17 ` Sean Christopherson
2022-10-31 19:44 ` Vipin Sharma
2022-10-31 17:38 ` [PATCH v7 4/5] KVM: selftests: Add atoi_positive() and atoi_non_negative() for input validation Vipin Sharma
2022-10-31 19:48 ` Sean Christopherson
2022-11-01 19:01 ` Vipin Sharma
2022-11-01 19:20 ` Sean Christopherson [this message]
2022-11-01 19:28 ` Vipin Sharma
2022-10-31 17:38 ` [PATCH v7 5/5] KVM: selftests: Allowing running dirty_log_perf_test on specific CPUs Vipin Sharma
2022-10-31 19:49 ` Sean Christopherson
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=Y2FxgNCw11tA7yDz@google.com \
--to=seanjc@google.com \
--cc=andrew.jones@linux.dev \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vipinsh@google.com \
--cc=wei.w.wang@intel.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).