[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <65b0070e-3386-4725-8e8a-15b0409b8368@oracle.com>
Date: Fri, 18 Apr 2025 23:33:09 +0530
From: ALOK TIWARI <alok.a.tiwari@...cle.com>
To: Leon Romanovsky <leon@...nel.org>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Jens Axboe <axboe@...nel.dk>, Christoph Hellwig <hch@....de>,
Keith Busch <kbusch@...nel.org>
Cc: Jake Edge <jake@....net>, Jonathan Corbet <corbet@....net>,
Jason Gunthorpe <jgg@...pe.ca>, Zhu Yanjun <zyjzyj2000@...il.com>,
Robin Murphy <robin.murphy@....com>, Joerg Roedel <joro@...tes.org>,
Will Deacon <will@...nel.org>, Sagi Grimberg <sagi@...mberg.me>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Logan Gunthorpe <logang@...tatee.com>,
Yishai Hadas <yishaih@...dia.com>,
Shameer Kolothum <shameerali.kolothum.thodi@...wei.com>,
Kevin Tian <kevin.tian@...el.com>,
Alex Williamson <alex.williamson@...hat.com>,
Jérôme Glisse <jglisse@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-block@...r.kernel.org,
linux-rdma@...r.kernel.org, iommu@...ts.linux.dev,
linux-nvme@...ts.infradead.org, linux-pci@...r.kernel.org,
kvm@...r.kernel.org, linux-mm@...ck.org,
Niklas Schnelle <schnelle@...ux.ibm.com>,
Chuck Lever <chuck.lever@...cle.com>,
Luis Chamberlain <mcgrof@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Dan Williams
<dan.j.williams@...el.com>,
Kanchan Joshi <joshi.k@...sung.com>,
Chaitanya Kulkarni <kch@...dia.com>,
Leon Romanovsky <leonro@...dia.com>
Subject: Re: [PATCH v8 20/24] blk-mq: add scatterlist-less DMA mapping helpers
> + * Start DMA mapping @req to @dma_dev. @state and @iter are provided by the
> + * caller and don't need to be initialized. @state needs to be stored for use
> + * at unmap time, @iter is only needed at map time.
> + *
> + * Returns %false if there is no segment to map, including due to an error, or
> + * %true it it did map a segment.
typo - it it -> if it
> + *
> + * If a segment was mapped, the DMA address for it is returned in @iter.addr and
> + * the length in @iter.len. If no segment was mapped the status code is
> + * returned in @iter.status.
> + *
> + * The caller can call blk_rq_dma_map_coalesce() to check if further segments
> + * need to be mapped after this, or go straight to blk_rq_dma_map_iter_next()
> + * to try to map the following segments.
> + */
> +bool blk_rq_dma_map_iter_start(struct request *req, struct device *dma_dev,
> + struct dma_iova_state *state, struct blk_dma_iter *iter)
> +{
> + unsigned int total_len = blk_rq_payload_bytes(req);
> + struct phys_vec vec;
> +
> + iter->iter.bio = req->bio;
> + iter->iter.iter = req->bio->bi_iter;
> + memset(&iter->p2pdma, 0, sizeof(iter->p2pdma));
> + iter->status = BLK_STS_OK;
> +
> + /*
> + * Grab the first segment ASAP because we'll need it to check for P2P
> + * transfers.
> + */
> + if (!blk_map_iter_next(req, &iter->iter, &vec))
> + return false;
> +
> + if (IS_ENABLED(CONFIG_PCI_P2PDMA) && (req->cmd_flags & REQ_P2PDMA)) {
> + switch (pci_p2pdma_state(&iter->p2pdma, dma_dev,
> + blk_phys_to_page(vec.paddr))) {
> + case PCI_P2PDMA_MAP_BUS_ADDR:
> + return blk_dma_map_bus(req, dma_dev, iter, &vec);
> + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
> + /*
> + * P2P transfers through the host bridge are treated the
> + * same as non-P2P transfers below and during unmap.
> + */
> + req->cmd_flags &= ~REQ_P2PDMA;
> + break;
> + default:
> + iter->status = BLK_STS_INVAL;
> + return false;
> + }
> + }
> +
> + if (blk_can_dma_map_iova(req, dma_dev) &&
> + dma_iova_try_alloc(dma_dev, state, vec.paddr, total_len))
> + return blk_rq_dma_map_iova(req, dma_dev, state, iter, &vec);
> + return blk_dma_map_direct(req, dma_dev, iter, &vec);
> +}
> +EXPORT_SYMBOL_GPL(blk_rq_dma_map_iter_start);
> +
> +/**
> + * blk_rq_dma_map_iter_next - map the next DMA segment for a request
> + * @req: request to map
> + * @dma_dev: device to map to
> + * @state: DMA IOVA state
> + * @iter: block layer DMA iterator
> + *
> + * Iterate to the next mapping after a previous call to
> + * blk_rq_dma_map_iter_start(). See there for a detailed description of the
> + * arguments.
> + *
> + * Returns %false if there is no segment to map, including due to an error, or
> + * %true it it did map a segment.
typo - it it -> if it
> + *
> + * If a segment was mapped, the DMA address for it is returned in @iter.addr and
> + * the length in @iter.len. If no segment was mapped the status code is
> + * returned in @iter.status.
> + */
> +bool blk_rq_dma_map_iter_next(struct request *req, struct device *dma_dev,
> + struct dma_iova_state *state, struct blk_dma_iter *iter)
> +{
> + struct phys_vec vec;
> +
> + if (!blk_map_iter_next(req, &iter->iter, &vec))
> + return false;
> +
> + if (iter->p2pdma.map == PCI_P2PDMA_MAP_BUS_ADDR)
> + return blk_dma_map_bus(req, dma_dev, iter, &vec);
> + return blk_dma_map_direct(req, dma_dev, iter, &vec);
> +}
> +EXPORT_SYMBOL_GPL(blk_rq_dma_map_iter_next);
> +
> static inline struct scatterlist *blk_next_sg(struct scatterlist **sg,
> struct scatterlist *sglist)
> {
> diff --git a/include/linux/blk-mq-dma.h b/include/linux/blk-mq-dma.h
> new file mode 100644
> index 000000000000..588dc3c1ad1f
> --- /dev/null
> +++ b/include/linux/blk-mq-dma.h
> @@ -0,0 +1,62 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef BLK_MQ_DMA_H
> +#define BLK_MQ_DMA_H
> +
> +#include <linux/blk-mq.h>
> +#include <linux/pci-p2pdma.h>
> +
> +struct blk_dma_iter {
> + /* Output address range for this iteration */
> + dma_addr_t addr;
> + u32 len;
> +
> + /* Status code. Only valid when blk_rq_dma_map_iter_* returned false */
> + blk_status_t status;
> +
> + /* Internal to blk_rq_dma_map_iter_* */
> + struct req_iterator iter;
> + struct pci_p2pdma_map_state p2pdma;
> +};
> +
> +bool blk_rq_dma_map_iter_start(struct request *req, struct device *dma_dev,
> + struct dma_iova_state *state, struct blk_dma_iter *iter);
> +bool blk_rq_dma_map_iter_next(struct request *req, struct device *dma_dev,
> + struct dma_iova_state *state, struct blk_dma_iter *iter);
> +
> +/**
> + * blk_rq_dma_map_coalesce - were all segments coalesced?
> + * @state: DMA state to check
> + *
> + * Returns true if blk_rq_dma_map_iter_start coalesced all segments into a
> + * single DMA range.
> + */
> +static inline bool blk_rq_dma_map_coalesce(struct dma_iova_state *state)
> +{
> + return dma_use_iova(state);
> +}
> +
> +/**
> + * blk_rq_dma_map_coalesce - try to DMA unmap a request
> + * @req: request to unmap
> + * @dma_dev: device to unmap from
> + * @state: DMA IOVA state
> + * @mapped_len: number of bytes to unmap
> + *
> + * Returns %false if the callers needs to manually unmap every DMA segment
typo needs -> need
> + * mapped using @iter or %true if no work is left to be done.
> + */
Thanks,
Alok
Powered by blists - more mailing lists