Re: [External] [PATCH v3 8/9] cachefiles: cyclic allocation of msg_id to avoid reuse

2024-07-02 Thread Jia Zhu via Linux-erofs
在 2024/6/28 14:29, libao...@huaweicloud.com 写道: From: Baokun Li Reusing the msg_id after a maliciously completed reopen request may cause a read request to remain unprocessed and result in a hung, as shown below: t1 | t2 | t3 ---

Re: [External] [PATCH v3 6/9] cachefiles: cancel all requests for the object that is being dropped

2024-07-02 Thread Jia Zhu via Linux-erofs
在 2024/6/28 14:29, libao...@huaweicloud.com 写道: From: Baokun Li Because after an object is dropped, requests for that object are useless, cancel them to avoid causing other problems. This prepares for the later addition of cancel_work_sync(). After the reopen requests is generated, cancel i

Re: [External] [PATCH v3 5/9] cachefiles: stop sending new request when dropping object

2024-07-02 Thread Jia Zhu via Linux-erofs
在 2024/6/28 14:29, libao...@huaweicloud.com 写道: From: Baokun Li Added CACHEFILES_ONDEMAND_OBJSTATE_DROPPING indicates that the cachefiles object is being dropped, and is set after the close request for the dropped object completes, and no new requests are allowed to be sent after this state.

Re: [PATCH 3/5] cachefiles: flush ondemand_object_worker during clean object

2024-04-24 Thread Jia Zhu via Linux-erofs
Thanks for catching this. How about adding a Fixes tag. Reviewed-by: Jia Zhu 在 2024/4/24 11:34, libao...@huaweicloud.com 写道: From: Hou Tao When queuing ondemand_object_worker() to re-open the object, cachefiles_object is not pinned. The cachefiles_object may be freed when the pending read r

Re: [PATCH 12/12] cachefiles: make on-demand read killable

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li Replacing wait_for_completion() with wait_for_completion_killable() in cachefiles_ondemand_send_req() allows us to kill processes that might trigger a hunk_task if the daemon is abnormal. But now only CACHEFILES_OP_READ is kill

Re: [PATCH 10/12] cachefiles: Set object to close if ondemand_id < 0 in copen

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Zizhi Wo If copen is maliciously called in the user mode, it may delete the request corresponding to the random id. And the request may have not been read yet. Note that when the object is set to reopen, the open request will be done wit

Re: [External] [PATCH 04/12] cachefiles: fix slab-use-after-free in cachefiles_ondemand_daemon_read()

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li We got the following issue in a fuzz test of randomly issuing the restore command: == BUG: KASAN: slab-use-after-free in cachefiles_ondemand_daemon_read+0xb41/0xb6

Re: [PATCH 03/12] cachefiles: fix slab-use-after-free in cachefiles_ondemand_get_fd()

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li We got the following issue in a fuzz test of randomly issuing the restore command: == BUG: KASAN: slab-use-after-free in cachefiles_ondemand_daemon_read+0x609/0xab

Re: [PATCH 02/12] cachefiles: remove err_put_fd tag in cachefiles_ondemand_daemon_read()

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li The err_put_fd tag is only used once, so remove it to make the code more readable. Signed-off-by: Baokun Li Reviewed-by: Jia Zhu --- fs/cachefiles/ondemand.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-)

Re: [PATCH 01/12] cachefiles: remove request from xarry during flush requests

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li This prevents concurrency from causing access to a freed req. Signed-off-by: Baokun Li Reviewed-by: Jia Zhu --- fs/cachefiles/daemon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/cachefiles/daemon.c b/fs/cac

Re: [PATCH 03/12] cachefiles: fix slab-use-after-free in cachefiles_ondemand_get_fd()

2024-04-24 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:39, libao...@huaweicloud.com 写道: From: Baokun Li We got the following issue in a fuzz test of randomly issuing the restore command: == BUG: KASAN: slab-use-after-free in cachefiles_ondemand_daemon_read+0x609/0xab

Re: [PATCH 5/5] cachefiles: add missing lock protection when polling

2024-04-23 Thread Jia Zhu via Linux-erofs
在 2024/4/24 11:34, libao...@huaweicloud.com 写道: From: Jingbo Xu Add missing lock protection in poll routine when iterating xarray, otherwise: Even with RCU read lock held, only the slot of the radix tree is ensured to be pinned there, while the data structure (e.g. struct cachefiles_req) st

Re: [External] [PATCH 5/6] cachefiles: Fix signed/unsigned mixup

2024-01-10 Thread Jia Zhu via Linux-erofs
Tested-by: Jia Zhu 在 2024/1/9 19:20, David Howells 写道: In __cachefiles_prepare_write(), the start and pos variables were made unsigned 64-bit so that the casts in the checking could be got rid of - which should be fine since absolute file offsets can't be negative, except that an error code may

[PATCH V6 RESEND 5/5] cachefiles: add restore command to recover inflight ondemand read requests

2023-11-19 Thread Jia Zhu via Linux-erofs
Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Sugg

