From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 0F51B46F486 for ; Fri, 21 Aug 2026 09:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305648; cv=none; b=rwjag9XNNxrLW0q80MY0DS/QQ/FFdg5bKJV5LmYPxKItEjqGcSMtqg5sEqXsL2WmAXSqp/eEMsI8pEgxy8ZlkZimoirdRKqP4HgT1SHyAX4Qj04o6ZAgZSsmONNVZyvZ1qOrupBAyq+cMFDf4vIKA5oGgi+UP0NtGrmLPZAJTh0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787305648; c=relaxed/simple; bh=IadjFUy4h8h9QtYK5SBavvUUGpvA0kBWUTh/umE+qqo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DBMbPZaykdDmHfZVACeMRJt2ns69dDJjzToOs9K6b8RqEYUfDP3GWSFKYFr2EImQ8NYZOgEc5iyr7SiUIOTcn23R3f/+RuG7lxRTeEdtuyA3ZvnXIXMAbRGG2Ts/me+MNOaqzJ7zaBKq8i8BhNvk6ObA8IIZwAxLtKrE7d+Ow7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Eh5wVqdD; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Eh5wVqdD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1787305645; x=1818841645; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=IadjFUy4h8h9QtYK5SBavvUUGpvA0kBWUTh/umE+qqo=; b=Eh5wVqdDoOW/3GmY1ke297npPTUKdtJN2d8G8V0DTKvAj/zwNYiMfLIP PnG03DGM31qZlu5SzvdjY5vE2q9aK9ugUYZdpOCQFzVU5/oF0COZCL5eZ nPD1+fLZ68KB+nfv+XujPxATEE3NsEFkcaMD0Og+h3HbgraPjo3PFIlWa z/vbpoO1RWiDmY00zNRiIljZ30nYNHHF4pk6kNyRDR9KD2bqbINCMxY/c 1KMVRYRCNWPOyCkpXDAuk4kuDGMMeCMPYc/olItTH5XFiE58OdjCJqGwz /bHgjz0iPLlFQP0j2PiBDPzhXamrvQe65vgnY2igrRAydJKOiOhHYNWPo g==; X-CSE-ConnectionGUID: 1nqj8YHWTrq6nrxhZe65uA== X-CSE-MsgGUID: CQc4QaaJRVKYgi6SuFrEBQ== X-IronPort-AV: E=McAfee;i="6800,10657,11881"; a="113391093" X-IronPort-AV: E=Sophos;i="6.25,234,1779174000"; d="scan'208";a="113391093" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2026 02:47:22 -0700 X-CSE-ConnectionGUID: NtUuOaHvQ1O/D4XhTHWuFg== X-CSE-MsgGUID: Y64nB0LNQreerI/W71XfJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,234,1779174000"; d="scan'208";a="271523484" Received: from fpallare-mobl4.ger.corp.intel.com (HELO [10.245.245.237]) ([10.245.245.237]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2026 02:47:20 -0700 Message-ID: <87ec838b-c73f-45d2-b90b-c696aa6017cc@intel.com> Date: Fri, 21 Aug 2026 10:47:17 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] drm_buddy: fix power-of-2 rounding errs To: David Gow , Jim Cromie , "Maciej W . Rozycki" , Andrew Morton , Arun Pravin , Joel Fernandes , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, David Gow References: <20260821091918.1902032-1-david@ingeniumdigital.com> <20260821091918.1902032-2-david@ingeniumdigital.com> Content-Language: en-GB From: Matthew Auld In-Reply-To: <20260821091918.1902032-2-david@ingeniumdigital.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 21/08/2026 10:19, David Gow wrote: > From: Jim Cromie > > 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 these 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 those macros with the safe 64-bit power-of-two > equivalents added in the previous patch. Do we also need something like is_power_of_2_u64() ? I think we could then remove that from i915_utils.h > > Signed-off-by: Jim Cromie > Signed-off-by: David Gow > --- > > This should actually be version 13, I think, as it's just a rebase of v12 > here, where it was part of a large series of fixups: > https://lore.kernel.org/all/20260326185413.1205870-40-jim.cromie@gmail.com/ > > The major changes since that version are: > - Add the helper functions rounddown_pow_of_two64() and > roundup_pow_of_two64() (see patch 1) instead of open-coding them > - Rebase now that the buddy allocator lives in drivers/gpu/buddy.c > instead of drivers/gpu/drm/drm_buddy.c > > This is still breaking the gpu_test_buddy_alloc_exceeds_max_order > KUnit test on 32-bit systems: > [09:01:26] # gpu_test_buddy_alloc_exceeds_max_order: EXPECTATION FAILED at drivers/gpu/tests/gpu_buddy_test.c:1429 > [09:01:26] Expected err == -22, but > [09:01:26] err == 0 (0x0) > [09:01:26] WARNING: drivers/gpu/buddy.c:508 at gpu_buddy_fini+0x244/0x2e0, CPU#0: kunit_try_catch/1595 > [09:01:26] # gpu_test_buddy_alloc_exceeds_max_order: drivers/gpu/buddy.c:508: gpu_buddy_assert(gpu_buddy_block_is_free(mm->roots[i])) > [09:01:26] WARNING: drivers/gpu/buddy.c:516 at gpu_buddy_fini+0x284/0x2e0, CPU#0: kunit_try_catch/1595 > [09:01:26] # gpu_test_buddy_alloc_exceeds_max_order: drivers/gpu/buddy.c:508: gpu_buddy_assert(gpu_buddy_block_is_free(mm->roots[i])) > [09:01:26] WARNING: drivers/gpu/buddy.c:516 at gpu_buddy_fini+0x284/0x2e0, CPU#0: kunit_try_catch/1595 > [09:01:26] # gpu_test_buddy_alloc_exceeds_max_order: drivers/gpu/buddy.c:519: gpu_buddy_assert(!mm->used_scoreboard[i]) > [09:01:26] [FAILED] gpu_test_buddy_alloc_exceeds_max_order > > Cheers, > -- David > > --- > 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 a5553fcec28c..64f41f1fe908 100644 > --- a/drivers/gpu/buddy.c > +++ b/drivers/gpu/buddy.c > @@ -1193,7 +1193,7 @@ static int __alloc_contig_try_harder(struct gpu_buddy *mm, > u64 modify_size; > int err; > > - modify_size = rounddown_pow_of_two(size); > + modify_size = rounddown_pow_of_two64(size); > order = ilog2(modify_size) - ilog2(mm->chunk_size); > if (order == 0) > return -ENOSPC; > @@ -1440,7 +1440,7 @@ int gpu_buddy_alloc_blocks(struct gpu_buddy *mm, > > /* Roundup the size to power of 2 */ > if (flags & GPU_BUDDY_CONTIGUOUS_ALLOCATION) { > - size = roundup_pow_of_two(size); > + size = roundup_pow_of_two64(size); > min_block_size = size; > /* > * Normalize the requested size to min_block_size for regular allocations.