From patchwork Thu Sep 15 12:10:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678263 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=112.213.38.117; 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=EbDVDyck; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4MSx0C4qCKz1ypd for ; Thu, 15 Sep 2022 22:12:11 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx0875TZz3bc8 for ; Thu, 15 Sep 2022 22:12:08 +1000 (AEST) 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=EbDVDyck; 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::434; helo=mail-pf1-x434.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=EbDVDyck; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 4MSwzG3w1Zz3bYM for ; Thu, 15 Sep 2022 22:11:22 +1000 (AEST) Received: by mail-pf1-x434.google.com with SMTP id b23so17834941pfp.9 for ; Thu, 15 Sep 2022 05:11:22 -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; bh=LPFHi8omvCILxLZbqdRE+ytSu8T6h3A1h/9IS2BZUI4=; b=EbDVDyckJxpjUq8l5cxdnXLZHnPQlOPjcT6sioaMtQ4UHOfj3iIw7nWXbiJkLYMj12 I//OqqUlmeSfuZap68jVENFSKcaxgjLam6cGirnkwK6UMnkoh4QfjJ6ROntvGmooxvbl iqqC7wnHNBYtDWvmoNbpJ7VMvewKiFODzCdYOChPa7vQZa3IZeb/oyKvsmNeSfeq5K6h j66wKzuPWxoOUKO3/MaIIqplOOzN1XIBEnvPfSFc7e8GVxlewDyeWAaCEvAOgdwWZU1n 9RrH2FiNAp17FClDsEXxRK1cNqCQnSQ9xglSVjXvPV1GFLsdkNsMn5boKnCxINdzBdAE qDjg== 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; bh=LPFHi8omvCILxLZbqdRE+ytSu8T6h3A1h/9IS2BZUI4=; b=XinbMjgaaehmrXRc80nI3FFVN7+NFXgdbg1UwSo7Gckxe8gl7WLxfT3QkxGjHIkN3W bXtMxuvXTO85SgM6LN6DROvOT7Q0MNeXL1hHQ86VO3Grwd9ks/xe3Xv1uDUdrPfrYTgL ufOTrZEAIbA8lqzxwPtUTHMeEDHzZu0Xk210lq3axuRNX+BcNiY3n7XvuDsc/PqdJ/eA fthOboVLB55+JuTIaf0QZwUUu6GdEBB/R90WYTO36wOzsGifVhdaq2SSCPoAwVyUNEJU 7M7XvH0QL+dR3RMjwUV1vgzZ1epafNpK3hgxMjRMvVvZgEOVNhYrLZX3qzVOoaJoI53j w/dw== X-Gm-Message-State: ACgBeo3QpQJQxTOcSVKxxPqwIwa7YoJqhw3LEO7bsdhVBOLR4uBTeKw5 tm6A/yfXg4OL2I/3AYwxTIlz/iZhiIE= X-Google-Smtp-Source: AA6agR5/srRa3CfhuSTzvDWRQjrituKKQZw72FILYJOjd+yKkAQIGVplrroQl5bozMDfKa8dAoM7kg== X-Received: by 2002:a05:6a00:b49:b0:545:8bf9:be6e with SMTP id p9-20020a056a000b4900b005458bf9be6emr15059171pfo.2.1663243879138; Thu, 15 Sep 2022 05:11:19 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:18 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/6] powerpc/64: mark irqs hard disabled in boot paca Date: Thu, 15 Sep 2022 22:10:53 +1000 Message-Id: <20220915121058.2288916-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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" This prevents interrupts in early boot (e.g., program check) from enabling MSR[EE], potentially causing endian mismatch or other crashes when reporting early boot traps. Fixes: 4423eb5ae32ec ("powerpc/64/interrupt: make normal synchronous interrupts enable MSR[EE] if possible") Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/setup_64.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 2b2d0b0fbb30..ce8fc6575eaa 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -182,8 +182,10 @@ static void __init fixup_boot_paca(void) get_paca()->cpu_start = 1; /* Allow percpu accesses to work until we setup percpu data */ get_paca()->data_offset = 0; - /* Mark interrupts disabled in PACA */ + /* Mark interrupts soft and hard disabled in PACA */ irq_soft_mask_set(IRQS_DISABLED); + get_paca()->irq_happened = PACA_IRQ_HARD_DIS; + WARN_ON(mfmsr() & MSR_EE); } static void __init configure_exceptions(void) From patchwork Thu Sep 15 12:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678265 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=e1wb1UpZ; 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 4MSx0q4cWMz1ypd for ; Thu, 15 Sep 2022 22:12:43 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx0q1bJpz3bpr for ; Thu, 15 Sep 2022 22:12:43 +1000 (AEST) 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=e1wb1UpZ; 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::429; helo=mail-pf1-x429.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=e1wb1UpZ; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (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 4MSwzJ2HMRz3bYM for ; Thu, 15 Sep 2022 22:11:24 +1000 (AEST) Received: by mail-pf1-x429.google.com with SMTP id 9so6753306pfz.12 for ; Thu, 15 Sep 2022 05:11:24 -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; bh=YteFL4oJUuvI+wsGC7pTGdQWykUALjUg2ga9NHdLMy4=; b=e1wb1UpZMFMRi33js/MulDrjzh3PauQwJ13PFFhvPqZSAMyDOsLOqsR+JIHZWB2Vwr vk3umJftmCfL49DkpQ12TTsUC412xNen+CEkHWc/zlAIVBezNnUEtjXWC1Rad9oD8+gj 4x6me5o58d7p1f+O0Iv39IP9jzNVJhAXvqXIcZGznPum8mp8/qBuViK+LxA5bWY/sT1T z4IqsnhPXi/YN/0p6/Ut0MyimOZs50V72tR5zXidrFCrm5yNJtq1RupAbubS4qRUqvcD N/gG5UWWBBmi4Hvg3H9R0cwfvjEnDzWTW0gcXBPNlvfTV957ZtFmj2M7o8k6cxO+WKdz J3EQ== 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; bh=YteFL4oJUuvI+wsGC7pTGdQWykUALjUg2ga9NHdLMy4=; b=zmDmF9eSlYhAgcYkv+LWzrVcKCZteUQLuQh8mpuemk/fgPS3p8iv79+1dHP6COfQpn ZMeWNI06Al5RtILVy1TqKs5W8oDGbzgrR0UCozF+JMj8OpcQu6JtDldBAgI4qQD9QWDw fo/2LgHomBRX6oYKhz5TwBO6aDUZg3SLqvOhO0W1xBcD2pKJnEJi7p/DcEkt1Vo0Xneu CGwPFcPsfj+AuQvARaTt+PehIj+3y935CKbDrP2QMkV3A3DpA9f7/Uz0+cyq5XdyxOib sYffPKnPdAj8VjVcf9waB7updnW243oFWbsgbi3ch+q/He6BPivvVYXbYiioKR2SoabS aQjA== X-Gm-Message-State: ACrzQf3JzxwxTr+UAoLYLAdyZNA4o1uy8I/+3t8IqR6xGRZxMgEThBSm FtFUpM5Bd33h0PjoG0nUAlyxIsxZAww= X-Google-Smtp-Source: AMsMyM6YrCovE9c9H1iE613cHx/MsUznUYZqi82CiqooVZrFMlIcJVOJlrrLLieLaSxU6fVBu6c+Dw== X-Received: by 2002:a63:6d44:0:b0:439:a999:e8ac with SMTP id i65-20020a636d44000000b00439a999e8acmr817655pgc.548.1663243881649; Thu, 15 Sep 2022 05:11:21 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:21 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/6] powerpc/64s/interrupt: move early boot ILE fixup into a macro Date: Thu, 15 Sep 2022 22:10:54 +1000 Message-Id: <20220915121058.2288916-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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" In preparation for using this sequence in machine check interrupt, move it into a macro, with a small change to make it position independent. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/exceptions-64s.S | 101 +++++++++++++++------------ 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index d98732a33afe..d629bcd7213b 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -702,6 +702,61 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR) ld r1,GPR1(r1) .endm +/* + * EARLY_BOOT_FIXUP - Fix real-mode interrupt with wrong endian in early boot. + * + * There's a short window during boot where although the kernel is running + * little endian, any exceptions will cause the CPU to switch back to big + * endian. For example a WARN() boils down to a trap instruction, which will + * cause a program check, and we end up here but with the CPU in big endian + * mode. The first instruction of the program check handler (in GEN_INT_ENTRY + * below) is an mtsprg, which when executed in the wrong endian is an lhzu with + * a ~3GB displacement from r3. The content of r3 is random, so that is a load + * from some random location, and depending on the system can easily lead to a + * checkstop, or an infinitely recursive page fault. + * + * So to handle that case we have a trampoline here that can detect we are in + * the wrong endian and flip us back to the correct endian. We can't flip + * MSR[LE] using mtmsr, so we have to use rfid. That requires backing up SRR0/1 + * as well as a GPR. To do that we use SPRG0/2/3, as SPRG1 is already used for + * the paca. SPRG3 is user readable, but this trampoline is only active very + * early in boot, and SPRG3 will be reinitialised in vdso_getcpu_init() before + * userspace starts. + */ +.macro EARLY_BOOT_FIXUP +#ifdef CONFIG_CPU_LITTLE_ENDIAN +BEGIN_FTR_SECTION + tdi 0,0,0x48 // Trap never, or in reverse endian: b . + 8 + b 2f // Skip trampoline if endian is correct + .long 0xa643707d // mtsprg 0, r11 Backup r11 + .long 0xa6027a7d // mfsrr0 r11 + .long 0xa643727d // mtsprg 2, r11 Backup SRR0 in SPRG2 + .long 0xa6027b7d // mfsrr1 r11 + .long 0xa643737d // mtsprg 3, r11 Backup SRR1 in SPRG3 + .long 0xa600607d // mfmsr r11 + .long 0x01006b69 // xori r11, r11, 1 Invert MSR[LE] + .long 0xa6037b7d // mtsrr1 r11 + .long 0x34026039 // li r11, 0x234 + /* + * This is 'li r11,1f' where 1f is the absolute address of that + * label, byteswapped into the SI field of the instruction. + */ + .long 0x00006039 | \ + ((ABS_ADDR(1f, real_vectors) & 0x00ff) << 24) | \ + ((ABS_ADDR(1f, real_vectors) & 0xff00) << 8) + .long 0xa6037a7d // mtsrr0 r11 + .long 0x2400004c // rfid +1: + mfsprg r11, 3 + mtsrr1 r11 // Restore SRR1 + mfsprg r11, 2 + mtsrr0 r11 // Restore SRR0 + mfsprg r11, 0 // Restore r11 +2: +END_FTR_SECTION(0, 1) // nop out after boot +#endif +.endm + /* * There are a few constraints to be concerned with. * - Real mode exceptions code/data must be located at their physical location. @@ -1619,51 +1674,7 @@ INT_DEFINE_BEGIN(program_check) INT_DEFINE_END(program_check) EXC_REAL_BEGIN(program_check, 0x700, 0x100) - -#ifdef CONFIG_CPU_LITTLE_ENDIAN - /* - * There's a short window during boot where although the kernel is - * running little endian, any exceptions will cause the CPU to switch - * back to big endian. For example a WARN() boils down to a trap - * instruction, which will cause a program check, and we end up here but - * with the CPU in big endian mode. The first instruction of the program - * check handler (in GEN_INT_ENTRY below) is an mtsprg, which when - * executed in the wrong endian is an lhzu with a ~3GB displacement from - * r3. The content of r3 is random, so that is a load from some random - * location, and depending on the system can easily lead to a checkstop, - * or an infinitely recursive page fault. - * - * So to handle that case we have a trampoline here that can detect we - * are in the wrong endian and flip us back to the correct endian. We - * can't flip MSR[LE] using mtmsr, so we have to use rfid. That requires - * backing up SRR0/1 as well as a GPR. To do that we use SPRG0/2/3, as - * SPRG1 is already used for the paca. SPRG3 is user readable, but this - * trampoline is only active very early in boot, and SPRG3 will be - * reinitialised in vdso_getcpu_init() before userspace starts. - */ -BEGIN_FTR_SECTION - tdi 0,0,0x48 // Trap never, or in reverse endian: b . + 8 - b 1f // Skip trampoline if endian is correct - .long 0xa643707d // mtsprg 0, r11 Backup r11 - .long 0xa6027a7d // mfsrr0 r11 - .long 0xa643727d // mtsprg 2, r11 Backup SRR0 in SPRG2 - .long 0xa6027b7d // mfsrr1 r11 - .long 0xa643737d // mtsprg 3, r11 Backup SRR1 in SPRG3 - .long 0xa600607d // mfmsr r11 - .long 0x01006b69 // xori r11, r11, 1 Invert MSR[LE] - .long 0xa6037b7d // mtsrr1 r11 - .long 0x34076039 // li r11, 0x734 - .long 0xa6037a7d // mtsrr0 r11 - .long 0x2400004c // rfid - mfsprg r11, 3 - mtsrr1 r11 // Restore SRR1 - mfsprg r11, 2 - mtsrr0 r11 // Restore SRR0 - mfsprg r11, 0 // Restore r11 -1: -END_FTR_SECTION(0, 1) // nop out after boot -#endif /* CONFIG_CPU_LITTLE_ENDIAN */ - + EARLY_BOOT_FIXUP GEN_INT_ENTRY program_check, virt=0 EXC_REAL_END(program_check, 0x700, 0x100) EXC_VIRT_BEGIN(program_check, 0x4700, 0x100) From patchwork Thu Sep 15 12:10:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678266 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=oN+jjaqW; 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 4MSx1V5YVHz1ypd for ; Thu, 15 Sep 2022 22:13:18 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx1V4ycsz3dqL for ; Thu, 15 Sep 2022 22:13:18 +1000 (AEST) 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=oN+jjaqW; 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::431; helo=mail-pf1-x431.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=oN+jjaqW; dkim-atps=neutral Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 4MSwzL4Svwz3bYM for ; Thu, 15 Sep 2022 22:11:26 +1000 (AEST) Received: by mail-pf1-x431.google.com with SMTP id w2so7574874pfb.0 for ; Thu, 15 Sep 2022 05:11:26 -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; bh=dI1XApg9D4NdasnJjUXIpQn6zBeMw3mea5f7GCONCKQ=; b=oN+jjaqW1qGSO2jmV5ePEyoaQMqBZpsQ8LJGkoJxsKu4AdUE0Xuy8k0eQCxpV9eYgQ nJ9loigRt/jzhFYxATqKuADWTcwSBtNlIdR5f7lueV7R+O0eGDxqci+vk/frTdteXnMV K4zfV3W6Nu48QbFsDSrrdUtMnV3LaolpkPNLEhw0KaXC3oj9/u9K6OvT5kd5q1CjGVNz xo0pJIRjQWIV7E+vzYIV1tsOjkWNX5o7bRLuA9M944tCiTUxXKXp9fYw3R4W1K8SQeFr YQIiJAnPqOzr1u3+u8Cd1wurJFy4PXXbmv8NQjRjDyzVY44DKJ3uP/P1yiSAzXwEMJtC UVwA== 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; bh=dI1XApg9D4NdasnJjUXIpQn6zBeMw3mea5f7GCONCKQ=; b=EgSmu7MzqmkWCY/6xmMn/DHLzxJdmhSMPRuwvPgFXq8d76DJez8T2AVkuKz7FLOSyd wU1Jv97ioN3rwkppG26VLeuZKRPIhrOrcAK+w0ODwPElhT3HqNFPMzHe1zf/SG7XKUHi B2zIyyFHXlwjHWHGwRi0Kffe9CaMB6SP/IdirIcnu02snDLOhMQ21sI7YYM02USGiIa9 QM5pALv6QEQwVTQ2kFnM2t51jhf7iUfx0tiZxoPq4ZLhmpS/ZNGqoLxbMUslkO+nqBg/ OEeh8Wk2HeVqsx8g5d7UVcS7fqIQ4+9cPry7M5Q1MrUlq5qpn09p34iTuLgui1yfxg5O ea+A== X-Gm-Message-State: ACgBeo3eX2XTN/YfBDlz034Wn/w7fQ+yYKOt1kti77/c08y8VFnFpYPl 0rmq79lRp+Af/dTEElBAJRcNiVNk0UU= X-Google-Smtp-Source: AA6agR5GFHEbT3z4DNyis1GoaeJ3oEdZ7wV5PvlJJ+hMygPf0LGqlUxKGXrQSn9NDTPkp7dL2FLcUQ== X-Received: by 2002:a63:e25:0:b0:41c:30f7:c39c with SMTP id d37-20020a630e25000000b0041c30f7c39cmr35686323pgl.147.1663243884092; Thu, 15 Sep 2022 05:11:24 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:23 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 3/6] powerpc/64s: early boot machine check handler Date: Thu, 15 Sep 2022 22:10:55 +1000 Message-Id: <20220915121058.2288916-4-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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" Use the early boot interrupt fixup in the machine check handler to allow the machine check handler to run before interrupt endian is set up. Branch to an early boot handler that just does a basic crash, which allows it to run before ppc_md is set up. MSR[ME] is enabled on the boot CPU earlier, and the machine check stack is temporarily set to the middle of the init task stack. This allows machine checks (e.g., due to invalid data access in real mode) to print something useful earlier in boot (as soon as udbg is set up, if CONFIG_PPC_EARLY_DEBUG=y). Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/asm-prototypes.h | 1 + arch/powerpc/kernel/exceptions-64s.S | 6 +++++- arch/powerpc/kernel/setup_64.c | 12 ++++++++++++ arch/powerpc/kernel/traps.c | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/asm-prototypes.h b/arch/powerpc/include/asm/asm-prototypes.h index 81631e64dbeb..a1039b9da42e 100644 --- a/arch/powerpc/include/asm/asm-prototypes.h +++ b/arch/powerpc/include/asm/asm-prototypes.h @@ -36,6 +36,7 @@ int64_t __opal_call(int64_t a0, int64_t a1, int64_t a2, int64_t a3, int64_t opcode, uint64_t msr); /* misc runtime */ +void enable_machine_check(void); extern u64 __bswapdi2(u64); extern s64 __lshrdi3(s64, int); extern s64 __ashldi3(s64, int); diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index d629bcd7213b..29d701a20c41 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -1134,6 +1134,7 @@ INT_DEFINE_BEGIN(machine_check) INT_DEFINE_END(machine_check) EXC_REAL_BEGIN(machine_check, 0x200, 0x100) + EARLY_BOOT_FIXUP GEN_INT_ENTRY machine_check_early, virt=0 EXC_REAL_END(machine_check, 0x200, 0x100) EXC_VIRT_NONE(0x4200, 0x100) @@ -1198,6 +1199,9 @@ BEGIN_FTR_SECTION bl enable_machine_check END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) addi r3,r1,STACK_FRAME_OVERHEAD +BEGIN_FTR_SECTION + bl machine_check_early_boot +END_FTR_SECTION(0, 1) // nop out after boot bl machine_check_early std r3,RESULT(r1) /* Save result */ ld r12,_MSR(r1) @@ -3098,7 +3102,7 @@ CLOSE_FIXED_SECTION(virt_trampolines); USE_TEXT_SECTION() /* MSR[RI] should be clear because this uses SRR[01] */ -enable_machine_check: +_GLOBAL(enable_machine_check) mflr r0 bcl 20,31,$+4 0: mflr r3 diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index ce8fc6575eaa..08173eea8977 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -180,6 +181,14 @@ static void __init fixup_boot_paca(void) { /* The boot cpu is started */ get_paca()->cpu_start = 1; + /* + * Give the early boot machine check stack somewhere to use, use + * half of the init stack. This is a bit hacky but there should not be + * deep stack usage in early init so shouldn't overflow it or overwrite + * things. + */ + get_paca()->mc_emergency_sp = (void *)&init_thread_union + + (THREAD_SIZE/2); /* Allow percpu accesses to work until we setup percpu data */ get_paca()->data_offset = 0; /* Mark interrupts soft and hard disabled in PACA */ @@ -357,6 +366,9 @@ void __init early_setup(unsigned long dt_ptr) /* -------- printk is now safe to use ------- */ + if (mfmsr() & MSR_HV) + enable_machine_check(); + /* Try new device tree based feature discovery ... */ if (!dt_cpu_ftrs_init(__va(dt_ptr))) /* Otherwise use the old style CPU table */ diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index dadfcef5d6db..37f8375452ad 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -68,6 +68,7 @@ #include #include #include +#include #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE) int (*__debugger)(struct pt_regs *regs) __read_mostly; @@ -850,6 +851,19 @@ static void __machine_check_exception(struct pt_regs *regs) } #ifdef CONFIG_PPC_BOOK3S_64 +DEFINE_INTERRUPT_HANDLER_RAW(machine_check_early_boot) +{ + udbg_printf("Machine check (early boot)\n"); + udbg_printf("SRR0=0x%016lx SRR1=0x%016lx\n", regs->nip, regs->msr); + udbg_printf(" DAR=0x%016lx DSISR=0x%08lx\n", regs->dar, regs->dsisr); + udbg_printf(" LR=0x%016lx R1=0x%08lx\n", regs->link, regs->gpr[1]); + udbg_printf("------\n"); + die("Machine check (early boot)", regs, SIGBUS); + for (;;) + ; + return 0; +} + DEFINE_INTERRUPT_HANDLER_ASYNC(machine_check_exception_async) { __machine_check_exception(regs); From patchwork Thu Sep 15 12:10:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678267 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=dCPzgOnE; 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 4MSx2B4yjbz1ypd for ; Thu, 15 Sep 2022 22:13:54 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx2B2nTMz3dwJ for ; Thu, 15 Sep 2022 22:13:54 +1000 (AEST) 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=dCPzgOnE; 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::1029; helo=mail-pj1-x1029.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=dCPzgOnE; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 4MSwzQ0gWhz3blY for ; Thu, 15 Sep 2022 22:11:29 +1000 (AEST) Received: by mail-pj1-x1029.google.com with SMTP id s14-20020a17090a6e4e00b0020057c70943so22174195pjm.1 for ; Thu, 15 Sep 2022 05:11:29 -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; bh=Bn0T7dQKNFXGgG78X/o6CPzfYUz1SqFWsqHr1/u9ZNw=; b=dCPzgOnEkOD5R0hEstwZ/ptyU93RI/BtzdkPEi1dfMiUuzXlyoEebb+YexTlrh3uql PVGe5z2Uc+z76BmB1MMq1B0WYm2xvgpN4g/RmN3+w+n854OMUNvqDXpjmsRuWYhhmuZ2 Akqd4gpCPwi8VR7Yd4e9prpUafkIh2Jx6d5nMA54SYcB+nIKeC8Gl3btTlXpiZHEMHuL IKGjzcl2cvWAP4zA68//NeLGU3zdSUWQwt8s2COBIOLV6q4fOQTEYeTfzxlcw1VpVPG6 hRamBrA/r0IUZgQ+J1yVPzTEY9UHND1rbQdwdFuDwRh3NXv3m9EbjYlm84JYVd8T4uDR 0LWg== 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; bh=Bn0T7dQKNFXGgG78X/o6CPzfYUz1SqFWsqHr1/u9ZNw=; b=rc8b8qlRinLKnbTIbUQoyMJF2KaJGktTS28P2lKBq3R+IE4QAlCUmfdlYb7Qix4yzd tbHXfbVBfGSVJQleW/UaGU+zyJVeKDHvx1ccBXGPlcoQNs5HAMK9aBMOc14Aj90DFLJT aYIX875rbyB04Ti2UHvYwcwsoMNIbO5v/ZL1DqaW9dRnQvzXwJYo324AIumiKHTVKPqn 1kVv4RYREvFGHJIWlSWB8S5R6XPxHkFieZWQD/TAIGDODt5vey4fIfgOnBMFrYnq8R3Y aoqjcpkQ4v2kuuOLjADhwfsK5b8EtwU1hOMmB/KEGDTecFnY3ePwO+Hp/9xtdQvWmnhB eouQ== X-Gm-Message-State: ACrzQf0iuKjTr/kFNDfIDfeTESsj+jy0wKJg3L2nxJ0TYepL0lLpEN8/ JNH3E45PZ76EksZbseXLZK6koG/rkao= X-Google-Smtp-Source: AMsMyM79ZWO467nLLkMT1RzjilED250EBoPp5Jq93D+mfjPB7Gcg6b0WuFH10eRiWT6f1FORNeSwvw== X-Received: by 2002:a17:902:db06:b0:178:24e7:639 with SMTP id m6-20020a170902db0600b0017824e70639mr4149649plx.46.1663243886982; Thu, 15 Sep 2022 05:11:26 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:26 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 4/6] powerpc/64: avoid using r13 in relocate Date: Thu, 15 Sep 2022 22:10:56 +1000 Message-Id: <20220915121058.2288916-5-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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" relocate() uses r13 in early boot before it is used for the paca. Use a different register for this so r13 is kept unchanged until it is set to the paca pointer. Avoid r14 as well while we're here, there's no reason not to use the volatile registers which is a bit less surprising, and r14 could be used as another fixed reg one day. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/reloc_64.S | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S index 232e4549defe..efd52f2e7033 100644 --- a/arch/powerpc/kernel/reloc_64.S +++ b/arch/powerpc/kernel/reloc_64.S @@ -27,8 +27,8 @@ _GLOBAL(relocate) add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */ ld r10,(p_st - 0b)(r12) add r10,r10,r12 /* r10 has runtime addr of _stext */ - ld r13,(p_sym - 0b)(r12) - add r13,r13,r12 /* r13 has runtime addr of .dynsym */ + ld r4,(p_sym - 0b)(r12) + add r4,r4,r12 /* r4 has runtime addr of .dynsym */ /* * Scan the dynamic section for the RELA, RELASZ and RELAENT entries. @@ -84,16 +84,16 @@ _GLOBAL(relocate) ld r0,16(r9) /* reloc->r_addend */ b .Lstore .Luaddr64: - srdi r14,r0,32 /* ELF64_R_SYM(reloc->r_info) */ + srdi r5,r0,32 /* ELF64_R_SYM(reloc->r_info) */ clrldi r0,r0,32 cmpdi r0,R_PPC64_UADDR64 bne .Lnext ld r6,0(r9) ld r0,16(r9) - mulli r14,r14,24 /* 24 == sizeof(elf64_sym) */ - add r14,r14,r13 /* elf64_sym[ELF64_R_SYM] */ - ld r14,8(r14) - add r0,r0,r14 + mulli r5,r5,24 /* 24 == sizeof(elf64_sym) */ + add r5,r5,r4 /* elf64_sym[ELF64_R_SYM] */ + ld r5,8(r5) + add r0,r0,r5 .Lstore: add r0,r0,r3 stdx r0,r7,r6 From patchwork Thu Sep 15 12:10:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678268 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=112.213.38.117; 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=g00LEzV4; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4MSx2s5zmVz1ypd for ; Thu, 15 Sep 2022 22:14:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx2s5SxQz3cdk for ; Thu, 15 Sep 2022 22:14:29 +1000 (AEST) 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=g00LEzV4; 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::636; helo=mail-pl1-x636.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=g00LEzV4; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 4MSwzS12xcz3brd for ; Thu, 15 Sep 2022 22:11:31 +1000 (AEST) Received: by mail-pl1-x636.google.com with SMTP id x1so18149696plv.5 for ; Thu, 15 Sep 2022 05:11:31 -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; bh=U5dstr6s1X7aN6wvLVSL3cQ3bYUMLDEq54B0w+D32uE=; b=g00LEzV4lD7HdZzg6Cu7sNccxi/MOLhR6oXpDWKXJtCQgtSOOHcQ1yPZsw+s7CkDCs vU19AktDani9W6aGz1qjnc/lw6R1uFuI8YhOZHHjo8+A9on8mzKfeWBRcGyEVyhx+jvS EruOXe5h5CC2DJd7XDu+Kj4LTRjuYrJOgzulsDuPoRCsuMLVkuF3yKzjbM09B/PMqZg3 u/eZ5bn0Pkrk/i0Eo+a5djvSArxdlboU5t2OAj+lSRayy+/wWeMVdgUqxfO/qHCj4xr3 u51w5QGmwoSB2tuHIdW8oYQgMz0KqO9R4LBVM9GbIYMepLx12DWD8QEt8pzOrs+ERT6d UptQ== 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; bh=U5dstr6s1X7aN6wvLVSL3cQ3bYUMLDEq54B0w+D32uE=; b=cgqBsjiD/xr0f1oTcUUrOoZei+tyHInPWuGPV8KopVhOYQIuL/AkZBzDh9JlQDrWUe gGj2sxGhMz4qv09Z3hpohMYiF0m9CaqnGHUI+t3DijDRNc4QJVu+bDSRZ+2IryeSNocw mYvc+YjxXY4M2IP2DiGW/kaN0m+uia8E74ucAB8v+2onB49WPnQi7VjcPW3BPGeTcmrm GB6xVOzDVq+J+YMRF0KtO3EgT7O7xt9KJxc0jdtUmSu3q3lhmJoFiKfpt1kvP4CM3ls2 qctyU/aTDxt0pVU7T0+TwSo5YG2FXDBP7SAYaXRaIZruj5MvBbjfHmdAeFLEQVBfvMns p1AQ== X-Gm-Message-State: ACrzQf3xutFKxT9I2FaSMIXS+OAwceYydmKRRKhtvexcdtZkS/wE0JvS Xj4DvBiB3WdD29rMWS6S69iZavvZVKs= X-Google-Smtp-Source: AMsMyM5HTIM6jKvW00jTUakoK+hfBuZHn5ylrmwt05UZhUjvcopK5hWc8nIjvtP/vEAGPwKteZaodg== X-Received: by 2002:a17:902:e74f:b0:176:e68f:f902 with SMTP id p15-20020a170902e74f00b00176e68ff902mr4071508plf.41.1663243889446; Thu, 15 Sep 2022 05:11:29 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:28 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 5/6] powerpc/64: don't set boot CPU's r13 to paca until the structure is set up Date: Thu, 15 Sep 2022 22:10:57 +1000 Message-Id: <20220915121058.2288916-6-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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 idea is to get to the point where if r13 is non-zero, then it should contain a reasonable paca. This can be used in early boot program check and machine check handlers to avoid running off into the weeds if they hit before r13 has a paca. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/setup_64.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 08173eea8977..214d10caf458 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -177,23 +177,23 @@ early_param("smt-enabled", early_smt_enabled); #endif /* CONFIG_SMP */ /** Fix up paca fields required for the boot cpu */ -static void __init fixup_boot_paca(void) +static void __init fixup_boot_paca(struct paca_struct *boot_paca) { /* The boot cpu is started */ - get_paca()->cpu_start = 1; + boot_paca->cpu_start = 1; /* * Give the early boot machine check stack somewhere to use, use * half of the init stack. This is a bit hacky but there should not be * deep stack usage in early init so shouldn't overflow it or overwrite * things. */ - get_paca()->mc_emergency_sp = (void *)&init_thread_union + + boot_paca->mc_emergency_sp = (void *)&init_thread_union + (THREAD_SIZE/2); /* Allow percpu accesses to work until we setup percpu data */ - get_paca()->data_offset = 0; + boot_paca->data_offset = 0; /* Mark interrupts soft and hard disabled in PACA */ - irq_soft_mask_set(IRQS_DISABLED); - get_paca()->irq_happened = PACA_IRQ_HARD_DIS; + boot_paca->irq_soft_mask = IRQS_DISABLED; + boot_paca->irq_happened = PACA_IRQ_HARD_DIS; WARN_ON(mfmsr() & MSR_EE); } @@ -361,8 +361,8 @@ void __init early_setup(unsigned long dt_ptr) * what CPU we are on. */ initialise_paca(&boot_paca, 0); - setup_paca(&boot_paca); - fixup_boot_paca(); + fixup_boot_paca(&boot_paca); + setup_paca(&boot_paca); /* install the paca into registers */ /* -------- printk is now safe to use ------- */ @@ -391,8 +391,8 @@ void __init early_setup(unsigned long dt_ptr) /* Poison paca_ptrs[0] again if it's not the boot cpu */ memset(&paca_ptrs[0], 0x88, sizeof(paca_ptrs[0])); } - setup_paca(paca_ptrs[boot_cpuid]); - fixup_boot_paca(); + fixup_boot_paca(paca_ptrs[boot_cpuid]); + setup_paca(paca_ptrs[boot_cpuid]); /* install the paca into registers */ /* * Configure exception handlers. This include setting up trampolines From patchwork Thu Sep 15 12:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1678269 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=etvoAtz3; 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 4MSx3X3C3hz1ynm for ; Thu, 15 Sep 2022 22:15:04 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MSx3X2R5Gz3f7f for ; Thu, 15 Sep 2022 22:15:04 +1000 (AEST) 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=etvoAtz3; 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::42e; helo=mail-pf1-x42e.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=etvoAtz3; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 4MSwzV336Yz3c23 for ; Thu, 15 Sep 2022 22:11:34 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id b75so12611700pfb.7 for ; Thu, 15 Sep 2022 05:11:34 -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; bh=tlKVVjRawq/qcmFqMWvK3Y1GAD9Ga6bp/aZ4Jamk95o=; b=etvoAtz3wzij9/nabO1rOOzAApcgrN0j4JhkUUUrHKhXJVzR5dFUMfk2x/bpU/ciH1 ufCqfrn8nWVOUSes+CRdKYT13CQ8FqWu3HdoDSauDTGETnsfyqzBBVyKJHdgNU4rlyhA 4esQREEFEobrQjH9NtNMQzM5Rjxpi9EUl6BGPGken+On8mufvETy1HuRinD7b0wPtq3z c9gwbaS0cJQpau2nn61DA6qbkqJhw34TgRHat/jLE0tg49vJ50eKGB+5Z8CVm40ipqRn xHMq04I0qbhwrnS7suYKF1yk4s5aehAU4xiPwrJS8L8Sks/YiLF3dNz1/O7iHg6v47ox ARkw== 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; bh=tlKVVjRawq/qcmFqMWvK3Y1GAD9Ga6bp/aZ4Jamk95o=; b=fbk+5y2giJk4apMryFVA8YVs7/lTonAf0trpDcJT1nptrfF9bKWjqndzoouPuS1WVI 63ALhFfivd72XB13V/xTSzvSM08GKNPrwexT/TBkaymCetv26zh3nq/q+3JFCTV9UrfP Z0xPdBeckOC6948pQy3hB6NudrCD8n8bOdvlUJiao4cgbCeAW067hUHNUO75E2z8pCDn yHbM81X1iOaGKWOFGua+KYdRrDdVSj9VJ7JpQ9wlNq+W2MMhwcx82DHBj12KWNXSzBjs OYLAYcZaC4kQCWhiK5de3n/8E9pXbcYp2ndCS1GjOL1s93hEc1hrHgDgg8D9WMZO3IVH vsiQ== X-Gm-Message-State: ACgBeo27LpRweUiWE6eBXvAOpEw1p6Lo1KA0kMpY45JUgCJ2lcwRVYAA l5dYuzz4NFfFw36r0lIgR3mcXymVMxM= X-Google-Smtp-Source: AA6agR7JH+6xS1+KCFWcUR7F4ZMRSz4fEH0PXEUdUXBBRwwHo9o+cfnVXwoZaloThfcB6pX61gKtMA== X-Received: by 2002:a65:5a4d:0:b0:438:8ba7:e597 with SMTP id z13-20020a655a4d000000b004388ba7e597mr25660423pgs.625.1663243891848; Thu, 15 Sep 2022 05:11:31 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([118.210.107.131]) by smtp.gmail.com with ESMTPSA id b6-20020a170902650600b00172a567d910sm12569420plk.289.2022.09.15.05.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 05:11:31 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 6/6] powerpc/64s/interrupt: halt early boot interrupts if paca is not set up Date: Thu, 15 Sep 2022 22:10:58 +1000 Message-Id: <20220915121058.2288916-7-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915121058.2288916-1-npiggin@gmail.com> References: <20220915121058.2288916-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" Ensure r13 is zero from very early in boot until it gets set to the boot paca pointer. This allows early program and mce handlers to halt if there is no valid paca, rather than potentially run off into the weeds. This preserves register and memory contents for low level debugging tools. Nothing could be printed to console at this point in any case because even udbg is only set up after the boot paca is set, so this shouldn't be missed. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/exceptions-64s.S | 11 +++++++++-- arch/powerpc/kernel/head_64.S | 3 +++ arch/powerpc/kernel/setup_64.c | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 29d701a20c41..5078b2578dbe 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -724,8 +724,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR) * userspace starts. */ .macro EARLY_BOOT_FIXUP -#ifdef CONFIG_CPU_LITTLE_ENDIAN BEGIN_FTR_SECTION +#ifdef CONFIG_CPU_LITTLE_ENDIAN tdi 0,0,0x48 // Trap never, or in reverse endian: b . + 8 b 2f // Skip trampoline if endian is correct .long 0xa643707d // mtsprg 0, r11 Backup r11 @@ -753,8 +753,15 @@ BEGIN_FTR_SECTION mtsrr0 r11 // Restore SRR0 mfsprg r11, 0 // Restore r11 2: -END_FTR_SECTION(0, 1) // nop out after boot #endif + /* + * program check could hit at any time, and pseries can not block + * MSR[ME] in early boot. So check if there is anything useful in r13 + * yet, and spin forever if not. + */ + cmpdi r13,0 + beq . +END_FTR_SECTION(0, 1) // nop out after boot .endm /* diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S index cf2c08902c05..6aeba8a9814e 100644 --- a/arch/powerpc/kernel/head_64.S +++ b/arch/powerpc/kernel/head_64.S @@ -494,6 +494,9 @@ __start_initialization_multiplatform: /* Make sure we are running in 64 bits mode */ bl enable_64b_mode + /* Zero r13 (paca) so early program check / mce don't use it */ + li r13,0 + /* Get TOC pointer (current runtime address) */ bl relative_toc diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 214d10caf458..d290ea9f0865 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -362,6 +362,7 @@ void __init early_setup(unsigned long dt_ptr) */ initialise_paca(&boot_paca, 0); fixup_boot_paca(&boot_paca); + WARN_ON(local_paca != 0); setup_paca(&boot_paca); /* install the paca into registers */ /* -------- printk is now safe to use ------- */