From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avhjG-0002Hu-Nc for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:55:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avhjC-0008Pd-7H for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:55:22 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:42862 helo=imgpgp01.kl.imgtec.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avhjB-0008PV-VB for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:55:18 -0400 Date: Thu, 28 Apr 2016 09:55:16 +0100 From: James Hogan Message-ID: <20160428085516.GD19902@jhogan-linux.le.imgtec.org> References: <1461795666-4704-1-git-send-email-james.hogan@imgtec.com> <20160428085128.GC13339@aurel32.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="yudcn1FV7Hsu/q59" Content-Disposition: inline In-Reply-To: <20160428085128.GC13339@aurel32.net> Subject: Re: [Qemu-devel] [PATCH] target-mips: Fix RDHWR exception host PC List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno Cc: qemu-devel@nongnu.org, Leon Alrae , Yongbok Kim --yudcn1FV7Hsu/q59 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 28, 2016 at 10:51:28AM +0200, Aurelien Jarno wrote: > On 2016-04-27 23:21, James Hogan wrote: > > Commit b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR") > > changed the rdhwr helpers to use check_hwrena() to check the register > > being accessed is enabled in CP0_HWREna when used from user mode. If > > that check fails an EXCP_RI exception is raised at the host PC > > calculated with GETPC(). > >=20 > > However check_hwrena() may not be fully inlined as the > > do_raise_exception() part of it is common regardless of the arguments. > > This causes GETPC() to calculate the address in the call in the helper > > instead of the generated code calling the helper. No TB will be found > > and the EPC reported with the resulting guest RI exception points to the > > beginning of the TB instead of the RDHWR instruction. > >=20 > > We can't reliably force check_hwrena() to be inlined, and converting it > > to a macro would be ugly, so instead pass the host PC in as an argument, > > with each rdhwr helper passing GETPC(). This should avoid any dependence > > on compiler behaviour, and in practice seems to prevent the partial > > inlining of check_hwrena() on x86_64. > >=20 > > This issue causes failures when running a MIPS KVM (trap & emulate) > > guest in a MIPS QEMU TCG guest, as the inner guest kernel will do a > > RDHWR of counter, which is disabled in the outer guest's CP0_HWREna by > > KVM so it can emulate the inner guest's counter. The emulation fails and > > the RI exception is passed to the inner guest. > >=20 > > Fixes: b00c72180c36 ("target-mips: add PC, XNP reg numbers to RDHWR") > > Signed-off-by: James Hogan > > Cc: Leon Alrae > > Cc: Yongbok Kim > > Cc: Aurelien Jarno > > --- > > target-mips/op_helper.c | 16 ++++++++-------- > > 1 file changed, 8 insertions(+), 8 deletions(-) >=20 > Thanks for the detailed analysis. The other solution would have been to > declare the function as __attribute__((__always_inline__)), but I think > your solution is even better. Yeh, I did try this first but I got big fat warnings from GCC like this one that probably rightly scared me off that approach: CC mips64el-softmmu/target-mips/op_helper.o target-mips/op_helper.c +2297 :48: error: always_inline function might not = be inlinable [-Werror=3Dattributes] static __attribute__((__always_inline__)) void check_hwrena(CPUMIPSState *= env, int reg) ^ >=20 > Reviewed-by: Aurelien Jarno Thanks! Cheers James --yudcn1FV7Hsu/q59 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXIc/0AAoJEGwLaZPeOHZ69EAP/30lmxNJinuBBUWgyZY8lKrT eUtq+K3VVNSKjnhXVA/eKZGyh6vQ7xUk2xi2bQtSpcZuIN/wOUwor3HB2Lw0fRf3 PuZuvWQtYCGbMoKL/l+Xp9ZEhnidmlzdXA7CJxsbjnoa5MczDBnYFTkrzLl1orSR vRs76ngY4N7+WjbZuZMcNZ8izFRtXqDCb2CeOkKVYokbDtMvP7rBAecZWmqxo3SU SEDhn6H7uUTcKI6gfSuCoybX5C85YL0c9V3YTz1A3IfJ/iLlS3jL0a5YJk3oKr40 RqfH1OTAE40Pz6Fn2gDVWhkgFakm/IlJn5ZD12qDXtGIYOXvMyDlI2YXbocvROUy IJ7UJZJ2EdjAVaRebMLaf/8AgKmJ+/g4tEGxxvdYQJgQQGlRPFW30L3n6e4wNw+Q xzOrKwpTyUJ2qiS69MlUyZp0G8dTJnXgcr+yVAl2ooZQkHzYqwUT2I+ZLIXtU29j mj+ajvs1LH8i5Z7wCZufO/PWN1KeAyje3nE9Nf/3MIOVwaLMo6k0/9VXrVbtWXhK TMqMCujXppgmsw965P6fZ77FDU55/Ok4kb4j9u3zZE/WAkrpVCc9Wjij6SIWZsKB EN6en6uj6A2BUaOAhHF8CBYeiQm8c99QGZhgyB99B6p22VFpk245ZIy4pKNVBgZb vHRx4S7kenHvk1HPOi7a =uqsx -----END PGP SIGNATURE----- --yudcn1FV7Hsu/q59--