Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4464992rwb; Tue, 6 Sep 2022 07:56:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Uj1yN9ko2DLpPYPTLGpP1ljUWN0FayUoG8PkRnIW24nDMgcwxf/ZX8JbksMELr5S5nSnE X-Received: by 2002:a65:6cc8:0:b0:3fe:2b89:cc00 with SMTP id g8-20020a656cc8000000b003fe2b89cc00mr47206822pgw.599.1662476205906; Tue, 06 Sep 2022 07:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476205; cv=none; d=google.com; s=arc-20160816; b=MhqsEvormpP/gSH0YWdiJIHCFSkD2msUqV4rV9ZRn325ohf0wJyHfyLLBjivJLX6zj OeIUoxrhY+Rdv9KT6H/72R9iht5C7y77n9bR6RTFzy2OUnYqOrn6ObYNyMBninqNDUsM hPXKt98AG258m5IMpWhCMfQICHA5imCoMjGKwa8ndOwl6Z/2idvGKZdAQ+aRCBnCFCVK XjdWqc+SuS7+jHo2KIo0/BvN+0dgskAuV03eR/DB8YrFpsciFQGKESO5N4IjQPMK4ZnB kb2UpdQtGCYKNh4kf1F9xhv1ZjKj06JAJrXO3QLh+14xy1ce8oP+4Hq9JH4fhVn3WSWU eKzg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0AMgR6/zO8e4cAbDZ+sbXu3262YRytcMqeoVWfbwByQ=; b=mybUNgUT7xwA3voDBBBdy6MPSfzDXSR8CV2u5YS/6qEZ5l1PMe1fr9zKNDknTfGo/a CU0Lt7HJWwdPuzi4safZQJxF1Nv8GXOFuBk8aZ7OPt9ddWO6ghKpb9coHVajTwgMNFzP QzIp7k3d164y72Tz4erutyeZiH1BP/JEyk0isS3AbRLaHn0+VElgktUr+sBnwIFurxfN Qn0G+edXDhtd+GmhvSelqeJysn7ThN2SX2E5eixPNVPCIPQQmtFeOXZdRZvsJGyzYLt/ wW01vIel9SvY3XsJhwvyc/gVFQ0T+MmaIItzTlnud2l6O1WuU8KyzSouYCpAMjyHgaw6 WrvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m3YaIGVa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id me6-20020a17090b17c600b001fe0682652esi16755724pjb.184.2022.09.06.07.56.34; Tue, 06 Sep 2022 07:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m3YaIGVa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239673AbiIFOIQ (ORCPT + 99 others); Tue, 6 Sep 2022 10:08:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240480AbiIFOGi (ORCPT ); Tue, 6 Sep 2022 10:06:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C92844DB; Tue, 6 Sep 2022 06:45:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6C76C61512; Tue, 6 Sep 2022 13:44:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DD04C433D6; Tue, 6 Sep 2022 13:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471861; bh=J3u+U+WQFMotdht0bsJwo5KI5Wb/8L6B1uIHx450JDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3YaIGVaawPQ4jDo1UTNaAp4/IrCjTc3sJa268CB35w6q/gUD8i62btMxcJy3p53t CdMW6ZNYmtcgCX8b2sD+uTDJaoz0HaW21r5q9GgBl5Lyxbj/6Gjcs9rB6w9SxX3qUQ pJ0ALxW71+s5+M+NNYGc/UkzZDCpm7eES7+OF7p4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Jordan Niethe Subject: [PATCH 5.19 063/155] powerpc/rtas: Fix RTAS MSR[HV] handling for Cell Date: Tue, 6 Sep 2022 15:30:11 +0200 Message-Id: <20220906132832.108499157@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Ellerman commit 91926d8b7e71aaf5f84f0cf208fc5a8b7a761050 upstream. The semi-recent changes to MSR handling when entering RTAS (firmware) cause crashes on IBM Cell machines. An example trace: kernel tried to execute user page (2fff01a8) - exploit attempt? (uid: 0) BUG: Unable to handle kernel instruction fetch Faulting instruction address: 0x2fff01a8 Oops: Kernel access of bad area, sig: 11 [#1] BE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=4 NUMA Cell Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 6.0.0-rc2-00433-gede0a8d3307a #207 NIP: 000000002fff01a8 LR: 0000000000032608 CTR: 0000000000000000 REGS: c0000000015236b0 TRAP: 0400 Tainted: G W (6.0.0-rc2-00433-gede0a8d3307a) MSR: 0000000008001002 CR: 00000000 XER: 20000000 ... NIP 0x2fff01a8 LR 0x32608 Call Trace: 0xc00000000143c5f8 (unreliable) .rtas_call+0x224/0x320 .rtas_get_boot_time+0x70/0x150 .read_persistent_clock64+0x114/0x140 .read_persistent_wall_and_boot_offset+0x24/0x80 .timekeeping_init+0x40/0x29c .start_kernel+0x674/0x8f0 start_here_common+0x1c/0x50 Unlike PAPR platforms where RTAS is only used in guests, on the IBM Cell machines Linux runs with MSR[HV] set but also uses RTAS, provided by SLOF. Fix it by copying the MSR[HV] bit from the MSR value we've just read using mfmsr into the value used for RTAS. It seems like we could also fix it using an #ifdef CELL to set MSR[HV], but that doesn't work because it's possible to build a single kernel image that runs on both Cell native and pseries. Fixes: b6b1c3ce06ca ("powerpc/rtas: Keep MSR[RI] set when calling RTAS") Cc: stable@vger.kernel.org # v5.19+ Signed-off-by: Michael Ellerman Reviewed-by: Jordan Niethe Link: https://lore.kernel.org/r/20220823115952.1203106-2-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/rtas_entry.S | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/powerpc/kernel/rtas_entry.S +++ b/arch/powerpc/kernel/rtas_entry.S @@ -109,8 +109,12 @@ __enter_rtas: * its critical regions (as specified in PAPR+ section 7.2.1). MSR[S] * is not impacted by RFI_TO_KERNEL (only urfid can unset it). So if * MSR[S] is set, it will remain when entering RTAS. + * If we're in HV mode, RTAS must also run in HV mode, so extract MSR_HV + * from the saved MSR value and insert into the value RTAS will use. */ + extrdi r0, r6, 1, 63 - MSR_HV_LG LOAD_REG_IMMEDIATE(r6, MSR_ME | MSR_RI) + insrdi r6, r0, 1, 63 - MSR_HV_LG li r0,0 mtmsrd r0,1 /* disable RI before using SRR0/1 */