From patchwork Fri Oct 1 17:11:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515066 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp1005779jaf; Fri, 1 Oct 2021 10:24:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqjlovsQzdKuWAfQy9MFwCjbxU7r82CtD936tC5uBkGHJlUTvMhG/WvwBRjLhzXh3hJnPL X-Received: by 2002:ab0:7e8a:: with SMTP id j10mr7280643uax.58.1633109045153; Fri, 01 Oct 2021 10:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633109045; cv=none; d=google.com; s=arc-20160816; b=J4V9pRtspKiFORePUCRYNYRNBhjQnUuZILI5GJ3v2BnQPIgbSxdoXRlDVqnYwCuaQ6 6mg2Y2BMdZeU4KwdCKVyCnCXTmSPDwYwc6vjaicJqHfRZ0d47pJaNGJLbJlqwH1q/Jz3 PRL8LyxYWwriyTZt3nGCLdAvRJBzrZv/QrkGaw3jR7Te1+GuPFf7y1YISj8+TciIDBae 6OfZQ6nnwLdeIW6x+OyYx0pkqs2EG/j0u2HgdTDktQtflya9UaPn2QO7muJQ3FyAJgmk r27K2OHK2Ii9Drh1tpDqzuQIqNTKuNRdZWFpB7kA3Dyv6d4PvCsjGnTSs7Ga/gsJATYg gOMg== 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=Bcv7+vrfVWDaxhREKP7oW3QycojCjuZf0xWMtNuZYi8=; b=vNbFG0H53MbLl8T++GmmH18IYfVkQzZBIM7t32vW8Y8yJ/zD9mZIcLeF0KD+lQ84Ug eteKIBVI9S0JvAK1yS+vSdyQCFDJNHy4lr9Wx5qMn2J7Nch/nEGaN9CDlv9NAEfwRylg dwMeJnFvdBuhkDa6sk7xbmzhMotmd4uW6qdWF11U+tgIzYGgAl/SaAA9X8ZEALdmAoPz Cry8WNZO84yOdRSH1lMm8zA3khyxlGacGTti/eTDECRo1MwAZf+AtujPC1ANiN2hXSI3 gcy7QLe/xxCW/uaOzxZedd7uGT7342nyK3blUNU09+BHtmD/tNfW3a12VsOEiiQ/pKVj 2lMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cRH7O3PC; 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 q10si5693111vka.43.2021.10.01.10.24.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Oct 2021 10:24:05 -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=cRH7O3PC; 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 ([::1]:46974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWMGS-0005w4-Ed for patch@linaro.org; Fri, 01 Oct 2021 13:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWM55-00054S-I2 for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:12:20 -0400 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:41703) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWM53-0005F8-UO for qemu-devel@nongnu.org; Fri, 01 Oct 2021 13:12:19 -0400 Received: by mail-qk1-x733.google.com with SMTP id m7so9817756qke.8 for ; Fri, 01 Oct 2021 10:12: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 :mime-version:content-transfer-encoding; bh=Bcv7+vrfVWDaxhREKP7oW3QycojCjuZf0xWMtNuZYi8=; b=cRH7O3PCIdNSdTUWPql16AGN37Jk7cpBm+xRH2InaSSDBRikY8r5epoUkoX/jAbyFA bVKITLVDsY0yELRFvIrjus2OjzFzp2YktjznTxOjCRY6j0WmqYz4ZSGHVivcgBzVK0Vs Y9iicmMfowAM1sUOfeMBrLY2pO7WKKbzQUyEDgYC46VmjUbU/rKar6jNClD+ObjmVKQE p2EuW2cVOE+Tu40NIZ8m8PoeN5qb/srLPDNTtzHZp8RYX/V4IFsSVN4PjJhPZlYJ2FW1 38M2M0pvFo6wt6TvUskAmHunRQyZoDN2SuK2qVGk5ngEe4HlULeS/zbYv15TR9Kvhri6 RvNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bcv7+vrfVWDaxhREKP7oW3QycojCjuZf0xWMtNuZYi8=; b=WcVvrX2hOD+jEg5C3NGk0Xxfd3mD3J0DR1OEQvvug0z1zv/82WKtybd0plQx1NZaqV AEUHHHPvhdYs1GM9X2OMclHvA6nnmqqUdDn55jyLrlFO50J1RIyEjqtaYVmC5uy5tjKB OIXGWYqeQooFziFRLN4GMhi2PONwwivnZfJ0F2HBLhgOs1sRQjELAme4+tp9OPECLLeg V03vvdQ0vB11lb18jgSCUwNqnYmHcrXy2HF2wlXcW5045oiCeJnDbFnzcRJ3/jz+wePD rlXAh1kprzPxXxS98b7V2tzP4Pw3GW/tVKugvxxTJQqxNjETI7LCtN1WBk17PaxpLTBQ zc8Q== X-Gm-Message-State: AOAM530IYwbQd8kWMYYeBHRD6+gY7tSaGsINVdd5F4nFngbokCRlijH7 feONhdlTP8lVnZDOBvTYR/XJcjg+ISak5A== X-Received: by 2002:a37:746:: with SMTP id 67mr10466779qkh.465.1633108337064; Fri, 01 Oct 2021 10:12:17 -0700 (PDT) Received: from localhost.localdomain (c-67-174-166-185.hsd1.ga.comcast.net. [67.174.166.185]) by smtp.gmail.com with ESMTPSA id y15sm3557250qko.78.2021.10.01.10.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 10:12:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 27/41] target/i386: Implement x86_cpu_record_sigsegv Date: Fri, 1 Oct 2021 13:11:37 -0400 Message-Id: <20211001171151.1739472-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211001171151.1739472-1-richard.henderson@linaro.org> References: <20211001171151.1739472-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x733.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: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Record cr2, error_code, and exception_index. That last means that we must exit to cpu_loop ourselves, instead of letting exception_index being overwritten. Use the maperr parameter to properly set PG_ERROR_P_MASK. Reviewed by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/tcg/helper-tcg.h | 6 ++++++ target/i386/tcg/tcg-cpu.c | 3 ++- target/i386/tcg/user/excp_helper.c | 23 +++++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h index 60ca09e95e..0a4401e917 100644 --- a/target/i386/tcg/helper-tcg.h +++ b/target/i386/tcg/helper-tcg.h @@ -43,9 +43,15 @@ bool x86_cpu_exec_interrupt(CPUState *cpu, int int_req); #endif /* helper.c */ +#ifdef CONFIG_USER_ONLY +void x86_cpu_record_sigsegv(CPUState *cs, vaddr addr, + MMUAccessType access_type, + bool maperr, uintptr_t ra); +#else bool x86_cpu_tlb_fill(CPUState *cs, vaddr address, int size, MMUAccessType access_type, int mmu_idx, bool probe, uintptr_t retaddr); +#endif void breakpoint_handler(CPUState *cs); diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c index 3ecfae34cb..6fdfdf9598 100644 --- a/target/i386/tcg/tcg-cpu.c +++ b/target/i386/tcg/tcg-cpu.c @@ -72,10 +72,11 @@ static const struct TCGCPUOps x86_tcg_ops = { .synchronize_from_tb = x86_cpu_synchronize_from_tb, .cpu_exec_enter = x86_cpu_exec_enter, .cpu_exec_exit = x86_cpu_exec_exit, - .tlb_fill = x86_cpu_tlb_fill, #ifdef CONFIG_USER_ONLY .fake_user_interrupt = x86_cpu_do_interrupt, + .record_sigsegv = x86_cpu_record_sigsegv, #else + .tlb_fill = x86_cpu_tlb_fill, .do_interrupt = x86_cpu_do_interrupt, .cpu_exec_interrupt = x86_cpu_exec_interrupt, .debug_excp_handler = breakpoint_handler, diff --git a/target/i386/tcg/user/excp_helper.c b/target/i386/tcg/user/excp_helper.c index a89b5228fd..cd507e2a1b 100644 --- a/target/i386/tcg/user/excp_helper.c +++ b/target/i386/tcg/user/excp_helper.c @@ -22,18 +22,29 @@ #include "exec/exec-all.h" #include "tcg/helper-tcg.h" -bool x86_cpu_tlb_fill(CPUState *cs, vaddr addr, int size, - MMUAccessType access_type, int mmu_idx, - bool probe, uintptr_t retaddr) +void x86_cpu_record_sigsegv(CPUState *cs, vaddr addr, + MMUAccessType access_type, + bool maperr, uintptr_t ra) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; + /* + * The error_code that hw reports as part of the exception frame + * is copied to linux sigcontext.err. The exception_index is + * copied to linux sigcontext.trapno. Short of inventing a new + * place to store the trapno, we cannot let our caller raise the + * signal and set exception_index to EXCP_INTERRUPT. + */ env->cr[2] = addr; - env->error_code = (access_type == MMU_DATA_STORE) << PG_ERROR_W_BIT; - env->error_code |= PG_ERROR_U_MASK; + env->error_code = ((access_type == MMU_DATA_STORE) << PG_ERROR_W_BIT) + | (maperr ? 0 : PG_ERROR_P_MASK) + | PG_ERROR_U_MASK; cs->exception_index = EXCP0E_PAGE; + + /* Disable do_interrupt_user. */ env->exception_is_int = 0; env->exception_next_eip = -1; - cpu_loop_exit_restore(cs, retaddr); + + cpu_loop_exit_restore(cs, ra); }