Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp466617rwl; Wed, 29 Mar 2023 04:39:06 -0700 (PDT) X-Google-Smtp-Source: AKy350bWJSrqu/tdC8KRan3PMnUBuK5czILGHobZs9uUADctG+2tmw+Sfl2USCqYndEqYYvflm1u X-Received: by 2002:a17:907:c209:b0:944:5d34:2111 with SMTP id ti9-20020a170907c20900b009445d342111mr12828877ejc.66.1680089946111; Wed, 29 Mar 2023 04:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680089946; cv=none; d=google.com; s=arc-20160816; b=qMtgcklFjiJSMunkk9lsoHp6RPL7NjTJgm3qASvpb9Gal2Yi1DlDA/MNBhummunrYA d3XelFD2L7d24b82i7HiBDxS/CbhFogyUxBRRtmrdyhcxBuSLs/kc2Q/eomssBWkxzc7 UgRcN60Morkj0rRrjBy7k/Wh7TWNdV0cPP/YAAesVkDzbE9y927K6kTp3ZchevL4PGvf yganDFQhax3Vmrgxn2e453W390CuEQJ96SM1IZt649v8wyNwoe+WGnWtsS6IfknsPkZP kdvRLeRoEjmMXsaOnynFQislCNUDS3L/Fa1a2Mk+0kPhQGsgxcUaTlEONNuzg+eA+8vJ DZLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:organization:in-reply-to:subject:cc:to :from:dkim-signature; bh=MNQY+jSiMTk/OxZJ2ZB/UCscjo4XARwWNrlCfNTGkXA=; b=neigyj276FhGTdcq0h7mYud/wyacYEELSukCfh27cDErrCyLQmtCOeUcjlNpPc3M6a zjUybGaI9fdHaB5djenjiRCy2+UuF930E+mEr9hF7mB2Gb9oQr2TxDDyWTjc6lh2VN4m YOPiBLn4xl8TUOdfTnLRPt0ssy9PvK47yZttWDzdspmxX7js3L3v8npn9DEDw3pIZ26+ eN9Inldzn3eALlu6T9eLnCiuZxAyQNQVFdiwm/SP7LAzCOPzLLL/0au9BppwKMfsw54y rnSpkZxw4/26imJ6xjd0M9Bvft/QBmeMHdm5+TbCvLVSiNvTQxulk4j1Q/4fz7UEf2Sr 22/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TGDuu2ZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ba9-20020a0564021ac900b00501d916b24fsi24180418edb.633.2023.03.29.04.38.41; Wed, 29 Mar 2023 04:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TGDuu2ZT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjC2L2y (ORCPT + 99 others); Wed, 29 Mar 2023 07:28:54 -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 X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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