Re: [PATCH] KVM: TDX: Charge misc cgroup before allocating HKID

From: Vishal Annapurve

Date: Thu Oct 01 2026 - 02:50:50 EST


On Fri, Aug 21, 2026 at 2:52 AM Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx> wrote:
>
> Add a tdx_hkid_alloc() helper that charges the misc cgroup before
> allocating an HKID, and unwind the charge if HKID allocation fails.
>
> __tdx_td_init() currently allocates an HKID before charging the misc
> cgroup. If the charge fails, the error path calls tdx_hkid_free(), which
> uncharges a resource that was never successfully charged. This can make
> the misc-cgroup usage negative.
>
> Charge the cgroup before allocating the HKID. Wrapping both steps in
> tdx_hkid_alloc() makes it the exact counterpart of tdx_hkid_free(), i.e.
> keeps resource allocation and release symmetric, and lets __tdx_td_init()
> simply bail on failure instead of open coding the unwind.
>
> Reported-by: sashiko-bot@xxxxxxxxxx
> Closes: https://lore.kernel.org/all/20260710040153.D8EA71F000E9@xxxxxxxxxxxxxxx
> Closes: https://lore.kernel.org/all/20260718020348.3B4221F000E9@xxxxxxxxxxxxxxx
> Fixes: 7c035bea9407 ("KVM: TDX: Register TDX host key IDs to cgroup misc controller")
> Signed-off-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>

Reviewed-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>