From patchwork Fri Nov 10 00:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 163670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp787490vqs; Thu, 9 Nov 2023 16:04:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4/0B37uqkOhkzeRkjrFnrc+u8zETS32i6crakJeCqvXN5b09Sn9jWvt2w5gsnVhrpmj7L X-Received: by 2002:a6b:7f01:0:b0:792:70c2:9db1 with SMTP id l1-20020a6b7f01000000b0079270c29db1mr3114435ioq.1.1699574665810; Thu, 09 Nov 2023 16:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699574665; cv=none; d=google.com; s=arc-20160816; b=JxzPwtxG60IWHg8gr5QoJLxMFogn7vL5OAu3wI8bIRo/PBbfZU5zQyTQYULjsF0f9J PgPnKWVsDG1iUgFIJmpkhFAsZWfjOiQjzjw5E2fjXfzjlciSunsZiHVn7Hxlxb2XlZDC +lQsfdBrikF+q8Y4uy44iVjkOzGLSc/cLQSed1xBK2FUIU5hmQ/qdkdIy/9HodTtn+/A tzwY/FBcPFJn4lUepKC5q21hRxjp1K+JGJQDwCs2qHN0RIwTUFZ3yPdJSDhGc51W9O9e yqayCdXwhjT3IyDO5lqToBfR4kTIOJQ89tmtyjRXdgn+JcTx9CtW0usWZVPZZweScX6e oXTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=UMm2Aciykg8ub3kZoou0mh34QtErvedZkYd88iOeNUI=; fh=K//si1Hi/RYC7s39rVvmvh0YbZGmBrdWWHQg3cPF7Xc=; b=wUnG97DJb42Py/gc1oEFO8y4rYp1mOImFUdceRwrRmeQ03ryLtO8F+wYrF+tRPW884 d1rxFYz+BeFuKuKyF/GzxVfIwA7//SByzulNAtfolUgl3OMRGAXJktnWCf/2ZIGA3tj2 m4c2roCx1C9yoK6MM29u2XpbgwAwxPwb2ZJPy29OOtjTCrnhBg482VHy7KLWByj3CGaH XytE3M56w8GlFPG61AUpCbD69K3/9sw3p6lStnahF+hCbOIzQ/V4mWVNpQUbATZe0Ukl 24wwqxVDRk1VMIL9NbD9L+pUNBRTVT1T577WgjUo7xK5BfPUieT3dFfVOlInkkRW6nTR 63EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="GWgsEV/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h191-20020a636cc8000000b005b9053cf6f2si8128065pgc.163.2023.11.09.16.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="GWgsEV/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5D69183AB723; Thu, 9 Nov 2023 16:04:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345749AbjKJAET (ORCPT + 30 others); Thu, 9 Nov 2023 19:04:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345547AbjKJADc (ORCPT ); Thu, 9 Nov 2023 19:03:32 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0E8949D0; Thu, 9 Nov 2023 16:01:27 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5b980391d7cso1159996a12.0; Thu, 09 Nov 2023 16:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699574487; x=1700179287; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=UMm2Aciykg8ub3kZoou0mh34QtErvedZkYd88iOeNUI=; b=GWgsEV/027OQHPtC1vnznP7fK32F+EGGTsRj3b7eQ25n5xf0zhbd2FCaLmh59h4wZj iY+cAR1eUhO2IDDfmsbI+hm9pWQMz+X6084/mw6xxXE07/6miPiErLijn2AMMM9U1O35 I2LMH+++b9k6oZPNh33Wgubf77zYZQrtLilcW0J1v4OSvaPtoOmKl9C9ebXbjU14yWVh ArfJtJRmjEUIY4T3x9MOu0fsoc/46Ju+mUUC8FJ5xCSndq1hwXKuop8NoZtAK2vDRCxv JbYaXymqURuTHDuNGF8vUq/qOEnulN7bOnv4eaj2cuu7CDgYvIZOmJHOgjpeWWBpFImj SpuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699574487; x=1700179287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UMm2Aciykg8ub3kZoou0mh34QtErvedZkYd88iOeNUI=; b=TzdRZi2jXEgnU9AqmQ+hG36vBoN38jiMuGLEY4qGuIQOnG5I3qr5zZDtI6bGYDrk52 R7wgij0HnQLxsSYoUs8wnGhro7fMb+eQEfZMRViv6TT5eOI6/HKfIBkxI3F9XfJXTG5W tx4wlHCnTdMQ35WgFzamgEbY9UxwWbv4tpRzdmVXQxj6ADNHV3KzIhIF1lxM+hQdPDrB anjeZPu8ClEB/MgI8FZxs3DF6dRvpn/kXIO/s7jacEDckCR+8ClimK8mqDzUf+AKFUEH qJzG5/Koh5eML86kxkaKcbuRIadHik13Mx0gE/sWnC8GjLY3ZYYJaZddAee7QBZEdaq6 WltA== X-Gm-Message-State: AOJu0YwPtEqais6KbDNcIrBdPlQkl1qCnbkfe13nTTamkG6Lztna0LJe rfshPr12LKAbcNf5LQdYAqE= X-Received: by 2002:a17:90a:1a0c:b0:280:290f:4d38 with SMTP id 12-20020a17090a1a0c00b00280290f4d38mr2923365pjk.36.1699574487262; Thu, 09 Nov 2023 16:01:27 -0800 (PST) Received: from bangji.corp.google.com ([2620:15c:2c0:5:d45c:ae16:d959:a5f1]) by smtp.gmail.com with ESMTPSA id k32-20020a17090a4ca300b002635db431a0sm371312pjh.45.2023.11.09.16.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:01:26 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: Ian Rogers , Adrian Hunter , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , Andi Kleen , linux-trace-devel@vger.kernel.org, linux-toolchains@vger.kernel.org Subject: [PATCH 46/52] perf annotate-data: Handle call instructions Date: Thu, 9 Nov 2023 16:00:05 -0800 Message-ID: <20231110000012.3538610-47-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231110000012.3538610-1-namhyung@kernel.org> References: <20231110000012.3538610-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 09 Nov 2023 16:04:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782133204991159061 X-GMAIL-MSGID: 1782133204991159061 When updating instruction states, the call instruction should play a role since it can change the register states. For simplicity, mark some registers as scratch registers (should be arch-dependent), and invalidate them all after a function call. If the function returns something, the designated register (ret_reg) will have the type info. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 45 +++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index bbd271cd3419..54791dfc6244 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -22,10 +22,14 @@ #include "symbol.h" #include "symbol_conf.h" -/* Type information in a register, valid when ok is true */ +/* + * Type information in a register, valid when @ok is true. + * The @scratch registers are invalidated after a function call. + */ struct type_state_reg { Dwarf_Die type; bool ok; + bool scratch; }; /* Type information in a stack location, dynamically allocated */ @@ -49,6 +53,7 @@ struct type_state_stack { struct type_state { struct type_state_reg regs[TYPE_STATE_MAX_REGS]; struct list_head stack_vars; + int ret_reg; }; static bool has_reg_type(struct type_state *state, int reg) @@ -56,10 +61,23 @@ static bool has_reg_type(struct type_state *state, int reg) return (unsigned)reg < ARRAY_SIZE(state->regs); } -void init_type_state(struct type_state *state, struct arch *arch __maybe_unused) +void init_type_state(struct type_state *state, struct arch *arch) { memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); + + if (arch__is(arch, "x86")) { + state->regs[0].scratch = true; + state->regs[1].scratch = true; + state->regs[2].scratch = true; + state->regs[4].scratch = true; + state->regs[5].scratch = true; + state->regs[8].scratch = true; + state->regs[9].scratch = true; + state->regs[10].scratch = true; + state->regs[11].scratch = true; + state->ret_reg = 0; + } } void exit_type_state(struct type_state *state) @@ -416,6 +434,29 @@ void update_insn_state(struct type_state *state, struct data_loc_info *dloc, int fbreg = dloc->fbreg; int fboff = 0; + if (ins__is_call(&dl->ins)) { + Dwarf_Die func_die; + + /* __fentry__ will preserve all registers */ + if (dl->ops.target.sym && + !strcmp(dl->ops.target.sym->name, "__fentry__")) + return; + + /* Otherwise invalidate scratch registers after call */ + for (unsigned i = 0; i < ARRAY_SIZE(state->regs); i++) { + if (state->regs[i].scratch) + state->regs[i].ok = false; + } + + /* Update register with the return type (if any) */ + if (die_find_realfunc(cu_die, dl->ops.target.addr, &func_die) && + die_get_real_type(&func_die, &type_die)) { + state->regs[state->ret_reg].type = type_die; + state->regs[state->ret_reg].ok = true; + } + return; + } + /* FIXME: remove x86 specific code and handle more instructions like LEA */ if (!strstr(dl->ins.name, "mov")) return;