From nobody Tue Dec 2 00:00:56 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37118301716 for ; Tue, 25 Nov 2025 21:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764107451; cv=none; b=O7wU5jnEnVy0hhBKKSSNX6mnPgAT19TwjRVYrSINA7PeNUb5xwKlbkZCtRzu3/n1S1tlSMXS5G3bKzgwQXHvBMx8UFJh+iKMF0fEaabSraoXCK2k1wqObPf9oF8vv1hmfdHIkjaRborDK3gmZJ5X8xWmzNiCxg3OB6pmziKUqzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764107451; c=relaxed/simple; bh=LMHPM9g/VVFhnRSZKndTGAcfxOdyXAS7yd1vDevPxh0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=SOB1bGKRpcDc86LdlwqKjhUnphwg9GSj7L/FawokW+ZQJ4okVbXylk3HORy8O+alK+DyZcxY2lHpDLiDZuDnYaDwTNTQFnOVLhgsVoVHa/b//rTZzuyCF09p5NRPKzhruJZuDfrJ7N+NVSk3uzKPUIlVEhJLMmgr/vRYErxuC88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3jHhdBAH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GrNJ7QKh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3jHhdBAH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GrNJ7QKh" Message-ID: <20251125214631.108458942@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1764107448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ZQ2ti2it9cvg0DD+5Wv2cs/vokli8Shax7DqKCeRSh4=; b=3jHhdBAHfjLsr4i4ga3mSx6tkr8DuF3yPszywziRNz1Ngibz8IlXWAq6bmRUGLGfMMdnIW /VMoWtqx2wfvtVrtsF/OcLgFwBaivpKeP/5yYqEPxcyw9lP7AkRNP3F9vSY4PmGshCHaRB fjg+zwyV8r8563Kvgqbv/3/C6x+Up7lpGmnhqIQTTsFK4XcIK9Ap4UbBJcRoi2GiTc2/GW F1OzrnFybbvUv/ctMxIgoqNMJu2PV/yP4kwXf0AnlNYluoXg6jzdkdzXJzmP/ImhRserKt X6ryj+jPRQIslq5X3qJWo5W2ZH0k0H5HHxEuntl8OcViBD4zuxS8d+pmbFDBtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1764107448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ZQ2ti2it9cvg0DD+5Wv2cs/vokli8Shax7DqKCeRSh4=; b=GrNJ7QKhLLfCeQg4aX+scUs3XjdW5YwF/vqCh9cl2TGdTBa1lOlTznA9Dv/UsuOAH+g3Ra CVD//elrg3uobtCQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Luigi Rizzo Subject: [patch V2 2/3] x86/irq: Cleanup posted MSI code References: <20251125214446.766096680@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Tue, 25 Nov 2025 22:50:47 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make code and comments readable and use __this_cpu..() as this is guaranteed to be invoked with interrupts disabled. Signed-off-by: Thomas Gleixner --- V2: Use __this_cpu...() - Luigi --- arch/x86/kernel/irq.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -400,11 +400,9 @@ static DEFINE_PER_CPU_CACHE_HOT(bool, po =20 void intel_posted_msi_init(void) { - u32 destination; - u32 apic_id; + u32 destination, apic_id; =20 this_cpu_write(posted_msi_pi_desc.nv, POSTED_MSI_NOTIFICATION_VECTOR); - /* * APIC destination ID is stored in bit 8:15 while in XAPIC mode. * VT-d spec. CH 9.11 @@ -448,8 +446,8 @@ static __always_inline bool handle_pendi } =20 /* - * Performance data shows that 3 is good enough to harvest 90+% of the ben= efit - * on high IRQ rate workload. + * Performance data shows that 3 is good enough to harvest 90+% of the + * benefit on high interrupt rate workloads. */ #define MAX_POSTED_MSI_COALESCING_LOOP 3 =20 @@ -459,11 +457,8 @@ static __always_inline bool handle_pendi */ DEFINE_IDTENTRY_SYSVEC(sysvec_posted_msi_notification) { + struct pi_desc *pid =3D __this_cpu_ptr(&posted_msi_pi_desc); struct pt_regs *old_regs =3D set_irq_regs(regs); - struct pi_desc *pid; - int i =3D 0; - - pid =3D this_cpu_ptr(&posted_msi_pi_desc); =20 /* Mark the handler active for intel_ack_posted_msi_irq() */ __this_cpu_write(posted_msi_handler_active, true); @@ -471,25 +466,25 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_posted_msi irq_enter(); =20 /* - * Max coalescing count includes the extra round of handle_pending_pir - * after clearing the outstanding notification bit. Hence, at most - * MAX_POSTED_MSI_COALESCING_LOOP - 1 loops are executed here. + * Loop only MAX_POSTED_MSI_COALESCING_LOOP - 1 times here to take + * the final handle_pending_pir() invocation after clearing the + * outstanding notification bit into account. */ - while (++i < MAX_POSTED_MSI_COALESCING_LOOP) { + for (int i =3D 1; i < MAX_POSTED_MSI_COALESCING_LOOP; i++) { if (!handle_pending_pir(pid->pir, regs)) break; } =20 /* - * Clear outstanding notification bit to allow new IRQ notifications, - * do this last to maximize the window of interrupt coalescing. + * Clear the outstanding notification bit to rearm the notification + * mechanism. */ pi_clear_on(pid); =20 /* - * There could be a race of PI notification and the clearing of ON bit, - * process PIR bits one last time such that handling the new interrupts - * are not delayed until the next IRQ. + * Clearing the ON bit can race with a notification. Process the + * PIR bits one last time so that handling the new interrupts is + * not delayed until the next notification happens. */ handle_pending_pir(pid->pir, regs);