Subject: Re: [PATCH v2 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block

From: Ritesh Harjani (IBM) <[email-masked]>
Date: Wed, 11 Mar 2026 07:50:24 +0530

Alex Williamson <[email-masked]> writes:

> Subject prefix should be "vfio/pci:".
>
> On Mon,  9 Mar 2026 18:08:37 +0530
> "Ritesh Harjani (IBM)" <[email-masked]> wrote:
>
>> Architectures like PowerPC uses runtime defined values for
>
> s/uses/use/
>

@maddy can we wrap this in while applying?
Otherwise - please let me know and I can re-send another version.

>> PMD_ORDER/PUD_ORDER. This is because it can use either RADIX or HASH MMU
>> at runtime using kernel cmdline. So the pXd_index_size is not known at
>> compile time. Without this fix, when we add huge pfn support on powerpc
>> in the next patch, vfio_pci_core driver compilation can fail with the
>> following errors.
>> 
>>   CC [M]  drivers/vfio/vfio_main.o
>>   CC [M]  drivers/vfio/group.o
>>   CC [M]  drivers/vfio/container.o
>>   CC [M]  drivers/vfio/virqfd.o
>>   CC [M]  drivers/vfio/vfio_iommu_spapr_tce.o
>>   CC [M]  drivers/vfio/pci/vfio_pci_core.o
>>   CC [M]  drivers/vfio/pci/vfio_pci_intrs.o
>>   CC [M]  drivers/vfio/pci/vfio_pci_rdwr.o
>>   CC [M]  drivers/vfio/pci/vfio_pci_config.o
>>   CC [M]  drivers/vfio/pci/vfio_pci.o
>>   AR      kernel/built-in.a
>> ../drivers/vfio/pci/vfio_pci_core.c: In function ‘vfio_pci_vmf_insert_pfn’:
>> ../drivers/vfio/pci/vfio_pci_core.c:1678:9: error: case label does not reduce to an integer constant
>>  1678 |         case PMD_ORDER:
>>       |         ^~~~
>> ../drivers/vfio/pci/vfio_pci_core.c:1682:9: error: case label does not reduce to an integer constant
>>  1682 |         case PUD_ORDER:
>>       |         ^~~~
>> make[6]: *** [../scripts/Makefile.build:289: drivers/vfio/pci/vfio_pci_core.o] Error 1
>> make[6]: *** Waiting for unfinished jobs....
>> make[5]: *** [../scripts/Makefile.build:546: drivers/vfio/pci] Error 2
>> make[5]: *** Waiting for unfinished jobs....
>> make[4]: *** [../scripts/Makefile.build:546: drivers/vfio] Error 2
>> make[3]: *** [../scripts/Makefile.build:546: drivers] Error 2
>> 
>> Fixes: f9e54c3a2f5b7 ("vfio/pci: implement huge_fault support")
>> Signed-off-by: Ritesh Harjani (IBM) <[email-masked]>
>> ---
>> v1 -> v2:
>> 1. addressed review comments from Christophe [1]
>> [1]: https://lore.kernel.org/linuxppc-dev/0b8[email-masked]/
>> 
>>  drivers/vfio/pci/vfio_pci_core.c | 19 +++++++------------
>>  1 file changed, 7 insertions(+), 12 deletions(-)
>> 
>> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
>> index d43745fe4c84..0967307235b8 100644
>> --- a/drivers/vfio/pci/vfio_pci_core.c
>> +++ b/drivers/vfio/pci/vfio_pci_core.c
>> @@ -1670,21 +1670,16 @@ vm_fault_t vfio_pci_vmf_insert_pfn(struct vfio_pci_core_device *vdev,
>>  	if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled(vdev))
>>  		return VM_FAULT_SIGBUS;
>> 
>> -	switch (order) {
>> -	case 0:
>> +	if (!order)
>>  		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
>> -#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
>> -	case PMD_ORDER:
>> +
>> +	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_PFNMAP) && order == PMD_ORDER)
>>  		return vmf_insert_pfn_pmd(vmf, pfn, false);
>> -#endif
>> -#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
>> -	case PUD_ORDER:
>> +
>> +	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PUD_PFNMAP) && order == PUD_ORDER)
>>  		return vmf_insert_pfn_pud(vmf, pfn, false);
>> -		break;
>> -#endif
>> -	default:
>> -		return VM_FAULT_FALLBACK;
>> -	}
>> +
>> +	return VM_FAULT_FALLBACK;
>>  }
>>  EXPORT_SYMBOL_GPL(vfio_pci_vmf_insert_pfn);
>
> Otherwise LGTM.  This appears to be no change for current use cases, so
> I assume this will go in through ppc trees.
>

I think that will make sense to take these 2 patches via the same tree,
so that we don't see any build issues on powerpc when the next patch
enables huge pfnmap support.

> Reviewed-by: Alex Williamson <[email-masked]>

Thanks!