Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4226749pxb; Mon, 30 Aug 2021 23:15:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1u2eKgmz04hTvUSl1gKhHJ3HfInASWKZdrEiwgOF66fgPtfNTfysuBu32mva4AnX0tm/y X-Received: by 2002:a02:93aa:: with SMTP id z39mr1321645jah.29.1630390535705; Mon, 30 Aug 2021 23:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630390535; cv=none; d=google.com; s=arc-20160816; b=XgmfaoCLn4XIxLdSfj4/40npwY5pIMWBIlqLqoqy49QV6w6Af2hqHn+svDG6Y2GvLY LBVcorKb9hUlGP/im8nOGTNBTRvJ213P027tiwrIcvDwlwK1wqXKeAJIuMvfhC4YNSnG MfBL/D/hH5Hqkf9gbzjPLc+BoOI6Xc9B5ZwmbJhTOsve07FurisU7NHcGaFgXSaeK9Gt Hjn3pOsTKtb6Z5dCl09xcXNot6vn6DV5ZE3QOfLR+S2zb5JFxHc2llo4uprrE70I8P2C 71RMSEFu5+afOcjsKRRBL0ZZ3RkG6rYfo3ToDD6QgrAoyQjEa4qeN1KMRQcpCCyxrvtB yAHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=brM7hW6JylJKzonqvDJYo3SspnbZ8CW+4pmvj8jGqAU=; b=k8quMmUbHRLYARd0nV29gzTcsnKLhs3UTtqYG+iiII0gPeAeDmQpEF2rFDWUhJhkrO 8FiP7AE8SGhM3sZePzwtDQPFkAFAu6iKzpRuuthnAkp0CmV5bAkI2g/mk51Rw39ldnUu 15oyImtrLsddW842LevM4VlIZ9fJp2T7B/gQ2z+YfarI/YbFFyid8AKw3HYKRao1NzfK XqAmkNioPT3aXHVrbOt4+aJSDUQfM5/CjC+QYqUIuoZBSZpd+zK4lqDSUEJlSz/0ZRC0 H66XcjmqWc/sGIoUYpt9xvZB6ooorlh36JOGyFuTjl9DeiU4g+HbYwy2+DtZSSSWADKe 4LCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TYqGCHFl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si16119419ioo.6.2021.08.30.23.15.21; Mon, 30 Aug 2021 23:15:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TYqGCHFl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbhHaGP2 (ORCPT + 99 others); Tue, 31 Aug 2021 02:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbhHaGP1 (ORCPT ); Tue, 31 Aug 2021 02:15:27 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5302C061575; Mon, 30 Aug 2021 23:14:32 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id j10-20020a17090a94ca00b00181f17b7ef7so1198640pjw.2; Mon, 30 Aug 2021 23:14:32 -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=brM7hW6JylJKzonqvDJYo3SspnbZ8CW+4pmvj8jGqAU=; b=TYqGCHFl281XM/Qsit8ay9Zvizlo3WsBq5y4Obt8jQHjiox2dt6MPHCEVsE0keSEFe RVBMplpcZxGJR3qyTkA0pPPouAWFmaRtqHYDQ5q9RW0g1lwmiQjAD0ViWNUs3dao+kx4 S2UvHOz/hjQkH9bwTm+PgxCySQVOYy02T+CcvZuSiad3G56SQJPckpPWvECGc6uGkywE 0E6AyJFNzwK/zRaE5CXVonaqmQcKxK76Jm37BWzpf5bT2UcoYiKXeREgNDRnb1NCBqZb Za6F8DrOiQ0lsDgXis4hdyTqctY0f/9POhO9D/nybaASbrGDiAI7LGYTSmzHAcUG242w s88w== 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=brM7hW6JylJKzonqvDJYo3SspnbZ8CW+4pmvj8jGqAU=; b=Bt9q7UNDvLX41LX4rQ3tucypRUjKOyRtqyld9dwCRK15qbpDkJFyMuKaUxlx47fuLM GA+1BQ21vQJu6A5Lb2GQ6OJYib1K2/1vEp4PHF32Am+IuXZdsGAik8DaVy+houpoG01l YNCEXmKzDVqNnxsjfxASHxcBBOE25z8jggdW64doITis/stM9atudfdvLDVN1IQBaC3t pjTtAlEqmwNfIAJe9RTU2SRUoovL8OObtvqC+fVMnxCdei0LSxOV3nuNNrj+cF3ssHC5 aXmQstMjg+HPdryOirZ7BBcDtzHykMfTBsLaa407aQfCNojA9ehupvbx0szauHc+v6SE fz1Q== X-Gm-Message-State: AOAM532qTADkCnX/TPasyAYy83WmcfdKKRY1ZQ+AmlUk4itcFHAyAmzp byPETemZkEQpWwn+2jUSwvucIrxbmpDB7+eS5XNNJQ== X-Received: by 2002:a17:902:c9d5:b0:138:a025:c944 with SMTP id q21-20020a170902c9d500b00138a025c944mr3135880pld.61.1630390472061; Mon, 30 Aug 2021 23:14:32 -0700 (PDT) Received: from sanitydock.wifi-cloud.jp ([210.160.217.69]) by smtp.gmail.com with ESMTPSA id z7sm1405724pjr.42.2021.08.30.23.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 23:14:31 -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 v9 0/4] drm: update locking for modesetting Date: Tue, 31 Aug 2021 14:13:44 +0800 Message-Id: <20210831061348.97696-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 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 v8 -> v9 (suggested by Daniel Vetter): - Dropped patches 5-7 to handle it in another series - Added 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) - Clarified 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