Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Amit Machhiwal <amachhiw@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Amit Machhiwal <amachhiw@linux.ibm.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v6 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV
Date: Thu, 6 Aug 2026 21:43:06 +0530	[thread overview]
Message-ID: <20260806214117.8a2ca150-97-amachhiw@linux.ibm.com> (raw)
In-Reply-To: <20260804182718.2B4581F000E9@smtp.kernel.org>

On 2026/08/04 06:27 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] `kvmppc_get_compat_caps()` incorrectly returns `-EINVAL` when the 'cpu-version' property is absent, breaking the `KVM_CAP_PPC_COMPAT_CAPS` contract.
> --
> 
> --- Patch [3]: [PATCH v6 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV ---
> commit b4de9c28bb9d6eeb95ed5310169709b332b6f664
> Author: Amit Machhiwal <amachhiw@linux.ibm.com>
> 
> KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV
> 
> This commit extends host CPU compatibility capability reporting to support
> nested virtualization on PowerNV systems. For nested API v1, it derives
> compatibility capabilities from the L1 guest by reading the cpu-version
> property from the device tree and maps it to the corresponding compatibility
> capability bitmap.
> 
> > diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> > index 8799124b80960..77558f6eed864 100644
> > --- a/arch/powerpc/kvm/book3s_hv.c
> > +++ b/arch/powerpc/kvm/book3s_hv.c
> 
> [ ... ]
> 
> >  static int kvmppc_get_compat_caps(struct kvm_ppc_compat_caps *host_caps)
> >  {
> > +	struct device_node *np;
> >  	unsigned long capabilities = 0;
> >  	long rc = -EINVAL;
> > +	u32 cpu_version = 0;
> >  
> >  	if (kvmhv_on_pseries()) {
> >  		if (kvmhv_is_nestedv2()) {
> >  			WARN_ON_ONCE(!nested_capabilities);
> >  			capabilities = nested_capabilities;
> >  			rc = 0;
> > +		} else {
> > +			for_each_node_by_type(np, "cpu") {
> > +				if (!of_property_read_u32(np, "cpu-version",
> > +							  &cpu_version)) {
> > +					of_node_put(np);
> > +					break;
> > +				}
> > +			}
> > +			if (!cpu_version)
> > +				return -EINVAL;
> 
> [Severity: High]
> If an L1 guest is booted in native mode (e.g. without a 'compat=' setting in
> QEMU), the cpu-version property is intentionally omitted from the device
> tree.
> 
> Doesn't returning -EINVAL here cause KVM_PPC_GET_COMPAT_CAPS to fail,
> thereby breaking nested virtualization initialization for native-mode L1
> guests?
> 
> Could this fall back to deriving capabilities from the physical native PVR
> instead of returning an error?

The premise is incorrect for the context where this code runs. This code
path is guarded by kvmhv_on_pseries(), which is true only when the
kernel is running as a PAPR guest (under PHYP or KVM on PowerNV acting
as L0). In that context, the `cpu-version` property in the guest DT is
always populated by the hypervisor (PHYP or QEMU) with a logical PVR
value including for native-mode guests. This is standard PAPR firmware
behavior and is documented in the PAPR specification.

For KVM on PowerNV (L0), the L1 guest's DT is built by QEMU which sets
cpu-version to the negotiated CPU version. For PHYP-managed LPARs, PHYP
always provides cpu-version regardless of whether the guest is in compat
mode or native mode.

The `if (!cpu_version) return -EINVAL` guard handles only the case where
of_property_read_u32() fails and leaves cpu_version at its 0
initialisation value — which would indicate an unexpected firmware or DT
construction error, not a normal native-mode guest scenario.

> 
> > +			rc = kvmppc_map_compat_capabilities(cpu_version,
> > +							    &capabilities);
> >  		}
> >  	}
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260804180705.59160-1-amachhiw@linux.ibm.com?part=3

  reply	other threads:[~2026-08-06 16:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 18:07 [PATCH v6 0/4] KVM: PPC: Expose CPU compatibility modes for nested guests Amit Machhiwal
2026-08-04 18:07 ` [PATCH v6 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Amit Machhiwal
2026-08-04 18:19   ` sashiko-bot
2026-08-06 16:07     ` Amit Machhiwal
2026-08-04 18:07 ` [PATCH v6 2/4] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Amit Machhiwal
2026-08-04 18:21   ` sashiko-bot
2026-08-06 16:09     ` Amit Machhiwal
2026-08-04 18:07 ` [PATCH v6 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Amit Machhiwal
2026-08-04 18:27   ` sashiko-bot
2026-08-06 16:13     ` Amit Machhiwal [this message]
2026-08-04 18:07 ` [PATCH v6 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Amit Machhiwal
2026-08-04 18:27   ` sashiko-bot
2026-08-06 16:15     ` Amit Machhiwal
2026-08-05  4:32 ` [PATCH v6 0/4] KVM: PPC: Expose CPU compatibility modes for nested guests Anushree Mathur
2026-08-05 18:39 ` Ritesh Harjani
2026-08-06  5:33   ` Amit Machhiwal
2026-08-06 13:05     ` Ritesh Harjani
2026-08-06 14:58       ` Amit Machhiwal

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=20260806214117.8a2ca150-97-amachhiw@linux.ibm.com \
    --to=amachhiw@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --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