Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp463095yba; Wed, 15 May 2019 04:33:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwW+WQxDUQSewL0GQymVfWT8XU/2QD2uga8VWym2zpJ9JC9lenSuals1czn9JGXnSbF2vmT X-Received: by 2002:a63:fd4a:: with SMTP id m10mr44335921pgj.302.1557920001377; Wed, 15 May 2019 04:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920001; cv=none; d=google.com; s=arc-20160816; b=ZYIrLTreV/0tooupDTZk+mcerFUrvoSXoTqHD2SlZIWM0WZa3DRJea9pqVwggMkc0J mmqVOUlhRyYvth36ktMF8XISIekZ91rrP/deePpu58G5+IywTzDPjuG1nPTHk1Iy3pNx PmhxS8Z7W5YLzlLv23GAOZGhByr6upIq9bmXYxqbNhOJJoqzCoyjZxZXzjuIMOkgZO/b +CSZKW6+qMBo8dPWfMj3Xnv2M9NzDfkj8+hMjNkmFJ6pnA/Mc+1jcKI4eRZdL2YYxdz3 S7eh5yZQzXnH7iCZ38qcTZS50K1zUTp79ntLhCxjt/NuUzC7eKRkpvuWv+ny+CpJ++Ay HASA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OmZdzqJ5rz9+sKviTohL16vpVVOGr+lw593IJRjGgWc=; b=jrlB5hiTxDaudF81bXshV9yZVyvEsa2qThq1Clfh9NJSj5q2DCILxfjLMpCWWh0tal JPdUqx0ZveAN0XBu6CdST6Qj2uDyKbC1sPv7lWp4wPKLwNmYNUVkllglQzR1a4igMFHr dW7e+zXDvBPF/NMegFsloP11VFZ1AKnFgFkt/EByek4xE9xjHn0LEjxFQfzrE29RlBIK WhahwMi+qFr0eLn1npzRS0/YJ24fpUjiXH+XD8VKVQ3xMJVDl/pommYgk1A6oQ2ikTcY /L0VMvydkGcrNFnZodur9xM5EeWahU7KlOjaIHh+eRpvlKCHkuVVvDJJX6I78BmDjE2+ Fmvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="h/gAaghP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si1653170plg.222.2019.05.15.04.33.06; Wed, 15 May 2019 04:33:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="h/gAaghP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731338AbfEOLb2 (ORCPT + 99 others); Wed, 15 May 2019 07:31:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:43178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732894AbfEOLbY (ORCPT ); Wed, 15 May 2019 07:31:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A7C120818; Wed, 15 May 2019 11:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919884; bh=vUQzSnELn00Y8vO8upYf8r+N3HxY9LCoXUePa8jzX6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h/gAaghPym6cTm621NQr/0YwQPgoQUwZHJIWMJzOXztGS/ZWTi4vOViAiuKCiyKcW 7/4LeDGib8pn9YWdyZZArT/fEcsAQb+HeAmfA0ekFDvE0HqiWB+XGzw3lVWm9TUJsY QJ1ft7KFeNZ+ftTL1r2TpFAgaetUH1FDGunUZmnU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell Currey , Akshay Adiga , Nicholas Piggin , Michael Ellerman Subject: [PATCH 5.0 131/137] powerpc/powernv/idle: Restore IAMR after idle Date: Wed, 15 May 2019 12:56:52 +0200 Message-Id: <20190515090703.387592033@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell Currey commit a3f3072db6cad40895c585dce65e36aab997f042 upstream. Without restoring the IAMR after idle, execution prevention on POWER9 with Radix MMU is overwritten and the kernel can freely execute userspace without faulting. This is necessary when returning from any stop state that modifies user state, as well as hypervisor state. To test how this fails without this patch, load the lkdtm driver and do the following: $ echo EXEC_USERSPACE > /sys/kernel/debug/provoke-crash/DIRECT which won't fault, then boot the kernel with powersave=off, where it will fault. Applying this patch will fix this. Fixes: 3b10d0095a1e ("powerpc/mm/radix: Prevent kernel execution of user space") Cc: stable@vger.kernel.org # v4.10+ Signed-off-by: Russell Currey Reviewed-by: Akshay Adiga Reviewed-by: Nicholas Piggin Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/idle_book3s.S | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/arch/powerpc/kernel/idle_book3s.S +++ b/arch/powerpc/kernel/idle_book3s.S @@ -170,6 +170,9 @@ core_idle_lock_held: bne- core_idle_lock_held blr +/* Reuse an unused pt_regs slot for IAMR */ +#define PNV_POWERSAVE_IAMR _DAR + /* * Pass requested state in r3: * r3 - PNV_THREAD_NAP/SLEEP/WINKLE in POWER8 @@ -200,6 +203,12 @@ pnv_powersave_common: /* Continue saving state */ SAVE_GPR(2, r1) SAVE_NVGPRS(r1) + +BEGIN_FTR_SECTION + mfspr r5, SPRN_IAMR + std r5, PNV_POWERSAVE_IAMR(r1) +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) + mfcr r5 std r5,_CCR(r1) std r1,PACAR1(r13) @@ -924,6 +933,17 @@ BEGIN_FTR_SECTION END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) REST_NVGPRS(r1) REST_GPR(2, r1) + +BEGIN_FTR_SECTION + /* IAMR was saved in pnv_powersave_common() */ + ld r5, PNV_POWERSAVE_IAMR(r1) + mtspr SPRN_IAMR, r5 + /* + * We don't need an isync here because the upcoming mtmsrd is + * execution synchronizing. + */ +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) + ld r4,PACAKMSR(r13) ld r5,_LINK(r1) ld r6,_CCR(r1)