[PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48

Julian Ruess posted 3 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
Posted by Julian Ruess 1 month, 2 weeks ago
Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
the ISM device on s390. This bar is never mapped.

Acked-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 4 ++--
 include/linux/vfio_pci_core.h    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 3a11e6f450f70105f17a3a621520c195d99e0671..3d70bf6668c7a69c4b46674195954d1ada662006 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1647,7 +1647,7 @@ static unsigned long vma_to_pfn(struct vm_area_struct *vma)
 	u64 pgoff;
 
 	pgoff = vma->vm_pgoff &
-		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
+		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
 
 	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
 }
@@ -1751,7 +1751,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
 	phys_len = PAGE_ALIGN(pci_resource_len(pdev, index));
 	req_len = vma->vm_end - vma->vm_start;
 	pgoff = vma->vm_pgoff &
-		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
+		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
 	req_start = pgoff << PAGE_SHIFT;
 
 	if (req_start + req_len > phys_len)
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 1ac86896875cf5c9b5cc8ef25fae8bbd4394de05..12781707f086a330161990dc3579ec0d75887da8 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -20,7 +20,7 @@
 #ifndef VFIO_PCI_CORE_H
 #define VFIO_PCI_CORE_H
 
-#define VFIO_PCI_OFFSET_SHIFT   40
+#define VFIO_PCI_OFFSET_SHIFT   48
 #define VFIO_PCI_OFFSET_TO_INDEX(off)	(off >> VFIO_PCI_OFFSET_SHIFT)
 #define VFIO_PCI_INDEX_TO_OFFSET(index)	((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
 #define VFIO_PCI_OFFSET_MASK	(((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)

-- 
2.51.0
Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
Posted by kernel test robot 1 month, 2 weeks ago
Hi Julian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b]

url:    https://github.com/intel-lab-lkp/linux/commits/Julian-Ruess/vfio-pci-Set-VFIO_PCI_OFFSET_SHIFT-to-48/20260212-220938
base:   05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
patch link:    https://lore.kernel.org/r/20260212-vfio_pci_ism-v1-1-333262ade074%40linux.ibm.com
patch subject: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
config: riscv-randconfig-001-20260213 (https://download.01.org/0day-ci/archive/20260213/202602130659.urh1Dx2i-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260213/202602130659.urh1Dx2i-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602130659.urh1Dx2i-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/vfio/pci/nvgrace-gpu/main.c: In function 'addr_to_pgoff':
>> drivers/vfio/pci/nvgrace-gpu/main.c:196:22: warning: left shift count >= width of type [-Wshift-count-overflow]
     196 |                 ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                      ^~
   drivers/vfio/pci/nvgrace-gpu/main.c: In function 'nvgrace_gpu_mmap':
   drivers/vfio/pci/nvgrace-gpu/main.c:272:22: warning: left shift count >= width of type [-Wshift-count-overflow]
     272 |                 ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                      ^~


vim +196 drivers/vfio/pci/nvgrace-gpu/main.c

a23b10608d4203 Ankit Agrawal 2025-11-27  191  
9db65489b87298 Ankit Agrawal 2025-11-27  192  static unsigned long addr_to_pgoff(struct vm_area_struct *vma,
9db65489b87298 Ankit Agrawal 2025-11-27  193  				   unsigned long addr)
9db65489b87298 Ankit Agrawal 2025-11-27  194  {
9db65489b87298 Ankit Agrawal 2025-11-27  195  	u64 pgoff = vma->vm_pgoff &
9db65489b87298 Ankit Agrawal 2025-11-27 @196  		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
9db65489b87298 Ankit Agrawal 2025-11-27  197  
9db65489b87298 Ankit Agrawal 2025-11-27  198  	return ((addr - vma->vm_start) >> PAGE_SHIFT) + pgoff;
9db65489b87298 Ankit Agrawal 2025-11-27  199  }
9db65489b87298 Ankit Agrawal 2025-11-27  200  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
Posted by kernel test robot 1 month, 2 weeks ago
Hi Julian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b]

