From patchwork Sat Oct 30 17:16:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516507 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1455357iml; Sat, 30 Oct 2021 11:24:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztRr8MgtVMk3acvIw4trPUmYkgxQVPEKUVfaUQwgYajTAu9keLezPahA1fIq4KefgD/aez X-Received: by 2002:a4a:d5c8:: with SMTP id a8mr12834691oot.18.1635618267513; Sat, 30 Oct 2021 11:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635618267; cv=none; d=google.com; s=arc-20160816; b=Dch/EEB35qYcAmmgxMy2Jy3y6dglv4j/MOVjV0b8Ng7/rIA4hdgUaKmCeTZTGKIHeT XkFgQvTtIX1AtWfzRey2G9hsugOTFL6PdfWW2WEV7cVg3OrMxkEO/GpQqwGRnsMqwRSE bhTQkjWZNi2q6iKdpkgMxaVIXoLgVuoYGOFVtkY16/W+rOQ/Jk+tcA9IKtwwuApgQt/E k5cGYIDZ5vWkxpDkXOk7QyNR82rjAVnYhJCynysqYRJ6LOX1f86U1NRp78dKfhLg8864 +rvLPj1JKGjy7IjMXoFizQv8dQvFnYv/nLV4L7//PDmdk5Bp+DnaIB2TCslZcftYTs4K UuDw== 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=ij1YRgU0peRo+QSVg6ezzkIr6IGfKaWXUXRkApukMz0=; b=ad6EhKHY+p8sSaoh5EV3sRCHA4TKz+58PMZgu5lDgoEaHhnSu6qCXnjlodteWUQcUg mkiFIZwEf3CGgi9/w3s2JAF4ZjnQZ4JOBBIe2vvuuJXwyc/0m8I7BvbWQV/75BT68Jan uwda2r+uWGODoI5czI4p70eycJHDQhi1oXG/V5aTSiyj/2WG0fGzAA3uqhPAzdrlo8uV EC/aIOYCRmzCXJMdgMbzZXr9UeauIdxkz+RUdSSwPiLqoNZqUxxQUviCv5hQrT8oEzNn zrmjM3gEsirp4jJ0LQrw5q8yJpK6Ru34vIZBLfzlbqPgWmqEZ6NgN+DgqpIsjgJaHMw/ JUIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EKiSZVL0; 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 a14si14261711oiw.6.2021.10.30.11.24.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Oct 2021 11:24:27 -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=EKiSZVL0; 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]:35920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgt1m-0004v5-RX for patch@linaro.org; Sat, 30 Oct 2021 14:24:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgryl-0002O2-HK for qemu-devel@nongnu.org; Sat, 30 Oct 2021 13:17:15 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:41671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgryi-0000EK-9t for qemu-devel@nongnu.org; Sat, 30 Oct 2021 13:17:15 -0400 Received: by mail-pf1-x436.google.com with SMTP id u33so278305pfg.8 for ; Sat, 30 Oct 2021 10:17:11 -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=ij1YRgU0peRo+QSVg6ezzkIr6IGfKaWXUXRkApukMz0=; b=EKiSZVL07poOg+G8OU4uOPul7nXaPSTIA7AbHSJ0kHPvuf8O9SPf+7CF15y8SFpNav ot7pZ295v8O/XoTvh8o+MaqBjNmUau+cMX2KiYQX/Ck06onqpd7iTDFodmB5mTN/ZhHN OzR2THohJ9bU3DeWxNxQg92AIru/DDwMv5XbIeS3j91KiFqdI3pNu89++DJDWVVriC4h 4iA7KA5UUekV7ZwUpAbMNBk++IsQj3YB+vPROeV7ObWKypy3YQ+U+7uElq/0ST/OTRcV qgkA3UYMPgTWT+frZmobWQpOtJVZIISMxy5BinsIQxF9+RFWIGpVop88A6o+CXSAz85/ heHQ== 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=ij1YRgU0peRo+QSVg6ezzkIr6IGfKaWXUXRkApukMz0=; b=u8XpzBuewYqYrf1f4lJ5CnrYsZ//CPJ1Q0ZVc6FBqOO7j0ZAjW51w7pe55OqXzChe8 BnqjcTSftE/suhMOIeX9CioOTqXun9cf4dPnNT/za//BggYpdFBWzlHbJVa2/EZ1uUqA O4adlmQ71q3ebI2THTujwRHm87gj2eY1V5YqzwIyshAtOIr3wiPJKCSNxx6X+3WjCOUr 6h2QVguNNY4DPKeuAke1YpJjVhY8wx3EXhHFtGP2KnDTSxqMCRxhldWtSkcgFU0+Y8XQ 1y6W/JxEiGXDZy6csbWwpdGNf6xZu5/meposErcb4br6Z/NCXjWCUAfJiAborlHOzLxT OnsA== X-Gm-Message-State: AOAM531TS2f8xzDCbKz241hzAVYaqCwGzAPU3/QcXOKRp8CCHXYbWFsF Y0nZtqhdBo5RBk3OLYcI6T697gZfIBsBHw== X-Received: by 2002:a62:1743:0:b0:480:a01f:bf14 with SMTP id 64-20020a621743000000b00480a01fbf14mr3200323pfx.72.1635614230446; Sat, 30 Oct 2021 10:17:10 -0700 (PDT) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id nv4sm3111943pjb.17.2021.10.30.10.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Oct 2021 10:17:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v6 37/66] target/s390x: Implement s390_cpu_record_sigsegv Date: Sat, 30 Oct 2021 10:16:06 -0700 Message-Id: <20211030171635.1689530-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030171635.1689530-1-richard.henderson@linaro.org> References: <20211030171635.1689530-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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, imp@bsdimp.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Move the masking of the address from cpu_loop into s390_cpu_record_sigsegv -- this is governed by hw, not linux. This does mean we have to raise our own exception, rather than return to the fallback. Use maperr to choose between PGM_PROTECTION and PGM_ADDRESSING. Use the appropriate si_code for each in cpu_loop. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/s390x/s390x-internal.h | 13 ++++++++++--- linux-user/s390x/cpu_loop.c | 13 ++++++------- target/s390x/cpu.c | 6 ++++-- target/s390x/tcg/excp_helper.c | 18 +++++++++++------- 4 files changed, 31 insertions(+), 19 deletions(-) -- 2.25.1 diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 27d4a03ca1..163aa4f94a 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -270,13 +270,20 @@ ObjectClass *s390_cpu_class_by_name(const char *name); void s390x_cpu_debug_excp_handler(CPUState *cs); void s390_cpu_do_interrupt(CPUState *cpu); bool s390_cpu_exec_interrupt(CPUState *cpu, int int_req); -bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size, - MMUAccessType access_type, int mmu_idx, - bool probe, uintptr_t retaddr); void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) QEMU_NORETURN; +#ifdef CONFIG_USER_ONLY +void s390_cpu_record_sigsegv(CPUState *cs, vaddr address, + MMUAccessType access_type, + bool maperr, uintptr_t retaddr); +#else +bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size, + MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr); +#endif + /* fpu_helper.c */ uint32_t set_cc_nz_f32(float32 v); diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c index 69b69981f6..d089c8417e 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -24,8 +24,6 @@ #include "cpu_loop-common.h" #include "signal-common.h" -/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */ -#define S390X_FAIL_ADDR_MASK -4096LL static int get_pgm_data_si_code(int dxc_code) { @@ -111,12 +109,13 @@ void cpu_loop(CPUS390XState *env) n = TARGET_ILL_ILLOPC; goto do_signal_pc; case PGM_PROTECTION: + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_ACCERR, + env->__excp_addr); + break; case PGM_ADDRESSING: - sig = TARGET_SIGSEGV; - /* XXX: check env->error_code */ - n = TARGET_SEGV_MAPERR; - addr = env->__excp_addr & S390X_FAIL_ADDR_MASK; - goto do_signal; + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, + env->__excp_addr); + break; case PGM_EXECUTE: case PGM_SPECIFICATION: case PGM_SPECIAL_OP: diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 7b7b05f1d3..593dda75c4 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -266,9 +266,11 @@ static void s390_cpu_reset_full(DeviceState *dev) static const struct TCGCPUOps s390_tcg_ops = { .initialize = s390x_translate_init, - .tlb_fill = s390_cpu_tlb_fill, -#if !defined(CONFIG_USER_ONLY) +#ifdef CONFIG_USER_ONLY + .record_sigsegv = s390_cpu_record_sigsegv, +#else + .tlb_fill = s390_cpu_tlb_fill, .cpu_exec_interrupt = s390_cpu_exec_interrupt, .do_interrupt = s390_cpu_do_interrupt, .debug_excp_handler = s390x_cpu_debug_excp_handler, diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c index 3d6662a53c..b923d080fc 100644 --- a/target/s390x/tcg/excp_helper.c +++ b/target/s390x/tcg/excp_helper.c @@ -89,16 +89,20 @@ void s390_cpu_do_interrupt(CPUState *cs) cs->exception_index = -1; } -bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size, - MMUAccessType access_type, int mmu_idx, - bool probe, uintptr_t retaddr) +void s390_cpu_record_sigsegv(CPUState *cs, vaddr address, + MMUAccessType access_type, + bool maperr, uintptr_t retaddr) { S390CPU *cpu = S390_CPU(cs); - trigger_pgm_exception(&cpu->env, PGM_ADDRESSING); - /* On real machines this value is dropped into LowMem. Since this - is userland, simply put this someplace that cpu_loop can find it. */ - cpu->env.__excp_addr = address; + trigger_pgm_exception(&cpu->env, maperr ? PGM_ADDRESSING : PGM_PROTECTION); + /* + * On real machines this value is dropped into LowMem. Since this + * is userland, simply put this someplace that cpu_loop can find it. + * S390 only gives the page of the fault, not the exact address. + * C.f. the construction of TEC in mmu_translate(). + */ + cpu->env.__excp_addr = address & TARGET_PAGE_MASK; cpu_loop_exit_restore(cs, retaddr); }