[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241107082502.4060233-1-wnliu@google.com>
Date: Thu, 7 Nov 2024 08:25:02 +0000
From: Weinan Liu <wnliu@...gle.com>
To: jpoimboe@...nel.org
Cc: acme@...nel.org, adrian.hunter@...el.com,
alexander.shishkin@...ux.intel.com, andrii.nakryiko@...il.com,
broonie@...nel.org, fweimer@...hat.com, indu.bhagat@...cle.com,
irogers@...gle.com, jolsa@...nel.org, jordalgo@...a.com, jremus@...ux.ibm.com,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
linux-toolchains@...r.kernel.org, linux-trace-kernel@...r.kerne.org,
luto@...nel.org, mark.rutland@....com, mathieu.desnoyers@...icios.com,
mingo@...nel.org, namhyung@...nel.org, peterz@...radead.org,
rostedt@...dmis.org, sam@...too.org, x86@...nel.org
Subject: Re: [PATCH v3 09/19] unwind: Introduce sframe user space unwinding
> diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c
...
> +static int find_fre(struct sframe_section *sec, struct sframe_fde *fde,
> + unsigned long ip, struct unwind_user_frame *frame)
> +{
> + unsigned char fde_type = SFRAME_FUNC_FDE_TYPE(fde->info);
> + unsigned char fre_type = SFRAME_FUNC_FRE_TYPE(fde->info);
> + unsigned char offset_count, offset_size;
> + s32 cfa_off, ra_off, fp_off, ip_off;
> + void __user *f, *last_f = NULL;
> + unsigned char addr_size;
> + u32 last_fre_ip_off = 0;
> + u8 fre_info = 0;
> + int i;
> +
> + addr_size = fre_type_to_size(fre_type);
> + if (!addr_size)
> + return -EINVAL;
> +
> + ip_off = ip - (sec->sframe_addr + fde->start_addr);
nit: Since we already know wether the ip_off should mask or not, I think we don't have to check fde_type and mask the ip_off everytime.
ip_off = (fde_type == SFRAME_FDE_TYPE_PCINC) ? ip_off : ip_off % fde->rep_size;
> +
> + f = (void __user *)sec->fres_addr + fde->fres_off;
> +
> + for (i = 0; i < fde->fres_num; i++) {
> + u32 fre_ip_off;
> +
> + SFRAME_GET_USER(fre_ip_off, f, addr_size);
> +
> + if (fre_ip_off < last_fre_ip_off)
> + return -EINVAL;
> +
> + last_fre_ip_off = fre_ip_off;
> +
> + if (fde_type == SFRAME_FDE_TYPE_PCINC) {
> + if (ip_off < fre_ip_off)
> + break;
> + } else {
> + /* SFRAME_FDE_TYPE_PCMASK */
> + if (ip_off % fde->rep_size < fre_ip_off)
> + break;
> + }
> +
> + SFRAME_GET_USER(fre_info, f, 1);
> +
> + offset_count = SFRAME_FRE_OFFSET_COUNT(fre_info);
> + offset_size = offset_size_enum_to_size(SFRAME_FRE_OFFSET_SIZE(fre_info));
> +
> + if (!offset_count || !offset_size)
> + return -EINVAL;
> +
> + last_f = f;
> + f += offset_count * offset_size;
> + }
> +
> + if (!last_f)
> + return -EINVAL;
> +
> + f = last_f;
> +
> + SFRAME_GET_USER(cfa_off, f, offset_size);
> + offset_count--;
> +
> + ra_off = sec->ra_off;
> + if (!ra_off) {
> + if (!offset_count--)
> + return -EINVAL;
> +
> + SFRAME_GET_USER(ra_off, f, offset_size);
> + }
> +
> + fp_off = sec->fp_off;
> + if (!fp_off && offset_count) {
> + offset_count--;
> + SFRAME_GET_USER(fp_off, f, offset_size);
> + }
> +
> + if (offset_count)
> + return -EINVAL;
> +
> + frame->cfa_off = cfa_off;
> + frame->ra_off = ra_off;
> + frame->fp_off = fp_off;
> + frame->use_fp = SFRAME_FRE_CFA_BASE_REG_ID(fre_info) == SFRAME_BASE_REG_FP;
> +
> + return 0;
> +}
Powered by blists - more mailing lists