url:    https://github.com/intel-lab-lkp/linux/commits/Julian-Ruess/vfio-pci-Set-VFIO_PCI_OFFSET_SHIFT-to-48/20260212-220938
base:   05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
patch link:    https://lore.kernel.org/r/20260212-vfio_pci_ism-v1-1-333262ade074%40linux.ibm.com
patch subject: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
config: powerpc-randconfig-002-20260213 (https://download.01.org/0day-ci/archive/20260213/202602130603.5vXcHBPj-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260213/202602130603.5vXcHBPj-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602130603.5vXcHBPj-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/vfio/pci/vfio_pci_core.c:1646:28: warning: shift count >= width of type [-Wshift-count-overflow]
    1646 |         int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
         |                                   ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1650:9: warning: shift count >= width of type [-Wshift-count-overflow]
    1650 |                 ((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                       ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1701:22: warning: shift count >= width of type [-Wshift-count-overflow]
    1701 |                             vma->vm_pgoff >>
         |                                           ^
    1702 |                                 (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT),
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:244:9: note: expanded from macro 'dev_dbg_ratelimited'
     244 |                                   ##__VA_ARGS__);                       \
         |                                     ^~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1729:24: warning: shift count >= width of type [-Wshift-count-overflow]
    1729 |         index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
         |                               ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/vfio/pci/vfio_pci_core.c:1754:9: warning: shift count >= width of type [-Wshift-count-overflow]
    1754 |                 ((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
         |                       ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   5 warnings generated.


vim +1646 drivers/vfio/pci/vfio_pci_core.c

abafbc551fdded drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-22  1642  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1643  static unsigned long vma_to_pfn(struct vm_area_struct *vma)
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1644  {
536475109c8284 drivers/vfio/pci/vfio_pci_core.c Max Gurtovoy    2021-08-26  1645  	struct vfio_pci_core_device *vdev = vma->vm_private_data;
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29 @1646  	int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1647  	u64 pgoff;
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1648  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1649  	pgoff = vma->vm_pgoff &
c298baab91b6e3 drivers/vfio/pci/vfio_pci_core.c Julian Ruess    2026-02-12  1650  		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1651  
aac6db75a9fc2c drivers/vfio/pci/vfio_pci_core.c Alex Williamson 2024-05-29  1652  	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1653  }
11c4cd07ba111a drivers/vfio/pci/vfio_pci.c      Alex Williamson 2020-04-28  1654  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
Posted by Alex Williamson 1 month, 2 weeks ago
On Thu, 12 Feb 2026 15:02:15 +0100
Julian Ruess <julianr@linux.ibm.com> wrote:

> Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
> VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
> the ISM device on s390. This bar is never mapped.

Why does the entirety of vfio-pci need to adapt to the BAR requirements
of this device?  There's a variant driver included here that implements
its own read/write handlers and doesn't support mmap, so you're already
halfway there to implement your own region offsets independent of the
conventions of the rest of vfio-pci.  Thanks,

Alex
 
> Acked-by: Alexandra Winter <wintera@linux.ibm.com>
> Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 4 ++--
>  include/linux/vfio_pci_core.h    | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 3a11e6f450f70105f17a3a621520c195d99e0671..3d70bf6668c7a69c4b46674195954d1ada662006 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -1647,7 +1647,7 @@ static unsigned long vma_to_pfn(struct vm_area_struct *vma)
>  	u64 pgoff;
>  
>  	pgoff = vma->vm_pgoff &
> -		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
> +		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
>  
>  	return (pci_resource_start(vdev->pdev, index) >> PAGE_SHIFT) + pgoff;
>  }
> @@ -1751,7 +1751,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
>  	phys_len = PAGE_ALIGN(pci_resource_len(pdev, index));
>  	req_len = vma->vm_end - vma->vm_start;
>  	pgoff = vma->vm_pgoff &
> -		((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
> +		((1UL << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
>  	req_start = pgoff << PAGE_SHIFT;
>  
>  	if (req_start + req_len > phys_len)
> diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
> index 1ac86896875cf5c9b5cc8ef25fae8bbd4394de05..12781707f086a330161990dc3579ec0d75887da8 100644
> --- a/include/linux/vfio_pci_core.h
> +++ b/include/linux/vfio_pci_core.h
> @@ -20,7 +20,7 @@
>  #ifndef VFIO_PCI_CORE_H
>  #define VFIO_PCI_CORE_H
>  
> -#define VFIO_PCI_OFFSET_SHIFT   40
> +#define VFIO_PCI_OFFSET_SHIFT   48
>  #define VFIO_PCI_OFFSET_TO_INDEX(off)	(off >> VFIO_PCI_OFFSET_SHIFT)
>  #define VFIO_PCI_INDEX_TO_OFFSET(index)	((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
>  #define VFIO_PCI_OFFSET_MASK	(((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
>
Re: [PATCH 1/3] vfio/pci: Set VFIO_PCI_OFFSET_SHIFT to 48
Posted by Jason Gunthorpe 1 month, 2 weeks ago
On Thu, Feb 12, 2026 at 03:02:15PM +0100, Julian Ruess wrote:
> Extend VFIO_PCI_OFFSET_SHIFT to 48 to use the vfio-pci
> VFIO_PCI_OFFSET_TO_INDEX() mechanism with the 256 TiB pseudo-BAR 0 of
> the ISM device on s390. This bar is never mapped.

Woah, this is dangerous, the size was selected to fit within a pgoff
of a 32bit system.. Does this entirely break vfio on 32 bit?

Jason