From patchwork Fri Dec 1 04:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 843319 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yp1G56khGz9t2f for ; Fri, 1 Dec 2017 15:17:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fw4Neyih"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yp1G5317SzDsVt for ; Fri, 1 Dec 2017 15:17:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fw4Neyih"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::243; helo=mail-pf0-x243.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.b="fw4Neyih"; dkim-atps=neutral Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yp1Bv3qT5zDsFS for ; Fri, 1 Dec 2017 15:15:01 +1100 (AEDT) Received: by mail-pf0-x243.google.com with SMTP id m26so4096415pfj.11 for ; Thu, 30 Nov 2017 20:15:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mXd1PEY+ku0GIoAnYAbBNiMPNNcZadktfH2QVVxh+pI=; b=fw4NeyihFyU55r75ZmxL0hk5vTWTGzUcIN0GHBtENXyN+3t0oNIBdB0XsOis+jCWKC hbzaXSd/l1pLZY29bJwfLhzEbe62Wmag2xMyOXaVb0Uop7VAdugoRkb2DqcDSeXEO45N l6G2ygmnsyhVBAmMIKkV34qr00YSBPdTEiopUxFTgGjvcNGvLoDobzKtG/0btrIjlywV 3AFMLqsvWR81BFlBURGCLhSFHmw+qznyQtfMeJ34A6BSeXXwAaSzuW9XvP4yknkPmaMa uZfR2JUM59eeKdkpEzLP6oE0F85pZrjtg900ls9Sl5fj47pbbqdAtU+l4lP/SWg0or2Z wQPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mXd1PEY+ku0GIoAnYAbBNiMPNNcZadktfH2QVVxh+pI=; b=M0WJnuBZuC5t57PLrVtb1zxK96g51lnAYw9JhKoweeA01GgkNb04UXmOPHQ4kozca+ j7tOY3YoQTw+G7TfGrv+Dj+JzWVImntAAC4SXzB572BR0wCHp6TlB/cDVrrzb91pxsJf 5DKLiUEPkMRQTTNq3ZSnd/itV3Z/qRkegZgW7jscfzqR9QSQZgSo+jARE7Hwvdf9yB/N 9gWmzFWJpAV/LRQ26WtLmiDYBzxq3SvLjh8T/LK6dZ1d06xgxNA4V3t4UHUjHtMDjGIl GVtcvckUez8UqEBuvfMpIkiL5EtxQnBEsljlBeBrbtYQ1tKH2soImJnoV/TkUbakqljr r+0g== X-Gm-Message-State: AJaThX6kp/GvZmIo9UjsbE4SrBNlarrUqj2ty6WEjl5VjfQnJ7ZD1vb6 2kFOeyPQ/LOCqBf3U6xdHIwyHw== X-Google-Smtp-Source: AGs4zMbJyJVj0c3Vbuyv64p9h1WawfwJdS2Uzl9+eEmHI/Fjjb/k+rGILm9O/jU0jQ5Kt603JjL6pQ== X-Received: by 10.99.146.65 with SMTP id s1mr4677756pgn.354.1512101699473; Thu, 30 Nov 2017 20:14:59 -0800 (PST) Received: from roar.au.ibm.com (27-33-241-195.tpgi.com.au. [27.33.241.195]) by smtp.gmail.com with ESMTPSA id n22sm9106707pgc.4.2017.11.30.20.14.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 20:14:58 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/64s: ISAv3 initialize MMU registers before setting partition table Date: Fri, 1 Dec 2017 14:14:48 +1000 Message-Id: <20171201041448.28053-1-npiggin@gmail.com> X-Mailer: git-send-email 2.15.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Aneesh Kumar K . V" , Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" kexec can leave MMU registers set, PIDR in particular, when booting the new kernel. The boot sequence does not zero PIDR ever, and it only gets changed as CPUs first switch to userspace processes. This can leave a window where speculative accesses from a CPU to quadrant 0 can pick up translations in the partition table that may be set up for processes running on other CPUs. These cached translations will not be involved in the invalidation protocol, so we can end with stable TLB and PWC. This can cause the kernel to hang in infinite page fault loops (usually in schedule_tail, which is usually the first quardant 0 access to a new PID. Fix this by zeroing out PIDR before setting PTCR. Signed-off-by: Nicholas Piggin --- arch/powerpc/mm/hash_utils_64.c | 6 ++++++ arch/powerpc/mm/pgtable-radix.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c index 655a5a9a183d..9176e1dda8e0 100644 --- a/arch/powerpc/mm/hash_utils_64.c +++ b/arch/powerpc/mm/hash_utils_64.c @@ -1029,6 +1029,9 @@ void __init hash__early_init_mmu(void) pci_io_base = ISA_IO_BASE; #endif + if (cpu_has_feature(CPU_FTR_ARCH_300)) + mtspr(SPRN_PID, 0); + /* Select appropriate backend */ if (firmware_has_feature(FW_FEATURE_PS3_LV1)) ps3_early_mm_init(); @@ -1055,6 +1058,9 @@ void __init hash__early_init_mmu(void) void hash__early_init_mmu_secondary(void) { /* Initialize hash table for that CPU */ + if (cpu_has_feature(CPU_FTR_ARCH_300)) + mtspr(SPRN_PID, 0); + if (!firmware_has_feature(FW_FEATURE_LPAR)) { if (cpu_has_feature(CPU_FTR_POWER9_DD1)) diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c index cfbbee941a76..88430acf4b85 100644 --- a/arch/powerpc/mm/pgtable-radix.c +++ b/arch/powerpc/mm/pgtable-radix.c @@ -563,12 +563,25 @@ void __init radix__early_init_mmu(void) __pte_frag_nr = H_PTE_FRAG_NR; __pte_frag_size_shift = H_PTE_FRAG_SIZE_SHIFT; + /* + * kexec kernels can boot into the new kernel with PIDR non-zero. + * + * PIDR should be zeroed before we set the partition table, + * to ensure no speculative TLB fill goes off to non-zero PIDs. + * This shouldn't be a problem in real-mode, but I have not + * found definitively in the ISA. + * + * We do need to ensure all CPUs have PID=0 when the MMU + * is turned on. + */ + mtspr(SPRN_PID, 0); if (!firmware_has_feature(FW_FEATURE_LPAR)) { radix_init_native(); if (cpu_has_feature(CPU_FTR_POWER9_DD1)) update_hid_for_radix(); lpcr = mfspr(SPRN_LPCR); mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR); + mtspr(SPRN_LPID, 0); radix_init_partition_table(); radix_init_amor(); } else { @@ -587,6 +600,7 @@ void radix__early_init_mmu_secondary(void) /* * update partition table control register and UPRT */ + mtspr(SPRN_PID, 0); if (!firmware_has_feature(FW_FEATURE_LPAR)) { if (cpu_has_feature(CPU_FTR_POWER9_DD1)) @@ -595,6 +609,7 @@ void radix__early_init_mmu_secondary(void) lpcr = mfspr(SPRN_LPCR); mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR); + mtspr(SPRN_LPID, 0); mtspr(SPRN_PTCR, __pa(partition_tb) | (PATB_SIZE_SHIFT - 12)); radix_init_amor();