From patchwork Tue Apr 16 21:40:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andres Rodriguez X-Patchwork-Id: 10904211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02A3E14DB for ; Tue, 16 Apr 2019 21:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E34AB289E8 for ; Tue, 16 Apr 2019 21:41:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1678289F8; Tue, 16 Apr 2019 21:41:00 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 6A413289F0 for ; Tue, 16 Apr 2019 21:41:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1BF3789D30; Tue, 16 Apr 2019 21:40:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45BF389D30 for ; Tue, 16 Apr 2019 21:40:56 +0000 (UTC) Received: by mail-io1-xd43.google.com with SMTP id v10so18910840iom.8 for ; Tue, 16 Apr 2019 14:40:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=U5AHxbmpyWYS8z9WhanPsdGra+atXNzCnP48uk7Pd7c=; b=Pi+0CGh3FuOhSShR78XZsrMjO08jtChzQluU8sQkU0A48bC6fluYfiK+mr/I2cvkME Hq49Ua+C9kIblJumGo5r3g13q4qDUd/2R4g+wulGQZVcHh/X2kAu8fY0GfIQswDixSnO pLMfUlWP5nHRmaGvnxHHY9ngws+ObYpGlCr+l7/iOIXEtVY36TBnIrhW4nW0HWvMbmHg qtw93fnhGtQ7k/R9Fqxydu7+Uiu+xwQVE/18lSl2bhWFFta5Ln1+TteqBwv0qA/LUZay X1HqeMOvfqdIMBAZ63mr1tXzMXCZ+Ftd78E8J4G89dg+KohpgaHjd2BKT2r7NWkuhyvp yFNA== X-Gm-Message-State: APjAAAXy8W4NUU9YQLLmiNAXyPzaN/yTmLU8YKnXgpU0RYMNH/d2VnmS 8FfByA5Vjssyf075pYcv/RExom36FIY= X-Google-Smtp-Source: APXvYqw2jB8+KP7Vqclhi8Sgw0tR2OYoo8TpZ/Fo8y+DA3w3ByiZD05pHW1Qq/nW60rg9LDmZA6Lmg== X-Received: by 2002:a6b:6019:: with SMTP id r25mr49499690iog.30.1555450855216; Tue, 16 Apr 2019 14:40:55 -0700 (PDT) Received: from andres-vr.valvesoftware.com (135-23-65-40.cpe.pppoe.ca. [135.23.65.40]) by smtp.gmail.com with ESMTPSA id c25sm18809067ioa.75.2019.04.16.14.40.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 14:40:54 -0700 (PDT) From: Andres Rodriguez To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: fix drm leases being broken on radv Date: Tue, 16 Apr 2019 17:40:46 -0400 Message-Id: <20190416214046.3551-1-andresx7@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=U5AHxbmpyWYS8z9WhanPsdGra+atXNzCnP48uk7Pd7c=; b=HiF7Q8LecD0W+VWVupJWOThd8bERWPxoxDfu7iCm9MS7tD3+RiwhKU3aNeT7HM1OKx KrIQbXXtryrTTH36NDrGAiGYPtd0j5mImPq8rdnLigh3eNq/X2zBgvloEsB8mL7rvJTk Ha2WsQXZJyzEGziiNw0nZuw2gWJPTVG1CUt5sW3DAZxcd77b61E+UdEFUiZuhOgqOWhJ DFySlX8g3lwv9rSSgDmtEsapQ8AjNgJet66OgoKyux/PoSTmX4jMLNWLKTzAe/hZs4A+ kNS0eXVfBjxojDBpj5PD+62FHc9e6G7n+laI4s8ORjOHsut8X96oU3xwdeS4gQxotk8M naBw== 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: Keith Packard , David Airlie , Andres Rodriguez , Alex Deucher , Emil Velikov Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP After a recent commit, access to the DRM_AUTH ioctls become more permissive. This resulted in a buggy check for drm_master capabilities inside radv stop working. This commit adds a backwards compatibility workaround so that the radv drm_master check keeps working as previously expected. This fixes SteamVR and other drm lease based apps being broken since v5.1-rc1 From the usermode side, radv will also be fixed to properly test for master capabilities: https://gitlab.freedesktop.org/mesa/mesa/merge_requests/669 Fixes: 8059add0478e ("drm: allow render capable master with DRM_AUTH ioctls") Signed-off-by: Andres Rodriguez Cc: Daniel Vetter Cc: David Airlie Cc: Emil Velikov Cc: Alex Deucher Cc: Keith Packard Reviewed-by: Keith Packard Reviewed-by: Daniel Vetter Acked-by: Emil Velikov --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 8d0d7f3dd5fb..e67bfee8d411 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -409,6 +409,9 @@ struct amdgpu_fpriv { struct mutex bo_list_lock; struct idr bo_list_handles; struct amdgpu_ctx_mgr ctx_mgr; + + /* Part of a backwards compatibility hack */ + bool is_first_ioctl; }; int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 7419ea8a388b..cd438afa7092 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -1128,6 +1128,7 @@ long amdgpu_drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct drm_file *file_priv = filp->private_data; + struct amdgpu_fpriv *fpriv = file_priv->driver_priv; struct drm_device *dev; long ret; dev = file_priv->minor->dev; @@ -1136,6 +1137,7 @@ long amdgpu_drm_ioctl(struct file *filp, return ret; ret = drm_ioctl(filp, cmd, arg); + fpriv->is_first_ioctl = false; pm_runtime_mark_last_busy(dev->dev); pm_runtime_put_autosuspend(dev->dev); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index e860412043bb..00c0a2fb2a69 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -455,6 +455,7 @@ static int amdgpu_hw_ip_info(struct amdgpu_device *adev, static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { struct amdgpu_device *adev = dev->dev_private; + struct amdgpu_fpriv *fpriv = filp->driver_priv; struct drm_amdgpu_info *info = data; struct amdgpu_mode_info *minfo = &adev->mode_info; void __user *out = (void __user *)(uintptr_t)info->return_pointer; @@ -470,6 +471,26 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file switch (info->query) { case AMDGPU_INFO_ACCEL_WORKING: + /* HACK: radv has a fragile open-coded check for drm master + * The pattern for the call is: + * open(DRM_NODE_PRIMARY) + * drmModeCommandWrite( query=AMDGPU_INFO_ACCEL_WORKING ) + * + * After commit 8059add04 this check stopped working due to + * operations on a primary node from non-master clients becoming + * more permissive. + * + * This backwards compatibility hack targets the calling pattern + * above to fail radv from thinking it has master access to the + * display system ( without reverting 8059add04 ). + * + * Users of libdrm will not be affected as some other ioctls are + * performed between open() and the AMDGPU_INFO_ACCEL_WORKING + * query. + */ + if (fpriv->is_first_ioctl && !filp->is_master) + return -EACCES; + ui32 = adev->accel_working; return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; case AMDGPU_INFO_CRTC_FROM_ID: @@ -987,6 +1008,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) goto error_vm; } + fpriv->is_first_ioctl = true; mutex_init(&fpriv->bo_list_lock); idr_init(&fpriv->bo_list_handles);