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

Re: [PATCH v8 3/8] xen/arm: Fold mmu_init_secondary_cpu() to head.S


  • To: Julien Grall <julien@xxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Wed, 1 Nov 2023 01:58:27 +0000
  • Accept-language: zh-CN, 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=6KCbIKvw7NtC/SYBt4hbAUM1pSPcvUI4IQb0RDApCGs=; b=Oqaf2IO3jQNO5xj/Y9iAJA9n7B0pUac9GkFFdIHNZzvBIvOK8AdBFWgTdUnk5qTJpVuh5aKMdF3c8D5CLySY+wWint57wdU8F16mNh+IpXBs/6Vvi/eOiZ6qA2petbcCKyX1caWoxl3uaIrnivBYpExIXg0qG+0IUGT/9OJRIiI4jBaYdav98PmILnBPVOz85bVpgW8ZYseiJ+h/NJx+rT4tgiAqGjhAKwFVYedDNwFOWlpRDEbZGcPjqbQar4aWRFvhIziEtz26L2GrdgiR58RZw30En29dd4LwJkjKmGzjPSrM4P57mgJeHMOBHh9sO2m48QYK8+YaUGKYFJH8eQ==
  • 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=6KCbIKvw7NtC/SYBt4hbAUM1pSPcvUI4IQb0RDApCGs=; b=jeCz4wRSKaRmW8LPvb/VPTm/C6ykZvm1WGvPudo0bi3dwSqFIjBkluqpTz5/JMTu4qeD5DHIub7PQ46RXrdVty3dCzshohbRE8aLsULX7YP4AH9N1nm+NNXJtBma9WXVs7rnVsOm7P7EzFudNhITgD6DPkLlmbaz39LrFUucwzT8RBQx+NF9tIFw7+KBMElhmXbxghR+XIXoYEU/rw0APUxogoI2iesdyMicFbSS/HzMHqABUlfRQ2bwuziUK0HOpg6QsbJ9KEUkAtnVLePmABVbOg3J1PAN6PoqVPmoQf3ilyq1m3BgnWjrbdhb5wKSv19EiB0Po+VRrNrD6NQrzw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=G7NB9oYTKqIezzSWB+4Jv2HYYmy7WYERwM3P3v2RVPrZeeiBj6ICce6GeMHgAtx80HWI3AaMAXTIrZCXxtxcywr6jOHNVLUCo70i3LwxNcyUuSoU1RtDJTvLtoJmKymX+pr0S1n9X/qUiU33EsRNCE5DuWrPhNN5xDBp2Wnhn8OkXu4lw0crHndIh71S5696p1J3Y5W4yncz0uAlZuXiYBgvx5JAznGVc0lA6krVp91PGlBukOXrOHq0N6FUz/y1BQyul3V16ORM7uoWM3zs/ry59UJW3O65JeVGdFwNm3vkwsE8ob3G90Gde5CP+bwjsgaCXBaOm5++wVfTKjukcQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UQlzgUPeNyjilR7wm8I4zlzocv1A4kRRiTyJPxjHBFNRbymML2T4qTOyE1/Li40RscVFzwik5VTsJq+GSpxp0LUalQ7H4bsLapsbLvfErRDumM53TceRpyOVyHIlwFlB1rG7gKsmCzDWNX0MRsHjrLbLlexguZHQMewOTCkJmft+mWyHbxQ3NRcxEyks5QAH37bZEtTQkO7uRMpND1zcPVmnzKhP8VVuv7BVgOuuW3uOCi9YRiH7FATwca5qeb5nThbVM6qBPilPRtXMvb03GhC4el9TgW7giGmqK4ynCCFA+XSz4WvK240ZyIiuFIsnCrXxu/y9u/kDGsxAYTVkBw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Julien Grall <jgrall@xxxxxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Wed, 01 Nov 2023 01:59:01 +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: AQHaBVagUvAeq6Jj0E+dI1rvNGdSyLBkRaEAgAB9cwA=
  • Thread-topic: [PATCH v8 3/8] xen/arm: Fold mmu_init_secondary_cpu() to head.S

Hi Julien,

