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 8782AC531DC for ; Tue, 20 Aug 2024 15:06:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3A606B007B; Tue, 20 Aug 2024 11:06:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEA3D6B0082; Tue, 20 Aug 2024 11:06:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B0F66B0083; Tue, 20 Aug 2024 11:06:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7C9056B007B for ; Tue, 20 Aug 2024 11:06:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 92E3716027B for ; Tue, 20 Aug 2024 15:06:04 +0000 (UTC) X-FDA: 82472949048.27.B25E061 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 9959F180030 for ; Tue, 20 Aug 2024 15:06:00 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KSdDrMP8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724166302; a=rsa-sha256; cv=none; b=yfTSyOkB/hLYMo5zDHYVA4ehzKdpGhFTf2leOLicxKyHw4l0+9VlQie4HuRd0XiCs2WBqH Mz4QY4fREl8NnZWkUYgNKv4jz5oT3efq/QsuGoKXKHVhQ8+xvZJYwMliWmgwVOmi896bFP a7+X/ozIUHLPTezAhpA4iTy8KIkwp6A= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KSdDrMP8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724166302; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QKJEG4GEz/CaDYhNF4/J/0WOtN5X3sVlUXkziObLcNo=; b=FH+5r6zhh+BAhz/EgCKxVzSyQ8TS6/XOQ7pfjdjCvgEa0edR53b7tAnMEdtVfXRTqAz9X5 iodR3/tHCarSxaQpwt7TcOHjMGMoLQWrnc4FWmNirLOdF/cGiWBo6zs938CoZf2Z+7k12a e56F+BRFxGoTbNBTlmgsa5rV7s2MZD4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724166359; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QKJEG4GEz/CaDYhNF4/J/0WOtN5X3sVlUXkziObLcNo=; b=KSdDrMP8eBSIWkGOxR1pYOzLE1xi2pXiUFoLOCT/JT1AtdvLU39eWTfZlYAoRvHm1GgJKU J7gYKtTre+VupDxs0jN99V7uXq13ZiwoFVwzBqI0DAGXGz33fJWKH5XBiiwSVjb/5k+JLz kJSIGM3XOU6USe/tLwdgs5kXUNLWj+w= Received: from mx-prod-mc-05.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-63-tuU3hisOMxSoYEVqU5q5Rg-1; Tue, 20 Aug 2024 11:05:55 -0400 X-MC-Unique: tuU3hisOMxSoYEVqU5q5Rg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E9801955BE4; Tue, 20 Aug 2024 15:05:52 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.99]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A883619560AD; Tue, 20 Aug 2024 15:05:41 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 20 Aug 2024 17:05:46 +0200 (CEST) Date: Tue, 20 Aug 2024 17:05:34 +0200 From: Oleg Nesterov To: Andrii Nakryiko Cc: Andrii Nakryiko , 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: <20240820150534.GD12400@redhat.com> References: <20240813042917.506057-1-andrii@kernel.org> <20240813042917.506057-10-andrii@kernel.org> <20240819134107.GB3515@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspamd-Queue-Id: 9959F180030 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uix5rug1wik456sphgd5b5wgdews846b X-HE-Tag: 1724166360-161515 X-HE-Meta: U2FsdGVkX18ErTktnN7iKHSg/UFI/+yFu+/Ow4JIhngtnOACQ0waB5THjcH9ZwsLJz4swRDUyDWiO5eSU/p2Dph/M9DrpcN1kpW/yUnrQXomGRL14lCcgrGw9OhyZtVSpN5SRojFH80v97R8Lv5TK42OjykoScuri4TBvpFgTUCf9ByJsI7bOpjiHIed4eKwrGOIvF+52YNJpu3EO/3QMHdfkt5e5mj1lI7C1xyLkmyRUX5TahmUnC/3qHs2SKCw8tjAbLcmcMaZSRPSoCulBZqJrOEeeX7Kd9fEMkGAzcoF0GhugDKfPszQ/wbiWHCd9lBEhdFRY7jZgUxeW1/hAI37egmu6ghfn5e924MtDM6jyXndyv4tBFSDpIkUPkpghPq1DnY6NZCJEhEL3sygeX7MqSq7Pvy71XCN5EL6+j8PYJV/830PYXomxtZhebAUHCZ7wPBBmW45GqeNZ2Wvohj+gpIfiZfJo9rhx0FMefvwxyQ/AmuWC6Z2Uie+EPjohPV34vBv0oSvwOMDcbIPkGzp60Vx9XiOVH/jvP/70LPxbJ6R9HFkwxVZ30NaQXzt7YX7bbe0kIcQmK4bVtbcQgHJkKdlKfKyNKXO3dK9HI5PTwlPov2qemVMpfDQs7dr5Uv/8Eeo4jURKAOFw7g8hVlM64dcHeG8k8cUTyZkzU4ZS65Fbke+zYPP7ei3IETgvPTcPMcfXpdZK3vLHM7bHAKdw8JDohU7B7eX8cYD4sDe8u/bJwU1ZouoP0zM9WitS9w4M7gu7fc8TXAI6kcLdAqU9AiyozDggzbSTZyh6WAzGacSvmpQFW+rz7UKaBbv8cptPErRqf0LJMnT4OgJnSDkOgSmAQj/06fhRQmHmjwT+G+hJ+NTWdbvSpeLcIRkvaVR6at2hs0ku8Ugqs2q/umcYVDvs6k0O6TZ1Bftf5sJut8foGAjo4nA4NP8X7HBLBGexQLO85zOu6F+qpR THx7untD pSdU70FKGK8dtIQ7WQES67SvcP1jK+C9g37GZEFx5qHqBmZ0tfMt+hxkB70HxpJncxVP+0mmdZ8i8bbpyhSqImOxYFgmWBjdGIuq9ZhSbyHYhxwih8af9uO/siBrDemr8fW/01hV7qLBotGBir7xl2/ZR8Q/3kgXQe4TPqPJR85sDKr5SlEhJgf+Ywlr/3Jg37wS9ywvRWD3dyNVtuhFgrbkae6QNZUg6lWYmr2DN/ORmpY/d+apOvCA/z4C6YzXeMYELltCsYzEauhswdZXaoZDzGB9kR0HTeEUUrnBb848CL/io5pRcPkGTuk86+sBcY31boHstbR/v0cnnokgrtzgTxt4nBERDmxQmr3nLVEb0w1ysziWSRg+FLlWWOta+t2lvUhlGjgFM8ai+WaG4Aj1eCA== 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/19, Andrii Nakryiko wrote: > > On Mon, Aug 19, 2024 at 6:41 AM Oleg Nesterov wrote: > > > > 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... > > Which parts? The atomic xchg() and cmpxchg() parts? What exactly do > you feel like you don't fully understand? Heh, everything looks too complex for me ;) Say, hprobe_expire(). It is also called by ri_timer() in softirq context, right? And it does /* We lost the race, undo our refcount bump. It can drop to zero. */ put_uprobe(uprobe); How so? If the refcount goes to zero, put_uprobe() does mutex_lock(), but it must not sleep in softirq context. Or, prepare_uretprobe() which does rcu_assign_pointer(utask->return_instances, ri); if (!timer_pending(&utask->ri_timer)) mod_timer(&utask->ri_timer, ...); Suppose that the timer was pending and it was fired right before rcu_assign_pointer(). What guarantees that prepare_uretprobe() will see timer_pending() == false? rcu_assign_pointer()->smp_store_release() is a one-way barrier. This timer_pending() check may appear to happen before rcu_assign_pointer() completes. In this (yes, theoretical) case ri_timer() can miss the new return_instance, while prepare_uretprobe() can miss the necessary mod_timer(). I think this needs another mb() in between. And I can't convince myself hprobe_expire() is correct... OK, I don't fully understand the logic, but why data_race(READ_ONCE(hprobe->leased)) ? READ_ONCE() should be enough in this case? > > As I have already mentioned in the previous discussions, we can simply kill > > utask->active_uprobe. And utask->auprobe. > > I don't have anything against that, in principle, but let's benchmark > and test that thoroughly. I'm a bit uneasy about the possibility that > some arch-specific code will do container_of() on this arch_uprobe in > order to get to uprobe, Well, struct uprobe is not "exported", the arch-specific code can't do this. Oleg.