Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp753235rdb; Sun, 28 Jan 2024 07:30:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaWY3IfJmvxQ0OklK4eybjQSj1oDJVwlE+qUrtBTki+XIMLSBHe0HmA9Wvd84GsqkZCPQ6 X-Received: by 2002:ad4:5ced:0:b0:684:d2a1:990f with SMTP id iv13-20020ad45ced000000b00684d2a1990fmr3572766qvb.40.1706455806495; Sun, 28 Jan 2024 07:30:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706455806; cv=pass; d=google.com; s=arc-20160816; b=Xox/5igBJKjm3EaFV8POSJDX3eiZ4OL3iKRNqRE7tctbNWDtWfZHl4kgGTwSCyqzdh 7stQTr4GBLG60SPLPZ7qIrCN60W92HuEbWL7u42D2AoeflMBPnksWoR248TYxQhR8Dkh bnvgUgV+W0TW/go4FXNnnwW0a4HTx16rlK2sa+wk423SkF2ywgNQS/l/7ss2Z17oTu4O Ew0//HqMtqVSe45Vs6iV9OlRAu+ORfbJDoaREYS+uf9VZS9Vx5hE5ZXYavRzel8ZoxkB QewirIVsUpjji3vOYNgvb6Q45CwwVLYqdbuXVih4onAHFEImpiKRbYkbzTGqeS3BB4LS emPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=TiXchze58qeeiz8DQMFxe3biRcczgHSP2UHL11Jzb/U=; fh=EIee8CzZD92nOFt2BViAL39aXSnRmeUprq6zkqqTptE=; b=Ki20eGXpFEw8b4sQfY7MqaDw+K+FVKGH6LlzRwElG9SAk7VPYzKcERH5k8f7GrjLlP FBMkdknH7pjTWGEynp/icA6GJ9c3PN4p0GrI6SCgYqHiiqpnuzp+PEM0Ud25kCmvmlSl fDNYAFuxPmmsxxrkfMJ8LnBjYjp6B54FBfLURcyDGD9k3ekcoBkwZvAOK1BXzJUC33I3 yUxhgUz115kViyxK9PVy4bEecbjAkhfAXCwq3Xt9p3oilwE4gFmyoGemrsRnfnsPCy2t 5V8PtYuYZM1XPv7Qi1flgt2wKVT7J8GLa6WF2xDg+Gzby0Fza1H7+whHlId7bYOK50Nw GjBA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="i7Kp+V/H"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-41642-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dv4-20020ad44ee4000000b0067fcb749906si5781791qvb.189.2024.01.28.07.30.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 07:30:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41642-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="i7Kp+V/H"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-41642-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 422381C20DFD for ; Sun, 28 Jan 2024 14:12:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12D33241EC; Sun, 28 Jan 2024 14:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i7Kp+V/H" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CCAC2376C; Sun, 28 Jan 2024 14:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451143; cv=none; b=IlOfJGEZ6WMMp7yPCB9KYeEFy+pUHkuF87kxaQbyuTPHF64dj6TvtNS1e4Y8yicdf9wdvKPPwCxARt8iJ3x9qGjKK+IqDfx7hktnx2OGWTPBpnDvdw3zlraOMVdiF2lVPRgwiw762CgV/jZKRNLMY7I9+XJPjZEy4ZUHnMftTVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451143; c=relaxed/simple; bh=PscjwXaV7X6sbLlYnE5Vyfx2zMsk7ANyms1ABld3+MQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=h1+ScO193giRIS2KE9tUr5UmXpDWEkQWnqKhAZHGLU3Zr597f/3rxdRC0FhngQK6BPzP4bKfYKWLsVNJhsDz3KzMfv1v+/Z8DqWLBT0DA5OZTkj1NKEYvgLS/4/IrT45fQqU3bxpW79ebpEraT0eIFTBmH3xbITiF3951370z08= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=i7Kp+V/H; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706451142; x=1737987142; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=PscjwXaV7X6sbLlYnE5Vyfx2zMsk7ANyms1ABld3+MQ=; b=i7Kp+V/HZiLRDjDem8f7tC94GKbniX5nZOE+M3kBUVf2uyJ3zpl0F0r/ 8kI+J8b+Sq21Ec2xfXZAZwMaIvos5FhSrMicaOpRLL4WlH9cql2BVEW9p E6ucPW/M+0IJJyVF1D5nW85NIbZqaRJCEAJ50xsm3l5L3K9dJeysOO0mN aAgKwa9rfZglCvIZLwnd4hESuSxtoIDEvrgj7f1ykwrdXDCTJBBFg6/da nLu7pkPqGrx/MBO+kX5jS9VzrII8Pgcqmfmg6oJxsidsgS8fI7rhiAPR3 s16CVh4d4IwTEQ1ptF9efaJvbfzetlYAIeSNxxLGajxEQxym93dhkHpsA w==; X-IronPort-AV: E=McAfee;i="6600,9927,10966"; a="10162187" X-IronPort-AV: E=Sophos;i="6.05,220,1701158400"; d="scan'208";a="10162187" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 06:12:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10966"; a="1118697076" X-IronPort-AV: E=Sophos;i="6.05,220,1701158400"; d="scan'208";a="1118697076" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.93.8.92]) ([10.93.8.92]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2024 06:12:15 -0800 Message-ID: <0f1dda5e-dd70-44b9-afd0-90a54abc086b@linux.intel.com> Date: Sun, 28 Jan 2024 22:12:13 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 041/121] KVM: x86/mmu: Allow per-VM override of the TDP max page level To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson References: From: Binbin Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/23/2024 7:53 AM, isaku.yamahata@intel.com wrote: > From: Sean Christopherson > > TDX requires special handling to support large private page. For > simplicity, only support 4K page for TD guest for now. Add per-VM maximum > page level support to support different maximum page sizes for TD guest and > conventional VMX guest. > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Acked-by: Kai Huang > --- > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/mmu/mmu.c | 2 ++ > arch/x86/kvm/mmu/mmu_internal.h | 2 +- > 3 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 430d7bd7c37c..313519edd79e 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1283,6 +1283,7 @@ struct kvm_arch { > unsigned long n_requested_mmu_pages; > unsigned long n_max_mmu_pages; > unsigned int indirect_shadow_pages; > + int tdp_max_page_level; Although only TDX need special handling for now, and TDX always use TDP, but it doesn't necessarily to be TDP, right? When the value is assigned to kvm_page_fault.max_level, it is also used for non-TDP code path. > u8 mmu_valid_gen; > struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; > struct list_head active_mmu_pages; > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 54d4c8f1ba68..e93bc16a5e9b 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -6307,6 +6307,8 @@ void kvm_mmu_init_vm(struct kvm *kvm) > > kvm->arch.split_desc_cache.kmem_cache = pte_list_desc_cache; > kvm->arch.split_desc_cache.gfp_zero = __GFP_ZERO; > + > + kvm->arch.tdp_max_page_level = KVM_MAX_HUGEPAGE_LEVEL; > } > > static void mmu_free_vm_memory_caches(struct kvm *kvm) > diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h > index 0443bfcf5d9c..2b9377442927 100644 > --- a/arch/x86/kvm/mmu/mmu_internal.h > +++ b/arch/x86/kvm/mmu/mmu_internal.h > @@ -296,7 +296,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, > .nx_huge_page_workaround_enabled = > is_nx_huge_page_enabled(vcpu->kvm), > > - .max_level = KVM_MAX_HUGEPAGE_LEVEL, > + .max_level = vcpu->kvm->arch.tdp_max_page_level, > .req_level = PG_LEVEL_4K, > .goal_level = PG_LEVEL_4K, > };