Jason Gunthorpe
2025-Jul-18 14:44 UTC
[PATCH v2 1/5] mm/hmm: HMM API to enable P2P DMA for device private pages
On Fri, Jul 18, 2025 at 03:17:00PM +0100, Matthew Wilcox wrote:> On Fri, Jul 18, 2025 at 02:51:08PM +0300, Yonatan Maman wrote: > > +++ b/include/linux/memremap.h > > @@ -89,6 +89,14 @@ struct dev_pagemap_ops { > > */ > > vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); > > > > + /* > > + * Used for private (un-addressable) device memory only. Return a > > + * corresponding PFN for a page that can be mapped to device > > + * (e.g using dma_map_page) > > + */ > > + int (*get_dma_pfn_for_device)(struct page *private_page, > > + unsigned long *dma_pfn); > > This makes no sense. If a page is addressable then it has a PFN. > If a page is not addressable then it doesn't have a PFN.The DEVICE_PRIVATE pages have a PFN, but it is not usable for anything. This is effectively converting from a DEVICE_PRIVATE page to an actual DMA'able address of some kind. The DEVICE_PRIVATE is just a non-usable proxy, like a swap entry, for where the real data is sitting. Jason
Alistair Popple
2025-Jul-21 00:11 UTC
[PATCH v2 1/5] mm/hmm: HMM API to enable P2P DMA for device private pages
On Fri, Jul 18, 2025 at 11:44:42AM -0300, Jason Gunthorpe wrote:> On Fri, Jul 18, 2025 at 03:17:00PM +0100, Matthew Wilcox wrote: > > On Fri, Jul 18, 2025 at 02:51:08PM +0300, Yonatan Maman wrote: > > > +++ b/include/linux/memremap.h > > > @@ -89,6 +89,14 @@ struct dev_pagemap_ops { > > > */ > > > vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); > > > > > > + /* > > > + * Used for private (un-addressable) device memory only. Return a > > > + * corresponding PFN for a page that can be mapped to device > > > + * (e.g using dma_map_page) > > > + */ > > > + int (*get_dma_pfn_for_device)(struct page *private_page, > > > + unsigned long *dma_pfn); > > > > This makes no sense. If a page is addressable then it has a PFN. > > If a page is not addressable then it doesn't have a PFN. > > The DEVICE_PRIVATE pages have a PFN, but it is not usable for > anything. > > This is effectively converting from a DEVICE_PRIVATE page to an actual > DMA'able address of some kind. The DEVICE_PRIVATE is just a non-usable > proxy, like a swap entry, for where the real data is sitting.Yes, it's on my backlog to start looking at using something other than a real PFN for this proxy. Because having it as an actual PFN has caused us all sorts of random issues as it still needs to reserve a real physical address range which may or may not be available on a given machine.> > Jason >
Matthew Wilcox
2025-Jul-21 13:23 UTC
[PATCH v2 1/5] mm/hmm: HMM API to enable P2P DMA for device private pages
On Fri, Jul 18, 2025 at 11:44:42AM -0300, Jason Gunthorpe wrote:> On Fri, Jul 18, 2025 at 03:17:00PM +0100, Matthew Wilcox wrote: > > On Fri, Jul 18, 2025 at 02:51:08PM +0300, Yonatan Maman wrote: > > > +++ b/include/linux/memremap.h > > > @@ -89,6 +89,14 @@ struct dev_pagemap_ops { > > > */ > > > vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); > > > > > > + /* > > > + * Used for private (un-addressable) device memory only. Return a > > > + * corresponding PFN for a page that can be mapped to device > > > + * (e.g using dma_map_page) > > > + */ > > > + int (*get_dma_pfn_for_device)(struct page *private_page, > > > + unsigned long *dma_pfn); > > > > This makes no sense. If a page is addressable then it has a PFN. > > If a page is not addressable then it doesn't have a PFN. > > The DEVICE_PRIVATE pages have a PFN, but it is not usable for > anything.OK, then I don't understand what DEVICE PRIVATE means. I thought it was for memory on a PCIe device that isn't even visible through a BAR and so the CPU has no way of addressing it directly. But now you say that it has a PFN, which means it has a physical address, which means it's accessible to the CPU. So what is it?> This is effectively converting from a DEVICE_PRIVATE page to an actual > DMA'able address of some kind. The DEVICE_PRIVATE is just a non-usable > proxy, like a swap entry, for where the real data is sitting. > > Jason >