Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3386247pxb; Mon, 16 Nov 2020 13:14:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJway0xGe5+3FSco7EGMTr38o9kLuQp9EGNKcsBh0yIebr5UwfpGJhXh/6/fPKK3dmpum+rw X-Received: by 2002:a17:906:5a8f:: with SMTP id l15mr16255160ejq.419.1605561252014; Mon, 16 Nov 2020 13:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605561252; cv=none; d=google.com; s=arc-20160816; b=HoSPpGI7KORuFVuRYId7RHG5ze33kMwAJSol6gEw+0jDCHDo6ap0bTPsTNEDmlxlVa j3fL1KNio3o8uso9iYjmFkvrdqH1oKqhh83WK4595sW2Y/v8IVTnAQdBTbU4UcJDlheZ K2VwYNlCYOUkCoaQvyE4NzYW9WZe5BdZIiEimY4MFqEWba7tdB6jBbN9ImmUC2xbiRIm Pj8Srk6cqFB7jpVncmHwyacFF+CXQtTQGSm96uc4sI6rVFqoqzVtgi7ImtAUUM7eLE4r TMRC8zdRIGKKKfGqVc8u3V0vnoHYNbYitcslxjsuRBqwRB5rYqyay7STickxf/ApazBx Tm/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=SjDkU1hFA1XGw4otkqzbiSBJy0tjjhZmU+I2RzCwK/k=; b=M7E/KUVphxxRLSz4pNHDQx/3MAu4XFDHfJbX64IW26vnmcZqw2iQI275nWS0gbzebq 31895eMhtDuV3ESoofHtmo6K4CdCukAuT/Tw/UfqJNyRCIcYeR3397xjaJnPtwin2Nwq U/rSJEU7R7cfW+CVVjYJv+fl/i28pWXYUwkHRjffy62YZ7xNGSQVCm8fWI1NVf4GLuzf baOMAWnA7apEV6bHtuSYJkpkRenzF9ZzoRYKXJAGiNy9RiNhXMvmLSAtP5Y3OkyxMWO7 EP7zE6xyFy7kLp8AlNounKEwcWhSaO29PHSMT1oW+H2+AdSvc6s55hicpWiAa3LVXbK+ WFPw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s17si11211658edt.578.2020.11.16.13.13.49; Mon, 16 Nov 2020 13:14:11 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388637AbgKPSbt (ORCPT + 99 others); Mon, 16 Nov 2020 13:31:49 -0500 Received: from mga06.intel.com ([134.134.136.31]:20636 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388104AbgKPS2H (ORCPT ); Mon, 16 Nov 2020 13:28:07 -0500 IronPort-SDR: LyT4YNPKVF3BeXDaQa1ur2noX03aG+tv/L+Ztl3hWzZriUvbcQ6vMhQZne43mxFACzDKxdjZOW LFbldh9G5SLA== X-IronPort-AV: E=McAfee;i="6000,8403,9807"; a="232410039" X-IronPort-AV: E=Sophos;i="5.77,483,1596524400"; d="scan'208";a="232410039" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2020 10:28:06 -0800 IronPort-SDR: ASwCFKCLy4OB4+gf56DduJlNArpGMnds+U8gtJMjxBGFNEsyjNPUrk1yfQiQe2DK7ACyGhmNp8 k1mX1KP5X9Iw== X-IronPort-AV: E=Sophos;i="5.77,483,1596524400"; d="scan'208";a="400528033" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2020 10:28:05 -0800 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH 29/67] KVM: x86: Add a switch_db_regs flag to handle TDX's auto-switched behavior Date: Mon, 16 Nov 2020 10:26:14 -0800 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add a flag, KVM_DEBUGREG_AUTO_SWITCHED, to skip saving/restoring DRs irrespective of any other flags. TDX-SEAM unconditionally saves and restores host DRs, ergo there is nothing to do. Opportunistically convert the KVM_DEBUGREG_* definitions to use BIT(). Reported-by: Xiaoyao Li Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 7 ++++--- arch/x86/kvm/x86.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a6c89666ec49..815469875445 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -464,9 +464,10 @@ struct kvm_pmu { struct kvm_pmu_ops; enum { - KVM_DEBUGREG_BP_ENABLED = 1, - KVM_DEBUGREG_WONT_EXIT = 2, - KVM_DEBUGREG_RELOAD = 4, + KVM_DEBUGREG_BP_ENABLED = BIT(0), + KVM_DEBUGREG_WONT_EXIT = BIT(1), + KVM_DEBUGREG_RELOAD = BIT(2), + KVM_DEBUGREG_AUTO_SWITCHED = BIT(3), }; struct kvm_mtrr_range { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 42bd24ba7fdd..098888edc3ad 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9009,7 +9009,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) if (test_thread_flag(TIF_NEED_FPU_LOAD)) switch_fpu_return(); - if (unlikely(vcpu->arch.switch_db_regs)) { + if (unlikely(vcpu->arch.switch_db_regs & ~KVM_DEBUGREG_AUTO_SWITCHED)) { set_debugreg(0, 7); set_debugreg(vcpu->arch.eff_db[0], 0); set_debugreg(vcpu->arch.eff_db[1], 1); @@ -9029,6 +9029,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) */ if (unlikely(vcpu->arch.switch_db_regs & KVM_DEBUGREG_WONT_EXIT)) { WARN_ON(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP); + WARN_ON(vcpu->arch.switch_db_regs & KVM_DEBUGREG_AUTO_SWITCHED); kvm_x86_ops.sync_dirty_debug_regs(vcpu); kvm_update_dr0123(vcpu); kvm_update_dr7(vcpu); @@ -9042,7 +9043,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) * care about the messed up debug address registers. But if * we have some of them active, restore the old state. */ - if (hw_breakpoint_active()) + if (hw_breakpoint_active() && + !(vcpu->arch.switch_db_regs & KVM_DEBUGREG_AUTO_SWITCHED)) hw_breakpoint_restore(); vcpu->arch.last_vmentry_cpu = vcpu->cpu; -- 2.17.1