Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1213826rdb; Fri, 9 Feb 2024 14:08:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdE1GiIyGs1CewVD922tlYHgaxjG3G5Vp5EdewDota41WSWyoULc308+Ay4kVCGJJQWJGB X-Received: by 2002:a05:620a:461f:b0:785:74f5:62c6 with SMTP id br31-20020a05620a461f00b0078574f562c6mr538833qkb.75.1707516524047; Fri, 09 Feb 2024 14:08:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707516524; cv=pass; d=google.com; s=arc-20160816; b=tJyUQ58R7l7kdS6TErg216/HTTqmXoRz2kJxV+0vc6B9G26m4kJqoiVJFmLFxRVmNp gzAXPeTW43dNjydlDgLzCsYvOiMgZO2oeqfPQ0b9dzJzwbWDx+HoHegAxS8EF2Zfi0s3 VQEUTovJ6Mb8VHAS0iHimIXiVisyT71tMcsIjkINh/3rRYXlslXps+Rz69gq0eqTLvPn TVtcRdabxgblQaGJm/OZwmfbh7wiaVGeUB76WaxbCxUMPpUkGZ9AlYf0yHnMlDMxLKgd wHWDcyx2GozS1GDdKsiHWATOGhL58+Gop+VtUSod+h64Yo6Md3X38Ifl4iOx2H+/2hH0 Sw/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=CiNmwT6G4ZjT0uaWThby9fO5R8PDoaUWp6GHwG0vlXE=; fh=UT7gdRa4PTy6Rfk6QWEntNB46qX13CAzD6qtx+Y5Spk=; b=QYgYTsRLdppNX4vKkEKQ5JaTVQZSbDTKl9i3/LgRlGcZoEXCtpwBIpzMvTaRJ8WMqd aBkrj3PBXuJFQ34KIM9F29/HlGN4id3BlkrLN8Ij+brkkScr8MDpDC8f/dtPStC8uWIK 9k2C/Xb9Ey6JoC4zDrPCS2HphXfLHhRn/kGgyUUZaa94VGClgqjaVJ0X+iWBxaLJw4v7 OIzqlVR5iUKp9IHG90lybDB5UOtXZW7xtMFJniNNpoqC9+Hq/w9t6keyE40bLtHTLNbH 3HrEpj7syo7BoaN3mE4eThtAy87fuIsneHJre5MHsyCi7Q/quX0q8uBSQdv00+aBxzDp fqkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=i7wj8mpT; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWd98blkmIlwUf9x6DKs6HzOVihKdlflUtFYZ+kGNfRqj3QZ7GH1p5/bPinvjUaQlLPu+325F2crTpaqdopse7XOt3GDXECSsw8gq9fbA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a14-20020a05620a066e00b00785be48c25fsi396760qkh.217.2024.02.09.14.08.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:08:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=i7wj8mpT; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C9CCF1C20FF9 for ; Fri, 9 Feb 2024 22:08:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C1C6364C0; Fri, 9 Feb 2024 22:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i7wj8mpT" 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 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-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-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 --- 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 *vcpu, for (i = 0; i < 8; i++) smram->gprs[i] = kvm_register_read_raw(vcpu, i); - smram->dr6 = (u32)kvm_get_dr(vcpu, 6); - smram->dr7 = (u32)kvm_get_dr(vcpu, 7); + smram->dr6 = (u32)vcpu->arch.dr6; + smram->dr7 = (u32)vcpu->arch.dr7; 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_LDTR); @@ -236,8 +236,8 @@ static void enter_smm_save_state_64(struct kvm_vcpu *vcpu, smram->rip = kvm_rip_read(vcpu); smram->rflags = kvm_get_rflags(vcpu); - smram->dr6 = kvm_get_dr(vcpu, 6); - smram->dr7 = kvm_get_dr(vcpu, 7); + smram->dr6 = vcpu->arch.dr6; + smram->dr7 = vcpu->arch.dr7; smram->cr0 = kvm_read_cr0(vcpu); smram->cr3 = 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 *vcpu, struct vmcs12 *vmcs12) (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE); if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_DEBUG_CONTROLS) - vmcs12->guest_dr7 = kvm_get_dr(vcpu, 7); + vmcs12->guest_dr7 = vcpu->arch.dr7; if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_EFER) vmcs12->guest_ia32_efer = 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 kvm_vcpu *vcpu, for (i = 0; i < ARRAY_SIZE(vcpu->arch.db); i++) dbgregs->db[i] = vcpu->arch.db[i]; - dbgregs->dr6 = kvm_get_dr(vcpu, 6); + dbgregs->dr6 = vcpu->arch.dr6; dbgregs->dr7 = vcpu->arch.dr7; } -- 2.43.0.687.g38aa6559b0-goog