Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp138688pxb; Tue, 2 Feb 2021 01:04:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDW6FVp7atj6Rw6cgy4TyJOmidAuKMTUY07pEK0nL1y4dVFShmMhOvh51d3vxlm1cWX+F9 X-Received: by 2002:a05:6402:4389:: with SMTP id o9mr22719343edc.164.1612256692854; Tue, 02 Feb 2021 01:04:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612256692; cv=none; d=google.com; s=arc-20160816; b=Sey2X6I0M0aKjieL36XJc0PvRIoE0VQP5gJr6EcqTCfhjvrc7/jtd67Z7R5ss+V2YI whQHU8BPro9/fn9JYyx3Da/s2N6YNGFkEiYY1/qKW6XyNx2GqMCceFM7dECqLdMxdgfg xN+V/4Xbbf6hzE7dntsHRfbnlpKM6mU3hGEvvtPbMrxYF79L8QNOdwSMQB+tU8HB/M/R 8Jt+5b7Ab4YMHygkIpDtAVhdJxTdApx8OV1QsDW9/huPImKgu2m0B7gYn6BAAmTJWVkW ZJ9WO+RzgTXTzkurnS6M7BKT8Ab3fJEvPoCumvVxd3Y0GEkQYJWRLpBoyXCJ5Hq/5Stg UnQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=47Pj2JeZEoCXHOBntPd1q0BDPMr3VzbI5++ys4MV8e4=; b=ZcNL8y9EAbQSWJwUdasjT8XsyF057aGSYObhlU6WEDYvWgZXrspCZlmSraNf+LLlVA hVrE8kXVAqGJjfNTXsIFK73qbNKS3z469OPq62MpAS4vm68i6p0gWh0WLNPOgEuLqdbd AHrMRr2LhsudOkKaaD4r8BTb5EVIJRDbl1jbtseMhmS7vWJ98vRE3Lhp3AP+QqMz3al2 pU2kiS2Oj1cLyoQeUbZ7pURzok6fIqbY1OvCjGRnKBzsi+379Exfj8pK6KRfDRjOZx0L oQ9pmaZ9ybLnDaQGS2f9gWri3lbsGVnWUGxUSdjN/A78A6W6ZbRliD/SojS1wNtCWq3z O4Pg== 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 y18si1788673eds.570.2021.02.02.01.04.28; Tue, 02 Feb 2021 01:04:52 -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 S232842AbhBBJCU (ORCPT + 99 others); Tue, 2 Feb 2021 04:02:20 -0500 Received: from mga02.intel.com ([134.134.136.20]:41952 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231860AbhBBJCG (ORCPT ); Tue, 2 Feb 2021 04:02:06 -0500 IronPort-SDR: XrMKU2HkKx9fiW3b+H1yepyU/f6S4zqM/oXovb0QfotGbQqPIk0nKyEpINDWtcnov1J7rPAf5C YgLi144x3qzw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="167929199" X-IronPort-AV: E=Sophos;i="5.79,394,1602572400"; d="scan'208";a="167929199" 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:22 -0800 IronPort-SDR: j3yg88fjdQC+eiSMyKy4p3zWzkI+sP40x0+NIYX0vo96ZYxg1B70EnzDxjKhf5KBBRDVDwY8lL k4TMvYAqMf3A== X-IronPort-AV: E=Sophos;i="5.79,394,1602572400"; d="scan'208";a="479491878" 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:20 -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 0/3] Add KVM support for bus lock debug exception Date: Tue, 2 Feb 2021 17:04:30 +0800 Message-Id: <20210202090433.13441-1-chenyi.qiang@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A bus lock is acquired either through split locked access to writeback (WB) memory or by using locks to uncacheable (UC) memory. This is typically > 1000 cycles slower than atomic opertaion within a cache line. It also disrupts performance on other cores. Bus lock debug exception is a sub-feature of bus lock detection. It is an ability to notify the kernel by an #DB trap after the instruction acquires a bus lock when CPL>0. This allows the kernel to enforce user application throttling or mitigatioins. Expose the bus lock debug exception to guest by the enumeration of CPUID.(EAX=7,ECX=0).ECX[24]. Software in guest can enable these exceptions by setting the DEBUGCTLMSR_BUS_LOCK_DETECT(bit 2) of MSR_IA32_DEBUTCTL. The bus lock #DB exception can also be intercepted by the VMM and identified through the bit 11 of the exit qualification at VM exit. The bit 11 (DR6_BUS_LOCK) of DR6 register is introduced to indicate a bus lock #DB exception. DR6_BUS_LOCK has formerly always been 1 and delivery of a bus lock #DB clears it. The VMM should emulate the exceptions by clearing the bit 11 of the guest DR6. Bus lock debug exception kernel patches are available at: https://lore.kernel.org/lkml/20201124205245.4164633-1-fenghua.yu@intel.com Document for Bus Lock Detection is now available at the latest "Intel Architecture Instruction Set Extensions Programming Reference". Document Link: https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html --- Changelogs v1->v2: - rename the DR6_INIT to DR6_LOW_ACTIVE suggested by Paolo and split it out as a new commit. - KVM v1:https://lore.kernel.org/lkml/20210108064924.1677-1-chenyi.qiang@intel.com Chenyi Qiang (3): KVM: X86: Rename DR6_INIT to DR6_ACTIVE_LOW KVM: X86: Add support for the emulation of DR6_BUS_LOCK bit KVM: X86: Expose bus lock debug exception to guest arch/x86/include/asm/kvm_host.h | 14 +++++++-- arch/x86/kvm/cpuid.c | 3 +- arch/x86/kvm/emulate.c | 2 +- arch/x86/kvm/svm/nested.c | 2 +- arch/x86/kvm/svm/svm.c | 6 ++-- arch/x86/kvm/vmx/nested.c | 4 +-- arch/x86/kvm/vmx/vmx.c | 27 ++++++++++++++--- arch/x86/kvm/x86.c | 52 +++++++++++++++------------------ arch/x86/kvm/x86.h | 2 ++ 9 files changed, 69 insertions(+), 43 deletions(-) -- 2.17.1