Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp178190lqt; Thu, 18 Apr 2024 11:37:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAEbzz/DxtkrEZO7b4ttLoNKpegsKTVUtKnXejTSlOqiq5De4jOfnPQa25zCEwEz2oFHOmPefFjwcc32GBHNqzFKHMwCZOuXRLSeX/Dg== X-Google-Smtp-Source: AGHT+IE8nvKpna6rSAUH713/SWmgk6CDRKF4Y+99rG8ddoMawUgFJpArFhiF9kOpeDW9366/xJFb X-Received: by 2002:a05:6a20:2589:b0:1a9:793c:59ec with SMTP id k9-20020a056a20258900b001a9793c59ecmr65319pzd.13.1713465437273; Thu, 18 Apr 2024 11:37:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713465437; cv=pass; d=google.com; s=arc-20160816; b=Vh7xF03d0a37DrEIbGE53tNT6SmPTCj2mLEaKIi8wMUwmimhP87QbtlohfLS9eRB4y RfP7Ix0vM2XyAtKcSi0X/zrha24iFVganYGGVbW2aOSKMbKYHJ94WojPurPiE2ykL6Na JmHAwB+uI59KPZaQmXmTH3r2tl6kle2i2TaGf8uMDVR7jPXjU+RA6jqjkXd4lJzkupJK El23FGJci6N/hGjnyRXwxL95qvCj02B3NUa+I4SmxPHQpjSHp1//MbsdvSSbvm+gbWvy rR8BHbAO6vsvbYVFxWk4Sb/7V4qm/jSqLcq9XqhT0M+fjJiKlC6PYrVhhLK155qsJiyC 6Dmg== 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=/h/Do95bbYq5Tt0KYD+0H8my015G5GgNdhr/yLxS+rI=; fh=+UUuM3zsjJwe2FgD2YHkbzr+xNFKN2BROUQ67dOgMM4=; b=OW985mlkAUJS01GFrC+8qp5REgSbTxwOsWzWrXfZ+DJ/6/siZpsY9jEWhXVErsN3H7 9Iul1DZj64xtN4D/L1L4717Dos4cM3gdjjHc+Aqjs2Npt+LattjIg6ro0cjA384xTeV+ ELPWm2lT+IXIBadB11tLQzSBFvQx4UmFvIy4YSwHfoS73jSSW6uZ3Xi8ujahSN1uBoEA /RjPKNhsednvL1RCM9JIOsWyJNwUOzQ7fCnsPtY1Vw0+V/BSk4m+49AtSjpyEEzJE7dc +ZfOZl4saJCaPcUXp7YFihxobsascsX+l53XaDmxAjHMV6SHK9Ftrp9q4S/4wXuM1chm IyNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BmR2ROPf; 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-150633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150633-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ll11-20020a056a00728b00b006e6f9ce6388si1864853pfb.195.2024.04.18.11.37.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BmR2ROPf; 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-150633-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150633-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4A9FDB239B2 for ; Thu, 18 Apr 2024 18:35:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5390D172BD0; Thu, 18 Apr 2024 18:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BmR2ROPf" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 2B04438DF2; Thu, 18 Apr 2024 18:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465301; cv=none; b=SJCrWNYVAl80bHY2xlghTNUPQW/vSNoLR1b+rYkQLB2jXH6t6mt3jBiXdEjhjjgdpuGJEiknjO+vmTnKc0MPiOd8UpifBI/hvqlbrSlRH2XlZk274UTaPJwnZOm5shfVCC7NXnqIrc5EnyWK0W3IYsY6tg9GTeVZ7O4X8/5eJfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465301; c=relaxed/simple; bh=cPt44jxSVrdhZJrIQnC8pnx/xoLCJM42pv8YS2Rc51w=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=cER/LfvI0JymXpRjoS3r6FeNbQb/nQV9O4kFVFJaIW18MCXp05+VDeY4aiXK7dfWKJbwV8fD/e/s7FV76kMQjt/VST6LcKVRrAhvkeTtfYNPkWUKu2LzXQqwoII06mBZqX+VVLPQl1p0MSAcqw1ytz30lSW4kZjkQU+PxL3FgnA= 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=BmR2ROPf; arc=none smtp.client-ip=209.85.210.171 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-pf1-f171.google.com with SMTP id d2e1a72fcca58-6ed2170d89fso1560140b3a.1; Thu, 18 Apr 2024 11:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713465299; x=1714070099; 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=/h/Do95bbYq5Tt0KYD+0H8my015G5GgNdhr/yLxS+rI=; b=BmR2ROPfUHjXmPwg/lsQajN9js9jtNXfTQ2nNjlKZbWekzB+MHpuVHUnG8QKFj01ap n5FPasCpfGLPnBMolNCSxx+l4j0MJRUULrLnkZ4lmHwLZYlJuygzaFrufrSwSs5T7k9G 9mR55GJCN68FIu/KaY5H14lfMWV2O3yIEbI9OawOgOpcdpgTaqFuNFZlaCqVpJzw1t6E CQpjITTujxV+itZxY51zZ3EXQYLuV8Vk3+QSYeFA7tNcOibEYyw3D7mzVaEZFlGwDIfG VbHnNpqGDVc0aMEAEf0Fj06w6lPiq3HWarAm498s1qHxOi0zRo398qZ2TTPCZGyDdd6e rz9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465299; x=1714070099; 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=/h/Do95bbYq5Tt0KYD+0H8my015G5GgNdhr/yLxS+rI=; b=EB1iN+crgrVmjGy/Sjv5BhYo3oFuBsep4+DDRDISX6lGBeYLtDIetjDwCtsMdZtDej Wbtmm2mXRnKhWbByKu7MCgYvDZAy7fwNR0Bk+3OuXjhfilfMCyUqAiYy6x3XLkaSjNqj FgAHOefCB5D4+62fvcHgWeE+jy+oeejt/qyAP3bAaXz+VP+4gOCr6IPs24oG234VK3sE scWgA9RnIOPg2fPE3Th57WEMuQtVj4urhspoQ6r6oHUl7uadYeP+qZsy+n0WEt6mLquP 3i3umhkDzDsmSow7UW2sgvrSFooT3r37EcsT8Es3Y/h925N/sKXNlA0jnmdWfNTzskgN NxDA== X-Forwarded-Encrypted: i=1; AJvYcCV8/J8YnNzUvaUfHw45Js1vTtgZR/Qgtnh/4QqKTiKJ/c1UTeMhKRX3p5rbG+qnRCDsraeLur6LgiJQHqh9T9cAWxarUTyvg6RvDtFHhpCHQCrLyHyppVWP3EfdUaZE04vEnyvAymQewjOOvugEDD6UxKSqqN+ORDjoA/oPHjkNVXlKEXTT X-Gm-Message-State: AOJu0YxfgJ7Dy8B9bWWf4sHofxnuf+DZxBMyVjUmcxOg+eqsUAQgZ1IF yEKAaIvAupKOieTRUnXy6XaIlsxmtyqL0OL7sttL5rIbCy6niLLdhC0RVAg/bO9x6TxJZawr77L yPWAEyf1b3LEmq7jMLSmTx4pVw4vgfQ== X-Received: by 2002:a05:6a21:2d8a:b0:1a7:53c1:ad8d with SMTP id ty10-20020a056a212d8a00b001a753c1ad8dmr44266pzb.24.1713465299216; Thu, 18 Apr 2024 11:34:59 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240402093302.2416467-1-jolsa@kernel.org> <20240402093302.2416467-2-jolsa@kernel.org> In-Reply-To: From: Andrii Nakryiko Date: Thu, 18 Apr 2024 11:34:46 -0700 Message-ID: Subject: Re: [PATCHv2 1/3] uprobe: Add uretprobe syscall to speed up return probe To: Jiri Olsa Cc: Steven Rostedt , Masami Hiramatsu , Oleg Nesterov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend , Peter Zijlstra , Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 15, 2024 at 1:25=E2=80=AFAM Jiri Olsa wrot= e: > > On Tue, Apr 02, 2024 at 11:33:00AM +0200, Jiri Olsa wrote: > > SNIP > > > #include > > #include > > @@ -308,6 +309,88 @@ static int uprobe_init_insn(struct arch_uprobe *au= probe, struct insn *insn, bool > > } > > > > #ifdef CONFIG_X86_64 > > + > > +asm ( > > + ".pushsection .rodata\n" > > + ".global uretprobe_syscall_entry\n" > > + "uretprobe_syscall_entry:\n" > > + "pushq %rax\n" > > + "pushq %rcx\n" > > + "pushq %r11\n" > > + "movq $" __stringify(__NR_uretprobe) ", %rax\n" > > + "syscall\n" > > + "popq %r11\n" > > + "popq %rcx\n" > > + > > + /* The uretprobe syscall replaces stored %rax value with final > > + * return address, so we don't restore %rax in here and just > > + * call ret. > > + */ > > + "retq\n" > > + ".global uretprobe_syscall_end\n" > > + "uretprobe_syscall_end:\n" > > + ".popsection\n" > > +); > > + > > +extern u8 uretprobe_syscall_entry[]; > > +extern u8 uretprobe_syscall_end[]; > > + > > +void *arch_uprobe_trampoline(unsigned long *psize) > > +{ > > + *psize =3D uretprobe_syscall_end - uretprobe_syscall_entry; > > + return uretprobe_syscall_entry; > > fyi I realized this screws 32-bit programs, we either need to add > compat trampoline, or keep the standard breakpoint for them: > > + struct pt_regs *regs =3D task_pt_regs(current); > + static uprobe_opcode_t insn =3D UPROBE_SWBP_INSN; > + > + if (user_64bit_mode(regs)) { > + *psize =3D uretprobe_syscall_end - uretprobe_syscall_entr= y; > + return uretprobe_syscall_entry; > + } > + > + *psize =3D UPROBE_SWBP_INSN_SIZE; > + return &insn; > > > not sure it's worth the effort to add the trampoline, I'll check > 32-bit arch isn't a high-performance target anyways, so I'd probably not bother and prioritize simplicity and long term maintenance. > > jirka