From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 178AF414DF4 for ; Wed, 22 Jul 2026 19:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784749231; cv=none; b=CFuM4JuiX52vQkWcc6vVacV6EJCpJQjwRYwEsdnc6wxmo9HxVSH9uahOu40mZXopQWb9bb1flJRpMJNv2q6VAsgvPp9HzZsrMXWu2WGFRi4zUaxdk1ZXEEx3atEo7Q7UU91L7Xz9XEi0Rlri7Q4XOMzP30eYyPFx+oppxCuwNtY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784749231; c=relaxed/simple; bh=nyBkYgKwOn4jVc5C8Fouc1FeTmY3h02EMe0OQ5ytqsI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Gls8snYm61rK/fdSQnRURLtpDCBuZVqxmF7U4LgMvxPO4usLYA5+zxjrpEqto/MXukG+YvUjN3I7FDL6jN0fhetWvyoi8vj99i3VFGjq5ghIEuzfPq74K0ymKTQ1auPpfjjfgsAm/Wt9jOZtAt5akI5PbKZsBJ3ewqOKYIgdvBI= 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=hovqb5P3; arc=none smtp.client-ip=209.85.210.197 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="hovqb5P3" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-84885a4fcabso10548655b3a.3 for ; Wed, 22 Jul 2026 12:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784749229; x=1785354029; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Ptao9s40NBhMm9qoNoLOa2VZyEW6G4SG8hWVVOs/sao=; b=hovqb5P3n8VEqY52HNZccABZ9r0eeTb7CNfrnv5TVVoQkGIanFwTwexRUwgjHgPApg DGB2wDB6xXbra5LEz4UL0Y7qJRiv5vR+/i9JArTfesPNvf+gJjKpnNamlGuK539oakHz M3uv5FqGreIid2H4tlUK4bSkVxgAE8pVoVa2NyqqsO29PF8u94hUgHcfn8R9Cw7/2/PF hHxP01e74ara8BggeSQOMMD/H8mltABdBNXzJI89LVSwjYLtpoCkJAUxcGIL88XbTPHc bjEXrTSDRj2GYVp3x0rglPMtmzr0LvFRTH26JWu/If/DLPrTWMa426GRXsnETvEUt54g JnlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784749229; x=1785354029; h=content-type: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:content-type; bh=Ptao9s40NBhMm9qoNoLOa2VZyEW6G4SG8hWVVOs/sao=; b=JAU0hYhVjqHQxtqmm/UJa71lRVu6b6+skR7keJUiJMWnaG6IujKbd49dywrtQf6F1h PvIDKKnkqj4iDHwG3XG5qO3wMo4B9D/5Trt0/HWwGmQ75XpsxX6S0FF7tY4eUiJUW8vz wbU/+PWE4uvvi9XZMo0ab7yogGY9YE2wUgrCPQrQnRYwHYARdqy+MruvUU3w8Vtn6RLZ mYJvNwJ1tEoFymVvnPChqthF6zY6OEJR64JvBfQo3yQFL1DR+wzNvBRlIPbKv+cLz9pc /K0y0/94mJ9O8Z9QCi5aRCv02fHMXxeBBMVEb4n7ZIEnWkQ/Zo4F6xxFHp2b7UWplhp6 3FkQ== X-Forwarded-Encrypted: i=1; AHgh+RqibKShKS1Y4bmQJQT6lqrEn5Ymyk2LkELHa9gwf5V2HkqbTaQRk2IgPbowawyqcx0gE156i0WURNjRD3Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yx23U+SORORfVzFIQVZOaLt3y3GZwreeMzyYbrOi4OKtMFrpTao 2oMo5JqgPT1IDJmxy7UIonhFuDs/4DqUakSfrtIvnJurDysorCFXddQ0jlIB+ZWvamXjUTPmtn5 tofd9eg== X-Received: from pfbhj6.prod.google.com ([2002:a05:6a00:8706:b0:847:840c:ba17]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:299a:b0:845:c6fc:2821 with SMTP id d2e1a72fcca58-84e2b8a6521mr317062b3a.22.1784749228959; Wed, 22 Jul 2026 12:40:28 -0700 (PDT) Date: Wed, 22 Jul 2026 12:40:28 -0700 In-Reply-To: <20260718014500.2231262-7-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260718014500.2231262-1-rick.p.edgecombe@intel.com> <20260718014500.2231262-7-rick.p.edgecombe@intel.com> Message-ID: Subject: Re: [PATCH v7 06/11] KVM: TDX: Allocate PAMT memory for TD and vCPU control structures From: Sean Christopherson To: Rick Edgecombe Cc: bp@alien8.de, dave.hansen@intel.com, hpa@zytor.com, kas@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, nik.borisov@suse.com, pbonzini@redhat.com, tglx@kernel.org, vannapurve@google.com, x86@kernel.org, chao.gao@intel.com, yan.y.zhao@intel.com, kai.huang@intel.com, tony.lindgren@linux.intel.com, binbin.wu@intel.com, Binbin Wu Content-Type: text/plain; charset="us-ascii" On Fri, Jul 17, 2026, Rick Edgecombe wrote: > From: "Kirill A. Shutemov" > > Use control page helpers for allocating and freeing TD control structures, > such that these operations can work for Dynamic PAMT. > > The TDX module tracks some state for each page of physical memory that it > might use. It calls this state the PAMT. It includes separate state for > each page size a physical page could be utilized at within the TDX module > (1GB, 2MB, 4KB). In Dynamic PAMT, only the 4KB page size state is > allocated dynamically. So the kernel must ensure PAMT backing is installed > for any 4KB page being gifted to the TDX module, and must tear down the > backing when all associated gifted pages are reclaimed. > > TD scoped control pages (TDR, TDCS) and vCPU scoped control pages (TDVPR, > TDCX) are all handed to the TDX module at 4KB page size and are therefore > subject to this requirement. Replace the raw alloc_page()/__free_page() > calls for these pages with tdx_alloc/free_control_page(). > > Switching between special Dynamic PAMT operations or normal page > alloc/free operations is handled internally in > tdx_alloc/free_control_page(). So don't check for Dynamic PAMT around these > calls. Just call them unconditionally. Similarly, drop the NULL checks > before freeing, as tdx_free_control_page() handles NULL internally. > > No functional change intended when Dynamic PAMT is not in use. > > Signed-off-by: Kirill A. Shutemov > [sean: handle alloc+free+reclaim in one patch] > Signed-off-by: Sean Christopherson > [rick: enhance log, reviewing, rebase, with help from AI tooling] > Signed-off-by: Rick Edgecombe > Reviewed-by: Binbin Wu > Reviewed-by: Chao Gao > Reviewed-by: Yan Zhao > Reviewed-by: Tony Lindgren > --- Acked-by: Sean Christopherson