From patchwork Tue Jun 15 03:07:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 460484 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3861615jae; Mon, 14 Jun 2021 20:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLWiJa1UmH1v46H7gHiW7qjP/iL4rmgXlkDd4KuoEVx36IvRxolatmz8u6hLZiq3VtznVZ X-Received: by 2002:a67:b30b:: with SMTP id a11mr3050111vsm.32.1623726637011; Mon, 14 Jun 2021 20:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623726637; cv=none; d=google.com; s=arc-20160816; b=MoBxsbdToyAW2eUEHHJwpB3cBnflxRzwyGKbkNEvMgUhV02VOZvH5RaUPlQ0TsPBMu eQV7hRFzIXkOL0bo0vYO59HKqBOZLiPWMCK+uzODi2cPPiFMqU3p68wQhwmrsw7UqWf1 9AVIO6MiPelafgA0bOo33sUX/mfv6wN1OPMqJXSBCLfunLLu3ve6SL626m2Hw6Cvy+x5 IguOhd9S9mtMkxnqXtF9FtlJ1dp0P0ewkgml+F8ucz3fCnQ2Dv3domlzmPVjgPR93DkI RpvF6U2zPMUdYhuRoPHCbPo8akqYZZ0fbZkDhy0KPbAza8R/+pUqJ9uCPin3on+oKkdp zjkA== 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=TQf3IjdFQae4tidY+aDNVPg91NNd8BgJC+OISDGWpvo=; b=V/mi9Df3namElRSTwTiSJdfKXJ2ZLbBXdsdUusgSsHtrWVWv2GBxZlIv/KYpmbOsht /cnKZLL5P7cHuryBHQpB2uFv/xE9zNiLIj0HAZYijYWEeDSv9IBUvYoHIhdm+cEkjwEG jbFHiBGSlBEjtxIY+iZxYItHLPs7irV/Ql5CH/bKji++CGVLqlS9qyZv88qlmCT27Oz6 ObArOmBrLRgVR8g1GM5yyTcKZckz76oPhum65w8uGKhdpQaVqxCIIdYDE2g8G7QvMtAj kOrOs698oQl3+oIgnQb6Bch94xP1Fij038y8vbzk1RHN9xWJvkLp9UcXrrsA1nFTcT0/ 7L4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RQ4TCrKN; 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 90si2278889uam.205.2021.06.14.20.10.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 20:10:37 -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=RQ4TCrKN; 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]:51344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lszTI-0000sl-Dl for patch@linaro.org; Mon, 14 Jun 2021 23:10:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lszQi-0004j9-6P for qemu-devel@nongnu.org; Mon, 14 Jun 2021 23:07:57 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:36558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lszQe-0008Ae-G0 for qemu-devel@nongnu.org; Mon, 14 Jun 2021 23:07:55 -0400 Received: by mail-pf1-x42a.google.com with SMTP id c12so12174959pfl.3 for ; Mon, 14 Jun 2021 20:07:52 -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=TQf3IjdFQae4tidY+aDNVPg91NNd8BgJC+OISDGWpvo=; b=RQ4TCrKNkNkBjR7TSkxoGfCpcWGpukR5UnCDcRxQDiRHJ6AfL37ld8HkjVwu9T9e2S rLhSbquzP+MT78WpVYQI6+14+7jvI6vJOlYnNopN8OyegXGtB1/AKOxN2MwsunXIFmVX XuLie1kqXC0YGteZW4TVOOXNAA92Eymcor7G+AfbnsG42kMNSqUbbRIbww/mJeG0WCpN u1dRb1EyR5p598KSGbVqnxGXqoyQgJ1ygUhtDX6FcLg+exXUe+rnFjvv23dVQK5yEQFN GxsjSMxSLAxG89kgMIRrim7Of7r0NOAAYRhEq6X/0M5RIErqKqNfF5FWEzScStLjDwRj tfug== 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=TQf3IjdFQae4tidY+aDNVPg91NNd8BgJC+OISDGWpvo=; b=JT0lkRRKS+brci6QA0XVza/Mh6gOgGJxNHZShho2XAPfb6B/TDi2oCiliQiIPjCNYg nyKN7cNSn4b7CVa3jE1021IPgQzHCylgZvEjjWR7TpgLx/4Ro/FDYrGMeNkMEdklyazA 5vpP2cWnUHz4qL4kkkduPumDRLuRt/1xJ84Ji4wGrOPhpviNWUCQfTXfMXMuscZ6C6yQ TFI4nBD7ZghcnrbUAuxysihjchY0osJEUqmAp4lgJkGe9feIhmhoFpgWZ9ZPRxFRmZ7P 4AFnlzBt/qZ7MujXx+IYPVwEXxbDQ4ezYqbEzPyiBuHPa71dfGv5M96+vr4tPaJyopBO R8oA== X-Gm-Message-State: AOAM532RFTHtgwm+tk9/ONKtypOsPmnrAwzyY/ps+gGcClao8twLVifc DHIs4v/U87oN9bpDXXUJ4nCjAkbF/UWGWg== X-Received: by 2002:a62:dd8b:0:b029:2e9:731a:e22e with SMTP id w133-20020a62dd8b0000b02902e9731ae22emr2108516pff.69.1623726471125; Mon, 14 Jun 2021 20:07:51 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id w71sm7554666pfc.164.2021.06.14.20.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 20:07:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 5/5] linux-user/s390x: Save and restore psw.mask properly Date: Mon, 14 Jun 2021 20:07:44 -0700 Message-Id: <20210615030744.1252385-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615030744.1252385-1-richard.henderson@linaro.org> References: <20210615030744.1252385-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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: ruixin.bao@ibm.com, jonathan.albrecht@linux.vnet.ibm.com, cohuck@redhat.com, qemu-s390x@nongnu.org, david@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At present, we're referencing env->psw.mask directly, which fails to ensure that env->cc_op is incorporated or updated. Use s390_cpu_{set_psw,get_psw_mask} to fix this. Mirror the kernel's cleaning of the psw.mask in save_sigregs and restore_sigregs. Ignore PSW_MASK_RI for now, as qemu does not support that. Signed-off-by: Richard Henderson --- linux-user/s390x/signal.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) -- 2.25.1 Reviewed-by: David Hildenbrand diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index ef136dae33..bf8a8fbfe9 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -112,15 +112,23 @@ get_sigframe(struct target_sigaction *ka, CPUS390XState *env, size_t frame_size) return (sp - frame_size) & -8ul; } +#define PSW_USER_BITS (PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \ + PSW_MASK_MCHECK | PSW_MASK_PSTATE | PSW_ASC_PRIMARY) +#define PSW_MASK_USER (PSW_MASK_ASC | PSW_MASK_CC | PSW_MASK_PM | \ + PSW_MASK_64 | PSW_MASK_32) + static void save_sigregs(CPUS390XState *env, target_sigregs *sregs) { + uint64_t psw_mask = s390_cpu_get_psw_mask(env); int i; /* * Copy a 'clean' PSW mask to the user to avoid leaking * information about whether PER is currently on. + * TODO: qemu does not support PSW_MASK_RI; it will never be set. */ - __put_user(env->psw.mask, &sregs->regs.psw.mask); + psw_mask = PSW_USER_BITS | (psw_mask & PSW_MASK_USER); + __put_user(psw_mask, &sregs->regs.psw.mask); __put_user(env->psw.addr, &sregs->regs.psw.addr); for (i = 0; i < 16; i++) { @@ -289,7 +297,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, static void restore_sigregs(CPUS390XState *env, target_sigregs *sc) { - target_ulong prev_addr; + uint64_t prev_addr, prev_mask, mask, addr; int i; for (i = 0; i < 16; i++) { @@ -297,9 +305,28 @@ static void restore_sigregs(CPUS390XState *env, target_sigregs *sc) } prev_addr = env->psw.addr; - __get_user(env->psw.mask, &sc->regs.psw.mask); - __get_user(env->psw.addr, &sc->regs.psw.addr); - trace_user_s390x_restore_sigregs(env, env->psw.addr, prev_addr); + __get_user(mask, &sc->regs.psw.mask); + __get_user(addr, &sc->regs.psw.addr); + trace_user_s390x_restore_sigregs(env, addr, prev_addr); + + /* + * Use current psw.mask to preserve PER bit. + * TODO: + * if (!is_ri_task(current) && (user_sregs.regs.psw.mask & PSW_MASK_RI)) + * return -EINVAL; + * Simply do not allow it to be set in mask. + */ + prev_mask = s390_cpu_get_psw_mask(env); + mask = (prev_mask & ~PSW_MASK_USER) | (mask & PSW_MASK_USER); + /* Check for invalid user address space control. */ + if ((mask & PSW_MASK_ASC) == PSW_ASC_HOME) { + mask = (mask & ~PSW_MASK_ASC) | PSW_ASC_PRIMARY; + } + /* Check for invalid amode. */ + if (mask & PSW_MASK_64) { + mask |= PSW_MASK_32; + } + s390_cpu_set_psw(env, mask, addr); for (i = 0; i < 16; i++) { __get_user(env->aregs[i], &sc->regs.acrs[i]);