From patchwork Fri Feb 23 14:47:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 10237917 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 2EECB602A0 for ; Fri, 23 Feb 2018 14:47:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CA9C29067 for ; Fri, 23 Feb 2018 14:47:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 103E2290EB; Fri, 23 Feb 2018 14:47:41 +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=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 8A80929067 for ; Fri, 23 Feb 2018 14:47:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 28F7E6F163; Fri, 23 Feb 2018 14:47:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0071.outbound.protection.outlook.com [104.47.36.71]) by gabe.freedesktop.org (Postfix) with ESMTPS id 880B46F163; Fri, 23 Feb 2018 14:47:36 +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=rYWmtAjp8PGNAWO+NQM1duetVZkQwMQB1rJg1I5nU8s=; b=vpD5MclcUgQF9Y3adU6Dk7DOKBVVvVccmWLlm06XCRDBC8VLcA0ph4dy6crOYDQ0ldrVILI/7xDFOX0mSe3wJqOMDkcj0VYBT5d+lOB+E4kJHBrdIebHErg0mvZa1/hUK1RNaZ4omS5+Te0ohK8A8UD8MmetwGhOBYx36TWn2zI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tom.StDenis@amd.com; Received: from tomtop.localdomain (65.95.38.236) by BN6PR1201MB0065.namprd12.prod.outlook.com (10.174.114.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Fri, 23 Feb 2018 14:47:34 +0000 From: Tom St Denis To: amd-gfx@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: replace iova debugfs file with iomem (v3) Date: Fri, 23 Feb 2018 09:47:24 -0500 Message-Id: <20180223144724.20555-1-tom.stdenis@amd.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [65.95.38.236] X-ClientProxiedBy: BN4PR11CA0024.namprd11.prod.outlook.com (10.164.240.162) To BN6PR1201MB0065.namprd12.prod.outlook.com (10.174.114.15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 415b90ab-3a6a-4bf8-1ca5-08d57acc5ff8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:BN6PR1201MB0065; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0065; 3:vZL91VLc937gB+VjAp/0bYvNbZXN/hAjYADbDMBSXwUxpu+1xv5OjOIPWzzcT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v3blfyabNuNTV9H7zJIyN5bch/kqdCxl1qwuM6h2JZCoBNxFf56enYUS8inyyaMgQgRu1V7Yto2OIRd4+667W2Ssjg3YsAsl2YaF0aPyChPRVyAqBT//m2esCaEzmLiBjORYrSI30VWLAqtcOx1aX/zYcyV+DGfe47g/r7DM81NVO37+n5wZumAoLIL9psf5WsTzFRglq0dj0JrAsH7KjW9pCONv3V+Ez9C4HEYmX8Xph/02ORQcbfxwX657JaQpwZW7FRNHtjEYIINyTZt3P64JMhPGwYpTYT4kT; 4:UV8OOkbqHh3gkPzHgwvrybHTrwtOoiuB0vBbqu88brcTr6p3z6pEJQ6olTuDQr+HB4IdaTmjcKg8rmmtMjxfOAE89tV9b+b1iTqxZO+USEeEJgjTdFWO1hS++LB+9k3hS/DJzwd3wJEW0fJwyGM9Gw+QW0QJbH8uiJv0fY3I8cpUyICkDGnkw6fFuSuDXkNNKc94rkj9+tGY9kNo4+MvX55q6O7K8omJC8US2CLRQ0Qxt45rtD7DNvCH8W9FrpVl/IJwejMe3MifiKn4VJ5hnqL02576MDrvWTDFzFTBmrrac0ZGSn1ny/PxCDhce5dBIz7hEFRX1eS77a42SBQFVw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001082)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231101)(944501161)(10201501046)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:BN6PR1201MB0065; BCL:0; PCL:0; RULEID:; SRVR:BN6PR1201MB0065; X-Forefront-PRVS: 0592A9FDE6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(376002)(39860400002)(346002)(396003)(366004)(189003)(199004)(25786009)(26005)(450100002)(6916009)(386003)(53936002)(6506007)(66066001)(478600001)(186003)(47776003)(2870700001)(1857600001)(72206003)(106356001)(4326008)(6512007)(59450400001)(6666003)(2361001)(6486002)(2351001)(50226002)(5660300001)(305945005)(105586002)(6116002)(3846002)(16526019)(97736004)(8936002)(316002)(7736002)(81156014)(8676002)(2906002)(86362001)(68736007)(1076002)(81166006)(36756003)(50466002)(23676004)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0065; H:tomtop.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyMDFNQjAwNjU7MjM6TlpERGVCUTFLT2JZakJ0NWtsQ3pGcWhh?= =?utf-8?B?MU1xanpYT2Z3UFNTKy9SeHN2M09qV2RYRmpvUm42U3JkWlFPTDlMamZQSmMv?= =?utf-8?B?M0wvaVYwMks1Si9na2Z4RnRvRURMWHBVeFVpME1sMHBMR3VGZEpBYklpaWhj?= =?utf-8?B?YWZTNVJBVDRmTzNzSExzTk9qdStxekVXUHpmeXIzVEIyMEFLMjk4VCtNWS9F?= =?utf-8?B?TitlaUV4dlAzcFpab3J2cElHVVVpL09WSlpLd1kvYUdSWE5WVTR3enp3aEFU?= =?utf-8?B?NmlnaERPSGVhcU5zNG8vRGZ6ZnBqTGlFWEs4RHZ2cDd0MkZHeVczNkpDbmsv?= =?utf-8?B?aTFMU1VyNDJQSXo2UjVveklKQlhuMi9pQU96STFsSmhrbHRJT0ZtNGZEdE1H?= =?utf-8?B?QUJId0xJbGl0VXQvTitYajhIMmZTOVhtSjdSQjVMWDlGNGpjVS9UajdOenBD?= =?utf-8?B?NUkrNDBKQlRKQkViNEtzcjR0ZGt4eEx6cDU5elhRL2tIVzZwZy9QNTVlN0lR?= =?utf-8?B?eS9LRWRVQ1RpU3VlQkdIYzRyWVhUVG5WcllIRlRKN3BoVGQxK1U2b0dHYWNn?= =?utf-8?B?MjZGRGVNd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Jm7UGoY59u2iSgo77/G3A SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0065; 20:EMvIZM1ZkDlyGdMP7vwviU0fjxpybT7b5cfOESTWmziES3HzRtPMOW/UGUNNFeJT+hvyxKw1fRkgDsQqB61b7UyE+ECOp7qMPZEyVteDRcaQqYwqKRVzjy7ZBNDCEroN6wPOVIho4JJc9h/dU0g/adpkzfvNEO9iYef085AL2QZDnwZJ9WUU7XjheclFp8GicvflvWitGUOr72brt7Xl+dKIipzhDCsSoYrgsjMTbKYmyXPBPEMyhtfDvpWyTeYx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2018 14:47:34.2618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 415b90ab-3a6a-4bf8-1ca5-08d57acc5ff8 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0065 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: Tom St Denis , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows access to pages allocated through the driver with optional IOMMU mapping. v2: Fix number of bytes copied and add write method v3: drop check for kmap return Original-by: Christian König Signed-off-by: Tom St Denis --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 102 +++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index b372d8d650a5..1338c908056f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1929,38 +1929,98 @@ static const struct file_operations amdgpu_ttm_gtt_fops = { #endif -static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf, - size_t size, loff_t *pos) +static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf, + size_t size, loff_t *pos) { struct amdgpu_device *adev = file_inode(f)->i_private; - int r; - uint64_t phys; struct iommu_domain *dom; + ssize_t result = 0; + int r; - // always return 8 bytes - if (size != 8) - return -EINVAL; + dom = iommu_get_domain_for_dev(adev->dev); - // only accept page addresses - if (*pos & 0xFFF) - return -EINVAL; + while (size) { + phys_addr_t addr = *pos & PAGE_MASK; + loff_t off = *pos & ~PAGE_MASK; + size_t bytes = PAGE_SIZE - off; + unsigned long pfn; + struct page *p; + void *ptr; + + bytes = bytes < size ? bytes : size; + + addr = dom ? iommu_iova_to_phys(dom, addr) : addr; + + pfn = addr >> PAGE_SHIFT; + if (!pfn_valid(pfn)) + return -EPERM; + + p = pfn_to_page(pfn); + if (p->mapping != adev->mman.bdev.dev_mapping) + return -EPERM; + + ptr = kmap(p); + r = copy_to_user(buf, ptr, bytes); + kunmap(p); + if (r) + return -EFAULT; + + size -= bytes; + *pos += bytes; + result += bytes; + } + + return result; +} + +static ssize_t amdgpu_iomem_write(struct file *f, const char __user *buf, + size_t size, loff_t *pos) +{ + struct amdgpu_device *adev = file_inode(f)->i_private; + struct iommu_domain *dom; + ssize_t result = 0; + int r; dom = iommu_get_domain_for_dev(adev->dev); - if (dom) - phys = iommu_iova_to_phys(dom, *pos); - else - phys = *pos; - r = copy_to_user(buf, &phys, 8); - if (r) - return -EFAULT; + while (size) { + phys_addr_t addr = *pos & PAGE_MASK; + loff_t off = *pos & ~PAGE_MASK; + size_t bytes = PAGE_SIZE - off; + unsigned long pfn; + struct page *p; + void *ptr; + + bytes = bytes < size ? bytes : size; - return 8; + addr = dom ? iommu_iova_to_phys(dom, addr) : addr; + + pfn = addr >> PAGE_SHIFT; + if (!pfn_valid(pfn)) + return -EPERM; + + p = pfn_to_page(pfn); + if (p->mapping != adev->mman.bdev.dev_mapping) + return -EPERM; + + ptr = kmap(p); + r = copy_from_user(ptr, buf, bytes); + kunmap(p); + if (r) + return -EFAULT; + + size -= bytes; + *pos += bytes; + result += bytes; + } + + return result; } -static const struct file_operations amdgpu_ttm_iova_fops = { +static const struct file_operations amdgpu_ttm_iomem_fops = { .owner = THIS_MODULE, - .read = amdgpu_iova_to_phys_read, + .read = amdgpu_iomem_read, + .write = amdgpu_iomem_write, .llseek = default_llseek }; @@ -1973,7 +2033,7 @@ static const struct { #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT }, #endif - { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM }, + { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM }, }; #endif