Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1022328ybb; Wed, 8 Apr 2020 14:51:10 -0700 (PDT) X-Google-Smtp-Source: APiQypLOWOF0F7JFHBVAhx9DYIVtG4TUQWjWFGVWFJcKa1vQmvfSRkYrkek6uzc22NCDJzzqZ3Tl X-Received: by 2002:aca:47c8:: with SMTP id u191mr4294781oia.170.1586382670814; Wed, 08 Apr 2020 14:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586382670; cv=none; d=google.com; s=arc-20160816; b=rFxO97pMy+C4spNrbHRcYp8Gc2zTvWY34bNm0nhamjUgzYtJnH7VK2Zfn03hgqUnGe ZKk7TG97/EQ9AvkNZ1pRp/znoz+WcF5o68iF0r0u42Jj2t0Jz1NkLjOLc1OqI51AcfCV zblXoqpTZbc6UJpgopxzoT4PaO/xGRLFg/O6QpJSf0rtjVS8Vl5guJDCABjH3uTZrgd1 l+lIBgdExlWMAlihaNnBErvUv9SG0Ief8Z3e2AHmBwln6KQfJnStPdZEI5IJlK7g8NX0 U3jaVZVU/lfmPLPje8nmUmJOfWIW1Ep/xZ8TOZ+XlAz6MbypblRO1OSCDykMeh44dDGZ fe+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=+taYuXC1h10AU0wu/ovHT1gFo20urgs7CYSRXFnTEWw=; b=dICC6/fKXym4x7aKhvMgAeHy96+mAYdt/SS0V9X32shaLmeR9qG9RxYvwOQQv2l2mm zv0ntxjdXmcMlB6OpMiEZpegijboUAQEnn8rqgUpx/ECGj97FimlvPE6WGHhXnr94tg1 Bmq+GtMeSA7yaZxgVWLfHNVP6JwVSg1CbKQBOKSv1ciDoOH8l2QxHSTV8NRDuxK33SUc KdOWsfs9v06xRrPn/HCa4ryhNWpgbtEEYnTvxD6RZt+7WbM5iIq2Vah1Y0j5LClz8O2O M/lPA3SrpUY4JBuwBZG38OcUSqdzMXBXQzuT2VDqpPB3ztoJJULminqzb4SKH+bHd0SP WhHg== 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 d63si2536968oib.224.2020.04.08.14.50.58; Wed, 08 Apr 2020 14:51: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 S1729413AbgDHSKZ (ORCPT + 99 others); Wed, 8 Apr 2020 14:10:25 -0400 Received: from ivanoab7.miniserver.com ([37.128.132.42]:39328 "EHLO www.kot-begemot.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbgDHSKY (ORCPT ); Wed, 8 Apr 2020 14:10:24 -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 1jMF9W-0002xJ-23; Wed, 08 Apr 2020 18:10:18 +0000 Received: from sleer.kot-begemot.co.uk ([192.168.3.72]) by jain.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jMF9T-0005u5-SG; Wed, 08 Apr 2020 19:10:17 +0100 Subject: Re: [PATCH] um: add a generic "fd" vector transport To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= Cc: linux-um , joerd.simons@collabora.co.uk, richard@nod.at, jdike@addtoit.com, Linux Kernel Mailing List , alex.dewar@gmx.co.uk References: <20200407202853.1791218-1-marcandre.lureau@redhat.com> <8a6dced2-886f-f8bd-aff9-3793f418cb0e@cambridgegreys.com> From: Anton Ivanov Organization: Cambridge Greys Message-ID: Date: Wed, 8 Apr 2020 19:10:15 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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 08/04/2020 18:07, Marc-André Lureau wrote: > Hi > > On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov > 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 >>> --- >>> 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; >>> } >>> >>> >> >> 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/