All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] um: add a generic "fd" vector transport
@ 2020-04-07 20:28 Marc-André Lureau
  2020-04-07 21:02   ` Anton Ivanov
  2020-04-09 13:20   ` Anton Ivanov
  0 siblings, 2 replies; 9+ messages in thread
From: Marc-André Lureau @ 2020-04-07 20:28 UTC (permalink / raw)
  To: linux-um
  Cc: linux-kernel, joerd.simons, jdike, richard, anton.ivanov,
	alex.dewar, Marc-André Lureau

Learn to take a pre-opened file-descriptor for vector IO.

Instead of teaching the driver to open a FD in multiple ways, it can
rely on management layer to do it on its behalf. For example, this
allows inheriting a preconfigured device fd or a simple socketpair()
setup, without further arguments, privileges or system access by UML.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
index 29fae0456ade..45c1550dbb37 100644
--- a/arch/um/drivers/vector_user.c
+++ b/arch/um/drivers/vector_user.c
@@ -29,6 +29,7 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <os.h>
+#include <limits.h>
 #include <um_malloc.h>
 #include "vector_user.h"
 
@@ -42,6 +43,9 @@
 #define TRANS_RAW "raw"
 #define TRANS_RAW_LEN strlen(TRANS_RAW)
 
+#define TRANS_FD "fd"
+#define TRANS_FD_LEN strlen(TRANS_FD)
+
 #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
 #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
 #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
@@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
 	return NULL;
 }
 
+static int strtofd(const char *nptr)
+{
+	long fd;
+	char *endptr;
+
+	if (nptr == NULL)
+		return -1;
+
+	errno = 0;
+	fd = strtol(nptr, &endptr, 10);
+	if (nptr == endptr ||
+		errno != 0 ||
+		*endptr != '\0' ||
+		fd < 0 ||
+		fd > INT_MAX) {
+		return -1;
+	}
+	return fd;
+}
+
+static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
+{
+	int fd = -1;
+	char *fdarg = NULL;
+	struct vector_fds *result = NULL;
+
+	fdarg = uml_vector_fetch_arg(ifspec, "fd");
+	fd = strtofd(fdarg);
+	if (fd == -1) {
+		printk(UM_KERN_ERR "fd open: bad or missing fd argument");
+		goto fd_cleanup;
+	}
+
+	result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
+	if (result == NULL) {
+		printk(UM_KERN_ERR "fd open: allocation failed");
+		goto fd_cleanup;
+	}
+
+	result->rx_fd = fd;
+	result->tx_fd = fd;
+	result->remote_addr_size = 0;
+	result->remote_addr = NULL;
+	return result;
+
+fd_cleanup:
+	if (fd >= 0)
+		os_close_file(fd);
+	if (result != NULL)
+		kfree(result);
+	return NULL;
+}
+
 static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
 {
 	int rxfd = -1, txfd = -1;
@@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
 		return user_init_socket_fds(parsed, ID_L2TPV3);
 	if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
 		return user_init_unix_fds(parsed, ID_BESS);
+	if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
+		return user_init_fd_fds(parsed);
 	return NULL;
 }
 
-- 
2.26.0.106.g9fadedd637


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

* Re: [PATCH] um: add a generic "fd" vector transport
  2020-04-07 20:28 [PATCH] um: add a generic "fd" vector transport Marc-André Lureau
@ 2020-04-07 21:02   ` Anton Ivanov
  2020-04-09 13:20   ` Anton Ivanov
  1 sibling, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-07 21:02 UTC (permalink / raw)
  To: Marc-André Lureau, linux-um
  Cc: joerd.simons, richard, jdike, linux-kernel, alex.dewar

