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 B1F001C0DE8 for ; Tue, 6 Aug 2024 10:54:27 +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=1722941669; cv=none; b=vC626I4LnW1S4AYFwfZRNRyBal//Qt1SAtnfs3GthuQOKDw6XmNxjg/A7f+QryhzJ9TYMWUurSGt8BFrNaRcTKZE1KZ4EdXcRiHrJtdL1Ppxq/PpF+poCgUEdWGCFI5Q4NSvVhmob9EF1bZJNUdNhg3gLgo79Qf0d0DhNXpcR8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722941669; c=relaxed/simple; bh=QI76W/6+qyfi/f/458udiZ+vMPBWVCY8s3vj6UfuSig=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tvRP8Lqa1nHZhhlYRjzKFoV9vUVodiPM5ValWdwq2hJ3HbfHLazDENo0eYlGRIeWcg5PBnDrK01TrBWUwlQAzx5dI1kjoIzUGGnqHLox40R9XOaCACnDMaLFG1pzCQwdCyJ9RI25VCqcBQKSM7lWQuK5pzkJErNHkPJBe59VpXg= 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=jIiJRDgN; 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="jIiJRDgN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722941666; 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=gegv+FUrL3Bk/gUnU9MjiVdI0lIqs6KIEoJQDH9Pkv4=; b=jIiJRDgNBpCOC0rzfJp8uXmLJ1dMJ9pipdSAE1fKiFO97NUCzTY6dt2pobCOjHvEe9PbLV XXibprHM3W5IJbRbvS04yR6qMUeNbmyEvy+lefAMF/iczVGlLdcYxbqznkAI/bu5KUwePC RpLFmGc8xVKUMcuMGgqZOMZHKBo3Azk= Received: from mx-prod-mc-03.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-503-WwuZVDk4MyCT6EGtkw8uxA-1; Tue, 06 Aug 2024 06:54:21 -0400 X-MC-Unique: WwuZVDk4MyCT6EGtkw8uxA-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3C1AE19560AA; Tue, 6 Aug 2024 10:54:19 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.155]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id EABC81955D44; Tue, 6 Aug 2024 10:54:14 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 6 Aug 2024 12:54:16 +0200 (CEST) Date: Tue, 6 Aug 2024 12:54:11 +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 Subject: Re: [PATCH 5/8] uprobes: travers uprobe's consumer list locklessly under SRCU protection Message-ID: <20240806105411.GB20881@redhat.com> References: <20240731214256.3588718-1-andrii@kernel.org> <20240731214256.3588718-6-andrii@kernel.org> <20240805155931.GC11049@redhat.com> 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=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 On 08/05, Andrii Nakryiko wrote: > > On Mon, Aug 5, 2024 at 8:59 AM Oleg Nesterov wrote: > > > > > int uprobe_apply(struct uprobe *uprobe, struct uprobe_consumer *uc, bool add) > > > { > > > struct uprobe_consumer *con; > > > - int ret = -ENOENT; > > > + int ret = -ENOENT, srcu_idx; > > > > > > down_write(&uprobe->register_rwsem); > > > - for (con = uprobe->consumers; con && con != uc ; con = con->next) > > > - ; > > > - if (con) > > > - ret = register_for_each_vma(uprobe, add ? uc : NULL); > > > + > > > + srcu_idx = srcu_read_lock(&uprobes_srcu); > > > + list_for_each_entry_srcu(con, &uprobe->consumers, cons_node, > > > + srcu_read_lock_held(&uprobes_srcu)) { > > > + if (con == uc) { > > > + ret = register_for_each_vma(uprobe, add ? uc : NULL); > > > + break; > > > + } > > > + } > > > > we can probably remove the similar check above? > > > > I mean, why do we need the list_for_each_entry_srcu() above? Is it possible > > that uprobe_apply(uprobe, uc) is called when "uc" is not on the ->consumers > > list? > > Tbh, I just don't completely understand how (and why) uprobe_apply() > is used from kernel/trace/trace_uprobe.c, so I wanted to preserve the > logic exactly. I still don't see when this consumer is added before > uprobe_apply()... Exposing uprobe_apply() seems like a huge API > violation to me and I'd rather get rid of its users. But one step at a > time. Agreed. Unlike uprobe_unregister(), uprobe_apply() doesn't WARN() or even explains this check, lets preserve the current logic for now. And just in case... I am not sure too that the con == NULL case is not possible with the current code. The recent discussions forced me to recall some bits in uprobe.c, but not in trace_uprobe.c ;) Oleg.