From patchwork Tue Oct 22 13:32:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13845691 Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.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 D669E1E481 for ; Tue, 22 Oct 2024 13:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604092; cv=none; b=b2GR6oSyt6kynKzo8YqMBk6Uz9Dd6hJ+JWge4ha3Fzi3CtcGIkPh2UlwVZcb6b8TDRgzgYdPSOjlCrHEeXcVVVkfsfSLINhwhNvOvVZ3n7vRz6T4jRZGMolyKxYj6uVa71r7XNGqjDCvPnRaxQQU+w2ggEQb0HIFbyxUmPEyz/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604092; c=relaxed/simple; bh=Kz4vGkhsU14SInO/EThGe6nS05YsS+HhirZwa3uwYGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TuIeIBH11N/fmhQ3jevr3ds5Jaz6hKphGUJ2q3fvEBPPvU4nkRIJw/rHUgTKIUb7LN2SKz+ZthOxUdm1KkHml+pC9b8JIimcshwvdMub8cBq7T6U3xWO3rd2jiVKNWVU0QuDRfN8lBapX63T3X67196TpdsQ3/a365hI5EiRQ4E= 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=D4O/o1fq; arc=none smtp.client-ip=209.85.166.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="D4O/o1fq" Received: by mail-il1-f171.google.com with SMTP id e9e14a558f8ab-3a3f82b2018so12826665ab.0 for ; Tue, 22 Oct 2024 06:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729604087; x=1730208887; 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=PVEVwHtUh+ycaU7GqFc+/vwJ88P9ex7Or1DogMBql6s=; b=D4O/o1fqHOeXCV+1w9WDiCDaOd7KQKNSbWnF+1ul9tM4XNeLpDqzXAsdObRQ23mLea aoNw8lIiyQnriNW60hvYPs/pQqmh3gJZ7om6+IVEZwY+e3UZDQVtBKGOKsT3em/M+iin +PaEAGOkbwHJ8CoaPLyrCHiXzU+aG7kfdfj32UvCr92SUoYOJHVGJimh3qbPF1FYY8eJ 62pV0rHnbm93twwRkpWbAs4iPblNKSsrY4xU+/WA++mHc08G970kUlfwoqb9i9jYkxkz rHZ1/5FF6Hilw++R/KxvbQ2U32X8L216fz6rL5TE05v9JROmIYhmcHZKjDm5NjOZXsnz SGdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729604087; x=1730208887; 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=PVEVwHtUh+ycaU7GqFc+/vwJ88P9ex7Or1DogMBql6s=; b=SHCSZEoYaXX0WPZkRU3cj250iMA0pONSOQBWTXWFdfLvUcjPyZxiOXvb8DM9YXy8/D phzoBw6POeq+QRyhj8cmoemnZxJ8gMZrLu8bzO7xMp+2r10zw5m7JiUmQ9SDbF3kIp5c svuWm/r4pIoEFtf/AsorabwrBYBBgzQKlT8SegX1Mi5MmaaH+GxPTXSeL7V0NEgugX1x Q3ZzRrvvhWDiuMIE7jgtHiYsTQIs2Zn8O3YGFxsJ6jWkg8R/0j8NZwrWtHW3z0Itlmjk cdfaZDbciBdLnJvdcy/vgrNNf1bQZZ7cWFrQpAwghzbPn5ynKrhFo2paVFo5PqVH0aG5 RpOw== X-Gm-Message-State: AOJu0YzZibVIOakGlJ8Vm0ubdg4gJyTjiwv48U90s40mSVKaCjMPtK7h 1DXbOyfJXOPXRebTipStO51cpMOLZ0shUqwViXSvJceGQwAIz3/Mr0I4OiIb3bhj0G2et+Q1ZCW E X-Google-Smtp-Source: AGHT+IGDUxO24JoxuiT14jNyoUG9xxnOwGk/D/aTDEy8c9WcIPT+0UT4W7yPzAtCFv3kkfKrCjbKhA== X-Received: by 2002:a05:6e02:16cf:b0:3a3:af94:461f with SMTP id e9e14a558f8ab-3a3f4050131mr145081265ab.1.1729604087464; Tue, 22 Oct 2024 06:34:47 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a400b7c76bsm18032385ab.72.2024.10.22.06.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 06:34:44 -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: Tue, 22 Oct 2024 07:32:55 -0600 Message-ID: <20241022133441.855081-2-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022133441.855081-1-axboe@kernel.dk> References: <20241022133441.855081-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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index 39c3c816ec78..58d0b817d6ea 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,17 @@ 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; + + /* Must have had rsrc_node assigned at prep time */ + if (req->rsrc_node) { + struct io_mapped_ubuf *imu; + + imu = READ_ONCE(ctx->user_bufs[req->buf_index]); + return io_import_fixed(rw, iter, imu, ubuf, len); + } - return io_import_fixed(rw, iter, req->imu, ubuf, len); + return -EFAULT; } EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed); From patchwork Tue Oct 22 13:32:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13845692 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (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 351298063C for ; Tue, 22 Oct 2024 13:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604093; cv=none; b=OtaxM2JznHzPXorAiPj7t0BSXedC6EPPHB8JTDUVrKbZkGQiasJ664UfpF8vniqje4utO+HVMHB2hIR/iKSM9lkrHG6O/xLhlomTzhdVS+WAtev9D0tDWRHMLwg9yRS4+gINSj6nrMylJo90d5Ws+FQvM4zLuyGfZtuzheqNvDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604093; c=relaxed/simple; bh=oDiF+iJtDAqOQFD3zFbOwHq1eNByLNSUH9pNke+Mbqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bzl5GRtX2bkcyi+QLZbxaNTsrF2dHMdc+YqW21073iUY046mYagXfsig9gfKtZa0lumZo0UbDbvkvjUf0S1tNe5jX3va3/6GQqjMVjtODHZP5mUF4haLBs1HkFczBYIIGUZ/rEfcvx+OkGPxWMSvaFvLK8IO6snCfozoQL3M73A= 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=Or+ZHDR8; arc=none smtp.client-ip=209.85.166.176 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="Or+ZHDR8" Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3a3aeb19ea2so20496275ab.0 for ; Tue, 22 Oct 2024 06:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729604089; x=1730208889; 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=Or+ZHDR8QKtT5XwcAb6/unOnTn/pXh74PmAaVBGUrDiLawSBJUuN/F6nccUr0auhEX g+hPq//EA8qgMYRj96wpx1/RdY0YWZtkWgrRSZrkUBE2+FCvgRvQ7spome8idgvOTr0N LeT/jHenf+LB2i8sLmp1mh3Fo2VK5K3yakmnNqwDuVEmzfp2KvWkCLAK6DcLD6wrctaj CGUzbk1wiod45HcmwA+JVpReVH2HF0k3mSGsegB020jIT+u+jVvMo1L/0ufW9G1aIgZx V35qaoAkw3DS05I7T9ErOWh2ama8hRIAfPQk0YzI2m95PHT593Ua8Neewu1/7kOTHT47 d6Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729604089; x=1730208889; 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=gTl4VhQAFAzfTjwgpWHtU4dH0MKPf0IXXnUqKSRzmeSLYQBxHd5sIwEdCbyHHhfbPJ tJdARBVSXuAE2z1ryfp/SSX98X61RRJ/TrZft4rpu7uBn21JwLr7n5p44fjFtLoIMxv8 NSXBFfNRkeJ/7gjp9wHWUTOXdnDVd8g+1pbTQtgK5dsQe1peVTioQogU+33Xdu6uXtgf 2+EH0qD75tz9y6RhB3heZ8oUzoLZNrLba7q+FaLnsHljcZDutAdDpiDy9PpWsfSDiefX JK4Cm5CzJfp5bR1WkLRq02s9tnazVAn1ex4uO1J6lZUjoqdPSSandqe8OkjG3W6O2q8e nazA== X-Gm-Message-State: AOJu0YzyL9Ys2uKJn92jxtyPZIeTJNcVOuONBj4pGh8i2tKg9lXdAhet Q56piIWk1sByiR02nEb1ZmW8I4q65keG6w/zneLzMGBVWUTAwySHD5P2dx4LGk6hDsuA1xgpANh z X-Google-Smtp-Source: AGHT+IFVXuej426JlMC2c7o9inbu+wH3hO+G59DaWZjOyU5Dp2D6pDT8083BLqOaEfAyHWOW/i9jVw== X-Received: by 2002:a05:6e02:1fc7:b0:3a0:9244:191d with SMTP id e9e14a558f8ab-3a3f40ab47cmr136132985ab.16.1729604089558; Tue, 22 Oct 2024 06:34:49 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a400b7c76bsm18032385ab.72.2024.10.22.06.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 06:34:47 -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: Tue, 22 Oct 2024 07:32:56 -0600 Message-ID: <20241022133441.855081-3-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022133441.855081-1-axboe@kernel.dk> References: <20241022133441.855081-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 13:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13845693 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.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 B62DB8063C for ; Tue, 22 Oct 2024 13:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604095; cv=none; b=SjhwI9wixnxHLZKirunQ6VlA5uXAno4PWjeL5yqxHPDMB5K5u7Wq8j53QzObd5w1j2F/Iiju1maKBP1yInUxUDWF0aWlZlKTOEgvnJjxIKuMdmNwGlQAXQLx8bXbYgwmn9MC/QNYmFdSpVnqY1/YkzzyXR4FouMeKOpG3X3epgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604095; c=relaxed/simple; bh=3kYq0C5TWd8rkmdhoT6VK1j4LEkRJ2s4Y0vBsL4z25o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FYRpNAoKMVMcjAF4jH1yQO5k1dFs1kNEC75N1emsNrfX+dY88dwic/SEovPl2KS7ZyujSGnMfLeoNK5I8fg1OQ5YB6w/xvIjnVZX15RkxtRJOrGh6jzsQF7S8sZL69d/iousRP6dpgsoVvNvi/7yj5DeruUYtmHNRxmxdOfC6GY= 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=iDoOaZSl; arc=none smtp.client-ip=209.85.166.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="iDoOaZSl" Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-3a3bb6a01eeso21723615ab.0 for ; Tue, 22 Oct 2024 06:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729604092; x=1730208892; 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=iDoOaZSl2X+GXiwz3u/g/xTL9QFrzHwHQ9TYicH87O45A/7yvt22wF6w3mFAu6QigK FcN+cm5yXkK20y8mXytT5EHBaLYOEIiEF14i/wf5ZNFqowqtguiuJY4k2q0rq9WQRhQJ 1Xoe3XuHx2wAoMOWQmLxuxfKijgVq1LpK/YKIOTYSjZV1BphMglFTWlRltKdQZ75iogM fxevf/ilj0lL6v4T+qZv6sEOl8xRpTa9KUGcR9pW2QcKUn8uq1OzYvWnfAylSJBGrOUT CE9WLsklHgOYvcoevmDV/5LfO2E2QpnFAq+Rz9D6y6qmOfLcyTIPUgsGMv8fjVd/uTUs n18Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729604092; x=1730208892; 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=Ub51A06MdxhUQIkyd1FzD0tJ37VhV416s0HMWed+7YsLFvwxLGuiZHecbweUzal5Co hXJfM1DdiBMu/QgP5W4MkhnTnXDAgcTFL4pRL/1ofvCnHJGF8Q4ENkosRWvP9HPr4FfL b8DgJhWPJdCdR+1SgSh0mNdWCrNNP7bY1TTedH7fdV9zFhwnm5eVmgn4kZMs5R++K3Zt qnpp3mEDnJKArL1QMhSFAwsKCp5jLXSbxs3oboHnebfJ6aPWurB2HxQi3LhPHquWzPq6 RDTW0RJmd3Z//Hk4/GjPtaFZGKicURs5KvnD/1AkQkwju+hyz21acsq/E1yviroK/kZU hYPA== X-Gm-Message-State: AOJu0Yw32l8Jpc4rRroujlayV0/FCGbRien7xVlUAVf7fHyjbEbexhVM 0Ca1HjIjE+SA0YxaFzK6WRGKz52ShMSFopu6I0BH8B62nbBCKJKtWFsBE+nedJu+dNEu8ndf+7e 6 X-Google-Smtp-Source: AGHT+IF8niKoHZhVwTWMWJUiRfWuzp6ACHcwRl6C2M7He1AnnX8Ne8CBQJzx7kA6h/bHl5OIzw1uJQ== X-Received: by 2002:a05:6e02:18c8:b0:3a0:8f20:36e7 with SMTP id e9e14a558f8ab-3a4cb4f25c7mr42552375ab.19.1729604092171; Tue, 22 Oct 2024 06:34:52 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a400b7c76bsm18032385ab.72.2024.10.22.06.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 06:34:49 -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: Tue, 22 Oct 2024 07:32:57 -0600 Message-ID: <20241022133441.855081-4-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022133441.855081-1-axboe@kernel.dk> References: <20241022133441.855081-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 13:32:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13845694 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 208E98063C for ; Tue, 22 Oct 2024 13:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604097; cv=none; b=fnN+sPKW9ggqOpgdci+TRhI4+TJtC9ohGBLxrLiuM170mQ87GzmQLcVV4TFU+w7ycnjNfhlgetal+MrkyCr1XIxsF/FDg4sqgL2MWgO41VHPW4TYxlglQoRbRQD99eOOo3g8Fw8P50280V8z9RqRWBxygvRkFgPPTm4WP2rseFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604097; c=relaxed/simple; bh=xTsMZ1NscutzFx3vj+pkF7qRllj0ph1Ef4bK3IFUMp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RE3VgMGyT+RR45xKVipjjrHDRJZwdAizpl+GBOy2p1T7hbkXd8mh1ZBbdeHJhRM+lqt84/y3XeyZ/MAF5pd8fkyHtzxUG59Y7C3o+YQNjrJqWRzj7RYGqLvezwn4tfbbklViqGClRAwJvS8TSGGrXa0D/iIN5bKcGznD9kcuR8o= 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=msrrBwUP; arc=none smtp.client-ip=209.85.166.177 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="msrrBwUP" Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-3a3b1aa0e80so23507025ab.1 for ; Tue, 22 Oct 2024 06:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1729604094; x=1730208894; 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=msrrBwUPInQTBtQXxkeoH/a/L8PIRBkAO/pnLHodRZbUBV6ZzZbkpM/Jx26mnRS9zC toOFYnY03KF5exPK9DpC93ig21CiAxO3W0uulT9DiBO7iUkwHioECu6u9nnnh3WKNWTJ d+tpqYwghUuLKbD/0vVicEPWV7mYxcqHRkBYx8dJYGJHJFOjWDGydu/9Vd8MOgiNpezH iKtVk6YFRDTPAYTVOW+FrOxNhoJJc40RnmhQW71W/IwLvKUnvoVD4aJxjvV6xM4KJhR5 /HnI/jK8FiYkG+GbQ1TLQwOLwhrm6n4LpxlvVOrl16oudPF6Tm7faXQVCBYEQVui2kjl HxZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729604094; x=1730208894; 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=T3vxL39temuFMrnex9NMQ+64Sb+P5cUFYVfQN6MltrP8x1DuI4bg+a93HDpUb7+loJ d8Gf4c3rCgdjrV2LuKqZ27cxMv6XGl/r7TB+T0iAzpr++VPBN0S+Ousu3ZyJzsT+xX4V wITgmHybJULU7kWLi06TgL2uhIQqNGz0yLTM6SROMY3Oe99N/dtOQsN0UhK5MihbHjhK iLfJ8AGbjc8Tvb6jGn+RyfDNMGuPYao1AxbUg/LxF+Sx8chbS3uwPIjuanlybNA9Kk/G oOcXEM2LJ/GiT0eRtlwLbvwezFUAM/OR166HAYGfCDULvFEFAC1XNJj4AVTTmY+0njJy Yn1A== X-Gm-Message-State: AOJu0YwRs5NkxLW84eD34mhkTJJnGpbfxm+siuSxCfhznCQCKJjc/Wns Wo31sHnoIG7FwHorc4SuEkZtJz1d2+3CcBPUZjXmSvnfYlvWzjstGnmS7ff4cSeBThnKQKRaEza 6 X-Google-Smtp-Source: AGHT+IH2FiVI3lN+DbElsJUjmx+BnUqWqw/31iptPVelEvwM0t7mJkvZ0jTZi4N3P7zuFNt0DqHqPw== X-Received: by 2002:a05:6e02:1d9b:b0:3a0:b631:76d4 with SMTP id e9e14a558f8ab-3a3f4045790mr152261065ab.1.1729604094286; Tue, 22 Oct 2024 06:34:54 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a400b7c76bsm18032385ab.72.2024.10.22.06.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 06:34:52 -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: Tue, 22 Oct 2024 07:32:58 -0600 Message-ID: <20241022133441.855081-5-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241022133441.855081-1-axboe@kernel.dk> References: <20241022133441.855081-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;