On 07/04/2020 21:28, Marc-André Lureau wrote:
> Learn to take a pre-opened file-descriptor for vector IO.
> 
> Instead of teaching the driver to open a FD in multiple ways, it can
> rely on management layer to do it on its behalf. For example, this
> allows inheriting a preconfigured device fd or a simple socketpair()
> setup, without further arguments, privileges or system access by UML.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
> 
> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> index 29fae0456ade..45c1550dbb37 100644
> --- a/arch/um/drivers/vector_user.c
> +++ b/arch/um/drivers/vector_user.c
> @@ -29,6 +29,7 @@
>   #include <netdb.h>
>   #include <stdlib.h>
>   #include <os.h>
> +#include <limits.h>
>   #include <um_malloc.h>
>   #include "vector_user.h"
>   
> @@ -42,6 +43,9 @@
>   #define TRANS_RAW "raw"
>   #define TRANS_RAW_LEN strlen(TRANS_RAW)
>   
> +#define TRANS_FD "fd"
> +#define TRANS_FD_LEN strlen(TRANS_FD)
> +
>   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>   	return NULL;
>   }
>   
> +static int strtofd(const char *nptr)
> +{
> +	long fd;
> +	char *endptr;
> +
> +	if (nptr == NULL)
> +		return -1;
> +
> +	errno = 0;
> +	fd = strtol(nptr, &endptr, 10);
> +	if (nptr == endptr ||
> +		errno != 0 ||
> +		*endptr != '\0' ||
> +		fd < 0 ||
> +		fd > INT_MAX) {
> +		return -1;
> +	}
> +	return fd;
> +}
> +
> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> +{
> +	int fd = -1;
> +	char *fdarg = NULL;
> +	struct vector_fds *result = NULL;
> +
> +	fdarg = uml_vector_fetch_arg(ifspec, "fd");
> +	fd = strtofd(fdarg);
> +	if (fd == -1) {
> +		printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> +		goto fd_cleanup;
> +	}
> +
> +	result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> +	if (result == NULL) {
> +		printk(UM_KERN_ERR "fd open: allocation failed");
> +		goto fd_cleanup;
> +	}
> +
> +	result->rx_fd = fd;
> +	result->tx_fd = fd;
> +	result->remote_addr_size = 0;
> +	result->remote_addr = NULL;
> +	return result;
> +
> +fd_cleanup:
> +	if (fd >= 0)
> +		os_close_file(fd);
> +	if (result != NULL)
> +		kfree(result);
> +	return NULL;
> +}
> +
>   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>   {
>   	int rxfd = -1, txfd = -1;
> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>   		return user_init_socket_fds(parsed, ID_L2TPV3);
>   	if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>   		return user_init_unix_fds(parsed, ID_BESS);
> +	if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> +		return user_init_fd_fds(parsed);
>   	return NULL;
>   }
>   
> 

We should also control enable/disable of recv/sendmmsg as an option here.

It can be made generic and be fed into get_transport_options() in 
vector_kern.c as an override.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* Re: [PATCH] um: add a generic "fd" vector transport
@ 2020-04-07 21:02   ` Anton Ivanov
  0 siblings, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-07 21:02 UTC (permalink / raw)
  To: Marc-André Lureau, linux-um
  Cc: joerd.simons, richard, jdike, linux-kernel, alex.dewar

On 07/04/2020 21:28, Marc-André Lureau wrote:
> Learn to take a pre-opened file-descriptor for vector IO.
> 
> Instead of teaching the driver to open a FD in multiple ways, it can
> rely on management layer to do it on its behalf. For example, this
> allows inheriting a preconfigured device fd or a simple socketpair()
> setup, without further arguments, privileges or system access by UML.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
> 
> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> index 29fae0456ade..45c1550dbb37 100644
> --- a/arch/um/drivers/vector_user.c
> +++ b/arch/um/drivers/vector_user.c
> @@ -29,6 +29,7 @@
>   #include <netdb.h>
>   #include <stdlib.h>
>   #include <os.h>
> +#include <limits.h>
>   #include <um_malloc.h>
>   #include "vector_user.h"
>   
> @@ -42,6 +43,9 @@
>   #define TRANS_RAW "raw"
>   #define TRANS_RAW_LEN strlen(TRANS_RAW)
>   
> +#define TRANS_FD "fd"
> +#define TRANS_FD_LEN strlen(TRANS_FD)
> +
>   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>   	return NULL;
>   }
>   
> +static int strtofd(const char *nptr)
> +{
> +	long fd;
> +	char *endptr;
> +
> +	if (nptr == NULL)
> +		return -1;
> +
> +	errno = 0;
> +	fd = strtol(nptr, &endptr, 10);
> +	if (nptr == endptr ||
> +		errno != 0 ||
> +		*endptr != '\0' ||
> +		fd < 0 ||
> +		fd > INT_MAX) {
> +		return -1;
> +	}
> +	return fd;
> +}
> +
> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> +{
> +	int fd = -1;
> +	char *fdarg = NULL;
> +	struct vector_fds *result = NULL;
> +
> +	fdarg = uml_vector_fetch_arg(ifspec, "fd");
> +	fd = strtofd(fdarg);
> +	if (fd == -1) {
> +		printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> +		goto fd_cleanup;
> +	}
> +
> +	result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> +	if (result == NULL) {
> +		printk(UM_KERN_ERR "fd open: allocation failed");
> +		goto fd_cleanup;
> +	}
> +
> +	result->rx_fd = fd;
> +	result->tx_fd = fd;
> +	result->remote_addr_size = 0;
> +	result->remote_addr = NULL;
> +	return result;
> +
> +fd_cleanup:
> +	if (fd >= 0)
> +		os_close_file(fd);
> +	if (result != NULL)
> +		kfree(result);
> +	return NULL;
> +}
> +
>   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>   {
>   	int rxfd = -1, txfd = -1;
> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>   		return user_init_socket_fds(parsed, ID_L2TPV3);
>   	if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>   		return user_init_unix_fds(parsed, ID_BESS);
> +	if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> +		return user_init_fd_fds(parsed);
>   	return NULL;
>   }
>   
> 

We should also control enable/disable of recv/sendmmsg as an option here.

It can be made generic and be fed into get_transport_options() in 
vector_kern.c as an override.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

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

* Re: [PATCH] um: add a generic "fd" vector transport
  2020-04-07 21:02   ` Anton Ivanov
