From patchwork Thu Nov 18 11:08:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 217E8C433F5 for ; Thu, 18 Nov 2021 11:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04F1161BCF for ; Thu, 18 Nov 2021 11:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343615AbhKRLLR (ORCPT ); Thu, 18 Nov 2021 06:11:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343599AbhKRLLM (ORCPT ); Thu, 18 Nov 2021 06:11:12 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C30C061570; Thu, 18 Nov 2021 03:08:12 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so7866108pjb.5; Thu, 18 Nov 2021 03:08:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yV6Z6mOtzVk7r22nV+6uVyIHOaPeyekpA0C9QvKiS1w=; b=Vmfud0yckSu8N7LCXLbuJ1zYsyucBf18JDQ/anQXqHXBnIV7ngxMekeB57U2FWCT6z ocDvxgC7iiExO4+4efUXVZ/wn+X0Fak+ZD4JpKom9o99OizaVISgbBnHOExkNmniB9Wd aSGJMh6EOpKH944Vb3t38bINmB4CeOPrZ7jI6DTfMiDNXHz4jUoB/sE5JAWgsYCrRRob Vgsk25jj1x46QwD3HXtwLiVbVuQDvJ072GoIg4J49K901ZRSXiRF2Rf8O6y5SIFxzXiv Iwbw8CJ//AHdi21dKIvYjj2kzYUFoDLHPKFCFj8ZxRvNqnTtZTWWN5mC/VfsVGuFiwt7 Q9qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yV6Z6mOtzVk7r22nV+6uVyIHOaPeyekpA0C9QvKiS1w=; b=trDUE/GgHYXsxWdYoWfUZJBgIXvi3umZenniw/VahjIjGZWzYb287WMUV7IugLGdSh WRdY18W5G7QWVMs4kFUDC/vx8w1qHRz3TVY1qREnuQ+Ph/cuVZidop7oUETos5Aph3GU dtOSfJRPV1+MqX+ocxbpKjSMm/SImrAI81IeQgSRSkFLkeuliSdYen29SOMraAUDaial 5GiHVycCV5JHJI8Ni44zINXNK50c1JTuDME410xWkIiROOdDFE0IOQYF9bmLWvb2YBnn 1reAIo/Jc/3Ecy1eA7EX1MVJ/rpPClBBH/3bDh1xQEMVIj6UnFstm6XcLDW5mKdecdSs Ufvw== X-Gm-Message-State: AOAM531wgE+qsbVX2TPuZHRy4RJR9uNrNdjkxQzp8p4sqS3yQ35s3Jqw QRQ+D+nXl0vcgWyi0KhL2qjUrt/VUVE= X-Google-Smtp-Source: ABdhPJyhfqNff/2QkthErbTw2UavCmg6E0aNJE9gEkuQVBZ0i94mjZ1z+yHoUPyRmHONuzxH19bcdw== X-Received: by 2002:a17:90a:9dca:: with SMTP id x10mr9487837pjv.170.1637233691773; Thu, 18 Nov 2021 03:08:11 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id y190sm2871691pfg.153.2021.11.18.03.08.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:11 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , x86@kernel.org, Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Kees Cook Subject: [PATCH 01/15] KVM: VMX: Use x86 core API to access to fs_base and inactive gs_base Date: Thu, 18 Nov 2021 19:08:00 +0800 Message-Id: <20211118110814.2568-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan And they use FSGSBASE instructions when enabled. Cc: x86@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/kvm_host.h | 10 ---------- arch/x86/kernel/process_64.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 14 +++++++------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 1fcb345bc107..4cbb402f5636 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1808,16 +1808,6 @@ static inline void kvm_load_ldt(u16 sel) asm("lldt %0" : : "rm"(sel)); } -#ifdef CONFIG_X86_64 -static inline unsigned long read_msr(unsigned long msr) -{ - u64 value; - - rdmsrl(msr, value); - return value; -} -#endif - static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code) { kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 3402edec236c..296bd5c2e38b 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -443,6 +443,7 @@ unsigned long x86_gsbase_read_cpu_inactive(void) return gsbase; } +EXPORT_SYMBOL_GPL(x86_gsbase_read_cpu_inactive); void x86_gsbase_write_cpu_inactive(unsigned long gsbase) { @@ -456,6 +457,7 @@ void x86_gsbase_write_cpu_inactive(unsigned long gsbase) wrmsrl(MSR_KERNEL_GS_BASE, gsbase); } } +EXPORT_SYMBOL_GPL(x86_gsbase_write_cpu_inactive); unsigned long x86_fsbase_read_task(struct task_struct *task) { diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 3127c66a1651..48a34d1a2989 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1156,11 +1156,11 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) } else { savesegment(fs, fs_sel); savesegment(gs, gs_sel); - fs_base = read_msr(MSR_FS_BASE); - vmx->msr_host_kernel_gs_base = read_msr(MSR_KERNEL_GS_BASE); + fs_base = x86_fsbase_read_cpu(); + vmx->msr_host_kernel_gs_base = x86_gsbase_read_cpu_inactive(); } - wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); + x86_gsbase_write_cpu_inactive(vmx->msr_guest_kernel_gs_base); #else savesegment(fs, fs_sel); savesegment(gs, gs_sel); @@ -1184,7 +1184,7 @@ static void vmx_prepare_switch_to_host(struct vcpu_vmx *vmx) ++vmx->vcpu.stat.host_state_reload; #ifdef CONFIG_X86_64 - rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); + vmx->msr_guest_kernel_gs_base = x86_gsbase_read_cpu_inactive(); #endif if (host_state->ldt_sel || (host_state->gs_sel & 7)) { kvm_load_ldt(host_state->ldt_sel); @@ -1204,7 +1204,7 @@ static void vmx_prepare_switch_to_host(struct vcpu_vmx *vmx) #endif invalidate_tss_limit(); #ifdef CONFIG_X86_64 - wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base); + x86_gsbase_write_cpu_inactive(vmx->msr_host_kernel_gs_base); #endif load_fixmap_gdt(raw_smp_processor_id()); vmx->guest_state_loaded = false; @@ -1216,7 +1216,7 @@ static u64 vmx_read_guest_kernel_gs_base(struct vcpu_vmx *vmx) { preempt_disable(); if (vmx->guest_state_loaded) - rdmsrl(MSR_KERNEL_GS_BASE, vmx->msr_guest_kernel_gs_base); + vmx->msr_guest_kernel_gs_base = x86_gsbase_read_cpu_inactive(); preempt_enable(); return vmx->msr_guest_kernel_gs_base; } @@ -1225,7 +1225,7 @@ static void vmx_write_guest_kernel_gs_base(struct vcpu_vmx *vmx, u64 data) { preempt_disable(); if (vmx->guest_state_loaded) - wrmsrl(MSR_KERNEL_GS_BASE, data); + x86_gsbase_write_cpu_inactive(data); preempt_enable(); vmx->msr_guest_kernel_gs_base = data; } From patchwork Thu Nov 18 11:08:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C8A5C433EF for ; Thu, 18 Nov 2021 11:08:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E97F261BCF for ; Thu, 18 Nov 2021 11:08:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343651AbhKRLLf (ORCPT ); Thu, 18 Nov 2021 06:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235730AbhKRLLR (ORCPT ); Thu, 18 Nov 2021 06:11:17 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D97C061767; Thu, 18 Nov 2021 03:08:18 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id u17so4927137plg.9; Thu, 18 Nov 2021 03:08:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iJYisT0ld7Chsu+T6PQppbIhzPNs7ZAW74mwSHZMRlU=; b=ZkAegnr+TE8L2A1TXLAmtpDoKg5Hj4vlATUKN/bFwRL/D3AN9XGwR8miHkZNq3tHgc xOAovwUa4vjtxJS3GgkTvsA0nRIN2qpkulMxM7hok1hbDChgIT/vmd6pEz2cohItvMmM jba9q0bVu09r9/cb7K9K1gJ9PgmuGbMpDm1VWb2CGH8dGUUfNlwwPiFGKYlbdEMpQWq5 QLOxsmfN5WWUCceqhAdLDW2lYUX5p3OX8W2d+N3PoiUqQ5avv3ailA31qaZDxJ4V+hcu DfMABCMLWkej0wEti2JS+VQ2DkDOTlsnTvmdkG3LFeJtIWboU+tI81HdfyuH6zPTdz5U DKkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iJYisT0ld7Chsu+T6PQppbIhzPNs7ZAW74mwSHZMRlU=; b=ciczWKqXJ4uz39Shc7OkO5+2EyRn9wu+ub+QHQpE6ZePdS1IHdOK1/JzC2fmtjxpzq 6xhsO9E8j6JnLMpDXuXjZ/JpbjqNuR205YUp38ro+xlv6wKWyRyzaUGsD3gb9nfEUsVR t4YMyEDA6GEMaPNqhc1uC9PfYCzzs13jF7dav3a7l1wNwNTZF83xCKkUhX3DDm++hgHT H8FBjkv8guPfxlC1ysv6tSKd8CfWTp0S5zNLzaRcB4UcBPapJjW4IzBaQWkVaVJx1lHF Zw3vgEyNc4gUWtOKgfUyyOUexfQ1nsm9JrL578BqUws7brdgzLDDordQwfVK7g78rE71 NW9g== X-Gm-Message-State: AOAM531iFTO4Qi8+A2F47jXs9ucTODUweuyhAZbhqiBZF9Gzvxa7IsMx fzdG95K2N3h0k9/pH5V+0/K2Z5dtXhs= X-Google-Smtp-Source: ABdhPJw7fXZRxSDyo2B3kKtdQsFm1FeAyBpoI5rb5SC7QfGA1PXqsNDz9ZV6o/Yz8qB7ajZpoXA1ow== X-Received: by 2002:a17:90b:3887:: with SMTP id mu7mr9550436pjb.89.1637233697464; Thu, 18 Nov 2021 03:08:17 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id nv12sm2641449pjb.49.2021.11.18.03.08.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:17 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 02/15] KVM: VMX: Avoid to rdmsrl(MSR_IA32_SYSENTER_ESP) Date: Thu, 18 Nov 2021 19:08:01 +0800 Message-Id: <20211118110814.2568-3-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The value of host MSR_IA32_SYSENTER_ESP is known to be constant for each CPU: (cpu_entry_stack(cpu) + 1) when 32 bit syscall is enabled or NULL is 32 bit syscall is not enabled. So rdmsrl() can be avoided for the first case and both rdmsrl() and vmcs_writel() can be avoided for the second case. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/vmx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 48a34d1a2989..4e4a33226edb 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1271,7 +1271,6 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu, if (!already_loaded) { void *gdt = get_current_gdt_ro(); - unsigned long sysenter_esp; /* * Flush all EPTP/VPID contexts, the new pCPU may have stale @@ -1287,8 +1286,11 @@ void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu, (unsigned long)&get_cpu_entry_area(cpu)->tss.x86_tss); vmcs_writel(HOST_GDTR_BASE, (unsigned long)gdt); /* 22.2.4 */ - rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp); - vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */ + if (IS_ENABLED(CONFIG_IA32_EMULATION) || IS_ENABLED(CONFIG_X86_32)) { + /* 22.2.3 */ + vmcs_writel(HOST_IA32_SYSENTER_ESP, + (unsigned long)(cpu_entry_stack(cpu) + 1)); + } vmx->loaded_vmcs->cpu = cpu; } @@ -4021,6 +4023,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx) rdmsr(MSR_IA32_SYSENTER_CS, low32, high32); vmcs_write32(HOST_IA32_SYSENTER_CS, low32); + rdmsrl(MSR_IA32_SYSENTER_ESP, tmpl); + vmcs_writel(HOST_IA32_SYSENTER_ESP, tmpl); rdmsrl(MSR_IA32_SYSENTER_EIP, tmpl); vmcs_writel(HOST_IA32_SYSENTER_EIP, tmpl); /* 22.2.3 */ From patchwork Thu Nov 18 11:08:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82B32C433EF for ; Thu, 18 Nov 2021 11:09:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6989F619EA for ; Thu, 18 Nov 2021 11:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343607AbhKRLMM (ORCPT ); Thu, 18 Nov 2021 06:12:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343627AbhKRLL1 (ORCPT ); Thu, 18 Nov 2021 06:11:27 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2AB5C061764; Thu, 18 Nov 2021 03:08:23 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id o4so5597969pfp.13; Thu, 18 Nov 2021 03:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6jKqwEPBzP3w6G3AtpS0thcI+j6oHMgihOAkR23jayk=; b=V2nP0rb1WssgEDmCO2HcTdJETovu8BUVVWmXX3ZhGGF5csCjMn88DPJi9a7TCDeejF YzLgFBWUKtjyGQJYTj2vdzsU2/r3d/DiSZuxZXFJf1QBakMAtUqMAY81G+T09hLDXK+j WFq2rKENP+/MX2A8xyuQPv+rwFNYhVMhMpOC3c1uzgSkb3LghQv2FFoDsw/cKXmU/3rr kyVOB5IwwlftMS5RkQjQCFNC4f6I416YnpFRPWyRe3zuTFQ773b2Oewa7sm42BH+Y7nR Pqk8AEr4PYG1L2EpY9dgrboohH59/qxUJPzRNxqhamp+QucVn8jp0Guudz0ELA/4KgLw fsqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6jKqwEPBzP3w6G3AtpS0thcI+j6oHMgihOAkR23jayk=; b=7kO7gi2jcTmI0/l3mLxtRVWH8uT476BidKHVVTMLoILdWLf2jKSkF5DGr5NyZCn0pB WK2cVPD3x9iGeconJwrsZDUUrQaksy4pE1pSXzvPDY0f6oKt7KCPOxGwHn+1xQVwNfDp nG5ONYC57pGVeD41cF0Gvvm9fwDZ5Xn2feJXTjSMU9jYs8EXaiXKfmKFE4lokTyq9wjm x/hWh2b+V8hBJrFxuXGuFwDvWoznKm8cUu2S+M+miV2MG3qX3RdQMK2cLRvZ2TBnHMAa YtvN5zpMj32rYDzFfnLBgTzxi4orX7FN/aTxL19YKU0Rum7QnYaEj4P5WNloUXlEOQdV EF1A== X-Gm-Message-State: AOAM5309YsmltNk8upv/5MB9mJnsZLB94LhixIqp5HMPahW7QoNkt1XC lpTXZapcXjXS25xqnn9HFroCPgD58qg= X-Google-Smtp-Source: ABdhPJxd8P155rYhd2AhTnmcS9rIRShVjdxGQ3nhpSvQ+XchOr6YfDZqtDimvkAAmU8bx6QAkCTVEA== X-Received: by 2002:a63:3ca:: with SMTP id 193mr10784594pgd.290.1637233703140; Thu, 18 Nov 2021 03:08:23 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id u22sm3135965pfk.148.2021.11.18.03.08.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:22 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 03/15] KVM: VMX: Update msr value after kvm_set_user_return_msr() succeeds Date: Thu, 18 Nov 2021 19:08:02 +0800 Message-Id: <20211118110814.2568-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan Aoid earlier modification. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/vmx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4e4a33226edb..fc7aa7f30ad5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -602,15 +602,13 @@ static int vmx_set_guest_uret_msr(struct vcpu_vmx *vmx, unsigned int slot = msr - vmx->guest_uret_msrs; int ret = 0; - u64 old_msr_data = msr->data; - msr->data = data; if (msr->load_into_hardware) { preempt_disable(); - ret = kvm_set_user_return_msr(slot, msr->data, msr->mask); + ret = kvm_set_user_return_msr(slot, data, msr->mask); preempt_enable(); - if (ret) - msr->data = old_msr_data; } + if (!ret) + msr->data = data; return ret; } From patchwork Thu Nov 18 11:08:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC526C433F5 for ; Thu, 18 Nov 2021 11:09:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A517061B73 for ; Thu, 18 Nov 2021 11:09:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343763AbhKRLMe (ORCPT ); Thu, 18 Nov 2021 06:12:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343635AbhKRLL3 (ORCPT ); Thu, 18 Nov 2021 06:11:29 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C193CC061766; Thu, 18 Nov 2021 03:08:29 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id p17so5040390pgj.2; Thu, 18 Nov 2021 03:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aaIPbPlZcX/+q0XyI84hSF4E3MWCnT4/ujYqpXHxVPo=; b=QY9eQPzc/SkgroFXdkdF3M+1x7ypzEd+TYs78bOckRExNeL5y2R8ggbH21rwJhKFJ0 mj8IvJMzwx1ju/RO/+GhEMAfmGqmoa7lNJaiO0+cMKX19CEejMgD8lLiVJovYTUHS8iD 4XDQo19aeY1xPLw514icmvE03g8A3R0uBoKHxGPHbR7NNHHgiEnkkJOUHdk1+XcGo7IC 4mrLJPq0GXWtKfh5dgyclVYlW9edARYJMs+VqaeqkwX6BlJK0KmMn0E1GuqxKXu7tRge NvvdQitxFuoz2E8bGCBb8w5MRBPhVYIZ0YZZvG6H46FfFrtTeyHytCe4Hclf2ygABwik 1sRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aaIPbPlZcX/+q0XyI84hSF4E3MWCnT4/ujYqpXHxVPo=; b=Ucd77rqsAaXb3DzrOmH2qdTBlVb9tGH29BPoD2LGrspN1P14QGqPvo2sWYLA8Sp1HQ I+ElM7tJaGF88plG+vi/WQ8+wVK4tOEXBgIX41m2Nv32aPUyeGO0eqyzqlvNkEWmlPw5 1et2A+nNPWLoCeM+yemewCiL6gAoKC2K4VXF7xJlF0ursLbL2WYjgCmpploaxmE70hgh 9eL7+OwJiDPfDcAzAk+p/UelylBrZr3k6XHhGLqbNuPL8plEjbgL+JcxfVXOaNVpud6r g+rvSoMopdr9PdlOGkZQ1Wd/P6WodzhSZiO+XRMtbz++n7PkzYai1jHXCGm3hLtLG9lD G2wA== X-Gm-Message-State: AOAM533URf//bLeoxMgA1ZH5C0H2T4WwmeEkNa+Mmfci6phbVYLG8q2m l+dQ/7ytJ1+GZIfvAst1HXloGoNyGdc= X-Google-Smtp-Source: ABdhPJzXMerScPVSdDHzA5OTRXv7ueO0CF4DfGKG8Dd2Id1jBMK/LUndTqUVkJoUipsRWau5fsah+g== X-Received: by 2002:a63:9141:: with SMTP id l62mr10732330pge.30.1637233709192; Thu, 18 Nov 2021 03:08:29 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id h21sm2061347pgk.74.2021.11.18.03.08.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:28 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 04/15] KVM: VMX: Save HOST_CR3 in vmx_prepare_switch_to_guest() Date: Thu, 18 Nov 2021 19:08:03 +0800 Message-Id: <20211118110814.2568-5-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The host CR3 in the vcpu thread can only be changed when scheduling. Moving the code in vmx_prepare_switch_to_guest() makes the code simpler. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/nested.c | 8 +------- arch/x86/kvm/vmx/vmx.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 2d9565b37fe0..d8d0dbc4fc18 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3028,7 +3028,7 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); - unsigned long cr3, cr4; + unsigned long cr4; bool vm_fail; if (!nested_early_check) @@ -3051,12 +3051,6 @@ static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu) */ vmcs_writel(GUEST_RFLAGS, 0); - cr3 = __get_current_cr3_fast(); - if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) { - vmcs_writel(HOST_CR3, cr3); - vmx->loaded_vmcs->host_state.cr3 = cr3; - } - cr4 = cr4_read_shadow(); if (unlikely(cr4 != vmx->loaded_vmcs->host_state.cr4)) { vmcs_writel(HOST_CR4, cr4); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index fc7aa7f30ad5..e8a41fdc3c4d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1103,6 +1103,7 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) #ifdef CONFIG_X86_64 int cpu = raw_smp_processor_id(); #endif + unsigned long cr3; unsigned long fs_base, gs_base; u16 fs_sel, gs_sel; int i; @@ -1167,6 +1168,14 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) #endif vmx_set_host_fs_gs(host_state, fs_sel, gs_sel, fs_base, gs_base); + + /* Host CR3 including its PCID is stable when guest state is loaded. */ + cr3 = __get_current_cr3_fast(); + if (unlikely(cr3 != host_state->cr3)) { + vmcs_writel(HOST_CR3, cr3); + host_state->cr3 = cr3; + } + vmx->guest_state_loaded = true; } @@ -6590,7 +6599,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); - unsigned long cr3, cr4; + unsigned long cr4; /* Record the guest's net vcpu time for enforced NMI injections. */ if (unlikely(!enable_vnmi && @@ -6634,12 +6643,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) if (kvm_register_is_dirty(vcpu, VCPU_REGS_RIP)) vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]); - cr3 = __get_current_cr3_fast(); - if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) { - vmcs_writel(HOST_CR3, cr3); - vmx->loaded_vmcs->host_state.cr3 = cr3; - } - cr4 = cr4_read_shadow(); if (unlikely(cr4 != vmx->loaded_vmcs->host_state.cr4)) { vmcs_writel(HOST_CR4, cr4); From patchwork Thu Nov 18 11:08:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 312E6C433F5 for ; Thu, 18 Nov 2021 11:10:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1266061A62 for ; Thu, 18 Nov 2021 11:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343630AbhKRLNw (ORCPT ); Thu, 18 Nov 2021 06:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343624AbhKRLMK (ORCPT ); Thu, 18 Nov 2021 06:12:10 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544E0C06120A; Thu, 18 Nov 2021 03:08:35 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id g28so5032329pgg.3; Thu, 18 Nov 2021 03:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Etx4Iv9+9jA1gDNW2CzF9nm1X7mKnJqCJON8r7DMYUk=; b=L0I+oavX4SYk+9SOpNvDZAf0ki0NgMAK19UaXb3GJiteI/VKeUIzSxcES8MALnHQdd Lb5e+/mQHzlznsnMOB+A+o2Zcjbt8WM3ZNkhb2WLzToOjzd1jixfA9zmXU19Ym1DdZqE 7tCuOjxT1FPpuInTqklSGJZzpDjvGOhGcw7zTEn/d0i45XV+XKP4HucXhSPKgtVTgAtm 0YVn1cHR3jOotdrPnTcsKIUQHeB/DQONdM/hlzsCIfZYFaoDrASXwfQhmH4Yi++yQaEy BeQ0KZ31VJHO04r+RTu7mJ7wpu2/ZBfuTytEnNfvk626HW1/z+ryXLsMY33dCyiDrhjt qQZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Etx4Iv9+9jA1gDNW2CzF9nm1X7mKnJqCJON8r7DMYUk=; b=0LIabbRI6EIQ2mCT1i1EsT1+FHkAGgJiJ+KRpfy97UsCT6zloyA+3SkpbBW9i1+roI Ci5ZD8qkK731/pELPgIVZGfhL8U8M70NHeguOpWA2nfcHOS2+Ra+WSYvngnQ2DIMTo3C R1T1Yg3gLFzAxpYTymJo+xFZOQLKX1PgpJp2YI+oyhbtI9rsLgZn61zeSJhaJrZsh/kx z9MAAW3WAuy7noH6jVeVCmyOzSMsmG9LVoCwjKE46+zM8orYB4iyjhlPUIKtZqoBxXYr 3P0AOPzxB774jTR7mLL6DK+9gVUaky0uIPnCv3Wt+2WRjkl4ii6vUJHNjAX/iypitPka RRHw== X-Gm-Message-State: AOAM5323jA5P1iwqnZ+suFGCby2ihcx/KR/X4yf0y15EkO8bjMkaiG5x TXt3kgwZm42Sd7eQqPWzyUikl+ogzeI= X-Google-Smtp-Source: ABdhPJyXLYdaEOn8/gAMIkq2OBAxshu/aMYi61rnloV3BChnrsCgjWSyiB8JA+0HQZSyfK/UtAgbrg== X-Received: by 2002:aa7:8151:0:b0:480:9d40:8e38 with SMTP id d17-20020aa78151000000b004809d408e38mr54582074pfn.72.1637233714790; Thu, 18 Nov 2021 03:08:34 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id ot18sm2787450pjb.14.2021.11.18.03.08.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:34 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 05/15] KVM: VMX: Add document to state that write to uret msr should always be intercepted Date: Thu, 18 Nov 2021 19:08:04 +0800 Message-Id: <20211118110814.2568-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan And adds a corresponding sanity check code. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/vmx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e8a41fdc3c4d..cd081219b668 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3703,13 +3703,21 @@ void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) if (!cpu_has_vmx_msr_bitmap()) return; + /* + * Write to uret msr should always be intercepted due to the mechanism + * must know the current value. Santity check to avoid any inadvertent + * mistake in coding. + */ + if (WARN_ON_ONCE(vmx_find_uret_msr(vmx, msr) && (type & MSR_TYPE_W))) + return; + if (static_branch_unlikely(&enable_evmcs)) evmcs_touch_msr_bitmap(); /* * Mark the desired intercept state in shadow bitmap, this is needed * for resync when the MSR filters change. - */ + */ if (is_valid_passthrough_msr(msr)) { int idx = possible_passthrough_msr_slot(msr); From patchwork Thu Nov 18 11:08:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E6DAC433EF for ; Thu, 18 Nov 2021 11:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65A0D61A62 for ; Thu, 18 Nov 2021 11:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343727AbhKRLOS (ORCPT ); Thu, 18 Nov 2021 06:14:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343758AbhKRLMb (ORCPT ); Thu, 18 Nov 2021 06:12:31 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B572C06120F; Thu, 18 Nov 2021 03:08:41 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so7867162pjb.5; Thu, 18 Nov 2021 03:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uQxQaa/j7EXWUJQyVa/licy6Kslt0KYeAuLANLkvvZs=; b=qlqlPe3BBwmkZD4k2waU8sSoD4bavgjN3pfvFIXodZeBucwmrMUiOcGACzE9/KXlAl uF8Ga+SZH8QNIFnaiv2KQ+3HnC1mVKL3fTZYsWkSHv3pLNI1dr5T9jw79lANQ0lmeSpy TpxYrAJ0qr9EeAxxpXpiQlUumHXjnlfRfymZT4HbTOGg1ajKlucukKS6JlEAopiBToN8 Pw3bfvBTas+auE7sVXlGXFdvIxbPQQddZbUOtvhdbTfwHn/mWKdKCTwotMzGVT26hTOA TsqcoROCUFip7R1b+qGLB+Ykf/kb4jvd96bBgWe496YmoZ+/7S6NwPPacaCjS2wZfvp4 LvDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uQxQaa/j7EXWUJQyVa/licy6Kslt0KYeAuLANLkvvZs=; b=oGQM2HYd8Djsijm31Tb2FUpLUkN6pK0C/H1Ymska7IiHwU1qufxGJtzrRG/j7neKOd jbcrZBrALdBC772hUgypSTg2Lgz7R99FD8BeMpjPsbn2RJR0y3eoSA1TbsHYIjPYISVf c6SoCnO3WokeGaotNeMRWxxUMvMnp2mC8tLsj8wBHgG3AdJ7ZhZuk3qJxYWZaBbebeQt ohh370S4V/URSCKIBK2FfCnfWt08QFZqe/HNaetX2fOlq8tSrB61vBMcRUxijNEJzsGI LggmuJiQCvAouiZk7X0xmk8H+93rhCyLOyKQ118PhmebfuQJWkFG9vYx21c0wZL4CQ6R A2Tw== X-Gm-Message-State: AOAM532jo7O90DKQ3uj3E+MnNccj33iaF5Ui//QCFFN6UgFLvRSsBNMJ 13xFLH0QPvkHW14xOCcTkl4+QV3Wf8I= X-Google-Smtp-Source: ABdhPJw6LQqlIxO7mSSJ6CrYFrjmOOBAQoWPfisRqGP2qNC+vfevJFbpCPOsUXgkxyFFgoZt7DNqvg== X-Received: by 2002:a17:90b:4f4c:: with SMTP id pj12mr9395993pjb.217.1637233721057; Thu, 18 Nov 2021 03:08:41 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id y18sm2166790pgh.18.2021.11.18.03.08.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:40 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 06/15] KVM: VMX: Use kvm_set_msr_common() for MSR_IA32_TSC_ADJUST in the default way Date: Thu, 18 Nov 2021 19:08:05 +0800 Message-Id: <20211118110814.2568-7-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan MSR_IA32_TSC_ADJUST can be left to the default way which also uese kvm_set_msr_common(). Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/vmx.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index cd081219b668..a0efc1e74311 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2104,9 +2104,6 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) } ret = kvm_set_msr_common(vcpu, msr_info); break; - case MSR_IA32_TSC_ADJUST: - ret = kvm_set_msr_common(vcpu, msr_info); - break; case MSR_IA32_MCG_EXT_CTL: if ((!msr_info->host_initiated && !(to_vmx(vcpu)->msr_ia32_feature_control & From patchwork Thu Nov 18 11:08:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD03AC433EF for ; Thu, 18 Nov 2021 11:11:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6F046138B for ; Thu, 18 Nov 2021 11:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343828AbhKRLOh (ORCPT ); Thu, 18 Nov 2021 06:14:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343635AbhKRLMm (ORCPT ); Thu, 18 Nov 2021 06:12:42 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 503C7C06121D; Thu, 18 Nov 2021 03:08:47 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id n26so5627310pff.3; Thu, 18 Nov 2021 03:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/8DObiGFy1ZJgr/sl7IgJ6YAecXd6ICgL6Wv5yClO9k=; b=THXQo6MHvGYoDnb5XubuHkCtaC6MFhwS+hunjE06Sjd6+HOJXgFTCZ6Fe0Nwj8la+9 DILH55iDqGdwHIcYiX20cgwdF4xtg678GAG5VQj7YDxEJuoGQw3GfdWrG6AtE4Rjp4+h vF9bI1s54nw5rncYHJyCUKsO0w/MqdjzpKCDCloyJeAF59hpeVfDGzm1kAQEXNUszEzK G/cUAe1H1FzS03jahJkTWDHw5tm6snRxcjPzmV1xqOi3T2a1KAYQ0Uy69nUpKYgwuXXq kChYuQBMAWBUesXqF5UsKtQCc5qHc3Eq/GQZFTj1RDVlVqrxIT5I9stWvkttAoNX72iO DuVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/8DObiGFy1ZJgr/sl7IgJ6YAecXd6ICgL6Wv5yClO9k=; b=VGyzkCA/9lyOOs73VIK7m7ZrfvORmhKNJj5ldgRW2rsgFEm6E8aNgb+Le8K5hsMucJ dIpLestltc+jcT8dShTlDh1S1q+Ir0cth8NhGmOtM2pJavtPCT9/1a6Jwmm6E3Ccf1D4 +nkPpj/X5gyCAGRUc+VI5i+kGRLYFHGPFuHi2S8t8RkbYeUQEYMWk8RhPNfUZcFqfEqX 6bzspZLbWu06dCdGWcWTzA+fi1/6D0qZAsG+0KY8kl/hnDkHtGi0NNto4QEjHS6KqMjD D+y9G3pEvvwMYfGUcEJIedRBRM3HxqiBCGc4NQE79E6D3xSPREu6bW3mJlPCatZ+k8JV F38A== X-Gm-Message-State: AOAM5306xOscIfh5cSUNHFsNxvb3dMYN/5GPIalRxl/u47cJ8y8HHusF IUVUmyAiGwD8LNFJxdbZPz4hx+LdB3g= X-Google-Smtp-Source: ABdhPJxYrTn+tMOGRmDnifEVTL9jK4h4e0hO/vF8kKu8Me12kXsicDQW59R5/sBWSTivP1EGIV9Rxw== X-Received: by 2002:a05:6a00:1c65:b0:49f:d8d0:c5d9 with SMTP id s37-20020a056a001c6500b0049fd8d0c5d9mr13920696pfw.72.1637233726730; Thu, 18 Nov 2021 03:08:46 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id a23sm2065793pgl.37.2021.11.18.03.08.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:46 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 07/15] KVM: VMX: Change comments about vmx_get_msr() Date: Thu, 18 Nov 2021 19:08:06 +0800 Message-Id: <20211118110814.2568-8-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The variable name is changed in the code. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a0efc1e74311..c6d9c50ea5d4 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1757,7 +1757,7 @@ static int vmx_get_msr_feature(struct kvm_msr_entry *msr) } /* - * Reads an msr value (of 'msr_index') into 'pdata'. + * Reads an msr value (of 'msr_info->index') into 'msr_info->data'. * Returns 0 on success, non-0 otherwise. * Assumes vcpu_load() was already called. */ From patchwork Thu Nov 18 11:08:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0427C433EF for ; Thu, 18 Nov 2021 11:11:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D65C6138B for ; Thu, 18 Nov 2021 11:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343848AbhKRLOn (ORCPT ); Thu, 18 Nov 2021 06:14:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343781AbhKRLMo (ORCPT ); Thu, 18 Nov 2021 06:12:44 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC4DDC061224; Thu, 18 Nov 2021 03:08:52 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id i12so5620559pfd.6; Thu, 18 Nov 2021 03:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ISbDnAZvCkNnZWiq8wIewWzuFvAywFkypxPVxiTn/no=; b=fDk3vkgnsu9ix+Uq/GpfSjAaUah/0sJLYC6VSPogC3NB0IzF6jCVq88murhVg7bGQE Kc2iHsg++txtFkCUiyNpP2OkF3YDr6hGnSSxP7p4Yuui5oPUwzLbIxerPvaoneAvLClt 029owMEhEwki8Kn7JzuiSKAiSHF5+uueIwlS6D4ynRgSDrbE6M/VR7CLKkdTWgAdzGwk sKfl9yUkpPUCPobdAOX5bEgDpGf4byWAII0981YW/NgJqMv4QsYB3GDSfHTM1/df8lYJ 428lZKssJ5ur3zRfuP8hXq3AjW9dW7Y2CQRnl4COV70L9/wApLp7AMyJRqZ5glB5XR4G 8LqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ISbDnAZvCkNnZWiq8wIewWzuFvAywFkypxPVxiTn/no=; b=qQTEpToz4IHx5fVtw1s8Xx95yYQsQQPkr2YIiAIClZcz2z4nkeMrHn9aKSld2gjdoJ YKpkBJXwbYvqkj9KXQn+MnOPQDyp5D5vDT3hCRicq3DT415VLdl1h1ZrZ7Rtlt4gFk/y Ks/9KJO58a1Tgq2Nc5JXLMflHVCaJP82axQaLnBlDZ8l3pxq3Ge+rsuj7BU5hlukgond CBPWreNGLx4PnqDqgklcvISJm0AyT7qfswShZbwu35wTRg5ogjgWYYhul2VeaeQXWMRQ tIlIl8uv3S3KO/22Lf9NqjVHMBK6Uukh+pAgupwzVzTYaglgpKHg8gtBZnwtwmlJ7fwm SGLw== X-Gm-Message-State: AOAM533uZQuBd5HN7XVxhOcDSB8zz8HCQsrSr+xLstiDEa9Xesbvbc8G Pqooh/XvV/mMO2z3Bf+VeCaU8p1p/UQ= X-Google-Smtp-Source: ABdhPJwtgAUJ8m882oG9AhS6YDRSLpX01XVkzwMuyNN2UhUdK4Lwij+vxgol7sq1FAVxN17bzXP/+g== X-Received: by 2002:a05:6a00:24cd:b0:49f:a4d8:3d43 with SMTP id d13-20020a056a0024cd00b0049fa4d83d43mr14300238pfv.49.1637233732315; Thu, 18 Nov 2021 03:08:52 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id u32sm3152846pfg.220.2021.11.18.03.08.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:52 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 08/15] KVM: SVM: Rename get_max_npt_level() to get_npt_level() Date: Thu, 18 Nov 2021 19:08:07 +0800 Message-Id: <20211118110814.2568-9-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan It returns the only proper NPT level, so the "max" in the name is not appropriate. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/svm/svm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 943da8a7d850..33b434fd5d9b 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -265,7 +265,7 @@ u32 svm_msrpm_offset(u32 msr) #define MAX_INST_SIZE 15 -static int get_max_npt_level(void) +static int get_npt_level(void) { #ifdef CONFIG_X86_64 return pgtable_l5_enabled() ? PT64_ROOT_5LEVEL : PT64_ROOT_4LEVEL; @@ -1029,9 +1029,9 @@ static __init int svm_hardware_setup(void) if (!boot_cpu_has(X86_FEATURE_NPT)) npt_enabled = false; - /* Force VM NPT level equal to the host's max NPT level */ - kvm_configure_mmu(npt_enabled, get_max_npt_level(), - get_max_npt_level(), PG_LEVEL_1G); + /* Force VM NPT level equal to the host's paging level */ + kvm_configure_mmu(npt_enabled, get_npt_level(), + get_npt_level(), PG_LEVEL_1G); pr_info("kvm: Nested Paging %sabled\n", npt_enabled ? "en" : "dis"); /* Note, SEV setup consumes npt_enabled. */ From patchwork Thu Nov 18 11:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC894C433F5 for ; Thu, 18 Nov 2021 11:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E81F6138B for ; Thu, 18 Nov 2021 11:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343886AbhKRLPP (ORCPT ); Thu, 18 Nov 2021 06:15:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343800AbhKRLNM (ORCPT ); Thu, 18 Nov 2021 06:13:12 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400C8C06122B; Thu, 18 Nov 2021 03:08:59 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id r132so5012486pgr.9; Thu, 18 Nov 2021 03:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fh/XlgYsBLsDFl8X1AJ7Nue6Cjst6u62FiLb/dSgde8=; b=FlHitvg74QJC+Ny8Rnqceob2+7pokibaATGqk1KZ9DKKKxl7dr4t5nAicTNsxSPFHA jR8S8LYZD8Ku1N/ocMot3tjYXdTuFxV2qGlq/E+n1hY4oNRDau/BeFfkfmEn5xw+6mVp uq1Gq+X3p8xrIcXAoQvKjePh6QwgOwvB/FrdmlbYyshq/DxzxjQn1PgRTzsjJZI1fV2o ry9PAkcrPAP6eY6oRFmB71a+Lt3xQmEET1q1jfDCalRhtGhhRJSDkkhs4va3O8oNRcW5 F9DhaaYpbyM2YxqdTd26NGRreSzFpbIK1eFFbEwRCGqqUDpws8K+LQJ0wCnhxb5tyVO7 eHrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fh/XlgYsBLsDFl8X1AJ7Nue6Cjst6u62FiLb/dSgde8=; b=3dUSEg3p0Xft1wMrJR0yP+rKC/y+OcvJqtyaTHApryMKI6sdZNeQzPIV2FPEUUdd7h iul1CMUwp4ChPECagPyXoKfoJEK/r3vwMse7dlZU7I+T78xVneMUoetTWyJzR8KAmKDi pVLJFicJAVYHAUOeuvPBBrm9aY2rOBvzJ//xi/S9T3EOtkwKP3nH+AQJ/592C+qr2d05 aSlfwoK1zEO0i89oyRsSkeLh7GWIQb3U69Zi1E3u/4NqDR7G6MH1LiH/8wLDKZEkCRlr tm5IFOGxLkIF+EauNqMj+zDUcCGZ+WI5DQl4Wf3HWy3AO2XA0r7hA1M1ylel9mzxb7Qh LwEw== X-Gm-Message-State: AOAM531tmBZnFkH8g1ZR77ZZ8NRYeGc6sijg7dIKszf+GAh5Kc+XhHOi V1MchzibGv8MhK55/Re1HRq2TX+FZnQ= X-Google-Smtp-Source: ABdhPJxLq4FNtKGzakxenbPaFL4EEzLWGkjrl9z9DkSh2apy0gYHf27qakH5SXb9ownwO6vAmIVTYw== X-Received: by 2002:a05:6a00:15ca:b0:49f:d22b:afff with SMTP id o10-20020a056a0015ca00b0049fd22bafffmr14398124pfu.35.1637233738665; Thu, 18 Nov 2021 03:08:58 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id j17sm1368394pgh.85.2021.11.18.03.08.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:08:58 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 09/15] KVM: SVM: Allocate sd->save_area with __GFP_ZERO Date: Thu, 18 Nov 2021 19:08:08 +0800 Message-Id: <20211118110814.2568-10-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan And remove clear_page() on it. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/svm/svm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 33b434fd5d9b..d855ba664fc2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -585,12 +585,10 @@ static int svm_cpu_init(int cpu) if (!sd) return ret; sd->cpu = cpu; - sd->save_area = alloc_page(GFP_KERNEL); + sd->save_area = alloc_page(GFP_KERNEL | __GFP_ZERO); if (!sd->save_area) goto free_cpu_data; - clear_page(page_address(sd->save_area)); - ret = sev_cpu_init(sd); if (ret) goto free_save_area; From patchwork Thu Nov 18 11:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E054C433F5 for ; Thu, 18 Nov 2021 11:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 164F161AD2 for ; Thu, 18 Nov 2021 11:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343919AbhKRLPj (ORCPT ); Thu, 18 Nov 2021 06:15:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343605AbhKRLNu (ORCPT ); Thu, 18 Nov 2021 06:13:50 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D9AC06122E; Thu, 18 Nov 2021 03:09:04 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id g28so5033405pgg.3; Thu, 18 Nov 2021 03:09:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7JOQN1FyHOOaGiRO0iQypErrhkvSTjnVtAXlZRhg9yE=; b=SWzLZH0gSfsxgOlxNe8D3XhBWumtB+31hB7IrnhHBoGf31cVnezIztbZRRvnuM2Mx6 9gMsvE9VIrqHg6l0zlVzdmLYMkx54vw/+ShFLTqMtMei3bA8VVCpRMfYI5biDZkZuhFX RXUSAWYWvi25bh3lNMW3I8Cp9GZYB4eMyofmNtjmuBp3mZOO7c8w/bLmCYScpvaRXBL5 miIfTBWeAH1h9pL8Y34onHqDWkhDPOIbPqPhzAlS682NdfqQ+RtrF60DvpfgPoSIPqLr q8apt5rp7S6xCyBFoNuiO4MFKvfUzc7L/aP56IOjvXYurQEMMQFat01Gs47R+lQYfO6N /h6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7JOQN1FyHOOaGiRO0iQypErrhkvSTjnVtAXlZRhg9yE=; b=OWX8DZ+9uILLnyZdloQElQ0QGmHC7WWV3DP670jSq1l+PLrhrE1QPOn3Xal1JT4Kwk kilLlZrheJ0JPJryCjhJdYp6h1pN1gBdAfyXtxtKUWA6kY2VaDn0C4ULgir5yOEvhMUV 6MS2+DQp9Fw6TnHSVLWVw/LDQGLnX1a6mNjLkXlJQ2o2Qhds7WglAExC2+hHKn0PtLJN YiDDRS5PlnQL1fX6xdd9NExFRrIH5B+3Uj8MJ+a2oSCBqXgOvGsw57YQzyZZyaqegef1 ro/BDEhMLSRCVhRag6IqBjkCsUq8O3JD5kKnlf0NxuN3xDBqawz19OTz7Ia2DCl9+Cy5 l1Yw== X-Gm-Message-State: AOAM531TmM2nLOekE7DKfExQ9L0hal91wCUHwAwbe+yrF2Nl/NtoPj5s Bq019K6hKOOnjeNPZlX9thwnuzGTK2I= X-Google-Smtp-Source: ABdhPJxEb0WzDlkM5eEdXOiWxh/TeUkASyZXnS6r6rOBGdjFZlx+XsxWWD3ZJUR2+3NHZRrwkFtiuQ== X-Received: by 2002:a05:6a00:234f:b0:3eb:3ffd:6da2 with SMTP id j15-20020a056a00234f00b003eb3ffd6da2mr55062168pfj.15.1637233744308; Thu, 18 Nov 2021 03:09:04 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id i184sm2845904pfe.15.2021.11.18.03.09.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:04 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 10/15] KVM: X86: Skip allocating pae_root for vcpu->arch.guest_mmu when !tdp_enabled Date: Thu, 18 Nov 2021 19:08:09 +0800 Message-Id: <20211118110814.2568-11-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan It is never used. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 8f0035517450..e1fe8af874ef 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5501,6 +5501,10 @@ static int __kvm_mmu_create(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu) for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) mmu->prev_roots[i] = KVM_MMU_ROOT_INFO_INVALID; + /* vcpu->arch.guest_mmu isn't used when !tdp_enabled. */ + if (!tdp_enabled && mmu == &vcpu->arch.guest_mmu) + return 0; + /* * When using PAE paging, the four PDPTEs are treated as 'root' pages, * while the PDP table is a per-vCPU construct that's allocated at MMU From patchwork Thu Nov 18 11:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C053C433F5 for ; Thu, 18 Nov 2021 11:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D84661A62 for ; Thu, 18 Nov 2021 11:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343962AbhKRLQK (ORCPT ); Thu, 18 Nov 2021 06:16:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343714AbhKRLOR (ORCPT ); Thu, 18 Nov 2021 06:14:17 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F09C061230; Thu, 18 Nov 2021 03:09:10 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so7874448pjc.4; Thu, 18 Nov 2021 03:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cEtQ1Na8i+7W/Q+NNUCdn0+wSJgL9gwMTU0z+MM3hHA=; b=mPLPZGdHN7CumIJHuMhCD1209JHXxJyt3SAvb/hdEmQiiQ0xpTDkkx/xCdYsIfEtdf Imk2DWb+ZkUXdccvfNoRePqNXGptuEFBXKEyzzyTujG6W0Wvg0dp6YEbdqaLprDhNPU4 cJ0ejMQEbJ9l9A4aq7vX2//ezzXDxTN2C1ipvmc/SVY7ZClssYb+THJRY2Vs0I2VHdE6 8ScXCn+23BTDzzd+gXmXfqjYyFC/ptMniKFLs96Kg8vG3Cf9gPZsGZLYSNKq7VSib0Nq iAVe1pSjTXX/pHF7KligiJe+DPwT4n2GH1puNMB28YxgcF3COsdQHqCC9501BGiZKyif ufBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cEtQ1Na8i+7W/Q+NNUCdn0+wSJgL9gwMTU0z+MM3hHA=; b=kIBjF0W/rU6rpDwGyNApXoqE2M2pql9M8TzyHi3P3FMWGO74MyC01TnIz9BLAh6v/p zx0QuE6f/6ciZF+f3VBRAhx9Ut0zaTZe/kH2aXTehJ6tfgOmmeEznWUzrMWjUawOajss 6UYgezEeYaPrX1BlHx3naI2NgVyee2+lyU775GwBk5/DINPPt6pZyp+J4Ps4Kj3fpekp qgVnB0yERV0nJI3hy33kHVExXSJZps/WHhnusttyl3RKq48i94LYchmCGoZz0xbVkIWV raTQ1/ZUS/wTD54v9o3UfCuJr8Q+K7WAZo2lwVHbP6kXLXC+IuzUotOPwI8M6lYkLFxp equw== X-Gm-Message-State: AOAM531QXQZkX0r7lT9dH7tSI9D2L3Oo/AZcIihMaaKtzz65mryC1S2h 3D8yW/lSP04Hpl+Mh9FBJHBZ6dATMyI= X-Google-Smtp-Source: ABdhPJzdFMacoH6J/1AVdPlIREGhk8b8sLZpfLrP2BLKvsx91PGlMyhUQXDjE7qwJoFVfOyPWXf+ng== X-Received: by 2002:a17:902:74cb:b0:143:6fe9:ca4 with SMTP id f11-20020a17090274cb00b001436fe90ca4mr66486639plt.2.1637233749926; Thu, 18 Nov 2021 03:09:09 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id w189sm2827192pfd.164.2021.11.18.03.09.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:09 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 11/15] KVM: X86: Fix comment in __kvm_mmu_create() Date: Thu, 18 Nov 2021 19:08:10 +0800 Message-Id: <20211118110814.2568-12-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The allocation of special roots is moved to mmu_alloc_special_roots(). Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index e1fe8af874ef..64599fa333c4 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5514,7 +5514,7 @@ static int __kvm_mmu_create(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu) * generally doesn't use PAE paging and can skip allocating the PDP * table. The main exception, handled here, is SVM's 32-bit NPT. The * other exception is for shadowing L1's 32-bit or PAE NPT on 64-bit - * KVM; that horror is handled on-demand by mmu_alloc_shadow_roots(). + * KVM; that horror is handled on-demand by mmu_alloc_special_roots(). */ if (tdp_enabled && kvm_mmu_get_tdp_level(vcpu) > PT32E_ROOT_LEVEL) return 0; From patchwork Thu Nov 18 11:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FA4DC433F5 for ; Thu, 18 Nov 2021 11:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA4B661A62 for ; Thu, 18 Nov 2021 11:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343742AbhKRLQO (ORCPT ); Thu, 18 Nov 2021 06:16:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343737AbhKRLOS (ORCPT ); Thu, 18 Nov 2021 06:14:18 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23415C061234; Thu, 18 Nov 2021 03:09:16 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id k4so4909890plx.8; Thu, 18 Nov 2021 03:09:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QMJpdANKm3zzFJkHU2o6JES7gSuM78lfiMvwlP1M7hQ=; b=TUWpZnMATYowjtDyJrxWeFHWT2q5M+vo43yTHkUrhiwoDJXW4mrtG+HjdXPDpCmSg9 mGWB8OpUxRGKpkfThcmw9bjL8sVDttRifo3k8EX9RVxrqOyL+2ZYxugqUkYN3sW9FBMa kNVq8c0CuylX/c3R/MgOlEMkKGKEK3wnOl15WYOiKpCvajZzamnH45titr/Nn0EzecJD vClr/39ocKuc418xN/rL4RnluWYpdlh1WK3IpM1QtVZ6kjshVnm8lTmUzB6TO1bOMutj ScljtztudiE9oE7s420Zwri7SvOxYqzTG4hNiznKgA8u9ApaxDo1eoEDmaMrMpepUTfo 9wag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMJpdANKm3zzFJkHU2o6JES7gSuM78lfiMvwlP1M7hQ=; b=M92Es7un8Xy1dMftI+kym11vSsPi3QdzSKbm7LPrwwp9B3q5tkDyp/ShsfuLo9sEX9 xZ96nWutqcESDbfhew5o2eLKRr6vrv8mi6obrxhbCIqrdXqqmNP/mPIAbwxe8TmD2v5D 9oLwaokQdOdduyxSfP6m/aKDdFoCyMcRtQFy+X6okyR4nvfXIax4IhFs7gTYAKpZ75a8 PG1xEeFoprbdhD0uKcY4T1vTFz3GcD7MTbN8Z/kGnNaTUX64Raqlavv5+u1gDm/CJ4LO ZYIISpAyjjWfG+bWdGL77ajv6ZAm8m+MwOG+WVYJZJvCBi9QWFitOOCuEiIpEDIi27Pf DrCA== X-Gm-Message-State: AOAM530wzcF52v9XBP4Mxvt6UerrD2k7+SE9Y8Vkmt9/V7lrslPo5cmG 2lYUllHD0G7cAiXjYK59zLY3D9qa6bQ= X-Google-Smtp-Source: ABdhPJwBg4A8+SJOCWpd/OCKYuMUyZ/P5eh4Q8aP2BtAP4CoEDstpDR0P+Vre9ySD5GxkwR3zVcBAw== X-Received: by 2002:a17:90a:df01:: with SMTP id gp1mr9389566pjb.28.1637233755578; Thu, 18 Nov 2021 03:09:15 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id q13sm3255133pfj.26.2021.11.18.03.09.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:15 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 12/15] KVM: X86: Remove unused declaration of __kvm_mmu_free_some_pages() Date: Thu, 18 Nov 2021 19:08:11 +0800 Message-Id: <20211118110814.2568-13-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan The body of __kvm_mmu_free_some_pages() has been removed. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/kvm_host.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4cbb402f5636..eb6ef0209ee6 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1760,7 +1760,6 @@ void kvm_inject_nmi(struct kvm_vcpu *vcpu); void kvm_update_dr7(struct kvm_vcpu *vcpu); int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn); -void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); void kvm_mmu_free_roots(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, ulong roots_to_free); void kvm_mmu_free_guest_mode_roots(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu); From patchwork Thu Nov 18 11:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4C0DC433EF for ; Thu, 18 Nov 2021 11:13:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0C656138B for ; Thu, 18 Nov 2021 11:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343996AbhKRLQg (ORCPT ); Thu, 18 Nov 2021 06:16:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343818AbhKRLOf (ORCPT ); Thu, 18 Nov 2021 06:14:35 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C58C061570; Thu, 18 Nov 2021 03:09:21 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso7928670pji.0; Thu, 18 Nov 2021 03:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7j1qk06E4vJqUJB6P4Ib9H/n91LJYpqZ3QPhrcbNoYM=; b=M8pHr3B+jGgySyah1q9QEBMTdDeusbVkuhrRgxvH6/K7BZROJOQSJEKlpEcU/zwfRl M1WlgHDEOaq4LjN17TfkwD9OFE5Wn/aeZf4cKc+lvz5sOmmzkRoZDUz4Nl5vZA7G8r6m LypS8TmgK3zXh8dGUdO7BGKtBxIzf48BxAiCtgHlDmXxEPYwn3IA45ykj3ulgoVunwHs lpMI4lXzHqjk0ZAz3UrPkB+nvJRLjK8ZwHqj9LQ+oI4Lw/GigaBk4HlyCU9X6QNZx803 33OaPwbSQfaOxE9cJxjK4HdndkEcku4FivnUat+1lx9rj2ld1QW4A+MU7H9wUth5QPp2 VsXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7j1qk06E4vJqUJB6P4Ib9H/n91LJYpqZ3QPhrcbNoYM=; b=t3Dc/01r7SeZtEfsvfgFp2IKjV3y0uWnguEJgPs2XjKHkDy117cVyElKjsRw7DvYGW dkZzI8hPZ+cZaC5XRC1JIgi7YTcM3YESrv73oRrExQ1YwOulxoIO1qxRPo3BMeObkEsZ pnxw/+mLqjTrlEx6a2fDkWfWPvo2yQqO5cjNiX46Wt/srOsqo2UbUVXw1a/EbzalEUXw Oy3zk6E3oK1jWwFiWw5vxrvecjYhCFnd6pl1s+q8tfevsYkQWwxhhsvMixGroPwqKY5t Dao6PFNmScnIphWCy1IDkbLh9UAZ++PZtF+MrtcIJeSA0nkgJmVp+igZCV+K/yNlfDQ5 ak2A== X-Gm-Message-State: AOAM530k6y1RjIHd8iewHGP57mDiYi0KTUzcf9kKD9aBqnH0UGnNcsx/ mmuNTpUlOyBObXRcgYEo9y0j+VpYwsk= X-Google-Smtp-Source: ABdhPJzrRBu2XpyJm19NI7CAKXh1hPSgnwyS2X6PZXWPwQrfuqv5X6KlzG5+30y8l3nmm6uTWrA6mA== X-Received: by 2002:a17:90b:4f4d:: with SMTP id pj13mr9706510pjb.4.1637233761239; Thu, 18 Nov 2021 03:09:21 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id k14sm2948863pff.6.2021.11.18.03.09.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:20 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 13/15] KVM: X86: Remove useless code to set role.gpte_is_8_bytes when role.direct Date: Thu, 18 Nov 2021 19:08:12 +0800 Message-Id: <20211118110814.2568-14-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan role.gpte_is_8_bytes is unused when role.direct, so this code is useless so far. And role.gpte_is_8_bytes is going to be used for indicating if gpte is 4 bytes even when role.direct is true when shadowpaging, so this code has to be removed for preparation. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 64599fa333c4..db8b64971f25 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2082,8 +2082,6 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role = vcpu->arch.mmu->mmu_role.base; role.level = level; role.direct = direct; - if (role.direct) - role.gpte_is_8_bytes = true; role.access = access; if (!direct_mmu && vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); From patchwork Thu Nov 18 11:08:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E615C433F5 for ; Thu, 18 Nov 2021 11:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4A5561037 for ; Thu, 18 Nov 2021 11:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344017AbhKRLQy (ORCPT ); Thu, 18 Nov 2021 06:16:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343862AbhKRLOt (ORCPT ); Thu, 18 Nov 2021 06:14:49 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB0E7C0611A6; Thu, 18 Nov 2021 03:09:27 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id m24so4913782pls.10; Thu, 18 Nov 2021 03:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YdfW8Ysp7XBeV8ztjWWa4B1sDAxYZYhnWqDn9ynnIjc=; b=hBlI2UjiYvGgt8fATl1AxekZFCzNUNKO5mUH+Rv83sZ1AxYQp8AwuHhWm0F4Wp+Y10 nLbMefcT4QvRK5ZCNbNL1YHq7jOr6pGKGncBmi8DNcO+R4mLUJnL9qLjHnCo2qWRpRfS efHGRCezvu5dftNFiuuvySIOCtOqyKpDyeI4ARHx2prGvrd+bjlA/ci0SKC0rjW5pagi 9pRrvKTWbNiJM17begN92SPTsR2kJLUp7JKzkzaTdq4frSwQoF/E1wT+761PMC7qXrlx 4Raj7snrGpKBZZ4+QKl8ktV+VijNt9vUkEUAKV2MzaKmmUw3wHf8FBTm2jxr/hTcAFa1 Rj0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YdfW8Ysp7XBeV8ztjWWa4B1sDAxYZYhnWqDn9ynnIjc=; b=JbAAkhwHeB68LYCcHwMVtVQ/1DJ+M0onpCPBjFjApI5o/B+1tgn88aD86KWVI+s5H5 eycxvL/USNxVMQGWT66POa0bgkDeOgh5/KPnL6MVylz2d1S9Wwe/CkrSgkqQ9t0AxJY9 8CbIn/OenzrkbOOIXDCdXtGBeasVdwzRyr7voJ6bR336TpirUSk2vfnndvqB/zSZLn3i +OlEZnwU/vYbBvo8dQF4aBRzzMISKvHg0UHIc6ZaSdsrDv+TAK0+eGJ9DovZKlQu+Nsf 5aevD09Qjx7D7GOaNvf1ZqIIIBFTABMF+ty1O60TW/6Nrc9wL6i+k6iqq5Lr0/L4ucVg KxjQ== X-Gm-Message-State: AOAM531FGKOsIy/Cz6iOFw3rsvM/r0S008BOQD9xkPKYOenbiINdHxxf jF3ytwAg7HkjPoNEfLZClWImHEhpk3A= X-Google-Smtp-Source: ABdhPJwh6mKtD+fwsCkurbQB+PShEkSx8rRBCbSHyaLiXoKD0oXPQwsBXEVMr0ES89UqFPANYAOgWA== X-Received: by 2002:a17:90b:3a89:: with SMTP id om9mr9427252pjb.29.1637233767086; Thu, 18 Nov 2021 03:09:27 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id y18sm3423546pfa.142.2021.11.18.03.09.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:26 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH 14/15] KVM: X86: Calculate quadrant when !role.gpte_is_8_bytes Date: Thu, 18 Nov 2021 19:08:13 +0800 Message-Id: <20211118110814.2568-15-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan role.quadrant is only valid when gpte size is 4 bytes and only be calculated when gpte size is 4 bytes. Although "vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL" also means gpte size is 4 bytes, but using "!role.gpte_is_8_bytes" is clearer Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index db8b64971f25..6948f2d696c3 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2083,7 +2083,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role.level = level; role.direct = direct; role.access = access; - if (!direct_mmu && vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL) { + if (!direct_mmu && !role.gpte_is_8_bytes) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1; role.quadrant = quadrant; From patchwork Thu Nov 18 11:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 12626623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BFECC433FE for ; Thu, 18 Nov 2021 11:14:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 207F76152B for ; Thu, 18 Nov 2021 11:14:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343650AbhKRLRC (ORCPT ); Thu, 18 Nov 2021 06:17:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343866AbhKRLOt (ORCPT ); Thu, 18 Nov 2021 06:14:49 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D7AC061A09; Thu, 18 Nov 2021 03:09:33 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id h63so4991332pgc.12; Thu, 18 Nov 2021 03:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t9lt885omYyDf9Kd0EGpZtn1YqCcccm2P44/Ln1qvGg=; b=iW3CIwzwxDatI0opTJwJRL70urQsh/wQQIwUiXFYIXUUu5i92gE3V0Z4Wecunjv/8U TSJ7fRKUN31k2cQESGh8lOABknBNeDp7NicF7HsWrUKmUTqUCgXMw6mVOriUhEU3HTP8 lJIPyGeGjiJHPX9eoRlYj66g9kAnNgruPtbKgR9GZjQlvcZ2wrb+wCT4i7HcXE0j9wAu UYS7PF76qTLSPhWAhGGaobD5dxyrTRB2D9Uk1sNqRjMFMPPCzxN5Dk3JBbSApzQoZg9N cNnlXpQsaOb5k8cV+LKjaJ6TVaWGN7XJh2JMeJVZtc8rf48TwzV71rOXxUP2MF+V+aqm RsfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t9lt885omYyDf9Kd0EGpZtn1YqCcccm2P44/Ln1qvGg=; b=7vHjCIqfc3wuQs02/AOuvQ5ou4gy3AUa7LZJgzD2qsO9PVsFuvakZ0E+oNHcJT+rFy wRH2Z0NkAU4VmhqPHvdu/0P8Ku7hg/5E08HJTwso9E2ugHBoVfVSs9krAlm97+aDRr9U j5hLTo1HNlnvDov6S8ZZdzx/COKfRbiWYQoVIAA2sfrBhyoFQLJpB8mcDx9O1WeBVbOf kuwMSqu9ZQcIWFVbDSmK6yecInrH30o77/P0Qji1FcPXYA76OT//QY7phbvgMKCgmSdL VUH2TRm4aJObPPaZzvN8lpZWzX6JCkpzB4HzJKjJjKBxr+2MT9X1Bwir8M7HRoImqn1N 6Dig== X-Gm-Message-State: AOAM530ccySGvfd/3TSY1ORZxhAB1IsRNM6mTCtnBCoO3YGBPspSfpC/ NUWkjEfhwHWApEq0lAPp7eCQ4bfD3cM= X-Google-Smtp-Source: ABdhPJysfV6ZF1b48jNjfeA5unjw7i0pMoensupDBHqUH5EXrEv9f4ZuMreR0OZDjV5qmRXjQ8hN5Q== X-Received: by 2002:a63:788d:: with SMTP id t135mr10393119pgc.2.1637233772985; Thu, 18 Nov 2021 03:09:32 -0800 (PST) Received: from localhost ([47.88.60.64]) by smtp.gmail.com with ESMTPSA id c2sm3238776pfv.112.2021.11.18.03.09.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Nov 2021 03:09:32 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Lai Jiangshan , Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org Subject: [PATCH 15/15] KVM: X86: Always set gpte_is_8_bytes when direct map Date: Thu, 18 Nov 2021 19:08:14 +0800 Message-Id: <20211118110814.2568-16-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211118110814.2568-1-jiangshanlai@gmail.com> References: <20211118110814.2568-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Lai Jiangshan When direct map, gpte_is_8_bytes has no meaning, but it is true for all other cases except direct map when nonpaping. Setting gpte_is_8_bytes to true when nonpaping can ensure that !gpte_is_8_bytes means 32-bit gptes for shadow paging. Signed-off-by: Lai Jiangshan --- Documentation/virt/kvm/mmu.rst | 2 +- arch/x86/kvm/mmu/mmu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/mmu.rst b/Documentation/virt/kvm/mmu.rst index f60f5488e121..5d1086602759 100644 --- a/Documentation/virt/kvm/mmu.rst +++ b/Documentation/virt/kvm/mmu.rst @@ -179,7 +179,7 @@ Shadow pages contain the following information: unpinned it will be destroyed. role.gpte_is_8_bytes: Reflects the size of the guest PTE for which the page is valid, i.e. '1' - if 64-bit gptes are in use, '0' if 32-bit gptes are in use. + if direct map or 64-bit gptes are in use, '0' if 32-bit gptes are in use. role.efer_nx: Contains the value of efer.nx for which the page is valid. role.cr0_wp: diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 6948f2d696c3..0c92cbc07320 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2083,7 +2083,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role.level = level; role.direct = direct; role.access = access; - if (!direct_mmu && !role.gpte_is_8_bytes) { + if (!role.gpte_is_8_bytes) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1; role.quadrant = quadrant; @@ -4777,7 +4777,7 @@ kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu, role.base.smep_andnot_wp = role.ext.cr4_smep && !____is_cr0_wp(regs); role.base.smap_andnot_wp = role.ext.cr4_smap && !____is_cr0_wp(regs); - role.base.gpte_is_8_bytes = ____is_cr0_pg(regs) && ____is_cr4_pae(regs); + role.base.gpte_is_8_bytes = !____is_cr0_pg(regs) || ____is_cr4_pae(regs); return role; }