From patchwork Thu Feb 27 01:13:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13993396 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D7CB54764 for ; Thu, 27 Feb 2025 01:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618810; cv=none; b=V892ULX6Of6YhVhvEL0omPuW3tT/wNv8k+AqfG64gsrn9OQS9Bdw9cljeKQ6YdgKCVI7K147wF4XUNbtOX5zhy30h40arick1fFcEReKJZdWQLkSrXkBXp34mDNrHoknFLv13NJw5akkWWCTaCR/MfEFvvOzc+fmsylB7yaSaDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618810; c=relaxed/simple; bh=zm2QaR360KIl6iSEbDz2zLo3X3lN7lh4lpL7RxCk81I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l3dg2rM7PJJUmQTPlVLagxsW0m8SmDzxEmoUNm7s3jNgdnw8JAK8xoHWSnPmy6Pxk54z0Q0DpmJVEb2KxzWYVsACNGy0qsXfU0qgu72mvjkmDHth2ia6pAAA5MtbyTQJ3OUOhRGLE6wOmlb0qb/yWKyMXLIMFXIaDTn7YILVrsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wRd89/ii; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wRd89/ii" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2fc518f0564so972993a91.2 for ; Wed, 26 Feb 2025 17:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618808; x=1741223608; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date :message-id:reply-to; bh=0b+q4LTl32D7RG/ClIETiGyEI98jipo9UuVZ1dxYatM=; b=wRd89/iii27OqFapIVMolJmD9T0c5Dy3zTnftS1MoFzmPRE4KydgURruYpBG5PNHJN t+uYDGWKxesHEg81ljVNJwFdWnPleG43Sj70vFtKr5mON2aLmTuQvWhi0b7kq4buOoL4 qkI9tdHUdfp12IJj+1dZnK8zT9nXb5KE3RM9FYpYi97LeencG+HLQdzq+yK+BdbHYtEy V6fZNMyZE1J/MspMkON4upRIpBONxjQQ3JUQaLqJmgWGGO6R1oU3u3nkDOZALQoUszS9 tqY9VzFrolqSnH6jVxWbqynJy+OjsHA4DqNpvrQZ0QgZzfVthdpIQgrKGi2l24zOA2ci i11g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618808; x=1741223608; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=0b+q4LTl32D7RG/ClIETiGyEI98jipo9UuVZ1dxYatM=; b=H/j00qMoMh7h0Q4ADC0OQlzgxCxC6UQYHAryrAL3f9gu91/RQRcL0mTcO5xtSgwvDN ITC2/BZS8KGDb7uroxOXvRCuOGOGnOLnEMSnD1Jfof8cq2BI8ctKAqXcGd508CUJxkjD OFY7SF6pV5KpR75K0l8MlYYIO584ULnMNot9mXpHcHQT2fwHEwV9VVcH83breZ/e5/MH OjrjnyjFTS8w/vdcbFuhnsxrzTewC8GZp1Hv1F0Gka84al3+2DVsfodXj54Y1qbKg2DX FaNpy2cG4HOvbWVRPqv6Pv9eVbXloHl3h6AMYNkkFcMd8V/Yu3PxJfAPpXgtnlXFcdX2 dQAA== X-Gm-Message-State: AOJu0YyLdgMZQoQhCrVkIjAfZ7Dq4A8mHnk6vM212ApmAeNOwDosawzJ F6HgW+IsjTX5rk59KfGh03rQjugMB8G96j+BcJuSgRX37wpVkC3WdVD2jVr4TES0Ru5nIr3PwFe SKA== X-Google-Smtp-Source: AGHT+IH4j2hz+QG3bfdUby9AHcMKdde1f0mz0Lh4hjfInlOzv66k2GVgHs1NibxtzgfdBTAmj0DWWrBKdCc= X-Received: from pgzz124.prod.google.com ([2002:a63:3382:0:b0:801:d5e9:804f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3287:b0:1ee:d06c:cddc with SMTP id adf61e73a8af0-1f0fc78fb84mr17684149637.30.1740618808506; Wed, 26 Feb 2025 17:13:28 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:13:17 -0800 In-Reply-To: <20250227011321.3229622-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227011321.3229622-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227011321.3229622-2-seanjc@google.com> Subject: [PATCH v2 1/5] KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Xiaoyao Li , rangemachine@gmail.com, whanos@sergal.fun Drop bits 5:2 from the guest's effective DEBUGCTL value, as AMD changed the architectural behavior of the bits and broke backwards compatibility. On CPUs without BusLockTrap (or at least, in APMs from before ~2023), bits 5:2 controlled the behavior of external pins: Performance-Monitoring/Breakpoint Pin-Control (PBi)—Bits 5:2, read/write. Software uses thesebits to control the type of information reported by the four external performance-monitoring/breakpoint pins on the processor. When a PBi bit is cleared to 0, the corresponding external pin (BPi) reports performance-monitor information. When a PBi bit is set to 1, the corresponding external pin (BPi) reports breakpoint information. With the introduction of BusLockTrap, presumably to be compatible with Intel CPUs, AMD redefined bit 2 to be BLCKDB: Bus Lock #DB Trap (BLCKDB)—Bit 2, read/write. Software sets this bit to enable generation of a #DB trap following successful execution of a bus lock when CPL is > 0. and redefined bits 5:3 (and bit 6) as "6:3 Reserved MBZ". Ideally, KVM would treat bits 5:2 as reserved. Defer that change to a feature cleanup to avoid breaking existing guest in LTS kernels. For now, drop the bits to retain backwards compatibility (of a sort). Note, dropping bits 5:2 is still a guest-visible change, e.g. if the guest is enabling LBRs *and* the legacy PBi bits, then the state of the PBi bits is visible to the guest, whereas now the guest will always see '0'. Reported-by: Ravi Bangoria Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 12 ++++++++++++ arch/x86/kvm/svm/svm.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index b8aa0f36850f..2280bd1d0863 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3165,6 +3165,18 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) kvm_pr_unimpl_wrmsr(vcpu, ecx, data); break; } + + /* + * AMD changed the architectural behavior of bits 5:2. On CPUs + * without BusLockTrap, bits 5:2 control "external pins", but + * on CPUs that support BusLockDetect, bit 2 enables BusLockTrap + * and bits 5:3 are reserved-to-zero. Sadly, old KVM allowed + * the guest to set bits 5:2 despite not actually virtualizing + * Performance-Monitoring/Breakpoint external pins. Drop bits + * 5:2 for backwards compatibility. + */ + data &= ~GENMASK(5, 2); + if (data & DEBUGCTL_RESERVED_BITS) return 1; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 5b159f017055..f573548b7b41 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -582,7 +582,7 @@ static inline bool is_vnmi_enabled(struct vcpu_svm *svm) /* svm.c */ #define MSR_INVALID 0xffffffffU -#define DEBUGCTL_RESERVED_BITS (~(0x3fULL)) +#define DEBUGCTL_RESERVED_BITS (~(DEBUGCTLMSR_BTF | DEBUGCTLMSR_LBR)) extern bool dump_invalid_vmcb; From patchwork Thu Feb 27 01:13:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13993397 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0938484D34 for ; Thu, 27 Feb 2025 01:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618812; cv=none; b=YAwuf0vodhbdwEUeInbTxViObVspJC93MByzEqLfSOvpECZ9JT01nAzAGpg/ZvIJe6uhJmghQEGihZUhK/9HVRrCp8QDYkKsc24FuLLOvK3P9NC+Cgx7s3tgnOQ54OaBIXyHHrM1uDHj4yMCfpSi4eUj4dKRkNoVLqB2cZVv5Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618812; c=relaxed/simple; bh=pUJzhfVuP8YDCZyv6pEaIsEIbkiixYOoWJyO/nE7JWM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Iy7VcZX9ndGkN9mcv3V4C1troPSr4FP4pgEJ5dQyfK+BvmGAOa/+h3XxLUh0ZuDOtt6T8zWWtFGYJ0U6xHPNk0bhvsEm2vjQDHHaEw09aZ/lVUGnaViQAJ+TaRwdDpHvs0e8TBXBvdYlh77h/QMHqLL0fYFr4eepAg3lAtETWHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P9+TXgZi; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P9+TXgZi" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fe8c5dbdb0so939782a91.3 for ; Wed, 26 Feb 2025 17:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618810; x=1741223610; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=+yfVH+oFZLBrscDapM9GBCwxFCs059IFc9U134nCSeM=; b=P9+TXgZi1sFwGrOiH/dORnFGIlTY+X5YO/fpt208HM2yW+OGi9hL7Th8rgH1Dps+DU +K2Lg1jZjQyWgDnnVAL6bJP18d92noYJavyDot2jBICtZbgC9forZR4Z2Nr6P+4UqBQ3 RU8p50wtcgmpgsQbV1WUW8jOZcBffmIyfokkVDl0ZJgkB14C/1gnfqThPON9cBm5naH3 Io8Y7AF2gxd0IezHjqQ1GZpr63qnARHEiuq0HrKig8rnEItgWGdorboA1AM4pps0QXgT dYRKnvH4XalhSJyJt6olkxi6B0FC+r/3LKOW5A+qfEbErTUBgBHVV/uNoejrmHx7UVIN qQhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618810; x=1741223610; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+yfVH+oFZLBrscDapM9GBCwxFCs059IFc9U134nCSeM=; b=UHqzp+oo2CI/tt2p9L4v4MhVuAbfqVD40BoIR3vPTBpwvLxTduLPCChNVWh+awZCgM H2cmhDdVP6XX6lanRaSNruiqfvHP/Mq2fSHrJu4WQer9rTtWl9U0eemoyJL+eWQqc1ks d54tSrzBbkvOgwSnY7R2a1fsLcg8jTM4NI5O9NknnOLn61MHeXwdClO33nEtZyAjfxFV sEAZwtEHUVH4TXHvtEPkm7KGN1P/nN3is/baQAD9C8Y0qW/x4CHv3MeeKxqpiG3d1iZU ybeEflzQSmhLSg5BU0DselI/YcWINqavjX3vaaAH/Yc0sZ1DCG5Lx5y0DGZTNm+7qh4n Lb4g== X-Gm-Message-State: AOJu0Yy9TMynPrNZxnqEL+LXtYM9MhWJBeSZbGGDFUysZKHODgCcTnPr Zoc0e0vBzDRb4suZMMxWoJ3CU9Ysa5KBsBalhXQuxSJDHarr5YXLJxjIFB8wahJ6YAxROZPNAX+ Y3A== X-Google-Smtp-Source: AGHT+IFS1eRlzm3hq046PPD2WG2HjjXP83OKFYPo9hMvfvu9vxphjIku4C28xVyGJKIdNWVM8z7mqhFV90Q= X-Received: from pgbbk13.prod.google.com ([2002:a05:6a02:28d:b0:add:b2fa:214d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:33a5:b0:1ee:d17a:d632 with SMTP id adf61e73a8af0-1f10acd89d8mr9599012637.9.1740618810345; Wed, 26 Feb 2025 17:13:30 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:13:18 -0800 In-Reply-To: <20250227011321.3229622-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227011321.3229622-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227011321.3229622-3-seanjc@google.com> Subject: [PATCH v2 2/5] KVM: x86: Snapshot the host's DEBUGCTL in common x86 From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Xiaoyao Li , rangemachine@gmail.com, whanos@sergal.fun Move KVM's snapshot of DEBUGCTL to kvm_vcpu_arch and take the snapshot in common x86, so that SVM can also use the snapshot. Opportunistically change the field to a u64. While bits 63:32 are reserved on AMD, not mentioned at all in Intel's SDM, and managed as an "unsigned long" by the kernel, DEBUGCTL is an MSR and therefore a 64-bit value. Reviewed-by: Xiaoyao Li Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 8 ++------ arch/x86/kvm/vmx/vmx.h | 2 -- arch/x86/kvm/x86.c | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 3506f497741b..02bffe6b54c8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -781,6 +781,7 @@ struct kvm_vcpu_arch { u32 pkru; u32 hflags; u64 efer; + u64 host_debugctl; u64 apic_base; struct kvm_lapic *apic; /* kernel irqchip context */ bool load_eoi_exitmap_pending; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b71392989609..729c224b72dd 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1514,16 +1514,12 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu, */ void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { - struct vcpu_vmx *vmx = to_vmx(vcpu); - if (vcpu->scheduled_out && !kvm_pause_in_guest(vcpu->kvm)) shrink_ple_window(vcpu); vmx_vcpu_load_vmcs(vcpu, cpu, NULL); vmx_vcpu_pi_load(vcpu, cpu); - - vmx->host_debugctlmsr = get_debugctlmsr(); } void vmx_vcpu_put(struct kvm_vcpu *vcpu) @@ -7458,8 +7454,8 @@ fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit) } /* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */ - if (vmx->host_debugctlmsr) - update_debugctlmsr(vmx->host_debugctlmsr); + if (vcpu->arch.host_debugctl) + update_debugctlmsr(vcpu->arch.host_debugctl); #ifndef CONFIG_X86_64 /* diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 8b111ce1087c..951e44dc9d0e 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -340,8 +340,6 @@ struct vcpu_vmx { /* apic deadline value in host tsc */ u64 hv_deadline_tsc; - unsigned long host_debugctlmsr; - /* * Only bits masked by msr_ia32_feature_control_valid_bits can be set in * msr_ia32_feature_control. FEAT_CTL_LOCKED is always included diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 58b82d6fd77c..09c3d27cc01a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4991,6 +4991,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) /* Save host pkru register if supported */ vcpu->arch.host_pkru = read_pkru(); + vcpu->arch.host_debugctl = get_debugctlmsr(); /* Apply any externally detected TSC adjustments (due to suspend) */ if (unlikely(vcpu->arch.tsc_offset_adjustment)) { From patchwork Thu Feb 27 01:13:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13993398 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B2B013DBA0 for ; Thu, 27 Feb 2025 01:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618814; cv=none; b=qwv78+TzjCmF+3sI1qfL0klYWKG2Ns9BiAKN4Fnyu8GuGqkcwUEPYrs6jFSWevB+POESIA9vGcPcxpYHGcamwQKnGrRRcW+Czq5Gfv/CnjqatInjJ9zk24glaHyya9XQqxh2bQBNeb6ytk2Cp0o8KHscqhi0t1K030gGBTi1//Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618814; c=relaxed/simple; bh=2H0CR+H3pcVCHgYY2mSN7jD4ZAwKWrOUyMZK1n/NR30=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tO92GqoIp+XxPe47ymHHYZUHxobBTYvkZ2gWmjTcJOE8AIYhPYy8gxFWbQ7bZdX0zMnFBIZUzDZlXMlup05ZwHQt5OOgzr9FjZP1ztXb0tbtRuRCTeOorcQt7ioV3yoCriktFioJOXBAhF8aSANRlG1lwkiGVfzZ3eS+fYWKHCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rkBqQnb3; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rkBqQnb3" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fc1eadf5a8so865338a91.3 for ; Wed, 26 Feb 2025 17:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618812; x=1741223612; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=U4QTUkGjoxdHKZ3Aw96WsHi8pQ/OYPAaRSw+vwAV2pA=; b=rkBqQnb3aD7fQ/DcA8AcgMB9TYkOXHgJ4NMchaqiFKggZx6DscBkWUBpT99ccuZy4b BP1mWtkJSH6e9P4HsPnpqW7wqVcuSwB42MMB3B+L+a9TuRsvOvWAOzwthhecRQD1S8sk muxzxupCrM3ZTltIAA+iNvKkAnLDAHNCa+fs0Ldd+Lts5HwwP791fMLErpKwrS3U7xZF jB7bjAETnrk33obqJIuOvXRnqbmRuFmeTfMJzrkG6U77Dp/ld7iSzqPTu3H90J+AQwnc Q+GgEM7T1T0KF8L61xsE5sNMATn7nZIRJ+IfBt0qptYA0Rk6aLdnUHZZLh5Ykqvm1Vsl yl7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618812; x=1741223612; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U4QTUkGjoxdHKZ3Aw96WsHi8pQ/OYPAaRSw+vwAV2pA=; b=WkZSLMC/afRExEqA9x0+kmvcXqHB4cSFYsUli7CwZGJoA8DzL0pv9Dh1DKSHH99vdg GfcxxzA1y5CJaEtXOTMe6MYLqSiKsJOOoxfeZDSTx/YMO87TjF6M8UwV/elNRP26COBG D2CTbaJBYDMIPJu5A9axf4/JM+1JPjv9SvVINbuvoXCFzcmHxUHqB+aTmzoSXIkFN16+ qwDdoU3ibLnT+02nH/AoXQbZ2EWJVj7NebohW2avaLBfGnphAFbuldD2BSmcTFGmF0ic q6+RmPhy4hSaGyP83bwNU3YMqzoc6vCzgaWX+JiVzi8HL0cpVyrwRSIIV/u7Nx4Kpkru IGiQ== X-Gm-Message-State: AOJu0YzJLeLOuSlbXHbFGMsHkQoKJ9HTf3RLZLxEN8GU+e3FTq5EixRU x7pXiqk4tCnF3b1NxRNbP6BmZMaCQ19+Z4he1kfnAsuLM5PYMjNJ7b7FPXUz6Cz24y570KOy8++ hqg== X-Google-Smtp-Source: AGHT+IEbf/Xd9EiLaKii1/R3daJnFR38nVtwLJP6WsLc/Li9JipSYGiZgwqvYoonvp4o+UkYpf7+iM9YoFA= X-Received: from pjz12.prod.google.com ([2002:a17:90b:56cc:b0:2f4:465d:5c61]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7286:b0:1f0:e8a3:719 with SMTP id adf61e73a8af0-1f10ae8de07mr8836586637.30.1740618811970; Wed, 26 Feb 2025 17:13:31 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:13:19 -0800 In-Reply-To: <20250227011321.3229622-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227011321.3229622-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227011321.3229622-4-seanjc@google.com> Subject: [PATCH v2 3/5] KVM: SVM: Manually context switch DEBUGCTL if LBR virtualization is disabled From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Xiaoyao Li , rangemachine@gmail.com, whanos@sergal.fun Manually load the guest's DEBUGCTL prior to VMRUN (and restore the host's value on #VMEXIT) if it diverges from the host's value and LBR virtualization is disabled, as hardware only context switches DEBUGCTL if LBR virtualization is fully enabled. Running the guest with the host's value has likely been mildly problematic for quite some time, e.g. it will result in undesirable behavior if BTF diverges. But the bug became fatal with the introduction of Bus Lock Trap ("Detect" in kernel paralance) support for AMD (commit 408eb7417a92 ("x86/bus_lock: Add support for AMD")), as a bus lock in the guest will trigger an unexpected #DB. Note, suppressing the bus lock #DB, i.e. simply resuming the guest without injecting a #DB, is not an option. It wouldn't address the general issue with DEBUGCTL, e.g. for things like BTF, and there are other guest-visible side effects if BusLockTrap is left enabled. If BusLockTrap is disabled, then DR6.BLD is reserved-to-1; any attempts to clear it by software are ignored. But if BusLockTrap is enabled, software can clear DR6.BLD: Software enables bus lock trap by setting DebugCtl MSR[BLCKDB] (bit 2) to 1. When bus lock trap is enabled, ... The processor indicates that this #DB was caused by a bus lock by clearing DR6[BLD] (bit 11). DR6[11] previously had been defined to be always 1. and clearing DR6.BLD is "sticky" in that it's not set (i.e. lowered) by other #DBs: All other #DB exceptions leave DR6[BLD] unmodified E.g. leaving BusLockTrap enable can confuse a legacy guest that writes '0' to reset DR6. Reported-by: rangemachine@gmail.com Reported-by: whanos@sergal.fun Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219787 Closes: https://lore.kernel.org/all/bug-219787-28872@https.bugzilla.kernel.org%2F Cc: Ravi Bangoria Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 2280bd1d0863..3924b9b198f4 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4265,6 +4265,16 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, clgi(); kvm_load_guest_xsave_state(vcpu); + /* + * Hardware only context switches DEBUGCTL if LBR virtualization is + * enabled. Manually load DEBUGCTL if necessary (and restore it after + * VM-Exit), as running with the host's DEBUGCTL can negatively affect + * guest state and can even be fatal, e.g. due to Bus Lock Detect. + */ + if (!(svm->vmcb->control.virt_ext & LBR_CTL_ENABLE_MASK) && + vcpu->arch.host_debugctl != svm->vmcb->save.dbgctl) + update_debugctlmsr(0); + kvm_wait_lapic_expire(vcpu); /* @@ -4292,6 +4302,10 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI)) kvm_before_interrupt(vcpu, KVM_HANDLING_NMI); + if (!(svm->vmcb->control.virt_ext & LBR_CTL_ENABLE_MASK) && + vcpu->arch.host_debugctl != svm->vmcb->save.dbgctl) + update_debugctlmsr(vcpu->arch.host_debugctl); + kvm_load_host_xsave_state(vcpu); stgi(); From patchwork Thu Feb 27 01:13:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13993399 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC57E1494D9 for ; Thu, 27 Feb 2025 01:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618815; cv=none; b=A0+ODoKe3slnz4/RX4aqQb1zyDjTC3E3WPPbJQAq5ETj9TNp+0BhOJX4Pik/up7TGkCXIT5c2+Fpm7IIZGnF9uIpXUXcrympeAxSDZdCiKaHjY9jzldWd606vS0CHolv0EzlUrEhvwiGPkJWYZrAQmMLWFRrN7kbPhsIfnkKa2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618815; c=relaxed/simple; bh=uaIIITJgUawWH54PuijoRuV64Rx6tfBFy6BV8graBMw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aHNOHlAhOGlxLSZ8RW+eAoucUjP23/elDD1Mukwqyum4UibvFkAE1Fhd54EBkkloAN2PuUdedSAaV2JvMkJyF/6JWkohDmn39dsWzbJSJ7sxndJEPs4pJvg9rFJGjA9LJ83jqEEBN0XNfqyxUTP3tLsqiPpbIp8gdyuQ/wpVk30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BhA9oCje; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BhA9oCje" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2fe8c697ec3so1794925a91.1 for ; Wed, 26 Feb 2025 17:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618813; x=1741223613; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=4G+4qHSVJnaTG8aqakqnf5oS6XZxipCyWxhYCrPdMqU=; b=BhA9oCjehr15kGno0LTWWgc4p7eaPwWB3ylKyIhJDsPOoSSo+zFz+AK/6AZyNeXRSr Pvg74JXDg0cn3tvXX735xyTlfWjdwe7UvTYmoXPuf7TokuwufxBJWYmw5M3OJpJdNyEi qdtsE0yIaY55kKiJeQvv67xopm8b8bUpRyQM0nA5vAqD2uTsFYJMHz0Ov5ddi+YV8Ain KGphSBeyL7WEvWFE/1rFUhsCKQQwFz9H5rs50jooEh92bZsw7nz8C4tf31U5Xj7cP1Hi 6f12bz4MsVgGethfBv2hMQkd/YW6Z5OzIi0rvto4jGsR3gVb2EJKwngdRqes3SLd09X4 hC2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618813; x=1741223613; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4G+4qHSVJnaTG8aqakqnf5oS6XZxipCyWxhYCrPdMqU=; b=VsSCiKsQVnelas6gxxhKNOdbFEwur7VaYve+TwxcEhZXko9liKJYTMqQzu2hm2ak9w BmuEmUUsOwmEq+1VVsGkrmyD2NKgkRI43/B7wxKgkvvuo/akWLUHqntPOZQwxmhccEp5 nfpQbdehIacsWilJ5A5ECXpyhLTst/34r31vO/g+HrylmJLZLvPgMQC3phPZUKxZIq0/ dyh4oRPBZE5VficbP/sQ1pwl+Fw2Znu4u83b0niN0QRvlFfFe9D0JNdGYYnN5p/7dhaU HijJKaCXOoIYjlOndpjxe7UKl0hmbdkfoYXjiIwoh1PFhGs/RtrNjpNPKeXAF58uN5/O PgiA== X-Gm-Message-State: AOJu0YxXtNQpxZ8uc97c8aeNe6LEQbsQZVoHiLXR6S1ugU2qgFTSKTsD 0uGSF2hFN2gx88bL8KGoPzu+CzvXSV+QFzxVLnjgD/l621JPABD/JR+WhEGhoY7aPVnFSYOp0CQ DuA== X-Google-Smtp-Source: AGHT+IF/0LojBvPM/mubJWQkN9zSmVziqMW9oNei9YATA6U+yuMtYGUbUTWyWB3moXPOEe6/3bNIOyIL5jQ= X-Received: from pgbdq17.prod.google.com ([2002:a05:6a02:f91:b0:ad5:418b:c301]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:8402:b0:1ee:b5f4:b1d7 with SMTP id adf61e73a8af0-1f2e387ef46mr2042905637.7.1740618813467; Wed, 26 Feb 2025 17:13:33 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:13:20 -0800 In-Reply-To: <20250227011321.3229622-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227011321.3229622-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227011321.3229622-5-seanjc@google.com> Subject: [PATCH v2 4/5] KVM: x86: Snapshot the host's DEBUGCTL after disabling IRQs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Xiaoyao Li , rangemachine@gmail.com, whanos@sergal.fun Snapshot the host's DEBUGCTL after disabling IRQs, as perf can toggle debugctl bits from IRQ context, e.g. when enabling/disabling events via smp_call_function_single(). Taking the snapshot (long) before IRQs are disabled could result in KVM effectively clobbering DEBUGCTL due to using a stale snapshot. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 09c3d27cc01a..a2cd734beef5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4991,7 +4991,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) /* Save host pkru register if supported */ vcpu->arch.host_pkru = read_pkru(); - vcpu->arch.host_debugctl = get_debugctlmsr(); /* Apply any externally detected TSC adjustments (due to suspend) */ if (unlikely(vcpu->arch.tsc_offset_adjustment)) { @@ -10984,6 +10983,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) set_debugreg(0, 7); } + vcpu->arch.host_debugctl = get_debugctlmsr(); + guest_timing_enter_irqoff(); for (;;) { From patchwork Thu Feb 27 01:13:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13993400 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4C69155A4D for ; Thu, 27 Feb 2025 01:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618817; cv=none; b=mB7YxVOT+Ekt/G00416X/mnb1ZCAPydpMOAkXmJjl3e8rHvWAqbn7/eWX7PBETpcLxXFhq+TdKQrmQM8WJTsj+PUQcUjwzFBo2WYg+PbcUYcuEgfTmER9eaYae6jQ6otlQIgPJrSfYgGalzvIxVU1cj2O+JCufbu33MdbHKFuss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740618817; c=relaxed/simple; bh=yu8TyCy5IstIMoYy9ePpidWG2ruXcYEZUf6VlP2oCYw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ma6AgKynlr4uLQiX6v/bWPftZOc2I9Rk0o0UBoVsruUjtSUAlYCnqhSkcVYNDicjpsuPEdu3Mwf45oCMLJJ6z+ZiRMHOGTTq0/2XN/etLpH1abAR7jv52oWLDYrSEFrcGAt/UJRCXuB2Xy9GszJrwqVOlidetbQCcMS9kf3KbEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4TX8+M5Q; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4TX8+M5Q" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2fe86c01e2bso921374a91.2 for ; Wed, 26 Feb 2025 17:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740618815; x=1741223615; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qmb3CzVJbBaqSWe8exsC1ZsMXmS+Kv6YmMHciuGnSnM=; b=4TX8+M5Q2qdpx05UcqzrpHMy/GCCBxOa2ARRRQlbLLsYcDjA1KPP3r1DLNRtZdzYT0 gOvcdk9foygKhwP6N0CKc34GUMjts+durzLeVC7R2t/0aECsHBej++xqEUxDKdhKGtEu wZySBq4dRCp1OyDcC1i5bHr6tP7WRwgqYO7PJTLjKnNA08/ztuEX7gHEo5tHUyRYj6td 5a7XrHlpVRbLJVPrW9XviqV7RCN5FUcsME51yQKx0OaAMyPTdwDHyxULmmtMRTHSWCl+ JdLohSj0QtNejR1rA4fn4f87b5TToUWVWpVL9Xams7Pg2qF0UQFriU9HQ2QvpsGZwVGS nurw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740618815; x=1741223615; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qmb3CzVJbBaqSWe8exsC1ZsMXmS+Kv6YmMHciuGnSnM=; b=iOfjUHFeBnZOq4rv8gTaCZPFjZ8nIVbxxCGXv4n1Isnr8auy/LcLbSPrZvHHZBjyeE KGiK39TeuEOmC4ne8L2EcboDrtvl/GRSg6ZFERwdA6sQ20LXW8QVCBYSUMvi5ScfDMI1 R/M7Uzpra2ECbj/1MAF6HF6Oexp7plQxqZTYKWclqMxR3N+rhgjK54v3mZ+SKid/GouL Kd65Y6qU8UjZ/hkplGQjVjynnftFRUWBk7Fv94yVDpj9lhRpqXO+xswan3nqL5wEiAET vT2pgkbuOz193J1opCdoLSXJ2G9C5AFa22/StE679nei4FgzlZbLsZeV9a+j8X68Xp+c m3fA== X-Gm-Message-State: AOJu0YxJzhBGnLJPFAdEur9LF8NIvcP3h3I9ZfXD674aEldGdRhE7Q0R zujdWgKjEZOk35G8SMbfryrRDYfmhjn8ZbDgsyr6VZG/nAll4uOPB29/ZHw63qRZ1CriHDUKEMH r+Q== X-Google-Smtp-Source: AGHT+IHbWmibGgYDxG0pPNvCP7ncWv5pWbcPv0vknPBvkXfOX2PBqWehwjnJxrxNDIGlFBQGAA28ThhFG8Q= X-Received: from pjuw13.prod.google.com ([2002:a17:90a:d60d:b0:2f9:dc36:b11]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5148:b0:2ee:c9b6:4c42 with SMTP id 98e67ed59e1d1-2fce86cf0ebmr41513310a91.16.1740618815327; Wed, 26 Feb 2025 17:13:35 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 26 Feb 2025 17:13:21 -0800 In-Reply-To: <20250227011321.3229622-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250227011321.3229622-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.711.g2feabab25a-goog Message-ID: <20250227011321.3229622-6-seanjc@google.com> Subject: [PATCH v2 5/5] KVM: SVM: Treat DEBUGCTL[5:2] as reserved From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Xiaoyao Li , rangemachine@gmail.com, whanos@sergal.fun Stop ignoring DEBUGCTL[5:2] on AMD CPUs and instead treat them as reserved. KVM has never properly virtualized AMD's legacy PBi bits, but did allow the guest (and host userspace) to set the bits. To avoid breaking guests when running on CPUs with BusLockTrap, which redefined bit 2 to BLCKDB and made bits 5:3 reserved, a previous KVM change ignored bits 5:3, e.g. so that legacy guest software wouldn't inadvertently enable BusLockTrap or hit a VMRUN failure due to setting reserved. To allow for virtualizing BusLockTrap and whatever future features may use bits 5:3, treat bits 5:2 as reserved (and hope that doing so doesn't break any existing guests). Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3924b9b198f4..7fc99c30d2cc 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3166,17 +3166,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) break; } - /* - * AMD changed the architectural behavior of bits 5:2. On CPUs - * without BusLockTrap, bits 5:2 control "external pins", but - * on CPUs that support BusLockDetect, bit 2 enables BusLockTrap - * and bits 5:3 are reserved-to-zero. Sadly, old KVM allowed - * the guest to set bits 5:2 despite not actually virtualizing - * Performance-Monitoring/Breakpoint external pins. Drop bits - * 5:2 for backwards compatibility. - */ - data &= ~GENMASK(5, 2); - if (data & DEBUGCTL_RESERVED_BITS) return 1;