Skip to contentSkip to conversation

offest calculation from the dma_address

DISCUSSION alexnln 2 participants 2 messages Apr 14, 2017 NVMe

lore
Share & tools
lore

alexnln

author
#0 lore raw

Hello,

In pci.c, in nvme_setup_prps() offset is calculated from the dma address:
int offset = dma_addr & (page_size - 1);

Why not to use sg->offset?

I mean, what if hypothetical dma allocator returns non-page aligned addresses? In such case offset would be wrong.

Thanks,
Alex

#1 lore raw
Quoted 4 lines · alexnln

In pci.c, in nvme_setup_prps() offset is calculated from the dma address:
int offset = dma_addr & (page_size - 1);

Why not to use sg->offset?

PRP lists are constructed from DMA addresses, so the DMA address offset is the one to use. Kernel virtual addresses don't necessarilly have the same page offset as DMA addresses.

Quoted 2 lines

I mean, what if hypothetical dma allocator returns non-page aligned addresses? In such case offset would be wrong.

I don't follow. If the DMA address isn't page aligned, we need to account for that when constructing the PRP.