Skip to contentSkip to conversation

do_no_pfn

PATCH In review Jes Sorensen 5 participants 15 messages Jun 19, 2006 – Jun 27, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 do_no_pfn

Hi,

I woke up this morning and had a revelation! Today is the day, the day of do_no_pfn()! It can be no other way ... :) And what happens, I come into the office to discover that 2.6.17 is out! It has to be a sign!

Anyway, I have had no objections to this patch for a while now, clearly it is perfect<tm> :) If anybody has new objections, it's obviously not my fault! But ok I'll look at them anyway :)

So here it is, it even boots!

Cheers,
Jes

Implement do_no_pfn() for handling mapping of memory without a struct page backing it. This avoids creating fake page table entries for regions which are not backed by real memory.

This version uses specific NOPFN_{SIGBUS,OOM} return values, rather than expect all negative pfn values would be an error. It also bugs on cow mappings as this would not work with the VM.

---
 include/linux/mm.h |    7 +++++
 mm/memory.c        |   62 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 5 deletions(-)
include/linux/mm.h +7 -0
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -199,6 +199,7 @@
 	void (*open)(struct vm_area_struct * area);
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
+	unsigned long (*nopfn)(struct vm_area_struct * area, unsigned long address);
 	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
 #ifdef CONFIG_NUMA
 	int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
