From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAEB6C74A5B for ; Wed, 29 Mar 2023 11:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbjC2L2z (ORCPT ); Wed, 29 Mar 2023 07:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjC2L2x (ORCPT ); Wed, 29 Mar 2023 07:28:53 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83FEC2109 for ; Wed, 29 Mar 2023 04:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680089332; x=1711625332; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=JGMbh0J3Ep4ALl5fvP9kT9Pq4VuAVtH2X+HHgJvfgKY=; b=TGDuu2ZTOju1ra41NqurTVy7llTrCwpk7A6KnmrvyAgGnAJOYAAoVros YZqX7bJ1tb/wLMq4tzXgiA+z1SD2YbJnckpw7DIQnDif1caWbQWBTyoSh xCKx8zE7KYhlI+7k+UZNYOw5Wed0kp3G9YPQDLBT3Gds1SMzuFufGs06m Spq4OnbercGbvKeWxhsoLjic2pazhKyDKaA8ATHJ4WJi9GV5S8wvS/a7e XXgAEgCEmDh2joEs0+uAI1heMukIV+wUJeVFc0qBv7CmuPK6Matg0xv9U UOrP9g7Yl4EmVrLJ5AMT5wzHHzkpCVYtgdZ0CFhbpQIX372K0tBBiDLwq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="342444267" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="342444267" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 04:28:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="634436238" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="634436238" Received: from jetten-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.51.146]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 04:28:47 -0700 From: Jani Nikula To: =?utf-8?Q?Ma=C3=ADra?= Canal , David Gow , =?utf-8?Q?Lu=C3=ADs?= Mendes , Christian =?utf-8?Q?K=C3=B6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?Q?Ma=C3=ADra?= Canal , Arthur Grillo Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH 2/2] drm: test: Fix 32-bit issue in drm_buddy_test In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20230329065532.2122295-1-davidgow@google.com> <20230329065532.2122295-2-davidgow@google.com> Date: Wed, 29 Mar 2023 14:28:45 +0300 Message-ID: <87fs9n4x02.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Mar 2023, Ma=C3=ADra Canal wrote: > On 3/29/23 03:55, David Gow wrote: >> The drm_buddy_test KUnit tests verify that returned blocks have sizes >> which are powers of two using is_power_of_2(). However, is_power_of_2() >> operations on a 'long', but the block size is a u64. So on systems where >> long is 32-bit, this can sometimes fail even on correctly sized blocks. >>=20 >> This only reproduces randomly, as the parameters passed to the buddy >> allocator in this test are random. The seed 0xb2e06022 reproduced it >> fine here. >>=20 >> For now, just hardcode an is_power_of_2() implementation using >> x & (x - 1). >>=20 >> Signed-off-by: David Gow > > As we still didn't consolidate an implementation of is_power_of_2_u64(), I just cooked up some patches to try to make is_power_of_2() more flexible. I only sent them to the "CI trybot" for a quick spin first, will post to lkml later. [1] BR, Jani. [1] https://patchwork.freedesktop.org/series/115785/ > > Reviewed-by: Ma=C3=ADra Canal > > Best Regards, > - Ma=C3=ADra Canal > >> --- >>=20 >> There are actually a couple of is_power_of_2_u64() implementations >> already around in: >> - drivers/gpu/drm/i915/i915_utils.h >> - fs/btrfs/misc.h (called is_power_of_two_u64) >>=20 >> So the ideal thing would be to consolidate these in one place. >>=20 >>=20 >> --- >> drivers/gpu/drm/tests/drm_buddy_test.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >>=20 >> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/te= sts/drm_buddy_test.c >> index f8ee714df396..09ee6f6af896 100644 >> --- a/drivers/gpu/drm/tests/drm_buddy_test.c >> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c >> @@ -89,7 +89,8 @@ static int check_block(struct kunit *test, struct drm_= buddy *mm, >> err =3D -EINVAL; >> } >>=20=20=20 >> - if (!is_power_of_2(block_size)) { >> + /* We can't use is_power_of_2() for a u64 on 32-bit systems. */ >> + if (block_size & (block_size - 1)) { >> kunit_err(test, "block size not power of two\n"); >> err =3D -EINVAL; >> } --=20 Jani Nikula, Intel Open Source Graphics Center