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

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux

Pull s390 updates from Martin Schwidefsky:
"common I/O layer
- Fix bit-fields crossing storage-unit boundaries in css_general_char

dasd driver
- Avoid a sparse warning in regard to the queue lock
- Allocate the struct dasd_ccw_req as per request data. Only for
internal I/O is the structure allocated separately
- Remove the unused function dasd_kmalloc_set_cda
- Save a few bytes in struct dasd_ccw_req by reordering fields
- Convert remaining users of dasd_kmalloc_request to
dasd_smalloc_request and remove the now unused function

vfio/ccw
- Refactor and improve pfn_array_alloc_pin/pfn_array_pin
- Add a new tracepoint for failed vfio/ccw requests
- Add a CCW translation improvement to accept more requests as valid
- Bug fixes"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux:
s390/dasd: only use preallocated requests
s390/dasd: reshuffle struct dasd_ccw_req
s390/dasd: remove dasd_kmalloc_set_cda
s390/dasd: move dasd_ccw_req to per request data
s390/dasd: simplify locking in process_final_queue
s390/cio: sanitize css_general_characteristics definition
vfio: ccw: add tracepoints for interesting error paths
vfio: ccw: set ccw->cda to NULL defensively
vfio: ccw: refactor and improve pfn_array_alloc_pin()
vfio: ccw: shorten kernel doc description for pfn_array_pin()
vfio: ccw: push down unsupported IDA check
vfio: ccw: fix error return in vfio_ccw_sch_event
s390/archrandom: Rework arch random implementation.
s390/net: add pnetid support