@ 2020-04-08 17:07     ` Marc-André Lureau
  -1 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2020-04-08 17:07 UTC (permalink / raw)
  To: Anton Ivanov
  Cc: linux-um, joerd.simons, richard, jdike,
	Linux Kernel Mailing List, alex.dewar

Hi

On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov
<anton.ivanov@cambridgegreys.com> wrote:
>
> On 07/04/2020 21:28, Marc-André Lureau wrote:
> > Learn to take a pre-opened file-descriptor for vector IO.
> >
> > Instead of teaching the driver to open a FD in multiple ways, it can
> > rely on management layer to do it on its behalf. For example, this
> > allows inheriting a preconfigured device fd or a simple socketpair()
> > setup, without further arguments, privileges or system access by UML.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
> >   1 file changed, 59 insertions(+)
> >
> > diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> > index 29fae0456ade..45c1550dbb37 100644
> > --- a/arch/um/drivers/vector_user.c
> > +++ b/arch/um/drivers/vector_user.c
> > @@ -29,6 +29,7 @@
> >   #include <netdb.h>
> >   #include <stdlib.h>
> >   #include <os.h>
> > +#include <limits.h>
> >   #include <um_malloc.h>
> >   #include "vector_user.h"
> >
> > @@ -42,6 +43,9 @@
> >   #define TRANS_RAW "raw"
> >   #define TRANS_RAW_LEN strlen(TRANS_RAW)
> >
> > +#define TRANS_FD "fd"
> > +#define TRANS_FD_LEN strlen(TRANS_FD)
> > +
> >   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
> >   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
> >   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> > @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
> >       return NULL;
> >   }
> >
> > +static int strtofd(const char *nptr)
> > +{
> > +     long fd;
> > +     char *endptr;
> > +
> > +     if (nptr == NULL)
> > +             return -1;
> > +
> > +     errno = 0;
> > +     fd = strtol(nptr, &endptr, 10);
> > +     if (nptr == endptr ||
> > +             errno != 0 ||
> > +             *endptr != '\0' ||
> > +             fd < 0 ||
> > +             fd > INT_MAX) {
> > +             return -1;
> > +     }
> > +     return fd;
> > +}
> > +
> > +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> > +{
> > +     int fd = -1;
> > +     char *fdarg = NULL;
> > +     struct vector_fds *result = NULL;
> > +
> > +     fdarg = uml_vector_fetch_arg(ifspec, "fd");
> > +     fd = strtofd(fdarg);
> > +     if (fd == -1) {
> > +             printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> > +             goto fd_cleanup;
> > +     }
> > +
> > +     result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> > +     if (result == NULL) {
> > +             printk(UM_KERN_ERR "fd open: allocation failed");
> > +             goto fd_cleanup;
> > +     }
> > +
> > +     result->rx_fd = fd;
> > +     result->tx_fd = fd;
> > +     result->remote_addr_size = 0;
> > +     result->remote_addr = NULL;
> > +     return result;
> > +
> > +fd_cleanup:
> > +     if (fd >= 0)
> > +             os_close_file(fd);
> > +     if (result != NULL)
> > +             kfree(result);
> > +     return NULL;
> > +}
> > +
> >   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
> >   {
> >       int rxfd = -1, txfd = -1;
> > @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
> >               return user_init_socket_fds(parsed, ID_L2TPV3);
> >       if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
> >               return user_init_unix_fds(parsed, ID_BESS);
> > +     if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> > +             return user_init_fd_fds(parsed);
> >       return NULL;
> >   }
> >
> >
>
> We should also control enable/disable of recv/sendmmsg as an option here.
>
> It can be made generic and be fed into get_transport_options() in
> vector_kern.c as an override.

So actually, there seems to be a way to do that already:

vec0:transport=fd,fd=N,vec=0

>
> --
> Anton R. Ivanov
> Cambridgegreys Limited. Registered in England. Company Number 10273661
> https://www.cambridgegreys.com/
>


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

* Re: [PATCH] um: add a generic "fd" vector transport
@ 2020-04-08 17:07     ` Marc-André Lureau
  0 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2020-04-08 17:07 UTC (permalink / raw)
  To: Anton Ivanov
  Cc: joerd.simons, richard, jdike, linux-um,
	Linux Kernel Mailing List, alex.dewar

