From patchwork Mon Dec 30 13:30:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13923278 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 5AB901A08B5 for ; Mon, 30 Dec 2024 13:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565388; cv=none; b=eRj2agcuzEngKEyJ+lXlfT7YwoFH0sABKaKExWKfdzmJ7SjVOIUElmh0OdrSEboZ3yCTjcQUpN+bf4w2GKS+h4n4+/3yeue2J7D9y3J/q60KmNPKMf1+/4M9hfY8m5YxNdnl+faHnK0RXiUQMztuiSIKQYnAUOsr6WL+B0GcGy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565388; c=relaxed/simple; bh=+ru0m8VCABWKI7i0qu6q8mWEx0ePC29pq0nhVnZNlUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/upWAXxSJnCzHd00p5FTg64sW1SgOhBlVdul4Va+HY8bqzBxk808UpdAbNanRYTECYZWsLOlSLvRRyHAsCHIU/Nmj0fFkpolZUzdTh8HoSWkM3b1j4K2ac+CTYQWWbWPWE9Y7XCqak0bF/PTae88hytmMo0lPAp43NbDHiC2uE= 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=KdV8QtP1; arc=none smtp.client-ip=209.85.208.54 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="KdV8QtP1" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d437235769so9794302a12.2 for ; Mon, 30 Dec 2024 05:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735565384; x=1736170184; 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=rBhlBvWPHzIweREjAp3dpOzDzxy4v1SZqhMGYzz78iM=; b=KdV8QtP1CxtvGtjmVqqSk+6FIHsEQRsjMVFK5l7OQvjqM+l7dcXoEc+2CY+gzWfTWJ D3kGanDi79El9z175FcPndRAIrXwxOoyzGIpfEa8WlW8jySqux8n0JzhK6T9fyF7ZtM6 qHLsqYuLSUu8uiuKAFVpui42kLjOBirY5C69sX0VcCtzU62dIiJbMj++s8DZCLLv8H9R 4RGWDKGMnuE69agXvJigD66K8ugDjkWxgCYv/8ATbOxe0meiHyW4mgle/nTs5tTJbXB9 e4802BYQB+JGjvn1GhpqKhtmr8ouacC3jVOaYYYCsWKAO5ThDBF+xDOyLLrc+fJwNt7w r8mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735565384; x=1736170184; 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=rBhlBvWPHzIweREjAp3dpOzDzxy4v1SZqhMGYzz78iM=; b=lCqnt50zbAGFFAqA5Z05wfdmseLavGYR2S0PXdHH5oCN/yBnac3lLOpkD+vlBN+MkT qYaWi1O64aglygIwFxvQlByqiXOwApyv9YZRI74nxoTPkd5AqKXxJtZS0zd1Pb2lVkDE Vt146UZRcYJK/pGuJ8mRegtcUH6hlKdXi2wupbl0ACMV0S9/3QoeZXjFkTDlSGeZlNfd n/8DOftBY3p/4+RwBbomqAbxP4/kSTwq/VeZseWrGkWIaHqAygLd/2Q/AilmeGAqYk1p sWzv/eQswWF+XgrugSDh6NHxSP6xm5ZRKvno/xaq+gSmFO2uYJ5naQvBPWcm9rjSCFWy RU5A== X-Gm-Message-State: AOJu0YxevBZjRGqWA7i2Tm5DtvH6bcTluk92B9sLj90ADDYVUF3jwPIh hETCmxkwPtWnSvT0QrjHz1ZBVQM9A/7A3zhY9omgHqKNOgJDGcKFu23+XA== X-Gm-Gg: ASbGncs2EvtlT7ge9/1yimIZQ68vfmRvni9WaPsIVahffNEzwq1i2OIPYFB5A/qR0Kl CFbhntoDPwnLCDMHZmxXriWsBfcTJc2hzIHBJS6ssiPnsLDSRF2gk7cg3awrw34KtMh/GoQNK+H XkxxkEWb8iQuRA3Q9OhAL5dAq3DYDZUWUPDb+bGQCCzWjdyKSONQgEXATj3jhLXeaNYMGDFCPHT ktMMEcHBcFb7ycClJI2ZUKeNIhowNtpnFLlxxwVWdzZ6lfKA1EQI8w7xS8sYtumL8SpDA== X-Google-Smtp-Source: AGHT+IH3fPCCFrf72r54Wb4YNbi8rViwVPRtCJue6xj4E717AlRiqQGBD+fD/9KpG+k+qGvsiZHCDA== X-Received: by 2002:a05:6402:348e:b0:5d3:d9f5:bf08 with SMTP id 4fb4d7f45d1cf-5d81dd5438cmr34394429a12.7.1735565384099; Mon, 30 Dec 2024 05:29:44 -0800 (PST) Received: from 127.0.0.1localhost ([85.255.235.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f35csm14694286a12.51.2024.12.30.05.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 05:29:43 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH 1/4] io_uring: add structure for registered arguments Date: Mon, 30 Dec 2024 13:30:21 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 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 making infra for wait arguments a bit more general to use in in following patches. Signed-off-by: Pavel Begunkov --- include/linux/io_uring_types.h | 9 +++++++-- io_uring/io_uring.c | 23 +++-------------------- io_uring/io_uring.h | 16 ++++++++++++++++ io_uring/register.c | 4 ++-- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 493a8f7fa8e4..49008f00d064 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -83,6 +83,11 @@ struct io_mapped_region { unsigned flags; }; +struct io_reg_args { + void *ptr; + size_t size; +}; + /* * Arbitrary limit, can be raised if need be */ @@ -332,8 +337,8 @@ struct io_ring_ctx { struct io_ev_fd __rcu *io_ev_fd; unsigned cq_extra; - void *cq_wait_arg; - size_t cq_wait_size; + struct io_reg_args wait_args; + } ____cacheline_aligned_in_smp; /* diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5535a72b0ce1..e2b6b256fc9a 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3178,25 +3178,6 @@ void __io_uring_cancel(bool cancel_all) io_uring_cancel_generic(cancel_all, NULL); } -static struct io_uring_reg_wait *io_get_ext_arg_reg(struct io_ring_ctx *ctx, - const struct io_uring_getevents_arg __user *uarg) -{ - unsigned long size = sizeof(struct io_uring_reg_wait); - unsigned long offset = (uintptr_t)uarg; - unsigned long end; - - if (unlikely(offset % sizeof(long))) - return ERR_PTR(-EFAULT); - - /* also protects from NULL ->cq_wait_arg as the size would be 0 */ - if (unlikely(check_add_overflow(offset, size, &end) || - end > ctx->cq_wait_size)) - return ERR_PTR(-EFAULT); - - offset = array_index_nospec(offset, ctx->cq_wait_size - size); - return ctx->cq_wait_arg + offset; -} - static int io_validate_ext_arg(struct io_ring_ctx *ctx, unsigned flags, const void __user *argp, size_t argsz) { @@ -3233,7 +3214,9 @@ static int io_get_ext_arg(struct io_ring_ctx *ctx, unsigned flags, if (ext_arg->argsz != sizeof(struct io_uring_reg_wait)) return -EINVAL; - w = io_get_ext_arg_reg(ctx, argp); + + w = io_args_get_ptr(&ctx->wait_args, (uintptr_t)argp, + sizeof(struct io_uring_reg_wait)); if (IS_ERR(w)) return PTR_ERR(w); diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 032758b28d78..a18da74f18e8 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -514,4 +514,20 @@ static inline bool io_has_work(struct io_ring_ctx *ctx) return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) || io_local_work_pending(ctx); } + +static inline void *io_args_get_ptr(struct io_reg_args *args, + unsigned long offset, size_t size) +{ + unsigned long end; + + if (unlikely(offset % sizeof(long))) + return ERR_PTR(-EFAULT); + + /* also protects from NULL as the size would be 0 */ + if (unlikely(check_add_overflow(offset, size, &end) || end > args->size)) + return ERR_PTR(-EFAULT); + + return args->ptr + array_index_nospec(offset, args->size - size); +} + #endif diff --git a/io_uring/register.c b/io_uring/register.c index f1698c18c7cb..b926eb053408 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -604,8 +604,8 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg) } if (reg.flags & IORING_MEM_REGION_REG_WAIT_ARG) { - ctx->cq_wait_arg = io_region_get_ptr(&ctx->param_region); - ctx->cq_wait_size = rd.size; + ctx->wait_args.ptr = io_region_get_ptr(&ctx->param_region); + ctx->wait_args.size = rd.size; } return 0; } From patchwork Mon Dec 30 13:30:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13923279 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 5001B1A83F0 for ; Mon, 30 Dec 2024 13:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565388; cv=none; b=acqYeYx5t+4KFu2Y4kHsEyPNWhrNopxxlCmAvr7wbS3VTsmhVud0dycIZVtYPGvmgpoJDbrSvAnHRfaULEWmHkyKHS6vFAbi4JChxpggntqqbe0XwaHa/CAALwzG097NyCQYqEzuqAJ2AmYbbLb8bQEBASnD2mx20sbYm+z/x70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565388; c=relaxed/simple; bh=me7i5q4jrFspSMqrXH9ZEGUZiiADFqgD+/KWA9+Z5HI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kkECFDkn9jPej9OSKMET6Cw9F8Peq/S8jJIRj00gRwZzlBS1cjDyxvwvO9EaBa5gQD4B1tjOO5l6hG+JFLocowwOXN7kojnYNTfPtT2BeqyEBSxJ25s1l39eyp2CtN1FHmx1Gz3xTKX4hYrmHUq6uaN1csaqGbGR57ioWUDD8HA= 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=XGcQOSNA; arc=none smtp.client-ip=209.85.208.47 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="XGcQOSNA" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d8de655efaso586531a12.1 for ; Mon, 30 Dec 2024 05:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735565385; x=1736170185; 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=9O0UtBRpJq8GiVtrDcFOtQ56EeyOUld69ffwr5omEOg=; b=XGcQOSNAxsfiGiT7eayZ2VohaeWW/8J06xwJH74aCK/6zsCy4SCLGSB9IwboxTt+yE 2tomv/+zABFS6QfJfnClN3LFQl7Nco+BtsKmsTAakd7WVxCWBheeQBs2YoB02N7xYA4J iEeodRHJC0u/XGY9/E1yJNsPFfNG/8SleZzqx9/EJ5ZTXD2qRg7cFHiX5RbhdXXQEND2 X6K/1YPXqjsaY4WcTVvlCN+9d5DFp1Rk/EIMHMtPuHkArHqHjMkFQVkuxdWn3ptJ/RI8 ap5QTg3BqrQFORnDAkAUqsoEt2E1rE3/gA+xu6+pcD8vHeOLYWYYaMTyMHEsGzfkH247 8/dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735565385; x=1736170185; 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=9O0UtBRpJq8GiVtrDcFOtQ56EeyOUld69ffwr5omEOg=; b=l8+du4BHqBbN4TREhE9xJolUlPoQloc0CCuGeNesv67K+70FLu+Hcccv0J22bFhNKR A/Zq7n0m7J5A8K/XvsbTmWEbKJ+wh6wMuQQ+AwX0G7k+A5c1m+qkO1nWUyLrOR1F2eGX 2L/TghGBlsO6r6sohAy9PMZAx+p7PTlkxQiArmxTBbAjGFdO+1WxxvG43n+A31Bh3QWU kyjNHjyDEk668fPVq9HwL2rBmHBgAXjiZePBLjvVZQCxTzlTVqfIyce1566wcB78O61A cTaD2lMD/Oi5UDNq1iq1WmYQ/KSmXQWJkEd4bue7nJPPxe/UF653UNiXSELUB+BIrf22 7ssg== X-Gm-Message-State: AOJu0Ywl6uoxjmB8v+ce5XH+38FHlY5OS5hiWMAaZ8De51pEILhcPo9o qxhmOldj3Xop5lC7EBEZgqkClofybwXTnzLy2pX3eeNZZow4q9byjQKQIA== X-Gm-Gg: ASbGnct1HIzVMM9uoQK1jTMyFYxVGoZ4OgYYeQ4+pLDaX5GmHXs3GBZJnMvygYzkFGQ HoH0JwUPBCGuiXoWalbUL/VFOGSK2GXCUE7cVqTv94f5f6cehrs50Cks/Ig0QgbbtzW7CUg5CF0 ezAdPofFoL/6kHIn8dh5EuHwm26lI/c1yubDkcrOO4PLgt3SX17FuVliNxbBpCPd40glot5VpCz h6liAKRObNCtwOLtpXlqfuJOpbgRn9W/m8xoTY6CgKWYu7gHJwLtlGU76+N93lND2wn5A== X-Google-Smtp-Source: AGHT+IFyuJfn/TqhXOLROym+BT2SAb4BiW52u3rt8LRlkFldETVwh+n4r61L/NCEM4xjXrjZOS+W1Q== X-Received: by 2002:a05:6402:2802:b0:5d3:d7c1:31a4 with SMTP id 4fb4d7f45d1cf-5d81dd5e8famr37519908a12.7.1735565385280; Mon, 30 Dec 2024 05:29:45 -0800 (PST) Received: from 127.0.0.1localhost ([85.255.235.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f35csm14694286a12.51.2024.12.30.05.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 05:29:44 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH 2/4] io_uring: add registered request arguments Date: Mon, 30 Dec 2024 13:30:22 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Similarly to registered wait arguments we want to have a pre-mapped space for various request arguments. Use the same parameter region, however as ->wait_args has different lifetime rules, add a new instance of struct io_reg_args. Signed-off-by: Pavel Begunkov --- include/linux/io_uring_types.h | 2 ++ io_uring/register.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 49008f00d064..cd6642855533 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -299,6 +299,8 @@ struct io_ring_ctx { struct io_submit_state submit_state; + struct io_reg_args sqe_args; + /* * Modifications are protected by ->uring_lock and ->mmap_lock. * The flags, buf_pages and buf_nr_pages fields should be stable diff --git a/io_uring/register.c b/io_uring/register.c index b926eb053408..d2232b90a81d 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -607,6 +607,9 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg) ctx->wait_args.ptr = io_region_get_ptr(&ctx->param_region); ctx->wait_args.size = rd.size; } + + ctx->sqe_args.ptr = io_region_get_ptr(&ctx->param_region); + ctx->sqe_args.size = rd.size; return 0; } From patchwork Mon Dec 30 13:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13923280 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 6AF8A1A8407 for ; Mon, 30 Dec 2024 13:29:48 +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=1735565390; cv=none; b=bbihbwqk22FDcW+c1Tgjp//t/yMBa1wH7GrTbvuMmoLqxUf+gn6TE8ZERmLdwQIVFZlGqJwEzW3CrP+oQS5VdYq/muBbn6uX58psDgZJijH95TiZyVI0Mm4qk58U3otD3CxhLFT6uY8zQgy3C/bqzD4ncsYuoYuCajUXO/ObFwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565390; c=relaxed/simple; bh=QbfFPINu0lMzqOcIlrJHsO09oZ0sKO+OcaPoE6+GzKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kdrh27tmhstO/InHcEZr7NxSBjL1CTbsYsEilNTT63kEU4uE5+iD8wZKXagxVldCOr/Ch0s8QB/QnhQ0lmaP0PYZ1T2m+ANJVKXTc2kMBUZ51wYHhdf3aCHInWy3IxfsjRs8Sh5Qy9wvs37OvxqrZqqu8guzNBedo4h0GfBpqhE= 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=FjoQSBwo; 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="FjoQSBwo" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5d3f57582a2so18105049a12.1 for ; Mon, 30 Dec 2024 05:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735565386; x=1736170186; 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=IbqMDu4h5fm/YGER5C62CbEH0I5y3CLxfXkq+w+swJQ=; b=FjoQSBwohLH/kcqiiBY0VkxQino3iiim9NAlmMLEYDDXYz3T9JHPG7wGe9aKlZnOGk YUeHkw+88IV9yc3RiGsCMdo+CPSS04Yw3uMh5wGnciSRX/E0KLQNxl0cUPJIXlgrO4q+ S7sh9Vel0WTqG6tNVvwAL6Kek3yYJ9/kAycCVezizPmU/k/AWe3wUvtvgf8jQL7aoc3H 9cB/q4Aj6Hu9lcu2SElKko73243QSSIZYXIt5Jf9ft8KfSk02clHTXjXrjQRWigif9nR ZW43039jzAmyRb1qkok7AGLWt3CsF9u5pnJy0KiWL23TCHsZD0acqCI9N7/9Y5bpWNxq ik9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735565386; x=1736170186; 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=IbqMDu4h5fm/YGER5C62CbEH0I5y3CLxfXkq+w+swJQ=; b=jo/wUlsnEvm7jBjrBxtpAIOUJBITK8u9z0d+cLVxlt2BLUrVqJUGx+H1YMnN49iLI6 nfPM7CMWUIhOiBlESVaW4uIB0vkE6TdMFRNyE8KGihFPAWk9/0+etoolEE49SvbDi/9b rqXYaqzzihsxJ2CdlZHFI8we2W9clTB8+RWwxUAVury1vpM4aQ0sveOoK7war70f77ED OLwz5E72915MJJpbyK7cHrp+g55eHbiVDYShDgOlZzaRZPDulyaqQMRhooAaIt36il93 /htw69Ai6YW8mktkBhfN+QCh2rsnfZiiLMV3UHi59MNBxOfbFFKB2fDSRZH1+6mD57oo ZmuQ== X-Gm-Message-State: AOJu0YxcycNcQslOslOg8MhGWZ08LubIxXVuMXWB6ER3MxjhYaJ/2Qz4 W5YthpMqNlLvdXqZ83mIUqZOc/oSbfC100FNxLFZlul6QyxS8uxA5EuSUQ== X-Gm-Gg: ASbGncvsSVjdz399dB2ExC0OvN8i3xfwX+eV0EEWfIrwemjpIvpESKukFzsNlXG7c2D Wx9jRQ4/J2ihODhHayu3BtZJPZT+1A+UPl3wXrC6qvWvA2wDOXd267bEt04y23hl1QqZpg05k85 JXdoM4ayeZ/rcmXEGdmrVSlqTfO/ADgrAdqytBck05Bh+7zrwlju1siwp9shu0ENFxjCmUjBCoS VclTwNvKrN7Ng09wV7otovHMlTF+zCuwa6yT9ZwXi75fpEVCJi2sib7iwzAgqElH6ORMQ== X-Google-Smtp-Source: AGHT+IHAcRCcJx0naousjL/x8lCegSX/+cuGOf+cvLLpn5xyMOd6pLWwAiZYL6pE9MUqsVvccTs0nw== X-Received: by 2002:a17:907:7207:b0:aa6:112f:50ba with SMTP id a640c23a62f3a-aac0815366cmr3610280266b.13.1735565386201; Mon, 30 Dec 2024 05:29:46 -0800 (PST) Received: from 127.0.0.1localhost ([85.255.235.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f35csm14694286a12.51.2024.12.30.05.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 05:29:45 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH 3/4] io_uring/rw: use READ_ONCE with rw attributes Date: Mon, 30 Dec 2024 13:30:23 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation to pre-mapped attributes read struct io_uring_attr_pi with READ_ONCE and use an intermediate pointer. Signed-off-by: Pavel Begunkov --- io_uring/rw.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index 75f70935ccf4..dc1acaf95db1 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -264,23 +264,29 @@ static inline void io_meta_restore(struct io_async_rw *io, struct kiocb *kiocb) static int io_prep_rw_pi(struct io_kiocb *req, struct io_rw *rw, int ddir, u64 attr_ptr, u64 attr_type_mask) { - struct io_uring_attr_pi pi_attr; + struct io_uring_attr_pi __pi_attr; + struct io_uring_attr_pi *pi_attr; struct io_async_rw *io; + void __user *pi_addr; + size_t pi_len; int ret; - if (copy_from_user(&pi_attr, u64_to_user_ptr(attr_ptr), + if (copy_from_user(&__pi_attr, u64_to_user_ptr(attr_ptr), sizeof(pi_attr))) return -EFAULT; + pi_attr = &__pi_attr; - if (pi_attr.rsvd) + if (pi_attr->rsvd) return -EINVAL; io = req->async_data; - io->meta.flags = pi_attr.flags; - io->meta.app_tag = pi_attr.app_tag; - io->meta.seed = pi_attr.seed; - ret = import_ubuf(ddir, u64_to_user_ptr(pi_attr.addr), - pi_attr.len, &io->meta.iter); + io->meta.flags = READ_ONCE(pi_attr->flags); + io->meta.app_tag = READ_ONCE(pi_attr->app_tag); + io->meta.seed = READ_ONCE(pi_attr->seed); + + pi_addr = u64_to_user_ptr(READ_ONCE(pi_attr->addr)); + pi_len = READ_ONCE(pi_attr->len); + ret = import_ubuf(ddir, pi_addr, pi_len, &io->meta.iter); if (unlikely(ret < 0)) return ret; req->flags |= REQ_F_HAS_METADATA; From patchwork Mon Dec 30 13:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13923281 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 2D5651A840B for ; Mon, 30 Dec 2024 13:29:49 +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=1735565390; cv=none; b=nDZoADNHX/7/emcrlMbo3Be6rvFYDYlxoz1Xj8IxKKTEVjetmFAqoZtB8/x3urGDEm9y8SBqw2urWbLhm0WUPRtFbK/A5U/x1BpOOT58Yjqc7L6MpCE9zgVEucgeBNlmeVShifrY/nb8MiAD9Xae6APAD32fBij5PSqMkSRJrKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735565390; c=relaxed/simple; bh=IDD18nfOacHH6xthKMwD+JSo1KFKeCmsSiilhvik5R8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j0Z+yIJWAhGGs6KQN3VJAklR0oMZ5ChXQWQ1Ml2oG8F46g4PK0Z46azdAVNg0RPIHyYrHZtDU2EjNRXXQgFznQ3DuTDXIIAGfitoMz6J/Jec8GPgv74MRbAKaqMEqAPpj6zPocXgEQwquhW88TmVKpSX7NxrJJS29/kcYnKBOJ4= 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=aHMHF86i; 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="aHMHF86i" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-aa6b4cc7270so1317955666b.0 for ; Mon, 30 Dec 2024 05:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735565387; x=1736170187; 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=nyT+dmpD0OjpuzQVnEahu3gllLOIz9gM7y0hDq3JK58=; b=aHMHF86iWi/oc/mZiE0RlmkUqwSzuuwD0Hrg4mXrx176y3EfTxrz4Yuau8dEb2oehB en/fo+jtZkvN0IF+JAOgIzvOblmxSZvUyZD+0MD/ZcPxwu7zV78DA2cIXgeq+WjS8Jlm WfvOx0kYvFXwqCM6s5jojBG6O4NhhBEfhGwk4OJdxSIq7nqglVeSCbAKev/ojwVpJ6a7 ugYtX9t1SfSi4wry783r1QHnVOHNdMfKRKZHVKhmpCj8T6F/ZmUR4AOFjxayMIRubDGb XTv7afrSaUQ4Q42SM4vLOzsonzC0gzyZ5pAZT6oy0tJxSoVraKOAccd2hnBwUyAXNkZd qC9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735565387; x=1736170187; 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=nyT+dmpD0OjpuzQVnEahu3gllLOIz9gM7y0hDq3JK58=; b=Qbm/E8ILrfoc3TwA3Bh8bx8+hklR/59UCpkXoc4hp21m/Hfte2V/W+0y21LLSwnSkH uTH3l0F/c9Bmw1g4qwtPsNAYuygDeojFgMKkVE9RzBQqU55WQ2l/x4tpnqppO2cHoEA1 HLP1moxVRrNlbcUK41cCf4d2uM3S3cymHhwUJv6waelvdneQgrO1Na7fgAdVRNSECRTO FASDTtRTQwV1156nk8qh5gSTDWfc15BNyrFOdH8IetgIYoOfCYLsbXn0eMlSz9M39rka Lq3Fihj/z/hpiCKSpoZ+UpA/iHSKiUpTfLkaahPGBsiJvQQGnOTCwsGDuIArYdp22OnH 4Taw== X-Gm-Message-State: AOJu0YztnIi73ilrQsJz79ger648N+tmih5GV/sCkTKy9vOCUeWbA7uv KVYn1nnD35ebfU5ayNACIf1Q0MtKsKWARbFXoRG6ynPjgyNgGeNuKvHq8A== X-Gm-Gg: ASbGncu4JNXbyPT4/ogUL15fkwZsQHrKXWXHML8RjRnJe1RoMR82KjbHTHZjon1BtK2 XEdY9Y768jicPZq7/h8PpV5OF07Py03TTYENh1jJXS+Jk0Xjd6sOl/OAeKU6eYASsJXFAZ82ADY iIDNuYuXfKg3QWKpDO52U0kibaLRV7S8ybRFmWDp4kyfj8DlPeuJVkkHp5qiiJcKuUbwdpQAz5m zLk2qTaD8N7TSPvJDm4eQW04qtgoVtF3LGUZ8o+YHv+1JhL0rU/AoEafxmy+fYPxJsDDw== X-Google-Smtp-Source: AGHT+IEMoC+fgEDZrp6dJmyI5ozwoogttigIrd2SEoYzMt7Yfx2NSCd9OAH0Camo+Kzhn82C4pFG6Q== X-Received: by 2002:a05:6402:35c2:b0:5d0:ea4f:972f with SMTP id 4fb4d7f45d1cf-5d81dd9af30mr73089455a12.8.1735565387302; Mon, 30 Dec 2024 05:29:47 -0800 (PST) Received: from 127.0.0.1localhost ([85.255.235.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f35csm14694286a12.51.2024.12.30.05.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 05:29:46 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com, Anuj Gupta , Kanchan Joshi Subject: [PATCH 4/4] io_uring/rw: pre-mapped rw attributes Date: Mon, 30 Dec 2024 13:30:24 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of copy_from_user()'ing request attributes, allow it to be grabbwd from a registered pre-registered parameter region like we do with registered wait arguments. Suggested-by: Anuj Gupta Signed-off-by: Pavel Begunkov --- include/uapi/linux/io_uring.h | 4 +++- io_uring/rw.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 38f0d6b10eaf..ec6e6fd37d1c 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -112,7 +112,9 @@ struct io_uring_sqe { }; /* sqe->attr_type_mask flags */ -#define IORING_RW_ATTR_FLAG_PI (1U << 0) +#define IORING_RW_ATTR_FLAG_PI (1UL << 0) +#define IORING_RW_ATTR_REGISTERED (1UL << 63) + /* PI attribute information */ struct io_uring_attr_pi { __u16 flags; diff --git a/io_uring/rw.c b/io_uring/rw.c index dc1acaf95db1..b1db4595788b 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -271,10 +271,17 @@ static int io_prep_rw_pi(struct io_kiocb *req, struct io_rw *rw, int ddir, size_t pi_len; int ret; - if (copy_from_user(&__pi_attr, u64_to_user_ptr(attr_ptr), - sizeof(pi_attr))) - return -EFAULT; - pi_attr = &__pi_attr; + if (attr_type_mask & IORING_RW_ATTR_REGISTERED) { + pi_attr = io_args_get_ptr(&req->ctx->sqe_args, attr_ptr, + sizeof(pi_attr)); + if (IS_ERR(pi_attr)) + return PTR_ERR(pi_attr); + } else { + if (copy_from_user(&__pi_attr, u64_to_user_ptr(attr_ptr), + sizeof(pi_attr))) + return -EFAULT; + pi_attr = &__pi_attr; + } if (pi_attr->rsvd) return -EINVAL; @@ -294,6 +301,8 @@ static int io_prep_rw_pi(struct io_kiocb *req, struct io_rw *rw, int ddir, return ret; } +#define IO_RW_ATTR_ALLOWED_MASK (IORING_RW_ATTR_FLAG_PI | IORING_RW_ATTR_REGISTERED) + static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe, int ddir, bool do_import) { @@ -332,7 +341,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe, u64 attr_ptr; /* only PI attribute is supported currently */ - if (attr_type_mask != IORING_RW_ATTR_FLAG_PI) + if (attr_type_mask & IO_RW_ATTR_ALLOWED_MASK) return -EINVAL; attr_ptr = READ_ONCE(sqe->attr_ptr);