linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block
@ 2026-02-27  6:16 Ritesh Harjani (IBM)
  2026-02-27  6:16 ` [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps Ritesh Harjani (IBM)
  2026-02-27  6:42 ` [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Christophe Leroy (CS GROUP)
  0 siblings, 2 replies; 6+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-02-27  6:16 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu, Ritesh Harjani (IBM)

Architectures like PowerPC uses runtime defined values for
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) <ritesh.list@gmail.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index d43745fe4c84..5395a6f30904 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1670,21 +1670,20 @@ 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 == 0) {
 		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
+	}
 #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
-	case PMD_ORDER:
+	 else if (order == PMD_ORDER) {
 		return vmf_insert_pfn_pmd(vmf, pfn, false);
+	 }
 #endif
 #ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
-	case PUD_ORDER:
+	 else if (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);

--
2.53.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps
  2026-02-27  6:16 [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Ritesh Harjani (IBM)
@ 2026-02-27  6:16 ` Ritesh Harjani (IBM)
  2026-02-27  6:47   ` Christophe Leroy (CS GROUP)
  2026-02-27  6:42 ` [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Christophe Leroy (CS GROUP)
  1 sibling, 1 reply; 6+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-02-27  6:16 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu, Ritesh Harjani (IBM)

This uses _RPAGE_SW2 bit for the PMD and PUDs similar to PTEs.
This also adds support for {pte,pmd,pud}_pgprot helpers needed for
follow_pfnmap APIs.

This allows us to extend the PFN mappings, e.g. PCI MMIO bars where
it can grow as large as 8GB or even bigger, to map at PMD / PUD level.
VFIO PCI core driver already supports fault handling at PMD / PUD level
for more efficient BAR mappings.

Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---

@linux-mm:
Is there any official test which I could use to verify this functionality.

For now I used basic ivshmem setup + vfio using Qemu and validated using some
basic test to see that we are seeing these prints.

[ 4351.435050] vfio_pci_mmap_huge_fault: 3 callbacks suppressed
[ 4351.435234] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x0: 0x100
[ 4351.457005] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x40: 0x100
[ 4351.463684] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x20: 0x100

 arch/powerpc/Kconfig                         |  1 +
 arch/powerpc/include/asm/book3s/64/pgtable.h | 23 ++++++++++++++++++++
 arch/powerpc/include/asm/pgtable.h           | 12 ++++++++++
 3 files changed, 36 insertions(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index ad7a2fe63a2a..cf9283757e5d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -172,6 +172,7 @@ config PPC
 	select ARCH_STACKWALK
 	select ARCH_SUPPORTS_ATOMIC_RMW
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC	if PPC_BOOK3S || PPC_8xx
+	select ARCH_SUPPORTS_HUGE_PFNMAP	if PPC_BOOK3S_64 && TRANSPARENT_HUGEPAGE
 	select ARCH_SUPPORTS_PAGE_TABLE_CHECK	if !HUGETLB_PAGE
 	select ARCH_SUPPORTS_SCHED_MC		if SMP
 	select ARCH_SUPPORTS_SCHED_SMT		if PPC64 && SMP
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 1a91762b455d..639cbf34f752 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1289,6 +1289,29 @@ static inline pud_t pud_mkhuge(pud_t pud)
 	return pud;
 }

+#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
+static inline bool pmd_special(pmd_t pmd)
+{
+	return pte_special(pmd_pte(pmd));
+}
+
+static inline pmd_t pmd_mkspecial(pmd_t pmd)
+{
+	return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
+}
+#endif
+
+#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
+static inline bool pud_special(pud_t pud)
+{
+	return pte_special(pud_pte(pud));
+}
+
+static inline pud_t pud_mkspecial(pud_t pud)
+{
+	return pte_pud(pte_mkspecial(pud_pte(pud)));
+}
+#endif

 #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
 extern int pmdp_set_access_flags(struct vm_area_struct *vma,
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index dcd3a88caaf6..2d27cb1c2334 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -63,6 +63,18 @@ static inline pgprot_t pte_pgprot(pte_t pte)
 	return __pgprot(pte_flags);
 }

+#define pmd_pgprot pmd_pgprot
+static inline pgprot_t pmd_pgprot(pmd_t pmd)
+{
+	return pte_pgprot(pmd_pte(pmd));
+}
+
+#define pud_pgprot pud_pgprot
+static inline pgprot_t pud_pgprot(pud_t pud)
+{
+	return pte_pgprot(pud_pte(pud));
+}
+
 static inline pgprot_t pgprot_nx(pgprot_t prot)
 {
 	return pte_pgprot(pte_exprotect(__pte(pgprot_val(prot))));
--
2.53.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block
  2026-02-27  6:16 [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Ritesh Harjani (IBM)
  2026-02-27  6:16 ` [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps Ritesh Harjani (IBM)
@ 2026-02-27  6:42 ` Christophe Leroy (CS GROUP)
  2026-02-27 10:30   ` Ritesh Harjani
  1 sibling, 1 reply; 6+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-02-27  6:42 UTC (permalink / raw)
  To: Ritesh Harjani (IBM), linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu



Le 27/02/2026 à 07:16, Ritesh Harjani (IBM) a écrit :
> Architectures like PowerPC uses runtime defined values for
> 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) <ritesh.list@gmail.com>
> ---
>   drivers/vfio/pci/vfio_pci_core.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index d43745fe4c84..5395a6f30904 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1670,21 +1670,20 @@ 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 == 0) {
>   		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
> +	}

