From patchwork Thu Feb 3 13:32:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734130 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 43301C433EF for ; Thu, 3 Feb 2022 13:33:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4CDC110F7D0; Thu, 3 Feb 2022 13:33:01 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2045.outbound.protection.outlook.com [40.107.237.45]) by gabe.freedesktop.org (Postfix) with ESMTPS id BC63910F7CE; Thu, 3 Feb 2022 13:32:59 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j1rP3wZ/X9cIwlOUVM8qmGO4MZ9AnDBeV352BEQABWXN9SpfwhwlZe1Prr8X6jwiA/dDAKV6vDavs3aQicU3ZO2bCIJx2dtKU81HPIIT6MtshJ/n8FGL8coQCoGK0CbEZzqd66RXVchgumawxD6CDDNwcqhmec1Td2plqIbruLZnl24/Xjuj29Awu5mImOi09aUlDk4JzX4pQq5KIQttTG4/nMh4YU5Ti+0f0Eek3KwOQmLrHslJbgy9pxEJzd+w5pcboGGT7M5Gh3ritgzF9nEtmJ8HKrkqOaQb0AcLXzFWTFFfY58cynh3aG/kPEzatdg8QryeQOVvFXB0uw/4ug== 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=e+0Vc/m6fnGYy5tAaJh0fWUeZJR79dokkHdBpFhtfF0=; b=QYa9EJPoqdxIWeWj0tDFbANYkNrV/ZEf+N6VRLwOtynWqtZ0WAXmfOEcA66Z5gxB27L94VaTvZCRs4eG41pWFD4HensWLnO534h3E3XxXHqhN5ncDimSYQR76YyovL4p2GgoxeLwUCgf02j/5RXq1SKzRcoxhIT3jRD3WErGHkk+rO3IHTrAD/PlX/nhjljVzB+eA2Et5+W7vXNTs6Cu/JnIJ+8DUJ/zHrPwj3g3P8pfV+rB4GzoyQxauBvj4V5axLOG9y94XdqocZykgzo7P8mtxDBWGLkMoTCpxmxzciwEhT5UuqWZ8afVuztQQLuHJrU+VVY58B/trSynQA7odA== 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 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=e+0Vc/m6fnGYy5tAaJh0fWUeZJR79dokkHdBpFhtfF0=; b=twuAmZ8RcOC0jhsajofHvjc6/VPABb4l8TYi3kJjq9Rmydy6MqcS38lDI5Ih7dvQHmwgyMpkPcvOI27VuH0aZawFBURRtf6plf+UmlUubqCGW9Pj9FZdg/Al1AsAGtor/d/xk6zxzhvZ9Cakbl260+eyCjm70HcP7KNb7c1u/RA= Received: from BN9PR03CA0674.namprd03.prod.outlook.com (2603:10b6:408:10e::19) by SN1PR12MB2526.namprd12.prod.outlook.com (2603:10b6:802:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 13:32:57 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10e:cafe::c5) by BN9PR03CA0674.outlook.office365.com (2603:10b6:408:10e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:32:57 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:32:56 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:32:53 -0600 From: Arunpravin To: , , Subject: [PATCH 1/7] drm/selftests: Move i915 buddy selftests into drm Date: Thu, 3 Feb 2022 19:02:28 +0530 Message-ID: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: a3f665f1-e411-4385-a25b-08d9e719b05c X-MS-TrafficTypeDiagnostic: SN1PR12MB2526:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pntX5WHCZd6J8+hU/s+GpCxDRY0aCaugoVewGASPB8T3JT7ugYrd/xFbAVJUYt2kJIDgpn8GBYkw61jQ7crvqGfjVeXl4cxiRvCKmSVUgVg5a9ii+3emVCLDbg5oAiPyP8XYYx6CtyHBc++Hij1kKxBF/mbvWNAEsxLdkKQv1B5vgJr/6M6iESSCAjwUedANeB6xIh/vf9Y/PmWHLKt6F6CtC++DYbllcblU/MW90gqzYtzw5ouz22lrBhtZ5RjrCSYFOL2JjmC493G9bDzDCfm7iFJWOCZow006cQ3q3N2bwJrdItKMZq9Q5laBloRFCyuEeXctGJmFk7MdvUFvaJR+AFgbbLjumE3jLJQelvhuUbWz9YWwLB/hxZNkQSHveqr658qDiSiie0esVXNQJGtfKB7SqkIH7VVHXOIYBlVxxMKfQdu6YGMOnDoAKbJS1BLySfSV/0jiaIFFYaxHm7N08hI2Ud7HjqjuG4RDrHC61EpGQ338P32VS/gmhRzRym71GsGeu/8Eexzmru5JsfIXviQbSFzEBYdX61AZWCbS+VShWKWz41tf2AxjcL7Tdhijs6HRWrjgGJcPu87Qir6clX0MB5gEWJqzSsfNVrwCXPmHosqE1tmOwy49yK65q7xwwgVSw8mTvOPlPiQiDI8Uh7X2Vcmb47DdNFOvVPN9XCIXvCCaBqlf+Yy7z/5f4/ku5EkZAgn4nO4to9a20g== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(54906003)(316002)(8936002)(70206006)(110136005)(70586007)(8676002)(4326008)(2616005)(7696005)(2906002)(36756003)(5660300002)(508600001)(6666004)(16526019)(336012)(426003)(86362001)(356005)(81166007)(186003)(26005)(1076003)(47076005)(40460700003)(36860700001)(82310400004)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:32:56.8070 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a3f665f1-e411-4385-a25b-08d9e719b05c 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: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2526 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - move i915 buddy selftests into drm selftests folder - add Makefile and Kconfig support - add sanitycheck testcase Prerequisites - These series of selftests patches are created on top of drm buddy series - Enable kselftests for DRM as a module in .config Signed-off-by: Arunpravin Acked-by: Matthew Auld --- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/selftests/Makefile | 3 +- .../gpu/drm/selftests/drm_buddy_selftests.h | 9 ++++ drivers/gpu/drm/selftests/test-drm_buddy.c | 49 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/selftests/drm_buddy_selftests.h create mode 100644 drivers/gpu/drm/selftests/test-drm_buddy.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index eb5a57ae3c5c..ff856df3f97f 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -71,6 +71,7 @@ config DRM_DEBUG_SELFTEST select DRM_DP_HELPER select DRM_LIB_RANDOM select DRM_KMS_HELPER + select DRM_BUDDY select DRM_EXPORT_FOR_TESTS if m default n help diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 0856e4b12f70..5ba5f9138c95 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -4,4 +4,5 @@ test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \ test-drm_damage_helper.o test-drm_dp_mst_helper.o \ test-drm_rect.o -obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o +obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o test-drm_cmdline_parser.o \ + test-drm_buddy.o diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h new file mode 100644 index 000000000000..a4bcf3a6dfe3 --- /dev/null +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* List each unit test as selftest(name, function) + * + * The name is used as both an enum and expanded as igt__name to create + * a module parameter. It must be unique and legal for a C identifier. + * + * Tests are executed in order by igt/drm_buddy + */ +selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c new file mode 100644 index 000000000000..51e4d393d22c --- /dev/null +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2019 Intel Corporation + */ + +#define pr_fmt(fmt) "drm_buddy: " fmt + +#include + +#include + +#include "../lib/drm_random.h" + +#define TESTS "drm_buddy_selftests.h" +#include "drm_selftest.h" + +static unsigned int random_seed; + +static int igt_sanitycheck(void *ignored) +{ + pr_info("%s - ok!\n", __func__); + return 0; +} + +#include "drm_selftest.c" + +static int __init test_drm_buddy_init(void) +{ + int err; + + while (!random_seed) + random_seed = get_random_int(); + + pr_info("Testing DRM buddy manager (struct drm_buddy), with random_seed=0x%x\n", + random_seed); + err = run_selftests(selftests, ARRAY_SIZE(selftests), NULL); + + return err > 0 ? 0 : err; +} + +static void __exit test_drm_buddy_exit(void) +{ +} + +module_init(test_drm_buddy_init); +module_exit(test_drm_buddy_exit); + +MODULE_AUTHOR("Intel Corporation"); +MODULE_LICENSE("GPL"); From patchwork Thu Feb 3 13:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734131 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 D5D64C433FE for ; Thu, 3 Feb 2022 13:33:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E0AE110F7D9; Thu, 3 Feb 2022 13:33:06 +0000 (UTC) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2089.outbound.protection.outlook.com [40.107.212.89]) by gabe.freedesktop.org (Postfix) with ESMTPS id 868D610F7D4; Thu, 3 Feb 2022 13:33:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kfY9eGB+A1K5jFUzKXcQO4+K5P+EVJ8FkXye3ifp6KRUbn2xLbfuN0jr4cZl2NoTRLjPBZ+5z3/cGeyQ8scCUDYb4zyK+GRluxhCnJaiZ1ZTzhPJNT0Monb6RD8sXB21IyQtgqjVfx8rmfXRaYtI0UbR7MYY+82lF/4s5G3a3Ld6Sdz8/kI+nsejNO2wcuyOQ8ZBvJI81IPMa/6ql7SuYf0itAhdWooCwB5RFxnpxCSSZT8jcT6ebLfgK2Gk1IgZV52h2s5vy+UhUQ/52oTIWHpwqk1sQhRzLPMI1NYlvd3f4qVoQNFvaeabdS3+4Xh6CwCxWQGzKv47c5pcbYADRA== 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=zVQWvBK9iMhnvZM4af0RCR4osVo3aXQ97WI30dRV+cs=; b=ZxSGQKCqFfkOhTPuxwh9q/AwgrNo0m1PaBReCKGoyVVrwDaXIqb2KKV8TLpiKZrrWBhjgxa+IIDTfrDOcRfRLa5s3aLYZzDwcS4Sq1+fkyzkpGJunIynzJi/sKhEtRYPMgzsegp3QiBKV5fQSrpGRXRuiFXU4WhIaBQjf5CHb6TjC08VS+2p+l4Ba1O59KhP7hQuKf8pEi6qTVBI4ib7dQxDcePxsdTiV9Dsb7TZx4nD3AFbo6tsDBntAI1aGqL86hMhRyjnTXdILKSSDW6ui2vQ55mX2VqHbGUZZi94Z2lErcg4rGrGBCp5LnqHV8ZySa1vUqyfJHeR1ekGeunkbQ== 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 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=zVQWvBK9iMhnvZM4af0RCR4osVo3aXQ97WI30dRV+cs=; b=g/ulytL809CzIi6WjHIQqHrilr+j3gv0Z6FunPDVbi9QYcAqiolL+ntS8KdKEaCQccWv04ZetWeUXcoAT+96p/vMGvJc+uAeMRCPkrWu7zfYAzC6ElG4nCSfD8I5fJ9gNwucyo41jcKK+Dw7DZUON3nf66uIAqvJpLHGc+3NVmQ= Received: from BN6PR13CA0008.namprd13.prod.outlook.com (2603:10b6:404:10a::18) by BY5PR12MB4818.namprd12.prod.outlook.com (2603:10b6:a03:1b4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 13:33:00 +0000 Received: from BN8NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:404:10a:cafe::7f) by BN6PR13CA0008.outlook.office365.com (2603:10b6:404:10a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.5 via Frontend Transport; Thu, 3 Feb 2022 13:33:00 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT010.mail.protection.outlook.com (10.13.177.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:32:59 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:32:56 -0600 From: Arunpravin To: , , Subject: [PATCH 2/7] drm/selftests: add drm buddy alloc limit testcase Date: Thu, 3 Feb 2022 19:02:29 +0530 Message-ID: <20220203133234.3350-2-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: 868d9e64-0c1f-48d2-b135-08d9e719b240 X-MS-TrafficTypeDiagnostic: BY5PR12MB4818:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:217; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QStLjOjvF8gDQSKJkKH8A04W5KROpFreuZxwnY87MTfis6zTJDwGLDP0qi5Hrpgeo4VqQe77gYP4VmDlNk3y0BOz9J1p4SsSyDZHKu1IGFkMvKdyJWP0WEaJHX41rvCrG9guorLGNxSGiR6TvUK6tNlVj/mWiLMTT/EcUCAwmwjz5GUSMbl7Bqc8OgzpRdi5hhLs1NbKXxLcml8cKtjNcI2Xj7+HyfImtRqxtGqa8SKt4TbXpQmgp7dmTMpRfXDtwjNo9lUY4wBdD5vrLltQtSFgZdOth6I7K8EfntsGQFa9bSJwC8R19X1/Fs6wY/Ht5r/BbW2GAjCc3bvLk47wF4bb45Xccnt0M4MzfaqrUc5z5OJMY/cSrbWXNbdRyCX+cHZXOhf/1YsxlDBT9Pq2b6JtPevVkoxTeXddLz3aYmWgdJ5cBpAsVqrOwoiJvRQFFH7Qoe/B5SSAWaBp5z2L9bwres1fZ6TtAB/Kk3Rw+n/Kh5nzvTPx438Ujeh+EU/O/MQidqgNyfshrQICbenbLAwp40865XX5Gfrrtghr5iO/Set5z6kmMc/xdU8ofnYeuU7raa0SS35RfIPZb19iD1UVoLoPCE3OJrHYOetYEVOLKPswb8uP1Yq/G636gFMALtRF0Afx6iOUWqiy2q611uUjxHHyvLpzAh/bknnrEbShhi+hxaIrDRJEhxBPsKW0Iq7ilLChxTZeYqQTasTAmg== 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:(13230001)(4636009)(40470700004)(36840700001)(46966006)(8936002)(4326008)(110136005)(508600001)(26005)(54906003)(8676002)(316002)(186003)(2906002)(5660300002)(7696005)(6666004)(36860700001)(1076003)(47076005)(426003)(83380400001)(2616005)(40460700003)(82310400004)(336012)(81166007)(36756003)(70586007)(356005)(16526019)(86362001)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:32:59.9793 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 868d9e64-0c1f-48d2-b135-08d9e719b240 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: BN8NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4818 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" add a test to check the maximum allocation limit Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index a4bcf3a6dfe3..ebe16162762f 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -7,3 +7,4 @@ * Tests are executed in order by igt/drm_buddy */ selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ +selftest(buddy_alloc_limit, igt_buddy_alloc_limit) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index 51e4d393d22c..fd7d1a112458 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -16,6 +16,66 @@ static unsigned int random_seed; +static int igt_buddy_alloc_limit(void *arg) +{ + u64 end, size = U64_MAX, start = 0; + struct drm_buddy_block *block; + unsigned long flags = 0; + LIST_HEAD(allocated); + struct drm_buddy mm; + int err; + + size = end = round_down(size, 4096); + err = drm_buddy_init(&mm, size, PAGE_SIZE); + if (err) + return err; + + if (mm.max_order != DRM_BUDDY_MAX_ORDER) { + pr_err("mm.max_order(%d) != %d\n", + mm.max_order, DRM_BUDDY_MAX_ORDER); + err = -EINVAL; + goto out_fini; + } + + err = drm_buddy_alloc_blocks(&mm, start, end, size, + PAGE_SIZE, &allocated, flags); + + if (unlikely(err)) + goto out_free; + + block = list_first_entry_or_null(&allocated, + struct drm_buddy_block, + link); + + if (!block) + goto out_fini; + + if (drm_buddy_block_order(block) != mm.max_order) { + pr_err("block order(%d) != %d\n", + drm_buddy_block_order(block), mm.max_order); + err = -EINVAL; + goto out_free; + } + + if (drm_buddy_block_size(&mm, block) != + BIT_ULL(mm.max_order) * PAGE_SIZE) { + pr_err("block size(%llu) != %llu\n", + drm_buddy_block_size(&mm, block), + BIT_ULL(mm.max_order) * PAGE_SIZE); + err = -EINVAL; + goto out_free; + } + + if (!err) + pr_info("%s - succeeded\n", __func__); + +out_free: + drm_buddy_free_list(&mm, &allocated); +out_fini: + drm_buddy_fini(&mm); + return err; +} + static int igt_sanitycheck(void *ignored) { pr_info("%s - ok!\n", __func__); From patchwork Thu Feb 3 13:32:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734132 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 267E9C43219 for ; Thu, 3 Feb 2022 13:33:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 09AF010F7DE; Thu, 3 Feb 2022 13:33:12 +0000 (UTC) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2071.outbound.protection.outlook.com [40.107.95.71]) by gabe.freedesktop.org (Postfix) with ESMTPS id F379D10F7D2; Thu, 3 Feb 2022 13:33:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=StCuygmHzbRQogs2rMDn1a6vdPCS16l+MJbe5q2fD19KcQeWflMbTh/PxtKZ/gXQH6epbP/lnreZtOVWsmAVF27MfdBl5iU0yqQcwotYM2Lw7I1NoikB0nIFJVTRH/DuhbUJK8ZRJRSiJ5LAFsPgrS/d94eay99O86ZsIE8oxxEAMmLtEB/Ei26OuG1j5YZ8v4kP7leDu4QvldpYeWNeL6QB/j2BUj2yf3813pBwguKdOvJHf1JPayFzvY1rhnH51cdDG8WpulvRbJZ7RKlvrVKGZqwnbJJAWvL1G3AT/rP4AQchwfeIw8whfp0Pbt49D66igNIQSlZ4ITBSkxQU6g== 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=wW9RgS3GjnHRwpVbLiNy0QYkgNmhfOXLtzfk6hB/ePI=; b=XfatAn+Al308aDX8yMwHoEdhWAJRGsi2R0xFu0F2vJ62FQ66JpJAFRwmVNvmD1LrpKBQe1VKA2m487dR5bdTPZAVOtaH1FvcnorBPjY3A1KDVJDS9cY076beckeTP6K4ogE3SsMfiUTTnC0SApFyGT//P8fopKk1nOZSFY79fNUflHScKh3gp8pMHLoygG5lyZ37q1jo2l1MXRVi45pT2dd9yvn0Alu2lvqnWGQPr9e3Mb6+JxYMlweP33eyYh6d0KtZeiqyIY6aM4vo+YzAZy6XXaj3SsQ0STh++CT57hqqgoS2NXskdzOGhK2bxcPYZiBj3duigxHbxiwArbGuTQ== 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 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=wW9RgS3GjnHRwpVbLiNy0QYkgNmhfOXLtzfk6hB/ePI=; b=ULKaWe1EwWav+6loqba881Vvv//yuTcA9MgSn0DV51Y3zFyQJCPwYmnz/6k8KfopH12XdWaNRpY+lWVF5HuN6FBzb4B+GPUJAoY5mHGxDbADM86lO5CVXf5H4FNkz1rkbHxz2WKrYRJkVv960HpNiq3Rqh39PhIcG+mM+Y0uHao= Received: from BN6PR22CA0071.namprd22.prod.outlook.com (2603:10b6:404:ca::33) by CY4PR12MB1622.namprd12.prod.outlook.com (2603:10b6:910:f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Thu, 3 Feb 2022 13:33:04 +0000 Received: from BN8NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:404:ca:cafe::4f) by BN6PR22CA0071.outlook.office365.com (2603:10b6:404:ca::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.14 via Frontend Transport; Thu, 3 Feb 2022 13:33:03 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT025.mail.protection.outlook.com (10.13.177.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:03 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:32:59 -0600 From: Arunpravin To: , , Subject: [PATCH 3/7] drm/selftests: add drm buddy alloc range testcase Date: Thu, 3 Feb 2022 19:02:30 +0530 Message-ID: <20220203133234.3350-3-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: b602489b-45c7-4b0b-4064-08d9e719b454 X-MS-TrafficTypeDiagnostic: CY4PR12MB1622:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:419; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IXCnqNEzKV7y8e9xSRfK1jkHiXLDVztq5XCi71XXTHcglymvR5RNS8WGteBtwQAGs9ql5eW9MiXGNCZZdu0PpFN5elcau3AZpeq4JmExxSW8DAHt9nEDBKI1PCWAKonINbUmbyARIrDg2ypjnbadjqAShv3QIc1TVFhor1mSX4TCHV57GAjGazW5kSC1S6xxiEUuZHmlHw4LvzW33NlIPYSd9ouIHfYbEMXjFz9vDUbJJJyLPNA3sSiF5HDrKBxeKigbHf2XGTMR0EvtWSfDGodjrZBHfwbygp6jwUI+M/TY6TIKsdzgm5/Ck7IMatpQnwM2z/n36j0ugWduHJLIDU8q/15dKp+BmAaaDSADkial98NsNzldLVIPy4SoQ06VqG8PiHq1oyOlmjbfuysXlwVe9WI0KfRMnKF516E2+UTlBCmzKsp0rJLGh3Fl23zqBI/39CzYxOHx2EN+NytlDHh+EelViVEBhpxD005+RfIs44UDJyxX89aq9YpIZwmwi6hgRcbs+IhkdjD6S2be5WnDupiuUBWWZbzi/qIf9kEnODVRPUY2LnBAYTyZNvJw9fkwkb9BZFWsFeUTnN7088B99Vfby5LMlDf5cjWizXb4/b9u1JRn0LmY6iMtSFJpcwEforfyc1JfN3CBKDHRzPfPknl5rKEY47ivV6tfQenjvc65EInL2PEy5l9YC7X6PqxvOddxLLWstwo9Ca83/A== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(40460700003)(30864003)(8676002)(8936002)(36860700001)(4326008)(70586007)(86362001)(70206006)(5660300002)(356005)(81166007)(82310400004)(36756003)(2906002)(1076003)(7696005)(186003)(110136005)(26005)(54906003)(426003)(336012)(508600001)(2616005)(47076005)(6666004)(16526019)(83380400001)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:33:03.4629 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b602489b-45c7-4b0b-4064-08d9e719b454 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: BN8NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1622 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - add a test to check the range allocation - export get_buddy() function in drm_buddy.c - export drm_prandom_u32_max_state() in lib/drm_random.c - include helper functions - include prime number header file Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- drivers/gpu/drm/drm_buddy.c | 20 +- drivers/gpu/drm/lib/drm_random.c | 3 +- drivers/gpu/drm/lib/drm_random.h | 2 + .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 390 ++++++++++++++++++ include/drm/drm_buddy.h | 3 + 6 files changed, 414 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 4845ef784b5e..501229d843c4 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -211,7 +211,7 @@ static int split_block(struct drm_buddy *mm, } static struct drm_buddy_block * -get_buddy(struct drm_buddy_block *block) +__get_buddy(struct drm_buddy_block *block) { struct drm_buddy_block *parent; @@ -225,6 +225,18 @@ get_buddy(struct drm_buddy_block *block) return parent->left; } +/** + * drm_get_buddy - get buddy address + * + * @block: DRM buddy block + */ +struct drm_buddy_block * +drm_get_buddy(struct drm_buddy_block *block) +{ + return __get_buddy(block); +} +EXPORT_SYMBOL(drm_get_buddy); + static void __drm_buddy_free(struct drm_buddy *mm, struct drm_buddy_block *block) { @@ -233,7 +245,7 @@ static void __drm_buddy_free(struct drm_buddy *mm, while ((parent = block->parent)) { struct drm_buddy_block *buddy; - buddy = get_buddy(block); + buddy = __get_buddy(block); if (!drm_buddy_block_is_free(buddy)) break; @@ -361,7 +373,7 @@ alloc_range_bias(struct drm_buddy *mm, * bigger is better, so make sure we merge everything back before we * free the allocated blocks. */ - buddy = get_buddy(block); + buddy = __get_buddy(block); if (buddy && (drm_buddy_block_is_free(block) && drm_buddy_block_is_free(buddy))) @@ -500,7 +512,7 @@ static int __alloc_range(struct drm_buddy *mm, * bigger is better, so make sure we merge everything back before we * free the allocated blocks. */ - buddy = get_buddy(block); + buddy = __get_buddy(block); if (buddy && (drm_buddy_block_is_free(block) && drm_buddy_block_is_free(buddy))) diff --git a/drivers/gpu/drm/lib/drm_random.c b/drivers/gpu/drm/lib/drm_random.c index eeb155826d27..31b5a3e21911 100644 --- a/drivers/gpu/drm/lib/drm_random.c +++ b/drivers/gpu/drm/lib/drm_random.c @@ -7,10 +7,11 @@ #include "drm_random.h" -static inline u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state) +u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state) { return upper_32_bits((u64)prandom_u32_state(state) * ep_ro); } +EXPORT_SYMBOL(drm_prandom_u32_max_state); void drm_random_reorder(unsigned int *order, unsigned int count, struct rnd_state *state) diff --git a/drivers/gpu/drm/lib/drm_random.h b/drivers/gpu/drm/lib/drm_random.h index 4a3e94dfa0c0..5543bf0474bc 100644 --- a/drivers/gpu/drm/lib/drm_random.h +++ b/drivers/gpu/drm/lib/drm_random.h @@ -22,5 +22,7 @@ unsigned int *drm_random_order(unsigned int count, void drm_random_reorder(unsigned int *order, unsigned int count, struct rnd_state *state); +u32 drm_prandom_u32_max_state(u32 ep_ro, + struct rnd_state *state); #endif /* !__DRM_RANDOM_H__ */ diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index ebe16162762f..3230bfd2770b 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -8,3 +8,4 @@ */ selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ selftest(buddy_alloc_limit, igt_buddy_alloc_limit) +selftest(buddy_alloc_range, igt_buddy_alloc_range) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index fd7d1a112458..e347060c05a2 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -6,6 +6,7 @@ #define pr_fmt(fmt) "drm_buddy: " fmt #include +#include #include @@ -16,6 +17,395 @@ static unsigned int random_seed; +static inline const char *yesno(bool v) +{ + return v ? "yes" : "no"; +} + +static void __igt_dump_block(struct drm_buddy *mm, + struct drm_buddy_block *block, + bool buddy) +{ + pr_err("block info: header=%llx, state=%u, order=%d, offset=%llx size=%llx root=%s buddy=%s\n", + block->header, + drm_buddy_block_state(block), + drm_buddy_block_order(block), + drm_buddy_block_offset(block), + drm_buddy_block_size(mm, block), + yesno(!block->parent), + yesno(buddy)); +} + +static void igt_dump_block(struct drm_buddy *mm, + struct drm_buddy_block *block) +{ + struct drm_buddy_block *buddy; + + __igt_dump_block(mm, block, false); + + buddy = drm_get_buddy(block); + if (buddy) + __igt_dump_block(mm, buddy, true); +} + +static int igt_check_block(struct drm_buddy *mm, + struct drm_buddy_block *block) +{ + struct drm_buddy_block *buddy; + unsigned int block_state; + u64 block_size; + u64 offset; + int err = 0; + + block_state = drm_buddy_block_state(block); + + if (block_state != DRM_BUDDY_ALLOCATED && + block_state != DRM_BUDDY_FREE && + block_state != DRM_BUDDY_SPLIT) { + pr_err("block state mismatch\n"); + err = -EINVAL; + } + + block_size = drm_buddy_block_size(mm, block); + offset = drm_buddy_block_offset(block); + + if (block_size < mm->chunk_size) { + pr_err("block size smaller than min size\n"); + err = -EINVAL; + } + + if (!is_power_of_2(block_size)) { + pr_err("block size not power of two\n"); + err = -EINVAL; + } + + if (!IS_ALIGNED(block_size, mm->chunk_size)) { + pr_err("block size not aligned to min size\n"); + err = -EINVAL; + } + + if (!IS_ALIGNED(offset, mm->chunk_size)) { + pr_err("block offset not aligned to min size\n"); + err = -EINVAL; + } + + if (!IS_ALIGNED(offset, block_size)) { + pr_err("block offset not aligned to block size\n"); + err = -EINVAL; + } + + buddy = drm_get_buddy(block); + + if (!buddy && block->parent) { + pr_err("buddy has gone fishing\n"); + err = -EINVAL; + } + + if (buddy) { + if (drm_buddy_block_offset(buddy) != (offset ^ block_size)) { + pr_err("buddy has wrong offset\n"); + err = -EINVAL; + } + + if (drm_buddy_block_size(mm, buddy) != block_size) { + pr_err("buddy size mismatch\n"); + err = -EINVAL; + } + + if (drm_buddy_block_state(buddy) == block_state && + block_state == DRM_BUDDY_FREE) { + pr_err("block and its buddy are free\n"); + err = -EINVAL; + } + } + + return err; +} + +static int igt_check_blocks(struct drm_buddy *mm, + struct list_head *blocks, + u64 expected_size, + bool is_contiguous) +{ + struct drm_buddy_block *block; + struct drm_buddy_block *prev; + u64 total; + int err = 0; + + block = NULL; + prev = NULL; + total = 0; + + list_for_each_entry(block, blocks, link) { + err = igt_check_block(mm, block); + + if (!drm_buddy_block_is_allocated(block)) { + pr_err("block not allocated\n"), + err = -EINVAL; + } + + if (is_contiguous && prev) { + u64 prev_block_size; + u64 prev_offset; + u64 offset; + + prev_offset = drm_buddy_block_offset(prev); + prev_block_size = drm_buddy_block_size(mm, prev); + offset = drm_buddy_block_offset(block); + + if (offset != (prev_offset + prev_block_size)) { + pr_err("block offset mismatch\n"); + err = -EINVAL; + } + } + + if (err) + break; + + total += drm_buddy_block_size(mm, block); + prev = block; + } + + if (!err) { + if (total != expected_size) { + pr_err("size mismatch, expected=%llx, found=%llx\n", + expected_size, total); + err = -EINVAL; + } + return err; + } + + if (prev) { + pr_err("prev block, dump:\n"); + igt_dump_block(mm, prev); + } + + pr_err("bad block, dump:\n"); + igt_dump_block(mm, block); + + return err; +} + +static int igt_check_mm(struct drm_buddy *mm) +{ + struct drm_buddy_block *root; + struct drm_buddy_block *prev; + unsigned int i; + u64 total; + int err = 0; + + if (!mm->n_roots) { + pr_err("n_roots is zero\n"); + return -EINVAL; + } + + if (mm->n_roots != hweight64(mm->size)) { + pr_err("n_roots mismatch, n_roots=%u, expected=%lu\n", + mm->n_roots, hweight64(mm->size)); + return -EINVAL; + } + + root = NULL; + prev = NULL; + total = 0; + + for (i = 0; i < mm->n_roots; ++i) { + struct drm_buddy_block *block; + unsigned int order; + + root = mm->roots[i]; + if (!root) { + pr_err("root(%u) is NULL\n", i); + err = -EINVAL; + break; + } + + err = igt_check_block(mm, root); + + if (!drm_buddy_block_is_free(root)) { + pr_err("root not free\n"); + err = -EINVAL; + } + + order = drm_buddy_block_order(root); + + if (!i) { + if (order != mm->max_order) { + pr_err("max order root missing\n"); + err = -EINVAL; + } + } + + if (prev) { + u64 prev_block_size; + u64 prev_offset; + u64 offset; + + prev_offset = drm_buddy_block_offset(prev); + prev_block_size = drm_buddy_block_size(mm, prev); + offset = drm_buddy_block_offset(root); + + if (offset != (prev_offset + prev_block_size)) { + pr_err("root offset mismatch\n"); + err = -EINVAL; + } + } + + block = list_first_entry_or_null(&mm->free_list[order], + struct drm_buddy_block, + link); + if (block != root) { + pr_err("root mismatch at order=%u\n", order); + err = -EINVAL; + } + + if (err) + break; + + prev = root; + total += drm_buddy_block_size(mm, root); + } + + if (!err) { + if (total != mm->size) { + pr_err("expected mm size=%llx, found=%llx\n", mm->size, + total); + err = -EINVAL; + } + return err; + } + + if (prev) { + pr_err("prev root(%u), dump:\n", i - 1); + igt_dump_block(mm, prev); + } + + if (root) { + pr_err("bad root(%u), dump:\n", i); + igt_dump_block(mm, root); + } + + return err; +} + +static void igt_mm_config(u64 *size, u64 *chunk_size) +{ + DRM_RND_STATE(prng, random_seed); + u32 s, ms; + + /* Nothing fancy, just try to get an interesting bit pattern */ + + prandom_seed_state(&prng, random_seed); + + /* Let size be a random number of pages up to 8 GB (2M pages) */ + s = 1 + drm_prandom_u32_max_state((BIT(33 - 12)) - 1, &prng); + /* Let the chunk size be a random power of 2 less than size */ + ms = BIT(drm_prandom_u32_max_state(ilog2(s), &prng)); + /* Round size down to the chunk size */ + s &= -ms; + + /* Convert from pages to bytes */ + *chunk_size = (u64)ms << 12; + *size = (u64)s << 12; +} + +static int igt_buddy_alloc_range(void *arg) +{ + unsigned long flags = DRM_BUDDY_RANGE_ALLOCATION; + u64 offset, size, rem, chunk_size, end; + unsigned long page_num; + struct drm_buddy mm; + LIST_HEAD(blocks); + int err; + + igt_mm_config(&size, &chunk_size); + + err = drm_buddy_init(&mm, size, chunk_size); + if (err) { + pr_err("buddy_init failed(%d)\n", err); + return err; + } + + err = igt_check_mm(&mm); + if (err) { + pr_err("pre-mm check failed, abort, abort, abort!\n"); + goto err_fini; + } + + rem = mm.size; + offset = 0; + + for_each_prime_number_from(page_num, 1, ULONG_MAX - 1) { + struct drm_buddy_block *block; + LIST_HEAD(tmp); + + size = min(page_num * mm.chunk_size, rem); + end = offset + size; + + err = drm_buddy_alloc_blocks(&mm, offset, end, size, mm.chunk_size, &tmp, flags); + if (err) { + if (err == -ENOMEM) { + pr_info("alloc_range hit -ENOMEM with size=%llx\n", + size); + } else { + pr_err("alloc_range with offset=%llx, size=%llx failed(%d)\n", + offset, size, err); + } + + break; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_range has no blocks\n"); + err = -EINVAL; + break; + } + + if (drm_buddy_block_offset(block) != offset) { + pr_err("alloc_range start offset mismatch, found=%llx, expected=%llx\n", + drm_buddy_block_offset(block), offset); + err = -EINVAL; + } + + if (!err) + err = igt_check_blocks(&mm, &tmp, size, true); + + list_splice_tail(&tmp, &blocks); + + if (err) + break; + + offset += size; + + rem -= size; + if (!rem) + break; + + cond_resched(); + } + + if (err == -ENOMEM) + err = 0; + + drm_buddy_free_list(&mm, &blocks); + + if (!err) { + err = igt_check_mm(&mm); + if (err) + pr_err("post-mm check failed\n"); + else + pr_info("%s - succeeded\n", __func__); + } + +err_fini: + drm_buddy_fini(&mm); + + return err; +} + static int igt_buddy_alloc_limit(void *arg) { u64 end, size = U64_MAX, start = 0; diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index bd21f9dfd15e..572077ff8ae7 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -134,6 +134,9 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size); void drm_buddy_fini(struct drm_buddy *mm); +struct drm_buddy_block * +drm_get_buddy(struct drm_buddy_block *block); + int drm_buddy_alloc_blocks(struct drm_buddy *mm, u64 start, u64 end, u64 size, u64 min_page_size, From patchwork Thu Feb 3 13:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734133 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 D22A2C433EF for ; Thu, 3 Feb 2022 13:33:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31A0710F7DF; Thu, 3 Feb 2022 13:33:12 +0000 (UTC) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2084.outbound.protection.outlook.com [40.107.243.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17FA510F7D5; Thu, 3 Feb 2022 13:33:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JMm+awwPAN93pzt0jqRbqpeCBX1j9lkmDoDIkOz4p9tTj0Z2sPfnuH+/pUGxsuGAGAujOM8SvSih59E2gpUwzFnP5L9SEBIRqlRHbkCDGGiGe/SOPwqW+GTjQr8o4QxQ+CuYPwoVmHDEY3L5sCGw/SrIJFkLPC39BH4FwGVHBoGdizBB26lehVR0WStZ6XB5txnaYv0sQCoQmjW6yycIiZVNQ2a9GxVZny0z6qJY5bH92vSvviPMwnaOPYTRPlWxJBrdfZZ/RldIMkNxZV4regnzAXS0+1ztbAj4aEPnz8eh4pJk1PaRYtgv5tNf2UT41Q7NmtVopdg1LYiw2jv7sg== 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=bMFLTpso+WStbZFYDeNTYF+bu+RrIUM2dDIejWL9ypc=; b=Ps4ajvJmZeDzu2iuA0AOCbB8jlqmgZG9w5cdiNUjtXTFvvPIh1SxTLs+jgW8FboCQvBw/uqRbENyiX7snJXbjY7QfmKRV4xd5Y4KZIDx9lLzjmjAG8O4nbvYN3pGTH8HPkukRPGCsDCNm96UyytMqyKZQrNokNgbsOfEM9ek+0eTW2l+lafEXjxqEEe55f1a7doRVLOHdOxECKOIGB+V/ZdT/9JpSitiTUedrfq2+ZkAL3ANixMVoTVenv8EawCuoMEEYxQOWbfp+K+tpqiTi00Ol3cNobWqM3QbHRFpklM/Iadw/cJbcX2k7Bv8iasGwxfNSvkQho7vllaN0zsFuw== 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 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=bMFLTpso+WStbZFYDeNTYF+bu+RrIUM2dDIejWL9ypc=; b=P4vIugantSJHL/C7PqKd+MAwzJ2HP2HpG6pXtGQtwQfhRUrtekxf1OZpfVpJZx15rqxWVAW8kjSH8zrbsjV9KvcAFE5runmFCjv5lJIyPq9QksxH1T3+VPn4a9gKyj2BEvRARBmsPeoXuAcOF3xffiR6gweBcmM07GXGbsYXnMc= Received: from BN0PR02CA0060.namprd02.prod.outlook.com (2603:10b6:408:e5::35) by MN2PR12MB3741.namprd12.prod.outlook.com (2603:10b6:208:162::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 13:33:06 +0000 Received: from BN8NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e5:cafe::38) by BN0PR02CA0060.outlook.office365.com (2603:10b6:408:e5::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:06 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT057.mail.protection.outlook.com (10.13.177.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:06 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:33:03 -0600 From: Arunpravin To: , , Subject: [PATCH 4/7] drm/selftests: add drm buddy optimistic testcase Date: Thu, 3 Feb 2022 19:02:31 +0530 Message-ID: <20220203133234.3350-4-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: bb1980df-016b-401e-eaa9-08d9e719b640 X-MS-TrafficTypeDiagnostic: MN2PR12MB3741:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:341; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L4rnvPWBVHrW71YsK9AS0/DLhTXIrJBISPbuS0v3EgYdj0tgc0vU9lyb79008Mvsi1YIkdwfRN/v3SFDWgDiJs9i500p3BdLU8emQP9VtYg+NBz4FiNnUzDd+aE/8D5hKx0GW6xaLanox84AHssMLo4I9VOBYvW187E6bhjbRwKBqeqHbaxEvZTYIrou9fASNSp+vuXMI7yVIsMpUYQZawFKBrEVlVA5vRC+zy5fdePHOETIU8gxQOOJpTs36x9+/fPTTojZDn45KMVrscSK7snTl5crpkCV4IL0saT366bwVfw1FHM/JTBZjViJaxzLmdz9GTc/RBwSN0UYWVGtRGzfwYJ0XEOwnw8kFDlBvJQ/gRLYzYIIIVig0U/WfZTY1MD/H7HH/LRVhfM70QjKCNVmpETCu9Ntom8/yb1qkuvp93gB0r1KOYOnUDm5jmFFvkmo7waN9HgDvh41WtfHvqQT/CVixtf4SgLOSIHvwHDPIAUgXzDBytiwoQoo4XFya0xkjQyzVM5JyT62MOPXSjJJWINkIntNnJU+IBrlxxS0CU+61jdPmEAGF/AyK0Yyzru0PiOgTjG9OzAKGPcvbEcnMABHzPhvzQDWtvaIrJAp1RxS/scvQmWqJk2Sk8lNqyoeZ/B6Zxt+Ip9io41Q8VVeysfcEmi5C8qes+cVUp73Wr+T7BMSatejRdU6Rg4gfayv/oeWDj3Cub3GVxQ8sg== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(2906002)(83380400001)(70586007)(82310400004)(70206006)(47076005)(8936002)(36860700001)(7696005)(6666004)(86362001)(8676002)(4326008)(40460700003)(2616005)(336012)(426003)(508600001)(186003)(26005)(1076003)(16526019)(5660300002)(356005)(36756003)(81166007)(110136005)(54906003)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:33:06.6917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb1980df-016b-401e-eaa9-08d9e719b640 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: BN8NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3741 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" create a mm with one block of each order available, and try to allocate them all. Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index 3230bfd2770b..21a6bd38864f 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -9,3 +9,4 @@ selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ selftest(buddy_alloc_limit, igt_buddy_alloc_limit) selftest(buddy_alloc_range, igt_buddy_alloc_range) +selftest(buddy_alloc_optimistic, igt_buddy_alloc_optimistic) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index e347060c05a2..b193d9556fb4 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -17,6 +17,11 @@ static unsigned int random_seed; +static inline u64 get_size(int order, u64 chunk_size) +{ + return (1 << order) * chunk_size; +} + static inline const char *yesno(bool v) { return v ? "yes" : "no"; @@ -309,6 +314,83 @@ static void igt_mm_config(u64 *size, u64 *chunk_size) *size = (u64)s << 12; } +static int igt_buddy_alloc_optimistic(void *arg) +{ + u64 mm_size, size, min_page_size, start = 0; + struct drm_buddy_block *block; + unsigned long flags = 0; + const int max_order = 16; + struct drm_buddy mm; + LIST_HEAD(blocks); + LIST_HEAD(tmp); + int order, err; + + /* + * Create a mm with one block of each order available, and + * try to allocate them all. + */ + + mm_size = PAGE_SIZE * ((1 << (max_order + 1)) - 1); + err = drm_buddy_init(&mm, + mm_size, + PAGE_SIZE); + if (err) { + pr_err("buddy_init failed(%d)\n", err); + return err; + } + + BUG_ON(mm.max_order != max_order); + + for (order = 0; order <= max_order; order++) { + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc hit -ENOMEM with order=%d\n", + order); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + } + + /* Should be completely full! */ + size = min_page_size = get_size(0, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (!err) { + pr_info("buddy_alloc unexpectedly succeeded, it should be full!"); + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + goto err; + } else { + pr_info("%s - succeeded\n", __func__); + err = 0; + } + +err: + drm_buddy_free_list(&mm, &blocks); + drm_buddy_fini(&mm); + return err; +} + static int igt_buddy_alloc_range(void *arg) { unsigned long flags = DRM_BUDDY_RANGE_ALLOCATION; From patchwork Thu Feb 3 13:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734134 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 1503BC433FE for ; Thu, 3 Feb 2022 13:33:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E78110F7E6; Thu, 3 Feb 2022 13:33:15 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2065.outbound.protection.outlook.com [40.107.94.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 01F3910F7E6; Thu, 3 Feb 2022 13:33:13 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oPr3K0GY3XkoKSIqeTR0BuNX6D529Lip7ElXAUovrnWgh2tqsoCSMVzbWeLLuNj1qN000kjnHzyjw8v3PqHsnW10MlZcEMrWXk2MVrw39mQfS+IcrGZWGzVKE9BSjuZfLFVWeDg83xRJoJsSlrxV9gRooNrhuaXtWJBiEXf+SJDyXFEvdC6NBAXTGzP6sSRSfB6spBgpXQ4TUSk35LQsOb5fSdFWWd7syw39RGlnMj7kDKGIR6OBIuIG85BZMWFeCl00QdoJNhpN3jU88FYknrvO4z23S1ovJIHhOFKALmQlGBvPf6G/3yt9NBDcGkAph9WB5O6xgZPBWzxYOEKqyQ== 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=IvmMh86UJluZVk7AYwGhD5Yex+BhIiv01HjRKon0L6s=; b=OSR/Q3Ye6C5iovz5f4TywbqA5+feX0v5zcPBahCztoD6boi2r0sGZdYYxN4gdCT8s1u8gIO9vltffvED8i5d3IGEC6f1zojWwoOgWh3Dw4PxfQ7/pw/sMxfFc+axPu7posrV//084RqneOuBGszOcAR/ggocz6Yc+a0Josf4mjJfOyIUKbio66qeSn7OdBFHTbRgoXucpR9NFYPROZTkDvoFB5H+nJqIQgwcm99sysoRYjC8UGORi8nm+7oI7o8ODLUA8YCQmyq1izR+ufwIbhcdQqTQUVPs+pPyTbO9p6zyNeYp4IxpAwNox5Zpsjp7rQjTSNq36sNOBdEaqCgblA== 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 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=IvmMh86UJluZVk7AYwGhD5Yex+BhIiv01HjRKon0L6s=; b=z+TFKO5h+V56Hmm+SAlR8PjYQDU3Koxh0PNAbz1niTeRLAureyh7NvbaSnbbLSNk3rYG9SP/AI76vSsmBGlLN84YDZkD44H1URn02/qIid1rUijWSx84+u99SNxsi7OZ68Jr4HWjDk7ZR8UEX7WrIBjD+EWGk0/iWYPl0ElO/rI= Received: from BN1PR13CA0013.namprd13.prod.outlook.com (2603:10b6:408:e2::18) by CH0PR12MB5122.namprd12.prod.outlook.com (2603:10b6:610:bd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 13:33:10 +0000 Received: from BN8NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::b0) by BN1PR13CA0013.outlook.office365.com (2603:10b6:408:e2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:10 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT026.mail.protection.outlook.com (10.13.177.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:09 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:33:06 -0600 From: Arunpravin To: , , Subject: [PATCH 5/7] drm/selftests: add drm buddy pessimistic testcase Date: Thu, 3 Feb 2022 19:02:32 +0530 Message-ID: <20220203133234.3350-5-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: 5da697d5-de0b-4887-56e6-08d9e719b82e X-MS-TrafficTypeDiagnostic: CH0PR12MB5122:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:813; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qO4PxbfindhCpEm5zVT+VMnq7JX4ErdwtPdT4URIFv9Wr6sNnEVYAZ3xA2dC36wiICQ8Xfp7piyBnrZkY+v+8J+/WNDwXqcCR1u773rd7I0UbT4iIpO+9JmbudY/bpn6R4RGhTaVeN1VEEfbJJ8pj6v992N3W4v5fYSDHiNL5iezx4y3H8WzLyp9LsZQk/iZd0TmOhXDoteo21cZRrUHbGQdkLsJN4SrTxlUkz75LTS9LpUavwvWnN/uzsl3CXcRZIRG7OU14VGSRgGaMmSUdETrcKb7L5gU6Hvxmyzx4HByWF3QCcGLQjQLTPZd7Yx+Xk9IfMTGHSXcHpZhVSdM3LhEBX1bbN5RtrAketp2tTJz3CQWbkiqYb2pc+g85gzgAyR5PYm/8NgP3E7ds287VBzHNcIkRFS8L8Ib/IDFywQ44m4+KvR4xgBWDVpzaR6ZEKtnFNc6CrLMU2do6X2Pb4ZcbqJxszYkPptFTiAmhFSc2fEX32F5XxKO3Vqr5CzT1z1lIw1tpJPplfLYvPv12dwWzGrxhrbjhevh55fQ+tW9tn8qf4Rwu6t0akQQCCGwRs0yN/Rgvxxe3T4VtSnypf0gj6heoom8L/53nwrgb12C33HcljayJ9r9l2azvGn2mdSyvSUHI/NbXFFBKsDh4ldMR7NNhwf3GMsEmMet7Zt6ztYEDeCUKJirJsJU9bBrv3sXZb0qyP5+AbFb0dsluw== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(356005)(8936002)(7696005)(6666004)(8676002)(4326008)(82310400004)(70206006)(70586007)(186003)(336012)(426003)(2616005)(16526019)(26005)(1076003)(81166007)(36860700001)(508600001)(86362001)(2906002)(5660300002)(83380400001)(36756003)(40460700003)(54906003)(110136005)(316002)(47076005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:33:09.9097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5da697d5-de0b-4887-56e6-08d9e719b82e 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: BN8NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5122 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" create a pot-sized mm, then allocate one of each possible order within. This should leave the mm with exactly one page left. Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 153 ++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index 21a6bd38864f..b14f04a1de19 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -10,3 +10,4 @@ selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ selftest(buddy_alloc_limit, igt_buddy_alloc_limit) selftest(buddy_alloc_range, igt_buddy_alloc_range) selftest(buddy_alloc_optimistic, igt_buddy_alloc_optimistic) +selftest(buddy_alloc_pessimistic, igt_buddy_alloc_pessimistic) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index b193d9556fb4..e97f583ed0cd 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -314,6 +314,159 @@ static void igt_mm_config(u64 *size, u64 *chunk_size) *size = (u64)s << 12; } +static int igt_buddy_alloc_pessimistic(void *arg) +{ + u64 mm_size, size, min_page_size, start = 0; + struct drm_buddy_block *block, *bn; + const unsigned int max_order = 16; + unsigned long flags = 0; + struct drm_buddy mm; + unsigned int order; + LIST_HEAD(blocks); + LIST_HEAD(tmp); + int err; + + /* + * Create a pot-sized mm, then allocate one of each possible + * order within. This should leave the mm with exactly one + * page left. + */ + + mm_size = PAGE_SIZE << max_order; + err = drm_buddy_init(&mm, mm_size, PAGE_SIZE); + if (err) { + pr_err("buddy_init failed(%d)\n", err); + return err; + } + BUG_ON(mm.max_order != max_order); + + for (order = 0; order < max_order; order++) { + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc hit -ENOMEM with order=%d\n", + order); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + } + + /* And now the last remaining block available */ + size = min_page_size = get_size(0, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc hit -ENOMEM on final alloc\n"); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + + /* Should be completely full! */ + for (order = max_order; order--; ) { + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (!err) { + pr_info("buddy_alloc unexpectedly succeeded at order %d, it should be full!", + order); + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + err = -EINVAL; + goto err; + } + } + + block = list_last_entry(&blocks, typeof(*block), link); + list_del(&block->link); + drm_buddy_free_block(&mm, block); + + /* As we free in increasing size, we make available larger blocks */ + order = 1; + list_for_each_entry_safe(block, bn, &blocks, link) { + list_del(&block->link); + drm_buddy_free_block(&mm, block); + + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc (realloc) hit -ENOMEM with order=%d\n", + order); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + drm_buddy_free_block(&mm, block); + order++; + } + + /* To confirm, now the whole mm should be available */ + size = min_page_size = get_size(max_order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc (realloc) hit -ENOMEM with order=%d\n", + max_order); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + drm_buddy_free_block(&mm, block); + + if (!err) + pr_info("%s - succeeded\n", __func__); + +err: + drm_buddy_free_list(&mm, &blocks); + drm_buddy_fini(&mm); + return err; +} + static int igt_buddy_alloc_optimistic(void *arg) { u64 mm_size, size, min_page_size, start = 0; From patchwork Thu Feb 3 13:32:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734135 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 10C26C4332F for ; Thu, 3 Feb 2022 13:33:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 005D310F7EC; Thu, 3 Feb 2022 13:33:20 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2054.outbound.protection.outlook.com [40.107.236.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F20E10F7E8; Thu, 3 Feb 2022 13:33:18 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bHHRCODYt88i03Fqyz/OU7cy0MqvfOipHqis7cW8mbfg96Ao+ACro8ld3P3MHjPI1C0zvWaHSlD4YT/4YwiiZ8DC805RJRaUwuLO1f9OZKLNVYIQUNI5ZF7z9L07bk/mP4qs91ngTMcseJoDXAGdFctOzpbopfoJSNHCwCAnYhiyGvlCHU0F61O2ocNektFU0qGHB+N691W5GiC+aY7dtB2QXjdeEwiJyfAteJAljaDbePZ0uuqTpgss8K8RyCGZk940gnz9VzVYxdFanem6ZPQLvtAU/rJHLG89WmzQO7YytGGgZ1Z+dCJgiJHYLUWaOnyWE4osZY+9t5tpl6IUIQ== 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=diHUITJP38VBN9xdJ03GS0k1N95OA8zUd3HAxYp3LrE=; b=FWcdYWldhwpNmT4RPZszbscEIbBadwqLGUa7Jmhjub98yBHBuH9ZK5d5q/Y7x5of2MLGER4tIrGK29LoE+YdIvXoSZClA0NPuM0KEXnw74TCGBe7kUZP5igQLROnZQqnJKkvEJPxE730T31oY0TSWxa6p3u0ITqs0g3NZJAegxptO8P000nEKoU5KklvMyJQn4LR4O4bGWswKCl0G3EOtLmv3dj+KcDwhFjJyDDj/Q97Mamzkf09BA+mGzwXLL7n9rQQgLadc1BqNsVD56FgPP9tuFyimHTqhNa6cxbq5Av8NTg7jvKYQZHJIiVsAOEgdZ+8Zn6AMySPZCF7H7SHUg== 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 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=diHUITJP38VBN9xdJ03GS0k1N95OA8zUd3HAxYp3LrE=; b=iQy/d8DZrYkxTWWN321bIy0Lpnt4S+HV2/1S6etsBX0OAEcY5WCJZfH+Z9m3KqbOo4bzjXz1CIREjrQy+bgr/F1p+OUvDdjXHbnMxtWEvK26Erj7SiEXTJEc9oFN9XQABHAMiYY36mdtUaEvZsTKM2DZ0IEHUaWR0TbhaZs0rlc= Received: from BN1PR13CA0004.namprd13.prod.outlook.com (2603:10b6:408:e2::9) by DM6PR12MB5024.namprd12.prod.outlook.com (2603:10b6:5:20a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 13:33:13 +0000 Received: from BN8NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::27) by BN1PR13CA0004.outlook.office365.com (2603:10b6:408:e2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.5 via Frontend Transport; Thu, 3 Feb 2022 13:33:13 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT026.mail.protection.outlook.com (10.13.177.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:13 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:33:09 -0600 From: Arunpravin To: , , Subject: [PATCH 6/7] drm/selftests: add drm buddy smoke testcase Date: Thu, 3 Feb 2022 19:02:33 +0530 Message-ID: <20220203133234.3350-6-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: 84711108-2058-4175-d85c-08d9e719ba1b X-MS-TrafficTypeDiagnostic: DM6PR12MB5024:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:294; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V/2zIlH+Mqb77eaLmxMHRBjH0iruF+flbCKwJkIb/K7/ctCN2RUf/dx2z3MIb+x8ANThMwgr1c3n1YETXIq+OLWR6O5cIY0bry2RnosjtsHtFy3xWA+1RwAW+mYMloqFtnRUGuspV2LkT4DwaJRPGsWLVrO5ujz1CXIbc3s1G//VxUMPzktstB6B1zZZi+hOmRmH9qhfFwgkbWRvdIHjsxfbHdbXKlUMBTOR2jNSVXl6b++4TZCqRR0sF6AXy1iS1Yh5khghUHJr6RXu3YiJde6ZLL8q3jP9/tXiQ+luFXaLnFHqD6X5lPeWFzBr9aYyqJPLlC3JVAX0oaB+sHzYSHFoFKCgaT6UKE2v55AtB8aLdUCNO1EwSpNmZdzML9+nGdfFTn3sage02yV328PX9I0svP/BvzyLpfh8NK067Us7CuT2tk8Vq2zpEUBX1yDhf04kJM4qbMncOcPKcDnUYoWrEbrQVsGNtq4ps2IRPoG5fxaU9Ye6uYqLct3Ln8/AjWu9L6FSq6ZWjvcDzJERT7jg7jdULJeIXNY70VHQkLJflkmaAtJ/9OyQft2ztZFNt9TM9rfKPK7Mgma8D/v0nRuovKzVZcRuhlI/fb0xJSyCM12HfMvfakWVYxwyYwTD23dhARFtevDVp5gC2X89YctzBi3m9AMnWCN0hloCxfHe1VMHF8+zGKJJkY0BEj8ql5Yhe+5f77ODLtHCoZqIyA== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36860700001)(70586007)(508600001)(2616005)(2906002)(6666004)(8936002)(7696005)(81166007)(5660300002)(70206006)(82310400004)(356005)(8676002)(4326008)(426003)(110136005)(83380400001)(16526019)(336012)(186003)(86362001)(47076005)(316002)(1076003)(36756003)(40460700003)(54906003)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:33:13.1440 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84711108-2058-4175-d85c-08d9e719ba1b 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: BN8NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5024 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - add a test to ascertain that the critical functionalities of the program is working fine - add a timeout helper function Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index b14f04a1de19..411d072cbfc5 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -11,3 +11,4 @@ selftest(buddy_alloc_limit, igt_buddy_alloc_limit) selftest(buddy_alloc_range, igt_buddy_alloc_range) selftest(buddy_alloc_optimistic, igt_buddy_alloc_optimistic) selftest(buddy_alloc_pessimistic, igt_buddy_alloc_pessimistic) +selftest(buddy_alloc_smoke, igt_buddy_alloc_smoke) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index e97f583ed0cd..2074e8c050a4 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -7,6 +7,7 @@ #include #include +#include #include @@ -15,6 +16,9 @@ #define TESTS "drm_buddy_selftests.h" #include "drm_selftest.h" +#define IGT_TIMEOUT(name__) \ + unsigned long name__ = jiffies + MAX_SCHEDULE_TIMEOUT + static unsigned int random_seed; static inline u64 get_size(int order, u64 chunk_size) @@ -22,6 +26,26 @@ static inline u64 get_size(int order, u64 chunk_size) return (1 << order) * chunk_size; } +__printf(2, 3) +static bool __igt_timeout(unsigned long timeout, const char *fmt, ...) +{ + va_list va; + + if (!signal_pending(current)) { + cond_resched(); + if (time_before(jiffies, timeout)) + return false; + } + + if (fmt) { + va_start(va, fmt); + vprintk(fmt, va); + va_end(va); + } + + return true; +} + static inline const char *yesno(bool v) { return v ? "yes" : "no"; @@ -314,6 +338,125 @@ static void igt_mm_config(u64 *size, u64 *chunk_size) *size = (u64)s << 12; } +static int igt_buddy_alloc_smoke(void *arg) +{ + u64 mm_size, min_page_size, chunk_size, start = 0; + unsigned long flags = 0; + struct drm_buddy mm; + int *order; + int err, i; + + DRM_RND_STATE(prng, random_seed); + IGT_TIMEOUT(end_time); + + igt_mm_config(&mm_size, &chunk_size); + + err = drm_buddy_init(&mm, mm_size, chunk_size); + if (err) { + pr_err("buddy_init failed(%d)\n", err); + return err; + } + + order = drm_random_order(mm.max_order + 1, &prng); + if (!order) + goto out_fini; + + for (i = 0; i <= mm.max_order; ++i) { + struct drm_buddy_block *block; + int max_order = order[i]; + bool timeout = false; + LIST_HEAD(blocks); + u64 total, size; + LIST_HEAD(tmp); + int order; + + err = igt_check_mm(&mm); + if (err) { + pr_err("pre-mm check failed, abort\n"); + break; + } + + order = max_order; + total = 0; + + do { +retry: + size = min_page_size = get_size(order, chunk_size); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, + min_page_size, &tmp, flags); + if (err) { + if (err == -ENOMEM) { + pr_info("buddy_alloc hit -ENOMEM with order=%d\n", + order); + } else { + if (order--) { + err = 0; + goto retry; + } + + pr_err("buddy_alloc with order=%d failed(%d)\n", + order, err); + } + + break; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + break; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + + if (drm_buddy_block_order(block) != order) { + pr_err("buddy_alloc order mismatch\n"); + err = -EINVAL; + break; + } + + total += drm_buddy_block_size(&mm, block); + + if (__igt_timeout(end_time, NULL)) { + timeout = true; + break; + } + } while (total < mm.size); + + if (!err) + err = igt_check_blocks(&mm, &blocks, total, false); + + drm_buddy_free_list(&mm, &blocks); + + if (!err) { + err = igt_check_mm(&mm); + if (err) + pr_err("post-mm check failed\n"); + } + + if (err || timeout) + break; + + cond_resched(); + } + + if (err == -ENOMEM) + err = 0; + + if (!err) + pr_info("%s - succeeded\n", __func__); + + kfree(order); +out_fini: + drm_buddy_fini(&mm); + + return err; +} + static int igt_buddy_alloc_pessimistic(void *arg) { u64 mm_size, size, min_page_size, start = 0; From patchwork Thu Feb 3 13:32:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12734136 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 35E16C433FE for ; Thu, 3 Feb 2022 13:33:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14F9710F7EF; Thu, 3 Feb 2022 13:33:24 +0000 (UTC) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2058.outbound.protection.outlook.com [40.107.244.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id 580F110F7EF; Thu, 3 Feb 2022 13:33:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=drES5KqrZuGv2X8E5Od9RGcuoxxa2Lr1WIllslaJ2/ji0EVJXsJ8Nu8v53XF0+rjImg3HGuwdseB7yZticyljPCGpbaRi4vGYP+AnxDUy7Afk2Oj5ZKGhvEXgBi7XQYnp+m4+xkO0qpw81tQD5TtGhAkJLgmRJwuanx9ew4BIJ6soPV+NJzU9PtONyOzPz0abbpVVqXo3mDhJ/0873Cxi5rB9/v7CTacvlWP9vpIC9Fm8yPc0aLzA1tJN1odb/sGElp8Acq/ydD/nUTyh/NNvA1PwuH7Qfuk/L9LcN1NMmvz2idlHsf9HvOPNUwgkhfEFITLFxfVO4qlZ62dFdvEfA== 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=QgujbPF/dWAgw3TPEYOUxkF6HSLg5ZZeFzG7vsSd7Z0=; b=KR5vogS2lesH7tCLQsWpA8NcgGfQFuCU3zUCxqwcS/eEFKY0EyOERBGhxAAn9ceFK67z98u/pcJzrtn+RRpGJACgBopRtOwa1c8g0BTIuHQiD90x+TQDBCgXdUcE40tJti+Mmi4btjOF4wt4v/jgIRVMBsP6SQaSY/YEoDMFgXN1X/zISVG96SD1DXdTt1J6tn5cF4Co+NqTuX7BqkQhdukjZhcZpf9DCMDB5vOCr/dSV6gAq1R+ScbcbFtKOAj+EHnBNDq7GiG0rJWnzo+TYZlaK28NKsSfdKzoRyxP2yLZoz/FE7v9Ds9JIbsFTMMPlNjgxV0KnwqgJXkmbQrB2Q== 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 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=QgujbPF/dWAgw3TPEYOUxkF6HSLg5ZZeFzG7vsSd7Z0=; b=XJScnB587CAegD4OITA33NdfpxtyBKqVz9n51rk29UTrHzammDWNCtdO7+tn4zpUC+L/ydYzj9gwe4hOQr1Bgn7fK2i3jzdSKuoWiDFWKF6WSXKmQ8oMdXlFIgojgwHgYu0L7yWT8Bo16loe6AW/5qdSFT6onf1IOrlY78j97Bk= Received: from BN9PR03CA0222.namprd03.prod.outlook.com (2603:10b6:408:f8::17) by BYAPR12MB2645.namprd12.prod.outlook.com (2603:10b6:a03:61::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Thu, 3 Feb 2022 13:33:17 +0000 Received: from BN8NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f8:cafe::b4) by BN9PR03CA0222.outlook.office365.com (2603:10b6:408:f8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11 via Frontend Transport; Thu, 3 Feb 2022 13:33:16 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT017.mail.protection.outlook.com (10.13.177.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 13:33:16 +0000 Received: from rtg-amd.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.2375.18; Thu, 3 Feb 2022 07:33:13 -0600 From: Arunpravin To: , , Subject: [PATCH 7/7] drm/selftests: add drm buddy pathological testcase Date: Thu, 3 Feb 2022 19:02:34 +0530 Message-ID: <20220203133234.3350-7-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203133234.3350-1-Arunpravin.PaneerSelvam@amd.com> References: <20220203133234.3350-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-Office365-Filtering-Correlation-Id: 76976948-526d-4f69-986c-08d9e719bc03 X-MS-TrafficTypeDiagnostic: BYAPR12MB2645:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:820; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Zo4N21n9HpkTS0URbTowRieCESEtsM4P4Fmwn969Ul+ldQAXipHlwPAv0TG19WdeZ/t/zJsOkz/2rRB2nKQMYMlj9+eok1N5glmD+mwq5QAQWpa2MeaNbCQ9+kfF1c5jobzv8nG+Da6HX7yfB0z4RZmrx4NPAA3eNN1ejWw/J5wkBrHht5EcqtE6PchcqUfqMrOp3edQo/J3txYIVtEW6/JFe4daF5XowcryVOZucKVLWqPi9NpYIsz4LfEzNrNn1t1XoCZyC2ZDzVo21a2Z39ORcrUKjGUSghEIcKv/s0ssErFxPsX4KjK0I1z5BV6fXSi73DVaenORCWzrJ16ea3zXEEUl8prCnKj4v5EIQf4jF8VxnJT1mCJ0m8FGwx/48bpQ1J5CP2sexZKCv/YoczhfeLavL0PHcLACTEmqKUGbCOyat3Pq5UTzDqNZ79+olIMU3vkx2/NpQdY7aUuw0yyfRKSPqQ31ZSteQZDkWS5guniO7xJsMhZ9u0RVYszYASGOVWPPOLq8d+uhe42Iq+QNpZEdc6ICJAHhZamlBkk6jx9Sa2anaN5oRfKn8ngCyUeWsDZgnUETXeFjStM/mybqO2Ufrb9tOskqHeClUwfWvalC5hJh/dXNNp1StMA4ajd3AmN/FxPvLRosYgD1C/dAyfmnHUEefJS+A7JdwcG8h03+NvUKZ2Xz8NZtq29ucSOTG/tpO3Iw1pY6su62HQ== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(70206006)(70586007)(86362001)(40460700003)(54906003)(4326008)(508600001)(110136005)(8936002)(8676002)(5660300002)(356005)(81166007)(316002)(36756003)(7696005)(82310400004)(16526019)(2616005)(26005)(6666004)(426003)(47076005)(2906002)(36860700001)(1076003)(83380400001)(336012)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 13:33:16.3561 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76976948-526d-4f69-986c-08d9e719bc03 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: BN8NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2645 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: , Cc: Arunpravin , matthew.auld@intel.com, tzimmermann@suse.de, alexander.deucher@amd.com, christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" create a pot-sized mm, then allocate one of each possible order within. This should leave the mm with exactly one page left. Free the largest block, then whittle down again. Eventually we will have a fully 50% fragmented mm. Signed-off-by: Arunpravin Reviewed-by: Matthew Auld --- .../gpu/drm/selftests/drm_buddy_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_buddy.c | 136 ++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h index 411d072cbfc5..455b756c4ae5 100644 --- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h +++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h @@ -12,3 +12,4 @@ selftest(buddy_alloc_range, igt_buddy_alloc_range) selftest(buddy_alloc_optimistic, igt_buddy_alloc_optimistic) selftest(buddy_alloc_pessimistic, igt_buddy_alloc_pessimistic) selftest(buddy_alloc_smoke, igt_buddy_alloc_smoke) +selftest(buddy_alloc_pathological, igt_buddy_alloc_pathological) diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c index 2074e8c050a4..b2d0313a4bc5 100644 --- a/drivers/gpu/drm/selftests/test-drm_buddy.c +++ b/drivers/gpu/drm/selftests/test-drm_buddy.c @@ -338,6 +338,142 @@ static void igt_mm_config(u64 *size, u64 *chunk_size) *size = (u64)s << 12; } +static int igt_buddy_alloc_pathological(void *arg) +{ + u64 mm_size, size, min_page_size, start = 0; + struct drm_buddy_block *block; + const int max_order = 3; + unsigned long flags = 0; + int order, top, err; + struct drm_buddy mm; + LIST_HEAD(blocks); + LIST_HEAD(holes); + LIST_HEAD(tmp); + + /* + * Create a pot-sized mm, then allocate one of each possible + * order within. This should leave the mm with exactly one + * page left. Free the largest block, then whittle down again. + * Eventually we will have a fully 50% fragmented mm. + */ + + mm_size = PAGE_SIZE << max_order; + err = drm_buddy_init(&mm, mm_size, PAGE_SIZE); + if (err) { + pr_err("buddy_init failed(%d)\n", err); + return err; + } + BUG_ON(mm.max_order != max_order); + + for (top = max_order; top; top--) { + /* Make room by freeing the largest allocated block */ + block = list_first_entry_or_null(&blocks, typeof(*block), link); + if (block) { + list_del(&block->link); + drm_buddy_free_block(&mm, block); + } + + for (order = top; order--; ) { + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, + min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc hit -ENOMEM with order=%d, top=%d\n", + order, top); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + } + + /* There should be one final page for this sub-allocation */ + size = min_page_size = get_size(0, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (err) { + pr_info("buddy_alloc hit -ENOME for hole\n"); + goto err; + } + + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &holes); + + size = min_page_size = get_size(top, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (!err) { + pr_info("buddy_alloc unexpectedly succeeded at top-order %d/%d, it should be full!", + top, max_order); + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + err = -EINVAL; + goto err; + } + } + + drm_buddy_free_list(&mm, &holes); + + /* Nothing larger than blocks of chunk_size now available */ + for (order = 1; order <= max_order; order++) { + size = min_page_size = get_size(order, PAGE_SIZE); + err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags); + if (!err) { + pr_info("buddy_alloc unexpectedly succeeded at order %d, it should be full!", + order); + block = list_first_entry_or_null(&tmp, + struct drm_buddy_block, + link); + if (!block) { + pr_err("alloc_blocks has no blocks\n"); + err = -EINVAL; + goto err; + } + + list_del(&block->link); + list_add_tail(&block->link, &blocks); + err = -EINVAL; + goto err; + } + } + + if (err) { + pr_info("%s - succeeded\n", __func__); + err = 0; + } + +err: + list_splice_tail(&holes, &blocks); + drm_buddy_free_list(&mm, &blocks); + drm_buddy_fini(&mm); + return err; +} + static int igt_buddy_alloc_smoke(void *arg) { u64 mm_size, min_page_size, chunk_size, start = 0;