From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 116D937474A for ; Wed, 28 Jan 2026 19:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769629895; cv=none; b=eiRNYSlT7q55lfQfYlvoQmTS1+qyaaaM5YMlhInN/J24vG/QZAR7zBNmodbQ9BPSnrKwFOvThsHNhHzSLoqe1WqnPNfissLOpH6DXnptvJWotyWhxYR6etZG07CYFDEE3Zw435TbD0zOhjJ9BDQ/7w/ySMegr+mQd+E7zxw2Gkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769629895; c=relaxed/simple; bh=DoY7z2AtHFkvOI3egT97zlHiNsmzFKz8EJ6ByjjVdYw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QIwVjwq+5vVa8M/oLHYy89Fy632/XTyaLITu8n9EaSXEMd6+iZPtGha4xIEuREpI1IXMQZzCaw+Vcw7/GqaeYUAGfK0XDsDL8veTpcR3FT6wnkxjHe7aiTw68q1DEujNmitDqScn05YWKA94odUPvWzjmkCCs6zBWbeB3DutJ0s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U/aDg1bC; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U/aDg1bC" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a77040ede0so2908035ad.2 for ; Wed, 28 Jan 2026 11:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769629893; x=1770234693; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Bn9lJXHqEiscK/LgfNH9l+HtQHGcpdsiMU6EHRGmE3Q=; b=U/aDg1bCip37l30tGfqGeI1ZM+DuK541Rcz9jpMLuV6a0BgUqQbSyhkOAVVDJbu+4f 8mL/ss/vowprY/yRIuCzl7QSLYDPf/uqFUPkhNi4WYvxJta1FhspjIWIo7S0uANIXlSH CXJAH2L37o/E2wX2c076N38nFDzuUv4ediozzgT4gmGfW7N4xXMGuZH0y2PIMocX9B4j Murp9mmOunkxrGXRHUI1lcweh/BMrjQ6phI5dXnuvmV25coyYfbjT9mStyea1WPE5/FI /SHqBOha2x3et5zPkopMgpvmqMub5cVSW/T5393UFvpT6oc7T/Z1AiM5VEbumli9qnk0 OEJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769629893; x=1770234693; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bn9lJXHqEiscK/LgfNH9l+HtQHGcpdsiMU6EHRGmE3Q=; b=IW5605D+timlIXH6FyPEf2AXTpjbZgx1VZbVAEmFK7x/uUOVwH/EehhRtdV6wTk8qS hfVGSpd9b3uoF9QzZg7HXHUE67cTikB1xpe32Ar1GSUamUKDSExxIMkPVNENkqfaZWld 4Bd7JYa8r+56ICsOlL6+oWYO5FAMyvgNIygcOo3sz3xJKlzyckJsusK0zq4hB/kyGpaV sBD06szSDpnWj+yLhW/VEKO13hFxTPR32jq/S8oyhKxK3akAqb7gC2wJOAQ85YUwaqj0 MoczdFtli/GRQMWrgZIwWGkXlXNsLiQWBMkU8rCc3pEr7K1oypsy4ZdJA84eH/iwdetK oDwg== X-Forwarded-Encrypted: i=1; AJvYcCVg/TwKFXokCoDzx+5aIIG5+ZHUBbjP8f4ttEb2kxVB3R3UxnsocX4E7Qsb0+SeQuK0F/Z3C5asV41Q2LE=@vger.kernel.org X-Gm-Message-State: AOJu0YzsivNz2/THRRnP4lReaQhaQMpoMMUa7U7EFpYedzdG5lDO8aiS 7LvH+sx9kFrMQplprFxNZoGVL1fYMevUPWCJwN24+WXNezfEEPKGAS/SnN2Xro9lfca4elqJbr3 2xTSCXg== X-Received: from plnx15.prod.google.com ([2002:a17:902:820f:b0:2a1:4625:795]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3545:b0:297:c048:fb60 with SMTP id d9443c01a7336-2a870d5d5e3mr58149345ad.25.1769629893346; Wed, 28 Jan 2026 11:51:33 -0800 (PST) Date: Wed, 28 Jan 2026 11:51:31 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260106101646.24809-1-yan.y.zhao@intel.com> <20260106102024.25023-1-yan.y.zhao@intel.com> Message-ID: Subject: Re: [PATCH v3 06/24] KVM: x86/mmu: Disallow page merging (huge page adjustment) for mirror root From: Sean Christopherson To: Yan Zhao Cc: pbonzini@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, rick.p.edgecombe@intel.com, dave.hansen@intel.com, kas@kernel.org, tabba@google.com, ackerleytng@google.com, michael.roth@amd.com, david@kernel.org, vannapurve@google.com, sagis@google.com, vbabka@suse.cz, thomas.lendacky@amd.com, nik.borisov@suse.com, pgonda@google.com, fan.du@intel.com, jun.miao@intel.com, francescolavra.fl@gmail.com, jgross@suse.com, ira.weiny@intel.com, isaku.yamahata@intel.com, xiaoyao.li@intel.com, kai.huang@intel.com, binbin.wu@linux.intel.com, chao.p.peng@intel.com, chao.gao@intel.com Content-Type: text/plain; charset="us-ascii" On Tue, Jan 27, 2026, Yan Zhao wrote: > On Mon, Jan 26, 2026 at 08:08:31AM -0800, Sean Christopherson wrote: > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > > index 321dbde77d3f..0fe3be41594f 100644 > > --- a/arch/x86/kvm/mmu/tdp_mmu.c > > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > > @@ -1232,7 +1232,17 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > > for_each_tdp_pte(iter, kvm, root, fault->gfn, fault->gfn + 1) { > > int r; > > > > - if (fault->nx_huge_page_workaround_enabled) > > + /* > > + * Don't replace a page table (non-leaf) SPTE with a huge SPTE > > + * (a.k.a. hugepage promotion) if the NX hugepage workaround is > > + * enabled, as doing so will cause significant thrashing if one > > + * or more leaf SPTEs needs to be executable. > > + * > > + * Disallow hugepage promotion for mirror roots as KVM doesn't > > + * (yet) support promoting S-EPT entries while holding mmu_lock > > + * for read (due to complexity induced by the TDX-Module APIs). > > + */ > > + if (fault->nx_huge_page_workaround_enabled || is_mirror_sp(root)) > A small nit: > Here, we check is_mirror_sp(root). > However, not far from here, in kvm_tdp_mmu_map(), we have another check of > is_mirror_sp(), which should get the same result since sp->role.is_mirror is > inherited from its parent. > > if (is_mirror_sp(sp)) > kvm_mmu_alloc_external_spt(vcpu, sp); > > So, do you think we can save the is_mirror status in a local variable? Eh, I vote "no". From a performance perspective, it's basically meaningless. The check is a single uop to test a flag that is all but guaranteed to be cache-hot, and any halfway decent CPU be able to predict the branch. >From a code perspective, I'd rather have the explicit is_mirror_sp(root) check, as opposed to having to go look at the origins of is_mirror. > Like this: > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index b524b44733b8..c54befec3042 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1300,6 +1300,7 @@ static int tdp_mmu_split_huge_page(struct kvm *kvm, struct tdp_iter *iter, > int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > { > struct kvm_mmu_page *root = tdp_mmu_get_root_for_fault(vcpu, fault); > + bool is_mirror = root && is_mirror_sp(root); > struct kvm *kvm = vcpu->kvm; > struct tdp_iter iter; > struct kvm_mmu_page *sp; > @@ -1316,7 +1317,17 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > for_each_tdp_pte(iter, kvm, root, fault->gfn, fault->gfn + 1) { > int r; > > - if (fault->nx_huge_page_workaround_enabled) > + /* > + * Don't replace a page table (non-leaf) SPTE with a huge SPTE > + * (a.k.a. hugepage promotion) if the NX hugepage workaround is > + * enabled, as doing so will cause significant thrashing if one > + * or more leaf SPTEs needs to be executable. > + * > + * Disallow hugepage promotion for mirror roots as KVM doesn't > + * (yet) support promoting S-EPT entries while holding mmu_lock > + * for read (due to complexity induced by the TDX-Module APIs). > + */ > + if (fault->nx_huge_page_workaround_enabled || is_mirror) > disallowed_hugepage_adjust(fault, iter.old_spte, iter.level); > > /* > @@ -1340,7 +1351,7 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > */ > sp = tdp_mmu_alloc_sp(vcpu); > tdp_mmu_init_child_sp(sp, &iter); > - if (is_mirror_sp(sp)) > + if (is_mirror) > kvm_mmu_alloc_external_spt(vcpu, sp); >