Hi

On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov
<anton.ivanov@cambridgegreys.com> wrote:
>
> On 07/04/2020 21:28, Marc-André Lureau wrote:
> > Learn to take a pre-opened file-descriptor for vector IO.
> >
> > Instead of teaching the driver to open a FD in multiple ways, it can
> > rely on management layer to do it on its behalf. For example, this
> > allows inheriting a preconfigured device fd or a simple socketpair()
> > setup, without further arguments, privileges or system access by UML.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
> >   1 file changed, 59 insertions(+)
> >
> > diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> > index 29fae0456ade..45c1550dbb37 100644
> > --- a/arch/um/drivers/vector_user.c
> > +++ b/arch/um/drivers/vector_user.c
> > @@ -29,6 +29,7 @@
> >   #include <netdb.h>
> >   #include <stdlib.h>
> >   #include <os.h>
> > +#include <limits.h>
> >   #include <um_malloc.h>
> >   #include "vector_user.h"
> >
> > @@ -42,6 +43,9 @@
> >   #define TRANS_RAW "raw"
> >   #define TRANS_RAW_LEN strlen(TRANS_RAW)
> >
> > +#define TRANS_FD "fd"
> > +#define TRANS_FD_LEN strlen(TRANS_FD)
> > +
> >   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
> >   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
> >   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> > @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
> >       return NULL;
> >   }
> >
> > +static int strtofd(const char *nptr)
> > +{
> > +     long fd;
> > +     char *endptr;
> > +
> > +     if (nptr == NULL)
> > +             return -1;
> > +
> > +     errno = 0;
> > +     fd = strtol(nptr, &endptr, 10);
> > +     if (nptr == endptr ||
> > +             errno != 0 ||
> > +             *endptr != '\0' ||
> > +             fd < 0 ||
> > +             fd > INT_MAX) {
> > +             return -1;
> > +     }
> > +     return fd;
> > +}
> > +
> > +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> > +{
> > +     int fd = -1;
> > +     char *fdarg = NULL;
> > +     struct vector_fds *result = NULL;
> > +
> > +     fdarg = uml_vector_fetch_arg(ifspec, "fd");
> > +     fd = strtofd(fdarg);
> > +     if (fd == -1) {
> > +             printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> > +             goto fd_cleanup;
> > +     }
> > +
> > +     result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> > +     if (result == NULL) {
> > +             printk(UM_KERN_ERR "fd open: allocation failed");
> > +             goto fd_cleanup;
> > +     }
> > +
> > +     result->rx_fd = fd;
> > +     result->tx_fd = fd;
> > +     result->remote_addr_size = 0;
> > +     result->remote_addr = NULL;
> > +     return result;
> > +
> > +fd_cleanup:
> > +     if (fd >= 0)
> > +             os_close_file(fd);
> > +     if (result != NULL)
> > +             kfree(result);
> > +     return NULL;
> > +}
> > +
> >   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
> >   {
> >       int rxfd = -1, txfd = -1;
> > @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
> >               return user_init_socket_fds(parsed, ID_L2TPV3);
> >       if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
> >               return user_init_unix_fds(parsed, ID_BESS);
> > +     if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> > +             return user_init_fd_fds(parsed);
> >       return NULL;
> >   }
> >
> >
>
> We should also control enable/disable of recv/sendmmsg as an option here.
>
> It can be made generic and be fed into get_transport_options() in
> vector_kern.c as an override.

