From nobody Sun Feb 8 23:25:21 2026 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 1E62D7E0E8 for ; Thu, 29 Jan 2026 01:15:33 +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=1769649335; cv=none; b=RvvyESDzhTNVMIWF12sxMgq920fzmZZ6+X/451vQK+mxQxdeLuLZKcsqVJb1m6FDZ1RMZOWAySJDAIFltLnItJ6t7EzB9xZ7XR5oFUqrYba7e2qKx+NhFsjnzrPCbkQ19kP4+5o8oHWppmpxdLDR0FA/2eQ727KP095CcFZkA6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769649335; c=relaxed/simple; bh=rawa+GdPzt/mn/jjYKeF7IrFPzAWvGBv/cL7AH4QpdE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pgSUfu9N1kY822Ym9H052msMnOz4kNUeHG1LTNW0CsAs5VxcIjsHScIQvWRb3JxXKgNxiuyAqapqxD3LG3uVSCGSwy+QNUlCmVeg8f+vMyz5mL0aI7KNbcelPR94kKWGDEKvVQUoJUaxdPmQsyriBpbn6EKP2OoLBVMmSJO2zTs= 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=Izhe0iXb; 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="Izhe0iXb" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-352de7a89e1so337943a91.1 for ; Wed, 28 Jan 2026 17:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769649333; x=1770254133; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=QDz31TgUHSC/pAT7NKm7s9BECEFc0xut5G3SF9CrPBg=; b=Izhe0iXbQIr5wee6Ty1226YDIUoBlPpzttNBH7dTq5yIE9nPjqyZIQHmTEOuvLTZ0Z DU5USJfKNI65e+kSZbJciUHrkGOh7jP1Uvm44E+kWNtfry6oldtYjvuYybSTOArYL/tw WKSY9AeeTrzVRtEZ17cgW760BkgpZfeAAbgkKYjAy9zba70laEZyxzvpY256PAMQdbUs EWdIREoVDcKjGtUeLm8q5jcCm+vlRR3PzB+dwFPHwIinSZOKNePqYhs6K+syXU37umtg h8wfDMGe4DIfFTzcwH0ppnWxLypmYzx32DslYQZ5rJQDf2E2UZbzNQsjtOjHXDKU6jmz C86Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769649333; x=1770254133; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QDz31TgUHSC/pAT7NKm7s9BECEFc0xut5G3SF9CrPBg=; b=OCVv1fzzIFDKW0Unkdq0R8oiS2WHDr3M5Dw5urqOShBIsDbB72sdU+6kg4En+7c7N4 oiglqgQuMaOwvsIJPC6nTMqS4iZbRQ40IjymFpNMZuxQ4Odh+qkSoQ0FN+fY+jmPax9s fFyIL1WBlwXZpUISs/i2xA87pVk8eQR9N44i9VPBAj9BnZV/FjrOEJ7QAQ8FTXOcGYd+ y37acq1I+Wpf6qJuhbmVu0dGwnnM9yqj66/BHLMn+vifGxUFhHdl4WxZMhBJCJtoWjZE 2mQoV/pxHbEnmEvLC0yF4zLuCacZmtn1hU3X4YVW+R0lPRNoXXjEqB7Mt1Si2Lek+Z0z GSZg== X-Gm-Message-State: AOJu0YyJPfaEb8Zima1v2nPRsesthOMGvPg+o8vtRRuV8IKxlwO3WUw7 UQt5rI9JJajR58S+2QaQQ06pcoE8+NBG8Ys6rXUuC2A9sc7K/uLk/onYaoT+w8nMFbteOfteQMW hilX/eg== X-Received: from pjbnh9.prod.google.com ([2002:a17:90b:3649:b0:352:ff8b:ef26]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:50c8:b0:32b:9774:d340 with SMTP id 98e67ed59e1d1-353fedb93fbmr6374509a91.33.1769649333379; Wed, 28 Jan 2026 17:15:33 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 28 Jan 2026 17:14:35 -0800 In-Reply-To: <20260129011517.3545883-1-seanjc@google.com> 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> X-Mailer: git-send-email 2.53.0.rc1.217.geba53bf80e-goog Message-ID: <20260129011517.3545883-4-seanjc@google.com> Subject: [RFC PATCH v5 03/45] KVM: TDX: Account all non-transient page allocations for per-TD structures From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, Kai Huang , Rick Edgecombe , Yan Zhao , Vishal Annapurve , Ackerley Tng , Sagi Shahar , Binbin Wu , Xiaoyao Li , Isaku Yamahata Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Account all non-transient allocations associated with a single TD (or its vCPUs), as KVM's ABI is that allocations that are active for the lifetime of a VM are accounted. Leave temporary allocations, i.e. allocations that are freed within a single function/ioctl, unaccounted, to again align with KVM's existing behavior, e.g. see commit dd103407ca31 ("KVM: X86: Remove unnecessary GFP_KERNEL_ACCOUNT for temporary variables"). Fixes: 8d032b683c29 ("KVM: TDX: create/destroy VM structure") Fixes: a50f673f25e0 ("KVM: TDX: Do TDX specific vcpu initialization") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang Reviewed-by: Rick Edgecombe --- arch/x86/kvm/vmx/tdx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 561461c9d131..5688c77616e3 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -2397,7 +2397,7 @@ static int __tdx_td_init(struct kvm *kvm, struct td_p= arams *td_params, =20 atomic_inc(&nr_configured_hkid); =20 - tdr_page =3D alloc_page(GFP_KERNEL); + tdr_page =3D alloc_page(GFP_KERNEL_ACCOUNT); if (!tdr_page) goto free_hkid; =20 @@ -2405,12 +2405,12 @@ static int __tdx_td_init(struct kvm *kvm, struct td= _params *td_params, /* TDVPS =3D TDVPR(4K page) + TDCX(multiple 4K pages), -1 for TDVPR. */ kvm_tdx->td.tdcx_nr_pages =3D tdx_sysinfo->td_ctrl.tdvps_base_size / PAGE= _SIZE - 1; tdcs_pages =3D kcalloc(kvm_tdx->td.tdcs_nr_pages, sizeof(*kvm_tdx->td.tdc= s_pages), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!tdcs_pages) goto free_tdr; =20 for (i =3D 0; i < kvm_tdx->td.tdcs_nr_pages; i++) { - tdcs_pages[i] =3D alloc_page(GFP_KERNEL); + tdcs_pages[i] =3D alloc_page(GFP_KERNEL_ACCOUNT); if (!tdcs_pages[i]) goto free_tdcs; } @@ -2885,7 +2885,7 @@ static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u6= 4 vcpu_rcx) int ret, i; u64 err; =20 - page =3D alloc_page(GFP_KERNEL); + page =3D alloc_page(GFP_KERNEL_ACCOUNT); if (!page) return -ENOMEM; tdx->vp.tdvpr_page =3D page; @@ -2898,14 +2898,14 @@ static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, = u64 vcpu_rcx) tdx->vp.tdvpr_pa =3D page_to_phys(tdx->vp.tdvpr_page); =20 tdx->vp.tdcx_pages =3D kcalloc(kvm_tdx->td.tdcx_nr_pages, sizeof(*tdx->vp= .tdcx_pages), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!tdx->vp.tdcx_pages) { ret =3D -ENOMEM; goto free_tdvpr; } =20 for (i =3D 0; i < kvm_tdx->td.tdcx_nr_pages; i++) { - page =3D alloc_page(GFP_KERNEL); + page =3D alloc_page(GFP_KERNEL_ACCOUNT); if (!page) { ret =3D -ENOMEM; goto free_tdcx; --=20 2.53.0.rc1.217.geba53bf80e-goog