From patchwork Fri Feb 12 18:48:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 381879 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3203231jah; Fri, 12 Feb 2021 11:31:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGjNpE7a7G4RXLb+0cxjYVAY31bM/iJu4AbgedK2EQADKxBFBjKzQgWt4RZ9YP2/cO8da/ X-Received: by 2002:a67:fc93:: with SMTP id x19mr2741357vsp.38.1613158277787; Fri, 12 Feb 2021 11:31:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613158277; cv=none; d=google.com; s=arc-20160816; b=ZjJjhhm2sSHt/T93ZEU9YpOwNdL90JEkrqF27FYroLchEWGbXfSoRsyJzLMDhCYgA8 81dW3bvVQErejsrjMImk4SPIC/JAIZsArEXY+rD2OsijfTrMNNe29VF07eVOZnEfm4n+ q9HjegWomm0B9J6dWxg51L5jw4CSxtW/JvtfDVmAKcWo5DxxNu0XHJBjuash+3JyWooV UlwQN9vO5/DFxOYaJsZ9Qlkq31hABYJbWk4hcAiLLfcSkZEEh4iofeyCcTUXdgYDr+w6 dwEUwbJobKKTn4J9zzzVar3+1b0wmUeE/GdKwWK+sgSw7eQ/lwjrr6Gn1qPZbc/Uql9D wJtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=974AXR02Bhg4aUVmYtdJXY9jOyaOxnirKIOpaZIiAKE=; b=LG8AtAunXBet1I4/JsM/5JcYhcBGho8mIPX1B00WH4Nb9IdzPe1en41FhCOc1Fj/d1 dZIkdc19o5YOfZLtUjWGTgVW8xGuYMbIJ2nNQoqG1wpLLRELp5nxg5XBvwTUHf4nRgYl NhJZH3J7RrEsQGDYlHNPVQGcDew2OIsIkjZkFIjkKcofI3Wq5pZzJLgr7NxSERAWfuQS 5BonNEOLpChAWB+aEYDIpxoVxCvp1XC9HzeukRCPnpyFlGCX7hg6BJV1R49i8msGzEZP 07u/PwahiHaYehYURY3S49IpyDiiUL+uxuRqadC7t42LGXETPMmTULkIZ9xg3xQIRhYD NILg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uL6QzSKv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q7si1691274ual.115.2021.02.12.11.31.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Feb 2021 11:31:17 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uL6QzSKv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAe9t-0003Kv-3u for patch@linaro.org; Fri, 12 Feb 2021 14:31:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAdVf-00023j-Kv for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:43 -0500 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:40724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAdVd-0007uy-7E for qemu-devel@nongnu.org; Fri, 12 Feb 2021 13:49:43 -0500 Received: by mail-pg1-x52b.google.com with SMTP id b21so243616pgk.7 for ; Fri, 12 Feb 2021 10:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=974AXR02Bhg4aUVmYtdJXY9jOyaOxnirKIOpaZIiAKE=; b=uL6QzSKvUa1R3uUlp4m8xmRsrjdhlzNPPwrd9PHaIKNmf0vhfQZyEJJKCKgqXH1WvH 2cx38JKyf5KCcTxTwpJuqXH+DGf4T5lFYuiZWclrqpqfKVF5cTOFeHlO30D3mVjTc95j OkEYTF1nWt4AHU3Psl02Xx1Nskdl1NYvS4aFbUM0y13kcs5rAOahZAu8zxjQZtW5hCyc cK3OvnKxphlznm7M8F+UTN49SYNiyXbaWLEfc0faq1VmuaPq5K79+mJCPX1VZ1ehCPMB zjwM2oRGfaaxxbGQglk5zgCg1Ps9nsSQDrMMAr7lX6JoKo9Xj50Rf53q0qEUo3F3ltGP DNvg== 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:mime-version:content-transfer-encoding; bh=974AXR02Bhg4aUVmYtdJXY9jOyaOxnirKIOpaZIiAKE=; b=My7NnbyIHWbwUMQ0Es1aAufvqkO89HvKkU6L8Sp3Ch2wCxga9htCGA2JnHdFKbk7NP +TdJeHE9OEXaiKWDRHWq5BeWMuIx95KBNFylomlB5/NsrDEHh+Ysgj4ZdvswPClD6iJr 06mRjsZDWzaHKOfF6BK9nZdUCiGVf4F3d8fyXx9VgZHhW/0YO7gNSyBdPzZlm8wd3H0s gwAvextfg6F7VXM42jney38toBGDGZZ4BEvSPj5K3oC6homTW9MgdYbBE7FdjoxYiZ5d bfgvaaOLqIptC6x52x3ay8TRv+5JLkEArGnqutA0B2AMSGRaVXhh4gkCNfrFuAK+GO5J xKqQ== X-Gm-Message-State: AOAM531maKPbmmSWmR6EAZqURKKlq5AaBrk/OK5PZwPoGarDrYVe6PPp ++pDSvNojzctkJ2bQ3VWZTjCvaGFpSMvvQ== X-Received: by 2002:a63:f4e:: with SMTP id 14mr4549998pgp.3.1613155778890; Fri, 12 Feb 2021 10:49:38 -0800 (PST) Received: from localhost.localdomain (174-21-150-71.tukw.qwest.net. [174.21.150.71]) by smtp.gmail.com with ESMTPSA id k5sm9427618pfi.31.2021.02.12.10.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 10:49:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 28/31] linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error Date: Fri, 12 Feb 2021 10:48:59 -0800 Message-Id: <20210212184902.1251044-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210212184902.1251044-1-richard.henderson@linaro.org> References: <20210212184902.1251044-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The real kernel collects _TIF_MTE_ASYNC_FAULT into the current thread's state on any kernel entry (interrupt, exception etc), and then delivers the signal in advance of resuming the thread. This means that while the signal won't be delivered immediately, it will not be delayed forever -- at minimum it will be delivered after the next clock interrupt. We don't have a clock interrupt in linux-user, so we issue a cpu_kick to signal a return to the main loop at the end of the current TB. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/target_signal.h | 1 + linux-user/aarch64/cpu_loop.c | 11 +++++++++++ target/arm/mte_helper.c | 10 ++++++++++ 3 files changed, 22 insertions(+) -- 2.25.1 diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h index 777fb667fe..18013e1b23 100644 --- a/linux-user/aarch64/target_signal.h +++ b/linux-user/aarch64/target_signal.h @@ -21,6 +21,7 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */ #define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ #define TARGET_ARCH_HAS_SETUP_FRAME diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index b6a2e65593..7c42f65706 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -164,6 +164,17 @@ void cpu_loop(CPUARMState *env) EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); abort(); } + + /* Check for MTE asynchronous faults */ + if (unlikely(env->cp15.tfsr_el[0])) { + env->cp15.tfsr_el[0] = 0; + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + info._sifields._sigfault._addr = 0; + info.si_code = TARGET_SEGV_MTEAERR; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + process_pending_signals(env); /* Exception return on AArch64 always clears the exclusive monitor, * so any return to running guest code implies this. diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 153bd1e9df..d55f8d1e1e 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -565,6 +565,16 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, select = 0; } env->cp15.tfsr_el[el] |= 1 << select; +#ifdef CONFIG_USER_ONLY + /* + * Stand in for a timer irq, setting _TIF_MTE_ASYNC_FAULT, + * which then sends a SIGSEGV when the thread is next scheduled. + * This cpu will return to the main loop at the end of the TB, + * which is rather sooner than "normal". But the alternative + * is waiting until the next syscall. + */ + qemu_cpu_kick(env_cpu(env)); +#endif break; default: