aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2019-02-27 07:19:33 -0500
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2019-02-27 07:19:33 -0500
commit7b660c225fa021b254be69aafb5787e79ec58af0 (patch)
treeeb59a48de72f12eaa13a8dd0cf74d2a4e4900758
parent36360658eb5a6cf04bb9f2704d1e4ce54037ec99 (diff)
parent2904337fd981217784c2820abdee537aa0c70330 (diff)
Merge tag 'vfio-ccw-20190227' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/vfio-ccw into features
Pull vfio-ccw from Cornelia Huck with the following changes: - Further fixes in TIC handling.
-rw-r--r--drivers/s390/cio/vfio_ccw_cp.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
index ba08fe137c2e..384b3987eeb4 100644
--- a/drivers/s390/cio/vfio_ccw_cp.c
+++ b/drivers/s390/cio/vfio_ccw_cp.c
@@ -283,6 +283,33 @@ static long copy_ccw_from_iova(struct channel_program *cp,
283 283
284#define ccw_is_chain(_ccw) ((_ccw)->flags & (CCW_FLAG_CC | CCW_FLAG_DC)) 284#define ccw_is_chain(_ccw) ((_ccw)->flags & (CCW_FLAG_CC | CCW_FLAG_DC))
285 285
286/*
287 * is_cpa_within_range()
288 *
289 * @cpa: channel program address being questioned
290 * @head: address of the beginning of a CCW chain
291 * @len: number of CCWs within the chain
292 *
293 * Determine whether the address of a CCW (whether a new chain,
294 * or the target of a TIC) falls within a range (including the end points).
295 *
296 * Returns 1 if yes, 0 if no.
297 */
298static inline int is_cpa_within_range(u32 cpa, u32 head, int len)
299{
300 u32 tail = head + (len - 1) * sizeof(struct ccw1);
301
302 return (head <= cpa && cpa <= tail);
303}
304
305static inline int is_tic_within_range(struct ccw1 *ccw, u32 head, int len)
306{
307 if (!ccw_is_tic(ccw))
308 return 0;
309
310 return is_cpa_within_range(ccw->cda, head, len);
311}
312
286static struct ccwchain *ccwchain_alloc(struct channel_program *cp, int len) 313static struct ccwchain *ccwchain_alloc(struct channel_program *cp, int len)
287{ 314{
288 struct ccwchain *chain; 315 struct ccwchain *chain;
@@ -392,7 +419,15 @@ static int ccwchain_calc_length(u64 iova, struct channel_program *cp)
392 return -EOPNOTSUPP; 419 return -EOPNOTSUPP;
393 } 420 }
394 421
395 if (!ccw_is_chain(ccw)) 422 /*
423 * We want to keep counting if the current CCW has the
424 * command-chaining flag enabled, or if it is a TIC CCW
425 * that loops back into the current chain. The latter
426 * is used for device orientation, where the CCW PRIOR to
427 * the TIC can either jump to the TIC or a CCW immediately
428 * after the TIC, depending on the results of its operation.
429 */
430 if (!ccw_is_chain(ccw) && !is_tic_within_range(ccw, iova, cnt))
396 break; 431 break;
397 432
398 ccw++; 433 ccw++;
@@ -408,13 +443,11 @@ static int ccwchain_calc_length(u64 iova, struct channel_program *cp)
408static int tic_target_chain_exists(struct ccw1 *tic, struct channel_program *cp) 443static int tic_target_chain_exists(struct ccw1 *tic, struct channel_program *cp)
409{ 444{
410 struct ccwchain *chain; 445 struct ccwchain *chain;
411 u32 ccw_head, ccw_tail; 446 u32 ccw_head;
412 447
413 list_for_each_entry(chain, &cp->ccwchain_list, next) { 448 list_for_each_entry(chain, &cp->ccwchain_list, next) {
414 ccw_head = chain->ch_iova; 449 ccw_head = chain->ch_iova;
415 ccw_tail = ccw_head + (chain->ch_len - 1) * sizeof(struct ccw1); 450 if (is_cpa_within_range(tic->cda, ccw_head, chain->ch_len))
416
417 if ((ccw_head <= tic->cda) && (tic->cda <= ccw_tail))
418 return 1; 451 return 1;
419 } 452 }
420 453
@@ -481,13 +514,11 @@ static int ccwchain_fetch_tic(struct ccwchain *chain,
481{ 514{
482 struct ccw1 *ccw = chain->ch_ccw + idx; 515 struct ccw1 *ccw = chain->ch_ccw + idx;
483 struct ccwchain *iter; 516 struct ccwchain *iter;
484 u32 ccw_head, ccw_tail; 517 u32 ccw_head;
485 518
486 list_for_each_entry(iter, &cp->ccwchain_list, next) { 519 list_for_each_entry(iter, &cp->ccwchain_list, next) {
487 ccw_head = iter->ch_iova; 520 ccw_head = iter->ch_iova;
488 ccw_tail = ccw_head + (iter->ch_len - 1) * sizeof(struct ccw1); 521 if (is_cpa_within_range(ccw->cda, ccw_head, iter->ch_len)) {
489
490 if ((ccw_head <= ccw->cda) && (ccw->cda <= ccw_tail)) {
491 ccw->cda = (__u32) (addr_t) (((char *)iter->ch_ccw) + 522 ccw->cda = (__u32) (addr_t) (((char *)iter->ch_ccw) +
492 (ccw->cda - ccw_head)); 523 (ccw->cda - ccw_head));
493 return 0; 524 return 0;
@@ -829,7 +860,7 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)
829{ 860{
830 struct ccwchain *chain; 861 struct ccwchain *chain;
831 u32 cpa = scsw->cmd.cpa; 862 u32 cpa = scsw->cmd.cpa;
832 u32 ccw_head, ccw_tail; 863 u32 ccw_head;
833 864
834 /* 865 /*
835 * LATER: 866 * LATER:
@@ -839,9 +870,7 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)
839 */ 870 */
840 list_for_each_entry(chain, &cp->ccwchain_list, next) { 871 list_for_each_entry(chain, &cp->ccwchain_list, next) {
841 ccw_head = (u32)(u64)chain->ch_ccw; 872 ccw_head = (u32)(u64)chain->ch_ccw;
842 ccw_tail = (u32)(u64)(chain->ch_ccw + chain->ch_len - 1); 873 if (is_cpa_within_range(cpa, ccw_head, chain->ch_len)) {
843
844 if ((ccw_head <= cpa) && (cpa <= ccw_tail)) {
845 /* 874 /*
846 * (cpa - ccw_head) is the offset value of the host 875 * (cpa - ccw_head) is the offset value of the host
847 * physical ccw to its chain head. 876 * physical ccw to its chain head.