Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/ap: Support driver_override for AP queue devices

Add a new sysfs attribute driver_override the AP queue's
directory. Writing in a string overrides the default driver
determination and the drivers are matched against this string
instead. This overrules the driver binding determined by the
apmask/aqmask bitmask fields.

According to the common understanding of how the driver_override
behavior shall work, there is no further checking done. Neither about
the string which is given as override driver nor if this device is
currently in use by an mdev device. Another patch may limit this
behavior to refuse a mixed usage of the driver_override and
apmask/aqmask feature.

As there exists some tooling for this kind of driver_override
(see package driverctl) the AP bus behavior for re-binding
should be compatible to this. The steps for a driver_override are:
1) unbind the current driver from the device. For example
echo "17.0005" > /sys/devices/ap/card17/17.0005/driver/unbind
2) set the new driver for this device in the sysfs
driver_override attribute. For example
echo "vfio_ap" > /sys//devices/ap/card17/17.0005/driver_override
3) trigger a bus reprobe of this device. For example
echo "17.0005" > /sys/bus/ap/drivers_probe
With the driverctl package this is more comfortable and
the settings get persisted:
driverctl -b ap set-override 17.0005 vfio_ap
and unset with
driverctl -b ap unset-override 17.0005

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

authored by

Harald Freudenberger and committed by
Heiko Carstens
d38a87d7 6917f434

