From patchwork Tue Aug 21 02:51:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Zbitskiy X-Patchwork-Id: 10570941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 489ED112E for ; Tue, 21 Aug 2018 02:58:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37A4729EFF for ; Tue, 21 Aug 2018 02:58:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A04E29F25; Tue, 21 Aug 2018 02:58:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA35129EFF for ; Tue, 21 Aug 2018 02:58:34 +0000 (UTC) Received: from localhost ([::1]:50393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frwsL-0000rT-Sd for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Aug 2018 22:58:33 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 >=. 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 >=, and not >. Likewise for len_src == 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--; /* now pack every value */ - while (len_dest >= 0) { + while (len_dest > 0) { b = 0; - if (len_src > 0) { + if (len_src >= 0) { b = cpu_ldub_data_ra(env, src, ra) & 0x0f; src--; len_src--; } - if (len_src > 0) { + if (len_src >= 0) { b |= cpu_ldub_data_ra(env, src, ra) << 4; src--; len_src--; diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target index 7de4376f52..151dc075aa 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -5,3 +5,4 @@ TESTS+=csst TESTS+=ipm TESTS+=exrl-trt TESTS+=exrl-trtr +TESTS+=pack 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[] = {0xaa, 0xaa, 0xf1, 0xf2, 0xf3, 0xc4, 0xaa, 0xaa}; + char exp[] = {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 = 0; i < 8; i++) { + if (data[i] != exp[i]) { + write(1, "bad data\n", 9); + return 1; + } + } + return 0; +}