> On Nov 1, 2023, at 02:29, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Henry,
> 
> +Ayan
> 
> On 23/10/2023 03:13, Henry Wang wrote:
>> Currently mmu_init_secondary_cpu() only enforces the page table
>> should not contain mapping that are both Writable and eXecutables
>> after boot. To ease the arch/arm/mm.c split work, fold this function
>> to head.S.
>> For arm32, introduce an assembly macro pt_enforce_wxn. The macro is
>> called before secondary CPUs jumping into the C world.
>> For arm64, set the SCTLR_Axx_ELx_WXN flag right when the MMU is
>> enabled. This would avoid the extra TLB flush and SCTLR dance.
> 
> For a random reader, it is not clear why you can't set WnX early for arm32 as 
> well. I think it would helpful to explain the difference. I.e. at the point 
> the MMU is enabled, the page-tables may still contain mapping which are 
> writable and executable.

Sounds good, I will add the suggested sentence.

>>  .endm
>>  +/*
>> + * Enforce Xen page-tables do not contain mapping that are both
>> + * Writable and eXecutables.
>> + *
>> + * This should be called on each secondary CPU.
>> + */
>> +.macro pt_enforce_wxn tmp
>> +        mrc   CP32(\tmp, HSCTLR)
>> +        orr   \tmp, \tmp, #SCTLR_Axx_ELx_WXN
>> +        dsb
>> +        mcr   CP32(\tmp, HSCTLR)
>> +        /*
>> +         * The TLBs may cache SCTLR_EL2.WXN. So ensure it is synchronized
>> +         * before flushing the TLBs.
>> +         */
>> +        isb
>> +        flush_xen_tlb_local \tmp
>> +.endm
>> +
>>  /*
>>   * Common register usage in this file:
>>   *   r0  -
>> @@ -254,6 +273,7 @@ secondary_switched:
>>          /* Use a virtual address to access the UART. */
>>          mov_w r11, EARLY_UART_VIRTUAL_ADDRESS
>>  #endif
>> +        pt_enforce_wxn r0
> 
> From recent discussion on IRC, Ayan reminded me this patch [1]. Ideally, I 
> would want to print a message just before to indicate that the bit is set. 
> But I understand that this would need to be droppped in Ayan rework as we 
> don't yet support early printk in enable_mmu().
> 
> While debugging an MMU issue on Arm32, I wrote a patch to sprinkle prints in 
> the enable_mmu() code. I will clean-up the patch and send it.

Just to make sure, your patch is for both Arm32 and Arm64, is my understanding 
correct?
If it is only for Arm32, do you need me adding the print for Arm64 as well in 
this patch?

> I will add a print at that point. Meanwhile, I would move the call a few 
> lines above? This will allow Ayan to drop [1].

Yeah I will include Ayan’s change in this patch and add his sign-off.

>>          PRINT("- Ready -\r\n")
>>          /* Jump to C world */
>>          mov_w r2, start_secondary
>> diff --git a/xen/arch/arm/arm64/mmu/head.S b/xen/arch/arm/arm64/mmu/head.S
>> index 88075ef083..df06cefbbe 100644
>> --- a/xen/arch/arm/arm64/mmu/head.S
>> +++ b/xen/arch/arm/arm64/mmu/head.S
>> @@ -264,10 +264,11 @@ ENDPROC(create_page_tables)
>>   * Inputs:
>>   *   x0 : Physical address of the page tables.
> 
> The inputs list should be updated to mention what x1 means.

I will use “x1: Extra flags of the SCTLR.” if this looks good to you.

>>   *
>> - * Clobbers x0 - x4
>> + * Clobbers x0 - x6
> 
> Below, you only seem to introduce x5. So shouldn't this be: "Clobbers x0 - 
> x5"?

Hmmm yes you are correct, I blindly copied the code from [2]. Sorry for the 
mess, I will
correct it in v9.

> Cheers,
> 
> [1] 
> https://lore.kernel.org/all/20230911135942.791206-2-ayan.kumar.halder@xxxxxxx/

[2] 
https://lore.kernel.org/xen-devel/4d7a9849-8990-8ddd-3531-93f4e2e262b1@xxxxxxx/

Kind regards,
Henry

> 
> -- 
> Julien Grall


 


Rackspace

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