On 04/01/18 12:22 PM, Jason Gunthorpe wrote:
This seems really clunky since we are going to want to do this same
logic all over the place.
I'd be much happier if dma_map_sg can tell the memory is P2P or not
from the scatterlist or dir arguments and not require the callers to
We tried things like this in an earlier iteration which assumed the
SG was homogenous (all P2P or all regular memory). This required serious
ugliness to try and ensure SGs were in fact homogenous. If you don't
assume homogenousness you need change every DMA mapping provider or have
a way to efficiently know if the SGL contains any P2P pages.
Unfortunately, it's hard to do any of this without significant
improvements to the SGL code (like ) but I understand there's
significant push back against such changes at this time.
For instance adding DMA_TO_P2P_DEVICE and DMA_FROM_P2P_DEVICE, or
adding another bit to the page flags in scatterlist.
Creating new direction flags doesn't really solve the problem you point
out. It'd only really work in the rdma_rw_ctx_init() case because that
function already takes the direction argument. It doesn't work in the
similar block device case because the DMA direction isn't passed through
Though, if there's agreement to do something like that I'm not against it.
The signature of pci_p2pmem_map_sg also doesn't look very good,
should mirror the usual dma_map_sg, otherwise it needs more revision
to extend this to do P2P through a root complex.
Generally, the feedback that I get is to not make changes that try to
anticipate the future. It would be easy enough to add those arguments
when the code for going through the RC is made (which I expect will be
very involved anyway).