Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2569916imu; Mon, 17 Dec 2018 04:22:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/V2BOzh3aDzKpT6wNjcUQgVueM6hS7EOckxuofuELU3NWwDOQYYMeh3chfKyM8q+iv5W0lx X-Received: by 2002:a62:9913:: with SMTP id d19mr12658259pfe.107.1545049336136; Mon, 17 Dec 2018 04:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545049336; cv=none; d=google.com; s=arc-20160816; b=WFYuS0wH8wg16BnSDaQ0yZgKoRcuo+Bi2GjPTUaxR5Uw46zUJeBXPVpYAO8TOgdCvK TT/MTFk/r9T8JPw5gG9b4tIqMpgpfwRdFoqMZ8nETAO14IqSLYt8mS13xlSz1zor6PXF yHJ7klyJ4F7ZzTjR6Zxlu86W87uCJzEiz5UwUKSGS3awmG99hJEhMjlgPBqfLhkrE4ic IPcmMXgvOn0Zi1xObn3gjBmMh54RbCZliF7fqhmDuDI+Sj5HA46Pd33sRKOzIVZnbKOm nbDD/z/E33lJs6uJ5+uu0yGF+CkqSXZ7PBVHvUXhP9nuRzKqsxHcJqPeUL/K9erfIg4s bFGw== 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; bh=lVQeEQTTBWSf0edVFznRijJE6q/yqEUfoKvlTMfECvU=; b=d/UoNRZ0+4zyOTgESC7zDQqXBlSCMnWlTiChjM8MoEiRZtWo8cY9LMfgXRKfUdzF5F zsBWleo+Exdj2FUNcXG95sP3p3fLF3aD72SOC9nf0AoIbxxoyYcP4yyUUuasSsOFQYqX qAq+niWUSzC311Cvv0Az2Y4SsdeEhRZP7HfqERppvDoJYEcSTEXgn21LYa+A9HrqVv4d f8AxMVvJVGgariDCjlKSfuZKFsMP3C+XDagA+6JgPAXz8nR3Mx/5vR8ExpR8kvn46Jy2 G8IMzP/ZKmeUDpMryiaxT290D2+g8L1C/CObgIJ2HK8BuT2ARBSJPY02ZJJn7CF3DjsJ yzcg== 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 1si10549772plk.296.2018.12.17.04.22.00; Mon, 17 Dec 2018 04:22:16 -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 S1731820AbeLQLUg (ORCPT + 99 others); Mon, 17 Dec 2018 06:20:36 -0500 Received: from ozlabs.org ([203.11.71.1]:56567 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbeLQLUg (ORCPT ); Mon, 17 Dec 2018 06:20:36 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 43JJc235L1z9s4s; Mon, 17 Dec 2018 22:20:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: "Dmitry V. Levin" , Oleg Nesterov Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter In-Reply-To: <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> <20181216172828.GA25359@altlinux.org> Date: Mon, 17 Dec 2018 22:20:26 +1100 Message-ID: <87y38otn5x.fsf@concordia.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 "Dmitry V. Levin" writes: > Invoke tracehook_report_syscall_entry once. Thanks. > 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; > + Do you mind if I just call it "flags", I find "cached_flags" a bit unwieldy for some reason. I'm happy to fix it up when applying. cheers > 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