From patchwork Wed Jan 17 08:59:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10168791 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 0FD6860386 for ; Wed, 17 Jan 2018 09:00:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F194B28429 for ; Wed, 17 Jan 2018 09:00:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2B272846F; Wed, 17 Jan 2018 09:00:11 +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 2BFDA28429 for ; Wed, 17 Jan 2018 09:00:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF6F06E3A5; Wed, 17 Jan 2018 09:00:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0054.outbound.protection.outlook.com [104.47.33.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD4936E3A6 for ; Wed, 17 Jan 2018 09:00:07 +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=LSme6uob0rZTYFjtzNOChfRqoffwScNHTCLjA/IzAIo=; b=4NOgOyd+Q2494Y7WbCnlZoWWYE3AZxydXwVZ/BS4Kz7Qaj3KHcKLX3RqAOIEq/9EuLpwc+S57Bz25NHy6Tw0LF64zIaVCDI/iRMSEBWtb8t6Iejxm7n/ZTW1ir7OYhtb3sjNtfOgLqXUkNE2xGMqIWixLVFttl+wApsSJm/e+gE= Received: from DM5PR12CA0049.namprd12.prod.outlook.com (10.175.83.139) 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 09:00:05 +0000 Received: from CO1NAM03FT050.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::202) by DM5PR12CA0049.outlook.office365.com (2603:10b6:3:103::11) 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 09:00:05 +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 CO1NAM03FT050.mail.protection.outlook.com (10.152.81.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.345.12 via Frontend Transport; Wed, 17 Jan 2018 09:00:04 +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; Wed, 17 Jan 2018 03:00:03 -0600 From: Roger He To: Subject: [PATCH] drm/ttm: add VADDR_FLAG_UPDATED_COUNT to correctly update dma_page global count Date: Wed, 17 Jan 2018 16:59:59 +0800 Message-ID: <1516179599-27339-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)(346002)(396003)(39380400002)(376002)(2980300002)(428003)(189003)(199004)(356003)(16586007)(4326008)(77096006)(59450400001)(305945005)(54906003)(478600001)(26005)(2351001)(6916009)(5660300001)(6666003)(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; CO1NAM03FT050; 1:mF3Y/Yg0zrushMtDLBL+5muysSiCXVW77Tgu/T7zwLL0d28JPc0PaYIUiLAxWG5K3egjvg4AlXmOdHp4ruK0uGLmqnqeI1WgF8LYmfiWZMXPaxpNE4oRZnxNP3ZNH7YJ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 266327ee-0af3-400b-b4ea-08d55d88b37c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060); SRVR:MWHPR12MB1454; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 3:3i8SNu2ZJwofnWylhU8uIKzrST9iy+tpmkPvYATkGhT8kGFciPXjj/gaNUtZPsmuXpsqHWmWZqwVwuDVWj0fuuc+IG+MiM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pt6e0VhAvoh+cpJfOXCKuRH+Q9rDRGwetvBvYbXlHUiVewn1Qr26Pu/y7ymtaWV+cEBUGauD1aqTUF5KT9TSaviNEdJ1yKlPWT5ABffNrrQu1B80PP0YRIt8Hgf5ZrerUSweddLfsjBmePYlWKYqH3hVjF8rBA2EwRJtCLga/zoVg8dBc+gpzzoNGE1YXFsfyEm9XvO5ZZZ/uAVpkr22I1dO7vThyz1bzI0ex39bme9dfwyhvdoFXITzqye/TUVXG2pQORBmkEME2hfhySrkydMjdEXKgmnglIK6Vu8QErvRLQQpAiK8HNel3d9qHjnhwgnD1DG7q0yVCdHkvKqzbYULLEORPw6zr6bnpVTEmxmsoJ 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)(10201501046)(3231023)(2400043)(944501161)(6055026)(6041268)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:MWHPR12MB1454; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR12MB1454; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 4:2bOiZ4z1EPaA0gpVOPQONs4QUJ9LmA9++mEhWj3oaZjL1sSD18PFN7Afv+HWKdGBKLLR/+bww3mOkqMXNyjRC9YAo6/BcbEanBGSNUg+Bry8Mt4Gwlqcb9/JgCdR8W0A3xHjkhUuGgp5F/rc6KVPp2LsZhq20YcwcmKwHKT0dmlMEDVT6apCO7solPbbLR0SYgVebhgr770KehUvyA4ZGITPlTXdzz1f4HvFDemV/n/WYfHxz2gmdFxy3zIjDR5AJzl3ZJBCGvQa8l1xcfe03QQMZRG6DeWAKKw9fzittYdPWA9wc9tZr7IEQRAbSHxU X-Forefront-PRVS: 0555EC8317 X-Microsoft-Exchange-Diagnostics: =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xabzQ9XuKtkptuFSmjlzT4AiKmXqxZPPaBjE7cWb+q5uVbumz0TleGo89zJwtevRZt/Yy4OQXu4qQnkgV05Kk0Zj3TU6IPiIMbY3q/FFB7tCkZng15/hFablpn/L2yIRUdJM2Q/Rx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1454; 20:ESiT0KY02MK9c4kz2qzhwVKUsj7hBq/1sUkFodob6yNdrtNEiB0qKUSgnLJRjaofyuIa3TtJbkymZ9hpyH+nrgznF+afIaxaYaX99ZHpuHC2IxiN1TJQENms6u9xlcqhJcvnn86wlYhek3ZYDnBtSmcP+XyoV0y5LRvCrY3zWfN/zrZ83kcxnmloWa24rp2O8GZkrZ3qd83OVPP6Mt81ro5iv/rB37ZTCSBPI0p+sSDF/MU+ZD+HOFhyCUunnEG2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2018 09:00:04.9148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 266327ee-0af3-400b-b4ea-08d55d88b37c 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. v2: only the update of last dma_page is not right v3: use lower bits of dma_page vaddr Signed-off-by: Roger He Reviewed-by: Christian König --- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 55 +++++++++++++++++--------------- 1 file changed, 29 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..a880515 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -61,6 +61,7 @@ #define SMALL_ALLOCATION 4 #define FREE_ALL_PAGES (~0U) #define VADDR_FLAG_HUGE_POOL 1UL +#define VADDR_FLAG_UPDATED_COUNT 2UL enum pool_type { IS_UNDEFINED = 0, @@ -874,18 +875,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 +895,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 +934,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 +963,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 +974,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, return -ENOMEM; } + d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT; 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 +998,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 +1011,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, return -ENOMEM; } + d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT; ++i; --num_pages; } @@ -1049,8 +1052,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->vaddr & VADDR_FLAG_UPDATED_COUNT) { + ttm_mem_global_free_page(ttm->glob->mem_glob, + d_page->p, pool->size); + d_page->vaddr &= ~VADDR_FLAG_UPDATED_COUNT; + } ttm_dma_page_put(pool, d_page); } @@ -1070,9 +1076,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->vaddr & VADDR_FLAG_UPDATED_COUNT) { + ttm_mem_global_free_page(ttm->glob->mem_glob, + d_page->p, pool->size); + d_page->vaddr &= ~VADDR_FLAG_UPDATED_COUNT; + } + + if (is_cached) + ttm_dma_page_put(pool, d_page); } spin_lock_irqsave(&pool->lock, irq_flags); @@ -1092,19 +1108,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;