Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2429716rdh; Wed, 27 Sep 2023 02:16:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlAvLWmw7x0T0Ol1nFAlQ8ofxesmJGhnxpKsRP76XXBumVnA0dd/Ib3fK3akUNA1m+9ZlC X-Received: by 2002:a05:6808:2126:b0:3ae:170f:a3b3 with SMTP id r38-20020a056808212600b003ae170fa3b3mr2092243oiw.26.1695806215282; Wed, 27 Sep 2023 02:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695806215; cv=none; d=google.com; s=arc-20160816; b=i9xQzmugDtQkXrgIhKu8O2ppys+PT47vlqYRZEUHXWWW006F9ihyDPVk/UPaqBf8Tx iCvDgt4xjibkzukKy4z3wGzjXgN0C7ysS5k2LY4hn5zUie0dn1W5/kH5FlZtdFbiNVu4 AL2yBsfKH0ePbGOhrhXhHUYFWTgNFltAU+p8F/pHSevBY1RgqlVmX2vSi/wGeypbXbLk 7qrF1iWuFrpvsQ2DAsZokbfgJ9WxodoOcUeXIxA8iFi8PmZhF4A6oBKwlkzj4xyFCXnN AfsQlcGhjQxLi6UAhgZFbSEYg27xnBooS+8Y+Pyar+en0jFMo1BgIGnKCj/8QIbzJUhM uRoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=d+9Ak0c2CWF0EmQbSLIn7TF/+0ZVwVc4k741kL8T3IE=; fh=axhJGGrDtRXei0nxnUavgaOxKL8HhRs/twj7DVmseHg=; b=mzH/LmU9m9cmQXay6N+gVMLCR+98Nzgyru2EoyDFbrjEJ1uIAD0ptI64mQyr7nEmK8 kbLacJIMJjRr9SDB2seJiAya0K+aby8BuAliiwGhhYlAscjwpRw/ucNazzNo+b1wHHYN hakskw9AJ0R1+0FWqls9fxgQjPn1J27Lzy05nYKTvTQWFJU4lhIuawWAzcFDi3g9lB6c jv7fYFtu7hOPSoCDc3lMZYmKH0oUCH3Qmz26vsJgb6wsRcwsLBZZQ2DmWJ2Ef0M+PBUx utq5m1WPzBodF6ybmaCQP0BnQn86KQ1qFpnzEeLHwhdqh/ulkEAxvs5/66yyFHwDKsBQ 2FJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id fc14-20020a056a002e0e00b0068ff333d768si15945578pfb.384.2023.09.27.02.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:16:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 62E1C8083E7A; Wed, 27 Sep 2023 01:05:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjI0IEx (ORCPT + 99 others); Wed, 27 Sep 2023 04:04:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230103AbjI0IEr (ORCPT ); Wed, 27 Sep 2023 04:04:47 -0400 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03471192; Wed, 27 Sep 2023 01:04:45 -0700 (PDT) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1c453379020so77202055ad.1; Wed, 27 Sep 2023 01:04:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695801885; x=1696406685; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=d+9Ak0c2CWF0EmQbSLIn7TF/+0ZVwVc4k741kL8T3IE=; b=XkZZHruWMP1/LpTwXuMRzhxwzpRPFJ99JEdmxCSEnAx+aqzCHpMxw8oZvm7tHzQT9L VSjNE1AwUs1ffv7NUB7Uw//I/DLiMIaDrKVoYGaJFe6TTlWkVl2WyJBIYjzKNPNAcPFj a1KhCSFEk1rU7VsiyWO6DTV4vUeLfos+BoiZHtQYD5Ei3KEePtPCT+2/Zozf6oi8eysZ YvLKxnW8o2mx2YXTMmz/WSSYXBvWILU4aguqF06IqYD9FdpQc671q43lmMo1dOiyPOAS wGFqkyD1klyJq7azdAhhRqTqtKWbeizxcuxIIyfJQNZbJO1PQ1EdyTWL4z3TlZ1s1Rox DSqg== X-Gm-Message-State: AOJu0Yztjon8zN+wmAJZQ8V2aAqYGMdy610Ut2qT/ZJOYGtnHKNezvsS qCDK637uA7YiWyL+5aHj6sA= X-Received: by 2002:a17:902:ef96:b0:1c6:19da:b29d with SMTP id iz22-20020a170902ef9600b001c619dab29dmr948578plb.44.1695801885181; Wed, 27 Sep 2023 01:04:45 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([20.69.120.36]) by smtp.gmail.com with ESMTPSA id v10-20020a1709028d8a00b001c5fda4d3eesm8407167plo.261.2023.09.27.01.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 01:04:44 -0700 (PDT) Date: Wed, 27 Sep 2023 08:04:42 +0000 From: Wei Liu To: Greg KH Cc: Nuno Das Neves , Wei Liu , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, patches@lists.linux.dev, mikelley@microsoft.com, kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, apais@linux.microsoft.com, Tianyu.Lan@microsoft.com, ssengar@linux.microsoft.com, mukeshrathor@microsoft.com, stanislav.kinsburskiy@gmail.com, jinankjain@linux.microsoft.com, vkuznets@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, will@kernel.org, catalin.marinas@arm.com Subject: Re: [PATCH v3 15/15] Drivers: hv: Add modules to expose /dev/mshv to VMMs running on Hyper-V Message-ID: References: <1695407915-12216-16-git-send-email-nunodasneves@linux.microsoft.com> <2023092342-staunch-chafe-1598@gregkh> <2023092630-masculine-clinic-19b6@gregkh> <2023092614-tummy-dwelling-7063@gregkh> <2023092646-version-series-a7b5@gregkh> <05119cbc-155d-47c5-ab21-e6a08eba5dc4@linux.microsoft.com> <2023092737-daily-humility-f01c@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2023092737-daily-humility-f01c@gregkh> X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 01:05:23 -0700 (PDT) Hi Greg It is past midnight here, so I may not be able to articulate my thoughts very well. I want to avoid waiting for another day for another round trip of emails though. We can look at your reply in the morning and reply again. On Wed, Sep 27, 2023 at 08:01:01AM +0200, Greg KH wrote: [...] > > > > If we're working with real devices like network cards or graphics cards > > > > I would agree -- it is easy to imagine that we have several cards of the > > > > same model in the system -- but in real world there won't be two > > > > hypervisor instances running on the same hardware. > > > > > > > > We can stash the struct device inside some private data fields, but that > > > > doesn't change the fact that we're still having one instance of the > > > > structure. Is this what you want? Or do you have something else in mind? > > > > > > You have a real device, it's how userspace interacts with your > > > subsystem. Please use that, it is dynamically created and handled and > > > is the correct representation here. > > > > > > > Are you referring to the struct device we get from calling > > misc_register? > > Yes. > We know about this, please see below. And we plan to use this. > > How would you suggest we get a reference to that device via e.g. open() > > or ioctl() without keeping a global reference to it? > > You explicitly have it in your open() and ioctl() call, you never need a > global reference for it the kernel gives it to you! > This is what I don't follow. Nuno and I discussed this today offline. We looked at the code before and looked again today (well, yesterday now). Here are the two functions: int vfs_open(const struct path *path, struct file *file) long vfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) Or, if we provide an open function in our file_operations struct, we get an additional struct inode pointer. int (*open) (struct inode *, struct file *); Neither struct file nor struct inode contains a reference to struct device. Then in vfs.rst, there is a section about open: ``open`` called by the VFS when an inode should be opened. When the VFS opens a file, it creates a new "struct file". It then calls the open method for the newly allocated file structure. You might think that the open method really belongs in "struct inode_operations", and you may be right. I think it's done the way it is because it makes filesystems simpler to implement. The open() method is a good place to initialize the "private_data" member in the file structure if you want to point to a device structure So, the driver is supposed to stash a pointer to struct device in private_data. That's what I alluded to in my previous reply. The core driver framework or the VFS doesn't give us a reference to struct device. We have to do it ourselves. We can do that for sure, but the struct device we stash into private_data is going to be the one that is returned from misc_register, which at the same time is already stashed inside a static variable in our driver by our own code (Note that this is a pervasive pattern in the kernel). I hope this is clear. If we're missing something extremely obvious, that somehow we can get a reference to struct device from the VFS while opening the file or doing ioctl without stashing it ourselves in our own code, please let us know. At this point I feel like either I'm extremely stupid or we're just talking past each other. If you tell me it is the former and help me understand how we can achieve what you described, I am more than happy to learn new things I don't know or understand. :-) If we have to propagate that reference ourselves, that then leads to next question whether it will just be more convenient to use the stashed value in the static variable directly like other drivers do, instead of stashing and propagating it around, knowing 100% it is the same object. I don't feel too strongly about this. As long as we are on the same page about getting a reference to struct device, we can do it either way. Thanks, Wei. > thanks, > > greg k-h >