All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] libs: implement some missing functions on FreeBSD
@ 2021-01-05 10:25 Roger Pau Monne
  2021-01-05 10:25 ` [PATCH 1/2] libs/foreignmemory: implement the " Roger Pau Monne
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Roger Pau Monne @ 2021-01-05 10:25 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ian Jackson, Wei Liu

Add support for dm_op, restrict and map resource ioctls on FreeBSD.

Roger Pau Monne (2):
  libs/foreignmemory: implement the missing functions on FreeBSD
  libs/devicemodel: add dm_op support for FreeBSD

 tools/include/xen-sys/FreeBSD/privcmd.h      | 29 +++++++++++
 tools/libs/devicemodel/Makefile              |  4 +-
 tools/libs/devicemodel/{linux.c => common.c} |  0
 tools/libs/foreignmemory/freebsd.c           | 51 ++++++++++++++++++++
 tools/libs/foreignmemory/private.h           |  2 +-
 5 files changed, 83 insertions(+), 3 deletions(-)
 rename tools/libs/devicemodel/{linux.c => common.c} (100%)

-- 
2.29.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] libs/foreignmemory: implement the missing functions on FreeBSD
  2021-01-05 10:25 [PATCH 0/2] libs: implement some missing functions on FreeBSD Roger Pau Monne
@ 2021-01-05 10:25 ` Roger Pau Monne
  2021-01-05 10:25 ` [PATCH 2/2] libs/devicemodel: add dm_op support for FreeBSD Roger Pau Monne
  2021-01-05 11:52 ` [PATCH 0/2] libs: implement some missing functions on FreeBSD Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Roger Pau Monne @ 2021-01-05 10:25 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ian Jackson, Wei Liu

Implement restrict, map resource and unmap resource helpers on
FreeBSD.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Note the implementation is fairly similar to the Linux one, so could
likely be merged with some ifdefary. Note sure it's worth it given
that we already have a split file.
---
 tools/include/xen-sys/FreeBSD/privcmd.h | 14 +++++++
 tools/libs/foreignmemory/freebsd.c      | 51 +++++++++++++++++++++++++
 tools/libs/foreignmemory/private.h      |  2 +-
 3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/tools/include/xen-sys/FreeBSD/privcmd.h b/tools/include/xen-sys/FreeBSD/privcmd.h
index cf1241f039..603aad67d5 100644
--- a/tools/include/xen-sys/FreeBSD/privcmd.h
+++ b/tools/include/xen-sys/FreeBSD/privcmd.h
@@ -56,9 +56,23 @@ typedef struct privcmd_mmap_entry {
 	unsigned long npages;
 } privcmd_mmap_entry_t;
 
+struct ioctl_privcmd_mmapresource {
+	domid_t dom; /* target domain */
+	unsigned int type; /* type of resource to map */
+	unsigned int id; /* type-specific resource identifier */
+	unsigned int idx; /* the index of the initial frame to be mapped */
+	unsigned long num; /* number of frames of the resource to be mapped */
+	unsigned long addr; /* physical address to map into */
+};
+typedef struct ioctl_privcmd_mmapresource privcmd_mmap_resource_t;
+
 #define IOCTL_PRIVCMD_HYPERCALL					\
 	_IOWR('E', 0, struct ioctl_privcmd_hypercall)
 #define IOCTL_PRIVCMD_MMAPBATCH					\
 	_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
+#define IOCTL_PRIVCMD_MMAP_RESOURCE				\
+	_IOW('E', 2, struct ioctl_privcmd_mmapresource)
+#define IOCTL_PRIVCMD_RESTRICT					\
+	_IOW('E', 4, domid_t)
 
 #endif /* !__XEN_PRIVCMD_H__ */
diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/freebsd.c
index 6e6bc4b11f..3d403a7cd0 100644
--- a/tools/libs/foreignmemory/freebsd.c
+++ b/tools/libs/foreignmemory/freebsd.c
@@ -95,6 +95,57 @@ int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
     return munmap(addr, num << PAGE_SHIFT);
 }
 
