From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21463C3DA4A for ; Mon, 19 Aug 2024 13:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 904296B0088; Mon, 19 Aug 2024 09:41:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B4526B0089; Mon, 19 Aug 2024 09:41:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77BB26B008A; Mon, 19 Aug 2024 09:41:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 555B26B0088 for ; Mon, 19 Aug 2024 09:41:31 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D2E3B1A1328 for ; Mon, 19 Aug 2024 13:41:30 +0000 (UTC) X-FDA: 82469107140.11.65F9E17 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id E389C140008 for ; Mon, 19 Aug 2024 13:41:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bL5sPvdn; spf=pass (imf23.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724074811; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PnscDpV0loAdA10GHqqV4Sk/NPtRpYZGLZNubtluAas=; b=Ri3yvBydtufb3aqP1jXItiSqxBe9lERXfLwrX2HYjQQYr+exPgRqPahhQvRst2S0c5qroG 6jMu3GoKDkZVoYqb/9sGdzAhT6A2X+AfpZxkRxpNJ+W8oJgJ5usls+6t9BeIE2X4IfBiFx /yT1yzo33Vu3Gs3kwng6mL1vi7rhm70= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724074811; a=rsa-sha256; cv=none; b=JRB6ZW0YqWnoPIetGYAvL79H9B+Srs3C4Kg0YtTqVCAUzrODYq0OcZ1uA+EYcxdRj2wopQ 1SZAKl0XsmkntFO1HexhS4Lj3DNq6mx/YyuUvTAGhPvV+9kZba/h4JNg2SJexfaj4oZN1R BeKseYAUBGTgmnKQuSP9hlkU6qa33iQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bL5sPvdn; spf=pass (imf23.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724074888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PnscDpV0loAdA10GHqqV4Sk/NPtRpYZGLZNubtluAas=; b=bL5sPvdnH3fTdBCoywvCU4aBCm2nCJIXqOo+KnLYiebWIYM3jjOXeTomVKgiTxXk1fpfCq Po24dJ0r+ArZNLB7INpQ1i1XkAZox195LlQiIXB9YofefMTS8/+5FlD4f25n+56iSOjMjs rslkLaifLWvpdyivQLbc0d493V4vTVw= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-251-om71W1M8Mt-rOYGSwdksHw-1; Mon, 19 Aug 2024 09:41:22 -0400 X-MC-Unique: om71W1M8Mt-rOYGSwdksHw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33EDE18EB228; Mon, 19 Aug 2024 13:41:19 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.68]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5CC2219560A3; Mon, 19 Aug 2024 13:41:14 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 19 Aug 2024 15:41:14 +0200 (CEST) Date: Mon, 19 Aug 2024 15:41:08 +0200 From: Oleg Nesterov To: Andrii Nakryiko Cc: linux-trace-kernel@vger.kernel.org, peterz@infradead.org, rostedt@goodmis.org, mhiramat@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, jolsa@kernel.org, paulmck@kernel.org, willy@infradead.org, surenb@google.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: Re: [PATCH RFC v3 09/13] uprobes: SRCU-protect uretprobe lifetime (with timeout) Message-ID: <20240819134107.GB3515@redhat.com> References: <20240813042917.506057-1-andrii@kernel.org> <20240813042917.506057-10-andrii@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240813042917.506057-10-andrii@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E389C140008 X-Stat-Signature: 8iek9q6wq5nwytjuczgjjynoixxefsgf X-HE-Tag: 1724074888-975933 X-HE-Meta: U2FsdGVkX185z5otTL6MJIAQmMCn73VS24duyUr6nTb4o7/yOx7OeaOUjFY3INEdBaWbxIjjbyuse3IONqXWYYD8xvLo/qCStPJblHZvTN4FI80D0OWSUpw9qbn7QIiWW1tDxRDDnWcRZfzyjWT/1QhdQGft38y8N9wqCu6xyPCpwVIA2Dn4xvRTPTIEF4+q1UmMga38dTta2uW8uq5mAFpiNUWmOSJsvvbrs5LPq5phN0bfhp8m4j3bE1hitIqPNNXv3jmrOTsXjWBcLH1QMaTQkrbyKu5hV6eOWhGwoNMdt9zP2eUJGDwgzKCnFbP3Kp09A0mN8K03OwPsu8VtI3opLKPA14pj9sxXM9GCmzqpm9NpJW3TuFWthXYA2/OwuyTwTPDlDj3c8lxrQwvnCe1QU3wUs+0IcAzr1Sppbp0AZj+jZdRbnQczNgPG0xf3MfD1USYhKDpTaYaTgsBy56ahyCRlnuDvwGEfyxHLipK4ZpSNQi9C1e9U2tyCpfa54QBDayIVkjshzPpW8Rt+amMzMZ3y3OuKw/LMVeQHxwe76uwY8f0hUEansSk3NaDsi71D9IytI+8/F4gN+S4nzn35hqPlJJBkwp4m7cjmBdVtjsX+1iMAtdK7agKlAKLo/Aid++k1HHkha8+exW7gjnAATBkupG6L2SJM4CbfPkFbCYlzqnqjxBpXR+4U+prjHH/rAlRlXIXMdtJWxbKCKXcpplj9scQxm/BgQ9ldjyQuA8/st6fukYqHZKdC/eu+65brFZTubDD1zMSKlEMYaH8hu4lNIq4g9EmjWKJuN3aOsgkvhZGU4wdV9fM5P7iHa/OKgXTAoq7jc1HMoMzCAhyUP/0FWcVQWmgjIl19Ds4sKDYtq/wOLYdXGvtp9UpR79bORfoBFBJElawgGa/UJgi2A/lWfJfrf75/Cc0OfBjKxFEMtV4a3J3LpnxzSqvrmkkxAOL6ItHko5f5Vhb DWfgrEOU fHcLa9f2+iPi8wcKGy+Hth/nKbvCr3lZWqJExJroR5Ecqr0DLweKR0yw56AO/jsZJ1wrIjFJwnuw1/WoSrUjeNZrTJKQSXMDAB+k74GpR+4V/u5TmyJcY1OyA1ehSDgA+dBcwwOTnXOQdIxmhcQX2L7QkMDv4+nvPG4Evj5z0fnuBpdsKsGs+PcfqQwVMUyxJCvzViZyxaS1QsRFNibTLRs/NOJFlA1AnGxanEM3vawiJ2iAIRuTCupRuLqH7sJta0LAhyrpi8Nn+7aBFMZN7ULyvCf3Aa6QS7XjwLI93FtCwBq54B8IHPdSDhg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 08/12, Andrii Nakryiko wrote: > > Avoid taking refcount on uprobe in prepare_uretprobe(), instead take > uretprobe-specific SRCU lock and keep it active as kernel transfers > control back to user space. ... > include/linux/uprobes.h | 49 ++++++- > kernel/events/uprobes.c | 294 ++++++++++++++++++++++++++++++++++------ > 2 files changed, 301 insertions(+), 42 deletions(-) Oh. To be honest I don't like this patch. I would like to know what other reviewers think, but to me it adds too many complications that I can't even fully understand... And how much does it help performance-wise? I'll try to take another look, and I'll try to think about other approaches, not that I have something better in mind... But lets forgets this patch for the moment. The next one adds even more complications, and I think it doesn't make sense. As I have already mentioned in the previous discussions, we can simply kill utask->active_uprobe. And utask->auprobe. So can't we start with the patch below? On top of your 08/13. It doesn't kill utask->auprobe yet, this needs a bit more trivial changes. What do you think? Oleg. ------------------------------------------------------------------------------- >From d7cb674eb6f7bb891408b2b6a5fb872a6c2f0f6c Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Mon, 19 Aug 2024 15:34:55 +0200 Subject: [RFC PATCH] uprobe: kill uprobe_task->active_uprobe Untested, not for inclusion yet, and I need to split it into 2 changes. It does 2 simple things: 1. active_uprobe != NULL is possible if and only if utask->state != 0, so it turns the active_uprobe checks into the utask->state checks. 2. handle_singlestep() doesn't really need ->active_uprobe, it only needs uprobe->arch which is "const" after prepare_uprobe(). So this patch adds the new "arch_uprobe uarch" member into utask and changes pre_ssout() to do memcpy(&utask->uarch, &uprobe->arch). --- include/linux/uprobes.h | 2 +- kernel/events/uprobes.c | 37 +++++++++++-------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 3a3154b74fe0..df6f3dab032c 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -56,6 +56,7 @@ struct uprobe_task { union { struct { + struct arch_uprobe uarch; struct arch_uprobe_task autask; unsigned long vaddr; }; @@ -66,7 +67,6 @@ struct uprobe_task { }; }; - struct uprobe *active_uprobe; unsigned long xol_vaddr; struct arch_uprobe *auprobe; diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index acc73c1bc54c..9689b557a5cf 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1721,7 +1721,7 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs) { struct uprobe_task *utask = current->utask; - if (unlikely(utask && utask->active_uprobe)) + if (unlikely(utask && utask->state)) return utask->vaddr; return instruction_pointer(regs); @@ -1747,9 +1747,6 @@ void uprobe_free_utask(struct task_struct *t) if (!utask) return; - if (utask->active_uprobe) - put_uprobe(utask->active_uprobe); - ri = utask->return_instances; while (ri) ri = free_ret_instance(ri); @@ -1965,14 +1962,9 @@ pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, unsigned long bp_vaddr) if (!utask) return -ENOMEM; - if (!try_get_uprobe(uprobe)) - return -EINVAL; - xol_vaddr = xol_get_insn_slot(uprobe); - if (!xol_vaddr) { - err = -ENOMEM; - goto err_out; - } + if (!xol_vaddr) + return -ENOMEM; utask->xol_vaddr = xol_vaddr; utask->vaddr = bp_vaddr; @@ -1980,15 +1972,12 @@ pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, unsigned long bp_vaddr) err = arch_uprobe_pre_xol(&uprobe->arch, regs); if (unlikely(err)) { xol_free_insn_slot(current); - goto err_out; + return err; } - utask->active_uprobe = uprobe; + memcpy(&utask->uarch, &uprobe->arch, sizeof(utask->uarch)); utask->state = UTASK_SSTEP; return 0; -err_out: - put_uprobe(uprobe); - return err; } /* @@ -2005,7 +1994,7 @@ bool uprobe_deny_signal(void) struct task_struct *t = current; struct uprobe_task *utask = t->utask; - if (likely(!utask || !utask->active_uprobe)) + if (likely(!utask || !utask->state)) return false; WARN_ON_ONCE(utask->state != UTASK_SSTEP); @@ -2313,19 +2302,15 @@ static void handle_swbp(struct pt_regs *regs) */ static void handle_singlestep(struct uprobe_task *utask, struct pt_regs *regs) { - struct uprobe *uprobe; int err = 0; - uprobe = utask->active_uprobe; if (utask->state == UTASK_SSTEP_ACK) - err = arch_uprobe_post_xol(&uprobe->arch, regs); + err = arch_uprobe_post_xol(&utask->uarch, regs); else if (utask->state == UTASK_SSTEP_TRAPPED) - arch_uprobe_abort_xol(&uprobe->arch, regs); + arch_uprobe_abort_xol(&utask->uarch, regs); else WARN_ON_ONCE(1); - put_uprobe(uprobe); - utask->active_uprobe = NULL; utask->state = UTASK_RUNNING; xol_free_insn_slot(current); @@ -2342,7 +2327,7 @@ static void handle_singlestep(struct uprobe_task *utask, struct pt_regs *regs) /* * On breakpoint hit, breakpoint notifier sets the TIF_UPROBE flag and * allows the thread to return from interrupt. After that handle_swbp() - * sets utask->active_uprobe. + * sets utask->state != 0. * * On singlestep exception, singlestep notifier sets the TIF_UPROBE flag * and allows the thread to return from interrupt. @@ -2357,7 +2342,7 @@ void uprobe_notify_resume(struct pt_regs *regs) clear_thread_flag(TIF_UPROBE); utask = current->utask; - if (utask && utask->active_uprobe) + if (utask && utask->state) handle_singlestep(utask, regs); else handle_swbp(regs); @@ -2388,7 +2373,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs) { struct uprobe_task *utask = current->utask; - if (!current->mm || !utask || !utask->active_uprobe) + if (!current->mm || !utask || !utask->state) /* task is currently not uprobed */ return 0; -- 2.25.1.362.g51ebf55