@@ -86,8 +86,17 @@ DEFINE_SPINLOCK(ap_queues_lock);
8686/* Default permissions (ioctl, card and domain masking) */
8787struct ap_perms ap_perms ;
8888EXPORT_SYMBOL (ap_perms );
89- DEFINE_MUTEX (ap_perms_mutex );
90- EXPORT_SYMBOL (ap_perms_mutex );
89+ /* true if apmask and/or aqmask are NOT default */
90+ bool ap_apmask_aqmask_in_use ;
91+ /* counter for how many driver_overrides are currently active */
92+ int ap_driver_override_ctr ;
93+ /*
94+ * Mutex for consistent read and write of the ap_perms struct,
95+ * ap_apmask_aqmask_in_use, ap_driver_override_ctr
96+ * and the ap bus sysfs attributes apmask and aqmask.
97+ */
98+ DEFINE_MUTEX (ap_attr_mutex );
99+ EXPORT_SYMBOL (ap_attr_mutex );
91100
92101/* # of bindings complete since init */
93102static atomic64_t ap_bindings_complete_count = ATOMIC64_INIT (0 );
@@ -853,20 +862,38 @@ static int __ap_revise_reserved(struct device *dev, void *dummy)
853862 int rc , card , queue , devres , drvres ;
854863
855864 if (is_queue_dev (dev )) {
856- card = AP_QID_CARD (to_ap_queue (dev )-> qid );
857- queue = AP_QID_QUEUE (to_ap_queue (dev )-> qid );
858- mutex_lock (& ap_perms_mutex );
859- devres = test_bit_inv (card , ap_perms .apm ) &&
860- test_bit_inv (queue , ap_perms .aqm );
861- mutex_unlock (& ap_perms_mutex );
862- drvres = to_ap_drv (dev -> driver )-> flags
863- & AP_DRIVER_FLAG_DEFAULT ;
864- if (!!devres != !!drvres ) {
865- pr_debug ("reprobing queue=%02x.%04x\n" , card , queue );
866- rc = device_reprobe (dev );
867- if (rc )
868- AP_DBF_WARN ("%s reprobing queue=%02x.%04x failed\n" ,
869- __func__ , card , queue );
865+ struct ap_driver * ap_drv = to_ap_drv (dev -> driver );
866+ struct ap_queue * aq = to_ap_queue (dev );
867+ struct ap_device * ap_dev = & aq -> ap_dev ;
868+
869+ card = AP_QID_CARD (aq -> qid );
870+ queue = AP_QID_QUEUE (aq -> qid );
871+
872+ if (ap_dev -> driver_override ) {
873+ if (strcmp (ap_dev -> driver_override ,
874+ ap_drv -> driver .name )) {
875+ pr_debug ("reprobing queue=%02x.%04x\n" , card , queue );
876+ rc = device_reprobe (dev );
877+ if (rc ) {
878+ AP_DBF_WARN ("%s reprobing queue=%02x.%04x failed\n" ,
879+ __func__ , card , queue );
880+ }
881+ }
882+ } else {
883+ mutex_lock (& ap_attr_mutex );
884+ devres = test_bit_inv (card , ap_perms .apm ) &&
885+ test_bit_inv (queue , ap_perms .aqm );
886+ mutex_unlock (& ap_attr_mutex );
887+ drvres = to_ap_drv (dev -> driver )-> flags
888+ & AP_DRIVER_FLAG_DEFAULT ;
889+ if (!!devres != !!drvres ) {
890+ pr_debug ("reprobing queue=%02x.%04x\n" , card , queue );
891+ rc = device_reprobe (dev );
892+ if (rc ) {
893+ AP_DBF_WARN ("%s reprobing queue=%02x.%04x failed\n" ,
894+ __func__ , card , queue );
895+ }
896+ }
870897 }
871898 }
872899
@@ -884,22 +911,37 @@ static void ap_bus_revise_bindings(void)
884911 * @card: the APID of the adapter card to check
885912 * @queue: the APQI of the queue to check
886913 *
887- * Note: the ap_perms_mutex must be locked by the caller of this function.
914+ * Note: the ap_attr_mutex must be locked by the caller of this function.
888915 *
889916 * Return: an int specifying whether the AP adapter is reserved for the host (1)
890917 * or not (0).
891918 */
892919int ap_owned_by_def_drv (int card , int queue )
893920{
921+ struct ap_queue * aq ;
894922 int rc = 0 ;
895923
896924 if (card < 0 || card >= AP_DEVICES || queue < 0 || queue >= AP_DOMAINS )
897925 return - EINVAL ;
898926
927+ aq = ap_get_qdev (AP_MKQID (card , queue ));
928+ if (aq ) {
929+ const struct device_driver * drv = aq -> ap_dev .device .driver ;
930+ const struct ap_driver * ap_drv = to_ap_drv (drv );
931+ bool override = !!aq -> ap_dev .driver_override ;
932+
933+ if (override && drv && ap_drv -> flags & AP_DRIVER_FLAG_DEFAULT )
934+ rc = 1 ;
935+ put_device (& aq -> ap_dev .device );
936+ if (override )
937+ goto out ;
938+ }
939+
899940 if (test_bit_inv (card , ap_perms .apm ) &&
900941 test_bit_inv (queue , ap_perms .aqm ))
901942 rc = 1 ;
902943
944+ out :
903945 return rc ;
904946}
905947EXPORT_SYMBOL (ap_owned_by_def_drv );
@@ -911,7 +953,7 @@ EXPORT_SYMBOL(ap_owned_by_def_drv);
911953 * @apm: a bitmap specifying a set of APIDs comprising the APQNs to check
912954 * @aqm: a bitmap specifying a set of APQIs comprising the APQNs to check
913955 *
914- * Note: the ap_perms_mutex must be locked by the caller of this function.
956+ * Note: the ap_attr_mutex must be locked by the caller of this function.
915957 *
916958 * Return: an int specifying whether each APQN is reserved for the host (1) or
917959 * not (0)
@@ -922,12 +964,10 @@ int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
922964 int card , queue , rc = 0 ;
923965
924966 for (card = 0 ; !rc && card < AP_DEVICES ; card ++ )
925- if (test_bit_inv (card , apm ) &&
926- test_bit_inv (card , ap_perms .apm ))
967+ if (test_bit_inv (card , apm ))
927968 for (queue = 0 ; !rc && queue < AP_DOMAINS ; queue ++ )
928- if (test_bit_inv (queue , aqm ) &&
929- test_bit_inv (queue , ap_perms .aqm ))
930- rc = 1 ;
969+ if (test_bit_inv (queue , aqm ))
970+ rc = ap_owned_by_def_drv (card , queue );
931971
932972 return rc ;
933973}
@@ -951,13 +991,19 @@ static int ap_device_probe(struct device *dev)
951991 */
952992 card = AP_QID_CARD (to_ap_queue (dev )-> qid );
953993 queue = AP_QID_QUEUE (to_ap_queue (dev )-> qid );
954- mutex_lock (& ap_perms_mutex );
955- devres = test_bit_inv (card , ap_perms .apm ) &&
956- test_bit_inv (queue , ap_perms .aqm );
957- mutex_unlock (& ap_perms_mutex );
958- drvres = ap_drv -> flags & AP_DRIVER_FLAG_DEFAULT ;
959- if (!!devres != !!drvres )
960- goto out ;
994+ if (ap_dev -> driver_override ) {
995+ if (strcmp (ap_dev -> driver_override ,
996+ ap_drv -> driver .name ))
997+ goto out ;
998+ } else {
999+ mutex_lock (& ap_attr_mutex );
1000+ devres = test_bit_inv (card , ap_perms .apm ) &&
1001+ test_bit_inv (queue , ap_perms .aqm );
1002+ mutex_unlock (& ap_attr_mutex );
1003+ drvres = ap_drv -> flags & AP_DRIVER_FLAG_DEFAULT ;
1004+ if (!!devres != !!drvres )
1005+ goto out ;
1006+ }
9611007 }
9621008
9631009 /*
@@ -983,8 +1029,17 @@ static int ap_device_probe(struct device *dev)
9831029 }
9841030
9851031out :
986- if (rc )
1032+ if (rc ) {
9871033 put_device (dev );
1034+ } else {
1035+ if (is_queue_dev (dev )) {
1036+ pr_debug ("queue=%02x.%04x new driver=%s\n" ,
1037+ card , queue , ap_drv -> driver .name );
1038+ } else {
1039+ pr_debug ("card=%02x new driver=%s\n" ,
1040+ to_ap_card (dev )-> id , ap_drv -> driver .name );
1041+ }
1042+ }
9881043 return rc ;
9891044}
9901045
@@ -1437,12 +1492,12 @@ static ssize_t apmask_show(const struct bus_type *bus, char *buf)
14371492{
14381493 int rc ;
14391494
1440- if (mutex_lock_interruptible (& ap_perms_mutex ))
1495+ if (mutex_lock_interruptible (& ap_attr_mutex ))
14411496 return - ERESTARTSYS ;
14421497 rc = sysfs_emit (buf , "0x%016lx%016lx%016lx%016lx\n" ,
14431498 ap_perms .apm [0 ], ap_perms .apm [1 ],
14441499 ap_perms .apm [2 ], ap_perms .apm [3 ]);
1445- mutex_unlock (& ap_perms_mutex );
1500+ mutex_unlock (& ap_attr_mutex );
14461501
14471502 return rc ;
14481503}
@@ -1452,6 +1507,7 @@ static int __verify_card_reservations(struct device_driver *drv, void *data)
14521507 int rc = 0 ;
14531508 struct ap_driver * ap_drv = to_ap_drv (drv );
14541509 unsigned long * newapm = (unsigned long * )data ;
1510+ unsigned long aqm_any [BITS_TO_LONGS (AP_DOMAINS )];
14551511
14561512 /*
14571513 * increase the driver's module refcounter to be sure it is not
@@ -1461,7 +1517,8 @@ static int __verify_card_reservations(struct device_driver *drv, void *data)
14611517 return 0 ;
14621518
14631519 if (ap_drv -> in_use ) {
1464- rc = ap_drv -> in_use (newapm , ap_perms .aqm );
1520+ bitmap_fill (aqm_any , AP_DOMAINS );
1521+ rc = ap_drv -> in_use (newapm , aqm_any );
14651522 if (rc )
14661523 rc = - EBUSY ;
14671524 }
@@ -1490,18 +1547,31 @@ static int apmask_commit(unsigned long *newapm)
14901547
14911548 memcpy (ap_perms .apm , newapm , APMASKSIZE );
14921549
1550+ /*
1551+ * Update ap_apmask_aqmask_in_use. Note that the
1552+ * ap_attr_mutex has to be obtained here.
1553+ */
1554+ ap_apmask_aqmask_in_use =
1555+ bitmap_full (ap_perms .apm , AP_DEVICES ) &&
1556+ bitmap_full (ap_perms .aqm , AP_DOMAINS ) ?
1557+ false : true;
1558+
14931559 return 0 ;
14941560}
14951561
14961562static ssize_t apmask_store (const struct bus_type * bus , const char * buf ,
14971563 size_t count )
14981564{
1499- int rc , changes = 0 ;
15001565 DECLARE_BITMAP (newapm , AP_DEVICES );
1566+ int rc = - EINVAL , changes = 0 ;
15011567
1502- if (mutex_lock_interruptible (& ap_perms_mutex ))
1568+ if (mutex_lock_interruptible (& ap_attr_mutex ))
15031569 return - ERESTARTSYS ;
15041570
1571+ /* Do not allow apmask/aqmask if driver override is active */
1572+ if (ap_driver_override_ctr )
1573+ goto done ;
1574+
15051575 rc = ap_parse_bitmap_str (buf , ap_perms .apm , AP_DEVICES , newapm );
15061576 if (rc )
15071577 goto done ;
@@ -1511,7 +1581,7 @@ static ssize_t apmask_store(const struct bus_type *bus, const char *buf,
15111581 rc = apmask_commit (newapm );
15121582
15131583done :
1514- mutex_unlock (& ap_perms_mutex );
1584+ mutex_unlock (& ap_attr_mutex );
15151585 if (rc )
15161586 return rc ;
15171587
@@ -1529,12 +1599,12 @@ static ssize_t aqmask_show(const struct bus_type *bus, char *buf)
15291599{
15301600 int rc ;
15311601
1532- if (mutex_lock_interruptible (& ap_perms_mutex ))
1602+ if (mutex_lock_interruptible (& ap_attr_mutex ))
15331603 return - ERESTARTSYS ;
15341604 rc = sysfs_emit (buf , "0x%016lx%016lx%016lx%016lx\n" ,
15351605 ap_perms .aqm [0 ], ap_perms .aqm [1 ],
15361606 ap_perms .aqm [2 ], ap_perms .aqm [3 ]);
1537- mutex_unlock (& ap_perms_mutex );
1607+ mutex_unlock (& ap_attr_mutex );
15381608
15391609 return rc ;
15401610}
@@ -1544,6 +1614,7 @@ static int __verify_queue_reservations(struct device_driver *drv, void *data)
15441614 int rc = 0 ;
15451615 struct ap_driver * ap_drv = to_ap_drv (drv );
15461616 unsigned long * newaqm = (unsigned long * )data ;
1617+ unsigned long apm_any [BITS_TO_LONGS (AP_DEVICES )];
15471618
15481619 /*
15491620 * increase the driver's module refcounter to be sure it is not
@@ -1553,7 +1624,8 @@ static int __verify_queue_reservations(struct device_driver *drv, void *data)
15531624 return 0 ;
15541625
15551626 if (ap_drv -> in_use ) {
1556- rc = ap_drv -> in_use (ap_perms .apm , newaqm );
1627+ bitmap_fill (apm_any , AP_DEVICES );
1628+ rc = ap_drv -> in_use (apm_any , newaqm );
15571629 if (rc )
15581630 rc = - EBUSY ;
15591631 }
@@ -1582,18 +1654,31 @@ static int aqmask_commit(unsigned long *newaqm)
15821654
15831655 memcpy (ap_perms .aqm , newaqm , AQMASKSIZE );
15841656
1657+ /*
1658+ * Update ap_apmask_aqmask_in_use. Note that the
1659+ * ap_attr_mutex has to be obtained here.
1660+ */
1661+ ap_apmask_aqmask_in_use =
1662+ bitmap_full (ap_perms .apm , AP_DEVICES ) &&
1663+ bitmap_full (ap_perms .aqm , AP_DOMAINS ) ?
1664+ false : true;
1665+
15851666 return 0 ;
15861667}
15871668
15881669static ssize_t aqmask_store (const struct bus_type * bus , const char * buf ,
15891670 size_t count )
15901671{
1591- int rc , changes = 0 ;
15921672 DECLARE_BITMAP (newaqm , AP_DOMAINS );
1673+ int rc = - EINVAL , changes = 0 ;
15931674
1594- if (mutex_lock_interruptible (& ap_perms_mutex ))
1675+ if (mutex_lock_interruptible (& ap_attr_mutex ))
15951676 return - ERESTARTSYS ;
15961677
1678+ /* Do not allow apmask/aqmask if driver override is active */
1679+ if (ap_driver_override_ctr )
1680+ goto done ;
1681+
15971682 rc = ap_parse_bitmap_str (buf , ap_perms .aqm , AP_DOMAINS , newaqm );
15981683 if (rc )
15991684 goto done ;
@@ -1603,7 +1688,7 @@ static ssize_t aqmask_store(const struct bus_type *bus, const char *buf,
16031688 rc = aqmask_commit (newaqm );
16041689
16051690done :
1606- mutex_unlock (& ap_perms_mutex );
1691+ mutex_unlock (& ap_attr_mutex );
16071692 if (rc )
16081693 return rc ;
16091694
@@ -2474,14 +2559,14 @@ static void __init ap_perms_init(void)
24742559 if (apm_str ) {
24752560 memset (& ap_perms .apm , 0 , sizeof (ap_perms .apm ));
24762561 ap_parse_mask_str (apm_str , ap_perms .apm , AP_DEVICES ,
2477- & ap_perms_mutex );
2562+ & ap_attr_mutex );
24782563 }
24792564
24802565 /* aqm kernel parameter string */
24812566 if (aqm_str ) {
24822567 memset (& ap_perms .aqm , 0 , sizeof (ap_perms .aqm ));
24832568 ap_parse_mask_str (aqm_str , ap_perms .aqm , AP_DOMAINS ,
2484- & ap_perms_mutex );
2569+ & ap_attr_mutex );
24852570 }
24862571}
24872572
0 commit comments