Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp363689rwe; Thu, 1 Sep 2022 00:11:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR7YXydurJgPWvuP8/CBQN7eRusrCEYmQdfTRnq1hTtqbFsg6kXimvalLxOHCu0J7YAoRTNX X-Received: by 2002:a17:90a:174a:b0:1fd:f273:de03 with SMTP id 10-20020a17090a174a00b001fdf273de03mr7213255pjm.188.1662016310957; Thu, 01 Sep 2022 00:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662016310; cv=none; d=google.com; s=arc-20160816; b=ob4RdZlgzEAOZEI919VzOULsZ47DmBE3qywXlRO+dVaapls2jbvO5KslTd6OFBCaHO 4X08ZZJ8DXiNlaJZ6XMhf8IcmJ2JinHMGZTCaQ+O/M3OfsqVQITuZcHHzezMf/6kRS6P AyHscaBPnuxY4koHYZLQ6vDd76JTFORZ0U4mo1DHi238++K+o6+ydEg9SPTxz/f+GaOx /8bl3yNSnCTdW+Ng4T5owfmNZqT5yP6Ogwv766FusKrURkAgzojZptYkC/sz9zR5K/gW zoDUzP8hOevKzzZ8KU3PeeUnnCLD8uCJPO2Gvk4aFkMG2JDS24uST4T0e+x3rN2AnSgk yXwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=modOtopFoK9+lUBX2cG+c7azHANBWevg1b9zOc8DESs=; b=n3OqQLQgHaE8mnHtVZY2iNfldswvpLdl1hR0qSAAWwdpjx8HQXNfwAy0QCAwxnEnE2 89GnOIg2ywQQaI5FdSINB47NEDaT5IIKoYdRNmn/06/uRv2IEbeCGF2Z6dzaCsVesdkF aipycmkclUwfRhw6uHMSAfdjUhGZQQMBmSDfp7cqBlACk1efzRxlwIkDUZ/lULnwQXlV dMkdDAA89KRdN6uyigtTggy2bh8eK83wxtnWWLKzRjeKSqDCZbLv1vVD3YLcfffXGD31 tgVZMU9jTk7IdXPx3Jo56qAXAezFPJMQqjlghui6dpxEm5RfS7VFtL7hi44nXtrIOPjl LLrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T9ez8zbg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a65564c000000b004068c3147fbsi7547387pgs.543.2022.09.01.00.11.39; Thu, 01 Sep 2022 00:11:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T9ez8zbg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233286AbiIAGs3 (ORCPT + 99 others); Thu, 1 Sep 2022 02:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbiIAGs1 (ORCPT ); Thu, 1 Sep 2022 02:48:27 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319C612140F; Wed, 31 Aug 2022 23:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662014907; x=1693550907; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=peHiaVdSwJ7TxmlSyI5wXME33FtW6AAZToRTJ8ib9Zk=; b=T9ez8zbgUsjCA/kVYPdGUz4sKarrprqAzC7E4NRnudlMDKseisafZF0D 2uLSfqXbTWefLoOxlxfSD2p8c5BzCL7Z0mwYqv1h5Cgc3diz29zZBMNfS CHwByY1RtSraD3o1tdTq/kldAAckpvONMfuZXsJqRrrsJst11pAOfL9To dbLcH4m2aIn4iTz3a6ixrY9jAzQT16MO2/q3162ZUY6Z1iS7beAaVFlTb ELPutnXIMSNfLVfQIHe4SyDiwxiP0iVwCtrU8mHCZltfQs7S8rjfzr3lz Zdj6b9HzoftC5/NxNWzZ94K8GKxWralcywwqWFKFBZFQLBL4H94eZvErv A==; X-IronPort-AV: E=McAfee;i="6500,9779,10456"; a="296416412" X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="296416412" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2022 23:48:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="857720767" Received: from yy-desk-7060.sh.intel.com (HELO localhost) ([10.239.159.76]) by fmsmga006.fm.intel.com with ESMTP; 31 Aug 2022 23:48:24 -0700 Date: Thu, 1 Sep 2022 14:48:24 +0800 From: Yuan Yao 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 Subject: Re: [PATCH v8 038/103] KVM: x86/tdp_mmu: refactor kvm_tdp_mmu_map() Message-ID: <20220901064824.mpjd3xpgal3d3ynu@yy-desk-7060> References: <021cf72b904933f23743d74b2a67341298ae5328.1659854790.git.isaku.yamahata@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <021cf72b904933f23743d74b2a67341298ae5328.1659854790.git.isaku.yamahata@intel.com> User-Agent: NeoMutt/20171215 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 07, 2022 at 03:01:23PM -0700, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > Factor out non-leaf SPTE population logic from kvm_tdp_mmu_map(). MapGPA > hypercall needs to populate non-leaf SPTE to record which GPA, private or > shared, is allowed in the leaf EPT entry. > > Signed-off-by: Isaku Yamahata > --- > arch/x86/kvm/mmu/tdp_mmu.c | 26 +++++++++++++++++++------- > 1 file changed, 19 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 8bc3a8d1803e..90b468a3a1a2 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1145,6 +1145,24 @@ static int tdp_mmu_link_sp(struct kvm *kvm, struct tdp_iter *iter, > return 0; > } > > +static int tdp_mmu_populate_nonleaf( > + struct kvm_vcpu *vcpu, struct tdp_iter *iter, bool account_nx) > +{ > + struct kvm_mmu_page *sp; > + int ret; > + > + WARN_ON(is_shadow_present_pte(iter->old_spte)); > + WARN_ON(is_removed_spte(iter->old_spte)); Why these 2 WARN_ON are necessary here ? In TPD MMU the changes of PTE with shared lock is not surprised and should be handle properly (e.g. the page is freed below for this case), or this function will be called without checking the present and removed state of the pte ? > + > + sp = tdp_mmu_alloc_sp(vcpu); > + tdp_mmu_init_child_sp(sp, iter); > + > + ret = tdp_mmu_link_sp(vcpu->kvm, iter, sp, account_nx, true); > + if (ret) > + tdp_mmu_free_sp(sp); > + return ret; > +} > + > /* > * Handle a TDP page fault (NPT/EPT violation/misconfiguration) by installing > * page tables and SPTEs to translate the faulting guest physical address. > @@ -1153,7 +1171,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > { > struct kvm_mmu *mmu = vcpu->arch.mmu; > struct tdp_iter iter; > - struct kvm_mmu_page *sp; > int ret; > > kvm_mmu_hugepage_adjust(vcpu, fault); > @@ -1199,13 +1216,8 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > if (is_removed_spte(iter.old_spte)) > break; > > - sp = tdp_mmu_alloc_sp(vcpu); > - tdp_mmu_init_child_sp(sp, &iter); > - > - if (tdp_mmu_link_sp(vcpu->kvm, &iter, sp, account_nx, true)) { > - tdp_mmu_free_sp(sp); > + if (tdp_mmu_populate_nonleaf(vcpu, &iter, account_nx)) > break; > - } > } > } > > -- > 2.25.1 >