Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp54804ybl; Tue, 10 Dec 2019 17:29:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwzkpPBNuz6VBdnmcTN0rkOlojrXgIrFKjDvfKZQewn9fZoyXcYKU3DeaJapo6ql3dZgx5h X-Received: by 2002:aca:d484:: with SMTP id l126mr839924oig.114.1576027741744; Tue, 10 Dec 2019 17:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576027741; cv=none; d=google.com; s=arc-20160816; b=yfDC+P8Pky8Bdu/PKRvgPx0Dgn/YcGhW81Btg0psCob3aD3QPh4uxUYhvIGG1mLsNT dmapZYk6j2n1rjJHZ1RpWk4RBafg6khPwCKcAJFix5Mm38QwTbKxFCS1NUpKiq4AVcbz T3qPYqqyCz/9DMt0h3tcBl/C/XnmRAN9noNRI9KJnBc0PmJ0xADOYDgMT69tRWhaOQRW bkGy9JKSdxbOMPjnZwQ17KjVhpVwdixs+3MynOWohMJRBng9OJnBaLg7MIp3zLJhzpU4 ox9zLo2X0uIvKHFptq7nLsS1L+o59Ki70NbZlfwxvHD0jWJL/rZc66Xfy3QZpINDCfXw iPYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=Zq0L0c1P42wYwLiTs4+HEsyekcwr/o04D4Obh8iVUCc=; b=h/w6u0Utxbhdc8jachyw6X5BtBU9+nJQQRFuI4R+umcnsAsAgPZCgP6xI/e/sGU+r7 6UTJQf/7QMPTJRIR5Gec5q4HsKfnbV/cGwKApIWoYTMesQOxeLirRLYV8Fx3ayW9mVX7 Zp8KlYXVfbp89JbNyf3e6Yz93UXKdU4hT3JCbQu5jwDLG9jr8gowUP7LngykxJtshMp4 2IlWC+j4Rteb68zme62VKLSKTAcJ6/bCKwZ9C1zlTqVoR9f0Jh0dufLDUKhX9mTM99vs rPHc2zVy7e8OMXB5uDBI9zMYaX/fhynTOwsaI235z2AH7ULOwIZ/O6f8JWbaDgNftOeu OZCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h200si213778oib.258.2019.12.10.17.28.49; Tue, 10 Dec 2019 17:29:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbfLKB1z (ORCPT + 99 others); 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