In a linux sk_buff, is skb->data a physical or virtual address?

3.4k views Asked by At

I'm investigating some memory corruption issues in an ethernet driver for an embedded system.

I suspect a problem between a bus mastering DMA controller and slow SDRAM. So I want to use a bounce buffer in fast SRAM. To do this I need two things: I must place the SRAM's physical address (from the bus master's perspective) into the DMA controller buffer descriptor, and I must memcpy the data from the bounce buffer into the sk_buff in SDRAM once the DMA controller reports an incoming packet.

What I haven't been able to determine, from reading

is whether skb->data is a physical or virtual address. i.e. should I call

memcpy(skb->data, phys_to_virt(bounce_addr), len);

or

memcpy(phys_to_virt(skb->data), phys_to_virt(bounce_addr), len);

to get the packet into an sk_buff so the rest of the linux networking stack can process it?

EDIT: This is the driver in question. I'd say that it's passing virtual addresses into the DMA controller registers and therefore can't work, but I have a devkit on which this code works. However my SDRAM doesn't have as good timings as the devkit DDR SDRAM, hence I'm thinking of implementing bounce buffers.

1

There are 1 answers

2
nelhage On BEST ANSWER

It's virtual. Basically anything of type foo * in the kernel is going to be a virtual address, and in fact, you'll very, very, rarely deal with physical addresses outside of low-level memory management -- you'll either have virtual addresses, or struct page that you need to kmap to get a virtual address.