From patchwork Thu May 9 22:26:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163770 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1574062ilr; Thu, 9 May 2019 15:35:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLvo+lALi1vX+9vcESZ60PKNJ5d+MKyOsj0pIEm+UBuUapo8L5owOPSgWc31kpP0UySMU7 X-Received: by 2002:a1c:81cc:: with SMTP id c195mr4522475wmd.61.1557441346953; Thu, 09 May 2019 15:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557441346; cv=none; d=google.com; s=arc-20160816; b=E3w2uruVVNKiGHa629kGLdaRE5gYZHurl7ea76T/7G3UdtBOI+cSDRKYqSjuiMSW6i 2JBZFfO+dBtqTX2KUcs10ty51P+kMNdSOgzITypJaNplaqStOo+zAhtWLm4dSQPDCe8n tKCgcdtDJyjBcJ/m+cee7edllFO79wMu6WZ+/34I0eLHM4EE+XPFWhkmUCIGLEKo5Hqv EIj4ols2h3Pz2RGeVn01HV4EFQRp/LwLCuI3efiqYt9weX452LpwR7xyxVWgVfVmorVS M309jrCKhlY1Fb5PXZ2YP2o9pFmGARAdVIxq+J0j0viKkIgPvKBcQNyExG0MG7rMM/ss zVug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=7ZAIu4sKS6YB4WebUUhTxA56tE0hF5se6ULN034aZNQ=; b=jQ16L2I7EdtpQQ7gym/HRopmgAV7fe2A+tuDh5KzjMNGfNbFya45k3iAJA6ObWEk3c v1YB91ldqkzlvnZ59KnMGRo5WqWdo1HVHV+WBM830v8wgPbjAeowpThsLm6k2zW1q3wZ zSOr1BiQbjMHB4szkX5wsWcEWyFfBkD8J1cTzt7D9icKqpE6iEnk7LW+7uAcmIpeOZB1 c1S78Xm8hVV+nLo4UIgwHIETvQRPj3CpQ7bcvUMDQJDTtcl/F1FhFo+YJT50hdds4K/V Oi3erBThYktR6o4UqJCr9toaRfDNPmqsEGsNIhHl3JEhxyNS9n3p9NREjLXv6aSROX55 OGnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x7C7VdUR; 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=fail (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 j6si2869734wru.330.2019.05.09.15.35.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 15:35:46 -0700 (PDT) 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=fail header.i=@linaro.org header.s=google header.b=x7C7VdUR; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:33569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOrdh-0007OJ-QI for patch@linaro.org; Thu, 09 May 2019 18:35:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOrUr-0007Vi-Ns for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOrUq-0005Mr-KN for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:37 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:42306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOrUq-0005Ma-E8 for qemu-devel@nongnu.org; Thu, 09 May 2019 18:26:36 -0400 Received: by mail-pg1-x542.google.com with SMTP id 145so1916389pgg.9 for ; Thu, 09 May 2019 15:26:36 -0700 (PDT) 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=7ZAIu4sKS6YB4WebUUhTxA56tE0hF5se6ULN034aZNQ=; b=x7C7VdUR/J75eALT7laVxfbag0DNejwYdKa1FQi1YfsU5rw7mEhcs/G2Tn52tQR0Jk 8wfpxpSfT1KfGA02VsKNsDh6sR2sgb8WpmqI3I++ZqKX6jACMmh6x38yuvn0E4qel5mO vtI7kZBBGmUTq7O32LKgnuwJQwVH1uROLPn+zIdBTIi3/qR/pxRerZXK4zmD6ZunYXwB 1dVQ4j46dwKAvMjRFY6G4QMngs+WkU7zMTx+K18Ba/AvctbusToTIur84dC3VISrnL43 bSqMddxCXyTwJGYbS17qbfRN2lyyZKp3XYyDV6T+qWL2Ow3rUS/r02Q3c8+2aR11WyDK ka3g== 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=7ZAIu4sKS6YB4WebUUhTxA56tE0hF5se6ULN034aZNQ=; b=fAcBkdrTwW72Qs/D/xzsDNyVVXrG3gLY4v5BOh8s2U3flVakhSPJn3gnOQMb2kEAeY ae0ZOnKs17BmeJVBZCqce2RjmYtk7Uj2kmZ2hW0Wm7jHxPXRbcb5l3JfB5f6AiT2dM8d 8PwUbSQFSLkg0e3Hke8s3XdcvUuzRp+tAa/1e1Mi3Wwu+0Au/2a9SGezLM1mEgvgrIXS XNDtB0oiLhvTjWQvamoIWv10u4k7Pu0hZmnQpznXBf+Tm2cNruse3BKCify297LTWPwL Um4iM2uQx6mXyVstZDz7EmUVjMDqG8vrq3i2I3uMRxK/Oe/+2Z7ld1PkG1AigzacoReD xWXw== X-Gm-Message-State: APjAAAVlNfOczWncHBZ6hPxkjZZitICPq7tkbVLuBXoPc08QyXLdKyA4 xfhvCPbRHC+uUE+d2BkcaZcqL8InhuU= X-Received: by 2002:a63:1d05:: with SMTP id d5mr8881169pgd.157.1557440795175; Thu, 09 May 2019 15:26:35 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id m2sm4490521pfi.24.2019.05.09.15.26.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 15:26:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 15:26:05 -0700 Message-Id: <20190509222631.14271-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190509222631.14271-1-richard.henderson@linaro.org> References: <20190509222631.14271-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v3 01/27] tcg: Add CPUClass::tlb_fill 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This hook will replace the (user-only mode specific) handle_mmu_fault hook, and the (system mode specific) tlb_fill function. The handle_mmu_fault hook was written as if there was a valid way to recover from an mmu fault, and had 3 possible return states. In reality, the only valid action is to raise an exception, return to the main loop, and deliver the SIGSEGV to the guest. Note that all of the current implementations of handle_mmu_fault for guests which support linux-user do in fact only ever return 1, which is the signal to return to the main loop. Using the hook for system mode requires that all targets be converted, so for now the hook is (optionally) used only from user-only mode. Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/qom/cpu.h | 9 +++++++++ accel/tcg/user-exec.c | 39 ++++++++++++++------------------------- 2 files changed, 23 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..c1f267b4e0 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -118,6 +118,12 @@ struct TranslationBlock; * will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). * @handle_mmu_fault: Callback for handling an MMU fault. + * @tlb_fill: Callback for handling a softmmu tlb miss or user-only + * address fault. For system mode, if the access is valid, call + * tlb_set_page and return true; if the access is invalid, and + * probe is true, return false; otherwise raise an exception and + * do not return. For user-only mode, always raise an exception + * and do not return. * @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the * associated memory transaction attributes to use for the access. @@ -191,6 +197,9 @@ typedef struct CPUClass { void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb); int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int size, int rw, int mmu_index); + bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr); hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 0789984fe6..199f88c826 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -65,6 +65,7 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, CPUClass *cc; int ret; unsigned long address = (unsigned long)info->si_addr; + MMUAccessType access_type; /* We must handle PC addresses from two different sources: * a call return address and a signal frame address. @@ -147,35 +148,23 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, are still valid segv ones */ address = h2g_nocheck(address); - cc = CPU_GET_CLASS(cpu); - /* see if it is an MMU fault */ - g_assert(cc->handle_mmu_fault); - ret = cc->handle_mmu_fault(cpu, address, 0, is_write, MMU_USER_IDX); - - if (ret == 0) { - /* The MMU fault was handled without causing real CPU fault. - * Retain helper_retaddr for a possible second fault. - */ - return 1; - } - - /* All other paths lead to cpu_exit; clear helper_retaddr - * for next execution. + /* + * There is no way the target can handle this other than raising + * an exception. Undo signal and retaddr state prior to longjmp. */ + sigprocmask(SIG_SETMASK, old_set, NULL); helper_retaddr = 0; - if (ret < 0) { - return 0; /* not an MMU fault */ + cc = CPU_GET_CLASS(cpu); + if (cc->tlb_fill) { + access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD; + cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc); + g_assert_not_reached(); + } else { + ret = cc->handle_mmu_fault(cpu, address, 0, is_write, MMU_USER_IDX); + g_assert(ret > 0); + cpu_loop_exit_restore(cpu, pc); } - - /* Now we have a real cpu fault. */ - cpu_restore_state(cpu, pc, true); - - sigprocmask(SIG_SETMASK, old_set, NULL); - cpu_loop_exit(cpu); - - /* never comes here */ - return 1; } #if defined(__i386__)