From patchwork Mon Sep 26 06:03:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12988243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1AC9EC32771 for ; Mon, 26 Sep 2022 06:05:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A365310E514; Mon, 26 Sep 2022 06:05:23 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2040.outbound.protection.outlook.com [40.107.94.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3DE710E4EB; Mon, 26 Sep 2022 06:04:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a9Zzue6fuDipbzCpfvzeZrnf7WgfPfbvJwj2OwTEz5xCNSKq6Co5BMc1eQZrx3epp+oJoWQVzJuXSpQt+5z42nvpoyDMVoh9u4QeuIuBKaECo47IeANznHCikR4jbfFBl1HN6LJk5KgJVhMMvVm6Mkgcjt+s44s7VvZpq+0UZpYeRkPTQ8Xp7jP+mS9whC+Fv5V+NKv0KOajPZTGy+GJX8fXF6BDQLMpwfXlqwaOAGvSopXSHzbDJbpxCruGJAXQ+Rg4v8v4VFwoKWZ0rBBjoDFXKou+J8m5wNZAzFdpN0r+ecVHC8Ukz3DIj8grqg/LKWCeWm07zhvkiWx6n7diYA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pbQbKA0W/wtOMie6uvz1GHqU00jSixx5Ur+w1U41HtM=; b=Ih3xnZ70QhNk5zBoc7ZPvatASevk/oiYxaxQQkvYY2HDMwLy06Umw28vYnnL7ogByUaPtkLFPhTReSGVqsPTmzWcL7wV/mPAcbM4Zo07GjIGFYcrsT666bJ8bl9AVqQaAC/npirvL/d1aJ+Ylq0WxuS90jE7JzIKACjKdZZ4vR5gxsg8qK+q0hhXcYKbcb8kyZYPUUjwachaN6HLOQhj8qcerkicnuSz98TLHn6+8U6rKrHieA4NmoOQqd4JwR9+NF14XX/rEqA1KiDI3AsNZ1txgoluvJyvVk38EIQvHO/M2lUCQ3/RIJGjgcQI5iNmJo6OH1nrnVe4I916Gyaitw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pbQbKA0W/wtOMie6uvz1GHqU00jSixx5Ur+w1U41HtM=; b=YZRMWB7iW3LcCzecaLuIRHP85rM4mcjht10C/r70JAzZwGixFN/newcSLc0H2NQxnF3p4O1cAO86uGoG3tWKKX2NIW53GmTze15zh1NRDrkNJs+1r50LbiIwJzF9tUnKAtmmu0n1xbgpB+8ym9UeNKUc4GgGd9n4P/26wDQZZfeledzRa4MvmMd6UF0iTP20yI5ejZywqW1N1hF3p6JL2m7udbjrbT97LwQQtPEgzjDqI4Vg+BGt4cRgtUx5R/DTWc/NlEL/Qwn7BRksFwKXwk8nuviHvMxJTXJC5SHuTcxKNoWp1rx0sPrnpHAKnXL3d8KQB+LRA1dTpIgQmjXQDA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by MW4PR12MB7359.namprd12.prod.outlook.com (2603:10b6:303:219::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Mon, 26 Sep 2022 06:04:37 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ed0:a520:ac8e:9966]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ed0:a520:ac8e:9966%6]) with mapi id 15.20.5654.025; Mon, 26 Sep 2022 06:04:37 +0000 From: Alistair Popple To: linux-mm@kvack.org, Andrew Morton Subject: [PATCH 5/7] nouveau/dmem: Refactor nouveau_dmem_fault_copy_one() Date: Mon, 26 Sep 2022 16:03:09 +1000 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: X-ClientProxiedBy: SYBPR01CA0213.ausprd01.prod.outlook.com (2603:10c6:10:16::33) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|MW4PR12MB7359:EE_ X-MS-Office365-Filtering-Correlation-Id: 32891b4b-a7a2-40e0-9ab5-08da9f84fe35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kU+lUcVvxCA+ofn9yeVdT0KOZaqMD5p1fc0TzZMiUkmL6GJdkZvNLZn2C92Yr5meoWu37ElYFn0L4vWDo1SwymLJ0UzfL5W1lqpylYmrnngZqm1lUwaKjAuutkDXMkQmRHw/vnSLru+zWPfDPCp2Cni2b+qwq3Y5BQwzyFPI7Go9hyBlIdlVA92BcZbHw2R/yMveXSOoXH1qSWRZJH+UrQOtZ5uYLevThKlw0o3UgiHyJNs8IgRDfG8rvYEzMxaVhY8gQvsh4dfIY66S/cZITge+zsrJqlHe9z7yXBvp/3vIh/HUGmKnJs81x0MG6ROQk6WQoVhhbYt1vhXqsTtdVmTJlWeHPpqE+VpvmAm0yAkRPlYRs5OfsFdQh6QjqLkXEJHGBSmwhaIjSWCu5X0oINlVrZkhqRW4zoadXBT6v/NXAUFWQ4lBdwZ9B9tKJA7euDFYacQAbjm0zmHLnUl7BkwhlsFfKtR828e6MKvBcGEx2NRnoYZ2Il5NOauYxXF+QODurUFKRpz5204Tcnsv0HKci0ELIVIo5ys8AgY/s8q/zq0vzNm4OFa16+iCo4I8NDNIQoMffX0B+xCIL5HTweLEBfpwkg34YcU3eisroVlEF8TlDFhjbQLjA+5IKhk4+TQ7KwDio57OD8BkZX6w02NsKVIA1rYhNrN3BUH7pZd240NoWpHmyjsGjMFQ1Ihh1eRattbbYMrHt/tYNrFkHiSFMN9o8PBZfYNjhhq3gAKNSRZR+HCy/gCaahFZpQi0 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR12MB3176.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(136003)(366004)(376002)(396003)(346002)(451199015)(8936002)(86362001)(7416002)(2906002)(5660300002)(83380400001)(6666004)(41300700001)(6512007)(186003)(107886003)(26005)(6506007)(478600001)(6486002)(2616005)(6916009)(66946007)(4326008)(66556008)(66476007)(8676002)(316002)(38100700002)(54906003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DneXTA/x7aBipup8UqZDGn+osT5MF867amYmUtHe58VRd0e5FiIg0O/ppsULHHOYnpu8bpie6YiWtjSy15VoNeVSPMXUa1hXdTaLIcDth9JweQWQ1YrhTVqIYZYe6XfIf8ma2DPCWHbRg0gMBv4MLxvf67G4EAkXWKlup6EVz8d8rY2CyM1uGxPH4slSLv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YiyFddUWcLPDW9UORFSL+nhLydEWG1biWIcldsORMkl/i2v0XnydQda12NrEqCwoZU2GmPGlGxbN4YiPwdct7hHvCrSEp53D454WtHcKA4MAzYN6cP5o44pzqoUprW0DbUTCZmgao7lJ7wA+++3+LBqZvXsOTguMG9gayp4+CC9qGIaTRTlz6IRNoRA3xjhr/POLoR7DbdCPDE3d/EtygIG8k+paOBhyrnBGZIIefpw7LFljr5ArKnff6hlaaLQLsu2tHpp2iCZe1wqeU/YYq/spoUO4EQv40fqpBcRYAxJjOFI2shU9xb6cV7mqexh51Fkbb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32891b4b-a7a2-40e0-9ab5-08da9f84fe35 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2022 06:04:37.7490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xrQonp5f4+KK2a0BpjaBdTX544f82d4XLFcIztTkczIx3dZZbDGJdisnpg3K+Dq/LWQZwCxOqgxz5IWrates/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7359 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: Alex Sierra , Karol Herbst , David Airlie , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Michael Ellerman , Alistair Popple , "Matthew Wilcox \(Oracle\)" , Ben Skeggs , Jason Gunthorpe , Ralph Campbell , John Hubbard , Nicholas Piggin , Dan Williams , Felix Kuehling , "Pan, Xinhui" , linux-kernel@vger.kernel.org, Alex Deucher , linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" nouveau_dmem_fault_copy_one() is used during handling of CPU faults via the migrate_to_ram() callback and is used to copy data from GPU to CPU memory. It is currently specific to fault handling, however a future patch implementing eviction of data during teardown needs similar functionality. Refactor out the core functionality so that it is not specific to fault handling. Signed-off-by: Alistair Popple Reviewed-by: Lyude Paul --- drivers/gpu/drm/nouveau/nouveau_dmem.c | 59 +++++++++++++-------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index f9234ed..66ebbd4 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -139,44 +139,25 @@ static void nouveau_dmem_fence_done(struct nouveau_fence **fence) } } -static vm_fault_t nouveau_dmem_fault_copy_one(struct nouveau_drm *drm, - struct vm_fault *vmf, struct migrate_vma *args, - dma_addr_t *dma_addr) +static int nouveau_dmem_copy_one(struct nouveau_drm *drm, struct page *spage, + struct page *dpage, dma_addr_t *dma_addr) { struct device *dev = drm->dev->dev; - struct page *dpage, *spage; - struct nouveau_svmm *svmm; - - spage = migrate_pfn_to_page(args->src[0]); - if (!spage || !(args->src[0] & MIGRATE_PFN_MIGRATE)) - return 0; - dpage = alloc_page_vma(GFP_HIGHUSER, vmf->vma, vmf->address); - if (!dpage) - return VM_FAULT_SIGBUS; lock_page(dpage); *dma_addr = dma_map_page(dev, dpage, 0, PAGE_SIZE, DMA_BIDIRECTIONAL); if (dma_mapping_error(dev, *dma_addr)) - goto error_free_page; + return -EIO; - svmm = spage->zone_device_data; - mutex_lock(&svmm->mutex); - nouveau_svmm_invalidate(svmm, args->start, args->end); if (drm->dmem->migrate.copy_func(drm, 1, NOUVEAU_APER_HOST, *dma_addr, - NOUVEAU_APER_VRAM, nouveau_dmem_page_addr(spage))) - goto error_dma_unmap; - mutex_unlock(&svmm->mutex); + NOUVEAU_APER_VRAM, + nouveau_dmem_page_addr(spage))) { + dma_unmap_page(dev, *dma_addr, PAGE_SIZE, DMA_BIDIRECTIONAL); + return -EIO; + } - args->dst[0] = migrate_pfn(page_to_pfn(dpage)); return 0; - -error_dma_unmap: - mutex_unlock(&svmm->mutex); - dma_unmap_page(dev, *dma_addr, PAGE_SIZE, DMA_BIDIRECTIONAL); -error_free_page: - __free_page(dpage); - return VM_FAULT_SIGBUS; } static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf) @@ -184,9 +165,11 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf) struct nouveau_drm *drm = page_to_drm(vmf->page); struct nouveau_dmem *dmem = drm->dmem; struct nouveau_fence *fence; + struct nouveau_svmm *svmm; + struct page *spage, *dpage; unsigned long src = 0, dst = 0; dma_addr_t dma_addr = 0; - vm_fault_t ret; + vm_fault_t ret = 0; struct migrate_vma args = { .vma = vmf->vma, .start = vmf->address, @@ -207,9 +190,25 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf) if (!args.cpages) return 0; - ret = nouveau_dmem_fault_copy_one(drm, vmf, &args, &dma_addr); - if (ret || dst == 0) + spage = migrate_pfn_to_page(src); + if (!spage || !(src & MIGRATE_PFN_MIGRATE)) + goto done; + + dpage = alloc_page_vma(GFP_HIGHUSER, vmf->vma, vmf->address); + if (!dpage) + goto done; + + dst = migrate_pfn(page_to_pfn(dpage)); + + svmm = spage->zone_device_data; + mutex_lock(&svmm->mutex); + nouveau_svmm_invalidate(svmm, args.start, args.end); + ret = nouveau_dmem_copy_one(drm, spage, dpage, &dma_addr); + mutex_unlock(&svmm->mutex); + if (ret) { + ret = VM_FAULT_SIGBUS; goto done; + } nouveau_fence_new(dmem->migrate.chan, false, &fence); migrate_vma_pages(&args);