From: Iouri Tarassov <iourit@linux.microsoft.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Wei Liu <wei.liu@kernel.org>,
kys@microsoft.com, haiyangz@microsoft.com,
sthemmin@microsoft.com, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org, spronovo@microsoft.com,
spronovo@linux.microsoft.com
Subject: Re: [PATCH v3 02/30] drivers: hv: dxgkrnl: Driver initialization and loading
Date: Wed, 2 Mar 2022 14:27:05 -0800 [thread overview]
Message-ID: <78df3646-4df6-5e2b-2f6e-e14824b08d85@linux.microsoft.com> (raw)
In-Reply-To: <Yh/Rq9PwWZAN8Mu2@kroah.com>
On 3/2/2022 12:20 PM, Greg KH wrote:
> On Wed, Mar 02, 2022 at 10:49:15AM -0800, Iouri Tarassov wrote:
> > On 3/2/2022 3:53 AM, Wei Liu wrote:
> > > On Wed, Mar 02, 2022 at 08:53:15AM +0100, Greg KH wrote:
> > > > On Tue, Mar 01, 2022 at 10:23:21PM +0000, Wei Liu wrote:
> > > > > > > +struct dxgglobal *dxgglobal;
> > > > > >
> > > > > > No, make this per-device, NEVER have a single device for your driver.
> > > > > > The Linux driver model makes it harder to do it this way than to do it
> > > > > > correctly. Do it correctly please and have no global structures like
> > > > > > this.
> > > > > >
> > > > >
> > > > > This may not be as big an issue as you thought. The device discovery is
> > > > > still done via the normal VMBus probing routine. For all intents and
> > > > > purposes the dxgglobal structure can be broken down into per device
> > > > > fields and a global structure which contains the protocol versioning
> > > > > information -- my understanding is there will always be a global
> > > > > structure to hold information related to the backend, regardless of how
> > > > > many devices there are.
> > > >
> > > > Then that is wrong and needs to be fixed. Drivers should almost never
> > > > have any global data, that is not how Linux drivers work. What happens
> > > > when you get a second device in your system for this? Major rework
> > > > would have to happen and the code will break. Handle that all now as it
> > > > takes less work to make this per-device than it does to have a global
> > > > variable.
> > > >
> > >
> > > It is perhaps easier to draw parallel from an existing driver. I feel
> > > like we're talking past each other.
> > >
> > > Let's look at drivers/iommu/intel/iommu.c. There are a bunch of lists
> > > like `static LIST_HEAD(dmar_rmrr_units)`. During the probing phase, new
> > > units will be added to the list. I this the current code is following
> > > this model. dxgglobal fulfills the role of a list.
> > >
> > > Setting aside the question of whether it makes sense to keep a copy of
> > > the per-VM state in each device instance, I can see the code be changed
> > > to:
> > >
> > > struct mutex device_mutex; /* split out from dxgglobal */
> > > static LIST_HEAD(dxglist);
> > >
> > > /* Rename struct dxgglobal to struct dxgstate */
> > > struct dxgstate {
> > > struct list_head dxglist; /* link for dxglist */
> > > /* ... original fields sans device_mutex */
> > > }
> > >
> > > /*
> > > * Provide a bunch of helpers manipulate the list. Called in probe /
> > > * remove etc.
> > > */
> > > struct dxgstate *find_dxgstate(...);
> > > void remove_dxgstate(...);
> > > int add_dxgstate(...);
> > >
> > > This model is well understood and used in tree. It is just that it
> > > doesn't provide much value in doing this now since the list will only
> > > contain one element. I hope that you're not saying we cannot even use a
> > > per-module pointer to quickly get the data structure we want to use,
> > > right?
> > >
> > > Are you suggesting Iouri use dev_set_drvdata to stash the dxgstate
> > > into the device object? I think that can be done too.
> > >
> > > The code can be changed as:
> > >
> > > /* Rename struct dxgglobal to dxgstate and remove unneeded fields */
> > > struct dxgstate { ... };
> > >
> > > static int dxg_probe_vmbus(...) {
> > >
> > > /* probe successfully */
> > >
> > > struct dxgstate *state = kmalloc(...);
> > > /* Fill in dxgstate with information from backend */
> > >
> > > /* hdev->dev is the device object from the core driver framework */
> > > dev_set_drvdata(&hdev->dev, state);
> > > }
> > >
> > > static int dxg_remove_vmbus(...) {
> > > /* Normal stuff here ...*/
> > >
> > > struct dxgstate *state = dev_get_drvdata(...);
> > > dev_set_drvdata(..., NULL);
> > > kfree(state);
> > > }
> > >
> > > /* In all other functions */
> > > void do_things(...) {
> > > struct dxgstate *state = dev_get_drvdata(...);
> > >
> > > /* Use state in place of where dxgglobal was needed */
> > >
> > > }
> > >
> > > Iouri, notice this doesn't change anything regarding how userspace is
> > > designed. This is about how kernel organises its data.
> > >
> > > I hope what I wrote above can bring our understanding closer.
> > >
> > > Thanks,
> > > Wei.
> >
> >
> > I can certainly remove dxgglobal and keep the pointer to the global
> > state in the device object.
> >
> > This will require passing of the global pointer to all functions, which
> > need to access it.
> >
> >
> > Maybe my understanding of the Greg's suggestion was not correct. I
> > thought the suggestion was
> >
> > to have multiple /dev/dxgN devices (one per virtual compute device).
>
> You have one device per HV device, as the bus already provides you.
> That's all you really need, right? Who would be opening the same device
> node multiple times?
> > This would change how the user mode
> > clients enumerate and communicate with compute devices.
>
> What does userspace have to do here? It should just open the device
> node that is present when needed. How will there be multiple userspace
> clients for a single HV device?
Dxgkrnl creates a single user mode visible device node /dev/dxg. It has
nothing to do with a specific hardware compute device on the host. Its
purpose is to provide services (IOCTLs) to enumerate and manage virtual
compute devices, which represent hardware devices on the host. The VMBus
devices are not used directly by user mode clients in the current design.
Virtual compute devices are shared between processes. There could be a
Cuda application, Gimp and a Direct3D12 application working at the same
time.This is what I mean by saying that there are multiple user mode
clients who use the /dev/dxg driver interface. Each of this applications
will open the /dev/dxg device node and enumerate/use virtual compute
devices.
If we change the way how the virtual compute devices are visible to user
mode, the Cuda runtime, Direct3D runtime would need to be changed.
I think we agreed that I will keep the global driver state in the device
object as Wei suggested and remove global variables. There still will be
a single /dev/dxg device node. Correct?
Thanks
Iouri
next prev parent reply other threads:[~2022-03-02 22:27 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 19:45 [PATCH v3 00/30] Driver for Hyper-v virtual compute device Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 01/30] drivers: hv: dxgkrnl: Add virtual compute device VM bus channel guids Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 02/30] drivers: hv: dxgkrnl: Driver initialization and loading Iouri Tarassov
2022-03-01 20:45 ` Greg KH
2022-03-01 22:23 ` Wei Liu
2022-03-01 22:47 ` Iouri Tarassov
2022-03-02 7:54 ` Greg KH
2022-03-02 7:53 ` Greg KH
2022-03-02 11:53 ` Wei Liu
2022-03-02 18:49 ` Iouri Tarassov
2022-03-02 20:20 ` Greg KH
2022-03-02 22:27 ` Iouri Tarassov [this message]
2022-03-03 13:16 ` Greg KH
2022-03-09 23:14 ` Steve Pronovost
2022-03-10 10:13 ` Greg KH
2022-03-10 18:31 ` Steve Pronovost
2022-03-02 20:34 ` Wei Liu
2022-03-03 1:09 ` Iouri Tarassov
2022-03-03 13:22 ` Greg KH
2022-03-04 16:04 ` Wei Liu
2022-03-04 17:55 ` Greg KH
2022-03-02 22:59 ` Iouri Tarassov
2022-03-03 13:29 ` Greg KH
2022-03-02 23:27 ` Iouri Tarassov
2022-03-03 13:10 ` Greg KH
2022-03-01 22:06 ` Wei Liu
2022-03-03 2:01 ` Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 03/30] drivers: hv: dxgkrnl: Add VM bus message support, initialize VM bus channels Iouri Tarassov
2022-03-01 22:57 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 04/30] drivers: hv: dxgkrnl: Creation of dxgadapter object Iouri Tarassov
2022-03-01 23:25 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 05/30] drivers: hv: dxgkrnl: Opening of /dev/dxg device and dxgprocess creation Iouri Tarassov
2022-03-01 20:46 ` Greg KH
2022-03-01 20:46 ` Greg KH
2022-03-01 23:47 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 06/30] drivers: hv: dxgkrnl: Enumerate and open dxgadapter objects Iouri Tarassov
2022-03-02 12:43 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 07/30] drivers: hv: dxgkrnl: Creation of dxgdevice objects Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 08/30] drivers: hv: dxgkrnl: Creation of dxgcontext objects Iouri Tarassov
2022-03-02 12:59 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 09/30] drivers: hv: dxgkrnl: Creation of compute device allocations and resources Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 10/30] drivers: hv: dxgkrnl: Creation of compute device sync objects Iouri Tarassov
2022-03-02 13:25 ` Wei Liu
2022-03-01 19:45 ` [PATCH v3 11/30] drivers: hv: dxgkrnl: Operations using " Iouri Tarassov
2022-03-01 19:45 ` [PATCH v3 12/30] drivers: hv: dxgkrnl: Sharing of dxgresource objects Iouri Tarassov
2022-03-02 14:13 ` Wei Liu
2022-03-02 14:15 ` Wei Liu
2022-03-01 19:46 ` [PATCH v3 13/30] drivers: hv: dxgkrnl: Sharing of sync objects Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 14/30] drivers: hv: dxgkrnl: Creation of hardware queues. Sync object operations to hw queue Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 15/30] drivers: hv: dxgkrnl: Creation of paging queue objects Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 16/30] drivers: hv: dxgkrnl: Submit execution commands to the compute device Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 17/30] drivers: hv: dxgkrnl: Share objects with the host Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 18/30] drivers: hv: dxgkrnl: Query the dxgdevice state Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 19/30] drivers: hv: dxgkrnl: Map(unmap) CPU address to device allocation Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 20/30] drivers: hv: dxgkrnl: Manage device allocation properties Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 21/30] drivers: hv: dxgkrnl: Flush heap transitions Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 22/30] drivers: hv: dxgkrnl: Query video memory information Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 23/30] drivers: hv: dxgkrnl: The escape ioctl Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 24/30] drivers: hv: dxgkrnl: Ioctl to put device to error state Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 25/30] drivers: hv: dxgkrnl: Ioctls to query statistics and clock calibration Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 26/30] drivers: hv: dxgkrnl: Offer and reclaim allocations Iouri Tarassov
2022-03-02 14:25 ` Wei Liu
2022-03-02 18:13 ` Iouri Tarassov
2022-03-02 18:23 ` Wei Liu
2022-03-01 19:46 ` [PATCH v3 27/30] drivers: hv: dxgkrnl: Ioctls to manage scheduling priority Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 28/30] drivers: hv: dxgkrnl: Manage residency of allocations Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 29/30] drivers: hv: dxgkrnl: Manage compute device virtual addresses Iouri Tarassov
2022-03-01 19:46 ` [PATCH v3 30/30] drivers: hv: dxgkrnl: Add support to map guest pages by host Iouri Tarassov
2022-03-02 14:29 ` Wei Liu
2022-03-01 21:37 ` [PATCH v3 01/30] drivers: hv: dxgkrnl: Add virtual compute device VM bus channel guids Wei Liu
2022-03-02 8:51 ` [PATCH v3 00/30] Driver for Hyper-v virtual compute device Christoph Hellwig
2022-03-02 14:53 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78df3646-4df6-5e2b-2f6e-e14824b08d85@linux.microsoft.com \
--to=iourit@linux.microsoft.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=spronovo@linux.microsoft.com \
--cc=spronovo@microsoft.com \
--cc=sthemmin@microsoft.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).