From patchwork Thu Nov 30 15:52:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 843062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.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 3ynhkq2lsHz9t2f for ; Fri, 1 Dec 2017 02:53:07 +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="YBFaFrbL"; 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 3ynhkq1f00zDsFr for ; Fri, 1 Dec 2017 02:53:07 +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="YBFaFrbL"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c05::241; helo=mail-pg0-x241.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="YBFaFrbL"; dkim-atps=neutral Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (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 3ynhkC59V3zDrpl for ; Fri, 1 Dec 2017 02:52:35 +1100 (AEDT) Received: by mail-pg0-x241.google.com with SMTP id w7so3151491pgv.6 for ; Thu, 30 Nov 2017 07:52: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:in-reply-to:references; bh=7DF7cXB8Q+RRItuanIS8Oqm329ADck9d9BXf7fC3+YM=; b=YBFaFrbLrgiIjpyVf+u0I2NM16HwKQ3BFoDPyZaTdaDJQstGjmLKKiR+z+j+zh771M Scbw7uqj55GF3toD+9NGg2aRunNHd/JWarXy4YrvbAlz8q/FOCR7Kfjw0YVDXBk3CR5H KlugRcO1NYNDONoAE9eyBKe9RSjjj0WP/4WGMYJ2FUSk7KTjBplD/+d2BLPPKYyX48/y GNmi7+OWlTFfIvmmkM98mYfONi8dCqw0p3F53D4xZ33zUsyTJQE53bveYwKiQmrDrl3o C5iRqgpeYI7QA6V9nuvuVmBtaWx1hHIRm5tx+dlOCOLSQSa5TnyKTsAK99unr4XK5hTp xvHQ== 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:in-reply-to :references; bh=7DF7cXB8Q+RRItuanIS8Oqm329ADck9d9BXf7fC3+YM=; b=RkBObuUiDuR25N6muB+IPT9xVKP2878DVVPFaIGaIk83E8skIml8ZJ9jCqafksWb9p R6H+uIrBrPl99PSvkXU4lPycbjjn+IqPRuuRAK0KpxA7z+AdBgRcaQhdBqfCPiP9vzBR 1wqJaPxUwc+xeXGNKnjEnsXJb9vg0mAcdw3o9FA0p+AI/lBA5PPH9vl7oyxbeuC3+sxD JmVXvHK1PpsXtjnZsZhBLtgF9snYuu48zrizwdy6lFk/ngLtu07/tRFm1SK+f1yUvXJe DSF+WsD6/OFqt7c48NCwog/5prBbOvn+fECTQ9nxxLzIwrh+y7RuOog8dCTVP0iCq4SP 8+sw== X-Gm-Message-State: AJaThX4eLQqMdb0n50ythQbGRxmiC97ylfdNoxpwXZC5ZoBVV3ltVRgC MFpuBa1uxl4Mp+WgFCJqpkNUJQ== X-Google-Smtp-Source: AGs4zMaPutIEiqr9DHrR5s5zimwEU23Q7YtyfBYYR122SBcnu+K1phy2sUJGiqeE2EW/PujENbM/aw== X-Received: by 10.98.26.23 with SMTP id a23mr7118495pfa.198.1512057153625; Thu, 30 Nov 2017 07:52:33 -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 p24sm8037935pfh.170.2017.11.30.07.52.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 07:52:32 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Fri, 1 Dec 2017 01:52:15 +1000 Message-Id: <20171130155215.30574-3-npiggin@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130155215.30574-1-npiggin@gmail.com> References: <20171130155215.30574-1-npiggin@gmail.com> Subject: [Skiboot] [RFC PATCH 2/2] core/cpu: have opal_reinit_cpus clear MMU registers X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Aneesh Kumar K . V" MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" When called with an MMU argument, have opal_reinit_cpus zero PIDR and LPID registers as well as flush TLBs. During MMU initialization and over kexec, existing Linux kernels do not clear PIDR, which does not get set until init is executed, which is well after CPUs start running with relocation on. This can result in CPUs incorrectly picking up and caching translations (PWC and PTEs) after the kexec/boot process has done its initial clearing out of TLBs. PTCR can not be cleared entirely here, because opal_reinit_cpus is called with relocation on, so the new kexec kernel always boots with stale PID 0 translations sadly, but in practice they get cleared out before relocation is turned on. Signed-off-by: Nicholas Piggin --- core/cpu.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/core/cpu.c b/core/cpu.c index b94e04ef2..519a60515 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -1280,24 +1280,42 @@ void cpu_set_radix_mode(void) cpu_change_all_hid0(&req); } -static void cpu_cleanup_one(void *param __unused) +static void cpu_cleanup_mmu_one(void *param __unused) { + if (proc_gen >= proc_gen_p9) { + mtspr(SPR_PID, 0); + } + mtspr(SPR_LPID, 0); mtspr(SPR_AMR, 0); mtspr(SPR_IAMR, 0); } -static int64_t cpu_cleanup_all(void) +/* + * Clean MMU registers and flush TLBs to prepare for a kexec (or similar + * environment). + */ +static int64_t cpu_cleanup_mmu(void) { struct cpu_thread *cpu; for_each_available_cpu(cpu) { if (cpu == this_cpu()) { - cpu_cleanup_one(NULL); + cpu_cleanup_mmu_one(NULL); continue; } - cpu_wait_job(cpu_queue_job(cpu, "cpu_cleanup", - cpu_cleanup_one, NULL), true); + cpu_wait_job(cpu_queue_job(cpu, "cpu_cleanup_mmu", + cpu_cleanup_mmu_one, NULL), true); } + + /* Cleanup the TLB. After PID and LPID are cleared, we can flush + * TLBs without them being prefetched, with the exception of PID 0, + * unfortunately Linux calls this with the MMU on, so we can't + * clear up the MMU registers completely and flush everything. + * + * This is P9 specific for now. + */ + cleanup_global_tlb(); + return OPAL_SUCCESS; } @@ -1362,7 +1380,10 @@ static int64_t opal_reinit_cpus(uint64_t flags) * transitions. Ideally Linux should do it but doing it * here works around existing broken kernels. */ - cpu_cleanup_all(); + if (flags & (OPAL_REINIT_CPUS_MMU_HASH | + OPAL_REINIT_CPUS_MMU_RADIX)) { + cpu_cleanup_mmu(); + } /* If HILE change via HID0 is supported ... */ if (hile_supported && @@ -1398,16 +1419,6 @@ static int64_t opal_reinit_cpus(uint64_t flags) } } - /* Cleanup the TLB. We do that unconditionally, this works - * around issues where OSes fail to invalidate the PWC in Radix - * mode for example. This only works on P9 and later, but we - * also know we don't have a problem with Linux cleanups on - * P8 so this isn't a problem. If we wanted to cleanup the - * TLB on P8 as well, we'd have to use jobs to do it locally - * on each CPU. - */ - cleanup_global_tlb(); - /* Apply HID bits changes if any */ if (req.set_bits || req.clr_bits) cpu_change_all_hid0(&req);