From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EF89D18B48F; Tue, 30 Jul 2024 16:07:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722355631; cv=none; b=VeXhBQvB2Gqp8prplPEZtoVK4vLzc9kaV5c3FCZOQc4axzDBSbNA/brpmgBnacHxo03pEsPhkICUpQvx/0BPHSm2mRTl76r/4iwlxxYvFaFtBLn9hb6Z/FKikSKLZB3KePjZq62srR6dSUskdsrQF0W91cbpyrfhNyhZmpc4kIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722355631; c=relaxed/simple; bh=1DNhpFBa/GAudhC++w/xmVJFdDF+xUCuB9GQOF6mLP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rG0NgGXQbjjIyFDYQ3NLe3MiJMawzX09GqzRzLZkKaJvmoy0AbjdR3Usc/69HqdTwkp1XYhziuFP+5UbjxB8c0eIWd8vgF4lOu2LyVC4GyQ7yGe4JVpuHkem4PUnNadOR3eFQYhstxp/jXa/q6KsCKIPKLYMTbd67TPMRnGTJIo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jawgDb5R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jawgDb5R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58F9DC32782; Tue, 30 Jul 2024 16:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722355630; bh=1DNhpFBa/GAudhC++w/xmVJFdDF+xUCuB9GQOF6mLP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jawgDb5RgFamG4eJGP3YofQX5wFduBaOyu9wdlXVuW65duRF9/nyfoa15cnu/drvc ZXuQcPEcTPU0omhbk2cIsvaOzF9oJPWxw1GEagW30f2xrh4krsEH+H0FSCkFafQPjv Y52Nr67zqvj+zvTWcLySmDXNhKACwRhzrGn6ZqX0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Adrian Hunter , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 6.1 112/440] perf: Fix default aux_watermark calculation Date: Tue, 30 Jul 2024 17:45:45 +0200 Message-ID: <20240730151620.266011900@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730151615.753688326@linuxfoundation.org> References: <20240730151615.753688326@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter [ Upstream commit 43deb76b19663a96ec2189d8f4eb9a9dc2d7623f ] The default aux_watermark is half the AUX area buffer size. In general, on a 64-bit architecture, the AUX area buffer size could be a bigger than fits in a 32-bit type, but the calculation does not allow for that possibility. However the aux_watermark value is recorded in a u32, so should not be more than U32_MAX either. Fix by doing the calculation in a correctly sized type, and limiting the result to U32_MAX. Fixes: d68e6799a5c8 ("perf: Cap allocation order at aux_watermark") Signed-off-by: Adrian Hunter Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20240624201101.60186-7-adrian.hunter@intel.com Signed-off-by: Sasha Levin --- kernel/events/ring_buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 45965f13757e4..f3a3c294ff2b3 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -683,7 +683,9 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event, * max_order, to aid PMU drivers in double buffering. */ if (!watermark) - watermark = nr_pages << (PAGE_SHIFT - 1); + watermark = min_t(unsigned long, + U32_MAX, + (unsigned long)nr_pages << (PAGE_SHIFT - 1)); /* * Use aux_watermark as the basis for chunking to -- 2.43.0