Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1822550imu; Sun, 16 Dec 2018 09:32:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/UwPBeYVVrg6MazkFCWrxgBRumSEY2fMzdFxZYctpBddVBeDn+JgGseSZmQTWRX6FGTKIEA X-Received: by 2002:a63:9f19:: with SMTP id g25mr9483625pge.327.1544981521733; Sun, 16 Dec 2018 09:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544981521; cv=none; d=google.com; s=arc-20160816; b=f97pdTKMBqddW3mR/blOcU+KmZxHg8aEve+eEpbpdRc/tfv1lZGx37gAXlC1trJW3n Yu4Vu0bQKiYQoadm2KmvTSGAI/EtuD9frU/cxx4lLdIy8uus6yyWCbIVRlM1nD133wdK oclabjGaLllxRkcKl496n94L3Dn0LbFVvmCzlSWrc+ovA2QlJGSLqvqyP1gwJ3TmH11C XFTa1X/Osh9r/zUeovPOAyHWi2JTSnBov13GryT/VoB+H9G3UQCo3yC4IrGtSZgstX+q BDwZJW9wcKz56VTgpFlWgIOPbedz5m8p1gcoox+/TR8uZ0hgac89csNZisOgQZESJMp0 hExg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RgdJfQmy0yyJH4ciX1CB7ETVGjadiAr3KbiCYYYv6Pg=; b=H2DHAk8VFOuDwUbTQe8w5237qOCWOakFVRm8XwBdrrBwBqLOcYDwisLRGsTMJbmeUM EQ7dIjM17oMzv4lQYvicgIvh3Tw5nit0xicR0MLAdQiwiJjjFPlHIU78fabTDnllP9Vi bZgD1W9rp0lcNLjJoRjAYJ9wBj8v91JNkfBpx6owm+d4iu9we6BX0hO1To0IuadlwlVJ htXrC6156J9ia9z7/94hzQCuT8XLNjtp4ta721lGZVlRvk2KbDhOWNaVOY5hDhiHGnRH nKx2evQA47cTNWw2i0/2sBBQodMueVQUBi+c4HDR9T1TbBKuzk+QFiNYjsPVD8cWC8mO iS1g== ARC-Authentication-Results: i=1; mx.google.com; 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 a32si9329012pla.168.2018.12.16.09.31.46; Sun, 16 Dec 2018 09:32:01 -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; 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 S1730675AbeLPR2b (ORCPT + 99 others); Sun, 16 Dec 2018 12:28:31 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:40148 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730449AbeLPR2b (ORCPT ); Sun, 16 Dec 2018 12:28:31 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 6394C72CC59; Sun, 16 Dec 2018 20:28:28 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 50C20965035; Sun, 16 Dec 2018 20:28:28 +0300 (MSK) Date: Sun, 16 Dec 2018 20:28:28 +0300 From: "Dmitry V. Levin" To: Michael Ellerman , Oleg Nesterov Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter Message-ID: <20181216172828.GA25359@altlinux.org> References: <20181119210139.GA8360@altlinux.org> <87efbe166y.fsf@concordia.ellerman.id.au> <20181203031823.GE11573@altlinux.org> <20181207011946.GA18558@altlinux.org> <87y391k2tq.fsf@concordia.ellerman.id.au> <20181207154255.GA28964@altlinux.org> <20181207155605.GB28964@altlinux.org> <20181207185226.GB31278@altlinux.org> <20181210132806.GA4177@redhat.com> <20181210133655.GH11942@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181210133655.GH11942@altlinux.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Invoke tracehook_report_syscall_entry once. Signed-off-by: Dmitry V. Levin --- arch/powerpc/kernel/ptrace.c | 54 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index 714c3480c52d..8794d32c2d9e 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) { return 0; } */ long do_syscall_trace_enter(struct pt_regs *regs) { + u32 cached_flags; + user_exit(); - if (test_thread_flag(TIF_SYSCALL_EMU)) { - /* - * A nonzero return code from tracehook_report_syscall_entry() - * tells us to prevent the syscall execution, but we are not - * going to execute it anyway. - * - * Returning -1 will skip the syscall execution. We want to - * avoid clobbering any register also, thus, not 'gotoing' - * skip label. - */ - if (tracehook_report_syscall_entry(regs)) - ; - return -1; - } + cached_flags = READ_ONCE(current_thread_info()->flags) & + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE); - /* - * The tracer may decide to abort the syscall, if so tracehook - * will return !0. Note that the tracer may also just change - * regs->gpr[0] to an invalid syscall number, that is handled - * below on the exit path. - */ - if (test_thread_flag(TIF_SYSCALL_TRACE) && - tracehook_report_syscall_entry(regs)) - goto skip; + if (cached_flags) { + int rc = tracehook_report_syscall_entry(regs); + + if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) { + /* + * A nonzero return code from + * tracehook_report_syscall_entry() tells us + * to prevent the syscall execution, but + * we are not going to execute it anyway. + * + * Returning -1 will skip the syscall execution. + * We want to avoid clobbering any register also, + * thus, not 'gotoing' skip label. + */ + return -1; + } + + if (rc) { + /* + * The tracer decided to abort the syscall. + * Note that the tracer may also just change + * regs->gpr[0] to an invalid syscall number, + * that is handled below on the exit path. + */ + goto skip; + } + } /* Run seccomp after ptrace; allow it to set gpr[3]. */ if (do_seccomp(regs)) -- ldv