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

Re: [PATCH v3 5/6] xen/arm: mpu: Enable MPU


  • To: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 24 Oct 2024 08:34:20 +0000
  • Accept-language: en-GB, 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=arm.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=arcselector10001; 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=kKGalIxB4zMKgUIqNKlSfKXHEHEYooS/pk7SbzcmLM0=; b=G1aYGK6F5lzBvdIuAWHvfMQ7Wp13GkD3mG5/BTuq1e21cU3/gloAgWEOuc/pyTgxYE99XgSOjk5OC/Ub7YjLJNunETnbLtOPpj0dzWvJh9LWNlkyV4ZB0t8vFTtThPOqnma7n/Ub91P+86mJVuPRqMbQKvWjmR+sgw4h6uP7641oUZhT7JC76fQz0/mHt7i/9+PctGyvlr+866tssHEUgbNIbE5Qtas59ua65AR+pUxeqWYxRpEW4O6ji9J3WTfeSpspwlGoi/zuSzf36I/PpFSnmIs3mwt/+UFoJdWvc4H44ajJhzzgrQcsLPU0BoZQV3moB/u7LLe7AvZ/6LmqlA==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=kKGalIxB4zMKgUIqNKlSfKXHEHEYooS/pk7SbzcmLM0=; b=KisBmlBZxyJUxiE1p+RWgaAAW3umwW58eg65/++8PAjxveZcTgzb3X/rtHRCgy3TmSWwuAsotYKVjuB68dUy1mGrsOGDjWSVOaXhDcIVk/c8JitDvqVqC055a5YBOP5G5mbe1+QzHQw0QyfFwDD26M1aD8n5kEuV9fzhHi2glqrsHsnVevdoaraAw31FJx/1SpuK7Y+NzdxrVzoAh2gCnp9c+BWVmPmewywMvyn8JO+krA80NjUdzS1FoZoF4Njq8J+dVVsYvBzVP8ZCsnNc4mKHJhi9WIGr3HuWPDoI8r2sISdbzbtT/GtyOENQ5Rr6exR67/a1t79PXc62Hna1aw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=MdRI7bzbNI/5V7jarYF1YrGIGW6DRA7GaqKg0L9XJ46DMknVcgz7TaaDDYUqDF3b+NxMWPUfrhCSIMYyVzkm6JtdKgweT6nqgOHWelcZCP0rheiXaJAzTiXJ1CJWGu93tQKVd7oB37Zx3oBGj7w6xx8JkH2vobP4cxiE573xmwmjKkEx/WQaQxMFO4TkOEIkI+mJcAhLBBjpHZhHX/iVI+0W9aqCXiALdkIet9t9fEDzn23Pe98fWpP0j1CprQPKuGi2GpUArUTrpMC2rTCAD33/ONEMPoFtTkC7fURpMF2+MtrbBfLpLEWM0Gdm0mVCUAqYWn0AHiHAIyvFnfbgxg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ppwPGVpVqvTkNqxoEsyvUekL/EtF1Lhm3E6658TDV0MV8fw48fnLiJttnhT0+v3Buw/6E3zCZXWIaqMy3N8+a6u+XYmOVQLDc/HDxbHNcBnZk7xUYyP1bMwUGsfVd8FNICHoeCiLgxHDcAD83Wl0LVp/v0py1OrwtfGd5Cdb3LG3CNmcRyvL4RkU2j2e5YcXNkUmwMeZIofHjC2EhthYmh6ZYkRG4iIjrID5jzeVkVbueXH/ceDE2p8uT5cYjYR2C9m+WPwzqGtvqXFtwb1uMs4Hbj5vFcslJYKJE68SAPcX9H8kYqgyTpc7nW+C8JrLa73ABgDb5q1EZVPLmVbO2w==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 24 Oct 2024 08:35:02 +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: AQHbGx2Ge9N55hTx/U2iD9lYiTVQprKNIysAgARC6gCAAA8agIAAAOKAgAEgqoCAAAHOgIAAAmiAgAA3SQCAADcxAIABi38AgAAB0oCAAAFRAIAAA2QAgAEElgCAAAi6AA==
  • Thread-topic: [PATCH v3 5/6] xen/arm: mpu: Enable MPU

Hi Ayan,

