From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796052221; b=wuZhVqwGXHeLHyelPoBmJRSGnRlscjKY3Rbs2EBRMEx5R5DGf4Kt/vCx2jJAJfA8lT2J nUgMJ9DYfnQBeOo/ukALmIKleejhJZBjtk0LVk05WM/4SAM0Jw+OwLF8dgp3ePI8VIACU 4W/NUVMawopsOTl0dt79VvxoAh6QCUnOAiySQIhh7yUzXern5JI/Xdc4ojWWiYvtg+5dd 9hTmD6iCymz5bfSSD1RcMR3joaJaQhcMW3EMLSFpTei7dQa6w5OFczvkgSn/m7sao85Go SHU+m54OvCfNfYqzPKp7sYi2VgTtOcdG6scqF4aIA9fYGrnsY6kWg+qKABE3P0LQPjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796052221; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=JuUzZKn8upy+WN77AsxdxFc8cLGuFmkqiui8mYzAzBk=; b=C39o3CHQUFyb3UfzI4cudubVNBGi1ke0+REolc4J8ENlhYvjWj8Aayhi6aSpELNyBW1x xnLipXWxE7MIEl91CMlyTk4bjuprugj5rf1tZbNVrjXk0XmGvwN7uWQt5xST5hp5cNN8X VHbuB8CJv52MtSIHtKV2wSpU2H+VTjInAPksz54bsDVhtYNzF6v4Ky5KLsGBorO3vu5X+ X880mMtfyZUdCLNAFeCtFZ0B9esHO2cP78n2ssFGU+xgL6zDN7xkFWnhJLZZvWEh8UfAo P03cbepYfLqcQPjQ3B5hABqVNLFoOxkBroDMbeL54zHctP2WgtuJ2JrP4kvSe8kn+Jg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="BRSUC/Yk"; arc=none smtp.remote-ip=209.85.221.70 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96CA1606A32C for ; Mon, 30 Nov 2026 15:23:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 96CA1606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=BRSUC/Yk Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48fcb657f32so6300465f8f.2 for ; Mon, 30 Nov 2026 07:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796052220; x=1796657020; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JuUzZKn8upy+WN77AsxdxFc8cLGuFmkqiui8mYzAzBk=; b=BRSUC/YkzpBgXOl6jrxAkgfBMO2oahig0wX1SJOIOvW75e2vtZ5Aoa3pifct9Fceyx WRvGvWIwWRlJq9zMjHo3pEcyvDo/nKzDN7CZeDQmwR0Uz13+bZHt1Ojn6qnS48qn7D7C vGhjC3sL9tttc1BvWqOvIuzk3TJK3gqYs8GgReouoyb+/mSjlqFgnAP05Jwo1BxnN1GS VTaCIeNqjrrtbrp6qv8/gEdFoBEroNlPTpU4e0zaUC2gULn8cNcFNCGggY2VUhznmiIv R6l2QHyWh2fJGnn0PW4F/OmzGEyvFFWPsM7Wg+H9phFrch1yoKGAdik3XICdxIC8KRpl HwAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796052220; x=1796657020; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JuUzZKn8upy+WN77AsxdxFc8cLGuFmkqiui8mYzAzBk=; b=HCiI9ZDNnam2wuIdwpSBhGuOymxUL9b37epBx+SedMpzR3U6qx92lVPqB67zmnyP6E AAs4mQkJkMlpfmcEJolReTTmbAb/x2Bg3lIAuOV4Y96yaQH9OHxfVMuHsFLIGshyMNWj jhda3EdUMY7sT80dPTxa33+AITjZbbguqYKzlFO6DOV4jSNZXgKn0658kfFhk5SoeINk uV7HsjjQxvS54E4eyrpMUVz6rh6a/LupIjiX0P5Skb+ZIGG63jrfyuUSQaMT2qdni/l8 XcioPmsCWGcqSA6mRlmomkzkCXKwixam2kQoqzZF1sBM1Y2zMlavnALRMrN+MwOJLMbx F9HQ== X-Forwarded-Encrypted: i=1; AL+hErEG2wfG0WEGtEaB6ztavoFaVoZfIxI3RTovThC1+061Qpm9nPteuiKh9lP7tJ4v3bWjWq5JWw86sYHnd244QKSqzIY=@vger.kernel.org X-Gm-Message-State: APuU4Z/sBXiyjChhJppx7BpkzubCx2QGN9gjPzIfhbGLXW0OyxgsLNjL kI3rcHiOIley9SNQQlpGhc4DN6OVo9v+QI8us54NzIV4P8sGHzQm+PYlQRoUIFqrKYqAy4n4dkj br8kYh6IlhQZdQ/VvsxcPfA== X-Received: from wmbz25.prod.google.com ([2002:a05:600c:c099:b0:4a1:e676:5ad4]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3508:b0:4b2:3c81:d1 with SMTP id 5b1f17b1804b1-4bb88826921mr686136025e9.5.1796052219860; Mon, 30 Nov 2026 07:23:39 -0800 (PST) Date: Mon, 30 Nov 2026 15:23:34 +0000 In-Reply-To: <20261130152335.2304881-1-vdonnefort@google.com> X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261130152335.2304881-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130152335.2304881-2-vdonnefort@google.com> Subject: [PATCH v1 1/2] ring-buffer: Use irqsave for the reader lock in ring_buffer_poll_remote From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Cc: mathieu.desnoyers@efficios.com, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort , Sashiko Content-Type: text/plain; charset="UTF-8" Calling rb_wakeups with the reader lock held but interrupts enabled can lead to a deadlock: the irq_work might run on the same CPU, but will block when acquiring that very same reader spinlock. First, rb_wakeups does not even need to be called under the reader lock. Move the function outside of the reader lock scope. Second, the reader lock must be acquired with IRQs disabled anyway. Use the irqsave variant of the spinlock. Fixes: 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260602171146.2238998-1-vdonnefort%40google.com # patch 8 Signed-off-by: Vincent Donnefort --- kernel/trace/ring_buffer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index a5a0adc934fa..9a268361762a 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -6928,14 +6928,19 @@ int ring_buffer_poll_remote(struct trace_buffer *buffer, int cpu) struct ring_buffer_per_cpu *cpu_buffer; if (cpu != RING_BUFFER_ALL_CPUS) { + bool wakeup; + if (!cpumask_test_cpu(cpu, buffer->cpumask)) return -EINVAL; cpu_buffer = buffer->buffers[cpu]; - guard(raw_spinlock)(&cpu_buffer->reader_lock); - rb_read_remote_meta_page(cpu_buffer); - if (rb_num_of_entries(cpu_buffer)) + scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) { + rb_read_remote_meta_page(cpu_buffer); + wakeup = rb_num_of_entries(cpu_buffer); + } + + if (wakeup) rb_wakeups(buffer, cpu_buffer); return 0; @@ -6950,7 +6955,7 @@ int ring_buffer_poll_remote(struct trace_buffer *buffer, int cpu) for_each_buffer_cpu(buffer, cpu) { cpu_buffer = buffer->buffers[cpu]; - guard(raw_spinlock)(&cpu_buffer->reader_lock); + guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock); rb_read_remote_meta_page(cpu_buffer); } -- 2.56.1.839.g22a8290db9-goog