[PATCH V6 RESEND 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode

2023-11-19 Thread Jia Zhu via Linux-erofs
Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/daemon.c | 14 -- fs/cachefiles/internal.h | 12 2 files changed, 24 insertions(+), 2 deletions(-) diff

[PATCH V6 RESEND 3/5] cachefiles: resend an open request if the read request's object is closed

2023-11-19 Thread Jia Zhu via Linux-erofs
When an anonymous fd is closed by user daemon, if there is a new read request for this file comes up, the anonymous fd should be re-opened to handle that read request rather than fail it directly. 1. Introduce reopening state for objects that are closed but have inflight/subsequent read request

[PATCH V6 RESEND 0/5] cachefiles: Introduce failover mechanism for on-demand mode

2023-11-19 Thread Jia Zhu via Linux-erofs
Changes since v5: In cachefiles_daemon_poll(), replace xa_for_each_marked with xas_for_each_marked. [Background] In the on-demand read mode, if user daemon unexpectedly closes an on-demand fd (for example, due to daemon crashing), subsequent read operations and inflight requests rely

[PATCH V6 RESEND 2/5] cachefiles: extract ondemand info field from cachefiles_object

2023-11-19 Thread Jia Zhu via Linux-erofs
We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/cachefiles/interface.c | 7 ++- fs/cachefiles/inte

[PATCH V6 RESEND 1/5] cachefiles: introduce object ondemand state

2023-11-19 Thread Jia Zhu via Linux-erofs
Previously, @ondemand_id field was used not only to identify ondemand state of the object, but also to represent the index of the xarray. This commit introduces @state field to decouple the role of @ondemand_id and adds helpers to access it. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/

Re: [External] [RESEND PATCH] erofs: relax the constraint of non-empty device tag in flatdev mode

2023-09-15 Thread Jia Zhu via Linux-erofs
在 2023/9/15 16:27, Jingbo Xu 写道: The device tag is not required in flatdev mode, and thus relax this constraint in flatdev mode. Signed-off-by: Jingbo Xu LGTM Reviewed-by: Jia Zhu --- Sorry I forget to cc linux-erofs@lists.ozlabs.org in the former patch. --- fs/erofs/super.c | 2 +-

[PATCH V6 5/5] cachefiles: add restore command to recover inflight ondemand read requests

2023-04-14 Thread Jia Zhu via Linux-erofs
Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Sugg

[PATCH V6 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode

2023-04-14 Thread Jia Zhu via Linux-erofs
Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu --- fs/cachefiles/daemon.c | 14 -- fs/cachefiles/internal.h | 12 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/d

[PATCH V6 3/5] cachefiles: resend an open request if the read request's object is closed

2023-04-14 Thread Jia Zhu via Linux-erofs
When an anonymous fd is closed by user daemon, if there is a new read request for this file comes up, the anonymous fd should be re-opened to handle that read request rather than fail it directly. 1. Introduce reopening state for objects that are closed but have inflight/subsequent read request

[PATCH V6 2/5] cachefiles: extract ondemand info field from cachefiles_object

2023-04-14 Thread Jia Zhu via Linux-erofs
We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu --- fs/cachefiles/interface.c | 7 ++- fs/cachefiles/internal.h | 26 +++

[PATCH V6 0/5] Introduce daemon failover mechanism to recover from crashing

2023-04-14 Thread Jia Zhu via Linux-erofs
Changes since v5: In cachefiles_daemon_poll(), replace xa_for_each_marked with xas_for_each_marked. [Background] In ondemand read mode, if user daemon closes anonymous fd(e.g. daemon crashes), subsequent read and inflight requests based on these fd will return -EIO. Even if above men

[PATCH V6 1/5] cachefiles: introduce object ondemand state

2023-04-14 Thread Jia Zhu via Linux-erofs
Previously, @ondemand_id field was used not only to identify ondemand state of the object, but also to represent the index of the xarray. This commit introduces @state field to decouple the role of @ondemand_id and adds helpers to access it. Signed-off-by: Jia Zhu --- fs/cachefiles/internal.h |

Re: Re: [PATCH V5 2/5] cachefiles: extract ondemand info field from cachefiles_object

2023-04-14 Thread Jia Zhu via Linux-erofs
在 2023/4/14 21:51, David Howells 写道: Jia Zhu wrote: #define CACHEFILES_OBJECT_STATE_FUNCS(_state, _STATE) \ static inline bool \ cachefiles_ondemand_object_is_##_state(const struct cachefiles_object *object) \ {

Re: Re: [PATCH V5 5/5] cachefiles: add restore command to recover inflight ondemand read requests

2023-04-14 Thread Jia Zhu via Linux-erofs
在 2023/4/14 21:53, David Howells 写道: Jia Zhu wrote: +int cachefiles_ondemand_restore(struct cachefiles_cache *cache, char *args) +{ + struct cachefiles_req *req; + + XA_STATE(xas, &cache->reqs, 0); + + if (!test_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags)) +

Re: Re: [PATCH V5 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode

2023-04-14 Thread Jia Zhu via Linux-erofs
在 2023/4/14 21:48, David Howells 写道: Jia Zhu wrote: if (cachefiles_in_ondemand_mode(cache)) { - if (!xa_empty(&cache->reqs)) - mask |= EPOLLIN; + if (!xa_empty(xa)) { + rcu_read_lock(); + x

[PATCH] erofs: explicit cast blkaddr to u64 before shift operation

2023-04-12 Thread Jia Zhu via Linux-erofs
We should explicitly cast @blkaddr from u32 to u64 before the shift operation to return the larger type. Fixes: b1c2d99b18ff ("erofs: avoid hardcoded blocksize for subpage block support") Signed-off-by: Jia Zhu --- fs/erofs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --gi

[PATCH V5 5/5] cachefiles: add restore command to recover inflight ondemand read requests

2023-03-29 Thread Jia Zhu via Linux-erofs
Previously, in ondemand read scenario, if the anonymous fd was closed by user daemon, inflight and subsequent read requests would return EIO. As long as the device connection is not released, user daemon can hold and restore inflight requests by setting the request flag to CACHEFILES_REQ_NEW. Sugg

[PATCH V5 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode

2023-03-29 Thread Jia Zhu via Linux-erofs
Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin Signed-off-by: Jia Zhu --- fs/cachefiles/daemon.c | 15 +-- fs/cachefiles/internal.h | 12 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/

[PATCH V5 3/5] cachefiles: resend an open request if the read request's object is closed

2023-03-29 Thread Jia Zhu via Linux-erofs
When an anonymous fd is closed by user daemon, if there is a new read request for this file comes up, the anonymous fd should be re-opened to handle that read request rather than fail it directly. 1. Introduce reopening state for objects that are closed but have inflight/subsequent read request

[PATCH V5 1/5] cachefiles: introduce object ondemand state

2023-03-29 Thread Jia Zhu via Linux-erofs
Previously, @ondemand_id field was used not only to identify ondemand state of the object, but also to represent the index of the xarray. This commit introduces @state field to decouple the role of @ondemand_id and adds helpers to access it. Signed-off-by: Jia Zhu --- fs/cachefiles/internal.h |

[PATCH V5 2/5] cachefiles: extract ondemand info field from cachefiles_object

2023-03-29 Thread Jia Zhu via Linux-erofs
We'll introduce a @work_struct field for @object in subsequent patches, it will enlarge the size of @object. As the result of that, this commit extracts ondemand info field from @object. Signed-off-by: Jia Zhu --- fs/cachefiles/interface.c | 7 ++- fs/cachefiles/internal.h | 26 +++

[PATCH V5 0/5] Introduce daemon failover mechanism to recover from crashing

2023-03-29 Thread Jia Zhu via Linux-erofs
Changes since v3: 1. Make enum cachefiles_object_state to all-uppercase and optimize the implement of CACHEFILES_OBJECT_STATE_FUNCS. 2. For struct cachefiles_object: 1. Make ondemand field inside of "#ifdef CONFIG_CACHEFILES_ONDEMAND". 2. Rename struct cachefiles_ondemand_info *p

Re: Re: [PATCH V4 3/5] cachefiles: resend an open request if the read request's object is closed

2023-03-29 Thread Jia Zhu via Linux-erofs
在 2023/3/28 22:12, David Howells 写道: Jia Zhu wrote: + struct cachefiles_object *object = + ((struct cachefiles_ondemand_info *)work)->object; container_of(). Thanks, will revise it. + continue; + } else if (cachefiles_ondemand_ob

Re: [External] Re: [PATCH V4 4/5] cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode

2023-03-29 Thread Jia Zhu via Linux-erofs
在 2023/3/28 22:19, David Howells 写道: Jia Zhu wrote: + if (!xa_empty(xa)) { + xa_lock(xa); + xa_for_each_marked(xa, index, req, CACHEFILES_REQ_NEW) { + if (!cachefiles_ondemand_is_reopening_read(req)) {

Re: Re: [PATCH V4 2/5] cachefiles: extract ondemand info field from cachefiles_object

2023-03-28 Thread Jia Zhu via Linux-erofs
在 2023/3/28 21:58, David Howells 写道: Jia Zhu wrote: @@ -65,10 +71,7 @@ struct cachefiles_object { enum cachefiles_content content_info:8; /* Info about content presence */ unsigned long flags; #define CACHEFILES_OBJECT_USING_TMPFILE 0

Re: Re: [PATCH V4 1/5] cachefiles: introduce object ondemand state

2023-03-28 Thread Jia Zhu via Linux-erofs
Hi David, Thanks for reviewing. 在 2023/3/28 21:52, David Howells 写道: Jia Zhu wrote: +enum cachefiles_object_state { + CACHEFILES_ONDEMAND_OBJSTATE_close, /* Anonymous fd closed by daemon or initial state */ + CACHEFILES_ONDEMAND_OBJSTATE_open, /* Anonymous fd associated with obj