> On 24 Oct 2024, at 09:02, Ayan Kumar Halder <ayankuma@xxxxxxx> wrote:
> 
> Hi Julien,
> 
> On 23/10/2024 17:30, Julien Grall wrote:
>> 
>> 
>> On 23/10/2024 17:18, Julien Grall wrote:
>>> 
>>> 
>>> On 23/10/2024 17:13, Julien Grall wrote:
>>>> 
>>>> 
>>>> On 23/10/2024 17:06, Ayan Kumar Halder wrote:
>>>>> Hi Luca/Julien,
>>>>> 
>>>>> On 22/10/2024 17:31, Luca Fancellu wrote:
>>>>>> Hi Julien,
>>>>>> 
>>>>>>> On 22 Oct 2024, at 14:13, Julien Grall <julien@xxxxxxx> wrote:
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> On 22/10/2024 10:56, Luca Fancellu wrote:
>>>>>>>>> On 22 Oct 2024, at 10:47, Julien Grall <julien@xxxxxxx> wrote:
>>>>>>>>> 
>>>>>>>>> Hi Luca,
>>>>>>>>> 
>>>>>>>>> On 22/10/2024 10:41, Luca Fancellu wrote:
>>>>>>>>>>> On 21 Oct 2024, at 17:27, Julien Grall <julien@xxxxxxx> wrote:
>>>>>>>>>> 2) dsb+isb barrier after enabling the MPU, since we are enabling the 
>>>>>>>>>> MPU but also because we are disabling the background region
>>>>>>>>> TBH, I don't understand this one. Why would disabling the background 
>>>>>>>>> region requires a dsb + isb? Do you have any pointer in the Armv8-R 
>>>>>>>>> specification?
>>>>>>>> I’m afraid this is only my deduction, Section C1.4 of the Arm® 
>>>>>>>> Architecture Reference Manual Supplement Armv8, for R-profile AArch64 
>>>>>>>> architecture,
>>>>>>>> (DDI 0600B.a) explains what is the background region, it says it 
>>>>>>>> implements physical address range(s), so when we disable it, we would 
>>>>>>>> like any data
>>>>>>>> access to complete before changing this implementation defined range 
>>>>>>>> with the ranges defined by us tweaking PRBAR/PRLAR, am I right?
>>>>>>> My mental model for the ordering is similar to a TLB flush which is:
>>>>>>>    1/ dsb nsh
>>>>>>>    2/ tlbi
>>>>>>>    3/ dsb nsh
>>>>>>>    4/ isb
>>>>>>> 
>>>>>>> Enabling the MPU is effectively 2. AFAIK, 1 is only necessary to ensure 
>>>>>>> the update to the page-tables. But it is not a requirement to ensure 
>>>>>>> any data access are completed (otherwise, we would have needed a dsb sy 
>>>>>>> because we don't know how far the access are going...).
>>>>>> Uhm… I’m not sure we are on the same page, probably I explained that 
>>>>>> wrongly, so my point is that:
>>>>>> 
>>>>>> FUNC_LOCAL(enable_mpu)
>>>>>>      mrs   x0, SCTLR_EL2
>>>>>>      bic   x0, x0, #SCTLR_ELx_BR       /* Disable Background region */
>>>>>>      orr   x0, x0, #SCTLR_Axx_ELx_M    /* Enable MPU */
>>>>>>      orr   x0, x0, #SCTLR_Axx_ELx_C    /* Enable D-cache */
>>>>>>      orr   x0, x0, #SCTLR_Axx_ELx_WXN  /* Enable WXN */
>>>>>>      dsb   sy
>>>>>>      ^— This data barrier is needed in order to complete any data 
>>>>>> access, which guarantees that all explicit memory accesses before
>>>>>>             this instruction complete, so we can safely turn ON the MPU 
>>>>>> and disable the background region.
>>>> 
>>>> I think
>>> 
>>> Sorry I fat fingered and pressed send too early. I think this is the part I 
>>> disagree with. All explicit accesses don't need to be complete (in the 
>>> sense observed by everyone in the system). They only need to have gone 
>>> through the permissions check.
>> 
>> I think I managed to find again the wording that would justify why a "dsb" 
>> is not necessary for the permission checks. From ARM DDI 0487K.a D23-7349:
>> 
>> ```
>> Direct writes using the instructions in Table D22-2 require synchronization 
>> before software can rely on the effects
>> of changes to the System registers to affect instructions appearing in 
>> program order after the direct write to the
>> System register. Direct writes to these registers are not allowed to affect 
>> any instructions appearing in program order
>> before the direct write.
>> ```
>> 
>> I understand the paragraph as enabling the MPU via SCTLR_EL2 will not affect 
>> any instruction before hand.
> 
> Yes, I agree.
> 
> However, as the line states
> 
> "Direct writes using the instructions in Table D22-2 require synchronization 
> before software can rely on the effects"
> 
> This means synchronization is required after the write to SCTLR_EL2.
> 
> However, this synchronization seems to imply dsb sy + isb.
> 
> FromARM DDI 0487K.a ID032224 B2-274
> 
> "A DSB instruction ordered after a direct write to a System PMU register does 
> not complete until all observers observe the direct write"

I think this is related only to the System PMU register, not to the registers 
in table D22-2 (which SCTLR_ELx are part)

Anyway we could discuss this in person at the Xen meet-up and write a summary 
in the thread later.

Cheers,
Luca


 


Rackspace

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