So actually, there seems to be a way to do that already:

vec0:transport=fd,fd=N,vec=0

>
> --
> Anton R. Ivanov
> Cambridgegreys Limited. Registered in England. Company Number 10273661
> https://www.cambridgegreys.com/
>


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

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

* Re: [PATCH] um: add a generic "fd" vector transport
  2020-04-08 17:07     ` Marc-André Lureau
@ 2020-04-08 18:10       ` Anton Ivanov
  -1 siblings, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-08 18:10 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: linux-um, joerd.simons, richard, jdike,
	Linux Kernel Mailing List, alex.dewar

On 08/04/2020 18:07, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov
> <anton.ivanov@cambridgegreys.com> wrote:
>>
>> On 07/04/2020 21:28, Marc-André Lureau wrote:
>>> Learn to take a pre-opened file-descriptor for vector IO.
>>>
>>> Instead of teaching the driver to open a FD in multiple ways, it can
>>> rely on management layer to do it on its behalf. For example, this
>>> allows inheriting a preconfigured device fd or a simple socketpair()
>>> setup, without further arguments, privileges or system access by UML.
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>>    arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>>>    1 file changed, 59 insertions(+)
>>>
>>> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
>>> index 29fae0456ade..45c1550dbb37 100644
>>> --- a/arch/um/drivers/vector_user.c
>>> +++ b/arch/um/drivers/vector_user.c
>>> @@ -29,6 +29,7 @@
>>>    #include <netdb.h>
>>>    #include <stdlib.h>
>>>    #include <os.h>
>>> +#include <limits.h>
>>>    #include <um_malloc.h>
>>>    #include "vector_user.h"
>>>
>>> @@ -42,6 +43,9 @@
>>>    #define TRANS_RAW "raw"
>>>    #define TRANS_RAW_LEN strlen(TRANS_RAW)
>>>
>>> +#define TRANS_FD "fd"
>>> +#define TRANS_FD_LEN strlen(TRANS_FD)
>>> +
>>>    #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>>>    #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>>>    #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
>>> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>>>        return NULL;
>>>    }
>>>
>>> +static int strtofd(const char *nptr)
>>> +{
>>> +     long fd;
>>> +     char *endptr;
>>> +
>>> +     if (nptr == NULL)
>>> +             return -1;
>>> +
>>> +     errno = 0;
>>> +     fd = strtol(nptr, &endptr, 10);
>>> +     if (nptr == endptr ||
>>> +             errno != 0 ||
>>> +             *endptr != '\0' ||
>>> +             fd < 0 ||
>>> +             fd > INT_MAX) {
>>> +             return -1;
>>> +     }
>>> +     return fd;
>>> +}
>>> +
>>> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
>>> +{
>>> +     int fd = -1;
>>> +     char *fdarg = NULL;
>>> +     struct vector_fds *result = NULL;
>>> +
>>> +     fdarg = uml_vector_fetch_arg(ifspec, "fd");
>>> +     fd = strtofd(fdarg);
>>> +     if (fd == -1) {
>>> +             printk(UM_KERN_ERR "fd open: bad or missing fd argument");
>>> +             goto fd_cleanup;
>>> +     }
>>> +
>>> +     result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
>>> +     if (result == NULL) {
>>> +             printk(UM_KERN_ERR "fd open: allocation failed");
>>> +             goto fd_cleanup;
>>> +     }
>>> +
>>> +     result->rx_fd = fd;
>>> +     result->tx_fd = fd;
>>> +     result->remote_addr_size = 0;
>>> +     result->remote_addr = NULL;
>>> +     return result;
>>> +
>>> +fd_cleanup:
>>> +     if (fd >= 0)
>>> +             os_close_file(fd);
>>> +     if (result != NULL)
>>> +             kfree(result);
>>> +     return NULL;
>>> +}
>>> +
>>>    static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>>>    {
>>>        int rxfd = -1, txfd = -1;
>>> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>>>                return user_init_socket_fds(parsed, ID_L2TPV3);
>>>        if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>>>                return user_init_unix_fds(parsed, ID_BESS);
>>> +     if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
>>> +             return user_init_fd_fds(parsed);
>>>        return NULL;
>>>    }
>>>
>>>
>>
>> We should also control enable/disable of recv/sendmmsg as an option here.
>>
>> It can be made generic and be fed into get_transport_options() in
>> vector_kern.c as an override.
> 
> So actually, there seems to be a way to do that already:
> 
> vec0:transport=fd,fd=N,vec=0

