From patchwork Tue Oct 22 14:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13845755 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 975E219F49C for ; Tue, 22 Oct 2024 14:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608163; cv=none; b=Lw8xxQphnsvDS5c3o1BCP/G/vKrpTbOLOuSm4yTjn43qpGNhlvIRu6dwSXo8BB4BiSy47v+dF6lV5NUxFUNpWsYq0EfhAi2L4siTtuOG8m1IpGyi8ko55OsugRhSPnyCwPzNz4vpGayUMc56GnN0pveQ86tSCr3E/gsZ4TssJ1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608163; c=relaxed/simple; bh=zo67mh1Ly5UEzDhVcNMP+SHJydfD6O6ctYKMF36dCQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=izL+CG4zee3zMbP11bEZJor4zIrpnC11aZc8yIP+sF9pYRdNvPpr94jJj1G7Lskel9GFGFPDUlOtrf07/R1O8QEKoyvaItWzlGQ9UgEdqAtbfNEeuLldJC3GPQDJ6ZFA/t8VEkG/LZ/J7ltHtlyxqbbg7AynytS74J9/+nrXMxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gV/wlwMC; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gV/wlwMC" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-539f6e1f756so6718266e87.0 for ; Tue, 22 Oct 2024 07:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729608159; x=1730212959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FzZHrLjrLlvB9EEo5Dak1GHSP1+/EWxQ9nQuugpqVf0=; b=gV/wlwMC95lR1x1JTE54PenbHJbyXXQ/blzBRc6wE+Gyl8mjos+QMiRICYFESFxjb7 3eQaKNQyZfSG3F5OT2v5l+dEI+pFRpuY1P4W/xoMWYo/rL14RWd0El+iSelREdOKYyq9 7m89mJRkB1eEyZ4HJP0xynccIRUi6Yj0xO13u4i56KRjo0PT0oJQHuIylIPxU9rRUUVn tz++QoojOIdRH+Urfxy2JI2jLx/vE7P/ypxN7e/53S24q0V6V3FYonyJ+bFiNYP857rd wwTqRAbX6VCbuMYcDKc/em+O799TnWpvhpb01z3XXW8vflJ4UcPynIs15SdNBftbUsAg 9VWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729608159; x=1730212959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzZHrLjrLlvB9EEo5Dak1GHSP1+/EWxQ9nQuugpqVf0=; b=AcNmDKLjM7t1+xEWDs0LswCtXYhu8L8auaZkA0Tjls3440QtzbQu6XZIUdLjQpbhZ1 41EWXGeil2rlXUyL9NSamP3zrfThBe0HJfLQNei0Aa5INO+eLF90yOLTluYm7RJCnS6O V8BFZj0C9KWAjaugnzy1cyDoU5EsGctjcCVqBxv1tMGIPGc5LKO3lJy3qAz1IWqgOAPP h4YUkSEWews0VTXUpAYNm6VrhU+rn+msu1JfIRstFh4MN7eWFwthnvctv+fjHXinzNj4 C9ZjEmI6sTawEqzIPxlkhnZKwYV6l8yEeCsvjkGjbOsZWU3mCBDS6B+5OrwA04JD1+DS o8+w== X-Gm-Message-State: AOJu0Yyk4uT9lH6HDiZ2c98XmTaBRUkP7GeWVis4kFIlT3dgCyoWViXg A+tHI5n8jD8kIzg9YEoH66tSkWZJcNkDbkYpTK3GJHl1ovWV1/SaRADRFw== X-Google-Smtp-Source: AGHT+IGvfavFHKpFawj3zMe/2+N1uJHK4LuyzEBFO+BTWGKck6DNboONspGJLDEgLqcbt5WbkrOwmg== X-Received: by 2002:a05:6512:1304:b0:539:fa43:fc36 with SMTP id 2adb3069b0e04-53a1520b1d2mr8144089e87.12.1729608159120; Tue, 22 Oct 2024 07:42:39 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.141.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb6696b631sm3244434a12.9.2024.10.22.07.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 07:42:38 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 1/4] io_uring/net: split send and sendmsg prep helpers Date: Tue, 22 Oct 2024 15:43:12 +0100 Message-ID: <1a2319471ba040e053b7f1d22f4af510d1118eca.1729607201.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A preparation patch splitting io_sendmsg_prep_setup into two separate helpers for send and sendmsg variants. Signed-off-by: Pavel Begunkov --- io_uring/net.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 18507658a921..cfe467f9e19f 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -384,16 +384,11 @@ static int io_send_setup(struct io_kiocb *req) return 0; } -static int io_sendmsg_prep_setup(struct io_kiocb *req, int is_msg) +static int io_sendmsg_setup(struct io_kiocb *req) { - struct io_async_msghdr *kmsg; + struct io_async_msghdr *kmsg = req->async_data; int ret; - kmsg = io_msg_alloc_async(req); - if (unlikely(!kmsg)) - return -ENOMEM; - if (!is_msg) - return io_send_setup(req); ret = io_sendmsg_copy_hdr(req, kmsg); if (!ret) req->flags |= REQ_F_NEED_CLEANUP; @@ -439,7 +434,11 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (req->ctx->compat) sr->msg_flags |= MSG_CMSG_COMPAT; #endif - return io_sendmsg_prep_setup(req, req->opcode == IORING_OP_SENDMSG); + if (unlikely(!io_msg_alloc_async(req))) + return -ENOMEM; + if (req->opcode != IORING_OP_SENDMSG) + return io_send_setup(req); + return io_sendmsg_setup(req); } static void io_req_msg_cleanup(struct io_kiocb *req, @@ -1286,7 +1285,11 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (req->ctx->compat) zc->msg_flags |= MSG_CMSG_COMPAT; #endif - return io_sendmsg_prep_setup(req, req->opcode == IORING_OP_SENDMSG_ZC); + if (unlikely(!io_msg_alloc_async(req))) + return -ENOMEM; + if (req->opcode != IORING_OP_SENDMSG_ZC) + return io_send_setup(req); + return io_sendmsg_setup(req); } static int io_sg_from_iter_iovec(struct sk_buff *skb, From patchwork Tue Oct 22 14:43:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13845756 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 EF937199248 for ; Tue, 22 Oct 2024 14:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608164; cv=none; b=O/5YuzjxfMGlJXQcpiOlpUYrH4hTUPKigo6pEoN4AVzP/sQLBhp0VWlHnNI8smVw3PgpvOD8girW91pKjvpf8EszVcX2DXSoh2iTOFDGAq7gHuh1Y8hJ+1PXQFbkRjG9jmdONBVonF2SEzd9RcFwjvOYlQ93WwIqtZYuxi+nGNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608164; c=relaxed/simple; bh=okB6g+p4pcTttNUIMEH61K9UOYH9zmoDEyECFLDp8Ew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uORmQwuEa820rcnZwg8uynxMMKcLKjvOBKob1firGbIvHAHS9dE6RqNrVkzCF4fLKVkqJN03+4/U5nv4A4ByQeqrDP4aBs6Kd2SP41boIRo20gzii4Ko7MkX3c2A8LBrnFU7346GzYZeDz6/Al45zg1xA2qsz/MnfOJOtqG6tUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LQgL0uq3; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LQgL0uq3" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a99fa009adcso321916366b.0 for ; Tue, 22 Oct 2024 07:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729608161; x=1730212961; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6rDvifaxatM+jj6SeF3/kFKoJFAV3SEh+iogj0f3cY0=; b=LQgL0uq3Hm6TTvFS7bjRVjNEpnCBXTzE1BbXJtFSLRW1CYMXjUOZ5loMI0xl5D/sGG jLB7gMw6LMUUOMLS99Fbu5vgSWB4i1zvTXmIZWctjphiNoZBdtphGTucHy1RHKBQxS1Y 2umKbvhRoLa78YkPdP/BlFsuAqPbfFzbZQ6grUyg6Tt6XN3m9u9asaj5JFPtNPDWaXKE 4wmH4pi0jCwOoVt7Zy1/ztOBUJWtHkTruD+AivxsS0uMfRVthV192enRv6DpsslnrX2t YP2IvDtJ93LVnwCYZW0EZ23vTqpDuCilw5Pl4UOtjlQGHoeLsCvV5qXwpX+dA9njRAcy DYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729608161; x=1730212961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6rDvifaxatM+jj6SeF3/kFKoJFAV3SEh+iogj0f3cY0=; b=Tk2Prrl/ME2YPifDsdk78kfK/jdNiiVwuGgW1GLiQcxPxfbxiBD1isOW0sbFzmS1nq zBDX3C24EC5egz6qoMtXK8LuS9PVmiv847+D3YowFwuj1sc9OW2AAcs4/u85zTq2p2CK LNdlHS5w/9T/WzLtZzQBlwH8e8/jB+yW/Z7kRqz4zFs2T+DDjr9Ws3nVK6ccIhFXo/u0 KMhnLWhu/cknIPNrMg8TRvwM8aAi8fzvuWXho2PyEZfeQ4cOKxwB7+iiJp4XeKC9DybU /mzjyQdddxv5TpIx4bs1Dj9DdbTjRO6wXr0dw5F9a+fo83PmZKtY1YQAyXgkwQqqm3EO yRxw== X-Gm-Message-State: AOJu0YzgoXZ+gdKGQHLi5a9Ofxyh/rP5B2+8Oe+3i7Q9l4I+XuuyqUuL 6G/3dibTlUTEmxVM+3P6X3A831vtoK6tzuFMWiwBvXOtgvAhhUMioXb/KQ== X-Google-Smtp-Source: AGHT+IE6QYzDt/KPaWV4bHCcRedEX5ukWtjFtVw0F/Ycr9LTFqlULfFE2kOyJnJlUs9k5zxdOioChg== X-Received: by 2002:a05:6402:d06:b0:5ca:ef8:bff8 with SMTP id 4fb4d7f45d1cf-5ca0ef8c061mr12994385a12.33.1729608160709; Tue, 22 Oct 2024 07:42:40 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.141.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb6696b631sm3244434a12.9.2024.10.22.07.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 07:42:39 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 2/4] io_uring/net: don't store send address ptr Date: Tue, 22 Oct 2024 15:43:13 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For non "msg" requests we copy the address at the prep stage and there is no need to store the address user pointer long term. Pass the SQE into io_send_setup(), let it parse it, and remove struct io_sr_msg addr addr_len fields. It saves some space and also less confusing. Signed-off-by: Pavel Begunkov --- io_uring/net.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index cfe467f9e19f..4d928017ed2a 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -74,9 +74,7 @@ struct io_sr_msg { unsigned nr_multishot_loops; u16 flags; /* initialised and used only by !msg send variants */ - u16 addr_len; u16 buf_group; - void __user *addr; void __user *msg_control; /* used only for send zerocopy */ struct io_kiocb *notif; @@ -356,24 +354,31 @@ void io_sendmsg_recvmsg_cleanup(struct io_kiocb *req) io_netmsg_iovec_free(io); } -static int io_send_setup(struct io_kiocb *req) +static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); struct io_async_msghdr *kmsg = req->async_data; + void __user *addr; + u16 addr_len; int ret; + if (READ_ONCE(sqe->__pad3[0])) + return -EINVAL; + kmsg->msg.msg_name = NULL; kmsg->msg.msg_namelen = 0; kmsg->msg.msg_control = NULL; kmsg->msg.msg_controllen = 0; kmsg->msg.msg_ubuf = NULL; - if (sr->addr) { - ret = move_addr_to_kernel(sr->addr, sr->addr_len, &kmsg->addr); + addr = u64_to_user_ptr(READ_ONCE(sqe->addr2)); + addr_len = READ_ONCE(sqe->addr_len); + if (addr) { + ret = move_addr_to_kernel(addr, addr_len, &kmsg->addr); if (unlikely(ret < 0)) return ret; kmsg->msg.msg_name = &kmsg->addr; - kmsg->msg.msg_namelen = sr->addr_len; + kmsg->msg.msg_namelen = addr_len; } if (!io_do_buffer_select(req)) { ret = import_ubuf(ITER_SOURCE, sr->buf, sr->len, @@ -403,13 +408,9 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) sr->done_io = 0; - if (req->opcode == IORING_OP_SEND) { - if (READ_ONCE(sqe->__pad3[0])) + if (req->opcode != IORING_OP_SEND) { + if (sqe->addr2 || sqe->file_index) return -EINVAL; - sr->addr = u64_to_user_ptr(READ_ONCE(sqe->addr2)); - sr->addr_len = READ_ONCE(sqe->addr_len); - } else if (sqe->addr2 || sqe->file_index) { - return -EINVAL; } sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr)); @@ -437,7 +438,7 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (unlikely(!io_msg_alloc_async(req))) return -ENOMEM; if (req->opcode != IORING_OP_SENDMSG) - return io_send_setup(req); + return io_send_setup(req, sqe); return io_sendmsg_setup(req); } @@ -1263,12 +1264,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) io_req_set_rsrc_node(notif, ctx, 0); } - if (req->opcode == IORING_OP_SEND_ZC) { - if (READ_ONCE(sqe->__pad3[0])) - return -EINVAL; - zc->addr = u64_to_user_ptr(READ_ONCE(sqe->addr2)); - zc->addr_len = READ_ONCE(sqe->addr_len); - } else { + if (req->opcode != IORING_OP_SEND_ZC) { if (unlikely(sqe->addr2 || sqe->file_index)) return -EINVAL; if (unlikely(zc->flags & IORING_RECVSEND_FIXED_BUF)) @@ -1288,7 +1284,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (unlikely(!io_msg_alloc_async(req))) return -ENOMEM; if (req->opcode != IORING_OP_SENDMSG_ZC) - return io_send_setup(req); + return io_send_setup(req, sqe); return io_sendmsg_setup(req); } From patchwork Tue Oct 22 14:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13845757 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 258D919F49C for ; Tue, 22 Oct 2024 14:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608165; cv=none; b=PoRSUlyagC4iG/de1P0auuzuE2xs09qkLeRV3HQyYt5GMYMt2ogR9TYtW9WIjSN99tqZR3xGxIwoiuvlfPvh8Kow9mb3Gct4fhMWvdMP6XAPVe9iqR6veatEYIjF99gCqNNfMtXJ4ZCRHJrIssUsM78dt3IJAuxV8M9KyeopeR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608165; c=relaxed/simple; bh=rNGJWymqGy0BJzwu0qxFxqk0iOJl3vElePVs0FY1LaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ChLM3PlPPmcSLoYFOl4eNbZcmPFsxKAjmVaW/d77fAzosqTp2ztneFUh47U/U9FMR1ka4EwMXTn4E/kHhAi4fs45Ecz7h2q2Z+5VH36S8+FvQfbBm8VBNQO01/fUp2su/I/4a58XhizzPyA4kO7EBIAanfLTXpDzbMM7pbTCemc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J2Nd4df+; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J2Nd4df+" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5c40aea5c40so1896032a12.0 for ; Tue, 22 Oct 2024 07:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729608162; x=1730212962; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F5lAwpEciN4YcPMS8u5Za8JEhBJIL0rRq0tPDhhMWRs=; b=J2Nd4df+jEqgpFjU4kaXJovQ6jbiNVYWyUZH00CaDw7K0DXNZOTfwpuHDXheBuf7mr gdsXNMB4+bR6d0RsScWWcQMh9PopVoHRZ77fQ/lnJRNl+LS4R335zN7CncWaOGI9MclW CagojBDCPGjdSOrbs2tWHrk3dx8ONS20Mthd/HrMbc0Ld13t6qjbL2xVwssD0Onq/HYl VSNJE/ORHAO8uy5GymL937KHVPAGadR3fSmeJx8NyxJ6R4Md9KzUnZl+hSATw0Tm5M3J XGdrgmTHlOopxotPLZHaYZbtRU0croRk05YqjR9wJEDCv9zHas1DRw+NtVgspZfvSD4E O1Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729608162; x=1730212962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F5lAwpEciN4YcPMS8u5Za8JEhBJIL0rRq0tPDhhMWRs=; b=eo0dmPS3aWGl/f1fr8Ny2IPIjGJtQGU+tIXFsKs8Ti4sXomMDt+GICV73Gdvazb6SY pJq7+dJ2OEpTIHSUsO48kQKozXot7kqL2vG7HSAkf9v98GNyidXs03FWqWA1CesClIID ZzwdzP3ZMEmJanfk4kZ5iuBtzsNnYa/nnBC7hr9HBy0OnPeT/KKQKBhP4HS3P+VOpQ1R 2elTqhmM7gPu76FtRJ3SrW4vBaaqSfj9L+K6BDTBjAhl3x7IcvcpVveYTaMGS2C/qJq7 gHbf8pXFZuTypuSFIHLZH1DgLvS1OZkjLtZa1e8U5+GW0C8UkStwn7wMJP9Hcy59Pnxr gNtQ== X-Gm-Message-State: AOJu0YxmJfwG3/6k5bPnTgaa9p4X9dUuiIIEku45ISiDrwIB5ZeLwRqz eyKhWVk/BsXmzZps3M8FMbNtj78d5KcDq2t5AEcrV7aIj+B0bzIqbdRXCg== X-Google-Smtp-Source: AGHT+IFbStHA6GKxvSXPcYgJVRo1H030j9QC9w3/WSjA+Iv+v5xOx8jqZmn/afSyZgU6+lZCePPofA== X-Received: by 2002:a05:6402:35cf:b0:5cb:6b7e:985a with SMTP id 4fb4d7f45d1cf-5cb79451b54mr3673671a12.2.1729608162035; Tue, 22 Oct 2024 07:42:42 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.141.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb6696b631sm3244434a12.9.2024.10.22.07.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 07:42:41 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 3/4] io_uring/net: don't alias send user pointer reads Date: Tue, 22 Oct 2024 15:43:14 +0100 Message-ID: <685d788605f5d78af18802fcabf61ba65cfd8002.1729607201.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We keep user pointers in an union, which could be a user buffer or a user pointer to msghdr. What is confusing is that it potenitally reads and assigns sqe->addr as one type but then uses it as another via the union. Even more, it's not even consistent across copy and zerocopy versions. Make send and sendmsg setup helpers read sqe->addr and treat it as the right type from the beginning. The end goal would be to get rid of the use of struct io_sr_msg::umsg for send requests as we only need it at the prep side. Signed-off-by: Pavel Begunkov --- io_uring/net.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 4d928017ed2a..7ff2cb771e1f 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -362,6 +362,8 @@ static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe) u16 addr_len; int ret; + sr->buf = u64_to_user_ptr(READ_ONCE(sqe->addr)); + if (READ_ONCE(sqe->__pad3[0])) return -EINVAL; @@ -389,11 +391,14 @@ static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe) return 0; } -static int io_sendmsg_setup(struct io_kiocb *req) +static int io_sendmsg_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe) { + struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); struct io_async_msghdr *kmsg = req->async_data; int ret; + sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr)); + ret = io_sendmsg_copy_hdr(req, kmsg); if (!ret) req->flags |= REQ_F_NEED_CLEANUP; @@ -413,7 +418,6 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; } - sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr)); sr->len = READ_ONCE(sqe->len); sr->flags = READ_ONCE(sqe->ioprio); if (sr->flags & ~SENDMSG_FLAGS) @@ -439,7 +443,7 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -ENOMEM; if (req->opcode != IORING_OP_SENDMSG) return io_send_setup(req, sqe); - return io_sendmsg_setup(req); + return io_sendmsg_setup(req, sqe); } static void io_req_msg_cleanup(struct io_kiocb *req, @@ -1271,7 +1275,6 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -EINVAL; } - zc->buf = u64_to_user_ptr(READ_ONCE(sqe->addr)); zc->len = READ_ONCE(sqe->len); zc->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL | MSG_ZEROCOPY; if (zc->msg_flags & MSG_DONTWAIT) @@ -1285,7 +1288,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return -ENOMEM; if (req->opcode != IORING_OP_SENDMSG_ZC) return io_send_setup(req, sqe); - return io_sendmsg_setup(req); + return io_sendmsg_setup(req, sqe); } static int io_sg_from_iter_iovec(struct sk_buff *skb, From patchwork Tue Oct 22 14:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13845758 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 DBDD219F49C for ; Tue, 22 Oct 2024 14:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608168; cv=none; b=HMUIxlCmEn+UrigCN/JnQ+C/iKXZEDIa3sXTMVp53aiRV69fuU6HH9zkD2y7xI+5ms8G5BpiWMhwqsmZoVqT1oq6reg4bx2VjtcRLTdHU2jg++IilyKGJhYLNNIXdTAgG6QsNX0WHgxPt1DCc45TNbNrR5ehnHtLV1G9UM3mdPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729608168; c=relaxed/simple; bh=LLMAyzjVzCHC0lMplM/PxfHLu1sviICy98QmeAIpg24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P5tu5GpjuaKPJzvpRNdBbkWslBAWqZWkXnGiCzxfOgHcez0BpVrgu6m2mdVhaQvVefO6vd9FKGGDwa/vbqEBX4wcsflRAAyLEPKsliXZDP7MmXg8Vq+5NA137n053Rw2xcFL7mmYDHVKyW0aIug30e1TWUX50LdssdFjQU3BvQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cpzbxFx8; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cpzbxFx8" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c9634c9160so6225110a12.2 for ; Tue, 22 Oct 2024 07:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729608164; x=1730212964; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TKQdQvaaPOZjv5rywWtr97sd8FUzNk7jVmtMShyoNp0=; b=cpzbxFx8OCpqjInXsigyFMoZqQY/G+jL5Y0Wi8MfeqqSYGz4/BOUasLNvb08HSl4qk axlmQHWI+HVPGoeVvmLfDi7uIQRdOltN6pHZ3F3Us4QB5/BTtpDx6cKn0xZHCCVVel3H 1CVO8BBIlh+sjvVhh/9RmZuP/65IRZuqso5RRHbtAlSK0/OaBBLTTKC3H0Q450xnsiNo 4HG0b2Dh6L+5k1uE9orqUz1Da+x7fF5Qnk1jlpkypjUAQl0+DVCiisllIbIcRFunjHVW NNiY9ZSSbkcOijhPzdrVQ/MZgMEh69OTRlU/0RM5m+k8QQjSktcsT7XV7tC6Os46Cay4 uhhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729608164; x=1730212964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TKQdQvaaPOZjv5rywWtr97sd8FUzNk7jVmtMShyoNp0=; b=iGQhrJffXpcpX9QF9/llLvx2cT3oRBNRAu+XJLy0+Ov01x7JaQKIPC3NKGnsBxq1NQ Mkau1ImIB5dzqsyuozz8G02EtniWX4Rw4dcmJiXjdJ4t5eIhnfOmZCAiFxiuemMBLz/L aEUnI0vvxGa+ezk4af6DPv3YNDfDDKAfx/EWR5Sx0m7wI30YNd/lJfxLAAfkuiGsrMjC VTcogeKVXWjg7xJl+yZl07Sr/ZTws3kMlpurikccYkj2oUt7L7FfRtx1GtQhKks7ReCS ELwsQguO+dojkGPyp3XOv4iloUU+mZb09ToD5Jyxaql7Cc5NoMOxAfiFfAbA8VNtlI5w 1QQw== X-Gm-Message-State: AOJu0YxWqSez6rWdJB+IXBj+8tvc7jImhk7F9KwU2SjILOfBtx/2hBoH 9b42WZqEIq4vW6/eWOVZ7FUnj+ZNEfwBigChOw3z9Lz0CePtOKoe/zIcxA== X-Google-Smtp-Source: AGHT+IFx9pf8yOBp3HQQwuHjmz3PhO1Bm9mdbK5WB3a880lq8qt/qNWEGfr7w5oKbhQVuf05akhgNg== X-Received: by 2002:a05:6402:1d4a:b0:5cb:69a2:7ad0 with SMTP id 4fb4d7f45d1cf-5cb69a27df0mr7344626a12.32.1729608163202; Tue, 22 Oct 2024 07:42:43 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.141.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cb6696b631sm3244434a12.9.2024.10.22.07.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 07:42:42 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH 4/4] io_uring/net: clean up io_msg_copy_hdr Date: Tue, 22 Oct 2024 15:43:15 +0100 Message-ID: <26c2f30b491ea7998bfdb5bb290662572a61064d.1729607201.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Put sr->umsg into a local variable, so it doesn't repeat "sr->umsg->" for every field. It looks nicer, and likely without the patch it compiles into a bunch of umsg memory reads. Signed-off-by: Pavel Begunkov --- io_uring/net.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 7ff2cb771e1f..ccdbb3c42ac0 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -261,6 +261,7 @@ static int io_msg_copy_hdr(struct io_kiocb *req, struct io_async_msghdr *iomsg, struct user_msghdr *msg, int ddir) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); + struct user_msghdr __user *umsg = sr->umsg; struct iovec *iov; int ret, nr_segs; @@ -272,16 +273,16 @@ static int io_msg_copy_hdr(struct io_kiocb *req, struct io_async_msghdr *iomsg, nr_segs = 1; } - if (!user_access_begin(sr->umsg, sizeof(*sr->umsg))) + if (!user_access_begin(umsg, sizeof(*umsg))) return -EFAULT; ret = -EFAULT; - unsafe_get_user(msg->msg_name, &sr->umsg->msg_name, ua_end); - unsafe_get_user(msg->msg_namelen, &sr->umsg->msg_namelen, ua_end); - unsafe_get_user(msg->msg_iov, &sr->umsg->msg_iov, ua_end); - unsafe_get_user(msg->msg_iovlen, &sr->umsg->msg_iovlen, ua_end); - unsafe_get_user(msg->msg_control, &sr->umsg->msg_control, ua_end); - unsafe_get_user(msg->msg_controllen, &sr->umsg->msg_controllen, ua_end); + unsafe_get_user(msg->msg_name, &umsg->msg_name, ua_end); + unsafe_get_user(msg->msg_namelen, &umsg->msg_namelen, ua_end); + unsafe_get_user(msg->msg_iov, &umsg->msg_iov, ua_end); + unsafe_get_user(msg->msg_iovlen, &umsg->msg_iovlen, ua_end); + unsafe_get_user(msg->msg_control, &umsg->msg_control, ua_end); + unsafe_get_user(msg->msg_controllen, &umsg->msg_controllen, ua_end); msg->msg_flags = 0; if (req->flags & REQ_F_BUFFER_SELECT) {