Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp2268pxx; Tue, 27 Oct 2020 18:49:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypZ64Vp+eAv7+GL0g8DfWLRt+xwljYbbMi0iBIZKI8Kirmna9qePAEiQUXQqENhJmXLrs3 X-Received: by 2002:a05:6402:1245:: with SMTP id l5mr5539094edw.78.1603849794554; Tue, 27 Oct 2020 18:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603849794; cv=none; d=google.com; s=arc-20160816; b=QnjteebV+/5ES+gt63krcKPT32tsCcfgs6Z872lFhQzijiIu/Wf8LZ7JceRUEoM0Ki kB01GPSstddQ8JYB59Q9sznvteYkMSCzpCqKjbHU+tWiBEdMxQvPROoPi+LhbDGS5DWI HL2Vv/W4IfAbD65dBTN3Xs3LPN3izizXnhtb1R3IzqX7MjP+948H0Zj+9tNvtXX/SBGG MYfg7IbQzHWMiZWaVcBkQrH2lLBVVRSkVnIQku4vb8dnHxqGx0kq2d5LDLIsdHWUuYkX 2YnJn7flK2PLvinW310l55vl6foC3Bxyq5ZAQ6vVT45PcyUlFTJYImVtVGlUSJ+Afcer hpkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZE1MXiQvZEuT9v9i4wiPmXal4aSR35J5m2P8MAzmPgo=; b=W0/UZDeq8Yp4BqhtaT7REmEhME2pIar0DHFt56e5k2amWCgNFZta3DsIheJ5B/kDVm lJtMNc+9S9DNUeSR5IW2dpYY3osHHpQVIgszquTFJK0KkRv/h0ZbbTs8FwKTtlbiiRsG VN7Tqir6lsqx+wltdcgpc0LHi+tcf5JLerU/NGZTTdWmEG6qX9zrdFy7YAyPntcNCasV 00gd/9ZfFI8fafKv+07c4mgvBqQLz8CkSyL/nvb+2QJ28wCAWi0NjA8aBgiNzz0OIMmL pdPT3bpH8VvJb9YiErzncN0D4T1tnaGKyeym9aevc5VOrDYzIAklQhrv0dFlE9cLtYzv S2NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ofoBOW8k; 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 t10si909340ejg.579.2020.10.27.18.49.32; Tue, 27 Oct 2020 18:49:54 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ofoBOW8k; 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 S2509027AbgJ0IUW (ORCPT + 99 others); Tue, 27 Oct 2020 04:20:22 -0400 Received: from casper.infradead.org ([90.155.50.34]:34394 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2894589AbgJ0IT4 (ORCPT ); Tue, 27 Oct 2020 04:19:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZE1MXiQvZEuT9v9i4wiPmXal4aSR35J5m2P8MAzmPgo=; b=ofoBOW8kmJGcEWu9GjGzLq53wc hstJvbsgNGlqxx2mAIbcCS2zyZG4FpFOUd3lHZOall1KU0G7Ym5Eeh6ygv310HZHOh2yOn553GiLt jAUrixEcFFXr+siNcRp5ovuRdZHbKPeynBkDPHXx3kMqYvoczfSB6VJAwRJA//9tGsETqJZ3Xquc1 FuoE46OjMR5z+Ap32+QR9vDS/7OuuE81zQB2O3Iqrt44aeCQCQ53Q0obMfqC0heI2HpP5uUstf9VG G7EGDfKs0zvJqNd58PHNvw+OM9khSLjWjCWZ8HhJAI6uUr//2uAz1XBTA4ziVv/kOIOOtqIpBXbCv jxI2baDg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXKCb-0001Q4-EQ; Tue, 27 Oct 2020 08:19:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5484C30411F; Tue, 27 Oct 2020 09:19:32 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3F7962127D318; Tue, 27 Oct 2020 09:19:32 +0100 (CET) Date: Tue, 27 Oct 2020 09:19:32 +0100 From: Peter Zijlstra To: Andy Lutomirski Cc: Kyle Huey , open list , Thomas Gleixner , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Linus Torvalds , Robert O'Callahan , Alexandre Chartre , "Paul E. McKenney" , Frederic Weisbecker , Paolo Bonzini , Sean Christopherson , Masami Hiramatsu , Petr Mladek , Joel Fernandes , Steven Rostedt , Boris Ostrovsky , Juergen Gross , Brian Gerst , Josh Poimboeuf , Daniel Thompson Subject: Re: [REGRESSION] x86/debug: After PTRACE_SINGLESTEP DR_STEP is no longer reported in dr6 Message-ID: <20201027081932.GY2611@hirez.programming.kicks-ass.net> References: <20201026155521.GQ2594@hirez.programming.kicks-ass.net> <20201026160513.GC2651@hirez.programming.kicks-ass.net> <20201026163100.GR2594@hirez.programming.kicks-ass.net> <20201026165519.GD2651@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 26, 2020 at 04:30:32PM -0700, Andy Lutomirski wrote: > > @@ -935,6 +936,26 @@ static __always_inline void exc_debug_user(struct pt_regs *regs, > > irqentry_enter_from_user_mode(regs); > > instrumentation_begin(); > > > > + /* > > + * Clear the virtual DR6 value, ptrace routines will set bits here for > > + * things we want signals for. > > + */ > > + current->thread.virtual_dr6 = 0; > > + > > + /* > > + * If PTRACE requested SINGLE(BLOCK)STEP, make sure to reflect that in > > + * the ptrace visible DR6 copy. > > + */ > > + if (test_thread_flag(TIF_BLOCKSTEP) || test_thread_flag(TIF_SINGLESTEP)) > > + current->thread.virtual_dr6 |= (dr6 & DR_STEP); > > I'm guessing that this would fail a much simpler test, though: have a > program use PUSHF to set TF and then read out DR6 from the SIGTRAP. I > can whip up such a test if you like. Kyle also mentioned it. The reason I didn't do that is because ptrace() didn't set the TF, so why should it see it in ptrace_get_debugreg(6) ? > Is there any compelling reason not to just drop the condition and do: > > current->thread.virtual_dr6 |= (dr6 & DR_STEP); > > unconditionally? This DR6 cause, along with ICEBP, have the > regrettable distinctions of being the only causes that a user program > can trigger all on its own without informing the kernel first. This > means that we can't fully separate the concept of "user mode is > single-stepping itself" from "ptrace or something else is causing the > kernel to single step a program." As per the other reply; TF and INT1 should work just fine. virtual_dr6 has nothing to do with that.