Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Binbin Wu <binbin.wu@linux.intel.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"kas@kernel.org" <kas@kernel.org>,
	"seanjc@google.com" <seanjc@google.com>,
	"Hansen, Dave" <dave.hansen@intel.com>
Subject: Re: [PATCH] KVM: TDX: Charge misc cgroup before allocating HKID
Date: Tue, 25 Aug 2026 10:00:30 +0800	[thread overview]
Message-ID: <48da6c88-aab5-423c-83ab-8e0514e2a344@linux.intel.com> (raw)
In-Reply-To: <35248f8b1859582cd78a31177043c3d61489c19f.camel@intel.com>

On 8/25/2026 5:10 AM, Edgecombe, Rick P wrote:
> On Fri, 2026-08-21 at 17:39 +0800, Binbin Wu 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@kernel.org
>> Closes: https://lore.kernel.org/all/20260710040153.D8EA71F000E9@smtp.kernel.org
>> Closes: https://lore.kernel.org/all/20260718020348.3B4221F000E9@smtp.kernel.org
>> Fixes: 7c035bea9407 ("KVM: TDX: Register TDX host key IDs to cgroup misc controller")
>> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
> 
> As a straightforward bug fix:
> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> 
> But it seems a bit awkward how the keyid allocator is carefully hidden away in
> arch/x86 but the KVM caller does the cgroup maintenance. Hmm, I'd wonder if we
> could move the struct misc_cg pointer to struct tdx_td or otherwise pass it in,
> and make this stuff managed by arch/x86.
> 
> I think the only reason it is KVM managed is that an old cgroup patch got
> applied on top of the base series. The old design from the era of that patch had
> the keyid range exported, and KVM used it to manage the keyid allocation. Then
> when the keyid range got hidden, it resulted in the alloc/free functions getting
> exported. So I wonder if the new tdx_hkid_alloc() should live in arch/x86.
> Otherwise we are doing the thing where KVM just wraps arch/x86 exports to do
> what it needed to do in the first place.

Yes, make sense.

> 
> But not needed for this patch in any case.

It could be a separate cleanup patch.



      reply	other threads:[~2026-08-25  2:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  9:39 [PATCH] KVM: TDX: Charge misc cgroup before allocating HKID Binbin Wu
2026-08-24 21:10 ` Edgecombe, Rick P
2026-08-25  2:00   ` Binbin Wu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48da6c88-aab5-423c-83ab-8e0514e2a344@linux.intel.com \
    --to=binbin.wu@linux.intel.com \
    --cc=dave.hansen@intel.com \
    --cc=kas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox