* [PATCH v2 0/2] net/9p: fix response size check in p9_check_errors()
@ 2022-11-22 19:21 Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 1/2] net/9p: distinguish zero-copy requests Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 2/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
0 siblings, 2 replies; 3+ messages in thread
From: Christian Schoenebeck @ 2022-11-22 19:21 UTC (permalink / raw)
To: Dominique Martinet, Stefano Stabellini
Cc: v9fs-developer, linux-kernel, GUO Zihua
Follow-up fix for:
https://lore.kernel.org/linux-kernel/Y3hADWgV9JeajmfF@codewreck.org/
Dominique, I moved `zc` to the end of the structure to somewhat address
the layout padding. If you prefer a function argument in the first place,
let me know and I'll send a v3.
v1 -> v2:
* Move `zc` to end of struct p9_rstatf (to avoid huge padding).
[patch 1]
* Fix format specifier for `capacity` (reported by kernel test bot).
[patch 2]
* Fix code style. [patch 1..2]
* Extend and adjust commit log messages. [patch 1..2]
Christian Schoenebeck (2):
net/9p: distinguish zero-copy requests
net/9p: fix response size check in p9_check_errors()
include/net/9p/9p.h | 2 ++
net/9p/client.c | 13 +++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2 1/2] net/9p: distinguish zero-copy requests
2022-11-22 19:21 [PATCH v2 0/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
@ 2022-11-22 19:20 ` Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 2/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
1 sibling, 0 replies; 3+ messages in thread
From: Christian Schoenebeck @ 2022-11-22 19:20 UTC (permalink / raw)
To: Dominique Martinet, Stefano Stabellini
Cc: v9fs-developer, linux-kernel, GUO Zihua
Add boolean `zc` member to struct p9_fcall to distinguish zero-copy
messages (not using the linear `sdata` buffer for message payload) from
regular messages (which do copy message payload to `sdata` before being
further processed).
This new member is appended to end of structure to avoid inserting huge
padding in generated layout.
Signed-off-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
---
include/net/9p/9p.h | 2 ++
net/9p/client.c | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h
index 13abe013af21..429adf6be29c 100644
--- a/include/net/9p/9p.h
+++ b/include/net/9p/9p.h
@@ -531,6 +531,7 @@ struct p9_rstatfs {
* @offset: used by marshalling routines to track current position in buffer
* @capacity: used by marshalling routines to track total malloc'd capacity
* @sdata: payload
+ * @zc: whether zero-copy is used
*
* &p9_fcall represents the structure for all 9P RPC
* transactions. Requests are packaged into fcalls, and reponses
@@ -549,6 +550,7 @@ struct p9_fcall {
struct kmem_cache *cache;
u8 *sdata;
+ bool zc;
};
int p9_errstr2errno(char *errstr, int len);
diff --git a/net/9p/client.c b/net/9p/client.c
index aaa37b07e30a..c7935e392812 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -680,6 +680,9 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
if (IS_ERR(req))
return req;
+ req->tc.zc = false;
+ req->rc.zc = false;
+
if (signal_pending(current)) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
@@ -778,6 +781,9 @@ static struct p9_req_t *p9_client_zc_rpc(struct p9_client *c, int8_t type,
if (IS_ERR(req))
return req;
+ req->tc.zc = true;
+ req->rc.zc = true;
+
if (signal_pending(current)) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 2/2] net/9p: fix response size check in p9_check_errors()
2022-11-22 19:21 [PATCH v2 0/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 1/2] net/9p: distinguish zero-copy requests Christian Schoenebeck
@ 2022-11-22 19:20 ` Christian Schoenebeck
1 sibling, 0 replies; 3+ messages in thread
From: Christian Schoenebeck @ 2022-11-22 19:20 UTC (permalink / raw)
To: Dominique Martinet, Stefano Stabellini
Cc: v9fs-developer, linux-kernel, GUO Zihua
Since commit 60ece0833b6c ("net/9p: allocate appropriate reduced message
buffers") it is no longer appropriate to check server's response size
against msize. Check against the previously allocated buffer capacity
instead.
- Omit this size check entirely for zero-copy messages, as those always
allocate 4k (P9_ZC_HDR_SZ) linear buffers which are not used for actual
payload and can be much bigger than 4k.
- Replace p9_debug() by pr_err() to make sure this message is always
printed in case this error is triggered.
- Add 9p message type to error message to ease investigation.
Signed-off-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
Reported-by: kernel test robot <lkp@intel.com>
---
net/9p/client.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/net/9p/client.c b/net/9p/client.c
index c7935e392812..0ff25c2157ab 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -514,10 +514,9 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
int ecode;
err = p9_parse_header(&req->rc, NULL, &type, NULL, 0);
- if (req->rc.size >= c->msize) {
- p9_debug(P9_DEBUG_ERROR,
- "requested packet size too big: %d\n",
- req->rc.size);
+ if (req->rc.size > req->rc.capacity && !req->rc.zc) {
+ pr_err("requested packet size too big: %d does not fit %zu (type=%d)\n",
+ req->rc.size, req->rc.capacity, req->rc.id);
return -EIO;
}
/* dump the response from server
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-22 20:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-22 19:21 [PATCH v2 0/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 1/2] net/9p: distinguish zero-copy requests Christian Schoenebeck
2022-11-22 19:20 ` [PATCH v2 2/2] net/9p: fix response size check in p9_check_errors() Christian Schoenebeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.