Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7290021rwi; Mon, 24 Oct 2022 12:26:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54oqu4dmB6mZeM0w2MpqIsFUPnq7r/ojG5xpcXQWYP9Auu8hK0RU9R2pAl8fmz72srFoaA X-Received: by 2002:a17:906:9b93:b0:78d:eb36:1ce7 with SMTP id dd19-20020a1709069b9300b0078deb361ce7mr29395151ejc.621.1666639563744; Mon, 24 Oct 2022 12:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639563; cv=none; d=google.com; s=arc-20160816; b=mBh87DX1SlSmQ8ijsEa25xZpTVTqVs2/51EQmaXZRgZVokk9ZPJtauCUIAtr+4WX4L ++7T6r7oAjuw1I5vIlmLg5PJyRFBQykdm3kp6eNaFTQ3h97+uBj7DeAy+B9bqyxnALTH WYjCoTETUSZ79JgQCLyarUw6I4F66zIeCvJDSlcnG0sfXmZ6HxIwNerGAHcWuZC7foQq LalGJDcv5YzQ6juX38Hr9DorKSPv3/VbhFBEPd+oNK8azc1aYx4TxK9+hbyv/ujZTVOf eSTBy1wo8PMwgELEix1H1Uadf+sWtWLzuuZARp1WSacYb1R8stSxNp9+hZXelJu/79JL kaug== 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=bxh04uXMJrpUFfltxrwK8WMIoPdPifdbHVy8zaKtgRg=; b=PcqMlYWsUQy2ePhxvSfbYLWEBG83y5/RWLBTWqJuC1Ft2banYOFoS4gb5+dMd1THZm AoPENWtgzNPRRutE1vTCg54vN8A7BUvfoNmdjMPlo/c8znjWmzejVX6ykClN+7/0Lp0W m7lNlg0+OjB1tXGe7aTpsvTYMnV3lxpBWtn4r2MwnPZBddbhEp0p9RPDBXEx/o9xY9CH wifgpgt3NbDh/TITuMIdAtkSrcKzxek6PZmcCGXmf2idhloRrrcMu+l6Yr3tySTeaJcD Hg5e4I6Zj9eT8MntD9FDOPkziQQF9Lm0V9fqDq7rSs1jEG+sEWvf0WUCH4Snn63pLsh2 wlKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XfD0Iled; 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 p20-20020a170906785400b007835897050esi433584ejm.404.2022.10.24.12.25.37; Mon, 24 Oct 2022 12:26:03 -0700 (PDT) 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=XfD0Iled; 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 S231791AbiJXTXE (ORCPT + 99 others); Mon, 24 Oct 2022 15:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbiJXTVv (ORCPT ); Mon, 24 Oct 2022 15:21:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C562B25F for ; Mon, 24 Oct 2022 10:57:18 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 9DF23B819B6 for ; Mon, 24 Oct 2022 17:44:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D404C43141 for ; Mon, 24 Oct 2022 17:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666633473; bh=rxyQTUdSdUwZ2Oz9EnvVUz0qxX4MCHVHqwvbb6aL05U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XfD0Iled2Tv4HZSuYwD9foAloyb2TNg/Wn8YFbjnQyzyNjNGK4qgw18aR/dV1k8zK hnvWg/J0PfbETsLprF3n9YPNN8SX16hG9BWWXTT2FQzlXkER1PkcBFZ1sPgNl0pJDn L8oPBFgU0oWtCGVLVOH3ySI/pt7NMmCMzCXHBGvwmZLO9vewnQ0TyX3GISvJ55gxqi fpLGZiAepxFqN2s98o7TQqU5WYPxcS1tKiFGEZhKb0Lma1YDWKiq9i2ZEuqjpVHgVv vcQvP8t0BWm0kJsolFSa+0/xsvn37gUrhuiETsUDHBumMzXk4IFil4qRmWww+uDqh4 uuE5BwvzyrToQ== Received: by mail-ej1-f54.google.com with SMTP id k2so6816484ejr.2 for ; Mon, 24 Oct 2022 10:44:33 -0700 (PDT) X-Gm-Message-State: ACrzQf3/7Xbyi1vq43UmKEzHM6JDyd16I18qwn7tSptgsBWEcJ5JqtKK UelMPmFOHT2PH9E/CAjEJeCZP4bMcYgHhyTeQ6Y= X-Received: by 2002:a17:906:8a52:b0:78d:b6db:149d with SMTP id gx18-20020a1709068a5200b0078db6db149dmr28562056ejc.733.1666633471396; Mon, 24 Oct 2022 10:44:31 -0700 (PDT) MIME-Version: 1.0 References: <20221022214622.18042-1-ogabbay@kernel.org> <20221022214622.18042-4-ogabbay@kernel.org> In-Reply-To: From: Oded Gabbay Date: Mon, 24 Oct 2022 20:43:58 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 3/3] drm: add dedicated minor for accelerator devices To: Jeffrey Hugo 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 , Jiho Chu , Daniel Stone , Tvrtko Ursulin , Christoph Hellwig , Kevin Hilman , Jagan Teki , Jacek Lawrynowicz , Maciej Kwapulinski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.6 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 Mon, Oct 24, 2022 at 6:21 PM Jeffrey Hugo wrote: > > On 10/22/2022 3:46 PM, Oded Gabbay wrote: > > The accelerator devices are exposed to user-space using a dedicated > > major. In addition, they are represented in /dev with new, dedicated > > device char names: /dev/accel/accel*. This is done to make sure any > > user-space software that tries to open a graphic card won't open > > the accelerator device by mistake. > > > > The above implies that the minor numbering should be separated from > > the rest of the drm devices. However, to avoid code duplication, we > > want the drm_minor structure to be able to represent the accelerator > > device. > > > > To achieve this, we add a new drm_minor* to drm_device that represents > > the accelerator device. This pointer is initialized for drivers that > > declare they handle compute accelerator, using a new driver feature > > flag called DRIVER_COMPUTE_ACCEL. It is important to note that this > > driver feature is mutually exclusive with DRIVER_RENDER. Devices that > > want to expose both graphics and compute device char files should be > > handled by two drivers that are connected using the auxiliary bus > > framework. > > > > In addition, we define a different idr to handle the accelerators > > minors. This is done to make the minor's index be identical to the > > device index in /dev/. In most places, this is hidden inside the drm > > core functions except when calling drm_minor_acquire(), where I had to > > add an extra parameter to specify the idr to use (because the > > accelerators minors index and the drm primary minor index both begin > > at 0). > > > > Signed-off-by: Oded Gabbay > > --- > > drivers/gpu/drm/drm_drv.c | 171 +++++++++++++++++++++++++-------- > > drivers/gpu/drm/drm_file.c | 69 +++++++++---- > > drivers/gpu/drm/drm_internal.h | 2 +- > > drivers/gpu/drm/drm_sysfs.c | 29 ++++-- > > include/drm/drm_device.h | 3 + > > include/drm/drm_drv.h | 8 ++ > > include/drm/drm_file.h | 21 +++- > > 7 files changed, 235 insertions(+), 68 deletions(-) > > Can we please add something to Documentation? I know this leverages DRM > a lot, but I believe that a new subsystem should not be introduced > without documentation. A lot of the info in the commit message is very > good, but should not be buried in the git log. > > Besides, imagine this has been in mainline for N years, and someone > completely new to the kernel wants to write an accel driver. They > should be able to get started with something from Documentation that > at-least gives that person some insight into what to grep the code for. Agreed. The only reason I haven't done it at this stage was because I wanted to get an initial reaction to the code itself, see if the direction is accepted. I didn't want to write documentation and then completely re-write it. So I will do it for the next patch-set, once I collect everyone's feedback and I see there is a majority agreement. > > > > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > > index b58ffb1433d6..c13701a8d4be 100644 > > --- a/drivers/gpu/drm/drm_drv.c > > +++ b/drivers/gpu/drm/drm_drv.c > > @@ -56,6 +56,9 @@ MODULE_LICENSE("GPL and additional rights"); > > static DEFINE_SPINLOCK(drm_minor_lock); > > static struct idr drm_minors_idr; > > > > +static DEFINE_SPINLOCK(accel_minor_lock); > > +static struct idr accel_minors_idr; > > IDR is deprecated. XArray is the preferred mechanism. > Yes, there already is IDR here, but I believe we should not be adding > new uses. Maybe at some point, the current IDR will be converted. Also > with XArray, I think you don't need the spinlock since XArray has > internal locking already. ok, I wasn't aware. I don't have any problem replacing the idr to xarray. Thanks, Oded