From patchwork Tue Oct 22 02:03:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13844976 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.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 8FEA25B216 for ; Tue, 22 Oct 2024 02:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562676; cv=none; b=k+Ro3Gu+lGImToOrku9Gzvu7OKS0CAmRBYs575DpDHgNL+IWmsTAah/Q2l7XdDXdqZWOMqqVNSiMHdM/jevORDNcFSoL2i8JRvwbkY+ZJ/vzFxpc0oqKBcisWTBIswMZdQ9FiwH7+h4qpR3bvNYXftAo7YAI/q+JSQnyqo0rF8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562676; c=relaxed/simple; bh=4cN3rSInxG031End0lb1dpyjNWiWykCGbxZ8WyXkePY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIPbRO1hSgN+VJ7zqqFi4nRbQhNsJZiFmM5Y9B+VljLFGKuvzYNJCfsKSO4aZixrmnqkjG3ZmOuwQTI7FRpV+lqfx6HaQiop6HrRH3wkX/zYxUt9yTXe/2pbFYKlIq445+Xmaqn+0CsqrkcpbgkUjTmfFLLcwIOQO3b4AKpNhYk= 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=kh1i2NA6; arc=none smtp.client-ip=209.85.160.45 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="kh1i2NA6" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-277e6002b7dso1842024fac.1 for ; Mon, 21 Oct 2024 19:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729562672; x=1730167472; 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=paxlLTuk+IUBQ5sAmbInMRBMpA5dgQe7Mulbt/p9r7s=; b=kh1i2NA6DgUtNss5dlsEyQjRzUevk5ZjFoUq62EnEtBZ14gb9UgfzjbCx6NH907qaq I5RPhyyqPzxO3FA7EagV3ymeJv8TCqwp9EcQq7R+O03m/PKmRBL74+E7Wks+bocWJmLv a0FfKAvI/FWv/5l64h2bUbWffzzK9Lsbgu4zs7nsdcdk6ZyoFnfY3GUnE5daEmtdBAQ/ Gc8n4tGtIFaBvmy7mAn+l+JNRnkNltrvb8czwXqcdaOXLoofZ1xZsR+QbB5xkDb/C5DI V7rM9knpZ+3NeyBJMJpVbZZrI3EHsKpQVW57SLOlKmg4YzzPyLueki5PYvU/n0rZDizU WMag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562672; x=1730167472; 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=paxlLTuk+IUBQ5sAmbInMRBMpA5dgQe7Mulbt/p9r7s=; b=IlDeeEwpVhK4NwRQ9wAsSMYjXo/rk/66XXCU5WJYWJOrmINYvl6hqr73CbeOZrLRD8 0SbED3sn0PjS8iz8A0QxCMYkDejbZ19enxLXgbJLFNVS9z475HDBbe3MwTiVBb6FjUDY NdPX+hU69Yr8x4A711XnhPoVSIrQK4GtTxdJAVO+xYyJNy5hKR4rWpi04qR65+9ELg33 5iWBzfDspl56O01xG3yIvfXspkAUis3lcr2SM+0gJ17rwjPqF2iZL5MLHW1QwImvKFGJ XAnryT2tC2cnOgTS5UzyXhngL5lgqN4LX28Mx1baOLoEjBuCKzzRfmNFV74A853rXwe4 z9+Q== X-Gm-Message-State: AOJu0Yyq8p61XbXgkwGj3g6t4rx6OL6pRRIjQrWX6EFtfpAKQhsJ1GZw 5UtQfwnRWD8BrEOaT1nEdQfyQzoWdlFh5CNn3BvwS4ItuuRe5lc7vmY8noeO57jvUdztc3A3jV3 i X-Google-Smtp-Source: AGHT+IFrfVOf1mgXjFmYLeULKBZNwks1gn2Rx5SpykJXksQnWZLFSkGZOQ+tyx+id5PnazOF1y4F/g== X-Received: by 2002:a05:6870:80c8:b0:270:1352:6c10 with SMTP id 586e51a60fabf-2892c5435d9mr11547675fac.37.1729562671796; Mon, 21 Oct 2024 19:04:31 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeab58820sm3845534a12.52.2024.10.21.19.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 19:04:30 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/4] io_uring/uring_cmd: get rid of using req->imu Date: Mon, 21 Oct 2024 20:03:20 -0600 Message-ID: <20241022020426.819298-2-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022020426.819298-1-axboe@kernel.dk> References: <20241022020426.819298-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's pretty pointless to use io_kiocb as intermediate storage for this, so split the validity check and the actual usage. The resource node is assigned upfront at prep time, to prevent it from going away. The actual import is never called with the ctx->uring_lock held, so grab it for the import. Signed-off-by: Jens Axboe --- io_uring/uring_cmd.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 39c3c816ec78..313e2a389174 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -211,11 +211,15 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) struct io_ring_ctx *ctx = req->ctx; u16 index; - req->buf_index = READ_ONCE(sqe->buf_index); - if (unlikely(req->buf_index >= ctx->nr_user_bufs)) + index = READ_ONCE(sqe->buf_index); + if (unlikely(index >= ctx->nr_user_bufs)) return -EFAULT; - index = array_index_nospec(req->buf_index, ctx->nr_user_bufs); - req->imu = ctx->user_bufs[index]; + req->buf_index = array_index_nospec(index, ctx->nr_user_bufs); + /* + * Pi node upfront, prior to io_uring_cmd_import_fixed() + * being called. This prevents destruction of the mapped buffer + * we'll need at actual import time. + */ io_req_set_rsrc_node(req, ctx, 0); } ioucmd->cmd_op = READ_ONCE(sqe->cmd_op); @@ -272,8 +276,16 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, struct iov_iter *iter, void *ioucmd) { struct io_kiocb *req = cmd_to_io_kiocb(ioucmd); + struct io_ring_ctx *ctx = req->ctx; + struct io_mapped_ubuf *imu; + int ret; - return io_import_fixed(rw, iter, req->imu, ubuf, len); + mutex_lock(&ctx->uring_lock); + imu = ctx->user_bufs[req->buf_index]; + ret = io_import_fixed(rw, iter, imu, ubuf, len); + mutex_unlock(&ctx->uring_lock); + + return ret; } EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed); From patchwork Tue Oct 22 02:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13844977 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 76EB8126C14 for ; Tue, 22 Oct 2024 02:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562677; cv=none; b=unR9P2sLfDRuanXHcO7YeVmJLmVs0nWqkqJKp5Drt+aytvC/XoAr+5abG27qUl8XgwkA8lDZn2wAfmkzODYOQMtP6tGuFlKLh3sNj+3F9EbP2f3/AxMpZzISQPjAIZocpbXy/TMoeoZPF0/jCbfmkzb8e8Cnjg1dWRaG+NDxoPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562677; c=relaxed/simple; bh=oDiF+iJtDAqOQFD3zFbOwHq1eNByLNSUH9pNke+Mbqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rOpzIPsFMT4fspFiO01VO7+9OFSov5izTQju8RSXZ/MwTTu+FwlUapBMkvSRSpsox8eW1wkh/U3hLEikF6t7G/VxeW+zbo7lRqrn6g6sMXQtWEPsg7f8E4c4iZeDNu9PFtZq8AnnDZlL5Hz5l5E67a0M9TrvS91G9Pup5NkabMk= 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=QCyjyLSo; arc=none smtp.client-ip=209.85.210.169 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="QCyjyLSo" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71e5a62031aso3534463b3a.1 for ; Mon, 21 Oct 2024 19:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729562674; x=1730167474; 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=q7q/V2BhkWsb+BFpGXBB0cov0CmL9fUYlsdRBSuHeDA=; b=QCyjyLSo9SuXwmCfO6zDJVTOsWG1X2UeREkGRjYkvBggBImEQbQPSu6iipv5x6KGB2 sjGpY9lkivLwJj45TD+abW5Pj0+fryYPin34gkJxKAYdKIbNlHDChYuXV/jbhtfXiwEs vg3gEjRL1G5hVhHqo5UrHbu54jbT/Lhd6U91ES57FUiKCj2xHAcjjtHk6/U/dUjMJYcz uqhfp4zeHkAxc+Ondfpxg3YuNAx1UTL3W6Vpo8b7xN+AePBlpbDiH5Co4axBXNBrXu6d xeH2JstAvqds1kWHMYG7BheZQA7z0JUlYIFB19va99LnuToNuSY5Pf2t957mRDsvOcC8 zYDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562674; x=1730167474; 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=q7q/V2BhkWsb+BFpGXBB0cov0CmL9fUYlsdRBSuHeDA=; b=YImVTby9iSY2yPb1q1vvLmHUH9WguCw/LbXlmpw+7211TAXv9igBuvGPly/oXt1ps4 UKctp09aMyaFSb6KcucGLG5yf4AgkdOidODyyNYIN+Na1W+G85moEDkoKlUlk9E9D/lA VUW4khqBB+rbPo2jTwUHJZOAWKma8FWbS3G3oTIdSzNuSuUDA562I+BFYHu7O/6s8XAh PQ9gf5iEN7sX4OEKDg9cjAb3wGKqwPyACGNCdfl29964NxZfs9wHzGCu60DUDvoMSXZu L9BHXBIAMOGWsjGAOErOU9hVxg2ezVKqmpbOzKr/GQGyDYfSwIwNeB68HsQkHuS/j1Yb xUzg== X-Gm-Message-State: AOJu0YwHSBg+pp6ETOg4XLeDEMjsVz80A1E6RsHP0Symmr/85MmiP8O2 8jIS+iKdizDLmzziFZG13h9r5cRGuUWAXw/i438c2wYhLTBFDJ17F3ux+/DRjgyG8igsURraoAj 6 X-Google-Smtp-Source: AGHT+IHH5WeaeaMGkW+lNW+ChYdE0rSmNCMtMorsY0gVu3JofWHzKzMBmjdykQSgXTltGJ3ZUDc3Hg== X-Received: by 2002:a05:6a20:bb28:b0:1d9:3456:b71e with SMTP id adf61e73a8af0-1d93456ba08mr12754907637.12.1729562673746; Mon, 21 Oct 2024 19:04:33 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeab58820sm3845534a12.52.2024.10.21.19.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 19:04:32 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/4] io_uring/rw: get rid of using req->imu Date: Mon, 21 Oct 2024 20:03:21 -0600 Message-ID: <20241022020426.819298-3-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022020426.819298-1-axboe@kernel.dk> References: <20241022020426.819298-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's assigned in the same function that it's being used, get rid of it. A local variable will do just fine. Signed-off-by: Jens Axboe --- io_uring/rw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index 80ae3c2ebb70..c633365aa37d 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -330,6 +330,7 @@ static int io_prep_rw_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); struct io_ring_ctx *ctx = req->ctx; + struct io_mapped_ubuf *imu; struct io_async_rw *io; u16 index; int ret; @@ -341,11 +342,11 @@ static int io_prep_rw_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe if (unlikely(req->buf_index >= ctx->nr_user_bufs)) return -EFAULT; index = array_index_nospec(req->buf_index, ctx->nr_user_bufs); - req->imu = ctx->user_bufs[index]; + imu = ctx->user_bufs[index]; io_req_set_rsrc_node(req, ctx, 0); io = req->async_data; - ret = io_import_fixed(ddir, &io->iter, req->imu, rw->addr, rw->len); + ret = io_import_fixed(ddir, &io->iter, imu, rw->addr, rw->len); iov_iter_save_state(&io->iter, &io->iter_state); return ret; } From patchwork Tue Oct 22 02:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13844978 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.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 5A2EF5B216 for ; Tue, 22 Oct 2024 02:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562679; cv=none; b=QwEHP8YYNUjQbijVL8v+A5Ln0usQ9Rc7pgDMi+j1FmbW2UjgVisg/QBP2/SxnTK048RzmzT1I1D07A4Z9OX7mRPPFsMBleZ9Wq5rGOpwc9nn/zuK0hlEhdrhfavsDaygOFfvdadpTVkc8ExD4qt+FChDktgHti/f98RFtLBO4KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562679; c=relaxed/simple; bh=3kYq0C5TWd8rkmdhoT6VK1j4LEkRJ2s4Y0vBsL4z25o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/aR59e1wbQiCAcArzSO1ixvLVVwtorrKyNt/NMepHDkj2dviP5ZWk3JuuNO4yaWMOeXZjMeB8wfubnaiAE5pCPPat21aUndSIu1EGlywCoaSR7vTRor9JVsDU33pCgszdFkH06i7f3LM2x39aHEuPxU28yvwC9z9RnyGymor4U= 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=sCTlyHp/; arc=none smtp.client-ip=209.85.160.45 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="sCTlyHp/" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-2887326be3dso2283115fac.1 for ; Mon, 21 Oct 2024 19:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729562676; x=1730167476; 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=fPVCm1Xor1/HRTQ9izeciEoHtF5Hj038MRohwzPQcik=; b=sCTlyHp/mo1YzTXTqWaWIX4iN1qpUh4mMl9KzS/AY1cpgI0853XXlMddcMcCxeL+4R hlXdHx6BqbKvyZxrY4y9u4R3vsJiD5viM5OCXA6gnX4V7VJaW7hZ/NxkZ8Poch0fyVv4 Y4GBAere12hEEFNE3aEnO5Jmpe8myCDI9rgSfbQulfkFTM2eKeXfFyLqKtD5SjY9JOyY PHS4S6iPCp8PYyl/tKPJlzdUh2mKhpRn/MOiE326ChPxnPjqGHHRoGl06+io7exvYOV7 pVIG+/BO7JUBor3MfZettjlq3dW/MnYbIfr4MU0eH7O15qsoTVOVmuevjFJ4MYW4Lyt1 q7jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562676; x=1730167476; 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=fPVCm1Xor1/HRTQ9izeciEoHtF5Hj038MRohwzPQcik=; b=TEXL3dIoC56GW+oc/DvYssa6nIp3NCVviv0IGfEqkCnu9a/Bh2Mn0hNzpO3NLsA7uA JkSlRJrNHZ0PelnV+iKdVFsnViIkVTxxcibWQBHIBLmJQ5zq30EhmGmCDd5iFzQcVh1C pFmY9wyb6B+j7AoiGqE3tXF+Q48BI9IW/Rtk7NkCxpGQF+HblriMaTeMZfO6QU7+G5De A90Em3X6zb1ypgHqBuoH+8mLgVaVsP3w2l+lYLuOOvSvrwO7w9m4uA09BDrKL/wrYcaf TqJo5bZjyXiDMXw7G2m2tKMfDXFIapDBH6gC2+ct2KM1Fll0HZmFsm0kfJVie3O919+m sTxQ== X-Gm-Message-State: AOJu0YxF4+GVY5EaqBv8jQaN3dJjSXN7603PNQdP6WebRrp4NqyJWGD/ 8ftWkI77YaSYqJaZFtuxdTX5dDq6VuSEFACkCY5vWKDHweL1R5KpMKr3o3taMvmJ0NTti9Uk657 D X-Google-Smtp-Source: AGHT+IEYPoUAg5MV17CYQZv1kDpTbLIkqP/K3YjUAxpvTanRuZR6viOAeWiPyVK3ZSnb9+rnVnCrZw== X-Received: by 2002:a05:6870:7012:b0:277:e1bc:7da7 with SMTP id 586e51a60fabf-28caff8e345mr1027006fac.22.1729562676315; Mon, 21 Oct 2024 19:04:36 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeab58820sm3845534a12.52.2024.10.21.19.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 19:04:34 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/4] io_uring/net: move send zc fixed buffer import to issue path Date: Mon, 21 Oct 2024 20:03:22 -0600 Message-ID: <20241022020426.819298-4-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022020426.819298-1-axboe@kernel.dk> References: <20241022020426.819298-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Let's keep it close with the actual import, there's no reason to do this on the prep side. With that, we can drop one of the branches checking for whether or not IORING_RECVSEND_FIXED_BUF is set. As a side-effect, get rid of req->imu usage. Signed-off-by: Jens Axboe --- io_uring/net.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 18507658a921..a5b875a40bbf 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -76,6 +76,7 @@ struct io_sr_msg { /* initialised and used only by !msg send variants */ u16 addr_len; u16 buf_group; + u16 buf_index; void __user *addr; void __user *msg_control; /* used only for send zerocopy */ @@ -1254,16 +1255,6 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) } } - if (zc->flags & IORING_RECVSEND_FIXED_BUF) { - unsigned idx = READ_ONCE(sqe->buf_index); - - if (unlikely(idx >= ctx->nr_user_bufs)) - return -EFAULT; - idx = array_index_nospec(idx, ctx->nr_user_bufs); - req->imu = READ_ONCE(ctx->user_bufs[idx]); - io_req_set_rsrc_node(notif, ctx, 0); - } - if (req->opcode == IORING_OP_SEND_ZC) { if (READ_ONCE(sqe->__pad3[0])) return -EINVAL; @@ -1279,6 +1270,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) 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; + zc->buf_index = READ_ONCE(sqe->buf_index); if (zc->msg_flags & MSG_DONTWAIT) req->flags |= REQ_F_NOWAIT; @@ -1339,13 +1331,24 @@ static int io_sg_from_iter(struct sk_buff *skb, return ret; } -static int io_send_zc_import(struct io_kiocb *req, struct io_async_msghdr *kmsg) +static int io_send_zc_import(struct io_kiocb *req, unsigned int issue_flags) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); + struct io_async_msghdr *kmsg = req->async_data; int ret; if (sr->flags & IORING_RECVSEND_FIXED_BUF) { - ret = io_import_fixed(ITER_SOURCE, &kmsg->msg.msg_iter, req->imu, + struct io_ring_ctx *ctx = req->ctx; + struct io_mapped_ubuf *imu; + int idx; + + if (unlikely(sr->buf_index >= ctx->nr_user_bufs)) + return -EFAULT; + idx = array_index_nospec(sr->buf_index, ctx->nr_user_bufs); + imu = READ_ONCE(ctx->user_bufs[idx]); + io_req_set_rsrc_node(sr->notif, ctx, issue_flags); + + ret = io_import_fixed(ITER_SOURCE, &kmsg->msg.msg_iter, imu, (u64)(uintptr_t)sr->buf, sr->len); if (unlikely(ret)) return ret; @@ -1382,7 +1385,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags) return -EAGAIN; if (!zc->done_io) { - ret = io_send_zc_import(req, kmsg); + ret = io_send_zc_import(req, issue_flags); if (unlikely(ret)) return ret; } From patchwork Tue Oct 22 02:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13844979 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (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 EBF0E126C14 for ; Tue, 22 Oct 2024 02:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562680; cv=none; b=itNSOYkPnkVLggqxF9nNfiSZKgs7LBYS9wk/D5Pg8VuE3kRiAsDx9Rj7jt/Sn80HA5qLiEzEPJkGWKz1IjbiID+cJw6WhVY5+Mx729T2LCoWmPhXkcWtf1U6PqwvMdgdU9eqc8ik/f318PYbxFqkbkHFI3RcnW3EmJjxeBvp3KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729562680; c=relaxed/simple; bh=xTsMZ1NscutzFx3vj+pkF7qRllj0ph1Ef4bK3IFUMp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i8wsGHeKEo8xdiKPP56WCEExJ9eFl9ch5ZiW/MceJaCfoiE6jkL60a+cS4Rj0At9dHP3c25IPMeysqcflMBFGad1Hj1GNQqUmY1ig+egs3L7cMRv/dk/5X8v5vJslLjsrYllQGwNPb1viV6eFnSaurEo892ig+R/82a82DmBi6U= 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=RXf1kqKS; arc=none smtp.client-ip=209.85.166.169 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="RXf1kqKS" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3a3b8964134so17593405ab.1 for ; Mon, 21 Oct 2024 19:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729562677; x=1730167477; 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=dBSkbQIxH9wsbcPCiHBwUytG72Sft1sfvVnb0fwF/aM=; b=RXf1kqKSsI4VlIJJwPb0WM3YwdE3ZVUe1EadFC1kiXnciXrxKzYpPkQ1KfHNrMs8c3 VZDWbvzXgNKoSHjZ55b0rvUOAtzA2iXlW0hyONCjiwFys9X9/xirfEodTppuvc+ZIvtI BzvNV4OMdKroRuh6UcrKWT4ouOsvvj/qCqvtCI0qYuQQcoJemTa8VusNwQJiUmZHXmnF MGwui8TSLgEmthJ21F//6bQl7xHoIzAkcjfBrYAI9/GfC+95dbUwsvf28pI4zTb4RodL f5jv/4UEHnkFKRnQ+TiIx9cYZ/aAD9QXbuaPCtKWJjjMdIe1375/I+wfvzY9zZJS64t8 PCdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562677; x=1730167477; 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=dBSkbQIxH9wsbcPCiHBwUytG72Sft1sfvVnb0fwF/aM=; b=XRrVhlOIyuqaf4nsSMyON3URDarOI7KSj3z/byOnKFsJTRhpy5y3gVp7y7tYsIRoGA wKRTIxTCcYK64FXXZ2Z6rY8ScyagVVPoLgB9Ti2QsDrSJcu1dGcGVuPXaxDIC4w/3HOo 6NV0QKe/n6k8dm3ovUd1+qiVMuR1EN64QjsvImrXzZl4Qmin+UKNRO6oSsf9PpcDqxh1 zeZHdOwz1Y/m64EDsSffTOJ2wHoALqDXBTXTBtoT74b1OocdXap4PgPQb1vk2Jb5F5O3 Rt8gyMC9braXE9Op3UCgILjI3Jembx5vAUlWKMhxwkQzJcE8YHWzVlFD+zQ/S4FqJv5w kwbg== X-Gm-Message-State: AOJu0YxqzNvNIYJEobpHgKUQ6M9mvn2/TwUouwSKrlV3zIUv7/bleQ8m vAIp6YFd3sy7lNmUgAuNxtTcq9GsZtdiuVN9zIU5D5wp4XIkBzdYSLlrk8WqYmk09V5DQPrFIAz b X-Google-Smtp-Source: AGHT+IGSHjHnrpmOhVVs/uuCYiDkh8mJ+mi+kXUMX7Lbkgfxr2ZL9NATjI2P7bpojAkT02PyD56JHw== X-Received: by 2002:a05:6e02:13ac:b0:3a3:b254:ca2a with SMTP id e9e14a558f8ab-3a3f405435cmr107364905ab.9.1729562677587; Mon, 21 Oct 2024 19:04:37 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeab58820sm3845534a12.52.2024.10.21.19.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 19:04:36 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/4] io_uring: kill 'imu' from struct io_kiocb Date: Mon, 21 Oct 2024 20:03:23 -0600 Message-ID: <20241022020426.819298-5-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022020426.819298-1-axboe@kernel.dk> References: <20241022020426.819298-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It's no longer being used, remove it. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 391087144666..6d3ee71bd832 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -613,9 +613,6 @@ struct io_kiocb { struct task_struct *task; union { - /* store used ubuf, so we can prevent reloading */ - struct io_mapped_ubuf *imu; - /* stores selected buf, valid IFF REQ_F_BUFFER_SELECTED is set */ struct io_buffer *kbuf;