From patchwork Mon Feb 5 02:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10199821 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 838E26056F for ; Mon, 5 Feb 2018 02:56:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6792926E7B for ; Mon, 5 Feb 2018 02:56:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AC9227CF3; Mon, 5 Feb 2018 02:56:22 +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 D944626E7B for ; Mon, 5 Feb 2018 02:56:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 82BAC6E248; Mon, 5 Feb 2018 02:56:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0065.outbound.protection.outlook.com [104.47.32.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id D63F76E248; Mon, 5 Feb 2018 02:56:18 +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=yz1CqjWOVQnArliw+2bqQmxGhXkQ5ZvdicVHcNcZ6IE=; b=SQTBqScoa/qm8dNio99AQcfBNMnrgXrwdTbtJvbQwJ9pgwmx/F8drvVjaDBryFFk9lKEo75eZ85cIVg81QboEEa7dv8svxXXNC7NWG52sskzHdsHRaauuCwmeRd9IgsV1sHXE7stuqX03KyljTI+4A0MWFyehxDVCQsbODYYVNI= Received: from MWHPR1201MB0127.namprd12.prod.outlook.com (10.174.98.142) by MWHPR1201MB0016.namprd12.prod.outlook.com (10.172.95.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Mon, 5 Feb 2018 02:56:16 +0000 Received: from MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) by MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) with mapi id 15.20.0464.015; Mon, 5 Feb 2018 02:56:16 +0000 From: "He, Roger" To: =?utf-8?B?Q2hyaXN0aWFuIEvDtm5pZw==?= , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" Subject: RE: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem Thread-Topic: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem Thread-Index: AQHTnFlxdfTp5HiE80y53vx1A5gUL6OVIEUg Date: Mon, 5 Feb 2018 02:56:16 +0000 Message-ID: References: <20180202190948.2654-1-christian.koenig@amd.com> <20180202190948.2654-5-christian.koenig@amd.com> In-Reply-To: <20180202190948.2654-5-christian.koenig@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hongbo.He@amd.com; x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR1201MB0016; 7:N7aJK3LIpB3M8GJmteqSIVVVw4/DFtdm/U79oYzdQMGc1XXIBRoKnI6KlBSvY6iFALD4IU5Rr3L+haUhjuqHXm4SK9haiXseWoAm52KC7oHMqTVTfR7oRBStnlS1rBomjA/CUJ0Ig0U8NOpxAgKQW+kgOe2a9ZYSofeXw/HwPm/qEmknVCqG++riamQUA6V56sk9VcvHOsazXFEtOsV4hqs2iMwNZStwhnEKqdwH1+oedqXyUNepgKUJGdw9B1NG; 20:AE4XIzG7QEpJxDat//EZAjN30B7+1It5ORb4P0aEkrnvtAudLmsxRcHHEED/x0M5LtzlN6Iv1gWdnj5CEJUqDTd/E4Iedgymd7EXxYdmJpovjXziyOnsZ82d6OkVokQLSEDwxnz/+pnetxFmVTUQDMnlbuAU4qaCCXR0FcelYIF0AkaBOp/ZFrBmqsBne7hnCamVq56Sgxa9RZVu64QP4/KHx/6poArdwRtfiSm4shuVdPhyyJWJfFXhAPprNzaF x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 41ae0897-4e60-4c71-94b2-08d56c4406b6 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:MWHPR1201MB0016; x-ms-traffictypediagnostic: MWHPR1201MB0016: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(788757137089)(217544274631240); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231101)(2400082)(944501161)(3002001)(6055026)(6041288)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:MWHPR1201MB0016; BCL:0; PCL:0; RULEID:; SRVR:MWHPR1201MB0016; x-forefront-prvs: 0574D4712B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(366004)(39860400002)(396003)(376002)(346002)(189003)(199004)(13464003)(55016002)(6306002)(7696005)(7736002)(53936002)(9686003)(305945005)(26005)(66066001)(316002)(186003)(77096007)(6436002)(6116002)(3846002)(68736007)(3280700002)(2501003)(6246003)(3660700001)(102836004)(5660300001)(2950100002)(33656002)(229853002)(81166006)(8676002)(81156014)(97736004)(106356001)(86362001)(59450400001)(2900100001)(2201001)(6506007)(478600001)(76176011)(105586002)(2906002)(8936002)(72206003)(99286004)(74316002)(14454004)(39060400002)(25786009)(53546011)(110136005)(966005); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0016; H:MWHPR1201MB0127.namprd12.prod.outlook.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-antispam-message-info: 0UcwRI8hzIHQHX9PdTZhdgkOG+WNS2KOiXPaOqrW39m+jjmbNkyhm1C9etIkE1WP1UoeqNBVaCiIGpzVH5THhA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41ae0897-4e60-4c71-94b2-08d56c4406b6 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Feb 2018 02:56:16.6810 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0016 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Patch1 & 2 & 4, Reviewed-by: Roger He Patch 5: Acked-by: Roger He -----Original Message----- From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Christian K?nig Sent: Saturday, February 03, 2018 3:10 AM To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem This allows access to pages allocated through the driver with optional IOMMU mapping. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 22 deletions(-) _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 648c449aaa79..795ceaeb82d5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1929,38 +1929,51 @@ 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; - dom = iommu_get_domain_for_dev(adev->dev); - if (dom) - phys = iommu_iova_to_phys(dom, *pos); - else - phys = *pos; + addr = dom ? iommu_iova_to_phys(dom, addr) : addr; - r = copy_to_user(buf, &phys, 8); - if (r) - return -EFAULT; + 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; - return 8; + 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, .llseek = default_llseek }; @@ -1973,7 +1986,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 -- 2.14.1