Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp375553rwb; Sun, 6 Nov 2022 07:16:53 -0800 (PST) X-Google-Smtp-Source: AMsMyM6sHjZzXvVFilGnYTkNFealLkJ0Gz9O+T8ldwJRtS4LWwanoXCiUa8PKlm2maK6IxqA9ssZ X-Received: by 2002:a17:906:cc4e:b0:7ae:3f78:c8b8 with SMTP id mm14-20020a170906cc4e00b007ae3f78c8b8mr10582851ejb.394.1667747813086; Sun, 06 Nov 2022 07:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667747813; cv=none; d=google.com; s=arc-20160816; b=Jzora8GakhSD4LjZ294N44fL6sX3EfXQqulirpszELgN89HYUW4Lo7iHFXKImcSqBk ug53EA3wOqxMU8ZAmVUqxvI++BgxIj4sH9Dg8jxHLccZZn0/rZKrdQT3lR/VW/ks6031 5NzQWfRXqaznqcKab4M8beX592VZLEMvrLSCNx06eb57FiPPak2GzQNSotu9jaDZ2zXT r4ZTXUt2xOO5zyR3F0P/SsHGuVR/uLOlj5PWij+RYTmrtl3Z+GPm3trdW3jzBzzMilJ9 E5QEt0oeS+vLUgIGNcyEpJScuy3TnPWA/uKLxYHYhSwbhEW4qwxWZOHpiUm/I4NdfIRx Kvzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uk3Mte0tgZAgPQqKBdryjSADlwCMpKBBJMtfZ2F6uaw=; b=XEuSuqQEZD2DzenpevR46LWyrOsmxUd+dzW9JBZy9XiL0rUWEoKA8biFHFMNk+9min T0xmg66ZIN88bqJz8Wnvo3lUUjrBjOG2yn9NDSQzvsHydTaVDzJuCAztBd1EPcS2VtIF sV9knxMFJjMx/v1auYu7ioIhVyxSVgblV3CJexRENhLoFjBZx5l+wyknHM8fGBMBhVF9 5TLbh3GvBCtwY7wN+iMSzsG03F4ZmTz8yMYhKfg97x831/sTcrHKcPDkAuvxG3lcNScj vUFSjoRHOHltF5n7oi7eC7aeHfkgoQG1cYWQRaAL3riQrFPEsQDUY/i4SzQUkACZD+7z HbTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=myhJUxum; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a508d0e000000b00462f85ee700si6103932eds.65.2022.11.06.07.16.29; Sun, 06 Nov 2022 07:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=myhJUxum; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229899AbiKFOQX (ORCPT + 96 others); Sun, 6 Nov 2022 09:16:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbiKFOQV (ORCPT ); Sun, 6 Nov 2022 09:16:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E60B1DC for ; Sun, 6 Nov 2022 06:16:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5CD8A60C56 for ; Sun, 6 Nov 2022 14:16:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB2C6C43148 for ; Sun, 6 Nov 2022 14:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667744179; bh=52sVKQiNtNqqCU+oQ35F2gbqQKJCpmOCxXRfhgc3Gi0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=myhJUxumxIpn2bDXOY4V1wqgJP6Fv/U5QEfcSiBjUxPB89z4OMOmgWV6AceAta/g5 l6r7Lu294t2HWnQSt/Etx6xolKAY7mzDzWhcvzYheWAVlO1Ml+pk9vdFzYiBHTHAbw JcgI2Of/OBU+MEAyWCke/aQGgDQojjoBQVZaXQMzF0Hj2CHRT7Tg3y/Dpj4F6YjgCC zTRTVS0gLycbakpcFPaqR4XVL+JrvA/hDW+hvqSfIfjjp9oPSE2IkoxoZDrkEKp3eU HEAC3Hhf+TTGUmiC/ZWiaHL8fMAIwKG0LWJAoR7qg7Ao2agC/whsyDD0nf8PxH5yK5 7PhrlI/jYNNxA== Received: by mail-yb1-f170.google.com with SMTP id 131so6482870ybl.3 for ; Sun, 06 Nov 2022 06:16:19 -0800 (PST) X-Gm-Message-State: ACrzQf2naZr9FBMDBOZOV2wFCIaKy1j5W/1PfJiCZ2UniAXNeSbrg0IF tnPhlUG9rwRpi3my4rDld48sWrZ2l+jKjAARC0o= X-Received: by 2002:a25:1e89:0:b0:6bf:9e55:5cb4 with SMTP id e131-20020a251e89000000b006bf9e555cb4mr44872509ybe.642.1667744178636; Sun, 06 Nov 2022 06:16:18 -0800 (PST) MIME-Version: 1.0 References: <20221102203405.1797491-1-ogabbay@kernel.org> <20221102203405.1797491-3-ogabbay@kernel.org> <20221103142554.6310a60f0f6dad1a59fa7644@samsung.com> In-Reply-To: From: Oded Gabbay Date: Sun, 6 Nov 2022 16:15:52 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v2 2/3] accel: add dedicated minor for accelerator devices To: Jiho Chu Cc: David Airlie , Daniel Vetter , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jason Gunthorpe , John Hubbard , Alex Deucher , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Yuji Ishikawa , Daniel Stone , Tvrtko Ursulin , Jeffrey Hugo , Christoph Hellwig , Kevin Hilman , Jagan Teki , Jacek Lawrynowicz , Maciej Kwapulinski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 6, 2022 at 12:54 PM Oded Gabbay wrote: > > On Thu, Nov 3, 2022 at 7:26 AM Jiho Chu wrote: > > > > On Wed, 2 Nov 2022 22:34:04 +0200 > > Oded Gabbay wrote: > > > > > +/** > > > + * accel_open - open method for ACCEL file > > > + * @inode: device inode > > > + * @filp: file pointer. > > > + * > > > + * This function must be used by drivers as their &file_operations.open method. > > > + * It looks up the correct ACCEL device and instantiates all the per-file > > > + * resources for it. It also calls the &drm_driver.open driver callback. > > > + * > > > + * Return: 0 on success or negative errno value on failure. > > > + */ > > > +int accel_open(struct inode *inode, struct file *filp) > > > +{ > > > + struct drm_device *dev; > > > + struct drm_minor *minor; > > > + int retcode; > > > + > > > + minor = accel_minor_acquire(iminor(inode)); > > > + if (IS_ERR(minor)) > > > + return PTR_ERR(minor); > > > + > > > + dev = minor->dev; > > > + > > > + atomic_fetch_inc(&dev->open_count); > > > + > > > > Hi, > > It needs to consider drm_global_mutex to access open_count. > > please check doxy of open_count. > Now that I'm changing the code back to be part of drm.ko, I can return > all the code that is in drm_copy which I removed for this to compile. I take it back. All the code that I omitted was for legacy drivers. If you look inside drm_dev_needs_global_mutex(), you will see 3 cases where you need to take the global mutex, and all 3 are only relevant for legacy drivers and/or drivers that use deprecated features. So, I disagree with your original comment here. Moreover, open_count is atomic, so I don't need to take the mutex to increment it, and as you can see in drm_open(), the function increments it regardless of whether it takes drm_dev_needs_global_mutex. Oded > > > > > > > > + /* share address_space across all char-devs of a single device */ > > > + filp->f_mapping = dev->anon_inode->i_mapping; > > > + > > > + retcode = drm_open_helper(filp, minor); > > > + if (retcode) > > > + goto err_undo; > > > + > > > + return 0; > > > + > > > +err_undo: > > > + atomic_dec(&dev->open_count); > > > + accel_minor_release(minor); > > > + return retcode; > > > +} > > > +EXPORT_SYMBOL_GPL(accel_open); > > > + > > > static int accel_stub_open(struct inode *inode, struct file *filp) > > > { > > > - DRM_DEBUG("Operation not supported"); > > > + const struct file_operations *new_fops; > > > + struct drm_minor *minor; > > > + int err; > > > + > > > + DRM_DEBUG("\n"); > > > > It seems useless. > Correct, I removed it in v3. > Thanks, > Oded > > > > Thanks. > > Jiho Chu