Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp259560rwi; Wed, 26 Oct 2022 00:03:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7XIUD+29A7wt5imQdQjStYYzD5BAXZ/S9dtsNM9CycjszN/yYtZM3UXBpfLspSw9rUsWrp X-Received: by 2002:a17:902:720a:b0:181:150c:fcc4 with SMTP id ba10-20020a170902720a00b00181150cfcc4mr43062969plb.109.1666767781191; Wed, 26 Oct 2022 00:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666767781; cv=none; d=google.com; s=arc-20160816; b=n93/Htb4BsIWCv7Hkj+AslfyDmdY6G5R4wFRNNSxdtNH1XtKrtS/jeqNLR4RfGG+im goV6F52kt417Qnvn7vc8TvxWD/9uvn1g9j3Kh98O7VijO1ewa7fYYcE0mvGtfUgIRGo4 aZbcLe9rYWl0AfTbJQed/PKjzkTFNZewqT4j7DbYiEiDNn5Eui+0MIZFm/XDBmRxE7ks xZEHTghFWMWQvVtHPSckvDtVA+0950c2adF/cLlfSbI7bJ4irpuIvGHUS9X+xfwfLSnr 7ArYkqUShEbwX2fpO1NxghhLW3y51vG23WweNihBT/4PKIPsznt5i+8Ctdsf9M42HrG9 bVXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0VRoXFs0Tqgt2sPIDIeMSxGrr1PlrvMV/dP6TJqGiCs=; b=HhlHuC5n2JwqP44P7mVtI+07UiJG+4/4ZalkIyEPxgogqWXqOQaL0DPfbXjXZps6oG qzwGHrq2GdD2GHWD2JUy13OeodPerAPgofF9YAFFdLs85dQ/G6nCPmthzDi/zJaflpl0 6F+uYXItH0rt7O0A0vypG1tWwWYJ9wSj7Sj1XdPwllT4VqVlpMznn3uJmPsO5OFBt6bM 6Yv7h10bLdVKa4W8cNKYmuPM50o9s2GJBXanNixVPY/x6PuvIbUEYdc4kewHp+3Ni8+5 EdTDZvVJ9JNC2ubnZi90iZzg87CC00DC3qkNon1C5L42UBdxBcpbziq/Grb7PH626yLF gLuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dV2JLFsK; 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 gl13-20020a17090b120d00b002008d0b0838si1431852pjb.178.2022.10.26.00.02.40; Wed, 26 Oct 2022 00:03:01 -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=dV2JLFsK; 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 S232727AbiJZGje (ORCPT + 99 others); Wed, 26 Oct 2022 02:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232995AbiJZGj3 (ORCPT ); Wed, 26 Oct 2022 02:39:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F00AE1B1 for ; Tue, 25 Oct 2022 23:39:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 95F3761D58 for ; Wed, 26 Oct 2022 06:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02957C43140 for ; Wed, 26 Oct 2022 06:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666766364; bh=yFlG8DyeHSBJrLAthLxUGjSJOLwrlJQPptyLz3jkn1U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dV2JLFsKDFQWV6+BzdLxfAPH3dmhFazYkd4h5vvIdk6BZtjHBWZ2JG9UPha18f1Fc PDp6r4gm6rGWQqWR34yPEvzHHlI1gndRON7DOHbdqM5rJtWytlGGcnHj5BWv+sF0C+ i9+WI7tZUhQmVabPv/rMCUGJuSD0SqWt99/9AfRsxdjJBOA75ecHKiMsOC2iPTEiuG dzZuvzUb3a2Tv27uxoNnn0S4TyExbKH+yD576bA5rnwgOZMNIhoujBgxvTqrZyeDZY /7/6o5STHvzJmx+DuM3fTKV6ulM000uV9EU13xsrc2Pcm/FsFvu+El3noxTDJy2Zl/ od/u1Y48g65GA== Received: by mail-ej1-f43.google.com with SMTP id fy4so18709268ejc.5 for ; Tue, 25 Oct 2022 23:39:23 -0700 (PDT) X-Gm-Message-State: ACrzQf0JX+E5IeI2qH081kNo0xNPJXP+15gUTbI9VL/R1fFBMfQUHSGV rTPEN3Ro1p8mM29jLNdbb+WbrCwdl2YGqhGbb7k= X-Received: by 2002:a17:906:5dcc:b0:78d:fb98:6f85 with SMTP id p12-20020a1709065dcc00b0078dfb986f85mr36812057ejv.123.1666766362209; Tue, 25 Oct 2022 23:39:22 -0700 (PDT) MIME-Version: 1.0 References: <20221022214622.18042-1-ogabbay@kernel.org> <20221022214622.18042-4-ogabbay@kernel.org> <20221025132654.fcbw7xvl7pu3yp6c@nostramo> In-Reply-To: <20221025132654.fcbw7xvl7pu3yp6c@nostramo> From: Oded Gabbay Date: Wed, 26 Oct 2022 09:38:55 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 3/3] drm: add dedicated minor for accelerator devices To: =?UTF-8?Q?Micha=C5=82_Winiarski?= Cc: Jeffrey Hugo , 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" Content-Transfer-Encoding: quoted-printable 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 Tue, Oct 25, 2022 at 4:27 PM Micha=C5=82 Winiarski wrote: > > On Mon, Oct 24, 2022 at 08:43:58PM +0300, Oded Gabbay wrote: > > On Mon, Oct 24, 2022 at 6:21 PM Jeffrey Hugo w= rote: > > > > > > 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, dedicate= d > > > > 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 accelerato= r > > > > device. > > > > > > > > To achieve this, we add a new drm_minor* to drm_device that represe= nts > > > > the accelerator device. This pointer is initialized for drivers tha= t > > > > 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 th= at > > > > want to expose both graphics and compute device char files should b= e > > > > 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 dr= m > > > > 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 begi= n > > > > 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 ve= ry > > > 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 fo= r. > > 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. A= lso > > > 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 xarra= y. > > The conversion is sitting on the mailinglist for a while now > (unfortunately, without much interest). > Perhaps you could help with reviewing it? > https://lore.kernel.org/dri-devel/20220911211443.581481-2-michal.winiarsk= i@intel.com/ > > -Micha=C5=82 I'll do it. Oded > > > > > Thanks, > > Oded > >