Kernel KVM virtualization development
 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 1/2] KVM: LoongArch: selftests: Enable LASX feature by auto detect method
Date: Tue, 16 Jun 2026 02:39:24 +0000	[thread overview]
Message-ID: <20260616023925.785621F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616022615.2141072-2-maobibo@loongson.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Hardcoding the base CPUCFG2 value silently clears FPU version, LLFTP revision, and other default KVM features.
--

commit 7ccc915fb84c033373faa2df43f4b5551f11c4d3
Author: Bibo Mao <maobibo@loongson.cn>

KVM: LoongArch: selftests: Enable LASX feature by auto detect method

This commit enables LSX and LASX features for LoongArch KVM selftests when
the host machine supports them.

> diff --git a/tools/testing/selftests/kvm/lib/loongarch/processor.c b/tools/testing/selftests/kvm/lib/loongarch/processor.c
> index 64d91fb76522d..e7fb54d746f45 100644
> --- a/tools/testing/selftests/kvm/lib/loongarch/processor.c
> +++ b/tools/testing/selftests/kvm/lib/loongarch/processor.c
[ ... ]
> @@ -292,6 +292,16 @@ void loongarch_vcpu_setup(struct kvm_vcpu *vcpu)
>  		TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
>  	}
>  
> +	/* Enable LSX/LASX feature by detecting host capability */
> +	cfg = CPUCFG2_FP | CPUCFG2_FPSP | CPUCFG2_FPDP | CPUCFG2_LLFTP;
> +	ret = __kvm_has_device_attr(vm->fd, KVM_LOONGARCH_VM_FEAT_CTRL, KVM_LOONGARCH_VM_FEAT_LSX);
> +	if (!ret)
> +		cfg |= CPUCFG2_LSX;
> +
> +	ret = __kvm_has_device_attr(vm->fd, KVM_LOONGARCH_VM_FEAT_CTRL, KVM_LOONGARCH_VM_FEAT_LASX);
> +	if (!ret)
> +		cfg |= CPUCFG2_LASX;
> +	loongarch_set_cpucfg(vcpu, LOONGARCH_CPUCFG2, cfg);

[Severity: Medium]
Does hardcoding the base CPUCFG2 value here inadvertently clear other default
KVM features?

Since KVM populates CPUCFG2 with defaults like CPUCFG2_FPVERS (FPU version)
and CPUCFG2_LLFTPREV (LLFTP revision) during vCPU creation, overwriting the
entire register with this bitmask might cause issues for tests or guests
relying on these standard properties.

Would it be better to read the existing KVM-provided value via vcpu_get_reg(),
bitwise-OR the detected LSX and LASX bits, and then write it back?

>  	cfg = read_cpucfg(LOONGARCH_CPUCFG6);
>  	loongarch_set_cpucfg(vcpu, LOONGARCH_CPUCFG6, cfg);
>

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

  reply	other threads:[~2026-06-16  2:39 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 [this message]
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

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=20260616023925.785621F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox