Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1957632rwl; Thu, 30 Mar 2023 04:06:35 -0700 (PDT) X-Google-Smtp-Source: AKy350ZEYDRUI1IknXUrbNfQNxq1hRCJV7SCMwRGCctQHJpElgOEZvXgw83GgsEFUPQfg2yisDlC X-Received: by 2002:a17:906:51cd:b0:931:4285:ea16 with SMTP id v13-20020a17090651cd00b009314285ea16mr1689644ejk.7.1680174395690; Thu, 30 Mar 2023 04:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680174395; cv=none; d=google.com; s=arc-20160816; b=I4WffPrXFc0V0yD/OZ/Cd/LunhrM/+M2Tb98xfwlUllBElQX9dZEOOe6S+vhaNFl0U LBJZQnm3D/VbJAGOEZrgggKxQ/0zm08kcHVo6cRAv34gxzFk5yORnWA6qhRPI4CahgWV T0JF6Jx7pepAraOeJrXKBWS5by/EFcbyNlOin4xFzBVv/nybDS5o60w0/7bpJqMqFMZ1 nhEov7mhVNEtPhDSWT8oiz6GFI900lJKmS6lBeHh5q6ayNqbEB9Q9m7aXS2ptM9AM1L0 amjccr4LqD5S2XBl3Y9jBUTVv31zN8z0TIrEie1yihqGe6W4uRZBGj20EpLxUZ1+R44a j88A== 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=y/kw3769fcYLZpZ1RZrQsjcBprN2W0ts30lgvj64evI=; b=Srka55F9uTTU+D8Ur+F0DKKIu9ln8J1oSLcjQBp47RCtg/RQPnX8ifaxvw5WF1y7Jg vGxHKWoj+qb9DkHLbpb78eIMURi5UJ7dF4QOGhKxs2GLPFmuk71m4Ji+F9rYylQBVcWT IQdE2ediAZhFQY6+60eF8AWhNsEW0IZeZVJYqurn8M06C6qPdJ5/g0leeK5pKaT5/dvA wqFU9pldWTqjvQV9KgPqq9C+g4UKCZP3F61c6lGjKGz2VczjA3RPyCZrq+YTe2F6rpJR zj1bnmLzSzwSsfZq2snFC9e9eC5Vk5ZKJEYa8i5xr81/ELQc9h1OefQqAe6ly2fOD7cn enlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RljzMu/R"; 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 j13-20020a1709066dcd00b009302c3128c4si34959105ejt.833.2023.03.30.04.06.00; Thu, 30 Mar 2023 04:06:35 -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="RljzMu/R"; 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 S229862AbjC3Kx4 (ORCPT + 99 others); Thu, 30 Mar 2023 06:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjC3Kxy (ORCPT ); Thu, 30 Mar 2023 06:53:54 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD2F64C2F for ; Thu, 30 Mar 2023 03:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680173633; x=1711709633; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=/a2NUyQvjACpQ05kbhWwDQBqs0dGUOck0k692foQm/k=; b=RljzMu/RZkHzBbdI5hVRMg0edt12gI3DcLsIi3T91okiRtlfYTwiYLKu +D3y8KAUHhLum0z3UhHwQchCAJRx0gQPPCkXAAco8P2wCHmojSJk2AE15 JsIhOY9fXO1cZZ7BspJJZTA5rfUqYkdvv4gEcov6eEB3hD9J0Dk54fXoc f9nNm/c7PcdSYL4FKwoy2PpFwq7YtCb9MBZtfO17X7zaKea0ig78fEbAG VvbEVMpSJJUKqpuK0XXw66yN+tLH6TGeBoEO+nLPsVrVLy1reqIvmwxYu ASQ3HFIuBnywz39/se6g6fTtW5M1otHyMUX7UZBElAlD9NjwI5Kxsk43B w==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="329628463" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="329628463" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 03:53:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="1014392291" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="1014392291" Received: from unknown (HELO localhost) ([10.237.66.160]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 03:53:49 -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=C3=ADra?= Canal , Arthur Grillo Cc: dri-devel@lists.freedesktop.org, David Gow , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] drm: buddy_allocator: Fix buddy allocator init on 32-bit systems In-Reply-To: <20230329065532.2122295-1-davidgow@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20230329065532.2122295-1-davidgow@google.com> Date: Thu, 30 Mar 2023 13:53:47 +0300 Message-ID: <878rfe4iis.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, David Gow wrote: > The drm buddy allocator tests were broken on 32-bit systems, as > rounddown_pow_of_two() takes a long, and the buddy allocator handles > 64-bit sizes even on 32-bit systems. > > This can be reproduced with the drm_buddy_allocator KUnit tests on i386: > ./tools/testing/kunit/kunit.py run --arch i386 \ > --kunitconfig ./drivers/gpu/drm/tests drm_buddy > > (It results in kernel BUG_ON() when too many blocks are created, due to > the block size being too small.) > > This was independently uncovered (and fixed) by Lu=C3=ADs Mendes, whose p= atch > added a new u64 variant of rounddown_pow_of_two(). This version instead > recalculates the size based on the order. > > Reported-by: Lu=C3=ADs Mendes > Link: https://lore.kernel.org/lkml/CAEzXK1oghXAB_KpKpm=3D-CviDQbNaH0qfgYT= SSjZgvvyj4U78AA@mail.gmail.com/T/ > Signed-off-by: David Gow > --- > drivers/gpu/drm/drm_buddy.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c > index 3d1f50f481cf..7098f125b54a 100644 > --- a/drivers/gpu/drm/drm_buddy.c > +++ b/drivers/gpu/drm/drm_buddy.c > @@ -146,8 +146,8 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u6= 4 chunk_size) > unsigned int order; > u64 root_size; >=20=20 > - root_size =3D rounddown_pow_of_two(size); > - order =3D ilog2(root_size) - ilog2(chunk_size); > + order =3D ilog2(size) - ilog2(chunk_size); > + root_size =3D chunk_size << order; Just noticed near the beginning of the function there's also: if (!is_power_of_2(chunk_size)) return -EINVAL; which is also wrong for 32-bit. BR, Jani. >=20=20 > root =3D drm_block_alloc(mm, NULL, order, offset); > if (!root) --=20 Jani Nikula, Intel Open Source Graphics Center