All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bibo Mao" <maobibo@loongson.cn>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 2/2] KVM: LoongArch: selftests: Add FPU test case
Date: Tue, 16 Jun 2026 02:34:55 +0000	[thread overview]
Message-ID: <20260616023455.67EA61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616022615.2141072-3-maobibo@loongson.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] FPU selftest fails to verify that `vcpu_fpu_set` actually modifies the vCPU FPU state.
--

commit 2bf4caa3158a9fa987285bf7aea2092fe7c8a3f7
Author: Bibo Mao <maobibo@loongson.cn>

KVM: LoongArch: selftests: Add FPU test case

This commit adds an FPU test case to verify FPU register get and set APIs
for LoongArch. It supports testing 64, 128, and 256-bit FPU widths.

> diff --git a/tools/testing/selftests/kvm/loongarch/fpu_test.c b/tools/testing/selftests/kvm/loongarch/fpu_test.c
> new file mode 100644
> index 0000000000000..fe58ed4f93c0b
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/loongarch/fpu_test.c

[ ... ]

> +int main(void)
> +{

[ ... ]

> +	fpu.fpr[0].val64[0] += random();
> +	vcpu_fpu_set(vcpu, &fpu);
> +	run_vcpu(vcpu);
> +	vcpu_fpu_get(vcpu, &fpu);
> +	sync_global_from_guest(vm, *fp);
> +	TEST_ASSERT(!memcmp(fpu.fpr, fp, 8), "Wanted 0x%llx from f0, got 0x%llx",
> +			fp->val64[0], fpu.fpr[0].val64[0]);

[Severity: Medium]
Does this sequence actually verify the set operation? 

The test adds random() to the fpu structure and calls vcpu_fpu_set(). However,
it then updates both the fpu structure via vcpu_fpu_get() and the fp structure
via sync_global_from_guest() before comparing them against each other.

If vcpu_fpu_set() silently fails or does nothing, won't both structures just
read back the previous, unmodified state and cause the memcmp() to pass anyway?
It looks like this pattern repeats for the 128-bit and 256-bit checks below as
well.

> +
> +	fpu.fpr[0].val64[0] += random();
> +	fpu.fpr[0].val64[1] += random();
> +	vcpu_fpu_set(vcpu, &fpu);
> +	run_vcpu(vcpu);
> +	vcpu_fpu_get(vcpu, &fpu);
> +	sync_global_from_guest(vm, *fp);
> +	TEST_ASSERT(!memcmp(fpu.fpr, fp, 16), "Wanted 0x%llx %llx from vr0, got 0x%llx %llx",
> +			fp->val64[0], fp->val64[1],
> +			fpu.fpr[0].val64[0], fpu.fpr[0].val64[1]);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260616022615.2141072-1-maobibo@loongson.cn?part=2

      reply	other threads:[~2026-06-16  2:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16  2:26 [PATCH v3 0/2] KVM: LoongArch: selftests: Add FPU test case Bibo Mao
2026-06-16  2:26 ` [PATCH v3 1/2] KVM: LoongArch: selftests: Enable LASX feature by auto detect method Bibo Mao
2026-06-16  2:39   ` sashiko-bot
2026-06-16  2:26 ` [PATCH v3 2/2] KVM: LoongArch: selftests: Add FPU test case Bibo Mao
2026-06-16  2:34   ` sashiko-bot [this message]

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=20260616023455.67EA61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=maobibo@loongson.cn \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.