Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp661217pxx; Wed, 28 Oct 2020 13:44:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxQ0Jt0OIXL8kFCyO00QduiXcCuxq3deV1XHmzDSo1VWnlgWheYZLvwDEujNBNZ0UGFQ/+ X-Received: by 2002:a17:907:270f:: with SMTP id w15mr836221ejk.505.1603917868605; Wed, 28 Oct 2020 13:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603917868; cv=none; d=google.com; s=arc-20160816; b=WEpwk/cnvE2S4psvl3emJMPN9PPDHZWoKqw1kU/6Gtplkmz3+AXU/LyVnTEgzmyX8m 66HrLABuTK9lowsndGpzT5lP9sfH9qEE6GDF/G3rmO3q6yxW3HNPQkQpZ2+oFQNxG8qs uPWinwUQZ5Jezj7Hlb552B8wpobbL26OYKgdE7dHas03pg7HgXmeibWySemBMb43yVN6 Z5ZHsR8MSET//r5ffloFBj2fhVk2sb4g8K+FD6zPu97/XVYus/PEnVdUJQsudgZjyhpP wZ+YZTdXBgrxbRbZsiBtoNuXAhIIqDwNc0uxM5BFjnU4S9hINrFmCHKJqQ900eNjqA/V zsUg== 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=VEzFHgL0HPz0HMmGxJDO5yInCLZElbuDa2OIjgfzZ8M=; b=Qnn2xF1Vk9XyhTrtvMgoyIdI7XEf+lGJVc/UvyiNaC+AvshZF+rDMA/g5fyaIQFXW+ GhDXHTk4oDrha3u2/K0Z+UEB3tevRSlxBEAfIk4AlfVJlFz8gVDMEPSKeHAh0PzCR69m jwpbTjHn1cZpm1FmdELWK+pQ1fqOlI06kVbkNA05U1rDpajG44pzVNaIXaU/kEl6GGfw 5rbuwEvpKpdpKnwNvJKHbOS9/ennfZicKUJdSYq2AAtLQGSpN1dEFslFSGnjZCAh1Nsf INDzYec3vhX/nz3q+nAKCvC/R9YPoRxHFzohVk5eAEFSUQ66o5CpjMn3A8gNZVgj9D/C 8SkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=tpxkmnDk; 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 j6si24427edq.236.2020.10.28.13.44.06; Wed, 28 Oct 2020 13:44:28 -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=merlin.20170209 header.b=tpxkmnDk; 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 S1829900AbgJ0TW4 (ORCPT + 99 others); Tue, 27 Oct 2020 15:22:56 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56080 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1829784AbgJ0TUh (ORCPT ); Tue, 27 Oct 2020 15:20:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=VEzFHgL0HPz0HMmGxJDO5yInCLZElbuDa2OIjgfzZ8M=; b=tpxkmnDk/FCCJupXnig4CJyTKD wqtXyBehLYOouAr6EZs2c+4d7jblmNUhhyIu4fWjZ9C8eCRQS7aCE4VnxXHtJAwp2AxIVpTuqPEr0 QKmqeRzZB87Fp/hySJwK6B218j+T4YFLLem45IUZDMtq990235v/AVMvytMKr4bE7HrG5hqMHa7Ir rEoRZfX9s8d37kuXuq20v9jWo7PUawNDcKf5M9GmPuEpsWcEc78yapXo6MFSvnbTFBz7CBqHoH2EK 159QDtn7lJy9pFEgm/jvVoqDrxmxxVc0uCLzfwOkvnN0JWbSaKJOvDjIPY9NCsGq7mlLVG2Mz4LsN OZUlMaiw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXUVv-0003jm-1Y; Tue, 27 Oct 2020 19:20:11 +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 47ECD307ABA; Tue, 27 Oct 2020 20:20:09 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 352A7203C2679; Tue, 27 Oct 2020 20:20:09 +0100 (CET) Date: Tue, 27 Oct 2020 20:20:09 +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: <20201027192009.GQ2628@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> <20201027081932.GY2611@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 Tue, Oct 27, 2020 at 11:00:52AM -0700, Andy Lutomirski wrote: > On Tue, Oct 27, 2020 at 1:19 AM Peter Zijlstra wrote: > > > > 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) ? > > I assume you already figured this out, but my specific concern is with > the get_si_code(dr6) part -- that's sent directly to the task being > debugged or debugging itself (and, sadly, to ptrace, and who knows > what debuggers do). Right, so for a task doing TF on its own, DR_STEP should remain set in our on-stack dr6 variable, nothing should consume it. So the get_si_code(dr6) should be identical. So the only difference is if DR_STEP is visible in ptrace or not.