From mboxrd@z Thu Jan 1 00:00:00 1970 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 8807FC433EF for ; Mon, 20 Jun 2022 10:15:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F166A6B0071; Mon, 20 Jun 2022 06:15:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9E1A8E0002; Mon, 20 Jun 2022 06:15:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D70DD8E0001; Mon, 20 Jun 2022 06:15:52 -0400 (EDT) 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 C21A26B0071 for ; Mon, 20 Jun 2022 06:15:52 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 891EE60CBB for ; Mon, 20 Jun 2022 10:15:52 +0000 (UTC) X-FDA: 79598208144.10.EAEDCC6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id C6164C0012 for ; Mon, 20 Jun 2022 10:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655720151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=17O633cxkzhtVlsw20bhFnYAwMJzxi4yxd1FxbpHmHk=; b=KxDTHlZgmAr40jCFsE1HUT4TB2QGQVaPEf8NzUkAJhS9GNeqSWMitOzrxlZbwlgcIh/ZsJ EYoP/sJ0YFRKNiPiAeKw1F93cc0Tr2GbjCHOldXy8GAkh6epfIIYaf6bv6sAa/ZAB8Ab1/ FIR8QUJNN53Lvi1apXJRZNyGPpNYpf4= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-h4ixxzm7N2uuqugAxixLew-1; Mon, 20 Jun 2022 06:15:49 -0400 X-MC-Unique: h4ixxzm7N2uuqugAxixLew-1 Received: by mail-qk1-f199.google.com with SMTP id w22-20020a05620a445600b006a6c18678f2so12618270qkp.4 for ; Mon, 20 Jun 2022 03:15:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=17O633cxkzhtVlsw20bhFnYAwMJzxi4yxd1FxbpHmHk=; b=wxnC0V4tbSCJ54hPX/YyqoJA0nv6wJ2sGPSZoLwzVUT3tMqw/bQ/8eEwOh9h1Js+S0 a5qHkSJm2NJU1IuiwSfk7VDobOkUgl9qf7pw5W2d1R8wNv4Ma2fRpPOd0ctUP8EJKNLR QocbTLdmiKAJ5ksG+Nn127F+Mw3TzIfA63VzZwXSNuPwOwD7wMhlsqZEIQyiNlgsM/vw t3sBn1aQv6hAYxSZ3Zljqw+MugkTVF1ID9JpfJdoJlRSzyhvuRdUVyukCQARh/7NbYhR 24Z+MXa3K7pfHWBP0hNa2fTTEzNU+eGZ384N4BGXaU/PXaDCFNTzMVeLNDiH0XLerLXT gVpQ== X-Gm-Message-State: AJIora+mc+mYpScFJvjq3W4cfiPgJu5bJqP7qlqB21y1KgaKcqHkFNcx STq9zblUHajzgfEceKCI4opoiqL2ohxaHS3130JhgvsTuBNR/XBy2yqcm4gHT97F1nw465C3uGX XcVdj9omctrk= X-Received: by 2002:ac8:5dce:0:b0:305:300e:146d with SMTP id e14-20020ac85dce000000b00305300e146dmr19314578qtx.546.1655720149399; Mon, 20 Jun 2022 03:15:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v/cEaNjKfBuKp+ZYEkUM0VlKRqhV9w3cgTc7c6P2YubjKi1eY5Etkh4aXJe37nZysORywQIw== X-Received: by 2002:ac8:5dce:0:b0:305:300e:146d with SMTP id e14-20020ac85dce000000b00305300e146dmr19314558qtx.546.1655720149125; Mon, 20 Jun 2022 03:15:49 -0700 (PDT) Received: from bfoster (c-24-61-119-116.hsd1.ma.comcast.net. [24.61.119.116]) by smtp.gmail.com with ESMTPSA id bm12-20020a05620a198c00b006a7284e5741sm12065536qkb.54.2022.06.20.03.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 03:15:48 -0700 (PDT) Date: Mon, 20 Jun 2022 06:15:46 -0400 From: Brian Foster To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Chinner , stable@vger.kernel.org Subject: Re: [PATCH 2/3] filemap: Handle sibling entries in filemap_get_read_batch() Message-ID: References: <20220619151143.1054746-1-willy@infradead.org> <20220619151143.1054746-3-willy@infradead.org> MIME-Version: 1.0 In-Reply-To: <20220619151143.1054746-3-willy@infradead.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KxDTHlZg; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of bfoster@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=bfoster@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655720152; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=17O633cxkzhtVlsw20bhFnYAwMJzxi4yxd1FxbpHmHk=; b=mDumEgffAyiHU+zS9lTEIvapMw6ebkXoBQsAKOV1puN4mupF3QGblNbNq+92r0azg1GONN +19MeSxcodncRvpFv98JLZ8nSmFTQElG0Tjoe7EuxwBX0gWGYZvfd9NlqQrje+mEsDoAxf 2zwKZhFWMpZKb1frOV6KG5wVX/y1tdc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655720152; a=rsa-sha256; cv=none; b=iGwvbwwGB/9/1rZJ/zJJzgQInLWEpLisg6kqdFtHtlFcAO3+JBuASUPO9iLevAk/DGdidM v34HuF9Suk4I9BLOdWAYyj8UOgCTS5Blv/uKvs6RFFXq1S8ZBKMq+vlc9fNGweOOeee6yu 0eJPD++Nb7XGKYSdOw4qjsKJVhQ779M= X-Rspamd-Queue-Id: C6164C0012 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KxDTHlZg; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of bfoster@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=bfoster@redhat.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: odd5nmtwuzkhpaoafybdubrnho57utsa X-HE-Tag: 1655720151-93294 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: On Sun, Jun 19, 2022 at 04:11:42PM +0100, Matthew Wilcox (Oracle) wrote: > If a read races with an invalidation followed by another read, it is > possible for a folio to be replaced with a higher-order folio. If that > happens, we'll see a sibling entry for the new folio in the next iteration > of the loop. This manifests as a NULL pointer dereference while holding > the RCU read lock. > > Handle this by simply returning. The next call will find the new folio > and handle it correctly. The other ways of handling this rare race are > more complex and it's just not worth it. > > Reported-by: Dave Chinner > Reported-by: Brian Foster > Debugged-by: Brian Foster > Tested-by: Brian Foster > Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read") > Cc: stable@vger.kernel.org > Signed-off-by: Matthew Wilcox (Oracle) > --- This has survived my testing for several days now. I think I grok the fix and analysis that lead to it, so FWIW: Reviewed-by: Brian Foster > mm/filemap.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 577068868449..ffdfbc8b0e3c 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struct address_space *mapping, > continue; > if (xas.xa_index > max || xa_is_value(folio)) > break; > + if (xa_is_sibling(folio)) > + break; > if (!folio_try_get_rcu(folio)) > goto retry; > > -- > 2.35.1 >