Message ID | 20241129125303.4033164-1-david@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 99875E7716D for <linux-mm@archiver.kernel.org>; Thu, 5 Dec 2024 15:30:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E8086B00E0; Thu, 5 Dec 2024 10:19:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CFF56B0125; Thu, 5 Dec 2024 10:19:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B6536B00DE; Thu, 5 Dec 2024 10:19:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5A2776B0085 for <linux-mm@kvack.org>; Fri, 29 Nov 2024 07:53:15 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 11DAD120333 for <linux-mm@kvack.org>; Fri, 29 Nov 2024 12:53:15 +0000 (UTC) X-FDA: 82839122856.30.D7F7D45 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 17EFE40016 for <linux-mm@kvack.org>; Fri, 29 Nov 2024 12:53:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Y33RLt/+"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732884789; a=rsa-sha256; cv=none; b=Adv+aFiBavPe6Mn6q9jH/YSFN7Hnsmz31zEG6WzPix/F4NEAmrsd2cWNYkIEpk0cvwH00g 7OyV3OuE9MZRBsygjKG53/W4n/CfpjC1rLu+P8oytolrWmtamHOLLaIu9Ne2H3Ixkvxlql B47auonSD62rMIU2RVuiDEqdYNCV4zE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Y33RLt/+"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732884789; 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:references:dkim-signature; bh=Cv6PjLDvvuWVXJelC4ktF5aqEnDKzqyylUqBRpvzsJg=; b=19wUPJWCduP4DlM6T74VuLorG5DVEWmhSdVHUQveiwwQ1SjU+plDohtsDyG5HYLzsf6uFH ZeZiAnoGIBv3Fp4FNpTaUgeMHwRsFdtxSDAD/G38O4pa07cQiOoga2lvFh7eE2c523k2Td hMpvH/kugIMGWB69Kw9Lh0SKMuNlifQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732884792; 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; bh=Cv6PjLDvvuWVXJelC4ktF5aqEnDKzqyylUqBRpvzsJg=; b=Y33RLt/+6POJHOD4Kzo3sSBcSJoEh3oFp0+KK2M/hsq4YqupExgp3RNCwCQuYl153t+a1+ ZqIKoqZ16CN+IT/guTS2q6HALx3lS8zTRYMX9D503d1I/tQtdmrccFKFswTIt9qI4vkpcd opIrGHdKb6tHzEtpRgYEz4eed9MbwWU= 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-647-GQ2_1JNLOROgSLH8GsROmA-1; Fri, 29 Nov 2024 07:53:10 -0500 X-MC-Unique: GQ2_1JNLOROgSLH8GsROmA-1 X-Mimecast-MFC-AGG-ID: GQ2_1JNLOROgSLH8GsROmA 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E4851955D4A; Fri, 29 Nov 2024 12:53:08 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.71]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CA2391955F30; Fri, 29 Nov 2024 12:53:04 +0000 (UTC) From: David Hildenbrand <david@redhat.com> To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, David Hildenbrand <david@redhat.com>, syzbot+9f9a7f73fb079b2387a6@syzkaller.appspotmail.com, "Matthew Wilcox (Oracle)" <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Hillf Danton <hdanton@sina.com> Subject: [PATCH v1] mm/filemap: don't call folio_test_locked() without a reference in next_uptodate_folio() Date: Fri, 29 Nov 2024 13:53:03 +0100 Message-ID: <20241129125303.4033164-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 17EFE40016 X-Stat-Signature: 9jcdwpwr6eoxye7b4rdy6bg48age4swc X-HE-Tag: 1732884781-499041 X-HE-Meta: U2FsdGVkX1/72o/LNVPat6nESIQuYfhHt6usjelfXiQ6euN3luMO3dTmpfVnvqUWKx0OltOiwFFsVozPAJAyCq8lUhKUYV5iRoGDvQWuGivl/YZUXrGLB3i9wfubOU2GecFmZS3R6puGc6EeNxUeqJghVJ1XAUk9+Dpa3kj8xMcQKiElA4EhHNAGv52YXDtva1Tszb37xn1VTHp3TBF811OKIIATt/lb2SZIhd0D38cXDjK8GMJsf/dFxdn6wH+q5VqLZK1biDDONvTwNpmOsCG/sq63odtlSS5JxLFunJVokWhqm5PgB0Ez+GMVDPDGjcc0ts8X4d2s0gD+cq7ql74W8sU61hv8f2xz8giWTEwsQtHalYp5xe7vsuclifEVzyWwa8te4Uol7PDtnKYz0SfraordnnnYwaMkf2bSlXuzLDqTU6B3hY6CrvxRwoKymBNGJJg5wpLxJXNpZvu8RbuY8ed4X9OCFoDe1zSdHpET1Ut8oqUHmlmSxX4gL06AH+RW6RRe4NVFhea0emw+Vsfqb7nfvRMUYHxw9YgcVvm+I+y503U4fABU97RAU7GXI3W/87nPUwD4R028ZcW3yF6p4wCMJcespZmEluI5xYvXsb7HBV9XJqh42E8UDPjQGcRSYgn9K3jsE/ZBsDdT+nrpa4TCgtkfgIPvanuV8L8MPWfBqjV4R0RriGnuM1cOrcQMbJLjLpQLwtjLW3vNKogxR+qHoSiXjRK+OAqBYtXhJ74LBDmEZizf63i1Qxgor+trhr5iNRdG2eAotzulpxC1uaVFRue3udyd7KgPL1YNQvajnz4o8euWSQUN1cOG3Pp4S7i2XlyLhuEuetuMu9jrVrMXsEgX00BuYl3Ul/uchPcS9h4LzlXhdXm8sYk33EThlAELJzT6l/NJ5ZnFHYvh7zbxt59mvXG56Ch8uG/JWdhFcLzlYMTGYZcb8zYVfBo5mTKi/9KOVwBsFVp CEysPQji WL7cNERMj9uvz8CfeyNnfYqwBG54wdQLRCG7KIvgtLov3Yq/BkCA99duNNdFkEtr91HHZ1hZWuP35lP46fkynKCyufQ2aBSdunn9l3p9Ftc1F81yWYGGQK06pDuOQd737tCJl0gaXF4RHzaidL4/00WR0bd1BsKeb1jlJlddYGkKCVmjOMF9MSqWm8WJ6VBSufy/WRU3dsY2LcIuE+fzop+sy0X2CDHvLMXem89/JqAZR67d/+vHOJe8XKqFLPtaEHIE25Ubkacll8ix/hezGDsoKbfs7Ezo1enkFyVFI/s3r4MW+MXUbZzCj5TA0rkftXLpQTD6LdznLEK2lRygFqP/k3G0s82cUKd59WnkKqfcitGpEyGdpievpltKA24JmrxhmwhoGCursujae6gKsLj61kIesOTR9F0rVLPDxQDH0AB4XA9LMcp7bn7EDNDTeGPpUjl7G75yELDR6HT/KF+OMEomKgLL0Ljni44Up0fqLXI1Ak0c7KzCLly8iDdTlObywv+nLtgM/nGJDGDbZiaK4gbgmtvI5DpPPvq51gSJSEdEUZtnNfwW3PI0Y3osbIMRuwgdYCeyJKvavvaygun9J7pCDBx1Zi2I67W4sF4HbYWgAS+wHt2aWaLRB2/BWOGZFlutz81DtVLFtP2+puRhYVLUnNR3QflkIqWHBP0Zw7WodO/trDfDfzpDTlECedHt7Jxm71tm0yXwNh2l6+ILygiUnmO8bnTqyNw/9NBvo86yCG9UVCJqutXx8jdZaE9hiCbQTDZl897I= 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
[v1] mm/filemap: don't call folio_test_locked() without a reference in next_uptodate_folio()
|
expand
|
diff --git a/mm/filemap.c b/mm/filemap.c index 7c76a123ba18b..f61cf51c22389 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3501,10 +3501,10 @@ static struct folio *next_uptodate_folio(struct xa_state *xas, continue; if (xa_is_value(folio)) continue; - if (folio_test_locked(folio)) - continue; if (!folio_try_get(folio)) continue; + if (folio_test_locked(folio)) + goto skip; /* Has the page moved or been split? */ if (unlikely(folio != xas_reload(xas))) goto skip;
The folio can get freed + buddy-merged + reallocated in the meantime, resulting in us calling folio_test_locked() possibly on a tail page. This makes const_folio_flags VM_BUG_ON_PGFLAGS() when stumbling over the tail page. Could this result in other issues? Doesn't look like it. False positives and false negatives don't really matter, because this folio would get skipped either way when detecting that they have been reallocated in the meantime. Fix it by performing the folio_test_locked() checked after grabbing a reference. If this ever becomes a real problem, we could add a special helper that racily checks if the bit is set even on tail pages ... but let's hope that's not required so we can just handle it cleaner: work on the folio after we hold a reference. Do we really need the folio_test_locked() check if we are going to trylock briefly after? Well, we can at least avoid a xas_reload(). It's a bit unclear which exact change introduced that issue. Likely, ever since we made PG_locked obey to the PF_NO_TAIL policy it could have been triggered in some way. Reported-by: syzbot+9f9a7f73fb079b2387a6@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/674184c9.050a0220.1cc393.0001.GAE@google.com/ Fixes: 48c935ad88f5 ("page-flags: define PG_locked behavior on compound pages") Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Hillf Danton <hdanton@sina.com> Signed-off-by: David Hildenbrand <david@redhat.com> --- mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)