From patchwork Fri Oct 14 03:07:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1689878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UU1s5OgO; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MpWbF15Mjz23jn for ; Fri, 14 Oct 2022 14:10:00 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MpWb91gWfz3bwQ for ; Fri, 14 Oct 2022 14:09:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UU1s5OgO; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::102f; helo=mail-pj1-x102f.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UU1s5OgO; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MpWXh545Fz30DP for ; Fri, 14 Oct 2022 14:07:46 +1100 (AEDT) Received: by mail-pj1-x102f.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so6682426pjg.1 for ; Thu, 13 Oct 2022 20:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VUM1eVPgnKnSlmMyivyjw988SQgffBXBeBVBEebs8w0=; b=UU1s5OgOOf/UGsJ+dgY7k4Bqt9eS7EWhGqMdgfmKlG/3D9mhgDi95fp5I0Vfu8cVol 1TMs8vXmnyG4YAMUNmlmPFgpm8U0h7133iJe/6veXHI0iASgOiffqk7QvluBr9Zda6FX s35Mvx/Fvi4Lc0GnTuzb1CK/eT3V84OrqvK00NWId21zNN4qBgSwbl9uOQvD8LLIIRBK N98cEFET9kS2fAX6QvfKlnhhK7tsC0YqGaPng4GpH/2JbH1337za+kQ8Svw2c0JJKugT BLnNiHfKd4Nc5wXdhBy/b2BFRXAGH0Lvhf3nonolI4TD/QKEDO7tcg9Wb+kY/JlRers/ UVkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VUM1eVPgnKnSlmMyivyjw988SQgffBXBeBVBEebs8w0=; b=TCA9uMfRT1tOXEiktG3mh018lSkvYvfCDtVzTEjy9W7s9Gzs/v2pWgeOyy4Vivj/TP 0I6k7VfD6I00tU5vaaZtGkgQ7KCFq1xsYI9bCm03Q5521DGOSCuELmmcVXVk1At2Qud3 JsHP6OzdTgE5+C/t/bgSmjIR5GKKGTOOXrZg/aVIfO9XyVUITgtxf531HGthSYf7Stvl 286qlzS5N7kEL1Fzjr4iWNp8UZ42AUSXEjSeuhGAxdYD+724n+3FHcqP4wOw9TdRqJ4F YK+KIDG5PS7GoMDmswBG5qoFaU+OrOEzjdZIRB/+cdDNLSOu+PFSn0XdCvpsthSmvbmq 7HaA== X-Gm-Message-State: ACrzQf0B+ngSTEkqHmBSNFPuarhRFYizgpOuEhC9kWB94p17IyR/VQQx jjZKgTafvksIiO+46P+vpwer9zthSPY= X-Google-Smtp-Source: AMsMyM4qdx0RchWaAQWQ2s7FKUF8yBmE/xrmAfnSITZMOfJqtfO3+U3ByWfc+2HYzkRfROX3hh9vMg== X-Received: by 2002:a17:903:20d3:b0:17c:8197:c4db with SMTP id i19-20020a17090320d300b0017c8197c4dbmr2842744plb.43.1665716862288; Thu, 13 Oct 2022 20:07:42 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([1.146.77.96]) by smtp.gmail.com with ESMTPSA id ij4-20020a170902ab4400b0017f8edd3d8asm523443plb.177.2022.10.13.20.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 20:07:41 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support context tracking Date: Fri, 14 Oct 2022 13:07:28 +1000 Message-Id: <20221014030729.2077151-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221014030729.2077151-1-npiggin@gmail.com> References: <20221014030729.2077151-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The context tracking code in PR-KVM and BookE implementations is not complete, and can cause host crashes if context tracking is enabled. Make these implementations depend on !CONTEXT_TRACKING_USER. Signed-off-by: Nicholas Piggin --- arch/powerpc/kvm/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig index 61cdd782d3c5..a9f57dad6d91 100644 --- a/arch/powerpc/kvm/Kconfig +++ b/arch/powerpc/kvm/Kconfig @@ -51,6 +51,7 @@ config KVM_BOOK3S_HV_POSSIBLE config KVM_BOOK3S_32 tristate "KVM support for PowerPC book3s_32 processors" depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT + depends on !CONTEXT_TRACKING_USER select KVM select KVM_BOOK3S_32_HANDLER select KVM_BOOK3S_PR_POSSIBLE @@ -105,6 +106,7 @@ config KVM_BOOK3S_64_HV config KVM_BOOK3S_64_PR tristate "KVM support without using hypervisor mode in host" depends on KVM_BOOK3S_64 + depends on !CONTEXT_TRACKING_USER select KVM_BOOK3S_PR_POSSIBLE help Support running guest kernels in virtual machines on processors @@ -190,6 +192,7 @@ config KVM_EXIT_TIMING config KVM_E500V2 bool "KVM support for PowerPC E500v2 processors" depends on PPC_E500 && !PPC_E500MC + depends on !CONTEXT_TRACKING_USER select KVM select KVM_MMIO select MMU_NOTIFIER @@ -205,6 +208,7 @@ config KVM_E500V2 config KVM_E500MC bool "KVM support for PowerPC E500MC/E5500/E6500 processors" depends on PPC_E500MC + depends on !CONTEXT_TRACKING_USER select KVM select KVM_MMIO select KVM_BOOKE_HV From patchwork Fri Oct 14 03:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1689875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j/614PaH; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MpWY95Bk2z23jn for ; Fri, 14 Oct 2022 14:08:12 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MpWY73XLtz3c2L for ; Fri, 14 Oct 2022 14:08:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j/614PaH; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::635; helo=mail-pl1-x635.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j/614PaH; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MpWXh6QC2z3bj8 for ; Fri, 14 Oct 2022 14:07:48 +1100 (AEDT) Received: by mail-pl1-x635.google.com with SMTP id c24so3576527plo.3 for ; Thu, 13 Oct 2022 20:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+Py/OynLN1dc8/m6hIl6sKvHR1UkBmJQ1rYnYYoA5U=; b=j/614PaHkXRd3CET+x2nqVS9ejGjQy8Gc2cbJtaW+7hZJAwpRZH53tcFxwyaYS359X WD7hOm8MplhAYJAZ6Vfi7K9a8R8oWF8L+kLgG+BPkXTtf8hBw6JMVGTxp1p6f2n/uo1g LGdqAoPOlzkAeSTmTIngn81jxngB/EFNHx2qIpC92peZkqjmy/jK+Ti2NZAovbj4XAVT jFUDUC6gNvB97cOvYSmLM3dTYd3GBYnxSfCdboe7TEyDy/b9+Hz+Y10Qz+C9JRjRbnZu Xum7IRROXu/s2ub3w4moU/6N2c9QtzJ1ReuciNxKcx8TvpuNLTGduo6BI3x/h1lHHly5 WlJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m+Py/OynLN1dc8/m6hIl6sKvHR1UkBmJQ1rYnYYoA5U=; b=s0DOCGynEbdWizKOf+0M7dgxA1gSczGQEvOZ1c+qipGgvws1heh/rDQwEYT7ciY1GK M+hlktMnlZASaxsIMoN98IQZt6EMiDG8gwkSPB6zEgCO6WpsUD8qE/UdaMOKsLjBjG7d v/hdqjwG98HtssNDjtTwYPu9nVEnLN5d+WhmM11KtB2Hhn6PZ1MWXgDnnGh2NJ3T6uwD LHAAM/BM2FKmRTEAQKJQIP1Axz/40p0s2G+85ws6YXqeqb14e5iigPyUGGF0OzeWwLH5 xYnqJZMVFfClYtBo4eGwYYlr01SdE0Xt2RONT66Hd7zoM6VnwqB86XVRTVVaxotABPY0 4lqA== X-Gm-Message-State: ACrzQf3Q8HKCFAb/BLi/j13BiD4xJHtcNMMXxAo1yL+t3E+SEsluOP4f Mn38LNHg49nrN7n/7JSTMghrtubhnyc= X-Google-Smtp-Source: AMsMyM6GHplyGin/d1ZaoRUEiASfYqmtXAJkCSAxlw/0oCKBWPN9VJhR+uVTRw9EHAwdTviR85Af1g== X-Received: by 2002:a17:903:1105:b0:178:ae31:aad with SMTP id n5-20020a170903110500b00178ae310aadmr3068687plh.3.1665716866263; Thu, 13 Oct 2022 20:07:46 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([1.146.77.96]) by smtp.gmail.com with ESMTPSA id ij4-20020a170902ab4400b0017f8edd3d8asm523443plb.177.2022.10.13.20.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 20:07:45 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning Date: Fri, 14 Oct 2022 13:07:29 +1000 Message-Id: <20221014030729.2077151-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221014030729.2077151-1-npiggin@gmail.com> References: <20221014030729.2077151-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" NMI PMIs really should not return using the normal interrupt_return function. If such a PMI hits in code returning to user with the context switched to user mode, this warning can fire. This was enough to cause crashes when reproducing on 64s, because another perf interrupt would hit while reporting bug, and that would cause another bug, and so on until smashing the stack. Work around that particular crash for now by just disabling that context warning for PMIs. This is a hack and not a complete fix, there could be other such problems lurking in corners. But it does fix the known crash. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/exceptions-64e.S | 7 +++++++ arch/powerpc/kernel/exceptions-64s.S | 7 +++++++ arch/powerpc/kernel/interrupt.c | 12 +++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S index 930e36099015..2f68fb2ee4fc 100644 --- a/arch/powerpc/kernel/exceptions-64e.S +++ b/arch/powerpc/kernel/exceptions-64e.S @@ -813,6 +813,13 @@ kernel_dbg_exc: EXCEPTION_COMMON(0x260) CHECK_NAPPING() addi r3,r1,STACK_FRAME_OVERHEAD + /* + * XXX: Returning from performance_monitor_exception taken as a + * soft-NMI (Linux irqs disabled) may be risky to use interrupt_return + * and could cause bugs in return or elsewhere. That case should just + * restore registers and return. There is a workaround for one known + * problem in interrupt_exit_kernel_prepare(). + */ bl performance_monitor_exception b interrupt_return diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 5381a43e50fe..7ca55ac7bb87 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -2357,6 +2357,13 @@ EXC_VIRT_END(performance_monitor, 0x4f00, 0x20) EXC_COMMON_BEGIN(performance_monitor_common) GEN_COMMON performance_monitor addi r3,r1,STACK_FRAME_OVERHEAD + /* + * XXX: Returning from performance_monitor_exception taken as a + * soft-NMI (Linux irqs disabled) may be risky to use interrupt_return + * and could cause bugs in return or elsewhere. That case should just + * restore registers and return. There is a workaround for one known + * problem in interrupt_exit_kernel_prepare(). + */ bl performance_monitor_exception b interrupt_return_srr diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c index f9db0a172401..7bc93367de68 100644 --- a/arch/powerpc/kernel/interrupt.c +++ b/arch/powerpc/kernel/interrupt.c @@ -374,10 +374,16 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs) if (regs_is_unrecoverable(regs)) unrecoverable_exception(regs); /* - * CT_WARN_ON comes here via program_check_exception, - * so avoid recursion. + * CT_WARN_ON comes here via program_check_exception, so avoid + * recursion. + * + * Skip the assertion on PMIs to work around a problem caused by NMI + * PMIs incorrectly taking this interrupt return path, it's possible + * for this to hit after interrupt exit to user switches context to + * user. See also the comment in the performance monitor handler in + * exceptions-64e/s.S */ - if (TRAP(regs) != INTERRUPT_PROGRAM) + if (TRAP(regs) != INTERRUPT_PROGRAM && TRAP(regs) != INTERRUPT_PERFMON) CT_WARN_ON(ct_state() == CONTEXT_USER); kuap = kuap_get_and_assert_locked();