[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH for-4.17] xen/arm: Support properly __ro_after_init on Arm


  • To: Julien Grall <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Wed, 17 Aug 2022 06:33:36 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hX4NiNgz/35k5Kn33h5cyAgjRGD3jbW93N2mxUJwnVk=; b=G1Dzyoor/Jb3EEuwEvW8hZbjVa2Sw+SDirYx83G/+WhGR37Dm+ju8uMiTN/+ZK9FTeimX1EwzX7AFUQaXko94TuG09d/3OxL8ReejUq1uTGOT4ACwvqEMaFL47n8bu441s79e/W6MPnoqRnlmvx6PCnJ6d5ktyKhH3Z10YGzBiYTZzFLjUaopVsKqxWXtCrcZ+5WoUHwaHtRbC87JiC32mc8YFmdcsCz6GJmVSLfrGXmyXxCaNMRCajMXC0AeOK+UENrOKwmvi7H15Oxr86BTcZxJNVSLO+miAqjy4mFFjuO+CyNHIqGus7v39aVJmqlKV828+6abuffsWIGmDNdsA==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hX4NiNgz/35k5Kn33h5cyAgjRGD3jbW93N2mxUJwnVk=; b=YDpZouQkN6i5bhOBvlzvMyZGfUIUaCp0ZumYERLS/BPgEuIsooJHx90vvFO7LvhcJZsGZZmxWQdZrvpdM2USEQ3cPhsGbJ+mO0nnc80HPO35YcIAGMHThlW/cINGiNZ7z3+Z9u/enOv1nslLT2+OKmquf6NFRQByJhXNnNKMMqFdOsPli/QKqaXvSxVJ7TsF2E1tj4+uAf8VM0EH+ys6ctbnyNBMgV+fuLBRyqb0qU/BT8l65H6aY6gD4W626JW1561nyYbRnTTy2pPLnEg4dTAnWCqASnjOJCE4aZe8g8yXKczooXX+VBvN3ng/MmNloG7Y7gcwrSWoSjReGGhALw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=i+daGOeFbT/BIR5qu92sBiR+s0gVJvGFwiAoNzi69W6XYGgdd0Qs85LaVzktgDWNWCE8FP8Os3VoBuIJvsFnMv9s/6j+XVQZni2ovESazo+r9je6Ysw6cZehN2oe1rBHuYsvtOQrGZQNmBu8Jns1zM2VKEmBaJ6hO/nK2wWqefzawBJplZisVKg1525ylEDIOLnYGEXuWx/Kz4kg2mpAeJguy2Ok543rpjniXgRxoWRdYgtdAmbaStw6alIOGahXAk5z+7GXQnP7sJ8fr+SnKsPD+Fn2pqe3F/G5swQfOB9M5Udip5XAVlHpV+vz0ATBot3lf5PTdkMa598Li2QC+w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MMIslOvgbxeZMLvP2cyMfXub3ix++DJlDLuXYYpWzk+osqjHyoTo/JyxvwCvhNK5sfudFYEPLm0ko4VualrFXNGlIYYfILZYLnRcUjNRhek8L/7mzSGYFeiNN6RleDp7ZGQT2nnDgSMl4bTmL1aKpeSIjtUXuOw8idOs0t9FSdrnRTpuSyh+GkZwdYK0wdZrdk3S84sEoqSGEsKmc+JyO+E+s2whjbYzRHKBqS5yjpAIH6AmRnQGDbKlABPLKaQwUhYKDcwduwOGK3ONQhpTlCMiu2cSWp3KuhBJEqPBwskKaT8OSqqCkPz1jie6jucCouHm/DOmbN+HqBrp8onHZw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <jgrall@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 17 Aug 2022 06:34:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYsaJ0xhlVHJdhd0SDwNAPSJC5Za2yoEsQ
  • Thread-topic: [PATCH for-4.17] xen/arm: Support properly __ro_after_init on Arm

Hi Julien

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx> On Behalf Of
> Julien Grall
> Sent: Wednesday, August 17, 2022 3:00 AM
> To: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: julien@xxxxxxx; Julien Grall <jgrall@xxxxxxxxxx>; Stefano Stabellini
> <sstabellini@xxxxxxxxxx>; Bertrand Marquis <Bertrand.Marquis@xxxxxxx>;
> Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
> Subject: [PATCH for-4.17] xen/arm: Support properly __ro_after_init on Arm
> 
> From: Julien Grall <jgrall@xxxxxxxxxx>
> 
> __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 <jgrall@xxxxxxxxxx>
> 

Reviewed-by: Penny Zheng <penny.zheng@xxxxxxx>

> ---
> 
> 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/setup.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);
> 
> +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;
> 
>  static __used void init_done(void)
>  {
> +    int rc;
> +
>      /* Must be done past setting system_state. */
>      unregister_init_virtual_region();
> 
>      free_init_memory();
> +
> +    /*
> +     * We have finished to boot. Mark the section .data.ro_after_init
> +     * read-only.
> +     */

Nit: Maybe it is finish + doing, could be wrong, feel free to change or not~~
 
> +    rc = 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 (rc
> = %d)\n",
> +              rc);
> +
>      startup_cpu_idle_loop();
>  }
> 
> 2.37.1
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.