Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp552049lqr; Wed, 5 Jun 2024 13:47:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNzN6IICOaBoLWHXxzC0OxYj0gQBy+XNgspp9lt/D81wHcglVOWSuxyxGYRU4s2ki8aCXKHFh8VGfJ5iCAMXiodWmQ4f16HO/0Ffgkzw== X-Google-Smtp-Source: AGHT+IHhZju2+FErdHlMbWfM8fOg1NibY4uRpX7X3BY/XBCvxfJCSeaK3AEHSMImpPTKgCykR3f2 X-Received: by 2002:a17:906:c10:b0:a62:cf3b:77ad with SMTP id a640c23a62f3a-a69a000e31fmr274662366b.49.1717620445428; Wed, 05 Jun 2024 13:47:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717620445; cv=pass; d=google.com; s=arc-20160816; b=Vsw9zq0M0t+jxjMeUv5RHcmEdYQHrR4tTcux0HjdnRYK2Ta0amWCTqe3J5OLsNA5ZG vk3WCW4+wUN+SymfMDRurSknkT5N6BcMIgy9tfNWrGKkophCecv6ZUD2JUH/nY+rlyiP so6Fb+k2pai3kbn0Gaxgs9hTu2ONOaZXIM5/QXDNfziviUGRQTjoygFUVUki2uf3sksJ UUvkOQl2BJRf6yicg3wJ58zyyg5sdPWwOspv0DhStOcvOqdineuOUdWC8e24HLQ+N3U0 /M8qN/26b1rFZbuEhcJm1kXI9Zm8h+9yr4BxNFc7oaNwygd0KAeJh7QQQgyBWUyQ5CNY Y4fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=+Glm3mA8QnXBmJCA+vVErk08DMx6cbnQiMEf8o6LS5k=; fh=t/UW68iU6VYjA/48I0fFkg0O0D9nL6zFcToBiflYspI=; b=hYmiIxYkFMGspK10S218U9a2of/2rXKUAMgmMtDYDxaVTiPIMoOIbVQqYiGOkjJN43 bhyZ73/E2yNR1KWIPNTJybxWeXRG/9ZODAeiE1gZpOh1ydjiLTO9/VvObwtzYeIH4ddV 7M0wsdbICeu/NyMTawyQXIGCz9XhYv3RQTM2jBEQJ1TMzT9Iv/NneOA5X5EngDZegcAq HxB2wXzrx+A9ov9O7vPzQAeXh3u2yTk7Bj99ycFxwKEeOwQD+cHGLICkxPRKESz7Qpmn u3/i4JhK7I2GoZu/K7TScMfVyIX7lVWIgY9GAdf4OC3Y9ZfMJ56tKK/F21HUS3S8gVVL /Vjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BwAJAF2k; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-203194-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203194-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a68f9feffcfsi396892766b.117.2024.06.05.13.47.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203194-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BwAJAF2k; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-203194-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203194-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F011D1F2333D for ; Wed, 5 Jun 2024 20:47:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBDFE15F32E; Wed, 5 Jun 2024 20:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BwAJAF2k" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80D777462; Wed, 5 Jun 2024 20:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717620434; cv=none; b=bPYsW4n1mfUk6LV/1NRJsoq3p2FluqwzeKPX13eZLCxizR3s1QLvbyfcIOf9bI2N231k2M2qI9ooNhueAX+zztvKDErf9LxSNtLGzHaALFrBL41ogURC7TcIe8G2DlsOiiKa9iI1a3C7uTh5XWVt7/mk4k8yKQBVZAm9WPS0Ekw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717620434; c=relaxed/simple; bh=klYKjOnVknraFytFz7IL6PTVE75Fk90Z7bNkhzgsgS8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=GiQL/nYdbgsv07xNLa24HVETeFj8wQUkorcuiomkmNa0auw+yr+5gisXNmEFd5LbNfVEPvuuUFErB1NMD+sg7D0ut7CfzAT7hxdGNrN4quUEZhfy5d8hKZdYXZWu7GLFSPO5k7683kAwJrEL2w3s4SkK+Vcqiz1iELl+uFCJkO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BwAJAF2k; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2c2200dbdf7so225328a91.2; Wed, 05 Jun 2024 13:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717620433; x=1718225233; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+Glm3mA8QnXBmJCA+vVErk08DMx6cbnQiMEf8o6LS5k=; b=BwAJAF2kmBu86dX245iKgqOmOdGM9b9ThofwHlPf9ULxkCMYor18OnJCFj+yUAfpbI PfGNNAfPnv6+o2OlmYNdOiDCRKyXR+G2K23Oz1omqtTxs3qPWUQRV33TBBKKKVVyRwSH 9X3DEIYSiI22TCDun2uuNYdJqRvT9jx+cjjt0iQMTqNSPo9QN1e/pbyqsdAncM01T0DP 2M+RMGPgIWHyF4J3JheCBq9J65KHdRnlIFy9WHv+nskKyMWcN7VSVxOSHhH1Fe78tO9r DJIU5D5wZB+r7ED40QuQFztGJ1/rFwbx/Gb6zdtOzEkbiTPXr00SlwqXCnBGi//COzp7 rarw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717620433; x=1718225233; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Glm3mA8QnXBmJCA+vVErk08DMx6cbnQiMEf8o6LS5k=; b=gg9hSDPlBu8wNsgc2RttNANTYKN3omM9U+5m7mJkyY4vAATui6CWeC/lrLtaqxpJ6F zkfdwLZ4I1PuWE2dOWOxvF2z2IgJeVhpStFSp5njsgDu5wHvMdetctTgNmWcam61Ykdt pGm/9LXdzS+rnYRLAe5n0xTgFEP5VQs8qUZEhtzvuFaA25FlPmVWb7CxoY+0QjP/kBPB O/DP0hGucoARHMdisE213G9yYVDdTyPO+ciyE1yoPRux6GnBg18UBBHXIWQGM3Z4YR4s FwlWJd4f8FcFzr7h6x96XJ4ZafvE7oJxdMaEmbskSUS1Lv6HhRNpHTOxilUOKJKYuicb 1nRQ== X-Forwarded-Encrypted: i=1; AJvYcCXcrHxVILeTRl+MqCJte6pl+MR8z3C623D8AbFXSe2WK+xxf6eSFAK08PNfuXkD9AUjsAUPa6EdR7sDeeScnVqC/G/UVEgrbielrg69239UHNyzjkkD5NKFFPCIOC0TpuzUsuigfHgyTE6O1+llQq5C6GpE7g4hrhlIkm9Uu+NwqQXXpUXg X-Gm-Message-State: AOJu0YyNsdUbma2F0tW+13nkaVDWyTtryq872Wi3sJ7zZ2KsDzkwH8z/ RWd5OlVqbkOhDq+/tL7Z2zuwAAVqTcqnBvcXW87DD0asjPfySHmcgO1mzTF54mH0IZKtVFNHx0D fTFlr30U7S3sSBbbz2KyAyqbK+5s= X-Received: by 2002:a17:90a:8d0c:b0:2c2:7dd6:97b with SMTP id 98e67ed59e1d1-2c27dd6098cmr3312784a91.16.1717620432636; Wed, 05 Jun 2024 13:47:12 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240604200221.377848-1-jolsa@kernel.org> <20240604200221.377848-2-jolsa@kernel.org> <20240605175619.GH25006@redhat.com> In-Reply-To: <20240605175619.GH25006@redhat.com> From: Andrii Nakryiko Date: Wed, 5 Jun 2024 13:47:00 -0700 Message-ID: Subject: Re: [RFC bpf-next 01/10] uprobe: Add session callbacks to uprobe_consumer To: Oleg Nesterov Cc: Jiri Olsa , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 5, 2024 at 10:57=E2=80=AFAM Oleg Nesterov wro= te: > > On 06/05, Andrii Nakryiko wrote: > > > > so any such > > limitations will cause problems, issue reports, investigation, etc. > > Agreed... > > > As one possible solution, what if we do > > > > struct return_instance { > > ... > > u64 session_cookies[]; > > }; > > > > and allocate sizeof(struct return_instance) + 8 * > > and then at runtime pass > > &session_cookies[i] as data pointer to session-aware callbacks? > > I too thought about this, but I guess it is not that simple. > > Just for example. Suppose we have 2 session-consumers C1 and C2. > What if uprobe_unregister(C1) comes before the probed function > returns? > > We need something like map_cookie_to_consumer(). Fair enough. The easy way to solve this is to have struct uprobe_session_cookie { int consumer_id; u64 cookie; }; And add id to each new consumer when it is added to struct uprobe. Unfortunately, it's impossible to tell when a new consumer was added to the list (as a front item, but maybe we just change it to be appended instead of prepending) vs when the old consumer was removed, so in some cases we'd need to do a linear search. But the good news is that in the common case we wouldn't need to search and the next item in session_cookies[] array would be the one we need. WDYT? It's still fast, and it's simpler than the shadow stack idea, IMO. P.S. Regardless, maybe we should change the order in which we insert consumers to uprobe? Right now uprobe consumer added later will be executed first, which, while not wrong, is counter-intuitive. And also it breaks a nice natural order when we need to match it up with stuff like session_cookies[] as described above. > > > > + /* The handler_session callback return value controls executi= on of > > > + * the return uprobe and ret_handler_session callback. > > > + * 0 on success > > > + * 1 on failure, DO NOT install/execute the return uprobe > > > + * console warning for anything else > > > + */ > > > + int (*handler_session)(struct uprobe_consumer *self, struct p= t_regs *regs, > > > + unsigned long *data); > > > + int (*ret_handler_session)(struct uprobe_consumer *self, unsi= gned long func, > > > + struct pt_regs *regs, unsigned lon= g *data); > > > + > > > > We should try to avoid an alternative set of callbacks, IMO. Let's > > extend existing ones with `unsigned long *data`, > > Oh yes, agreed. > > And the comment about the return value looks confusing too. I mean, the > logic doesn't differ from the ret-code from ->handler(). > > "DO NOT install/execute the return uprobe" is not true if another > non-session-consumer returns 0. > > Oleg. >