From patchwork Tue Oct 10 12:50:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 9996027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6F9C60216 for ; Tue, 10 Oct 2017 12:51:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98CF028590 for ; Tue, 10 Oct 2017 12:51:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D8A0285A9; Tue, 10 Oct 2017 12:51:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 047A428590 for ; Tue, 10 Oct 2017 12:51:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NBmpacP73pypAtcUvrdTOHRA9lJsqrMO86HMAzMP3vs=; b=UBHfBhkCDAu7n4 YCgiNFH8mJM785i09LwQf6kiO2owl3SIxLK1ted15SHwppCiqHWnSDrYiVzBACUmwM3PSXpRdUKAq 3vjv8l6cuzaZSPmHSimSievKebngUhrSuhxrpwlSSDl7WpHVobOIvjBoqwXY45zvNyQskqluKjvrT vchcPBBDrKS9M8kODdwAxSlbVfkMI+4zRn2qX3DLYhHCKh3BBEeN88My1atsgdx1Kk4E5Zc6aU2De mEOu2xybvowYOXX2vAoA1T5vn7bXNy5WZ4LURcQ3zbI9qwtfpFRgrjFwBJ6uv8Cp1kqfOPFvz+oqS HaZ6oRJKVFghtNHkQV1Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e1tzx-00064c-N5; Tue, 10 Oct 2017 12:51:01 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e1tzu-0005zm-6x for linux-arm-kernel@lists.infradead.org; Tue, 10 Oct 2017 12:50:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DD44D80D; Tue, 10 Oct 2017 05:50:36 -0700 (PDT) Received: from [10.1.78.252] (unknown [10.1.78.252]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC08B3F58C; Tue, 10 Oct 2017 05:50:35 -0700 (PDT) Subject: Re: [PATCH 1/3] arm64: mm: Support Common Not Private translations To: James Morse , Catalin Marinas References: <1507553734-27854-1-git-send-email-vladimir.murzin@arm.com> <1507553734-27854-2-git-send-email-vladimir.murzin@arm.com> <20171009152300.yrjdhnwna5r2enae@armageddon.cambridge.arm.com> <59DBA864.9030108@arm.com> From: Vladimir Murzin Message-ID: Date: Tue, 10 Oct 2017 13:50:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <59DBA864.9030108@arm.com> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171010_055058_269142_4A7F3D31 X-CRM114-Status: GOOD ( 17.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, marc.zyngier@arm.com, kbuild-all@01.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi James, On 09/10/17 17:48, James Morse wrote: > Hi Catalin, Vladimir, > > On 09/10/17 16:23, Catalin Marinas wrote: >> On Mon, Oct 09, 2017 at 01:55:32PM +0100, Vladimir Murzin wrote: >>> This patch adds support for Common Not Private translations on >>> different exceptions levels: > >>> (2) For EL1 we postpone setting CNP till all cpus are up and rely on >>> cpufeature framework to 1) patch the code which is sensitive to >>> CNP and 2) update TTBR1_EL1 with CNP bit set. The only case where >>> TTBR1_EL1 can be reprogrammed is hibirnation, so the code there is >>> changed to save raw TTBR1_EL1 and blindly restore it on resume. > >> Even if you do this when all the CPUs are up, that's not always true. >> Starting with maxcpus=1 allows something like systemd to bring up new >> CPUs once user space starts. > > For secondary CPUs cpu_enable_cnp() will be called to set CNP on TTBR1_EL1. But > what about cpuidle? This also resets the TTBR1_EL1 value. Good point! I've missed it because reset happens via __enable_mmu, which has no idea about CnP. Would something like below be sufficient? > > >> The problem we have is that we don't know >> what the firmware is doing, whether it's setting CnP or not. Maybe we >> should add some statement in Documentation/arm64/booting.txt that >> firmware must not use CnP at all. > > >>> diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c >>> index 095d3c1..1d056f3 100644 >>> --- a/arch/arm64/kernel/hibernate.c >>> +++ b/arch/arm64/kernel/hibernate.c >>> @@ -124,7 +124,7 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size) >>> return -EOVERFLOW; >>> >>> arch_hdr_invariants(&hdr->invariants); >>> - hdr->ttbr1_el1 = __pa_symbol(swapper_pg_dir); >>> + hdr->ttbr1_el1 = read_sysreg(ttbr1_el1); >>> hdr->reenter_kernel = _cpu_resume; >>> >>> /* We can't use __hyp_get_vectors() because kvm may still be loaded */ > >> Are all the CPUs up when coming out of hibernation and restoring >> ttbr1_el1? > > 'nonboot' CPUs are powered off around hibernate, so this only runs on one CPU. > > Restoring with the CNP set like this will share all the TTBR1 mappings using the > reserved ASID out of TTBR0. Hibernate then calls cpu_uninstall_idmap() via > __cpu_suspend_exit(), which will restore the original ttbr0 value and CNP bit. > Thanks for explanation! Vladimir > > Thanks, > > James > diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c index 1e3be90..03a02c4 100644 --- a/arch/arm64/kernel/suspend.c +++ b/arch/arm64/kernel/suspend.c @@ -46,6 +46,10 @@ void notrace __cpu_suspend_exit(void) */ cpu_uninstall_idmap(); +#ifdef CONFIG_ARM64_CNP + /* Restore CnP bit in TTBR1_EL1 */ + cpu_replace_ttbr1(swapper_pg_dir); +#endif /* * PSTATE was not saved over suspend/resume, re-enable any detected * features that might not have been set correctly.