Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp138826pxb; Tue, 2 Feb 2021 01:05:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7zV4ndZrjV4vn07z8l/VhUON9fl2KjVP/MZrfvHCE1Xy3NQYo+IWKQzDqcnwYrest0w7X X-Received: by 2002:a17:906:af6b:: with SMTP id os11mr9924289ejb.472.1612256706340; Tue, 02 Feb 2021 01:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612256706; cv=none; d=google.com; s=arc-20160816; b=S7dh0cy5ggcXOY5HW/zcVlTWtCloNmu5nTar1J0RnnIVTRSQ1h008puIAn3a/3TyTy Ls2unvYoMnDV9o9+6kh8oeXSuhO6WNoFebYwUOcL2nJ03e2M2QSzqc4edqLOCuXle7Xy VTqzRzqZ/HJbkGmwxrRtSrvhdsXeSBHMqGbQ/PFHeEAB6Ge82MXExAXvhLWBMRr56vJ2 GEwldi4pzgfkMBDeCMq8m4xWIcRBPbl6TwHsQXcuIZVhVj5tiBBklRxo1ilr0UWXQiNH 2vUNmgYc/OpmiNguHbnYpi/2KDMQ2C88njT4VvsPNm39DvVBkZww5i/wlmNVqWKC9Eg6 ZisA== 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:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=hY2AwgHpo0inaLp6hHXYWJHEaQalQgDJ4F60IanDaVQ=; b=RKXml20Vw778x7AtA9NcCg5hdZ3CHQVCd8ekXFUlqszy23EMVkjT/MzDTOQHBL5YYC nG9qUTDMCCAmZGw+OgQY4bOWJGV4zXzI7nKC8D8sLwPRIVd5v5x9cR6YZO/z2Yr4p7/v vcElruMTQqv5ZkmwoA7fAfxN7lS9MhbH0d/BXmRtZHjd59zOzob2nWrNJzJENWuPG2Nz ljSlPE/DXf04Ko49nR6m3xYj+yjsJpp8emBNbFYCKlRXfLYQoAENspYYBBhmRqTl+tLz qsKqyVmLFd2RcJlvMoBYWTGvQZMHwMDbaHITG36GXd2coPpE0j6P2g+FBRpMQcS5zF7A 28dA== 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 y10si12516514edm.261.2021.02.02.01.04.40; Tue, 02 Feb 2021 01:05:06 -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 S232864AbhBBJCX (ORCPT + 99 others); Tue, 2 Feb 2021 04:02:23 -0500 Received: from mga02.intel.com ([134.134.136.20]:41964 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232785AbhBBJCJ (ORCPT ); Tue, 2 Feb 2021 04:02:09 -0500 IronPort-SDR: Gi/0KOgBT81A6QeDqVeUtEJBx9f0U9WCjMOC2zcZAw361DxcykAuKmhE6bYNJZebrGN7FDXk1M mcJgmb66rTcw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="167929244" X-IronPort-AV: E=Sophos;i="5.79,394,1602572400"; d="scan'208";a="167929244" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2021 01:01:28 -0800 IronPort-SDR: wCCmJuRcMSIFP4GZGLCuJIrs4XqI/nOgmCW9eTjMfxBsemJmOcWzMtSnSV3NbeaCKltWZLiNNm QzRPiGISwfQA== X-IronPort-AV: E=Sophos;i="5.79,394,1602572400"; d="scan'208";a="479491938" Received: from chenyi-pc.sh.intel.com ([10.239.159.24]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2021 01:01:25 -0800 From: Chenyi Qiang To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Xiaoyao Li Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] KVM: X86: Add support for the emulation of DR6_BUS_LOCK bit Date: Tue, 2 Feb 2021 17:04:32 +0800 Message-Id: <20210202090433.13441-3-chenyi.qiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210202090433.13441-1-chenyi.qiang@intel.com> References: <20210202090433.13441-1-chenyi.qiang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bus lock debug exception introduces a new bit DR6_BUS_LOCK (bit 11 of DR6) to indicate that bus lock #DB exception is generated. The set/clear of DR6_BUS_LOCK is similar to the DR6_RTM. The processor clears DR6_BUS_LOCK when the exception is generated. For all other #DB, the processor sets this bit to 1. Software #DB handler should set this bit before returning to the interrupted task. In VMM, to avoid breaking the CPUs without bus lock #DB exception support, activate the DR6_BUS_LOCK conditionally in DR6_FIXED_1 bits. When intercepting the #DB exception caused by bus locks, bit 11 of the exit qualification is set to identify it. The VMM should emulate the exception by clearing the bit 11 of the guest DR6. Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li Signed-off-by: Chenyi Qiang --- arch/x86/include/asm/kvm_host.h | 5 +++-- arch/x86/kvm/x86.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 5b80f92a7fde..44d790cff6aa 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -196,11 +196,12 @@ enum x86_intercept_stage; #define KVM_NR_DB_REGS 4 +#define DR6_BUS_LOCK (1 << 11) #define DR6_BD (1 << 13) #define DR6_BS (1 << 14) #define DR6_BT (1 << 15) #define DR6_RTM (1 << 16) -#define DR6_FIXED_1 0xfffe0ff0 +#define DR6_FIXED_1 0xfffe07f0 /* * DR6_ACTIVE_LOW is actual the result of DR6_FIXED_1 | ACTIVE_LOW_BITS. * We can regard all the current FIXED_1 bits as active_low bits even @@ -209,7 +210,7 @@ enum x86_intercept_stage; * At the same time, it can be served as the init/reset value for DR6. */ #define DR6_ACTIVE_LOW 0xffff0ff0 -#define DR6_VOLATILE 0x0001e00f +#define DR6_VOLATILE 0x0001e80f #define DR7_BP_EN_MASK 0x000000ff #define DR7_GE (1 << 9) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1946e6710919..e149cb2c921c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1131,6 +1131,9 @@ static u64 kvm_dr6_fixed(struct kvm_vcpu *vcpu) if (!guest_cpuid_has(vcpu, X86_FEATURE_RTM)) fixed |= DR6_RTM; + + if (!guest_cpuid_has(vcpu, X86_FEATURE_BUS_LOCK_DETECT)) + fixed |= DR6_BUS_LOCK; return fixed; } -- 2.17.1