Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp349579rwl; Wed, 29 Mar 2023 02:47:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bIw/kjIvLasJP14+bDMffecSLJhpxxUXWULqFpDu4p+iZLKmfI1E9K1/3dPeHrevJ9iQqi X-Received: by 2002:a17:906:3755:b0:8e9:afb1:65c6 with SMTP id e21-20020a170906375500b008e9afb165c6mr1767142ejc.13.1680083225597; Wed, 29 Mar 2023 02:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680083225; cv=none; d=google.com; s=arc-20160816; b=vSF7SnDgwVKLvqcDVe6+UBh7LCA2nXNdoq6dmm14JIhVtTaAcWwJpVlPxx8Z8wk9Q9 5AnT4t2fmxEi8GvUMaW8LHjqfus45V1K4OwEkGiB1SWOYBNEGnFALhsHnCmBHxVPIV39 A1N00nNR3sT/l/oxCO6Uv+8iU7w/3uK2Kp+YtvfnXxhXzSz2Xnai58k12oUa5vH6DytJ rYW4sDvXBZu49GPYXFpqHWtd2+YDgjOHtlWD668H3StiKMz4mMarJQoDncpSEcAEXMww C2xGJLs2d8JEM7hmA97UtMC9ubB5D9+pindlHQZZfudw9iovWirUy20zOx+bA6nE8ZUo O4FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=fD6yr4cFuvXKePYUJpSPyNrf/VhLADuUgB1Spja6obc=; b=cVaN4pvrGyudGtuXI0pjOPHYgAYRajFDCZedJX3+BOwsyhjda0aGo5kM7RjoNCmnH0 MW1aH1/iuQddFjta8CR9glI7PXsAwKsKmSmyn0CxpLGxOUYdcG+7m9uzNdDhSyspBJMd 6wyVYsskNaeYbj4medBLe1EiM+Bvu7TFtPebX3f8oVO2H8bovgYbhr6u+5BlNM6ipSxm 2iLcMXINiPhf23HxcWFR9hFDcVdztZ9ehvifQoDEW+ldMIGDc9euMh1gN+yaxbyn0ktL jM4ftTHtfWiu1cJLnGq7UnhqEdQj5+TZEASY58UkXhVZhgbsNejpgowSPHZ9Dx9XazWQ aYTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GsOtpc2G; 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 vk5-20020a170907cbc500b009334be3d5fcsi30789643ejc.296.2023.03.29.02.46.40; Wed, 29 Mar 2023 02:47:05 -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=GsOtpc2G; 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 S230448AbjC2Jmp (ORCPT + 99 others); Wed, 29 Mar 2023 05:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjC2Jmn (ORCPT ); Wed, 29 Mar 2023 05:42:43 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E880210D for ; Wed, 29 Mar 2023 02:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680082962; x=1711618962; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=wsUEbabLSJ+xqGqt7Fcvy5Ojm7Y0fRXRafogIThAt4k=; b=GsOtpc2Gl8eaTNKg92V9rKTLEf9fbiNsPYmdPfsY528rck2e2M7FFQZ3 JSx76SvncXEW9B/eTYSk9waY580btsWKgBKD+XzVxEG0Kc4BLydDZZd+j XLg/zcwVrPkjUV32kJ6uZhEXJZThkbm1tLHIc1LHp8iogdDLNWSlq7fXd PCf7HBzYkBVh3Xll9E+oavrOxiTUlO8lu15wUGnO7fHglBHxbIVg6clVg TYM8xF1mljanyLJHoMB3FZlRBQjMAVjE1wwPWcJgKgU3EOKrT+PDnfEal HnGSjeviq1ovLnfgBGa+/ArRxJhSjEddOCJdJ38kcGGwMp2ZypbIWj+Fb g==; X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="403454487" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="403454487" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 02:42:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10663"; a="773508919" X-IronPort-AV: E=Sophos;i="5.98,300,1673942400"; d="scan'208";a="773508919" Received: from jetten-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.51.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2023 02:42:37 -0700 From: Jani Nikula To: 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?= =?utf-8?Q?=C3=ADra?= Canal , Arthur Grillo Cc: dri-devel@lists.freedesktop.org, David Gow , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] drm: test: Fix 32-bit issue in drm_buddy_test In-Reply-To: <87lejf522a.fsf@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20230329065532.2122295-1-davidgow@google.com> <20230329065532.2122295-2-davidgow@google.com> <87lejf522a.fsf@intel.com> Date: Wed, 29 Mar 2023 12:42:35 +0300 Message-ID: <87ilej51x0.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain 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,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, Jani Nikula wrote: > On Wed, 29 Mar 2023, 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. >> >> This only reproduces randomly, as the parameters passed to the buddy >> allocator in this test are random. The seed 0xb2e06022 reproduced it >> fine here. >> >> For now, just hardcode an is_power_of_2() implementation using >> x & (x - 1). >> >> Signed-off-by: David Gow >> --- >> >> 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) >> >> So the ideal thing would be to consolidate these in one place. >> >> >> --- >> drivers/gpu/drm/tests/drm_buddy_test.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/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 = -EINVAL; >> } >> >> - 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)) { > > Then maybe use is_power_of_2_u64() instead? *sigh* And as soon as I wrote that I realized it's a local thing in btrfs. Never mind for now... ...but in the long run would be nice to either fix is_power_of_2() for u64 or add that u64 version... BR, Jani. > > BR, > Jani. > >> kunit_err(test, "block size not power of two\n"); >> err = -EINVAL; >> } -- Jani Nikula, Intel Open Source Graphics Center