Skip to content

Commit eed3419

Browse files
committed
Merge tag 'vfio-ccw-20190717-2' of https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/vfio-ccw into fixes
Fixes in vfio-ccw for older and newer issues.
2 parents 69e9620 + 4c4cbba commit eed3419

3 files changed

Lines changed: 46 additions & 15 deletions

File tree

‎Documentation/s390/vfio-ccw.rst‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ The process of how these work together.
180180
add it to an iommu_group and a vfio_group. Then we could pass through
181181
the mdev to a guest.
182182

183+
184+
VFIO-CCW Regions
185+
----------------
186+
187+
The vfio-ccw driver exposes MMIO regions to accept requests from and return
188+
results to userspace.
189+
183190
vfio-ccw I/O region
184191
-------------------
185192

@@ -205,6 +212,25 @@ irb_area stores the I/O result.
205212

206213
ret_code stores a return code for each access of the region.
207214

215+
This region is always available.
216+
217+
vfio-ccw cmd region
218+
-------------------
219+
220+
The vfio-ccw cmd region is used to accept asynchronous instructions
221+
from userspace::
222+
223+
#define VFIO_CCW_ASYNC_CMD_HSCH (1 << 0)
224+
#define VFIO_CCW_ASYNC_CMD_CSCH (1 << 1)
225+
struct ccw_cmd_region {
226+
__u32 command;
227+
__u32 ret_code;
228+
} __packed;
229+
230+
This region is exposed via region type VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD.
231+
232+
Currently, CLEAR SUBCHANNEL and HALT SUBCHANNEL use this region.
233+
208234
vfio-ccw operation details
209235
--------------------------
210236

@@ -306,9 +332,8 @@ Together with the corresponding work in QEMU, we can bring the passed
306332
through DASD/ECKD device online in a guest now and use it as a block
307333
device.
308334

309-
While the current code allows the guest to start channel programs via
310-
START SUBCHANNEL, support for HALT SUBCHANNEL or CLEAR SUBCHANNEL is
311-
not yet implemented.
335+
The current code allows the guest to start channel programs via
336+
START SUBCHANNEL, and to issue HALT SUBCHANNEL and CLEAR SUBCHANNEL.
312337

313338
vfio-ccw supports classic (command mode) channel I/O only. Transport
314339
mode (HPF) is not supported.

‎drivers/s390/cio/vfio_ccw_cp.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len)
7272
sizeof(*pa->pa_iova_pfn) +
7373
sizeof(*pa->pa_pfn),
7474
GFP_KERNEL);
75-
if (unlikely(!pa->pa_iova_pfn))
75+
if (unlikely(!pa->pa_iova_pfn)) {
76+
pa->pa_nr = 0;
7677
return -ENOMEM;
78+
}
7779
pa->pa_pfn = pa->pa_iova_pfn + pa->pa_nr;
7880

7981
pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT;
@@ -421,7 +423,7 @@ static int ccwchain_loop_tic(struct ccwchain *chain,
421423
static int ccwchain_handle_ccw(u32 cda, struct channel_program *cp)
422424
{
423425
struct ccwchain *chain;
424-
int len;
426+
int len, ret;
425427

426428
/* Copy 2K (the most we support today) of possible CCWs */
427429
len = copy_from_iova(cp->mdev, cp->guest_cp, cda,
@@ -448,7 +450,12 @@ static int ccwchain_handle_ccw(u32 cda, struct channel_program *cp)
448450
memcpy(chain->ch_ccw, cp->guest_cp, len * sizeof(struct ccw1));
449451

450452
/* Loop for tics on this new chain. */
451-
return ccwchain_loop_tic(chain, cp);
453+
ret = ccwchain_loop_tic(chain, cp);
454+
455+
if (ret)
456+
ccwchain_free(chain);
457+
458+
return ret;
452459
}
453460

454461
/* Loop for TICs. */
@@ -642,17 +649,16 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb)
642649

643650
/* Build a ccwchain for the first CCW segment */
644651
ret = ccwchain_handle_ccw(orb->cmd.cpa, cp);
645-
if (ret)
646-
cp_free(cp);
647-
648-
/* It is safe to force: if not set but idals used
649-
* ccwchain_calc_length returns an error.
650-
*/
651-
cp->orb.cmd.c64 = 1;
652652

653-
if (!ret)
653+
if (!ret) {
654654
cp->initialized = true;
655655

656+
/* It is safe to force: if it was not set but idals used
657+
* ccwchain_calc_length would have returned an error.
658+
*/
659+
cp->orb.cmd.c64 = 1;
660+
}
661+
656662
return ret;
657663
}
658664

‎drivers/s390/cio/vfio_ccw_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)
8888
(SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT));
8989
if (scsw_is_solicited(&irb->scsw)) {
9090
cp_update_scsw(&private->cp, &irb->scsw);
91-
if (is_final)
91+
if (is_final && private->state == VFIO_CCW_STATE_CP_PENDING)
9292
cp_free(&private->cp);
9393
}
9494
mutex_lock(&private->io_mutex);

0 commit comments

Comments
 (0)