+285 -268
+32 -30
arch/s390/include/asm/css_chars.h
··· 6 6 7 7 struct css_general_char { 8 8 u64 : 12; 9 - u32 dynio : 1; /* bit 12 */ 10 - u32 : 4; 11 - u32 eadm : 1; /* bit 17 */ 12 - u32 : 23; 13 - u32 aif : 1; /* bit 41 */ 14 - u32 : 3; 15 - u32 mcss : 1; /* bit 45 */ 16 - u32 fcs : 1; /* bit 46 */ 17 - u32 : 1; 18 - u32 ext_mb : 1; /* bit 48 */ 19 - u32 : 7; 20 - u32 aif_tdd : 1; /* bit 56 */ 21 - u32 : 1; 22 - u32 qebsm : 1; /* bit 58 */ 23 - u32 : 2; 24 - u32 aiv : 1; /* bit 61 */ 25 - u32 : 5; 26 - u32 aif_osa : 1; /* bit 67 */ 27 - u32 : 12; 28 - u32 eadm_rf : 1; /* bit 80 */ 29 - u32 : 1; 30 - u32 cib : 1; /* bit 82 */ 31 - u32 : 5; 32 - u32 fcx : 1; /* bit 88 */ 33 - u32 : 19; 34 - u32 alt_ssi : 1; /* bit 108 */ 35 - u32 : 1; 36 - u32 narf : 1; /* bit 110 */ 37 - u32 : 12; 38 - u32 util_str : 1;/* bit 123 */ 9 + u64 dynio : 1; /* bit 12 */ 10 + u64 : 4; 11 + u64 eadm : 1; /* bit 17 */ 12 + u64 : 23; 13 + u64 aif : 1; /* bit 41 */ 14 + u64 : 3; 15 + u64 mcss : 1; /* bit 45 */ 16 + u64 fcs : 1; /* bit 46 */ 17 + u64 : 1; 18 + u64 ext_mb : 1; /* bit 48 */ 19 + u64 : 7; 20 + u64 aif_tdd : 1; /* bit 56 */ 21 + u64 : 1; 22 + u64 qebsm : 1; /* bit 58 */ 23 + u64 : 2; 24 + u64 aiv : 1; /* bit 61 */ 25 + u64 : 2; 26 + 27 + u64 : 3; 28 + u64 aif_osa : 1; /* bit 67 */ 29 + u64 : 12; 30 + u64 eadm_rf : 1; /* bit 80 */ 31 + u64 : 1; 32 + u64 cib : 1; /* bit 82 */ 33 + u64 : 5; 34 + u64 fcx : 1; /* bit 88 */ 35 + u64 : 19; 36 + u64 alt_ssi : 1; /* bit 108 */ 37 + u64 : 1; 38 + u64 narf : 1; /* bit 110 */ 39 + u64 : 12; 40 + u64 util_str : 1;/* bit 123 */ 39 41 } __packed; 40 42 41 43 extern struct css_general_char css_general_characteristics;
+57 -116
drivers/s390/block/dasd.c
··· 1222 1222 device->hosts_dentry = pde; 1223 1223 } 1224 1224 1225 - /* 1226 - * Allocate memory for a channel program with 'cplength' channel 1227 - * command words and 'datasize' additional space. There are two 1228 - * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed 1229 - * memory and 2) dasd_smalloc_request uses the static ccw memory 1230 - * that gets allocated for each device. 1231 - */ 1232 - struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength, 1233 - int datasize, 1234 - struct dasd_device *device) 1235 - { 1236 - struct dasd_ccw_req *cqr; 1237 - 1238 - /* Sanity checks */ 1239 - BUG_ON(datasize > PAGE_SIZE || 1240 - (cplength*sizeof(struct ccw1)) > PAGE_SIZE); 1241 - 1242 - cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); 1243 - if (cqr == NULL) 1244 - return ERR_PTR(-ENOMEM); 1245 - cqr->cpaddr = NULL; 1246 - if (cplength > 0) { 1247 - cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1), 1248 - GFP_ATOMIC | GFP_DMA); 1249 - if (cqr->cpaddr == NULL) { 1250 - kfree(cqr); 1251 - return ERR_PTR(-ENOMEM); 1252 - } 1253 - } 1254 - cqr->data = NULL; 1255 - if (datasize > 0) { 1256 - cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA); 1257 - if (cqr->data == NULL) { 1258 - kfree(cqr->cpaddr); 1259 - kfree(cqr); 1260 - return ERR_PTR(-ENOMEM); 1261 - } 1262 - } 1263 - cqr->magic = magic; 1264 - set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 1265 - dasd_get_device(device); 1266 - return cqr; 1267 - } 1268 - EXPORT_SYMBOL(dasd_kmalloc_request); 1269 - 1270 - struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, 1271 - int datasize, 1272 - struct dasd_device *device) 1225 + struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize, 1226 + struct dasd_device *device, 1227 + struct dasd_ccw_req *cqr) 1273 1228 { 1274 1229 unsigned long flags; 1275 - struct dasd_ccw_req *cqr; 1276 - char *data; 1277 - int size; 1230 + char *data, *chunk; 1231 + int size = 0; 1278 1232 1279 - size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; 1280 1233 if (cplength > 0) 1281 1234 size += cplength * sizeof(struct ccw1); 1282 1235 if (datasize > 0) 1283 1236 size += datasize; 1237 + if (!cqr) 1238 + size += (sizeof(*cqr) + 7L) & -8L; 1239 + 1284 1240 spin_lock_irqsave(&device->mem_lock, flags); 1285 - cqr = (struct dasd_ccw_req *) 1286 - dasd_alloc_chunk(&device->ccw_chunks, size); 1241 + data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size); 1287 1242 spin_unlock_irqrestore(&device->mem_lock, flags); 1288 - if (cqr == NULL) 1243 + if (!chunk) 1289 1244 return ERR_PTR(-ENOMEM); 1290 - memset(cqr, 0, sizeof(struct dasd_ccw_req)); 1291 - data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); 1292 - cqr->cpaddr = NULL; 1293 - if (cplength > 0) { 1294 - cqr->cpaddr = (struct ccw1 *) data; 1295 - data += cplength*sizeof(struct ccw1); 1296 - memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); 1245 + if (!cqr) { 1246 + cqr = (void *) data; 1247 + data += (sizeof(*cqr) + 7L) & -8L; 1297 1248 } 1298 - cqr->data = NULL; 1249 + memset(cqr, 0, sizeof(*cqr)); 1250 + cqr->mem_chunk = chunk; 1251 + if (cplength > 0) { 1252 + cqr->cpaddr = data; 1253 + data += cplength * sizeof(struct ccw1); 1254 + memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1)); 1255 + } 1299 1256 if (datasize > 0) { 1300 1257 cqr->data = data; 1301 1258 memset(cqr->data, 0, datasize); ··· 1264 1307 } 1265 1308 EXPORT_SYMBOL(dasd_smalloc_request); 1266 1309 1267 - /* 1268 - * Free memory of a channel program. This function needs to free all the 1269 - * idal lists that might have been created by dasd_set_cda and the 1270 - * struct dasd_ccw_req itself. 1271 - */ 1272 - void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) 1273 - { 1274 - struct ccw1 *ccw; 1275 - 1276 - /* Clear any idals used for the request. */ 1277 - ccw = cqr->cpaddr; 1278 - do { 1279 - clear_normalized_cda(ccw); 1280 - } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC)); 1281 - kfree(cqr->cpaddr); 1282 - kfree(cqr->data); 1283 - kfree(cqr); 1284 - dasd_put_device(device); 1285 - } 1286 - EXPORT_SYMBOL(dasd_kfree_request); 1287 - 1288 1310 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) 1289 1311 { 1290 1312 unsigned long flags; 1291 1313 1292 1314 spin_lock_irqsave(&device->mem_lock, flags); 1293 - dasd_free_chunk(&device->ccw_chunks, cqr); 1315 + dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk); 1294 1316 spin_unlock_irqrestore(&device->mem_lock, flags); 1295 1317 dasd_put_device(device); 1296 1318 } ··· 1821 1885 } 1822 1886 } 1823 1887 1888 + static void __dasd_process_cqr(struct dasd_device *device, 1889 + struct dasd_ccw_req *cqr) 1890 + { 1891 + char errorstring[ERRORLENGTH]; 1892 + 1893 + switch (cqr->status) { 1894 + case DASD_CQR_SUCCESS: 1895 + cqr->status = DASD_CQR_DONE; 1896 + break; 1897 + case DASD_CQR_ERROR: 1898 + cqr->status = DASD_CQR_NEED_ERP; 1899 + break; 1900 + case DASD_CQR_CLEARED: 1901 + cqr->status = DASD_CQR_TERMINATED; 1902 + break; 1903 + default: 1904 + /* internal error 12 - wrong cqr status*/ 1905 + snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status); 1906 + dev_err(&device->cdev->dev, 1907 + "An error occurred in the DASD device driver, " 1908 + "reason=%s\n", errorstring); 1909 + BUG(); 1910 + } 1911 + if (cqr->callback) 1912 + cqr->callback(cqr, cqr->callback_data); 1913 + } 1914 + 1824 1915 /* 1825 1916 * the cqrs from the final queue are returned to the upper layer 1826 1917 * by setting a dasd_block state and calling the callback function ··· 1858 1895 struct list_head *l, *n; 1859 1896 struct dasd_ccw_req *cqr; 1860 1897 struct dasd_block *block; 1861 - void (*callback)(struct dasd_ccw_req *, void *data); 1862 - void *callback_data; 1863 - char errorstring[ERRORLENGTH]; 1864 1898 1865 1899 list_for_each_safe(l, n, final_queue) { 1866 1900 cqr = list_entry(l, struct dasd_ccw_req, devlist); 1867 1901 list_del_init(&cqr->devlist); 1868 1902 block = cqr->block; 1869 - callback = cqr->callback; 1870 - callback_data = cqr->callback_data; 1871 - if (block) 1903 + if (!block) { 1904 + __dasd_process_cqr(device, cqr); 1905 + } else { 1872 1906 spin_lock_bh(&block->queue_lock); 1873 - switch (cqr->status) { 1874 - case DASD_CQR_SUCCESS: 1875 - cqr->status = DASD_CQR_DONE; 1876 - break; 1877 - case DASD_CQR_ERROR: 1878 - cqr->status = DASD_CQR_NEED_ERP; 1879 - break; 1880 - case DASD_CQR_CLEARED: 1881 - cqr->status = DASD_CQR_TERMINATED; 1882 - break; 1883 - default: 1884 - /* internal error 12 - wrong cqr status*/ 1885 - snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status); 1886 - dev_err(&device->cdev->dev, 1887 - "An error occurred in the DASD device driver, " 1888 - "reason=%s\n", errorstring); 1889 - BUG(); 1890 - } 1891 - if (cqr->callback != NULL) 1892 - (callback)(cqr, callback_data); 1893 - if (block) 1907 + __dasd_process_cqr(device, cqr); 1894 1908 spin_unlock_bh(&block->queue_lock); 1909 + } 1895 1910 } 1896 1911 } 1897 1912 ··· 2982 3041 cqr->callback_data = req; 2983 3042 cqr->status = DASD_CQR_FILLED; 2984 3043 cqr->dq = dq; 2985 - *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req)) = cqr; 2986 3044 2987 3045 blk_mq_start_request(req); 2988 3046 spin_lock(&block->queue_lock); ··· 3012 3072 unsigned long flags; 3013 3073 int rc = 0; 3014 3074 3015 - cqr = *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req)); 3075 + cqr = blk_mq_rq_to_pdu(req); 3016 3076 if (!cqr) 3017 3077 return BLK_EH_DONE; 3018 3078 ··· 3114 3174 int rc; 3115 3175 3116 3176 block->tag_set.ops = &dasd_mq_ops; 3117 - block->tag_set.cmd_size = sizeof(struct dasd_ccw_req *); 3177 + block->tag_set.cmd_size = sizeof(struct dasd_ccw_req); 3118 3178 block->tag_set.nr_hw_queues = DASD_NR_HW_QUEUES; 3119 3179 block->tag_set.queue_depth = DASD_MAX_LCU_DEV * DASD_REQ_PER_DEV; 3120 3180 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; ··· 3978 4038 struct ccw1 *ccw; 3979 4039 unsigned long *idaw; 3980 4040 3981 - cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device); 4041 + cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device, 4042 + NULL); 3982 4043 3983 4044 if (IS_ERR(cqr)) { 3984 4045 /* internal error 13 - Allocating the RDC request failed*/
+3 -3
drivers/s390/block/dasd_alias.c
··· 407 407 int rc; 408 408 unsigned long flags; 409 409 410 - cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 410 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 411 411 (sizeof(struct dasd_psf_prssd_data)), 412 - device); 412 + device, NULL); 413 413 if (IS_ERR(cqr)) 414 414 return PTR_ERR(cqr); 415 415 cqr->startdev = device; ··· 457 457 lcu->flags |= NEED_UAC_UPDATE; 458 458 spin_unlock_irqrestore(&lcu->lock, flags); 459 459 } 460 - dasd_kfree_request(cqr, cqr->memdev); 460 + dasd_sfree_request(cqr, cqr->memdev); 461 461 return rc; 462 462 } 463 463
+2 -1
drivers/s390/block/dasd_diag.c
··· 536 536 /* Build the request */ 537 537 datasize = sizeof(struct dasd_diag_req) + 538 538 count*sizeof(struct dasd_diag_bio); 539 - cqr = dasd_smalloc_request(DASD_DIAG_MAGIC, 0, datasize, memdev); 539 + cqr = dasd_smalloc_request(DASD_DIAG_MAGIC, 0, datasize, memdev, 540 + blk_mq_rq_to_pdu(req)); 540 541 if (IS_ERR(cqr)) 541 542 return cqr; 542 543
+25 -21
drivers/s390/block/dasd_eckd.c
··· 886 886 } 887 887 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, 888 888 0, /* use rcd_buf as data ara */ 889 - device); 889 + device, NULL); 890 890 if (IS_ERR(cqr)) { 891 891 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 892 892 "Could not allocate RCD request"); ··· 1442 1442 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 1443 1443 (sizeof(struct dasd_psf_prssd_data) + 1444 1444 sizeof(struct dasd_rssd_features)), 1445 - device); 1445 + device, NULL); 1446 1446 if (IS_ERR(cqr)) { 1447 1447 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not " 1448 1448 "allocate initialization request"); ··· 1504 1504 1505 1505 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , 1506 1506 sizeof(struct dasd_psf_ssc_data), 1507 - device); 1507 + device, NULL); 1508 1508 1509 1509 if (IS_ERR(cqr)) { 1510 1510 DBF_DEV_EVENT(DBF_WARNING, device, "%s", ··· 1815 1815 1816 1816 cplength = 8; 1817 1817 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data); 1818 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device); 1818 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device, 1819 + NULL); 1819 1820 if (IS_ERR(cqr)) 1820 1821 return cqr; 1821 1822 ccw = cqr->cpaddr; ··· 2093 2092 */ 2094 2093 itcw_size = itcw_calc_size(0, count, 0); 2095 2094 2096 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); 2095 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev, 2096 + NULL); 2097 2097 if (IS_ERR(cqr)) 2098 2098 return cqr; 2099 2099 ··· 2188 2186 cplength += count; 2189 2187 2190 2188 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 2191 - startdev); 2189 + startdev, NULL); 2192 2190 if (IS_ERR(cqr)) 2193 2191 return cqr; 2194 2192 ··· 2334 2332 } 2335 2333 /* Allocate the format ccw request. */ 2336 2334 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, 2337 - datasize, startdev); 2335 + datasize, startdev, NULL); 2338 2336 if (IS_ERR(fcp)) 2339 2337 return fcp; 2340 2338 ··· 3105 3103 } 3106 3104 /* Allocate the ccw request. */ 3107 3105 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 3108 - startdev); 3106 + startdev, blk_mq_rq_to_pdu(req)); 3109 3107 if (IS_ERR(cqr)) 3110 3108 return cqr; 3111 3109 ccw = cqr->cpaddr; ··· 3264 3262 3265 3263 /* Allocate the ccw request. */ 3266 3264 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 3267 - startdev); 3265 + startdev, blk_mq_rq_to_pdu(req)); 3268 3266 if (IS_ERR(cqr)) 3269 3267 return cqr; 3270 3268 ccw = cqr->cpaddr; ··· 3597 3595 3598 3596 /* Allocate the ccw request. */ 3599 3597 itcw_size = itcw_calc_size(0, ctidaw, 0); 3600 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev); 3598 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev, 3599 + blk_mq_rq_to_pdu(req)); 3601 3600 if (IS_ERR(cqr)) 3602 3601 return cqr; 3603 3602 ··· 3865 3862 3866 3863 /* Allocate the ccw request. */ 3867 3864 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, 3868 - datasize, startdev); 3865 + datasize, startdev, blk_mq_rq_to_pdu(req)); 3869 3866 if (IS_ERR(cqr)) 3870 3867 return cqr; 3871 3868 ··· 4105 4102 return -EACCES; 4106 4103 4107 4104 useglobal = 0; 4108 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 4105 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4109 4106 if (IS_ERR(cqr)) { 4110 4107 mutex_lock(&dasd_reserve_mutex); 4111 4108 useglobal = 1; ··· 4160 4157 return -EACCES; 4161 4158 4162 4159 useglobal = 0; 4163 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 4160 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4164 4161 if (IS_ERR(cqr)) { 4165 4162 mutex_lock(&dasd_reserve_mutex); 4166 4163 useglobal = 1; ··· 4214 4211 return -EACCES; 4215 4212 4216 4213 useglobal = 0; 4217 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 4214 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4218 4215 if (IS_ERR(cqr)) { 4219 4216 mutex_lock(&dasd_reserve_mutex); 4220 4217 useglobal = 1; ··· 4274 4271 4275 4272 useglobal = 0; 4276 4273 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 4277 - sizeof(struct dasd_snid_data), device); 4274 + sizeof(struct dasd_snid_data), device, 4275 + NULL); 4278 4276 if (IS_ERR(cqr)) { 4279 4277 mutex_lock(&dasd_reserve_mutex); 4280 4278 useglobal = 1; ··· 4335 4331 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 4336 4332 (sizeof(struct dasd_psf_prssd_data) + 4337 4333 sizeof(struct dasd_rssd_perf_stats_t)), 4338 - device); 4334 + device, NULL); 4339 4335 if (IS_ERR(cqr)) { 4340 4336 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 4341 4337 "Could not allocate initialization request"); ··· 4481 4477 psf1 = psf_data[1]; 4482 4478 4483 4479 /* setup CCWs for PSF + RSSD */ 4484 - cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device); 4480 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2, 0, device, NULL); 4485 4481 if (IS_ERR(cqr)) { 4486 4482 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 4487 4483 "Could not allocate initialization request"); ··· 5041 5037 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 5042 5038 (sizeof(struct dasd_psf_prssd_data) + 5043 5039 sizeof(struct dasd_rssd_messages)), 5044 - device); 5040 + device, NULL); 5045 5041 if (IS_ERR(cqr)) { 5046 5042 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5047 5043 "Could not allocate read message buffer request"); ··· 5130 5126 5131 5127 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 5132 5128 sizeof(struct dasd_psf_prssd_data) + 1, 5133 - device); 5129 + device, NULL); 5134 5130 if (IS_ERR(cqr)) { 5135 5131 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5136 5132 "Could not allocate read message buffer request"); ··· 5288 5284 int rc; 5289 5285 5290 5286 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , 5291 - sizeof(struct dasd_psf_cuir_response), 5292 - device); 5287 + sizeof(struct dasd_psf_cuir_response), 5288 + device, NULL); 5293 5289 5294 5290 if (IS_ERR(cqr)) { 5295 5291 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
+5 -5
drivers/s390/block/dasd_eer.c
··· 447 447 * is a new ccw in device->eer_cqr. Free the "old" 448 448 * snss request now. 449 449 */ 450 - dasd_kfree_request(cqr, device); 450 + dasd_sfree_request(cqr, device); 451 451 } 452 452 453 453 /* ··· 472 472 if (rc) 473 473 goto out; 474 474 475 - cqr = dasd_kmalloc_request(DASD_ECKD_MAGIC, 1 /* SNSS */, 476 - SNSS_DATA_SIZE, device); 475 + cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* SNSS */, 476 + SNSS_DATA_SIZE, device, NULL); 477 477 if (IS_ERR(cqr)) { 478 478 rc = -ENOMEM; 479 479 cqr = NULL; ··· 505 505 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 506 506 507 507 if (cqr) 508 - dasd_kfree_request(cqr, device); 508 + dasd_sfree_request(cqr, device); 509 509 510 510 return rc; 511 511 } ··· 528 528 in_use = test_and_clear_bit(DASD_FLAG_EER_IN_USE, &device->flags); 529 529 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 530 530 if (cqr && !in_use) 531 - dasd_kfree_request(cqr, device); 531 + dasd_sfree_request(cqr, device); 532 532 } 533 533 534 534 /*
+4 -2
drivers/s390/block/dasd_fba.c
··· 356 356 datasize = sizeof(struct DE_fba_data) + 357 357 nr_ccws * (sizeof(struct LO_fba_data) + sizeof(struct ccw1)); 358 358 359 - cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev); 359 + cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev, 360 + blk_mq_rq_to_pdu(req)); 360 361 if (IS_ERR(cqr)) 361 362 return cqr; 362 363 ··· 491 490 datasize += (count - 1)*sizeof(struct LO_fba_data); 492 491 } 493 492 /* Allocate the ccw request. */ 494 - cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev); 493 + cqr = dasd_smalloc_request(DASD_FBA_MAGIC, cplength, datasize, memdev, 494 + blk_mq_rq_to_pdu(req)); 495 495 if (IS_ERR(cqr)) 496 496 return cqr; 497 497 ccw = cqr->cpaddr;
+5 -21
drivers/s390/block/dasd_int.h
··· 158 158 159 159 struct dasd_ccw_req { 160 160 unsigned int magic; /* Eye catcher */ 161 + int intrc; /* internal error, e.g. from start_IO */ 161 162 struct list_head devlist; /* for dasd_device request queue */ 162 163 struct list_head blocklist; /* for dasd_block request queue */ 163 - 164 - /* Where to execute what... */ 165 164 struct dasd_block *block; /* the originating block device */ 166 165 struct dasd_device *memdev; /* the device used to allocate this */ 167 166 struct dasd_device *startdev; /* device the request is started on */ 168 167 struct dasd_device *basedev; /* base device if no block->base */ 169 168 void *cpaddr; /* address of ccw or tcw */ 169 + short retries; /* A retry counter */ 170 170 unsigned char cpmode; /* 0 = cmd mode, 1 = itcw */ 171 171 char status; /* status of this request */ 172 - short retries; /* A retry counter */ 172 + char lpm; /* logical path mask */ 173 173 unsigned long flags; /* flags of this request */ 174 174 struct dasd_queue *dq; 175 - 176 - /* ... and how */ 177 175 unsigned long starttime; /* jiffies time of request start */ 178 176 unsigned long expires; /* expiration period in jiffies */ 179 - char lpm; /* logical path mask */ 180 177 void *data; /* pointer to data area */ 181 - 182 - /* these are important for recovering erroneous requests */ 183 - int intrc; /* internal error, e.g. from start_IO */ 184 178 struct irb irb; /* device status in case of an error */ 185 179 struct dasd_ccw_req *refers; /* ERP-chain queueing. */ 186 180 void *function; /* originating ERP action */ 181 + void *mem_chunk; 187 182 188 - /* these are for statistics only */ 189 183 unsigned long buildclk; /* TOD-clock of request generation */ 190 184 unsigned long startclk; /* TOD-clock of request start */ 191 185 unsigned long stopclk; /* TOD-clock of request interrupt */ 192 186 unsigned long endclk; /* TOD-clock of request termination */ 193 187 194 - /* Callback that is called after reaching final status. */ 195 188 void (*callback)(struct dasd_ccw_req *, void *data); 196 189 void *callback_data; 197 190 }; ··· 707 714 extern struct kmem_cache *dasd_page_cache; 708 715 709 716 struct dasd_ccw_req * 710 - dasd_kmalloc_request(int , int, int, struct dasd_device *); 711 - struct dasd_ccw_req * 712 - dasd_smalloc_request(int , int, int, struct dasd_device *); 713 - void dasd_kfree_request(struct dasd_ccw_req *, struct dasd_device *); 717 + dasd_smalloc_request(int, int, int, struct dasd_device *, struct dasd_ccw_req *); 714 718 void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *); 715 719 void dasd_wakeup_cb(struct dasd_ccw_req *, void *); 716 - 717 - static inline int 718 - dasd_kmalloc_set_cda(struct ccw1 *ccw, void *cda, struct dasd_device *device) 719 - { 720 - return set_normalized_cda(ccw, cda); 721 - } 722 720 723 721 struct dasd_device *dasd_alloc_device(void); 724 722 void dasd_free_device(struct dasd_device *);
+1
drivers/s390/cio/Makefile
··· 5 5 6 6 # The following is required for define_trace.h to find ./trace.h 7 7 CFLAGS_trace.o := -I$(src) 8 + CFLAGS_vfio_ccw_fsm.o := -I$(src) 8 9 9 10 obj-y += airq.o blacklist.o chsc.o cio.o css.o chp.o idset.o isc.o \ 10 11 fcx.o itcw.o crw.o ccwreq.o trace.o ioasm.o
+77 -67
drivers/s390/cio/vfio_ccw_cp.c
··· 23 23 #define CCWCHAIN_LEN_MAX 256 24 24 25 25 struct pfn_array { 26 + /* Starting guest physical I/O address. */ 26 27 unsigned long pa_iova; 28 + /* Array that stores PFNs of the pages need to pin. */ 27 29 unsigned long *pa_iova_pfn; 30 + /* Array that receives PFNs of the pages pinned. */ 28 31 unsigned long *pa_pfn; 32 + /* Number of pages pinned from @pa_iova. */ 29 33 int pa_nr; 30 34 }; 31 35 ··· 50 46 }; 51 47 52 48 /* 53 - * pfn_array_pin() - pin user pages in memory 49 + * pfn_array_alloc_pin() - alloc memory for PFNs, then pin user pages in memory 54 50 * @pa: pfn_array on which to perform the operation 55 51 * @mdev: the mediated device to perform pin/unpin operations 52 + * @iova: target guest physical address 53 + * @len: number of bytes that should be pinned from @iova 56 54 * 57 - * Attempt to pin user pages in memory. 55 + * Attempt to allocate memory for PFNs, and pin user pages in memory. 58 56 * 59 57 * Usage of pfn_array: 60 - * @pa->pa_iova starting guest physical I/O address. Assigned by caller. 61 - * @pa->pa_iova_pfn array that stores PFNs of the pages need to pin. Allocated 62 - * by caller. 63 - * @pa->pa_pfn array that receives PFNs of the pages pinned. Allocated by 64 - * caller. 65 - * @pa->pa_nr number of pages from @pa->pa_iova to pin. Assigned by 66 - * caller. 67 - * number of pages pinned. Assigned by callee. 58 + * We expect (pa_nr == 0) and (pa_iova_pfn == NULL), any field in 59 + * this structure will be filled in by this function. 68 60 * 69 61 * Returns: 70 62 * Number of pages pinned on success. 71 - * If @pa->pa_nr is 0 or negative, returns 0. 63 + * If @pa->pa_nr is not 0, or @pa->pa_iova_pfn is not NULL initially, 64 + * returns -EINVAL. 72 65 * If no pages were pinned, returns -errno. 73 66 */ 74 - static int pfn_array_pin(struct pfn_array *pa, struct device *mdev) 75 - { 76 - int i, ret; 77 - 78 - if (pa->pa_nr <= 0) { 79 - pa->pa_nr = 0; 80 - return 0; 81 - } 82 - 83 - pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT; 84 - for (i = 1; i < pa->pa_nr; i++) 85 - pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1; 86 - 87 - ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr, 88 - IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); 89 - 90 - if (ret > 0 && ret != pa->pa_nr) { 91 - vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret); 92 - pa->pa_nr = 0; 93 - return 0; 94 - } 95 - 96 - return ret; 97 - } 98 - 99 - /* Unpin the pages before releasing the memory. */ 100 - static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev) 101 - { 102 - vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr); 103 - pa->pa_nr = 0; 104 - kfree(pa->pa_iova_pfn); 105 - } 106 - 107 - /* Alloc memory for PFNs, then pin pages with them. */ 108 67 static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev, 109 68 u64 iova, unsigned int len) 110 69 { 111 - int ret = 0; 70 + int i, ret = 0; 112 71 113 72 if (!len) 114 73 return 0; 115 74 116 - if (pa->pa_nr) 75 + if (pa->pa_nr || pa->pa_iova_pfn) 117 76 return -EINVAL; 118 77 119 78 pa->pa_iova = iova; ··· 93 126 return -ENOMEM; 94 127 pa->pa_pfn = pa->pa_iova_pfn + pa->pa_nr; 95 128 96 - ret = pfn_array_pin(pa, mdev); 129 + pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT; 130 + for (i = 1; i < pa->pa_nr; i++) 131 + pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1; 97 132 98 - if (ret > 0) 99 - return ret; 100 - else if (!ret) 133 + ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr, 134 + IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); 135 + 136 + if (ret < 0) { 137 + goto err_out; 138 + } else if (ret > 0 && ret != pa->pa_nr) { 139 + vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret); 101 140 ret = -EINVAL; 102 - 103 - kfree(pa->pa_iova_pfn); 141 + goto err_out; 142 + } 104 143 105 144 return ret; 145 + 146 + err_out: 147 + pa->pa_nr = 0; 148 + kfree(pa->pa_iova_pfn); 149 + pa->pa_iova_pfn = NULL; 150 + 151 + return ret; 152 + } 153 + 154 + /* Unpin the pages before releasing the memory. */ 155 + static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev) 156 + { 157 + vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr); 158 + pa->pa_nr = 0; 159 + kfree(pa->pa_iova_pfn); 106 160 } 107 161 108 162 static int pfn_array_table_init(struct pfn_array_table *pat, int nr) ··· 353 365 * This is the chain length not considering any TICs. 354 366 * You need to do a new round for each TIC target. 355 367 * 368 + * The program is also validated for absence of not yet supported 369 + * indirect data addressing scenarios. 370 + * 356 371 * Returns: the length of the ccw chain or -errno. 357 372 */ 358 373 static int ccwchain_calc_length(u64 iova, struct channel_program *cp) ··· 381 390 cnt = 0; 382 391 do { 383 392 cnt++; 393 + 394 + /* 395 + * As we don't want to fail direct addressing even if the 396 + * orb specified one of the unsupported formats, we defer 397 + * checking for IDAWs in unsupported formats to here. 398 + */ 399 + if ((!cp->orb.cmd.c64 || cp->orb.cmd.i2k) && ccw_is_idal(ccw)) 400 + return -EOPNOTSUPP; 384 401 385 402 if ((!ccw_is_chain(ccw)) && (!ccw_is_tic(ccw))) 386 403 break; ··· 502 503 struct ccw1 *ccw; 503 504 struct pfn_array_table *pat; 504 505 unsigned long *idaws; 505 - int idaw_nr; 506 + int ret; 506 507 507 508 ccw = chain->ch_ccw + idx; 508 509 ··· 522 523 * needed when translating a direct ccw to a idal ccw. 523 524 */ 524 525 pat = chain->ch_pat + idx; 525 - if (pfn_array_table_init(pat, 1)) 526 - return -ENOMEM; 527 - idaw_nr = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, 528 - ccw->cda, ccw->count); 529 - if (idaw_nr < 0) 530 - return idaw_nr; 526 + ret = pfn_array_table_init(pat, 1); 527 + if (ret) 528 + goto out_init; 529 + 530 + ret = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, ccw->cda, ccw->count); 531 + if (ret < 0) 532 + goto out_init; 531 533 532 534 /* Translate this direct ccw to a idal ccw. */ 533 - idaws = kcalloc(idaw_nr, sizeof(*idaws), GFP_DMA | GFP_KERNEL); 535 + idaws = kcalloc(ret, sizeof(*idaws), GFP_DMA | GFP_KERNEL); 534 536 if (!idaws) { 535 - pfn_array_table_unpin_free(pat, cp->mdev); 536 - return -ENOMEM; 537 + ret = -ENOMEM; 538 + goto out_unpin; 537 539 } 538 540 ccw->cda = (__u32) virt_to_phys(idaws); 539 541 ccw->flags |= CCW_FLAG_IDA; ··· 542 542 pfn_array_table_idal_create_words(pat, idaws); 543 543 544 544 return 0; 545 + 546 + out_unpin: 547 + pfn_array_table_unpin_free(pat, cp->mdev); 548 + out_init: 549 + ccw->cda = 0; 550 + return ret; 545 551 } 546 552 547 553 static int ccwchain_fetch_idal(struct ccwchain *chain, ··· 577 571 pat = chain->ch_pat + idx; 578 572 ret = pfn_array_table_init(pat, idaw_nr); 579 573 if (ret) 580 - return ret; 574 + goto out_init; 581 575 582 576 /* Translate idal ccw to use new allocated idaws. */ 583 577 idaws = kzalloc(idaw_len, GFP_DMA | GFP_KERNEL); ··· 609 603 kfree(idaws); 610 604 out_unpin: 611 605 pfn_array_table_unpin_free(pat, cp->mdev); 606 + out_init: 607 + ccw->cda = 0; 612 608 return ret; 613 609 } 614 610 ··· 664 656 /* 665 657 * XXX: 666 658 * Only support prefetch enable mode now. 667 - * Only support 64bit addressing idal. 668 - * Only support 4k IDAW. 669 659 */ 670 - if (!orb->cmd.pfch || !orb->cmd.c64 || orb->cmd.i2k) 660 + if (!orb->cmd.pfch) 671 661 return -EOPNOTSUPP; 672 662 673 663 INIT_LIST_HEAD(&cp->ccwchain_list); ··· 694 688 ret = ccwchain_loop_tic(chain, cp); 695 689 if (ret) 696 690 cp_unpin_free(cp); 691 + /* It is safe to force: if not set but idals used 692 + * ccwchain_calc_length returns an error. 693 + */ 694 + cp->orb.cmd.c64 = 1; 697 695 698 696 return ret; 699 697 }
+4 -1
drivers/s390/cio/vfio_ccw_drv.c
··· 177 177 { 178 178 struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); 179 179 unsigned long flags; 180 + int rc = -EAGAIN; 180 181 181 182 spin_lock_irqsave(sch->lock, flags); 182 183 if (!device_is_registered(&sch->dev)) ··· 188 187 189 188 if (cio_update_schib(sch)) { 190 189 vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_NOT_OPER); 190 + rc = 0; 191 191 goto out_unlock; 192 192 } 193 193 ··· 197 195 private->state = private->mdev ? VFIO_CCW_STATE_IDLE : 198 196 VFIO_CCW_STATE_STANDBY; 199 197 } 198 + rc = 0; 200 199 201 200 out_unlock: 202 201 spin_unlock_irqrestore(sch->lock, flags); 203 202 204 - return 0; 203 + return rc; 205 204 } 206 205 207 206 static struct css_device_id vfio_ccw_sch_ids[] = {
+16 -1
drivers/s390/cio/vfio_ccw_fsm.c
··· 13 13 #include "ioasm.h" 14 14 #include "vfio_ccw_private.h" 15 15 16 + #define CREATE_TRACE_POINTS 17 + #include "vfio_ccw_trace.h" 18 + 16 19 static int fsm_io_helper(struct vfio_ccw_private *private) 17 20 { 18 21 struct subchannel *sch; ··· 113 110 */ 114 111 cio_disable_subchannel(sch); 115 112 } 113 + inline struct subchannel_id get_schid(struct vfio_ccw_private *p) 114 + { 115 + return p->sch->schid; 116 + } 116 117 117 118 /* 118 119 * Deal with the ccw command request from the userspace. ··· 128 121 union scsw *scsw = &private->scsw; 129 122 struct ccw_io_region *io_region = &private->io_region; 130 123 struct mdev_device *mdev = private->mdev; 124 + char *errstr = "request"; 131 125 132 126 private->state = VFIO_CCW_STATE_BOXED; 133 127 ··· 140 132 /* Don't try to build a cp if transport mode is specified. */ 141 133 if (orb->tm.b) { 142 134 io_region->ret_code = -EOPNOTSUPP; 135 + errstr = "transport mode"; 143 136 goto err_out; 144 137 } 145 138 io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev), 146 139 orb); 147 - if (io_region->ret_code) 140 + if (io_region->ret_code) { 141 + errstr = "cp init"; 148 142 goto err_out; 143 + } 149 144 150 145 io_region->ret_code = cp_prefetch(&private->cp); 151 146 if (io_region->ret_code) { 147 + errstr = "cp prefetch"; 152 148 cp_free(&private->cp); 153 149 goto err_out; 154 150 } ··· 160 148 /* Start channel program and wait for I/O interrupt. */ 161 149 io_region->ret_code = fsm_io_helper(private); 162 150 if (io_region->ret_code) { 151 + errstr = "cp fsm_io_helper"; 163 152 cp_free(&private->cp); 164 153 goto err_out; 165 154 } ··· 177 164 178 165 err_out: 179 166 private->state = VFIO_CCW_STATE_IDLE; 167 + trace_vfio_ccw_io_fctl(scsw->cmd.fctl, get_schid(private), 168 + io_region->ret_code, errstr); 180 169 } 181 170 182 171 /*
+54
drivers/s390/cio/vfio_ccw_trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 2 + * Tracepoints for vfio_ccw driver 3 + * 4 + * Copyright IBM Corp. 2018 5 + * 6 + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> 7 + * Halil Pasic <pasic@linux.vnet.ibm.com> 8 + */ 9 + 10 + #undef TRACE_SYSTEM 11 + #define TRACE_SYSTEM vfio_ccw 12 + 13 + #if !defined(_VFIO_CCW_TRACE_) || defined(TRACE_HEADER_MULTI_READ) 14 + #define _VFIO_CCW_TRACE_ 15 + 16 + #include <linux/tracepoint.h> 17 + 18 + TRACE_EVENT(vfio_ccw_io_fctl, 19 + TP_PROTO(int fctl, struct subchannel_id schid, int errno, char *errstr), 20 + TP_ARGS(fctl, schid, errno, errstr), 21 + 22 + TP_STRUCT__entry( 23 + __field(int, fctl) 24 + __field_struct(struct subchannel_id, schid) 25 + __field(int, errno) 26 + __field(char*, errstr) 27 + ), 28 + 29 + TP_fast_assign( 30 + __entry->fctl = fctl; 31 + __entry->schid = schid; 32 + __entry->errno = errno; 33 + __entry->errstr = errstr; 34 + ), 35 + 36 + TP_printk("schid=%x.%x.%04x fctl=%x errno=%d info=%s", 37 + __entry->schid.cssid, 38 + __entry->schid.ssid, 39 + __entry->schid.sch_no, 40 + __entry->fctl, 41 + __entry->errno, 42 + __entry->errstr) 43 + ); 44 + 45 + #endif /* _VFIO_CCW_TRACE_ */ 46 + 47 + /* This part must be outside protection */ 48 + 49 + #undef TRACE_INCLUDE_PATH 50 + #define TRACE_INCLUDE_PATH . 51 + #undef TRACE_INCLUDE_FILE 52 + #define TRACE_INCLUDE_FILE vfio_ccw_trace 53 + 54 + #include <trace/define_trace.h>