Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5476345rwb; Mon, 14 Nov 2022 05:21:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5iP0gqiMsxK/ImrDggLXPqR1no3uEcUIZoBZ+k92TNDIJZiqSn7qFVjGxyvx1utqldjbNa X-Received: by 2002:a05:6402:2499:b0:461:f94:913 with SMTP id q25-20020a056402249900b004610f940913mr10931143eda.102.1668432073965; Mon, 14 Nov 2022 05:21:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668432073; cv=none; d=google.com; s=arc-20160816; b=naUdaMAkUckCu82qhM5oF2cqCK+ZIzEfn4v1GPgdctYwVvAcS/PI5PdCGXZ3ELEFsT kjloRuWV2PAx6YDB51oWgQDo9xlQ7DwSssYz++jTO/7y5Bq4IiL3dlsDiuenEt6kNccF v+Lx65V+GLPS6xISzujbPqFFkGz6/H0lCYqVF8mongst0kQAnYbohWtRuqy7+AIXo6le r6l3ZRJdLn3lG3Cr9pYtZTvKDL/LiiUAfL94S1cWJjCiaoRwx19KQvxP+3svNpmDxSbr 6zXu3vBJ43Y9IShsEuEv3mMqvA9lnpGeD9nCtxPV+xw0G6MCieFG+Fl1R003nVoLRQhs kA+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Ar+szC/uHUwnczzOf0l21yUecnbHyOAyqat0IeMV70k=; b=l480yoepdIt0a7/bBF9gL7rqavPidFqxLxEhRmTBGeC/jTayzfisl08aKPxbwIU+tJ OYM9KwQfiiEHNJAKHcXhbUwl8PL0IkB90ORSG8Yu1fLBYPIXv0FgSnBA9kZ3QlPegcFS lvRTwqb+lWp9n31dODl+aLDbV1m+xbw+5Q0Tjy3hH25nnqriY/hO78fj+Zb2dP4DszID MVeKnq3MbmN+Or7PqqGB68yOS9h4TuIF3BtCU7dfyz5AmHbMsItYs+kCzWrqFbLbmr79 t+VHTYp3qmN1l9g0hkb5hq+eoKtInfkY4wYNO1LKJvegiYMSbaewmFB574GvOLl3tg0l MztQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402278700b00462e597dc46si8590933ede.301.2022.11.14.05.20.51; Mon, 14 Nov 2022 05:21:13 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237090AbiKNMTv (ORCPT + 88 others); Mon, 14 Nov 2022 07:19:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237092AbiKNMTt (ORCPT ); Mon, 14 Nov 2022 07:19:49 -0500 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D83B6222A0 for ; Mon, 14 Nov 2022 04:19:47 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R561e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VUmtJD9_1668428383; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VUmtJD9_1668428383) by smtp.aliyun-inc.com; Mon, 14 Nov 2022 20:19:44 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, yinxin.x@bytedance.com, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, dhowells@redhat.com Subject: [PATCH v2] erofs: fix missing xas_retry() in fscache mode Date: Mon, 14 Nov 2022 20:19:43 +0800 Message-Id: <20221114121943.29987-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 The xarray iteration only holds the RCU read lock and thus may encounter XA_RETRY_ENTRY if there's process modifying the xarray concurrently. This will cause oops when referring to the invalid entry. Fix this by adding the missing xas_retry(), which will make the iteration wind back to the root node if XA_RETRY_ENTRY is encountered. Fixes: d435d53228dd ("erofs: change to use asynchronous io for fscache readpage/readahead") Suggested-by: David Howells Reviewed-by: Gao Xiang Reviewed-by: Jia Zhu Signed-off-by: Jingbo Xu --- v2: - update the commit message suggested by David - add "Suggested-by" tag, as this patch actually fixes the same issue as that fixed by David's patch [1]. Sorry I forgot in v1 ;-\ - add "Reviewed-by" tags [1] https://lore.kernel.org/lkml/084d78a4-6052-f2ec-72f2-af9c4979f5dc@linux.alibaba.com/T/#m036d0221dacde491a1bcf2f4428e8b1450179df9 --- fs/erofs/fscache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index fe05bc51f9f2..458c1c70ef30 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -75,11 +75,15 @@ static void erofs_fscache_rreq_unlock_folios(struct netfs_io_request *rreq) rcu_read_lock(); xas_for_each(&xas, folio, last_page) { - unsigned int pgpos = - (folio_index(folio) - start_page) * PAGE_SIZE; - unsigned int pgend = pgpos + folio_size(folio); + unsigned int pgpos, pgend; bool pg_failed = false; + if (xas_retry(&xas, folio)) + continue; + + pgpos = (folio_index(folio) - start_page) * PAGE_SIZE; + pgend = pgpos + folio_size(folio); + for (;;) { if (!subreq) { pg_failed = true; -- 2.19.1.6.gb485710b