From patchwork Fri Dec 13 13:50:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13907059 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 8B805E77180 for ; Fri, 13 Dec 2024 13:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 253966B008A; Fri, 13 Dec 2024 08:50:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DDEA6B008C; Fri, 13 Dec 2024 08:50:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07DF06B0092; Fri, 13 Dec 2024 08:50:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CF4F76B008A for ; Fri, 13 Dec 2024 08:50:52 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 778A342030 for ; Fri, 13 Dec 2024 13:50:52 +0000 (UTC) X-FDA: 82890070368.03.F7ADC36 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 4C2A140019 for ; Fri, 13 Dec 2024 13:50:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hod7ZKFr; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1734097833; 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=EP45p+cLd1dDJ3/M9yBe/6nHDozsGhktItpu1CrIpGQ=; b=0TOjW2dioJWviFnool9E6oAVl7yQaoduWhMQteEo6R9Fn5/dOwpfq3zAQxtPc9kzOqOb22 XguWWzHKOwcbH8ooyPtcdUq2ZLMsC29DLyV5e/geDZp+WmIkh4joXg2ZHjVMTmPEokKg9R 605IHXV16l7v2kPXPbFYG6MRwmfr9lU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734097833; a=rsa-sha256; cv=none; b=FmkLg4cPkW8iDPo/47yaRpEmsGR35kLTwa2B1LSIv1+mmA4GtGfe8SksqSGK+KoHfhfIBZ T6eE1qRK8/aUD6TwionmSCB/4hTXztXJH+zeJOs0sZhcMinxZOpCjRkDP8uAb0+IwSs0LA jFzDVZL1BATn7e7Nfq2mZ/ljPrP1ifM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hod7ZKFr; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734097850; 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=EP45p+cLd1dDJ3/M9yBe/6nHDozsGhktItpu1CrIpGQ=; b=hod7ZKFrsZ9CGVnJhIxiZSSz5OLer/7C1glbHR+jJt6RAK1ax/UYGpqN8w2X3IGfD0WAI0 4f2SPA7lgqHNa3vP4wK1Mj/zyGjsVPyIa3DcGRTZCqfRqCHAFYsoktQsj4rKFPKM1PaWvQ StGpB8BKpGw3oHZJK1k/Jl6/EAno6N8= Received: from mx-prod-mc-05.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-638-UcRIgQcnN_-cN26AjAuVpA-1; Fri, 13 Dec 2024 08:50:46 -0500 X-MC-Unique: UcRIgQcnN_-cN26AjAuVpA-1 X-Mimecast-MFC-AGG-ID: UcRIgQcnN_-cN26AjAuVpA Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 96F4C1955F28; Fri, 13 Dec 2024 13:50:43 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.48]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C692F1956052; Fri, 13 Dec 2024 13:50:38 +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, syzbot+404b4b745080b6210c6c@syzkaller.appspotmail.com, Dmitry Antipov Subject: [PATCH 03/10] netfs: Fix enomem handling in buffered reads Date: Fri, 13 Dec 2024 13:50:03 +0000 Message-ID: <20241213135013.2964079-4-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.17 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4C2A140019 X-Stat-Signature: r74cb4b4jns9of4tsyk8hmqs4gk3s1be X-Rspam-User: X-HE-Tag: 1734097827-977368 X-HE-Meta: U2FsdGVkX1/Vf4Z6SVuvmRMKmzvO8bWUvanpVEBeDUq8hLoMoeMY0w673iEev4UmlosIVELmvGDkeRuc2vCfQRGpS07uCu7N7EwkyQdmMmQ15ibg+oobGstdrWSPeDjgnhscta2QNSw1L1N+tVd+C8rluecoE0tFetGu0Kz4on5bGjqrE5r46X0JPw9R2aoSF9lA7tzJOT9SyVI0GNdlQcnpkSVi5QrM88vaygWwwA7DS03Ag6mlGNlA2f2lBhg1cBkJ4VTrJpyJ6jjZEnoeTuPCmlLRYA92f9039O9wR6ISr5O/6ArYr6ywV9RLByaW5IgI26Lp0tzQGK7hwYps/Dbkl4b1XZgADh9Byks2yQpBaDOcBdRU0yR0AT/tUDubBo5hZRBP9dGs4mxYAl3TXz66xkS45GC+z92xy40Pv8EUheeOkmmxxgNrFthaWLrutaz0RmbfDJRuDr3SCI8Yi3koezG0Yck41Sr7mOeOejb97REWSXhv+/kefUyv6AAAfcDCN+cFyHNXNSotnZozudIlkar7lT/tBMxE8LVMh67Q1uebGImcxza7kSVS0a0JqYSBo9t5WKbmaLTYovwQCfdLiEmRUNC1sgqwKxHg709+dQ2HUrBFu5A/0epNu75Jd2YZM5REue8Yl+Cxh0HJVf7I5KyCyFr6z6S51lUN50c2h2EFMgyX6GdbVlKJaOMKzegnCj2m6pywKU5hs8pEvxLx56f2TffQTf+fbTYeRDgMU1q1gi2VkUphwAohJHrsC4oZoqgE4HCdj1p6YGSOHSeiSCpPvaSVcx+2z3MCV4GxanNCu5G5LEku5ryzS4leIwX1JGyOwo6+MNSJzN7VSUn9hbualxSsSwmXfLID+ntibnxE83zmwToBKRP9NHSCPt7nMnaaNsZL6G6HoAyfZ3ssdOHOOUWKGlJX3eg68nkv+ajtIHja4THliMGg3LAw5S+WA/EQkDrSRotrRUy UwD3C1zj VqYFCLUvJX1dMB06Zv/Kn803+0cOel6GVjmjT44kebOCmmhogu0XMKAD2EiYYClzL+V2Hz6n5BhHKm1IQTD1/AomA/vg7dKQ61M//p9pp5DG9je+6lgWdnS2sJThEbLFrlIzbK1wrgYRkxy0JGNB2EJ9mq4FmGKOowhkGbUXlv2hWVt8Gi6+C7N8y8Uaofb4T/sQYxB5CF6j4zZYRWwGod28IO8KqSSrI5KzuP9OUV2Csz2JuCihmtqGLHx1oWdTvg+cKHMHv5g8yS2ko6i2mf+mThir1DRrHSYFNRBtIe6ax/SS5gVKRw0wfQP1KttDBV+J9h+x+hHi6MbqZbiHbBSMUGvpgSUjbxE8VncjhwVWlKs67u0uHvCJakdnXgVAz80tOHeqh4RossBGdeF4Oltdg0WsRwwTxPVwPVrk65ZTDeIKvdqQXWH+9aXfplDLJ+C+IfONtOYoXRMVa1//mA031ys5nWhjkMswnkw0w/mtyyl2Fd/GcSiXH0ixx1ziBsV3RtS66A55csGbLkjFHPXvU5M+KlXOWWBu9bjMC9MK+r+jHW7PlEGE8X4ZfVIdC0NIWEfWUFAfYlV/EL+Rn88n7W6am1X+Agc/+TS0VQv96l9RIF0IQTpf6/4RtWfGYNH+ULPZ6LzVtNh9+IdNtiJOJZ9RYd700RxCMcbn6R2cK99aw9lEqWyg/k9NlNF/Whh7A 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: If netfs_read_to_pagecache() gets an error from either ->prepare_read() or from netfs_prepare_read_iterator(), it needs to decrement ->nr_outstanding, cancel the subrequest and break out of the issuing loop. Currently, it only does this for two of the cases, but there are two more that aren't handled. Fix this by moving the handling to a common place and jumping to it from all four places. This is in preference to inserting a wrapper around netfs_prepare_read_iterator() as proposed by Dmitry Antipov[1]. Link: https://lore.kernel.org/r/20241202093943.227786-1-dmantipov@yandex.ru/ [1] Fixes: ee4cdf7ba857 ("netfs: Speed up buffered reading") Reported-by: syzbot+404b4b745080b6210c6c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=404b4b745080b6210c6c Signed-off-by: David Howells cc: Dmitry Antipov cc: Jeff Layton cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/buffered_read.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 7ac34550c403..4dc9b8286355 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -275,22 +275,14 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) netfs_stat(&netfs_n_rh_download); if (rreq->netfs_ops->prepare_read) { ret = rreq->netfs_ops->prepare_read(subreq); - if (ret < 0) { - atomic_dec(&rreq->nr_outstanding); - netfs_put_subrequest(subreq, false, - netfs_sreq_trace_put_cancel); - break; - } + if (ret < 0) + goto prep_failed; trace_netfs_sreq(subreq, netfs_sreq_trace_prepare); } slice = netfs_prepare_read_iterator(subreq); - if (slice < 0) { - atomic_dec(&rreq->nr_outstanding); - netfs_put_subrequest(subreq, false, netfs_sreq_trace_put_cancel); - ret = slice; - break; - } + if (slice < 0) + goto prep_iter_failed; rreq->netfs_ops->issue_read(subreq); goto done; @@ -302,6 +294,8 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) trace_netfs_sreq(subreq, netfs_sreq_trace_submit); netfs_stat(&netfs_n_rh_zero); slice = netfs_prepare_read_iterator(subreq); + if (slice < 0) + goto prep_iter_failed; __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags); netfs_read_subreq_terminated(subreq, 0, false); goto done; @@ -310,6 +304,8 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) if (source == NETFS_READ_FROM_CACHE) { trace_netfs_sreq(subreq, netfs_sreq_trace_submit); slice = netfs_prepare_read_iterator(subreq); + if (slice < 0) + goto prep_iter_failed; netfs_read_cache_to_pagecache(rreq, subreq); goto done; } @@ -318,6 +314,14 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) WARN_ON_ONCE(1); break; + prep_iter_failed: + ret = slice; + prep_failed: + subreq->error = ret; + atomic_dec(&rreq->nr_outstanding); + netfs_put_subrequest(subreq, false, netfs_sreq_trace_put_cancel); + break; + done: size -= slice; start += slice;