From nobody Sat Sep 28 22:43:26 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548701140741383.92701450563527; Mon, 28 Jan 2019 10:45:40 -0800 (PST) Received: from localhost ([127.0.0.1]:36875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBuT-0005r0-Jh for importer@patchew.org; Mon, 28 Jan 2019 13:45:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBN9-0002fX-OB for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goBN8-0008OQ-8T for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:03 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:41234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goBN7-0008Hl-U0 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:02 -0500 Received: by mail-wr1-x42a.google.com with SMTP id x10so19122664wrs.8 for ; Mon, 28 Jan 2019 10:10:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id b18sm97910681wrw.83.2019.01.28.10.10.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 10:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sgxndn8yvcv9jGeYe3WGmBhKDBlYqLQWYGqaHVEw8D8=; b=FkHEFBk81DCp4GMw5yLodv5SZeUxP2ZDxDZkrnevSk3pWROmCS5zEjhOr9DPXhxJ2W 7rlzcDwCGe0f19Z3Pq3TZrafY9h0dKC9qA9CZZM8RfNe6YfjNw+LNyj5FamK2muCu7b0 PuoCFyMSqq80X54UFBAvj4lOk8klDl/sLS7y4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sgxndn8yvcv9jGeYe3WGmBhKDBlYqLQWYGqaHVEw8D8=; b=ajXedJ8Xcyjkuc27oJrzudmA0i652QKcxF7i54iAJUM/hcK1kq+X+Cv7JD/nLAgI17 QCf8KvGV0xCgDDsoViJyPomUrA13ajk4aA9AtUK5TfRYoEWIOnxb2BS8vzm9xadtTfu7 TKs/igpiK/ae/o1uagCaFCAFqzRWvob6OJ361nxbWUAeutQdoqTfyEoS+hkjf/CNloTv dmMwjVJpuLDzo0VRiHwAiS0hpV/S/KJNUDjhMFB3YgtMzdi2Ty9Kqrl3u2gQ8njcnsIg Ecuk8Z8eijcDhYVSzsl9rwvWJyWMVX6L6fzTeR4d70nWoHbUn9o5JDORIZN3EXkH1ZEX 7G2g== X-Gm-Message-State: AJcUukdwYc1gApYaGRx/ACubFv2XU/ZIB3XsXdIq+FGyk7nBq3NW0da2 F09JV+malWKGjnDsFA3Zvsg6moKruDUVEQ== X-Google-Smtp-Source: ALg8bN6EWRHdEl49vSyDWiT3eoUdeerVSQMR3FRgT57kA8WFfi8Fqb3XDFHO/bW2s5rXVO0V+TPCiw== X-Received: by 2002:adf:f903:: with SMTP id b3mr23718000wrr.82.1548699058518; Mon, 28 Jan 2019 10:10:58 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 18:10:28 +0000 Message-Id: <20190128181047.20781-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128181047.20781-1-peter.maydell@linaro.org> References: <20190128181047.20781-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42a Subject: [Qemu-devel] [PULL 07/26] accel/tcg/user-exec: Don't parse aarch64 insns to test for read vs write 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In cpu_signal_handler() for aarch64 hosts, currently we parse the faulting instruction to see if it is a load or a store. Since the 3.16 kernel (~2014), the kernel has provided us with the syndrome register for a fault, which includes the WnR bit. Use this instead if it is present, only falling back to instruction parsing if not. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20190108180014.32386-1-peter.maydell@linaro.org --- accel/tcg/user-exec.c | 66 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 941295ea49b..66cc818e3f3 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -479,28 +479,66 @@ int cpu_signal_handler(int host_signum, void *pinfo, =20 #elif defined(__aarch64__) =20 +#ifndef ESR_MAGIC +/* Pre-3.16 kernel headers don't have these, so provide fallback definitio= ns */ +#define ESR_MAGIC 0x45535201 +struct esr_context { + struct _aarch64_ctx head; + uint64_t esr; +}; +#endif + +static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc) +{ + return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved; +} + +static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr) +{ + return (struct _aarch64_ctx *)((char *)hdr + hdr->size); +} + int cpu_signal_handler(int host_signum, void *pinfo, void *puc) { siginfo_t *info =3D pinfo; ucontext_t *uc =3D puc; uintptr_t pc =3D uc->uc_mcontext.pc; - uint32_t insn =3D *(uint32_t *)pc; bool is_write; + struct _aarch64_ctx *hdr; + struct esr_context const *esrctx =3D NULL; =20 - /* XXX: need kernel patch to get write flag faster. */ - is_write =3D ( (insn & 0xbfff0000) =3D=3D 0x0c000000 /* C3.3.1 */ - || (insn & 0xbfe00000) =3D=3D 0x0c800000 /* C3.3.2 */ - || (insn & 0xbfdf0000) =3D=3D 0x0d000000 /* C3.3.3 */ - || (insn & 0xbfc00000) =3D=3D 0x0d800000 /* C3.3.4 */ - || (insn & 0x3f400000) =3D=3D 0x08000000 /* C3.3.6 */ - || (insn & 0x3bc00000) =3D=3D 0x39000000 /* C3.3.13 */ - || (insn & 0x3fc00000) =3D=3D 0x3d800000 /* ... 128bit */ - /* Ingore bits 10, 11 & 21, controlling indexing. */ - || (insn & 0x3bc00000) =3D=3D 0x38000000 /* C3.3.8-12 */ - || (insn & 0x3fe00000) =3D=3D 0x3c800000 /* ... 128bit */ - /* Ignore bits 23 & 24, controlling indexing. */ - || (insn & 0x3a400000) =3D=3D 0x28000000); /* C3.3.7,14-16= */ + /* Find the esr_context, which has the WnR bit in it */ + for (hdr =3D first_ctx(uc); hdr->magic; hdr =3D next_ctx(hdr)) { + if (hdr->magic =3D=3D ESR_MAGIC) { + esrctx =3D (struct esr_context const *)hdr; + break; + } + } =20 + if (esrctx) { + /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */ + uint64_t esr =3D esrctx->esr; + is_write =3D extract32(esr, 27, 5) =3D=3D 0x12 && extract32(esr, 6= , 1) =3D=3D 1; + } else { + /* + * Fall back to parsing instructions; will only be needed + * for really ancient (pre-3.16) kernels. + */ + uint32_t insn =3D *(uint32_t *)pc; + + is_write =3D ((insn & 0xbfff0000) =3D=3D 0x0c000000 /* C3.3.1 */ + || (insn & 0xbfe00000) =3D=3D 0x0c800000 /* C3.3.2 */ + || (insn & 0xbfdf0000) =3D=3D 0x0d000000 /* C3.3.3 */ + || (insn & 0xbfc00000) =3D=3D 0x0d800000 /* C3.3.4 */ + || (insn & 0x3f400000) =3D=3D 0x08000000 /* C3.3.6 */ + || (insn & 0x3bc00000) =3D=3D 0x39000000 /* C3.3.13 = */ + || (insn & 0x3fc00000) =3D=3D 0x3d800000 /* ... 128b= it */ + /* Ignore bits 10, 11 & 21, controlling indexing. */ + || (insn & 0x3bc00000) =3D=3D 0x38000000 /* C3.3.8-1= 2 */ + || (insn & 0x3fe00000) =3D=3D 0x3c800000 /* ... 128b= it */ + /* Ignore bits 23 & 24, controlling indexing. */ + || (insn & 0x3a400000) =3D=3D 0x28000000); /* C3.3.7,1= 4-16 */ + } return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask); } =20 --=20 2.20.1