Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3453967ybk; Tue, 19 May 2020 05:11:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtAkbp/vwEy2iQKK4eMk6FS/TI1XEB93t2ChkxyrlOV2TaE/U0l4aqvmh4RKGhpF9WfP4L X-Received: by 2002:a17:906:9490:: with SMTP id t16mr358934ejx.413.1589890311249; Tue, 19 May 2020 05:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589890311; cv=none; d=google.com; s=arc-20160816; b=qcn2nuld258nogkodsG8Ntb+aziO50MCEzx7pIVSKtOkYmhbcTiDzr9InthNUG8cCE 5U1EU5MTT6bUvCMb6JOja60XHuE0+CgLl08XZBpDefAe6l98qDl1UxFGKDfs4EUXDldE bUCIUc9ErlB4MfCF9opBv/AKcq9ucpKTshDGqZyQ3eKy37ZO0gdSePYa50Xj2TxhrZEH TrAttgqOn817lAyW5aYSSmldayQFCC57A6OLR9usVBx/FYgiF8IEcwQgE8qy/YDhB5An IlQcLdvKiUw1r31vv0c+rRsPexKgT/v5kF1o3TM/zxTFlZcc+QBzC5WRj9jlFBWNlzwS uLew== 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=9sK2GkYoxTyTRe0f08yU6leELu+iUjlx9/d0c37mL1g=; b=yzycNJGOaJQ77bLG/x0DbM0X/TQMXY/IWQU9/JIYlIIur9Ec5ab+fgsKsR0uKXJCsU xtTzo9KWdeTan5uCsvQqQkAwMRt8LD4cj4v1hvcDBJkxP5UN/0ByjyVUuf1yxncK2rcd uwpqKTsIkXrQPluP+WiYTVptpdIoRgxdzonW960OfNftgkEZKm+OeayTvR0EwEPKXcJR tmZccvm1akPPg+Wuxbn9idhsy278prloEe6HzgQwWzA6p5wHax/P6mhz+2uvuDoo1xMM LvIDuKAPw7HFzIOggOIz9XwYnoiYCunfs8P19plmu5D6qUkFQxfGtBHvuI/sl5J+X3OM FMfA== 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 o1si7558903edv.414.2020.05.19.05.11.26; Tue, 19 May 2020 05:11:51 -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 S1728858AbgESMHb (ORCPT + 99 others); Tue, 19 May 2020 08:07:31 -0400 Received: from foss.arm.com ([217.140.110.172]:59944 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728286AbgESMHb (ORCPT ); Tue, 19 May 2020 08:07:31 -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 A4CB230E; Tue, 19 May 2020 05:07:30 -0700 (PDT) Received: from gaia (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8CD1F3F52E; Tue, 19 May 2020 05:07:29 -0700 (PDT) Date: Tue, 19 May 2020 13:07:27 +0100 From: Catalin Marinas To: Will Deacon Cc: Keno Fischer , linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, sudeep.holla@arm.com, oleg@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: Fix PTRACE_SYSEMU semantics Message-ID: <20200519120725.GA20313@gaia> References: <20200515222253.GA38408@juliacomputing.com> <20200518114119.GB32394@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200518114119.GB32394@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Catalin