From patchwork Wed Dec 6 08:21:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 845063 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 3ysBTN4z15z9s84 for ; Wed, 6 Dec 2017 19:23:36 +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="dapu7LL0"; 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 3ysBTN0mJtzF0HC for ; Wed, 6 Dec 2017 19:23:36 +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="dapu7LL0"; 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:c01::242; helo=mail-pl0-x242.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="dapu7LL0"; dkim-atps=neutral Received: from mail-pl0-x242.google.com (mail-pl0-x242.google.com [IPv6:2607:f8b0:400e:c01::242]) (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 3ysBR35p8fzF0HB for ; Wed, 6 Dec 2017 19:21:35 +1100 (AEDT) Received: by mail-pl0-x242.google.com with SMTP id 1so511545pla.7 for ; Wed, 06 Dec 2017 00:21:35 -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=rlCH12k1KP2r0GnMa3P8b3PipZAyuN6/E66p+v/SvwA=; b=dapu7LL01G2dIIFix28Tck2Xj1BoOkNupfUeN1Dkchnn1MWgtFJ3Fth/gab91T27nF 25TtTh4ZxZ2+bHAeHVXDmvqDXKrrA85EOsRf5unHeKyOffUoZsR+CBEQHcRfA1ZGWqiQ Ck2xHelLTlkqM38pvjikPFvycK7vhL34Q8IIWRDX4ao1942Y2xBRo+XyZAuBVv8igxlK LGw2tjO5X+yuaniPzMKK97ETQdr0kUcSK19RtLG5qh9sOq/95YmC/2uWnoTYIXE2G5UV idNn3Ho8/DlhtQBHrKeqazrw7r6zqu0Nqxe5NC4W4m9QAl2iNzs42pgCxIqRbn0GoFH4 jGHA== 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=rlCH12k1KP2r0GnMa3P8b3PipZAyuN6/E66p+v/SvwA=; b=gV0t/VvXT56m4y0vslaJW31Ms9mFmCF/2Q1s8QmpsYHHa59nZCJXjM36lD8tkg3IN/ KpmmFD5+PS7sLGEF4uj90Z/7Z0F90IK7ReX8CcZS6LYaBur7zAVxcUgsYqG9ZmZSfDVw sK4CmMQoHCTnrwDDT2vVejXAMFTJP7nSRwAc55dwj9CDwYvG5z37w8+G9zGsGs++6nWH WS6DP3BWi+eJb9mbKILFEmnkU3OFCzg4puHd02S7ombllwPhbI43Sf13Iverz0CvuoQB /n/mBRKffRsUVT1T3guODXDI4Pko2pZrmN8QwxFXjLzcKsCfDNBJ33WRxkbYWRmxg9e3 w5vA== X-Gm-Message-State: AJaThX4Vpb0J01dATSCpzQQKLtE4gOX3LIOlpXqjvf/RfmlFoKgDE287 nBpwa5VIvharwxXDEdAIjVKO3g== X-Google-Smtp-Source: AGs4zMZC8umsxIPSAHPwxknUBFzUOpCeQTsSTuKBiR62K5QOZw2PpDG/cTZrQ4cXQrVLLjopKccUJw== X-Received: by 10.84.204.136 with SMTP id b8mr21608477ple.319.1512548493434; Wed, 06 Dec 2017 00:21:33 -0800 (PST) Received: from roar.ozlabs.ibm.com (27-33-241-195.tpgi.com.au. [27.33.241.195]) by smtp.gmail.com with ESMTPSA id c24sm3437238pfl.2.2017.12.06.00.21.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Dec 2017 00:21:32 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3] powerpc/64s: ISAv3 initialize MMU registers before setting partition table Date: Wed, 6 Dec 2017 18:21:14 +1000 Message-Id: <20171206082114.30302-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: Michael Neuling , Nicholas Piggin , "Aneesh Kumar K . V" Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" kexec can leave MMU registers set when booting into a new kernel, PIDR in particular. The boot sequence does not zero PIDR, so it only gets set when CPUs first switch to a userspace processes (until then it's running a kernel thread with effective PID = 0). This leaves a window where a process table entry and page tables are set up due to user processes running on other CPUs, that happen to match with a stale PID. The CPU with that PID may cause speculative accesses that address quadrant 0, which will result in cached translations and PWC for that process, on a CPU which is not in the mm_cpumask and so they will not get invalidated properly. The most common result is the kernel hanging in infinite page fault loops soon after kexec (usually in schedule_tail, which is usually the first non-speculative quardant 0 access to a new PID) due to a stale PWC. However being a stale translation error, it could result in anything up to security and data corruption problems. Fix this by zeroing out PIDR at boot and kexec. Signed-off-by: Nicholas Piggin --- v3: do the register clearing in the early CPU setup code, suggested by Michael Ellerman, which already clears LPID. arch/powerpc/kernel/cpu_setup_power.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/kernel/cpu_setup_power.S b/arch/powerpc/kernel/cpu_setup_power.S index 610955fe8b81..679bbe714e85 100644 --- a/arch/powerpc/kernel/cpu_setup_power.S +++ b/arch/powerpc/kernel/cpu_setup_power.S @@ -102,6 +102,7 @@ _GLOBAL(__setup_cpu_power9) li r0,0 mtspr SPRN_PSSCR,r0 mtspr SPRN_LPID,r0 + mtspr SPRN_PID,r0 mfspr r3,SPRN_LPCR LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) or r3, r3, r4 @@ -126,6 +127,7 @@ _GLOBAL(__restore_cpu_power9) li r0,0 mtspr SPRN_PSSCR,r0 mtspr SPRN_LPID,r0 + mtspr SPRN_PID,r0 mfspr r3,SPRN_LPCR LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) or r3, r3, r4