From patchwork Fri Jun 14 16:30:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13698951 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB91D1A2FDF; Fri, 14 Jun 2024 16:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382655; cv=none; b=VVE8JFNeUmsgOkRW+vZwouiUMGGIu4Igzy5dvtbdVPD4fYOHOkJe9uZOXk1W08s+nDTPXr8vvKbJXwqyLFZrWtLFGCVuAxaeg6dOXUc0wPX/9i05M9ONvEY91Y7Y4g6SdoKZuuLN7VP7a+/vn843I83ZCPRQt8MZ/2Rmg8RKKUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382655; c=relaxed/simple; bh=KJUTQ5e5knyD5SNwjIzJ1iA9VAbMzTa8qYYjBswQIPQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uyI1Xv8bIK2jH/J1xB3tiTRcsiMkqyMO5q1hxqmzxlI583J5BqVLoft8H25WMvM3efMek4bCAwardfEWpgxqiviY1kGqXGvMm0Uf4kMyjLzVI0QQrb8eFToRoWykIYLWN5cVw80Ia2RaabxQT45Klvfy71sirvj5+B0XHQKcsZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WpfI1Oke; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=2NZ3Ygj5; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WpfI1Oke; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=2NZ3Ygj5; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WpfI1Oke"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="2NZ3Ygj5"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WpfI1Oke"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="2NZ3Ygj5" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AB750206A0; Fri, 14 Jun 2024 16:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mDenGiS4mqkZjRoBJtdVazrDHVboB46YT+YEJgnd3hc=; b=WpfI1OkeL+SwhCF7JVwhBZHQHFWk+YYuSy7TRfwIT+T7RQBGhk9UvzUPACqEBID9RbLWf/ ghS6I3jetgf4DMkPgGC/HH5tio+NPfBG9pi86dCrKmSwod7Tk8nJPol5e3tQY3Q3ikqKPx axnH/3M5ZxpEu1N+5oIJDu1D1sUOeBU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mDenGiS4mqkZjRoBJtdVazrDHVboB46YT+YEJgnd3hc=; b=2NZ3Ygj5aCpxI/PSa/jPzgVOz9ZDhOd7sbc2q00JwODs9az/3xdMPCVmi/Xp1TLqPHNKen AB8h5fkgGYMJIYCw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=WpfI1Oke; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=2NZ3Ygj5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mDenGiS4mqkZjRoBJtdVazrDHVboB46YT+YEJgnd3hc=; b=WpfI1OkeL+SwhCF7JVwhBZHQHFWk+YYuSy7TRfwIT+T7RQBGhk9UvzUPACqEBID9RbLWf/ ghS6I3jetgf4DMkPgGC/HH5tio+NPfBG9pi86dCrKmSwod7Tk8nJPol5e3tQY3Q3ikqKPx axnH/3M5ZxpEu1N+5oIJDu1D1sUOeBU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mDenGiS4mqkZjRoBJtdVazrDHVboB46YT+YEJgnd3hc=; b=2NZ3Ygj5aCpxI/PSa/jPzgVOz9ZDhOd7sbc2q00JwODs9az/3xdMPCVmi/Xp1TLqPHNKen AB8h5fkgGYMJIYCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7095613AAF; Fri, 14 Jun 2024 16:30:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IM8uFTtwbGa7cwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 16:30:51 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Date: Fri, 14 Jun 2024 12:30:44 -0400 Message-ID: <20240614163047.31581-1-krisman@suse.de> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: AB750206A0 X-Spam-Score: -3.01 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Patchwork-Delegate: kuba@kernel.org io_uring holds a reference to the file and maintains a sockaddr_storage address. Similarly to what was done to __sys_connect_file, split an internal helper for __sys_bind in preparation to supporting an io_uring bind command. Reviewed-by: Jens Axboe Signed-off-by: Gabriel Krisman Bertazi Reviewed-by: Kuniyuki Iwashima Acked-by: Jakub Kicinski --- include/linux/socket.h | 2 ++ net/socket.c | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index 89d16b90370b..b3000f49e9f5 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -442,6 +442,8 @@ extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr, extern int __sys_socket(int family, int type, int protocol); extern struct file *__sys_socket_file(int family, int type, int protocol); extern int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen); +extern int __sys_bind_socket(struct socket *sock, struct sockaddr_storage *address, + int addrlen); extern int __sys_connect_file(struct file *file, struct sockaddr_storage *addr, int addrlen, int file_flags); extern int __sys_connect(int fd, struct sockaddr __user *uservaddr, diff --git a/net/socket.c b/net/socket.c index e416920e9399..fd0714e10ced 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1822,6 +1822,20 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol, return __sys_socketpair(family, type, protocol, usockvec); } +int __sys_bind_socket(struct socket *sock, struct sockaddr_storage *address, + int addrlen) +{ + int err; + + err = security_socket_bind(sock, (struct sockaddr *)address, + addrlen); + if (!err) + err = READ_ONCE(sock->ops)->bind(sock, + (struct sockaddr *)address, + addrlen); + return err; +} + /* * Bind a name to a socket. Nothing much to do here since it's * the protocol's responsibility to handle the local address. @@ -1839,15 +1853,8 @@ int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen) sock = sockfd_lookup_light(fd, &err, &fput_needed); if (sock) { err = move_addr_to_kernel(umyaddr, addrlen, &address); - if (!err) { - err = security_socket_bind(sock, - (struct sockaddr *)&address, - addrlen); - if (!err) - err = READ_ONCE(sock->ops)->bind(sock, - (struct sockaddr *) - &address, addrlen); - } + if (!err) + err = __sys_bind_socket(sock, &address, addrlen); fput_light(sock->file, fput_needed); } return err; From patchwork Fri Jun 14 16:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13698952 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FD071AB53D; Fri, 14 Jun 2024 16:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382657; cv=none; b=HHqelC5CGQCdQAWJLWPW8WR0rVBiwR4/TZ92WQk8W8oA7kWwce67gmlT+2QCKic79QFo98cc8V6qhiZVpyxECoJQPwaAPtqBrptu/7VSajAMMsJUX06nHYiFn37hB1HndfndX5ZFuj5RYXf4SP0k4w11ETJsULFxmF2JZ8Wp7cY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382657; c=relaxed/simple; bh=8OQaVnOf6Lrs8SXGQx+ICnX7DrUjQ/CEO83HF+rrb/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RskApCwQ843dvQ7x2T5DxB+QBueT79BQcZATsYq5hP+NKguuRFbHCBTp6dx6fqrj7jnWWf+MhmY6rj6EavuoxB/anKpCXGo7M0W68tavBLBuHIUCl39bhCR338kX2JLs+3ODzy7AfucankTJknvpQ7kkLSbulP2lzoTHTZoOsRw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=hSjM9aTT; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+5ApCs4Q; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=hSjM9aTT; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+5ApCs4Q; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hSjM9aTT"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+5ApCs4Q"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="hSjM9aTT"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+5ApCs4Q" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 607F433972; Fri, 14 Jun 2024 16:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cx8yWo9oN9pFHj/SsQFr91uiuZoriXFK39ouBxCXtRU=; b=hSjM9aTTx0kfTSUhkdU/JI9erRkwTwvTsW4fTLqtJvdd9eagjFnnOMzIyOy8dMBlK3wdMb w1OZm1cmw0o4NmqNwN7WjZydrsun70N42SLzqdqI5vpd508rGB9Obk87tl12Qy+2htuEye o9fMu3kK5FH9m5Xbp4X/986beupNlcg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cx8yWo9oN9pFHj/SsQFr91uiuZoriXFK39ouBxCXtRU=; b=+5ApCs4Qx7FtQXu7UjSsWjZVDiC8NMtj5RTVpr/QnZEhWXduSEdYB58qgV21WGK6LNzZ94 HLYzlKiBZxm2lhAw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hSjM9aTT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=+5ApCs4Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cx8yWo9oN9pFHj/SsQFr91uiuZoriXFK39ouBxCXtRU=; b=hSjM9aTTx0kfTSUhkdU/JI9erRkwTwvTsW4fTLqtJvdd9eagjFnnOMzIyOy8dMBlK3wdMb w1OZm1cmw0o4NmqNwN7WjZydrsun70N42SLzqdqI5vpd508rGB9Obk87tl12Qy+2htuEye o9fMu3kK5FH9m5Xbp4X/986beupNlcg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cx8yWo9oN9pFHj/SsQFr91uiuZoriXFK39ouBxCXtRU=; b=+5ApCs4Qx7FtQXu7UjSsWjZVDiC8NMtj5RTVpr/QnZEhWXduSEdYB58qgV21WGK6LNzZ94 HLYzlKiBZxm2lhAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 22A6713AAF; Fri, 14 Jun 2024 16:30:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id JlCsAT1wbGa/cwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 16:30:53 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v2 2/4] net: Split a __sys_listen helper for io_uring Date: Fri, 14 Jun 2024 12:30:45 -0400 Message-ID: <20240614163047.31581-2-krisman@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614163047.31581-1-krisman@suse.de> References: <20240614163047.31581-1-krisman@suse.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 607F433972 X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: X-Patchwork-Delegate: kuba@kernel.org io_uring holds a reference to the file and maintains a sockaddr_storage address. Similarly to what was done to __sys_connect_file, split an internal helper for __sys_listen in preparation to support an io_uring listen command. Reviewed-by: Jens Axboe Signed-off-by: Gabriel Krisman Bertazi Reviewed-by: Kuniyuki Iwashima Acked-by: Jakub Kicinski --- include/linux/socket.h | 1 + net/socket.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index b3000f49e9f5..c1f16cdab677 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -449,6 +449,7 @@ extern int __sys_connect_file(struct file *file, struct sockaddr_storage *addr, extern int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen); extern int __sys_listen(int fd, int backlog); +extern int __sys_listen_socket(struct socket *sock, int backlog); extern int __sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); extern int __sys_getpeername(int fd, struct sockaddr __user *usockaddr, diff --git a/net/socket.c b/net/socket.c index fd0714e10ced..fcbdd5bc47ac 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1870,23 +1870,28 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen) * necessary for a listen, and if that works, we mark the socket as * ready for listening. */ +int __sys_listen_socket(struct socket *sock, int backlog) +{ + int somaxconn, err; + + somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn); + if ((unsigned int)backlog > somaxconn) + backlog = somaxconn; + + err = security_socket_listen(sock, backlog); + if (!err) + err = READ_ONCE(sock->ops)->listen(sock, backlog); + return err; +} int __sys_listen(int fd, int backlog) { struct socket *sock; int err, fput_needed; - int somaxconn; sock = sockfd_lookup_light(fd, &err, &fput_needed); if (sock) { - somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn); - if ((unsigned int)backlog > somaxconn) - backlog = somaxconn; - - err = security_socket_listen(sock, backlog); - if (!err) - err = READ_ONCE(sock->ops)->listen(sock, backlog); - + err = __sys_listen_socket(sock, backlog); fput_light(sock->file, fput_needed); } return err; From patchwork Fri Jun 14 16:30:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13698953 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F09321AB90E; Fri, 14 Jun 2024 16:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382658; cv=none; b=jUPxLJSCVeFmUqYtGezgwT/eLFPRAX4DHu4vjoNO/c+FLGfJzUPxgVO36VLZjr9ZRyTU5KQDssAdT2gM5Zz3G6hkYgfA2j8WnTFxFxkLytF9NI+h7WOPCbKwnFhJNFMs5FaMjv9ILQOs9S2Qjvv5SNwQEl+7grFTLjOydJ/qtrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382658; c=relaxed/simple; bh=Cq1BPkY9jBEWEMd1nBIm2xXsuRH7ylDX1Amwb2/km9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tfJtg+aBBPCBDrjIbtyVMDdhua1tBqBwnhGbUpUQSVQicBTjLHjPjvIXXu3HXNUplnybTKLGaAkhgbJ3DJ3UxdEyiq+Qz7kyaOr5e50R+WkUfHjyOynTr/f5sP0XjFRxaPMtWCRmd2IY3WR/fbpGQDD+eDUX5NLJiVSnnovihgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WT59sI9z; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=gow4ef/x; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=WT59sI9z; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=gow4ef/x; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WT59sI9z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="gow4ef/x"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WT59sI9z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="gow4ef/x" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1236D206A5; Fri, 14 Jun 2024 16:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382655; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HkvWK7HMvwX+vbndomN45roZNAsAKWXfV5+RfpP+YrU=; b=WT59sI9z8soI34bekZZ7f1XXgchQF/pIOZYYqUkwWOkv47TuWlcY6oYO89l2pj/dZnYSP0 VXvJN8NegplQ0sA/wKwku7x9JLHyG/NWRP/YZETu3J1/gSAhub7aBIwbLSAbRjDCyPplqM ZY1qKr5XJ+Hnc+UrpWfladkQz7DBbQ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382655; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HkvWK7HMvwX+vbndomN45roZNAsAKWXfV5+RfpP+YrU=; b=gow4ef/x3PiwSmvw8Tu2Hqro3736QiTzRZY2zxIrMJmSHz/01mciudOyfh2zPlu/jF4Crd F8rdg40ba1OaxOAQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382655; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HkvWK7HMvwX+vbndomN45roZNAsAKWXfV5+RfpP+YrU=; b=WT59sI9z8soI34bekZZ7f1XXgchQF/pIOZYYqUkwWOkv47TuWlcY6oYO89l2pj/dZnYSP0 VXvJN8NegplQ0sA/wKwku7x9JLHyG/NWRP/YZETu3J1/gSAhub7aBIwbLSAbRjDCyPplqM ZY1qKr5XJ+Hnc+UrpWfladkQz7DBbQ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382655; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HkvWK7HMvwX+vbndomN45roZNAsAKWXfV5+RfpP+YrU=; b=gow4ef/x3PiwSmvw8Tu2Hqro3736QiTzRZY2zxIrMJmSHz/01mciudOyfh2zPlu/jF4Crd F8rdg40ba1OaxOAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C94AC13AAF; Fri, 14 Jun 2024 16:30:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id VpiHKj5wbGbGcwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 16:30:54 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Date: Fri, 14 Jun 2024 12:30:46 -0400 Message-ID: <20240614163047.31581-3-krisman@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614163047.31581-1-krisman@suse.de> References: <20240614163047.31581-1-krisman@suse.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email]; RCVD_TLS_ALL(0.00)[] IORING_OP_BIND provides the semantic of bind(2) via io_uring. While this is an essentially synchronous system call, the main point is to enable a network path to execute fully with io_uring registered and descriptorless files. Signed-off-by: Gabriel Krisman Bertazi --- changes since v1: - drop explocit error handling for move_addr_to_kernel (jens) - Remove empty line ahead of return; --- include/uapi/linux/io_uring.h | 1 + io_uring/net.c | 36 +++++++++++++++++++++++++++++++++++ io_uring/net.h | 3 +++ io_uring/opdef.c | 13 +++++++++++++ 4 files changed, 53 insertions(+) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 994bf7af0efe..4ef153d95c87 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -257,6 +257,7 @@ enum io_uring_op { IORING_OP_FUTEX_WAITV, IORING_OP_FIXED_FD_INSTALL, IORING_OP_FTRUNCATE, + IORING_OP_BIND, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/net.c b/io_uring/net.c index 0a48596429d9..8cbc29aff15c 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -51,6 +51,11 @@ struct io_connect { bool seen_econnaborted; }; +struct io_bind { + struct file *file; + int addr_len; +}; + struct io_sr_msg { struct file *file; union { @@ -1715,6 +1720,37 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags) return IOU_OK; } +int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind); + struct sockaddr __user *uaddr; + struct io_async_msghdr *io; + + if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in) + return -EINVAL; + + uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr)); + bind->addr_len = READ_ONCE(sqe->addr2); + + io = io_msg_alloc_async(req); + if (unlikely(!io)) + return -ENOMEM; + return move_addr_to_kernel(uaddr, bind->addr_len, &io->addr); +} + +int io_bind(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind); + struct io_async_msghdr *io = req->async_data; + int ret; + + ret = __sys_bind_socket(sock_from_file(req->file), &io->addr, bind->addr_len); + if (ret < 0) + req_set_fail(req); + io_req_set_res(req, ret, 0); + return 0; +} + void io_netmsg_cache_free(const void *entry) { struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry; diff --git a/io_uring/net.h b/io_uring/net.h index 0eb1c1920fc9..49f9a7bc1113 100644 --- a/io_uring/net.h +++ b/io_uring/net.h @@ -49,6 +49,9 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags); int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); void io_send_zc_cleanup(struct io_kiocb *req); +int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_bind(struct io_kiocb *req, unsigned int issue_flags); + void io_netmsg_cache_free(const void *entry); #else static inline void io_netmsg_cache_free(const void *entry) diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 2de5cca9504e..19ee9445f024 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -495,6 +495,16 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_ftruncate_prep, .issue = io_ftruncate, }, + [IORING_OP_BIND] = { +#if defined(CONFIG_NET) + .needs_file = 1, + .prep = io_bind_prep, + .issue = io_bind, + .async_size = sizeof(struct io_async_msghdr), +#else + .prep = io_eopnotsupp_prep, +#endif + }, }; const struct io_cold_def io_cold_defs[] = { @@ -711,6 +721,9 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_FTRUNCATE] = { .name = "FTRUNCATE", }, + [IORING_OP_BIND] = { + .name = "BIND", + }, }; const char *io_uring_get_opcode(u8 opcode) From patchwork Fri Jun 14 16:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13698954 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82BDD1ABCBE; Fri, 14 Jun 2024 16:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382660; cv=none; b=q4mJHm2hwmdYfl9ZzTXYajHlsG0SGySQFZy9CICvuiy/10MK/8RrEV+C0sXuY1kcYmzXUho0se1b/0E1G0cke+oHu+EDDU3e0M7gFYYO9UiYMNncFbZ/1P8pF2xln6JKmpRakbjKS9XeMgEj+Rmd8ocCrEj5jgdq6A0FcjC3Ri0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382660; c=relaxed/simple; bh=XKkvYpzilvAEE/2RfdhRbhpL5cY/9xwiyRLEwPWPwIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cRhQMarCJmnxi+Igt8zjrd+k4QcL+rekIimnt+2V+uIdLteqc7jXBYVi5FXA+4jngzZjz88tbK7lkKaMTLZ1KOFB8SotiQmC/30qoomusX5Cg8q9qDpYiCoKep1Nknxj9uiC5l7kRp1bVjH9QSXOxpWP5265hnHUxhGBuy1EqTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Cj8FmAYj; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=DaOjhVSX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Cj8FmAYj; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=DaOjhVSX; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Cj8FmAYj"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="DaOjhVSX"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Cj8FmAYj"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="DaOjhVSX" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AF0AF2069E; Fri, 14 Jun 2024 16:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kwq8WeoOYXAFfq4ENmQXheUFFriDONAIFF1ZwyrMatE=; b=Cj8FmAYjfaJwgcUep2VvZi+ZdpumPDMSTCD18DcxK2BlvzK2uqrcoi/2FwY1xzlQtIXCNB 3a3ld8ERwsvsVzVR2loEl04dGgQy49pte6dVZRao7WlADbO/++1kovfQ/zUHRp5evxTdw9 p/SGqdl+Y00UKy29r7Agg4o5GxgNn1Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kwq8WeoOYXAFfq4ENmQXheUFFriDONAIFF1ZwyrMatE=; b=DaOjhVSXyK5C5nsgHnlqok6wipuPy8d1+0Gl1xN0i3uqozvBxYGbWj2kjRcqXd21VVSun9 YlKFkP3BQEBmQeDw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Cj8FmAYj; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DaOjhVSX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718382656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kwq8WeoOYXAFfq4ENmQXheUFFriDONAIFF1ZwyrMatE=; b=Cj8FmAYjfaJwgcUep2VvZi+ZdpumPDMSTCD18DcxK2BlvzK2uqrcoi/2FwY1xzlQtIXCNB 3a3ld8ERwsvsVzVR2loEl04dGgQy49pte6dVZRao7WlADbO/++1kovfQ/zUHRp5evxTdw9 p/SGqdl+Y00UKy29r7Agg4o5GxgNn1Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718382656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kwq8WeoOYXAFfq4ENmQXheUFFriDONAIFF1ZwyrMatE=; b=DaOjhVSXyK5C5nsgHnlqok6wipuPy8d1+0Gl1xN0i3uqozvBxYGbWj2kjRcqXd21VVSun9 YlKFkP3BQEBmQeDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 73D2813AAF; Fri, 14 Jun 2024 16:30:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sT3IFUBwbGbIcwAAD6G6ig (envelope-from ); Fri, 14 Jun 2024 16:30:56 +0000 From: Gabriel Krisman Bertazi To: axboe@kernel.dk Cc: io-uring@vger.kernel.org, netdev@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN Date: Fri, 14 Jun 2024 12:30:47 -0400 Message-ID: <20240614163047.31581-4-krisman@suse.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240614163047.31581-1-krisman@suse.de> References: <20240614163047.31581-1-krisman@suse.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:email,suse.de:dkim]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: AF0AF2069E X-Spam-Flag: NO X-Spam-Score: -3.01 X-Spam-Level: IORING_OP_LISTEN provides the semantic of listen(2) via io_uring. While this is an essentially synchronous system call, the main point is to enable a network path to execute fully with io_uring registered and descriptorless files. Signed-off-by: Gabriel Krisman Bertazi --- changes since v1: - Drop empty lines ahead of return (Jens). --- include/uapi/linux/io_uring.h | 1 + io_uring/net.c | 28 ++++++++++++++++++++++++++++ io_uring/net.h | 3 +++ io_uring/opdef.c | 13 +++++++++++++ 4 files changed, 45 insertions(+) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 4ef153d95c87..2aaf7ee256ac 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -258,6 +258,7 @@ enum io_uring_op { IORING_OP_FIXED_FD_INSTALL, IORING_OP_FTRUNCATE, IORING_OP_BIND, + IORING_OP_LISTEN, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/net.c b/io_uring/net.c index 8cbc29aff15c..028e126ab30c 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -56,6 +56,11 @@ struct io_bind { int addr_len; }; +struct io_listen { + struct file *file; + int backlog; +}; + struct io_sr_msg { struct file *file; union { @@ -1751,6 +1756,29 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags) return 0; } +int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen); + + if (sqe->addr || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in || sqe->addr2) + return -EINVAL; + + listen->backlog = READ_ONCE(sqe->len); + return 0; +} + +int io_listen(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen); + int ret; + + ret = __sys_listen_socket(sock_from_file(req->file), listen->backlog); + if (ret < 0) + req_set_fail(req); + io_req_set_res(req, ret, 0); + return 0; +} + void io_netmsg_cache_free(const void *entry) { struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry; diff --git a/io_uring/net.h b/io_uring/net.h index 49f9a7bc1113..52bfee05f06a 100644 --- a/io_uring/net.h +++ b/io_uring/net.h @@ -52,6 +52,9 @@ void io_send_zc_cleanup(struct io_kiocb *req); int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_bind(struct io_kiocb *req, unsigned int issue_flags); +int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_listen(struct io_kiocb *req, unsigned int issue_flags); + void io_netmsg_cache_free(const void *entry); #else static inline void io_netmsg_cache_free(const void *entry) diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 19ee9445f024..7d5c51fb8e6e 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -503,6 +503,16 @@ const struct io_issue_def io_issue_defs[] = { .async_size = sizeof(struct io_async_msghdr), #else .prep = io_eopnotsupp_prep, +#endif + }, + [IORING_OP_LISTEN] = { +#if defined(CONFIG_NET) + .needs_file = 1, + .prep = io_listen_prep, + .issue = io_listen, + .async_size = sizeof(struct io_async_msghdr), +#else + .prep = io_eopnotsupp_prep, #endif }, }; @@ -724,6 +734,9 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_BIND] = { .name = "BIND", }, + [IORING_OP_LISTEN] = { + .name = "LISTEN", + }, }; const char *io_uring_get_opcode(u8 opcode)