From patchwork Tue Feb 27 18:51:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13574294 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 1716F4D59F for ; Tue, 27 Feb 2024 18:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059935; cv=none; b=Qr0FkYeJu+xBYyACaJm8EUFf3cUNEMMu0fxYDe12PW27QgfzQ2bxqf+3QNdbbBhHxzM/EQXIKKf786pD/pljhF2AH+jeM0drcpS3CTLBkKnrFbyOnMCihypq/hLd7XIZ1F7/LyCFH2/nwLLsLCl78Imvi0Ycr7dnLOaI38170Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059935; c=relaxed/simple; bh=Bwz1XCGG8sAa4hB/q27XYGr3ZK5UY47pzg7bfBwJ80o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q8i9N0ERL/JX6gG6v0elU1bYmE9x/X7XHs8pV9QXOyM0U7KXsTebPnvK0iuZuirv5kByvTm4Pg6EgrKtc5dCT9kY+bwRImawXjW3IhHZ04/TiRAhgCf/DdF2i8SjnwskLO1rz+iXWYGWpuuj1tLb87KuFOFgzRycyG6O6SLOG+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=LRXhzDQo; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="LRXhzDQo" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e555d6adafso40349b3a.0 for ; Tue, 27 Feb 2024 10:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1709059933; x=1709664733; 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=qke7VBOcxahFVWc17Wbuzh6Bf+gTJGXU/ImftE7zCJs=; b=LRXhzDQodJ6uGAGTuwDk3aCyZwnr+x0MkE0s632oc9O+huRJhWnf/qKbOpD7PNqIKD gqr1Tnrv7FMlhYNzZe5NbeAB5Q8PU8AF223jHKgFxWcOGNzZ6e91KMFwXAsG5tvHgw+S Fb1xWLgrsSDhFmX4T0bCICo6Pap5/mXQYFNjsejIv4gVuoidfo18JQzlEt/wptFc2KVw vCuJrnh6GWV7wn+3AofEBZ1vM6ssieZzWxMCpW3MUXZJsDx2o4QRPIYGr+roddT1ArOo BjdnKJkn0kh363lGALGHTb9AZb8RGC1yy/nJV38gpQ7NanTev0AYiLLnsOLFTsYe2/J3 QCfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059933; x=1709664733; 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=qke7VBOcxahFVWc17Wbuzh6Bf+gTJGXU/ImftE7zCJs=; b=vL/4kvByKYxJvBcRi3k12ALVb8NwM5O0KFa08U4fmDJf4g5ZVb2QCcYpH8k6i0vU/E svP/p66KF6o2qu6gQs+Y0fRZPPX5831RKOQO/e6gD94CIpyPodf9kF7aeogipMUBkbQs tLs2qixiq5LtS3i0k/OyOYPnbvmBQfEpxGWuif8GP4sxE+7xniCDcw8O0xWf/YzJBDgW oRJIF/KjNtD6aeNO38STTQIU1M1Qoc2IWX3HHlCyX+sApcSsUnEKrYAl9tHY4koUo39V 9EOLjE7ha8aLe171gMxiwtOg+T7cK66f2Y4xAy1+PoIPF7UjuYwdA25Dugh5GW1vmp3k qgmw== X-Gm-Message-State: AOJu0YwkK1QKfzcVQu9xsihSLb8iGPCr+fD+8oZwq7FcfJOH24EaGeng zBls1HoLLMS++93R0SV19VcuDLMoqWtZJB11GgjLL7yLeLRtrI/uDJluSaMZXr9qAZpk0t6S60+ W X-Google-Smtp-Source: AGHT+IGfLs7gmo4dg1oRtZgKnsm3S57tNQsCx6JleJ8kywUWPxvkG1bUtplCOUyd/WBnoKZhFxu6HA== X-Received: by 2002:a05:6a20:1595:b0:1a1:3e2:dcc5 with SMTP id h21-20020a056a20159500b001a103e2dcc5mr5234751pzj.6.1709059932934; Tue, 27 Feb 2024 10:52:12 -0800 (PST) Received: from localhost.localdomain ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id l5-20020a170902eb0500b001dc1e53ca32sm1860721plb.38.2024.02.27.10.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:52:11 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/3] io_uring/kbuf: flag request if buffer pool is empty after buffer pick Date: Tue, 27 Feb 2024 11:51:09 -0700 Message-ID: <20240227185208.986844-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227185208.986844-1-axboe@kernel.dk> References: <20240227185208.986844-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Normally we do an extra roundtrip for retries even if the buffer pool has depleted, as we don't check that upfront. Rather than add this check, have the buffer selection methods mark the request with REQ_F_BL_EMPTY if the used buffer group is out of buffers after this selection. This is very cheap to do once we're all the way inside there anyway, and it gives the caller a chance to make better decisions on how to proceed. For example, recv/recvmsg multishot could check this flag when it decides whether to keep receiving or not. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 3 +++ io_uring/kbuf.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index bd7071aeec5d..d8111d64812b 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -480,6 +480,7 @@ enum { REQ_F_POLL_NO_LAZY_BIT, REQ_F_CANCEL_SEQ_BIT, REQ_F_CAN_POLL_BIT, + REQ_F_BL_EMPTY_BIT, /* not a real bit, just to check we're not overflowing the space */ __REQ_F_LAST_BIT, @@ -556,6 +557,8 @@ enum { REQ_F_CANCEL_SEQ = IO_REQ_FLAG(REQ_F_CANCEL_SEQ_BIT), /* file is pollable */ REQ_F_CAN_POLL = IO_REQ_FLAG(REQ_F_CAN_POLL_BIT), + /* buffer list was empty after selection of buffer */ + REQ_F_BL_EMPTY = IO_REQ_FLAG(REQ_F_BL_EMPTY_BIT), }; typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts); diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index ee866d646997..3d257ed9031b 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -139,6 +139,8 @@ static void __user *io_provided_buffer_select(struct io_kiocb *req, size_t *len, list_del(&kbuf->list); if (*len == 0 || *len > kbuf->len) *len = kbuf->len; + if (list_empty(&bl->buf_list)) + req->flags |= REQ_F_BL_EMPTY; req->flags |= REQ_F_BUFFER_SELECTED; req->kbuf = kbuf; req->buf_index = kbuf->bid; @@ -152,12 +154,16 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len, unsigned int issue_flags) { struct io_uring_buf_ring *br = bl->buf_ring; + __u16 tail, head = bl->head; struct io_uring_buf *buf; - __u16 head = bl->head; - if (unlikely(smp_load_acquire(&br->tail) == head)) + tail = smp_load_acquire(&br->tail); + if (unlikely(tail == head)) return NULL; + if (head + 1 == tail) + req->flags |= REQ_F_BL_EMPTY; + head &= bl->mask; /* mmaped buffers are always contig */ if (bl->is_mmap || head < IO_BUFFER_LIST_BUF_PER_PAGE) { From patchwork Tue Feb 27 18:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13574295 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 6EE203D988 for ; Tue, 27 Feb 2024 18:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059936; cv=none; b=EgQDhI3i7PbLOwM0b/7ESDezuONtnvgnU0R7RPK6x3xBsnNFuYr9JygzJDUKJeDDjBHKeN1JhJV+Iqx2tztbvy+tOIA3R3YQmGvuMfssmcyBG3dr2D+cYDmiZN/Y6ob+g4riTzVTT+JR+lblONowKzViB6Y62roKwFuK12rEVtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059936; c=relaxed/simple; bh=srMU7n+sXIFcrgdUEN3TXNnawtJORwd7jO7WIFzhWjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=haMTC2VhQ9Xo4IV2e6s1Xt85wS8zFdv+oVMZDe3dGHhq+KtIzmwtR2Fv3Eppwz6h5tMlCcojEEYuxgTGe5N7TGnYzctlsASxjvmWSzvjMgNFjwUggr7nUsVq73eta3mGoff9RCVxmPvZokXfmnen91a0jiAazxzoHpnmtQ5w6/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=jxl6E9Zx; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="jxl6E9Zx" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-58962bf3f89so1611689a12.0 for ; Tue, 27 Feb 2024 10:52:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1709059934; x=1709664734; 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=GNuK0EUNkoiUg4kijOvZTjdBLy+N5AN1n6F7lAul+9A=; b=jxl6E9ZxYpG3HMjRWKjbDB/u5ILWo6eZQjHN+dbPlfnNtsmnX+FB9qSAQvlOZg8OEY cKeOyfjjMV8Oy86YE1VsdprYkvPaZv1uBiCknWTZKxDXcLDWdL0P2RM4vq1mgUAMZkYD YUWuJbVR4OlQqobcZa0ARMBwinVZzbfghUOi+R5qisNGIb4e4CgXYnYJxKdkcbJJ74+N VHt+dLcAXeu8V1vphaQ3O1amNJ4wb4nnnwkHz8an+nMryHVeLvsEWfAh6/Cxp7qNtxae wHBC1MtDznH8JfZnCneAxJBiuHpbyJ1GK/TpI5rckiEfzoLhL31HHRLc7kX3clzAioE9 LCQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059934; x=1709664734; 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=GNuK0EUNkoiUg4kijOvZTjdBLy+N5AN1n6F7lAul+9A=; b=ad79hXy6Mgj1yojoaPeo9TzfI6Rl2DiZmNleLO9IbSxWHZkKJ4UP0V09k0zYgWk+Hs ERmAeBeY2bRHYVzoL0RVCCWKu0a1cBGmJqQ1V7sDvFIUFYy2xR4eVBgd19+v02K6HgiL kXBsXofoYJE7tkW+0M6J8zdznNdSoPnQ0zPsE7jflRvFlqF7Dx4pNtnzJ6x12wOF5F55 laxMY28cW4+hXshXkR7W2/y9pVv13XSjbR8bcErmCDNEHJKjaZv3IUhV680buCnWU3E+ LulT6avMGAgjddK1TS2/PBuA6jESS7nlb8Lmdyc+VgsrkfIgvbvwXwful8jRMyf99EvE WsfQ== X-Gm-Message-State: AOJu0YxalZvV9t4jdbmGodyuib/JD53Z/LLKZGy3lQo2AZEtK9tbWC/6 YFYpI5y1tECsRjAk1Fa5zULizvOqlQCZ5G6eFfCCX+D/AJYuJq4LProQO2ktbRS34w9orkOkaN1 w X-Google-Smtp-Source: AGHT+IG+FLmSxXYmrMN8IcDHqYpoxpDOs64yEH5Qct/8U1iYdSPGKzIkbF36wa/yikdH1T4HorKBBA== X-Received: by 2002:a17:902:a70c:b0:1db:94a9:f9f0 with SMTP id w12-20020a170902a70c00b001db94a9f9f0mr11594441plq.2.1709059934255; Tue, 27 Feb 2024 10:52:14 -0800 (PST) Received: from localhost.localdomain ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id l5-20020a170902eb0500b001dc1e53ca32sm1860721plb.38.2024.02.27.10.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:52:13 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/3] io_uring/net: avoid redundant -ENOBUFS on recv multishot retry Date: Tue, 27 Feb 2024 11:51:10 -0700 Message-ID: <20240227185208.986844-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227185208.986844-1-axboe@kernel.dk> References: <20240227185208.986844-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we know if the buffer list is empty upfront, there's no point doing a retry for that case. This can help avoid a redundant -ENOBUFS which would terminate the multishot receive, requiring the app to re-arm it. Signed-off-by: Jens Axboe --- io_uring/net.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 9fe2a11f3554..ef91a1af6ba6 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -716,6 +716,11 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret, int mshot_retry_ret = IOU_ISSUE_SKIP_COMPLETE; io_recv_prep_retry(req); + + /* buffer list now empty, no point trying again */ + if (req->flags & REQ_F_BL_EMPTY) + goto enobufs; + /* Known not-empty or unknown state, retry */ if (cflags & IORING_CQE_F_SOCK_NONEMPTY || msg->msg_inq == -1) { if (sr->nr_multishot_loops++ < MULTISHOT_MAX_RETRY) @@ -724,6 +729,7 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret, sr->nr_multishot_loops = 0; mshot_retry_ret = IOU_REQUEUE; } +enobufs: if (issue_flags & IO_URING_F_MULTISHOT) *ret = mshot_retry_ret; else From patchwork Tue Feb 27 18:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13574296 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 205A951009 for ; Tue, 27 Feb 2024 18:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059938; cv=none; b=T1BletVmH6Qb1U4q63XCZZAj+Qvb/PDko8WCma/eAV5aAU8YHkKdz/+f27IDqjh4ND8xhNrqSls865RJkFQ9ROsLvYM8t+TWzETR+2A92jO92ekMU2YvuNVJO/Pcv1mEPhpGjXAE0L/qbmPwcG+TX5nLLhJUgnEdzxWUfJ7Lh2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709059938; c=relaxed/simple; bh=eWMmgurVnS74plEJEDBqQPt2hR21lu/HCwoFIqDp578=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rYfcMaB6w8Z2IZt0xg1A3VoIwSf3NUV1M2/7X7/PmynZ7+4FhmtgUvrjgmxk3kkTQZW0oyXxlf6ax4sXUzZ95vpLKIh+pthaYcF7PfaaB4Gcy/H56T+vCn/INrUmY4v6IKjywYoSR7HCVYDYOwqAIVbfyOHEVQuikGYyrj/FUiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=aGfuQig9; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="aGfuQig9" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dcbf3e4598so503545ad.1 for ; Tue, 27 Feb 2024 10:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1709059936; x=1709664736; 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=SJNK4P6oCRaJOCSI5a5JNdJbt4izWo8cRTeTXrAp1EQ=; b=aGfuQig9/rBJ6gYH90pHeNYF66DjVouEp04df9Xj/KDEV4gJbEejqcX3vuJ/OPxowQ JxTECQBmL+Zn3nHPs73uyC1g5/Cm7HglKv8aCfxRJcwaAh9ZaMFkJ+nu4yY1HpC1Zsdk lVgOF9Bbyk8vGCwJcv4u2qrY5hGwV6sxytJWwUaYoPt1jtnvaW8UvjWKbLVqpzBbYNww f01XiL4E+pmaTC2uFRa5W6aJyCPW1b7CkerYXh85VY7GjC7oHamIcvwWega0iD5q4j1A xdzL52/8CA3mgj5lx3FLt7gFe/LYYps5SKgWhdigUaE7EHl/AuboHvwdlpBBQGHQWpRI p4gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059936; x=1709664736; 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=SJNK4P6oCRaJOCSI5a5JNdJbt4izWo8cRTeTXrAp1EQ=; b=Qt6mE5Hkl9MmTl3hd/E/cNr+GSfqavWxhJDRGIRu3X/nR9+9puSQA+sCjxsyNMkfml qR82j3JZktevIiG7Ebm8r5UPuq/EN+MlhWLUWlSRvVHPJ7zN87C/ZyeonWUhKE+Uo5+l iFypX0jpGSKu8eUz2WRostvJHRN9unRXdRvNIWuBIoX6UOeks9f/c6bjCQpeghrKkIEs gK/LMsdzaO+cyIOOQc3FvTYRYJHi+rhLi652xN7spW90KkkqeRGF6w0x8w2iNMI9qmNR JhfA3YEAuRLP1U+Gkwi3XvigWN692m4k+s49LCFGQQvYgdsx75XhpJ+YNpEh6u7eTqBh DhXw== X-Gm-Message-State: AOJu0YzaflzXXvX5Ys7riNMA/PVoZFDPV0f96CkQ+2FoIzpq1bL27sGm J0aN069g8agjOmvhTY5vliblP0wYnR1tOjYDZYWCw1jdCHmX46xjn1LHU0FaMg+Z1A/cMvVyMUM 7 X-Google-Smtp-Source: AGHT+IHrjheqDuX6NYP1kmQKmUJdh73z9leqV3/S2oHzGDpVqPaMVkv6VhXwb3y3+ZYmSVnJW1iLgQ== X-Received: by 2002:a17:902:eec6:b0:1dc:83b3:99a5 with SMTP id h6-20020a170902eec600b001dc83b399a5mr10123760plb.0.1709059936016; Tue, 27 Feb 2024 10:52:16 -0800 (PST) Received: from localhost.localdomain ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id l5-20020a170902eb0500b001dc1e53ca32sm1860721plb.38.2024.02.27.10.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:52:14 -0800 (PST) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/3] io_uring/net: move recv/recvmsg flags out of retry loop Date: Tue, 27 Feb 2024 11:51:11 -0700 Message-ID: <20240227185208.986844-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227185208.986844-1-axboe@kernel.dk> References: <20240227185208.986844-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The flags don't change, just intialize them once rather than every loop for multishot. Signed-off-by: Jens Axboe --- 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 ef91a1af6ba6..926d1fb0335d 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -861,6 +861,10 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) if (!io_check_multishot(req, issue_flags)) return io_setup_async_msg(req, kmsg, issue_flags); + flags = sr->msg_flags; + if (force_nonblock) + flags |= MSG_DONTWAIT; + retry_multishot: if (io_do_buffer_select(req)) { void __user *buf; @@ -881,10 +885,6 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) iov_iter_ubuf(&kmsg->msg.msg_iter, ITER_DEST, buf, len); } - flags = sr->msg_flags; - if (force_nonblock) - flags |= MSG_DONTWAIT; - kmsg->msg.msg_get_inq = 1; kmsg->msg.msg_inq = -1; if (req->flags & REQ_F_APOLL_MULTISHOT) { @@ -970,6 +970,10 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) msg.msg_iocb = NULL; msg.msg_ubuf = NULL; + flags = sr->msg_flags; + if (force_nonblock) + flags |= MSG_DONTWAIT; + retry_multishot: if (io_do_buffer_select(req)) { void __user *buf; @@ -988,9 +992,6 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) msg.msg_inq = -1; msg.msg_flags = 0; - flags = sr->msg_flags; - if (force_nonblock) - flags |= MSG_DONTWAIT; if (flags & MSG_WAITALL) min_ret = iov_iter_count(&msg.msg_iter);