From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796167311; b=ldlKBb25+s4LXffQe5GmeHDVGd/iWnx9YYj/d2cmw1KVM2ousME0uhir8fFjWhrmTaQr 53dDUi7DkuWGj1geHx7mJv4P8JicdIJ1IgxZVyMpgXCGgXftHy3829lTdOey13a55On8V Uj/fVDVMecAomWSjPgdvVGLFN2x0Bge7QGUprvPhaUYt/EUky58qDrVLLCvnyra7H8WhW ORwK2uUVhJUQcU4zPPF/Boktp8ouNp9RiNrfgGhH7AFNTuN3DAzdKFv6ev00eXCHs/q+G 7eUOfLjiOxWN0ri1Li5D7urQ5ipQqFPwQkpqmYi60fwHLJZPPNJKnRGecIWnEmVa0bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167311; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=dh4FoS1eR5EgQnu+3OnyGBQnSqw3Y6HtOU25q9dSWFQ=; b=b4nVmmomPE+WkT1e4ZkJkOVyXTFciPoBTtIYoJ7DRmZ0ySO3aVqC1pKbzYlSMzA/DLo1 u4moXx/EKmDC4Jk6S3dLDr8dTgSjFLQzqjwaSVXPylAeqJvAekXLSXt+dSWmV55ugoE6E m0g204MGNRQcA9VFSoJQhDNbyUrx4/RMevyYnq+bp5pCHvcovb3JZ8G7tKDqac++7OyBP z4rSuxte0EgB9rr2xioBr0TcX7wf+i38kk5vFoc27fySIJUSrQPOn7iMBdxiKEF22yS6H Mv0eJS+84DmFc9n7eYu9kDKx5zvkzlBsSNdgzmIyAM8X4ujas/ewhEKqbl8gHBkLWyw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WyJ0Ws9K; arc=none smtp.remote-ip=209.85.160.71 Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1436260A5BE6 for ; Tue, 1 Dec 2026 23:21:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1436260A5BE6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WyJ0Ws9K Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-47cfa971c9eso14910176fac.0 for ; Tue, 01 Dec 2026 15:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796167310; x=1796772110; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dh4FoS1eR5EgQnu+3OnyGBQnSqw3Y6HtOU25q9dSWFQ=; b=WyJ0Ws9KPJmudm2S9GX7Zk462iUZrGZNCfO5yJBWxJjy4Jq1XjjLDDLPjlmST7mGyn T2n2JM7HHVKp77OhUr0595GCJf1dYQMI+BkjSj6D0A/ZCgBWTG+hOOcWoYvLlwSzjHcI O4UCvNWEASsT9hDVoMC1+2+phTnknbntlF/atV8UBt1VC8/KQSog/dkf+e0bk7KBR3ti nlkdPJPxcQGOSRBdN2jJW+IBf3mJwmECYRt5Fm2HJyPCw3wYAkx6oiLIdv+E3Qjmq4Ny mt1Ar6Zry9cf7K4ZJ0BYfehVBK86gheOgbA4VckpFfMBPVQcpvHmxZhAp1LKX5Y9cHdk XkCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796167310; x=1796772110; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dh4FoS1eR5EgQnu+3OnyGBQnSqw3Y6HtOU25q9dSWFQ=; b=11+MzPVwbBy16iYQuVeNFuGuV5jt2pVV1SVCerhrY61RyDaRITDV0nODApJ36yZqo/ 3uMvbrVYGudaWcpci0kz4kws6V2waXmx6mycRXjeCSYacJ1rvjtput9Kwt5y+pUgxI3L 4IPxDD/vxqkAYybfPgwGtFBh+b3DtaHgJabMMMrTEXUb3wja0Edoo8ZH2HwJV4U1+XZm zht0YaXHoKSTA3JD6hNp7XKT5JLvE/ZYXxncZImkz32N5kNL0JO78QBbTpTouoFYSVd0 BgOCMMQZolTBUho+nI/33hCyam3sAw9wi/ZH9CsxeTxYytQUQHccd2QQxRXvnOIZkvLd op2Q== X-Forwarded-Encrypted: i=1; AL+hErHSrT6Nxboawdis8TLKjNon3uS9dECewDFJlM7gyUodXbd8expBCpwEL7NBfrmldWsJpRrsvIu+W6A/qWv09UeI@vger.kernel.org X-Gm-Message-State: APuU4Z/YANt64OjoY0N69UWiGqbVhH+mpm+HzWNGKmgUtgFlFs6Nade6 WKnnqQZssW1NTfWYVUp7p5n4PLp5DsJEePPWlX9xqrKRVw3Bzg2nmdCFJL//AKEfDWT6EXLRdt/ eZVCHDIghdQ== X-Received: from oadxh27-n1.prod.google.com ([2002:a05:6871:ed1b:10b0:4dc:6ca2:5869]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:31ab:b0:4ad:60e2:474b with SMTP id 586e51a60fabf-4bc77f2d42amr26508417fac.0.1796167309694; Tue, 01 Dec 2026 15:21:49 -0800 (PST) Date: Tue, 1 Dec 2026 15:21:10 -0800 In-Reply-To: <20261201232116.1988791-1-irogers@google.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201232116.1988791-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261201232116.1988791-11-irogers@google.com> Subject: [RFC PATCH 10/16] perf symbol: Support host IP resolution and guest fallback symbolization From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: Marc Zyngier , Alexei Starovoitov , linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Store resolved host mapping state (host_map, host_sym, host_addr, raw_host_ip) in struct addr_location and resolve sample->host_ip against machines->host in machine__resolve(). When a guest sample cannot be symbolized in the guest machine, automatically fall back to the resolved host mapping and symbol (and clear HIST_FILTER__GUEST when perf_host or perf_guest is active), so guest code backed by host DAX or file-backed mappings symbolizes transparently without guest symbol state. Signed-off-by: Ian Rogers --- tools/perf/util/addr_location.c | 7 ++++ tools/perf/util/addr_location.h | 4 +++ tools/perf/util/event.c | 58 +++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_location.c index 57e8217a00f9..ca0380260ee6 100644 --- a/tools/perf/util/addr_location.c +++ b/tools/perf/util/addr_location.c @@ -9,8 +9,12 @@ void addr_location__init(struct addr_location *al) al->thread = NULL; al->map = NULL; al->sym = NULL; + al->host_map = NULL; + al->host_sym = NULL; al->srcline = NULL; al->addr = 0; + al->host_addr = 0; + al->raw_host_ip = 0; al->level = 0; al->filtered = 0; al->cpumode = 0; @@ -28,6 +32,7 @@ void addr_location__init(struct addr_location *al) void addr_location__exit(struct addr_location *al) { map__zput(al->map); + map__zput(al->host_map); thread__zput(al->thread); } @@ -35,7 +40,9 @@ void addr_location__copy(struct addr_location *dst, struct addr_location *src) { thread__put(dst->thread); map__put(dst->map); + map__put(dst->host_map); *dst = *src; dst->thread = thread__get(src->thread); dst->map = map__get(src->map); + dst->host_map = map__get(src->host_map); } diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_location.h index fdc4d3f3a68b..d4148d7df998 100644 --- a/tools/perf/util/addr_location.h +++ b/tools/perf/util/addr_location.h @@ -13,8 +13,12 @@ struct addr_location { struct thread *thread; struct map *map; struct symbol *sym; + struct map *host_map; + struct symbol *host_sym; const char *srcline; u64 addr; + u64 host_addr; + u64 raw_host_ip; char level; u8 cpumode; u16 filtered; diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index ea75816d126a..96d88d88ba06 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -808,6 +808,11 @@ int machine__resolve(struct machine *machine, struct addr_location *al, struct thread *thread; struct dso *dso; + map__zput(al->host_map); + al->host_sym = NULL; + al->host_addr = 0; + al->raw_host_ip = sample->host_ip; + if (symbol_conf.guest_code && !machine__is_host(machine)) thread = machine__findnew_guest_code(machine, sample->pid); else @@ -862,6 +867,57 @@ int machine__resolve(struct machine *machine, struct addr_location *al, */ al->latency = sample->period * 1000 / al->parallelism; + if (al->map) + al->sym = map__find_symbol(al->map, al->addr); + + if (sample->host_ip) { + struct machine *host_machine = machine__is_host(machine) ? + machine : (machine->machines ? &machine->machines->host : NULL); + + if (host_machine) { + struct thread *host_thread = machine__findnew_thread(host_machine, + sample->pid, + sample->tid); + struct maps *host_maps = NULL; + bool load_host_map = false; + + if (machine__kernel_ip(host_machine, sample->host_ip)) { + host_maps = machine__kernel_maps(host_machine); + load_host_map = !symbol_conf.lazy_load_kernel_maps; + } else if (host_thread) { + host_maps = thread__maps(host_thread); + } + + if (host_maps) { + al->host_map = maps__find(host_maps, sample->host_ip); + if (al->host_map) { + if (load_host_map) + map__load(al->host_map); + al->host_addr = map__map_ip(al->host_map, + sample->host_ip); + al->host_sym = map__find_symbol(al->host_map, + al->host_addr); + } + } + thread__put(host_thread); + } + + if ((sample->cpumode == PERF_RECORD_MISC_GUEST_USER || + sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && + !al->sym && al->host_map && (al->host_sym || !al->map)) { + map__zput(al->map); + al->map = map__get(al->host_map); + al->addr = al->host_addr; + al->sym = al->host_sym; + dso = map__dso(al->map); + if (perf_host || perf_guest) { + al->filtered &= ~(1 << HIST_FILTER__GUEST); + al->level = (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ? + 'g' : 'u'; + } + } + } + if (al->map) { if (symbol_conf.dso_list && (!dso || !(strlist__has_entry(symbol_conf.dso_list, @@ -871,8 +927,6 @@ int machine__resolve(struct machine *machine, struct addr_location *al, dso__long_name(dso)))))) { al->filtered |= (1 << HIST_FILTER__DSO); } - - al->sym = map__find_symbol(al->map, al->addr); } else if (symbol_conf.dso_list) { al->filtered |= (1 << HIST_FILTER__DSO); } -- 2.56.1.915.g69d5ec7298-goog