From nobody Sun Feb 8 22:58:30 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 E25FD374F1 for ; Fri, 9 Feb 2024 22:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516480; cv=none; b=uz5RyuK9XquBZ75ykfR/hyOp+hf2nzFqJG/k7Ad62l+40xzoLrDUb24cASuzS7XWtFUFOcepXt35fxVdxJdHjbIsjYsrv6BZw5r1n4tlNlByJsczna6HTVEERZungBXmtQdx1zOaTNX37vLLokMpjPfKWOjS+rAQPeJzJMilGOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516480; c=relaxed/simple; bh=G8yYb549bHS0dm420NgpCxsXl+WFxhziVrxJ57VN10A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eoCW/FZvy0GdxNycAbzI066bSNwHPpBfNW3kFyFQMRZixKhzI01pwMT25shXHj/nmzz7xoVcVN/hC7v1CplgrAywXkQYaJEHSOo8hHaySDyyCgWNTSbrmfSvgmn1iT3szJ595TqElULEuMjKAsLXz4aivkhYYXWuwStm3cg5WGk= 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=i7wj8mpT; arc=none smtp.client-ip=209.85.219.201 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="i7wj8mpT" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc3645a6790so2659196276.0 for ; Fri, 09 Feb 2024 14:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707516478; x=1708121278; 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=CiNmwT6G4ZjT0uaWThby9fO5R8PDoaUWp6GHwG0vlXE=; b=i7wj8mpT2zu8prxr0fg8qTWPuPGzcSLsfevxIA4G/j/GW1uT+DgC7iDbKEJRsJDUWg Ze3zk3Smrhr2K4gI8a+GJcqWFYWhirb2JRM3StOeI/WhXRcEuYGlEuknN6YJFHcQAGx1 0MKHYuA+RuBlXRQev3GiCgaZKPownxAt199ZKw62NmBAZ7iLTYdEuo/MRHfBtycreJQy bJUJskw22D7APpQQb82n1UyGN2NPUFMP026cf+yu9mgM2qio7qQEhVkgq1AovB8Rwqc/ kAxMCbfCZvWemxJPp+5Yk3TF4+OlYfKKn1jGP3Ndj3aBB7c4mL8VJqJ7iHU9LEGGGQju tzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707516478; x=1708121278; 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=CiNmwT6G4ZjT0uaWThby9fO5R8PDoaUWp6GHwG0vlXE=; b=jDko3zWCnkOX9HBqNJ0mDHiaRgu2FzOwDtio2w+oFdJ2HRDnm33zsrkz+yrakbbL4H jVaLm/OCp7HsYDCAYtXUaTata0MZ9eBfGyQGEGKFWZiIbQELoN2b+QgLny7XmFpyiDID SLhuFsYnM79iVQNoO5mvsPXW7X/dQ/PSBabSRs7Gw5qj02yHwUnMdQhOzp2Ai7NL4nsT cPgIgIqo6jq1/LH1SSh9WNSzI9I/acHwm4h1JweRWQpMFy7v/OJoQamWLC5ZSj4MFsVv ML011ml1LXdmljeK60+/RqI/dThob4wNal+SXAX8cg4Ea+d1isO9tzwHAmyEDvMQzERg ldFw== X-Gm-Message-State: AOJu0Ywxnf2ZZyo/iPDkBjJi0Um8l/GxiySlYU0GWYvARP6e1EKA11od /puxeWVaYXVna/ytGnLE6iKo2Ojzm11uwfFesJYaWEuwNx3yhXIDJR27jO8Yjpq83V8qOYHnPvC yMg== X-Google-Smtp-Source: AGHT+IHtfM9LTc4d2GpYZt5fisFL8uhOLCh2hC0auqTcKJbjQu/fK8j5e8AkLzG6VyiPL+ddqdUewMn6buY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:18d2:b0:dc6:d233:ffdd with SMTP id ck18-20020a05690218d200b00dc6d233ffddmr112509ybb.0.1707516477995; Fri, 09 Feb 2024 14:07:57 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:07:52 -0800 In-Reply-To: <20240209220752.388160-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240209220752.388160-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209220752.388160-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: x86: Open code all direct reads to guest DR6 and DR7 From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mathias Krause Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Bite the bullet, and open code all direct reads of DR6 and DR7. KVM currently has a mix of open coded accesses and calls to kvm_get_dr(), which is confusing and ugly because there's no rhyme or reason as to why any particular chunk of code uses kvm_get_dr(). The obvious alternative is to force all accesses through kvm_get_dr(), but it's not at all clear that doing so would be a net positive, e.g. even if KVM ends up wanting/needing to force all reads through a common helper, e.g. to play caching games, the cost of reverting this change is likely lower than the ongoing cost of maintaining weird, arbitrary code. No functional change intended. Cc: Mathias Krause Signed-off-by: Sean Christopherson Reviewed-by: Mathias Krause --- arch/x86/kvm/smm.c | 8 ++++---- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/x86.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c index 19a7a0a31953..d06d43d8d2aa 100644 --- a/arch/x86/kvm/smm.c +++ b/arch/x86/kvm/smm.c @@ -194,8 +194,8 @@ static void enter_smm_save_state_32(struct kvm_vcpu *vc= pu, for (i =3D 0; i < 8; i++) smram->gprs[i] =3D kvm_register_read_raw(vcpu, i); =20 - smram->dr6 =3D (u32)kvm_get_dr(vcpu, 6); - smram->dr7 =3D (u32)kvm_get_dr(vcpu, 7); + smram->dr6 =3D (u32)vcpu->arch.dr6; + smram->dr7 =3D (u32)vcpu->arch.dr7; =20 enter_smm_save_seg_32(vcpu, &smram->tr, &smram->tr_sel, VCPU_SREG_TR); enter_smm_save_seg_32(vcpu, &smram->ldtr, &smram->ldtr_sel, VCPU_SREG_LDT= R); @@ -236,8 +236,8 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vc= pu, smram->rip =3D kvm_rip_read(vcpu); smram->rflags =3D kvm_get_rflags(vcpu); =20 - smram->dr6 =3D kvm_get_dr(vcpu, 6); - smram->dr7 =3D kvm_get_dr(vcpu, 7); + smram->dr6 =3D vcpu->arch.dr6; + smram->dr7 =3D vcpu->arch.dr7; =20 smram->cr0 =3D kvm_read_cr0(vcpu); smram->cr3 =3D kvm_read_cr3(vcpu); diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 28d1088a1770..d05ddf751491 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4433,7 +4433,7 @@ static void sync_vmcs02_to_vmcs12(struct kvm_vcpu *vc= pu, struct vmcs12 *vmcs12) (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE); =20 if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_DEBUG_CONTROLS) - vmcs12->guest_dr7 =3D kvm_get_dr(vcpu, 7); + vmcs12->guest_dr7 =3D vcpu->arch.dr7; =20 if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_EFER) vmcs12->guest_ia32_efer =3D vcpu->arch.efer; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bfffc13f91e6..5a08d895bde6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5510,7 +5510,7 @@ static void kvm_vcpu_ioctl_x86_get_debugregs(struct k= vm_vcpu *vcpu, for (i =3D 0; i < ARRAY_SIZE(vcpu->arch.db); i++) dbgregs->db[i] =3D vcpu->arch.db[i]; =20 - dbgregs->dr6 =3D kvm_get_dr(vcpu, 6); + dbgregs->dr6 =3D vcpu->arch.dr6; dbgregs->dr7 =3D vcpu->arch.dr7; } =20 --=20 2.43.0.687.g38aa6559b0-goog