Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp996366ybb; Wed, 8 Apr 2020 14:13:18 -0700 (PDT) X-Google-Smtp-Source: APiQypIA/Ryb07n2vGPLN59UL6qiXMsn83tNWMmv/Zv8m+FJoVm5pvMvjbM7Kh9AqM1zhfA5PQgM X-Received: by 2002:a4a:d746:: with SMTP id h6mr7474595oot.21.1586380398100; Wed, 08 Apr 2020 14:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586380398; cv=none; d=google.com; s=arc-20160816; b=ZLlz7oU/F1ClhZ5ZdoCpHRf5a6VEH6WNkcP7j9liVtMbhld5zn7550o3pzyORZ3cuG IlUm5MFlQ9hIMOqmPXi74m0n/DqlbYEdJzsYBjZXo66MwI4xe+85fcQEsAdFoy7e+PE0 5FgZsRubFM4YAt9QmYtQ/RuoxLh9t0o5HOxKRXfkx1c4aUcPTeAMRLaVKg7UjmkZlQsN o0W7oBnd01OhRmKHXWCvq3GDERfrxT3SrVtTYm4fueJjc0DlcvdeSqpiLzxGJC8L75As MS8068cukz1CfC+ixcyS0vxFNxvI70hzUeEtWRdBvLnJOjTNgznUexun5PFfMQ1pyhFw HDdA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=831n3NNH1eOyJVeWwcK0b1hYMKlT0SmVSL68krCbNsU=; b=g85qlS813EU3D+pXTSPUrvfVcsoRm6GDzDJjr+OEHqpUIx6SUGEfu9XR3EgzHA0Ajx HVGp9633sz1n2RV9tPrQMOUqbcSBf1tGZ4pvijm5fjzzczvgozDC8cfe5l+TKVA7A7Tf +4h6DN6KJKziLTNg4lmXaewHZvCLI98NNBWNGynFhyf8xPtOugdE2v1/WSw/1H/zac66 mR3uFRQGm/rFp/HFAGvhHtsqNiB8vvdTHdeKP4lHO5fyIeiMXwRJwrCfvzs7FfZWbHhA dHg3GtfdbZvUcYQsi76mJHUGb4UXl5VO7HuYwd6DMbjkKqL09dOc9B4koPfgZF0YeOVZ lS0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fYtnQ7q7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si2529927oif.204.2020.04.08.14.13.04; Wed, 08 Apr 2020 14:13:18 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fYtnQ7q7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729439AbgDHRH7 (ORCPT + 99 others); Wed, 8 Apr 2020 13:07:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39537 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726663AbgDHRH7 (ORCPT ); Wed, 8 Apr 2020 13:07:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586365678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=831n3NNH1eOyJVeWwcK0b1hYMKlT0SmVSL68krCbNsU=; b=fYtnQ7q7TC3yLE5fEYOVY9F7beAgGr42MM+uoMj+iD+e6EuULAsGNVzbq9dvwMGhFiTKAN GjNejQU9Pm4yuKbgglxu51Mm1HAMmW+TcmCmxHOWjkq0xGIc3Ow75gD8aBN+x8Db+TA5XJ kdoWare79tWzm4YV+kfX1R+59+3zu+g= Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-GFrqFxbHMQ2INrZ7SzVn_Q-1; Wed, 08 Apr 2020 13:07:54 -0400 X-MC-Unique: GFrqFxbHMQ2INrZ7SzVn_Q-1 Received: by mail-il1-f200.google.com with SMTP id a79so7398953ill.19 for ; Wed, 08 Apr 2020 10:07:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=831n3NNH1eOyJVeWwcK0b1hYMKlT0SmVSL68krCbNsU=; b=li6NuvVmNsOU68trtwnnYnlJ8UFD0MGMPipDUTyB82+//EoB4lpAi3OBd+lDiOhztL vRU3EtF9k3e5VABMLtf32S15wv9Ze0GidosTVJt79pdk7DvXXYI9brTN7lwjxdu0ZVHp M2Dj0AOdGqC1TjcRijaylpq4X/SZ2xsDQnjwNpOemoFT+ocCxzeCld8YioTS9aQ3IRe8 IZS+A6V7IPLRX8x3npiV2XSAQVWrcuzX3OujdG8Lk2pbWrq465R1J/EpbmJ3ZjlS3axY /C9nqfrWqh35k4kvdXoazH6y3v8x9TP3v8V1W3fpNK0HSj5RPDZ9Ii4mCjYeOOlGNalv leiQ== X-Gm-Message-State: AGi0PubaA/3SvdrSIxrkfCtIrkvSNsV5nopmMbpCzYPCuMU6irPJJnMt V35gur0m8ctTTABMlWA35f16EACNx1dU042vXmFZIL/jYGuoBR4pmInysUhlmFjsK+n8/+MrEDP ZEndgZ8NtdPM/ath6VD9MOO7VNhRA5VMigTQepcYj X-Received: by 2002:a02:aa93:: with SMTP id u19mr3298083jai.70.1586365673742; Wed, 08 Apr 2020 10:07:53 -0700 (PDT) X-Received: by 2002:a02:aa93:: with SMTP id u19mr3298064jai.70.1586365673393; Wed, 08 Apr 2020 10:07:53 -0700 (PDT) MIME-Version: 1.0 References: <20200407202853.1791218-1-marcandre.lureau@redhat.com> <8a6dced2-886f-f8bd-aff9-3793f418cb0e@cambridgegreys.com> In-Reply-To: <8a6dced2-886f-f8bd-aff9-3793f418cb0e@cambridgegreys.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Wed, 8 Apr 2020 19:07:42 +0200 Message-ID: Subject: Re: [PATCH] um: add a generic "fd" vector transport To: Anton Ivanov Cc: linux-um , joerd.simons@collabora.co.uk, richard@nod.at, jdike@addtoit.com, Linux Kernel Mailing List , alex.dewar@gmx.co.uk Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On Tue, Apr 7, 2020 at 11:02 PM Anton Ivanov wrote: > > On 07/04/2020 21:28, Marc-Andr=C3=A9 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=C3=A9 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_use= r.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=3D%= i" > > @@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struc= t arglist *ifspec, int id) > > return NULL; > > } > > > > +static int strtofd(const char *nptr) > > +{ > > + long fd; > > + char *endptr; > > + > > + if (nptr =3D=3D NULL) > > + return -1; > > + > > + errno =3D 0; > > + fd =3D strtol(nptr, &endptr, 10); > > + if (nptr =3D=3D endptr || > > + errno !=3D 0 || > > + *endptr !=3D '\0' || > > + fd < 0 || > > + fd > INT_MAX) { > > + return -1; > > + } > > + return fd; > > +} > > + > > +static struct vector_fds *user_init_fd_fds(struct arglist *ifspec) > > +{ > > + int fd =3D -1; > > + char *fdarg =3D NULL; > > + struct vector_fds *result =3D NULL; > > + > > + fdarg =3D uml_vector_fetch_arg(ifspec, "fd"); > > + fd =3D strtofd(fdarg); > > + if (fd =3D=3D -1) { > > + printk(UM_KERN_ERR "fd open: bad or missing fd argument")= ; > > + goto fd_cleanup; > > + } > > + > > + result =3D uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL); > > + if (result =3D=3D NULL) { > > + printk(UM_KERN_ERR "fd open: allocation failed"); > > + goto fd_cleanup; > > + } > > + > > + result->rx_fd =3D fd; > > + result->tx_fd =3D fd; > > + result->remote_addr_size =3D 0; > > + result->remote_addr =3D NULL; > > + return result; > > + > > +fd_cleanup: > > + if (fd >=3D 0) > > + os_close_file(fd); > > + if (result !=3D NULL) > > + kfree(result); > > + return NULL; > > +} > > + > > static struct vector_fds *user_init_raw_fds(struct arglist *ifspec) > > { > > int rxfd =3D -1, txfd =3D -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) =3D=3D 0) > > return user_init_unix_fds(parsed, ID_BESS); > > + if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) =3D=3D 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=3Dfd,fd=3DN,vec=3D0 > > -- > Anton R. Ivanov > Cambridgegreys Limited. Registered in England. Company Number 10273661 > https://www.cambridgegreys.com/ >