From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Pavel Begunkov <asml.silence@gmail.com>,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 5.9 05/74] io_uring: stash ctx task reference for SQPOLL
Date: Sat, 31 Oct 2020 12:35:47 +0100 [thread overview]
Message-ID: <20201031113500.297738073@linuxfoundation.org> (raw)
In-Reply-To: <20201031113500.031279088@linuxfoundation.org>
From: Jens Axboe <axboe@kernel.dk>
commit 2aede0e417db846793c276c7a1bbf7262c8349b0 upstream.
We can grab a reference to the task instead of stashing away the task
files_struct. This is doable without creating a circular reference
between the ring fd and the task itself.
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/io_uring.c | 47 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 13 deletions(-)
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -265,7 +265,16 @@ struct io_ring_ctx {
/* IO offload */
struct io_wq *io_wq;
struct task_struct *sqo_thread; /* if using sq thread polling */
- struct mm_struct *sqo_mm;
+
+ /*
+ * For SQPOLL usage - we hold a reference to the parent task, so we
+ * have access to the ->files
+ */
+ struct task_struct *sqo_task;
+
+ /* Only used for accounting purposes */
+ struct mm_struct *mm_account;
+
wait_queue_head_t sqo_wait;
/*
@@ -969,9 +978,10 @@ static int __io_sq_thread_acquire_mm(str
{
if (!current->mm) {
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
- !mmget_not_zero(ctx->sqo_mm)))
+ !ctx->sqo_task->mm ||
+ !mmget_not_zero(ctx->sqo_task->mm)))
return -EFAULT;
- kthread_use_mm(ctx->sqo_mm);
+ kthread_use_mm(ctx->sqo_task->mm);
}
return 0;
@@ -7591,11 +7601,11 @@ static void io_unaccount_mem(struct io_r
if (ctx->limit_mem)
__io_unaccount_mem(ctx->user, nr_pages);
- if (ctx->sqo_mm) {
+ if (ctx->mm_account) {
if (acct == ACCT_LOCKED)
- ctx->sqo_mm->locked_vm -= nr_pages;
+ ctx->mm_account->locked_vm -= nr_pages;
else if (acct == ACCT_PINNED)
- atomic64_sub(nr_pages, &ctx->sqo_mm->pinned_vm);
+ atomic64_sub(nr_pages, &ctx->mm_account->pinned_vm);
}
}
@@ -7610,11 +7620,11 @@ static int io_account_mem(struct io_ring
return ret;
}
- if (ctx->sqo_mm) {
+ if (ctx->mm_account) {
if (acct == ACCT_LOCKED)
- ctx->sqo_mm->locked_vm += nr_pages;
+ ctx->mm_account->locked_vm += nr_pages;
else if (acct == ACCT_PINNED)
- atomic64_add(nr_pages, &ctx->sqo_mm->pinned_vm);
+ atomic64_add(nr_pages, &ctx->mm_account->pinned_vm);
}
return 0;
@@ -7918,9 +7928,12 @@ static void io_ring_ctx_free(struct io_r
{
io_finish_async(ctx);
io_sqe_buffer_unregister(ctx);
- if (ctx->sqo_mm) {
- mmdrop(ctx->sqo_mm);
- ctx->sqo_mm = NULL;
+
+ if (ctx->sqo_task) {
+ put_task_struct(ctx->sqo_task);
+ ctx->sqo_task = NULL;
+ mmdrop(ctx->mm_account);
+ ctx->mm_account = NULL;
}
io_sqe_files_unregister(ctx);
@@ -8665,8 +8678,16 @@ static int io_uring_create(unsigned entr
ctx->user = user;
ctx->creds = get_current_cred();
+ ctx->sqo_task = get_task_struct(current);
+
+ /*
+ * This is just grabbed for accounting purposes. When a process exits,
+ * the mm is exited and dropped before the files, hence we need to hang
+ * on to this mm purely for the purposes of being able to unaccount
+ * memory (locked/pinned vm). It's not used for anything else.
+ */
mmgrab(current->mm);
- ctx->sqo_mm = current->mm;
+ ctx->mm_account = current->mm;
/*
* Account memory _before_ installing the file descriptor. Once
next prev parent reply other threads:[~2020-10-31 11:48 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-31 11:35 [PATCH 5.9 00/74] 5.9.3-rc1 review Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 01/74] cpufreq: Improve code around unlisted freq check Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 02/74] netfilter: nftables_offload: KASAN slab-out-of-bounds Read in nft_flow_rule_create Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 03/74] io_uring: allow timeout/poll/files killing to take task into account Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 04/74] io_uring: move dropping of files into separate helper Greg Kroah-Hartman
2020-10-31 11:35 ` Greg Kroah-Hartman [this message]
2020-10-31 11:35 ` [PATCH 5.9 06/74] io_uring: unconditionally grab req->task Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 07/74] io_uring: return cancelation status from poll/timeout/files handlers Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 08/74] io_uring: enable task/files specific overflow flushing Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 09/74] io_uring: dont rely on weak ->files references Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 10/74] io_uring: reference ->nsproxy for file table commands Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 11/74] io_wq: Make io_wqe::lock a raw_spinlock_t Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 12/74] io-wq: fix use-after-free in io_wq_worker_running Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 13/74] io_uring: no need to call xa_destroy() on empty xarray Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 14/74] io_uring: Fix use of XArray in __io_uring_files_cancel Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 15/74] io_uring: Fix XArray usage in io_uring_add_task_file Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 16/74] io_uring: Convert advanced XArray uses to the normal API Greg Kroah-Hartman
2020-10-31 11:35 ` [PATCH 5.9 17/74] scripts/setlocalversion: make git describe output more reliable Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 18/74] efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 19/74] fs/kernel_read_file: Remove FIRMWARE_EFI_EMBEDDED enum Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 20/74] arm64: Run ARCH_WORKAROUND_1 enabling code on all CPUs Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 21/74] arm64: Run ARCH_WORKAROUND_2 " Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 22/74] arm64: link with -z norelro regardless of CONFIG_RELOCATABLE Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 23/74] x86/PCI: Fix intel_mid_pci.c build error when ACPI is not enabled Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 24/74] x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}() Greg Kroah-Hartman
2020-11-02 21:34 ` Hans-Peter Jansen
2020-11-03 6:35 ` Greg Kroah-Hartman
2020-11-03 7:54 ` Hans-Peter Jansen
2020-10-31 11:36 ` [PATCH 5.9 25/74] x86/copy_mc: Introduce copy_mc_enhanced_fast_string() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 26/74] efivarfs: Replace invalid slashes with exclamation marks in dentries Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 27/74] bnxt_en: Check abort error state in bnxt_open_nic() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 28/74] bnxt_en: Fix regression in workqueue cleanup logic in bnxt_remove_one() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 29/74] bnxt_en: Invoke cancel_delayed_work_sync() for PFs also Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 30/74] bnxt_en: Re-write PCI BARs after PCI fatal error Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 31/74] bnxt_en: Send HWRM_FUNC_RESET fw command unconditionally Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 32/74] chelsio/chtls: fix deadlock issue Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 33/74] chelsio/chtls: fix memory leaks in CPL handlers Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 34/74] chelsio/chtls: fix tls record info to user Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 35/74] cxgb4: set up filter action after rewrites Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 36/74] gtp: fix an use-before-init in gtp_newlink() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 37/74] ibmveth: Fix use of ibmveth in a bridge Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 38/74] ibmvnic: fix ibmvnic_set_mac Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 39/74] mlxsw: core: Fix memory leak on module removal Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 40/74] mlxsw: Only advertise link modes supported by both driver and device Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 41/74] netem: fix zero division in tabledist Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 42/74] net: hns3: Clear the CMDQ registers before unmapping BAR region Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 43/74] net: ipa: command payloads already mapped Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 44/74] net/sched: act_mpls: Add softdep on mpls_gso.ko Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 45/74] r8169: fix issue with forced threading in combination with shared interrupts Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 46/74] ravb: Fix bit fields checking in ravb_hwtstamp_get() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 47/74] tcp: Prevent low rmem stalls with SO_RCVLOWAT Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 48/74] tipc: fix memory leak caused by tipc_buf_append() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 49/74] net/smc: fix invalid return code in smcd_new_buf_create() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 50/74] net/smc: fix suppressed return code Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 51/74] net: protect tcf_block_unbind with block lock Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 52/74] erofs: avoid duplicated permission check for "trusted." xattrs Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 53/74] arch/x86/amd/ibs: Fix re-arming IBS Fetch Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 54/74] x86/traps: Fix #DE Oops message regression Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 55/74] x86/xen: disable Firmware First mode for correctable memory errors Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 56/74] PCI: aardvark: Fix initialization with old Marvells Arm Trusted Firmware Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 57/74] ata: ahci: mvebu: Make SATA PHY optional for Armada 3720 Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 58/74] fuse: fix page dereference after free Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 59/74] bpf: Fix comment for helper bpf_current_task_under_cgroup() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 60/74] evm: Check size of security.evm before using it Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 61/74] p54: avoid accessing the data mapped to streaming DMA Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 62/74] cxl: Rework error message for incompatible slots Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 63/74] RDMA/addr: Fix race with netevent_callback()/rdma_addr_cancel() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 64/74] mtd: lpddr: Fix bad logic in print_drs_error Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 65/74] drm/i915/gem: Serialise debugfs i915_gem_objects with ctx->mutex Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 66/74] serial: qcom_geni_serial: To correct QUP Version detection logic Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 67/74] serial: pl011: Fix lockdep splat when handling magic-sysrq interrupt Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 68/74] PM: runtime: Fix timer_expires data type on 32-bit arches Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 69/74] ata: sata_rcar: Fix DMA boundary mask Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 70/74] mm: mark async iocb read as NOWAIT once some data has been copied Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 71/74] xen/gntdev.c: Mark pages as dirty Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 72/74] io_uring: dont reuse linked_timeout Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 73/74] misc: rtsx: do not setting OC_POWER_DOWN reg in rtsx_pci_init_ocp() Greg Kroah-Hartman
2020-10-31 11:36 ` [PATCH 5.9 74/74] phy: marvell: comphy: Convert internal SMCC firmware return codes to errno Greg Kroah-Hartman
2020-10-31 17:11 ` [PATCH 5.9 00/74] 5.9.3-rc1 review Jeffrin Jose T
2020-11-01 10:41 ` Greg Kroah-Hartman
2020-11-01 13:46 ` Jeffrin Jose T
2020-10-31 20:09 ` Guenter Roeck
2020-11-01 11:52 ` Greg Kroah-Hartman
2020-11-01 7:04 ` Naresh Kamboju
2020-11-01 11:53 ` Greg Kroah-Hartman
2020-11-02 9:53 ` Jon Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201031113500.297738073@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).