Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4001447rwd; Tue, 23 May 2023 01:24:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DmOQ9SR5B+epUejrQBNN+29mBn7yVBVn/XrmdisRKNB7TSNuvF1wNOZrPCazhuNpn1eyL X-Received: by 2002:a17:902:748c:b0:1a9:21bc:65f8 with SMTP id h12-20020a170902748c00b001a921bc65f8mr12323631pll.11.1684830247163; Tue, 23 May 2023 01:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684830247; cv=none; d=google.com; s=arc-20160816; b=fgJjd7dFG/JMnZCiq4/vtxJhfOAXVlaTT9ueIFn/GFQVpuS07l4w3Z86V6j4l9TiRI V/And55U6rzS0fLOfqqOrhf7qdtDuwOD5THpPnsULm9tsTZYJrUbOIyT70SHAEKukC2W FYOLMfvR6LzU74lTH/XEg9cDVtC4kbTxDjLnvTKXp6+PA7ncxzZ6F39B75xTAfjgy2D5 Ka5yb/im+vlFVHcbddueHVX8y3ALnAVbyuWpflS/C7VkWE/96XAB41pLENdUB6u+0RV1 /dGFCqYIe65vsI3ICuJ6drFhS1ia9S7xaJ6JPS6ZQ6aNuH6PnWdxQc60sme8LrgyNcNl /sOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=zWw/T7rwHSimbHVkp4+v1OXRQuiFSOj6e4gDbi9lREQ=; b=N9Yk3LReHEG+N+b3fx0H+Q3SOQFr09GPGf4h4MlvCguXkFTOQUDrLWDG7DjkDwtFva rN2GoONCXR8bI6Fft67EjZ4nU98tfDxzWPrI/AZ8TX2IQoKcSVMo+MS173vIOmOE1hfi QMfzk7tM2Sk2ObkJs7PA5cQofAhWLDNTL89FbYM8QMYtvpTGTFWbns8MX3J44o8g8o5O ock0KhGCmgfVYEmVzebGleMMOqNsE+HAVQbqBNBGV1R2Xt0wk57c2FOSG3ltJ+9YHyOe bt80QXJFVpCaAD6fcYEb0geD0pz/jlOdrXFwvpVzAbmOL/h+CxophxVV06cypeuafMdQ ldVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=wtDzdDHF; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=l9fYplhW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a170902f7c300b001ab18790b12si1910950plw.97.2023.05.23.01.23.54; Tue, 23 May 2023 01:24:07 -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=@suse.cz header.s=susede2_rsa header.b=wtDzdDHF; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=l9fYplhW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236147AbjEWISA (ORCPT + 99 others); Tue, 23 May 2023 04:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235772AbjEWIRH (ORCPT ); Tue, 23 May 2023 04:17:07 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27D01171C; Tue, 23 May 2023 01:15:09 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D48F72041D; Tue, 23 May 2023 08:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1684829707; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zWw/T7rwHSimbHVkp4+v1OXRQuiFSOj6e4gDbi9lREQ=; b=wtDzdDHF0Br+Uhki4HbRPGxLQHhofVARenTOezF6rYvQZUaOIr0HVmKsJY1msqQUAdlSDh wMlvrekipOTP82oP0mfkAKzDhsiG+TzIUIdBeFcOu3HnL/5F0rFa4ibSovcUVeX60vOIzh zkI3AjuT45ZFzF82C2oY5lPgfaLnscs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1684829707; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zWw/T7rwHSimbHVkp4+v1OXRQuiFSOj6e4gDbi9lREQ=; b=l9fYplhWdg84Mz1JKrEpNHtgWMMrq1aMVNg3sxRvkeugy/F6jeuMJkgqIUR8ldgSs9qd3O P8Gm9UvhV9FvRuCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BFDD513A10; Tue, 23 May 2023 08:15:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id lj7RLgt2bGTdNAAAMHmgww (envelope-from ); Tue, 23 May 2023 08:15:07 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 49B4AA075D; Tue, 23 May 2023 10:15:07 +0200 (CEST) Date: Tue, 23 May 2023 10:15:07 +0200 From: Jan Kara To: David Howells Cc: Jens Axboe , Al Viro , Christoph Hellwig , 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: Re: [PATCH v21 5/6] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Message-ID: <20230523081507.sjzaau75hhw3oyul@quack3> References: <20230522205744.2825689-1-dhowells@redhat.com> <20230522205744.2825689-6-dhowells@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230522205744.2825689-6-dhowells@redhat.com> X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Mon 22-05-23 21:57:43, David Howells wrote: > 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 affected by/visible to 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 > --- Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > > 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/bio.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/block/bio.c b/block/bio.c > index 17bd01ecde36..798cc4cf3bd2 100644 > --- a/block/bio.c > +++ b/block/bio.c > @@ -1205,7 +1205,7 @@ static int bio_iov_add_page(struct bio *bio, struct page *page, > } > > if (same_page) > - put_page(page); > + bio_release_page(bio, page); > return 0; > } > > @@ -1219,7 +1219,7 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, > queue_max_zone_append_sectors(q), &same_page) != len) > return -EINVAL; > if (same_page) > - put_page(page); > + bio_release_page(bio, page); > return 0; > } > > @@ -1230,10 +1230,10 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, > * @bio: bio to add pages to > * @iter: iov iterator describing the region to be mapped > * > - * Pins pages from *iter and appends them to @bio's bvec array. The > - * pages will have to be released using put_page() when done. > - * For multi-segment *iter, this function only adds pages from the > - * next non-empty segment of the iov iterator. > + * Extracts pages from *iter and appends them to @bio's bvec array. The pages > + * will have to be cleaned up in the way indicated by the BIO_PAGE_PINNED flag. > + * For a multi-segment *iter, this function only adds pages from the next > + * non-empty segment of the iov iterator. > */ > static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > { > @@ -1265,9 +1265,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > * result to ensure the bio's total size is correct. The remainder of > * the iov data will be picked up in the next bio iteration. > */ > - size = iov_iter_get_pages(iter, pages, > - UINT_MAX - bio->bi_iter.bi_size, > - nr_pages, &offset, extraction_flags); > + size = iov_iter_extract_pages(iter, &pages, > + UINT_MAX - bio->bi_iter.bi_size, > + nr_pages, extraction_flags, &offset); > if (unlikely(size <= 0)) > return size ? size : -EFAULT; > > @@ -1300,7 +1300,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > iov_iter_revert(iter, left); > out: > while (i < nr_pages) > - put_page(pages[i++]); > + bio_release_page(bio, pages[i++]); > > return ret; > } > @@ -1335,7 +1335,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > return 0; > } > > - bio_set_flag(bio, BIO_PAGE_REFFED); > + if (iov_iter_extract_will_pin(iter)) > + bio_set_flag(bio, BIO_PAGE_PINNED); > do { > ret = __bio_iov_iter_get_pages(bio, iter); > } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); > -- Jan Kara SUSE Labs, CR