I have forgotten about it (it's been a while since I wrote the drivers).

I will update the docs.

In that case the patch looks good to go, I will ack it shortly.

> 
>>
>> --
>> Anton R. Ivanov
>> Cambridgegreys Limited. Registered in England. Company Number 10273661
>> https://www.cambridgegreys.com/
>>
> 
> 


-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* Re: [PATCH] um: add a generic "fd" vector transport
@ 2020-04-08 18:10       ` Anton Ivanov
  0 siblings, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-08 18:10 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: joerd.simons, richard, jdike, linux-um,
	Linux Kernel Mailing List, alex.dewar

On 08/04/2020 18:07, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov
> <anton.ivanov@cambridgegreys.com> wrote:
>>
>> On 07/04/2020 21:28, Marc-André Lureau wrote:
>>> Learn to take a pre-opened file-descriptor for vector IO.
>>>
>>> Instead of teaching the driver to open a FD in multiple ways, it can
>>> rely on management layer to do it on its behalf. For example, this
>>> allows inheriting a preconfigured device fd or a simple socketpair()
>>> setup, without further arguments, privileges or system access by UML.
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>>    arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>>>    1 file changed, 59 insertions(+)
>>>
>>> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
>>> index 29fae0456ade..45c1550dbb37 100644
>>> --- a/arch/um/drivers/vector_user.c
>>> +++ b/arch/um/drivers/vector_user.c
>>> @@ -29,6 +29,7 @@
>>>    #include <netdb.h>
>>>    #include <stdlib.h>
>>>    #include <os.h>
>>> +#include <limits.h>
>>>    #include <um_malloc.h>
>>>    #include "vector_user.h"
>>>
>>> @@ -42,6 +43,9 @@
>>>    #define TRANS_RAW "raw"
>>>    #define TRANS_RAW_LEN strlen(TRANS_RAW)
>>>
>>> +#define TRANS_FD "fd"
>>> +#define TRANS_FD_LEN strlen(TRANS_FD)
>>> +
>>>    #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>>>    #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>>>    #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
>>> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>>>        return NULL;
>>>    }
>>>
>>> +static int strtofd(const char *nptr)
>>> +{
>>> +     long fd;
>>> +     char *endptr;
>>> +
>>> +     if (nptr == NULL)
>>> +             return -1;
>>> +
>>> +     errno = 0;
>>> +     fd = strtol(nptr, &endptr, 10);
>>> +     if (nptr == endptr ||
>>> +             errno != 0 ||
>>> +             *endptr != '\0' ||
>>> +             fd < 0 ||
>>> +             fd > INT_MAX) {
>>> +             return -1;
>>> +     }
>>> +     return fd;
>>> +}
>>> +
>>> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
>>> +{
>>> +     int fd = -1;
>>> +     char *fdarg = NULL;
>>> +     struct vector_fds *result = NULL;
>>> +
>>> +     fdarg = uml_vector_fetch_arg(ifspec, "fd");
>>> +     fd = strtofd(fdarg);
>>> +     if (fd == -1) {
>>> +             printk(UM_KERN_ERR "fd open: bad or missing fd argument");
>>> +             goto fd_cleanup;
>>> +     }
>>> +
>>> +     result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
>>> +     if (result == NULL) {
>>> +             printk(UM_KERN_ERR "fd open: allocation failed");
>>> +             goto fd_cleanup;
>>> +     }
>>> +
>>> +     result->rx_fd = fd;
>>> +     result->tx_fd = fd;
>>> +     result->remote_addr_size = 0;
>>> +     result->remote_addr = NULL;
>>> +     return result;
>>> +
>>> +fd_cleanup:
>>> +     if (fd >= 0)
>>> +             os_close_file(fd);
>>> +     if (result != NULL)
>>> +             kfree(result);
>>> +     return NULL;
>>> +}
>>> +
>>>    static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>>>    {
>>>        int rxfd = -1, txfd = -1;
>>> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>>>                return user_init_socket_fds(parsed, ID_L2TPV3);
>>>        if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>>>                return user_init_unix_fds(parsed, ID_BESS);
>>> +     if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
>>> +             return user_init_fd_fds(parsed);
>>>        return NULL;
>>>    }
>>>
>>>
>>
>> We should also control enable/disable of recv/sendmmsg as an option here.
>>
>> It can be made generic and be fed into get_transport_options() in
>> vector_kern.c as an override.
> 
> So actually, there seems to be a way to do that already:
> 
> vec0:transport=fd,fd=N,vec=0

I have forgotten about it (it's been a while since I wrote the drivers).

I will update the docs.

In that case the patch looks good to go, I will ack it shortly.

> 
>>
>> --
>> Anton R. Ivanov
>> Cambridgegreys Limited. Registered in England. Company Number 10273661
>> https://www.cambridgegreys.com/
>>
> 
> 


-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

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

* Re: [PATCH] um: add a generic "fd" vector transport
  2020-04-07 20:28 [PATCH] um: add a generic "fd" vector transport Marc-André Lureau
@ 2020-04-09 13:20   ` Anton Ivanov
  2020-04-09 13:20   ` Anton Ivanov
  1 sibling, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-09 13:20 UTC (permalink / raw)
  To: Marc-André Lureau, linux-um
  Cc: joerd.simons, richard, jdike, linux-kernel, alex.dewar


On 07/04/2020 21:28, Marc-André Lureau wrote:
> Learn to take a pre-opened file-descriptor for vector IO.
>
> Instead of teaching the driver to open a FD in multiple ways, it can
> rely on management layer to do it on its behalf. For example, this
> allows inheriting a preconfigured device fd or a simple socketpair()
> setup, without further arguments, privileges or system access by UML.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
>
> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> index 29fae0456ade..45c1550dbb37 100644
> --- a/arch/um/drivers/vector_user.c
> +++ b/arch/um/drivers/vector_user.c
> @@ -29,6 +29,7 @@
>   #include <netdb.h>
>   #include <stdlib.h>
>   #include <os.h>
> +#include <limits.h>
>   #include <um_malloc.h>
>   #include "vector_user.h"
>   
> @@ -42,6 +43,9 @@
>   #define TRANS_RAW "raw"
>   #define TRANS_RAW_LEN strlen(TRANS_RAW)
>   
> +#define TRANS_FD "fd"
> +#define TRANS_FD_LEN strlen(TRANS_FD)
> +
>   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>   	return NULL;
>   }
>   
> +static int strtofd(const char *nptr)
> +{
> +	long fd;
> +	char *endptr;
> +
> +	if (nptr == NULL)
> +		return -1;
> +
> +	errno = 0;
> +	fd = strtol(nptr, &endptr, 10);
> +	if (nptr == endptr ||
> +		errno != 0 ||
> +		*endptr != '\0' ||
> +		fd < 0 ||
> +		fd > INT_MAX) {
> +		return -1;
> +	}
> +	return fd;
> +}
> +
> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> +{
> +	int fd = -1;
> +	char *fdarg = NULL;
> +	struct vector_fds *result = NULL;
> +
> +	fdarg = uml_vector_fetch_arg(ifspec, "fd");
> +	fd = strtofd(fdarg);
> +	if (fd == -1) {
> +		printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> +		goto fd_cleanup;
> +	}
> +
> +	result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> +	if (result == NULL) {
> +		printk(UM_KERN_ERR "fd open: allocation failed");
> +		goto fd_cleanup;
> +	}
> +
> +	result->rx_fd = fd;
> +	result->tx_fd = fd;
> +	result->remote_addr_size = 0;
> +	result->remote_addr = NULL;
> +	return result;
> +
> +fd_cleanup:
> +	if (fd >= 0)
> +		os_close_file(fd);
> +	if (result != NULL)
> +		kfree(result);
> +	return NULL;
> +}
> +
>   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>   {
>   	int rxfd = -1, txfd = -1;
> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>   		return user_init_socket_fds(parsed, ID_L2TPV3);
>   	if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>   		return user_init_unix_fds(parsed, ID_BESS);
> +	if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> +		return user_init_fd_fds(parsed);
>   	return NULL;
>   }
>   
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/


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

* Re: [PATCH] um: add a generic "fd" vector transport
@ 2020-04-09 13:20   ` Anton Ivanov
  0 siblings, 0 replies; 9+ messages in thread
From: Anton Ivanov @ 2020-04-09 13:20 UTC (permalink / raw)
  To: Marc-André Lureau, linux-um
  Cc: joerd.simons, richard, jdike, linux-kernel, alex.dewar


On 07/04/2020 21:28, Marc-André Lureau wrote:
> Learn to take a pre-opened file-descriptor for vector IO.
>
> Instead of teaching the driver to open a FD in multiple ways, it can
> rely on management layer to do it on its behalf. For example, this
> allows inheriting a preconfigured device fd or a simple socketpair()
> setup, without further arguments, privileges or system access by UML.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   arch/um/drivers/vector_user.c | 59 +++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
>
> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> index 29fae0456ade..45c1550dbb37 100644
> --- a/arch/um/drivers/vector_user.c
> +++ b/arch/um/drivers/vector_user.c
> @@ -29,6 +29,7 @@
>   #include <netdb.h>
>   #include <stdlib.h>
>   #include <os.h>
> +#include <limits.h>
>   #include <um_malloc.h>
>   #include "vector_user.h"
>   
> @@ -42,6 +43,9 @@
>   #define TRANS_RAW "raw"
>   #define TRANS_RAW_LEN strlen(TRANS_RAW)
>   
> +#define TRANS_FD "fd"
> +#define TRANS_FD_LEN strlen(TRANS_FD)
> +
>   #define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
>   #define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
>   #define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
> @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
>   	return NULL;
>   }
>   
> +static int strtofd(const char *nptr)
> +{
> +	long fd;
> +	char *endptr;
> +
> +	if (nptr == NULL)
> +		return -1;
> +
> +	errno = 0;
> +	fd = strtol(nptr, &endptr, 10);
> +	if (nptr == endptr ||
> +		errno != 0 ||
> +		*endptr != '\0' ||
> +		fd < 0 ||
> +		fd > INT_MAX) {
> +		return -1;
> +	}
> +	return fd;
> +}
> +
> +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
> +{
> +	int fd = -1;
> +	char *fdarg = NULL;
> +	struct vector_fds *result = NULL;
> +
> +	fdarg = uml_vector_fetch_arg(ifspec, "fd");
> +	fd = strtofd(fdarg);
> +	if (fd == -1) {
> +		printk(UM_KERN_ERR "fd open: bad or missing fd argument");
> +		goto fd_cleanup;
> +	}
> +
> +	result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
> +	if (result == NULL) {
> +		printk(UM_KERN_ERR "fd open: allocation failed");
> +		goto fd_cleanup;
> +	}
> +
> +	result->rx_fd = fd;
> +	result->tx_fd = fd;
> +	result->remote_addr_size = 0;
> +	result->remote_addr = NULL;
> +	return result;
> +
> +fd_cleanup:
> +	if (fd >= 0)
> +		os_close_file(fd);
> +	if (result != NULL)
> +		kfree(result);
> +	return NULL;
> +}
> +
>   static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>   {
>   	int rxfd = -1, txfd = -1;
> @@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
>   		return user_init_socket_fds(parsed, ID_L2TPV3);
>   	if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
>   		return user_init_unix_fds(parsed, ID_BESS);
> +	if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
> +		return user_init_fd_fds(parsed);
>   	return NULL;
>   }
>   
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

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

end of thread, other threads:[~2020-04-09 13:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 20:28 [PATCH] um: add a generic "fd" vector transport Marc-André Lureau
2020-04-07 21:02 ` Anton Ivanov
2020-04-07 21:02   ` Anton Ivanov
2020-04-08 17:07   ` Marc-André Lureau
2020-04-08 17:07     ` Marc-André Lureau
2020-04-08 18:10     ` Anton Ivanov
2020-04-08 18:10       ` Anton Ivanov
2020-04-09 13:20 ` Anton Ivanov
2020-04-09 13:20   ` Anton Ivanov

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.