s390/css: handle CCW_FLAG_SKIP
RFC PATCH v2 1/1 s390/css: handle CCW_FLAG_SKIP
If a ccw has CCW_FLAG_SKIP set, and the command is of type read, read backwards, or sense, no data should be written to the guest for that command.
---
v1 -> v2: fixed checks for command type [Eric]
Still only lightly tested (it boots); I don't think I have a tool generating channel programs with the skip flag handy.
--- hw/s390x/css.c | 22 ++++++++++++++++++---- include/hw/s390x/css.h | 1 + 2 files changed, 19 insertions(+), 4 deletions(-)
hw/s390x/css.c +18 -4
@@ -830,8 +830,12 @@ static int ccw_dstream_rw_noflags(CcwDataStream *cds, void *buff, int len,if (op ==CDS_OP_A ) { goto incr; } - ret =address_space_rw (&address_space_memory, cds->cda, -MEMTXATTRS_UNSPECIFIED , buff, len, op); +if (!cds->do_skip) { + ret =address_space_rw (&address_space_memory, cds->cda, +MEMTXATTRS_UNSPECIFIED , buff, len, op); + }else { + ret =0 ; + }if (ret !=MEMTX_OK ) { cds->flags |=CDS_F_STREAM_BROKEN ;return -EINVAL ;
@@ -928,8 +932,13 @@ static int ccw_dstream_rw_ida(CcwDataStream *cds, void *buff, int len, do { iter_len = MIN(len, cont_left); if (op != CDS_OP_A) { - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, iter_len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, iter_len, + op); + } else { + ret = 0; + } if (ret != MEMTX_OK) { /* assume inaccessible address */ ret = -EINVAL; /* channel program check */
@@ -968,6 +977,11 @@ void ccw_dstream_init(CcwDataStream *cds, CCW1 const *ccw, ORB const *orb) cds->count = ccw->count; cds->cda_orig = ccw->cda; +/* skip is only effective for read, read backwards, or sense commands */ + cds->do_skip = (ccw->flags &CCW_FLAG_SKIP ) && + ((ccw->cmd_code &CCW_CMD_BASIC_SENSE ) ==CCW_CMD_BASIC_SENSE || + (ccw->cmd_code &0x02 ) ==0x02 /* read */ || + (ccw->cmd_code &0x0c ) ==0x0c /* read backwards */ );ccw_dstream_rewind (cds);if (!(cds->flags &CDS_F_IDA )) { cds->op_handler = ccw_dstream_rw_noflags;
include/hw/s390x/css.h +1 -0
@@ -97,6 +97,7 @@ typedef struct CcwDataStream {int (*op_handler)(struct CcwDataStream *cds,void *buff,int len,CcwDataStreamOp op);hwaddr cda; +bool do_skip; } CcwDataStream;/*
Signature · 1 line
2.20.1
Quoted 53 lines · Cornelia Huck
If a ccw has
CCW_FLAG_SKIPset, and the command is of type read, read backwards, or sense, no data should be written to the guest for that command.Signed-off-by Cornelia Huck <[email protected]>---
v1 -> v2: fixed checks for command type [Eric]
Still only lightly tested (it boots); I don't think I have a tool generating channel programs with the skip flag handy.
--- hw/s390x/css.c | 22 ++++++++++++++++++---- include/hw/s390x/css.h | 1 + 2 files changed, 19 insertions(+), 4 deletions(-)hw/s390x/css.c +13
-4@@ -830,8 +830,12 @@ static int ccw_dstream_rw_noflags(CcwDataStream *cds, void *buff, int len,if (op ==CDS_OP_A ) { goto incr; } - ret =address_space_rw (&address_space_memory, cds->cda, -MEMTXATTRS_UNSPECIFIED , buff, len, op); +if (!cds->do_skip) { + ret =address_space_rw (&address_space_memory, cds->cda, +MEMTXATTRS_UNSPECIFIED , buff, len, op); + }else { + ret =0 ; + }if (ret !=MEMTX_OK ) { cds->flags |=CDS_F_STREAM_BROKEN ;return -EINVAL ;@@ -928,8 +932,13 @@ static int ccw_dstream_rw_ida(CcwDataStream *cds, void *buff, int len, do { iter_len = MIN(len, cont_left); if (op != CDS_OP_A) { - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, iter_len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, iter_len, + op); + } else { + ret = 0; + } if (ret != MEMTX_OK) { /* assume inaccessible address */ ret = -EINVAL; /* channel program check */
hw/s390x/css.c void ccw_dstream_init(CcwDataStream *cds, CCW1 const *ccw, ORB const *orb) · line 984
Quoted 8 lines
hw/s390x/css.c +5
-0@@ -968,6 +977,11 @@ void ccw_dstream_init(CcwDataStream *cds, CCW1 const *ccw, ORB const *orb) cds->count = ccw->count; cds->cda_orig = ccw->cda; +/* skip is only effective for read, read backwards, or sense commands */ + cds->do_skip = (ccw->flags &CCW_FLAG_SKIP ) && + ((ccw->cmd_code &CCW_CMD_BASIC_SENSE ) ==CCW_CMD_BASIC_SENSE || + (ccw->cmd_code &0x02 ) ==0x02 /* read */ || + (ccw->cmd_code &0x0c ) ==0x0c /* read backwards */ );
I think you should use masks like ((code & 0x3) == 2) => READ ((code & 0xf) == 0xc) => READ BACKWARD ((code & 0xf) == 0x4) => SENSE
Regards,
Pierre
Quoted 16 lines
hw/s390x/css.c +0
-0ccw_dstream_rewind (cds);if (!(cds->flags &CDS_F_IDA )) { cds->op_handler = ccw_dstream_rw_noflags;include/hw/s390x/css.h +1
-0@@ -97,6 +97,7 @@ typedef struct CcwDataStream {int (*op_handler)(struct CcwDataStream *cds,void *buff,int len,CcwDataStreamOp op);hwaddr cda; +bool do_skip; } CcwDataStream;/*
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Quoted 5 lines · Pierre Morel
Quoted 4 lines · Cornelia Huck
If a ccw has
CCW_FLAG_SKIPset, and the command is of type read, read backwards, or sense, no data should be written to the guest for that command.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Cornelia Huck <[email protected]>---
v1 -> v2: fixed checks for command type [Eric]
Still only lightly tested (it boots); I don't think I have a tool generating channel programs with the skip flag handy.
FWIW, my test program hits this code once (read of a single page, with SLI and SKIP flags set) before getting into the passthrough codepath.
Quoted 52 lines
Quoted 52 lines
---
hw/s390x/css.c | 22 ++++++++++++++++++----include/hw/s390x/css.h| 1 +2 files changed, 19 insertions(+), 4 deletions(-)hw/s390x/css.c +6
-2@@ -830,8 +830,12 @@ static int ccw_dstream_rw_noflags(CcwDataStream *cds, void *buff, int len, if (op == CDS_OP_A) { goto incr; } - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, len, op); + } else { + ret = 0; + } if (ret != MEMTX_OK) { cds->flags |= CDS_F_STREAM_BROKEN;return
-EINVAL;hw/s390x/css.c +7
-2@@ -928,8 +932,13 @@ static int ccw_dstream_rw_ida(CcwDataStream *cds, void *buff, int len, do { iter_len = MIN(len, cont_left); if (op != CDS_OP_A) { - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, iter_len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, iter_len, + op); + } else { + ret = 0; + }if (ret !=
MEMTX_OK) {
/* assume inaccessible address */ ret =-EINVAL; /* channel program check */hw/s390x/css.c +1
-0@@ -968,6 +977,11 @@ void ccw_dstream_init(CcwDataStream *cds, CCW1 const *ccw, ORB const *orb) cds->count = ccw->count; cds->cda_orig = ccw->cda; + /* skip is only effective for read, read backwards, or sensecommands */
+cds->do_skip= (ccw->flags&CCW_FLAG_SKIP) &&
Quoted 8 lines
Quoted 3 lines
+ ((
ccw->cmd_code&CCW_CMD_BASIC_SENSE) ==CCW_CMD_BASIC_SENSE|| + (ccw->cmd_code&0x02) ==0x02/* read */ ||
+ (ccw->cmd_code&0x0c) ==0x0c/* read backwards */);I think you should use masks like ((code &
0x3) == 2) => READ ((code &0xf) ==0xc) => READ BACKWARD ((code &0xf) ==0x4) => SENSE
I think Pierre is right. In the v2 code, a control CCW (like NOP) would still be flagged as a READ.
Quoted 24 lines
Regards,
PierreQuoted 15 lines
ccw_dstream_rewind(cds);
if (!(cds->flags &CDS_F_IDA)) {cds->op_handler=ccw_dstream_rw_noflags;include/hw/s390x/css.h +1
-0@@ -97,6 +97,7 @@ typedef struct CcwDataStream { int (*op_handler)(struct CcwDataStream *cds, void *buff, int len, CcwDataStreamOp op); hwaddr cda; + bool do_skip; } CcwDataStream; /*
Quoted 9 lines · On Tue, 7 May 2019 11:31:16 -0400 Eric Farman <[email protected]> wrote:
Quoted 8 lines · Pierre Morel
Quoted 7 lines · Cornelia Huck
If a ccw has
CCW_FLAG_SKIPset, and the command is of type read, read backwards, or sense, no data should be written to the guest for that command.Signed-off-by Cornelia Huck <[email protected]>---
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
v1 -> v2: fixed checks for command type [Eric]
Still only lightly tested (it boots); I don't think I have a tool generating channel programs with the skip flag handy.
FWIW, my test program hits this code once (read of a single page, with SLI and SKIP flags set) before getting into the passthrough codepath.
Ah, good.
Quoted 62 lines
Quoted 53 lines
Quoted 53 lines
---
hw/s390x/css.c | 22 ++++++++++++++++++----include/hw/s390x/css.h| 1 +2 files changed, 19 insertions(+), 4 deletions(-)hw/s390x/css.c +6
-2@@ -830,8 +830,12 @@ static int ccw_dstream_rw_noflags(CcwDataStream *cds, void *buff, int len, if (op == CDS_OP_A) { goto incr; } - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, len, op); + } else { + ret = 0; + } if (ret != MEMTX_OK) { cds->flags |= CDS_F_STREAM_BROKEN;return
-EINVAL;hw/s390x/css.c +7
-2@@ -928,8 +932,13 @@ static int ccw_dstream_rw_ida(CcwDataStream *cds, void *buff, int len, do { iter_len = MIN(len, cont_left); if (op != CDS_OP_A) { - ret = address_space_rw(&address_space_memory, cds->cda, - MEMTXATTRS_UNSPECIFIED, buff, iter_len, op); + if (!cds->do_skip) { + ret = address_space_rw(&address_space_memory, cds->cda, + MEMTXATTRS_UNSPECIFIED, buff, iter_len, + op); + } else { + ret = 0; + }if (ret !=
MEMTX_OK) {
/* assume inaccessible address */ ret =-EINVAL; /* channel program check */hw/s390x/css.c +1
-0@@ -968,6 +977,11 @@ void ccw_dstream_init(CcwDataStream *cds, CCW1 const *ccw, ORB const *orb) cds->count = ccw->count; cds->cda_orig = ccw->cda; + /* skip is only effective for read, read backwards, or sensecommands */
+cds->do_skip= (ccw->flags&CCW_FLAG_SKIP) &&Quoted 8 lines
Quoted 3 lines
+ ((
ccw->cmd_code&CCW_CMD_BASIC_SENSE) ==CCW_CMD_BASIC_SENSE|| + (ccw->cmd_code&0x02) ==0x02/* read */ ||
+ (ccw->cmd_code&0x0c) ==0x0c/* read backwards */);I think you should use masks like ((code &
0x3) == 2) => READ ((code &0xf) ==0xc) => READ BACKWARD ((code &0xf) ==0x4) => SENSE
Quoted 2 lines
I think Pierre is right. In the v2 code, a control CCW (like NOP) would still be flagged as a READ.
Sigh. I hope third time's the charm.