From patchwork Fri Jul 1 18:24:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinclair Yeh X-Patchwork-Id: 9210331 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 2B49560752 for ; Fri, 1 Jul 2016 18:25:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F58B286B6 for ; Fri, 1 Jul 2016 18:25:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12A70286CF; Fri, 1 Jul 2016 18:25:13 +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=BAD_ENC_HEADER,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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 835BF286B6 for ; Fri, 1 Jul 2016 18:25:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBF666E1E0; Fri, 1 Jul 2016 18:25:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EX13-EDG-OU-001.vmware.com (ex13-edg-ou-001.vmware.com [208.91.0.189]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4D5A26E1E0 for ; Fri, 1 Jul 2016 18:25:10 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Fri, 1 Jul 2016 11:24:36 -0700 Received: from EX13-CAS-009.vmware.com (ex13-cas-009.vmware.com [10.113.191.61]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id E1F6BB0596; Fri, 1 Jul 2016 11:24:46 -0700 (PDT) Received: from EX13-MBX-032.vmware.com (10.113.191.72) by EX13-MBX-030.vmware.com (10.113.191.50) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Fri, 1 Jul 2016 11:24:46 -0700 Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-032.vmware.com (10.113.191.72) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Fri, 1 Jul 2016 11:24:46 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-003.vmware.com (10.113.191.53) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Fri, 1 Jul 2016 11:24:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=1jTh8dzuik8X0sWThGoHU1CUJTg4Uq5XemRHWoMdtVg=; b=XPaACT39a62XQumupVjSwq7vGDdvAgVdKHPgjEkc49jgQzYigboEd7p/YiQ8vnU+gGlmyhXscoinJSIxEJH/Jn/jRWpgXjdjMddlZKXG4oxpoG9qpYrtXnm+H6DcZxLYpP2YPR5+DiS14o4sc6dSaY2E+xTBZuH+fPe+Rux8x30= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=syeh@vmware.com; Received: from promb-2n-dhcp105.eng.vmware.com (208.91.1.34) by CO2PR05MB698.namprd05.prod.outlook.com (10.141.229.13) with Microsoft SMTP Server (TLS) id 15.1.523.12; Fri, 1 Jul 2016 18:24:36 +0000 From: To: Subject: [PATCH 2/3] drm/vmwgfx: Check pin count before attempting to move a buffer Date: Fri, 1 Jul 2016 11:24:09 -0700 Message-ID: <1467397450-3648-2-git-send-email-syeh@vmware.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1467397450-3648-1-git-send-email-syeh@vmware.com> References: <1467397450-3648-1-git-send-email-syeh@vmware.com> MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CY1PR1101CA0035.namprd11.prod.outlook.com (10.169.17.45) To CO2PR05MB698.namprd05.prod.outlook.com (10.141.229.13) X-MS-Office365-Filtering-Correlation-Id: 176de48e-e860-40f2-0b45-08d3a1dcf517 X-Microsoft-Exchange-Diagnostics: 1; CO2PR05MB698; 2:i1u+bs1Zd1cee+SztFJRKldgYhRCe0kVe8VYp6ScqCygdS6nJDel42ZgqtxFhWT4rSkqJe6t8S3eChEva64kL2HbZ47+5fr2/zs6HLVzlcVLdspKen1dRq64hh5MaUyUt8SgdJYF0wG2rJhRRo0/c14EcLFaeetMhJqt+SwB1HFkSv6e+7GHTQacBII4lklo; 3:LXj9W9wvVAevgXXY3diMSQxU7dB17zvx9XYKqDBUsrvZLQp/nJSYGEfl5np3A2HDqbsREeP/St3hW614oegZJmycmQk3KSnS6/7aYZpczYJc23OWqy1QqlzV5+YqtpJY; 25:5fSI4gB4tH7rtxDsRYzdmdGZdV7StkX1UAY0YTT/LydbnaOrCYAtZqs3r9vGhlXtrn03CEdQFRZ0GorVE/BOpQYsiebAohFXLA4xjqF1pav9y8/Yupjg3GFdofr+q+BRfxtxKoHcgMXkW1hkLb11Spl0Z2GqldcFONtzfQ2s/HYkd4iSDm4uXab65v2iLaoDs19HWwH+QoI69VAVXFv0EFQOU1oubxteHiYYpeF3jsNJNSrNGL7BK3lWJGikc3D2AWL1rkO9UDOp1tJgYtGJK553hEcLTr2YcEtdvs21tj9RX9Uon8efIWK7ac2JiumQsqohkVAEFeQJ1vgwVdIGCaBNJO4gO44MgFGq3PXxa4EG//R/iAH6uFi87gXS5aVM3bpEo/cAeIffH3naIhhFNXiVXbF8TOaeR4HxRpxst9s= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR05MB698; X-Microsoft-Exchange-Diagnostics: 1; CO2PR05MB698; 20:YHsUhqTl5tQI2RhNxlLTRicbDn1/uFkofT6FHE9gzABS8ONUEGGDtJQzd+g5SmkqxDLvjso31Qv800clp44LWMxtnrELaNr6ij0KYp83ZVhqXGHtvrH6T8Rumwdeu7CwY86gotY8m1mUO7rUftxi+M3WjX7EnaM41hbKDifzSB7x8Eg9rpxU3Djr73krxogMXRTvFZKQSQjpEtKCz4XTcad9vEFeXCiQ5bOZyO/eE+QrBwV+TIXzF5URirOWCYCV; 4:qSCu03LwofM6qIMW4oWXL/VQqD4YqH6yQHk8NlpifpWRjINsC8wynI9ADSfelx7VMOA924pcJvTe04tfrwM37NtCZ0Dl0CpnLf2mJKn3L8AalD0hqCjjK3Svj+9NbFfUYplfWNxXwfKqeA9mUSrkqNURo53BwtN8v09bJNmwVFDOsL9dQYwXDK0oz7tdEhCm7/+R1PXv8/5By7i09RdNEUeNXO2nlXYkYk6/AYeyMj+NFXBL4aEjfnb6XrsuAWxzaZUiw/b0lon2ZcRwfpw5fkrCBCYAs5nxG2i4DG033d284gQZUspYTNeuGxRRLtcX/HIR/BNf/uk51tYJeyjVtop2qjnBpKaylrYGHBQlvMXfddbLe8NEGEwV+jDjfCptfm+JJXTAox0/yOWMcUwV/Q5Th0kSIzf/iyDg3xQo5xQTRJ4PJMEWwQG3cQEDLdCl X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150)(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:CO2PR05MB698; BCL:0; PCL:0; RULEID:; SRVR:CO2PR05MB698; X-Forefront-PRVS: 0990C54589 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(2950100001)(8676002)(305945005)(86152002)(66066001)(81156014)(77096005)(7736002)(106356001)(81166006)(586003)(101416001)(3846002)(50466002)(42186005)(2876002)(4326007)(2906002)(86362001)(105586002)(97736004)(92566002)(19580395003)(19580405001)(50226002)(189998001)(110136002)(2351001)(5003940100001)(7846002)(47776003)(48376002)(76176999)(6116002)(36756003)(50986999)(68736007)(33646002)(229853001)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR05MB698; H:promb-2n-dhcp105.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (EX13-EDG-OU-001.vmware.com: syeh@vmware.com does not designate permitted sender hosts) Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR05MB698; 23:HJCgyOmeigHl3oplRLJLC+QTXozixtgUz/sWd0im8b?= =?us-ascii?Q?FpflEhbSO1ci7cFAEPAbIBmj73URZnmuaxRK2PEcq5VklSMBuNf+6FGviOR9?= =?us-ascii?Q?qP9MYK1GYjnPoHmxddf9zhYeyxnoKBUqQGakYUJ+tVA8BrX5BtHOd5NQYOf9?= =?us-ascii?Q?KyvsAE8aecpNtBmB8On6Uwl/eEVsSqfOU1GPAH1aR/9jHz0z0c37slM5VdTO?= =?us-ascii?Q?25SNrJkZKiuh78oqREb9DyUG+TRA3Ijl3VE0aTJOcbhh+atrX8QvDXG1D7sz?= =?us-ascii?Q?nV4Fbalj3QmER+MB6A1DP2/89MLQDY69fTd/wCjXz7ftpvLHD2Vlsrvbit/H?= =?us-ascii?Q?CEDxoz77T/Xga2PWkQ4CloxhlfovOO01lGxphcrz8K7ceeCqQNmDCT14hb/x?= =?us-ascii?Q?t8axO/5xApfJ//R5rNoSAN1IqUhMfKAxgdohKhXPPVd7PLdDVyrmUZPZRKtB?= =?us-ascii?Q?jyWU9YvvLVytStZwZD39CcBKgWkMtX25BytH/WX+O/swaqXI0PF8IgnCLQtM?= =?us-ascii?Q?HFsXyDFDdp9FHlHu4s6bmM6a4pEgZs+amfvFJ7//iDNZXwabpocWv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j6MjfCnRlJEwhuGE1c70e7LUmIm8lNtYXCC9pn5OQNW8RjFttLcxXeg8POyWbBsG1NJyPHDPJHBSPP71CT1qgWW63HQllQmO3L1bzbIfeqFixmuDntSZ+0KqCJdLZBKSR3RTxs27oYmOIH3sA1wrQ==; 24:tLNnoAihfDpswH3hSWmLxPlaPjynf4htPajRj0Z/898lzb8VfYBn/mTjAX0R9cQ02ASp7Q9zqTjfn/Kg5bNGDH5wLHhOwIUw79zZEoOHYDs=; 7:q7QN/CJezJz94MvF0j/ha5PrWaQ3NjtRZxTkFV1pnSndjKilD9cz3SEr35RfGGyYkXGWv6Ib6751cx85CC7BAdDIkIcvyyZvDj1lTgdSIZptofZ0zWul9B4s7PYwg68HFhgPK5mmL6LBw/qKvAmgIP614nwD8Xv6ajjrSzvCin5JIn55tgJomqrkn96ZcUsbuy6FGd5B0MzikQxdVPXT2gz949/zSM+AvHE1jO5LYzeX6GUJ7TE/Ez5qsx3tljEu71URTqxR7AREC7OR0GsGjg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR05MB698; 20:Tu/XkqzZWWOn61pawOsCb/IxEDBOvJaArd0hIKrlQsO6mxSNQRsTEugcK92DA/3Gxh+0vEBMINrFR7TPp1OGrBx42q9EmJDExIbZi/jZli1Pqu6aZXvSRsw6UVHkPETUoOIHLQWzO+X09Q4AZ2ewwd+GY2dvUNRT1BCPrrvmB18= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2016 18:24:36.0992 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR05MB698 Cc: stable@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 From: Sinclair Yeh In certain scenarios, e.g. when fbdev is enabled, we can get into a situation where a vmw_framebuffer_pin() is called on a buffer that is already pinned. When this happens, ttm_bo_validate() will unintentially remove the TTM_PL_FLAG_NO_EVICT flag, thus unpinning it, and leaving no way to actually pin the buffer again. To prevent this, if a buffer is already pinned, then instead of calling ttm_bo_validate(), just make sure the proposed placement is compatible with the existing placement. Signed-off-by: Sinclair Yeh Reviewed-by: Thomas Hellstrom Cc: --- This is the 2nd patch in a 3-patch series to fix a console black screen issue on Ubuntu 16.04 server. This fixes a BUG_ON() condition where a pinned buffer gets accidentally put onto the LRU list. --- drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c index 9b078a4..0cd8890 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c @@ -49,6 +49,7 @@ int vmw_dmabuf_pin_in_placement(struct vmw_private *dev_priv, { struct ttm_buffer_object *bo = &buf->base; int ret; + uint32_t new_flags; ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); if (unlikely(ret != 0)) @@ -60,7 +61,12 @@ int vmw_dmabuf_pin_in_placement(struct vmw_private *dev_priv, if (unlikely(ret != 0)) goto err; - ret = ttm_bo_validate(bo, placement, interruptible, false); + if (buf->pin_count > 0) + ret = ttm_bo_mem_compat(placement, &bo->mem, + &new_flags) == true ? 0 : -EINVAL; + else + ret = ttm_bo_validate(bo, placement, interruptible, false); + if (!ret) vmw_bo_pin_reserved(buf, true); @@ -91,6 +97,7 @@ int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, { struct ttm_buffer_object *bo = &buf->base; int ret; + uint32_t new_flags; ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); if (unlikely(ret != 0)) @@ -102,6 +109,12 @@ int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, if (unlikely(ret != 0)) goto err; + if (buf->pin_count > 0) { + ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, &bo->mem, + &new_flags) == true ? 0 : -EINVAL; + goto out_unreserve; + } + ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, interruptible, false); if (likely(ret == 0) || ret == -ERESTARTSYS) @@ -161,6 +174,7 @@ int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *dev_priv, struct ttm_placement placement; struct ttm_place place; int ret = 0; + uint32_t new_flags; place = vmw_vram_placement.placement[0]; place.lpfn = bo->num_pages; @@ -185,10 +199,15 @@ int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *dev_priv, */ if (bo->mem.mem_type == TTM_PL_VRAM && bo->mem.start < bo->num_pages && - bo->mem.start > 0) + bo->mem.start > 0 && + buf->pin_count == 0) (void) ttm_bo_validate(bo, &vmw_sys_placement, false, false); - ret = ttm_bo_validate(bo, &placement, interruptible, false); + if (buf->pin_count > 0) + ret = ttm_bo_mem_compat(&placement, &bo->mem, + &new_flags) == true ? 0 : -EINVAL; + else + ret = ttm_bo_validate(bo, &placement, interruptible, false); /* For some reason we didn't end up at the start of vram */ WARN_ON(ret == 0 && bo->offset != 0);