From patchwork Mon Nov 14 12:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 19780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2116014wru; Mon, 14 Nov 2022 04:32:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4udUhpA7bls20dgPQjFr5Qt9fooArjfvxBasOvbr+fSdx/FW1hb325ATXJ1R+hbxm5ZE2Z X-Received: by 2002:a63:a5b:0:b0:46e:f67c:c097 with SMTP id z27-20020a630a5b000000b0046ef67cc097mr11417196pgk.623.1668429161898; Mon, 14 Nov 2022 04:32:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668429161; cv=none; d=google.com; s=arc-20160816; b=ngV0vJ7LXcVPEUsMbXUCmIlzTicAe3Sg790d2k5GyofgiAnOu02wVHQIyzHxt+LK2N Dsb++BV2wlZSqPkkANLytchnxCI0WnoMKSx+0G44B8IRmGJ5lyTAmaPvkI3wICFe1AAL 7PqQMNzac3y1t8+wDDwNhChcwjs2nDekT09+0w8XNNXs68ZkrI1d4/gF1JxROQ0yyf+M Ldbv4buSgVF2TDQJUxARSaHcZE7gRBYV1FLuqdwQ5FpAZhfCG2ZTsGXdEqDmKvSLl6af WN6Ju9cOQxtcxBPf7BNODUNVGTHxUvhRelKk9GIn3VKMZ9rFkML48nYyzQjDFavYdE/d Fdhw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y192-20020a638ac9000000b0046f714d96fcsi9465879pgd.728.2022.11.14.04.32.28; Mon, 14 Nov 2022 04:32:41 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749190593606444396?= X-GMAIL-MSGID: =?utf-8?q?1749474776720295388?= 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;