From patchwork Fri Jan 19 08:11:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10174695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E715760386 for ; Fri, 19 Jan 2018 08:11:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CABFA285B7 for ; Fri, 19 Jan 2018 08:11:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD6C0285D8; Fri, 19 Jan 2018 08:11:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 008AF285B7 for ; Fri, 19 Jan 2018 08:11:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EDC5D6E7BF; Fri, 19 Jan 2018 08:11:32 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0067.outbound.protection.outlook.com [104.47.32.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id B25966E7BF for ; Fri, 19 Jan 2018 08:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rJNSCMdSfP/nJ+ClCu1k+83OJST0A7QUryhpGbezM6M=; b=H5N73Gxjx/tMz7uQaFQ5DETK2am4Sb4vUflJhqM45NY98WuLv3S73qc1FwFyvoFGaHSUA/qfbZbcY9tCJhQ9RH8nH/ceeEDci0/Eci6esswQNwuQApOPC5v2b0zgw7Kcp79SkcSXtEsM+1V/b54MoYKG1HIBbEh0CbBF6kRdi4w= Received: from BN4PR12CA0010.namprd12.prod.outlook.com (10.164.241.20) by CY4PR12MB1445.namprd12.prod.outlook.com (10.172.71.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Fri, 19 Jan 2018 08:11:29 +0000 Received: from DM3NAM03FT020.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::209) by BN4PR12CA0010.outlook.office365.com (2603:10b6:403:2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Fri, 19 Jan 2018 08:11:29 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by DM3NAM03FT020.mail.protection.outlook.com (10.152.82.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.345.19 via Frontend Transport; Fri, 19 Jan 2018 08:11:28 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Fri, 19 Jan 2018 02:11:27 -0600 From: Roger He To: Subject: [PATCH] drm/ttm: add the missed global memory count update Date: Fri, 19 Jan 2018 16:11:23 +0800 Message-ID: <1516349483-30717-1-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39860400002)(396003)(39380400002)(346002)(376002)(2980300002)(428003)(199004)(189003)(86362001)(4326008)(8936002)(5660300001)(15650500001)(97736004)(26005)(77096007)(53936002)(47776003)(316002)(16586007)(54906003)(36756003)(305945005)(105586002)(106466001)(50226002)(2351001)(59450400001)(7696005)(51416003)(53416004)(478600001)(8676002)(72206003)(6916009)(2906002)(6666003)(68736007)(356003)(50466002)(81166006)(81156014)(48376002)(104016004); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1445; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT020; 1:lAsAQeILkQS63VOv/buM4E6NyBS8A8ntNNUlv6rf6EvIGhXPLGHeo4Iz4z4quVwbKEzSdUpre3xNDw1RpMh8FT3p+3/LDpNCzSAqdaHnlzAKTIpaVfdXmi9/1HXYqAUi X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d183877-85d3-49ee-43a5-08d55f143e0a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR12MB1445; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1445; 3:yI4f7YXphz0qNekhQCNmTaNgOaSfEAgDvePZ57VtObKNJ8am2ROESwtBozHn3P8c2HKaDIWqHrnpgkmNkRaslv5TXyrexpD4Bmkwn2/QpSw22NRz93OlWY1VpvVyZhsA0V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4Yc9sX8wqcugkt7BiE4Ory6v79CVFtYkCvV+xX1HRxUTgNYaXF0mvWj9gz64hJNxK4FPCC5+54637dT2KoVq2sNebeytHQwy0V9cv/zCgrYJMhcNX5Fd4EfBdhIF/zuadjFg4V8YO0QeCNj0WXq4xKb1O90PRQFVzWLebh+gAPI2vGm6ad0u7/EcjAM5KD0zRPU6aCT8fSriSe/ACI9CWaudmKRBVtCO+1tYWAFEHAXjvKGIV5diweOmXc6fN+vVeHPGHfry/L+cGajQlPcRc032DEhTJ9RZO4agIw/jNU+5ftDFtRgDd/06evXb8MO1n1sP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(93006095)(93003095)(3231023)(2400074)(944501161)(10201501046)(6055026)(6041268)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR12MB1445; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR12MB1445; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1445; 4:mcfVnriX4kiVXZaBWu81VmUjQNWZfWUrNEp4Tq9csZagoTPBdzvkd+24+4OmYi0nnadcnKqd+w37l1hjOTGHcVYePqs33kBXgUfY4m3I0MMPK281ipmEEb/blvie9Ak/qm2J1EyRvdcU2ZSnll0YESU2lO0iAatJRFFLLBMOOq5F2KAG7DOjKbGYkOZfkv4NB0BEGp2K4mcr89f1EjTl7Y+LedkujsU6/UVH6Sb5UkwshCT5ypBYYao5qJWF6Peh/hrji0ahMIMZXDIc25jmpv27qNQGbO/kk6VGVA9yg8+QPxt0j2tbAbttiWrA7kBV X-Forefront-PRVS: 0557CBAD84 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1445; 23:HfDlI1ATGgaxAdB74wkXlBWxNd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IY9BwKzQuwHIyWki2sUXJhG1Jn11dqZUT7wNwT3oMAwdgc+v1XZNgQWRUnFssZvci0NST5+CVUZmhT99v6bK3jHAgRjbUWXMP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1445; 20:ac/ls+G+soFLQp1CHcAosH9NlQEfbkkG7br+GKg0esmJ3PfzO1ssWJS6z9TTz4Rh3gpYACFr2LZcYbdxbuIFv07Cx+kAuSPT7m+nd0mUOHFl++mD5eKrHmpxr8nk+5lZIaF4bZBrp1YlLPn5sfJMKLYytH6tVsQLf6fsnqxg7VAE2O/mvPY2PPlyNTjsBk6IWV17oCCqWK/HAMQFaJunMrcXM5kZ744YyCxB0ngus2GVmIKBruRcMm75Ru5Q7xV/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 08:11:28.6231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d183877-85d3-49ee-43a5-08d55f143e0a 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=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1445 Cc: Roger He , Christian.Koenig@amd.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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" X-Virus-Scanned: ClamAV using ClamSMTP when ttm_mem_global_alloc_page fails, we should call ttm_mem_global_free_page to update memory count for the ttm pages which already run ttm_mem_global_alloc_page successfully Signed-off-by: Roger He Reviewed-by: Christian König --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 41 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 2b12c55a..9ec2021 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -1063,6 +1063,28 @@ void ttm_page_alloc_fini(void) _manager = NULL; } +static void +ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) +{ + unsigned i; + + if (mem_count_update == 0) + goto put_pages; + + for (i = 0; i < mem_count_update; ++i) { + if (!ttm->pages[i]) + continue; + + ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i], + PAGE_SIZE); + } + +put_pages: + ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags, + ttm->caching_state); + ttm->state = tt_unpopulated; +} + int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) { struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; @@ -1075,8 +1097,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching_state); if (unlikely(ret != 0)) { - ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags, - ttm->caching_state); + ttm_pool_unpopulate_helper(ttm, 0); return ret; } @@ -1084,8 +1105,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], PAGE_SIZE, ctx); if (unlikely(ret != 0)) { - ttm_put_pages(ttm->pages, ttm->num_pages, - ttm->page_flags, ttm->caching_state); + ttm_pool_unpopulate_helper(ttm, i); return -ENOMEM; } } @@ -1105,18 +1125,7 @@ EXPORT_SYMBOL(ttm_pool_populate); void ttm_pool_unpopulate(struct ttm_tt *ttm) { - unsigned i; - - for (i = 0; i < ttm->num_pages; ++i) { - if (!ttm->pages[i]) - continue; - - ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i], - PAGE_SIZE); - } - ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags, - ttm->caching_state); - ttm->state = tt_unpopulated; + ttm_pool_unpopulate_helper(ttm, ttm->num_pages); } EXPORT_SYMBOL(ttm_pool_unpopulate);