Intel SGX development
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "Miao, Jun" <jun.miao@intel.com>,
	"jarkko@kernel.org" <jarkko@kernel.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Cc: "linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
	"Du, Fan" <fan.du@intel.com>,
	"challvy.tee@gmail.com" <challvy.tee@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86/sgx: Periodically yield in EPC sanitization to unblock rcu_tasks GP
Date: Fri, 19 Jun 2026 04:08:32 +0000	[thread overview]
Message-ID: <1bf5ef6fd45bbc241bbfdd3d0a4102f78000e7c2.camel@intel.com> (raw)
In-Reply-To: <20260618100432.2280834-1-jun.miao@intel.com>

On Thu, 2026-06-18 at 18:04 +0800, Jun Miao wrote:
> During early boot, ksgxd (Intel Software Guard Extensions Kernel Thread)
> iterates over all post-kexec dirty EPC pages in a tight loop calling
> cond_resched() after each page.  But, on isolated CPUs
> (a common configuration in cloud VMs), cond_resched() never triggers a
> real context switch because TIF_NEED_RESCHED is not set when no competing
> runnable task exists on that CPU.
> 
> synchronize_rcu_tasks(), invoked by BPF LSM during initialization, must
> wait for every task that was running at the start of the grace period to
> pass through a quiescent state (a voluntary sleep or preemption point).
> If ksgxd never leaves the CPU, the rcu_tasks grace period stalls, causing
> boot delays exceeding 60 seconds on machines with large EPC regions.
> 
> Fix this by introducing SGX_SANITIZE_RESCHED_INTERVAL (32768) and forcing
> ksgxd to sleep for one jiffy every that many pages, guaranteeing that an
> rcu_tasks quiescent state is reached in bounded time regardless of CPU
> isolation.  Keep cond_resched() for all other iterations.
> 
> Without this patch, instead, virtual machines (VMs) experience a long OS boot times:

This seems a common problem at the scheduler and RCU layer, but not specific to
SGX.  I originally thought cond_resched() should be able to handle this, but
after reading some history it is not the case.

IIUC, cond_resched_tasks_rcu_qs() was specifically introduced to to address this
issue.  See bde6c3aa9930 ("rcu: Provide cond_resched_rcu_qs() to force quiescent
states in long loops").

Could you try this solution?

  parent reply	other threads:[~2026-06-19  4:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18 10:04 [PATCH] x86/sgx: Periodically yield in EPC sanitization to unblock rcu_tasks GP Jun Miao
2026-06-19  0:41 ` Jarkko Sakkinen
2026-06-19  4:08 ` Huang, Kai [this message]
2026-06-22  4:14   ` Miao, Jun

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=1bf5ef6fd45bbc241bbfdd3d0a4102f78000e7c2.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=challvy.tee@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=fan.du@intel.com \
    --cc=jarkko@kernel.org \
    --cc=jun.miao@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    /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