zfcp: Use DMA streaming API to map I/O
Subsystems (2)
PATCH v12 2/2 zfcp: Use DMA streaming API to map I/O
In the existing zFCP driver, virtual addresses are translated directly into bus (physical) addresses for DMA operations on all I/O buffers passed from the zFCP driver to the device.
Need for DMA API:
In secure execution environment, the host must ensure that device DMA addresses are restricted to non-guest-private, page-sized memory blocks. This prevents I/O failures that can occur when a device attempts to access guest-private memory. Therefore, guest memory pages must be prepared by the hypervisor before they become accessible to an I/O device.
To support this requirement, the host linux kernel must be reliably informed whenever a memory region becomes eligible for device DMA access and when that access must be revoked. This information must be maintained correctly at least at page level granularity.
To satisfy these requirements, all I/O buffers used by the zFCP driver should be mapped through the DMA API.
DMA streaming API usage in zFCP:
Changes in this patch-series converts all I/O buffer mappings in the zFCP driver to use the DMA streaming API. Specifically, dma_map_sgtable() and dma_unmap_sgtable() are used to map and unmap the scatter-gather lists.
All zFCP I/O buffers (QTCB, SRB, CT/ELS and SCSI I/O) are represented using scatter-gather lists. The sg_table structure, which encapsulates the scatterlist together with the original and mapped entry counts, is used to manage DMA mappings efficiently.
For QTCB and status read buffers, which are not currently scatter-gather based, sg_init_one() is used to initialize a single-entry scatterlist. The resulting scatterlist is then associated with an sg-table by initializing its sgl and orig_nents fields before DMA mapping.
For SCSI I/O, the SCSI midlayer already maintains sg_table instances for both normal and protection enabled SCSI commands. These sg tables are mapped using the same DMA mapping functions.
DMA mapping is performed after the associated I/O buffers have been populated or updated. Consequently, no explicit DMA synchronization for device access before passing the DMA address to the adapter. On the receive path, synchronization for CPU access is handled implicitly by the DMA unmap operations.
Reference-ID: SAN2402
---
v11 -> v12
- Modify comments to mention metadata is for SRB as well.
- Fix double unmap for exchange port and config data scenarios.
- Fix correct error value -EIO in mapping failure for QTCB.
--- drivers/s390/scsi/zfcp_aux.c | 16 +++ drivers/s390/scsi/zfcp_def.h | 4 + drivers/s390/scsi/zfcp_ext.h | 10 +- drivers/s390/scsi/zfcp_fsf.c | 260 ++++++++++++++++++++++++++++------ drivers/s390/scsi/zfcp_qdio.c | 37 +++-- drivers/s390/scsi/zfcp_qdio.h | 27 ++-- 6 files changed, 283 insertions(+), 71 deletions(-)
drivers/s390/scsi/zfcp_aux.c +16 -0
@@ -328,6 +328,19 @@ static void zfcp_destroy_adapter_work_queue(struct zfcp_adapter *adapter) } +static int zfcp_set_dma_mask_for_adapter (struct zfcp_adapter *adapter) +{ +int ret; + + ret =dma_set_mask_and_coherent (&adapter->ccw_device->dev, +DMA_BIT_MASK (64 )); +if (ret) +dev_err (&adapter->ccw_device->dev, +"Setting the DMA mask failed for the FCP device.\n" ); + +return ret; +} +/** * zfcp_adapter_enqueue - enqueue a new adapter to the list * @ccw_device: pointer to the struct cc_device
@@ -403,6 +416,9 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)rwlock_init (&adapter->erp_lock);rwlock_init (&adapter->abort_lock); +if (zfcp_set_dma_mask_for_adapter (adapter)) + goto failed; +if (zfcp_erp_thread_setup (adapter)) goto failed;
drivers/s390/scsi/zfcp_def.h +4 -0
@@ -322,6 +322,8 @@ static inline u64 zfcp_scsi_dev_lun(struct scsi_device *sdev)* @pool: reference to memory pool if used for this request * @issued: time when request was send (STCK) * @handler: handler which should be called to process response +* @metadata_sgt: sg_table for metadata of a QTCB or SRB request +* @metadata_sg: scatterlist for metadata of a QTCB or SRB request */ struct zfcp_fsf_req {struct list_head list;
@@ -337,6 +339,8 @@ struct zfcp_fsf_req {mempool_t *pool;unsigned long long issued;void (*handler)(struct zfcp_fsf_req *); +struct sg_table metadata_sgt; +struct scatterlist metadata_sg; }; static inline
drivers/s390/scsi/zfcp_ext.h +8 -2
@@ -148,14 +148,20 @@ enum zfcp_fsf_print_fmt {extern ssize_t zfcp_fsf_scnprint_fc_security (char *buf,size_t size,u32 fc_security,enum zfcp_fsf_print_fmt fmt); +int zfcp_fsf_req_map_sg (struct zfcp_fsf_req *req,struct sg_table *sgt, +enum dma_data_direction dma_dir); +void zfcp_fsf_req_unmap_sg (struct zfcp_fsf_req *req, +struct sg_table *sgt, +enum dma_data_direction dma_dir);/* zfcp_qdio.c */ extern int zfcp_qdio_setup (struct zfcp_adapter *);extern void zfcp_qdio_destroy (struct zfcp_qdio *);extern int zfcp_qdio_sbal_get (struct zfcp_qdio *);extern int zfcp_qdio_send (struct zfcp_qdio *,struct zfcp_qdio_req *); -extern int zfcp_qdio_sbals_from_sg (struct zfcp_qdio *,struct zfcp_qdio_req *, -struct scatterlist *); +int zfcp_qdio_sbals_from_sg (struct zfcp_qdio *qdio,struct sg_table *sgt, +struct zfcp_fsf_req *req, +enum dma_data_direction dma_dir);extern void zfcp_qdio_shost_update (struct zfcp_adapter *const adapter,const struct zfcp_qdio *const qdio);extern int zfcp_qdio_open (struct zfcp_qdio *);
drivers/s390/scsi/zfcp_fsf.c +216 -44
510 lines not on this page · raw message
drivers/s390/scsi/zfcp_qdio.c +23 -14
@@ -233,31 +233,40 @@ zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req) }/** -* zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list +* zfcp_qdio_sbals_from_sg - DMA map scatter-gather list and fill SBALs from it * @qdio: pointer to struct zfcp_qdio -* @q_req: pointer to struct zfcp_qdio_req -* @sg: scatter-gather list -* Returns: zero or -EINVAL on error +* @sgt: pointer to scattergather list table +* @req: pointer to zfcp_fsf_req +* @dma_dir: DMA direction of I/O +* Returns: zero on success, -EINVAL or -EIO otherwise */ -int zfcp_qdio_sbals_from_sg (struct zfcp_qdio *qdio,struct zfcp_qdio_req *q_req, -struct scatterlist *sg) +int zfcp_qdio_sbals_from_sg (struct zfcp_qdio *qdio,struct sg_table *sgt, +struct zfcp_fsf_req *req, +enum dma_data_direction dma_dir) {struct qdio_buffer_element *sbale; +int i; +struct scatterlist *sg_element; + +if (zfcp_fsf_req_map_sg (req, sgt, dma_dir)) +return -EIO ;/* set storage-block type for this request */ - sbale =zfcp_qdio_sbale_req (qdio, q_req); - sbale->sflags |= q_req->sbtype; + sbale =zfcp_qdio_sbale_req (qdio, &req->qdio_req); + sbale->sflags |= req->qdio_req.sbtype; -for (; sg; sg =sg_next (sg)) { - sbale =zfcp_qdio_sbale_next (qdio, q_req); +for_each_sgtable_dma_sg (sgt, sg_element, i) { + sbale =zfcp_qdio_sbale_next (qdio, &req->qdio_req);if (!sbale) {atomic_inc (&qdio->req_q_full); -zfcp_qdio_zero_sbals (qdio->req_q, q_req->sbal_first, - q_req->sbal_number); +zfcp_qdio_zero_sbals (qdio->req_q, + req->qdio_req.sbal_first, + req->qdio_req.sbal_number); +zfcp_fsf_req_unmap_sg (req, sgt, dma_dir);return -EINVAL ; } - sbale->addr =u64_to_dma64 (sg_phys (sg)); - sbale->length = sg->length; + sbale->addr =u64_to_dma64 (sg_dma_address (sg_element)); + sbale->length =sg_dma_len (sg_element); }return 0 ; }
drivers/s390/scsi/zfcp_qdio.h +16 -11
@@ -11,6 +11,7 @@#define ZFCP_QDIO_H #include <linux/interrupt.h> +#include <linux/types.h> #include <asm/qdio.h> #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
@@ -106,16 +107,19 @@ zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)* @q_req: the qdio request to start * @req_id: The request id * @sbtype: type flags to set for all sbals -* @data: First data block -* @len: Length of first data block +* @has_qtcb: FSF request has a QTCB +* @qtcb_len: Length of first data block QTCB, if any +* @qtcb_dma_handle: DMA handle of the QTCB, if any * * This is the start of putting the request into the queue, the last * step is passing the request to zfcp_qdio_send. The request queue * lock must be held during the whole process from init to send. */ static inline -void zfcp_qdio_req_init (struct zfcp_qdio *qdio,struct zfcp_qdio_req *q_req, -u64 req_id,u8 sbtype,void *data,u32 len) +void zfcp_qdio_req_init (struct zfcp_qdio *qdio, +struct zfcp_qdio_req *q_req,u64 req_id, +u8 sbtype,bool has_qtcb,u32 qtcb_len, +dma_addr_t qtcb_dma_handle) {struct qdio_buffer_element *sbale; int count = min(atomic_read(&qdio->req_q_free),
@@ -133,33 +137,34 @@ void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req, sbale->eflags =0 ; sbale->sflags =SBAL_SFLAGS0_COMMAND | sbtype; -if (unlikely (!data)) +if (unlikely (!has_qtcb))return ; sbale++; - sbale->addr =virt_to_dma64 (data); - sbale->length = len; + sbale->addr =u64_to_dma64 (qtcb_dma_handle); + sbale->length = qtcb_len; }/** * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests * @qdio: pointer to struct zfcp_qdio * @q_req: pointer to struct zfcp_queue_req -* @data: pointer to data +* @dma_handle: dma address * @len: length of data * * This is only required for single sbal requests, calling it when * wrapping around to the next sbal is a bug. */ static inline -void zfcp_qdio_fill_next (struct zfcp_qdio *qdio,struct zfcp_qdio_req *q_req, -void *data,u32 len) +void zfcp_qdio_fill_next (struct zfcp_qdio *qdio, +struct zfcp_qdio_req *q_req, +dma_addr_t dma_handle,u32 len) {struct qdio_buffer_element *sbale;BUG_ON (q_req->sbale_curr == qdio->max_sbale_per_sbal -1 ); q_req->sbale_curr++; sbale =zfcp_qdio_sbale_curr (qdio, q_req); - sbale->addr =virt_to_dma64 (data); + sbale->addr =u64_to_dma64 (dma_handle); sbale->length = len; }
Signature · 1 line
2.53.0