From patchwork Mon Nov 9 11:32:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11891223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B737C388F7 for ; Mon, 9 Nov 2020 11:35:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27CA3206A4 for ; Mon, 9 Nov 2020 11:35:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dZZexzp/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="MCRqykL9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27CA3206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=I7R35cJJh+a7w23Z0jfe2002jnv0cosINEFEZCExEZg=; b=dZZexzp/ai/ednCecBa/SMpNw QJnsodZHLYgt2ac0SHYV+huq89BlAfkUuUYa1a6oiUGqCyFRRUDMIyZdwmh4oo1X72GCeYkFS266y inK8qtQ295QOYEiZdNQIpEeDkVZJlCQTV6Kg1td+cteyrFVdc9cq8lf7AguRh+7LMLNizG52fk2FA eUivx5UsSumf1saKU+ylxwbZjcnEcnojYzax2hny+11DdxmsG911wDbDOgjpWwQu4gxqWow9RBV63 s9ZQI15KOfTZQNQrCWc9ypYru0zpi+INrxtpxVogpO9n4MF0u+rAcIXWY9zUn45DQCNB0eI8t6WoN +j0IWrfMQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5RG-0004rr-Dd; Mon, 09 Nov 2020 11:34:22 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5Pn-0004Mv-AY for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:32:53 +0000 Received: by mail-wm1-x343.google.com with SMTP id c9so7649345wml.5 for ; Mon, 09 Nov 2020 03:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TMiiQe8dps8UlLBMP1/FfXowdt6jftkROOTkeidxQ6Q=; b=MCRqykL93UM7VZQO7vOhlkxdVJd5QUgPMkxVuee5FdSRMJf/BpccDShKLgQFp6NJJd a0GX41CxmIkcMxdrCqMlr3D1qzLzNdLplauS1isnCth0p9/uPsFW6ciOvkzVQEEbTlHr sDAwsqFq+4vuRh01aPYBnrgs07qPmTEXFgDmT9rhYEhienboEBJ0PywqJ5kUmoQ1iRGA NBq7mkZ0pkz4GW5W7NYFl3CIouu0NEU/GFuddHE7KlI8KlJg1kALvOO0XajU60WENmIq 9S7QvnQQ4fQEoMI8XAgHgDgZP82yWyBNsJwSQfCZW3eq+MMeAmGEECSfXBkODrOoI87n gpWw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TMiiQe8dps8UlLBMP1/FfXowdt6jftkROOTkeidxQ6Q=; b=oYadmFZvKBXcshSXjTGiFuNFFgI2eLmo0HbQfMskXIL5F5svrCjC1PVDws8IS3e0LG ILHpQnelwTBT/ZMNEJMcaP9xUuu9MtWmMRpS+IymMRsmaUJvSOVmgz2Zh7bNrfNj1+g7 tvHDg931kUk0AEQQLHDPX+IJppAbvRjH6vStWI4hi/Aj9ScAb5dCi5Pn3MvZOkXkWt4I fHlls/4cZsFITQvf/r6WbBJbR24+7DLaCyjAzmc4s4alb4gjDmJ5rptX0X4lNApFEKqE k7ROlQrqtuAbzjlz8zOW7x4Eub1407zq/kMaq0F7bnCWa+q42dax73LSbVEYAUnIVP0H ANZQ== X-Gm-Message-State: AOAM5337LPKBgKLqU/S+dsIJeBdYHfe4gb7RbMnJwocAc6A1Rja1+l4s yfo1TRGkgPOnDHafUAw4Jshzdg== X-Google-Smtp-Source: ABdhPJzAdZ6FSQO5hV6ykLynqoddSFPjL1oAewWOLopW6hRU1epsokgUxLtDcZsMEgQ0kGTnP14D+w== X-Received: by 2002:a7b:c089:: with SMTP id r9mr13395753wmh.45.1604921570013; Mon, 09 Nov 2020 03:32:50 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id v2sm2974539wrm.96.2020.11.09.03.32.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:32:49 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 05/24] kvm: arm64: Add .hyp.data..ro_after_init ELF section Date: Mon, 9 Nov 2020 11:32:14 +0000 Message-Id: <20201109113233.9012-6-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_063251_450944_81ABA829 X-CRM114-Status: GOOD ( 20.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , David Brazdil , Will Deacon , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add rules for renaming the .data..ro_after_init ELF section in KVM nVHE object files to .hyp.data..ro_after_init, linking it into the kernel and mapping it in hyp at runtime. The section is RW to the host, then mapped RO in hyp. The expectation is that the host populates the variables in the section and they are never changed by hyp afterwards. Signed-off-by: David Brazdil --- arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/vmlinux.lds.S | 10 ++++++++++ arch/arm64/kvm/arm.c | 8 ++++++++ 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 3994169985ef..8ff579361731 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -11,6 +11,7 @@ extern char __alt_instructions[], __alt_instructions_end[]; 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 __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 1bda604f4c70..4382b5d0645d 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -30,6 +30,13 @@ jiffies = jiffies_64; *(__kvm_ex_table) \ __stop___kvm_ex_table = .; +#define HYPERVISOR_DATA_SECTIONS \ + HYP_SECTION_NAME(.data..ro_after_init) : { \ + __hyp_data_ro_after_init_start = .; \ + *(HYP_SECTION_NAME(.data..ro_after_init)) \ + __hyp_data_ro_after_init_end = .; \ + } + #define HYPERVISOR_PERCPU_SECTION \ . = ALIGN(PAGE_SIZE); \ HYP_SECTION_NAME(.data..percpu) : { \ @@ -37,6 +44,7 @@ jiffies = jiffies_64; } #else /* CONFIG_KVM */ #define HYPERVISOR_EXTABLE +#define HYPERVISOR_DATA_SECTIONS #define HYPERVISOR_PERCPU_SECTION #endif @@ -234,6 +242,8 @@ SECTIONS _sdata = .; RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) + HYPERVISOR_DATA_SECTIONS + /* * Data written with the MMU off but read with the MMU on requires * cache lines to be invalidated, discarding up to a Cache Writeback diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5750ec34960e..9ba9db2aa7f8 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1602,6 +1602,14 @@ static int init_hyp_mode(void) goto out_err; } + err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_ro_after_init_start), + kvm_ksym_ref(__hyp_data_ro_after_init_end), + PAGE_HYP_RO); + if (err) { + kvm_err("Cannot map .hyp.data..ro_after_init section\n"); + goto out_err; + } + err = create_hyp_mappings(kvm_ksym_ref(__start_rodata), kvm_ksym_ref(__end_rodata), PAGE_HYP_RO); if (err) { diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S index bb2d986ff696..5d76ff2ba63e 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S @@ -16,4 +16,5 @@ SECTIONS { HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) } + HYP_SECTION(.data..ro_after_init) }