From nobody Sun Feb 8 23:04:18 2026 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 E6BA9242D6C for ; Fri, 30 Jan 2026 11:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769773015; cv=none; b=tCFLJyc4NwfmIbCvipqqH8HesKCIFO4q6X8X7XqxB2Ro9IHiSxo+jhDqpOX2ZdusadwVSXPJJ0uQ4+nfUbgzVT9pNvDw4lHotmrMVi3cEhEKIa1xtx7YLxXHasg5TeTZ+e56QCHCjncGwV8gWu7VwOzafML/Cfe90EOqcK+QPHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769773015; c=relaxed/simple; bh=6enp7fhWbIxPFVMpL3Gux4c3ByJ3xmD20INyTy7mJRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VMwWZZCO+1umCt+6g/MKj8augcTGJaX5NI5/4VQvTfyCY58xOqBC18V3+rnzmgKvL74LpZlcV4AvfTWzIljuc6Zu4J7IGhyoPyISe+ieN71NDvmXG3wemE49k8+gPp5qAbSpJKB5ugBjVtw30lHulIP4e3zdhTe3Z9Gzq+ArX6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qOVHlo2R; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qOVHlo2R; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qOVHlo2R"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qOVHlo2R" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7870C5BCC1; Fri, 30 Jan 2026 11:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1769773010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UE3VzBbKzKt4j6z1sSUxKExz3XaeTJdPcN4/kigYAas=; b=qOVHlo2RMIwR0UhTV/WNht58wgtmu1bzEEUcT3Y1e4qVKuyIi5vwlkOUmd5p9OiQ1iTTFc QjiBZNewKYZA9rIYBKaIzlU0SfkUdiNlPl7desu6IWceMIMk2EudlGHuiB3IW87uDjhUz+ CHEH1iCBlvGm6oAE2ZuBXqhdTT/da8A= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1769773010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UE3VzBbKzKt4j6z1sSUxKExz3XaeTJdPcN4/kigYAas=; b=qOVHlo2RMIwR0UhTV/WNht58wgtmu1bzEEUcT3Y1e4qVKuyIi5vwlkOUmd5p9OiQ1iTTFc QjiBZNewKYZA9rIYBKaIzlU0SfkUdiNlPl7desu6IWceMIMk2EudlGHuiB3IW87uDjhUz+ CHEH1iCBlvGm6oAE2ZuBXqhdTT/da8A= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C1DB3EA61; Fri, 30 Jan 2026 11:36:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id kjORCdKXfGlmHgAAD6G6ig (envelope-from ); Fri, 30 Jan 2026 11:36:50 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 4/4] x86/mtrr: Drop cache_disable_lock Date: Fri, 30 Jan 2026 12:36:25 +0100 Message-ID: <20260130113625.599305-5-jgross@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260130113625.599305-1-jgross@suse.com> References: <20260130113625.599305-1-jgross@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-Spam-Score: -6.80 X-Spam-Level: Content-Type: text/plain; charset="utf-8" Now that no global state is modified under cache_disable_lock, it can be dropped. All required serialization is done via mtrr_mutex and cpus_read_lock(), ensuring that only one set_mtrr() can be active at any time and that this call can't run concurrently with CPU bringup. The main advantages are a faster boot of machines with lots of CPUs, and avoiding hard lockups on those machines in case mtrr_generic_set_state() takes too long in uncached mode, resulting in other CPUs waiting for seconds to get the cache_disable_lock. This has been seen happening in more than 1% of all boots on an Intel machine with 960 CPUs. With this patch applied boot was always successful. Signed-off-by: Juergen Gross --- I was considering applying a "Fixes:" tag, but this could only reference the initial kernel git commit, as MTRR support predates git, and the problem existed since MTRRs became a thing. Signed-off-by: Juergen Gross --- arch/x86/kernel/cpu/mtrr/generic.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/= generic.c index d49e1837a7af..236b83867bab 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -972,7 +972,6 @@ static void mtrr_enable(struct mtrr_work_state *state) * The caller must ensure that local interrupts are disabled and * are reenabled after cache_enable() has been called. */ -static DEFINE_RAW_SPINLOCK(cache_disable_lock); =20 /* * Cache flushing is the most time-consuming step when programming the @@ -986,17 +985,9 @@ static void maybe_flush_caches(void) } =20 static void cache_disable(struct mtrr_work_state *state) - __acquires(cache_disable_lock) { unsigned long cr0; =20 - /* - * This is not ideal since the cache is only flushed/disabled - * for this CPU while the MTRRs are changed, but changing this - * requires more invasive changes to the way the kernel boots. - */ - raw_spin_lock(&cache_disable_lock); - /* Enter the no-fill (CD=3D1, NW=3D0) cache mode and flush caches. */ cr0 =3D read_cr0() | X86_CR0_CD; write_cr0(cr0); @@ -1020,7 +1011,6 @@ static void cache_disable(struct mtrr_work_state *sta= te) } =20 static void cache_enable(struct mtrr_work_state *state) - __releases(cache_disable_lock) { /* Flush TLBs (no need to flush caches - they are disabled) */ count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); @@ -1035,8 +1025,6 @@ static void cache_enable(struct mtrr_work_state *stat= e) /* Restore value of CR4 */ if (cpu_feature_enabled(X86_FEATURE_PGE)) __write_cr4(state->cr4); - - raw_spin_unlock(&cache_disable_lock); } =20 void mtrr_generic_set_state(void) --=20 2.52.0