Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp441255ybk; Wed, 20 May 2020 03:37:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylTqxK0UllAoM0lDzJbXiE2ozDy/HP5+7/qPTuYi0otHFXyCgz1R2NYVCr3N8qT2+YQhOc X-Received: by 2002:a17:906:3481:: with SMTP id g1mr2961565ejb.530.1589971046909; Wed, 20 May 2020 03:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589971046; cv=none; d=google.com; s=arc-20160816; b=EoUhhaiQVP5DRHRv10w7YNE8f+eJdioTxmek9YH8OCnMGplz9l8b7UnVRTV3wmFdyP V10TjPdvn0xD/Bw0jZy4rDGhG+A2UwrN7vWOnGkhIQ9RtthyOezBfb5OymeEYSgyxBR7 sdiNda53H10oeDnHwz6LsuNJrToxB437zVGPUE5cG81zFzbB9hF5wHelnS852FSso3d3 xmaw8v2egqksXpk1dio/xyVeQ5+Wkijd7iEzA8h6/pGc8GUjCbm8GRLkH3pXaZm9cMCU hB3Lb2/Cwai2Uz1gUI78lvWZ35OECnstwEvOztxHSvs/MrrIfgK4jTRSwAXNdhCSMiWs Yk0g== 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:references:in-reply-to:message-id:date :subject:cc:to:from; bh=V6yknj+vJWXws54gcKT0qSazCRx0gDnSyc0i2MrCsWI=; b=Qcc5kn2OKwR76HMmQiIaq9zl98Z7AG2zdhZISgWXrPZcWc3RH7HdmtEreKTCuzCVCI WJTF4xyZA/wORE4BAsbrsRddKgA6KpmUH9rimJV78Fc9rxcUXtXvQeumVoafwJIw0g6J Oczz2AeLHrV/vrv9vujKC+PFyLVob/Pl92Ek07OJ99ACbqPYr+DnafWXCe6/8qIoHpuc wXaArLJxPr70ETogpD4cjBvhjxjqivpcHkYJ1ehkYN9z3rHDHPfQ3OVZDgyt/gRUCu3M TFn3no+XNUQOsTGGgShW6BT8hHANMGIiammkakQ72OATPJZnnv5Hd3GZPnR5iuYqL+CE ulTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de21si1185770edb.304.2020.05.20.03.37.03; Wed, 20 May 2020 03:37:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726810AbgETKfa (ORCPT + 99 others); Wed, 20 May 2020 06:35:30 -0400 Received: from foss.arm.com ([217.140.110.172]:52642 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgETKfa (ORCPT ); Wed, 20 May 2020 06:35:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E02A31B; Wed, 20 May 2020 03:35:29 -0700 (PDT) Received: from localhost.localdomain (unknown [10.169.41.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5957E3F68F; Wed, 20 May 2020 03:35:27 -0700 (PDT) From: Bin Lu To: catalin.marinas@arm.com Cc: keno@juliacomputing.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, oleg@redhat.com, sudeep.holla@arm.com, will@kernel.org, Bin Lu Subject: Re: [PATCH] arm64: Fix PTRACE_SYSEMU semantics Date: Wed, 20 May 2020 18:34:20 +0800 Message-Id: <1589970860-62695-1-git-send-email-bin.lu@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20200519120725.GA20313@gaia> References: <20200519120725.GA20313@gaia> References: <20200515222253.GA38408@juliacomputing.com> <20200518114119.GB32394@willie-the-truck> <20200519120725.GA20313@gaia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200519120725.GA20313@gaia> X-Mutt-References: <20200519120725.GA20313@gaia> X-Mutt-Fcc: =ARM/Sent Items Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bin Lu On Tue, May 19, 2020 at 01:07:27PM +0100, Catalin Marinas wrote: > On Mon, May 18, 2020 at 12:41:20PM +0100, Will Deacon wrote: > > On Fri, May 15, 2020 at 06:22:53PM -0400, Keno Fischer wrote: > > > Quoth the man page: > > > ``` > > > If the tracee was restarted by PTRACE_SYSCALL or PTRACE_SYSEMU, the > > > tracee enters syscall-enter-stop just prior to entering any system > > > call (which will not be executed if the restart was using > > > PTRACE_SYSEMU, regardless of any change made to registers at this > > > point or how the tracee is restarted after this stop). > > > ``` > > > > > > The parenthetical comment is currently true on x86 and powerpc, > > > but not currently true on arm64. arm64 re-checks the _TIF_SYSCALL_EMU > > > flag after the syscall entry ptrace stop. However, at this point, > > > it reflects which method was used to re-start the syscall > > > at the entry stop, rather than the method that was used to reach it. > > > Fix that by recording the original flag before performing the ptrace > > > stop, bringing the behavior in line with documentation and x86/powerpc. > > > > > > Signed-off-by: Keno Fischer > > > --- > > > arch/arm64/kernel/ptrace.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > > > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > > > index b3d3005d9515..b67b4d14aa17 100644 > > > --- a/arch/arm64/kernel/ptrace.c > > > +++ b/arch/arm64/kernel/ptrace.c > > > @@ -1829,10 +1829,12 @@ static void tracehook_report_syscall(struct pt_regs *regs, > > > > > > int syscall_trace_enter(struct pt_regs *regs) > > > { > > > - if (test_thread_flag(TIF_SYSCALL_TRACE) || > > > - test_thread_flag(TIF_SYSCALL_EMU)) { > > > + u32 flags = READ_ONCE(current_thread_info()->flags) & > > > + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE); > > > + > > > + if (flags) { > > > > nit: but I'd rather the '&' operation was in the conditional so that the > > 'flags' variable holds all of the flags. > > > > With that: > > > > Acked-by: Will Deacon > > > > Also needs: > > > > Cc: > > Fixes: f086f67485c5 ("arm64: ptrace: add support for syscall emulation") > > > > Catalin -- can you pick this up for 5.7 please, with my 'nit' addressed? > > I'll queue it with the above addressed. I think flags also needs to be > unsigned long rather than u32. > > However, before sending the pull request, I'd like Sudeep to confirm > that it doesn't break his original use-case for this feature. > Tested-by: Bin Lu (for gVisor) I have just tested all gVisor syscall test cases with ptrace(Regs, FPRegs, TLS) on Arm64 platform. The test results are the same as before there was no patch. My idea is that this kernel patch has no bad effects on gVisor. Linux Kernel version: 5.7.0-rc6+ gVisor version: release-20200511.0