Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp686877ybt; Fri, 10 Jul 2020 09:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfcrUWWkJGCWMiGkvbo979afx/Dh4e9eRLSn46BlVxkbNLwW48cxPPSR1ipVaIHM6VenbP X-Received: by 2002:a05:6402:1c0f:: with SMTP id ck15mr75184523edb.155.1594399735626; Fri, 10 Jul 2020 09:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594399735; cv=none; d=google.com; s=arc-20160816; b=v9Pd5AdEePZ/osRn9asOK4BKXrVGoRCQQcFeaTforoAt9klX4mI74P25uLUQT8rYLK vqqWpGGJ+V/Fu2XH8pOyvvvsU7rZ2ZoZg4Qlkk32Qhre2jhXqp04b/ajVMq79bSYjP9U v6vM1/6XOVpiSty/vWJI0Pgx+nYknI2dCmm8HBBa3Y5jdg3uIlO1+pZQtbdLChgKdweJ Gpytt9hcT+qAQn3KncOGPM0FGod9yf7pEQ6hXRymxLGGEPAUkBFoQ6tW8dCvhwCXmdkR M61NqHj35xcbTmQfNuOOuDRvpCphYsXUErdXevWt2KLSxo2DgRYqn/YyH1+xhYXgW/kE hgyg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=BEJ4O5IRtxDaBgCbgZ/Q408W88KkDEGUZbbV6ihxQP4=; b=SKvCq0BSmqQz98DWxcykZS7EdXqGkKTE705ryyQ5HPGd12xOPY4oqLcRrmn1ue7Bwh Yn/TV2f6sqOnws6x1Km3N22YafWW3xhtpZXW/6YVNVO8IW6YjVpcGaJ9h7K89GQQBkDt GcVqbEk4Dw1bx3NjQQNPcHep4VAGRAh5I5JtzrMAyWF52fgTSKzq3othtqJrTBfJBYep Ora4dM6rgsxc78oedLuKrauGWoR7W+EaY7WOmc8cP0s8Hyw+FDqha9pOg3M28k9xLlE0 Pliq2WQAz/hPhdeUIW2xHrUqKI2MUyyobx+fq8vzJm4CvuJktBpRzcXQ9LZFbv1AxXqY IY8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m8jqouEa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si289158ejd.290.2020.07.10.09.48.32; Fri, 10 Jul 2020 09:48:55 -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=@google.com header.s=20161025 header.b=m8jqouEa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728146AbgGJQqJ (ORCPT + 99 others); Fri, 10 Jul 2020 12:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgGJQqJ (ORCPT ); Fri, 10 Jul 2020 12:46:09 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF11C08C5DC for ; Fri, 10 Jul 2020 09:46:09 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id e8so2768215pgc.5 for ; Fri, 10 Jul 2020 09:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BEJ4O5IRtxDaBgCbgZ/Q408W88KkDEGUZbbV6ihxQP4=; b=m8jqouEai9bWz+XEvv1yWqI+GZ0fpiFnMhVhotCGhobHSsVF0OzprD/Pu+8bIz883f wn2NMRgiZgQhyXD3guMQPXhE7b0qa30Goqz+Maq/Af+u2SmZzvdmH8XHzIeOQyuAQ2LE pWucWqF61fm5PbBH1RVdMIpsLsNikV8VlUloYdHkTVWbHEfryUU7JVSwYr32AG54tSTK wSqPgq/K/NXtYGP/ELB7Hi1ciGgWF6CYUVsDCosZD2CrdAQvo5yQFVmNEK1r5YcMzBsz uf06YTRPOXqdexRP7lNgmTxtXk+LEJkUpqA9iOnQ/EKmeNgnEzTrjp6KfXn77H6ptzjJ nqMg== 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:from:date :message-id:subject:to:cc; bh=BEJ4O5IRtxDaBgCbgZ/Q408W88KkDEGUZbbV6ihxQP4=; b=LbRN8TZVAJGrZUcSTy1yrgYxC14oAdWzg5EbgfPmCu+ldhYSNur9LpVMN05p1sUXUC r28tmG6+AeBUntqieN+limP40K6oP29FaRJhz0nHPltuXffWY2iNOCBG0GfscONPXdpQ Qp/iRLM+CiSQGnJ7Gi86B9NSQCVdXVm2gPTk9fNipazU4taxYWxD4ESjhZ9t1erp3/P1 E2R88pPhte7xeCsPFtwrJxiQ4u1J8Ojblvyw3ZhHTTDPd3czdbuazucEnVWYRrCP/j1t BIQ5NSehN0biiKfTjBGCLYWh9iuwvcUd7Z7v99LbnxYBjdHPLT9FxFVu0Thm575RJXwz K50g== X-Gm-Message-State: AOAM533rHHNphOBp7rvhpzfx4VMTmnybXumA8KakV+L4+HiW1O4LQajX Z1haw/+iboHuSBpPQCNYszMSPlHKMQj3/29QeKr/3Q== X-Received: by 2002:a05:6a00:15ca:: with SMTP id o10mr64641771pfu.169.1594399568391; Fri, 10 Jul 2020 09:46:08 -0700 (PDT) MIME-Version: 1.0 References: <1592531704.23014.1.camel@mtkswgap22> <20200706182713.3693762-1-nhuck@google.com> In-Reply-To: <20200706182713.3693762-1-nhuck@google.com> From: Nick Desaulniers Date: Fri, 10 Jul 2020 09:45:55 -0700 Message-ID: Subject: Re: [PATCH v2] ARM: stacktrace: Fix unwind_frame for clang-built kernels To: Nathan Huckleberry Cc: Russell King , Vincent Whitchurch , Linux ARM , LKML , clang-built-linux , Miles Chen , "# 3.4.x" 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 Hi Nathan, Would you please submit this to Russell's patch tracking system: https://www.arm.linux.org.uk/developer/patches/ login -> add new patch. On Mon, Jul 6, 2020 at 11:27 AM Nathan Huckleberry 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 > Reported-by: Miles Chen > Tested-by: Miles Chen > Cc: stable@vger.kernel.org > Reviewed-by: Nick Desaulniers > Signed-off-by: Nathan Huckleberry > --- > 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.212.ge8ba1cc988-goog > -- Thanks, ~Nick Desaulniers