From patchwork Fri Mar 24 13:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 74564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp650932vqo; Fri, 24 Mar 2023 07:05:53 -0700 (PDT) X-Google-Smtp-Source: AKy350a3SrZL/p2lPkRnQRxsSw+jYwLfm1WDGlKMUzoA9DxTVbubbFZqG4ytZwoH1sjm2BOw6Drj X-Received: by 2002:aa7:d8cf:0:b0:4fc:8642:ce56 with SMTP id k15-20020aa7d8cf000000b004fc8642ce56mr2887933eds.25.1679666753068; Fri, 24 Mar 2023 07:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679666753; cv=none; d=google.com; s=arc-20160816; b=zNdkzZTYnEVIKcGkPooCapEmAaf70g9ffmEeeUHs1qllkt5hugjYRWRl+49NmkvLmt 9jymG/r0lHfNqWX0B6LhbY4OEQ/XC9rrkTRKa2c7Yxlqwiv38wh0WfrjcLk5OSQx2gE4 Ax7CE5um+d+KTj0jX+w47f4bZety3b5MCwmCyeLOWYqUhwV/KygMOmY/xdjXimwHYMFy 4qlKJGI2LpwIICWNPAPqfCdtWiOKkB2MOCA2xJHcUKWmplkosyhTL/XLAwxqt3+SYXpq VZ10ry5cdEQFYJ+T7ORdcsgXDkj3xkAoSVTYdRucNEzRQUkRXZfYxnS89m3y/cK5tKhZ fafw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uuQC+m3nWXpEvAHBrpKpd923ngOUWFuBZCOxaTw0mf8=; b=t/YqsdLoM+fDWbsBlNq9lU5jXidCcBzGDdr3yQjMPytoi8Pk4p+F+GC+Lh+X6JwyNs c1LthX3vgSP1L089SI2ELUf9z9CJPLQ2gotzB6u1tVI644DM2aKxRFQBa5y7pESqh4su v0jvonxSptqSEPG9hdOiL/H5T9rzBWH0X3+GBLD1ow+HBBHkcCzROyR4gfgvkzTeq+sA +O5cdcAvzQqrP2xRboYFU8XXmiEySv0A1w1S+sjn/5dvnnXTJzWWTHou2bllUReMv6zy nJRRFJIAGVVIRhFMHdsyXSHpswswQk1NPU/gril6VWXQGM1q4JpCh39qZ0j4W1ckKvzM 5fJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WgsG0oRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020aa7cb58000000b0050029c65a33si12264586edt.305.2023.03.24.07.05.10; Fri, 24 Mar 2023 07:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WgsG0oRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232120AbjCXOBI (ORCPT + 99 others); Fri, 24 Mar 2023 10:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231958AbjCXOA1 (ORCPT ); Fri, 24 Mar 2023 10:00:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CECF51C31D for ; Fri, 24 Mar 2023 06:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679666354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uuQC+m3nWXpEvAHBrpKpd923ngOUWFuBZCOxaTw0mf8=; b=WgsG0oRey4sA3/94UJ8aXmGLTyZVUjoS1ExwvfE568rZA5btH6hYGHmcpL8oVoM41cmOqf w3l5D6gSQknPYp3TbLIDlbF+vwLQTqURtD/r1vUAJmPZ6Xss+8Db0xie9kU1NeOYB2kjrw b792fz2BB2QNnJAWrO+s/B2q0kP3UR8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-OzWGU5o8N2yR7DVTUK2FWw-1; Fri, 24 Mar 2023 09:59:10 -0400 X-MC-Unique: OzWGU5o8N2yR7DVTUK2FWw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49D26185A7AC; Fri, 24 Mar 2023 13:59:10 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 811204042AC9; Fri, 24 Mar 2023 13:59:09 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miklos Szeredi , ZiyangZhang , Xiaoguang Wang , Bernd Schubert , Pavel Begunkov , Stefan Hajnoczi , Ming Lei Subject: [PATCH V4 14/17] block: ublk_drv: support to copy any part of request pages Date: Fri, 24 Mar 2023 21:58:05 +0800 Message-Id: <20230324135808.855245-15-ming.lei@redhat.com> In-Reply-To: <20230324135808.855245-1-ming.lei@redhat.com> References: <20230324135808.855245-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761258245305878128?= X-GMAIL-MSGID: =?utf-8?q?1761258245305878128?= Add 'offset' to 'struct ublk_map_data', so that ublk_copy_user_pages() can be used to copy any sub-buffer(linear mapped) of the request. Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 88d5a657834d..26a14c54da1d 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -511,19 +511,36 @@ static void ublk_copy_io_pages(struct ublk_io_iter *data, } } +static bool ublk_advance_io_iter(const struct request *req, + struct ublk_io_iter *iter, unsigned int offset) +{ + struct bio *bio = req->bio; + + for_each_bio(bio) { + if (bio->bi_iter.bi_size > offset) { + iter->bio = bio; + iter->iter = bio->bi_iter; + bio_advance_iter(iter->bio, &iter->iter, offset); + return true; + } + offset -= bio->bi_iter.bi_size; + } + return false; +} + /* * Copy data between request pages and io_iter, and 'offset' * is the start point of linear offset of request. */ static size_t ublk_copy_user_pages(const struct request *req, - struct iov_iter *uiter, int dir) + unsigned offset, struct iov_iter *uiter, int dir) { - struct ublk_io_iter iter = { - .bio = req->bio, - .iter = req->bio->bi_iter, - }; + struct ublk_io_iter iter; size_t done = 0; + if (!ublk_advance_io_iter(req, &iter, offset)) + return 0; + while (iov_iter_count(uiter) && iter.bio) { unsigned nr_pages; size_t len, off; @@ -576,7 +593,7 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, import_single_range(dir, u64_to_user_ptr(io->addr), rq_bytes, &iov, &iter); - return ublk_copy_user_pages(req, &iter, dir); + return ublk_copy_user_pages(req, 0, &iter, dir); } return rq_bytes; } @@ -596,7 +613,7 @@ static int ublk_unmap_io(const struct ublk_queue *ubq, import_single_range(dir, u64_to_user_ptr(io->addr), io->res, &iov, &iter); - return ublk_copy_user_pages(req, &iter, dir); + return ublk_copy_user_pages(req, 0, &iter, dir); } return rq_bytes; }