Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp199262ybt; Tue, 16 Jun 2020 21:26:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRqcJFblHAE2d/TfjYoXHmwowZPfxXCrYQPhgkszqKxOjYq6ad2dJJ+pa8+A766ZFKX5jP X-Received: by 2002:a50:a694:: with SMTP id e20mr5363081edc.144.1592367983251; Tue, 16 Jun 2020 21:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592367983; cv=none; d=google.com; s=arc-20160816; b=VJM9Txh1YL66DiMGZMuT6KCUu14WK5fBjc07SepZSNrC8KNtPFt/9cioyX9s6B0lO4 Y1qgdHOa2Xykj2IdjLH+majyOJaTkhz9qXqMqsD9m95G267qqvITRn8WqL9VQR1BpZxm IyTiiLerMqLrf4R1U+etqp6Rjd6V7DkBgKytNXMz9GUVYtPzKah0pTjVRzbXYBNVTvhC hK4ZL3qpdxNJgoXdQ5mSnIeI5h536c7pvbAhL5iwjChVMCpnMVBXZY1/+q0SNLvq4uTG AmOF10rUC2yayEQUhAyRPCfXdKyVbzCLoXqAVkott0LeEMYoAu3vsDI0jWjBK3CINrWC 8UWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:dkim-signature; bh=qnyhMMIEN0LrK0bROeu2AicdajFIxeITYjNsoHRgC8U=; b=EOGzgET5HYxBFTfrZMibmdZPwe4J7Iuyc4tk0Bort/YOtQlRzzc/p11LcdHYTD4YlT wWsnOxpKegeuFT9FXotPxzE6wQiWil93K4uwLks6ZPhLThHXKQbKT7e/kqWyqoDv50hv AEvJ7QorbMHfxJWVev5bASiHnjfNsHvz86qHu4a9rPkECWSJ/11xqeuDfxYlIa6PgMZd I06UNotGOW8rClyaV2Jo4ZjzMk0Nrzecm/I6RkLtv0UcZ9UUbfrkZCMSIQAerC625wbi 807nAeYi1KVuObhbT4uM4hIOwz/RX4IrECUtDjzuOP6sEXjnNfG5dfE8NNiGRt6BqoRF 9gMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nufeHlQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si11546096edp.566.2020.06.16.21.26.00; Tue, 16 Jun 2020 21:26:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nufeHlQ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726497AbgFQEYC (ORCPT + 99 others); Wed, 17 Jun 2020 00:24:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgFQEYC (ORCPT ); Wed, 17 Jun 2020 00:24:02 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAFB7C061573 for ; Tue, 16 Jun 2020 21:24:01 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id q8so1237380iow.7 for ; Tue, 16 Jun 2020 21:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=qnyhMMIEN0LrK0bROeu2AicdajFIxeITYjNsoHRgC8U=; b=nufeHlQ+xs1/zH/m/xtBaDN2m0JgiiUl7Wu3rP4N8z3WkDzhLoj21XpHN2NG386Hsm hmXxXQGLHDNFtUBZRgP2U/FAY3zrMGXf9gUI7N6wpsLwgTuaeCFAbO/4ctgt7XP7qXmT MzONHz5hsVNIgP90DFzJCOoA05nCbJWYz2jIAwLCTvldLhFSbmF4+kr1QLdvJCuSiWfG 44pTap6vEFqEZo7RcDJirK6m8XuQydmfcFb+LpBOx5lCfr/yEqnTMGPUjYO2LYk0X5lJ QmbaCHJspStHUqXAiu9+eHrK73JZA2PutbiE6LuG9NjKEKqKqAETNGx+FWJ5jXwDxDGb 49SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=qnyhMMIEN0LrK0bROeu2AicdajFIxeITYjNsoHRgC8U=; b=PsrXxbb9W/lDM2qt/LHhIIq2+szd6PI8RkppQ5xf0dLb7jWtWpbzk+k3Rznx3O6Aj0 m/ywka4OfLxmAa8b5MG/iOid/PrnRsShR4UKjE/+SS9UfYUUJHt0oOjYy4G2fsL2vryw 95277ZYV2hCXEQTORZvYmlWlwvmAK+v6XnTEznolXvWTcDGaN4LeSCfUGwCG2XGFF4Qe WA6CxpfR7rGl3Zdww7SeCiRrPJ+BmTghBdLBvuKBSHufuUO8Pv/S8eh35j7zMmYv8NqR Ug5AK8groVLpcXEvhfE1EoNe3eH5EBB9naKxYgYjtaxGbjlBmwQzPHsq4Y08aC62RwIP MKCg== X-Gm-Message-State: AOAM530S/m1WdNPP64mSN22Ff/H2zdFemOJywjfeBZITWIjJRhXFVriy MUnWndpzm95mE8SPssMIhppma8MwYah5j1ZfFsI= X-Received: by 2002:a05:6602:2c45:: with SMTP id x5mr6354932iov.80.1592367840047; Tue, 16 Jun 2020 21:24:00 -0700 (PDT) MIME-Version: 1.0 References: <20200616223633.73971-1-nhuck@google.com> In-Reply-To: <20200616223633.73971-1-nhuck@google.com> Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Wed, 17 Jun 2020 06:23:48 +0200 Message-ID: Subject: Re: [PATCH] Fix unwind_frame for clang-built kernels To: Nathan Huckleberry Cc: linux@armlinux.org.uk, vincent.whitchurch@axis.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Clang-Built-Linux ML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 17, 2020 at 12:36 AM 'Nathan Huckleberry' via Clang Built Linux wrote: > > Since clang does not push pc and sp in function prologues, the current > implementation of unwind_frame does not work. By using the previous > frame's lr/fp instead of saved pc/sp we get valid unwinds on clang-built > kernels. > > The bounds check on next frame pointer must be changed as well since > there are 8 less bytes between frames. > > This fixes /proc//stack. > > Link: https://github.com/ClangBuiltLinux/linux/issues/912 > Signed-off-by: Nathan Huckleberry Just a small nit. Please label your patch with: "arm/stacktrace: ..." or "arm: stacktrace: ..." git log --oneline arch/arm/kernel/stacktrace.c ...is your friend :-). - Sedat - > --- > arch/arm/kernel/stacktrace.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c > index cc726afea023..76ea4178a55c 100644 > --- a/arch/arm/kernel/stacktrace.c > +++ b/arch/arm/kernel/stacktrace.c > @@ -22,6 +22,19 @@ > * A simple function epilogue looks like this: > * ldm sp, {fp, sp, pc} > * > + * When compiled with clang, pc and sp are not pushed. A simple function > + * prologue looks like this when built with clang: > + * > + * stmdb {..., fp, lr} > + * add fp, sp, #x > + * sub sp, sp, #y > + * > + * A simple function epilogue looks like this when built with clang: > + * > + * sub sp, fp, #x > + * ldm {..., fp, pc} > + * > + * > * Note that with framepointer enabled, even the leaf functions have the same > * prologue and epilogue, therefore we can ignore the LR value in this case. > */ > @@ -34,6 +47,16 @@ int notrace unwind_frame(struct stackframe *frame) > low = frame->sp; > high = ALIGN(low, THREAD_SIZE); > > +#ifdef CONFIG_CC_IS_CLANG > + /* check current frame pointer is within bounds */ > + if (fp < low + 4 || fp > high - 4) > + return -EINVAL; > + > + frame->sp = frame->fp; > + frame->fp = *(unsigned long *)(fp); > + frame->pc = frame->lr; > + frame->lr = *(unsigned long *)(fp + 4); > +#else > /* check current frame pointer is within bounds */ > if (fp < low + 12 || fp > high - 4) > return -EINVAL; > @@ -42,6 +65,7 @@ int notrace unwind_frame(struct stackframe *frame) > frame->fp = *(unsigned long *)(fp - 12); > frame->sp = *(unsigned long *)(fp - 8); > frame->pc = *(unsigned long *)(fp - 4); > +#endif > > return 0; > } > -- > 2.27.0.290.gba653c62da-goog > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200616223633.73971-1-nhuck%40google.com.