Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1957469rwl; Thu, 30 Mar 2023 04:06:29 -0700 (PDT) X-Google-Smtp-Source: AKy350ZLsIvyeQYZwcHTg/bAfx+SV26je00+g0cZy3LPDvJQHw0oLsJOtxqwybE8YTSMHFzz6Xg2 X-Received: by 2002:a05:6402:2803:b0:502:e50:3358 with SMTP id h3-20020a056402280300b005020e503358mr2200536ede.3.1680174388778; Thu, 30 Mar 2023 04:06:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680174388; cv=pass; d=google.com; s=arc-20160816; b=QLD4EQKVJseVelXK5aObk+01nAGdgCW6+6KYiHOPZkBYHAxh7tGGmg2+ERpAZFn8uz BiMhDFOVryHb44s5FwS1vdjUEGkE/7ACZ/FGOYyxNq9B5mLigQ4RpxIGBdgfApI31yKg DunmlhXP+aHPKvi81fI+KMxD3jNyuxawRwZ0qMoF9STvQ39X0QyFYsgfUqTRdLL0tuXv fgIGIUqyDaogVJwnuKZLNj9W58NCrGAQA9d/byCft7MyRX18Y8Q49TNxu+1klCeXT3Vb q+TLWUhAMfJaukhzGFMff8vNmXDJEGcE0MvC/cseIuq3vrJ8RLeplRuK7ArqFPXWhuBF nVCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=xBKJgTvVMUw6WSjprv+iFaGtvY7zpB1L8rMB2wzx57g=; b=BnpYIRvkt8UjgSQoS4xfKowPwbUqk1zV/XJ2vOI/mQOomLWP4Ha+UUGMHmO5u2KLW1 lGlFVrJA/osSRcyjtswMrSoKhXYEsyjRFPpEFt95t941b2ii0bA5eYIr4+iYABjgIxAk 0xg795i4FzXcYXafn85z5Q6/8Yef1xM6UfskmsGWfnCjhc4Cz9L+KuPp75jc2oSng6MW ZqitLB1r+qRMFdP9Nfqu6fbJdJPbz28mH+mafDf1zZBh+27fueSMz0gpYnKnyPdCF+A0 J7jxropFRuI7Pdo6LTHxauHiDjcTSMzWh/Bos9z9tz9rCfm3SakfujgjPr+Hd51YMuix 4+MA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=qeA8kCNR; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a50fb02000000b00501e22f86cbsi24420140edq.245.2023.03.30.04.06.03; Thu, 30 Mar 2023 04:06:28 -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=@amd.com header.s=selector1 header.b=qeA8kCNR; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbjC3K4x (ORCPT + 99 others); Thu, 30 Mar 2023 06:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbjC3K4s (ORCPT ); Thu, 30 Mar 2023 06:56:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DDE8A62 for ; Thu, 30 Mar 2023 03:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e8c76S1m8068GT3XxUneb0MyFOl8pw6hB3I79qhLC5LbG+H1KRZzN6w1n7nKI4SEN1IF4tIiPJfp8OPQeyNf7wfX/YVtfFtZKiZ0rRi7YMC6N19syMwYU6HReRBzRRzvwHiPQJb9oy7Nt+PyV0/6/5qtqdTH8Ku/IPJX+E2pvEJ9+WGRoTSsHRzokvdWyp+bi42NaNf5XAWMyyToJsrunhxoWsGopCnNSLelIfMiQMvbcCDXeN9dp6ifsdD0/qvW9gvwaiQ3f+L75hAdp1Hmg/mqvEcIzGumy3FKvhM0CW6SC/2NH7sqGNoqxm5Lv7ghBzJrsPnsTlVd+Nmhzd0J+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xBKJgTvVMUw6WSjprv+iFaGtvY7zpB1L8rMB2wzx57g=; b=IDHN6l+CRFZLkJBXVS5FVJvMHK4cutOyTodA0zjmXaw2mo1l9zarfZ/zbddcdGuyWs5BYhfmv8BslSpTR1KY/Q7ZudKq7bDaibtuyh6dGYg1Okusduy4OXcI5CNOc3Q9lxyhO3jiC50odTT9NlHytutbSzwHL/N+4dHr7PTO1qMK2P9VkvmrE+GrVdsxgPpe7/UwdVViQt7kwGqSTcz4OV7ws6/eWumChThOHEteNUniUY3jk+L+CApHjB9ER6ga3NUz8jyb9saH/Cbfa/kboDP5vOO5aVwGNXnMYPH8Q5uB+Ve6kMj6vJgDftMcpU/TBydh8e8gMzeWTJALJlAMAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xBKJgTvVMUw6WSjprv+iFaGtvY7zpB1L8rMB2wzx57g=; b=qeA8kCNRSurGDHZjsoUJjoBWCprKjVIfiQQP5VIO3zrU2GBHqnPciZlTyVLxG/n6TgJPYJ74jspNm4sbzH729T0cMCI0ll9eUng3ZzUF+pFdXBFgANvqpykaWGfauW3ghBEq3r+NFtrvlHmqUqyPdMWKMAD7dNdF8n7jrKO6F+0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by DM6PR12MB4265.namprd12.prod.outlook.com (2603:10b6:5:211::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.33; Thu, 30 Mar 2023 10:56:33 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::4624:dc39:943e:6ae]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::4624:dc39:943e:6ae%5]) with mapi id 15.20.6254.022; Thu, 30 Mar 2023 10:56:32 +0000 Message-ID: Date: Thu, 30 Mar 2023 12:56:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH 1/2] drm: buddy_allocator: Fix buddy allocator init on 32-bit systems Content-Language: en-US To: Jani Nikula , David Gow , =?UTF-8?Q?Lu=c3=ads_Mendes?= , 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, linux-kernel@vger.kernel.org References: <20230329065532.2122295-1-davidgow@google.com> <878rfe4iis.fsf@intel.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <878rfe4iis.fsf@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FRYP281CA0004.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::14) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8PR12MB3587:EE_|DM6PR12MB4265:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fecfa18-a45c-4845-206f-08db310d6bed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hYTZXPhQgANCBTKvrU+khI5dmp0xwuU3+yrTCezmP8LuHcxbPhR4dBw/0vzQzhmtofqWKtiQe/o9sl9hfYigk0MmtV4cetT8y++4jdmyaa5bAKZoHom4uXup5cvpB04LSQ23Kryje2FnJbyjkQwuPVGKRwFEb/3kTnzvJEWzYTmZZInvrbKoFQYpRoYg8TeRfkO9RZIWLMpHIHFlKVv8MvlqwNCr5tyUKm0F/kLvw6LP2Wnd2RdTTltv0ZtwkQNKCY3gfTQerWk1rbbsfCcAdJgGJ/xaerk91zlOxECV/yjOMttXbfH6WqKD7ZiNS/g0umIEhfyhspS+IYCsL1YhW4NjUtKC8dAfKxbuvNVWg6AIsqTU+dY02hrDjSDRl1fWVKfdncVgPrPYHwIrTFFeQsIND8TwuzraSOginkvlgSvFDH3eauf0IWNBMkc2s7Zk4CvpXpZYeKtIuyFGxAYxUfu2jRpSpmsMzIN3QUfEV+FBabxGJhQyBuebHxR22J74bdqPQ04KNpuwwc2Adnz6AGnb1tFYnl5hbset/vRvDImZqae9g9izAgXgpaWD3yA3DoyF9+iZ8VNMdZ/ckxiQ4YzcM4RVV03pYD//oSCz2heUw3y1UQthm0b8wvNCAM4CJk3ay9mXRwT4QaYQ+ywSPWsiCrgqnl4PdMc9McpFUWQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(366004)(396003)(136003)(39860400002)(451199021)(31686004)(2906002)(83380400001)(66574015)(7416002)(26005)(8936002)(5660300002)(6506007)(6666004)(316002)(36756003)(966005)(6486002)(110136005)(66946007)(478600001)(6512007)(66476007)(2616005)(186003)(66556008)(4326008)(38100700002)(8676002)(41300700001)(31696002)(921005)(86362001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bmp5YVBId0Z6VFpPSjFIdTZmTFVsYmgzaXNmaFJ1THRwcFhnbmhZcHpZWlhR?= =?utf-8?B?VXE1TWZ6dHBrTEZoSzBFM01mbnBBOUZpY3A3R2ZTUW02M05DQkRWS3lyemFm?= =?utf-8?B?ZkhqRW1uUWRYc3BGWFhVUVU2dHZLenNDTnAyVS9rd1BrN1Zmb1ByVU1KcGxh?= =?utf-8?B?NGlpL0dST2Q4M3Qrck8rY2hRRWlZK1hNQXVmSng1MGsrWTJrTnR5L3lVRjVn?= =?utf-8?B?SmoydHAzQlJHcDFrbjg5eExQejlhQ1cxeEs1cVdjZUVGSkJEL2MzWklpS3lx?= =?utf-8?B?bUpyNnNLNG1odW5uZDEzMEh2TGdvdGZmbU85NFFZcThlYmovQnRHSHZISk12?= =?utf-8?B?Qko0ZllZTlh4d0hqUXllSFBPeWdnZ3lxOWlEZTN4K2ZwMUpUSitJR2tDQUxB?= =?utf-8?B?N3ZrUHdRcTRpNldvSyttYjBQRUg1dDd2a21ObVM5VEJVZVo0ckZabHJvRzE3?=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dUY2K2ZNZWJjZnBj?= =?utf-8?B?aFJtandsdmVzUkhidkl2OHlrWGlWZFFzb2x3S0Y5ckIxZjF6dWo3WVpWQjZq?= =?utf-8?B?L0ZNT05lQ2pLNE45U3A5dzNGa2ZiY0RSTkZFL3dQYnpzandSZUtTbEFydHB6?= =?utf-8?B?amp3VmozRzJudnQ1RzZKR0FSclJIZGRKT2QwTWZBdnNSTmw4QUlBM2QrMkVy?= =?utf-8?B?SDkxalc0V0ZyN0FhSHgrNTVuSlg2QlV0Wm9rd2tVcUxUa29MYk9tTWMrYkZL?= =?utf-8?B?WHFNeEQrVzB3ekQvS29ZeE00WXdGRHhRWFdDZFdDc2k5aHNHMXM4ZmFuWUFw?= =?utf-8?B?ZTZCQzRMRE9tRzE5VUl5eXRJTDhtalFqT0dCSm5NTUtWS0QyR25md1ZjVHJo?= =?utf-8?B?OTEzN0NIazlobUNWOEYzZVV5bkErdThNWFh6NERub2ZmRGlOd0hKUS9ZZ1h4?= =?utf-8?B?S3g2ZVd4WGNVOWN5VlNmNXZyaWk2UXdoUUU0QTBoSkpvaXdueEtYY0luYi96?= =?utf-8?B?ek1Na0dDUUZ2RCtFeU1qVWJ6NVo4NG80Z3EzNlNrNEFMTVkrNkhzc0pwWHdD?= =?utf-8?B?Vm55bVFEZVRKbDJMUFhRM2NjOUdTVzFIcTdXQWhsTzZJWGV5d2RFS3NsY2NS?= =?utf-8?B?TDl1bDVFTVFMd1dUQ0JHRnRIbzJ1QjlXV1cvam82K1o3OGlMdXBlUTNzcUg3?= =?utf-8?B?UHdOcmtZQkNzTnJhUDQ3Uk91cFdWR2FhMTBUZGVxdGJNRHA4MW1jWjdFTk9I?= =?utf-8?Q?hQDI=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fecfa18-a45c-4845-206f-08db310d6bed X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2023 10:56:32.0399 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CNRadyi83x+X2Mk7L+EoIz682MNWjFaBT/bj8nKhTxZEX/EgmVmnVMZ84h6wv0Qo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4265 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 Am 30.03.23 um 12:53 schrieb Jani Nikula: > 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ís Mendes, whose patch >> added a new u64 variant of rounddown_pow_of_two(). This version instead >> recalculates the size based on the order. >> >> Reported-by: Luís Mendes >> Link: https://lore.kernel.org/lkml/CAEzXK1oghXAB_KpKpm=-CviDQbNaH0qfgYTSSjZgvvyj4U78AA@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, u64 chunk_size) >> unsigned int order; >> u64 root_size; >> >> - root_size = rounddown_pow_of_two(size); >> - order = ilog2(root_size) - ilog2(chunk_size); >> + order = ilog2(size) - ilog2(chunk_size); >> + root_size = 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. Yeah, but that isn't vital. We just use u64 for the chunk_size for consistency. In reality I wouldn't except more than 256K here. Regards, Christian. > > > BR, > Jani. > > >> >> root = drm_block_alloc(mm, NULL, order, offset); >> if (!root)