Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1224058rdb; Fri, 9 Feb 2024 14:33:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKDtdSp2bvDLPGzBmigbUJDLtGcXj2luiGH8UVcHw5hyxd+tim9OBHl7mfUXwJjwxO1+2h X-Received: by 2002:a17:906:e4f:b0:a3b:fccb:2207 with SMTP id q15-20020a1709060e4f00b00a3bfccb2207mr245833eji.41.1707517987194; Fri, 09 Feb 2024 14:33:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707517987; cv=pass; d=google.com; s=arc-20160816; b=rMbm6meCujEaq3IxuqAtiD/1zzorO9LFMA51YWO/ALNK1ijnYX+iI4BmY3QgOcS/OF ffel4swj7OaaQbgmmgpS9iA5QRg/0HeverXQFOZpS6Yv5EEctGiDgTz6uAyJB3ABb7LY 8IGfUToxGgOK2YyGn026FKPpxJ85MI1MLYlSGcwo3bJCaym0clJxYuaZPOdbPU6GJ2xi uEASEnpFjc+pfnl3pJRySib3LIsiPBcjNwZw8JkRMD8geTrxA6Yg53Ce7FwMEi5dz1Lg wCIXjOW2u2zS9UlQiuDNRICo3J5ktHxB4iwDvWikHtQFWR5jZ6J4Hj4Wk4h/gMljXKB5 NtJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=Q334rdbHohWsxJ77bsjyPgsTUJYym92p9x/mltaYtVg=; fh=SL2K5L3ZZ4fkemfwN/fHqI4m2YUU2ga4Axwf4dPiJYw=; b=bMGrfQwwmtiC/yErhljbNTT4PrcNEEpYRoK9mF2nkpq9BTjUXSTN7zvMYH0XN7UV5y E95btEIomiRIq6XFU+QX61JpGuRtGCfvGs+IsxrE+Khk0wNeH/PVDeliVZcuEZpL90i1 RxS0wyFCJyJltVAAzJMJ83hg4veZ2UzJ9sD87gfmXKwzghMj/hb4qjB8FYvPyltyJm7u Crw2nGohSUfQqp3m6hySIOcqoWDe6X3gJwy8DVo7l+5PTFhSrOL4KHUarbFL5AOXWjgw WTk8JPMG41kYB6VAmfkq9v9FEEHsMEb8dYwuzVXyM7MqKIWwbxHB7xMhA19IYBLC5KUB hu+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@grsecurity.net header.s=grsec header.b=G4brQ5d7; arc=pass (i=1 spf=pass spfdomain=opensrcsec.com dkim=pass dkdomain=grsecurity.net dmarc=pass fromdomain=grsecurity.net); spf=pass (google.com: domain of linux-kernel+bounces-60112-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60112-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=grsecurity.net X-Forwarded-Encrypted: i=2; AJvYcCV0WaA599BcthUyTKISDApMaOZXCUZzhJ1ykLVRi9scsNdsEfk1Knb7iP/znIKFGjwqjvEfuuveWBi2xHPjV7g9kIbDHH/mtMb89L/xEA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gt39-20020a1709072da700b00a3c06597bb6si680759ejc.14.2024.02.09.14.33.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60112-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@grsecurity.net header.s=grsec header.b=G4brQ5d7; arc=pass (i=1 spf=pass spfdomain=opensrcsec.com dkim=pass dkdomain=grsecurity.net dmarc=pass fromdomain=grsecurity.net); spf=pass (google.com: domain of linux-kernel+bounces-60112-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60112-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=grsecurity.net 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 am.mirrors.kernel.org (Postfix) with ESMTPS id BA6031F22368 for ; Fri, 9 Feb 2024 22:33:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 777913D0B8; Fri, 9 Feb 2024 22:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b="G4brQ5d7" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 7EF1D3D0C2 for ; Fri, 9 Feb 2024 22:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517829; cv=none; b=PySq9lEW8TNtZWMpv/bpMiYsGXed18ZvBbjTC6Odbso7PQLirvK+hIQKHmS+0F5Mm/HHIqvoa9ZZT0bokqJJORjx6GP8vSk05I95lmiX6DUQkzv1IZqASqVyS3Aeh3c2I7MGzGF4EUhFWXOeyM9URatQwUzRculGICeAQpjIZnE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517829; c=relaxed/simple; bh=Fy+DFfgl9iPfXE4Cc00lQVCWdaZmYtdMTKbSdOK6dr8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ldz1wgwWD0iIwoZCkT1GL1YZPjGaoP4E+sQf7Wj3ByA6T9ap6fKIA+dQNXEljiF+siZAC8MX44M7T7RtsKPK8M54hXvsmaHBYZgVKUR4FhpcYb8AoRfAJNNuNvscKEerc0JRv8+lMJ0TQzFfiozx+EMyr30sr3dcNSM4s6JHfVk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net; spf=pass smtp.mailfrom=opensrcsec.com; dkim=pass (2048-bit key) header.d=grsecurity.net header.i=@grsecurity.net header.b=G4brQ5d7; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=grsecurity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensrcsec.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a3832ef7726so177548966b.0 for ; Fri, 09 Feb 2024 14:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1707517826; x=1708122626; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Q334rdbHohWsxJ77bsjyPgsTUJYym92p9x/mltaYtVg=; b=G4brQ5d77cF1vSB81B3cApym8KcnqmQTkHY/ti4R52o80rTHXJQxFOOSSGsqhZDbM1 /2LP7bUzmrcwhYRIbvrVzKBVrb185RMshNCy3M/Ymx1ON0rFl0ocZ1kRHvipokwFHO8T SxjSKYt6+XVx2uhhra6pCHDzBUfxKoN+vrDKyKqsPNdTLgGlEX0+AD09Mfayq3geGSR5 6HZZLU5Luq7DLRxkLoZc1m1OSfi6DFYc5bnp6Vhwb+ZItd+r6OKdbuz5mPlX40Q02Qfd UYoXgxeWPIsUE3D7UMN9C8hi+hNQ0tNSmrJvItcKMsrPpy5uMkZLH68yaK4FDJnkN08D 9bKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517826; x=1708122626; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q334rdbHohWsxJ77bsjyPgsTUJYym92p9x/mltaYtVg=; b=JqvgpqKZXDu2rq5/wKPp29AmqDVvcTvNmvWwkwv+tjo9KsReToZdOD+hROoNt2/J+0 rkObOYWva5UwO0BPfaCe6P9JSUKxTunGGLcknS+089IdvLXprxQOaVF3gsUfLR6YzYya QgdHTMsr9h4ZPvwEazTD/jAXvT2yoQWfo3qH5VzT+MImWeShdCp6ptd0OkuiOiWzB1wS ynaqmx6pp+ZX8hWQ54hI+pxPB495eFkZXcz1FnICbDuWQ2wf6AOamkU2KFHAI6a+kYva 2XB4BdKOqh37uGqa137PGzCLEiuZ/ADlH9X+PpzqxjJP7v5HvSGfJAqoo7G/yMEYv8lY Q3BQ== X-Gm-Message-State: AOJu0YzsloEyhcg9WyNFTDADGpHCFSrs+lDQTWjd8D9EsPOFNmcvQq0Q pcioqwQBlrn/xMQmNcp9Vyld38FeDByRN24ngYHkeuDprJcCtenfeXHg4105wxY= X-Received: by 2002:a17:906:68d8:b0:a38:96ef:4199 with SMTP id y24-20020a17090668d800b00a3896ef4199mr221824ejr.75.1707517825779; Fri, 09 Feb 2024 14:30:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXmhADPjPQXFV6Z5GdiurBvyAgwNK0C3N9z8jawo/KNCwaAZNMD4Omlh3uuSxofmTcAOMTOPM/REeziKhZeuvQx6sG8n5NWEigzjfAgdeIRQv74hkcJtGgZQWWHikAQz3QF Received: from ?IPV6:2003:f6:af2c:a500:6e26:87f:cb2:6335? (p200300f6af2ca5006e26087f0cb26335.dip0.t-ipconnect.de. [2003:f6:af2c:a500:6e26:87f:cb2:6335]) by smtp.gmail.com with ESMTPSA id go43-20020a1709070dab00b00a385535a02asm1171411ejc.171.2024.02.09.14.30.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 14:30:25 -0800 (PST) Message-ID: <19824d6d-28f9-4aa0-8b10-bacefc49adfd@grsecurity.net> Date: Fri, 9 Feb 2024 23:30:26 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] KVM: x86: Open code all direct reads to guest DR6 and DR7 Content-Language: en-US, de-DE To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240209220752.388160-1-seanjc@google.com> <20240209220752.388160-3-seanjc@google.com> From: Mathias Krause Autocrypt: addr=minipli@grsecurity.net; keydata= xsDNBF4u6F8BDAC1kCIyATzlCiDBMrbHoxLywJSUJT9pTbH9MIQIUW8K1m2Ney7a0MTKWQXp 64/YTQNzekOmta1eZFQ3jqv+iSzfPR/xrDrOKSPrw710nVLC8WL993DrCfG9tm4z3faBPHjp zfXBIOuVxObXqhFGvH12vUAAgbPvCp9wwynS1QD6RNUNjnnAxh3SNMxLJbMofyyq5bWK/FVX 897HLrg9bs12d9b48DkzAQYxcRUNfL9VZlKq1fRbMY9jAhXTV6lcgKxGEJAVqXqOxN8DgZdU aj7sMH8GKf3zqYLDvndTDgqqmQe/RF/hAYO+pg7yY1UXpXRlVWcWP7swp8OnfwcJ+PiuNc7E gyK2QEY3z5luqFfyQ7308bsawvQcFjiwg+0aPgWawJ422WG8bILV5ylC8y6xqYUeSKv/KTM1 4zq2vq3Wow63Cd/qyWo6S4IVaEdfdGKVkUFn6FihJD/GxnDJkYJThwBYJpFAqJLj7FtDEiFz LXAkv0VBedKwHeBaOAVH6QEAEQEAAc0nTWF0aGlhcyBLcmF1c2UgPG1pbmlwbGlAZ3JzZWN1 cml0eS5uZ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KkNH7oQYXAQyZh42WJo6UFesaRAPc3KCOCFAsDXz19cc9l6uvHnSo/OAazf/RKtTE 0xGB6mQN34UAEQEAAcLA9gQYAQoAIAIbDBYhBHeyd+fQfcCoBrAfeCeIT8WGARmGBQJeORkW AAoJECeIT8WGARmGXtgL/jM4NXaPxaIptPG6XnVWxhAocjk4GyoUx14nhqxHmFi84DmHUpMz 8P0AEACQ8eJb3MwfkGIiauoBLGMX2NroXcBQTi8gwT/4u4Gsmtv6P27Isn0hrY7hu7AfgvnK owfBV796EQo4i26ZgfSPng6w7hzCR+6V2ypdzdW8xXZlvA1D+gLHr1VGFA/ZCXvVcN1lQvIo S9yXo17bgy+/Xxi2YZGXf9AZ9C+g/EvPgmKrUPuKi7ATNqloBaN7S2UBJH6nhv618bsPgPqR SV11brVF8s5yMiG67WsogYl/gC2XCj5qDVjQhs1uGgSc9LLVdiKHaTMuft5gSR9hS5sMb/cL zz3lozuC5nsm1nIbY62mR25Kikx7N6uL7TAZQWazURzVRe1xq2MqcF+18JTDdjzn53PEbg7L VeNDGqQ5lJk+rATW2VAy8zasP2/aqCPmSjlCogC6vgCot9mj+lmMkRUxspxCHDEms13K41tH RzDVkdgPJkL/NFTKZHo5foFXNi89kA== In-Reply-To: <20240209220752.388160-3-seanjc@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 09.02.24 23:07, Sean Christopherson wrote: > 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; > } > Reviewed-by: Mathias Krause Nice cleanup. Thanks a lot, Sean!