[PATCH OLK-6.6] loop: support PCI P2PDMA I/O
hulk inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/10302 -------------------------------- Advertise PCI P2PDMA on the loop queue when the backing block device supports it and the loop device uses direct I/O, so that user O_DIRECT with p2pmem pages is accepted. Only the direct I/O path forwards the request pages unchanged. The buffered path cannot access P2PDMA pages, so requests that cannot take the direct path are rejected with BLK_STS_NOTSUPP. Signed-off-by: Zizhi Wo <wozizhi@huawei.com> --- drivers/block/loop.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 8bda3a5e52c6..db68c6484ce2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -32,10 +32,11 @@ #include <linux/blk-cgroup.h> #include <linux/sched/mm.h> #include <linux/statfs.h> #include <linux/uaccess.h> #include <linux/blk-mq.h> +#include <linux/memremap.h> #include <linux/spinlock.h> #include <uapi/linux/loop.h> /* Possible states of device */ enum { @@ -180,10 +181,28 @@ static bool lo_bdev_can_use_dio(struct loop_device *lo, if (lo->lo_offset & (sb_bsize - 1)) return false; return true; } +static void loop_update_p2pdma(struct loop_device *lo) +{ + struct file *file = lo->lo_backing_file; + struct inode *inode = file->f_mapping->host; + struct block_device *backing_bdev = NULL; + + if (S_ISBLK(inode->i_mode)) + backing_bdev = I_BDEV(inode); + else if (inode->i_sb->s_bdev) + backing_bdev = inode->i_sb->s_bdev; + + if (lo->use_dio && backing_bdev && + blk_queue_pci_p2pdma(bdev_get_queue(backing_bdev))) + blk_queue_flag_set(QUEUE_FLAG_PCI_P2PDMA, lo->lo_queue); + else + blk_queue_flag_clear(QUEUE_FLAG_PCI_P2PDMA, lo->lo_queue); +} + static void __loop_update_dio(struct loop_device *lo, bool dio) { struct file *file = lo->lo_backing_file; struct inode *inode = file->f_mapping->host; struct block_device *backing_bdev = NULL; @@ -213,10 +232,11 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) lo->use_dio = use_dio; if (use_dio) lo->lo_flags |= LO_FLAGS_DIRECT_IO; else lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; + loop_update_p2pdma(lo); if (lo->lo_state == Lo_bound) blk_mq_unfreeze_queue(lo->lo_queue); } /** @@ -602,10 +622,11 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, lo->lo_backing_file = file; lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping); mapping_set_gfp_mask(file->f_mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); loop_update_dio(lo); + loop_update_p2pdma(lo); blk_mq_unfreeze_queue(lo->lo_queue); partscan = lo->lo_flags & LO_FLAGS_PARTSCAN; loop_global_unlock(lo, is_loop); /* @@ -1086,10 +1107,11 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, blk_queue_io_min(lo->lo_queue, bsize); loop_config_discard(lo); loop_update_rotational(lo); loop_update_dio(lo); + loop_update_p2pdma(lo); loop_sysfs_init(lo); size = get_loop_size(lo, file); loop_set_size(lo, size); @@ -1150,10 +1172,11 @@ static void __loop_clr_fd(struct loop_device *lo, bool release) lo->lo_device = NULL; lo->lo_offset = 0; lo->lo_sizelimit = 0; memset(lo->lo_file_name, 0, LO_NAME_SIZE); + blk_queue_flag_clear(QUEUE_FLAG_PCI_P2PDMA, lo->lo_queue); blk_queue_logical_block_size(lo->lo_queue, 512); blk_queue_physical_block_size(lo->lo_queue, 512); blk_queue_io_min(lo->lo_queue, 512); invalidate_disk(lo->lo_disk); loop_sysfs_exit(lo); @@ -1855,10 +1878,21 @@ device_param_cb(hw_queue_depth, &loop_hw_qdepth_param_ops, &hw_queue_depth, 0444 MODULE_PARM_DESC(hw_queue_depth, "Queue depth for each hardware queue. Default: " __stringify(LOOP_DEFAULT_HW_Q_DEPTH)); MODULE_LICENSE("GPL"); MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); +static bool loop_req_has_p2p(struct request *rq) +{ + struct req_iterator iter; + struct bio_vec bv; + + rq_for_each_bvec(bv, rq, iter) + if (is_pci_p2pdma_page(bv.bv_page)) + return true; + return false; +} + static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { struct request *rq = bd->rq; struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq); @@ -1878,10 +1912,14 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, default: cmd->use_aio = lo->use_dio; break; } + if ((req_op(rq) == REQ_OP_READ || req_op(rq) == REQ_OP_WRITE) && + !blk_queue_pci_p2pdma(lo->lo_queue) && loop_req_has_p2p(rq)) + return BLK_STS_NOTSUPP; + /* always use the first bio's css */ cmd->blkcg_css = NULL; cmd->memcg_css = NULL; #ifdef CONFIG_BLK_CGROUP if (rq->bio) { -- 2.52.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/31127 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/7HJ... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/31127 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/7HJ...
participants (2)
-
patchwork bot -
Zizhi Wo