From nobody Tue Apr 7 12:55:15 2026 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 33FFB3BC676 for ; Fri, 13 Mar 2026 13:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773408309; cv=none; b=OZOR68QQAlD7pMGedPj05IjfXsMHj74rNZ8C6HuZ+mmK5ya94nH5pbSUinzvctcgKMvysZ+090QiZaHXs2VZKed8GLY0vTOvdwoHlplPDEpna9ZYcMUX6Hj2xo9fITs56/L3P9SriHIsUxooyCKiILkHAGSY02Gg84dgI3wbWS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773408309; c=relaxed/simple; bh=pkCgTSJJXbt5VxzxPj8oHFbgppFep4H/tIjoWSquLFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oHJMfaqKT2yGo3lSRZ6kBz/euahjwrzD4/B58R53rz0EYdPwqsYa0P8sSrJz2HEMe9w5d92awCYeUb7EjiP7lZoPO+KGHZvGe1o8I+pN+MYsckRYM2Co1cFstIV9IVE2R/+QpYh+rP23eQebkk3d4Ii7K3wzYqVjAiRhWCeoxwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L+YIynbm; arc=none smtp.client-ip=209.85.167.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L+YIynbm" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-4672076355aso1531417b6e.2 for ; Fri, 13 Mar 2026 06:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773408307; x=1774013107; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p9IAEzSkGuy9vSx6TA0Y4hBOc80UNfiz/9RCZw4zMCM=; b=L+YIynbmbz9BTuVVxQvLpkb2SZNeupxsAgpgw7kBfNK3krce3V7GJN0juAJTklZMpV Rcxd0mEoloHbuKhTvJws4Mb7AT6f6DLQRUkqNYdmYMbXGazY+l2XL39eNhiRCowe8Vve g6SGuwFlJI9Xmsp86AhA/nC4ScfxkHiUIKOH2medcAN+cpfEAmmpFe7/IT0hp1/34r8m LkK7+wBGcVzsIEbaqxY+L3uRvJJgAqXhuydUJOkpOYKh6xHbPfV8W9D49wrYh1a/rHhe MFD7SW7tP+Eec+2NlqJVPMhoRZrhx/Y2Zv1LQO5ZUtYiSBG8uJ/99L68nwCOuYuL6tJh GfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773408307; x=1774013107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p9IAEzSkGuy9vSx6TA0Y4hBOc80UNfiz/9RCZw4zMCM=; b=qadOXhIH3/XaXJpW+D4K8ZULv3Lg1SVRbm9sRhLqEGzKAMq1L1r9Oej/DXuduv+IPU F3ojYEtYvrlwcgyOmG/78pJD0J8Zyrfi9eUlQ0k8QgV5SBLZc+RzWPt/4Z6trlUAs5jb /o8nO70xUzlVsVGD9MYGO6879Vfbz46J5S/dvy2kj5IsEhl6pmdLAuWFT3TB7rVQssRz LezPv5uWa5A3gYcv+XD3IENbmt+TyaqWDg2JHatynY7ZPyLrdhTVsBiQGQrhHyX0B6OR VtGKdkBs+VHdhIgggM5+fVZXPcmTBIhAAxXjlxvbB8Czm62rW02MhmMo06NRfgyl+0+g oTig== X-Forwarded-Encrypted: i=1; AJvYcCVo3ANOhXuzNwyA32ukHMl1XGB5QjvIdNy71VfY0lmKdioLTiOQGGHLfd/7bEmP8eSi06bg2yaeNbgeOSo=@vger.kernel.org X-Gm-Message-State: AOJu0YzAcM0YJVpl8HUwGsZ2M5LZ5feHNTVSaNIk7raqztLt7hQRO2uN yRZ5GrsIIdfolttfXUoPfV2bUOYbNGiDeu2v3yKU+g+Be1NGyLKvM9YD X-Gm-Gg: ATEYQzwGqCLIS68oZZhkMlptrnSgcNrlntdPIXvZ88u06zus819X3woeIhMrkHdQeCU qwPvb69zA6t1iLCHj/NgzX1muJGFtJ30N5SzAEl/DR5dsFJZs4lVVDEBsWfuGlJHic94rKHaCX4 UA6MLrZpDIQ3x62jadOKVsTmyzEONt9XCKxSI61K7IBswXbf+riz9NhXwGcikKgGmdZUJ+6Giw1 Qgd+PF7YpPdC927+Bua2O+b/IxY9hmV2jYPxdsq05xcxLZLf4yTb77NP5mYHF6fjffF7o3nWucV FQVPvqbndHTDOW+yW3KkHlBos9+Gp51kVw8p3s5IhZajjfdLe0Wf1ePU+rAhp+mkDfnWELzIQRy 2pGnybuHTq+rgqLkNvStMZ7prHxk20eqJ6S6wDszR6haI9uwm6mdUsuhmpwoUvlnNp1npYtOYcb zy2UtL1h3btUzQyuipWv070vWA1O/RKRnjBR/YohkQsON8CIYA X-Received: by 2002:a05:6808:1912:b0:467:4a4e:5a80 with SMTP id 5614622812f47-467575aef9cmr1688429b6e.45.1773408306845; Fri, 13 Mar 2026 06:25:06 -0700 (PDT) Received: from frodo (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 5614622812f47-4673434a35csm4795987b6e.20.2026.03.13.06.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2026 06:25:06 -0700 (PDT) From: Jim Cromie To: airlied@gmail.com, simona@ffwll.ch, jbaron@akamai.com, gregkh@linuxfoundation.org, Matthew Auld , Arun Pravin , Christian Koenig , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Jim Cromie , mripard@kernel.org, tzimmermann@suse.de, maarten.lankhorst@linux.intel.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, louis.chauvet@bootlin.com, skhan@linuxfoundation.org, pmladek@suse.com, ukaszb@chromium.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH v11 63/65] drm_buddy: fix 64-bit truncation in power-of-2 rounding Date: Fri, 13 Mar 2026 07:20:28 -0600 Message-ID: <20260313132103.2529746-64-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260313132103.2529746-1-jim.cromie@gmail.com> References: <20260313132103.2529746-1-jim.cromie@gmail.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 Content-Type: text/plain; charset="utf-8" The standard roundup_pow_of_two() and rounddown_pow_of_two() macros use unsigned long internally, which on 32-bit architectures (like arm32) is a 32-bit type. drm_test_buddy_alloc_exceeds_max_order() uses the on a u64 value, where they silently truncate the 10GB allocation, giving unexpected success in DRM-CI. (see below the snip). Fix this by replacing the standard macros with safe 64-bit power-of-two calculations using ilog2(). Signed-off-by: Jim Cromie --- [23:19:40] [PASSED] drm_test_buddy_alloc_clear [23:19:40] [PASSED] drm_test_buddy_alloc_range_bias [23:19:41] [PASSED] drm_test_buddy_fragmentation_performance [23:19:41] # drm_test_buddy_alloc_exceeds_max_order: EXPECTATION FA= ILED at drivers/gpu/drm/tests/drm_buddy_test.c:889 [23:19:41] Expected err =3D=3D -22, but [23:19:41] err =3D=3D 0 (0x0) [23:19:41] ------------[ cut here ]------------ [23:19:41] WARNING: drivers/gpu/drm/drm_buddy.c:405 at drm_buddy_fini+0= x114/0x1b8, CPU#0: kunit_try_catch/74 [23:19:41] CPU: 0 UID: 0 PID: 74 Comm: kunit_try_catch Tainted: G = N 7.0.0-rc1-gdfb0bcedd08a #1 VOLUNTARY [23:19:41] Tainted: [N]=3DTEST [23:19:41] Hardware name: Generic DT based system [23:19:41] Call trace: [23:19:41] unwind_backtrace from show_stack+0x10/0x14 [23:19:41] show_stack from dump_stack_lvl+0x3c/0x4c [23:19:41] dump_stack_lvl from __warn+0xe8/0x1c4 [23:19:41] __warn from warn_slowpath_fmt+0xa4/0xc0 [23:19:41] warn_slowpath_fmt from drm_buddy_fini+0x114/0x1b8 [23:19:41] drm_buddy_fini from drm_test_buddy_alloc_exceeds_max_order+= 0x1c8/0x36c [23:19:41] drm_test_buddy_alloc_exceeds_max_order from kunit_try_run_c= ase+0x78/0x1c8 [23:19:41] kunit_try_run_case from kunit_generic_run_threadfn_adapter+= 0x1c/0x34 [23:19:41] kunit_generic_run_threadfn_adapter from kthread+0x108/0x134 [23:19:41] kthread from ret_from_fork+0x14/0x28 [23:19:41] Exception stack(0xf0bd5fb0 to 0xf0bd5ff8) [23:19:41] 5fa0: 00000000 00000000 = 00000000 00000000 [23:19:41] 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 = 00000000 00000000 [23:19:41] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [23:19:41] ---[ end trace 0000000000000000 ]--- [23:19:41] # drm_test_buddy_alloc_exceeds_max_order: drivers/gpu/dr= m/drm_buddy.c:406: buddy_fini() root [23:19:41] ------------[ cut here ]------------ [23:19:41] WARNING: drivers/gpu/drm/drm_buddy.c:414 at drm_buddy_fini+0= x1b4/0x1b8, CPU#0: kunit_try_catch/74 [23:19:41] CPU: 0 UID: 0 PID: 74 Comm: kunit_try_catch Tainted: G = W N 7.0.0-rc1-gdfb0bcedd08a #1 VOLUNTARY [23:19:41] Tainted: [W]=3DWARN, [N]=3DTEST [23:19:41] Hardware name: Generic DT based system [23:19:41] Call trace: [23:19:41] unwind_backtrace from show_stack+0x10/0x14 [23:19:41] show_stack from dump_stack_lvl+0x3c/0x4c [23:19:41] dump_stack_lvl from __warn+0xe8/0x1c4 [23:19:41] __warn from warn_slowpath_fmt+0xa4/0xc0 [23:19:41] warn_slowpath_fmt from drm_buddy_fini+0x1b4/0x1b8 [23:19:41] drm_buddy_fini from drm_test_buddy_alloc_exceeds_max_order+= 0x1c8/0x36c [23:19:41] drm_test_buddy_alloc_exceeds_max_order from kunit_try_run_c= ase+0x78/0x1c8 [23:19:41] kunit_try_run_case from kunit_generic_run_threadfn_adapter+= 0x1c/0x34 [23:19:41] kunit_generic_run_threadfn_adapter from kthread+0x108/0x134 [23:19:41] kthread from ret_from_fork+0x14/0x28 [23:19:41] Exception stack(0xf0bd5fb0 to 0xf0bd5ff8) [23:19:41] 5fa0: 00000000 00000000 = 00000000 00000000 [23:19:41] 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 = 00000000 00000000 [23:19:41] 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [23:19:41] ---[ end trace 0000000000000000 ]--- [23:19:41] [FAILED] drm_test_buddy_alloc_exceeds_max_order [23:19:41] # drm_buddy: Testing DRM buddy manager, with random_seed= =3D0xacce106c [23:19:41] # module: drm_buddy_test [23:19:41] # drm_buddy: pass:8 fail:1 skip:0 total:9 --- drivers/gpu/buddy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c index 52686672e99f..ed4d33a30687 100644 --- a/drivers/gpu/buddy.c +++ b/drivers/gpu/buddy.c @@ -1091,7 +1091,7 @@ static int __alloc_contig_try_harder(struct gpu_buddy= *mm, u64 modify_size; int err; =20 - modify_size =3D rounddown_pow_of_two(size); + modify_size =3D 1ULL << ilog2(size); pages =3D modify_size >> ilog2(mm->chunk_size); order =3D fls(pages) - 1; if (order =3D=3D 0) @@ -1318,7 +1318,7 @@ int gpu_buddy_alloc_blocks(struct gpu_buddy *mm, =20 /* Roundup the size to power of 2 */ if (flags & GPU_BUDDY_CONTIGUOUS_ALLOCATION) { - size =3D roundup_pow_of_two(size); + size =3D 1ULL << (ilog2(size - 1) + 1); min_block_size =3D size; /* * Normalize the requested size to min_block_size for regular allocation= s. --=20 2.53.0