From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avhff-0005OZ-Bt for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:51:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avhfe-0007hr-AZ for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:51:39 -0400 Received: from hall.aurel32.net ([2001:bc8:30d7:100::1]:54028) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avhfe-0007gq-4A for qemu-devel@nongnu.org; Thu, 28 Apr 2016 04:51:38 -0400 Date: Thu, 28 Apr 2016 10:51:28 +0200 From: Aurelien Jarno Message-ID: <20160428085128.GC13339@aurel32.net> References: <1461795666-4704-1-git-send-email-james.hogan@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1461795666-4704-1-git-send-email-james.hogan@imgtec.com> 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: James Hogan Cc: qemu-devel@nongnu.org, Leon Alrae , Yongbok Kim 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(). > > 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. > > 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. > > 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. > > 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(-) 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. Reviewed-by: Aurelien Jarno -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://www.aurel32.net