From patchwork Tue Jan 30 10:30:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 10191659 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 5341E60388 for ; Tue, 30 Jan 2018 10:31:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40D62283C3 for ; Tue, 30 Jan 2018 10:31:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35A3F28998; Tue, 30 Jan 2018 10:31:05 +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 C3A9D283C3 for ; Tue, 30 Jan 2018 10:31:01 +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:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nGaSp3uBe7pyHAcQ2bp5CVQi9HayG5bJrjWsuMw//Cs=; b=lWrFzfAOUf3oFZ uAEILnKojNWF7T0Fna6uWp1IvthrrCJVTLxKoybHysVeqb+6zYlxUbHIRXizr1hkQDkgQTXpM8D/B aJZObN3jpmioNhJ8HU0nUB8vK5Nl/Q+548WhpjmEyyRn0+Nda6SQLqjZ99NVwOK2LqIVedQW104tT IR0zMYxoxRtVvxT32SHksKj7E9scWUnJK1WJDXMoa3q62o3KqAdr+oHmWnx2/U3ZVRVF4GTq+MjZ3 vw+GzANUsefCk5UNDBZuKWqreg+k0pgc6HGnI1UgzzKBrUGyqy//wi8mDlnBQ7UCKAeNTNI3AP3av /0yyZDvmaScSoKbQ73NQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egTBr-0007Ng-K0; Tue, 30 Jan 2018 10:30:59 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egTBl-0007J6-4h for linux-arm-kernel@lists.infradead.org; Tue, 30 Jan 2018 10:30:58 +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 C0E3580D; Tue, 30 Jan 2018 02:30:40 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 890B53F25C; Tue, 30 Jan 2018 02:30:40 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id A844D1AE4D9C; Tue, 30 Jan 2018 10:30:41 +0000 (GMT) Date: Tue, 30 Jan 2018 10:30:41 +0000 From: Will Deacon To: linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 4/9] arm64: kpti: Add ->enable callback to remap swapper using nG mappings Message-ID: <20180130103041.GA29693@arm.com> References: <1517227200-20412-1-git-send-email-will.deacon@arm.com> <1517227200-20412-5-git-send-email-will.deacon@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1517227200-20412-5-git-send-email-will.deacon@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) 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: marc.zyngier@arm.com, catalin.marinas@arm.com, robert.richter@cavium.com, ddaney@caviumnetworks.com, jcm@redhat.com 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 On Mon, Jan 29, 2018 at 11:59:55AM +0000, Will Deacon wrote: > Defaulting to global mappings for kernel space is generally good for > performance and appears to be necessary for Cavium ThunderX. If we > subsequently decide that we need to enable kpti, then we need to rewrite > our existing page table entries to be non-global. This is fiddly, and > made worse by the possible use of contiguous mappings, which require > a strict break-before-make sequence. > > Since the enable callback runs on each online CPU from stop_machine > context, we can have all CPUs enter the idmap, where secondaries can > wait for the primary CPU to rewrite swapper with its MMU off. It's all > fairly horrible, but at least it only runs once. > > Tested-by: Marc Zyngier > Reviewed-by: Marc Zyngier > Signed-off-by: Will Deacon > --- > arch/arm64/include/asm/assembler.h | 10 ++ > arch/arm64/kernel/cpufeature.c | 25 +++++ > arch/arm64/mm/proc.S | 204 +++++++++++++++++++++++++++++++++++-- > 3 files changed, 231 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h > index 3873dd7b5a32..23251eae6e8a 100644 > --- a/arch/arm64/include/asm/assembler.h > +++ b/arch/arm64/include/asm/assembler.h > @@ -523,6 +523,16 @@ alternative_endif > #endif > .endm > > + .macro pte_to_phys, phys, pte > +#ifdef CONFIG_ARM64_PA_BITS_52 > + ror \phys, \pte, #16 > + bfi \phys, \phys, #(16 + 12), #32 > + lsr \phys, \phys, #12 I spun this up on a model with 52-bit PA support and it doesn't work, unfortunately, because the lsr of #12 leaves 4 bits of the OA in the bottom nybble. Instead, we need the following on top: Will diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index f311a1ed34d0..f4f3350f697e 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -539,9 +539,9 @@ alternative_endif .macro pte_to_phys, phys, pte #ifdef CONFIG_ARM64_PA_BITS_52 - ror \phys, \pte, #16 - bfi \phys, \phys, #(16 + 12), #32 - lsr \phys, \phys, #12 + ubfiz \phys, \pte, #(48 - 16 - 12), #16 + bfxil \phys, \pte, #16, #32 + lsl \phys, \phys, #16 #else and \phys, \pte, #PTE_ADDR_MASK #endif