Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3132855pxb; Mon, 9 Nov 2020 03:35:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNFp7sat+zV1+MzEBB5GuCoMplkX8MDO7ja2fQW6JIvkuvKnh+dIRq0id4yvjNkFmJsv2T X-Received: by 2002:a50:f604:: with SMTP id c4mr2141102edn.117.1604921706107; Mon, 09 Nov 2020 03:35:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604921706; cv=none; d=google.com; s=arc-20160816; b=mThNcscHK1+3opjlwp1lUmOl6Rl5HpIpxYow8bPfECP0svJTUjRAfp/yEXt0N6ZPEY x82t1nibMNEP2Tvow5+5LiakY6TXdHf8a4oxLhVV0dvO01WDX6duk8wXlGq/1bWf/l7+ zYsxqxRjGfEkYJMkWpUPD5my3Tw6oNXInBc6CFpgf8Q8DJTTiZAoOVcYQ0ZbSEiQp6JK exUcS8N+zuffVKhJXi+ZdUwwnOFjboZhoFWI5nNkuO6dEziVes/4myhlOQH82qiLtEdl 6a0nsD+0fG6IGkdK6qe1cXGt1avK67r0LlqkX18sqdyOb1gMC9OlOp6oWZL75MlBkduj MnfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TMiiQe8dps8UlLBMP1/FfXowdt6jftkROOTkeidxQ6Q=; b=O6+7qSIrxqaF5jyQ6G/s3cO6fhJd8lnP/SbeI84LB9qmWxY7fcxa739ulxitBNowWY JlgIDPdlQIrFZpG33SqPwGFnNl65t+jHERaLDtR08l83fZ5zJ4xqu+pHnWff+j1VsFAi YvWi5YSCdfLJnS1JQPKouRAbZhK2SjJo14u7789+gxHha/fdh8E/SOY8Fs+eceProk1G sWdmsFc4dRc+rgeOrCpO1A8cpxSJLVAX6QCGfLZ31HWW7fZB6hUm6eZi0frphCG/C6TQ kfL1/I+wSPdKl1/69qgvTGu8YG4bg6Ees0iScpA54Rr/yFulkc8eNHKicYDM+/DPava4 H/lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MCRqykL9; 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 k7si2257806edo.371.2020.11.09.03.34.42; Mon, 09 Nov 2020 03:35:06 -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=MCRqykL9; 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 S1729537AbgKILc4 (ORCPT + 99 others); Mon, 9 Nov 2020 06:32:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729442AbgKILcv (ORCPT ); Mon, 9 Nov 2020 06:32:51 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6122DC0613D3 for ; Mon, 9 Nov 2020 03:32:51 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id c16so7604134wmd.2 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=c5iPIY91n5HnVdCoQWvrD3p+loGzIh7/iwqVaQBv/cUqFhrAsIvQd+TLS4aKOuFllT PwrniPjsg/TNI3vYtnCbeCkIs7QcjmnufzPohsyJR5lmISdVY6lGjEdp/LJB1YhYGQXO zEbt5ZnYw0AhX+CvRYHI9tJXMwk5X5MQJ1r/UUoTEavIAE3vDOt5PP5Q5Gahxfu4CnmZ tBGoRCelFaXVZqy3HETewiaLrTxfFTMNOloNttGE3FRxt5pBYeHdfPFKmJX/7OK/dbcM C3mDhQj0rLvSHu3b7b1feRefVKBLwLf4gQ1w/JonwehimIpsLn725TZGiPtBBA5dQM1r 90xg== X-Gm-Message-State: AOAM5329rCdGDYG6b2k6tL4LE+0pOkAKjz/nVwB9Cp1v/2UCGVuGHt9b PrqxbZhJR24hBjKlt5anPfI5uA== 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Quentin Perret , Andrew Scull , Andrew Walbran , kernel-team@android.com, David Brazdil 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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) } -- 2.29.2.222.g5d2a92d10f8-goog