s390x: css: report errors from ccw_dstream_read/write
v2 cover s390x: css: report errors from ccw_dstream_read/write
By checking the results of errors on SSCH in the kvm-unit-tests We noticed that no error was reported when a SSCH is started to access addresses not existing in the guest.
For exemple accessing 3G on a guest with 1G memory.
If we look at QEMU ccw_dstream_write/write functions we see that they are often not checked for error in various places.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Regards,
Pierre
Pierre Morel (1):
s390x: css: report errors from ccw_dstream_read/write
hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)
Signature · 13 lines
2.17.1 changelog: from v1: - handle_payload_3270_read, return CSS error on CSS access errors keep returning -EIO for other 3270 internal errors. (Connie) - css_interpret_ccw, let CSS handle the residual count even on errors it is supposed to do it right. (Connie)
PATCH v2 1/1 s390x: css: report errors from ccw_dstream_read/write
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)
hw/char/terminal3270.c +9 -2
@@ -200,9 +200,13 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) {Terminal3270 *t =TERMINAL_3270 (dev);int len; +int ret; len =MIN (ccw_dstream_avail (get_cds (t)), t->in_len); -ccw_dstream_write_buf (get_cds (t), t->inv, len); + ret =ccw_dstream_write_buf (get_cds (t), t->inv, len); +if (ret <0 ) { +return ret; + } t->in_len -= len;return len;
@@ -260,7 +264,10 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd) t->outv[out_len++] = cmd; do { - ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + retval = ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + if (retval < 0) { + return retval; + } count = ccw_dstream_avail(get_cds(t)); out_len += len;
hw/s390x/3270-ccw.c +4 -1
@@ -31,6 +31,9 @@ static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) } len = ck->read_payload_3270 (dev); +if (len <0 ) { +return len; + } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;return 0 ;
@@ -50,7 +53,7 @@ static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) len = ck->write_payload_3270 (dev, ccw->cmd_code);if (len <=0 ) { -return -EIO ; +return len ? len : -EIO ; } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;
hw/s390x/css.c +8 -6
@@ -1055,10 +1055,11 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr, } } len =MIN (ccw.count,sizeof (sch->sense_data)); -ccw_dstream_write_buf (&sch->cds, sch->sense_data, len); + ret =ccw_dstream_write_buf (&sch->cds, sch->sense_data, len); sch->curr_status.scsw.count =ccw_dstream_residual_count (&sch->cds); -memset (sch->sense_data,0 ,sizeof (sch->sense_data)); - ret =0 ; +if (!ret) { +memset (sch->sense_data,0 ,sizeof (sch->sense_data)); + }break ;case CCW_CMD_SENSE_ID : {
@@ -1083,9 +1084,10 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr, }else { sense_id[0 ] =0 ; } -ccw_dstream_write_buf (&sch->cds, sense_id, len); - sch->curr_status.scsw.count =ccw_dstream_residual_count (&sch->cds); - ret =0 ; + ret =ccw_dstream_write_buf (&sch->cds, sense_id, len); +if (!ret) { + sch->curr_status.scsw.count =ccw_dstream_residual_count (&sch->cds); + }break ; }case CCW_CMD_TIC :
hw/s390x/virtio-ccw.c +48 -18
138 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 11 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Signed-off-by Pierre Morel <[email protected]>
I did not look into the whole scsw.count stuff or into wether your changes to 3270 (look form <mark></mark> in the diff part) affect more than just ccw_dstream_*.
I would have preferred this patch split up based on the intended effect and thus also subsystem (css, virtio-ccw, 3270), but I've alluded to that before, and since we are in a hurry I can live with it as is.
Regards,
Halil
Quoted 43 lines
--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)hw/char/terminal3270.c +9
-2@@ -200,9 +200,13 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) {Terminal3270 *t =TERMINAL_3270 (dev);int len; +int ret; len =MIN (ccw_dstream_avail (get_cds (t)), t->in_len); -ccw_dstream_write_buf (get_cds (t), t->inv, len); + ret =ccw_dstream_write_buf (get_cds (t), t->inv, len); +if (ret <0 ) { +return ret; + } t->in_len -= len;return len;@@ -260,7 +264,10 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd) t->outv[out_len++] = cmd; do { - ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + retval = ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + if (retval < 0) { + return retval; + } count = ccw_dstream_avail(get_cds(t)); out_len += len;hw/s390x/3270-ccw.c +0
-0
hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 33
Quoted 3 lines
hw/s390x/3270-ccw.c +0
-0@@ -31,6 +31,9 @@ static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) } len = ck->read_payload_3270 (dev);
<mark>
hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 38
Quoted 5 lines
hw/s390x/3270-ccw.c +3
-0+if (len <0 ) { +return len; + } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;
</mark>
Do we eventually update scsw.count?
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 55
Quoted 5 lines
hw/s390x/3270-ccw.c +0
-0return 0 ;@@ -50,7 +53,7 @@ static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) len = ck->write_payload_3270 (dev, ccw->cmd_code);if (len <=0 ) {
<mark>
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 56
Quoted 2 lines
hw/s390x/3270-ccw.c +1
-1-return -EIO ; +return len ? len : -EIO ;
</mark>
Quoted 5 lines
hw/s390x/3270-ccw.c +0
-0} ccw_dev->sch->curr_status.scsw.count = ccw->count - len;hw/s390x/css.c +0
-0
Quoted 83 lines · On Fri, 9 Apr 2021 10:38:37 +0200 Halil Pasic <[email protected]> wrote:
Quoted 11 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Signed-off-by Pierre Morel <[email protected]>Acked-by Halil Pasic <[email protected]>I did not look into the whole scsw.count stuff or into wether your changes to 3270 (look form <mark></mark> in the diff part) affect more than just ccw_dstream_*.
I would have preferred this patch split up based on the intended effect and thus also subsystem (css, virtio-ccw, 3270), but I've alluded to that before, and since we are in a hurry I can live with it as is.
Regards,
HalilQuoted 43 lines
--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)hw/char/terminal3270.c +9
-2@@ -200,9 +200,13 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) {Terminal3270 *t =TERMINAL_3270 (dev);int len; +int ret; len =MIN (ccw_dstream_avail (get_cds (t)), t->in_len); -ccw_dstream_write_buf (get_cds (t), t->inv, len); + ret =ccw_dstream_write_buf (get_cds (t), t->inv, len); +if (ret <0 ) { +return ret; + } t->in_len -= len;return len;@@ -260,7 +264,10 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd) t->outv[out_len++] = cmd; do { - ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + retval = ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + if (retval < 0) { + return retval; + } count = ccw_dstream_avail(get_cds(t)); out_len += len;hw/s390x/3270-ccw.c +0
-0hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 33
Quoted 3 lines
hw/s390x/3270-ccw.c +0
-0@@ -31,6 +31,9 @@ static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) } len = ck->read_payload_3270 (dev);<mark>
hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 38
Quoted 5 lines
hw/s390x/3270-ccw.c +3
-0+if (len <0 ) { +return len; + } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;
Quoted 3 lines
</mark>
Do we eventually update scsw.count?
I think we can consider the contents of scsw.count 'unpredictable', no?
Quoted 19 lines
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 55
Quoted 6 lines
hw/s390x/3270-ccw.c +0
-0return 0 ;@@ -50,7 +53,7 @@ static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) len = ck->write_payload_3270 (dev, ccw->cmd_code);if (len <=0 ) {<mark>
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 56
Quoted 2 lines
hw/s390x/3270-ccw.c +1
-1-return -EIO ; +return len ? len : -EIO ;</mark>
Quoted 5 lines
hw/s390x/3270-ccw.c +0
-0} ccw_dev->sch->curr_status.scsw.count = ccw->count - len;hw/s390x/css.c +0
-0
Quoted 86 lines · Cornelia Huck
Quoted 83 lines · On Fri, 9 Apr 2021 10:38:37 +0200 Halil Pasic <[email protected]> wrote:
Quoted 11 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Signed-off-by Pierre Morel <[email protected]>Acked-by Halil Pasic <[email protected]>I did not look into the whole scsw.count stuff or into wether your changes to 3270 (look form <mark></mark> in the diff part) affect more than just ccw_dstream_*.
I would have preferred this patch split up based on the intended effect and thus also subsystem (css, virtio-ccw, 3270), but I've alluded to that before, and since we are in a hurry I can live with it as is.
Regards,
HalilQuoted 43 lines
--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)hw/char/terminal3270.c +9
-2@@ -200,9 +200,13 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) {Terminal3270 *t =TERMINAL_3270 (dev);int len; +int ret; len =MIN (ccw_dstream_avail (get_cds (t)), t->in_len); -ccw_dstream_write_buf (get_cds (t), t->inv, len); + ret =ccw_dstream_write_buf (get_cds (t), t->inv, len); +if (ret <0 ) { +return ret; + } t->in_len -= len;return len;@@ -260,7 +264,10 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd) t->outv[out_len++] = cmd; do { - ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + retval = ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + if (retval < 0) { + return retval; + } count = ccw_dstream_avail(get_cds(t)); out_len += len;hw/s390x/3270-ccw.c +0
-0hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 33
Quoted 3 lines
hw/s390x/3270-ccw.c +0
-0@@ -31,6 +31,9 @@ static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) } len = ck->read_payload_3270 (dev);<mark>
Quoted 5 lines
hw/s390x/3270-ccw.c +3
-0+if (len <0 ) { +return len; + } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;
Quoted 5 lines
Quoted 3 lines
</mark>
Do we eventually update scsw.count?
I think we can consider the contents of scsw.count 'unpredictable', no?
I think so, the (len < 0) here will trigger a program check and the POP specifies the count as "not meaningful" in case of a program check.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/s390x/3270-ccw.c +0
-0return 0 ;@@ -50,7 +53,7 @@ static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) len = ck->write_payload_3270 (dev, ccw->cmd_code);
Quoted 7 lines
Quoted 7 lines
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 55
Quoted 1 line
hw/s390x/3270-ccw.c +0
-0if (len <=0 ) {<mark>
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 56
Quoted 2 lines
hw/s390x/3270-ccw.c +1
-1-return -EIO ; +return len ? len : -EIO ;</mark>
Here we do not change the previous behavior.
This problem, if it is one, is not related to not checking the dstream read/write functions.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
hw/s390x/3270-ccw.c +0
-0} ccw_dev->sch->curr_status.scsw.count = ccw->count - len;hw/s390x/css.c +0
-0
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Quoted 87 lines · On Fri, 9 Apr 2021 11:55:56 +0200 Pierre Morel <[email protected]> wrote:
Quoted 86 lines · Cornelia Huck
Quoted 83 lines · On Fri, 9 Apr 2021 10:38:37 +0200 Halil Pasic <[email protected]> wrote:
Quoted 11 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Signed-off-by Pierre Morel <[email protected]>Acked-by Halil Pasic <[email protected]>I did not look into the whole scsw.count stuff or into wether your changes to 3270 (look form <mark></mark> in the diff part) affect more than just ccw_dstream_*.
I would have preferred this patch split up based on the intended effect and thus also subsystem (css, virtio-ccw, 3270), but I've alluded to that before, and since we are in a hurry I can live with it as is.
Regards,
HalilQuoted 43 lines
--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)hw/char/terminal3270.c +9
-2@@ -200,9 +200,13 @@ static int read_payload_3270(EmulatedCcw3270Device *dev) {Terminal3270 *t =TERMINAL_3270 (dev);int len; +int ret; len =MIN (ccw_dstream_avail (get_cds (t)), t->in_len); -ccw_dstream_write_buf (get_cds (t), t->inv, len); + ret =ccw_dstream_write_buf (get_cds (t), t->inv, len); +if (ret <0 ) { +return ret; + } t->in_len -= len;return len;@@ -260,7 +264,10 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd) t->outv[out_len++] = cmd; do { - ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + retval = ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len); + if (retval < 0) { + return retval; + } count = ccw_dstream_avail(get_cds(t)); out_len += len;hw/s390x/3270-ccw.c +0
-0hw/s390x/3270-ccw.c static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 33
Quoted 3 lines
hw/s390x/3270-ccw.c +0
-0@@ -31,6 +31,9 @@ static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) } len = ck->read_payload_3270 (dev);<mark>
Quoted 5 lines
hw/s390x/3270-ccw.c +3
-0+if (len <0 ) { +return len; + } ccw_dev->sch->curr_status.scsw.count = ccw->count - len;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
</mark>
Do we eventually update scsw.count?
I think we can consider the contents of scsw.count 'unpredictable', no?
I think so, the (len < 0) here will trigger a program check and the POP specifies the count as "not meaningful" in case of a program check.
Yes, that's what I meant.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 55
Quoted 9 lines
hw/s390x/3270-ccw.c +0
-0return 0 ;@@ -50,7 +53,7 @@ static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) len = ck->write_payload_3270 (dev, ccw->cmd_code);if (len <=0 ) {<mark>
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
hw/s390x/3270-ccw.c static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) · line 56
Quoted 2 lines
hw/s390x/3270-ccw.c +1
-1-return -EIO ; +return len ? len : -EIO ;</mark>
Here we do not change the previous behavior.
This problem, if it is one, is not related to not checking the dstream read/write functions.
I agree.
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
hw/s390x/3270-ccw.c +0
-0} ccw_dev->sch->curr_status.scsw.count = ccw->count - len;hw/s390x/css.c +0
-0
Quoted 10 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)
Thanks, queued to s390-fixes (with cc:stable added.)
Quoted 21 lines · Cornelia Huck
Quoted 10 lines · On Thu, 8 Apr 2021 18:32:09 +0200 Pierre Morel <[email protected]> wrote:
ccw_dstream_read/write functions returned values are sometime not taking into account and reported back to the upper level of interpretation of CCW instructions.
It follows that accessing an invalid address does not trigger a subchannel status program check to the guest as it should.
Let's test the return values of ccw_dstream_write[_buf] and ccw_dstream_read[_buf] and report it to the caller.
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>--- hw/char/terminal3270.c | 11 +++++-- hw/s390x/3270-ccw.c | 5 +++- hw/s390x/css.c | 14 +++++---- hw/s390x/virtio-ccw.c | 66 ++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 27 deletions(-)
Quoted 2 lines
Thanks, queued to s390-fixes (with cc:stable added.)
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen