Received: by 2002:a25:d80d:0:0:0:0:0 with SMTP id p13csp8183ybg; Sat, 23 May 2020 06:06:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhkZIV5oCjOygmGyVm59SRz9q935CDAk2vRQn3bTqGijMuZXzI9mMZTovkef1FjmBpCiwE X-Received: by 2002:a17:906:7fd7:: with SMTP id r23mr11633684ejs.386.1590239189044; Sat, 23 May 2020 06:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590239189; cv=none; d=google.com; s=arc-20160816; b=rS3xnPoa8TA0Itcj4mpkK0u/0IXlRLz54ODJa0I+Ayoap9qxMagGmaFBWH7FB/yr0/ VTOw+0fEXRMl48laowHZc7c9JMRaIn2qziPIxBfW6UvfzIZOjJ6bndurXqIrSsfMM45e 1IhZI2gLlaWgAmOpqkDf2bmxYvwsurBahwZqb266bJzyHH4WAmYQwqC6y/V+Xmpy5YEy ii6yK7AmVXo0B2z8TPzO95JmI1d5EuigunhGOkXmfCTolI6WSk5AwUVn8igLad0CqXQ2 W62ON5M4cDP5M3jXBoDpoBDRZU8UJUoOKMMuocxhlNsD0qSCZ+DyoYg5YH+isV3FmEWu 7NSQ== 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:dkim-signature; bh=i+W32p7Xn+loQfbQxblgigVhjgb2f2mo+rxQQ2WzG34=; b=MgGr3DTaAqkmVbcBjk/1f0AwRYQZQpWaHtpUJJnH7/IcO0lEcYfpgX/8himNOWpvJe AXgKQ0f5mfmFIcSSxXija06Q3RtRd73pCtSKJiySTflATzYH5vBGDtp11qOLGtQiPLtV /ljuQn6iN3tA7fTyJVKNT4BF11oUMnWXZ5HbBGOWW289q9/789GFYlCI3E5Ed/HmKrgU C0VqTlwKCS+f2TfdeZ9RVt6LRWgWp13Z+BIozmfeQSabSRjHfrq8oHq7UQsYOwCypvDm qOkpfksF5Et46MAkAsOoIWsHwJ3rJSBQJYcyatALvpr/GQbsUp5r/tnzZCxe84Rt2g8O bVgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=AKceh5o6; 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 w15si6101668edr.151.2020.05.23.06.06.05; Sat, 23 May 2020 06:06:29 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=AKceh5o6; 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 S1731291AbgEWNCO (ORCPT + 99 others); Sat, 23 May 2020 09:02:14 -0400 Received: from merlin.infradead.org ([205.233.59.134]:54174 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731227AbgEWNCO (ORCPT ); Sat, 23 May 2020 09:02:14 -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=i+W32p7Xn+loQfbQxblgigVhjgb2f2mo+rxQQ2WzG34=; b=AKceh5o6OodesP30RZroLDIYPC 7PLxJoMMc4SZOFO5rwEM7MtkO1ousap93Qimv2T3EHonJEkuBkyq6hjgyixdHqEcGKlFCScddYuMP i4AP7dtvSiQPtuy3SLuF3jf9+q2MCVaqNclWf+JbXzLdq6ZvVHAkhZyMBj4zZ2qeqTLMxSENnjoDl mvVSMJ0r+nLZCWaQZLfqw2ZkMnuaXPXlPbdilgOxsIOlklCbhgB5STpwdhgAE1BIDwibSo62Z4M6D uuLdh8eGRh6SH8xcFZ9gIq2vRRvP/K4G7MQX8myA77cXHtR94l+pZ3ansJVr44RCElrwHo0898Lj0 7WfMcDoQ==; Received: from [24.132.217.100] (helo=worktop.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jcTkq-000089-VT; Sat, 23 May 2020 12:59:57 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id EBDEA9834A3; Sat, 23 May 2020 14:59:40 +0200 (CEST) Date: Sat, 23 May 2020 14:59:40 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Thomas Gleixner , LKML , X86 ML Subject: Re: [RFC][PATCH 0/4] x86/entry: disallow #DB more Message-ID: <20200523125940.GA2483@worktop.programming.kicks-ass.net> References: <20200522204738.645043059@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, May 22, 2020 at 03:13:57PM -0700, Andy Lutomirski wrote: > On Fri, May 22, 2020 at 1:49 PM Peter Zijlstra wrote: > > > > Hai, this kills #DB during NMI/#MC and with that allows removing all the nasty > > IST rewrite crud. > > > > This is great, except that the unconditional DR7 write is going to > seriously hurt perf performance. Fortunately, no one cares about > perf, right? :) Good point, so the trivial optimization is below. I couldn't find instruction latency numbers for DRn load/stores anywhere. I'm hoping loads are cheap. > Even just reading first won't help enough because DR7 > reads are likely to be VM exits. WTF, why is virt always such a horrible piece of crap? > Can we have a percpu dr7 shadow > (with careful ordering) or even just a percpu count of dr7 users so we > can skip this if there are no breakpoints? We have cpu_dr7, and some > minor changes would make this work. Maybe replace all the direct > cpu_dr7 access with helpers like dr7_set_bits() and dr7_clear_bits()? I'll try and sort through that on Monday or so. --- arch/x86/include/asm/debugreg.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/arch/x86/include/asm/debugreg.h +++ b/arch/x86/include/asm/debugreg.h @@ -97,7 +97,8 @@ extern void hw_breakpoint_restore(void); static __always_inline void local_db_save(unsigned long *dr7) { get_debugreg(*dr7, 7); - set_debugreg(0, 7); + if (*dr7) + set_debugreg(0, 7); /* * Ensure the compiler doesn't lower the above statements into * the critical section; disabling breakpoints late would not @@ -114,7 +115,8 @@ static __always_inline void local_db_res * not be good. */ barrier(); - set_debugreg(dr7, 7); + if (dr7) + set_debugreg(dr7, 7); } #ifdef CONFIG_CPU_SUP_AMD