Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3714973imu; Mon, 10 Dec 2018 06:47:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/XuJEwcgL9GGIEHBxorYe8Yrwi/qwkOUeK37Q86WtA1F82aMZLkedRQT5KPj3aXryph44Sb X-Received: by 2002:a62:d74d:: with SMTP id v13mr12396476pfl.34.1544453221677; Mon, 10 Dec 2018 06:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544453221; cv=none; d=google.com; s=arc-20160816; b=pT4CRR1ciyXpPMELVtMkRHJD3axQXl4Oig2B9m5j2WyM8xIUQuO/D/Nf0N7lvHW/VJ 1n+db6CyR02in2R+vUsZmEpLOWLLiKp4yBc1lgphzHo248Vu1/Zqs2MGvDEHBTr8Crpa 6JtgBQeaxCrTovOO08aBS7q+ZV+4fx2YXTjUZi32q2LqoXD0x3sZt8138jlyvnalTAbD UdrYKZT3ph83c2vgniir0Yj1eXZSEudcmmMUqmSd7ANpxuGO1CJWd9JkJxAJinKbJigv TZrrnxQ97zm8veK0bnxjTORHgiprnfeEjodwBS5F/9HhF/XpXB70uKmthWEFmUhXDNx7 ZT1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=doCj9Xz//Tw6R8UfqCLF5aF5GHDQ1niTGcU6MCodvH4=; b=G7KY26DRYBpk+kBq2jVX/AKSbk4Z3tpYAfDTnXpAoJdlSZ+0m2KJaHthWtIH2/70n0 DGLr4T7IaU4m+IZ+sqA5RvmzcvnvZ3Gqkx3DjvUakZqYZ/hgdvjpefyJ6ABgVuHDdMO8 rsy8N1DyLa15zZKTq2UcUBeVzbYx+RTBbN41UsPljC71/6pnutSor10AmHb0l/UY2/AU fb3Zp8510fQfyiWI3uozmpx9o6jI83HJdW9gyZRR87ZNyVux+AmR5sIQE5+wzVxxJABw jMDjsPSFAgkl8NJEIgU36VioIJN/d3VQZG+w3pdxdWtnQLTs9x/JBZhhE3uyRi4a8oi3 SRFQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si10033682plk.77.2018.12.10.06.46.38; Mon, 10 Dec 2018 06:47: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727516AbeLJN2P (ORCPT + 99 others); Mon, 10 Dec 2018 08:28:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33446 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726687AbeLJN2N (ORCPT ); Mon, 10 Dec 2018 08:28:13 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8F35811A9; Mon, 10 Dec 2018 13:28:12 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.131]) by smtp.corp.redhat.com (Postfix) with SMTP id E94F01A7D4; Mon, 10 Dec 2018 13:28:07 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 10 Dec 2018 14:28:12 +0100 (CET) Date: Mon, 10 Dec 2018 14:28:07 +0100 From: Oleg Nesterov To: "Dmitry V. Levin" Cc: Michael Ellerman , Elvira Khabirova , Benjamin Herrenschmidt , Paul Mackerras , Breno Leitao , Andy Lutomirski , Eugene Syromyatnikov , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Message-ID: <20181210132806.GA4177@redhat.com> References: <20181116121701.14359da0@akathisia> <87ftw12nyn.fsf@concordia.ellerman.id.au> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181207185226.GB31278@altlinux.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 10 Dec 2018 13:28:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/07, Dmitry V. Levin wrote: > > Please make either v5 or v6 edition of this fix, or any similar fix, > into v4.20. IIUC, v5 above means [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call you sent in another series... > long do_syscall_trace_enter(struct pt_regs *regs) > { > + struct thread_info *ti; > + u32 cached_flags; > + > user_exit(); > > - if (test_thread_flag(TIF_SYSCALL_EMU)) { > - ptrace_report_syscall(regs); > - /* > - * Returning -1 will skip the syscall execution. We want to > - * avoid clobbering any register also, thus, not 'gotoing' > - * skip label. > - */ > - return -1; > - } > + ti = current_thread_info(); > + cached_flags = READ_ONCE(ti->flags) & > + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE | > + _TIF_SYSCALL_TRACEPOINT); > > - /* > - * 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 & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { > + 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)) > @@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) > if (regs->gpr[0] >= NR_syscalls) > goto skip; > > - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) > + if (unlikely(cached_flags & _TIF_SYSCALL_TRACEPOINT)) I will leave this to maintainers, but to me this change looks good and imo it also cleanups the code. However I am not sure cached_flags should include _TIF_SYSCALL_TRACEPOINT. If nothing else, the caller can sleep in ptrace_stop() unpredictably long and TIF_SYSCALL_TRACEPOINT can be set/cleared meanwhile. Oleg.