+int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
+                                    domid_t domid)
+{
+    return ioctl(fmem->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
+}
+
+int osdep_xenforeignmemory_unmap_resource(xenforeignmemory_handle *fmem,
+                                        xenforeignmemory_resource_handle *fres)
+{
+    return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0;
+}
+
+int osdep_xenforeignmemory_map_resource(xenforeignmemory_handle *fmem,
+                                        xenforeignmemory_resource_handle *fres)
+{
+    privcmd_mmap_resource_t mr = {
+        .dom = fres->domid,
+        .type = fres->type,
+        .id = fres->id,
+        .idx = fres->frame,
+        .num = fres->nr_frames,
+    };
+    int rc;
+
+    fres->addr = mmap(fres->addr, fres->nr_frames << PAGE_SHIFT,
+                      fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0);
+    if ( fres->addr == MAP_FAILED )
+        return -1;
+
+    mr.addr = (uintptr_t)fres->addr;
+
+    rc = ioctl(fmem->fd, IOCTL_PRIVCMD_MMAP_RESOURCE, &mr);
+    if ( rc )
+    {
+        int saved_errno;
+
+        if ( errno != ENOSYS )
+            PERROR("mmap resource ioctl failed");
+        else
+            errno = EOPNOTSUPP;
+
+        saved_errno = errno;
+        osdep_xenforeignmemory_unmap_resource(fmem, fres);
+        errno = saved_errno;
+
+        return -1;
+    }
+
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libs/foreignmemory/private.h b/tools/libs/foreignmemory/private.h
index 8f1bf081ed..ebd45c4785 100644
--- a/tools/libs/foreignmemory/private.h
+++ b/tools/libs/foreignmemory/private.h
@@ -54,7 +54,7 @@ struct xenforeignmemory_resource_handle {
     int flags;
 };
 
-#ifndef __linux__
+#if !defined(__linux__) && !defined(__FreeBSD__)
 static inline int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
                                                   domid_t domid)
 {
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] libs/devicemodel: add dm_op support for FreeBSD
  2021-01-05 10:25 [PATCH 0/2] libs: implement some missing functions on FreeBSD Roger Pau Monne
  2021-01-05 10:25 ` [PATCH 1/2] libs/foreignmemory: implement the " Roger Pau Monne
@ 2021-01-05 10:25 ` Roger Pau Monne
  2021-01-05 11:52 ` [PATCH 0/2] libs: implement some missing functions on FreeBSD Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Roger Pau Monne @ 2021-01-05 10:25 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ian Jackson, Wei Liu

The FreeBSD ioctls have the same fields has the Linux ones, so the
same file can be shared between both OSes.

No functional change for OSes different than FreeBSD.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/include/xen-sys/FreeBSD/privcmd.h      | 15 +++++++++++++++
 tools/libs/devicemodel/Makefile              |  4 ++--
 tools/libs/devicemodel/{linux.c => common.c} |  0
 3 files changed, 17 insertions(+), 2 deletions(-)
 rename tools/libs/devicemodel/{linux.c => common.c} (100%)

diff --git a/tools/include/xen-sys/FreeBSD/privcmd.h b/tools/include/xen-sys/FreeBSD/privcmd.h
index 603aad67d5..649ad443c7 100644
--- a/tools/include/xen-sys/FreeBSD/privcmd.h
+++ b/tools/include/xen-sys/FreeBSD/privcmd.h
@@ -66,12 +66,27 @@ struct ioctl_privcmd_mmapresource {
 };
 typedef struct ioctl_privcmd_mmapresource privcmd_mmap_resource_t;
 
+struct privcmd_dmop_buf {
+	void *uptr; /* pointer to memory (in calling process) */
+	size_t size; /* size of the buffer */
+};
+typedef struct privcmd_dmop_buf privcmd_dm_op_buf_t;
+
+struct ioctl_privcmd_dmop {
+	domid_t dom; /* target domain */
+	unsigned int num; /* num of buffers */
+	const struct privcmd_dmop_buf *ubufs; /* array of buffers */
+};
+typedef struct ioctl_privcmd_dmop privcmd_dm_op_t;
+
 #define IOCTL_PRIVCMD_HYPERCALL					\
 	_IOWR('E', 0, struct ioctl_privcmd_hypercall)
 #define IOCTL_PRIVCMD_MMAPBATCH					\
 	_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
 #define IOCTL_PRIVCMD_MMAP_RESOURCE				\
 	_IOW('E', 2, struct ioctl_privcmd_mmapresource)
+#define IOCTL_PRIVCMD_DM_OP					\
+	_IOW('E', 3, struct ioctl_privcmd_dmop)
 #define IOCTL_PRIVCMD_RESTRICT					\
 	_IOW('E', 4, domid_t)
 
diff --git a/tools/libs/devicemodel/Makefile b/tools/libs/devicemodel/Makefile
index b67fc0fac1..500de7adc5 100644
--- a/tools/libs/devicemodel/Makefile
+++ b/tools/libs/devicemodel/Makefile
@@ -5,8 +5,8 @@ MAJOR    = 1
 MINOR    = 3
 
 SRCS-y                 += core.c
-SRCS-$(CONFIG_Linux)   += linux.c
-SRCS-$(CONFIG_FreeBSD) += compat.c
+SRCS-$(CONFIG_Linux)   += common.c
+SRCS-$(CONFIG_FreeBSD) += common.c
 SRCS-$(CONFIG_SunOS)   += compat.c
 SRCS-$(CONFIG_NetBSD)  += compat.c
 SRCS-$(CONFIG_MiniOS)  += compat.c
diff --git a/tools/libs/devicemodel/linux.c b/tools/libs/devicemodel/common.c
similarity index 100%
rename from tools/libs/devicemodel/linux.c
rename to tools/libs/devicemodel/common.c
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] libs: implement some missing functions on FreeBSD
  2021-01-05 10:25 [PATCH 0/2] libs: implement some missing functions on FreeBSD Roger Pau Monne
  2021-01-05 10:25 ` [PATCH 1/2] libs/foreignmemory: implement the " Roger Pau Monne
  2021-01-05 10:25 ` [PATCH 2/2] libs/devicemodel: add dm_op support for FreeBSD Roger Pau Monne
@ 2021-01-05 11:52 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2021-01-05 11:52 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel, Ian Jackson, Wei Liu

On Tue, Jan 05, 2021 at 11:25:44AM +0100, Roger Pau Monne wrote:
> Add support for dm_op, restrict and map resource ioctls on FreeBSD.
> 
> Roger Pau Monne (2):
>   libs/foreignmemory: implement the missing functions on FreeBSD
>   libs/devicemodel: add dm_op support for FreeBSD

Acked-by: Wei Liu <wl@xen.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-05 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 10:25 [PATCH 0/2] libs: implement some missing functions on FreeBSD Roger Pau Monne
2021-01-05 10:25 ` [PATCH 1/2] libs/foreignmemory: implement the " Roger Pau Monne
2021-01-05 10:25 ` [PATCH 2/2] libs/devicemodel: add dm_op support for FreeBSD Roger Pau Monne
2021-01-05 11:52 ` [PATCH 0/2] libs: implement some missing functions on FreeBSD Wei Liu

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.