Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4066155pxb; Tue, 17 Nov 2020 10:19:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZxwiol4kmMfWQp+gsmNG4tK4/7Kdz23lTEXfKAwwrKhx7VIjddH7/ehim+xhsiTRcnYq7 X-Received: by 2002:a05:6402:170e:: with SMTP id y14mr22527515edu.115.1605637185428; Tue, 17 Nov 2020 10:19:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605637185; cv=none; d=google.com; s=arc-20160816; b=elTmgyeTcJcUuL/oPsp0wsEzO4xVXlkB5GAisczQ8cEasQbzPMLSkIlJ9U3D0RZdAY Dmee02CpARRJ0wTeDLcytaWmFwEvfi5Q/utDyFp5v8CY/ZKCGrgwhxBNvuaHWSQeQnqd fIu85y4doadf2MLB2F/DkMdXA2g1Qg3DYqll4yb6eOe0FuRc8oVV4y5TfsOyMgsV/L0i QZSlbgAaXfGveH2YugW9F3rlq9KxyGlt92ts05LILT/qM9gEig1TTNz5xJXJ6d9m8ec+ 0TEF0XGBW8Lr2M/OL6kWMp1qroAnKQkwB6E28vUV8qBdF5kBLKAn4pDN6og07o6wAqua S4MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=ku0UFgVufHs9v1IJuu4Ni7X8qoCAXYV3NVQ1AKXoaAA=; b=pCGF4eLeeWqdXKnyMgV4efFFQkbo6dL9JkMmdPrBj7RqXUebsvuje4NVh+WSm87HgY 1OFESDgCkKCxPBG0GLd4hSzrgDDHS7D12tkt0HOIWOpQTVdqhjyPu67xoJ/aAlVbxjFJ 49sI/3kGbIrRROVHF8X76BmuCBjzrzIVBsg7ThqhbS6v29nfJyE5oRQTs9wbhvkVSKtC L7JX+Du3OTyKdC+7sokUxVRnka9EGk1Bl5+deTnREEYtbbI/R9lzecAZDfK4sLW1nzWM SMvKfsDOAjdrPMHB3cgS/YSy3iw9VtQDULNFKdydkhiBgx5lbmJndoGfwu1V3S1A25xC 4fgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H5BJeQDN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si7928862edh.608.2020.11.17.10.19.22; Tue, 17 Nov 2020 10:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H5BJeQDN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730819AbgKQSQi (ORCPT + 99 others); Tue, 17 Nov 2020 13:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730747AbgKQSQh (ORCPT ); Tue, 17 Nov 2020 13:16:37 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4DB0C0613CF for ; Tue, 17 Nov 2020 10:16:36 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id w17so13200096wrp.11 for ; Tue, 17 Nov 2020 10:16:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ku0UFgVufHs9v1IJuu4Ni7X8qoCAXYV3NVQ1AKXoaAA=; b=H5BJeQDNLb++2xZvg4tH88cc0a517Nx1EBbTKeYIiv7k2xmQWwSp58eVZTiebUdyMG +g9ZeTElu3osA0nWOAV/aPjF1sobwPu1mjr/Dc4ZR36cFV5rLKkzslvkaXdW4CLYUChE nsu09uy4ADkg28f4TLlCpZGieLbT7PYoNhrfsiVb3HuoZcGEbh4XzBqyFM2bwNG3qIfY hH/rYe/JYRFiC/HTk4i7mRnSpAofJBPD+hamGi87aZT+MwV5MFfE4MgTO4nNxijcnPew C0S1hc2bUUhl2BBBC+fbW8SxHu46dT+sn/YDa0tekeckiqLhsPvIgfkzwciINYE0N9jK cxtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ku0UFgVufHs9v1IJuu4Ni7X8qoCAXYV3NVQ1AKXoaAA=; b=mHU+20f+w51NxoRrRs3Ga5rmWM5mFauLvDGQ45AC2yLwOaWxkbGWH8UV/swTtDp/ci GA8ir1VoP/ZXlfbYsP3WfSfXSALUAIh7XxjB4lG3DxFk6oh9vIUrj4un3b/fSvdUIj5F qrJC7m0uubhQXczX3TOw7nmUWBIORRuPKNOkDJqYoRfb/l3XiPBrgZw/aD1payYjWp9D meJuM1hYck1TvxTRD2I5BKSpAz/PKRUSoMaCDd5nmndBuY/NqMQrHAEiukntlQIbn27e q8aJfeq/otxlol/I27VDvNOC8oO2cmZl5EHHh/2vRW4mndTRgvXWyoEVomgnAeoIY/Lo w7Ag== X-Gm-Message-State: AOAM530PyyWyzDbZndth2f1nMJf2fQz+MuR+75cyD2rJuvqdGze/Fwaz iXNYKt8sM+lRj3JxilaSUiMfrKYtdRdA Sender: "qperret via sendgmr" X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) (user=qperret job=sendgmr) by 2002:a1c:398a:: with SMTP id g132mr368672wma.51.1605636995303; Tue, 17 Nov 2020 10:16:35 -0800 (PST) Date: Tue, 17 Nov 2020 18:15:47 +0000 In-Reply-To: <20201117181607.1761516-1-qperret@google.com> Message-Id: <20201117181607.1761516-8-qperret@google.com> Mime-Version: 1.0 References: <20201117181607.1761516-1-qperret@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH 07/27] KVM: arm64: Introduce a BSS section for use at Hyp From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand Cc: "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , open list , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , kernel-team@android.com, android-kvm@google.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the hyp code cannot make full use of a bss, as the kernel section is mapped read-only. While this mapping could simply be changed to read-write, it would intermingle even more the hyp and kernel state than they currently are. Instead, introduce a __hyp_bss section, that uses reserved pages, and create the appropriate RW hyp mappings during KVM init. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/vmlinux.lds.S | 7 +++++++ arch/arm64/kvm/arm.c | 11 +++++++++++ arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 4 files changed, 20 insertions(+) diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index 8ff579361731..f58cf493de16 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -12,6 +12,7 @@ extern char __hibernate_exit_text_start[], __hibernate_exit_text_end[]; extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[]; extern char __hyp_text_start[], __hyp_text_end[]; extern char __hyp_data_ro_after_init_start[], __hyp_data_ro_after_init_end[]; +extern char __hyp_bss_start[], __hyp_bss_end[]; extern char __idmap_text_start[], __idmap_text_end[]; extern char __initdata_begin[], __initdata_end[]; extern char __inittext_begin[], __inittext_end[]; diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 4382b5d0645d..ded78a25365d 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -8,6 +8,13 @@ #define RO_EXCEPTION_TABLE_ALIGN 8 #define RUNTIME_DISCARD_EXIT +#define BSS_FIRST_SECTIONS \ + . = ALIGN(PAGE_SIZE); \ + __hyp_bss_start = .; \ + *(.hyp.bss) \ + . = ALIGN(PAGE_SIZE); \ + __hyp_bss_end = .; + #include #include #include diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 7335eb4fb0bd..882eb383bd75 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1709,7 +1709,18 @@ static int init_hyp_mode(void) goto out_err; } + /* + * .hyp.bss is placed at the beginning of the .bss section, so map that + * part RW, and the rest RO as the hyp shouldn't be touching it. + */ err = create_hyp_mappings(kvm_ksym_ref(__bss_start), + kvm_ksym_ref(__hyp_bss_end), PAGE_HYP); + if (err) { + kvm_err("Cannot map hyp bss section: %d\n", err); + goto out_err; + } + + err = create_hyp_mappings(kvm_ksym_ref(__hyp_bss_end), kvm_ksym_ref(__bss_stop), PAGE_HYP_RO); if (err) { kvm_err("Cannot map bss section\n"); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S index 5d76ff2ba63e..dc281d90063e 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S @@ -17,4 +17,5 @@ SECTIONS { PERCPU_INPUT(L1_CACHE_BYTES) } HYP_SECTION(.data..ro_after_init) + HYP_SECTION(.bss) } -- 2.29.2.299.gdc1121823c-goog