Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3921540pxb; Mon, 30 Aug 2021 14:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFaL+ul5IXCdSEaErN6nsfp7H8ejNKH1IziDi9TBitjuHgJYP+V5zUWE+z/PEeE5VCDctu X-Received: by 2002:a05:6e02:4cd:: with SMTP id f13mr17848913ils.126.1630357512616; Mon, 30 Aug 2021 14:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630357512; cv=none; d=google.com; s=arc-20160816; b=Uwa2pqAYOis+ax2Scg/TfKDm/0lOoLCVQHpwQs785hpMbDLeQgI3CicD7EIxnB9wNO bqxXY5aQC7i8ORD3kdtss3jxL81bCLQBbB+R1Z7omUisfhgc8s2JmrgHosP6jpZnY8Ev 1WKwDGTZCX3LWy9IO9t/lM8zpG1D2AqiW5sakAV6aDChT7a7E4TXIS9BxdTbz+4IpoQ3 0OPjag2+Xba/hy2ckPIgPO933GZ9g61r/R0FIRcRdYNoC6mEQrauCSL+beoCxE1eovSv 0lWopVJUx06Kx2SDA4q0umRJ4ed91UdN4F60xa5mmP/p+kQowzEJSTyylRm8CtBP9jTT I6Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:dkim-signature; bh=DR2Bm1R7YKSILao3MIz9gdsriioL6L4Hdgm+Hq95yfk=; b=tKYWCGIHg2G5FAD1o+Tg9/1dgxxaiw+ThhmXbwb9SqQCKwuUeoF8Gf6rZu0pM1GwN5 ObuAQuw5EqtUbwI5zBDRYJBn/uyzYGCY0eCzaFHePhwMXPvntxkoGXczoOnv+XypOpP9 tF5Zrj632txFtoHilqIrHrRdORcvP+lawr/SrUDXj2RryzevACWYF0TRqa8+/ZSeX+uG L/qOQYqSIkEZ3bLiU+E6Vshv2gkzQDqlFC54e2pgjQwFM2APQUFRRSj1F8lXzbd6WgBv N6b/h8vAVDShQU1s6vNAgEHQ2HIoKyollu+7mI/olnai8NnrA0SY3hsUI1txrN6qEzdg +K/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ah+4CA5h; 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 f8si15080293ilu.107.2021.08.30.14.05.00; Mon, 30 Aug 2021 14:05:12 -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=ah+4CA5h; 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 S236451AbhH3VFL (ORCPT + 99 others); Mon, 30 Aug 2021 17:05:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236009AbhH3VFJ (ORCPT ); Mon, 30 Aug 2021 17:05:09 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29234C061575; Mon, 30 Aug 2021 14:04:15 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id fs6so10351146pjb.4; Mon, 30 Aug 2021 14:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=DR2Bm1R7YKSILao3MIz9gdsriioL6L4Hdgm+Hq95yfk=; b=ah+4CA5h+kOwFd9qrEibSKfYAPfYPA83e3z19xKkl0kEPGZHX9BjvNNIlNCmuCTkXX OmMkgnLYCbXJFPMl/uNwnZ7tGJd9XFnyVK5rD+PPYOjgk9EhpGul2WjEs/kNX+h2CQix bDevhwEQZAchriHqTe8K2o7x4pbEeMPBILP1vLOOSXFb8wGKzXjRJHqqB591CppFPJpS 7k7ACVFs9omrP3aTjkTx3K4LwCNocbanA6eC7hRPlw0/8xD6o2t3uJnBfKBeXbGJ1cEL JvjGWRXh76BC39zDasi/DXiNmZwP/TCyXDbjekiUeEikZJrcl1u3AKpJbERDh9fuopj6 /92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DR2Bm1R7YKSILao3MIz9gdsriioL6L4Hdgm+Hq95yfk=; b=Qbv3t7Sp2ECZNr5WOA8FwEQK8OwTbwAOeLs4Ana1rDnrlaNHqyxEjjWXryZky6GG7w Lkg66gQruRvBLLLdHunfXL3FPFAU6Mfl9cFD/2jApUC4LP23P6vdWlANXX179XUoSejS mW/1aXnnmJDqFUmlrjthpepiMDwQ6XwLa4SqZ0mLPxynAZOwgbb+GjBcDkifeliZhqYG WnAwBWzrQn9cWd5PO9hJOlWdi1ThtavTXeloTe0USQJt3bYWe0IYI/2G0yG+GZOomlPE pBDDm8mJlxMsGs6P7/HjQnOFGqklE3WFlbPH9Lzv6RzRvhnU1ysu7cB5en5cU7CbtttP 9VKg== X-Gm-Message-State: AOAM530P+S/pkYyZj81BTRlQ5exokh5mUc/vsphmH+vh4Oxetaf9gzzc N8hkmlD9h30MQfBsoYbeOtU= X-Received: by 2002:a17:902:9682:b0:138:e2f9:720d with SMTP id n2-20020a170902968200b00138e2f9720dmr1366038plp.57.1630357454505; Mon, 30 Aug 2021 14:04:14 -0700 (PDT) Received: from [10.80.16.166] ([103.137.210.137]) by smtp.gmail.com with ESMTPSA id w4sm362753pjj.15.2021.08.30.14.04.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Aug 2021 14:04:13 -0700 (PDT) Subject: Re: [PATCH v8 3/7] drm: lock drm_global_mutex earlier in the ioctl handler To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, sumit.semwal@linaro.org, christian.koenig@amd.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, ville.syrjala@linux.intel.com, matthew.auld@intel.com, dan.carpenter@oracle.com, tvrtko.ursulin@intel.com, matthew.d.roper@intel.com, lucas.demarchi@intel.com, karthik.b.s@intel.com, jose.souza@intel.com, manasi.d.navare@intel.com, airlied@redhat.com, aditya.swarup@intel.com, andrescj@chromium.org, linux-graphics-maintainer@vmware.com, zackr@vmware.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Daniel Vetter References: <20210826020122.1488002-1-desmondcheongzx@gmail.com> <20210826020122.1488002-4-desmondcheongzx@gmail.com> From: Desmond Cheong Zhi Xi Message-ID: Date: Tue, 31 Aug 2021 05:04:04 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/8/21 5:58 pm, Daniel Vetter wrote: > On Thu, Aug 26, 2021 at 10:01:18AM +0800, Desmond Cheong Zhi Xi wrote: >> In a future patch, a read lock on drm_device.master_rwsem is >> held in the ioctl handler before the check for ioctl >> permissions. However, this inverts the lock hierarchy of >> drm_global_mutex --> master_rwsem. >> >> To avoid this, we do some prep work to grab the drm_global_mutex >> before checking for ioctl permissions. >> >> Signed-off-by: Desmond Cheong Zhi Xi >> --- >> drivers/gpu/drm/drm_ioctl.c | 18 +++++++++--------- >> 1 file changed, 9 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c >> index d25713b09b80..158629d88319 100644 >> --- a/drivers/gpu/drm/drm_ioctl.c >> +++ b/drivers/gpu/drm/drm_ioctl.c >> @@ -772,19 +772,19 @@ long drm_ioctl_kernel(struct file *file, drm_ioctl_t *func, void *kdata, >> if (drm_dev_is_unplugged(dev)) >> return -ENODEV; >> >> + /* Enforce sane locking for modern driver ioctls. */ >> + if (unlikely(drm_core_check_feature(dev, DRIVER_LEGACY)) && !(flags & DRM_UNLOCKED)) > > Maybe have a local bool locked_ioctl for this so it's extremely clear it's > the same condition in both? > > Either way: Reviewed-by: Daniel Vetter > Thanks for the suggestion and review. Sounds good, I'll update and send out a new version. (Sorry for delays, been busy with moving) >> + mutex_lock(&drm_global_mutex); >> + >> retcode = drm_ioctl_permit(flags, file_priv); >> if (unlikely(retcode)) >> - return retcode; >> + goto out; >> >> - /* Enforce sane locking for modern driver ioctls. */ >> - if (likely(!drm_core_check_feature(dev, DRIVER_LEGACY)) || >> - (flags & DRM_UNLOCKED)) >> - retcode = func(dev, kdata, file_priv); >> - else { >> - mutex_lock(&drm_global_mutex); >> - retcode = func(dev, kdata, file_priv); >> + retcode = func(dev, kdata, file_priv); >> + >> +out: >> + if (unlikely(drm_core_check_feature(dev, DRIVER_LEGACY)) && !(flags & DRM_UNLOCKED)) >> mutex_unlock(&drm_global_mutex); >> - } >> return retcode; >> } >> EXPORT_SYMBOL(drm_ioctl_kernel); >> -- >> 2.25.1 >> >