From patchwork Fri May 19 07:40:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 96255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1067035vqo; Fri, 19 May 2023 01:13:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/WnOSe4palRHDrfH/HWbsdLyxmYIFjqu+Ew5toHaKMJPyNq3Bp8m6tDkmmf1vOaY0OeMC X-Received: by 2002:a17:90b:3847:b0:250:ca46:dfe1 with SMTP id nl7-20020a17090b384700b00250ca46dfe1mr1108949pjb.48.1684483990670; Fri, 19 May 2023 01:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684483990; cv=none; d=google.com; s=arc-20160816; b=oGNAEsaGdLn+Z5pYgeGIG+R3YnahvMMB4Msa9BQtf5UxcXENSyO5T54qAn7lC9Rcie K9QA0TkrfjQYHwyNG9hyKDC1HwVieb4eiLoUAC0KyTDI7iHgLGlsDM6K9lL6vCie79fO 1vPyfvtmuQ/pjmzdsp/3HkswMZipOEJcqSyTqTDARP9kedkNhWkmhabWp9BJZxAx/wBM Fe9+dPeHp4DFr3pbQe4/amhXWreH+wB9K1iphBc7X0DQvTRV8FmsELSCdY9N0g6zhhk/ /ka7697Gjxndq3Z8N6I0jbh1aA73t7ECZyBWDpwunEl81y5/QAorbJnd/FnZzTtMrnHy o+zg== 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=A3vXzOuVdMvH89sf0By+tn1OlRy/3loCu0bvbEyBwbk75Egrl5vTwmv883eRR+eR+9 RiIUOm3yHMkpwb7Ds1otbvvBC31/+wbSYbW8aqMP5H20diXVgZXK13FAjib1HPtRAtZg sGj4jh82oBS8vcoDjet6fGS4wyq6QkTj1QV3a+KwE/OJyO/Lk1XXuLez4mfmhQ8tU2o1 Bz9UKkam9fQ2tmIpCtLqPIFMuYayEmfCHK5kmdzh5jam7C9TfusbKSdri86LF+H3lLJM gwyhO2AygrY6KnM/94JQWnAimsjPByqXTJsAxBuX7K9EazVoWpVH4vAIH8cusGTf1CcW MsYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jUVUx3KT; 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 e131-20020a636989000000b00528519a4371si3037577pgc.516.2023.05.19.01.12.55; Fri, 19 May 2023 01:13:10 -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=jUVUx3KT; 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 S231371AbjESHrX (ORCPT + 99 others); Fri, 19 May 2023 03:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231538AbjESHqr (ORCPT ); Fri, 19 May 2023 03:46:47 -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 BC17E198A for ; Fri, 19 May 2023 00:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482171; 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=0UdxcT7QYPFwRvPO4h85pE794/0OGizygn6UovNdu60=; b=jUVUx3KTwhweTrBjGAPexHrmA0/P6O4LZnJj11WXcf/V6hzdOfJ+Zwh4jwsgczxBs1Xgdu p1I0SkvqlYqClWwlOOG05s8t/8n9z5rtCQkvIsnh1Z90IbRAbGFNIoCFdwoqRoWkD8i6dw siMFv21+6e0BM/UD3NRBWhmQYq4UShQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-iVklZYPOP7qgZhTLOyp__w-1; Fri, 19 May 2023 03:42:47 -0400 X-MC-Unique: iVklZYPOP7qgZhTLOyp__w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C287E38035AD; Fri, 19 May 2023 07:42:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id A83937C2A; Fri, 19 May 2023 07:42:44 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v20 32/32] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Fri, 19 May 2023 08:40:47 +0100 Message-Id: <20230519074047.1739879-33-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1766309485073331729?= X-GMAIL-MSGID: =?utf-8?q?1766309485073331729?= This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O could otherwise end up being visible to/affected by the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/blk-map.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index 33d9f6e89ba6..3551c3ff17cf 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -281,22 +281,21 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); - bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { - struct page **pages, *stack_pages[UIO_FASTIOV]; + struct page *stack_pages[UIO_FASTIOV]; + struct page **pages = stack_pages; ssize_t bytes; size_t offs; int npages; - if (nr_vecs <= ARRAY_SIZE(stack_pages)) { - pages = stack_pages; - bytes = iov_iter_get_pages(iter, pages, LONG_MAX, - nr_vecs, &offs, extraction_flags); - } else { - bytes = iov_iter_get_pages_alloc(iter, &pages, - LONG_MAX, &offs, extraction_flags); - } + if (nr_vecs > ARRAY_SIZE(stack_pages)) + pages = NULL; + + bytes = iov_iter_extract_pages(iter, &pages, LONG_MAX, + nr_vecs, extraction_flags, &offs); if (unlikely(bytes <= 0)) { ret = bytes ? bytes : -EFAULT; goto out_unmap; @@ -318,7 +317,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (!bio_add_hw_page(rq->q, bio, page, n, offs, max_sectors, &same_page)) { if (same_page) - put_page(page); + bio_release_page(bio, page); break; } @@ -330,7 +329,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, * release the pages we didn't map into the bio, if any */ while (j < npages) - put_page(pages[j++]); + bio_release_page(bio, pages[j++]); if (pages != stack_pages) kvfree(pages); /* couldn't stuff something into bio? */