Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp85206lqj; Thu, 11 Apr 2024 10:27:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAAnVCMYHW4gQTD82T9MmEqc3XlkQfYS/gk7G/xU36JBx1jdPnuVqg+CefyZSyvEFdMsiZxzB/AnTePZQyDvKYdTu4tpX9XI0k6Jpc0Q== X-Google-Smtp-Source: AGHT+IF9rypIJR1WDCB2dAev0TOg1me0bi+rq055V6UZIeuoYdUvxZi2ToVlgfvyKzdt+Ahmnb/o X-Received: by 2002:a05:6808:47:b0:3c6:efa2:6655 with SMTP id v7-20020a056808004700b003c6efa26655mr253337oic.37.1712856454025; Thu, 11 Apr 2024 10:27:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712856454; cv=pass; d=google.com; s=arc-20160816; b=uhs+wHdbUxkbINvEnO+gA+v2JH0m0Fn9fT2+Jk7J62K27h/EgB3531cl836QkgIT7E UDcxPf0xbzEBCFtJPyUKF8HUe63Zr0zJ5RrTXOO2e4s4A/B0dfPb/Vt/v2ppPxLf63gA NIQiYkug3Bs68eHIWUMQuHMUq73DqbcFb1koIoH3593SQbZTTkgSiuYdUM4F0P53xBOR tM4+IcfupsKP6osQ1THm6rgoZzTyWwfZj+k7xu6iBSk58f0k8X5Fv2JPSApT1qIFDsRj NjBu/IXdYxDh/bW3DaWnAGlyqvC650IScrEauOZvY42Ls1lNsEnjirld7WJW7VmWfNXL MSaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter; bh=PV+e+azs9UB18fleivcFVR2+EgH1ys27iJCSFmbhMV4=; fh=mZAD7VuFLA0q8Xv2r4aDXLEA9N9ASI7l//I0uowB468=; b=oLnIxjKXHFggCvOgKOdbb8gbHzYk+ZtRq02dR6X7eBfavKXho+KQjBhTxf9je2TWXO kxQWbuv4t1NbIYWC/MSacnGdY9qClv8e9dV9dQF+S2QwQm6cy1PAHO6FiMQB97JJGu4s VAf+mV+QVsNXnums7ozfbpFtH9isOWmSxHM+jvETc5rxyteBQpAtElAX4q0SylJSdX8A dFEE8TY75Wc1MLgHR0Pv3TG5n6VilA7ePqhlanmWwUc+31lV+owdes9xd8q25OvEjU9C 9xfNwGHt6YCoo+B85UMIIkNoqz2Gl6vBkMFh19M9IgVwVGPjODiaiSvr4k7GcV+oEI2v beSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=DQYh+KCS; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-141247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t40-20020a05622a182800b00434feb79d31si1934218qtc.720.2024.04.11.10.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:27:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=DQYh+KCS; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-141247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 562721C209AA for ; Thu, 11 Apr 2024 17:27:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CA9479DD5; Thu, 11 Apr 2024 15:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="DQYh+KCS" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 404BF79B8E; Thu, 11 Apr 2024 15:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851150; cv=none; b=aFVyLzOu67pqCFFqm//MCIPBlBsDM9ms224SmMfU/n26eXQGeQtVQ8r45+5RoMY8CranyffVmnjjRUyTOwevk3C0PPQtaRagwH6R5e7xCwkRYKf/bedfkhstyPYYQg1sUdZluZVUnHSebUYKgOlGtoqxeufkwkXcWLiHlZodP1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712851150; c=relaxed/simple; bh=1cxH4Uf9JTRKo/wgayt4O34eDNtZBOzBmCb5Kc5mcNs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XBUaeA0fzNc1t+F1pwJOanbSyCAsMpXXo/nnqJwqRg++TvOTOVDs6PRY/TCPwdjFUES6v2qWOWyxVtNixmqiyQXFnKjOelCb8aL5mj5GuEm/0rV1QytS7dlgcrkfwMJjNOWzmRl7DtCa5EiG5ZB653TzGjrXCJ5yLyHunZo5ltQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=DQYh+KCS; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from DESKTOP-4OLSCEK. (c-76-135-27-212.hsd1.wa.comcast.net [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 4233720EB6E9; Thu, 11 Apr 2024 08:59:03 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4233720EB6E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1712851143; bh=PV+e+azs9UB18fleivcFVR2+EgH1ys27iJCSFmbhMV4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DQYh+KCScm5LH79cKmU6VK0GpxFKMMOCVkEz0xOU31E0GX3CUgqYhED9dRIO7LnTw ZO+DchNbeF+qd6Eor07hhGx17Fm7Sz3cMpXDbiDSxg+orssHXez80nMZLl+leMWGzY /fAQWr/7GjCeH+dV/O92Xj5kNTPgZOAcElXGUX7Y= Date: Thu, 11 Apr 2024 08:58:58 -0700 From: Beau Belgrave To: Masami Hiramatsu Cc: Namhyung Kim , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Copying TLS/user register data per perf-sample? Message-ID: <20240411155858.GA452-beaub@linux.microsoft.com> References: <20240404192641.GA2628-beaub@linux.microsoft.com> <20240410220628.609188857f8c93e33e48d12a@kernel.org> <20240410153542.GA460-beaub@linux.microsoft.com> <20240412005519.e7b664950ac776993da348bd@kernel.org> Precedence: bulk X-Mailing-List: linux-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: <20240412005519.e7b664950ac776993da348bd@kernel.org> On Fri, Apr 12, 2024 at 12:55:19AM +0900, Masami Hiramatsu wrote: > On Wed, 10 Apr 2024 08:35:42 -0700 > Beau Belgrave wrote: > > > On Wed, Apr 10, 2024 at 10:06:28PM +0900, Masami Hiramatsu wrote: > > > On Thu, 4 Apr 2024 12:26:41 -0700 > > > Beau Belgrave wrote: > > > > > > > Hello, > > > > > > > > I'm looking into the possibility of capturing user data that is pointed > > > > to by a user register (IE: fs/gs for TLS on x86/64) for each sample via > > > > perf_events. > > > > > > > > I was hoping to find a way to do this similar to PERF_SAMPLE_STACK_USER. > > > > I think it could even use roughly the same ABI in the perf ring buffer. > > > > Or it may be possible by some kprobe linked to the perf sample function. > > > > > > > > This would allow a profiler to collect TLS (or other values) on x64. In > > > > the Open Telemetry profiling SIG [1], we are trying to find a fast way > > > > to grab a tracing association quickly on a per-thread basis. The team > > > > at Elastic has a bespoke way to do this [2], however, I'd like to see a > > > > more general way to achieve this. The folks I've been talking with seem > > > > open to the idea of just having a TLS value for this we could capture > > > > upon each sample. We could then just state, Open Telemetry SDKs should > > > > have a TLS value for span correlation. However, we need a way to sample > > > > the TLS value(s) when a sampling event is generated. > > > > > > > > Is this already possible via some other means? It'd be great to be able > > > > to do this directly at the perf_event sample via the ABI or a probe. > > > > > > > > > > Have you tried to use uprobes? It should be able to access user-space > > > registers including fs/gs. > > > > > > > We need to get fs/gs during a sample interrupt from perf. If the sample > > interrupt lands during kernel code (IE: syscall) we would also like to > > get these TLS values when in process context. > > OK, those are not directly accessible from pt_regs. > Yeah, it's a per-arch thread attribute. > > > > I have some patches into the kernel to make this possible via > > perf_events that works well, however, I don't want to reinvent the wheel > > if there is some way to get these via perf samples already. > > I would like to see it. I think it is possible to introduce a helper > to get a base address of user TLS for probe events, and start supporting > from x86. > For sure, I'm hoping the patches start the right conversations. > > > > In OTel, we are trying to attribute samples to transactions that are > > occurring. So the TLS fetch has to be aligned exactly with the sample. > > You can do this via eBPF when it's available, however, we have > > environments where eBPF is not available. > > > > It's sounding like to do this properly without eBPF a new feature would > > be required. If so, I do have some patches I can share in a bit as an > > RFC. > > It is better to be shared in RFC stage, so that we can discuss it from > the direction level. > Agree, it could be that having the ability to run a probe on sample may be a better option. Not sure. Thanks, -Beau > Thank you, > > > > > Thanks, > > -Beau > > > > > Thank you, > > > > > > -- > > > Masami Hiramatsu (Google) > > > -- > Masami Hiramatsu (Google)