Re: [PATCH v3 0/2] avoid inserting duplicate IDs in dynids list

2020-11-20 Thread Bjorn Helgaas
On Tue, Nov 17, 2020 at 01:44:07PM +0800, Zhenzhong Duan wrote:
> vfio-pci and pci-stub use new_id to bind devices. But one can add same IDs
> multiple times, for example:
> 
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> -bash: echo: write error: No such device
> 
> This doesn't cause user-visible broken behavior, but not user friendly.
> he has to remove same IDs same times to ensure it's completely gone.
> 
> Changed to only allow one dynamic entry of the same kind, after fix:
> 
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
> -bash: echo: write error: File exists
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> # echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
> -bash: echo: write error: No such device
> 
> 
> v3: add a separate patch to process dependency issue per Bjorn
> make commit log more clear per Bjorn
> v2: revert the export of pci_match_device() per Christoph
> combind PATCH1 and PATCH2 into one.
> 
> v2 link:https://lkml.org/lkml/2020/10/25/347
> 
> Zhenzhong Duan (2):
>   PCI: move pci_match_device() ahead of new_id_store()
>   PCI: avoid duplicate IDs in dynamic IDs list
> 
>  drivers/pci/pci-driver.c | 146 
> +++
>  1 file changed, 73 insertions(+), 73 deletions(-)
> 
> -- 
> 1.8.3.1
> 
> 
> Zhenzhong Duan (2):
>   PCI: move pci_match_device() ahead of new_id_store()
>   PCI: avoid duplicate IDs in dynamic IDs list
> 
>  drivers/pci/pci-driver.c | 146 
> +++
>  1 file changed, 73 insertions(+), 73 deletions(-)

I corrected the subject lines:

  PCI: Move pci_match_device() ahead of new_id_store()
  PCI: Avoid duplicate IDs in driver dynamic IDs list

and applied both to pci/enumeration for v5.11, thanks!


[PATCH v3 0/2] avoid inserting duplicate IDs in dynids list

2020-11-16 Thread Zhenzhong Duan
vfio-pci and pci-stub use new_id to bind devices. But one can add same IDs
multiple times, for example:

# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
-bash: echo: write error: No such device

This doesn't cause user-visible broken behavior, but not user friendly.
he has to remove same IDs same times to ensure it's completely gone.

Changed to only allow one dynamic entry of the same kind, after fix:

# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
-bash: echo: write error: File exists
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
# echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/remove_id
-bash: echo: write error: No such device


v3: add a separate patch to process dependency issue per Bjorn
make commit log more clear per Bjorn
v2: revert the export of pci_match_device() per Christoph
combind PATCH1 and PATCH2 into one.

v2 link:https://lkml.org/lkml/2020/10/25/347

Zhenzhong Duan (2):
  PCI: move pci_match_device() ahead of new_id_store()
  PCI: avoid duplicate IDs in dynamic IDs list

 drivers/pci/pci-driver.c | 146 +++
 1 file changed, 73 insertions(+), 73 deletions(-)

-- 
1.8.3.1


Zhenzhong Duan (2):
  PCI: move pci_match_device() ahead of new_id_store()
  PCI: avoid duplicate IDs in dynamic IDs list

 drivers/pci/pci-driver.c | 146 +++
 1 file changed, 73 insertions(+), 73 deletions(-)

-- 
1.8.3.1