From patchwork Fri Feb 9 17:27:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 10209573 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 8B00A60236 for ; Fri, 9 Feb 2018 17:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77F5B2985D for ; Fri, 9 Feb 2018 17:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6369C298C3; Fri, 9 Feb 2018 17:28:10 +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 C2CC02985D for ; Fri, 9 Feb 2018 17:28:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1876E6E8FF; Fri, 9 Feb 2018 17:28:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0076.outbound.protection.outlook.com [104.47.34.76]) by gabe.freedesktop.org (Postfix) with ESMTPS id 312C96E8FE; Fri, 9 Feb 2018 17:28:03 +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=sAQbg+6zwbH7hXCAmSeBtDi/qSCTKsGEZUp9XlhmGGo=; b=AyiTkQZgyIEGYfhNqvI0PoUry2ntrVISGkJ/JZiX6OShYYaTcUY6tNQsAPChJOEiZeOopR4apKP7uIEkOBSlKK+y4FFvaypnEaA14ROzIpM9Uf7F1LfaaFZgG187JNnhEcjQkThLEr2geXcStv3bcwFppy/Ir2MfF9Xnoc5W9E8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tom.StDenis@amd.com; Received: from fx8.amd.com (165.204.55.251) by DM5PR1201MB0073.namprd12.prod.outlook.com (10.174.106.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Fri, 9 Feb 2018 17:28:01 +0000 From: Tom St Denis To: amd-gfx@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: replace iova debugfs file with iomem (v2) Date: Fri, 9 Feb 2018 12:27:50 -0500 Message-Id: <20180209172750.15675-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: MWHPR22CA0012.namprd22.prod.outlook.com (10.172.163.150) To DM5PR1201MB0073.namprd12.prod.outlook.com (10.174.106.15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fe461cc3-51bb-442e-d226-08d56fe278d5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:DM5PR1201MB0073; X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0073; 3:TzkVG9skWlxoOMSZ2bTa8oBX9TnUt3mS6v/hhGmEnGUgVxNw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qnhe9AQrZJYPJiXv1LvocsHCxNQkChYR0d/tuokiJ1tvdPuKU6tkKcWvXwHjGVLj/Hl478IuBcHYEVUE5gsPIgZNibM8vdQ9dz1ra6TWIvTVjPgdXSddz+z/UMgTEVdgr8ktABMFEM9sXkpjnx45wzISIDJ/OxiSbSDs2OXaho6QXevZKlo+nAO7vUSgSnxl+PsqEXwCWt+GG/xcFFpEwk5l2MxHADtsWRkkF9CobDyOckDyMXI58SJGzAUPaNZOtvjrE9UVAqs3Sk6s8n/x7VzqbBv+ypAyGdjdr4qRod02fwij; 4:tjUbSHrEtKtI8Dc6L+f97fKUr68RBvxVfgq4j0cEF5pfWkIie0csA5N0OKmt7w0ISh1YFJHiF82BR8s/ppponlfzJh133oJtSukYIlH+zpJQOVZYgagq3C2usDP66jXJGt4Drs9K1c01SGZoMoqB4T7BDN9LFfN246/LxtNsekd5728HpA4zJYsxwpKj6mB+kxf1u8fKZ5K7QLOEmOefz7N9vUjmqqNP/urNOmLGH+5j3yRpQ9NotgPs7zYncw+2bhFMeoj5ZqeHqSbOYJn47hRa6/nb3Phb7ppF13ZXZOJA1pSKA/yBtRIRVWrugzUOw6eJJ2W0+aS2+N7PvQGZi2lAsLyBuGfjhpQE+y+1yPiT3W6pYbic1LDEnPHTjYio 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)(93006095)(93001095)(3231101)(2400082)(944501161)(10201501046)(3002001)(6055026)(6041288)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:DM5PR1201MB0073; BCL:0; PCL:0; RULEID:; SRVR:DM5PR1201MB0073; X-Forefront-PRVS: 057859F9C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(366004)(376002)(346002)(396003)(39860400002)(189003)(199004)(2361001)(72206003)(36756003)(66066001)(105586002)(7736002)(2351001)(8676002)(305945005)(106356001)(6916009)(4326008)(81166006)(81156014)(23676004)(86362001)(8936002)(68736007)(52116002)(7696005)(53416004)(59450400001)(6116002)(3846002)(6666003)(50226002)(1076002)(2906002)(50466002)(5660300001)(2870700001)(386003)(25786009)(39060400002)(478600001)(47776003)(1857600001)(316002)(16526019)(97736004)(26005)(53936002)(54906003)(186003)(6486002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR1201MB0073; 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?MTtETTVQUjEyMDFNQjAwNzM7MjM6QkhtNWYzWnl6d0doNElBQlhZam93dTZG?= =?utf-8?B?OVJITSs3NkNsZ3BDK3hLaEdDMWRMTG1QSGVGNU9RN3RCbnZueDhqdHpRb0ln?= =?utf-8?B?VkMyTnQxUzJCY1ZTRFRKNjdJVkZvUDVIbFhuVjB6a1BoUmtZNDVQVmNtb1Rm?= =?utf-8?B?dGtHL09SbStqR1FuZmNDMWRoUGppQXI4ZzlqN0dWZ0NmSThyNHRtazZrMzJk?= =?utf-8?B?akgzem0vcldCejIvMnBOcWZESFNXeVVTU1pPelA2UElpMnJ5akNBa0VCeTJB?= =?utf-8?B?UTJpQVErTi92QzQxZ25wc3BFQjZicGExS0pOR2V2L0dVNFlXRVRZdThzQ2ti?= =?utf-8?B?SmdRUFV5MHhQUHZYNnNnQWs5NENXK25aWFVFcUp4dHJWSVRkam5EUzJmZXl4?= =?utf-8?B?TDlLeUY3WGpPRm1INWp4RzYzb3NWVkpjOFZUb016U01zWTZYVEthUnpWcjBU?= =?utf-8?B?YXJVQ2hyMjl5ZjdsMTNodFV2c3Y2TTVoQm52TkdzWTFVbUNGaEhwZTdncU1F?= =?utf-8?B?b2I1eUp4d1pORDg2YVpL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XRgadkWNCKdmFfisQSwsr+dBuwXMql63OgNQDb6CUXfL44ft8y9NzYd6c4iDWd0cszruLl2cFb9QXQQ1N4Bh0LACZQIyN4TaZHSuTOlzagGwmrPza1EcmOnUyE4MkYKxFmG1YEDKVeYUXRpKwrN7I66H5B SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0073; 20:hmd49K0fzP1IWb7ZXytZ4KNjTGJMakowGggOJgpkwViN4xpxjJ0tRSzNBK8mbJJE/se5uJGiWrpkeKD8DXbpNB+xFgAqb5wnOUri4QEQgYMd9WqOsAEENGPKahaFw/+lv139/y8wAc8jG5m5DcXa4iZCg6v1mgv73cNA/uawzhwYkAD2itIjJS5qLzerhpleCSRZVgEaTJFP03Ckjr9FAQ3AA7pz5AhO1lSM6GpP+a7KsgTRBpWmITObNjKx0Bb0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2018 17:28:01.4145 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe461cc3-51bb-442e-d226-08d56fe278d5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0073 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 Original-by: Christian König Signed-off-by: Tom St Denis --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 110 ++++++++++++++++++++++++++------ 1 file changed, 89 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..d6c56b001a2c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1929,38 +1929,106 @@ 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); + if (ptr) { + r = copy_to_user(buf, ptr, bytes); + kunmap(p); + if (r) + return -EFAULT; + } else { + 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; + + addr = dom ? iommu_iova_to_phys(dom, addr) : addr; - return 8; + 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); + if (ptr) { + r = copy_from_user(ptr, buf, bytes); + kunmap(p); + if (r) + return -EFAULT; + } else { + 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 +2041,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