From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D73ECC07E9B for ; Fri, 9 Jul 2021 10:05:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE3CD60C40 for ; Fri, 9 Jul 2021 10:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbhGIKIW (ORCPT ); Fri, 9 Jul 2021 06:08:22 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:24795 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231958AbhGIKIV (ORCPT ); Fri, 9 Jul 2021 06:08:21 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0UfChuN8_1625825125; Received: from C02XQCBJJG5H.local(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0UfChuN8_1625825125) by smtp.aliyun-inc.com(127.0.0.1); Fri, 09 Jul 2021 18:05:26 +0800 Subject: Re: [PATCH] KVM: X86: Also reload the debug registers before kvm_x86->run() when the host is using them To: Paolo Bonzini , Lai Jiangshan , linux-kernel@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org References: <20210628172632.81029-1-jiangshanlai@gmail.com> <46e0aaf1-b7cd-288f-e4be-ac59aa04908f@redhat.com> <397a448e-ffa7-3bea-af86-e92fbb273a07@redhat.com> From: Lai Jiangshan Message-ID: Date: Fri, 9 Jul 2021 18:05:25 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <397a448e-ffa7-3bea-af86-e92fbb273a07@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/7/9 17:49, Paolo Bonzini wrote: > On 09/07/21 05:09, Lai Jiangshan wrote: >> I just noticed that emulation.c fails to emulate with DBn. >> Is there any problem around it? > > Just what you said, it's not easy and the needs are limited.  I implemented kvm_vcpu_check_breakpoint because I was > interested in using hardware breakpoints from gdb, even with unrestricted_guest=0 and invalid guest state, but that's it. > Hello Paolo I just remembered I once came across the patch, but I forgot it when I wrote the mail. It seems kvm_vcpu_check_breakpoint() handles only for code breakpoint and doesn't handle for data breakpoints. And no code handles DR7_GD bit when the emulation is not resulted from vm-exit. (for example, the non-first instruction when kvm emulates instructions back to back and the instruction accesses to DBn). Thanks Lai > Paolo > >> For code breakpoint, if the instruction didn't cause vm-exit, >> (for example, the 2nd instruction when kvm emulates instructions >> back to back) emulation.c fails to emulate with DBn. >> >> For code breakpoint, if the instruction just caused vm-exit. >> It is difficult to analyze this case due to the complex priorities >> between vectored events and fault-like vm-exit. >> Anyway, if it is an instruction that vm-exit has priority over #DB, >> emulation.c fails to emulate with DBn. >> >> For data breakpoint, a #DB must be delivered to guest or to VMM (when >> guest-debug) after the instruction. But emulation.c doesn't do so. >> >> And the existence of both of effective DBn (guest debug) and guest DBn >> complicates the problem when we try to emulate them.