+110 -27
+73 -27
drivers/s390/crypto/ap_bus.c
··· 853 853 int rc, card, queue, devres, drvres; 854 854 855 855 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); 856 + struct ap_driver *ap_drv = to_ap_drv(dev->driver); 857 + struct ap_queue *aq = to_ap_queue(dev); 858 + struct ap_device *ap_dev = &aq->ap_dev; 859 + 860 + card = AP_QID_CARD(aq->qid); 861 + queue = AP_QID_QUEUE(aq->qid); 862 + 863 + if (ap_dev->driver_override) { 864 + if (strcmp(ap_dev->driver_override, 865 + ap_drv->driver.name)) { 866 + pr_debug("reprobing queue=%02x.%04x\n", card, queue); 867 + rc = device_reprobe(dev); 868 + if (rc) { 869 + AP_DBF_WARN("%s reprobing queue=%02x.%04x failed\n", 870 + __func__, card, queue); 871 + } 872 + } 873 + } else { 874 + mutex_lock(&ap_perms_mutex); 875 + devres = test_bit_inv(card, ap_perms.apm) && 876 + test_bit_inv(queue, ap_perms.aqm); 877 + mutex_unlock(&ap_perms_mutex); 878 + drvres = to_ap_drv(dev->driver)->flags 879 + & AP_DRIVER_FLAG_DEFAULT; 880 + if (!!devres != !!drvres) { 881 + pr_debug("reprobing queue=%02x.%04x\n", card, queue); 882 + rc = device_reprobe(dev); 883 + if (rc) { 884 + AP_DBF_WARN("%s reprobing queue=%02x.%04x failed\n", 885 + __func__, card, queue); 886 + } 887 + } 870 888 } 871 889 } 872 890 ··· 909 891 */ 910 892 int ap_owned_by_def_drv(int card, int queue) 911 893 { 894 + struct ap_queue *aq; 912 895 int rc = 0; 913 896 914 897 if (card < 0 || card >= AP_DEVICES || queue < 0 || queue >= AP_DOMAINS) 915 898 return -EINVAL; 916 899 900 + aq = ap_get_qdev(AP_MKQID(card, queue)); 901 + if (aq) { 902 + const struct device_driver *drv = aq->ap_dev.device.driver; 903 + const struct ap_driver *ap_drv = to_ap_drv(drv); 904 + bool override = !!aq->ap_dev.driver_override; 905 + 906 + if (override && drv && ap_drv->flags & AP_DRIVER_FLAG_DEFAULT) 907 + rc = 1; 908 + put_device(&aq->ap_dev.device); 909 + if (override) 910 + goto out; 911 + } 912 + 917 913 if (test_bit_inv(card, ap_perms.apm) && 918 914 test_bit_inv(queue, ap_perms.aqm)) 919 915 rc = 1; 920 916 917 + out: 921 918 return rc; 922 919 } 923 920 EXPORT_SYMBOL(ap_owned_by_def_drv); ··· 955 922 int card, queue, rc = 0; 956 923 957 924 for (card = 0; !rc && card < AP_DEVICES; card++) 958 - if (test_bit_inv(card, apm) && 959 - test_bit_inv(card, ap_perms.apm)) 925 + if (test_bit_inv(card, apm)) 960 926 for (queue = 0; !rc && queue < AP_DOMAINS; queue++) 961 - if (test_bit_inv(queue, aqm) && 962 - test_bit_inv(queue, ap_perms.aqm)) 963 - rc = 1; 927 + if (test_bit_inv(queue, aqm)) 928 + rc = ap_owned_by_def_drv(card, queue); 964 929 965 930 return rc; 966 931 } ··· 982 951 */ 983 952 card = AP_QID_CARD(to_ap_queue(dev)->qid); 984 953 queue = AP_QID_QUEUE(to_ap_queue(dev)->qid); 985 - mutex_lock(&ap_perms_mutex); 986 - devres = test_bit_inv(card, ap_perms.apm) && 987 - test_bit_inv(queue, ap_perms.aqm); 988 - mutex_unlock(&ap_perms_mutex); 989 - drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT; 990 - if (!!devres != !!drvres) 991 - goto out; 954 + if (ap_dev->driver_override) { 955 + if (strcmp(ap_dev->driver_override, 956 + ap_drv->driver.name)) 957 + goto out; 958 + } else { 959 + mutex_lock(&ap_perms_mutex); 960 + devres = test_bit_inv(card, ap_perms.apm) && 961 + test_bit_inv(queue, ap_perms.aqm); 962 + mutex_unlock(&ap_perms_mutex); 963 + drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT; 964 + if (!!devres != !!drvres) 965 + goto out; 966 + } 992 967 } 993 968 994 969 /* ··· 1020 983 } 1021 984 1022 985 out: 1023 - if (rc) 986 + if (rc) { 1024 987 put_device(dev); 988 + } else { 989 + if (is_queue_dev(dev)) { 990 + pr_debug("queue=%02x.%04x new driver=%s\n", 991 + card, queue, ap_drv->driver.name); 992 + } else { 993 + pr_debug("card=%02x new driver=%s\n", 994 + to_ap_card(dev)->id, ap_drv->driver.name); 995 + } 996 + } 1025 997 return rc; 1026 998 } 1027 999
+1
drivers/s390/crypto/ap_bus.h
··· 166 166 struct ap_device { 167 167 struct device device; 168 168 int device_type; /* AP device type. */ 169 + const char *driver_override; 169 170 }; 170 171 171 172 #define to_ap_dev(x) container_of((x), struct ap_device, device)
+36
drivers/s390/crypto/ap_queue.c
··· 731 731 732 732 static DEVICE_ATTR_RO(ap_functions); 733 733 734 + static ssize_t driver_override_show(struct device *dev, 735 + struct device_attribute *attr, 736 + char *buf) 737 + { 738 + struct ap_queue *aq = to_ap_queue(dev); 739 + struct ap_device *ap_dev = &aq->ap_dev; 740 + int rc; 741 + 742 + device_lock(dev); 743 + if (ap_dev->driver_override) 744 + rc = sysfs_emit(buf, "%s\n", ap_dev->driver_override); 745 + else 746 + rc = sysfs_emit(buf, "\n"); 747 + device_unlock(dev); 748 + 749 + return rc; 750 + } 751 + 752 + static ssize_t driver_override_store(struct device *dev, 753 + struct device_attribute *attr, 754 + const char *buf, size_t count) 755 + { 756 + struct ap_queue *aq = to_ap_queue(dev); 757 + struct ap_device *ap_dev = &aq->ap_dev; 758 + int rc; 759 + 760 + rc = driver_set_override(dev, &ap_dev->driver_override, buf, count); 761 + if (rc) 762 + return rc; 763 + 764 + return count; 765 + } 766 + 767 + static DEVICE_ATTR_RW(driver_override); 768 + 734 769 #ifdef CONFIG_AP_DEBUG 735 770 static ssize_t states_show(struct device *dev, 736 771 struct device_attribute *attr, char *buf) ··· 878 843 &dev_attr_config.attr, 879 844 &dev_attr_chkstop.attr, 880 845 &dev_attr_ap_functions.attr, 846 + &dev_attr_driver_override.attr, 881 847 #ifdef CONFIG_AP_DEBUG 882 848 &dev_attr_states.attr, 883 849 &dev_attr_last_err_rc.attr,