From patchwork Thu May 9 06:02:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163660 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp541659ilr; Wed, 8 May 2019 23:05:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSqacBkXxdvWQgHXG8nJ14c52qiekJ9jYYizhW6/p7nxvpseyl0C/W7Gj1uJ4fGyik/PF0 X-Received: by 2002:a1c:eb12:: with SMTP id j18mr1466070wmh.48.1557381944297; Wed, 08 May 2019 23:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557381944; cv=none; d=google.com; s=arc-20160816; b=klaW3yHDeQBcouZZPL+LwXrilvx+Hy6gD/nWl5JBMUypDfyup/VqEpzz+zz8Fo4k32 irMJYuRqvacSCj6OHByw6Xi4rdoaOy69vqUwd3VaHJMZk+2xzcACxXpr5UNIVnhmNFLB V+rhz9ohLnWgMHFdmHBOzluHwy5iHkU79/4dkCVsfaN9sZW0N8rnZ49oG/znEI8awCbi mIU3AiQ+soUwJQUlcS0AxBIbzrQrVpj9JG50HPg+5Fcphvn6cQDqmvR/3e8Edv+QtrjH qNFjmAX0FAqyrA1QhEm54aqZubGwtQsbijqPRCNaIcqtDuyR07lsWMCmlt+AR+4bBhJy p2BA== 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=Beo6inO//WJ/P87zouheT0EPWAODR9kofCctnu88ZHk=; b=dnstZob3VvvVSSrFJPRoEytBB25TDjSk5aUSCLxDT9nCgPulZoveclX7Vv9lxOeAkB Gegjq2LfD+tiIchiL8wdj2MxI6WfZF1pvTQlzMeeNAM1XwD7eoj2cmEfmTphD8PFNa+5 a2EqoYQGIBBDeDi/64Q5lZLdKdbRy8T8psHK4vSLqE2X6OoEeNfAjGC9WYy3AMCVeu4k M8EIJJggPEJP37l3A5eqgjH5q59mhAXRhKGgqq7dwAaRWH7fG30Ix02NBZzCWWmUMEyp KVw0OXpuWq4Z6oK4+WJVW409kpR0yFCEfnJ4SQ0XmyMMhF1eL8J7ZXHrsGGcdqsgfEbq 7Irw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ndcfxVaT; 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 i7si950747wro.366.2019.05.08.23.05.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 May 2019 23:05:44 -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=ndcfxVaT; 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]:48605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOcBa-0008JX-Vd for patch@linaro.org; Thu, 09 May 2019 02:05:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOc8q-0005v8-K1 for qemu-devel@nongnu.org; Thu, 09 May 2019 02:02:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOc8p-00070I-En for qemu-devel@nongnu.org; Thu, 09 May 2019 02:02:52 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:44349) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOc8p-0006zu-5M for qemu-devel@nongnu.org; Thu, 09 May 2019 02:02:51 -0400 Received: by mail-pg1-x544.google.com with SMTP id z16so617152pgv.11 for ; Wed, 08 May 2019 23:02:51 -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=Beo6inO//WJ/P87zouheT0EPWAODR9kofCctnu88ZHk=; b=ndcfxVaTyswjTBmIPmeWAYCCgZQ3qml/I2wyFk6fNPP816QWeSIiT/yPE+ky/PIdea Nghm8PO3ZmGbOn7fGR8kGRzJP3eghNXokUJuAY4CbDYl0tmL9FJqcPOk/YGo0jicS/0D RcxxKENjw5mHASi/MDyvJ8Ss2sPaXQ8h4x4gasxevcTNpIARs231xDDFz7bqg1ionmUV CXGKSWgn/YNmv1KCVEBIbNFqVlWdmd6CwAy0NBSrTdr3yUmsnYLVbzHcxBKrxlKEzJYH 9JugZhcj5s6RhSq8A+PLs6FUCACZHxihZzkO5YR7lO5IlRTGRbmJySpDYabCy+y5gakZ 8Cow== 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=Beo6inO//WJ/P87zouheT0EPWAODR9kofCctnu88ZHk=; b=P7PgfeoRIQzVwR+fHorCAFtFgtSC6ue90QjnZSrBqUBfKBvl/2o80bi69iVZAvI7cY XaslC1kCGgD/Ol8/nV0uW+3a5WikehNMq0cuPfuDLeoUh1RDolz7WmmjG2NPulMONL1O MJKk3rOCRIXRA7/BBFHrdERtV66esYqsZ+eEWDUUHkfI9FrqyKuS8oHoqERK6YZF9U3e u9FbJ68f/8HJu64+t7a7zViedS8TI9QTUbmSVg69JF3gK0lpbi8lpycPK8cuBZJfQL5X DrpT/l1YUqFEniop3WdnVfTE9Tc8u8RrcbJyZ1HbGiWzf7bBmyyy6GPVjw6JaiN2gUdI 3qjQ== X-Gm-Message-State: APjAAAWzrP8G06TYfMtCD1kuFfWC/x9tvEpfEw4mKRMFob5gb+IVrF9N AXXmPswmMR2mHzxOEkweLOSa4rBvjF0= X-Received: by 2002:a65:4c86:: with SMTP id m6mr3104123pgt.75.1557381769794; Wed, 08 May 2019 23:02:49 -0700 (PDT) Received: from localhost.localdomain (97-113-27-95.tukw.qwest.net. [97.113.27.95]) by smtp.gmail.com with ESMTPSA id n7sm1496109pff.45.2019.05.08.23.02.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 May 2019 23:02:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 8 May 2019 23:02:20 -0700 Message-Id: <20190509060246.4031-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190509060246.4031-1-richard.henderson@linaro.org> References: <20190509060246.4031-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::544 Subject: [Qemu-devel] [PATCH v2 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: 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 Reviewed-by: Alistair Francis 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__)