From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A0B0C432BE for ; Tue, 31 Aug 2021 07:25:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 306BE60E98 for ; Tue, 31 Aug 2021 07:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239949AbhHaH00 (ORCPT ); Tue, 31 Aug 2021 03:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239937AbhHaH0V (ORCPT ); Tue, 31 Aug 2021 03:26:21 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56FFDC06175F; Tue, 31 Aug 2021 00:25:26 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so1304337pjc.3; Tue, 31 Aug 2021 00:25:26 -0700 (PDT) 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=jxGI0ujHdl0N9GyGT2D3gCCB89vXr6ZHaDLYSvDAb0ZPJwcEXuX0JTOEampQTrFjnT R26DUsjxGUV2bNbq11XYxHiYUTV/uhTyuRaSRpftAlhLNY+PZYIOzUIExnRbFTF5Rnrq n7liC6CH5fsoUMhY6V6BKI3bZpqEPdZersNF3QuTd3yaxx6NO1Hx39aiwKeZuszeHUHv EX1SNZbPUwkQUarOBZmOPveUMleCesg2Zdur/+YXj4VfUkMN0TcSZ1kJJ4f1zDAZrLk+ MGLPPd80FAOi/Irzp/mnPQkGHNpv58wKjPpEb29iiC4LBAZch9D8LBW54yjgya0qO7Pd Djuw== 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=Nq1J7aCPJYkytedD7dmLcqXF7VPhOhwOtOQgx/HN6t8ceUDs/u1Db7pBxShYjA5bPW zAxtX1uyHuVfnxfguwELO6s5lP3KnEB4F8n/NrM3NTy/U+AbOVVLH35/kNJA50ckJGVD zb1d8IOWvBpk3SwifTDkXGBGg0aHkYIJkdsMqOPMBTeL6+h0H63jOkQoW0jMNXfs3fIb A0P0rGzohYLp2m0DZm0I3uwrEaxbzmVjuETCKlC0bkEz7OtE+UMTpkVCxks6dddXqiDk NQ6oAme+tlgU2kIrsLJVzVDJmiMXcz53wxC73XATbstn3d3Gl4yaztp+PQMseL8OK0oN H1HQ== X-Gm-Message-State: AOAM533B+kqgDieG/NDystbRUQQqhmDhcVHMD2QeT6+UJ6kguKE3ydXL HvIAdKzR2s7DEBs5Pl1uM4M= X-Google-Smtp-Source: ABdhPJyXMfL4c3g1dgTRJF/g+KwCIJImavM64F0XKUZcJVbQKi+4eCx2e6aSpaHBso5IjMGSKotQkA== X-Received: by 2002:a17:902:c101:b0:138:f219:b0a0 with SMTP id 1-20020a170902c10100b00138f219b0a0mr393100pli.1.1630394725844; Tue, 31 Aug 2021 00:25:25 -0700 (PDT) Received: from sanitydock.wifi-cloud.jp ([210.160.217.69]) by smtp.gmail.com with ESMTPSA id m11sm1720724pjn.2.2021.08.31.00.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 00:25:25 -0700 (PDT) From: Desmond Cheong Zhi Xi To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com Cc: Desmond Cheong Zhi Xi , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH v10 0/4] drm: update locking for modesetting Date: Tue, 31 Aug 2021 15:24:57 +0800 Message-Id: <20210831072501.184211-1-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry for the noise, rebasing on top of drm-misc-next. Please ignore the v9 series. Hi, I updated the patch set with some suggestions by Daniel Vetter, and dropped the patches after patch 4 so that we can stick the landing for avoiding races with modesetting rights before dealing with the tricky spinlock. Overall, this series fixes races with modesetting rights, and converts drm_device.master_mutex into master_rwsem. - Patch 1: Fix a potential null ptr dereference in drm_master_release - Patch 2: Convert master_mutex into rwsem (avoids creating a new lock) - Patch 3: Update global mutex locking in the ioctl handler (avoids deadlock when grabbing read lock on master_rwsem in drm_ioctl_kernel) - Patch 4: Plug races with drm modesetting rights v9 -> v10: - Rebase on top of drm-misc-next, caught by Intel-gfx CI v8 -> v9 (suggested by Daniel Vetter): - Drop patches 5-7 to handle it in another series - Add the appropriate Fixes: tag for the null ptr dereference fix (patch 1) - Create a locked_ioctl bool to clarify locking/unlocking patterns in the ioctl handler (patch 3) - Clarify the kernel doc for master_rwsem (patch 4) v7 -> v8: - Avoid calling drm_lease_held in drm_mode_setcrtc and drm_wait_vblank_ioctl, caught by Intel-gfx CI v6 -> v7: - Export __drm_mode_object_find for loadable modules, caught by the Intel-gfx CI v5 -> v6: - Fix recursive locking on master_rwsem, caught by the Intel-gfx CI v4 -> v5: - Avoid calling drm_file_get_master while holding on to the modeset mutex, caught by the Intel-gfx CI v3 -> v4 (suggested by Daniel Vetter): - Drop a patch that added an unnecessary master_lookup_lock in drm_master_release - Drop a patch that addressed a non-existent race in drm_is_current_master_locked - Remove fixes for non-existent null ptr dereferences - Protect drm_master.magic_map,unique{_len} with master_rwsem instead of master_lookup_lock - Drop the patch that moved master_lookup_lock into struct drm_device - Drop a patch to export task_work_add - Revert the check for the global mutex in the ioctl handler to use drm_core_check_feature instead of drm_dev_needs_global_mutex - Push down master_rwsem locking for selected ioctls to avoid lock hierarchy inversions, and to allow us to hold write locks on master_rwsem instead of flushing readers - Remove master_lookup_lock by replacing it with master_rwsem v2 -> v3: - Unexport drm_master_flush, as suggested by Daniel Vetter. - Merge master_mutex and master_rwsem, as suggested by Daniel Vetter. - Export task_work_add, reported by kernel test robot. - Make master_flush static, reported by kernel test robot. - Move master_lookup_lock into struct drm_device. - Add a missing lock on master_lookup_lock in drm_master_release. - Fix a potential race in drm_is_current_master_locked. - Fix potential null ptr dereferences in drm_{auth, ioctl}. - Protect magic_map,unique{_len} with master_lookup_lock. - Convert master_mutex into a rwsem. - Update global mutex locking in the ioctl handler. v1 -> v2 (suggested by Daniel Vetter): - Address an additional race when drm_open runs. - Switch from SRCU to rwsem to synchronise readers and writers. - Implement drm_master_flush with task_work so that flushes can be queued to run before returning to userspace without creating a new DRM_MASTER_FLUSH ioctl flag. Best wishes, Desmond Desmond Cheong Zhi Xi (4): drm: fix null ptr dereference in drm_master_release drm: convert drm_device.master_mutex into a rwsem drm: lock drm_global_mutex earlier in the ioctl handler drm: avoid races with modesetting rights drivers/gpu/drm/drm_auth.c | 39 ++++++++++++++++------------ drivers/gpu/drm/drm_debugfs.c | 4 +-- drivers/gpu/drm/drm_drv.c | 3 +-- drivers/gpu/drm/drm_file.c | 6 ++--- drivers/gpu/drm/drm_ioctl.c | 49 ++++++++++++++++++++++------------- drivers/gpu/drm/drm_lease.c | 35 +++++++++++++++++-------- include/drm/drm_auth.h | 6 ++--- include/drm/drm_device.h | 16 +++++++++--- include/drm/drm_file.h | 12 ++++----- 9 files changed, 104 insertions(+), 66 deletions(-) -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 051FAC4320E for ; Tue, 31 Aug 2021 07:25:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB71D60E98 for ; Tue, 31 Aug 2021 07:25:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BB71D60E98 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D60B8899DB; Tue, 31 Aug 2021 07:25:26 +0000 (UTC) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by gabe.freedesktop.org (Postfix) with ESMTPS id 695EE899DB; Tue, 31 Aug 2021 07:25:26 +0000 (UTC) Received: by mail-pl1-x632.google.com with SMTP id u1so6282636plq.5; Tue, 31 Aug 2021 00:25:26 -0700 (PDT) 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=jxGI0ujHdl0N9GyGT2D3gCCB89vXr6ZHaDLYSvDAb0ZPJwcEXuX0JTOEampQTrFjnT R26DUsjxGUV2bNbq11XYxHiYUTV/uhTyuRaSRpftAlhLNY+PZYIOzUIExnRbFTF5Rnrq n7liC6CH5fsoUMhY6V6BKI3bZpqEPdZersNF3QuTd3yaxx6NO1Hx39aiwKeZuszeHUHv EX1SNZbPUwkQUarOBZmOPveUMleCesg2Zdur/+YXj4VfUkMN0TcSZ1kJJ4f1zDAZrLk+ MGLPPd80FAOi/Irzp/mnPQkGHNpv58wKjPpEb29iiC4LBAZch9D8LBW54yjgya0qO7Pd Djuw== 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=WWpIEDPGuDmIegjVOLI7DlDuyK6XMz2/uBJPpi36p+v5wRzIBCx0rcouaV9gU0HmMq cwov86nzqksnbe6tdHXcFtMuLd1Azkc5YTqxpWVBugMZZ6pVk7khZk/uEycrTwaulC9j uedESrgX0Vm8L9XYd//rdNY/J9km89NP1QIPIrhKEbo3SuVpec42mmc8CXeW5JFkHWSk 6tSHt9HQ9+xI3plAXxKwU6J4xm6rjm7+w3kxYZ4yW/ljbAjP6Pzh0z9mUy6Em9XU+vcg iaPq7Zhl8zj8s9iwKS0OYdFlTwbHeBCmm7garQicl3lGUCVuD20lC8lkU6M1e/mb6iLR /9og== X-Gm-Message-State: AOAM532JRzZslU3skGyzepQ149cHf4woYF48goSbU705T3DRBCty5Tus OvTXb4sGBZjbIDv9QfWEt8k= X-Google-Smtp-Source: ABdhPJyXMfL4c3g1dgTRJF/g+KwCIJImavM64F0XKUZcJVbQKi+4eCx2e6aSpaHBso5IjMGSKotQkA== X-Received: by 2002:a17:902:c101:b0:138:f219:b0a0 with SMTP id 1-20020a170902c10100b00138f219b0a0mr393100pli.1.1630394725844; Tue, 31 Aug 2021 00:25:25 -0700 (PDT) Received: from sanitydock.wifi-cloud.jp ([210.160.217.69]) by smtp.gmail.com with ESMTPSA id m11sm1720724pjn.2.2021.08.31.00.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 00:25:25 -0700 (PDT) From: Desmond Cheong Zhi Xi To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com Cc: Desmond Cheong Zhi Xi , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Date: Tue, 31 Aug 2021 15:24:57 +0800 Message-Id: <20210831072501.184211-1-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Intel-gfx] [PATCH v10 0/4] drm: update locking for modesetting X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Sorry for the noise, rebasing on top of drm-misc-next. Please ignore the v9 series. Hi, I updated the patch set with some suggestions by Daniel Vetter, and dropped the patches after patch 4 so that we can stick the landing for avoiding races with modesetting rights before dealing with the tricky spinlock. Overall, this series fixes races with modesetting rights, and converts drm_device.master_mutex into master_rwsem. - Patch 1: Fix a potential null ptr dereference in drm_master_release - Patch 2: Convert master_mutex into rwsem (avoids creating a new lock) - Patch 3: Update global mutex locking in the ioctl handler (avoids deadlock when grabbing read lock on master_rwsem in drm_ioctl_kernel) - Patch 4: Plug races with drm modesetting rights v9 -> v10: - Rebase on top of drm-misc-next, caught by Intel-gfx CI v8 -> v9 (suggested by Daniel Vetter): - Drop patches 5-7 to handle it in another series - Add the appropriate Fixes: tag for the null ptr dereference fix (patch 1) - Create a locked_ioctl bool to clarify locking/unlocking patterns in the ioctl handler (patch 3) - Clarify the kernel doc for master_rwsem (patch 4) v7 -> v8: - Avoid calling drm_lease_held in drm_mode_setcrtc and drm_wait_vblank_ioctl, caught by Intel-gfx CI v6 -> v7: - Export __drm_mode_object_find for loadable modules, caught by the Intel-gfx CI v5 -> v6: - Fix recursive locking on master_rwsem, caught by the Intel-gfx CI v4 -> v5: - Avoid calling drm_file_get_master while holding on to the modeset mutex, caught by the Intel-gfx CI v3 -> v4 (suggested by Daniel Vetter): - Drop a patch that added an unnecessary master_lookup_lock in drm_master_release - Drop a patch that addressed a non-existent race in drm_is_current_master_locked - Remove fixes for non-existent null ptr dereferences - Protect drm_master.magic_map,unique{_len} with master_rwsem instead of master_lookup_lock - Drop the patch that moved master_lookup_lock into struct drm_device - Drop a patch to export task_work_add - Revert the check for the global mutex in the ioctl handler to use drm_core_check_feature instead of drm_dev_needs_global_mutex - Push down master_rwsem locking for selected ioctls to avoid lock hierarchy inversions, and to allow us to hold write locks on master_rwsem instead of flushing readers - Remove master_lookup_lock by replacing it with master_rwsem v2 -> v3: - Unexport drm_master_flush, as suggested by Daniel Vetter. - Merge master_mutex and master_rwsem, as suggested by Daniel Vetter. - Export task_work_add, reported by kernel test robot. - Make master_flush static, reported by kernel test robot. - Move master_lookup_lock into struct drm_device. - Add a missing lock on master_lookup_lock in drm_master_release. - Fix a potential race in drm_is_current_master_locked. - Fix potential null ptr dereferences in drm_{auth, ioctl}. - Protect magic_map,unique{_len} with master_lookup_lock. - Convert master_mutex into a rwsem. - Update global mutex locking in the ioctl handler. v1 -> v2 (suggested by Daniel Vetter): - Address an additional race when drm_open runs. - Switch from SRCU to rwsem to synchronise readers and writers. - Implement drm_master_flush with task_work so that flushes can be queued to run before returning to userspace without creating a new DRM_MASTER_FLUSH ioctl flag. Best wishes, Desmond Desmond Cheong Zhi Xi (4): drm: fix null ptr dereference in drm_master_release drm: convert drm_device.master_mutex into a rwsem drm: lock drm_global_mutex earlier in the ioctl handler drm: avoid races with modesetting rights drivers/gpu/drm/drm_auth.c | 39 ++++++++++++++++------------ drivers/gpu/drm/drm_debugfs.c | 4 +-- drivers/gpu/drm/drm_drv.c | 3 +-- drivers/gpu/drm/drm_file.c | 6 ++--- drivers/gpu/drm/drm_ioctl.c | 49 ++++++++++++++++++++++------------- drivers/gpu/drm/drm_lease.c | 35 +++++++++++++++++-------- include/drm/drm_auth.h | 6 ++--- include/drm/drm_device.h | 16 +++++++++--- include/drm/drm_file.h | 12 ++++----- 9 files changed, 104 insertions(+), 66 deletions(-) -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 735C4C43214 for ; Tue, 31 Aug 2021 07:25:32 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2882060FE8 for ; Tue, 31 Aug 2021 07:25:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2882060FE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id EFA1B81A58; Tue, 31 Aug 2021 07:25:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4P2yKYQclzHR; Tue, 31 Aug 2021 07:25:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1A1C081A5F; Tue, 31 Aug 2021 07:25:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E501CC0010; Tue, 31 Aug 2021 07:25:27 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 191ACC000E for ; Tue, 31 Aug 2021 07:25:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 0554C81A5F for ; Tue, 31 Aug 2021 07:25:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BNeoyOtu0zVC for ; Tue, 31 Aug 2021 07:25:26 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6081781A58 for ; Tue, 31 Aug 2021 07:25:26 +0000 (UTC) Received: by mail-pl1-x630.google.com with SMTP id e7so673046plh.8 for ; Tue, 31 Aug 2021 00:25:26 -0700 (PDT) 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=jxGI0ujHdl0N9GyGT2D3gCCB89vXr6ZHaDLYSvDAb0ZPJwcEXuX0JTOEampQTrFjnT R26DUsjxGUV2bNbq11XYxHiYUTV/uhTyuRaSRpftAlhLNY+PZYIOzUIExnRbFTF5Rnrq n7liC6CH5fsoUMhY6V6BKI3bZpqEPdZersNF3QuTd3yaxx6NO1Hx39aiwKeZuszeHUHv EX1SNZbPUwkQUarOBZmOPveUMleCesg2Zdur/+YXj4VfUkMN0TcSZ1kJJ4f1zDAZrLk+ MGLPPd80FAOi/Irzp/mnPQkGHNpv58wKjPpEb29iiC4LBAZch9D8LBW54yjgya0qO7Pd Djuw== 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=JNsb6x1cQWvzMyudhFnNtCYBKN16JRWCSincvM+uOoY=; b=iehh4oPh2gaJw+3wbjxVIlaFj5UBhLNFZn6z8/uUOtESBAYbUyjMtjfetGXyISc1Ve O0GwQwlzFmfL20GRLh011ztFvqH/jdPz4m2wYsCHGtW//r+us+lSkH0BOm/oKfRBB4OW Bi8c9DE2P1nIuTVW2/IQuyy7xVEsh1g/pPrAsXSqdXyZYdTNIRdy87TvB87R2TEjEdza Si2Ts+NQCydUkPniZnBtpnz2jBLJEx9d2ngdFsPkB8pXnw1VFSMknmVly12r/CPAkHWP xoh0a7bJPFaRjQlbeQJp9CUkkuHNserLOR/kjbkLCDDlU+pFqbsZUun/2IgSYXQQB2Lq UvEA== X-Gm-Message-State: AOAM531PgRyxcpfev+jiF66Q2gYYoDYblUG1IH2czi5skuVw0FTDKQYG VSwJHsYejlYI0bONcGoKElQ= X-Google-Smtp-Source: ABdhPJyXMfL4c3g1dgTRJF/g+KwCIJImavM64F0XKUZcJVbQKi+4eCx2e6aSpaHBso5IjMGSKotQkA== X-Received: by 2002:a17:902:c101:b0:138:f219:b0a0 with SMTP id 1-20020a170902c10100b00138f219b0a0mr393100pli.1.1630394725844; Tue, 31 Aug 2021 00:25:25 -0700 (PDT) Received: from sanitydock.wifi-cloud.jp ([210.160.217.69]) by smtp.gmail.com with ESMTPSA id m11sm1720724pjn.2.2021.08.31.00.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 00:25:25 -0700 (PDT) From: Desmond Cheong Zhi Xi To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com Subject: [PATCH v10 0/4] drm: update locking for modesetting Date: Tue, 31 Aug 2021 15:24:57 +0800 Message-Id: <20210831072501.184211-1-desmondcheongzx@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Cc: intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Desmond Cheong Zhi Xi , linux-kernel-mentees@lists.linuxfoundation.org, linux-media@vger.kernel.org X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" Sorry for the noise, rebasing on top of drm-misc-next. Please ignore the v9 series. Hi, I updated the patch set with some suggestions by Daniel Vetter, and dropped the patches after patch 4 so that we can stick the landing for avoiding races with modesetting rights before dealing with the tricky spinlock. Overall, this series fixes races with modesetting rights, and converts drm_device.master_mutex into master_rwsem. - Patch 1: Fix a potential null ptr dereference in drm_master_release - Patch 2: Convert master_mutex into rwsem (avoids creating a new lock) - Patch 3: Update global mutex locking in the ioctl handler (avoids deadlock when grabbing read lock on master_rwsem in drm_ioctl_kernel) - Patch 4: Plug races with drm modesetting rights v9 -> v10: - Rebase on top of drm-misc-next, caught by Intel-gfx CI v8 -> v9 (suggested by Daniel Vetter): - Drop patches 5-7 to handle it in another series - Add the appropriate Fixes: tag for the null ptr dereference fix (patch 1) - Create a locked_ioctl bool to clarify locking/unlocking patterns in the ioctl handler (patch 3) - Clarify the kernel doc for master_rwsem (patch 4) v7 -> v8: - Avoid calling drm_lease_held in drm_mode_setcrtc and drm_wait_vblank_ioctl, caught by Intel-gfx CI v6 -> v7: - Export __drm_mode_object_find for loadable modules, caught by the Intel-gfx CI v5 -> v6: - Fix recursive locking on master_rwsem, caught by the Intel-gfx CI v4 -> v5: - Avoid calling drm_file_get_master while holding on to the modeset mutex, caught by the Intel-gfx CI v3 -> v4 (suggested by Daniel Vetter): - Drop a patch that added an unnecessary master_lookup_lock in drm_master_release - Drop a patch that addressed a non-existent race in drm_is_current_master_locked - Remove fixes for non-existent null ptr dereferences - Protect drm_master.magic_map,unique{_len} with master_rwsem instead of master_lookup_lock - Drop the patch that moved master_lookup_lock into struct drm_device - Drop a patch to export task_work_add - Revert the check for the global mutex in the ioctl handler to use drm_core_check_feature instead of drm_dev_needs_global_mutex - Push down master_rwsem locking for selected ioctls to avoid lock hierarchy inversions, and to allow us to hold write locks on master_rwsem instead of flushing readers - Remove master_lookup_lock by replacing it with master_rwsem v2 -> v3: - Unexport drm_master_flush, as suggested by Daniel Vetter. - Merge master_mutex and master_rwsem, as suggested by Daniel Vetter. - Export task_work_add, reported by kernel test robot. - Make master_flush static, reported by kernel test robot. - Move master_lookup_lock into struct drm_device. - Add a missing lock on master_lookup_lock in drm_master_release. - Fix a potential race in drm_is_current_master_locked. - Fix potential null ptr dereferences in drm_{auth, ioctl}. - Protect magic_map,unique{_len} with master_lookup_lock. - Convert master_mutex into a rwsem. - Update global mutex locking in the ioctl handler. v1 -> v2 (suggested by Daniel Vetter): - Address an additional race when drm_open runs. - Switch from SRCU to rwsem to synchronise readers and writers. - Implement drm_master_flush with task_work so that flushes can be queued to run before returning to userspace without creating a new DRM_MASTER_FLUSH ioctl flag. Best wishes, Desmond Desmond Cheong Zhi Xi (4): drm: fix null ptr dereference in drm_master_release drm: convert drm_device.master_mutex into a rwsem drm: lock drm_global_mutex earlier in the ioctl handler drm: avoid races with modesetting rights drivers/gpu/drm/drm_auth.c | 39 ++++++++++++++++------------ drivers/gpu/drm/drm_debugfs.c | 4 +-- drivers/gpu/drm/drm_drv.c | 3 +-- drivers/gpu/drm/drm_file.c | 6 ++--- drivers/gpu/drm/drm_ioctl.c | 49 ++++++++++++++++++++++------------- drivers/gpu/drm/drm_lease.c | 35 +++++++++++++++++-------- include/drm/drm_auth.h | 6 ++--- include/drm/drm_device.h | 16 +++++++++--- include/drm/drm_file.h | 12 ++++----- 9 files changed, 104 insertions(+), 66 deletions(-) -- 2.25.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees