Message ID | 20210630082145.5729-3-lingshan.zhu@intel.com |
---|---|
State | New |
Headers | show |
Series | vDPA/ifcvf: implement management netlink framework | expand |
On Thu, Jul 01, 2021 at 03:04:09AM +0800, kernel test robot wrote: > Hi Zhu, > > Thank you for the patch! Perhaps something to improve: > > [auto build test WARNING on linus/master] > [also build test WARNING on v5.13 next-20210630] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch] > > url: https://github.com/0day-ci/linux/commits/Zhu-Lingshan/vDPA-ifcvf-implement-management-netlink-framework/20210630-162940 > base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 007b350a58754a93ca9fe50c498cc27780171153 > config: x86_64-randconfig-a015-20210630 (attached as .config) > compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 8d21d5472501460933e78aead04cf59579025ba4) > reproduce (this is a W=1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # install x86_64 cross compiling tool for clang build > # apt-get install binutils-x86-64-linux-gnu > # https://github.com/0day-ci/linux/commit/7ea782fbd896e1a5b3c01b29f4929773748a525f > git remote add linux-review https://github.com/0day-ci/linux > git fetch --no-tags linux-review Zhu-Lingshan/vDPA-ifcvf-implement-management-netlink-framework/20210630-162940 > git checkout 7ea782fbd896e1a5b3c01b29f4929773748a525f > # save the attached .config to linux build tree > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp@intel.com> > > All warnings (new ones prefixed by >>): > > >> drivers/vdpa/ifcvf/ifcvf_main.c:612:14: warning: variable 'adapter' is uninitialized when used here [-Wuninitialized] > put_device(&adapter->vdpa.dev); > ^~~~~~~ > drivers/vdpa/ifcvf/ifcvf_main.c:546:31: note: initialize the variable 'adapter' to silence this warning > struct ifcvf_adapter *adapter; > ^ > = NULL > 1 warning generated. compiler being silly again? > > vim +/adapter +612 drivers/vdpa/ifcvf/ifcvf_main.c > > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 541 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 542 static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 543 { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 544 struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 545 struct device *dev = &pdev->dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 546 struct ifcvf_adapter *adapter; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 547 u32 dev_type; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 548 int ret; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 549 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 550 ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 551 if (!ifcvf_mgmt_dev) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 552 IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 553 return -ENOMEM; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 554 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 555 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 556 dev_type = get_dev_type(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 557 switch (dev_type) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 558 case VIRTIO_ID_NET: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 559 ifcvf_mgmt_dev->mdev.id_table = id_table_net; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 560 break; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 561 case VIRTIO_ID_BLOCK: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 562 ifcvf_mgmt_dev->mdev.id_table = id_table_blk; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 563 break; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 564 default: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 565 IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 566 ret = -EOPNOTSUPP; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 567 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 568 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 569 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 570 ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 571 ifcvf_mgmt_dev->mdev.device = dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 572 ifcvf_mgmt_dev->pdev = pdev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 573 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 574 ret = pcim_enable_device(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 575 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 576 IFCVF_ERR(pdev, "Failed to enable device\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 577 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 578 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 579 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 580 ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 581 IFCVF_DRIVER_NAME); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 582 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 583 IFCVF_ERR(pdev, "Failed to request MMIO region\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 584 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 585 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 586 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 587 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 588 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 589 IFCVF_ERR(pdev, "No usable DMA configuration\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 590 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 591 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 592 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 593 ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 594 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 595 IFCVF_ERR(pdev, > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 596 "Failed for adding devres for freeing irq vectors\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 597 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 598 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 599 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 600 pci_set_master(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 601 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 602 ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 603 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 604 IFCVF_ERR(pdev, > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 605 "Failed to initialize the management interfaces\n"); > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 606 goto err; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 607 } > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 608 > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 609 return 0; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 610 > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 611 err: > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 @612 put_device(&adapter->vdpa.dev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 613 kfree(ifcvf_mgmt_dev); > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 614 return ret; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 615 } > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 616 > > --- > 0-DAY CI Kernel Test Service, Intel Corporation > https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
On Thu, Jul 01, 2021 at 03:04:09AM +0800, kernel test robot wrote: > Hi Zhu, > > Thank you for the patch! Perhaps something to improve: > > [auto build test WARNING on linus/master] > [also build test WARNING on v5.13 next-20210630] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch] > > url: https://github.com/0day-ci/linux/commits/Zhu-Lingshan/vDPA-ifcvf-implement-management-netlink-framework/20210630-162940 > base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 007b350a58754a93ca9fe50c498cc27780171153 > config: x86_64-randconfig-a015-20210630 (attached as .config) > compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 8d21d5472501460933e78aead04cf59579025ba4) > reproduce (this is a W=1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # install x86_64 cross compiling tool for clang build > # apt-get install binutils-x86-64-linux-gnu > # https://github.com/0day-ci/linux/commit/7ea782fbd896e1a5b3c01b29f4929773748a525f > git remote add linux-review https://github.com/0day-ci/linux > git fetch --no-tags linux-review Zhu-Lingshan/vDPA-ifcvf-implement-management-netlink-framework/20210630-162940 > git checkout 7ea782fbd896e1a5b3c01b29f4929773748a525f > # save the attached .config to linux build tree > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp@intel.com> > > All warnings (new ones prefixed by >>): > > >> drivers/vdpa/ifcvf/ifcvf_main.c:612:14: warning: variable 'adapter' is uninitialized when used here [-Wuninitialized] > put_device(&adapter->vdpa.dev); > ^~~~~~~ > drivers/vdpa/ifcvf/ifcvf_main.c:546:31: note: initialize the variable 'adapter' to silence this warning > struct ifcvf_adapter *adapter; > ^ > = NULL > 1 warning generated. > Actually the problem is real and this is almost surely the wrong fix. We need an extra label to skip using put_device when adapter was not yet initialized. > vim +/adapter +612 drivers/vdpa/ifcvf/ifcvf_main.c > > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 541 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 542 static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 543 { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 544 struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 545 struct device *dev = &pdev->dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 546 struct ifcvf_adapter *adapter; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 547 u32 dev_type; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 548 int ret; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 549 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 550 ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 551 if (!ifcvf_mgmt_dev) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 552 IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 553 return -ENOMEM; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 554 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 555 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 556 dev_type = get_dev_type(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 557 switch (dev_type) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 558 case VIRTIO_ID_NET: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 559 ifcvf_mgmt_dev->mdev.id_table = id_table_net; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 560 break; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 561 case VIRTIO_ID_BLOCK: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 562 ifcvf_mgmt_dev->mdev.id_table = id_table_blk; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 563 break; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 564 default: > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 565 IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 566 ret = -EOPNOTSUPP; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 567 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 568 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 569 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 570 ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 571 ifcvf_mgmt_dev->mdev.device = dev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 572 ifcvf_mgmt_dev->pdev = pdev; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 573 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 574 ret = pcim_enable_device(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 575 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 576 IFCVF_ERR(pdev, "Failed to enable device\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 577 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 578 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 579 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 580 ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 581 IFCVF_DRIVER_NAME); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 582 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 583 IFCVF_ERR(pdev, "Failed to request MMIO region\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 584 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 585 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 586 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 587 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 588 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 589 IFCVF_ERR(pdev, "No usable DMA configuration\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 590 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 591 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 592 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 593 ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 594 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 595 IFCVF_ERR(pdev, > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 596 "Failed for adding devres for freeing irq vectors\n"); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 597 goto err; > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 598 } > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 599 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 600 pci_set_master(pdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 601 > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 602 ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 603 if (ret) { > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 604 IFCVF_ERR(pdev, > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 605 "Failed to initialize the management interfaces\n"); > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 606 goto err; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 607 } > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 608 > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 609 return 0; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 610 > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 611 err: > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 @612 put_device(&adapter->vdpa.dev); > 7ea782fbd896e1 drivers/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2021-06-30 613 kfree(ifcvf_mgmt_dev); > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 614 return ret; > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 615 } > 5a2414bc454e89 drivers/virtio/vdpa/ifcvf/ifcvf_main.c Zhu Lingshan 2020-03-26 616 > > --- > 0-DAY CI Kernel Test Service, Intel Corporation > https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
在 2021/6/30 下午4:21, Zhu Lingshan 写道: > This commit implments the management netlink framework for ifcvf, > including register and add / remove a device > > It works with iprouter2: > [root@localhost lszhu]# vdpa mgmtdev show -jp > { > "mgmtdev": { > "pci/0000:01:00.5": { > "supported_classes": [ "net" ] > }, > "pci/0000:01:00.6": { > "supported_classes": [ "net" ] > } > } > } > > [root@localhost lszhu]# vdpa dev add mgmtdev pci/0000:01:00.5 name vdpa0 > [root@localhost lszhu]# vdpa dev add mgmtdev pci/0000:01:00.6 name vdpa1 > > Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> > --- > drivers/vdpa/ifcvf/ifcvf_base.h | 6 ++ > drivers/vdpa/ifcvf/ifcvf_main.c | 156 ++++++++++++++++++++++++-------- > 2 files changed, 126 insertions(+), 36 deletions(-) > > diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h > index ded1b1b5fb13..e5251fcbb200 100644 > --- a/drivers/vdpa/ifcvf/ifcvf_base.h > +++ b/drivers/vdpa/ifcvf/ifcvf_base.h > @@ -104,6 +104,12 @@ struct ifcvf_lm_cfg { > struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS]; > }; > > +struct ifcvf_vdpa_mgmt_dev { > + struct vdpa_mgmt_dev mdev; > + struct ifcvf_adapter *adapter; > + struct pci_dev *pdev; > +}; > + > int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev); > int ifcvf_start_hw(struct ifcvf_hw *hw); > void ifcvf_stop_hw(struct ifcvf_hw *hw); > diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c > index 5f70ab1283a0..7c2f64ca2163 100644 > --- a/drivers/vdpa/ifcvf/ifcvf_main.c > +++ b/drivers/vdpa/ifcvf/ifcvf_main.c > @@ -442,6 +442,16 @@ static const struct vdpa_config_ops ifc_vdpa_ops = { > .set_config_cb = ifcvf_vdpa_set_config_cb, > }; > > +static struct virtio_device_id id_table_net[] = { > + {VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID}, > + {0}, > +}; > + > +static struct virtio_device_id id_table_blk[] = { > + {VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID}, > + {0}, > +}; > + > static u32 get_dev_type(struct pci_dev *pdev) > { > u32 dev_type; > @@ -462,48 +472,30 @@ static u32 get_dev_type(struct pci_dev *pdev) > return dev_type; > } > > -static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > +static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) > { > - struct device *dev = &pdev->dev; > + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > struct ifcvf_adapter *adapter; > + struct pci_dev *pdev; > struct ifcvf_hw *vf; > + struct device *dev; > int ret, i; > > - ret = pcim_enable_device(pdev); > - if (ret) { > - IFCVF_ERR(pdev, "Failed to enable device\n"); > - return ret; > - } > - > - ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), > - IFCVF_DRIVER_NAME); > - if (ret) { > - IFCVF_ERR(pdev, "Failed to request MMIO region\n"); > - return ret; > - } > - > - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); > - if (ret) { > - IFCVF_ERR(pdev, "No usable DMA configuration\n"); > - return ret; > - } > - > - ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); > - if (ret) { > - IFCVF_ERR(pdev, > - "Failed for adding devres for freeing irq vectors\n"); > - return ret; > - } > + ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); > + if (ifcvf_mgmt_dev->adapter) > + return -EOPNOTSUPP; > > + pdev = ifcvf_mgmt_dev->pdev; > + dev = &pdev->dev; > adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, > - dev, &ifc_vdpa_ops, NULL); > - if (adapter == NULL) { > + dev, &ifc_vdpa_ops, name); > + if (!adapter) { > IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); > return -ENOMEM; > } > > - pci_set_master(pdev); > - pci_set_drvdata(pdev, adapter); > + ifcvf_mgmt_dev->adapter = adapter; > + pci_set_drvdata(pdev, ifcvf_mgmt_dev); > > vf = &adapter->vf; > vf->dev_type = get_dev_type(pdev); > @@ -515,7 +507,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > ret = ifcvf_init_hw(vf, pdev); > if (ret) { > IFCVF_ERR(pdev, "Failed to init IFCVF hw\n"); > - goto err; > + return ret; > } > > for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) > @@ -523,9 +515,94 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > > vf->hw_features = ifcvf_get_hw_features(vf); > > - ret = vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2); > + adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; > + ret = _vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2); > if (ret) { > - IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus"); > + IFCVF_ERR(pdev, "Failed to register to vDPA bus"); > + return ret; > + } > + > + return 0; > +} > + > +static void ifcvf_vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev) > +{ > + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > + > + ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); > + _vdpa_unregister_device(dev); > + ifcvf_mgmt_dev->adapter = NULL; > +} > + > +static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = { > + .dev_add = ifcvf_vdpa_dev_add, > + .dev_del = ifcvf_vdpa_dev_del > +}; > + > +static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > +{ > + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > + struct device *dev = &pdev->dev; > + struct ifcvf_adapter *adapter; adapter is not used. > + u32 dev_type; > + int ret; > + > + ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); > + if (!ifcvf_mgmt_dev) { > + IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); > + return -ENOMEM; > + } > + > + dev_type = get_dev_type(pdev); > + switch (dev_type) { > + case VIRTIO_ID_NET: > + ifcvf_mgmt_dev->mdev.id_table = id_table_net; > + break; > + case VIRTIO_ID_BLOCK: > + ifcvf_mgmt_dev->mdev.id_table = id_table_blk; > + break; > + default: > + IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); > + ret = -EOPNOTSUPP; > + goto err; > + } > + > + ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; > + ifcvf_mgmt_dev->mdev.device = dev; > + ifcvf_mgmt_dev->pdev = pdev; > + > + ret = pcim_enable_device(pdev); > + if (ret) { > + IFCVF_ERR(pdev, "Failed to enable device\n"); > + goto err; > + } > + > + ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), > + IFCVF_DRIVER_NAME); > + if (ret) { > + IFCVF_ERR(pdev, "Failed to request MMIO region\n"); > + goto err; > + } > + > + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); > + if (ret) { > + IFCVF_ERR(pdev, "No usable DMA configuration\n"); > + goto err; > + } > + > + ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); > + if (ret) { > + IFCVF_ERR(pdev, > + "Failed for adding devres for freeing irq vectors\n"); > + goto err; > + } > + > + pci_set_master(pdev); > + > + ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); > + if (ret) { > + IFCVF_ERR(pdev, > + "Failed to initialize the management interfaces\n"); > goto err; > } > > @@ -533,14 +610,21 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > > err: > put_device(&adapter->vdpa.dev); > + kfree(ifcvf_mgmt_dev); > return ret; > } > > static void ifcvf_remove(struct pci_dev *pdev) > { > - struct ifcvf_adapter *adapter = pci_get_drvdata(pdev); > + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > + struct ifcvf_adapter *adapter; > + > + ifcvf_mgmt_dev = pci_get_drvdata(pdev); > + adapter = ifcvf_mgmt_dev->adapter; > + if (adapter) > + vdpa_unregister_device(&adapter->vdpa); > > - vdpa_unregister_device(&adapter->vdpa); > + kfree(ifcvf_mgmt_dev); > } Let's use vdpa_mgmtdev_register() to be more safe. Thanks > > static struct pci_device_id ifcvf_pci_ids[] = {
On Mon, Jul 05, 2021 at 01:04:11PM +0800, Jason Wang wrote: > > +static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > > +{ > > + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; > > + struct device *dev = &pdev->dev; > > + struct ifcvf_adapter *adapter; > > > adapter is not used. It's used in error handling below. It's not *initialized*. > > > + u32 dev_type; > > + int ret; > > + > > + ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); > > + if (!ifcvf_mgmt_dev) { > > + IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); > > + return -ENOMEM; > > + } > > + > > + dev_type = get_dev_type(pdev); > > + switch (dev_type) { > > + case VIRTIO_ID_NET: > > + ifcvf_mgmt_dev->mdev.id_table = id_table_net; > > + break; > > + case VIRTIO_ID_BLOCK: > > + ifcvf_mgmt_dev->mdev.id_table = id_table_blk; > > + break; > > + default: > > + IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); > > + ret = -EOPNOTSUPP; > > + goto err; > > + } > > + > > + ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; > > + ifcvf_mgmt_dev->mdev.device = dev; > > + ifcvf_mgmt_dev->pdev = pdev; > > + > > + ret = pcim_enable_device(pdev); > > + if (ret) { > > + IFCVF_ERR(pdev, "Failed to enable device\n"); > > + goto err; > > + } > > + > > + ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), > > + IFCVF_DRIVER_NAME); > > + if (ret) { > > + IFCVF_ERR(pdev, "Failed to request MMIO region\n"); > > + goto err; > > + } > > + > > + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); > > + if (ret) { > > + IFCVF_ERR(pdev, "No usable DMA configuration\n"); > > + goto err; > > + } > > + > > + ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); > > + if (ret) { > > + IFCVF_ERR(pdev, > > + "Failed for adding devres for freeing irq vectors\n"); > > + goto err; > > + } > > + > > + pci_set_master(pdev); > > + > > + ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); > > + if (ret) { > > + IFCVF_ERR(pdev, > > + "Failed to initialize the management interfaces\n"); > > goto err; > > } > > @@ -533,14 +610,21 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) > > err: > > put_device(&adapter->vdpa.dev); > > + kfree(ifcvf_mgmt_dev); > > return ret; > > }
On 7/5/2021 2:34 PM, Michael S. Tsirkin wrote: > On Mon, Jul 05, 2021 at 01:04:11PM +0800, Jason Wang wrote: >>> +static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) >>> +{ >>> + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; >>> + struct device *dev = &pdev->dev; >>> + struct ifcvf_adapter *adapter; >> >> adapter is not used. > It's used in error handling below. It's not *initialized*. sorry, my bad. I think I should move adapter related error handling code into ifcvf_vdpa_dev_add(), probe() does not see adapter anymore, only struct ifcvf_vdpa_mgmt_dev. Thanks > >>> + u32 dev_type; >>> + int ret; >>> + >>> + ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); >>> + if (!ifcvf_mgmt_dev) { >>> + IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); >>> + return -ENOMEM; >>> + } >>> + >>> + dev_type = get_dev_type(pdev); >>> + switch (dev_type) { >>> + case VIRTIO_ID_NET: >>> + ifcvf_mgmt_dev->mdev.id_table = id_table_net; >>> + break; >>> + case VIRTIO_ID_BLOCK: >>> + ifcvf_mgmt_dev->mdev.id_table = id_table_blk; >>> + break; >>> + default: >>> + IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); >>> + ret = -EOPNOTSUPP; >>> + goto err; >>> + } >>> + >>> + ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; >>> + ifcvf_mgmt_dev->mdev.device = dev; >>> + ifcvf_mgmt_dev->pdev = pdev; >>> + >>> + ret = pcim_enable_device(pdev); >>> + if (ret) { >>> + IFCVF_ERR(pdev, "Failed to enable device\n"); >>> + goto err; >>> + } >>> + >>> + ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), >>> + IFCVF_DRIVER_NAME); >>> + if (ret) { >>> + IFCVF_ERR(pdev, "Failed to request MMIO region\n"); >>> + goto err; >>> + } >>> + >>> + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); >>> + if (ret) { >>> + IFCVF_ERR(pdev, "No usable DMA configuration\n"); >>> + goto err; >>> + } >>> + >>> + ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); >>> + if (ret) { >>> + IFCVF_ERR(pdev, >>> + "Failed for adding devres for freeing irq vectors\n"); >>> + goto err; >>> + } >>> + >>> + pci_set_master(pdev); >>> + >>> + ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); >>> + if (ret) { >>> + IFCVF_ERR(pdev, >>> + "Failed to initialize the management interfaces\n"); >>> goto err; >>> } >>> @@ -533,14 +610,21 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) >>> err: >>> put_device(&adapter->vdpa.dev); >>> + kfree(ifcvf_mgmt_dev); >>> return ret; >>> }
diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h index ded1b1b5fb13..e5251fcbb200 100644 --- a/drivers/vdpa/ifcvf/ifcvf_base.h +++ b/drivers/vdpa/ifcvf/ifcvf_base.h @@ -104,6 +104,12 @@ struct ifcvf_lm_cfg { struct ifcvf_vring_lm_cfg vring_lm_cfg[IFCVF_MAX_QUEUE_PAIRS]; }; +struct ifcvf_vdpa_mgmt_dev { + struct vdpa_mgmt_dev mdev; + struct ifcvf_adapter *adapter; + struct pci_dev *pdev; +}; + int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *dev); int ifcvf_start_hw(struct ifcvf_hw *hw); void ifcvf_stop_hw(struct ifcvf_hw *hw); diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index 5f70ab1283a0..7c2f64ca2163 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -442,6 +442,16 @@ static const struct vdpa_config_ops ifc_vdpa_ops = { .set_config_cb = ifcvf_vdpa_set_config_cb, }; +static struct virtio_device_id id_table_net[] = { + {VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID}, + {0}, +}; + +static struct virtio_device_id id_table_blk[] = { + {VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID}, + {0}, +}; + static u32 get_dev_type(struct pci_dev *pdev) { u32 dev_type; @@ -462,48 +472,30 @@ static u32 get_dev_type(struct pci_dev *pdev) return dev_type; } -static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) +static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) { - struct device *dev = &pdev->dev; + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; struct ifcvf_adapter *adapter; + struct pci_dev *pdev; struct ifcvf_hw *vf; + struct device *dev; int ret, i; - ret = pcim_enable_device(pdev); - if (ret) { - IFCVF_ERR(pdev, "Failed to enable device\n"); - return ret; - } - - ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), - IFCVF_DRIVER_NAME); - if (ret) { - IFCVF_ERR(pdev, "Failed to request MMIO region\n"); - return ret; - } - - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); - if (ret) { - IFCVF_ERR(pdev, "No usable DMA configuration\n"); - return ret; - } - - ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); - if (ret) { - IFCVF_ERR(pdev, - "Failed for adding devres for freeing irq vectors\n"); - return ret; - } + ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); + if (ifcvf_mgmt_dev->adapter) + return -EOPNOTSUPP; + pdev = ifcvf_mgmt_dev->pdev; + dev = &pdev->dev; adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, - dev, &ifc_vdpa_ops, NULL); - if (adapter == NULL) { + dev, &ifc_vdpa_ops, name); + if (!adapter) { IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); return -ENOMEM; } - pci_set_master(pdev); - pci_set_drvdata(pdev, adapter); + ifcvf_mgmt_dev->adapter = adapter; + pci_set_drvdata(pdev, ifcvf_mgmt_dev); vf = &adapter->vf; vf->dev_type = get_dev_type(pdev); @@ -515,7 +507,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret = ifcvf_init_hw(vf, pdev); if (ret) { IFCVF_ERR(pdev, "Failed to init IFCVF hw\n"); - goto err; + return ret; } for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) @@ -523,9 +515,94 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) vf->hw_features = ifcvf_get_hw_features(vf); - ret = vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2); + adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; + ret = _vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2); if (ret) { - IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus"); + IFCVF_ERR(pdev, "Failed to register to vDPA bus"); + return ret; + } + + return 0; +} + +static void ifcvf_vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev) +{ + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; + + ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev); + _vdpa_unregister_device(dev); + ifcvf_mgmt_dev->adapter = NULL; +} + +static const struct vdpa_mgmtdev_ops ifcvf_vdpa_mgmt_dev_ops = { + .dev_add = ifcvf_vdpa_dev_add, + .dev_del = ifcvf_vdpa_dev_del +}; + +static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; + struct device *dev = &pdev->dev; + struct ifcvf_adapter *adapter; + u32 dev_type; + int ret; + + ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); + if (!ifcvf_mgmt_dev) { + IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); + return -ENOMEM; + } + + dev_type = get_dev_type(pdev); + switch (dev_type) { + case VIRTIO_ID_NET: + ifcvf_mgmt_dev->mdev.id_table = id_table_net; + break; + case VIRTIO_ID_BLOCK: + ifcvf_mgmt_dev->mdev.id_table = id_table_blk; + break; + default: + IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", dev_type); + ret = -EOPNOTSUPP; + goto err; + } + + ifcvf_mgmt_dev->mdev.ops = &ifcvf_vdpa_mgmt_dev_ops; + ifcvf_mgmt_dev->mdev.device = dev; + ifcvf_mgmt_dev->pdev = pdev; + + ret = pcim_enable_device(pdev); + if (ret) { + IFCVF_ERR(pdev, "Failed to enable device\n"); + goto err; + } + + ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4), + IFCVF_DRIVER_NAME); + if (ret) { + IFCVF_ERR(pdev, "Failed to request MMIO region\n"); + goto err; + } + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (ret) { + IFCVF_ERR(pdev, "No usable DMA configuration\n"); + goto err; + } + + ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); + if (ret) { + IFCVF_ERR(pdev, + "Failed for adding devres for freeing irq vectors\n"); + goto err; + } + + pci_set_master(pdev); + + ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev); + if (ret) { + IFCVF_ERR(pdev, + "Failed to initialize the management interfaces\n"); goto err; } @@ -533,14 +610,21 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) err: put_device(&adapter->vdpa.dev); + kfree(ifcvf_mgmt_dev); return ret; } static void ifcvf_remove(struct pci_dev *pdev) { - struct ifcvf_adapter *adapter = pci_get_drvdata(pdev); + struct ifcvf_vdpa_mgmt_dev *ifcvf_mgmt_dev; + struct ifcvf_adapter *adapter; + + ifcvf_mgmt_dev = pci_get_drvdata(pdev); + adapter = ifcvf_mgmt_dev->adapter; + if (adapter) + vdpa_unregister_device(&adapter->vdpa); - vdpa_unregister_device(&adapter->vdpa); + kfree(ifcvf_mgmt_dev); } static struct pci_device_id ifcvf_pci_ids[] = {
This commit implments the management netlink framework for ifcvf, including register and add / remove a device It works with iprouter2: [root@localhost lszhu]# vdpa mgmtdev show -jp { "mgmtdev": { "pci/0000:01:00.5": { "supported_classes": [ "net" ] }, "pci/0000:01:00.6": { "supported_classes": [ "net" ] } } } [root@localhost lszhu]# vdpa dev add mgmtdev pci/0000:01:00.5 name vdpa0 [root@localhost lszhu]# vdpa dev add mgmtdev pci/0000:01:00.6 name vdpa1 Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> --- drivers/vdpa/ifcvf/ifcvf_base.h | 6 ++ drivers/vdpa/ifcvf/ifcvf_main.c | 156 ++++++++++++++++++++++++-------- 2 files changed, 126 insertions(+), 36 deletions(-)