Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp67624lqc; Thu, 29 Feb 2024 10:27:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWbAVHw3VlXzvYZ3RXu5FAzCAWb8bN4YK/mtG+Zs8VVwGbemhey9I5M+UlLGg0/8q3EKa/OEsZhTk6Plq24blMNCVCml9DAAMUtwZDprw== X-Google-Smtp-Source: AGHT+IFVMApQppUULl5KoGbFiNlcFb//+u/tSpUGOsDmEJ2si3vyzJdHhfVQjdrCkzYmmu4uAxIy X-Received: by 2002:aa7:c907:0:b0:566:4e7a:fa2b with SMTP id b7-20020aa7c907000000b005664e7afa2bmr2134826edt.36.1709231253684; Thu, 29 Feb 2024 10:27:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709231253; cv=pass; d=google.com; s=arc-20160816; b=FlDY8HusK9V/gL/476i4CPg8NaH+a69H018x2DebYXE5TgysHfd2pyr8tnSAZPW00Q sIJ+Xx0wmplW18TF/Mc3wNW3N/5BQq5ihetIQ7g7nGJduR/zwx8X7eANeg0ngfyZBrbu /sg+FswSwxJz6Xjc/18F5ITxSnGMocKS1luvilBHVeVqNsk8Z77nZKvH2RsGFOOnoAeZ hWe2wGnbzpMDERKgqsGCkBmr6Nxzq1w2v14rhcx6/6tloVW1WP8yEFOdq7XNGZ7tJT4q 3hvurZ75YQMnqhRi2pYC16e5vATzIvjweIbGAA4201xdHzDJfQb6LLe2uY7EQn0mKw15 WLVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=GyTYh7rZxyuaZxAK4E6INt0hy/oXnF2VsS983Qgm9WI=; fh=5STaPbxd6GML62J35fQhwq5d97XGwYWMpMCDvWWUthg=; b=zbxiQV0lVzaeX88c7ETLlhTEJ5XHnxLlW4T/8VjKsgwKhEoOxYQaWBbwiaDiE2/aE2 V+rlNWZPpb/2Th1RunHpd6ghPtLKih6OGoLz8OLf1beXwZDlW6J3tdW2SNVVDS5te8gj 6W6h/mjXVBHFCZIBSK+fvbJLWaFuxcojDOmCljrAMMkPZmT8mz/qeYKrt/vNWUtBfIqB KdISOxeBlN9euKAKscvHaMcXMd1DLjmllVw5M3g4nR8gMqiLMIKErERVVvaxYWB86WqW 1+7S3tE9Bm4MD4wf5enRl+azsvE5kN9QLfoKJtHi/lH03PZ3KkbvTCcNB7d8BA7X6NeA AsKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=EHNEAJpH; arc=pass (i=1 spf=pass spfdomain=cybernetics.com dkim=pass dkdomain=cybernetics.com dmarc=pass fromdomain=cybernetics.com); spf=pass (google.com: domain of linux-kernel+bounces-87286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m28-20020a50d7dc000000b005649f9ea4c2si767328edj.507.2024.02.29.10.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 10:27:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=EHNEAJpH; arc=pass (i=1 spf=pass spfdomain=cybernetics.com dkim=pass dkdomain=cybernetics.com dmarc=pass fromdomain=cybernetics.com); spf=pass (google.com: domain of linux-kernel+bounces-87286-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6905B1F212FC for ; Thu, 29 Feb 2024 18:27:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E215F7D08C; Thu, 29 Feb 2024 18:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cybernetics.com header.i=@cybernetics.com header.b="EHNEAJpH" Received: from mail.cybernetics.com (mail.cybernetics.com [72.215.153.18]) (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 F10137A157 for ; Thu, 29 Feb 2024 18:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=72.215.153.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709231239; cv=none; b=McJRNt2y8x4V5tDNLKNizqRDcHmzvMjQlndSGIXgXwj6ZR7gGPMckWmOqZ2rVSgNiW0/Le2WN4ts/XthIS0LmllmcQkPrX5FkEWhfLnUo+HXNibckz0+TIYx2TgtY4UjksYRCK3vfI+PLioeYnwS7KyrNOl2zHlBcMtfnDLiSr8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709231239; c=relaxed/simple; bh=0ujY1W7EPTMDMv8Qjd/XFEAXcyl4EZ0O06CzvoVFYCc=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=FiR/9aIhjQFwCcGsuFzwQkxGWNm59SZ7msxGDbtjYsdvf6iXcn7dI608YwFTkHmC3eFzxKf1ltpqELWk64bJenyUAMC8ebgvaQZIbqdVc0eUudNvCw5K3lSeHMBsZHrYvkL9ZSkEtYrFDxGsimDLVUkDXzfopEpYw59bi1dOZ7A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cybernetics.com; spf=pass smtp.mailfrom=cybernetics.com; dkim=pass (1024-bit key) header.d=cybernetics.com header.i=@cybernetics.com header.b=EHNEAJpH; arc=none smtp.client-ip=72.215.153.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cybernetics.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cybernetics.com X-ASG-Debug-ID: 1709230070-1cf4391a1c4fcf0003-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id skGYSPFiFfPsVh4j for ; Thu, 29 Feb 2024 13:08:13 -0500 (EST) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-Barracuda-RBL-Trusted-Forwarder: 10.10.4.126 X-ASG-Whitelist: Client DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cybernetics.com; s=mail; bh=GyTYh7rZxyuaZxAK4E6INt0hy/oXnF2VsS983Qgm9WI=; h=Content-Transfer-Encoding:Content-Type:Subject:From:Cc:To:Content-Language: MIME-Version:Date:Message-ID; b=EHNEAJpH9NO6DGJeblalbgxMQVo9ZjLHP5lNuDo0CY5z+ 3qRP6j8BSOQ1clNEfFa8V1xd1wyAxTkw7gIdJuf4r5DcXWB08/uQ/7qeVuc70mLwffJnHoNaXO4ro 5M6b7FYErqw/nqlHndEyRgwppLhJ5Aw8n43zpvTRnqCKTu0iA= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 13108803; Thu, 29 Feb 2024 13:08:10 -0500 Message-ID: <86e592a9-98d4-4cff-a646-0c0084328356@cybernetics.com> X-Barracuda-RBL-Trusted-Forwarder: 10.157.2.224 Date: Thu, 29 Feb 2024 13:08:09 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Jens Axboe Cc: "Matthew Wilcox (Oracle)" , 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" From: Tony Battersby Subject: [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() Content-Type: text/plain; charset=UTF-8 X-ASG-Orig-Subj: [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() Content-Transfer-Encoding: 7bit X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1709230093 X-Barracuda-URL: https://10.10.4.122:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-Scan-Msg-Size: 1347 Fix an incorrect number of pages being released for buffers that do not start at the beginning of a page. Fixes: 1b151e2435fc ("block: Remove special-casing of compound pages") Cc: stable@vger.kernel.org Signed-off-by: Tony Battersby --- Tested with 6.1.79. The 6.1 backport can just use folio_put_refs(fi.folio, nr_pages) instead of do {...} while. block/bio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/bio.c b/block/bio.c index b9642a41f286..b52b56067e79 100644 --- a/block/bio.c +++ b/block/bio.c @@ -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); base-commit: d206a76d7d2726f3b096037f2079ce0bd3ba329b -- 2.25.1