From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 D0FB74218AE for ; Fri, 6 Feb 2026 14:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770389179; cv=none; b=LC1uF0t9/YPgqMVgzjXeUdicvUEl+Z6m0Xmf2nl+dosPvzD3PKLLY11cvFj4t3DT28ICFY3kqcJy/9v8vH0CNcqdQiuMCnO2pLJ3nVr3XWgzhmLn0WVQ5Yz4/IL8YuoHWl4+85x9vEaBnO5L9JMiqHuItS7uGkhDT+oCHttZK4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770389179; c=relaxed/simple; bh=Z+6pMsVne8koEollpw2BnyiblSLa1jaNRfnGAaiwAJE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BNxdUlJiPWI78+uu06F57eP0FLNFkNLHmiE/JGsfFYKptEHyfh7kJcq4VQe1ClHBMKeiPOUB4MtzFM81FvRTbSl4lUjs+KX2yNIdL1hGWlYiEg3UK0W9U4KMyfEzB3QFCRUiEvB5GECMNSlniE1LEL7NUGLTUiKIZ1jLRubYD74= 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=oizlH8Bu; arc=none smtp.client-ip=209.85.216.73 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="oizlH8Bu" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3547cd89bcfso5088213a91.3 for ; Fri, 06 Feb 2026 06:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770389178; x=1770993978; 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=fWVMjsX7lzriNU4H/gh4s77Y7csX7rcHx58QQQuHKyI=; b=oizlH8Bu/phQ5zbdddMz5k+Tz3wTh1gdZckdW+NLPCmRbX7hn2tJDywGSTI75TGxhT eety7SsmEyy92dkPzs4nUrz5+jn+6+E1Br4eBX2igyqL5AK2GLhTk/8stM7Zktg5ysOp YpeR6DntcinyR9RFiEE1GPjrioY4o0NTT6nXZj64U9SZgkMFsJzq4FxEnxDVGdrJRJsb AMkqGXF3h6b6W6EHPmjfFAm1np2w+MqCFwxNFC1w+Ik9Q4AUrdH4v3zCHjj48wMYYv4R 9pd6bF6FaRKWpywyVvJaX5n0QA8KP4OHvteH1UUdGrobk8UAM6WBVNahX3Jr0sf/V1Cx XvKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770389178; x=1770993978; 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=fWVMjsX7lzriNU4H/gh4s77Y7csX7rcHx58QQQuHKyI=; b=RmAlv/UI8jAeLGJjY00Hl5HI++e9c1LZyBB9gLMs217wEypjWObtos41lTnigC98h/ //dCbba8NJB3IT+wAksAKOtha+60d14/wzVNh2xh0BZnw2qktViaxt4ZTuCNFm7/x7Xw Vp4rfTCqEyJNhCJwZRQymeD8Z23gTtTz4PPGjRfH/SnsH/5Uqh7g8TUZf641LV3qXCkR 8epWaHV2WtdgovgkAfKtwMd57HHh5GCdOsYYDtE97/omI/eG4EHAV1cWJsxm3uxQs7RO xLoPbf6CWrITIXR+boDmOEftoAgfuX+eoGB4CIla1cBb43oqIewpa2YC2uEzX7xevNN4 wcgg== X-Forwarded-Encrypted: i=1; AJvYcCW7p074fRg/QTJRGIHL4+WQXTQ82Rp4qGJCcdRRPGK9ONhKGo/CJHhagkp+Wl1/D+z+FxgoU1JpwwaKJQQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyzfmC0SCPhP9prcy6qR33/O6/uwpVYmKITBNXXq1O9BS7H+6w6 mWteJcS3bEkp6diy8S3CyCo+ScghLlRUsAkbT0NmQUYUCfQBqbeFJD3obTGKo9suHXYQSWpSuW5 2NF72yA== X-Received: from pgbcr4.prod.google.com ([2002:a05:6a02:4104:b0:c65:be00:c5c6]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6e43:b0:38e:9e55:6dee with SMTP id adf61e73a8af0-393ad3a12c3mr3152790637.57.1770389178229; Fri, 06 Feb 2026 06:46:18 -0800 (PST) Date: Fri, 6 Feb 2026 06:46:16 -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: <20260129011517.3545883-1-seanjc@google.com> <20260129011517.3545883-45-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v5 44/45] KVM: x86/mmu: Add support for splitting S-EPT hugepages on conversion From: Sean Christopherson To: Yan Zhao Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Paolo Bonzini , linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, Kai Huang , Rick Edgecombe , Vishal Annapurve , Ackerley Tng , Sagi Shahar , Binbin Wu , Xiaoyao Li , Isaku Yamahata Content-Type: text/plain; charset="us-ascii" On Fri, Feb 06, 2026, Yan Zhao wrote: > On Wed, Jan 28, 2026 at 05:15:16PM -0800, Sean Christopherson wrote: > > Add support for splitting S-EPT hugepages in preparation for converting a > > subset of a hugepage to be shared, as KVM must precisely zap/remove S-EPT > > entries to avoid clobbering guest memory (the lifetime of guest private > > memory is tied to the S-EPT). I.e. KVM needs to first split a hugepage so > > that only the to-be-converted small pages can be zapped. > > > > To avoid unnecessary work, e.g. if only the tail/end page of massive region > > isn't aligned to the conversion, explicitly detect unaligned head and tail > > pages relative to the max page size support by KVM, i.e. head/tail pages > > that will undergo partial conversion. > > > > To support splitting an S-EPT hugepage without a vCPU, add a per-VM PAMT > > cache, along with a mutex to guard the cache. Using a mutex, e.g. versus > > a spinlock, is important at it allows KVM to allocate memory *without* > > dropping the lock, i.e. so that the PAMT cache can be topped-up as needed > > without needed to juggle arch.tdp_mmu_external_cache_lock. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/include/asm/kvm_host.h | 8 +++- > > arch/x86/kvm/mmu/mmu.c | 2 +- > > arch/x86/kvm/mmu/tdp_mmu.c | 72 +++++++++++++++++++++++++++++++-- > > arch/x86/kvm/vmx/tdx.c | 34 +++++++++++++--- > > arch/x86/kvm/vmx/tdx.h | 2 + > > 5 files changed, 107 insertions(+), 11 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index 385f1cf32d70..54dea90a53dc 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1563,6 +1563,12 @@ struct kvm_arch { > > * the code to do so. > > */ > > spinlock_t tdp_mmu_pages_lock; > > + > > + /* > > + * Protect the per-VM cache of pre-allocate pages used to populate the > > + * Dynamic PAMT when splitting S-EPT huge pages without a vCPU. > > + */ > > + struct mutex tdp_mmu_external_cache_lock; > Missing "spin_lock_init(&kvm->arch.tdp_mmu_external_cache_lock);" in > kvm_mmu_init_tdp_mmu(). > > Will check the patch you replied next week. It has the same bug. FWIW, I found and fixed the bug on our internal branch, but I either missed the fixup when synchronizing back to the upstream branch, or I found the issue after posting. @@ -634,6 +642,7 @@ int tdx_vm_init(struct kvm *kvm) struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); tdx_init_pamt_cache(&kvm_tdx->pamt_cache); + mutex_init(&kvm_tdx->pamt_cache_lock); kvm->arch.has_protected_state = true; /*