From patchwork Tue Jun 22 16:23:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 12338011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30851C48BDF for ; Tue, 22 Jun 2021 16:24:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F00D260240 for ; Tue, 22 Jun 2021 16:24:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F00D260240 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 481D46E5BE; Tue, 22 Jun 2021 16:24:13 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2069.outbound.protection.outlook.com [40.107.94.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id C65F26E2D5; Tue, 22 Jun 2021 16:24:11 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzIuBSXLYkqKXyFcs+KekZ7oMkMfA2K1PnDyzj0FtMgoknGzoEvACzQQbNz1w0u7rOw+rsUCxtJywNmirDU4vPY19oM6C1QhTX0biZ1cC6vWsOhzkVyL1zydYs7NEeVt2n/5IQ3O95rtsioZuWJ0wllObPcFkd+134eUBO0zl2NQzLXY+SXx1wKIuI1LdsQ/CVISepz9duBWoe8zk+jtDARp6G+1RvbU6LHrfQdbFQTmpkDC1sZKGmbtFv0eADQ/1nBtheah2F//fTtkcrRI5h5CLLruxxKTAVcN7G/9YQS/12H+rcbV+NSp9YkmaPgRVOe5GZi2zc+fmib4UNeDxQ== 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-SenderADCheck; bh=cIlbrlBQPhwCCtEJn+woubiFNTaH47GxA/pBqNMl0l8=; b=dm1UEVOcTvsteDvnC35SQ3yte3mkkvs3nPqZCgwHjWMUrJfEtwSn8wAQXL4gPxe2S33ib/y/LJVqtTxICQZdGo9jQA1C2J3JQb9kV1vP0JwoHiUnsf8m8yba09xtzMSQl1dHxdhmre8FyB5CnyYTYcAteqmZhTRT+AF7JfWENvbkef9zmfRP4EBLkvGV6JyrTqYd0E0HTx2s7tnRIaFXAG/uqJ0mTmsxamI6YOK9fd4fcCxnspT0/o68qcmX3A1RFyD4Y/idJ5MIKmGwRkSwfeqKcBZoxy/xgX7lGKraNBDJc+MgYYLGz+uPnKWKHT/JFu/mIPkarZ5AnjuSBkBtwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=cIlbrlBQPhwCCtEJn+woubiFNTaH47GxA/pBqNMl0l8=; b=5Rw7pl8O4ecEHM9R5e63aJYlhjaJ+Bx6+FMInjyN8w3BLxmSIjYkRZHDiAEcoIWABFCcmf29EXyRCM2LE6gSDEjqe5hEGXTgbvnl6YKK9ZNgb6mKlzrrdICPHdpGbtS9sPFPDtBxRzHh/PzD65ZWopbMeEBcmMkw0ytjRWao8g4= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) by SA0PR12MB4462.namprd12.prod.outlook.com (2603:10b6:806:95::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.18; Tue, 22 Jun 2021 16:24:10 +0000 Received: from SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::9f8:ec71:6535:cd36]) by SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::9f8:ec71:6535:cd36%5]) with mapi id 15.20.4242.023; Tue, 22 Jun 2021 16:24:10 +0000 From: Andrey Grodzovsky To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 2/6] drm/amdgpu: user temporary GTT as bounce buffer Date: Tue, 22 Jun 2021 12:23:35 -0400 Message-Id: <20210622162339.761651-2-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210622162339.761651-1-andrey.grodzovsky@amd.com> References: <20210622162339.761651-1-andrey.grodzovsky@amd.com> X-Originating-IP: [2607:fea8:3edf:49b0:5c6b:dde9:a4fe:685] X-ClientProxiedBy: YT1PR01CA0137.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::16) To SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from agrodzovsky-All-Series.hitronhub.home (2607:fea8:3edf:49b0:5c6b:dde9:a4fe:685) by YT1PR01CA0137.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18 via Frontend Transport; Tue, 22 Jun 2021 16:24:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 39e8f2a5-0b89-44f6-3f23-08d9359a2a32 X-MS-TrafficTypeDiagnostic: SA0PR12MB4462: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l95BeDMYyx22SoNxA9JHF5gWTpbJixZccbDJzLJQVQBUxiR5MyBj1Sj5QG+iwu5lH6iUaLN1bvKACxTvo+gFPJtolYgH+b7ZUG9sYHY0AO3774O60NmindHwNSMJxVdU0i6U/AwY4yUgfO5pi4QdfsKgZUBseZpElFSyA+YzgTDweq6/U3YYT0vIj4+MQsmfP43UwB8Ngpqz35CB2FFMJIJzHcHOQjAp22ZhCmWmpuultJLFCsWZTsud8GbLI8ApaA6uB6TkE+MvYVvk+Qxsf7E8dPtrtpvgJhRTklwdlNkxwAa6QcHKnvrAO0XXPM4nGQ3SZZ78bqmzvvoA2KXWirtJcfwNgVYOOR4zMeDljZi0MCHWSHNgyN/Ss/5J7DLhCoJj+xvsViH6/4ewYIdCe7j+lYxqG5oSk2rqjUzCIsVgEZ0CqbGGUiRQ8UEDfWyOeJj2Ixj2KNqGbntAbmzVEjqTx+vLx881uS6zczc8AOq398p+JwNfJz1y64fkIx2ZQrax/eFOq28P2inyTFztSwT/Dc9OcXip0qe01jTnNQZoW/zLoYEa73VZLl7fHIH+wNxBJOkOeLnRpFEO8ewK9PEKF0tyFE8u58CuKnXKmEQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4623.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(2906002)(6486002)(498600001)(5660300002)(1076003)(52116002)(16526019)(8676002)(83380400001)(6666004)(36756003)(44832011)(38100700002)(66574015)(6506007)(4326008)(6512007)(66946007)(8936002)(86362001)(2616005)(66556008)(186003)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?RKO0UGR60N1ZvOlsmb0fgU8n3uS9?= =?utf-8?q?hyMuj8gfjFvpbouiwJWkJlW7eZf4BjbY19gy0aWq0y3MfBZc7zlcU5UFsRiWeWzg5?= =?utf-8?q?XINzdCo5bFcPALwpp1Nrv+eHHO3UrJoRFItfwaGM9i6q4tfXhTh/r205zw3bweJuP?= =?utf-8?q?ijxKO7cFMhHVnTjsO5EkHZk1IHB+p5x0CURM+r5Q+TzQ4EQnPSIJlIHEfT4CG3/lY?= =?utf-8?q?5fYawrnwtEjGDITEOKDihLvChfcPyD+yEJ/DDv6sIltALpNeLch3eLu0RjHRbySzX?= =?utf-8?q?53SXxy7okuGW+v1rRs8iHseWIrdk11e94gpjmsLhcrvM7VHLyr6bvSOeTpuK39zuy?= =?utf-8?q?B7V0nfFSmsX88fwoJrLNwr5GF6fUFMgACZK1eBpR5O7WXsp89nKGMY8HUfhQtSbpu?= =?utf-8?q?f34cX5AgL+lsNrh+vHtkbzrGuA0Nx3MKIG3QlHdfy/cGOuMR2F/pvoAASt+V5smMD?= =?utf-8?q?9NmalZOk428zxNVrcRvmMGn9wkap+e+Gu85PghOyOJ4W8gPQyQA8AUTjneGcrwmg5?= =?utf-8?q?bFNnWAsSjsl+4vuH50W/CdUoWuZ85izVyoGryFjSVdLAdt/e/YLehh/t/JlQ2OfC2?= =?utf-8?q?EbhLpmF6iGC2DW019YwnGO4NJ+fzH0CECr4AAZbnJZogj9Oj/NLao2kUzijim8x2O?= =?utf-8?q?6EaPqBtwG47E8iITO3e07CCfICcyoDN3Eaw7tPSY/WHxgoBnpVsTEtJypshD7DGWb?= =?utf-8?q?RJ/EkKnpXeAc1c4t6CYqdOf9hferi/8Ku4OUlYopj4rvo4FO32ojc/XJROoiD/YBB?= =?utf-8?q?vqxNQDwDxSkYDUfcwFnlzW70tpLDSvOh2KWytxJTOqJlBSyvGFp6JJQeWc8vVeIu7?= =?utf-8?q?N6hUVlkaNFvf/kPrECRC6Yscc6dQdwNXek8XGJP8aCbW6euDQ3v6kFfK4xQa4z958?= =?utf-8?q?DqFH0b8GsX6MphlmfqlcGgBOQbZRtDS9jyC9OmrsIU9xkddEuVwOIOhNepbbj+YP0?= =?utf-8?q?vdOsAT8pwNdilCmEY5QHo/5zDYc7tPKsBw4968ANCamHijwrYy4Dz8VDgPUr8EiKp?= =?utf-8?q?cNMTHSD+3DdGBZr2Eiq0C4U2Haz30IYYEYK+l/ISe5IFqxEr2qws3kYBABauYL9IK?= =?utf-8?q?l5/YveKhovbQOALA7jPBu/Z7JHMq4Mljw1vT1WXCuYAQF++JtFP24NNl0iPML6bku?= =?utf-8?q?oVmQSDdL2PI37duGTQXIceh02u8dyRbdbxp/u5IBefYMCrFZvbjlWi4HA4BJYzGDX?= =?utf-8?q?dsIXiyL1etDiaDXLfLw0XVU7GW2CmPYR/GC3p9qjb2JKVii/K1choYebNoptw6//w?= =?utf-8?q?njQq/0LIm4EBhz6dAYHFRzw1KmBP4bm571QL+Z72Fht2BVbQ5x5TBfzzKdhKxVh7o?= =?utf-8?q?wE1eZR9VQIE9rnM?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39e8f2a5-0b89-44f6-3f23-08d9359a2a32 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4623.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2021 16:24:10.1516 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D7iYFtoLMx5y/Uszr7KWBpzPZORTf7C8q9pX+1avJFSGbOiEkVfMEZqkL5uUiRP1NyS5Pd5W7RleqZVVF9ZLxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4462 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: ckoenig.leichtzumerken@gmail.com, Lang.Yu@amd.com, =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Lang Yu Currently, we have a limitted GTT memory size and need a bounce buffer when doing buffer migration between VRAM and SYSTEM domain. The problem is under GTT memory pressure we can't do buffer migration between VRAM and SYSTEM domain. But in some cases we really need that. Eespecially when validating a VRAM backing store BO which resides in SYSTEM domain. v2: still account temporary GTT allocations v3 (chk): revert to the simpler change for now Signed-off-by: Lang Yu Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 20 ++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index ec96e0b26b11..b694dc96b336 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -132,14 +132,15 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, struct amdgpu_gtt_node *node; int r; - spin_lock(&mgr->lock); - if (tbo->resource && tbo->resource->mem_type != TTM_PL_TT && - atomic64_read(&mgr->available) < num_pages) { + if (!(place->flags & TTM_PL_FLAG_TEMPORARY)) { + spin_lock(&mgr->lock); + if (atomic64_read(&mgr->available) < num_pages) { + spin_unlock(&mgr->lock); + return -ENOSPC; + } + atomic64_sub(num_pages, &mgr->available); spin_unlock(&mgr->lock); - return -ENOSPC; } - atomic64_sub(num_pages, &mgr->available); - spin_unlock(&mgr->lock); node = kzalloc(struct_size(node, base.mm_nodes, 1), GFP_KERNEL); if (!node) { @@ -175,7 +176,8 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, kfree(node); err_out: - atomic64_add(num_pages, &mgr->available); + if (!(place->flags & TTM_PL_FLAG_TEMPORARY)) + atomic64_add(num_pages, &mgr->available); return r; } @@ -198,7 +200,9 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, if (drm_mm_node_allocated(&node->base.mm_nodes[0])) drm_mm_remove_node(&node->base.mm_nodes[0]); spin_unlock(&mgr->lock); - atomic64_add(res->num_pages, &mgr->available); + + if (!(res->placement & TTM_PL_FLAG_TEMPORARY)) + atomic64_add(res->num_pages, &mgr->available); kfree(node); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 80dff29f2bc7..79f875792b30 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -521,7 +521,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict, hop->fpfn = 0; hop->lpfn = 0; hop->mem_type = TTM_PL_TT; - hop->flags = 0; + hop->flags = TTM_PL_FLAG_TEMPORARY; return -EMULTIHOP; }