Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1645373ybb; Thu, 9 Apr 2020 06:24:10 -0700 (PDT) X-Google-Smtp-Source: APiQypI+pUNgzz2uEDwPRBVAEJ+2ct/8i5UqkvHYTnsd/MUBE6YzTFev62dbxaXNzSWpYahoLKcx X-Received: by 2002:ac8:ac4:: with SMTP id g4mr11697043qti.318.1586438650584; Thu, 09 Apr 2020 06:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586438650; cv=none; d=google.com; s=arc-20160816; b=Ukkk+kHBlWA/XefISkWFLa3Bdzins1HslwntOFKHqulUOFZyl3TDpBKtkse1prknRu JvkhjPHxKQQA/V3oNTYfRdHTbE7szyKuP1083QhiAYdMuh24xuq8iAFZdCrSdozNjXIh 6IYMYOnoP1f6yybNrh2YIap+TVqP6ske75sCfL5LFjkXfgDFA6vQvd9INjoYqwLl1uzv +5xHRjRJg/j4ZJ17tLkjmGLkN+4W4b7VYSLIp6PkSP7uZz4I9bkIjAJxMhJzgOHgoA06 hBEGUSRV50tzsZ8v4UMl7qSaLrzPL1lL/jn5xnukhJ9zmyeVgEwjKby05Q4LMPvABJTb CyWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Awvwj6ww4OkPMeWAWRuZkOsJbgbE/oo5HwHXRK/8nvE=; b=bdP7xQDAaICKV+DuS3wuxhGwWwVg7izY00cST5R77oup5vckhSWGa3wBb907Ggcsqt eRE5ESDAN91OjylbzkWkTQk7fFYWIgbT/6Rc7VKs/gHUrTZRIiOcmyzF01MBNUgYj0Tz 22fwm7ouCRI61tdPYKWmTNw8l+OMK+uBTiSjza2c/C4pD0UbNlEAlRuIlhuYwnXnBZQx 7yEx0A7iqoBzRvIrTHA9dasVu4oa4K6qBk8IAfthYWWlxCKNCTAhUAtzix/J3utUjgwr p3LTaLdkG3vuQJIo0iTaRClTDdLp8RAONTDn1HrCWtKPpQRag7xBZ+yr8rG07Ajp6gvc cssw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 190si5707678qkh.271.2020.04.09.06.23.54; Thu, 09 Apr 2020 06:24:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726783AbgDINUm (ORCPT + 99 others); Thu, 9 Apr 2020 09:20:42 -0400 Received: from ivanoab7.miniserver.com ([37.128.132.42]:41048 "EHLO www.kot-begemot.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbgDINUl (ORCPT ); Thu, 9 Apr 2020 09:20:41 -0400 Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMX6k-0006Uc-Ha; Thu, 09 Apr 2020 13:20:38 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1jMX6i-00080H-5Q; Thu, 09 Apr 2020 14:20:38 +0100 Subject: Re: [PATCH] um: add a generic "fd" vector transport To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , linux-um@lists.infradead.org Cc: joerd.simons@collabora.co.uk, richard@nod.at, jdike@addtoit.com, linux-kernel@vger.kernel.org, alex.dewar@gmx.co.uk References: <20200407202853.1791218-1-marcandre.lureau@redhat.com> From: Anton Ivanov Message-ID: Date: Thu, 9 Apr 2020 14:20:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200407202853.1791218-1-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 > #include > #include > +#include > #include > #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 R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/