From patchwork Wed Apr 3 03:43:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 161654 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2514208jan; Tue, 2 Apr 2019 20:50:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4TyQlum1LWEupaujgTyZbn+o4bVhiNLLFjQzfB91602cEJulBHl5v6x1MJcBJv4wxUoA0 X-Received: by 2002:a0d:de82:: with SMTP id h124mr14530689ywe.430.1554263411339; Tue, 02 Apr 2019 20:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554263411; cv=none; d=google.com; s=arc-20160816; b=R93WKaUji+XKFOti4ON6PVsIiMWqcjCFakGlrXVZnWG8w1jKIfhUYjmaz4s0r2wv0L jtrrjpx0YQxy77xHYZRwguCi9ZRSqyoEpR5lBSRsMNHIGclgHoLWZ2BJKFbmU5yGSct3 1wh0OzqpKlLRpZEl2DRAGx01z1e9Nm8hMU2yrBJ06EBZA1NU2Ka4tE0jXhwq5ZHODNcf WeJKpJn8lvMf2Lz3It49BtBnujnGbTI5PcbvQYm9eJc9oEcgYj8jBUxvxyALBA6mwvt6 UhVPhbbp5cIHTW++8EO+9tqIvH53ugm74MLI3RRAk8EwiGtG5OYgW7u6kOFOpA0KfUnO pjnw== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=a1RF8tzN4d+znSGg74/q0NFp8F7G9Ydq9o76y67KjZ4=; b=1Jn9GYpWUZOqcG7jZuyq8snGh1ppzXNnq3NMK0L/QSb357qYgC9XRq8hJjB2ZlKuX6 sS2FzQg8pwyy9YMrsysfo4ZY9jqGTShgszN+o7E6781yBoe7a5Fk6G93jkdUqH35aAOi x0aszIKDalxaJm8Myil7LU0KcfDP3wGWtRwdaZBukbAcSKzIYP/qikjH1BuR/X7QTBXB 8vlb/2l8MHQ1DSMnl8982pAnBIPX2qI9uRWEg6Wp7KM3GH1k/7agXpxACrUD5ZI1sL5J JoggdBcVimxFWTI8b3Sum58kWaGVqO7ujhU5NIqZ5aG38Vbcyxlqnzt4S4QNrOys+rne X48A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C9gLXxmP; 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 r123si10334056ybr.290.2019.04.02.20.50.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 02 Apr 2019 20:50:11 -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=C9gLXxmP; 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]:52643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWug-0007iN-PR for patch@linaro.org; Tue, 02 Apr 2019 23:50:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hBWor-0002cK-1w for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hBWop-0007sc-QD for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:08 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:46015) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hBWop-0007ob-HH for qemu-devel@nongnu.org; Tue, 02 Apr 2019 23:44:07 -0400 Received: by mail-pg1-x541.google.com with SMTP id y3so7573750pgk.12 for ; Tue, 02 Apr 2019 20:44:07 -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; bh=a1RF8tzN4d+znSGg74/q0NFp8F7G9Ydq9o76y67KjZ4=; b=C9gLXxmPxjYURlpbxZK/cZU+3YqdbQmJlqUN+tCRs5VW8+hzfS0i5mLI8ZxFlbo60U Www/huG0VS5r7O8thn7/hLlrYekz493kzZUtIBxfGqjlLZQF9/63RAougs3K+NNOgpnM hexfA4PLEZHEonCJ4YkliPyksQiSS6cssUgISfosquFOiiB6s3hcGiWhoZAWvD4p/cZt Zs3BF46pFIOehsqjckPRbmekvZFPK3IzoHdRwftFmRYxCgb1ojkngVtGpCLuY0+DReSw H7Zs1CJXWw4CHFRGGsJ3MFe0nF7E910zLhKhE/ciyubGpnFMFK9Lu24pXjc/yCy/5eaN DzLw== 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; bh=a1RF8tzN4d+znSGg74/q0NFp8F7G9Ydq9o76y67KjZ4=; b=p+TiQM9/TsoImGgA0xv7M2zGBOACKhO2l/7jWr3ONFArvgMek/07qAzy0f+/LfIqeX lSA2EPKPnPkav4tcnxJN+bqnbMCTGY+echZNvYzhqJU9pf5FyzUvyG9VzNG+tErWIzAQ W3eTuVcUh40M/LbgvbVoMYdvEPok/6Bh65k/9eOtmG3fgrX3tZZD5TIFmXdMtR6ypJrq 7mq2Kz2hm/4nmhEYIQQqdKAp+ili0pGNI5cGUsb/8EMYsBybojjdHe9r32vUv5uTwY21 wNu2Zy4xUX4oV/iAhNV4oT++EdbfPyBIcDz/BjshNEaJO7Iw9vSUw/mMK9W5CtDEmwUr CW4A== X-Gm-Message-State: APjAAAWooWCr7pd+MfNENlatfVSU3I0oJ9X4Bf6ebkfYHHKyzFthHh1g N0LZrwAA2RLIfNxwyO1EhojVmfHReVXOYA== X-Received: by 2002:a62:b602:: with SMTP id j2mr59683619pff.68.1554263046136; Tue, 02 Apr 2019 20:44:06 -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.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 20:44:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 3 Apr 2019 10:43:34 +0700 Message-Id: <20190403034358.21999-3-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::541 Subject: [Qemu-devel] [PATCH 02/26] 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 delver the SIGSEGV to the guest. 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. Signed-off-by: Richard Henderson --- include/qom/cpu.h | 9 +++++++++ accel/tcg/user-exec.c | 42 ++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-) -- 2.17.1 Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1d6099e5d4..7e96a0aed3 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -119,6 +119,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. @@ -194,6 +200,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 fa9380a380..f13c0b2b67 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. @@ -151,40 +152,25 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, #if TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 64 g_assert(h2g_valid(address)); #endif - - /* Convert forcefully to guest address space, invalid addresses - 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__)