From patchwork Mon Feb 12 15:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 10213285 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 35D1E60236 for ; Mon, 12 Feb 2018 15:18:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 265C82872A for ; Mon, 12 Feb 2018 15:18:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A8D628C33; Mon, 12 Feb 2018 15:18:52 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, 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 219192872A for ; Mon, 12 Feb 2018 15:18:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5554689CB3; Mon, 12 Feb 2018 15:18:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0050.outbound.protection.outlook.com [104.47.38.50]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9DA6289CB3; Mon, 12 Feb 2018 15:18:49 +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=lYgjkMQUdJnnToPtyIUe+rUayYPJc1kXAxhDtTV2EcU=; b=alYqT/z/OmTgdafxdzwMhIAJtHp/RjMorRZwUPj247uf7QkopB/VwnDvzrRhWelB7gsWNdQYvaUMHYNRfWqPbmCyuXr7cnwHH5tfAxnYmAmeBSWjGvsISAsHjWIFbFDFPPYbdxCrvtY8zJCG99JWUMUsbSwArdxHufoay5jmuqo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tom.StDenis@amd.com; Received: from fx8.amd.com (165.204.55.251) by BN6PR1201MB0067.namprd12.prod.outlook.com (10.174.114.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Mon, 12 Feb 2018 15:18:46 +0000 From: Tom St Denis To: amd-gfx@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: replace iova debugfs file with iomem (v3) Date: Mon, 12 Feb 2018 10:18:36 -0500 Message-Id: <20180212151836.15088-1-tom.stdenis@amd.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: SN2PR01CA0026.prod.exchangelabs.com (10.167.12.164) To BN6PR1201MB0067.namprd12.prod.outlook.com (10.174.114.17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3e8dbf23-d42c-4ec1-fd92-08d5722be96f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:BN6PR1201MB0067; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0067; 3:7wER0YprY2tswhWyfmppTZ6zkmM3KzqXmu7KlyIg6m+2u9YCl0AJML+PuK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PpRAMmRzVT6u64/dsCb91dl9hMQpLXsN9LXrLmDwTofpoT+m1soPN9SoI3hVGLOb2ZzwCeCccdz39jnTNUj2FRWpBBGqg+g+jeaoG6YWRyXjDc8hfT/Pg780TMJ9kyq46sWMr1GmkP6+ZuefGWeap0qcPvBiIcmwH1TFPpCZ6o2+HdKpCLhV/3cR91BjX24JGSl+2eLWnU90SR6oNwO6AbD4EgKveJeyKqRd3AXD3VJlpIT3kNJzCaqcaaLT7XZuj39YsAC6eEHWewQMbCYR+s7ZKT6Xk0Cu3+Wy+g; 4:pTEyDQw6mqy/SwPjTz1Kyf0+B/eEsmtmzDEqpt026a61w+CjCnUWRhf7qW/BcGnukVhTxjXSAYp9rjsInvTb0MAWwP4SNEOU5qktFZt69Q6MQsoBrzAv6sQLqhCXe0abKMSdhi0d98ZrjGhM6ib+KFxqFGF8T5QIaLE/g17PyXWcJSr3XVngl2Y1P3va/2WR4P6wY7tGjf2g2LRbvZEn3rue4SH0SFvVurIsXenyf2uQzAbWjw2HfFgyTj6EdT2adnzwZ2M+jluqu9D8GtKTsd49A+STQIXxyiMceiRWAouiifS45KiagtEIYnRyiBIb2b8+pMs+u8o1AdNsq1r3KJJfvZPiH5oLinOk6NNe30UKA6rfqju4sMAPptfacMN6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(767451399110)(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3231101)(2400082)(944501161)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:BN6PR1201MB0067; BCL:0; PCL:0; RULEID:; SRVR:BN6PR1201MB0067; X-Forefront-PRVS: 0581B5AB35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(376002)(366004)(39380400002)(396003)(189003)(199004)(316002)(6486002)(68736007)(105586002)(54906003)(478600001)(7736002)(5660300001)(1076002)(39060400002)(72206003)(305945005)(16526019)(50226002)(186003)(8936002)(26005)(53416004)(97736004)(53936002)(8676002)(1857600001)(81166006)(81156014)(86362001)(66066001)(2906002)(25786009)(386003)(59450400001)(7696005)(36756003)(52116002)(23676004)(6666003)(6916009)(6116002)(106356001)(3846002)(47776003)(50466002)(2870700001)(2361001)(4326008)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0067; H:fx8.amd.com; 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?MTtCTjZQUjEyMDFNQjAwNjc7MjM6ci9MZjJFVldsQnJlc3c2cGRlWks4R2p3?= =?utf-8?B?Ky9hellJVVBWVmo5cThYMkRYY3YvZ2t0VjViSXlaVVlKR0NKdGZjVjM5aXJp?= =?utf-8?B?dUJRdkNhQkd2RFVNL0NZWWV4a2hRSkdxUkhqM3VBalFpcEtSendNV0hXUzZK?= =?utf-8?B?cFIzTHRqTlBUUEVleVVsay9kaEd3ZDdtaldxOW5QSlA3VlZ4MlgrRGxsdmE4?= =?utf-8?B?SnM1dE0vRTRiVzlSOVJwbnlxeVRlbE5CUGhJbkwxVm9XY241a0NTeTVPcThK?= =?utf-8?B?MUZYaEw0NGtCRU9wNTFMNVBTMVZueC9pemJUVGpwb09zdm1oRVI4bHZlelhp?= =?utf-8?B?MW9TVVdONWtjN1BGaUxlRGlPT3IrdkZvVXNBYkJtOGxwc0F5R3IwTXZKVEVO?= =?utf-8?B?WEwybkRMR25ORldnZWpYUk03M1NHd05tTkJiejh0RThla0ZQdTIxYkQ0eTdo?= =?utf-8?B?Z0FwT0hGcUtHUkx5Ym5hLzMzdDBNLzc0RzlsUmVFVUJ2R1h5VGhRd3VrSjZK?= =?utf-8?B?NUFCeUlnVmtmcTkz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J4fJ3FSL1gs/LejrXmMlMbBt/AO6pO9dIBPHmDKX/HCXikYDgPrZZSXxKWTzk9kw/y8GcYM0ML7kZQW0nOpMgT8pp5djYEkCqbSkML0QwH3lRl3ZKP2JbJn+q8t70SSXz8BiGMfAOMbInG7M/cuCq85k+oGLXC/MMrahGPgOmNb0yvR2vzlJ4OXl8nMz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0067; 20:/96UtZvobXB9eNQZ8dfKXhFs7mZe1fekeQJdaaeEqQIOrUPZsw6ePzgx8AFSZSNJTtDPFxK1r77+zfWAZh4WqK0WRO5pFF+lQKYjuMte0q87g4COJyCe7B8jZMZF00yMMjnR6BZbIY+53zAXBh3pg2r7RpqAAsrfphYZC4htyT0PFbiHCoRwEh1gFzjB8jJYcH1GaNABUb/tIrglMNDzmtThQaiIQwefzwHrKUcc3hXDkbRjzvQJEzhG2PJj/9gI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2018 15:18:46.2128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e8dbf23-d42c-4ec1-fd92-08d5722be96f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0067 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 , =?UTF-8?q?Christian=20K=C3=B6nig?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König 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