{"id":816383,"url":"http://patchwork.ozlabs.org/api/patches/816383/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170920172314.102710-3-pasic@linux.vnet.ibm.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170920172314.102710-3-pasic@linux.vnet.ibm.com>","list_archive_url":null,"date":"2017-09-20T17:23:14","name":"[2/2] s390x/3270: handle writes of arbitrary length","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5a3e7d388646dd221f05bb11603714e9dbae47d1","submitter":{"id":68297,"url":"http://patchwork.ozlabs.org/api/people/68297/?format=json","name":"Halil Pasic","email":"pasic@linux.vnet.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170920172314.102710-3-pasic@linux.vnet.ibm.com/mbox/","series":[{"id":4185,"url":"http://patchwork.ozlabs.org/api/series/4185/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4185","date":"2017-09-20T17:23:12","name":"3270 improvements","version":1,"mbox":"http://patchwork.ozlabs.org/series/4185/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816383/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816383/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xy67261fQz9t2V\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 03:24:30 +1000 (AEST)","from localhost ([::1]:49909 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duijc-0005B1-T2\n\tfor incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 13:24:28 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:51664)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pasic@linux.vnet.ibm.com>) id 1duiiw-00057S-7v\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 13:23:48 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pasic@linux.vnet.ibm.com>) id 1duiit-000624-Gp\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 13:23:46 -0400","from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38070)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pasic@linux.vnet.ibm.com>)\n\tid 1duiit-00060s-7d\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 13:23:43 -0400","from pps.filterd (m0098404.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv8KHLteK093667\n\tfor <qemu-devel@nongnu.org>; Wed, 20 Sep 2017 13:23:41 -0400","from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2d3ueqmxu8-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <qemu-devel@nongnu.org>; Wed, 20 Sep 2017 13:23:40 -0400","from localhost\n\tby e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <qemu-devel@nongnu.org> from <pasic@linux.vnet.ibm.com>;\n\tWed, 20 Sep 2017 18:23:38 +0100","from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196)\n\tby e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tWed, 20 Sep 2017 18:23:35 +0100","from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com\n\t[9.149.105.58])\n\tby b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v8KHNYpP21299338; Wed, 20 Sep 2017 17:23:34 GMT","from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 5C3434C046;\n\tWed, 20 Sep 2017 18:19:58 +0100 (BST)","from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 1F28E4C040;\n\tWed, 20 Sep 2017 18:19:58 +0100 (BST)","from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9])\n\tby d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS;\n\tWed, 20 Sep 2017 18:19:58 +0100 (BST)"],"From":"Halil Pasic <pasic@linux.vnet.ibm.com>","To":"Cornelia Huck <cohuck@redhat.com>,\n\tChristian Borntraeger <borntraeger@de.ibm.com>","Date":"Wed, 20 Sep 2017 19:23:14 +0200","X-Mailer":"git-send-email 2.13.5","In-Reply-To":"<20170920172314.102710-1-pasic@linux.vnet.ibm.com>","References":"<20170920172314.102710-1-pasic@linux.vnet.ibm.com>","X-TM-AS-GCONF":"00","x-cbid":"17092017-0040-0000-0000-000003DBC014","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17092017-0041-0000-0000-000025DCF6CF","Message-Id":"<20170920172314.102710-3-pasic@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-20_04:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=0\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709200234","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy]","X-Received-From":"148.163.156.1","Subject":"[Qemu-devel] [PATCH 2/2] s390x/3270: handle writes of arbitrary\n\tlength","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Halil Pasic <pasic@linux.vnet.ibm.com>, qemu-devel@nongnu.org,\n\tAlexander Graf <agraf@suse.de>,\n\t\"Jason J . Herne\" <jjherne@linux.vnet.ibm.com>,\n\tDong Jia Shi <bjsdjshi@linux.vnet.ibm.com>,\n\tRichard Henderson <rth@twiddle.net>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"The problem is, that the current implementation places unrealistic and\narbitrary constraints on the length of writes to the device (that is the\noutbound requests), by asserting ccw.count being such that that even the\nworst case escaped payload will fit an  more or less arbitrary sized\nbuffer. Actually on protocol level there is nothing to justify such\na limitation.\n\nAnother strange thing is the return value which more or less reflects\nthe size (written) after escaping instead of before escaping. This\nis strange, because this return value is used to calculate SCSW.count.\n\nLet us teach 3270 how to deal with arbitrary long writes.\n\nSigned-off-by: Halil Pasic <pasic@linux.vnet.ibm.com>\nAcked-by: Christian Borntraeger <borntraeger@de.ibm.com>\nReviewed-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>\nReported-by: Jason J . Herne <jjherne@linux.vnet.ibm.com>\nTested-by: Jason J . Herne <jjherne@linux.vnet.ibm.com>\n---\n hw/char/terminal3270.c | 30 ++++++++++++++++++------------\n 1 file changed, 18 insertions(+), 12 deletions(-)","diff":"diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c\nindex c976a63cc2..a109ce5987 100644\n--- a/hw/char/terminal3270.c\n+++ b/hw/char/terminal3270.c\n@@ -30,7 +30,6 @@ typedef struct Terminal3270 {\n     uint8_t inv[INPUT_BUFFER_SIZE];\n     uint8_t outv[OUTPUT_BUFFER_SIZE];\n     int in_len;\n-    int out_len;\n     bool handshake_done;\n     guint timer_tag;\n } Terminal3270;\n@@ -145,7 +144,6 @@ static void chr_event(void *opaque, int event)\n \n     /* Ensure the initial status correct, always reset them. */\n     t->in_len = 0;\n-    t->out_len = 0;\n     t->handshake_done = false;\n     if (t->timer_tag) {\n         g_source_remove(t->timer_tag);\n@@ -231,8 +229,9 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd)\n     Terminal3270 *t = TERMINAL_3270(dev);\n     int retval = 0;\n     int count = ccw_dstream_avail(get_cds(t));\n-\n-    assert(count <= (OUTPUT_BUFFER_SIZE - 3) / 2);\n+    int bound = (OUTPUT_BUFFER_SIZE - 3) / 2;\n+    int len = MIN(count, bound);\n+    int out_len = 0;\n \n     if (!t->handshake_done) {\n         if (!(t->outv[0] == IAC && t->outv[1] != IAC)) {\n@@ -247,16 +246,23 @@ static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd)\n         /* We just say we consumed all data if there's no backend. */\n         return count;\n     }\n-    t->outv[0] = cmd;\n-    ccw_dstream_read_buf(get_cds(t), &t->outv[1], count);\n-    t->out_len = count + 1;\n \n-    t->out_len = insert_IAC_escape_char(t->outv, t->out_len);\n-    t->outv[t->out_len++] = IAC;\n-    t->outv[t->out_len++] = IAC_EOR;\n+    t->outv[out_len++] = cmd;\n+    do {\n+        ccw_dstream_read_buf(get_cds(t), &t->outv[out_len], len);\n+        count = ccw_dstream_avail(get_cds(t));\n+        out_len += len;\n \n-    retval = qemu_chr_fe_write_all(&t->chr, t->outv, t->out_len);\n-    return (retval <= 0) ? 0 : (retval - 3);\n+        out_len = insert_IAC_escape_char(t->outv, out_len);\n+        if (!count) {\n+            t->outv[out_len++] = IAC;\n+            t->outv[out_len++] = IAC_EOR;\n+        }\n+        retval = qemu_chr_fe_write_all(&t->chr, t->outv, out_len);\n+        len = MIN(count, bound);\n+        out_len = 0;\n+    } while (len && retval >= 0);\n+    return (retval <= 0) ? 0 : get_cds(t)->count;\n }\n \n static Property terminal_properties[] = {\n","prefixes":["2/2"]}