Those braces are unneeded as all legs of the if/else are single lines

>   #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP

ifdef could be replaced by IS_ENABLED() because PxD_ORDER and 
vmf_insert_pfn_xxx() are declared all the time

> -	case PMD_ORDER:
> +	 else if (order == PMD_ORDER) {

'else' is not needed because every 'if' leads to a return statement

>   		return vmf_insert_pfn_pmd(vmf, pfn, false);
> +	 }
>   #endif
>   #ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
> -	case PUD_ORDER:
> +	 else if (order == PUD_ORDER) {
>   		return vmf_insert_pfn_pud(vmf, pfn, false);
> -		break;
> +	 }
>   #endif
> -	default:
> -		return VM_FAULT_FALLBACK;
> -	}
> +	return VM_FAULT_FALLBACK;

So at the end we should get something like:

	if (!order)
		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);

	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_PFNMAP) && order == PMD_ORDER)
		return vmf_insert_pfn_pmd(vmf, pfn, false);

	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PUD_PFNMAP) && order == PMD_ORDER)
		return vmf_insert_pfn_pud(vmf, pfn, false);

	return VM_FAULT_FALLBACK;


>   }
>   EXPORT_SYMBOL_GPL(vfio_pci_vmf_insert_pfn);
> 
> --
> 2.53.0
> 
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps
  2026-02-27  6:16 ` [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps Ritesh Harjani (IBM)
@ 2026-02-27  6:47   ` Christophe Leroy (CS GROUP)
  2026-02-27 10:32     ` Ritesh Harjani
  0 siblings, 1 reply; 6+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-02-27  6:47 UTC (permalink / raw)
  To: Ritesh Harjani (IBM), linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu



Le 27/02/2026 à 07:16, Ritesh Harjani (IBM) a écrit :
> This uses _RPAGE_SW2 bit for the PMD and PUDs similar to PTEs.
> This also adds support for {pte,pmd,pud}_pgprot helpers needed for
> follow_pfnmap APIs.
> 
> This allows us to extend the PFN mappings, e.g. PCI MMIO bars where
> it can grow as large as 8GB or even bigger, to map at PMD / PUD level.
> VFIO PCI core driver already supports fault handling at PMD / PUD level
> for more efficient BAR mappings.
> 
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>


> ---
> 
> @linux-mm:
> Is there any official test which I could use to verify this functionality.
> 
> For now I used basic ivshmem setup + vfio using Qemu and validated using some
> basic test to see that we are seeing these prints.
> 
> [ 4351.435050] vfio_pci_mmap_huge_fault: 3 callbacks suppressed
> [ 4351.435234] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x0: 0x100
> [ 4351.457005] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x40: 0x100
> [ 4351.463684] vfio-pci 0001:00:00.0: vfio_pci_mmap_huge_fault(,order = 5) BAR 2 page offset 0x20: 0x100
> 
>   arch/powerpc/Kconfig                         |  1 +
>   arch/powerpc/include/asm/book3s/64/pgtable.h | 23 ++++++++++++++++++++
>   arch/powerpc/include/asm/pgtable.h           | 12 ++++++++++
>   3 files changed, 36 insertions(+)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index ad7a2fe63a2a..cf9283757e5d 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -172,6 +172,7 @@ config PPC
>   	select ARCH_STACKWALK
>   	select ARCH_SUPPORTS_ATOMIC_RMW
>   	select ARCH_SUPPORTS_DEBUG_PAGEALLOC	if PPC_BOOK3S || PPC_8xx
> +	select ARCH_SUPPORTS_HUGE_PFNMAP	if PPC_BOOK3S_64 && TRANSPARENT_HUGEPAGE
>   	select ARCH_SUPPORTS_PAGE_TABLE_CHECK	if !HUGETLB_PAGE
>   	select ARCH_SUPPORTS_SCHED_MC		if SMP
>   	select ARCH_SUPPORTS_SCHED_SMT		if PPC64 && SMP
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 1a91762b455d..639cbf34f752 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -1289,6 +1289,29 @@ static inline pud_t pud_mkhuge(pud_t pud)
>   	return pud;
>   }
> 
> +#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
> +static inline bool pmd_special(pmd_t pmd)
> +{
> +	return pte_special(pmd_pte(pmd));
> +}
> +
> +static inline pmd_t pmd_mkspecial(pmd_t pmd)
> +{
> +	return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
> +}
> +#endif
> +
> +#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
> +static inline bool pud_special(pud_t pud)
> +{
> +	return pte_special(pud_pte(pud));
> +}
> +
> +static inline pud_t pud_mkspecial(pud_t pud)
> +{
> +	return pte_pud(pte_mkspecial(pud_pte(pud)));
> +}
> +#endif
> 
>   #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
>   extern int pmdp_set_access_flags(struct vm_area_struct *vma,
> diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
> index dcd3a88caaf6..2d27cb1c2334 100644
> --- a/arch/powerpc/include/asm/pgtable.h
> +++ b/arch/powerpc/include/asm/pgtable.h
> @@ -63,6 +63,18 @@ static inline pgprot_t pte_pgprot(pte_t pte)
>   	return __pgprot(pte_flags);
>   }
> 
> +#define pmd_pgprot pmd_pgprot
> +static inline pgprot_t pmd_pgprot(pmd_t pmd)
> +{
> +	return pte_pgprot(pmd_pte(pmd));
> +}
> +
> +#define pud_pgprot pud_pgprot
> +static inline pgprot_t pud_pgprot(pud_t pud)
> +{
> +	return pte_pgprot(pud_pte(pud));
> +}
> +
>   static inline pgprot_t pgprot_nx(pgprot_t prot)
>   {
>   	return pte_pgprot(pte_exprotect(__pte(pgprot_val(prot))));
> --
> 2.53.0
> 
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block
  2026-02-27  6:42 ` [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Christophe Leroy (CS GROUP)
@ 2026-02-27 10:30   ` Ritesh Harjani
  0 siblings, 0 replies; 6+ messages in thread
From: Ritesh Harjani @ 2026-02-27 10:30 UTC (permalink / raw)
  To: Christophe Leroy (CS GROUP), linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu

"Christophe Leroy (CS GROUP)" <chleroy@kernel.org> writes:

> Le 27/02/2026 à 07:16, Ritesh Harjani (IBM) a écrit :
>> Architectures like PowerPC uses runtime defined values for
>> 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) <ritesh.list@gmail.com>
>> ---
>>   drivers/vfio/pci/vfio_pci_core.c | 15 +++++++--------
>>   1 file changed, 7 insertions(+), 8 deletions(-)
>> 
>> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
>> index d43745fe4c84..5395a6f30904 100644
>> --- a/drivers/vfio/pci/vfio_pci_core.c
>> +++ b/drivers/vfio/pci/vfio_pci_core.c
>> @@ -1670,21 +1670,20 @@ 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 == 0) {
>>   		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
>> +	}
>
> Those braces are unneeded as all legs of the if/else are single lines
>
>>   #ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
>
> ifdef could be replaced by IS_ENABLED() because PxD_ORDER and 
> vmf_insert_pfn_xxx() are declared all the time
>
>> -	case PMD_ORDER:
>> +	 else if (order == PMD_ORDER) {
>
> 'else' is not needed because every 'if' leads to a return statement
>
>>   		return vmf_insert_pfn_pmd(vmf, pfn, false);
>> +	 }
>>   #endif
>>   #ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
>> -	case PUD_ORDER:
>> +	 else if (order == PUD_ORDER) {
>>   		return vmf_insert_pfn_pud(vmf, pfn, false);
>> -		break;
>> +	 }
>>   #endif
>> -	default:
>> -		return VM_FAULT_FALLBACK;
>> -	}
>> +	return VM_FAULT_FALLBACK;
>
> So at the end we should get something like:
>
> 	if (!order)
> 		return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
>
> 	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PMD_PFNMAP) && order == PMD_ORDER)
> 		return vmf_insert_pfn_pmd(vmf, pfn, false);
>
> 	if (IS_ENABLED(CONFIG_ARCH_SUPPORTS_PUD_PFNMAP) && order == PMD_ORDER)
                                                                ^^^ PUD_ORDER

> 		return vmf_insert_pfn_pud(vmf, pfn, false);
>
> 	return VM_FAULT_FALLBACK;
>
>

Looks a lot cleaner. Thanks!
I will make that change in v2.

-ritesh


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps
  2026-02-27  6:47   ` Christophe Leroy (CS GROUP)
@ 2026-02-27 10:32     ` Ritesh Harjani
  0 siblings, 0 replies; 6+ messages in thread
From: Ritesh Harjani @ 2026-02-27 10:32 UTC (permalink / raw)
  To: Christophe Leroy (CS GROUP), linuxppc-dev
  Cc: linux-mm, kvm, Alex Williamson, Peter Xu

"Christophe Leroy (CS GROUP)" <chleroy@kernel.org> writes:

> Le 27/02/2026 à 07:16, Ritesh Harjani (IBM) a écrit :
>> This uses _RPAGE_SW2 bit for the PMD and PUDs similar to PTEs.
>> This also adds support for {pte,pmd,pud}_pgprot helpers needed for
>> follow_pfnmap APIs.
>> 
>> This allows us to extend the PFN mappings, e.g. PCI MMIO bars where
>> it can grow as large as 8GB or even bigger, to map at PMD / PUD level.
>> VFIO PCI core driver already supports fault handling at PMD / PUD level
>> for more efficient BAR mappings.
>> 
>> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>
> Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
>
>

Thanks for the review!

>>   #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
>>   extern int pmdp_set_access_flags(struct vm_area_struct *vma,
>> diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
>> index dcd3a88caaf6..2d27cb1c2334 100644
>> --- a/arch/powerpc/include/asm/pgtable.h
>> +++ b/arch/powerpc/include/asm/pgtable.h
>> @@ -63,6 +63,18 @@ static inline pgprot_t pte_pgprot(pte_t pte)
>>   	return __pgprot(pte_flags);
>>   }
>> 
>> +#define pmd_pgprot pmd_pgprot
>> +static inline pgprot_t pmd_pgprot(pmd_t pmd)
>> +{
>> +	return pte_pgprot(pmd_pte(pmd));
>> +}
>> +
>> +#define pud_pgprot pud_pgprot
>> +static inline pgprot_t pud_pgprot(pud_t pud)
>> +{
>> +	return pte_pgprot(pud_pte(pud));
>> +}
>> +

In v2 - I will add above under #ifdef CONFIG_PPC_BOOK3S_64 
to avoid build issues with 32-bit PPC.

-ritesh


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-27 12:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-27  6:16 [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Ritesh Harjani (IBM)
2026-02-27  6:16 ` [RFC v1 2/2] powerpc/64s: Add support for huge pfnmaps Ritesh Harjani (IBM)
2026-02-27  6:47   ` Christophe Leroy (CS GROUP)
2026-02-27 10:32     ` Ritesh Harjani
2026-02-27  6:42 ` [RFC v1 1/2] drivers/vfio_pci_core: Change PXD_ORDER check from switch case to if/else block Christophe Leroy (CS GROUP)
2026-02-27 10:30   ` Ritesh Harjani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox