From patchwork Mon Jan 29 08:31:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10189411 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 A404960212 for ; Mon, 29 Jan 2018 08:31:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9127428866 for ; Mon, 29 Jan 2018 08:31:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85BF22886B; Mon, 29 Jan 2018 08:31:28 +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 E817928866 for ; Mon, 29 Jan 2018 08:31:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 25ACC6E04B; Mon, 29 Jan 2018 08:31:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0042.outbound.protection.outlook.com [104.47.40.42]) by gabe.freedesktop.org (Postfix) with ESMTPS id F013289DB9 for ; Mon, 29 Jan 2018 08:31:23 +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=q64XovbcPVbZRk8XLnO+uFOkseNSrMx4ZJuiyjXuYtw=; b=Hv1fWuZ6RLcQx3a9fi24QcQ+3fi6k4nx8lEqpI7UQzvzBLHdnuDwLTOE7ft1jTRR3KO2NI936E3nlu+peXj0Y/0ppCDt5pQ8A3V1hA6I583NV8kSMKoni6SUGE2L4Dv6wcN4VzhoM74olLtwHnN9IVy/OzftoWCHNOf0LtLuuco= Received: from CY4PR12CA0035.namprd12.prod.outlook.com (10.175.82.149) by CY4PR12MB1272.namprd12.prod.outlook.com (10.168.167.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Mon, 29 Jan 2018 08:31:22 +0000 Received: from CO1NAM03FT043.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::208) by CY4PR12CA0035.outlook.office365.com (2603:10b6:903:129::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.444.14 via Frontend Transport; Mon, 29 Jan 2018 08:31:22 +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 CO1NAM03FT043.mail.protection.outlook.com (10.152.81.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.444.13 via Frontend Transport; Mon, 29 Jan 2018 08:31:21 +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; Mon, 29 Jan 2018 02:31:20 -0600 From: Roger He To: Subject: [PATCH 2/2] drm/ttm: add ttm page_flags TTM_PAGE_FLAG_PAGEFAULT Date: Mon, 29 Jan 2018 16:31:13 +0800 Message-ID: <1517214673-30962-2-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517214673-30962-1-git-send-email-Hongbo.He@amd.com> References: <1517214673-30962-1-git-send-email-Hongbo.He@amd.com> 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)(39380400002)(39860400002)(376002)(2980300002)(428003)(199004)(189003)(305945005)(4326008)(186003)(5660300001)(6916009)(2950100002)(356003)(8936002)(2906002)(50226002)(54906003)(6666003)(105586002)(53936002)(72206003)(478600001)(47776003)(53416004)(2351001)(7696005)(76176011)(59450400001)(77096007)(8676002)(51416003)(36756003)(81156014)(81166006)(68736007)(26005)(16586007)(104016004)(97736004)(316002)(575784001)(50466002)(86362001)(106466001)(336011)(48376002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1272; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT043; 1:g19fy2fj9tGnJVb2jTYaXSYAHyItOrpcIrXSrG7NReYcsTUtTJoxjAfybXVy1l50pdhRqdNLfYbkbxEubeK4ENTMIGqfQ5Vvb1VFTtac3BPxIG9K4+07RDY/QoFpMHQ+ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6cbc070-792d-4249-67aa-08d566f2ad57 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR12MB1272; X-Microsoft-Exchange-Diagnostics: 1; CY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50qHflheAdQByGybcuTWupEkiOz5z0FuUTqlXXBhyS37Mwfjh1p8xAfktRqj/u4vz8mFgU5uT0Mk52PpMueT3OvWNt84IZNhblsUvoB05qJ2SFIcTyqeOtwCrHRqJv+HrdR6ZTAkJ2Hu8rZ7K888i0UkfLFf+BexjfI/y2gxNHSqIaCJWFTTZsPtm3pxOAQKYuS9c3SgSWjFDANknW9ELwVSR2zL78+l0hwtj/ECjEG96iYWKKkzXQPrzh3U1E979mtsbPr7s/8VvJ93TlVld+vTmdKkPXYrUGr4+oexxzF7VRV0PsvC80Hs+LjgYcZprGEERXhCf2A6d+IsTUpdxKGbzscIavfirPsEnqjrU0hU5BWieB+mVYOjwedmCc/LdaKFjxsNuiLt+ggqrmJMEcJ+VT0yjWtCfnjc0Y0TfDG2PHjqWK8+0fT5gojbIVp6pp3B0aAqx5Ou5u3XRs37jXPGHkpnhtBWqod5 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(10201501046)(3231101)(944501161)(3002001)(93006095)(93003095)(6055026)(6041288)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:CY4PR12MB1272; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1272; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1272; 4:PRl6wKtsDjJB/c7uSXAEqU8bTiJJRJGzNxIECjba1NxZ9UB2QSw/1oE+kZ/jh2MluZE2Qd/lnhWuDD5Z+/sDm5NW0cGqaug1GeICJtjtZ0NKh5ArBI8SPTguRVIon+KRLqMyIhsOHBUNP1kMXd9lKnzOEK0ktzpxiBuVhoi1NsiHK5xNWJBIxVr3UqJhYUpdXwcPJW/yvV6Xu14vw2+4TJm2BrvvaZfvIqvQxaeqElqJiouo9taf8dGi5h8m1gWBzorlLZA5WIIVjTvLgx9b5RGpwlKbwHQj4i1V7gdAeoUw9SIGqhg1Q3mdq1IqjlyV X-Forefront-PRVS: 0567A15835 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1272; 23:eeUgesTg4az3d5uWeMMjRKz4+0xZET9S0w+iWNVDl?= =?us-ascii?Q?b15y2IAV2rB8BykI3KFEm8ZB4SRoEYC7v8S7DEiib0PrCG+ZZ99Ib9aKbMWc?= =?us-ascii?Q?zt/SlxdKYh8RwuceA97/gMEF/JrV8iyeZtuQCllzIQi7w5TYpbGbCLukiaIu?= =?us-ascii?Q?T+dut9HJOx6MlA/y+09ManTOrx4hPsEoddptE0pYDU0Um0vn2O1+QzUzNi6A?= =?us-ascii?Q?po56D8ywvQyV1O0tdwqgbzZoY7ImDre9h4huJoSueWOBGeHpFjzqxifPa9co?= =?us-ascii?Q?JvCb6UH9pzmieHj0z5eFn112sUODy+GG89EBNOsaJvgImVAF4lOkuxQmdbWO?= =?us-ascii?Q?K8aaLgjmZGUTfZs6XaAQwRNCCHw30ZN7BjfPFTLYn54U15TfyDmp9nU0+Jex?= =?us-ascii?Q?4DVKKiFP34kLjguKoG1yGuS7DjG/KQ+PMx3W65zEV9nAAjlSHAdNqL3ZUzoz?= =?us-ascii?Q?h5rbN1iWBaJb5rSXXuM3tvivuFl8a3FuX7ZWMiPkOVndWrcIwV3Rze15Q6ir?= =?us-ascii?Q?ePZFgUt9XTds1uDtSU3GM25Zckvi1XNx0a9afqoGRTj+t1SPyhbBMu1OtnOe?= =?us-ascii?Q?EiJbmSNbZRQDq2tniiHYBo3uIsAH7+qUfqXz4G731gGPgjY3i7gIIoHbbaZa?= =?us-ascii?Q?y2nslLwSYpCVvE6f4XnHuuxSd1D/oqOw9+ZUfBOf2KpodR1eBP6NzGtDOBiI?= =?us-ascii?Q?iNdyPWqgwx7ksZ0Gzq/oQlKz+ImwQqS4Yd24pm044gBgmD3KMawFFpbfINRc?= =?us-ascii?Q?AJ8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PC0+p2GmstXySkI7po3bkV34Km296nfUdW0ntS4XhwMGRj+84V3X0fAquwBm81tTpvcc487ZJWWulhwQSw=; 7:k3g1hqhxVrkusH+Ns2i5x2gqS1/hsYrVyB9HxaEhM0dGGxYiAs7IMDTRHBEeOmuHGjOP5tJGaUBocQfbz17680nqYKJWltbR3un6FLLSvDSQ6zpfPD4jmQaCNUbBGys4/KjLMrdaI96lJCzCKfuagVLdS06AIbaA2/WtoIJL0ADquaIJityANAbjtPC0sNyS273tmmq0uZ81Ba39l02niLvIDwkzXFVl9l1DFcE6n1/NE+iq+xCKmns/oXUBJ1VQ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1272; 20:yP+rbJ7XK8zTRm1AuA6014Zht2dzVmBchdSvf3tQmrGDwrlQgqgIt0i9qCWlwRzzB+I8BJ3dMGxTCxKHUYefn65nS9KZ0r+jmWbXzxz0FVvtPZEx/r7vsHDdsNnS/6WFoIsY4ML4o21XXWFiHKi9fdMn1PzLsupEG3JZh+9M7ICsvPIGrdVambGnnKIUSKUBOitepeRV7AxKJK0B5JOI5HV4Wvw5tAgmQDeFaIDCfc2a1Meg7tvf7R3Tt5eUVufq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2018 08:31:21.7066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6cbc070-792d-4249-67aa-08d566f2ad57 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: CY4PR12MB1272 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roger He , Christian.Koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP to indicate whether we are serving for page fault routine when in ttm_mem_global_reserve. for ttm_mem_global_reserve if in page fault routine, allow success always. because page fault routing already grabbed system memory successfully and allow this exception is harmless. Otherwise, it will trigger OOM killer. v2: add new page flag TTM_PAGE_FLAG_PAGEFAULT rather than using struct ttm_operation_ctx Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_bo_vm.c | 6 ++++-- drivers/gpu/drm/ttm/ttm_memory.c | 27 +++++++++++++++++++-------- drivers/gpu/drm/ttm/ttm_page_alloc.c | 5 ++++- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++--- drivers/gpu/drm/ttm/ttm_tt.c | 2 +- include/drm/ttm/ttm_bo_driver.h | 1 + include/drm/ttm/ttm_memory.h | 3 ++- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c index 08a3c32..1aee124 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -235,9 +235,11 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) ttm = bo->ttm; cvma.vm_page_prot = ttm_io_prot(bo->mem.placement, cvma.vm_page_prot); - + ttm->page_flags |= TTM_PAGE_FLAG_PAGEFAULT; /* Allocate all page at once, most common usage */ - if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) { + ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx); + ttm->page_flags &= ~TTM_PAGE_FLAG_PAGEFAULT; + if (ret) { retval = VM_FAULT_OOM; goto out_io_unlock; } diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index 06024ba..d0312a7 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -473,7 +473,8 @@ EXPORT_SYMBOL(ttm_mem_global_free); static int ttm_mem_global_reserve(struct ttm_mem_global *glob, struct ttm_mem_zone *single_zone, - uint64_t amount, bool reserve) + uint64_t amount, bool reserve, + bool in_pagefault) { uint64_t swap_glob_mem, max_swap_cache; uint64_t limit, total_used_mem; @@ -485,6 +486,13 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob, max_swap_cache = (get_total_swap_pages() >> 1) << PAGE_SHIFT; spin_lock(&glob->lock); + /* + * if in page_fault allow reserve successfully anyway since it + * already allocated system pages. Otherwise it will trigger OOM + */ + if (in_pagefault) + goto reserve_direct; + for (i = 0; i < glob->num_zones; ++i) { zone = glob->zones[i]; if (single_zone && zone != single_zone) @@ -499,6 +507,7 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob, goto out_unlock; } +reserve_direct: if (reserve) { for (i = 0; i < glob->num_zones; ++i) { zone = glob->zones[i]; @@ -520,13 +529,13 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob, static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, struct ttm_mem_zone *single_zone, uint64_t memory, - struct ttm_operation_ctx *ctx) + struct ttm_operation_ctx *ctx, + bool in_pagefault) { int count = TTM_MEMORY_ALLOC_RETRIES; - while (unlikely(ttm_mem_global_reserve(glob, - single_zone, - memory, true) + while (unlikely(ttm_mem_global_reserve(glob, single_zone, memory, + true, in_pagefault) != 0)) { if (ctx->no_wait_gpu) return -ENOMEM; @@ -546,13 +555,14 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, * all zones. */ - return ttm_mem_global_alloc_zone(glob, NULL, memory, ctx); + return ttm_mem_global_alloc_zone(glob, NULL, memory, ctx, false); } EXPORT_SYMBOL(ttm_mem_global_alloc); int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, struct page *page, uint64_t size, - struct ttm_operation_ctx *ctx) + struct ttm_operation_ctx *ctx, + bool in_pagefault) { struct ttm_mem_zone *zone = NULL; @@ -568,7 +578,8 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, if (glob->zone_dma32 && page_to_pfn(page) > 0x00100000UL) zone = glob->zone_kernel; #endif - return ttm_mem_global_alloc_zone(glob, zone, size, ctx); + return ttm_mem_global_alloc_zone(glob, zone, size, + ctx, in_pagefault); } void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page, diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 5edcd89..39b184f 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -1094,6 +1094,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update) int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) { struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; + bool in_pagefault; unsigned i; int ret; @@ -1107,9 +1108,11 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) return ret; } + in_pagefault = ttm->page_flags | TTM_PAGE_FLAG_PAGEFAULT; for (i = 0; i < ttm->num_pages; ++i) { ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], - PAGE_SIZE, ctx); + PAGE_SIZE, ctx, + in_pagefault); if (unlikely(ret != 0)) { ttm_pool_unpopulate_helper(ttm, i); return -ENOMEM; diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index 9e90d0e..77dd167 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -939,6 +939,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, struct dma_pool *pool; struct dma_page *d_page; enum pool_type type; + bool in_pagefault; unsigned i; int ret; @@ -948,8 +949,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, INIT_LIST_HEAD(&ttm_dma->pages_list); i = 0; + in_pagefault = ttm_dma->ttm.page_flags | TTM_PAGE_FLAG_PAGEFAULT; type = ttm_to_type(ttm->page_flags, ttm->caching_state); - #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (ttm->page_flags & TTM_PAGE_FLAG_DMA32) goto skip_huge; @@ -971,7 +972,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, break; ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], - pool->size, ctx); + pool->size, ctx, + in_pagefault); if (unlikely(ret != 0)) { ttm_dma_unpopulate(ttm_dma, dev); return -ENOMEM; @@ -1008,7 +1010,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, } ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], - pool->size, ctx); + pool->size, ctx, + in_pagefault); if (unlikely(ret != 0)) { ttm_dma_unpopulate(ttm_dma, dev); return -ENOMEM; diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index 395cac0..c36db66 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c @@ -386,7 +386,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage) ttm->page_flags |= TTM_PAGE_FLAG_PERSISTENT_SWAP; else atomic64_add_return(ttm->num_pages << PAGE_SHIFT, - &ttm->glob->mem_glob->swap_glob_mem); + &ttm->glob->mem_glob->swap_glob_mem); return 0; out_err: diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index 9b417eb..8f68781 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -87,6 +87,7 @@ struct ttm_backend_func { #define TTM_PAGE_FLAG_DMA32 (1 << 7) #define TTM_PAGE_FLAG_SG (1 << 8) #define TTM_PAGE_FLAG_NO_RETRY (1 << 9) +#define TTM_PAGE_FLAG_PAGEFAULT (1 << 10) enum ttm_caching_state { tt_uncached, diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index a273581..b801010 100644 --- a/include/drm/ttm/ttm_memory.h +++ b/include/drm/ttm/ttm_memory.h @@ -87,7 +87,8 @@ extern void ttm_mem_global_free(struct ttm_mem_global *glob, uint64_t amount); extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, struct page *page, uint64_t size, - struct ttm_operation_ctx *ctx); + struct ttm_operation_ctx *ctx, + bool in_pagefault); extern void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page, uint64_t size); extern size_t ttm_round_pot(size_t size);