Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp217437lqc; Thu, 29 Feb 2024 15:31:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU5ym1X+xvv5NmYpTuj4fwcbc2MMr7f/5ZzP6x3SQf4E/FzH6rWU9XUVdDGM90rKHmBzHbz4yrsE6lJBVdVD5Ic5bdNWc8MmkPSRGInZg== X-Google-Smtp-Source: AGHT+IH7/EnOp6qoVYRc/VMTzRQHGb+evW3uSXQ1Xn5aD12tdG0+GAKMdVuXCKwXW/HvgaZm0fX1 X-Received: by 2002:a05:6a20:6c87:b0:1a1:18e9:9258 with SMTP id em7-20020a056a206c8700b001a118e99258mr3693655pzb.25.1709249480235; Thu, 29 Feb 2024 15:31:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709249480; cv=pass; d=google.com; s=arc-20160816; b=q7WB+bKL+K7EDO9Q1CpPTrN7dsSH/yvnBrKdKswRrCQgvN1b1xqyc+87UjEmeL3qZ8 VGyjUWg5C4M52Xmfsm0RLL8zcDQFBJEMdWMbGrJPMQ7tzql5dhmLBx+eZbb8eSjjhERj Gw9UjlZWmKyfE/OxKE7zrEJIuZTvyPIdEtcYHSJ9FzUPnveod+oucj6Px0pBSIYYLWUO ok967Ah7QqwR+Mb+fi559IzrJYpFxqNVkQIsEzTWRQeAIv66n98f8TdPda/u6/ArI1/w D7LuStuqU9sE5SQFoBaqXHmbpCssRUKo9phHJzPcITthgS3wm7C/L3OE6wCB6Lf9tuGg KYDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Bb0wm2nkTd/whNJaK5PnfQ4qYt8CNWiFcGX/Paukpmw=; fh=TMuQFgNfK2iovzZ0HJiSPvZKWM9A++g7+kuV9nmdavs=; b=iCZn3awxpYWt/h56n5p9GcPHnOlRdQb1XWDB8kfIOjcLv7k+tPvTt4ZDnETZMPmG8J keOM4vezjA8B0mz+xzZwpOK45xdJQMQ9bNN6RlcX5uWAyOzk5NsA6KxIa0yZzVklTNiR 21QyVumvhm3Zn2xbcAY2vaCeytEheswOl7WDBdAdVT+tU5LLoEZ3Z4MLwvrzJ2Um5fzs +AECShuAeZ2prFIDWZgnUNJMoKFVEobLMfE0L6yq/fCxJImtp7ooxxyv/Emj247VDjqN tRyXKdnXe5tp5EqtOfAazCf1EyPKj1lPtvsVPJY62apOm+QJ5HXD/yy/1Q5F8aM7e+yB eu+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kZk0KDwg; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-87389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87389-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y64-20020a638a43000000b005dc42fd8c40si2252902pgd.404.2024.02.29.15.31.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:31:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kZk0KDwg; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-87389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87389-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F91628714A for ; Thu, 29 Feb 2024 19:54:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C234513F45E; Thu, 29 Feb 2024 19:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="kZk0KDwg" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6306D13442F; Thu, 29 Feb 2024 19:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709236419; cv=none; b=V6S+Wx0de1LEKgrGTpWMteX/HP70LWPNJQHT7hvPS0JZR3JCwzbYDOT38TwgyBraKkA02KA4YSrhqIsTBB80A6V2Wil28An3FeWyHe6FleUaxXETQ+jr1U/3JOns5OV1QUDt+eJNifQUZNTTqUXS4Q9TV43PUsCRzs9cLdLtgDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709236419; c=relaxed/simple; bh=R1BZ2B3YZgTUGmT4mMT7KfnkAaZyyAG23JCeCS4OagM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HgFcxL5qZsP7WcCYtswefl4Y3HRrSHjB9yrssorWoPJ8gwB4a1gJKctVBxGPPRTq0IM2BqNc+uuAoESo+SkaeKgO5MrZGcYunlLAdFN6XDTsbtdXJHxWeRuu+HCO2UzeHHQIkWf2f+QgwokGaczs3n9B+G/K2sw/4i6R3/zZjAM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=kZk0KDwg; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Bb0wm2nkTd/whNJaK5PnfQ4qYt8CNWiFcGX/Paukpmw=; b=kZk0KDwgDkN4bmFPAagPUbZC2G sBTzbBpYG7E0r2P/i9p0uGtviBLPYrIcMiftyKU78jeLhFaPGFyMv8zxJrE+Z6YzMT4kj04Un7Zgj h7ITshosnFYQ1n/W8eV2VYO0pVID6ghAUizomEF2pT2sxACIvx+oTbzoIwnaOZgslvwgIIJ4x6pCP IJRnYitWHvGJEx/rWTVdtMWgiKwfrIwksn87VbFzuq/fCjeuGcjImN5eyrceaBjmObYg/u20wuSAL LfbYtxmtm58zHi3o/k6B3DRdOurGOSgw4FimgiB/Z0kum0N5jbn0aFyYxXFZ9VMK+Kwzl42ZusQYy g9Ks4m5A==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfmTC-00000008t28-06bC; Thu, 29 Feb 2024 19:53:30 +0000 Date: Thu, 29 Feb 2024 19:53:29 +0000 From: Matthew Wilcox To: Tony Battersby Cc: Jens Axboe , Andrew Morton , "Kirill A . Shutemov" , Hugh Dickins , Hannes Reinecke , Keith Busch , linux-mm , linux-block@vger.kernel.org, linux-fsdevel , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() Message-ID: References: <86e592a9-98d4-4cff-a646-0c0084328356@cybernetics.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86e592a9-98d4-4cff-a646-0c0084328356@cybernetics.com> On Thu, Feb 29, 2024 at 01:08:09PM -0500, Tony Battersby wrote: > Fix an incorrect number of pages being released for buffers that do not > start at the beginning of a page. Oh, I see what I did. Wouldn't a simpler fix be to just set "done" to offset_in_page(fi.offset)? > @@ -1152,7 +1152,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty) > > bio_for_each_folio_all(fi, bio) { > struct page *page; > - size_t done = 0; > + size_t nr_pages; > > if (mark_dirty) { > folio_lock(fi.folio); > @@ -1160,10 +1160,11 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty) > folio_unlock(fi.folio); > } > page = folio_page(fi.folio, fi.offset / PAGE_SIZE); > + nr_pages = (fi.offset + fi.length - 1) / PAGE_SIZE - > + fi.offset / PAGE_SIZE + 1; > do { > bio_release_page(bio, page++); > - done += PAGE_SIZE; > - } while (done < fi.length); > + } while (--nr_pages != 0); > } > } > EXPORT_SYMBOL_GPL(__bio_release_pages); The long-term path here, I think, is to replace this bio_release_page() with a bio_release_folio(folio, offset, length) which calls into a new unpin_user_folio(folio, nr) which calls gup_put_folio().