Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp230312rwl; Thu, 3 Nov 2022 22:47:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ssg5gvoTjRY25DaVgAEbmnDgXgkQwkWByxjjH1et/p7m+Rs9BctwtW8QD2ad1TYnuRg96 X-Received: by 2002:a05:6402:1e96:b0:462:89aa:d402 with SMTP id f22-20020a0564021e9600b0046289aad402mr33579072edf.190.1667540830127; Thu, 03 Nov 2022 22:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667540830; cv=none; d=google.com; s=arc-20160816; b=YSfyRyFttObFE+ehU7wZtNnlYYe8eR8OQakIbP0uvIpSK5cHU0+VTEYr0YHyiRgfPB mX0+PqwRb7mcTeNNV5dUAc3oyaddeHoJUczbMc4qpq7UP7PU3rZX5eLu9CzTg4W5T8+4 +hlfEAxVLwC7kKVis027uvN/57bVVyJ4vFk15j8mm/Okv9DE76qLNglmMM8ZYIlB9SOZ FdeHUS86aAFFO9GWpuft5LHCN7kMeutNpUr3ugyGKDNBe5GVnCeJcSJnTX4YIZKhsWVr xjcg0OTC/GSLdvs3gkmK7gmCWBiGVc3bUj/W0zUCB29Bo6ir3OCAMBvLMEpKndMJBqjG puDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vRhorNMeRiQoRaKrSnOZSP0Z2JAnZelYagdaxo3QYUk=; b=shrO/vIc2MwowLZU1tTN05oAeZCXvBh7RXdzyxxoy7Wl7pxbmFtF2n8C9aau5pQKyb kOlT3PXV65rQH1+q4HDkJJ3il17HYy6qG9oacB1ctTmT6csTmTgvy4pHM5UlOiNwTxER xkr2FJmV5uA3pzcNdS52Eja93rWbYkeWqe2diEdnoQ9XPKmoik1li3sB3umnc93YQoMJ hPsKFzWt/1yUlNN4TY5kor9tA5DQPxTFU/j9vzG8ID91jCdHuiHTPaJm/j8GLB+/xGRI 8ys3Nuzu+SYgQpL68FKZh4vSkVQSpgEZAx+ip4aXbU8yZ8cBcWkVR0MuoZiD1sx4Wku3 IQaw== 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 t1-20020a170906268100b007825337afeesi2994081ejc.273.2022.11.03.22.46.43; Thu, 03 Nov 2022 22:47:10 -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; 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 S231140AbiKDFkj (ORCPT + 95 others); Fri, 4 Nov 2022 01:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbiKDFkg (ORCPT ); Fri, 4 Nov 2022 01:40:36 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0FB275DB for ; Thu, 3 Nov 2022 22:40:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R381e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VTvadhw_1667540430; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VTvadhw_1667540430) by smtp.aliyun-inc.com; Fri, 04 Nov 2022 13:40:31 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org Cc: zhujia.zj@bytedance.com, yinxin.x@bytedance.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] erofs: get correct count for unmapped range in fscache mode Date: Fri, 4 Nov 2022 13:40:28 +0800 Message-Id: <20221104054028.52208-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20221104054028.52208-1-jefflexu@linux.alibaba.com> References: <20221104054028.52208-1-jefflexu@linux.alibaba.com> 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,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 For unmapped range, the returned map.m_llen is zero, and thus the calculated count is unexpected zero. Prior to the refactoring introduced by commit 1ae9470c3e14 ("erofs: clean up .read_folio() and .readahead() in fscache mode"), only the readahead routine suffers from this. With the refactoring of making .read_folio() and .readahead() calling one common routine, both read_folio and readahead have this issue now. Fix this by calculating count separately in unmapped condition. Fixes: c665b394b9e8 ("erofs: implement fscache-based data readahead") Fixes: 1ae9470c3e14 ("erofs: clean up .read_folio() and .readahead() in fscache mode") Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 83559008bfa8..260fa4737fc0 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -296,15 +296,16 @@ static int erofs_fscache_data_read(struct address_space *mapping, return PAGE_SIZE; } - count = min_t(size_t, map.m_llen - (pos - map.m_la), len); - DBG_BUGON(!count || count % PAGE_SIZE); - if (!(map.m_flags & EROFS_MAP_MAPPED)) { + count = len; iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, count); iov_iter_zero(count, &iter); return count; } + count = min_t(size_t, map.m_llen - (pos - map.m_la), len); + DBG_BUGON(!count || count % PAGE_SIZE); + mdev = (struct erofs_map_dev) { .m_deviceid = map.m_deviceid, .m_pa = map.m_pa, -- 2.19.1.6.gb485710b