From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF8EC2D0DB for ; Mon, 27 Jan 2020 14:20:29 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD934214DB for ; Mon, 27 Jan 2020 14:20:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t4sEFpjI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD934214DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 485sN90YnjzDq5f for ; Tue, 28 Jan 2020 01:20:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1044; helo=mail-pj1-x1044.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=t4sEFpjI; dkim-atps=neutral Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 485sJt4cQDzDqHR for ; Tue, 28 Jan 2020 01:17:32 +1100 (AEDT) Received: by mail-pj1-x1044.google.com with SMTP id m13so3169471pjb.2 for ; Mon, 27 Jan 2020 06:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xhqemme1Xo9JwMmnanmQLo+0xQhW4ZzkILZwbQ2Yi7I=; b=t4sEFpjIV3ttLi5oDVAYXdAm4+DV9IxCmtXwd1Idd9ka8ThpWkUBXgKpHed7Ylnsks Vrel8yFyyF3q1y/Gf6+68lQc62Ov+ApQJ05ARakwYdE/0kdfLti8jJgQb7JMVS+WCAfk 1L3/jjCk/SrgqxlkCioaEMhiO9H6FiNtC8RpxBStDiT2jFa/xhGBzlEi5n50X8zDEkaC K7LyBpIXt4QnviJrmGh0GIWBTvEP8sbTwFCXAwVRfdpyoXyNBQmazYmWAz3A7YS9/SaP ybS/M0vVTYMmaGJuD7ZPIKg4wqxHS+EJPl/tndzFgwBhUKXEUwEnfTB7yA7YThBZduDx 5Mxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xhqemme1Xo9JwMmnanmQLo+0xQhW4ZzkILZwbQ2Yi7I=; b=Zh+E/hky1FkOcZm+3Vn0R4l9/wKBs9mHK2n5Qpagmfgj7WG6eYjWhulluDKIUYkwdg v20uT+J0F4SlbATdbQf3y+2rUvdh1n4RWWWRLpXpHTejIhYyWOitdZySRK/9sqKaEQcm Pf/GUpkX6SYrrc9l++dYNrIJs/8bE/4UZnWR+L34gqKujZ/VlmwHFezcKbO1nULBcU0v py8CaJ7AmZ6johQic/xg3i/mGgcWQFUDX54mMgh1SsbLwfA8RZVkNvmZpD/rkrOIaPGt VfUn6e5dji2Of0RtBAqpSLl9kKbn7msPr7wFtDbOFjLBnSdfBsVR3L3Rixt6wuErdXx9 DIsQ== X-Gm-Message-State: APjAAAUeHSmOZ7R0aZczBazeQecIlsK8AmT1nVsA6d6d02F6/6Nr+jIn ZfjebHU3j5ZelTEOmtcsfVL8ohr9 X-Google-Smtp-Source: APXvYqzdRD/hzcwYXosSYsisTyGZnqhfx9tg7T1HQCrhPhSerlScgdnHFZi2/kTkSNh5n7/stUzVZA== X-Received: by 2002:a17:902:768a:: with SMTP id m10mr18297283pll.9.1580134649250; Mon, 27 Jan 2020 06:17:29 -0800 (PST) Received: from bobo.ibm.com ([203.194.47.138]) by smtp.gmail.com with ESMTPSA id c68sm16437027pfc.156.2020.01.27.06.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 06:17:28 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/64: system call implement the bulk of the logic in C fix Date: Tue, 28 Jan 2020 00:17:12 +1000 Message-Id: <20200127141712.96738-1-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Suchanek , Nicholas Piggin Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" This incremental patch fixes several soft-mask debug and unsafe smp_processor_id messages due to tracing and false positives in "unreconciled" code. It also fixes a bug with syscall tracing functions that set registers (e.g., PTRACE_SETREG) not setting GPRs properly. There was a bug reported with the TM selftests, I haven't been able to reproduce that one. I can squash this into the main patch and resend the series if it helps but the incremental helps to see the bug fixes. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/cputime.h | 39 +++++++++++++++++------------- arch/powerpc/kernel/syscall_64.c | 26 ++++++++++++++------ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h index c43614cffaac..6639a6847cc0 100644 --- a/arch/powerpc/include/asm/cputime.h +++ b/arch/powerpc/include/asm/cputime.h @@ -44,6 +44,28 @@ static inline unsigned long cputime_to_usecs(const cputime_t ct) #ifdef CONFIG_PPC64 #define get_accounting(tsk) (&get_paca()->accounting) static inline void arch_vtime_task_switch(struct task_struct *tsk) { } + +/* + * account_cpu_user_entry/exit runs "unreconciled", so can't trace, + * can't use use get_paca() + */ +static notrace inline void account_cpu_user_entry(void) +{ + unsigned long tb = mftb(); + struct cpu_accounting_data *acct = &local_paca->accounting; + + acct->utime += (tb - acct->starttime_user); + acct->starttime = tb; +} +static notrace inline void account_cpu_user_exit(void) +{ + unsigned long tb = mftb(); + struct cpu_accounting_data *acct = &local_paca->accounting; + + acct->stime += (tb - acct->starttime); + acct->starttime_user = tb; +} + #else #define get_accounting(tsk) (&task_thread_info(tsk)->accounting) /* @@ -60,23 +82,6 @@ static inline void arch_vtime_task_switch(struct task_struct *prev) } #endif -static inline void account_cpu_user_entry(void) -{ - unsigned long tb = mftb(); - struct cpu_accounting_data *acct = get_accounting(current); - - acct->utime += (tb - acct->starttime_user); - acct->starttime = tb; -} -static inline void account_cpu_user_exit(void) -{ - unsigned long tb = mftb(); - struct cpu_accounting_data *acct = get_accounting(current); - - acct->stime += (tb - acct->starttime); - acct->starttime_user = tb; -} - #endif /* __KERNEL__ */ #else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ static inline void account_cpu_user_entry(void) diff --git a/arch/powerpc/kernel/syscall_64.c b/arch/powerpc/kernel/syscall_64.c index 529393a1ff1e..cfe458adde07 100644 --- a/arch/powerpc/kernel/syscall_64.c +++ b/arch/powerpc/kernel/syscall_64.c @@ -19,7 +19,8 @@ extern void __noreturn tabort_syscall(void); typedef long (*syscall_fn)(long, long, long, long, long, long); -long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, +/* Has to run notrace because it is entered "unreconciled" */ +notrace long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs) { unsigned long ti_flags; @@ -36,7 +37,7 @@ long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, #ifdef CONFIG_PPC_SPLPAR if (IS_ENABLED(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && firmware_has_feature(FW_FEATURE_SPLPAR)) { - struct lppaca *lp = get_lppaca(); + struct lppaca *lp = local_paca->lppaca_ptr; if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx))) accumulate_stolen_time(); @@ -71,13 +72,22 @@ long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, * We use the return value of do_syscall_trace_enter() as the * syscall number. If the syscall was rejected for any reason * do_syscall_trace_enter() returns an invalid syscall number - * and the test below against NR_syscalls will fail. + * and the test against NR_syscalls will fail and the return + * value to be used is in regs->gpr[3]. */ r0 = do_syscall_trace_enter(regs); - } - - if (unlikely(r0 >= NR_syscalls)) + if (unlikely(r0 >= NR_syscalls)) + return regs->gpr[3]; + r3 = regs->gpr[3]; + r4 = regs->gpr[4]; + r5 = regs->gpr[5]; + r6 = regs->gpr[6]; + r7 = regs->gpr[7]; + r8 = regs->gpr[8]; + + } else if (unlikely(r0 >= NR_syscalls)) { return -ENOSYS; + } /* May be faster to do array_index_nospec? */ barrier_nospec(); @@ -139,8 +149,10 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, regs->gpr[3] = r3; } - if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) + if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) { do_syscall_trace_leave(regs); + ret |= _TIF_RESTOREALL; + } again: local_irq_disable(); -- 2.23.0