From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E45561C7B7B for ; Sun, 15 Sep 2024 14:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726411778; cv=none; b=obF7Hy8A0gR5XcIqVoG4XnIiGERoEzORB362+u+CNEaBOPa+TEmbAzP4QE0LkmfgsT775k/tCI4EZ4asuWmCs7arha/rvFdDY7zu7yyA5IJbij7NI/YzTJU9kG9tVQQmIPlj4bI+ylKcIwlZzz2cVHsqspFrymtG4bVmhUydsF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726411778; c=relaxed/simple; bh=sqVpq7WvWnmSd2FBUoOCS2aq1ILQha8H1RSMfI7mCK8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W63aDo6yz0AgkDv4JwPVD6LjSc4YayRSCdD6y+vm2McjukyrPOGHKTUwxVfMPmz7ggzBP8lhUY4HQEh2PGhs4G8th2azQqj/7gSARHSdpXNVo/whLzeQpFTHdQqpFv6kmndbmyNiNq4+NOeYlq+i01IGCwRsJaVk8qITNyTDVq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AgCJqw8u; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AgCJqw8u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726411775; 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=7vz7BVMbbODLF+2QjXXjcIGmDzTcyLOpiRfgDFCrlgg=; b=AgCJqw8uiuPdDGtHIf2WcKNz6F2hTW0L9/1jkwb3qMwfWYQELHJEXk9HZvB3COicDYx66f lysuVmv1jbYGxMa/oaMhvSTSOPbPjObeVY9qQIv33IUrRCyDRB8JHEVf3mQBlfG5RHmLQU S44k4zxJnJOMrPKRMtk4F5+vMja03Ew= 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-541-CEkhrFAGNzaLAUXrw77nRg-1; Sun, 15 Sep 2024 10:49:30 -0400 X-MC-Unique: CEkhrFAGNzaLAUXrw77nRg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 26E0D1956096; Sun, 15 Sep 2024 14:49:28 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.40]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id AA34530001AB; Sun, 15 Sep 2024 14:49:24 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 15 Sep 2024 16:49:15 +0200 (CEST) Date: Sun, 15 Sep 2024 16:49:11 +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 Subject: Re: [PATCH 1/3] uprobes: allow put_uprobe() from non-sleepable softirq context Message-ID: <20240915144910.GA27726@redhat.com> References: <20240909224903.3498207-1-andrii@kernel.org> <20240909224903.3498207-2-andrii@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240909224903.3498207-2-andrii@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 09/09, Andrii Nakryiko wrote: > > Currently put_uprobe() might trigger mutex_lock()/mutex_unlock(), which > makes it unsuitable to be called from more restricted context like softirq. > > Let's make put_uprobe() agnostic to the context in which it is called, > and use work queue to defer the mutex-protected clean up steps. ... > +static void uprobe_free_deferred(struct work_struct *work) > +{ > + struct uprobe *uprobe = container_of(work, struct uprobe, work); > + > + /* > + * If application munmap(exec_vma) before uprobe_unregister() > + * gets called, we don't get a chance to remove uprobe from > + * delayed_uprobe_list from remove_breakpoint(). Do it here. > + */ > + mutex_lock(&delayed_uprobe_lock); > + delayed_uprobe_remove(uprobe, NULL); > + mutex_unlock(&delayed_uprobe_lock); > + > + kfree(uprobe); > +} > + > static void uprobe_free_rcu(struct rcu_head *rcu) > { > struct uprobe *uprobe = container_of(rcu, struct uprobe, rcu); > > - kfree(uprobe); > + INIT_WORK(&uprobe->work, uprobe_free_deferred); > + schedule_work(&uprobe->work); > } This is still wrong afaics... If put_uprobe() can be called from softirq (after the next patch), then put_uprobe() and all other users of uprobes_treelock should use write_lock_bh/read_lock_bh to avoid the deadlock. To be honest... I simply can't force myself to even try to read 2/3 ;) I'll try to do this later, but I am sure I will never like it, sorry. Oleg.