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 C933FC433EF for ; Tue, 16 Nov 2021 03:17:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC03261A4E for ; Tue, 16 Nov 2021 03:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbhKPDUg (ORCPT ); Mon, 15 Nov 2021 22:20:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237714AbhKPDSE (ORCPT ); Mon, 15 Nov 2021 22:18:04 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBCF9C125D61 for ; Mon, 15 Nov 2021 15:46:27 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id p13-20020a63c14d000000b002da483902b1so9888947pgi.12 for ; Mon, 15 Nov 2021 15:46:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0zwyK1+5SQSFi33zyn3A2qd649otgAUCjnWlf13vnt4=; b=eLYV4+JIwHSuMcMpNKKlGM6iy8jUFnvLlNL8Aq95E7jZBtaCwbmdVfVVHCF0LY6qeS 3WfargDXoaDwa5wtyd3HN/VegDEqqGFbzcS/kLiu3JhWuUFMG6L0WyaXb3yNzpF1UDxT Db2GTF8u0GsI7+1GaPha6eX1CuiWHO0L2WKt6Y4uN9V+ZNgXMYhy/MHgOF4zHqz2Bjfq sIV146dWVag2Y+XUfHbjrCHJxZYXvRlqp0QspMblFxm8D8oQtbRuLUlNuqmZFtee2cT8 Jz/BRbS5ImG9Dx2qndjtt2CeQ/C0ULPdJZdB0vP4AHrrZRioItj9bcxJbirYqucQBIxJ jOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0zwyK1+5SQSFi33zyn3A2qd649otgAUCjnWlf13vnt4=; b=EL/dv3wwC7ta76Ek1iA0FmOTh08w2tkJ/NO3PxOf95lQ/XVbUjJvS/wtt9B7iaN3Oa 8mR6CJllJNTSl2fFVBTegC8so4TKCVP3/tWqsVGU8q9ICFD/dd22Mze+byIV5eTZQN7a hqCTc8pRb3AdTY2EW5KLwGz4nIizrNh7sm7WWS/g8YuSRb8q9wZciUqzuGju0lJPj52Z ji+t8GPKJuQA4T4Wb6DKfRE/OMfbB9rYbolcPYZcmw+gvXuk3G5L1YiCkTVc/RyhHh6s o+mn/bplwqHWJZ3VwbXqXfueAK3/1rcPUVPEScIqH4Mvl4I6N2/BaCEmu07y2UxTANKa IUMQ== X-Gm-Message-State: AOAM532KapGPTDzs4bJNRNEl5QtH/YweawP8kxWQeUT6v6EFFmkSrXsl L14z04EqylvPt4sbikV/VKlAPdsml0OssiSeLeWtAGJV/mFT/gym79CWUERDVVckIZSsYpEFQXv z/C8KnYm1lZsLTdVy5YdFhHXV+kOFQys62PeMcNicqKe4O5oejyeM4vprpBHFRx6897fsMn7+ X-Google-Smtp-Source: ABdhPJy0ArkW29tRlngLJfDrzxQXp4ZPpLuHRsLyZfvuNRCXPgtMO6AdXTagSFmsnZPpyQZO6mAqrpn/wzPb X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:916d:2253:5849:9965]) (user=bgardon job=sendgmr) by 2002:a17:90a:800a:: with SMTP id b10mr70386185pjn.162.1637019987257; Mon, 15 Nov 2021 15:46:27 -0800 (PST) Date: Mon, 15 Nov 2021 15:45:59 -0800 In-Reply-To: <20211115234603.2908381-1-bgardon@google.com> Message-Id: <20211115234603.2908381-12-bgardon@google.com> Mime-Version: 1.0 References: <20211115234603.2908381-1-bgardon@google.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog Subject: [PATCH 11/15] KVM: x86/MMU: Refactor vmx_get_mt_mask From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , David Matlack , Mingwei Zhang , Yulei Zhang , Wanpeng Li , Xiao Guangrong , Kai Huang , Keqian Zhu , David Hildenbrand , Ben Gardon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove the gotos from vmx_get_mt_mask to make it easier to separate out the parts which do not depend on vcpu state. No functional change intended. Signed-off-by: Ben Gardon --- arch/x86/kvm/vmx/vmx.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 71f54d85f104..77f45c005f28 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6987,7 +6987,6 @@ static int __init vmx_check_processor_compat(void) static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) { u8 cache; - u64 ipat = 0; /* We wanted to honor guest CD/MTRR/PAT, but doing so could result in * memory aliases with conflicting memory types and sometimes MCEs. @@ -7007,30 +7006,22 @@ static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) * EPT memory type is used to emulate guest CD/MTRR. */ - if (is_mmio) { - cache = MTRR_TYPE_UNCACHABLE; - goto exit; - } + if (is_mmio) + return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; - if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) { - ipat = VMX_EPT_IPAT_BIT; - cache = MTRR_TYPE_WRBACK; - goto exit; - } + if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) + return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; if (kvm_read_cr0(vcpu) & X86_CR0_CD) { - ipat = VMX_EPT_IPAT_BIT; if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) cache = MTRR_TYPE_WRBACK; else cache = MTRR_TYPE_UNCACHABLE; - goto exit; - } - cache = kvm_mtrr_get_guest_memory_type(vcpu, gfn); + return (cache << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; + } -exit: - return (cache << VMX_EPT_MT_EPTE_SHIFT) | ipat; + return kvm_mtrr_get_guest_memory_type(vcpu, gfn) << VMX_EPT_MT_EPTE_SHIFT; } static void vmcs_set_secondary_exec_control(struct vcpu_vmx *vmx, u32 new_ctl) -- 2.34.0.rc1.387.gb447b232ab-goog