Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3229936pxb; Tue, 20 Apr 2021 03:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzAqHev7+c6JSGlwcH2K71D/FCjl7qUrDWApdKeUJQ+3V0kBi+e3XnyGdU2kuAd10w+RdA X-Received: by 2002:a17:906:28d4:: with SMTP id p20mr10948240ejd.552.1618915412306; Tue, 20 Apr 2021 03:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618915412; cv=none; d=google.com; s=arc-20160816; b=kKr8fBPJMtVtVVaM9mfVdsdwmS58AcSIraANPiNpOMPf5FjwQhmcHaVyPP47Hizezq +PLJ+v6EjFiuinl+RYSCMpRuv6sr/+1KgU1QtPGdKp7Rtg18hg5DupXP4vwP1MonzNVc PeKFPJto8LC+XP0TVjMH2dur6vOH+RGKhG56nhUqNRk8qOXhAAsmPYx7AvgGMZEL3wmw J9WkTaLSHLldU4WF0GZg+4yFPRM2/yfXZ6sUdkvofly03nXf5zuThFoNBpmvdymdU35l XozV6HeLf8lPiVkdQaZVpuZtR0GzZUSoUK40Fubo89F+9OSI6IYkuQHqhgjyhQfzx8M2 CzgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=TZ6zH/+MEVGhH5bNTmZ86Pc/3qtsTq9WByYPpPk/U1E=; b=neplR2tK+xyI42kSabIkHplFh4Ej1+RtV8oYMQEQTwu8exRzPSqr1caBmSjrqzZ2FM 11oxAIMhyR7b4OlLBzONxiZ9oC/+ar7gUmkjsasnMFCZfZhmqufO/jqpQ+eWZWTLitNu JR3n7dxPKL5MJRoeUUTrJ5PgofohO2mZNO1L9C1XAxkgeoqOyIEXGAJeJd1O+WmtCeR3 8rOZHGLhMUafTJlmjytG0FG1FztbK/10JV0eWR+Q3nfC03rYySTHgDw86IbWEZO/ak+D Ldm3bHPAvaPjP/fSDxf1Ca/sPutlBKuUReh2tWxg8kkburPyCqyhtrchKrxCnnx0TPyt jO7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rv16si14540690ejb.283.2021.04.20.03.43.09; Tue, 20 Apr 2021 03:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbhDTKmV (ORCPT + 99 others); Tue, 20 Apr 2021 06:42:21 -0400 Received: from mga17.intel.com ([192.55.52.151]:34980 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbhDTKmP (ORCPT ); Tue, 20 Apr 2021 06:42:15 -0400 IronPort-SDR: TSVSRA43u1ky5eM30/77mR30WZhJVaambscMIBU/TYbNaUrpL1pHqltewNv2C9Rxcc/iPtgSNZ pM2iwsVZmvWw== X-IronPort-AV: E=McAfee;i="6200,9189,9959"; a="175590753" X-IronPort-AV: E=Sophos;i="5.82,236,1613462400"; d="scan'208";a="175590753" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 03:41:44 -0700 IronPort-SDR: O6ZDerzSrXnynP9aZdQoiGklnGaYhDwGmlS6BzkYHvDo4trYaAUoAwZqXlUvM3AiBG3UV4alrm oCZ4u2TdoE5Q== X-IronPort-AV: E=Sophos;i="5.82,236,1613462400"; d="scan'208";a="426872768" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 03:41:44 -0700 From: Isaku Yamahata To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson Cc: isaku.yamahata@gmail.com, Isaku Yamahata Subject: [RFC PATCH 03/10] KVM: x86/mmu: make direct_page_fault() receive single argument Date: Tue, 20 Apr 2021 03:39:13 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert direct_page_fault() to receive struct kvm_page_fault instead of many arguments. No functional change is intended. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu.h | 10 ++++++++++ arch/x86/kvm/mmu/mmu.c | 32 ++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 7fcd9c147e63..fa3b1df502e7 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -112,6 +112,11 @@ struct kvm_page_fault { gpa_t cr2_or_gpa; u32 error_code; bool prefault; + + /* internal state */ + gfn_t gfn; + bool is_tdp; + int max_level; }; static inline void kvm_page_fault_init( @@ -122,6 +127,11 @@ static inline void kvm_page_fault_init( kpf->cr2_or_gpa = cr2_or_gpa; kpf->error_code = error_code; kpf->prefault = prefault; + + /* default value */ + kpf->is_tdp = false; + kpf->gfn = cr2_or_gpa >> PAGE_SHIFT; + kpf->max_level = PG_LEVEL_4K; } int kvm_tdp_page_fault(struct kvm_page_fault *kpf); diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 46998cfabfd3..cb90148f90af 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3681,13 +3681,18 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn, return false; } -static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, - bool prefault, int max_level, bool is_tdp) -{ +static int direct_page_fault(struct kvm_page_fault *kpf) +{ + struct kvm_vcpu *vcpu = kpf->vcpu; + gpa_t gpa = kpf->cr2_or_gpa; + u32 error_code = kpf->error_code; + bool prefault = kpf->prefault; + int max_level = kpf->max_level; + bool is_tdp = kpf->is_tdp; bool write = error_code & PFERR_WRITE_MASK; bool map_writable; - gfn_t gfn = gpa >> PAGE_SHIFT; + gfn_t gfn = kpf->gfn; unsigned long mmu_seq; kvm_pfn_t pfn; hva_t hva; @@ -3750,10 +3755,12 @@ static int nonpaging_page_fault(struct kvm_page_fault *kpf) pgprintk("%s: gva %lx error %x\n", __func__, kpf->cr2_or_gpa, kpf->error_code); + kpf->cr2_or_gpa &= PAGE_MASK; + kpf->is_tdp = false; + kpf->max_level = PG_LEVEL_2M; + /* This path builds a PAE pagetable, we can map 2mb pages at maximum. */ - return direct_page_fault(kpf->vcpu, kpf->cr2_or_gpa & PAGE_MASK, - kpf->error_code, - kpf->prefault, PG_LEVEL_2M, false); + return direct_page_fault(kpf); } int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code, @@ -3791,21 +3798,22 @@ EXPORT_SYMBOL_GPL(kvm_handle_page_fault); int kvm_tdp_page_fault(struct kvm_page_fault *kpf) { - u32 gpa = kpf->cr2_or_gpa; + struct kvm_vcpu *vcpu = kpf->vcpu; int max_level; + kpf->is_tdp = true; for (max_level = KVM_MAX_HUGEPAGE_LEVEL; max_level > PG_LEVEL_4K; max_level--) { int page_num = KVM_PAGES_PER_HPAGE(max_level); - gfn_t base = (gpa >> PAGE_SHIFT) & ~(page_num - 1); + gfn_t base = kpf->gfn & ~(page_num - 1); - if (kvm_mtrr_check_gfn_range_consistency(kpf->vcpu, base, page_num)) + if (kvm_mtrr_check_gfn_range_consistency(vcpu, base, page_num)) break; } + kpf->max_level = max_level; - return direct_page_fault(kpf->vcpu, gpa, kpf->error_code, kpf->prefault, - max_level, true); + return direct_page_fault(kpf); } static void nonpaging_init_context(struct kvm_vcpu *vcpu, -- 2.25.1