From patchwork Wed Jan 17 05:54:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10168537 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 96FFF601E7 for ; Wed, 17 Jan 2018 05:55:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7574127E5A for ; Wed, 17 Jan 2018 05:55:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6690C27F8E; Wed, 17 Jan 2018 05:55:08 +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 57E2E27E5A for ; Wed, 17 Jan 2018 05:55:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B86EF89232; Wed, 17 Jan 2018 05:55:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0079.outbound.protection.outlook.com [104.47.37.79]) by gabe.freedesktop.org (Postfix) with ESMTPS id B8B0389232 for ; Wed, 17 Jan 2018 05:55:03 +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=9WtCzuSxy76pRou8GdZr0gCLP/00wDg8Xe5XD7gvdQ4=; b=4xoKUHqXCnKkR9s51q0NnnbYTbVfd/xFA6zkL7/+2uzwM9s70LU8/aJtcEzLNjDf1GgGOw4JLue0K8+bx7QlRI3o6WktVS614VNV35ATLJISyMrpqOjJLe7Pdy2IJpI/WyaJg/dKNvS8KSoNv+24w8IflkSnZigLlhfZAZBnt5Q= Received: from BN4PR12CA0022.namprd12.prod.outlook.com (10.164.241.32) by MWHPR12MB1454.namprd12.prod.outlook.com (10.172.55.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Wed, 17 Jan 2018 05:55:01 +0000 Received: from DM3NAM03FT040.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::208) by BN4PR12CA0022.outlook.office365.com (2603:10b6:403:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Wed, 17 Jan 2018 05:55:00 +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 DM3NAM03FT040.mail.protection.outlook.com (10.152.83.222) 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; Wed, 17 Jan 2018 05:55:00 +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; Tue, 16 Jan 2018 23:54:59 -0600 From: Roger He To: Subject: [PATCH] drm/ttm: add updated_glob_count in dma_page Date: Wed, 17 Jan 2018 13:54:54 +0800 Message-ID: <1516168494-13506-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)(346002)(396003)(39860400002)(376002)(39380400002)(2980300002)(428003)(189003)(199004)(356003)(16586007)(77096006)(4326008)(59450400001)(305945005)(54906003)(2351001)(478600001)(26005)(6916009)(6666003)(5660300001)(2906002)(72206003)(15650500001)(53936002)(50466002)(47776003)(36756003)(81156014)(86362001)(106466001)(7696005)(51416003)(48376002)(316002)(97736004)(68736007)(105586002)(81166006)(8676002)(53416004)(50226002)(8936002)(104016004); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1454; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT040; 1:lHC/4zBG2jg5QOxKZa+oWf4nPxhtvwNex9j+fS+9OQC4wR7Q82urkJz/7UADfw8/x1sSLhit7R1AzNWlc48ZItff7GX6Ep4gdpOTqJ2rdIe5ClZh6pTxBSX+FE0aV9sr X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9a9354f-9803-47a6-554a-08d55d6ed869 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060); SRVR:MWHPR12MB1454; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 3:GcVortiBmOUXXcg2/wfFcCo9DwdGyUQWEXpAF3jMBQWbXDWk1HbXUgHL9OKOuuSjfCiXZCg3B5VROaNemRn+M+hrfOylP+8yJjN6/atjoCd9SmEhpCZIxWDKRH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QYS8m0cuGYvyX/1HqofKEEw7JqZh3qGHFBoIUrrr/MfmRjyjSkvz85/+YVfx1vkLA8tk9qI03zXCidBFibEzyUd/COGFG8dhxZW5UAXIZktFpnVbFHdwVHXZvXfBis4ROo5OQ3xB1RzEtcNomO4TYEGiyctkr0SmOiFVKFwfOQF74ZTqcb6wPJpixDgw1swxgtmmFlsAA6IOy0tcVofz/qoOm+zK5ROMKsFDxwyA9KcCxaRTl1xhn+iRFBwJQDOiKV4SKiXb0NHIQWbvrGP17DPiNAmB2Sv1j4nACqkzx0zFX5wWMNFTqS3Ci+nIw5uuK3Kfwcw5Zl+ThvpcVd 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)(10201501046)(93006095)(93003095)(3231023)(2400041)(944501161)(6055026)(6041268)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MWHPR12MB1454; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR12MB1454; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 4:zvnGJHuGULSLuaBamWUuZUvX4PGU1n+th/effNGgxattbJx4fKxQg33DSl7SBuy3YzFrncIskjeOzfTtV7r8USbaxuY9l3s8FeozI09h00/45Sgn5MnElMkmVb0DzvMWLluvtTjrIl48UTsyNQzpomGxoP9mi501ywopFTIifXVUSG5OYLnupBoaMR5a3u543AH/aKdqCgLggmYOK2sBGcjlwhMeTXdmgEgBOvVQ507uEtTHz4yaLci0em6V4byfloDXz2eO4WM7d0WrllaATpXLeR8NrFL72RDheNX87aFv23Oh/aKhrD5oe9zi5KQB X-Forefront-PRVS: 0555EC8317 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1454; 23:vfIBdzxw0FVBsDQOgOo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m7aiugXGbjC9zpYJJ5v+SISnCzidvwB2ajvBvoj6WzBETYlaDZYcabbMx+0u8HuGLgEOvdjg8Xm1bZcdWU0foNKrYbh2uBmGbkyE1HYMof SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 20:zQ9GKxqZEBByBN60eRl4YqVG617RLnEqeYLpej6abG3tejB70VfoD4VV7RTrmD4T1qYEyxhnZvdcXjUyi/hFhBwUIss0r+IXNRyT4sc+lQV3H0neuNflJ2H2lasvrFQHlyYQys8zSwuLwNTBWT0GkTl2arfQnHTDxYFuk58vK92Asl0N3f7IZJLqmxehg7Qu77r3ZtLZXJeVnnxI3ImuBKaeVbFsn5sVBpTGQd2zsuAHhY+0dPMBcZhXURdJstva X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2018 05:55:00.0553 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9a9354f-9803-47a6-554a-08d55d6ed869 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: MWHPR12MB1454 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 add this for correctly updating global mem count in ttm_mem_zone. before that when ttm_mem_global_alloc_page fails, we would update all dma_page's global mem count in ttm_dma->pages_list. but actually here we should not update for the last dma_page. Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 57 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index c7f01a4..3e78ea4 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -121,6 +121,8 @@ struct dma_pool { * @vaddr: The virtual address of the page and a flag if the page belongs to a * huge pool * @dma: The bus address of the page. If the page is not allocated + * @updated_glob_count: to indicate whether we already updated global + * memory count in ttm_mem_zone * via the DMA API, it will be -1. */ struct dma_page { @@ -128,6 +130,7 @@ struct dma_page { unsigned long vaddr; struct page *p; dma_addr_t dma; + bool updated_glob_count; }; /* @@ -874,18 +877,18 @@ static int ttm_dma_page_pool_fill_locked(struct dma_pool *pool, } /* - * @return count of pages still required to fulfill the request. * The populate list is actually a stack (not that is matters as TTM * allocates one page at a time. + * return dma_page pointer if success, otherwise NULL. */ -static int ttm_dma_pool_get_pages(struct dma_pool *pool, +static struct dma_page *ttm_dma_pool_get_pages(struct dma_pool *pool, struct ttm_dma_tt *ttm_dma, unsigned index) { - struct dma_page *d_page; + struct dma_page *d_page = NULL; struct ttm_tt *ttm = &ttm_dma->ttm; unsigned long irq_flags; - int count, r = -ENOMEM; + int count; spin_lock_irqsave(&pool->lock, irq_flags); count = ttm_dma_page_pool_fill_locked(pool, &irq_flags); @@ -894,12 +897,11 @@ static int ttm_dma_pool_get_pages(struct dma_pool *pool, ttm->pages[index] = d_page->p; ttm_dma->dma_address[index] = d_page->dma; list_move_tail(&d_page->page_list, &ttm_dma->pages_list); - r = 0; pool->npages_in_use += 1; pool->npages_free -= 1; } spin_unlock_irqrestore(&pool->lock, irq_flags); - return r; + return d_page; } static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge) @@ -934,6 +936,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; unsigned long num_pages = ttm->num_pages; struct dma_pool *pool; + struct dma_page *d_page; enum pool_type type; unsigned i; int ret; @@ -962,8 +965,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, while (num_pages >= HPAGE_PMD_NR) { unsigned j; - ret = ttm_dma_pool_get_pages(pool, ttm_dma, i); - if (ret != 0) + d_page = ttm_dma_pool_get_pages(pool, ttm_dma, i); + if (!d_page) break; ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], @@ -973,6 +976,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, return -ENOMEM; } + d_page->updated_glob_count = true; for (j = i + 1; j < (i + HPAGE_PMD_NR); ++j) { ttm->pages[j] = ttm->pages[j - 1] + 1; ttm_dma->dma_address[j] = ttm_dma->dma_address[j - 1] + @@ -996,8 +1000,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } while (num_pages) { - ret = ttm_dma_pool_get_pages(pool, ttm_dma, i); - if (ret != 0) { + d_page = ttm_dma_pool_get_pages(pool, ttm_dma, i); + if (!d_page) { ttm_dma_unpopulate(ttm_dma, dev); return -ENOMEM; } @@ -1009,6 +1013,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, return -ENOMEM; } + d_page->updated_glob_count = true; ++i; --num_pages; } @@ -1049,8 +1054,11 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) continue; count++; - ttm_mem_global_free_page(ttm->glob->mem_glob, - d_page->p, pool->size); + if (d_page->updated_glob_count) { + ttm_mem_global_free_page(ttm->glob->mem_glob, + d_page->p, pool->size); + d_page->updated_glob_count = false; + } ttm_dma_page_put(pool, d_page); } @@ -1070,9 +1078,19 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) /* make sure pages array match list and count number of pages */ count = 0; - list_for_each_entry(d_page, &ttm_dma->pages_list, page_list) { + list_for_each_entry_safe(d_page, next, &ttm_dma->pages_list, + page_list) { ttm->pages[count] = d_page->p; count++; + + if (d_page->updated_glob_count) { + ttm_mem_global_free_page(ttm->glob->mem_glob, + d_page->p, pool->size); + d_page->updated_glob_count = false; + } + + if (is_cached) + ttm_dma_page_put(pool, d_page); } spin_lock_irqsave(&pool->lock, irq_flags); @@ -1092,19 +1110,6 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) } spin_unlock_irqrestore(&pool->lock, irq_flags); - if (is_cached) { - list_for_each_entry_safe(d_page, next, &ttm_dma->pages_list, page_list) { - ttm_mem_global_free_page(ttm->glob->mem_glob, - d_page->p, pool->size); - ttm_dma_page_put(pool, d_page); - } - } else { - for (i = 0; i < count; i++) { - ttm_mem_global_free_page(ttm->glob->mem_glob, - ttm->pages[i], pool->size); - } - } - INIT_LIST_HEAD(&ttm_dma->pages_list); for (i = 0; i < ttm->num_pages; i++) { ttm->pages[i] = NULL;