@@ -3696,48 +3696,6 @@ static int hv_send_resources_released(struct hv_device *hdev)
36963696 return 0 ;
36973697}
36983698
3699- #define HVPCI_DOM_MAP_SIZE (64 * 1024)
3700- static DECLARE_BITMAP (hvpci_dom_map , HVPCI_DOM_MAP_SIZE ) ;
3701-
3702- /*
3703- * PCI domain number 0 is used by emulated devices on Gen1 VMs, so define 0
3704- * as invalid for passthrough PCI devices of this driver.
3705- */
3706- #define HVPCI_DOM_INVALID 0
3707-
3708- /**
3709- * hv_get_dom_num() - Get a valid PCI domain number
3710- * Check if the PCI domain number is in use, and return another number if
3711- * it is in use.
3712- *
3713- * @dom: Requested domain number
3714- *
3715- * return: domain number on success, HVPCI_DOM_INVALID on failure
3716- */
3717- static u16 hv_get_dom_num (u16 dom )
3718- {
3719- unsigned int i ;
3720-
3721- if (test_and_set_bit (dom , hvpci_dom_map ) == 0 )
3722- return dom ;
3723-
3724- for_each_clear_bit (i , hvpci_dom_map , HVPCI_DOM_MAP_SIZE ) {
3725- if (test_and_set_bit (i , hvpci_dom_map ) == 0 )
3726- return i ;
3727- }
3728-
3729- return HVPCI_DOM_INVALID ;
3730- }
3731-
3732- /**
3733- * hv_put_dom_num() - Mark the PCI domain number as free
3734- * @dom: Domain number to be freed
3735- */
3736- static void hv_put_dom_num (u16 dom )
3737- {
3738- clear_bit (dom , hvpci_dom_map );
3739- }
3740-
37413699/**
37423700 * hv_pci_probe() - New VMBus channel probe, for a root PCI bus
37433701 * @hdev: VMBus's tracking struct for this root PCI bus
@@ -3750,9 +3708,9 @@ static int hv_pci_probe(struct hv_device *hdev,
37503708{
37513709 struct pci_host_bridge * bridge ;
37523710 struct hv_pcibus_device * hbus ;
3753- u16 dom_req , dom ;
3711+ int ret , dom ;
3712+ u16 dom_req ;
37543713 char * name ;
3755- int ret ;
37563714
37573715 bridge = devm_pci_alloc_host_bridge (& hdev -> device , 0 );
37583716 if (!bridge )
@@ -3779,11 +3737,14 @@ static int hv_pci_probe(struct hv_device *hdev,
37793737 * PCI bus (which is actually emulated by the hypervisor) is domain 0.
37803738 * (2) There will be no overlap between domains (after fixing possible
37813739 * collisions) in the same VM.
3740+ *
3741+ * Because Gen1 VMs use domain 0, don't allow picking domain 0 here,
3742+ * even if bytes 4 and 5 of the instance GUID are both zero. For wider
3743+ * userspace compatibility, limit the domain ID to a 16-bit value.
37823744 */
37833745 dom_req = hdev -> dev_instance .b [5 ] << 8 | hdev -> dev_instance .b [4 ];
3784- dom = hv_get_dom_num (dom_req );
3785-
3786- if (dom == HVPCI_DOM_INVALID ) {
3746+ dom = pci_bus_find_emul_domain_nr (dom_req , 1 , U16_MAX );
3747+ if (dom < 0 ) {
37873748 dev_err (& hdev -> device ,
37883749 "Unable to use dom# 0x%x or other numbers" , dom_req );
37893750 ret = - EINVAL ;
@@ -3917,7 +3878,7 @@ static int hv_pci_probe(struct hv_device *hdev,
39173878destroy_wq :
39183879 destroy_workqueue (hbus -> wq );
39193880free_dom :
3920- hv_put_dom_num (hbus -> bridge -> domain_nr );
3881+ pci_bus_release_emul_domain_nr (hbus -> bridge -> domain_nr );
39213882free_bus :
39223883 kfree (hbus );
39233884 return ret ;
@@ -4042,8 +4003,6 @@ static void hv_pci_remove(struct hv_device *hdev)
40424003 irq_domain_remove (hbus -> irq_domain );
40434004 irq_domain_free_fwnode (hbus -> fwnode );
40444005
4045- hv_put_dom_num (hbus -> bridge -> domain_nr );
4046-
40474006 kfree (hbus );
40484007}
40494008
@@ -4217,9 +4176,6 @@ static int __init init_hv_pci_drv(void)
42174176 if (ret )
42184177 return ret ;
42194178
4220- /* Set the invalid domain number's bit, so it will not be used */
4221- set_bit (HVPCI_DOM_INVALID , hvpci_dom_map );
4222-
42234179 /* Initialize PCI block r/w interface */
42244180 hvpci_block_ops .read_block = hv_read_config_block ;
42254181 hvpci_block_ops .write_block = hv_write_config_block ;
0 commit comments