From nobody Sat May 10 02:43:04 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1608447141; cv=none; d=zohomail.com; s=zohoarc; b=KFG3/JtiY7ppttTKjeZYJuJlBrue4L09VG8+5uH1yuAV3hobGRCfdE14QaYeLlqT660Ile9AdAfe9jsZUTPP3Z3S4zYuufO65id4O4i3hbkM7EpWgHH8sBB+XPPU680sTo0pVtoiDAEg60jz/ebAgDg8Qlfr4m+2peHzzOQVBDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608447141; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:MIME-Version:Message-ID:Subject:To; bh=GxxzTBDSRDHyuhWRw4W2qqZlaU5pdzFe8fEwTaUs9WE=; b=Rv3aBEQ5EdMiAnWmEngBZfhWScidQKPwIa9n5umMVnhOcS8lA6Es9OcfcEqMJgcqXtTbqAGZ82o/MCDZzbmQqXVEyeNMA/pATQcgEZA218yFHJ0C6SmDy+yUT1JOMftyKoiOl2L6emSl0WDev6J7qs9sEkjc0ulJ4bEUX9LHwU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1608447141887509.4228170897451; Sat, 19 Dec 2020 22:52:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727314AbgLTGv3 (ORCPT ); Sun, 20 Dec 2020 01:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgLTGv2 (ORCPT ); Sun, 20 Dec 2020 01:51:28 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C096C0613CF; Sat, 19 Dec 2020 22:50:48 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id v2so4521305pfm.9; Sat, 19 Dec 2020 22:50:48 -0800 (PST) Received: from noah.hsd1.ca.comcast.net ([2601:642:c300:6ca0:1800:e2b9:9586:956b]) by smtp.googlemail.com with ESMTPSA id p15sm12579758pgl.19.2020.12.19.22.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 22:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GxxzTBDSRDHyuhWRw4W2qqZlaU5pdzFe8fEwTaUs9WE=; b=gzqoY1gK/EQtK1qgxt9rkz7xbvNxdeH/QWq71v7oqV2qklg/yCCdyGLEwdsYDaGMZt lsYsodqKyEWk2MMVKW1qf+SzlRRNgcFsgaNvvy1UJtdiR9IoKJQ2o7F5SlFLWKB63u6+ 3EFpst5/1I2QNV+tuCO74oNJk+dDWRA/vD2gUAanvIIXYvJCm0xsLZwTrTHT71gPEp72 j3/qtQHKtB5ZIkIivBeWpKgmHoXcy1SI/weHLS+4WXUptBS+RdiFh8omC9FScHUVtnlg e4hAvYyfq0Uv+jdgYAV4s2OzmlUkMabN6afVI5MuRQBLlAWMMSbSaz9V2Dw8+B2IlBCL aH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GxxzTBDSRDHyuhWRw4W2qqZlaU5pdzFe8fEwTaUs9WE=; b=ATp0dvvg2UBBccwMzqtJ11L1f6sgN5/c9u4WhkdpyDwlAYSp92NU6wfhaI1KNYF88a p5QbpLG2C7orwj6ts//zYohP5vY6yA5VtmgJxgQWX6TpuMxzHlJ2mQUCYtS1KxiTzQRV gXULmhCrZotjxJpd9UTKffX54g7HNgXu+rbna4UykfzYZYn1BZGeLkF2TKlO5MOuMdZ1 zifCi4OhwSq7vyBEsEW7Ij944zRiz6249e+qH0svTfnaiNIut/xTtxbA98/oBVeYTEbN g+TMxgq68sD3YWlF5uswBtEImcHh+6J0afw4ccRld7w2nxDGM9VbUzFVvFLalP4tlDP4 i0yQ== X-Gm-Message-State: AOAM530jXJkIuRB7SilCYinjfouBl2aRvea/NDNeKOMFT1vG791a+vc/ PPmys8DSEpCIQJr27yvtxvg= X-Google-Smtp-Source: ABdhPJxMe09hsE9jwnlOmDLbZhHlSE4vk3ID1ryYwiMBtx05aKRzON/oHJrTPtebB0lZsHsufi9b1g== X-Received: by 2002:a62:ea17:0:b029:1ad:4788:7815 with SMTP id t23-20020a62ea170000b02901ad47887815mr3057594pfh.1.1608447047524; Sat, 19 Dec 2020 22:50:47 -0800 (PST) From: noah Cc: goldstein.w.n@gmail.com, noah , Jens Axboe , Alexander Viro , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update Date: Sun, 20 Dec 2020 01:50:25 -0500 Message-Id: <20201220065025.116516-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: noah This patch makes it so that specify a file descriptor value of -2 will skip updating the corresponding fixed file index. This will allow for users to reduce the number of syscalls necessary to update a sparse file range when using the fixed file option. Signed-off-by: noah --- fs/io_uring.c | 72 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 6f9392c35eef..43ab2b7a87d4 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7876,42 +7876,44 @@ static int __io_sqe_files_update(struct io_ring_ctx= *ctx, err =3D -EFAULT; break; } - i =3D array_index_nospec(up->offset, ctx->nr_user_files); - table =3D &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT]; - index =3D i & IORING_FILE_TABLE_MASK; - if (table->files[index]) { - file =3D table->files[index]; - err =3D io_queue_file_removal(data, file); - if (err) - break; - table->files[index] =3D NULL; - needs_switch =3D true; - } - if (fd !=3D -1) { - file =3D fget(fd); - if (!file) { - err =3D -EBADF; - break; - } - /* - * Don't allow io_uring instances to be registered. If - * UNIX isn't enabled, then this causes a reference - * cycle and this instance can never get freed. If UNIX - * is enabled we'll handle it just fine, but there's - * still no point in allowing a ring fd as it doesn't - * support regular read/write anyway. - */ - if (file->f_op =3D=3D &io_uring_fops) { - fput(file); - err =3D -EBADF; - break; - } - table->files[index] =3D file; - err =3D io_sqe_file_register(ctx, file, i); - if (err) { + if (fd !=3D -2) { + i =3D array_index_nospec(up->offset, ctx->nr_user_files); + table =3D &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT]; + index =3D i & IORING_FILE_TABLE_MASK; + if (table->files[index]) { + file =3D table->files[index]; + err =3D io_queue_file_removal(data, file); + if (err) + break; table->files[index] =3D NULL; - fput(file); - break; + needs_switch =3D true; + } + if (fd !=3D -1) { + file =3D fget(fd); + if (!file) { + err =3D -EBADF; + break; + } + /* + * Don't allow io_uring instances to be registered. If + * UNIX isn't enabled, then this causes a reference + * cycle and this instance can never get freed. If UNIX + * is enabled we'll handle it just fine, but there's + * still no point in allowing a ring fd as it doesn't + * support regular read/write anyway. + */ + if (file->f_op =3D=3D &io_uring_fops) { + fput(file); + err =3D -EBADF; + break; + } + table->files[index] =3D file; + err =3D io_sqe_file_register(ctx, file, i); + if (err) { + table->files[index] =3D NULL; + fput(file); + break; + } } } nr_args--; --=20 2.29.2