From owner-svn-src-all@freebsd.org Wed Sep 23 00:09:30 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AB9E23E5858; Wed, 23 Sep 2020 00:09:30 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bwz7Z3sDgz3fjL; Wed, 23 Sep 2020 00:09:30 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 692F72784A; Wed, 23 Sep 2020 00:09:30 +0000 (UTC) (envelope-from bdragon@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08N09Uae016449; Wed, 23 Sep 2020 00:09:30 GMT (envelope-from bdragon@FreeBSD.org) Received: (from bdragon@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08N09ThC016444; Wed, 23 Sep 2020 00:09:29 GMT (envelope-from bdragon@FreeBSD.org) Message-Id: <202009230009.08N09ThC016444@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdragon set sender to bdragon@FreeBSD.org using -f From: Brandon Bergren Date: Wed, 23 Sep 2020 00:09:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366037 - in head/sys: conf powerpc/conf powerpc/ofw powerpc/powernv X-SVN-Group: head X-SVN-Commit-Author: bdragon X-SVN-Commit-Paths: in head/sys: conf powerpc/conf powerpc/ofw powerpc/powernv X-SVN-Commit-Revision: 366037 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2020 00:09:30 -0000 Author: bdragon Date: Wed Sep 23 00:09:29 2020 New Revision: 366037 URL: https://svnweb.freebsd.org/changeset/base/366037 Log: [PowerPC64LE] Work around qemu TCG bug in mtmsrd emulation. The TCG implementation of mtmsrd in qemu blindly copies the entire register to the MSR, instead of the specific bit positions listed in the ISA. This means that qemu will prematurely switch endian out from under the running code instead of waiting for the rfid, causing an immediate trap as it attempts to interpret the next instruction in the wrong endianness. To work around this, ensure PSL_LE is still set before doing the mtmsrd. In the future, we may wish to just turn off translation and unconditionally use rfid to switch to the ofmsr instead of quasi-switching to the ofmsr. Add a new platform option so this can be disabled. (And so that we can conditonalize additional QEMU-specific hacks in the platform code.) Sponsored by: Tag1 Consulting, Inc. Modified: head/sys/conf/options.powerpc head/sys/powerpc/conf/GENERIC64 head/sys/powerpc/conf/NOTES head/sys/powerpc/ofw/ofwcall64.S head/sys/powerpc/powernv/opalcall.S Modified: head/sys/conf/options.powerpc ============================================================================== --- head/sys/conf/options.powerpc Wed Sep 23 00:06:48 2020 (r366036) +++ head/sys/conf/options.powerpc Wed Sep 23 00:09:29 2020 (r366037) @@ -29,6 +29,7 @@ MAMBO POWERNV opt_platform.h PSERIES PSIM +QEMU opt_platform.h SC_OFWFB opt_ofwfb.h Modified: head/sys/powerpc/conf/GENERIC64 ============================================================================== --- head/sys/powerpc/conf/GENERIC64 Wed Sep 23 00:06:48 2020 (r366036) +++ head/sys/powerpc/conf/GENERIC64 Wed Sep 23 00:09:29 2020 (r366037) @@ -30,6 +30,7 @@ makeoptions WITH_CTF=1 options POWERMAC #NewWorld Apple PowerMacs options PS3 #Sony Playstation 3 options MAMBO #IBM Mambo Full System Simulator +options QEMU #QEMU processor emulator options PSERIES #PAPR-compliant systems (e.g. IBM p) options POWERNV #Non-virtualized OpenPOWER systems Modified: head/sys/powerpc/conf/NOTES ============================================================================== --- head/sys/powerpc/conf/NOTES Wed Sep 23 00:06:48 2020 (r366036) +++ head/sys/powerpc/conf/NOTES Wed Sep 23 00:09:29 2020 (r366037) @@ -44,6 +44,7 @@ options POWERMAC #NewWorld Apple PowerMacs #options PS3 #Sony Playstation 3 options PSIM #GDB PSIM ppc simulator options MAMBO #IBM Mambo Full System Simulator +options QEMU #QEMU processor emulator # The cpufreq(4) driver provides support for CPU frequency control device cpufreq Modified: head/sys/powerpc/ofw/ofwcall64.S ============================================================================== --- head/sys/powerpc/ofw/ofwcall64.S Wed Sep 23 00:06:48 2020 (r366036) +++ head/sys/powerpc/ofw/ofwcall64.S Wed Sep 23 00:09:29 2020 (r366037) @@ -32,6 +32,8 @@ #include #include +#include "opt_platform.h" + #define OFWSTKSZ 4096 /* 4K Open Firmware stack */ /* @@ -119,6 +121,10 @@ ASENTRY_NOPROF(ofwcall) addis %r5,%r2,TOC_REF(ofmsr)@ha ld %r5,TOC_REF(ofmsr)@l(%r5) ld %r5,0(%r5) +#if defined(__LITTLE_ENDIAN__) && defined(QEMU) + /* QEMU hack: qemu does not emulate mtmsrd correctly! */ + ori %r5,%r5,1 /* Leave PSR_LE set */ +#endif mtmsrd %r5 isync @@ -270,6 +276,10 @@ ASENTRY_NOPROF(rtascall) addis %r7,%r2,TOC_REF(rtasmsr)@ha ld %r7,TOC_REF(rtasmsr)@l(%r7) ld %r7,0(%r7) +#ifdef __LITTLE_ENDIAN__ + /* QEMU hack: qemu does not emulate mtmsrd correctly! */ + ori %r7,%r7,1 /* Leave PSR_LE set */ +#endif mtmsrd %r7 isync Modified: head/sys/powerpc/powernv/opalcall.S ============================================================================== --- head/sys/powerpc/powernv/opalcall.S Wed Sep 23 00:06:48 2020 (r366036) +++ head/sys/powerpc/powernv/opalcall.S Wed Sep 23 00:09:29 2020 (r366037) @@ -27,6 +27,8 @@ #include +#include "opt_platform.h" + GLOBAL(opal_entrypoint) .llong 0 GLOBAL(opal_data) @@ -70,8 +72,17 @@ ASENTRY(opal_call) ld %r2,TOC_REF(opal_data)@l(%r2) ld %r2,0(%r2) + +#if defined(__LITTLE_ENDIAN__) && defined(QEMU) + /* QEMU hack: qemu does not emulate mtmsrd correctly! */ + ori %r3,%r3,1 /* Leave PSR_LE set */ +#endif mtmsrd %r3 isync +#if defined(__LITTLE_ENDIAN__) && defined(QEMU) + /* Clean up from qemu hack */ + xori %r3,%r3,1 +#endif /* Shift registers over */ mr %r3,%r4