From patchwork Wed Apr 3 03:43:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10882641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 466FA17E1 for ; Wed, 3 Apr 2019 03:48:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B7D7289A2 for ; Wed, 3 Apr 2019 03:48:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EA55289B9; Wed, 3 Apr 2019 03:48:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 80FE3289A2 for ; Wed, 3 Apr 2019 03:48:50 +0000 (UTC) Received: from localhost ([127.0.0.1]:52317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWtN-0006iy-T0 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Apr 2019 23:48:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWp0-0002lM-PU for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBWoz-0008CA-FK for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:18 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:45149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hBWoz-0008An-5e for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:17 -0400 Received: by mail-pg1-x535.google.com with SMTP id y3so7573902pgk.12 for ; Tue, 02 Apr 2019 20:44:17 -0700 (PDT) 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; bh=03y4rJUeRFEukrKOoroIoXi8bqiR++D8zkd8dBnyBJA=; b=fZfC+CaPjBIEPxmpuoAB07jDoqpFjlvqU6lkNcSZdMw7xEofoGUjEJlahQJ+phS96j t47N3NPkVycbwK+Ky7x1RPFOeu17VdsuzwoRM4fa4kH/zFX15gPckR1XZeNb85S8IUvq NdiU20k8Zl/zWFrR69fMCMtlguvWwYTK+U4RLIblVe3HPOj1hdwJb5VetT+F7vn5Ermf huqFrWeTSuOzQnadZgfNwfnvj222Th7rOU4+kcPAO1osPfKYKhlpwknsg2ZGc7Od8tPN iO1+N4sNQkUhiFPDOEoy8ayrqO+GipwQVzhHWmLBrT6WM6eyBFef2MImQJU9o10dvtU4 Y8Ig== 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; bh=03y4rJUeRFEukrKOoroIoXi8bqiR++D8zkd8dBnyBJA=; b=RKA3wsTeym61aGbTyjKCa/ldITHL0m5KAaXlGL7UmVD5B1IvuSyqeKxgSnkyMB0oY8 8jvXyDNFoC+DPPjYn02r77m2kCi/D0lMbVwgiYYHC7TXQLJVCegQHLZbauphqNyadY+6 WMpzAUQeA/rlTy2vdeacO8iAvgPNiYZqFpTCNR8OYXXcPVhA124q0+tAxjq70eJvA9DS VrtsK4YW6qTvYrSmqQKUL8QNZBvnnxZ4zMJQRb8a5V7/O3TWemcXiKZ8ZA4Bp+i2mFbZ neCbjA8bHz6wX3L3xsYeGdp8WQDPG7jneWGHfKfKCkFqfFd+LUGGycmDtvpBJxhcit42 9BPg== X-Gm-Message-State: APjAAAU5ifJ1Aj3YeZlRI/nTEwawmngAEFZMZvSvoTdRXrlFCEgmcO1T J8j3cN1NLV+GZ0lakyt1qrCbbzTTGr3a8Q== X-Google-Smtp-Source: APXvYqyz+vCCyenHu3KdAkhWohgUEL6ZWrJJK+mPaqju1+NfG0U0PrHmZbz9VnvVwBI7JlR8RRbreg== X-Received: by 2002:a63:1003:: with SMTP id f3mr60438287pgl.227.1554263055737; Tue, 02 Apr 2019 20:44:15 -0700 (PDT) Received: from cloudburst.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id z6sm26753214pgo.31.2019.04.02.20.44.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 20:44:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 3 Apr 2019 10:43:39 +0700 Message-Id: <20190403034358.21999-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190403034358.21999-1-richard.henderson@linaro.org> References: <20190403034358.21999-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::535 Subject: [Qemu-devel] [PATCH 07/26] target/i386: Convert to 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: , Cc: Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We do not support probing, but we do not need it yet either. Cc: Paolo Bonzini Cc: Eduardo Habkost Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/i386/cpu.h | 5 ++-- target/i386/cpu.c | 5 ++-- target/i386/excp_helper.c | 61 +++++++++++++++++++++++++-------------- target/i386/mem_helper.c | 21 -------------- 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 83fb522554..1ce070ceb9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1655,8 +1655,9 @@ void host_cpuid(uint32_t function, uint32_t count, void host_vendor_fms(char *vendor, int *family, int *model, int *stepping); /* helper.c */ -int x86_cpu_handle_mmu_fault(CPUState *cpu, vaddr addr, int size, - int is_write, int mmu_idx); +bool x86_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); void x86_cpu_set_a20(X86CPU *cpu, int a20_state); #ifndef CONFIG_USER_ONLY diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d6bb57d210..237bd88710 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5866,9 +5866,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_write_register = x86_cpu_gdb_write_register; cc->get_arch_id = x86_cpu_get_arch_id; cc->get_paging_enabled = x86_cpu_get_paging_enabled; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = x86_cpu_handle_mmu_fault; -#else + cc->tlb_fill = x86_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->asidx_from_attrs = x86_asidx_from_attrs; cc->get_memory_mapping = x86_cpu_get_memory_mapping; cc->get_phys_page_debug = x86_cpu_get_phys_page_debug; diff --git a/target/i386/excp_helper.c b/target/i386/excp_helper.c index 49231f6b69..6f59b7bafc 100644 --- a/target/i386/excp_helper.c +++ b/target/i386/excp_helper.c @@ -137,26 +137,7 @@ void raise_exception_ra(CPUX86State *env, int exception_index, uintptr_t retaddr raise_interrupt2(env, exception_index, 0, 0, 0, retaddr); } -#if defined(CONFIG_USER_ONLY) -int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, int size, - int is_write, int mmu_idx) -{ - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - - /* user mode only emulation */ - is_write &= 1; - env->cr[2] = addr; - env->error_code = (is_write << PG_ERROR_W_BIT); - env->error_code |= PG_ERROR_U_MASK; - cs->exception_index = EXCP0E_PAGE; - env->exception_is_int = 0; - env->exception_next_eip = -1; - return 1; -} - -#else - +#if !defined(CONFIG_USER_ONLY) static hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type, int *prot) { @@ -365,8 +346,8 @@ static hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type, * 0 = nothing more to do * 1 = generate PF fault */ -int x86_cpu_handle_mmu_fault(CPUState *cs, vaddr addr, int size, - int is_write1, int mmu_idx) +static int handle_mmu_fault(CPUState *cs, vaddr addr, int size, + int is_write1, int mmu_idx) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; @@ -691,3 +672,39 @@ do_check_protect_pse36: return 1; } #endif + +bool x86_cpu_tlb_fill(CPUState *cs, vaddr addr, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + +#ifdef CONFIG_USER_ONLY + /* user mode only emulation */ + env->cr[2] = addr; + env->error_code = (access_type == MMU_DATA_STORE) << PG_ERROR_W_BIT; + env->error_code |= PG_ERROR_U_MASK; + cs->exception_index = EXCP0E_PAGE; + env->exception_is_int = 0; + env->exception_next_eip = -1; + cpu_loop_exit_restore(cs, retaddr); +#else + env->retaddr = retaddr; + if (handle_mmu_fault(cs, addr, size, access_type, mmu_idx)) { + /* FIXME: On error in get_hphys we have already jumpped out. */ + g_assert(!probe); + raise_exception_err_ra(env, cs->exception_index, + env->error_code, retaddr); + } + return true; +#endif +} + +#if !defined(CONFIG_USER_ONLY) +void tlb_fill(CPUState *cs, target_ulong addr, int size, + MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) +{ + x86_cpu_tlb_fill(cs, addr, size, access_type, mmu_idx, false, retaddr); +} +#endif diff --git a/target/i386/mem_helper.c b/target/i386/mem_helper.c index 6cc53bcb40..1885df29d2 100644 --- a/target/i386/mem_helper.c +++ b/target/i386/mem_helper.c @@ -191,24 +191,3 @@ void helper_boundl(CPUX86State *env, target_ulong a0, int v) raise_exception_ra(env, EXCP05_BOUND, GETPC()); } } - -#if !defined(CONFIG_USER_ONLY) -/* try to fill the TLB and return an exception if error. If retaddr is - * NULL, it means that the function was called in C code (i.e. not - * from generated code or from helper.c) - */ -/* XXX: fix it to restore all registers */ -void tlb_fill(CPUState *cs, target_ulong addr, int size, - MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) -{ - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - int ret; - - env->retaddr = retaddr; - ret = x86_cpu_handle_mmu_fault(cs, addr, size, access_type, mmu_idx); - if (ret) { - raise_exception_err_ra(env, cs->exception_index, env->error_code, retaddr); - } -} -#endif