From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56CC1C43603 for ; Wed, 11 Dec 2019 01:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 332C1206D5 for ; Wed, 11 Dec 2019 01:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbfLKB1z (ORCPT ); Tue, 10 Dec 2019 20:27:55 -0500 Received: from mga17.intel.com ([192.55.52.151]:32077 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfLKB1y (ORCPT ); Tue, 10 Dec 2019 20:27:54 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 17:27:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,301,1571727600"; d="scan'208";a="245060376" Received: from joy-optiplex-7040.sh.intel.com (HELO joy-OptiPlex-7040) ([10.239.13.9]) by fmsmga002.fm.intel.com with ESMTP; 10 Dec 2019 17:27:52 -0800 Date: Tue, 10 Dec 2019 20:19:41 -0500 From: Yan Zhao To: Alex Williamson Cc: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "libvir-list@redhat.com" , "qemu-devel@nongnu.org" , "cohuck@redhat.com" , "zhenyuw@linux.intel.com" , "Wang, Zhi A" , "Tian, Kevin" , "He, Shaopeng" Subject: Re: [RFC PATCH 1/9] vfio/pci: introduce mediate ops to intercept vfio-pci ops Message-ID: <20191211011941.GB28339@joy-OptiPlex-7040> Reply-To: Yan Zhao References: <20191205032419.29606-1-yan.y.zhao@intel.com> <20191205032536.29653-1-yan.y.zhao@intel.com> <20191205165519.106bd210@x1.home> <20191206075655.GG31791@joy-OptiPlex-7040> <20191206142226.2698a2be@x1.home> <20191209034225.GK31791@joy-OptiPlex-7040> <20191209170339.2cb3d06e@x1.home> <20191210024422.GA27331@joy-OptiPlex-7040> <20191210095824.5c4cdad7@x1.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191210095824.5c4cdad7@x1.home> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 11, 2019 at 12:58:24AM +0800, Alex Williamson wrote: > On Mon, 9 Dec 2019 21:44:23 -0500 > Yan Zhao wrote: > > > > > > > Currently, yes, i40e has build dependency on vfio-pci. > > > > > > It's like this, if i40e decides to support SRIOV and compiles in vf > > > > > > related code who depends on vfio-pci, it will also have build dependency > > > > > > on vfio-pci. isn't it natural? > > > > > > > > > > No, this is not natural. There are certainly i40e VF use cases that > > > > > have no interest in vfio and having dependencies between the two > > > > > modules is unacceptable. I think you probably want to modularize the > > > > > i40e vfio support code and then perhaps register a table in vfio-pci > > > > > that the vfio-pci code can perform a module request when using a > > > > > compatible device. Just and idea, there might be better options. I > > > > > will not accept a solution that requires unloading the i40e driver in > > > > > order to unload the vfio-pci driver. It's inconvenient with just one > > > > > NIC driver, imagine how poorly that scales. > > > > > > > > > what about this way: > > > > mediate driver registers a module notifier and every time when > > > > vfio_pci is loaded, register to vfio_pci its mediate ops? > > > > (Just like in below sample code) > > > > This way vfio-pci is free to unload and this registering only gives > > > > vfio-pci a name of what module to request. > > > > After that, > > > > in vfio_pci_open(), vfio-pci requests the mediate driver. (or puts > > > > the mediate driver when mediate driver does not support mediating the > > > > device) > > > > in vfio_pci_release(), vfio-pci puts the mediate driver. > > > > > > > > static void register_mediate_ops(void) > > > > { > > > > int (*func)(struct vfio_pci_mediate_ops *ops) = NULL; > > > > > > > > func = symbol_get(vfio_pci_register_mediate_ops); > > > > > > > > if (func) { > > > > func(&igd_dt_ops); > > > > symbol_put(vfio_pci_register_mediate_ops); > > > > } > > > > } > > > > > > > > static int igd_module_notify(struct notifier_block *self, > > > > unsigned long val, void *data) > > > > { > > > > struct module *mod = data; > > > > int ret = 0; > > > > > > > > switch (val) { > > > > case MODULE_STATE_LIVE: > > > > if (!strcmp(mod->name, "vfio_pci")) > > > > register_mediate_ops(); > > > > break; > > > > case MODULE_STATE_GOING: > > > > break; > > > > default: > > > > break; > > > > } > > > > return ret; > > > > } > > > > > > > > static struct notifier_block igd_module_nb = { > > > > .notifier_call = igd_module_notify, > > > > .priority = 0, > > > > }; > > > > > > > > > > > > > > > > static int __init igd_dt_init(void) > > > > { > > > > ... > > > > register_mediate_ops(); > > > > register_module_notifier(&igd_module_nb); > > > > ... > > > > return 0; > > > > } > > > > > > > > > No, this is bad. Please look at MODULE_ALIAS() and request_module() as > > > used in the vfio-platform for loading reset driver modules. I think > > > the correct approach is that vfio-pci should perform a request_module() > > > based on the device being probed. Having the mediation provider > > > listening for vfio-pci and registering itself regardless of whether we > > > intend to use it assumes that we will want to use it and assumes that > > > the mediation provider module is already loaded. We should be able to > > > support demand loading of modules that may serve no other purpose than > > > providing this mediation. Thanks, > > hi Alex > > Thanks for this message. > > So is it good to create a separate module as mediation provider driver, > > and alias its module name to "vfio-pci-mediate-vid-did". > > Then when vfio-pci probes the device, it requests module of that name ? > > I think this would give us an option to have the mediator as a separate > module, but not require it. Maybe rather than a request_module(), > where if we follow the platform reset example we'd then expect the init > code for the module to register into a list, we could do a > symbol_request(). AIUI, this would give us a reference to the symbol > if the module providing it is already loaded, and request a module > (perhaps via an alias) if it's not already load. Thanks, > ok. got it! Thank you :) Yan