From nobody Wed Nov 5 10:07:11 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 15338703959951021.2810106590921; Thu, 9 Aug 2018 20:06:35 -0700 (PDT) Received: from localhost ([::1]:54011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnxl4-0000qc-SE for importer@patchew.org; Thu, 09 Aug 2018 23:06:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnxiQ-00068x-89 for qemu-devel@nongnu.org; Thu, 09 Aug 2018 23:03:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnxiP-0004BD-EQ for qemu-devel@nongnu.org; Thu, 09 Aug 2018 23:03:50 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:44469) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnxiP-0004A8-9R; Thu, 09 Aug 2018 23:03:49 -0400 Received: by mail-qt0-x242.google.com with SMTP id b15-v6so8852094qtp.11; Thu, 09 Aug 2018 20:03:49 -0700 (PDT) Received: from WAL-L-PZ01.rocketsoftware.com ([2620:117:0:a::c]) by smtp.gmail.com with ESMTPSA id i1-v6sm4457425qtj.65.2018.08.09.20.03.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 20:03:47 -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=BV4WN+AaurihIjW0NPhlY6Sq+TgS+qGzkdHmdcL2bLngI+y64RuHj8AgwPupHVQqDW 1myaWUDenQmRh/PYZ+ylFAWTpREat44DaJjXuXvi0qlAg6CCpw3E6/oQ00PznBuVuVZl 8Z0pSr+fgvfAhlzNg+SWza0EhllSY6jF5zynFqy5BNThu3kQuWsVuhIduAkvk0yyu2sD MZJPaGBXz/uZ8fVQaM6/8uVgvGtz+JCs025DhA15AlFzjnnVnxxzvrghnHg8DY5iAYys O8eOKMTRfAq5TNsEGBTIz/y1u0oLtUVcgWRIrbmS6nUaRO8nCSEWUSV7JXAyIPytUwFV E89Q== 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=Nl8zJTgFLHfU2g/69a8HtNfZLFi1RDNoKaZSemCcKXX7KBMrARkwAlH2TO9QOCRj8f 0SpQfw9XBvAgbcn5muYAXB8ISOZvZVN6cr7gcosGzVzPtXFDaS6K0Dp/G0YkxYu58+Q1 Fa6gdXqm+qmgiUmuEOpcD6GLvLm2BCJKRtM90swsACi0mZ71knEayjVj8r/r4JH87XkI lCwNaD/qvWxCcmToW0D34MisIahyTcZYMNh7tYS4xjPUIN0YGShJk51ta6Q17huF1ICf pLUBouYV+irVgb8OpXYoLaVePHORWez1qmk0LDBRSX/LQJO74+tC9PL3pjFcR1YKfJad lKcg== X-Gm-Message-State: AOUpUlH3ZXRck/mXVfO6GHjsBK06PvfVDACBMDBRSRpeY6m6pXExPEst 0xNkff9exs3S5c+2oeEMbUr0+Jar2t0= X-Google-Smtp-Source: AA+uWPwU1mxFLUOgmBrZGkCrcCR/ZVpMi2axhacIjgbf/IvKfzHBYZQQT+gQXJfJMnAHuwfb68jJFA== X-Received: by 2002:ac8:fc9:: with SMTP id f9-v6mr4837844qtk.377.1533870228318; Thu, 09 Aug 2018 20:03:48 -0700 (PDT) From: Pavel Zbitskiy To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2018 23:01:38 -0400 Message-Id: <20180810030139.25916-7-pavel.zbitskiy@gmail.com> In-Reply-To: <20180810030139.25916-1-pavel.zbitskiy@gmail.com> References: <20180810030139.25916-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:c0d::242 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 --- 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