From: Marc Zyngier <maz@kernel.org>
To: Haibo Xu <xiaobo55x@gmail.com>
Cc: Haibo Xu <haibo1.xu@intel.com>,
ajones@ventanamicro.com, Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Anup Patel <anup@brainfault.org>,
Atish Patra <atishp@atishpatra.org>, Guo Ren <guoren@kernel.org>,
Mayuresh Chitale <mchitale@ventanamicro.com>,
Greentime Hu <greentime.hu@sifive.com>,
wchen <waylingii@gmail.com>,
Conor Dooley <conor.dooley@microchip.com>,
Heiko Stuebner <heiko@sntech.de>,
Minda Chen <minda.chen@starfivetech.com>,
Samuel Holland <samuel@sholland.org>,
Jisheng Zhang <jszhang@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Peter Xu <peterx@redhat.com>, Like Xu <likexu@tencent.com>,
Vipin Sharma <vipinsh@google.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Aaron Lewis <aaronlewis@google.com>,
Thomas Huth <thuth@redhat.com>,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
kvm-riscv@lists.infradead.org
Subject: Re: [PATCH v4 11/11] KVM: selftests: Enable tunning of err_margin_us in arch timer test
Date: Thu, 21 Dec 2023 09:25:02 +0000 [thread overview]
Message-ID: <86plyzaowh.wl-maz@kernel.org> (raw)
In-Reply-To: <CAJve8o=nTsAwwgSib4vOLXjOWSMV2+J+BFsUZ57OdAK7eW8q8A@mail.gmail.com>
On Thu, 21 Dec 2023 02:58:40 +0000,
Haibo Xu <xiaobo55x@gmail.com> wrote:
>
> On Wed, Dec 20, 2023 at 9:58 PM Marc Zyngier <maz@kernel.org> wrote:
> >
> > On Wed, 20 Dec 2023 13:51:24 +0000,
> > Haibo Xu <xiaobo55x@gmail.com> wrote:
> > >
> > > On Wed, Dec 20, 2023 at 5:00 PM Marc Zyngier <maz@kernel.org> wrote:
> > > >
> > > > On 2023-12-20 06:50, Haibo Xu wrote:
> > > > > On Wed, Dec 20, 2023 at 2:22 AM Marc Zyngier <maz@kernel.org> wrote:
> > > > >>
> > > > >> On Tue, 12 Dec 2023 09:31:20 +0000,
> > > > >> Haibo Xu <haibo1.xu@intel.com> wrote:
> > > > >> > diff --git a/tools/testing/selftests/kvm/include/timer_test.h b/tools/testing/selftests/kvm/include/timer_test.h
> > > > >> > index 968257b893a7..b1d405e7157d 100644
> > > > >> > --- a/tools/testing/selftests/kvm/include/timer_test.h
> > > > >> > +++ b/tools/testing/selftests/kvm/include/timer_test.h
> > > > >> > @@ -22,6 +22,7 @@ struct test_args {
> > > > >> > int nr_iter;
> > > > >> > int timer_period_ms;
> > > > >> > int migration_freq_ms;
> > > > >> > + int timer_err_margin_us;
> > > > >>
> > > > >> ... except that you are storing it as a signed value. Some consistency
> > > > >> wouldn't hurt, really, and would avoid issues when passing large
> > > > >> values.
> > > > >>
> > > > >
> > > > > Yes, it's more proper to use an unsigned int for the non-negative error
> > > > > margin.
> > > > > Storing as signed here is just to keep the type consistent with that
> > > > > of timer_period_ms
> > > > > since there will be '+' operation in other places.
> > > > >
> > > > > tools/testing/selftests/kvm/aarch64/arch_timer.c
> > > > > /* Setup a timeout for the interrupt to arrive */
> > > > > udelay(msecs_to_usecs(test_args.timer_period_ms) +
> > > > > test_args.timer_err_margin_us);
> > > >
> > > > But that's exactly why using a signed quantity is wrong.
> > > > What does it mean to have a huge *negative* margin?
> > > >
> > >
> > > Hi Marc,
> > >
> > > I agree that negative values are meaningless for the margin.
> > > If I understand correctly, the negative margin should be filtered by
> > > assertion in atoi_non_negative().
> >
> > No. Please.
> >
> > atoi_non_negative() returns a uint32_t, which is what it should do.
> > The bug is squarely in the use of an 'int' to store such value, and it
> > is the *storage* that turns a positive value into a negative one.
> >
>
> Thanks for the detailed info!
>
> May I understand that your concern is mainly for a platform with
> 64bit int type, which may trigger the positive to negative convert?
No. It specifically applies to architectures with a 32bit int type,
which is... *EVERYTHING*. Here's a basic example:
<quote>
#include <stdio.h>
int main(int argc, char *argv[])
{
int x = 1U << 31;
printf("%d (%d)\n", x, sizeof(x));
return 0;
}
</quote>
which returns "-2147483648 (4)" on any platform.
This really is basic C, and I am very worried that you don't see the
issue. I strongly suggest that you go and read about the C type system
before touching this code.
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-12-21 9:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 9:31 [PATCH v4 00/11] RISCV: Add kvm Sstc timer selftests Haibo Xu
2023-12-12 9:31 ` [PATCH v4 01/11] selftests/kvm: Fix issues with $(SPLIT_TESTS) Haibo Xu
2023-12-12 9:31 ` [PATCH v4 02/11] KVM: arm64: selftests: Split arch_timer test code Haibo Xu
2023-12-14 6:41 ` Anup Patel
2023-12-12 9:31 ` [PATCH v4 03/11] KVM: selftests: Add CONFIG_64BIT definition for the build Haibo Xu
2023-12-13 13:52 ` Andrew Jones
2023-12-12 9:31 ` [PATCH v4 04/11] tools: riscv: Add header file csr.h Haibo Xu
2023-12-12 9:31 ` [PATCH v4 05/11] tools: riscv: Add header file vdso/processor.h Haibo Xu
2023-12-13 14:02 ` Andrew Jones
2023-12-12 9:31 ` [PATCH v4 06/11] KVM: riscv: selftests: Switch to use macro from csr.h Haibo Xu
2023-12-12 9:31 ` [PATCH v4 07/11] KVM: riscv: selftests: Add exception handling support Haibo Xu
2023-12-12 9:31 ` [PATCH v4 08/11] KVM: riscv: selftests: Add guest helper to get vcpu id Haibo Xu
2023-12-13 14:08 ` Andrew Jones
2023-12-19 2:28 ` Haibo Xu
2023-12-12 9:31 ` [PATCH v4 09/11] KVM: riscv: selftests: Change vcpu_has_ext to a common function Haibo Xu
2023-12-12 9:31 ` [PATCH v4 10/11] KVM: riscv: selftests: Add sstc timer test Haibo Xu
2023-12-13 14:18 ` Andrew Jones
2023-12-12 9:31 ` [PATCH v4 11/11] KVM: selftests: Enable tunning of err_margin_us in arch " Haibo Xu
2023-12-13 14:27 ` Andrew Jones
2023-12-14 6:44 ` Anup Patel
2023-12-19 18:22 ` Marc Zyngier
2023-12-20 6:50 ` Haibo Xu
2023-12-20 9:00 ` Marc Zyngier
2023-12-20 13:51 ` Haibo Xu
2023-12-20 13:58 ` Marc Zyngier
2023-12-21 2:58 ` Haibo Xu
2023-12-21 9:25 ` Marc Zyngier [this message]
2024-01-04 11:09 ` Andrew Jones
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=86plyzaowh.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=aaronlewis@google.com \
--cc=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@atishpatra.org \
--cc=conor.dooley@microchip.com \
--cc=greentime.hu@sifive.com \
--cc=guoren@kernel.org \
--cc=haibo1.xu@intel.com \
--cc=heiko@sntech.de \
--cc=james.morse@arm.com \
--cc=jszhang@kernel.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=likexu@tencent.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=mchitale@ventanamicro.com \
--cc=minda.chen@starfivetech.com \
--cc=oliver.upton@linux.dev \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=samuel@sholland.org \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=thuth@redhat.com \
--cc=vipinsh@google.com \
--cc=waylingii@gmail.com \
--cc=xiaobo55x@gmail.com \
--cc=yuzenghui@huawei.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).