From patchwork Wed Feb 14 05:22:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 13555960 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AA28C4829A for ; Wed, 14 Feb 2024 05:22:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 64A9C10E1A3; Wed, 14 Feb 2024 05:22:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="OB2tvQZv"; dkim-atps=neutral Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2064.outbound.protection.outlook.com [40.107.223.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5360810E2BC; Wed, 14 Feb 2024 05:22:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WIZqMrIreR2bMNKfCjcocrB3RfO50RQr94Ux8aOiBgFW7xZjuBzX/qWJ8hAMHUvb9tkc1OZzXKing0g6ii7hpFD6XOtpO6Nkfbu6v8Qgc4mZ5XIweMQiW6O3x3jVGLOm4bIfclblzx05W//SvObbWSgE6R3L8FaGrWZg5dD42Cci+t2O9+GJaOw586m9polMf2VhIQBZdbmEnO4eIpq3PNQ41Qkp6ULXmFzYkEDXGkDimWjYekRqgtWOSi0ZDBX1nI1GavEMSw973vPwaekLLXPN4LdDwla2Q6pOMy5BpKbB2S4qec4SI92Sbs/IOVTg+fmiP+bOsDOQNS9PORMMIA== 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=qkdu6Myyqg8Cmg4PTCDnX9YhrNcYLp3uOeKpuuacY9c=; b=J62AqdRLKu1m1MxsAarTDssrrarVXUXv0V6ymV17tdUrHxXWuKLbKPZALsTqtINZidQPuT2FvuqN9BRV/Sk/u8x2m0HC9N2/VVHMC7lZQ52xCMBS40cIMMKEWBre3lRv+2bpPVNOyatWT+mtnvzo+0iIoQcfZj5F8c1xufPgHwPzO3tVhbwW2ezzXejqissuLfFzlLLgkEKOkriLofUdmPsZng6mLjBJ7mKKGtrCrqzh+ULOj3S3K6WQNvK8F0pbLHDiauLIyyhsLqDrZhaeoJEK9YuYwLukpHJd3oGBphw/jHol5RGqewesoWC92BWK9DhspejgpxNQmqSul62Dpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=qkdu6Myyqg8Cmg4PTCDnX9YhrNcYLp3uOeKpuuacY9c=; b=OB2tvQZv+Co0DPZSxnjmkmsSxHgVWtxoXniNr44Bj157hBV4WMqM5ZYVPBkGso4EqQ1ySdCvztFONbbe2RdOlsa9j/qZsWGZThhm4o5kSn2a5bYhBzX1kfaB9gdm5AzKIpyLfflSCugHZnKLHa0Kcu8uP46lAIIRxRY+9yXjINQ= Received: from DM6PR12CA0003.namprd12.prod.outlook.com (2603:10b6:5:1c0::16) by DS7PR12MB5837.namprd12.prod.outlook.com (2603:10b6:8:78::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.21; Wed, 14 Feb 2024 05:22:29 +0000 Received: from CY4PEPF0000EE34.namprd05.prod.outlook.com (2603:10b6:5:1c0:cafe::b2) by DM6PR12CA0003.outlook.office365.com (2603:10b6:5:1c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.39 via Frontend Transport; Wed, 14 Feb 2024 05:22:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE34.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Wed, 14 Feb 2024 05:22:28 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 13 Feb 2024 23:22:25 -0600 From: Arunpravin Paneer Selvam To: , , CC: , , , , , Arunpravin Paneer Selvam , Subject: [PATCH 1/2] drm/buddy: Fix alloc_range() error handling code Date: Wed, 14 Feb 2024 10:52:07 +0530 Message-ID: <20240214052208.3035-1-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE34:EE_|DS7PR12MB5837:EE_ X-MS-Office365-Filtering-Correlation-Id: bf322ab0-1c77-4c89-2fff-08dc2d1cf02b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N1oh+SLwFdgW13Wtg+wIpWTRo2hV+Zj5BHDVflKJXgnoLav5+W2nkxOJ30jAonPieY4qMI8NtGvqXc2VEpmZ0Ko8RuSZEE+hAbfD8qSnDwZGyQ9AwltpqLpt8nem4Hd45NmUe+0ARdlMXNG3FKdgx9ODMCwqBT65d88sH0CFiXeDji99F7OPAl8GNAs/l1AHPDWEGdqwunC3u2xJzISlUZlusTVhp1Ypi4h9FNV28IkbznDjT7PAIg/ub/LQSrPkjDzVZxfAKYejcTU4Du+3tqOcqmam190W82MSqpKWIMatvMaPLgrY7NhKZWmy4XcRfwY4yOMNWwN3SHxDk72rT9Pp8wzYDz53WJ5aG2xKR/SvN1tslaX0eDnjkeb3mp8kp+DgFIv1ikdny9n/6dDpwXBvfdnkiINhteJmEDb3vCiO4OvOAu36VBi93zeJtCF0FAhuFzbsi4TFOiDR80/NcFdWU6NQpn2H6vvol9WKbxF65meFYzSutIelSGamQxgS9rmSCkB+2GLYbQDjFaB8bXrto0VjMWztFaIB8d2PPrILJOBT9SnOj1zgIfF1xmFen5JeRiJ8ZyATUXQYWctAmg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(136003)(346002)(376002)(39860400002)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(186009)(36840700001)(46966006)(40470700004)(2906002)(966005)(7696005)(36756003)(1076003)(110136005)(6666004)(82740400003)(83380400001)(426003)(54906003)(26005)(336012)(478600001)(316002)(2616005)(41300700001)(70586007)(16526019)(70206006)(8676002)(8936002)(4326008)(86362001)(81166007)(5660300002)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2024 05:22:28.9745 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf322ab0-1c77-4c89-2fff-08dc2d1cf02b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE34.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5837 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Few users have observed display corruption when they boot the machine to KDE Plasma or playing games. We have root caused the problem that whenever alloc_range() couldn't find the required memory blocks the function was returning SUCCESS in some of the corner cases. The right approach would be if the total allocated size is less than the required size, the function should return -ENOSPC. Cc: # 6.7+ Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation") Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097 Tested-by: Mario Limonciello Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/ Acked-by: Christian König Reviewed-by: Matthew Auld Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/drm_buddy.c | 6 ++++++ 1 file changed, 6 insertions(+) base-commit: 2c80a2b715df75881359d07dbaacff8ad411f40e diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index f57e6d74fb0e..c1a99bf4dffd 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm, } while (1); list_splice_tail(&allocated, blocks); + + if (total_allocated < size) { + err = -ENOSPC; + goto err_free; + } + return 0; err_undo: From patchwork Wed Feb 14 05:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 13555961 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50F50C4829A for ; Wed, 14 Feb 2024 05:22:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A26CA10E36B; Wed, 14 Feb 2024 05:22:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="qYCxAjuy"; dkim-atps=neutral Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2089.outbound.protection.outlook.com [40.107.220.89]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA72210E33A; Wed, 14 Feb 2024 05:22:37 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Si1+bpoQNfoyqWwiDPJEjDIGOwV7SqI2GKX3myzAbTi51svXmXMROaQddlPAvclBqKMoVceOPQjq7BQXAnQ7BvtOe0Vl+twvCQxUl81H0jHj1vE+pRiCq/fhuKpvtmAruFz/NipPtpWF+bNbOvdUCEwkClF9ZbJlVrVlmBV7P+bIIL3OkeHCzu1UtEa+zP9sTvDPGd1FOTL8iLxcI4h+LOdOxlTH8XnSMvNZa2l69R9eC4gt9jy+Uv/88mh4/bi2akydqsuRxz4ErFiQRCGnRyUtwK2Ybiki2jzP3fpULxu2P3vbYwkN4LuBjJFwWVJAzFs4gRR/9/IcpN7GJjYSpw== 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=YGh7i6wAe3vTIS5iSMRiWzVAXCQn1NU1AqQdWxMKfV0=; b=Vicie5IRr2EKpRQlQBUGgVp3axxlky/4oXCxDX/LQ7qNRGiicUq/fQBxSJMt0jdB6p9YhBefSG+0P4G7htixzxOgOhE7Ux3q8/RSB4pIv+G4qAbtWzuPIeDPmBqe+Ht2I3wMQJqeTjxIOzTvIpYZyPU7T/dahDqgOpnVM2Jzh4AeP63SqYlmOJowWYWx/1YOMzqtBHRawe0XXCtYtuvtmCZyaVZ17OFEHZKReh5dBY19Kw7msHSNOmbrv4gB1t1rB/SHkJnmIpCM5jvVPnqc9bMVD+zs94a9I8UahG+SGBDKSvr/ziyUa9npon3ANUR64r9IM9P4USv/6wYo0f3xkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=YGh7i6wAe3vTIS5iSMRiWzVAXCQn1NU1AqQdWxMKfV0=; b=qYCxAjuyB4HHHvaEb8NDq1ffjr265VjZSEYOec1JQZYq4LydB9hPPIb5ePZbRhjBD1OEVXwCuU9Gm5PpjEcJRPyzX2fwt4C3npnS4EZ14sfAlACLtUVOI0rnsmsOfg2h4jryh04WJIiCXplnrk7MiNrWEJSs6rJaUe6Htft4VO4= Received: from CY5P221CA0096.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:9::31) by SA3PR12MB9177.namprd12.prod.outlook.com (2603:10b6:806:39d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.18; Wed, 14 Feb 2024 05:22:32 +0000 Received: from CY4PEPF0000EE32.namprd05.prod.outlook.com (2603:10b6:930:9:cafe::8c) by CY5P221CA0096.outlook.office365.com (2603:10b6:930:9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.26 via Frontend Transport; Wed, 14 Feb 2024 05:22:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE32.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Wed, 14 Feb 2024 05:22:31 +0000 Received: from amd-X570-AORUS-ELITE.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 13 Feb 2024 23:22:28 -0600 From: Arunpravin Paneer Selvam To: , , CC: , , , , , Arunpravin Paneer Selvam Subject: [PATCH 2/2] drm/tests/drm_buddy: add alloc_contiguous test Date: Wed, 14 Feb 2024 10:52:08 +0530 Message-ID: <20240214052208.3035-2-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240214052208.3035-1-Arunpravin.PaneerSelvam@amd.com> References: <20240214052208.3035-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE32:EE_|SA3PR12MB9177:EE_ X-MS-Office365-Filtering-Correlation-Id: eb009395-3353-4355-a96c-08dc2d1cf1e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +UUs4qmGvJwb+ruhfp8RxwV0pPi0Jjr48OkYPtCd4PODH9iSgCbj2qCUFygh2C4jgyhIA9+5vSIM2UfQZVoxoGoiB/N7MLU2WDWLXv8ioaZMkJd8ZqJ8k3Fu9ow4kO3wNTnUpb39Gax6ikLYCQz6n40VGGqiXeARu3x9E2PCePpqaHRE7adD2IOiErqsV6LIyPCWnOiPUMtnSiapHmUX/LfB/rkVEHkSX6IvR80+qqH2xjfyN/9afdED40e/zXSTVl4EcxGO1cLKTd8xnDk8hg/wLgP+uVpXlFWl5zBQBTGnE4e2AZE+70PCbs+euNLsWR9C7asL63JtcXw56wf8IiaploMr/vfdrIgFTv4zW9RMO4llLkNbJyOO4gA5Fpxw1iXpve05xywvmUQeTlLxz+cg7DvKCwB/BkGFFeFHh0/tNTyN9FfyFl/NbghNDt0fN0KiPGmmGRf0fw1H6nLyIkUB0pR+KAZ+zlFyniuxG/NsfpItYE74ud8WbcL0dbrPgnkbywEurKuryJBciecRoKJraASeG9mMQCBSiI8ztK9Xp96mR+Mf5xIL7lA04/hpxrTKSt+4oKxPTk+raYVGAg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(376002)(39860400002)(136003)(396003)(346002)(230922051799003)(64100799003)(1800799012)(82310400011)(186009)(451199024)(40470700004)(46966006)(36840700001)(356005)(83380400001)(86362001)(82740400003)(70206006)(70586007)(478600001)(81166007)(966005)(426003)(6666004)(110136005)(2616005)(54906003)(16526019)(1076003)(336012)(7696005)(26005)(36756003)(66574015)(316002)(5660300002)(8676002)(2906002)(4326008)(8936002)(41300700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2024 05:22:31.8325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb009395-3353-4355-a96c-08dc2d1cf1e1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE32.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9177 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Matthew Auld Sanity check DRM_BUDDY_CONTIGUOUS_ALLOCATION. References: https://gitlab.freedesktop.org/drm/amd/-/issues/3097 Signed-off-by: Matthew Auld Cc: Arunpravin Paneer Selvam Cc: Limonciello Cc: Christian König Reviewed-by: Arunpravin Paneer Selvam Signed-off-by: Arunpravin Paneer Selvam --- drivers/gpu/drm/tests/drm_buddy_test.c | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c index ea2af6bd9abe..4215d8b5fcf0 100644 --- a/drivers/gpu/drm/tests/drm_buddy_test.c +++ b/drivers/gpu/drm/tests/drm_buddy_test.c @@ -8,6 +8,7 @@ #include #include +#include #include @@ -18,6 +19,93 @@ static inline u64 get_size(int order, u64 chunk_size) return (1 << order) * chunk_size; } +static void drm_test_buddy_alloc_contiguous(struct kunit *test) +{ + u64 mm_size, ps = SZ_4K, i, n_pages, total; + struct drm_buddy_block *block; + struct drm_buddy mm; + LIST_HEAD(left); + LIST_HEAD(middle); + LIST_HEAD(right); + LIST_HEAD(allocated); + + mm_size = 16 * 3 * SZ_4K; + + KUNIT_EXPECT_FALSE(test, drm_buddy_init(&mm, mm_size, ps)); + + /* + * Idea is to fragment the address space by alternating block + * allocations between three different lists; one for left, middle and + * right. We can then free a list to simulate fragmentation. In + * particular we want to exercise the DRM_BUDDY_CONTIGUOUS_ALLOCATION, + * including the try_harder path. + */ + + i = 0; + n_pages = mm_size / ps; + do { + struct list_head *list; + int slot = i % 3; + + if (slot == 0) + list = &left; + else if (slot == 1) + list = &middle; + else + list = &right; + KUNIT_ASSERT_FALSE_MSG(test, + drm_buddy_alloc_blocks(&mm, 0, mm_size, + ps, ps, list, 0), + "buddy_alloc hit an error size=%d\n", + ps); + } while (++i < n_pages); + + KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 3 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc didn't error size=%d\n", 3 * ps); + + drm_buddy_free_list(&mm, &middle); + KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 3 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc didn't error size=%llu\n", 3 * ps); + KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 2 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc didn't error size=%llu\n", 2 * ps); + + drm_buddy_free_list(&mm, &right); + KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 3 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc didn't error size=%llu\n", 3 * ps); + /* + * At this point we should have enough contiguous space for 2 blocks, + * however they are never buddies (since we freed middle and right) so + * will require the try_harder logic to find them. + */ + KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 2 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc hit an error size=%d\n", 2 * ps); + + drm_buddy_free_list(&mm, &left); + KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, + 3 * ps, ps, &allocated, + DRM_BUDDY_CONTIGUOUS_ALLOCATION), + "buddy_alloc hit an error size=%d\n", 3 * ps); + + total = 0; + list_for_each_entry(block, &allocated, link) + total += drm_buddy_block_size(&mm, block); + + KUNIT_ASSERT_EQ(test, total, ps * 2 + ps * 3); + + drm_buddy_free_list(&mm, &allocated); + drm_buddy_fini(&mm); +} + static void drm_test_buddy_alloc_pathological(struct kunit *test) { u64 mm_size, size, start = 0; @@ -280,6 +368,7 @@ static struct kunit_case drm_buddy_tests[] = { KUNIT_CASE(drm_test_buddy_alloc_optimistic), KUNIT_CASE(drm_test_buddy_alloc_pessimistic), KUNIT_CASE(drm_test_buddy_alloc_pathological), + KUNIT_CASE(drm_test_buddy_alloc_contiguous), {} };