From patchwork Thu Feb 26 15:29:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 45182 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D954D20674 for ; Thu, 26 Feb 2015 15:32:24 +0000 (UTC) Received: by wesk11 with SMTP id k11sf8790474wes.3 for ; Thu, 26 Feb 2015 07:32:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=lGujmDuTM7CqMgQGx6w2SHjHdwKpYf+7PjActt/YSQI=; b=HFid8Te9P+fTd6eXTUrDPLJp3pd1dcMiUDTEbp/nHdMzlxB2VLGoqr5OxHacCJCZrl GZXtCFEybDwCErw1DGF4nUhoxONkLxI6kHV34F+z0iBMndvHmAtAGJvLC+Iei7tHK7h+ xT6chb0b9xQVyrKyTdI24t+Ed+CXvcg3gPYiqPDNqySF1hiawgu3lE5q6emyCf15cmhu ca7tOyKn7Zyc3XCoSFpiuwr2x2oSd3IfafgQqep+3BaBVhLpCZXV/cghFwkXkHIC/i3X wEYxaf6iBKlx9cw7TYvu8+5LsZgST3/pq5p/F+i8btWIoCXcW+qfJtsmbxf4bYGm/aWn khKA== X-Gm-Message-State: ALoCoQnnZoAW5RnpcSAX0ErMl/pY58Sr12pmCAa//Kd2F5ElfYTYLD3AXViymgJp+eFc3Bcpgv4U X-Received: by 10.152.6.232 with SMTP id e8mr1395239laa.2.1424964744167; Thu, 26 Feb 2015 07:32:24 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.246.38 with SMTP id xt6ls45869lac.102.gmail; Thu, 26 Feb 2015 07:32:23 -0800 (PST) X-Received: by 10.112.138.233 with SMTP id qt9mr8144410lbb.44.1424964743866; Thu, 26 Feb 2015 07:32:23 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id eq5si866201lac.66.2015.02.26.07.32.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2015 07:32:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbiz11 with SMTP id z11so11616051lbi.5 for ; Thu, 26 Feb 2015 07:32:23 -0800 (PST) X-Received: by 10.152.203.194 with SMTP id ks2mr8160779lac.88.1424964743708; Thu, 26 Feb 2015 07:32:23 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp3375219lbj; Thu, 26 Feb 2015 07:32:22 -0800 (PST) X-Received: by 10.68.253.104 with SMTP id zz8mr6122220pbc.73.1424964741863; Thu, 26 Feb 2015 07:32:21 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kn1si1499348pdb.158.2015.02.26.07.32.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2015 07:32:21 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YR0Oq-0001GW-UN; Thu, 26 Feb 2015 15:30:52 +0000 Received: from mail-wg0-f54.google.com ([74.125.82.54]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YR0Ni-000844-In for linux-arm-kernel@lists.infradead.org; Thu, 26 Feb 2015 15:29:43 +0000 Received: by wghl18 with SMTP id l18so11883059wgh.7 for ; Thu, 26 Feb 2015 07:29:20 -0800 (PST) X-Received: by 10.180.89.173 with SMTP id bp13mr17436929wib.88.1424964560259; Thu, 26 Feb 2015 07:29:20 -0800 (PST) Received: from ards-macbook-pro.lan (bl11-65-113.dsl.telepac.pt. [85.244.65.113]) by mx.google.com with ESMTPSA id q10sm1846563wjr.41.2015.02.26.07.29.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Feb 2015 07:29:19 -0800 (PST) From: Ard Biesheuvel To: will.deacon@arm.com, mark.rutland@arm.com, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, steve.capper@linaro.org, christoffer.dall@linaro.org Subject: [RFC PATCH 2/3] arm64: make ID map shareable with EL2 Date: Thu, 26 Feb 2015 15:29:06 +0000 Message-Id: <1424964547-2118-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1424964547-2118-1-git-send-email-ard.biesheuvel@linaro.org> References: <1424964547-2118-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150226_072942_806122_79DAF27A X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.54 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.54 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This changes the ID map creation in head.S so that it can be reused by KVM to ID map the HYP init code in EL2. Since the architecture defines the AP[1] bit as RES1 in page table entries used at EL2, we must ensure that the HYP init code is mapped with the AP[1] bit set. However, AP[1] means 'writable at EL0' when set at EL1, which automatically implies PXN == 1 (rendering the entire ID map non-executable) unless we also set AP[2], which means read-only at both EL0 and EL1. To prevent having to make the entire ID map read-only, we split the ID map in two regions, and only set AP[2:1] == 0b11 for the first part, that covers the HYP .text section. Note that this also moves it to before _stext, which removes it from the runtime executable at EL1 region. This is a nice bonus, in fact, since this code should never be executable at EL1 anyway. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 22 ++++++++++++++++++---- arch/arm64/kernel/vmlinux.lds.S | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index a3612eadab3c..0b3fb672640c 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -79,8 +79,10 @@ #ifdef CONFIG_ARM64_64K_PAGES #define MM_MMUFLAGS PTE_ATTRINDX(MT_NORMAL) | PTE_FLAGS +#define MM_MMUFLAGS_HYP MM_MMUFLAGS | PTE_HYP | PTE_RDONLY #else #define MM_MMUFLAGS PMD_ATTRINDX(MT_NORMAL) | PMD_FLAGS +#define MM_MMUFLAGS_HYP MM_MMUFLAGS | PMD_HYP | PMD_SECT_RDONLY #endif /* @@ -379,8 +381,6 @@ __create_page_tables: cmp x0, x6 b.lo 1b - ldr x7, =MM_MMUFLAGS - /* * Create the identity mapping. */ @@ -426,9 +426,23 @@ __create_page_tables: #endif create_pgd_entry x0, x3, x5, x6 - ldr x6, =KERNEL_END + + /* + * Map the first region -which also contains the HYP text sections- with + * HYP compatible attributes, so that we can share the ID map with KVM. + */ + ldr x7, =MM_MMUFLAGS_HYP + adrp x6, _stext // __pa(_stext) mov x5, x3 // __pa(KERNEL_START) - add x6, x6, x28 // __pa(KERNEL_END) + create_block_map x0, x7, x3, x5, x6 + + /* + * Map everything else with the default attributes. + */ + ldr x7, =MM_MMUFLAGS + adrp x3, (_stext + BLOCK_SIZE - 1) // next block after _stext + adrp x6, KERNEL_END + mov x5, x3 create_block_map x0, x7, x3, x5, x6 /* diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 17383c257a7d..4874ebca4b3e 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -83,6 +83,7 @@ SECTIONS .head.text : { _text = .; HEAD_TEXT + HYPERVISOR_TEXT } ALIGN_DEBUG_RO .text : { /* Real text segment */ @@ -94,7 +95,6 @@ SECTIONS TEXT_TEXT SCHED_TEXT LOCK_TEXT - HYPERVISOR_TEXT *(.fixup) *(.gnu.warning) . = ALIGN(16);