Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2854285ybb; Sun, 5 Apr 2020 18:54:13 -0700 (PDT) X-Google-Smtp-Source: APiQypLzncelHOaStkzXfeuIMtV8/qcjChhDGi9rRHtYkLMnqUa1SbPMGHLMAJ/eCpq0lMdo8BHI X-Received: by 2002:a54:4f0a:: with SMTP id e10mr11511006oiy.127.1586138053321; Sun, 05 Apr 2020 18:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586138053; cv=none; d=google.com; s=arc-20160816; b=WUciyFsUhgI9RnJpwPxoNgN0HLFLJwOgYRyLE5EMPyOeWXK2TDeoK4UYpngxgzx7hA on9Cqzs3Buqa0f6Bx89B5vYo9krOgNTdRDoG81NygWJUJhRjET8W4GQ12PwhTsW1Rkm0 2kYEvx+YcgWWt+oHoSX4urmFkWbAoy/DMA58211aMwe5oFDo6PDuYBke6RYL43SBxNAq 60eXk2NR6U3UoPd80w++AT7HV2IcByvIOn4a1QcKQI+IKekBWjDkTe2GySJuDObrxDOn 52JkkLuwhxytzTGUckp8ejOk/Z76LVHJWr2Yq9LF6k/t3zZn056FD8CQTHzLz4qGnCi9 gOjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id :user-agent:mime-version:in-reply-to:references:cc:to:subject:from :date:dkim-signature; bh=SXNmSzR5dCwNc7/+tCsUjUE/EFRQc9Jf99e8qsmtQcE=; b=F6UQPH+yftPUW70cxByDp1czRFEleUPqcigG4EdyVwIRBxjRC9h/Vrl1lYdfax3Z2p BzWn96YcKx6Vg0x3zSwBYWj0uDpBJgCHwTbTEB93ZP6oytD7PuOHNa9DhxhclWJ7H6S/ LitJF+6ZKXXyA7cHW2isFQibvGUOgbqO3Z9sq4JUItmlQU1AAq6jY7Z7Ja6jGDIHJYer hvLtqJ7wMjdapHAR+F8ZbDSRMLL2o+NodzMLVgPWrTRFkWLOrzrF8wHGsW+7M+DqvYv+ t2ChOSDhdZ9Q2oDx28MNbOvb1MK8WFp9TYLwCdm8cr6RuRsuQsmzK0Iq6+SHiRfgFTvA itQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="me/5NIBv"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b16si6712276oop.83.2020.04.05.18.54.01; Sun, 05 Apr 2020 18:54:13 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b="me/5NIBv"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726483AbgDFBxP (ORCPT + 99 others); Sun, 5 Apr 2020 21:53:15 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41735 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726373AbgDFBxP (ORCPT ); Sun, 5 Apr 2020 21:53:15 -0400 Received: by mail-pg1-f193.google.com with SMTP id m13so2800403pgd.8 for ; Sun, 05 Apr 2020 18:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :user-agent:message-id:content-transfer-encoding; bh=SXNmSzR5dCwNc7/+tCsUjUE/EFRQc9Jf99e8qsmtQcE=; b=me/5NIBvO2lNB6Y0A1jhUtCoK1+T+/rgkm3YXt9oSeGy8v0G+3YBCqKT3p+13hjTKQ GkgNLcAQu5c7KE63P+RDnYtjmZmulP4U5V4S71QgcEfbYPn4GltpEFFq1CJX7Wp4fb6M eyzwM6AeuqdYUfWbMG9iIJL7Gu5TpQGkj6FX3Wv+/+JydxYuNBuMmDJ0OG6iFp9X5e4S PbnLja9dWFc7/pT2d2TfWV84PhsHTOXsTMzeiGNElukoiR2+7KULficc6UmGveDGobzJ 898ZdO9LzU8pJcf+4w0jrk5AYdGe4pSqdkT891row6mVAFWfn7d66WvxzXFEoFZTCnqW i2rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:user-agent:message-id:content-transfer-encoding; bh=SXNmSzR5dCwNc7/+tCsUjUE/EFRQc9Jf99e8qsmtQcE=; b=DKdiICX0GBQ4yFm/RumBSqtkjwQwetd5L6Oifba9rbL5WueH6C/0wZX10YZoCo0lZq 9nZeeaDzGePVYF3z8ldJxCscDMNB36MyNNjGBPTGez0wHkoZMqYx3bGRfPL0MkSIAhPm rHbMqr1gYx5eb1bVqzdu1bVpM2TGaVI225aSYOggj9BhQ9VTB56USRW7mxvmSFfKaJzv Zx7AlSebimB+adorvTa+0zuyeW+DTmQ9wP7rcSzNJ7q/WyIuUzGdtdgWYl2LPlEPl0Yr 0qic0fxQcBqMq+6sQuhD1VvjjwrYddE5W2o7l//wvw+qTXqyoD9QynfPOkLNtQV+ET/R nvQA== X-Gm-Message-State: AGi0PuZNlZ95DTeK857HSj8zubo6uzARoGaZ/LcQz1RB/pP5D5NeF7dZ PcwAs5qn2XPKAnDZd18jfKE= X-Received: by 2002:a63:fc24:: with SMTP id j36mr18103516pgi.397.1586137991685; Sun, 05 Apr 2020 18:53:11 -0700 (PDT) Received: from localhost (60-241-117-97.tpgi.com.au. [60.241.117.97]) by smtp.gmail.com with ESMTPSA id q8sm10636205pjq.28.2020.04.05.18.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Apr 2020 18:53:11 -0700 (PDT) Date: Mon, 06 Apr 2020 11:52:03 +1000 From: Nicholas Piggin Subject: Re: [RFC PATCH v2 06/13] powerpc/syscall: Make syscall_64.c buildable on PPC32 To: Benjamin Herrenschmidt , Christophe Leroy , Michael Ellerman , msuchanek@suse.de, Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <029e1064b1ad738785718221ea468c9cfc282457.1586108649.git.christophe.leroy@c-s.fr> <923ab2df9d4a4d0f3a072421e054028c18d614d8.1586108649.git.christophe.leroy@c-s.fr> In-Reply-To: <923ab2df9d4a4d0f3a072421e054028c18d614d8.1586108649.git.christophe.leroy@c-s.fr> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1586137334.pcovkdryot.astroid@bobo.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe Leroy's on April 6, 2020 3:44 am: > ifdef out specific PPC64 stuff to allow building > syscall_64.c on PPC32. >=20 > Modify Makefile to always build syscall.o >=20 > Signed-off-by: Christophe Leroy > --- > arch/powerpc/kernel/Makefile | 5 ++--- > arch/powerpc/kernel/syscall.c | 10 ++++++++++ > 2 files changed, 12 insertions(+), 3 deletions(-) >=20 > diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile > index 8cc3c831dccd..e4be425b7718 100644 > --- a/arch/powerpc/kernel/Makefile > +++ b/arch/powerpc/kernel/Makefile > @@ -45,11 +45,10 @@ obj-y :=3D cputable.o syscalls.o \ > signal.o sysfs.o cacheinfo.o time.o \ > prom.o traps.o setup-common.o \ > udbg.o misc.o io.o misc_$(BITS).o \ > - of_platform.o prom_parse.o > + of_platform.o prom_parse.o syscall.o > obj-y +=3D ptrace/ > obj-$(CONFIG_PPC64) +=3D setup_64.o sys_ppc32.o signal_64.o \ > - paca.o nvram_64.o firmware.o note.o \ > - syscall.o > + paca.o nvram_64.o firmware.o note.o > obj-$(CONFIG_VDSO32) +=3D vdso32/ > obj-$(CONFIG_PPC_WATCHDOG) +=3D watchdog.o > obj-$(CONFIG_HAVE_HW_BREAKPOINT) +=3D hw_breakpoint.o > diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.= c > index 72f3d2f0a823..28bd43db8755 100644 > --- a/arch/powerpc/kernel/syscall.c > +++ b/arch/powerpc/kernel/syscall.c > @@ -25,8 +25,10 @@ notrace long system_call_exception(long r3, long r4, l= ong r5, > unsigned long ti_flags; > syscall_fn f; > =20 > +#ifdef CONFIG_PPC64 > if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) > BUG_ON(irq_soft_mask_return() !=3D IRQS_ALL_DISABLED); > +#endif > =20 > trace_hardirqs_off(); /* finish reconciling */ > =20 > @@ -34,7 +36,9 @@ notrace long system_call_exception(long r3, long r4, lo= ng r5, > BUG_ON(!(regs->msr & MSR_RI)); > BUG_ON(!(regs->msr & MSR_PR)); > BUG_ON(!FULL_REGS(regs)); > +#ifdef CONFIG_PPC64 > BUG_ON(regs->softe !=3D IRQS_ENABLED); > +#endif > =20 > account_cpu_user_entry(); > =20 > @@ -56,7 +60,9 @@ notrace long system_call_exception(long r3, long r4, lo= ng r5, > * frame, or if the unwinder was taught the first stack frame always > * returns to user with IRQS_ENABLED, this store could be avoided! > */ > +#ifdef CONFIG_PPC64 > regs->softe =3D IRQS_ENABLED; > +#endif > =20 > local_irq_enable(); > =20 > @@ -148,7 +154,9 @@ notrace unsigned long syscall_exit_prepare(unsigned l= ong r3, > ret |=3D _TIF_RESTOREALL; > } > =20 > +#ifdef CONFIG_PPC64 > again: > +#endif > local_irq_disable(); > ti_flags =3D READ_ONCE(*ti_flagsp); > while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) { > @@ -191,6 +199,7 @@ notrace unsigned long syscall_exit_prepare(unsigned l= ong r3, > =20 > /* This pattern matches prep_irq_for_idle */ > __hard_EE_RI_disable(); > +#ifdef CONFIG_PPC64 > if (unlikely(lazy_irq_pending())) { > __hard_RI_enable(); > trace_hardirqs_off(); > @@ -201,6 +210,7 @@ notrace unsigned long syscall_exit_prepare(unsigned l= ong r3, > } > local_paca->irq_happened =3D 0; > irq_soft_mask_set(IRQS_ENABLED); > +#endif > =20 > #ifdef CONFIG_PPC_TRANSACTIONAL_MEM > local_paca->tm_scratch =3D regs->msr; > --=20 > 2.25.0 >=20 >=20 The #ifdefs disappoint me! Here is (unested) something that should help 32-bit avoid several ifdefs=20 in the main part of the function. I should have done this as part of the=20 merged series, but that's okay I'll submit as a cleanup. The rest looks okay for now. Maybe we grow some helpers to manage the soft-mask state, though I'm not really sure it would make sense for=20 32-bit code to ever call them. Maybe just confined to this file would be okay but for now the ifdefs are okay. --- arch/powerpc/kernel/syscall_64.c | 58 +++++++++++++++----------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall= _64.c index cf06eb443a80..f021db893ec2 100644 --- a/arch/powerpc/kernel/syscall_64.c +++ b/arch/powerpc/kernel/syscall_64.c @@ -103,6 +103,31 @@ notrace long system_call_exception(long r3, long r4, l= ong r5, return f(r3, r4, r5, r6, r7, r8); } =20 +/* + * local irqs must be disabled. Returns false if the caller must re-enable + * them, check for new work, and try again. + */ +static notrace inline bool prep_irq_for_enabled_exit(void) +{ + /* This must be done with RI=3D1 because tracing may touch vmaps */ + trace_hardirqs_on(); + + /* This pattern matches prep_irq_for_idle */ + __hard_EE_RI_disable(); + if (unlikely(lazy_irq_pending())) { + /* Took an interrupt, may have more exit work to do. */ + __hard_RI_enable(); + trace_hardirqs_off(); + local_paca->irq_happened |=3D PACA_IRQ_HARD_DIS; + + return false; + } + local_paca->irq_happened =3D 0; + irq_soft_mask_set(IRQS_ENABLED); + + return true; +} + /* * This should be called after a syscall returns, with r3 the return value * from the syscall. If this function returns non-zero, the system call @@ -186,21 +211,10 @@ notrace unsigned long syscall_exit_prepare(unsigned l= ong r3, } } =20 - /* This must be done with RI=3D1 because tracing may touch vmaps */ - trace_hardirqs_on(); - - /* This pattern matches prep_irq_for_idle */ - __hard_EE_RI_disable(); - if (unlikely(lazy_irq_pending())) { - __hard_RI_enable(); - trace_hardirqs_off(); - local_paca->irq_happened |=3D PACA_IRQ_HARD_DIS; + if (unlikely(!prep_irq_for_enabled_exit())) { local_irq_enable(); - /* Took an interrupt, may have more exit work to do. */ goto again; } - local_paca->irq_happened =3D 0; - irq_soft_mask_set(IRQS_ENABLED); =20 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM local_paca->tm_scratch =3D regs->msr; @@ -264,19 +278,11 @@ notrace unsigned long interrupt_exit_user_prepare(str= uct pt_regs *regs, unsigned } } =20 - trace_hardirqs_on(); - __hard_EE_RI_disable(); - if (unlikely(lazy_irq_pending())) { - __hard_RI_enable(); - trace_hardirqs_off(); - local_paca->irq_happened |=3D PACA_IRQ_HARD_DIS; + if (unlikely(!prep_irq_for_enabled_exit())) { local_irq_enable(); local_irq_disable(); - /* Took an interrupt, may have more exit work to do. */ goto again; } - local_paca->irq_happened =3D 0; - irq_soft_mask_set(IRQS_ENABLED); =20 #ifdef CONFIG_PPC_BOOK3E if (unlikely(ts->debug.dbcr0 & DBCR0_IDM)) { @@ -334,13 +340,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(st= ruct pt_regs *regs, unsign } } =20 - trace_hardirqs_on(); - __hard_EE_RI_disable(); - if (unlikely(lazy_irq_pending())) { - __hard_RI_enable(); - irq_soft_mask_set(IRQS_ALL_DISABLED); - trace_hardirqs_off(); - local_paca->irq_happened |=3D PACA_IRQ_HARD_DIS; + if (unlikely(!prep_irq_for_enabled_exit())) { /* * Can't local_irq_restore to replay if we were in * interrupt context. Must replay directly. @@ -354,8 +354,6 @@ notrace unsigned long interrupt_exit_kernel_prepare(str= uct pt_regs *regs, unsign /* Took an interrupt, may have more exit work to do. */ goto again; } - local_paca->irq_happened =3D 0; - irq_soft_mask_set(IRQS_ENABLED); } else { /* Returning to a kernel context with local irqs disabled. */ __hard_EE_RI_disable(); --=20 2.23.0 =