From patchwork Fri Nov 4 05:40:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 15335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp188337wru; Thu, 3 Nov 2022 22:44:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rwHM2QbncyNX6hLKhsmQvP7BLS+k4Bzz2+FnSwC8lrDTTuqimDfkLPyBBcyIEskDjNJ67 X-Received: by 2002:a17:906:9bc2:b0:7ad:975f:b567 with SMTP id de2-20020a1709069bc200b007ad975fb567mr33454230ejc.107.1667540640120; Thu, 03 Nov 2022 22:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667540640; cv=none; d=google.com; s=arc-20160816; b=JqwB0++Q4xbaCzHQ5BtRNNn49dN5lZ+USSPB+Adilcm+AXP+dL+w69zkkUNB9bzzwr exzqKxz4ugXnp01TETu9v6RJV/8WOSLXM6+xw04whOWBKAYK7x6PSbhHV1xDehdI+QIn 5RmOsjZ+ySHSIuTCHD7pmUjv+oUYvTQ7wpoE+wMEpk2/i96EaUDV3CNW6YTzPotHjdjX hHulwlk9pVZ30TtusS4+aahGKN2Cu0Iijov46LQEKkUynFG7+lIgiNss94ML0YtJKNcf geQnD7fQWLb6hQ2/DFF23OK9rFTkOZ2siMuvxH/ch3hiRi/+A7YpOhpz8UZcnzpndEIy MNoA== 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=k9HY3GJS/DeUVFkQcniYMofo7svGH3qCslnxPlrwSyA=; b=FJQnqO3bJVdz0NPWg3w/xSWv6ZuGYqiYqr5VF+Ejus+MIz19bj2QscF16lP9zdL5tw T2B/GVR/6GrdE6LxZIEhNpQW0W3VCUcWWldotFXvAMf89JW//FgLxPpbVGwSYbljlA/8 DTxPGlejVgkqxWoQ67nQKWiUEz9O/oy3NZykdMXe5YC9F+PbV36vQYKBPTd0m5QxvgZb fOPcReko5iAqHbGJJ1n5782eGxkf93JXr0wzel0FVe9TGqP60p1OhrXdBlLhhwC05RKX 45EubHPJp327adNNQV1SjJrcki03Ns72ovsTFTctDwDGLUjA0WF0n8Fu1MSMbFPiTdOB JLmQ== 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 hg5-20020a1709072cc500b0078da30cb4bfsi4435864ejc.428.2022.11.03.22.43.35; Thu, 03 Nov 2022 22:44:00 -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 S230185AbiKDFkn (ORCPT + 99 others); Fri, 4 Nov 2022 01:40:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbiKDFkg (ORCPT ); Fri, 4 Nov 2022 01:40:36 -0400 Received: from out199-9.us.a.mail.aliyun.com (out199-9.us.a.mail.aliyun.com [47.90.199.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C0CD275DD for ; Thu, 3 Nov 2022 22:40:35 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;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=7;SR=0;TI=SMTPD_---0VTve-EV_1667540429; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VTve-EV_1667540429) by smtp.aliyun-inc.com; Fri, 04 Nov 2022 13:40:30 +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 1/2] erofs: put metabuf in error path in fscache mode Date: Fri, 4 Nov 2022 13:40:27 +0800 Message-Id: <20221104054028.52208-2-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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,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?1748543094093459256?= X-GMAIL-MSGID: =?utf-8?q?1748543094093459256?= For tail packing layout, put metabuf when error is encountered. Fixes: 1ae9470c3e14 ("erofs: clean up .read_folio() and .readahead() in fscache mode") Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang Reviewed-by: Jia Zhu Reviewed-by: Chao Yu --- fs/erofs/fscache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index fe05bc51f9f2..83559008bfa8 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -287,8 +287,10 @@ static int erofs_fscache_data_read(struct address_space *mapping, return PTR_ERR(src); iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, PAGE_SIZE); - if (copy_to_iter(src + offset, size, &iter) != size) + if (copy_to_iter(src + offset, size, &iter) != size) { + erofs_put_metabuf(&buf); return -EFAULT; + } iov_iter_zero(PAGE_SIZE - size, &iter); erofs_put_metabuf(&buf); return PAGE_SIZE; From patchwork Fri Nov 4 05:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 15338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp188955wru; Thu, 3 Nov 2022 22:45:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7aJ9sJ8afzvGnOH20OyuJadWSzZfJMuExKAS1xgTOtCUx2/twHAsO1BZNy9kSwWcAQCdLB X-Received: by 2002:a17:907:628f:b0:72f:58fc:3815 with SMTP id nd15-20020a170907628f00b0072f58fc3815mr32010282ejc.719.1667540753444; Thu, 03 Nov 2022 22:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667540753; cv=none; d=google.com; s=arc-20160816; b=gPQF4AxDLAx337M1azhrf4ygXQyZhP7cn/JKsPPfEJRHcFUG94kG7x2/ZWc8cHzlmm GAEVeUA5fMiGUTbdFK1krnMtivK3ZyXGvaoZ0e37KSspe5Ulv3diAmcHCsT77bryQ0A1 41Zi3mVUZA0IxMPI911beoMxffkmbtEAmFZVMTPMC2RO45AuwBkppL7g46oi+QZWt7ZD 995sbGmmFNvlfMbDEN9GrlW3xxYG6jCZKnHNBgV45sFS57hO7xwN4bBbgqBxGXDESle9 yGeBwQ2i3mLXnJFWolFYAq0NIU2SyyPGGnE/Rcpweh69/euktl9+xCROgwZIzzVw4wx2 x0Hw== 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 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.45.30; Thu, 03 Nov 2022 22:45:53 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748543213432185530?= X-GMAIL-MSGID: =?utf-8?q?1748543213432185530?= 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 Reviewed-by: Gao Xiang Reviewed-by: Chao Yu --- 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,