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 DFE48C433FE for ; Wed, 10 Nov 2021 22:31:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6BC161250 for ; Wed, 10 Nov 2021 22:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbhKJWeF (ORCPT ); Wed, 10 Nov 2021 17:34:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234004AbhKJWdx (ORCPT ); Wed, 10 Nov 2021 17:33:53 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D649C061767 for ; Wed, 10 Nov 2021 14:31:05 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id d3-20020a17090a6a4300b001a70e45f34cso1805607pjm.0 for ; Wed, 10 Nov 2021 14:31:05 -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=FWwXwDfBnz5LFBsDCQ1wpQlpwGxzZTjObPP1GkJajQw=; b=IROO4E6G6/Tu+tdfzalPUTSYwK6uUaJHX2LmS4eaKh5TTZtnmAE9yCGDoEY62aX/vL 7OTdREb33pFkvarZYwglLn1c93rjqtLfoUEZG8aV0oSTvejcx8hXPUqEXKb5oqtsSxWn p4S+1x/dh9KDaZ8U5NNI/J/t4w5QJC5mDT349cbnv0qjic1Y5SZQvmTQZ7wxqMNuwkO1 f9oflPCjnaenuvAnzSVA0Mv2U/aGvR/9D9g9bTas6o3KG8PiqjLgrCMH6QIOa9acVC1O CjiAzXzcscqZTr1+BITbqpcYiOY4CQ+qrBDl+1JBVpRg0BS/eJa7y+G/APsZ25ArjaKk Sxuw== 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=FWwXwDfBnz5LFBsDCQ1wpQlpwGxzZTjObPP1GkJajQw=; b=4TI2m5C2eVYPzjKgrO12hiO+Tn8vjuTnQxsgqmh0CUkO80NzcVS5Hu5uqjMJ4fYD8i y+cQm08OMBBYfMSUoXlPlxteS45zzw3VjXD+DROY48Zim1SV7qLKRA9H2BpolqVXdVdD wjNFJTRjNrp2fy/bw/MymoEjTMaMs3BBXeWX8I9a2TyFbqvr/8eNDM8MTY9hcbks/6zT KFDbJE4p0M9EkU7IjhbuPilig9qcLjEnr9iv2GyjtMssI5OKrr1OwQO+rPy6FOVz0bOv 6xeXtwUvkmfzrWGLkmYdUxcJjL8bAn+C+3UjOgEip15wsn8rjXUhOZSnCClfpqe69PcG KfGQ== X-Gm-Message-State: AOAM532riMV4JTWqRjJdWWcJFrl2oAPp0dk8ZRV1X+KvI2qKBH9hijHG ftrfyEuLcoOMD2gKH30D9b78QEFJQ2cXBZ/zh5BGoeAPuYZZGpblzw5sqyapUlxjgwRE9Xo2vvr ywPMvvwn1vk6mArJkf8ZSarAFrWu0Q18CmE2ShQSo/4FRz6sLKTs+6YD50kbySZ0gtHIvWJk5 X-Google-Smtp-Source: ABdhPJxUzvRq1lCmdEsikMFwEJuiowRKri6jjr8/fv+T3xudb3seeFH03JVAy+YjfbSGQ4njn1KEsGfxjt9X X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:6586:7b2f:b259:2011]) (user=bgardon job=sendgmr) by 2002:a05:6a00:174e:b0:47b:d4d6:3b9e with SMTP id j14-20020a056a00174e00b0047bd4d63b9emr2356149pfc.21.1636583464658; Wed, 10 Nov 2021 14:31:04 -0800 (PST) Date: Wed, 10 Nov 2021 14:30:06 -0800 In-Reply-To: <20211110223010.1392399-1-bgardon@google.com> Message-Id: <20211110223010.1392399-16-bgardon@google.com> Mime-Version: 1.0 References: <20211110223010.1392399-1-bgardon@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC 15/19] 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.rc0.344.g81b53c2807-goog