From nobody Fri May 17 17:25:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1660676440; cv=none; d=zohomail.com; s=zohoarc; b=H63pln1D4F2XILqybu7/pL0w2EQDw52oi1kZQw+8KBqERngS68ye8tBjwU5QLhDWwqSexv7M5ymKJx41jsELgur2ZsmxksGrho7b69kaYPwU8NtCSIiPVATOmsBQSBGceDX8GIXXXgCIMtlBM6cRL9mbObxL3keak7H/GHnVdyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660676440; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=D98GVDZfQ8TCxXBLkFuwake+DQisiai93uMoMlFu4B0=; b=AT3NlYkZu/m+essgActnMB284XsAOnvbD5QlfL5Ls98apykapJkH8bFZOY9a9+87yqC8dC4VgMKQwODprBbgiHzFwm5dSSFY7pMZQGlf/xegh3HWfOWH3jzEwB4Uj6x1Rj92X2R4Z/e2QnRvLOyO8KaKEgbtvcwjFLQjsiDHoLs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1660676440026860.6174789226404; Tue, 16 Aug 2022 12:00:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.388498.625160 (Exim 4.92) (envelope-from ) id 1oO1nC-00059W-MQ; Tue, 16 Aug 2022 18:59:58 +0000 Received: by outflank-mailman (output) from mailman id 388498.625160; Tue, 16 Aug 2022 18:59:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oO1nC-00059P-Ji; Tue, 16 Aug 2022 18:59:58 +0000 Received: by outflank-mailman (input) for mailman id 388498; Tue, 16 Aug 2022 18:59:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oO1nB-00059H-Ax for xen-devel@lists.xenproject.org; Tue, 16 Aug 2022 18:59:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oO1nB-0004Pk-0e; Tue, 16 Aug 2022 18:59:57 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oO1nA-0001Am-O1; Tue, 16 Aug 2022 18:59:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=D98GVDZfQ8TCxXBLkFuwake+DQisiai93uMoMlFu4B0=; b=OISsjH fAKMW6PRWj6Oo5hq+5kicslYSUXJO5gJYxnlhM6jKmLnwKEXB4EOjChVZnuq6v3e8WhfzazCXYaZ/ VtNrkOyX9cwj84dnsexNHlXn48Cu39hLNcSFGuQEzKsom+DjSBJ8AoOnhewGTTA4AsguX5zY55Zzk FwFOUrBoARc=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH for-4.17] xen/arm: Support properly __ro_after_init on Arm Date: Tue, 16 Aug 2022 19:59:54 +0100 Message-Id: <20220816185954.31945-1-julien@xen.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1660676440811100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall __ro_after_init was introduced recently to prevent modifying some variables after init. At the moment, on Arm, the variables will still be accessible because the region permission is not updated. Address that, but moving the sections .data.ro_after_init out of .data and then mark the region read-only once we finish to boot. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis Reviewed-by: Penny Zheng Tested-by: Henry Wang --- This patch is targeting Xen 4.17. There are quite a few arm specific variables that could be switch to use __ro_after_init. This is not addressed by the commit. We could consider to switch some of them for Xen 4.17. So the benefits for now is any common variables using __ro_after_init. --- xen/arch/arm/include/asm/setup.h | 2 ++ xen/arch/arm/setup.c | 14 ++++++++++++++ xen/arch/arm/xen.lds.S | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 2bb01ecfa88f..5815ccf8c5cc 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -137,6 +137,8 @@ u32 device_tree_get_u32(const void *fdt, int node, int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, void *data); =20 +extern const char __ro_after_init_start[], __ro_after_init_end[]; + #endif /* * Local variables: diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 500307edc08d..5bde321b9d07 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -75,10 +75,24 @@ domid_t __read_mostly max_init_domid; =20 static __used void init_done(void) { + int rc; + /* Must be done past setting system_state. */ unregister_init_virtual_region(); =20 free_init_memory(); + + /* + * We have finished to boot. Mark the section .data.ro_after_init + * read-only. + */ + rc =3D modify_xen_mappings((unsigned long)&__ro_after_init_start, + (unsigned long)&__ro_after_init_end, + PAGE_HYPERVISOR_RO); + if ( rc ) + panic("Unable to mark the .data.ro_after_init section read-only (r= c =3D %d)\n", + rc); + startup_cpu_idle_loop(); } =20 diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 1e986e211f68..92c298405259 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -83,6 +83,13 @@ SECTIONS _erodata =3D .; /* End of read-only data */ =20 . =3D ALIGN(PAGE_SIZE); + .data.ro_after_init : { + __ro_after_init_start =3D .; + *(.data.ro_after_init) + . =3D ALIGN(PAGE_SIZE); + __ro_after_init_end =3D .; + } : text + .data.read_mostly : { /* Exception table */ __start___ex_table =3D .; --=20 2.37.1