Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp209782ybl; Thu, 23 Jan 2020 22:00:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw9yfNyohCXSSIL887qe/fRHsLn8pCbVi/FlXBfJKaemYjvmWhoX+oEb0bGvR+BbGlw+Z4+ X-Received: by 2002:a05:6830:154a:: with SMTP id l10mr1568065otp.44.1579845608844; Thu, 23 Jan 2020 22:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579845608; cv=none; d=google.com; s=arc-20160816; b=TBqPwfcIZGifAmoFZz+XfbYny1TSL1kmFasRKz8L4KP+yqrys8aSg4TMRgsU+K9wev JOD9TFv9YcYBPj7Tuc+pTKFrTWBzZ0E0e6o1F7Sd5OtqXNGHM7Yku66KVfVyAAIUj89Z DhJ8BXgkf1Es0dcEd2Zu1ZpdeAeM594WwWsrNVuHfluFHpJCKtwFCneMU+ItFHe0QNbA JkKzX5umjUsE9lb/VN3QOvH35CGjEdoe0YqNnxosRqvdbutw77Om9ZvM75XrYbQ1uMCV OCIZosSPhn5xfBpXVgT3Kq78XMfMDUxzDmBEHGCGR+lsf6s7p53YJzEUwUWEEwnQfGHt 3r9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=JgEZm9iIiPXJ0E4Zz/OKJVLLnrSaAMzU4HW1LLAIvx4=; b=LQP6HDAJur/P498pJ1D05PvjspAP4GMbdkZy+JJBkZEQ/mKwIHo6arIjnOOECjP1hb NW1//TiZ075CnC2by+sXUEUEq/9e7cE04ruAJtp2D1fUmxItWxo2iQPhP/YbyITEDi2n 5f2NEpQny+1EiGDRxv35zguU0leVAuiVjRLXkg39ui/8N5QAd14AJQzjpOz50m1A6nmQ a0ATgA1B84Nu9gACe/e0KOMiOwe4VVmpZTVH3gzyqzo54bFnqWnbVHYaZ9pFDIjIjAcX /SoFoWZKubbzSLa+4q/qIctnl/2meWpBAYLc6Oy7kRpwe/Bt/46dmwOlVWk+x6xWg2ps 4c6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=i+1ZNLkn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l189si1912572oih.166.2020.01.23.21.59.54; Thu, 23 Jan 2020 22:00:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=i+1ZNLkn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730502AbgAXFqa (ORCPT + 99 others); Fri, 24 Jan 2020 00:46:30 -0500 Received: from bilbo.ozlabs.org ([203.11.71.1]:45001 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730247AbgAXFqa (ORCPT ); Fri, 24 Jan 2020 00:46:30 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 483p6W5zVMz9sNF; Fri, 24 Jan 2020 16:46:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1579844788; bh=gUhlGsmxPsj7AoZY/nvO9RjsEp2BAfmFuizDcUbrgWo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=i+1ZNLknNeLIspRl2aa5x3e2lpTbg88wfyCrpdxXnt8EvwW3El3+zs2qZBVm1FDcK TcRLmmkSc5q4TEwLXC6TqhOjfnX901H4gmhsXzQv/R3TPmIe6cDj7CakIRwiyTy+6L 9WhV6NW9ZmZE07oOmbO9m04kgo3ift2emmVWMK1NAecX+ZoJMhXsGXMqgkOSPd730g BhRrJY4+wkqP8DzYxEV1OfVFHysGfy0yxHlQ1Y8L7H4YWh5hIo41AFqOhLFFHYKbkR NV+VIqtvStT8EdbeJtYKjVLQ1+W3zy5kGFQxeb6jJWgeoCWHtTOorJjVfbRrgsz3Tf +9YgFW25zZ9Hg== From: Michael Ellerman To: Christophe Leroy , Benjamin Herrenschmidt , Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Segher Boessenkool Subject: Re: [PATCH 1/2] powerpc/irq: don't use current_stack_pointer() in check_stack_overflow() In-Reply-To: References: Date: Fri, 24 Jan 2020 16:46:24 +1100 Message-ID: <87d0b9iez3.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe Leroy writes: > current_stack_pointer() doesn't return the stack pointer, but the > caller's stack frame. See commit bfe9a2cfe91a ("powerpc: Reimplement > __get_SP() as a function not a define") and commit acf620ecf56c > ("powerpc: Rename __get_SP() to current_stack_pointer()") for details. > > The purpose of check_stack_overflow() is to verify that the stack has > not overflowed. > > To really know whether the stack pointer is still within boundaries, > the check must be done directly on the value of r1. > > Signed-off-by: Christophe Leroy > --- > arch/powerpc/kernel/irq.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c > index bb34005ff9d2..4d468d835558 100644 > --- a/arch/powerpc/kernel/irq.c > +++ b/arch/powerpc/kernel/irq.c > @@ -599,9 +599,8 @@ u64 arch_irq_stat_cpu(unsigned int cpu) > static inline void check_stack_overflow(void) > { > #ifdef CONFIG_DEBUG_STACKOVERFLOW > - long sp; > - > - sp = current_stack_pointer() & (THREAD_SIZE-1); > + register unsigned long r1 asm("r1"); > + long sp = r1 & (THREAD_SIZE - 1); This appears to work but seems to be "unsupported" by GCC, and clang actually complains about it: /linux/arch/powerpc/kernel/irq.c:603:12: error: variable 'r1' is uninitialized when used here [-Werror,-Wuninitialized] long sp = r1 & (THREAD_SIZE - 1); ^~ The GCC docs say: The only supported use for this feature is to specify registers for input and output operands when calling Extended asm (see Extended Asm). https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Local-Register-Variables.html#Local-Register-Variables If I do this it seems to work, but feels a little dicey: asm ("" : "=r" (r1)); sp = r1 & (THREAD_SIZE - 1); Generated code looks OK ish: clang: sp = r1 & (THREAD_SIZE - 1); 22e0: a0 04 24 78 clrldi r4,r1,50 if (unlikely(sp < 2048)) { 22e4: ff 07 24 28 cmpldi r4,2047 22e8: 58 00 81 40 ble 2340 gcc: if (unlikely(sp < 2048)) { 2eb4: 00 38 28 70 andi. r8,r1,14336 ... 2ecc: 24 00 82 40 bne c000000000002ef0 cheers