From patchwork Mon Mar 15 18:46:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400539 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3683385jai; Mon, 15 Mar 2021 12:04:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG9Iq5W0u37D2gGYUMLuzpY/n+mAPiON1QWRdYijeGQmGRjYFt7Olc40e2UjxMMFsxX534 X-Received: by 2002:a1c:4143:: with SMTP id o64mr1116613wma.50.1615835051444; Mon, 15 Mar 2021 12:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615835051; cv=none; d=google.com; s=arc-20160816; b=JY2qRamXmIkfzd9Zh05yu4uovoiYdXX/ZxBUngURZy2nUBKZwFrAgmllKx7CdHgvjV g0y+0fJh+Z23piFKTGWSBaQAWzb28qS71UkVFCNYXne7SvP5si9c4fmV/vY9X8aPZD/4 bOYKxCrmTj74A8paAKzz301ZgC/PsbISRgj9Tn+7I4D1COxWDXXeyuXxxUWRdqkAk1SZ KEZ4cVFVCXA+pllo0DpKNF7XMpIQnEO19rJmLvq1o8Hw/WcDs3NGZiLF4XUu7Bn/dyPG q3vF3Otp83P8QvvYH7NoHCnFtsblBrkKBl6WgnBRiJ0QHXHje6SEW9oDSfGT8EnU5Pul ip8Q== 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=GP7KN1O/N4US4bdn1IcXHif9taZ0y5n50rRX2Q2HUDY=; b=DL+yqBxaVbAJfPSgYcKDNRPkHvx6AKcKdpiyrVU6NU+SgtUUbd7IiIGaRMDIRuonK6 ZgZCxH/JLoSJcGtB+mdoxurttP6i6Gp2L7FZB/n7n387kEXb2Y90ma7EEDW7ooM9FnHX zbOiSlPWNVFncOpwlUnbO6e+CX8Gw6NPAgLJdJYsoWEn+gMB56k6FSABrciTCBmSRN1L TD15rWrC2rLWJI7U3pVOiF/0DKUmWsz4ey1ljjB8+R9kua+A0pfybPxVA7DgKJMbGKVc VvohG3Qt3XlOM7opKVuokghomRFTSQFSDBbQtSCjfIGfwfNwaAi0HS430wQNc7eXvE/k eIvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F620gfJe; 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 r16si18497598wrn.27.2021.03.15.12.04.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Mar 2021 12:04: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=pass header.i=@linaro.org header.s=google header.b=F620gfJe; 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]:58688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLsVe-0005xa-9O for patch@linaro.org; Mon, 15 Mar 2021 15:04:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLsEm-0007cO-EL for qemu-devel@nongnu.org; Mon, 15 Mar 2021 14:46:46 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:46892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLsEf-0001ik-Ox for qemu-devel@nongnu.org; Mon, 15 Mar 2021 14:46:40 -0400 Received: by mail-oi1-x22b.google.com with SMTP id w125so6923751oib.13 for ; Mon, 15 Mar 2021 11:46:37 -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=GP7KN1O/N4US4bdn1IcXHif9taZ0y5n50rRX2Q2HUDY=; b=F620gfJeeuRvpaXMgCyk4HU0DyPD3V72S6urrgqtn6fW2hISBxlNweQbnC08tD+/so PjgRn0lQDg/Irn3W6N5wfkKXVTaY0mIOiv90yGBJS87GSn4R8DQKyEnz5WLush3m2AJE lafL2pxKIvR2ifoGLrrnNz3hVm2jU+ZfuYc8gmdMy0nraL7vROji4BV9sq4jVoEIQM8A hL55FRf9MjLy6fI88o1zCi8tSxLiCHsPIwTIc1P1T/OiHfB0gShUl5o7gQumWkYXWb1m cet872Q539CqlebKahWi2HWA/jCtmYojqlWlVlXsi3Gg39EQdTRasHXef5NNKQMziqEK mMew== 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:mime-version:content-transfer-encoding; bh=GP7KN1O/N4US4bdn1IcXHif9taZ0y5n50rRX2Q2HUDY=; b=NheHuH7eoYB05VM5ztUUtwy5rJdKWuMewx5QOjqVp/uQjiO8R6d6homUaI64oaUaly JFWUUlPwTJSFM2T8UIS4upwmkBJuhJJHP/7+GxwS93S9dfMDijsKVyGbFmY/Ks3J7qTm x6+wGHWn4f+8eAveAqaOqA2hHMHMDfDV6dPz03Ke8dYmM+Dsnpo9KRi4nroKiLWNskfg Y1to7/LYOYZMjygUhA8mmBqCAhwkfpL1vywAWBID+HvZdgowD2vBpn0+qmcRehChpsxk A52nR3DVyUf1oPn2fnBbVMa8hyOf6zHPx4dFr9XsQ0VV7yAw7JBHPh6E5RmswrY50avN smIQ== X-Gm-Message-State: AOAM5323uR5QDNXjuyfCbOYS4tCjTRxUc6uEcxkBE+euDEIQA9OuzQpF HywB8knJmymH8uoEFK+EEtyJx2da0ZUjTyxk X-Received: by 2002:aca:4785:: with SMTP id u127mr338807oia.163.1615833996787; Mon, 15 Mar 2021 11:46:36 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id o25sm7519851otk.11.2021.03.15.11.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:46:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 16/17] linux-user/ppc: Fix msr updates for signal handling Date: Mon, 15 Mar 2021 12:46:14 -0600 Message-Id: <20210315184615.1985590-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315184615.1985590-1-richard.henderson@linaro.org> References: <20210315184615.1985590-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22b.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: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In save_user_regs, there are two bugs where we OR in a bit number instead of the bit, clobbering the low bits of MSR. However: The MSR_VR and MSR_SPE bits control the availability of the insns. If the bits were not already set in MSR, then any attempt to access those registers would result in SIGILL. For linux-user, we always initialize MSR to the capabilities of the cpu. We *could* add checks vs MSR where we currently check insn_flags and insn_flags2, but we know they match. Also, there's a stray cut-and-paste comment in restore. Then, do not force little-endian binaries into big-endian mode. Finally, use ppc_store_msr for the update to affect hflags. Which is the reason none of these bugs were previously noticed. Signed-off-by: Richard Henderson --- linux-user/ppc/cpu_loop.c | 5 +++-- linux-user/ppc/signal.c | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index df71e15a25..4a0f6c8dc2 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -492,11 +492,12 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) #if defined(TARGET_PPC64) int flag = (env->insns_flags2 & PPC2_BOOKE206) ? MSR_CM : MSR_SF; #if defined(TARGET_ABI32) - env->msr &= ~((target_ulong)1 << flag); + ppc_store_msr(env, env->msr & ~((target_ulong)1 << flag)); #else - env->msr |= (target_ulong)1 << flag; + ppc_store_msr(env, env->msr | (target_ulong)1 << flag); #endif #endif + env->nip = regs->nip; for(i = 0; i < 32; i++) { env->gpr[i] = regs->gpr[i]; diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index b78613f7c8..bad38f8ed9 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -261,9 +261,6 @@ static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame) __put_user(avr->u64[PPC_VEC_HI], &vreg->u64[0]); __put_user(avr->u64[PPC_VEC_LO], &vreg->u64[1]); } - /* Set MSR_VR in the saved MSR value to indicate that - frame->mc_vregs contains valid data. */ - msr |= MSR_VR; #if defined(TARGET_PPC64) vrsave = (uint32_t *)&frame->mc_vregs.altivec[33]; /* 64-bit needs to put a pointer to the vectors in the frame */ @@ -300,9 +297,6 @@ static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame) for (i = 0; i < ARRAY_SIZE(env->gprh); i++) { __put_user(env->gprh[i], &frame->mc_vregs.spe[i]); } - /* Set MSR_SPE in the saved MSR value to indicate that - frame->mc_vregs contains valid data. */ - msr |= MSR_SPE; __put_user(env->spe_fscr, &frame->mc_vregs.spe[32]); } #endif @@ -354,8 +348,10 @@ static void restore_user_regs(CPUPPCState *env, __get_user(msr, &frame->mc_gregs[TARGET_PT_MSR]); /* If doing signal return, restore the previous little-endian mode. */ - if (sig) - env->msr = (env->msr & ~(1ull << MSR_LE)) | (msr & (1ull << MSR_LE)); + if (sig) { + ppc_store_msr(env, ((env->msr & ~(1ull << MSR_LE)) | + (msr & (1ull << MSR_LE)))); + } /* Restore Altivec registers if necessary. */ if (env->insns_flags & PPC_ALTIVEC) { @@ -376,8 +372,6 @@ static void restore_user_regs(CPUPPCState *env, __get_user(avr->u64[PPC_VEC_HI], &vreg->u64[0]); __get_user(avr->u64[PPC_VEC_LO], &vreg->u64[1]); } - /* Set MSR_VEC in the saved MSR value to indicate that - frame->mc_vregs contains valid data. */ #if defined(TARGET_PPC64) vrsave = (uint32_t *)&v_regs[33]; #else @@ -468,7 +462,7 @@ void setup_frame(int sig, struct target_sigaction *ka, env->nip = (target_ulong) ka->_sa_handler; /* Signal handlers are entered in big-endian mode. */ - env->msr &= ~(1ull << MSR_LE); + ppc_store_msr(env, env->msr & ~(1ull << MSR_LE)); unlock_user_struct(frame, frame_addr, 1); return; @@ -563,8 +557,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->nip = (target_ulong) ka->_sa_handler; #endif +#ifdef TARGET_WORDS_BIGENDIAN /* Signal handlers are entered in big-endian mode. */ - env->msr &= ~(1ull << MSR_LE); + ppc_store_msr(env, env->msr & ~(1ull << MSR_LE)); +#else + /* Signal handlers are entered in little-endian mode. */ + ppc_store_msr(env, env->msr | (1ull << MSR_LE)); +#endif unlock_user_struct(rt_sf, rt_sf_addr, 1); return;