From patchwork Mon May 16 23:14:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12851672 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B480DC4321E for ; Mon, 16 May 2022 23:15:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D2436B0075; Mon, 16 May 2022 19:15:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 232F28D0007; Mon, 16 May 2022 19:15:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3FE86B0075; Mon, 16 May 2022 19:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A2E156B0078 for ; Mon, 16 May 2022 19:15:08 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 788EF2F4B2 for ; Mon, 16 May 2022 23:15:08 +0000 (UTC) X-FDA: 79473163896.29.BB78804 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062.outbound.protection.outlook.com [40.107.92.62]) by imf15.hostedemail.com (Postfix) with ESMTP id BD308A00B7 for ; Mon, 16 May 2022 23:14:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qxpn3Ng79XJ6NCZ1PuIQGxKccc0v12wvp2nJXDrAvE5W01p7vdVCjzIt/iV/hXHabuMwOUF1MhCkItbbl9XNVPZ+WQSObSl0/UPYOwB4jI5fsNhjCGEP2+L/jMa/QBzmoI7/Voa/as1FhPBPwqMrg1UNXZJB8YsJLGrfEAE0FeP0fFhTVN+toKQ62n7KXjyagHvyZyinxeNEuMaSqm3r6k7mKJMJIranQt23fF8+RqtgFF2/WM2bd0H7A6QsTLXUuqMpIoCsiFkSdPk0sQsq4fdRS5aePmRlx8OYgDscIMAb5/2/lBt56SSrW0Ed62t8fENODj5G/T3D3U93SpT/AQ== 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=nl288P0aFMxHvyTdajqKdYE2bhkbzZtjR6cg4VQwpEg=; b=kRnIxbrKUHTvmTqumiYUL+Eb7ORNwOWDKpBYzK2MYvzpSwQxei83mY78NctGwsnJQApFjysr8s7WDpM+Dp60MxvAm0JyY6golbRdU9EEjfyIlDakkEgnMPoTOB1PUNEGT5ER/RGXPf6F8mYWZRXrDvGv4oyBlNY4axmmJjodOGpTTldbJ59DoO9rXXZyjxkcFJVhzE3UJmZv1RLOpPJxuFsoDlvb1oNKODtsQ/6MdHvyN9mes4En3Mh/oW28ioHKyloW8x8rvdSCy8znglCCyqFNi+fz5VdYdLlFqLh5xr2tsVfKKO4q+uC+oueSlAGfFZerq5G6ZZxwucnNFMAOdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=nl288P0aFMxHvyTdajqKdYE2bhkbzZtjR6cg4VQwpEg=; b=ocvCMLTec9+0iVnrea0FBdWwHKS4DXrA7nQyFaLpohD+ZJvpit8n5Z2jvIHkK+RzQl4nqNDhY3AGI4cc7oxZubBVxlEXll0MR+HEniaxinhKLMl3XGZ0Y6jiBl5puf8/rhrBa08EMI2/gPF9icrmTx4g+jYKYTF5CX12XZ3JVMc= Received: from BN9PR03CA0369.namprd03.prod.outlook.com (2603:10b6:408:f7::14) by MN2PR12MB3182.namprd12.prod.outlook.com (2603:10b6:208:107::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.18; Mon, 16 May 2022 23:15:00 +0000 Received: from BN8NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::e) by BN9PR03CA0369.outlook.office365.com (2603:10b6:408:f7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14 via Frontend Transport; Mon, 16 May 2022 23:15:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT051.mail.protection.outlook.com (10.13.177.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5250.13 via Frontend Transport; Mon, 16 May 2022 23:15:00 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 16 May 2022 18:14:59 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v2 05/13] drm/amdkfd: add SPM support for SVM Date: Mon, 16 May 2022 18:14:24 -0500 Message-ID: <20220516231432.20200-6-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220516231432.20200-1-alex.sierra@amd.com> References: <20220516231432.20200-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a86ff996-e302-4bcc-8987-08da3791e698 X-MS-TrafficTypeDiagnostic: MN2PR12MB3182:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CMhDJrvW7UMUslFmym0jG1ZSwj40AJceDoZXsLDRX1xQ+4UiEV6X4UrNFULG7sNHhEkytyOphp0leebXJ9nk7jERDr4kWNdsRs0R+z6arnIWmr//Y6tnKPXZZzq/wb6hYsaVdYMsEGwQBEAIzH3DNa0naf3YJWC3hCi6YPGI3PylZYBooZ05jiMb5UZALc/6T4U5icE2RaHlZX5PnN3+kiR+JCVnWGdzw3htV4ny7xS7C9CFKo7PkTJkv/Jc3ZUzxJEpyM7tK8T5Oi1pJoHeNIdcc7kQpkeCxg6KYCIBPPff4uA27lQWCbRjEa5Y2axeocDg4stF6pVhxraZHSSl5TxVBSSuWy796Pnm/xVIYttKOADUWGC35+bKtCntkkcsrLiPhyzAAhLOmyTyCTZV2e0lr35Pt1brjG9bUQ8gnzvoRKp1xkYtRtAGIfbLuZQYQlUxohRAadouWIPTeViylNKQlMn6IncVVuYTahcm/dFGR6K3q6UR6256ihF9s2jKNGDz2wk0oNlZYzo+2xq1vQKO4XWBXUfESjZZEs5tfbYqDRQkZxQk6SCbnAUkF8Ca6yS9QUuyAM/WHCVzz6/EpD1laHa2isj03BhvJF11Hs7T9jHMmz/2qW8rROQKfg+b3KBlDlxbzCAqcyFKIV9stq5EJrDNDRC0KMce73oTRMzW6bHpRyg5/qD7C09F3Yds+nN1lxdM2TqDCPQUeiWmBQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(44832011)(508600001)(5660300002)(70206006)(7416002)(70586007)(8936002)(4326008)(8676002)(86362001)(40460700003)(186003)(1076003)(16526019)(26005)(36756003)(2616005)(7696005)(2906002)(54906003)(47076005)(426003)(356005)(336012)(6666004)(81166007)(36860700001)(83380400001)(82310400005)(6916009)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2022 23:15:00.4107 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a86ff996-e302-4bcc-8987-08da3791e698 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3182 X-Stat-Signature: 5p1581asjiz1edw15y17urdak88h3baa X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BD308A00B7 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ocvCMLTe; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf15.hostedemail.com: domain of Alex.Sierra@amd.com designates 40.107.92.62 as permitted sender) smtp.mailfrom=Alex.Sierra@amd.com X-HE-Tag: 1652742892-563737 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_COHERENT to create the device page map region. Also, MIGRATE_VMA_SELECT_DEVICE_COHERENT flag is selected for coherent type case during migration to device. Signed-off-by: Alex Sierra Reviewed-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 7e3a7fcb9fe6..25c9f7a4325d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -673,9 +673,12 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + if (adev->gmc.xgmi.connected_to_cpu) + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_COHERENT; + else + migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; buf = kvmalloc(size, GFP_KERNEL | __GFP_ZERO); @@ -948,7 +951,7 @@ int svm_migrate_init(struct amdgpu_device *adev) { struct kfd_dev *kfddev = adev->kfd.dev; struct dev_pagemap *pgmap; - struct resource *res; + struct resource *res = NULL; unsigned long size; void *r; @@ -963,28 +966,34 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); - if (IS_ERR(res)) - return -ENOMEM; + if (adev->gmc.xgmi.connected_to_cpu) { + pgmap->range.start = adev->gmc.aper_base; + pgmap->range.end = adev->gmc.aper_base + adev->gmc.aper_size - 1; + pgmap->type = MEMORY_DEVICE_COHERENT; + } else { + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) + return -ENOMEM; + pgmap->range.start = res->start; + pgmap->range.end = res->end; + pgmap->type = MEMORY_DEVICE_PRIVATE; + } - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; - pgmap->range.start = res->start; - pgmap->range.end = res->end; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; - + pgmap->flags = 0; /* Device manager releases device-specific resources, memory region and * pgmap when driver disconnects from device. */ r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); - /* Disable SVM support capability */ pgmap->type = 0; - devm_release_mem_region(adev->dev, res->start, resource_size(res)); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) + devm_release_mem_region(adev->dev, res->start, + res->end - res->start + 1); return PTR_ERR(r); }