kvm-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Haibo Xu <xiaobo55x@gmail.com>
To: kvm-riscv@lists.infradead.org
Subject: [PATCH v4 08/12] KVM: arm64: selftests: Move reject_set check logic to a function
Date: Wed, 28 Jun 2023 13:58:21 +0800	[thread overview]
Message-ID: <CAJve8ony9nj9LyCAJjtvthR+ABLvSPHvpeE5e5=wr_z44i20qw@mail.gmail.com> (raw)
In-Reply-To: <20230627-4d207186c4ef81be43c9d874@orel>

On Tue, Jun 27, 2023 at 5:09?PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> On Fri, Jun 23, 2023 at 06:40:10PM +0800, Haibo Xu wrote:
> > No functional changes. Just move the reject_set check logic to a
> > function so we can check for specific errno for specific register.
> > This is a preparation for support reject_set in riscv.
> >
> > Suggested-by: Andrew Jones <ajones@ventanamicro.com>
> > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > ---
> >  tools/testing/selftests/kvm/aarch64/get-reg-list.c | 8 ++++++++
> >  tools/testing/selftests/kvm/get-reg-list.c         | 7 ++++++-
> >  2 files changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> > index aaf035c969ec..4e2e1fe833eb 100644
> > --- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> > +++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> > @@ -27,6 +27,14 @@ bool filter_reg(__u64 reg)
> >       return false;
> >  }
> >
> > +bool reject_set_fail(__u64 reg)
> > +{
> > +     if (reg == KVM_REG_ARM64_SVE_VLS)
> > +             return (errno != EPERM);
> > +
> > +     return false;
> > +}
>
> I think we should pass errno in as a parameter and I prefer positive
> predicate functions, so I'd name this check_reject_set() and reverse
> the logic. Also, we don't want to check for KVM_REG_ARM64_SVE_VLS,
> because that duplicates the rejects set. I see in a later patch
> that riscv needs to check reg because different errors are used
> for different registers, but that's because KVM_REG_RISCV_TIMER_REG(state)
> was erroneously added to the rejects set. KVM_REG_RISCV_TIMER_REG(state)
> doesn't belong there. That register can be set, but it only supports
> certain input, otherwise, it correctly, results in EINVAL. We'll need
> the concept of a "skip set" to avoid tripping over that one.
>
> So, I think arm's function should be
>
>  bool check_reject_set(int errno)
>  {
>      return errno == EPERM;
>  }
>
> and riscv's should be
>
>  bool check_reject_set(int errno)
>  {
>      return errno == EOPNOTSUPP;
>  }
>

Sure, will add a new 'skips_set' member to 'struct vcpu_reg_sublist' and
move KVM_REG_RISCV_TIMER_REG(state) reg to it.

> > +
> >  #define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK | KVM_REG_ARM_COPROC_MASK)
> >
> >  #define CORE_REGS_XX_NR_WORDS        2
> > diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
> > index f6ad7991a812..b956ee410996 100644
> > --- a/tools/testing/selftests/kvm/get-reg-list.c
> > +++ b/tools/testing/selftests/kvm/get-reg-list.c
> > @@ -98,6 +98,11 @@ void __weak print_reg(const char *prefix, __u64 id)
> >       printf("\t0x%llx,\n", id);
> >  }
> >
> > +bool __weak reject_set_fail(__u64 reg)
> > +{
> > +     return false;
> > +}
> > +
> >  #ifdef __aarch64__
> >  static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *init)
> >  {
> > @@ -216,7 +221,7 @@ static void run_test(struct vcpu_reg_list *c)
> >                       if (s->rejects_set && find_reg(s->rejects_set, s->rejects_set_n, reg.id)) {
> >                               reject_reg = true;
> >                               ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
> > -                             if (ret != -1 || errno != EPERM) {
> > +                             if (ret != -1 || reject_set_fail(reg.id)) {
> >                                       printf("%s: Failed to reject (ret=%d, errno=%d) ", config_name(c), ret, errno);
> >                                       print_reg(config_name(c), reg.id);
> >                                       putchar('\n');
> > --
> > 2.34.1
> >
>
> Thanks,
> drew


  reply	other threads:[~2023-06-28  5:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 10:40 [PATCH v4 00/12] RISCV: Add KVM_GET_REG_LIST API Haibo Xu
2023-06-23 10:40 ` [PATCH v4 01/12] KVM: arm64: selftests: Replace str_with_index with strdup_printf Haibo Xu
2023-06-23 10:40 ` [PATCH v4 02/12] KVM: arm64: selftests: Drop SVE cap check in print_reg Haibo Xu
2023-06-23 10:40 ` [PATCH v4 03/12] KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config Haibo Xu
2023-06-23 10:40 ` [PATCH v4 04/12] KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h Haibo Xu
2023-06-23 10:40 ` [PATCH v4 05/12] KVM: arm64: selftests: Delete core_reg_fixup Haibo Xu
2023-06-23 10:40 ` [PATCH v4 06/12] KVM: arm64: selftests: Split get-reg-list test code Haibo Xu
2023-06-23 10:40 ` [PATCH v4 07/12] KVM: arm64: selftests: Finish generalizing get-reg-list Haibo Xu
2023-06-23 10:40 ` [PATCH v4 08/12] KVM: arm64: selftests: Move reject_set check logic to a function Haibo Xu
2023-06-27  9:09   ` Andrew Jones
2023-06-28  5:58     ` Haibo Xu [this message]
2023-06-23 10:40 ` [PATCH v4 09/12] KVM: selftests: Only do get/set tests on present blessed list Haibo Xu
2023-06-27  9:11   ` Andrew Jones
2023-06-28  6:00     ` Haibo Xu
2023-06-23 10:40 ` [PATCH v4 10/12] KVM: riscv: Add KVM_GET_REG_LIST API support Haibo Xu
2023-06-23 10:40 ` [PATCH v4 11/12] KVM: riscv: selftests: Add finalize_vcpu check in run_test Haibo Xu
2023-06-27  9:16   ` Andrew Jones
2023-06-28 10:29     ` Haibo Xu
2023-06-23 10:40 ` [PATCH v4 12/12] KVM: riscv: selftests: Add get-reg-list test Haibo Xu
2023-06-27  9:25   ` Andrew Jones
2023-06-28 10:28     ` Haibo Xu

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='CAJve8ony9nj9LyCAJjtvthR+ABLvSPHvpeE5e5=wr_z44i20qw@mail.gmail.com' \
    --to=xiaobo55x@gmail.com \
    --cc=kvm-riscv@lists.infradead.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).