Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp899994pxb; Fri, 3 Sep 2021 16:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCdpz4Y8KHXmpF6Qa/ZxLmXRFE5TGmu47OQeXAZq3nSuv5iH9K0bSoCt/zJ0TeHIsg8eOF X-Received: by 2002:a6b:7106:: with SMTP id q6mr1170130iog.174.1630712638988; Fri, 03 Sep 2021 16:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630712638; cv=none; d=google.com; s=arc-20160816; b=h9JgXwU3Mlsw/OUn3U6UVrA8ybu+4NEFXkbGKa5OSoEPcSaeEej7+FJO+uw3aDeHSU x6dDQyeW1Sb+n05tASgMVPoqibNB5tXBydi8ums961b+fob4Ev7zxLHlNTKgI2n/L1UG 1wzUcBxCxpq+fXehUDBKnpuR7KvyVRYFtSQdDRccI2i7gYOoIN4Q/jn5d7E/gMhb/vYu 6SFjdXMV8icf9/j/orM6f/mvR7khJ3NH23m5Bj6066oMuxi5NK3OBwY483Znj8PFnFw/ jZDjA+4MXJ9Y/9rDX0/oq9lKpAI/yoPEirkbbZ0nBFqOiREPDrzSagvwKcfWApQygeox XmFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=omdAfx+k213K/nvXRXneAyzfo55VqJjHg529yTSEP3s=; b=bmaknMl5fgIA5ridhcp7bIdct4j2//hR8Kqc2hrgfcYbub7+zWbBH6SL3t8DsmmNMB nlIcfcM4tf5mNil0MZfBrGcdRibxrK3MGI9noe7LsagKAesFkcMSEKXA0xvDPS4Dh8NU euIyOYSxsVkU+yE8gKckbncLi6PmhJp4fBXUbsdHlRxwZol34Pf+0hEg8PxYo2JmXvfz m/EM83EcE66mLnIL5FUQjOiSn4KIwUFkKZUBdeC0Q8LlhfkFeZrQNMu+aPoCRa2889Oh IhzFvJzUS1UNiR7Yzu/O+dW013mMHQ1TD63c222VHEAUQ2XLSX2kRqu97tXWcOepfS1/ 57VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ie3jZOju; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v9si647757ile.167.2021.09.03.16.43.47; Fri, 03 Sep 2021 16:43:58 -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=@kernel.org header.s=k20201202 header.b=ie3jZOju; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350740AbhICXZD (ORCPT + 99 others); Fri, 3 Sep 2021 19:25:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:35032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242236AbhICXZD (ORCPT ); Fri, 3 Sep 2021 19:25:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 17D4460FDC; Fri, 3 Sep 2021 23:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630711442; bh=ACCxEolEsBare+4plIWhMemWYTJcclcvIZOrthMVAZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ie3jZOjuQEegdSKsBXeNP5mzCP/oy8RYbKJ5vBRRmJm+QfeUjlJSH3cddq8ab3rHo kSmBI4RG6QnRyRXHSlMZM8LKOEsqwguAJVlVmDWW6bmJf+l9xQDcXhLbD/BHMJ83XJ /8O76OQD9aTe5HEnuryBrnaihzGJK2YqtC8sLa/JWme4EnelJw2BLEotA6u8DazbtZ VVC2JVoJWToAipnbGm4fhzvj9o31hI3EFZ02HUgVx18FaphDOUE1/HuhXgLdUAd1ID 4NGr2R3r6khQI7pCGjl8l3pip8BVD85J0Iz+8GyIPKZpnZ4FVO5ncUcy8z9/bKtRQW muZk9jPiHkFXw== Date: Fri, 3 Sep 2021 16:23:59 -0700 From: Nathan Chancellor To: Vasily Gorbik Cc: Marco Elver , Heiko Carstens , Christian Borntraeger , Linus Torvalds , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, qemu-s390x Subject: Re: [PATCH] s390/unwind: use current_frame_address() to unwind current task Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 01, 2021 at 04:05:59PM +0200, Vasily Gorbik wrote: > current_stack_pointer() simply returns current value of %r15. If > current_stack_pointer() caller allocates stack (which is the case in > unwind code) %r15 points to a stack frame allocated for callees, meaning > current_stack_pointer() caller (e.g. stack_trace_save) will end up in > the stacktrace. This is not expected by stack_trace_save*() callers and > causes problems. > > current_frame_address() on the other hand returns function stack frame > address, which matches %r15 upon function invocation. Using it in > get_stack_pointer() makes it more aligned with x86 implementation > (according to BACKTRACE_SELF_TEST output) and meets stack_trace_save*() > caller's expectations, notably KCSAN. > > Also make sure unwind_start is always inlined. > > Reported-by: Nathan Chancellor > Suggested-by: Marco Elver > Signed-off-by: Vasily Gorbik Sorry for the late response and I see that this has already been applied but I took this for a spin and all of the tests pass with clang-14 in QEMU. Thank you for the quick fix so that we can get this turned on in CI :) [ 10.362073] ok 1 - test_basic [ 13.870386] ok 2 - test_concurrent_races [ 17.379643] ok 3 - test_novalue_change [ 17.393315] ok 4 - test_novalue_change_exception [ 17.409815] ok 5 - test_unknown_origin [ 20.914289] ok 6 - test_write_write_assume_atomic [ 20.982545] ok 7 - test_write_write_struct [ 21.106135] ok 8 - test_write_write_struct_part [ 24.622205] ok 9 - test_read_atomic_write_atomic [ 24.662048] ok 10 - test_read_plain_atomic_write [ 24.775291] ok 11 - test_read_plain_atomic_rmw [ 28.294457] ok 12 - test_zero_size_access [ 31.829529] ok 13 - test_data_race [ 31.867174] ok 14 - test_assert_exclusive_writer [ 31.929184] ok 15 - test_assert_exclusive_access [ 35.446281] ok 16 - test_assert_exclusive_access_writer [ 35.540228] ok 17 - test_assert_exclusive_bits_change [ 39.052271] ok 18 - test_assert_exclusive_bits_nochange [ 39.097020] ok 19 - test_assert_exclusive_writer_scoped [ 39.152914] ok 20 - test_assert_exclusive_access_scoped [ 42.675158] ok 21 - test_jiffies_noreport [ 46.192453] ok 22 - test_seqlock_noreport [ 49.712712] ok 23 - test_atomic_builtins [ 49.746428] ok 24 - test_1bit_value_change [ 49.753316] ok 1 - kcsan Tested-by: Nathan Chancellor > --- > arch/s390/include/asm/stacktrace.h | 20 ++++++++++---------- > arch/s390/include/asm/unwind.h | 8 ++++---- > 2 files changed, 14 insertions(+), 14 deletions(-) > > diff --git a/arch/s390/include/asm/stacktrace.h b/arch/s390/include/asm/stacktrace.h > index 3d8a4b94c620..22c41d7fd95c 100644 > --- a/arch/s390/include/asm/stacktrace.h > +++ b/arch/s390/include/asm/stacktrace.h > @@ -34,16 +34,6 @@ static inline bool on_stack(struct stack_info *info, > return addr >= info->begin && addr + len <= info->end; > } > > -static __always_inline unsigned long get_stack_pointer(struct task_struct *task, > - struct pt_regs *regs) > -{ > - if (regs) > - return (unsigned long) kernel_stack_pointer(regs); > - if (task == current) > - return current_stack_pointer(); > - return (unsigned long) task->thread.ksp; > -} > - > /* > * Stack layout of a C stack frame. > */ > @@ -74,6 +64,16 @@ struct stack_frame { > ((unsigned long)__builtin_frame_address(0) - \ > offsetof(struct stack_frame, back_chain)) > > +static __always_inline unsigned long get_stack_pointer(struct task_struct *task, > + struct pt_regs *regs) > +{ > + if (regs) > + return (unsigned long) kernel_stack_pointer(regs); > + if (task == current) > + return current_frame_address(); > + return (unsigned long) task->thread.ksp; > +} > + > /* > * To keep this simple mark register 2-6 as being changed (volatile) > * by the called function, even though register 6 is saved/nonvolatile. > diff --git a/arch/s390/include/asm/unwind.h b/arch/s390/include/asm/unwind.h > index de9006b0cfeb..5ebf534ef753 100644 > --- a/arch/s390/include/asm/unwind.h > +++ b/arch/s390/include/asm/unwind.h > @@ -55,10 +55,10 @@ static inline bool unwind_error(struct unwind_state *state) > return state->error; > } > > -static inline void unwind_start(struct unwind_state *state, > - struct task_struct *task, > - struct pt_regs *regs, > - unsigned long first_frame) > +static __always_inline void unwind_start(struct unwind_state *state, > + struct task_struct *task, > + struct pt_regs *regs, > + unsigned long first_frame) > { > task = task ?: current; > first_frame = first_frame ?: get_stack_pointer(task, regs); > -- > 2.25.4