From patchwork Mon Feb 20 18:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655121 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1552583wrc; Mon, 20 Feb 2023 10:46:05 -0800 (PST) X-Google-Smtp-Source: AK7set/qFWNXaLrBLFF0Fng/6UaBx6AJphPKnpH9H6pqd/gRrPYzkFkVwjABt8wl34PU+D49plix X-Received: by 2002:a05:622a:87:b0:3b9:d1c1:6da6 with SMTP id o7-20020a05622a008700b003b9d1c16da6mr15626094qtw.7.1676918765263; Mon, 20 Feb 2023 10:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676918765; cv=none; d=google.com; s=arc-20160816; b=CyxUFsIfOa+ebvg7aiiNaGZz1Ewsr6FObrk7x9pJQwg2eEhhOTzpSgRcbb+TGYSXJR nWc42p0WUY3mHeV18/OkPyo4W1l/a8+mL2F6vBtIDvAUXd9+cGqOGTXP15IL+k0J7o9C JUmF7a/mt9hozP7rn6EJWMBR7W+yoo1oVLYCdEOFmGoL3krD42SiNfUQ/bxTve8xVw8l S92b6BLMbIcHHgu5gDuhV4ALgq52dlv6JpAfHDW0l8Kj+JCZ6F2fik1bJhxm2Yw6ysCl j35ANOA0F/16lCX5jULr6RxfoWkdWomqN7//mI0ybhNNJCKuTzSPzKlLtoAdLzDqT83L qSWg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x6mVVLeAKLfZ1QsaICACHihb7zGLUdrCmrZOJHSfaPM=; b=EZAeQ1aYe+FoPV3YdT59lGkKR1HgzRCEHuv7Lfkrjb00Xr9WTUk3gTk+8YeZWmt7aS NjC/Vx86J18jJCreXuWrOTNZnGUh2sSiuCH3Fm7kbLQC8ttlMvx0Fjlg8EN2Zw5zxnYm 8rbhtRCbjCQ+lP69/bKqmEpDUEfD0QFqH3cIkyQsxvgTawGqx7S6yjAZ+Pz3h3561z8E eIsaOP4cKwmuKZsnBz9HH8eQ7/pzxahVCaS56WN7EMC6SElkgPiCUgslnXEgWFRiO04u UxBvDSCUZZyXunQcBkFeFY2hwRghFLsHi0EqgO/5NRL/WcNxs2RuEtW0LYOj+j+3iFo5 tUfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Pa/2FLLd"; 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=pass (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 de41-20020a05620a372900b00706672c17c3si9963011qkb.758.2023.02.20.10.46.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2023 10:46:05 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b="Pa/2FLLd"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUB7Q-0004y5-0n; Mon, 20 Feb 2023 13:42:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUB6W-0004Xp-Ai for qemu-devel@nongnu.org; Mon, 20 Feb 2023 13:41:40 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUB6L-000484-Aw for qemu-devel@nongnu.org; Mon, 20 Feb 2023 13:41:32 -0500 Received: by mail-pl1-x62c.google.com with SMTP id bh1so2503000plb.11 for ; Mon, 20 Feb 2023 10:41:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x6mVVLeAKLfZ1QsaICACHihb7zGLUdrCmrZOJHSfaPM=; b=Pa/2FLLdjM+UIhNaCoU7zB6nIBxw5Lo4d+Hk8Y9R/DetyIES7yznTCruZFvUGghlrW HGteNiVQj//DAyJBfXVm+BM1550BTMXCF5wRTp7vshS4+pQJGmpKXe7Ex8DVKY6kLzrw oGN7LM2+6Hn4mv3aFqGqPWMH/3brV3YWsRKy9hV1yKqpqg6mfbHvHr3EMrhyp4i3XZ1L d4lZvENCN/ydjL6G+wPGxrFLVGxVEEkaYy66mKqNnj768HATRiYppd7812AZm+V0dlGn E70uHd2fIJToXL/BnI8OnTeag8072HS+Te/5jyknMfWKYFj37Ftr151qAz3vt3pJKyVt gE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x6mVVLeAKLfZ1QsaICACHihb7zGLUdrCmrZOJHSfaPM=; b=eRDolln4l+NeDljgKMw1Z0SIsiZjxkt1pIab3pJ6UKQHDi4WvDhMIKzrUVwb3Kg+UZ 93eK6TbElMLE9rTPEv40dOmkC1TZY4VtP+CONOacFhwd+0JrpMh4TzgidogZcL9DRZRn IrH8DMNsPWgVonu1YwwxcG52llc4aW+LXYvJUdiu9r3B2HFhwMHOHEjb1fOCp+/YTlPx Gr7/T02yJykBgeZwzDDzM10vI9wCN0bUNgMl5zNX/rnlCvTyjOC9YBlBgLtK3+k/HTUT N+o8jrR54fp91cmtGTFZGt9+/Lmrmau8OeqWTRIlGPzg1BQhJnqnsUjTJ5YOPcWQ6cuE HvYg== X-Gm-Message-State: AO0yUKW+9h5GexWI99F9TfV+aSoi+9u8PmQoClDtugFlKRHcs63MLalH t6FClPXv73N+QlIacEMaE8rtaaX08u3f4Nqt6q4= X-Received: by 2002:a17:902:f68f:b0:19c:1433:5fba with SMTP id l15-20020a170902f68f00b0019c14335fbamr2708852plg.0.1676918481992; Mon, 20 Feb 2023 10:41:21 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id jk20-20020a170903331400b0019258bcf3ffsm1911676plb.56.2023.02.20.10.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 10:41:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: thuth@redhat.com, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 14/27] target/s390x: Assert masking of psw.addr in cpu_get_tb_cpu_state Date: Mon, 20 Feb 2023 08:40:39 -1000 Message-Id: <20230220184052.163465-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220184052.163465-1-richard.henderson@linaro.org> References: <20230220184052.163465-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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.29 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-bounces+patch=linaro.org@nongnu.org When changing modes via SAM, we raise a specification exception if the new PC is out of range. The masking in s390x_tr_init_disas_context was too late to be correct, but may be removed. Add a debugging assert in cpu_get_tb_cpu_state. Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- target/s390x/cpu.h | 20 ++++++++++++++------ target/s390x/tcg/translate.c | 6 +----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 7d6d01325b..c7eeebfc53 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -379,17 +379,25 @@ static inline int cpu_mmu_index(CPUS390XState *env, bool ifetch) } static inline void cpu_get_tb_cpu_state(CPUS390XState* env, target_ulong *pc, - target_ulong *cs_base, uint32_t *flags) + target_ulong *cs_base, uint32_t *pflags) { - *pc = env->psw.addr; - *cs_base = env->ex_value; - *flags = (env->psw.mask >> FLAG_MASK_PSW_SHIFT) & FLAG_MASK_PSW; + int flags = (env->psw.mask >> FLAG_MASK_PSW_SHIFT) & FLAG_MASK_PSW; if (env->cregs[0] & CR0_AFP) { - *flags |= FLAG_MASK_AFP; + flags |= FLAG_MASK_AFP; } if (env->cregs[0] & CR0_VECTOR) { - *flags |= FLAG_MASK_VECTOR; + flags |= FLAG_MASK_VECTOR; } + *pflags = flags; + *cs_base = env->ex_value; + *pc = env->psw.addr; +#ifdef CONFIG_DEBUG_TCG + if (!(flags & FLAG_MASK_32)) { + assert(*pc <= 0xffffff); + } else if (!(flags & FLAG_MASK_64)) { + assert(*pc <= 0x7fffffff); + } +#endif } /* PER bits from control register 9 */ diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 3a61491222..d21b6d7f72 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -6563,11 +6563,7 @@ static void s390x_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) { DisasContext *dc = container_of(dcbase, DisasContext, base); - /* 31-bit mode */ - if (!(dc->base.tb->flags & FLAG_MASK_64)) { - dc->base.pc_first &= 0x7fffffff; - dc->base.pc_next = dc->base.pc_first; - } + /* Note cpu_get_tb_cpu_state asserts PC is masked for the mode. */ dc->cc_op = CC_OP_DYNAMIC; dc->ex_value = dc->base.tb->cs_base;