Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1152983rwl; Fri, 24 Mar 2023 07:01:57 -0700 (PDT) X-Google-Smtp-Source: AKy350Zk7ckSIZ72LLltXRyI4vYVSZb/8z+iTsl4uvOy0kBEhqS2LRn/5RMSEVvWlXE7Ye81TkSn X-Received: by 2002:a17:906:c20e:b0:920:388c:5c60 with SMTP id d14-20020a170906c20e00b00920388c5c60mr2920812ejz.41.1679666516948; Fri, 24 Mar 2023 07:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679666516; cv=none; d=google.com; s=arc-20160816; b=mOUQozb7w1GCGts5z5Y8n9RdgdPiMbmRCOINGbJQzLIR3OdcsXujT9KFii1rRl9VoQ gCZaBT5qlTPAMfS1ORq2q4NYJYl8fVW/dhbmH1DoEM2xIfhGeNPe6H9y9ztEWkNrdmpv WWFFXrvYn+UTRNx7xgc7loBDkGhHdjCgRqLoz4T9dZc27j+LQUeXdSrVb2EgKbjbw9Bi NQFBHLGA5BiAGFQirRdVK91eKyahOD2PxtQX5GVjLeF+I2tJoEx24cnuNQbHu0nQwelE OhXHM2SANl2Mbiwvd88BZ10HDoO1IXvY0UWvPDJiz0sQm5wbaiEdRVAMSd7V1FbVrtGI UFdQ== 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=ULACr9hwIdunm2lWS57kdMnN4Bb/D0rvhYQEw4GmFbc=; b=ewDGgYjp2KQb4FyC+iFOqpsm/HS38frAfkVwTXMHp5npzzp6kJpmMYmD6i3yMMwu+3 XxeNXGWOHJp5HNDzYLi3dVyobmP49eVVoOhITewPyxPjeNHCzDXBiuZ9en2otF6yPBIk a5jQfkokPi/u6HNF9hwGLo9P2nJM6RMA4OJjO07OR/sdVRrBHIPQZz4/PBYBoEpF1jJE bNH2mtf9SEsi+kpzrEZGQag1BtqsHB7SXugp7qMh7tJCpyIsVVmBunS5Xyk9oKZnbe90 QctujLXOUFlTlEzlbn97BDFZ+J17dMzs4LGXrWfHYlt78pDNIpO1emVyKoI3RigtJzFI RB6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DnlYVuvo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020aa7d542000000b004c49811c587si19179020edr.377.2023.03.24.07.01.32; Fri, 24 Mar 2023 07:01:56 -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=DnlYVuvo; 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 S231596AbjCXOAb (ORCPT + 99 others); Fri, 24 Mar 2023 10:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231961AbjCXOAI (ORCPT ); Fri, 24 Mar 2023 10:00:08 -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 8E7E21B30C for ; Fri, 24 Mar 2023 06:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679666336; 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=ULACr9hwIdunm2lWS57kdMnN4Bb/D0rvhYQEw4GmFbc=; b=DnlYVuvoze8a1BREF7CFLiRqxHyF3OZy1nU+iOPNWdBn7msZNqoY1SnAGwcr+FxZkvU6Uq 1dvOcLCkgiIrrQH1cjbwXWg8ov74NCH5ua/1q8Wu+fQbM1m4HZQELPYIe7FXpXthtjTjxw FZQP6tY3p9U5ANdIcBJHNx8ZMJUs8Mo= 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-437-3JFO45fQOEennVluWcWD3A-1; Fri, 24 Mar 2023 09:58:53 -0400 X-MC-Unique: 3JFO45fQOEennVluWcWD3A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB518855312; Fri, 24 Mar 2023 13:58:52 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE6D02027040; Fri, 24 Mar 2023 13:58:51 +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 09/17] block: ublk_drv: add two helpers to clean up map/unmap request Date: Fri, 24 Mar 2023 21:58:00 +0800 Message-Id: <20230324135808.855245-10-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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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 Add two helpers for checking if map/unmap is needed, since we may have passthrough request which needs map or unmap in future, such as for supporting report zones. Meantime don't mark ublk_copy_user_pages as inline since this function is a bit fat now. Reviewed-by: Ziyang Zhang Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 4fe324da97a0..43c0b1247924 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -488,8 +488,7 @@ static inline unsigned ublk_copy_io_pages(struct ublk_io_iter *data, return done; } -static inline int ublk_copy_user_pages(struct ublk_map_data *data, - bool to_vm) +static int ublk_copy_user_pages(struct ublk_map_data *data, bool to_vm) { const unsigned int gup_flags = to_vm ? FOLL_WRITE : 0; const unsigned long start_vm = data->io->addr; @@ -525,6 +524,16 @@ static inline int ublk_copy_user_pages(struct ublk_map_data *data, return done; } +static inline bool ublk_need_map_req(const struct request *req) +{ + return ublk_rq_has_data(req) && req_op(req) == REQ_OP_WRITE; +} + +static inline bool ublk_need_unmap_req(const struct request *req) +{ + return ublk_rq_has_data(req) && req_op(req) == REQ_OP_READ; +} + static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, struct ublk_io *io) { @@ -535,7 +544,7 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, * context and the big benefit is that pinning pages in current * context is pretty fast, see ublk_pin_user_pages */ - if (ublk_rq_has_data(req) && req_op(req) == REQ_OP_WRITE) { + if (ublk_need_map_req(req)) { struct ublk_map_data data = { .ubq = ubq, .rq = req, @@ -556,7 +565,7 @@ static int ublk_unmap_io(const struct ublk_queue *ubq, { const unsigned int rq_bytes = blk_rq_bytes(req); - if (req_op(req) == REQ_OP_READ && ublk_rq_has_data(req)) { + if (ublk_need_unmap_req(req)) { struct ublk_map_data data = { .ubq = ubq, .rq = req, @@ -770,7 +779,7 @@ static inline void __ublk_rq_task_work(struct request *req) return; } - if (ublk_need_get_data(ubq) && (req_op(req) == REQ_OP_WRITE)) { + if (ublk_need_get_data(ubq) && ublk_need_map_req(req)) { /* * We have not handled UBLK_IO_NEED_GET_DATA command yet, * so immepdately pass UBLK_IO_RES_NEED_GET_DATA to ublksrv -- 2.39.2