From patchwork Fri Mar 17 05:13:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 740166 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 3vkv3150kYz9ryZ for ; Fri, 17 Mar 2017 16:26:37 +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="ao9co4Ix"; 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 3vkv313jlwzDqkc for ; Fri, 17 Mar 2017 16:26:37 +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="ao9co4Ix"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::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 3vktly2Wx3zDqp4 for ; Fri, 17 Mar 2017 16:13:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ao9co4Ix"; dkim-atps=neutral Received: by mail-pf0-x242.google.com with SMTP id r137so4184828pfr.3 for ; Thu, 16 Mar 2017 22:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=V61rhKhFAG7g9ro5QqrdoOk7uJqM9j5EU+zzb8y1dns=; b=ao9co4IxDea7NYY5++yAAqpWLEpkn2laHWFnlpetBzpo9jh3OGquOB3bv56dJmceFA 5aZbnZVzqlc5pS33Mz58m3Z5AsDCUMc2KqmFGqi/SGw25ZEYreEGjrF4J5PTihJpxNNd sDF9ggReVyt1jzKDCLTwU9Rzp6+Nk4ZpGVCSnMEiKutJvfL8NLS/FwSbd6282N/Q2T7t MmJfwhacUXZykN7UMX0TtN4KcmuMw7PiB+1pwP5JIZa4e6yYjh4wwKd5NylL9nk9n5VW yNTOR3f5kk6s3aMFl0xgjKp4N12zWa9ObwKpOPOoTjhWx14oRzJl/tvUCF4EI20U39yR vayA== 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=V61rhKhFAG7g9ro5QqrdoOk7uJqM9j5EU+zzb8y1dns=; b=FXxenHP3uZ3YOU8gueE46+XRBImvDT9tSt2vSv9UqSbaCPovvK4vUdfMdtdUzPyCRj V88caIuS+cBvHYnnREWwXMng2jGPdc8mYwKG3M8BRNwOoVhK2OmCkwqQyDxZ1Gy+Y1cS JJcfE8Q36n5Q24FGuisFMyeULuCG51EXjHlnvXYe6y+qIxPCkg6H8HyJp7JEC2ecuWso ZHYjfZQWSrbIfAIhV/XKm9USvc5Kuj2TvI3jadv6x+DctU+JxudE4crz/8GYV52+bSrR 2bmtLpXJYVd3ieF+cBN+7MloEUBFmPqZGfG1E3Nue06CJIJokxs7BLHnjt0YVE5lBq1f 8sLg== X-Gm-Message-State: AFeK/H3PYrJh/Cd7Kjyni7qHQ3zUZ/yY2A3DluRSvNReeehQuO2EqN8LrVuDpBZMg5fkBw== X-Received: by 10.84.179.99 with SMTP id a90mr17571568plc.26.1489727612736; Thu, 16 Mar 2017 22:13:32 -0700 (PDT) Received: from roar.au.ibm.com ([203.221.48.234]) by smtp.gmail.com with ESMTPSA id a16sm13742063pgd.62.2017.03.16.22.13.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 22:13:31 -0700 (PDT) From: Nicholas Piggin To: Michael Ellerman Subject: [PATCH] powerpc/64s: fix idle wakeup potential to clobber registers Date: Fri, 17 Mar 2017 15:13:20 +1000 Message-Id: <20170317051320.7069-1-npiggin@gmail.com> X-Mailer: git-send-email 2.11.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Gautham R . Shenoy" , linuxppc-dev@lists.ozlabs.org, Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" We concluded there may be a window where the idle wakeup code could get to pnv_wakeup_tb_loss (which clobbers non-volatile GPRs), but the hardware may set SRR1[46:47] to 01b (no state loss) which would result in the wakeup code failing to restore non-volatile GPRs. I was not able to trigger this condition with trivial tests on real hardware or simulator, but the ISA (at least 2.07) seems to allow for it, and Gautham says that it can happen if there is an exception pending when the sleep/winkle instruction is executed. Signed-off-by: Nicholas Piggin Acked-by: Gautham R. Shenoy --- arch/powerpc/kernel/idle_book3s.S | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S index 995728736677..6fd08219248d 100644 --- a/arch/powerpc/kernel/idle_book3s.S +++ b/arch/powerpc/kernel/idle_book3s.S @@ -449,9 +449,23 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) _GLOBAL(pnv_wakeup_tb_loss) ld r1,PACAR1(r13) /* - * Before entering any idle state, the NVGPRs are saved in the stack - * and they are restored before switching to the process context. Hence - * until they are restored, they are free to be used. + * Before entering any idle state, the NVGPRs are saved in the stack. + * If there was a state loss, or PACA_NAPSTATELOST was set, then the + * NVGPRs are restored. If we are here, it is likely that state is lost, + * but not guaranteed -- neither ISA207 nor ISA300 tests to reach + * here are the same as the test to restore NVGPRS: + * PACA_THREAD_IDLE_STATE test for ISA207, PSSCR test for ISA300, + * and SRR1 test for restoring NVGPRs. + * + * We are about to clobber NVGPRs now, so set NAPSTATELOST to + * guarantee they will always be restored. This might be tightened + * with careful reading of specs (particularly for ISA300) but this + * is already a slow wakeup path and it's simpler to be safe. + */ + li r0,1 + stb r0,PACA_NAPSTATELOST(r13) + + /* * * Save SRR1 and LR in NVGPRs as they might be clobbered in * opal_call() (called in CHECK_HMI_INTERRUPT). SRR1 is required