Re: [RFC][PATCH 0/4] x86/entry: disallow #DB more

Andy Lutomirski
2020-05-22T22:43:43Z

> On May 22, 2020, at 3:20 PM, Sean Christopherson <sean.j.christopherson@intel.com> wrote:
>
> ﻿On Fri, May 22, 2020 at 03:13:57PM -0700, Andy Lutomirski wrote:
>>> On Fri, May 22, 2020 at 1:49 PM Peter Zijlstra <peterz@infradead.org> 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? :) Even just reading first won't help enough because DR7
>> reads are likely to be VM exits. 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?
>
> Hmm, I believe hw_breakpoint_active() is what you're looking for, KVM uses
> it to avoid unnecessary restoration of host DR7 after VM-Exit.
>
> Amusingly, checking that in the NMI handler could give a false positive if
> an NMI occurs in guest as DR7 is cleared on exit and KVM invokes the NMI
> handler prior to restoring host DR7. I doubt that's common enough to care
> about though.

False positives are unavoidable: there’s no way we can set a percpu variable and set DR7 without risking an NMI in between.