Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3424668pxb; Mon, 16 Nov 2020 14:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJytDGs7OR9JZjF4G3KyVgfJ3pK1wU++TUiYfLTEnYRPFgGLv0TdWMT+WPl9dva782QNiG/1 X-Received: by 2002:a17:906:c357:: with SMTP id ci23mr15910921ejb.311.1605565764391; Mon, 16 Nov 2020 14:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605565764; cv=none; d=google.com; s=arc-20160816; b=Vkhh99CkEsPLy2Vayid3RLKx9IDlbFMPjLtYMyZyQ8Slhjgi4Gy3Jdw5hLn/BEJEGV oQ+jA3YCSAE2EJO5UGkAdzSd70AR/+aSa/KUvXU1A0vj2fllc5gg9ijlUp/KmxjvDvHD omBVB2nagonE63NdbC1tWytLRCetQt6YjjH7Hl3Uh6m9kSE/RmlHTMFsLi6qWdHmjIq1 hHTpbE1hmqVw4mQCzRA4Or43Ooov3XVy9u/fKEq8hO3sY/4rMPHcmJFQvAHT+LRSX6G5 Jv9Wcpu1JfrY+chA/f5ybzERWpCUF7/CvZyt1dHdQrnZYY8YYwJCjHl4TGskVWqYwxD8 oyvQ== 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=/xSxQ6wMrJch4MkdpKs1AkVDK65s53fUsfBxRtXSdJ0=; b=chFphdjbVmr+dzidxoJGARWFmBTWfIq1nl1J8BdSZ4XeF5YM03y2YFOEKT+B7jdknI 37T3gBvb48gS8r/PZ42LVGWdfBrM6YNPgqpXaEBEygws25/3hEB1OIasrX/qn9X9co+o CFY298IvC10MDJi0z9x4dh/amHmcoqb6nkvyRWy50bSGS9QZ3P1yR6VRub+ykMideHD7 icGAasiun7zb0AlqK1iK5rCwdjWo5bENtfihQsLDl74wNybfCYhr7qR/VDuaTWrLbkkN 5aQV5O1z2CzMUGaE7ju3xH9y9XF+tuu/4CwZuSrNaCPiyG1g7Py7gHY+zlT3ANFuD1rb XHJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m5ieAtIS; 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 ga28si11827029ejc.566.2020.11.16.14.29.01; Mon, 16 Nov 2020 14:29:24 -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=m5ieAtIS; 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 S2387634AbgKPUno (ORCPT + 99 others); Mon, 16 Nov 2020 15:43:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733259AbgKPUnn (ORCPT ); Mon, 16 Nov 2020 15:43:43 -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 9C022C0613CF for ; Mon, 16 Nov 2020 12:43:43 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id d142so589998wmd.4 for ; Mon, 16 Nov 2020 12:43:43 -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=/xSxQ6wMrJch4MkdpKs1AkVDK65s53fUsfBxRtXSdJ0=; b=m5ieAtISL0bm/LUKttamwfLlzhs+j8pVtTzSWO66zpxkqSyqcI9qGCjmMZEITUAsRh yqdiGq+w6rI0GCGo50z0jh68U/2ypSU/r5sGtiGWJw2pmO5VyM0KMM0SeNdtc5WgZzsM hirMis8efojxuO/J5IlkDJ+y9wXS3qa/89kQ2mq7YV6N570irqpYEX257aEHd/E/wn5A v7VtE91FuEp2YqQTS9U57cMquhdQFIHh9s21Z+didm2rlYVIGVYX5gAtB31/xEBm/fTe 5F49guosSVTnCZftqO+UK+EX3tg5d0FaLtNe7b9IcgkySeAZDQRoqZnRIiBAutOTssIs cSWg== 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=/xSxQ6wMrJch4MkdpKs1AkVDK65s53fUsfBxRtXSdJ0=; b=DzYmOhIah8Iq9NjDmoyU55tONPCj1+gbkJXmkFoYhW1zA7efzITHyFW9vzPk3BXvQa LRlJjjfOR69S9YZ5Qx1wkITd6VxTrxQdS6QIFST5RvAZEf7pRTOtra+5DrTzztQqQtcy 93oHSI42qwYLu9AgQ1FfN9/IuPIQDvdL6XKbI9DvQ/5AmdpjEgTM3fSUzzMhO+NmF1bd zTItAaYc60kYRiFSwlmuuD4p4SEwOrm7OzgMX1t6jIlDAbJbXWLhevn4j4OmirGpSMK6 gFzg1YK4QICJWU+hexBLSJpw1cPHjF2CiEsQgrEveoL/tvA1pIENm8okUYssa/01d2HX MDrg== X-Gm-Message-State: AOAM530/oVGRGqW73/WEXt/c1pfiLccOiDTMnwwyt8RAns3TIoAL9DoI QuQsg7iE4QoMp+uG+q8oQqSC8UkfDlQmvQKAx4g= X-Received: by 2002:a1c:44d4:: with SMTP id r203mr743633wma.60.1605559422223; Mon, 16 Nov 2020 12:43:42 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:bc40:bd71:373a:1b33]) by smtp.gmail.com with ESMTPSA id i10sm24457621wrs.22.2020.11.16.12.43.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2020 12:43:41 -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 v2 09/24] kvm: arm64: Add .hyp.data..ro_after_init ELF section Date: Mon, 16 Nov 2020 20:43:03 +0000 Message-Id: <20201116204318.63987-10-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201116204318.63987-1-dbrazdil@google.com> References: <20201116204318.63987-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 4838556920fb..97af6c285f84 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1620,6 +1620,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.299.gdc1121823c-goog