Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5471659pxv; Wed, 7 Jul 2021 04:42:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHl/T0ldPRSfOFRHgBO2c0Z8dtHfgpmJBhPG8TPTHxQO7FhiU4bIZysyJ/SpwM9T2ZrvyD X-Received: by 2002:a92:ca8f:: with SMTP id t15mr3940607ilo.262.1625658158870; Wed, 07 Jul 2021 04:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625658158; cv=none; d=google.com; s=arc-20160816; b=hCWmJ5FWRboddWj3RH9hbLhM9g+5p4I94ldz/3EJQWCZGJyLwjRgkQwH/e2uwuPxlM 2eKfK27Pj6j76k2SnGR93aUKrWmCsjG7k+DUf+IHig4KDOFQe+GC9IYYtRyXC+kkfPuh 0HhT+GeCVxxfmlPJVxBtQ9UqfXFez3hK/KNdXHomM0xg8zlfDE/J3awau9Osp4M3xzt5 4hQ+7/1xbhU3SOI0nZl3ETUZnx7chKnboS52cN1CM7GR6Ml10eze+Ni0ZNqGYKQUQT36 YKeeAjLcXtz2J65kyopkB8UxB4yMQnMUK47D4Soc+XdeZVwRSHhiPbcecVJ+X+77oNus /Qwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SjCPjtxsD7x8AhV/ce/R0ldaWbBbErIon5fucvDcAwE=; b=nsw0E3hgM7/OLClcsZfrh15dgoko2JTPXYg92V/D09OVXqTHPGpeq7jpwNfOKgP1J8 JTiYIfg3w9LpsgxWZ+dVhGKdLosFTm46t+526nPdcc8RHZuY2AESsU1/8eyZm/8VWKYf 1KKkuR/yXZb4GkI2wb4WPoimuOf5s/tZQNJXlfKEF+QfbcVCAZ1uyy2vuOT7T1QlesxT tVB6kBAakEbn4fLJTn/23G3MP0yNNNizE+HQ2m+uwWSPtG3oHkVP/NT+a/veYvehepjt Bio/JSZcudt8Gm0tGWrZj3bK2Ka80P+z8DeaY2tzO9o+wLIO935MZXQx6+Tul7dJrRCo fPTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ueaVWLeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si19914614ilt.27.2021.07.07.04.42.26; Wed, 07 Jul 2021 04:42:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ueaVWLeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbhGGLnO (ORCPT + 99 others); Wed, 7 Jul 2021 07:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbhGGLnB (ORCPT ); Wed, 7 Jul 2021 07:43:01 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBEFC061574; Wed, 7 Jul 2021 04:40:20 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t6so2667467wrm.9; Wed, 07 Jul 2021 04:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SjCPjtxsD7x8AhV/ce/R0ldaWbBbErIon5fucvDcAwE=; b=ueaVWLeB2tT5vn1d5Ycrggbk01HiU0EeCp6+WRfAFR7CbfGVsoNdg5qMI2/xxukzdt taZcicT/jA6fWn5me8Q3RODQyvPB3Mdiv3umhpbQ42sTlzvVJaPkBs56xJ1ESCKrAAMO b2++HLpJaEv4hflgKY8Z9YUp6QVZWXys6qssFIF6d1o/u8i3lH20zcEboBWc8MnVfSLa XBYx1KC50Zq0JeZic+F1OiVzv5eX6TkDNluBBz/VDavmu7XHDr4I63klnQ2D/JCmzzlS VTdsvhjMdCC6UQPEyirHcKuTlU9xXN7WHO/D5dM0fFxbxKL7f+qoEV8V//+wT0rmwQgw EKaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SjCPjtxsD7x8AhV/ce/R0ldaWbBbErIon5fucvDcAwE=; b=qrmrxnHNeJPv9hRF5ziS4rh1g9e+FrKIdr8gIZBM8Xf//G49zUi9y4cdiKJxzoI5X9 0GO0027K0E0aciq9mmGZnZs7XTi2xT6RTHz6QOTlnvyQXFcJBFJg5D7tLNmnDetXpyaQ IT6bBKkvp9bFe9Z0V2XUyBADsgrXlQA8mx2YU9o0WQfWGW/U+uVZVt/RXVGi1t/eQCpa kFPNxVZzLxtMY7vEZ00p5cHZVt4OVPt4XtKVZjwXLFhNbsmox3OHRRjjOR/eKBEn/mUn ydXZqVLTwZ2DBurb+yr0AobJjmUKfypEGa0lgBsV8wL20LVQcLTyNVTHAM2QwdC38lLi Qxlg== X-Gm-Message-State: AOAM531ZTLNoOLmzwF4RlDT8N+sRS2cT7X/2KXz6/JhKLM/Q10ojlJtM csHdSDBVmt6T4VDIDZKYPjU= X-Received: by 2002:a5d:4001:: with SMTP id n1mr27826764wrp.159.1625658019235; Wed, 07 Jul 2021 04:40:19 -0700 (PDT) Received: from localhost.localdomain ([85.255.234.206]) by smtp.gmail.com with ESMTPSA id p9sm18415790wmm.17.2021.07.07.04.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 04:40:18 -0700 (PDT) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 4/4] io_uring: accept directly into fixed file table Date: Wed, 7 Jul 2021 12:39:46 +0100 Message-Id: <1a57d821f6f3c35aef26316febe70e16f39f7c7d.1625657451.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As done with open opcodes, allow accept to skip installing fd into processes' file tables and put it directly into io_uring's fixed file table. Same restrictions and design as for open. Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index fd0dcee251b0..f7db43bf7dad 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4675,14 +4675,17 @@ static int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) return -EINVAL; - if (sqe->ioprio || sqe->len || sqe->buf_index) + if (sqe->ioprio || sqe->len) return -EINVAL; accept->addr = u64_to_user_ptr(READ_ONCE(sqe->addr)); accept->addr_len = u64_to_user_ptr(READ_ONCE(sqe->addr2)); accept->flags = READ_ONCE(sqe->accept_flags); accept->nofile = rlimit(RLIMIT_NOFILE); + req->buf_index = READ_ONCE(sqe->file_index); + if (req->buf_index && (accept->flags & SOCK_CLOEXEC)) + return -EINVAL; if (accept->flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) return -EINVAL; if (SOCK_NONBLOCK != O_NONBLOCK && (accept->flags & SOCK_NONBLOCK)) @@ -4695,28 +4698,34 @@ static int io_accept(struct io_kiocb *req, unsigned int issue_flags) struct io_accept *accept = &req->accept; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; unsigned int file_flags = force_nonblock ? O_NONBLOCK : 0; + bool fixed = !!req->buf_index; struct file *file; int ret, fd; if (req->file->f_flags & O_NONBLOCK) req->flags |= REQ_F_NOWAIT; - fd = __get_unused_fd_flags(accept->flags, accept->nofile); - if (unlikely(fd < 0)) - return fd; - + if (!fixed) { + fd = __get_unused_fd_flags(accept->flags, accept->nofile); + if (unlikely(fd < 0)) + return fd; + } file = do_accept(req->file, file_flags, accept->addr, accept->addr_len, accept->flags); if (IS_ERR(file)) { + if (!fixed) + put_unused_fd(fd); ret = PTR_ERR(file); if (ret == -EAGAIN && force_nonblock) return -EAGAIN; if (ret == -ERESTARTSYS) ret = -EINTR; req_set_fail(req); - } else { + } else if (!fixed) { fd_install(fd, file); ret = fd; + } else { + ret = io_install_fixed_file(req, file, issue_flags); } __io_req_complete(req, issue_flags, ret, 0); return 0; -- 2.32.0