@@ -612,6 +613,12 @@
 #define NOPAGE_OOM	((struct page *) (-1))
 
 /*
+ * Error return values for the *_nopfn functions
+ */
+#define NOPFN_SIGBUS	((unsigned long) -1)
+#define NOPFN_OOM	((unsigned long) -2)
+
+/*
  * Different kinds of faults, as returned by handle_mm_fault().
  * Used to decide whether a process gets delivered SIGBUS or
  * just gets major/minor fault counters bumped up.
mm/memory.c +57 -5

74 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · Jes Sorensen

Hi,

I woke up this morning and had a revelation! Today is the day, the day of do_no_pfn()! It can be no other way ... :) And what happens, I come into the office to discover that 2.6.17 is out! It has to be a sign!

Anyway, I have had no objections to this patch for a while now, clearly it is perfect<tm> :) If anybody has new objections, it's obviously not my fault! But ok I'll look at them anyway :)

So here it is, it even boots!

The big question is - why do you have pages without struct page? It seems ... wrong.

-Andi

#2 lore raw
Quoted 2 lines · Andi Kleen

The big question is - why do you have pages without struct page? It seems ... wrong.

For mspec, these are pages which come from the efi trim regions. They are not usuable by the kernel. Dropping in a kernel TLB entry for them does allow speculation into PROM reserved memory which will result in corrupting PROMs memory. We have seen this in the past.

Additionally, Carsten Otte had been pursuing a do_no_pfn function to allow execute in place to insert executable pages into an os instance which are actually part of the physical machines memory map, but not part of the virtual machines. Several virtual machines could share the same physical page. I, of course, reserve the right to have gotten Carsten's intentions completely wrong. I don't believe I have misinterpretted the intentions of do_no_pfn as expressed on the linux-mm mailing list.

Are you saying the for the mspec pages we should extend the vmem_map, partially populate the regions for the mspec pages, mark those pages as uncached and reserved and then turn them over to the uncached allocator? Seems like we have done a lot of extra work to put a struct page behind a page which requires special handling.

For Carsten's case, how would you propose we handle that?

Thanks,
Robin

#3 lore raw
Quoted 3 lines · Robin Holt
Quoted 2 lines · Andi Kleen

The big question is - why do you have pages without struct page? It seems ... wrong.

[snip]

Quoted 5 lines

Are you saying the for the mspec pages we should extend the vmem_map, partially populate the regions for the mspec pages, mark those pages as uncached and reserved and then turn them over to the uncached allocator? Seems like we have done a lot of extra work to put a struct page behind a page which requires special handling.

Note that Bjorn Helgas has a case where he needs this as well.

We could fake the pages by giving them a struct page, but it really makes no point as you say.

Cheers,
Jes

#4 lore raw
Quoted 11 lines · Jes Sorensen
Quoted 3 lines · Robin Holt
Quoted 2 lines · Andi Kleen

The big question is - why do you have pages without struct page? It seems ... wrong.

[snip]

Quoted 5 lines

Are you saying the for the mspec pages we should extend the vmem_map, partially populate the regions for the mspec pages, mark those pages as uncached and reserved and then turn them over to the uncached allocator? Seems like we have done a lot of extra work to put a struct page behind a page which requires special handling.

Quoted 4 lines

Note that Bjorn Helgas has a case where he needs this as well.

We could fake the pages by giving them a struct page, but it really makes no point as you say.

I think it would be better if you gave them struct pages instead of messing up core vm with such strange hooks.

Or alternatively code this in a different way. There are drivers who map IO memory into user space without needing hacks like that. Usually they just tweak the page tables directly on mmap.

-Andi

#5 lore raw
Quoted 10 lines · Andi Kleen
Quoted 2 lines · Jes Sorensen

We could fake the pages by giving them a struct page, but it really makes no point as you say.

I think it would be better if you gave them struct pages instead of messing up core vm with such strange hooks.

Or alternatively code this in a different way. There are drivers who map IO memory into user space without needing hacks like that. Usually they just tweak the page tables directly on mmap.

Please go back and read the old threads on this for all the details, I would miss half the points if I was to try and restate it all from memory.

Doing this at mmap time does not work, you want NUMA node locality. It has to be done through first touch mappings.

Jes

#6 lore raw
Quoted 4 lines

Please go back and read the old threads on this for all the details, I would miss half the points if I was to try and restate it all from memory.

Shouldn't these points be in the patch submission description?

Quoted 2 lines

Doing this at mmap time does not work, you want NUMA node locality. It has to be done through first touch mappings.

Then create struct page *s.

-Andi

#7 lore raw
Quoted 5 lines · Andi Kleen
Quoted 3 lines

Please go back and read the old threads on this for all the details, I would miss half the points if I was to try and restate it all from memory.

Shouldn't these points be in the patch submission description?

You expect people to go look for things on random mailing lists when you post it, but you don't care to search the archives yourself.... och well.

http://www.gelato.unsw.edu.au/archives/linux-ia64/0603/index.html#17543

http://www.ussg.iu.edu/hypermail/linux/kernel/0604.2/index.html#0652
http://www.ussg.iu.edu/hypermail/linux/kernel/0604.3/index.html#0029

Quoted 4 lines
Quoted 2 lines

Doing this at mmap time does not work, you want NUMA node locality. It has to be done through first touch mappings.

Then create struct page *s.

One struct page for a random single page here, another for a single random page there. And the risk that someone will start walking the pages and dereference and cause data corruption. As explained before, it's a bad idea.

Jes

#8 lore raw
Quoted 5 lines

One struct page for a random single page here, another for a single random page there. And the risk that someone will start walking the pages and dereference and cause data corruption. As explained before, it's a bad idea.

Note sure what your point is. Why should they cause memory corruption?

Allowing struct page less VM is worse. If you add that then people will use it for other stuff, and eventually we got a two class VM. All not very good.

-Andi

#9 lore raw
Quoted 11 lines · Andi Kleen
Quoted 5 lines

One struct page for a random single page here, another for a single random page there. And the risk that someone will start walking the pages and dereference and cause data corruption. As explained before, it's a bad idea.

Note sure what your point is. Why should they cause memory corruption?

Allowing struct page less VM is worse. If you add that then people will use it for other stuff, and eventually we got a two class VM. All not very good.

You already have that. You already stated the mapping of device memory. The only thing we are asking to do is have a block of device memory which has its pfn inserted at first touch. The device is essentially available on each node. It is not something the generic parts of the VM need to manage. What benefit are we going to get from having struct page * behind the pages when the struct page need to be marked as reserved and uncached?

Thanks,
Robin

#10 lore raw
In reply to Andi Kleen
Quoted 10 lines · Andi Kleen
Quoted 4 lines

One struct page for a random single page here, another for a single random page there. And the risk that someone will start walking the pages and dereference and cause data corruption. As explained before, it's a bad idea.

Note sure what your point is. Why should they cause memory corruption?

Allowing struct page less VM is worse. If you add that then people will use it for other stuff, and eventually we got a two class VM. All not very good.

Special treatment of the pages are required. In particular they *must* be referenced in uncached mode. If something derefences the struct page in cached mode and the official user of the page does it correctly in uncached mode one risks memory corruption. It's worse than that in fact it has to be a full granule of pages that isn't touched like this.

But as Robin pointed out, there just is no real benefit to having a struct page behind it.

Cheers,
Jes

#11 lore raw
In reply to Jes Sorensen
Quoted 6 lines · Jes Sorensen
Quoted 3 lines · Robin Holt
Quoted 2 lines · Andi Kleen

The big question is - why do you have pages without struct page? It seems ... wrong.

...
Note that Bjorn Helgas has a case where he needs this as well.

I do have a case where I used pages without struct pages, but I don't really like the implementation, and I'd love to have someone who knows about VM tell me "no, dummy, you should do it this way instead."

Here's the scenario: I'm trying to implement /sys/class/pci_bus/DDDD:BB/legacy_mem so we can run X servers on multiple VGA cards. The chipset (used in HP parisc and ia64 boxes) supports multiple PCI root bridges, and it routes the VGA legacy MMIO space at 0xA0000-0xBFFFF to one of them.

This region is MMIO, so there are no struct pages for it. I can easily mmap the space for the first VGA device. But to support a second device, I have to be able to invalidate the mappings for the first device, twiddle stuff in the chipset, and make new mappings for the second device. And of course I have to do the reverse (invalidate mappings of second device, twiddle chipset, map first device) when the first X server faults on the frame buffer.

Basically, only one of the /sys/class/pci_bus/DDDD:BB/legacy_mem files can have an active mmap at a time, and I haven't figured out a good way to do the mutual exclusion.

Bjorn

#12 lore raw
Quoted 20 lines · Bjorn Helgaas

I do have a case where I used pages without struct pages, but I don't really like the implementation, and I'd love to have someone who knows about VM tell me "no, dummy, you should do it this way instead."

Here's the scenario: I'm trying to implement /sys/class/pci_bus/DDDD:BB/legacy_mem so we can run X servers on multiple VGA cards. The chipset (used in HP parisc and ia64 boxes) supports multiple PCI root bridges, and it routes the VGA legacy MMIO space at 0xA0000-0xBFFFF to one of them.

This region is MMIO, so there are no struct pages for it. I can easily mmap the space for the first VGA device. But to support a second device, I have to be able to invalidate the mappings for the first device, twiddle stuff in the chipset, and make new mappings for the second device. And of course I have to do the reverse (invalidate mappings of second device, twiddle chipset, map first device) when the first X server faults on the frame buffer.

Quoted 3 lines

Basically, only one of the /sys/class/pci_bus/DDDD:BB/legacy_mem files can have an active mmap at a time, and I haven't figured out a good way to do the mutual exclusion.

Probably you can just nuke the pte's similar to __xip_unmap() in mm/filemap_xip.c.

cheers,
Carsten

#13 lore raw
In reply to Robin Holt
Quoted 1 line · Robin Holt

For Carsten's case, how would you propose we handle that?

After previous discussion with Linus, and because I do not have a good idea how to solve the remaining problems in a clean way (yet?), please leave my case out for now. We won't need it anytime soon on 390 as far as I can tell.

Quoted 2 lines · Linus Torvalds

You _really_ cannot do COW together with "random pfn filling".

cheers,
Carsten

#14 lore raw

PATCH 1/1 do_no_pfn - against latest git

In reply to Jes Sorensen

Hi Linus,

Included is the latest diff of the do_no_pfn patch against the latest git tree. Since there has been no new objections to this one, it would be nice to get it in before 2.6.18 closes.

Thanks,
Jes

Implement do_no_pfn() for handling mapping of memory without a struct page backing it. This avoids creating fake page table entries for regions which are not backed by real memory.

This feature is used by the MSPEC driver and other users, where it is highly undesirable to have a struct page sitting behind the page (for instance if the page is accessed in cached mode via the struct page in parallel to the the driver accessing it uncached, which can result in data corruption on some architectures, such as ia64).

This version uses specific NOPFN_{SIGBUS,OOM} return values, rather than expect all negative pfn values would be an error. It also bugs on cow mappings as this would not work with the VM.

---
 include/linux/mm.h |    7 +++++
 mm/memory.c        |   62 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 5 deletions(-)
include/linux/mm.h +7 -0
Index: linux-2.6/include/linux/mm.h
===================================================================
@@ -197,6 +197,7 @@ struct vm_operations_struct {
 	void (*open)(struct vm_area_struct * area);
 	void (*close)(struct vm_area_struct * area);
 	struct page * (*nopage)(struct vm_area_struct * area, unsigned long address, int *type);
+	unsigned long (*nopfn)(struct vm_area_struct * area, unsigned long address);
 	int (*populate)(struct vm_area_struct * area, unsigned long address, unsigned long len, pgprot_t prot, unsigned long pgoff, int nonblock);
 
 	/* notification that a previously read-only page is about to become
@@ -619,6 +620,12 @@ static inline int page_mapped(struct pag
 #define NOPAGE_OOM	((struct page *) (-1))
 
 /*
+ * Error return values for the *_nopfn functions
+ */
+#define NOPFN_SIGBUS	((unsigned long) -1)
+#define NOPFN_OOM	((unsigned long) -2)
+
+/*
  * Different kinds of faults, as returned by handle_mm_fault().
  * Used to decide whether a process gets delivered SIGBUS or
  * just gets major/minor fault counters bumped up.
mm/memory.c +57 -5

74 lines not on this page · raw message