Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp148384lqc; Thu, 29 Feb 2024 12:59:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9idHqWgOeaA0VEgZJjQjjVqdWlggHcepLEKQHtquZx+oxVW+CyBBfPGJdncta/4Ve4FrhHojDXHQYLcY+iVm9ouUGyFmj3LwVbzdPeQ== X-Google-Smtp-Source: AGHT+IHkFAs0qYS9eXp+4FHSrjykpwVsXbWKw9J8f/cvGf0/RCPKWWBkC4DHHosXuTksIp4CNdCc X-Received: by 2002:a05:6a21:3183:b0:1a1:1f7b:9b0f with SMTP id za3-20020a056a21318300b001a11f7b9b0fmr4211497pzb.42.1709240370626; Thu, 29 Feb 2024 12:59:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709240370; cv=pass; d=google.com; s=arc-20160816; b=cz+pfzhIJuKAvs+zC8ubNByjpMH95xf4r9qf51WJ93kVvJnZ14ewnX+uqJRb4DiAg9 Nr1gqNr8YAb/lnUCrh7vR2y1p3KsMPowaVnzbRHCSGN3NCe1JE8qflFy2kYgbrsOUULq j+s19UuRse6xwT/8umfbnhZEo/efeJ/C1S4nWXH4x7U6ueS1HQkkKZahXeM4/GBM0u7b aTas8cGPqcCJL6NK9rESCRyYzK1LrK84fCctYaN3Rll+BnVPa7VExonMFmtF7RYn2ejd iqO0ZxwCYNRLg3pZ5lxtW6dDo5DurHi1dNge9Z3dfHflmjRTy3Nx2OSgegtZfH6OYdB3 1FRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=KGdwz7goRECtYGm5sOnk6GBz6zSl4J5s0wT/cSLJdMw=; fh=kAB13BMjqmMM0xe9dY9mDgrrSkBRpYQ+bXao8Ax9zSk=; b=bjL9VmOg+MqWmnFgNqeHwReS4yRH4MeeUuSzCbQzzar6qYXDhyS84EbPQQ47we12it B+n5pmUc+1TH6++RIyZv09vgKL8F0h/hG1IitUerOVJlkuksUs/wbioPRgGwJ/tSo3UZ rg0JRf9GoykKXaPYY1nK47P876v7rjCq+myxG9DKwmjE6hh71P2kE4ItYMUoCkNsaa5s p6pBZigyJBBr/LSxs2HaYj/52tCtzLeu2yhXitpTVytMwCCPqr0YP4nf/T/MqFyccllH aaGpYi/ukMTYO25SqrS8N2FkroLNOTIWdZLvE6/yTN4Uoalq6J8iAKG0InpOZUCsB1Yy 1bOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=oND8RtnD; 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-87483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 38-20020a630c66000000b005e49408e834si2073745pgm.881.2024.02.29.12.59.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 12:59:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=oND8RtnD; 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-87483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87483-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 21D21B22D1E for ; Thu, 29 Feb 2024 20:52:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A40213E7EF; Thu, 29 Feb 2024 20:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cybernetics.com header.i=@cybernetics.com header.b="oND8RtnD" 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 B37EA13E7D1 for ; Thu, 29 Feb 2024 20:40:36 +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=1709239238; cv=none; b=GtkReUhqtfzMIqKRMzfdC/aqhiuEaTowN7AXWSH5AGCfjRk8JNvQak16FjD4m/9eBCs/DNWsPi1oXqneVG1d1pGTmdSXbTLEN6kUhKPFiOXdE4EjFCxq/zTWIl9nTpinsqcKggVj6m3VND9KSKZp+tDXJAY02MPDLny4rhv+CFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709239238; c=relaxed/simple; bh=d2Jnd4yjkGkEApv48eNzr6PHo1ck9eCm1SggiXIqMu4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HorlnkVJpwB/3SpWOA4WwLKBLVqAYpKiEkzIIZdAM8qUUc/Oiz/x5e3dfEXfqjCI9bDPljtmtbxsI11cxBDD/we9cPbkMLTOG2IdCoT+i6euiHJPXO64wBWk/NRoLSztSNim5OlATp7cVp3UaFdsWkBLrd+A1qPak5HVZ7zw3MU= 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=oND8RtnD; 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: 1709239210-1cf4391a1c513a0002-xx1T2L Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id PjbAbyf3BfhDty5E for ; Thu, 29 Feb 2024 15:40:32 -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=KGdwz7goRECtYGm5sOnk6GBz6zSl4J5s0wT/cSLJdMw=; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To: Content-Language:Subject:MIME-Version:Date:Message-ID; b=oND8RtnDJqAi9sA80RB4 sb4XkMRRCvNMjh6iERzlbrwrBvsjIOrbs14Fav2aVqBlrnTByQSS+hxqeGim5/aVdLcGaeyzzFjAt NXzreOxVb4kMcqOJ2IsQTScZkRwbiu5reQ7c8yHiEMiU44bqKuGSJgsmQLeCuBABcbFTPk8IMY= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 13109217; Thu, 29 Feb 2024 15:40:10 -0500 Message-ID: <2dbe097c-a4b8-4f22-8c39-1bdecbee4581@cybernetics.com> X-Barracuda-RBL-Trusted-Forwarder: 10.157.2.224 Date: Thu, 29 Feb 2024 15:40: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 Subject: Re: [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() Content-Language: en-US X-ASG-Orig-Subj: Re: [PATCH] block: Fix page refcounts for unaligned buffers in __bio_release_pages() To: Matthew Wilcox 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" References: <86e592a9-98d4-4cff-a646-0c0084328356@cybernetics.com> From: Tony Battersby In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1709239232 X-Barracuda-URL: https://10.10.4.122:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-Scan-Msg-Size: 1861 X-Barracuda-BRTS-Status: 1 On 2/29/24 14:53, Matthew Wilcox wrote: > 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)? Actually it would be: ssize_t done = -offset_in_page(offset); But then you have signed vs. unsigned comparison in the while(), or you could rearrange the loop to avoid the negative, but then it gets clunky. > >> @@ -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(). I developed the patch with the 6.1 stable series, which just has: nr_pages = (fi.offset + fi.length - 1) / PAGE_SIZE - fi.offset / PAGE_SIZE + 1; folio_put_refs(fi.folio, nr_pages); Which is another reason that I went for the direct nr_pages calculation.  Would you still prefer the negative offset_in_page() approach? Tony