Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1148508pxv; Fri, 9 Jul 2021 19:33:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytzVo3+D/6ckUqXZUeSoAwxUjKrmTHMONa5pwzO3pPMXb3RUivxIZucYjradyT7jD5ku1k X-Received: by 2002:a05:6402:5212:: with SMTP id s18mr16759649edd.370.1625884424345; Fri, 09 Jul 2021 19:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884424; cv=none; d=google.com; s=arc-20160816; b=PERHUZr+hquDynzX9fVv349mVCiXACrFz5D/xfY+Er4pBNmIVQ54QnhF5Mc4J3o6uE i+Tf2D6YNRZ6EEN+lGCiWRtdhQ/xv6KdAiJ8QrGQM3Grz38qTM7q7bChlKS6uT+HN5PC Jh4IMeeMOlFOIt3zx6wm23LrKHM4ucdtsV0KzG4iioZIOiCH445fEPeISbqq5KKnWtLD cruvSwAT6Qhb1+IJoL4eELreNn8fcl6hxtsCTYPUUMRH6hRYmMFPzAi+YiuetYswbQRr 6WH6wAGZEbAWXrNmW8ZZxv0028ZxXkzhznssDVmQHjpHAWhJB0xVVxO/HH1Pmzo5aTTT zu4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jyWVTb0r0VYP5LNKDk55iPXX6oleZ+Rufbc5Hbmlhzg=; b=UPs/tj7iRQd78Zhh9YVeiJis4ODVzIObu6w01DBVId+s6k5lUGRcs9KPtSAzC+Bpsw EGo6ticMmv00idi9azuejogC13hrYrSEaFQeF7TgsUgkkIJj1AWubMrXBwL6iEMUyEX6 PxOF21Ax+UHZ4Klxu1ykA8QoNy/MDbQSpjM/zLRpo/royUjruGumm+rfefRmGQYASVOo jalrKMMwhsh6f4yL+cB8HzC2H7sSSUpUbLqNlqG7rFVyoM2bzjj6VLw1Lxv9NoH5M04f jCOIZGGZYuB5bsYH6tDFJgy7Yxg1vPdOqDggL1p3VqGWAIal/XgiaHtQQLIvOpho1fCg q5pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IxhP42UZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si8579350edc.382.2021.07.09.19.33.21; Fri, 09 Jul 2021 19:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IxhP42UZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbhGJCcd (ORCPT + 99 others); Fri, 9 Jul 2021 22:32:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:43326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbhGJC33 (ORCPT ); Fri, 9 Jul 2021 22:29:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 77C506140A; Sat, 10 Jul 2021 02:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883997; bh=OU7RHW8RCJ20JtwD/Ek2scsCmITqJZlaW4FZJH/iKEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IxhP42UZEwEOIorVKwioIdrnDuOsqgIAwacENiIteebh99XerUg/uh23ZuN9ad7CZ pBfM+8NhOwgak0JDPEwxghY1/vHU4YVLg9ACXE0YqyDwLB/uxEh6Yq4bVf9+YzqWeK ImbFpRgcDtCqbqVN2v15nMVv0WHzs4LLG2ia9RvGhUtnJgY5r4SBGEE0EKrMl1otP8 mphxT8WX1QKHLHxPikFIWqT5LQjB8dP+ttsZVDfU/5+HgUZ+QfzZD7zjheVCH+Hbbz SNjJ7nbhqSUiqC5EibM/n8DUzb5qqnXONcWk42oCdvuRDFG7qKzreaFZYV2CsXzQVr IJUoQEbpNR9Qg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Heiko Carstens , Vasily Gorbik , Sasha Levin , linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 72/93] s390/mem_detect: fix tprot() program check new psw handling Date: Fri, 9 Jul 2021 22:24:06 -0400 Message-Id: <20210710022428.3169839-72-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiko Carstens [ Upstream commit da9057576785aaab52e706e76c0475c85b77ec14 ] The tprot() inline asm temporarily changes the program check new psw to redirect a potential program check on the diag instruction. Restoring of the program check new psw is done in C code behind the inline asm. This can be problematic, especially if the function is inlined, since the compiler can reorder instructions in such a way that a different instruction, which may result in a program check, might be executed before the program check new psw has been restored. To avoid such a scenario move restoring into the inline asm. For consistency reasons move also saving of the original program check new psw into the inline asm. Signed-off-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- arch/s390/boot/mem_detect.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/arch/s390/boot/mem_detect.c b/arch/s390/boot/mem_detect.c index 032d68165216..85049541c191 100644 --- a/arch/s390/boot/mem_detect.c +++ b/arch/s390/boot/mem_detect.c @@ -115,24 +115,30 @@ static int diag260(void) static int tprot(unsigned long addr) { - unsigned long pgm_addr; + unsigned long reg1, reg2; int rc = -EFAULT; - psw_t old = S390_lowcore.program_new_psw; + psw_t old; - S390_lowcore.program_new_psw.mask = __extract_psw(); asm volatile( - " larl %[pgm_addr],1f\n" - " stg %[pgm_addr],%[psw_pgm_addr]\n" + " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n" + " epsw %[reg1],%[reg2]\n" + " st %[reg1],0(%[psw_pgm])\n" + " st %[reg2],4(%[psw_pgm])\n" + " larl %[reg1],1f\n" + " stg %[reg1],8(%[psw_pgm])\n" " tprot 0(%[addr]),0\n" " ipm %[rc]\n" " srl %[rc],28\n" - "1:\n" - : [pgm_addr] "=&d"(pgm_addr), - [psw_pgm_addr] "=Q"(S390_lowcore.program_new_psw.addr), - [rc] "+&d"(rc) - : [addr] "a"(addr) + "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n" + : [reg1] "=&d" (reg1), + [reg2] "=&a" (reg2), + [rc] "+&d" (rc), + "=Q" (S390_lowcore.program_new_psw.addr), + "=Q" (old) + : [psw_old] "a" (&old), + [psw_pgm] "a" (&S390_lowcore.program_new_psw), + [addr] "a" (addr) : "cc", "memory"); - S390_lowcore.program_new_psw = old; return rc; } -- 2.30.2