Commit 71189f26 authored by Cornelia Huck's avatar Cornelia Huck

vfio-ccw: make it safe to access channel programs

When we get a solicited interrupt, the start function may have
been cleared by a csch, but we still have a channel program
structure allocated. Make it safe to call the cp accessors in
any case, so we can call them unconditionally.

While at it, also make sure that functions called from other parts
of the code return gracefully if the channel program structure
has not been initialized (even though that is a bug in the caller).
Reviewed-by: default avatarEric Farman <farman@linux.ibm.com>
Reviewed-by: default avatarFarhan Ali <alifm@linux.ibm.com>
Signed-off-by: default avatarCornelia Huck <cohuck@redhat.com>
parent 1c410fd6
...@@ -362,6 +362,7 @@ static void cp_unpin_free(struct channel_program *cp) ...@@ -362,6 +362,7 @@ static void cp_unpin_free(struct channel_program *cp)
struct ccwchain *chain, *temp; struct ccwchain *chain, *temp;
int i; int i;
cp->initialized = false;
list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) {
for (i = 0; i < chain->ch_len; i++) { for (i = 0; i < chain->ch_len; i++) {
pfn_array_table_unpin_free(chain->ch_pat + i, pfn_array_table_unpin_free(chain->ch_pat + i,
...@@ -732,6 +733,9 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) ...@@ -732,6 +733,9 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb)
*/ */
cp->orb.cmd.c64 = 1; cp->orb.cmd.c64 = 1;
if (!ret)
cp->initialized = true;
return ret; return ret;
} }
...@@ -746,6 +750,7 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) ...@@ -746,6 +750,7 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb)
*/ */
void cp_free(struct channel_program *cp) void cp_free(struct channel_program *cp)
{ {
if (cp->initialized)
cp_unpin_free(cp); cp_unpin_free(cp);
} }
...@@ -791,6 +796,10 @@ int cp_prefetch(struct channel_program *cp) ...@@ -791,6 +796,10 @@ int cp_prefetch(struct channel_program *cp)
struct ccwchain *chain; struct ccwchain *chain;
int len, idx, ret; int len, idx, ret;
/* this is an error in the caller */
if (!cp->initialized)
return -EINVAL;
list_for_each_entry(chain, &cp->ccwchain_list, next) { list_for_each_entry(chain, &cp->ccwchain_list, next) {
len = chain->ch_len; len = chain->ch_len;
for (idx = 0; idx < len; idx++) { for (idx = 0; idx < len; idx++) {
...@@ -826,6 +835,10 @@ union orb *cp_get_orb(struct channel_program *cp, u32 intparm, u8 lpm) ...@@ -826,6 +835,10 @@ union orb *cp_get_orb(struct channel_program *cp, u32 intparm, u8 lpm)
struct ccwchain *chain; struct ccwchain *chain;
struct ccw1 *cpa; struct ccw1 *cpa;
/* this is an error in the caller */
if (!cp->initialized)
return NULL;
orb = &cp->orb; orb = &cp->orb;
orb->cmd.intparm = intparm; orb->cmd.intparm = intparm;
...@@ -862,6 +875,9 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw) ...@@ -862,6 +875,9 @@ void cp_update_scsw(struct channel_program *cp, union scsw *scsw)
u32 cpa = scsw->cmd.cpa; u32 cpa = scsw->cmd.cpa;
u32 ccw_head; u32 ccw_head;
if (!cp->initialized)
return;
/* /*
* LATER: * LATER:
* For now, only update the cmd.cpa part. We may need to deal with * For now, only update the cmd.cpa part. We may need to deal with
...@@ -898,6 +914,9 @@ bool cp_iova_pinned(struct channel_program *cp, u64 iova) ...@@ -898,6 +914,9 @@ bool cp_iova_pinned(struct channel_program *cp, u64 iova)
struct ccwchain *chain; struct ccwchain *chain;
int i; int i;
if (!cp->initialized)
return false;
list_for_each_entry(chain, &cp->ccwchain_list, next) { list_for_each_entry(chain, &cp->ccwchain_list, next) {
for (i = 0; i < chain->ch_len; i++) for (i = 0; i < chain->ch_len; i++)
if (pfn_array_table_iova_pinned(chain->ch_pat + i, if (pfn_array_table_iova_pinned(chain->ch_pat + i,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* @ccwchain_list: list head of ccwchains * @ccwchain_list: list head of ccwchains
* @orb: orb for the currently processed ssch request * @orb: orb for the currently processed ssch request
* @mdev: the mediated device to perform page pinning/unpinning * @mdev: the mediated device to perform page pinning/unpinning
* @initialized: whether this instance is actually initialized
* *
* @ccwchain_list is the head of a ccwchain list, that contents the * @ccwchain_list is the head of a ccwchain list, that contents the
* translated result of the guest channel program that pointed out by * translated result of the guest channel program that pointed out by
...@@ -30,6 +31,7 @@ struct channel_program { ...@@ -30,6 +31,7 @@ struct channel_program {
struct list_head ccwchain_list; struct list_head ccwchain_list;
union orb orb; union orb orb;
struct device *mdev; struct device *mdev;
bool initialized;
}; };
extern int cp_init(struct channel_program *cp, struct device *mdev, extern int cp_init(struct channel_program *cp, struct device *mdev,
......
...@@ -31,6 +31,10 @@ static int fsm_io_helper(struct vfio_ccw_private *private) ...@@ -31,6 +31,10 @@ static int fsm_io_helper(struct vfio_ccw_private *private)
private->state = VFIO_CCW_STATE_BUSY; private->state = VFIO_CCW_STATE_BUSY;
orb = cp_get_orb(&private->cp, (u32)(addr_t)sch, sch->lpm); orb = cp_get_orb(&private->cp, (u32)(addr_t)sch, sch->lpm);
if (!orb) {
ret = -EIO;
goto out;
}
/* Issue "Start Subchannel" */ /* Issue "Start Subchannel" */
ccode = ssch(sch->schid, orb); ccode = ssch(sch->schid, orb);
...@@ -64,6 +68,7 @@ static int fsm_io_helper(struct vfio_ccw_private *private) ...@@ -64,6 +68,7 @@ static int fsm_io_helper(struct vfio_ccw_private *private)
default: default:
ret = ccode; ret = ccode;
} }
out:
spin_unlock_irqrestore(sch->lock, flags); spin_unlock_irqrestore(sch->lock, flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment