From patchwork Fri Dec 13 13:50:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13907058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5788FE77180 for ; Fri, 13 Dec 2024 13:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E88F16B0088; Fri, 13 Dec 2024 08:50:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E12446B0089; Fri, 13 Dec 2024 08:50:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8C436B008A; Fri, 13 Dec 2024 08:50:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A38836B0088 for ; Fri, 13 Dec 2024 08:50:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 69FCC1C7D9A for ; Fri, 13 Dec 2024 13:50:46 +0000 (UTC) X-FDA: 82890070242.27.1C8EDB8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id B3AE61C0002 for ; Fri, 13 Dec 2024 13:50:17 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Rgc7YuW9; spf=pass (imf20.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734097827; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XyqR/WjDCwAE5X+NDEcLa5xYMEUn9QBuN0OBrTmThCY=; b=lrVK27iwhbwqhCg8tHiW0/9bp7gvWZKO2YRMZm2rSLiifBRQ3InIxyB4QhcgRJ3OwgC0od EZcefx5Mv8H38wd3RpmC2zKzyYvnst823m+fJHmHH1R9H5VIVrxwGraoqyaqrnieugT3i1 6jvDVeyuOaVvRqu4DxCEqpBQZLqX04E= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Rgc7YuW9; spf=pass (imf20.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734097827; a=rsa-sha256; cv=none; b=76OAQGMMs7efUsjYvjBF/qX66x+ScnRbjvupoEMC51yhA3S3HcyvVaBCtM3u8qRurv27uA XTFl/syNQbyfzaTsEZiotLqRv1qwfStHoEgZa3xkFd6oHO2RM2/ef5TjcwtS3PihfVsrJy mZQJ/fNRkYrFuRp6E44q8m6/cXTswA0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734097844; 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=XyqR/WjDCwAE5X+NDEcLa5xYMEUn9QBuN0OBrTmThCY=; b=Rgc7YuW9JNB//oZMuTVw7KwzVTQrGrFlf9xWClLXtH5PrC6i37r51AuCNiUccM8+YojxA1 iZHWFr4uTngWfXMm3tVmDEqXaUT5J6pvAczXHANEGNkBKEXobgGWN+70yBuWdsJu93tP2Z ynrBp9dzQoLOkh5pDU7KAJzVH/YF3vg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73--YEkMWSgNkChCQp0_JqhQQ-1; Fri, 13 Dec 2024 08:50:40 -0500 X-MC-Unique: -YEkMWSgNkChCQp0_JqhQQ-1 X-Mimecast-MFC-AGG-ID: -YEkMWSgNkChCQp0_JqhQQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7662919560AF; Fri, 13 Dec 2024 13:50:37 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.48]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BF2F1956089; Fri, 13 Dec 2024 13:50:31 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Max Kellermann , Ilya Dryomov , Xiubo Li , Trond Myklebust , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shyam Prasad N , Steve French , Paulo Alcantara Subject: [PATCH 02/10] netfs: Fix non-contiguous donation between completed reads Date: Fri, 13 Dec 2024 13:50:02 +0000 Message-ID: <20241213135013.2964079-3-dhowells@redhat.com> In-Reply-To: <20241213135013.2964079-1-dhowells@redhat.com> References: <20241213135013.2964079-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam05 X-Stat-Signature: og6e5aefzddpbg1omtd8m3xw77ecikdb X-Rspamd-Queue-Id: B3AE61C0002 X-Rspam-User: X-HE-Tag: 1734097817-261570 X-HE-Meta: U2FsdGVkX18Nt/OycgGZ4AQL3l9VIcp/GXKkFWaSF1LE5ODtU3Yo68QUSHTzX+o8nVrhZiMc6efMvF//jMeS/c4z1s9PHSK30X1cwp6bvs27PriV18+6zIsQsVUpnraHTOSvbRDdVWlTNQhNIKZJwl9O/b2bLzQRfKWipq8HjQupbiVktLgJGiqibQbX8RFQe1eUVU+9I/gHyta9CV3euZOaEqmpwJiyqm4L9yXvtTs/7Z7eSZtnjrI+/q86eLW7Q/c3OAbNr8lJXIHdeQKgeZqgHlYhEzwLTB/tAaz+w9SBdI57Q+R6k2J8KoYMFMDB1a5pGsYCnza7GwXm0Chby8scErWSQYpr2cBiCp2S8Sm0hVguGHZjgZFkmUAoFKB1o0ZwDce15/HxATbJ4QZL2rQl6GXVr3Bdgtwj0o26tygUFl1irs6fFMMuXUY5RgVDtLnAGb4d2h/k1ppCKYPg3ow88bCsrFpGEbnX11OqfZTNrnxnR+gIjjH0i6QMqjhxQ13OMX91KrmMpnDNsGiFi/KDAehfJydITwq2znqSwvfuCNw55wxuBtA5QPc5gS2kkA62AjSqwNlXybzYLTqe68EFHYKDR6v0l3/q+jrV+dyUkN7T2qFLAtB0uqJkdNOklkyA8NDuWgI2a84dUJyV6SQ540D0LQp0bybFL3UfY1wu4jckxErSQnsXXaps2GbexmfA9VX+NYT1w8iYVfYRGrdTqEXrPIVGTtI4Ex1e+irtDY2fh7k+NnY05JKqY3OcVkuquW+0ypwL69uNMqDKjX4vkF60vwCxIOoEW8IQuWGf3uoAj52PTC0PQrSTS1dOlx+O39x03i7BCnRr/vLAbPSYMCJTjljtiV1ETYl/x2Xcmu7onewX5kCVEIR0098eE4q9SON6zvpbjLPMKiUKzms7yLGDslAQVaDiDTOZUBj2hwZuRvoRGimIBVZZU7i0RGDYFYXogkj5FC2qe91 WCr6oby3 K420PZN97s6+eTrqd9PVCwFBxNzWxN+uwhqCGw3G40vQ3H/abmcfewNrCcumHW7nmJrsuYdMF/7w/T8GVPwYbPlv4a+MZE2aaQ6Pmw7GPML/uVa55HBtydbuwxihIQx1/a601cAac5Ldr2yfdrKy+0uLqu53S46cNLY1MpzMZL0B47n+i2ZCG+RFBc2pLVNTP9kHC51oI0oyQ2MSFiVSPzVsWH6RHTJVkwzG6IdB+vvAxbQ5v9jHy3pXqtsV/fOw0ps5wAvIw2Sv0ialwS97PEXRxf+8SKSptvasoyruwF0JYarUor6Oebo/5SqtZzUspzhl3ZXNiARim2qsXdsgj89jPprsZtGWQXUwWAkihwfcNJJsv7tfy7SRAkGP62AEnu2Mh8WrGNTJo08Qyb5k77irD3wTXn7cBN20Zps7MiZInmcQoCKBzCDbQWUUFkdaOwoaD4x4Iz015r4pKks/bazBlW39IPLPnY0oxfRFiVKk7UJ5gHARq2e+lLLg9EIG+y6S2oQkk9CxDd74lVsNONlDyteZrXfyjnIW/X8K3mIXaXaU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When a read subrequest finishes, if it doesn't have sufficient coverage to complete the folio(s) covering either side of it, it will donate the excess coverage to the adjacent subrequests on either side, offloading responsibility for unlocking the folio(s) covered to them. Now, preference is given to donating down to a lower file offset over donating up because that check is done first - but there's no check that the lower subreq is actually contiguous, and so we can end up donating incorrectly. The scenario seen[1] is that an 8MiB readahead request spanning four 2MiB folios is split into eight 1MiB subreqs (numbered 1 through 8). These terminate in the order 1,6,2,5,3,7,4,8. What happens is: - 1 donates to 2 - 6 donates to 5 - 2 completes, unlocking the first folio (with 1). - 5 completes, unlocking the third folio (with 6). - 3 donates to 4 - 7 donates to 4 incorrectly - 4 completes, unlocking the second folio (with 3), but can't use the excess from 7. - 8 donates to 4, also incorrectly. Fix this by preventing downward donation if the subreqs are not contiguous (in the example above, 7 donates to 4 across the gap left by 5 and 6). Reported-by: Shyam Prasad N Closes: https://lore.kernel.org/r/CANT5p=qBwjBm-D8soFVVtswGEfmMtQXVW83=TNfUtvyHeFQZBA@mail.gmail.com/ Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/r/526707.1733224486@warthog.procyon.org.uk/ [1] --- fs/netfs/read_collect.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/netfs/read_collect.c b/fs/netfs/read_collect.c index 3cbb289535a8..b415e3972336 100644 --- a/fs/netfs/read_collect.c +++ b/fs/netfs/read_collect.c @@ -247,16 +247,17 @@ static bool netfs_consume_read_data(struct netfs_io_subrequest *subreq, bool was /* Deal with the trickiest case: that this subreq is in the middle of a * folio, not touching either edge, but finishes first. In such a - * case, we donate to the previous subreq, if there is one, so that the - * donation is only handled when that completes - and remove this - * subreq from the list. + * case, we donate to the previous subreq, if there is one and if it is + * contiguous, so that the donation is only handled when that completes + * - and remove this subreq from the list. * * If the previous subreq finished first, we will have acquired their * donation and should be able to unlock folios and/or donate nextwards. */ if (!subreq->consumed && !prev_donated && - !list_is_first(&subreq->rreq_link, &rreq->subrequests)) { + !list_is_first(&subreq->rreq_link, &rreq->subrequests) && + subreq->start == prev->start + prev->len) { prev = list_prev_entry(subreq, rreq_link); WRITE_ONCE(prev->next_donated, prev->next_donated + subreq->len); subreq->start += subreq->len;