Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4738600ybb; Tue, 7 Apr 2020 13:30:11 -0700 (PDT) X-Google-Smtp-Source: APiQypIsKkTJXOz54gaaiO1xzZXrLZBTStSnwoQY8YG81edLQfu8uThVgQHBhvRBpVG/Hup+DfKb X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr3086626otr.335.1586291410886; Tue, 07 Apr 2020 13:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586291410; cv=none; d=google.com; s=arc-20160816; b=COLdpQ1lL2g01tOqks9J3EHbg++TPEH8Wg3Y+JXPVGcYhMLCZcWVd/Wi0p6ipSTWln p+VRMHB5wyn3aGS3+E0LgW46n2D4iszulsIbcMznYAFp6RVUVWkSA4PRy8cUNUmIpeVd tZT8UcZJg8jnVpvqm5G3ceAtsXLB2qhm4ZO7+fPXdaw+kGM1s7RhbYio4zhCn/Or3j+i 8ldQVCabIh+ANKSEUWbkGLTkL5m6ciRWSMwqepnpmKXFDZhLaYJcBYhP0Gk3Wy4IgdbU sM7aEhwH2MPLvL5Wpzfwx65AXanrMHSbrnKgPViaRnrbQzWf/FQMclei3uzSnHd7uUMH jmEg== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zk1012gzAvIBdJE5HTKwuZBYt2+UO/CryxBo1Cp7uNE=; b=RcZr5W1KQU6xgb3aId2mygPYdlNqGGO93gc67e/7Pd9nqBjCddis2ViNATTwKlD+We 2uTBgcNuKU6ePq/7PEGOBOOSKyog2d+/lEEsDQGZDA2TaPhhHzVTt1dc/WwCQS2M72Py f1H8uvl2gG6NUlflolpOu5z3wzUkWC+wJOpfTIOIVIAM2LeZNXIHdTCfA/PW0AtUAkZl 1FmiHTtitnI3eVyu0Ejecq8Bk8B9egfAarBjvmtKrM3aC48rlqEeHoXCkmQuGKl00exb b6C2635biaHdo8JFAp6euLKznwtBWrrBCBNhHqeMp7SOyBOUG+FjjFTeoiGXmYnTOOas u8dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H7GjHmY1; 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 g8si1878142otn.56.2020.04.07.13.29.56; Tue, 07 Apr 2020 13:30: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H7GjHmY1; 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 S1726417AbgDGU3G (ORCPT + 99 others); Tue, 7 Apr 2020 16:29:06 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:27397 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726277AbgDGU3G (ORCPT ); Tue, 7 Apr 2020 16:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586291344; 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; bh=zk1012gzAvIBdJE5HTKwuZBYt2+UO/CryxBo1Cp7uNE=; b=H7GjHmY1QYovqS/sALIA65/ho+HHvfbZcVMycDaibUm/iE5cVV3oKFQ7PV8d4PgWrjlSN+ AmzT6Jhf/NJVxvS4sMU6VE990taeHrGC/s+j0NE3r/wvUKsf7jEbY9+s+4uQbzVoqu1BO3 JEnWGco950qe5JPquMZtT6RYHHzQrNA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-PEd1Lrc8Mm2hyfvy8GwhLw-1; Tue, 07 Apr 2020 16:29:00 -0400 X-MC-Unique: PEd1Lrc8Mm2hyfvy8GwhLw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92247800D50; Tue, 7 Apr 2020 20:28:58 +0000 (UTC) Received: from localhost (unknown [10.36.110.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7D001BC6D; Tue, 7 Apr 2020 20:28:54 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-um@lists.infradead.org Cc: linux-kernel@vger.kernel.org, joerd.simons@collabora.co.uk, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com, alex.dewar@gmx.co.uk, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH] um: add a generic "fd" vector transport Date: Tue, 7 Apr 2020 22:28:53 +0200 Message-Id: <20200407202853.1791218-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_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" =20 @@ -42,6 +43,9 @@ #define TRANS_RAW "raw" #define TRANS_RAW_LEN strlen(TRANS_RAW) =20 +#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(struct = arglist *ifspec, int id) return NULL; } =20 +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; } =20 --=20 2.26.0.106.g9fadedd637