From nobody Fri Dec 19 17:43:32 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 1145E1DC98B for ; Mon, 27 Jan 2025 21:33:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738013621; cv=none; b=LrWb0RerbcRVRxrxxgl0zPVWQGG2gGOYfCdtPGJggEiCTNSeTqfp5XidAuLG2RgY/usWauRDe2He+Ej8KueZIF+ASBh9Lk48F1LT/S2z63Y6xJpW2tcMP+J16VZPslk9BugSNATnLoGVqxTxfckOghQuvucFJpv9kSPZL9sMvm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738013621; c=relaxed/simple; bh=tLQk9i7rfIosZMUbrAAbSOIaa7HREbh9qj/W4g2I5R0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VVN0khwWNiA/qpunCU6qw7f1jBK7AnaOcsFyMadyB2DVMf9K1kXg+Z59ynYKPop81wx1pJmXM4tZrQVhOkucy0YuQ3Lkp4DHv508KY7GxgnE6GCIR6pQj8SkalT4kf9Gf/xv3kUK8GaGBxM9PBk+fwFAEL9+yU6GtrAZqZJQ65s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wnliu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UJjR64Tw; arc=none smtp.client-ip=209.85.214.202 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--wnliu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UJjR64Tw" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21655569152so96002525ad.2 for ; Mon, 27 Jan 2025 13:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013619; x=1738618419; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FcMmLMqjQF9870LrAMy1ogNf6Ad9PcDDaPxJ25OGjiY=; b=UJjR64Twt0a/emLT+XNSdujeU7vYZURAjRUPGpFeJDkby7i07DSNHLR8rnGPWOfd0M aGxnYZJ0QUhpjwC8P5DrCb3/FKHI+4BR4/JHAYiRIDNXCaZ1xPgTIUFmpb1GdXckUkJB l0Hb03BR89lyeV5mNco8xVD4cqBlIhtHuhqhBAP2/gUIh/GqrhZtfPXrlDW13yzNyj80 dJu1pWM1HSUvjWB7SV/WzXI7lMzigKUuZFhHYnSInmb9U+VpSfMzcWTFoCvYgLi9qZJk bdBtfXowLHxLVP/ehik04W5ZBRtcjrGm8mwerEY3tOQszgbFVqNWJ5l+Lx8/iE31XtnO VFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013619; x=1738618419; h=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; bh=FcMmLMqjQF9870LrAMy1ogNf6Ad9PcDDaPxJ25OGjiY=; b=WYj//AoKqsEL0j/5pncwwyEcppPQ8NZrAgsDmWLbq5DiztE9HEXS60VymBsTCJfnsD o683RQ0GyVVAzrrnNhpYs+IdtzUu8YwAFf/1/IEH9Q5TrMPtQ7FbqhgMaOh8As0WBYcS KJZvGOXs0eeme635QFkPe0/+XYidfOoCqGlOx435lsa58/MMxr/85ox1dZh9ckehWbho mrQ/e69yHDdXBT/iQiNe6rCv3XY2zzNu885IdFQVTBRIv2t36S4kc/MhyUMV7B0Z/fbL 78etvBTGV+AvUVaL5RHidIURl8cmc4Zmrmn3cm7QkJDw7rHSyGnMHXQCsNy3YRcprmRG rogA== X-Forwarded-Encrypted: i=1; AJvYcCUD2FcdOrAkbiqjrU1WBDgHiVhpuORTf0QPG28JYyXCYcYdLFnpt85mgxfi2hkossBxu0hKI8J1zgpV6VQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+b0vkFVBf1UG2NAAkPr+6uxBmWqOA0xpS+gwNcxSjqBfLaP1n H+KyOeDEkb5Y9CkVw+5Z8lUOEIYOyKKSLE+C7AUqcJ/DJT4b6CrX0rGsYV7iX2h7ilP3h6dIrg= = X-Google-Smtp-Source: AGHT+IENqQ4a+JpNNuEyJE6twpdJLH79mb1KDwUiISYTqFmJctu2Pc5D2j5e3Ta7eQhNemgumBMfeJjRgA== X-Received: from pgbbg17.prod.google.com ([2002:a05:6a02:111:b0:7fc:2b57:38f5]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:841c:b0:1e0:d9a0:4ff7 with SMTP id adf61e73a8af0-1eb21599eecmr80987482637.32.1738013619557; Mon, 27 Jan 2025 13:33:39 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:08 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-7-wnliu@google.com> Subject: [PATCH 6/8] unwind: arm64: add reliable stacktrace support for arm64 From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To support livepatch, we need to add arch_stack_walk_reliable to support reliable stacktrace according to https://docs.kernel.org/livepatch/reliable-stacktrace.html#requirements report stacktrace is not reliable if we are not able to unwind the stack by sframe unwinder and fallback to FP based unwinder Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- arch/arm64/include/asm/stacktrace/common.h | 2 + arch/arm64/kernel/stacktrace.c | 47 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/includ= e/asm/stacktrace/common.h index 19edae8a5b1a..26449cd402db 100644 --- a/arch/arm64/include/asm/stacktrace/common.h +++ b/arch/arm64/include/asm/stacktrace/common.h @@ -26,6 +26,7 @@ struct stack_info { * @stacks: An array of stacks which can be unwound. * @nr_stacks: The number of stacks in @stacks. * @cfa: The sp value at the call site of the current function. + * @unreliable: Stacktrace is unreliable. */ struct unwind_state { unsigned long fp; @@ -36,6 +37,7 @@ struct unwind_state { int nr_stacks; #ifdef CONFIG_SFRAME_UNWINDER unsigned long cfa; + bool unreliable; #endif }; =20 diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index c035adb8fe8a..eab16dc05bb5 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -310,11 +310,16 @@ kunwind_next(struct kunwind_state *state) case KUNWIND_SOURCE_TASK: case KUNWIND_SOURCE_REGS_PC: #ifdef CONFIG_SFRAME_UNWINDER - err =3D unwind_next_frame_sframe(&state->common); + if (!state->common.unreliable) + err =3D unwind_next_frame_sframe(&state->common); =20 /* Fallback to FP based unwinder */ - if (err) + if (err || state->common.unreliable) { err =3D kunwind_next_frame_record(state); + /* Mark its stacktrace result as unreliable if it is unwindable via FP */ + if (!err) + state->common.unreliable =3D true; + } #else err =3D kunwind_next_frame_record(state); #endif @@ -446,6 +451,44 @@ noinline noinstr void arch_stack_walk(stack_trace_cons= ume_fn consume_entry, kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, regs); } =20 +#ifdef CONFIG_SFRAME_UNWINDER +struct kunwind_reliable_consume_entry_data { + stack_trace_consume_fn consume_entry; + void *cookie; + bool unreliable; +}; + +static __always_inline bool +arch_kunwind_reliable_consume_entry(const struct kunwind_state *state, voi= d *cookie) +{ + struct kunwind_reliable_consume_entry_data *data =3D cookie; + + if (state->common.unreliable) { + data->unreliable =3D true; + return false; + } + return data->consume_entry(data->cookie, state->common.pc); +} + +noinline notrace int arch_stack_walk_reliable( + stack_trace_consume_fn consume_entry, + void *cookie, struct task_struct *task) +{ + struct kunwind_reliable_consume_entry_data data =3D { + .consume_entry =3D consume_entry, + .cookie =3D cookie, + .unreliable =3D false, + }; + + kunwind_stack_walk(arch_kunwind_reliable_consume_entry, &data, task, NULL= ); + + if (data.unreliable) + return -EINVAL; + + return 0; +} +#endif + struct bpf_unwind_consume_entry_data { bool (*consume_entry)(void *cookie, u64 ip, u64 sp, u64 fp); void *cookie; --=20 2.48.1.262.g85cc9f2d1e-goog