Skip to contentSkip to conversation

tools: Use posix_memalign instead of valloc for NetBSD

PATCH In review Frediano Ziglio 5 participants 7 messages Apr 30 – Jul 3

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Use posix_memalign instead of valloc for NetBSD

More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018 and went out of support on May 4, 2024.

---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/include/xenctrl.h +5 -0
index d5dbf69c89..f4316089e7 100644
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
tools/libs/ctrl/xc_netbsd.c +8 -1
index 1318d4d906..d27154dce9 100644
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
Signature · 1 line
2.43.0
#1 lore raw

Adding Manuel that maintains the NetBSD xen-tools package.

Quoted 49 lines · Frediano Ziglio

More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018 and went out of support on May 4, 2024.

---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/include/xenctrl.h +5 -0
index d5dbf69c89..f4316089e7 100644
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
tools/libs/ctrl/xc_netbsd.c +8 -1
index 1318d4d906..d27154dce9 100644
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
Signature · 1 line
2.43.0
#2 lore raw
Quoted 1 line · Roger Pau Monné

Adding Manuel that maintains the NetBSD xen-tools package.

thanks
AFAIK this patch is fine

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#3 lore raw
In reply to Roger Pau Monné
Quoted 49 lines · Roger Pau Monné

Adding Manuel that maintains the NetBSD xen-tools package.

Quoted 45 lines · Frediano Ziglio

More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018 and went out of support on May 4, 2024.

---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/include/xenctrl.h +5 -0
index d5dbf69c89..f4316089e7 100644
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
tools/libs/ctrl/xc_netbsd.c +8 -1
index 1318d4d906..d27154dce9 100644
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
Quoted 4 lines
Quoted 4 lines
tools/libs/ctrl/xc_netbsd.c +0 -1
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
--

2.43.0

I saw Manuel reply almost 2 months ago.
Still pending.

Frediano

#4 lore raw
Quoted 50 lines · Frediano Ziglio
Quoted 49 lines · Roger Pau Monné

Adding Manuel that maintains the NetBSD xen-tools package.

Quoted 45 lines · Frediano Ziglio

More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018 and went out of support on May 4, 2024.

---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/include/xenctrl.h +5 -0
index d5dbf69c89..f4316089e7 100644
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
tools/libs/ctrl/xc_netbsd.c +8 -1
index 1318d4d906..d27154dce9 100644
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
tools/libs/ctrl/xc_netbsd.c +0 -1
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
--

2.43.0

I saw Manuel reply almost 2 months ago.
Still pending.

You understand, though, that Roger can't approve this patch. That'll need to be Anthony. Sending a ping _his_ way is certainly appropriate after this long a time.

Jan

#5 lore raw
Quoted 60 lines · Jan Beulich
Quoted 50 lines · Frediano Ziglio
Quoted 49 lines · Roger Pau Monné

Adding Manuel that maintains the NetBSD xen-tools package.

Quoted 45 lines · Frediano Ziglio

More similar to other implementation.
posix_memalign was adde in NetBSD 8.0, released on July 17, 2018 and went out of support on May 4, 2024.

---
 tools/include/xenctrl.h     | 5 +++++
 tools/libs/ctrl/xc_netbsd.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
tools/include/xenctrl.h +5 -0
index d5dbf69c89..f4316089e7 100644
@@ -1390,6 +1390,11 @@ int xc_lockprof_query(xc_interface *xch,
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+/**
+ * Allocate memory with a given alignment.
+ * The alignment must be a power of 2 and at least sizeof(void*).
+ * It returns NULL on error, errno is not set.
+ */
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
tools/libs/ctrl/xc_netbsd.c +8 -1
index 1318d4d906..d27154dce9 100644
@@ -60,7 +60,14 @@ void discard_file_cache(xc_interface *xch, int fd, int flush)
 
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
 {
-    return valloc(size);
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
 }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
tools/libs/ctrl/xc_netbsd.c +0 -1
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
--

2.43.0

I saw Manuel reply almost 2 months ago.
Still pending.

Quoted 5 lines

You understand, though, that Roger can't approve this patch. That'll need to be Anthony. Sending a ping _his_ way is certainly appropriate after this long a time.

Jan

Okay, looking at previous exchanges I thought the maintainer was Manuel.

Frediano