From nobody Wed Nov 5 14:25:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534820330145943.8092089030552; Mon, 20 Aug 2018 19:58:50 -0700 (PDT) Received: from localhost ([::1]:50394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frwsa-00017x-UH for importer@patchew.org; Mon, 20 Aug 2018 22:58:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frwlc-0004Am-Af for qemu-devel@nongnu.org; Mon, 20 Aug 2018 22:51:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frwlb-0004ju-C9 for qemu-devel@nongnu.org; Mon, 20 Aug 2018 22:51:36 -0400 Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]:38148) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frwlb-0004jg-84; Mon, 20 Aug 2018 22:51:35 -0400 Received: by mail-qk0-x236.google.com with SMTP id g197-v6so830938qke.5; Mon, 20 Aug 2018 19:51:34 -0700 (PDT) Received: from WAL-L-PZ01.rocketsoftware.com (inet-64-112-177-9.bos.netblazr.com. [64.112.177.9]) by smtp.gmail.com with ESMTPSA id d100-v6sm4897991qkh.34.2018.08.20.19.51.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 19:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LbyHSl2hUt8aBAYCRJx6cP1mlH3i/VVzz9/twYYyQPc=; b=XMKGrGzl9QCpQLZVZVhVIXhjk3eHub7G4LWC2fCP+YtKV0Uzo8/ytBOhThbe4XeucW k43b44w3vHZItVQfdy3ZKUXGfSgj+H9NkceIyEOdDWVJYyRn5uyeVMpmFnZCRjCDJQph 8wQut5PZuoApIg+K4uWQpB99y5/fcixXah4axSbg5c9ma+Zwvalj5z6U1iE7by7bnUpu 7bdiZH80Cqpkw7r+4f7TSEYgV0UseDdoLz+2JTKinaWTCV58s0kHZv1WeLWdcZKpJ4fx h9pR1zp0x/uFb4dLwJVORtACjVF380S1nz38eN45nBgTn80f1Yha8n8OoxFI0+yJsr0h jQKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LbyHSl2hUt8aBAYCRJx6cP1mlH3i/VVzz9/twYYyQPc=; b=uEnbCPk/JQu+KqEEN5XFN+4M1fWwtA4qCxIW9LKzIj+tvB6xhpp6wf39Vt5k0hzJ6k PoV0qXw7xCDj/EcrHuVf1p5NtDdMPmu4cQ0o9rRf961heDEfj5lhFZkCloe4pfzydR3B pRiELzOpgcmfxa/rDu8y9quXIDS3Dr3mvNefnsUu01CHPBz3STwMO+bY2jvN0EEepq/4 JaK0z0ecX2POug3948d2DJTJa2GS1ZXolTazOVkYuudYF0dZIhDd+kNs6lbf0fEhQOoE oTP6tsKZd4fYDOLPeK7ANo9fgfuUroDgNBT/k003+Mf0xfvGEcU5E1bGysdSppdSw2c3 i5hw== X-Gm-Message-State: AOUpUlHVPjAhFfGL4Ulnuzn4d5zZiVeHXHtuE3NSIraMYU2ZqP9z5f9D DJv/N3f3Zx43+MqbL9VxZVJCatURuEI= X-Google-Smtp-Source: AA+uWPxvhrdlEi2K7q4pdkzGLb0j0ugzvWuOtm+0Zm5/AQHPLofLj0cNWtx2Vdw7slkgt7u4fxgoDQ== X-Received: by 2002:a37:2b8d:: with SMTP id r13-v6mr17080294qkr.198.1534819894410; Mon, 20 Aug 2018 19:51:34 -0700 (PDT) From: Pavel Zbitskiy To: qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 22:51:03 -0400 Message-Id: <20180821025104.19604-7-pavel.zbitskiy@gmail.com> In-Reply-To: <20180821025104.19604-1-pavel.zbitskiy@gmail.com> References: <20180821025104.19604-1-pavel.zbitskiy@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::236 Subject: [Qemu-devel] [PATCH 6/7] target/s390x: fix PACK reading 1 byte less and writing 1 byte more X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Zbitskiy , david@redhat.com, cohuck@redhat.com, richard.henderson@linaro.org, Alexander Graf , qemu-s390x@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" PACK fails on the test from the Principles of Operation: F1F2F3F4 becomes 0000234C instead of 0001234C due to an off-by-one error. Furthermore, it overwrites one extra byte to the left of F1. If len_dest is 0, then we only want to flip the 1st byte and never loop over the rest. Therefore, the loop condition should be > and not >=3D. If len_src is 1, then we should flip the 1st byte and pack the 2nd. Since len_src is already decremented before the loop, the first condition should be >=3D, and not >. Likewise for len_src =3D=3D 2 and the second condition. Signed-off-by: Pavel Zbitskiy Reviewed-by: David Hildenbrand --- target/s390x/mem_helper.c | 6 +++--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/pack.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/s390x/pack.c diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c index 704d0193b5..bacae4f503 100644 --- a/target/s390x/mem_helper.c +++ b/target/s390x/mem_helper.c @@ -1019,15 +1019,15 @@ void HELPER(pack)(CPUS390XState *env, uint32_t len,= uint64_t dest, uint64_t src) len_src--; =20 /* now pack every value */ - while (len_dest >=3D 0) { + while (len_dest > 0) { b =3D 0; =20 - if (len_src > 0) { + if (len_src >=3D 0) { b =3D cpu_ldub_data_ra(env, src, ra) & 0x0f; src--; len_src--; } - if (len_src > 0) { + if (len_src >=3D 0) { b |=3D cpu_ldub_data_ra(env, src, ra) << 4; src--; len_src--; diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index 7de4376f52..151dc075aa 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -5,3 +5,4 @@ TESTS+=3Dcsst TESTS+=3Dipm TESTS+=3Dexrl-trt TESTS+=3Dexrl-trtr +TESTS+=3Dpack diff --git a/tests/tcg/s390x/pack.c b/tests/tcg/s390x/pack.c new file mode 100644 index 0000000000..4be36f29a7 --- /dev/null +++ b/tests/tcg/s390x/pack.c @@ -0,0 +1,21 @@ +#include + +int main(void) +{ + char data[] =3D {0xaa, 0xaa, 0xf1, 0xf2, 0xf3, 0xc4, 0xaa, 0xaa}; + char exp[] =3D {0xaa, 0xaa, 0x00, 0x01, 0x23, 0x4c, 0xaa, 0xaa}; + int i; + + asm volatile( + " pack 2(4,%[data]),2(4,%[data])\n" + : + : [data] "r" (&data[0]) + : "memory"); + for (i =3D 0; i < 8; i++) { + if (data[i] !=3D exp[i]) { + write(1, "bad data\n", 9); + return 1; + } + } + return 0; +} --=20 2.18.0