Skip to contentSkip to conversation

fix sg_phys to use dma_addr_t

PATCH In review Hugh Dickins 4 participants 10 messages Oct 25, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix sg_phys to use dma_addr_t

x86_32 CONFIG_HIGHMEM64G with 5GB RAM hung when booting, after issuing some "request_module: runaway loop modprobe binfmt-0000" messages in trying to exec /sbin/init.

The binprm buf doesn't see the right ".ELF" header because sg_phys() is providing the wrong physical addresses for high pages: a 32-bit unsigned long is too small in this case, we need to use dma_addr_t.

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

 include/linux/scatterlist.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/scatterlist.h +2 -1
@@ -1,6 +1,7 @@
 #ifndef _LINUX_SCATTERLIST_H
 #define _LINUX_SCATTERLIST_H
 
+#include <asm/types.h>
 #include <asm/scatterlist.h>
 #include <linux/mm.h>
 #include <linux/string.h>
@@ -237,7 +238,7 @@ static inline void sg_init_table(struct 
  *   on the sg page.
  *
  **/
-static inline unsigned long sg_phys(struct scatterlist *sg)
+static inline dma_addr_t sg_phys(struct scatterlist *sg)
 {
 	return page_to_phys(sg_page(sg)) + sg->offset;
 }
#1 lore raw
Quoted 10 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

#2 lore raw
Quoted 10 lines · Arjan van de Ven
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

True. Perhaps sg_phys() should use its own sg_phys_addr_t, defined or typedefed to be the same as dma_addr_t. But would this inline function then be the only place in the tree which uses that type? If so, then it'd probably be better just to let sg_phys() carry on using dma_addr_t, but insert a comment there to make your point.

But I'll leave it to Jens to fix up the patch appropriately: for all I know, there might be arches on which using dma_addr_t there actually does the wrong thing - I don't think so, but I know too little about it.

Hugh

#3 lore raw
Quoted 21 lines · Hugh Dickins
Quoted 10 lines · Arjan van de Ven
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

True. Perhaps sg_phys() should use its own sg_phys_addr_t, defined or typedefed to be the same as dma_addr_t. But would this inline function then be the only place in the tree which uses that type? If so, then it'd probably be better just to let sg_phys() carry on using dma_addr_t, but insert a comment there to make your point.

Quoted 4 lines

But I'll leave it to Jens to fix up the patch appropriately: for all I know, there might be arches on which using dma_addr_t there actually does the wrong thing - I don't think so, but I know too little about it.

dma_addr_t would seem OK to me, given the lack of phys_addr_t.

Signature · 1 line
Jens Axboe
#4 lore raw
In reply to Arjan van de Ven

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Ok, then: how do I actually get such an address?

Eike

#5 lore raw
Quoted 11 lines · Rolf Eike Beer

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 5 lines
Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Ok, then: how do I actually get such an address?

You use the dma mapping api, Documentation/DMA-mapping.txt

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 12 lines · Jens Axboe
Quoted 11 lines · Rolf Eike Beer

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Ok, then: how do I actually get such an address?

You use the dma mapping api, Documentation/DMA-mapping.txt

Which comes back always to the same point: if I get a buffer from userspace to use for DMA: what can I do then? I need to convert a given list of (physical, pinned) pages to DMA addresses.

Eike

#7 lore raw
Quoted 17 lines · Rolf Eike Beer
Quoted 16 lines · Jens Axboe
Quoted 15 lines · Rolf Eike Beer

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 13 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Ok, then: how do I actually get such an address?

You use the dma mapping api, Documentation/DMA-mapping.txt

Which comes back always to the same point: if I get a buffer from userspace to use for DMA: what can I do then? I need to convert a given list of (physical, pinned) pages to DMA addresses.

get_user_pages() -> fill in sg table -> pci/dma_map_sg()

Signature · 1 line
Jens Axboe
#8 lore raw
Quoted 20 lines · Jens Axboe
Quoted 19 lines · Rolf Eike Beer
Quoted 18 lines · Jens Axboe
Quoted 16 lines · Rolf Eike Beer

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Ok, then: how do I actually get such an address?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

You use the dma mapping api, Documentation/DMA-mapping.txt

Which comes back always to the same point: if I get a buffer from userspace to use for DMA: what can I do then? I need to convert a given list of (physical, pinned) pages to DMA addresses.

get_user_pages() -> fill in sg table -> pci/dma_map_sg()

So the answer to the first question should have been sg_dma_address() ;)

Eike

#9 lore raw
Quoted 23 lines · Rolf Eike Beer
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Rolf Eike Beer
Quoted 19 lines · Jens Axboe
Quoted 11 lines · Rolf Eike Beer

Am Donnerstag, 25. Oktober 2007 schrieb Arjan van de Ven:

Quoted 10 lines
Quoted 9 lines

---
Whether this is a complete patch, suitable for all architectures, I'm not sure: it builds, boots and runs correctly on the x86_32 box in question, but you'll be a lot wiser than me about using dma_addr_t for everyone. (Seems a bit of a shame to include <asm/types.h> here, when I think all arches already get to include it one way or another, typically via asm/scatterlist.h; but I guess it's safest to repeat it.)

Quoted 5 lines
Quoted 3 lines

there is a problem with this... sg_phys doesn't return an actual *dma* address.... at least not an address you can give to the device. Using dma_addr_t is thus a bit misleading.....

Ok, then: how do I actually get such an address?

You use the dma mapping api, Documentation/DMA-mapping.txt

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Which comes back always to the same point: if I get a buffer from userspace to use for DMA: what can I do then? I need to convert a given list of (physical, pinned) pages to DMA addresses.

get_user_pages() -> fill in sg table -> pci/dma_map_sg()

So the answer to the first question should have been sg_dma_address() ;)

Yes, provided it's mapped you use sg_dma_address() and sg_dma_len() :-)

Signature · 1 line
Jens Axboe