* [PATCH 0/3] Several small fixes
@ 2025-02-18 2:07 David Gibson
2025-02-18 2:07 ` [PATCH 1/3] packet: Use flexible array member in struct pool David Gibson
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: David Gibson @ 2025-02-18 2:07 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
As discussed on the call, here's the first of a number of pending
fixes I'm clearing from my backlog. I suppoted these while working on
the MTU fixes back in December, but they don't have an awful lot to do
with that inherently.
David Gibson (3):
packet: Use flexible array member in struct pool
packet: Don't pass start and offset separately to packet_check_range()
tap: Remove unused ETH_HDR_INIT() macro
packet.c | 36 +++++++++++++++++++-----------------
packet.h | 5 ++---
tap.h | 2 --
vu_common.c | 11 ++++-------
4 files changed, 25 insertions(+), 29 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] packet: Use flexible array member in struct pool
2025-02-18 2:07 [PATCH 0/3] Several small fixes David Gibson
@ 2025-02-18 2:07 ` David Gibson
2025-02-18 2:07 ` [PATCH 2/3] packet: Don't pass start and offset separately to packet_check_range() David Gibson
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2025-02-18 2:07 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
Currently we have a dummy pkt[1] array, which we alias with an array of
a different size via various macros. However, we already require C11 which
includes flexible array members, so we can do better.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
packet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packet.h b/packet.h
index 3f70e949..85ee5508 100644
--- a/packet.h
+++ b/packet.h
@@ -21,7 +21,7 @@ struct pool {
size_t buf_size;
size_t size;
size_t count;
- struct iovec pkt[1];
+ struct iovec pkt[];
};
int vu_packet_check_range(void *buf, size_t offset, size_t len,
--
@@ -21,7 +21,7 @@ struct pool {
size_t buf_size;
size_t size;
size_t count;
- struct iovec pkt[1];
+ struct iovec pkt[];
};
int vu_packet_check_range(void *buf, size_t offset, size_t len,
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] packet: Don't pass start and offset separately to packet_check_range()
2025-02-18 2:07 [PATCH 0/3] Several small fixes David Gibson
2025-02-18 2:07 ` [PATCH 1/3] packet: Use flexible array member in struct pool David Gibson
@ 2025-02-18 2:07 ` David Gibson
2025-02-18 2:07 ` [PATCH 3/3] tap: Remove unused ETH_HDR_INIT() macro David Gibson
2025-02-18 8:14 ` [PATCH 0/3] Several small fixes Stefano Brivio
3 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2025-02-18 2:07 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
Fundamentally what packet_check_range() does is to check whether a given
memory range is within the allowed / expected memory set aside for packets
from a particular pool. That range could represent a whole packet (from
packet_add_do()) or part of a packet (from packet_get_do()), but it doesn't
really matter which.
However, we pass the start of the range as two parameters: @start which is
the start of the packet, and @offset which is the offset within the packet
of the range we're interested in. We never use these separately, only as
(start + offset). Simplify the interface of packet_check_range() and
vu_packet_check_range() to directly take the start of the relevant range.
This will allow some additional future improvements.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
packet.c | 36 +++++++++++++++++++-----------------
packet.h | 3 +--
vu_common.c | 11 ++++-------
3 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/packet.c b/packet.c
index 03a11e6a..0330b548 100644
--- a/packet.c
+++ b/packet.c
@@ -23,23 +23,22 @@
#include "log.h"
/**
- * packet_check_range() - Check if a packet memory range is valid
+ * packet_check_range() - Check if a memory range is valid for a pool
* @p: Packet pool
- * @offset: Offset of data range in packet descriptor
+ * @ptr: Start of desired data range
* @len: Length of desired data range
- * @start: Start of the packet descriptor
* @func: For tracing: name of calling function
* @line: For tracing: caller line of function call
*
* Return: 0 if the range is valid, -1 otherwise
*/
-static int packet_check_range(const struct pool *p, size_t offset, size_t len,
- const char *start, const char *func, int line)
+static int packet_check_range(const struct pool *p, const char *ptr, size_t len,
+ const char *func, int line)
{
if (p->buf_size == 0) {
int ret;
- ret = vu_packet_check_range((void *)p->buf, offset, len, start);
+ ret = vu_packet_check_range((void *)p->buf, ptr, len);
if (ret == -1)
trace("cannot find region, %s:%i", func, line);
@@ -47,16 +46,16 @@ static int packet_check_range(const struct pool *p, size_t offset, size_t len,
return ret;
}
- if (start < p->buf) {
- trace("packet start %p before buffer start %p, "
- "%s:%i", (void *)start, (void *)p->buf, func, line);
+ if (ptr < p->buf) {
+ trace("packet range start %p before buffer start %p, %s:%i",
+ (void *)ptr, (void *)p->buf, func, line);
return -1;
}
- if (start + len + offset > p->buf + p->buf_size) {
- trace("packet offset plus length %zu from size %zu, "
- "%s:%i", start - p->buf + len + offset,
- p->buf_size, func, line);
+ if (ptr + len > p->buf + p->buf_size) {
+ trace("packet range end %p after buffer end %p, %s:%i",
+ (void *)(ptr + len), (void *)(p->buf + p->buf_size),
+ func, line);
return -1;
}
@@ -81,7 +80,7 @@ void packet_add_do(struct pool *p, size_t len, const char *start,
return;
}
- if (packet_check_range(p, 0, len, start, func, line))
+ if (packet_check_range(p, start, len, func, line))
return;
if (len > UINT16_MAX) {
@@ -110,6 +109,8 @@ void packet_add_do(struct pool *p, size_t len, const char *start,
void *packet_get_do(const struct pool *p, size_t idx, size_t offset,
size_t len, size_t *left, const char *func, int line)
{
+ char *ptr;
+
if (idx >= p->size || idx >= p->count) {
if (func) {
trace("packet %zu from pool size: %zu, count: %zu, "
@@ -135,14 +136,15 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset,
return NULL;
}
- if (packet_check_range(p, offset, len, p->pkt[idx].iov_base,
- func, line))
+ ptr = (char *)p->pkt[idx].iov_base + offset;
+
+ if (packet_check_range(p, ptr, len, func, line))
return NULL;
if (left)
*left = p->pkt[idx].iov_len - offset - len;
- return (char *)p->pkt[idx].iov_base + offset;
+ return ptr;
}
/**
diff --git a/packet.h b/packet.h
index 85ee5508..bdc07fef 100644
--- a/packet.h
+++ b/packet.h
@@ -24,8 +24,7 @@ struct pool {
struct iovec pkt[];
};
-int vu_packet_check_range(void *buf, size_t offset, size_t len,
- const char *start);
+int vu_packet_check_range(void *buf, const char *ptr, size_t len);
void packet_add_do(struct pool *p, size_t len, const char *start,
const char *func, int line);
void *packet_get_do(const struct pool *p, const size_t idx,
diff --git a/vu_common.c b/vu_common.c
index 48826b13..686a09b2 100644
--- a/vu_common.c
+++ b/vu_common.c
@@ -26,14 +26,12 @@
* vu_packet_check_range() - Check if a given memory zone is contained in
* a mapped guest memory region
* @buf: Array of the available memory regions
- * @offset: Offset of data range in packet descriptor
+ * @ptr: Start of desired data range
* @size: Length of desired data range
- * @start: Start of the packet descriptor
*
* Return: 0 if the zone is in a mapped memory region, -1 otherwise
*/
-int vu_packet_check_range(void *buf, size_t offset, size_t len,
- const char *start)
+int vu_packet_check_range(void *buf, const char *ptr, size_t len)
{
struct vu_dev_region *dev_region;
@@ -41,9 +39,8 @@ int vu_packet_check_range(void *buf, size_t offset, size_t len,
/* NOLINTNEXTLINE(performance-no-int-to-ptr) */
char *m = (char *)(uintptr_t)dev_region->mmap_addr;
- if (m <= start &&
- start + offset + len <= m + dev_region->mmap_offset +
- dev_region->size)
+ if (m <= ptr &&
+ ptr + len <= m + dev_region->mmap_offset + dev_region->size)
return 0;
}
--
@@ -26,14 +26,12 @@
* vu_packet_check_range() - Check if a given memory zone is contained in
* a mapped guest memory region
* @buf: Array of the available memory regions
- * @offset: Offset of data range in packet descriptor
+ * @ptr: Start of desired data range
* @size: Length of desired data range
- * @start: Start of the packet descriptor
*
* Return: 0 if the zone is in a mapped memory region, -1 otherwise
*/
-int vu_packet_check_range(void *buf, size_t offset, size_t len,
- const char *start)
+int vu_packet_check_range(void *buf, const char *ptr, size_t len)
{
struct vu_dev_region *dev_region;
@@ -41,9 +39,8 @@ int vu_packet_check_range(void *buf, size_t offset, size_t len,
/* NOLINTNEXTLINE(performance-no-int-to-ptr) */
char *m = (char *)(uintptr_t)dev_region->mmap_addr;
- if (m <= start &&
- start + offset + len <= m + dev_region->mmap_offset +
- dev_region->size)
+ if (m <= ptr &&
+ ptr + len <= m + dev_region->mmap_offset + dev_region->size)
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] tap: Remove unused ETH_HDR_INIT() macro
2025-02-18 2:07 [PATCH 0/3] Several small fixes David Gibson
2025-02-18 2:07 ` [PATCH 1/3] packet: Use flexible array member in struct pool David Gibson
2025-02-18 2:07 ` [PATCH 2/3] packet: Don't pass start and offset separately to packet_check_range() David Gibson
@ 2025-02-18 2:07 ` David Gibson
2025-02-18 8:14 ` [PATCH 0/3] Several small fixes Stefano Brivio
3 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2025-02-18 2:07 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
The uses of this macro were removed in d4598e1d18ac ("udp: Use the same
buffer for the L2 header for all frames").
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tap.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/tap.h b/tap.h
index dfbd8b9e..a476a125 100644
--- a/tap.h
+++ b/tap.h
@@ -6,8 +6,6 @@
#ifndef TAP_H
#define TAP_H
-#define ETH_HDR_INIT(proto) { .h_proto = htons_constant(proto) }
-
/**
* struct tap_hdr - tap backend specific headers
* @vnet_len: Frame length (for qemu socket transport)
--
@@ -6,8 +6,6 @@
#ifndef TAP_H
#define TAP_H
-#define ETH_HDR_INIT(proto) { .h_proto = htons_constant(proto) }
-
/**
* struct tap_hdr - tap backend specific headers
* @vnet_len: Frame length (for qemu socket transport)
--
2.48.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] Several small fixes
2025-02-18 2:07 [PATCH 0/3] Several small fixes David Gibson
` (2 preceding siblings ...)
2025-02-18 2:07 ` [PATCH 3/3] tap: Remove unused ETH_HDR_INIT() macro David Gibson
@ 2025-02-18 8:14 ` Stefano Brivio
3 siblings, 0 replies; 6+ messages in thread
From: Stefano Brivio @ 2025-02-18 8:14 UTC (permalink / raw)
To: David Gibson; +Cc: passt-dev
On Tue, 18 Feb 2025 13:07:16 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:
> As discussed on the call, here's the first of a number of pending
> fixes I'm clearing from my backlog. I suppoted these while working on
> the MTU fixes back in December, but they don't have an awful lot to do
> with that inherently.
>
> David Gibson (3):
> packet: Use flexible array member in struct pool
> packet: Don't pass start and offset separately to packet_check_range()
> tap: Remove unused ETH_HDR_INIT() macro
Applied.
--
Stefano
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] packet: Use flexible array member in struct pool
2024-12-13 12:01 [PATCH 0/3] Cleanups to packet pool handling and sizing David Gibson
@ 2024-12-13 12:01 ` David Gibson
0 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2024-12-13 12:01 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
Currently we have a dummy pkt[1] array, which we alias with an array of
a different size via various macros. However, we already require C11 which
includes flexible array members, so we can do better.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
packet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packet.h b/packet.h
index 3f70e949..85ee5508 100644
--- a/packet.h
+++ b/packet.h
@@ -21,7 +21,7 @@ struct pool {
size_t buf_size;
size_t size;
size_t count;
- struct iovec pkt[1];
+ struct iovec pkt[];
};
int vu_packet_check_range(void *buf, size_t offset, size_t len,
--
@@ -21,7 +21,7 @@ struct pool {
size_t buf_size;
size_t size;
size_t count;
- struct iovec pkt[1];
+ struct iovec pkt[];
};
int vu_packet_check_range(void *buf, size_t offset, size_t len,
--
2.47.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-02-18 8:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-18 2:07 [PATCH 0/3] Several small fixes David Gibson
2025-02-18 2:07 ` [PATCH 1/3] packet: Use flexible array member in struct pool David Gibson
2025-02-18 2:07 ` [PATCH 2/3] packet: Don't pass start and offset separately to packet_check_range() David Gibson
2025-02-18 2:07 ` [PATCH 3/3] tap: Remove unused ETH_HDR_INIT() macro David Gibson
2025-02-18 8:14 ` [PATCH 0/3] Several small fixes Stefano Brivio
-- strict thread matches above, loose matches on Subject: below --
2024-12-13 12:01 [PATCH 0/3] Cleanups to packet pool handling and sizing David Gibson
2024-12-13 12:01 ` [PATCH 1/3] packet: Use flexible array member in struct pool David Gibson
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).