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 210B62BE7B6 for ; Mon, 20 Jul 2026 15:23:04 +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=1784560986; cv=none; b=PiVzBxpNyNOuci50KUfpq1zNsPqXGZcdC/tz5h1zkTYsVGP4S1BZaLdglFqwFjaiMGmIROmtsyORJJ4/q4f0YLkzov2qjolKhiYTl61MlEcAlp+n9QBMDqNiiTe0LROyrt/HAe76LzyW6aNoaZ82akp9P9uy4t1ig6LJ9IRydaQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784560986; c=relaxed/simple; bh=Mkc4mr/tcF3rMYZ6RBMabIjNlTXCOsi1yQkThjn3CV4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=QL2ClCjixEeYn/MmxTeoXFtSMS73/0siz7nHsy705O1TiibdpIKSSxxnzYpyQ2L4EoVsoQ5RqbX2mYkPRswBFzrc1nA5wDV7TsTDw9IZHgHENiMGX05xPNJ3dGYVHiJJNuN9ORjsplAIIEJ290jhGeC/EZ1VK7RF7/OQxmyb43A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=TRCMGDv4; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=LSXj8yff; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="TRCMGDv4"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="LSXj8yff" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784560984; 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:autocrypt:autocrypt; bh=qRG0EQoIBPvYKanAjjzqNY2Gr16T4oqswbVpTvZJXsA=; b=TRCMGDv4WUMR3r38HQl90FOoeElsxnGylGKMeOa8OT+awjhxgUUKIr4pDJ/V98sE5LlgUi fVjgRq5pSbkg1VjrXBImqq4u9Z9IC5kSCBwVTWTqUuuLxalXquRTkWVOEtfgjxDMMYBXfG ou9JQ355kBZWHbKyHs9X2Rlp+xnuhFk= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-OVQv6btaM5SpSjIsWAyohw-1; Mon, 20 Jul 2026 11:23:02 -0400 X-MC-Unique: OVQv6btaM5SpSjIsWAyohw-1 X-Mimecast-MFC-AGG-ID: OVQv6btaM5SpSjIsWAyohw_1784560981 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c11f2b9f62fso536267466b.2 for ; Mon, 20 Jul 2026 08:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784560981; x=1785165781; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=qRG0EQoIBPvYKanAjjzqNY2Gr16T4oqswbVpTvZJXsA=; b=LSXj8yffvv8IacTJ6sA5nXyLxj7PQKeanP4tSEayt+kZjVMPV4wuFOQ2SIV/BT4cfV ZrOZApbmHUq0zi66wULDi7NJWN3LF/OT7k1SeLL8eiKX69VfZRsVxEzcOZLgdAFEca/j iLPVlL2tSbuPElR64sYsApJmCpiLeikxnbh2hL2NfzqyhgPfNcYnWF/o2ekR+ALopxlX rrTpYMeQ/fwoJkgbvvnVEhcKnzfqwcLSL+mbvxO/UU5d/pPxZBC/lS6Tkp6S6zVnJDXu 4JKjT0enr/sIJYOgLXUzUMwIbHVo7e+jQ/fqdJWpulmpV1Agz/i8+7H/2IcQF0ZRiKzi 38JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784560981; x=1785165781; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=qRG0EQoIBPvYKanAjjzqNY2Gr16T4oqswbVpTvZJXsA=; b=BTXwSRo2l5Sa+UrpsJ7P8nqGH8zAnEBXLEBxUIpsuruXZZjYtOkiRyUoMrmNj2klNx lAF/QJyXJq4afTzjEmEj0CYmZeDkgEegNuKWy509etTiK5y1TO28mvSd1gyV/0Kafo6X r3WeQW07TKKwdEg8sibhilZpZiz1xuEW4Dg1km2EvOfKYrJzj9QG8Sp9+alRLys9TyLA RkS7dv6QL1pyOf87IlKbPKtnKUBJmD/JGhh382wGkuIef0pSDbRBxVChhTlMN6l859c9 dw4gKs93XaeAUxruQZzkT8vWKd3pdLOK2TZ2+Rpefakb5e3BvbaHyDaOd5NEMz0KkE0X ZE0Q== X-Forwarded-Encrypted: i=1; AHgh+RoeYNqddnj5Ujr+LK7Nkbg8WtXnYijfsY+RdFEp9uMogx/ZxZVTDq613OCTbIc1eHGc7RpA3jo5U+l1NkA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq1AAWPvO8X4J7TNtuCM6hqvCAgTFmy0kM9gpVZM+ghGZNlsdL L+2J4L6ljn0r/jAe5ZuJOrrrzKh+zdV9s+5S4X8puq7RuA99cecf4vWt4upl1PZFnPo0k+kA6DI p/I1zhwDGqNc5mAJX87g0UnyoBOt+FnkKhalwstHywBmvR1GXUZSnu1MpB/r7oMsVgg== X-Gm-Gg: AfdE7cl1mLq7isU/Xfp7sVt8u61GmntMvZg4V4OdubAezcjABGEg0xn6Yib1mev1R2N I/cZ+xj7359qqdylMf0UI2BuJHrCC+0rj/fyjR033YObFMbC0uPyxZjcER9SK+0lItzHF/sBW8z rzDrK7PhoJ6apy432hSFbZjkSgy5SScCH6l9xJRH1wIJiF7j6DuYrExROHZthSGp7nq1a66VWar S7ABZeRIfO8fGc3/dk/bKhT3Hr/9YxPYX2KqjZIqewL6DvaC4fvL3CuQNS5QDZC32UHJr2Jn9KP oCx6H/hbXYgxy1dmVmZQqWNRxhRRTu/WJv1o6l23PJybIFRsqnasVmqfmq5ze5I7qi4GxF0a/rd QYTJtv/K/i83O93Kbe7DXCR0XX48TMtnbKKYAcYznn1rNLsqaNKjA30F4mLzlmbLBDwDvxw== X-Received: by 2002:a17:907:961c:b0:c16:5855:6594 with SMTP id a640c23a62f3a-c16b485db23mr721732566b.55.1784560981397; Mon, 20 Jul 2026 08:23:01 -0700 (PDT) X-Received: by 2002:a17:907:961c:b0:c16:5855:6594 with SMTP id a640c23a62f3a-c16b485db23mr721730466b.55.1784560981001; Mon, 20 Jul 2026 08:23:01 -0700 (PDT) Received: from gmonaco-thinkpadt14gen3.rmtit.csb (212-8-243-115.hosted-by-worldstream.net. [212.8.243.115]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1734c0d439sm484787466b.51.2026.07.20.08.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 08:23:00 -0700 (PDT) Message-ID: <55912ee1fc569e5c81e25a32d516db54d1986336.camel@redhat.com> Subject: Re: [PATCH v4 2/8] rv: add generic uprobe infrastructure for RV monitors From: Gabriele Monaco To: wen.yang@linux.dev Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 20 Jul 2026 17:22:59 +0200 In-Reply-To: <31d0438f98e80503370a6fb3932d0ec7df0673c3.1783524627.git.wen.yang@linux.dev> References: <31d0438f98e80503370a6fb3932d0ec7df0673c3.1783524627.git.wen.yang@linux.dev> Autocrypt: addr=gmonaco@redhat.com; prefer-encrypt=mutual; keydata=mDMEZuK5YxYJKwYBBAHaRw8BAQdAmJ3dM9Sz6/Hodu33Qrf8QH2bNeNbOikqYtxWFLVm0 1a0JEdhYnJpZWxlIE1vbmFjbyA8Z21vbmFjb0BrZXJuZWwub3JnPoiZBBMWCgBBFiEEysoR+AuB3R Zwp6j270psSVh4TfIFAmjKX2MCGwMFCQWjmoAFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgk Q70psSVh4TfIQuAD+JulczTN6l7oJjyroySU55Fbjdvo52xiYYlMjPG7dCTsBAMFI7dSL5zg98I+8 cXY1J7kyNsY6/dcipqBM4RMaxXsOtCRHYWJyaWVsZSBNb25hY28gPGdtb25hY29AcmVkaGF0LmNvb T6InAQTFgoARAIbAwUJBaOagAULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgBYhBMrKEfgLgd0WcK eo9u9KbElYeE3yBQJoymCyAhkBAAoJEO9KbElYeE3yjX4BAJ/ETNnlHn8OjZPT77xGmal9kbT1bC1 7DfrYVISWV2Y1AP9HdAMhWNAvtCtN2S1beYjNybuK6IzWYcFfeOV+OBWRDQ== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2026-07-08 at 23:38 +0800, wen.yang@linux.dev wrote: > From: Wen Yang > > +++ b/kernel/trace/rv/Kconfig > @@ -59,6 +59,13 @@ config RV_PER_TASK_MONITORS > =C2=A0 =C2=A0 This option configures the maximum number of per-task RV mo= nitors > that can run > =C2=A0 =C2=A0 simultaneously. > =C2=A0 > +config RV_UPROBE > + bool > + depends on RV && UPROBES > + help > + =C2=A0 Generic uprobe infrastructure for RV monitors.=C2=A0 Provides pa= th > + =C2=A0 resolution, registration, and safe synchronous teardown. This isn't exposed, it's selected automatically when required, I don't even think the help text is visible (menuconfig doesn't show it), do we really need it? > + > =C2=A0source "kernel/trace/rv/monitors/wip/Kconfig" > =C2=A0source "kernel/trace/rv/monitors/wwnr/Kconfig" > =C2=A0 ... > +++ b/kernel/trace/rv/rv_uprobe.c > @@ -0,0 +1,104 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Generic uprobe infrastructure for RV monitors. > + * > + * struct rv_uprobe embeds struct uprobe_consumer directly.=C2=A0 This i= s safe > + * because rv_uprobe_sync() calls uprobe_unregister_sync(), which calls > + * synchronize_rcu_tasks_trace().=C2=A0 handler_chain() runs under > + * rcu_read_lock_trace(), so after synchronize_rcu_tasks_trace() returns= , > + * all in-flight handler_chain() iterations, including any pending > + * uc->cons_node.next reads, have completed on all CPUs.=C2=A0 The calle= r may > + * then free the struct containing rv_uprobe immediately. > + */ > +#include > +#include > +#include > +#include > +#include > + > +/** > + * rv_uprobe_register - initialise and register an uprobe > + */ > +int rv_uprobe_register(const char *binpath, loff_t offset, struct rv_upr= obe > *p) > +{ > + struct inode *inode; > + struct path path; > + int ret; > + > + if (!p->uc.handler && !p->uc.ret_handler) > + return -EINVAL; uprobe_register() does this already, do we need it here too? > + > + ret =3D kern_path(binpath, LOOKUP_FOLLOW, &path); > + if (ret) > + return ret; > + > + if (!d_is_reg(path.dentry)) { > + path_put(&path); > + return -EINVAL; > + } > + > + inode =3D d_real_inode(path.dentry); > + p->inode =3D inode; > + > + /* > + * uprobe_register() requires the inode (and mount) to remain > + * referenced across the call.=C2=A0 Keep the path alive until after > + * uprobe_register() has stored its own reference, then release it. > + */ > + p->uprobe =3D uprobe_register(inode, offset, 0, &p->uc); > + path_put(&path); I believe I was mistaken here, as sashiko pointed out, uprobe_register() doesn't keep a reference to the inode, (explicitly stated in it's docs: "Caller of uprobe_register() is required to keep @inode (and the containing mount) referenced."). We should probably revert back to holding path instead of inode and putting it after synchronous cleanup. That's also what BPF does. Thanks, Gabriele > + if (IS_ERR(p->uprobe)) { > + ret =3D PTR_ERR(p->uprobe); > + p->uprobe =3D NULL; > + p->inode =3D NULL; > + return ret; > + } > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(rv_uprobe_register); > + > +/** > + * rv_uprobe_is_registered - test whether an uprobe is currently active > + */ > +bool rv_uprobe_is_registered(const struct rv_uprobe *p) > +{ > + return p && p->uprobe; > +} > +EXPORT_SYMBOL_GPL(rv_uprobe_is_registered); > + > +/** > + * rv_uprobe_unregister - synchronously unregister a uprobe > + */ > +void rv_uprobe_unregister(struct rv_uprobe *p) > +{ > + if (!p || !p->uprobe) > + return; > + > + rv_uprobe_unregister_nosync(p); > + rv_uprobe_sync(); > +} > +EXPORT_SYMBOL_GPL(rv_uprobe_unregister); > + > +/** > + * rv_uprobe_unregister_nosync - dequeue an uprobe without waiting > + */ > +void rv_uprobe_unregister_nosync(struct rv_uprobe *p) > +{ > + if (!p || !p->uprobe) > + return; > + > + uprobe_unregister_nosync(p->uprobe, &p->uc); > + p->uprobe =3D NULL; > + p->inode =3D NULL; > +} > +EXPORT_SYMBOL_GPL(rv_uprobe_unregister_nosync); > + > +/** > + * rv_uprobe_sync - wait for all in-flight uprobe handlers to complete > + */ > +void rv_uprobe_sync(void) > +{ > + uprobe_unregister_sync(); > +} > +EXPORT_SYMBOL_GPL(rv_uprobe_sync);