On 2026/05/05 02:16 PM, Harsh Prateek Bora wrote:
> 
> 
> On 30/04/26 11:19 am, Amit Machhiwal wrote:
> > Add handling for KVM_PPC_GET_COMPAT_CAPS in kvm_arch_vm_ioctl() and
> > advertise support via KVM_CAP_PPC_COMPAT_CAPS.
> > 
> > The ioctl retrieves host CPU compatibility capabilities via a
> > PowerPC-specific backend implementation when available. If the
> > capability is not supported, the ioctl returns success with no
> > capabilities set, allowing userspace to fall back gracefully.
> > 
> > Signed-off-by: Amit Machhiwal <[email protected]>
> > ---
> >   arch/powerpc/include/asm/kvm_ppc.h |  1 +
> >   arch/powerpc/kvm/powerpc.c         | 19 +++++++++++++++++++
> >   2 files changed, 20 insertions(+)
> > 
> > diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> > b/arch/powerpc/include/asm/kvm_ppc.h
> > index 0953f2daa466..cadfb839e836 100644
> > --- a/arch/powerpc/include/asm/kvm_ppc.h
> > +++ b/arch/powerpc/include/asm/kvm_ppc.h
> > @@ -319,6 +319,7 @@ struct kvmppc_ops {
> >     bool (*hash_v3_possible)(void);
> >     int (*create_vm_debugfs)(struct kvm *kvm);
> >     int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu, struct dentry 
> > *debugfs_dentry);
> > +   int (*get_compat_cpu_ver)(struct kvm_ppc_compat_caps *host_caps);
> >   };
> >   extern struct kvmppc_ops *kvmppc_hv_ops;
> > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> > index 00302399fc37..f35017d83d77 100644
> > --- a/arch/powerpc/kvm/powerpc.c
> > +++ b/arch/powerpc/kvm/powerpc.c
> > @@ -697,6 +697,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long 
> > ext)
> >                     }
> >             }
> >             break;
> > +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE)
> > +   case KVM_CAP_PPC_COMPAT_CAPS:
> > +           if (kvmhv_on_pseries())
> 
> What about PowerNV ?

I'm not sure if understand the question completely. The goal is to handle the
compatibility mode for a nested guest, i.e., an L2 KVM guest booted inside a
pSeries KVM L1 booted on a PowerNV host with HV compatibilities and as well as
on a Logical Parition booted on PowerVM, hence the check. Does that answer your
question?

> Also, can't we just check if get_compat_cpu_ver is initialized and return
> accordingly ?
> 
> > +                   r = 1;
> > +           break;
> > +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
> >     default:
> >             r = 0;
> >             break;
> > @@ -2463,6 +2469,19 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned 
> > int ioctl, unsigned long arg)
> >             r = kvm->arch.kvm_ops->svm_off(kvm);
> >             break;
> >     }
> > +   case KVM_PPC_GET_COMPAT_CAPS: {
> > +           struct kvm_ppc_compat_caps host_caps;
> > +
> > +           memset(&host_caps, 0, sizeof(host_caps));
> > +           if (!kvm->arch.kvm_ops->get_compat_cpu_ver)
> > +                   goto out;
> 
> I guess we want to init r = 0 before returning in this case.

Sure, will do in the next version.

> Also prefer break over goto unless really needed.

I used goto out; to stay consistent with the existing exit paths in this
function, where similar branches go through the same out label. I do not have a
strong preference either way. Please let me know your views.

Thanks,
Amit

> 
> > +
> > +           r = kvm->arch.kvm_ops->get_compat_cpu_ver(&host_caps);
> > +           if (!r && copy_to_user(argp, &host_caps,
> > +                                sizeof(host_caps)))
> > +                   r = -EFAULT;
> > +           break;
> > +   }
> >     default: {
> >             struct kvm *kvm = filp->private_data;
> >             r = kvm->arch.kvm_ops->arch_vm_ioctl(filp, ioctl, arg);
> 

Reply via email to