Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp881646pxk; Thu, 17 Sep 2020 20:13:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuf9CFDV65NB9S+/10Z3+9X9ZZAYHsof/W++Rmf8jOa9dP27amwXDuXisC/W1tG49bLQPL X-Received: by 2002:a17:906:c55:: with SMTP id t21mr34875833ejf.276.1600398802036; Thu, 17 Sep 2020 20:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398802; cv=none; d=google.com; s=arc-20160816; b=HXvbeMjr8lkQz7/3Ztho0dWfA3MAOZ7jyX79pqmHbROVRzthE1U5bPPSd2/k0nZBvF KOOlJdEaENb6fxsTrN7uZ+RgoHzps069RsgeITRWedOmHcoAZvrrX7PyIgQsR47Dj3aD 7rMFmYImAW8CH054RU4+J/jv4dkiW7tR1/B/JAYCXNn/h6WZMK26BOFbp0+NXTxLyz4Z +DCVxdwnSYlGXePdahDjXlgywkwpMqoLcHV1/ocJU20yyoD5/Xy9NZxsFnTwsCMsyBdp QaWtQZv3sIEoRK1WN4Ryl8DeBXCHnT2EAt9PQ5ymLBHjEX25CmCoUmN/of7pY44wok3d jSbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E/b/oGlzQHR7V5hvd5eDg+jld3G3LKvrnptF8vuLWrM=; b=te41u9VYCDCwaVapc3/Y6mQZ5Ds1BQMXb9qnQk+pfUxDRWMLU1ilRhkzf6Gp6j+x5C tV7AJRZNl1UmmLZ00DZq527G1xwB94b2LcCTkqNXzT5Lu1n863GV94PmfweAMi6Eesx2 xJS54pn6Mc1pqUFJyyTItVorMZgxj/0SiIDIMexDY7P3JDdJ0MuAWMQA6qTKQeF09BxD CF2cnlPNIvcEqW3ZoLnz+iU7xL2jkG/w+q6qJx+2oZFGNf+5wkHHm5SFpUxXaL5OpuwK MyMmmj9zA3W8JmxTPaEvytPsGgmw4omG6b2h7bSg+4oL0Jt2CqbX8Ojh9nR0BI7uKC2e jV7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M3+iUEDh; 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 z6si1123081edr.566.2020.09.17.20.12.59; Thu, 17 Sep 2020 20:13:22 -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=default header.b=M3+iUEDh; 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 S1726859AbgIRDLM (ORCPT + 99 others); Thu, 17 Sep 2020 23:11:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:47702 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbgIRCCb (ORCPT ); Thu, 17 Sep 2020 22:02:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B9152087D; Fri, 18 Sep 2020 02:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394550; bh=o1UIEffgkGVqT10VkWmZfxY3hxOMHLjiuAxTGUvbeMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3+iUEDhPIu4R3JWxS7MDedZRM7G05xKu4SZZhtSBIjUIBnOcRVRPZVmG+JVL+sq9 SnzHM4vR3oK4StZmZ/2ANj0aTODzWwjW0iEQDf+2dn4H6J8W+5SNzin2gA/Jxw6kd5 sjMUuTLmyUNzWx0oY/M3rdGArZU4nDvhsx81w1Hk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vasily Gorbik , Heiko Carstens , Sasha Levin , linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 067/330] s390: avoid misusing CALL_ON_STACK for task stack setup Date: Thu, 17 Sep 2020 21:56:47 -0400 Message-Id: <20200918020110.2063155-67-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Gorbik [ Upstream commit 7bcaad1f9fac889f5fcd1a383acf7e00d006da41 ] CALL_ON_STACK is intended to be used for temporary stack switching with potential return to the caller. When CALL_ON_STACK is misused to switch from nodat stack to task stack back_chain information would later lead stack unwinder from task stack into (per cpu) nodat stack which is reused for other purposes. This would yield confusing unwinding result or errors. To avoid that introduce CALL_ON_STACK_NORETURN to be used instead. It makes sure that back_chain is zeroed and unwinder finishes gracefully ending up at task pt_regs. Reviewed-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- arch/s390/include/asm/stacktrace.h | 11 +++++++++++ arch/s390/kernel/setup.c | 9 +-------- arch/s390/kernel/smp.c | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/s390/include/asm/stacktrace.h b/arch/s390/include/asm/stacktrace.h index 0ae4bbf7779c8..3679d224fd3c5 100644 --- a/arch/s390/include/asm/stacktrace.h +++ b/arch/s390/include/asm/stacktrace.h @@ -111,4 +111,15 @@ struct stack_frame { r2; \ }) +#define CALL_ON_STACK_NORETURN(fn, stack) \ +({ \ + asm volatile( \ + " la 15,0(%[_stack])\n" \ + " xc %[_bc](8,15),%[_bc](15)\n" \ + " brasl 14,%[_fn]\n" \ + ::[_bc] "i" (offsetof(struct stack_frame, back_chain)), \ + [_stack] "a" (stack), [_fn] "X" (fn)); \ + BUG(); \ +}) + #endif /* _ASM_S390_STACKTRACE_H */ diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index 07b2b61a0289f..82ef081e7448e 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -356,7 +356,6 @@ early_initcall(async_stack_realloc); void __init arch_call_rest_init(void) { - struct stack_frame *frame; unsigned long stack; stack = stack_alloc(); @@ -369,13 +368,7 @@ void __init arch_call_rest_init(void) set_task_stack_end_magic(current); stack += STACK_INIT_OFFSET; S390_lowcore.kernel_stack = stack; - frame = (struct stack_frame *) stack; - memset(frame, 0, sizeof(*frame)); - /* Branch to rest_init on the new stack, never returns */ - asm volatile( - " la 15,0(%[_frame])\n" - " jg rest_init\n" - : : [_frame] "a" (frame)); + CALL_ON_STACK_NORETURN(rest_init, stack); } static void __init setup_lowcore_dat_off(void) diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c index 66bf050d785cf..ad426cc656e56 100644 --- a/arch/s390/kernel/smp.c +++ b/arch/s390/kernel/smp.c @@ -878,7 +878,7 @@ static void __no_sanitize_address smp_start_secondary(void *cpuvoid) S390_lowcore.restart_source = -1UL; __ctl_load(S390_lowcore.cregs_save_area, 0, 15); __load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT); - CALL_ON_STACK(smp_init_secondary, S390_lowcore.kernel_stack, 0); + CALL_ON_STACK_NORETURN(smp_init_secondary, S390_lowcore.kernel_stack); } /* Upping and downing of CPUs */ -- 2.25.1