Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2722598iog; Mon, 20 Jun 2022 03:23:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tR+7mVppavri+te05mgEt3DfRSHLWDfvV5E66/OGbwqw69L0EiPRg+shIgLUTIBBeQjR4J X-Received: by 2002:a50:ff04:0:b0:431:6a31:f19e with SMTP id a4-20020a50ff04000000b004316a31f19emr28517952edu.89.1655720582415; Mon, 20 Jun 2022 03:23:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655720582; cv=none; d=google.com; s=arc-20160816; b=rcA8GnQQscM17hFMw7wIAOvpJSLw/VSOeZNTS7cEPR2oAdAIKSIu7gsj5iSVOJrKlp vj98UvOuAoe6ws9/+q+jEpp+jxRZN2wMrFk7UwloK9eWEfLaQlYDjHyPE7ULnuulNPKT rIDVqqso705Axe7V9Bj9f9MESKpGf+n/gcUaX5RcZ3ribZZD4X1n2HXt4EoKab9sdWE+ FN4ZFngund93xeVmK1B8iI8y9kO8pqCzHjFlW8gN3WjRBLPh4ZOu1S1Kzd56DXktkl/t 2IvGirRI/0GG9Pj0tMCr7JP2JVT0i3vNEh1EbFNbK+qvXwGnxYT2CLojFu8PKjbXMftW TWjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=17O633cxkzhtVlsw20bhFnYAwMJzxi4yxd1FxbpHmHk=; b=zbid2uVeZRRFJ52yl3Ail6KlEop7vYEM9ffACBZIDxv+T+BV8oZUagG9uX2lFLzW2j YQB1zP/GATTdWlCohZbocJ9CC1R2v8mw5U/8zElfIt/ImFoGjwcdH1OLiyVn9Z9JXh3m Eph96iC9OSlyyUjx/VIXa95gDcacNNSC46jpuotxrE6YCf0c4lldxWhiDgHF6j5ucb/L lU3T0Ni8hSdAWfIOo1DVKHBEQ6YYIkyeWAnmiey9qSK0Xdff+Nh1w7a/jGXaxF4QhnwQ 85a43PuJUFtDw4PTmHMZ6Bs6drTBjsoVHrQo7Qs95Fy1zlqUZieK0ZdoaDMuS3U99mYL 0fqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KxDTHlZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji10-20020a170907980a00b00701eb604fffsi10312099ejc.5.2022.06.20.03.22.35; Mon, 20 Jun 2022 03:23:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KxDTHlZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240786AbiFTKPy (ORCPT + 99 others); Mon, 20 Jun 2022 06:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236474AbiFTKPx (ORCPT ); Mon, 20 Jun 2022 06:15:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 112EE13DEC for ; Mon, 20 Jun 2022 03:15:51 -0700 (PDT) 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-PrqRYbWIOfimd1lqt7Z5Nw-1; Mon, 20 Jun 2022 06:15:49 -0400 X-MC-Unique: PrqRYbWIOfimd1lqt7Z5Nw-1 Received: by mail-qk1-f199.google.com with SMTP id x4-20020a05620a448400b006ac665e1dfeso5196039qkp.17 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=0/bxNp+niStu/Vtuot7qvJrIV+oFWCdWu/PbkN3tvep/GnYRQFvaEnqNqGNZFzouW/ 3sqNQB+PKRAQtrkbVydyH2FBEPfzI2lnU20b37wRzx3HGkA2MH4gHoMBcrqZCeAWfBkX 1P5kz2PXSay7lBKews/WgqA8crLIVNnozpQDYGrARBPvJo0EKA1oHQmdFAy5fRWxaGnS snX85B2a/CoLbra/RKnPjPOsMLYDbNvEWrhMX9NbtNA++2K0nOXtRi91AMXY/Ji64joI SN+h1+G4s177yW7ze1wviCXqoGHoYKBZYtifGf0HxqAVO81nZ67An5O23aa2h8qAklTZ VQDQ== X-Gm-Message-State: AJIora9Qxnvxr9nXwkozOUTSwcQ1dsEGtsJkkpsenojKttUVGEgrtZbX Nb/PHGf5ApwG6PqFrfy+/Ha8k6X4xwXGoXrTK0IVPC7IoJuiVm+XS95vLur1OXrGxEEC98KlRJ5 F/dcFvaXwW5hSxT0ZkUGQ+JAj X-Received: by 2002:ac8:5dce:0:b0:305:300e:146d with SMTP id e14-20020ac85dce000000b00305300e146dmr19314579qtx.546.1655720149399; Mon, 20 Jun 2022 03:15:49 -0700 (PDT) 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220619151143.1054746-3-willy@infradead.org> X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >