xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: xen-devel@lists.xenproject.org,
	Andrii Anisov <Andrii_Anisov@epam.com>,
	Oleksandr_Tyshchenko@epam.com
Subject: Re: [Xen-devel] [PATCH MM-PART3 v2 12/12] xen/arm: mm: Remove set_pte_flags_on_range()
Date: Thu, 13 Jun 2019 09:51:10 +0100	[thread overview]
Message-ID: <9624343c-38ff-08bc-ec38-b46929a33843@arm.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1906121535560.13737@sstabellini-ThinkPad-T480s>

Hi Stefano,

On 6/12/19 11:41 PM, Stefano Stabellini wrote:
> On Tue, 14 May 2019, Julien Grall wrote:
>> set_pte_flags_on_range() is yet another function that will open-code
>> update to a specific range in the Xen page-tables. It can be completely
>> dropped by using either modify_xen_mappings() or destroy_xen_mappings().
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>> Reviewed-by: Andrii Anisov <andrii_anisov@epam.com>
>>
>> ---
>>      Changes in v2:
>>          - Add missing newline in panic
>>          - Add Andrii's reviewed-by
>> ---
>>   xen/arch/arm/mm.c | 58 ++++++++++---------------------------------------------
>>   1 file changed, 10 insertions(+), 48 deletions(-)
>>
>> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
>> index 23ca61e8f0..d74101bcd2 100644
>> --- a/xen/arch/arm/mm.c
>> +++ b/xen/arch/arm/mm.c.
>> @@ -1277,52 +1277,6 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags)
>>       return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags);
>>   }
>>   
>> -enum mg { mg_clear, mg_ro, mg_rw, mg_rx };
>> -static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
>> -{
>> -    lpae_t pte;
>> -    int i;
>> -
>> -    ASSERT(is_kernel(p) && is_kernel(p + l));
>> -
>> -    /* Can only guard in page granularity */
>> -    ASSERT(!((unsigned long) p & ~PAGE_MASK));
>> -    ASSERT(!(l & ~PAGE_MASK));
>> -
>> -    for ( i = (p - _start) / PAGE_SIZE;
>> -          i < (p + l - _start) / PAGE_SIZE;
>> -          i++ )
>> -    {
>> -        pte = xen_xenmap[i];
>> -        switch ( mg )
>> -        {
>> -        case mg_clear:
>> -            pte.pt.valid = 0;
>> -            break;
>> -        case mg_ro:
>> -            pte.pt.valid = 1;
>> -            pte.pt.pxn = 1;
>> -            pte.pt.xn = 1;
>> -            pte.pt.ro = 1;
>> -            break;
>> -        case mg_rw:
>> -            pte.pt.valid = 1;
>> -            pte.pt.pxn = 1;
> 
> It shouldn't make any difference, but FYI we don't set pxn in
> xen_pt_update.

Per D5.4.5 in DDI0487D.a, the PXN bit should be RES0 for any stage-1 
that supports only a single VA range.

The hypervisor stage-1 only supports a single VA range (we have only one 
TTBR), so this bit should be RES0. Any other value would be wrong and 
could lead to undefined behavior in the future.

So the current code was wrong. I will mention it in the commit message.

> 
> 
>> -            pte.pt.xn = 1;
>> -            pte.pt.ro = 0;
>> -            break;
>> -        case mg_rx:
>> -            pte.pt.valid = 1;
>> -            pte.pt.pxn = 0;
>> -            pte.pt.xn = 0;
>> -            pte.pt.ro = 1;
>> -            break;
>> -        }
>> -        write_pte(xen_xenmap + i, pte);
>> -    }
>> -    flush_xen_tlb_local();
>> -}
>> -
>>   /* Release all __init and __initdata ranges to be reused */
>>   void free_init_memory(void)
>>   {
>> @@ -1331,8 +1285,12 @@ void free_init_memory(void)
>>       uint32_t insn;
>>       unsigned int i, nr = len / sizeof(insn);
>>       uint32_t *p;
>> +    int rc;
>>   
>> -    set_pte_flags_on_range(__init_begin, len, mg_rw);
>> +    rc = modify_xen_mappings((unsigned long)__init_begin,
>> +                             (unsigned long)__init_end, PAGE_HYPERVISOR_RW);
>> +    if ( rc )
>> +        panic("Unable to map RW the init section (rc = %d)\n", rc);
> 
> Like for the previous patch, I wonder if we should replace ASSERTs with
> panics: ASSERTs don't cause issues in non-debug builds. We don't really
> have an "official policy" about this, but I have been going by the rule
> of thumb that ASSERTs are really good to have while we need to be
> careful with BUG_ON/panic because they might introduce instability (see
> Linux policy not to have any.)

We do have a policy docs/misc/xen-error-handling.txt. While I agree that 
we have to be careful with BUG_ON()/panic... you also have to take into 
account from where it is called.

In this case, replacing by an ASSERT here is going to make much worst.
This function is only called once at the end of the boot to remove any 
part of Xen that is not used anymore. If this were to fail, then this 
means that something goes really wrong and this is better to stop here 
rather than continuing with in an unstable state.

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-06-13  8:51 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14 12:31 [PATCH MM-PART3 v2 00/12] xen/arm: Provide a generic function to update Xen PT Julien Grall
2019-05-14 12:31 ` [Xen-devel] " Julien Grall
2019-05-14 12:31 ` [PATCH MM-PART3 v2 01/12] xen/arm: lpae: Add a macro to generate offsets from an address Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 18:21   ` Stefano Stabellini
2019-06-11 18:27     ` Julien Grall
2019-05-14 12:31 ` [PATCH MM-PART3 v2 02/12] xen/arm: mm: Rename create_xen_entries() to xen_pt_update() Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 18:23   ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 18:29   ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 04/12] xen/arm: mm: Only increment mfn when valid in xen_pt_update Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 18:37   ` Stefano Stabellini
2019-06-11 19:56     ` [Xen-devel] Checking INVALID_MFN in mfn_add (WAS: Re: [PATCH MM-PART3 v2 04/12] xen/arm: mm: Only increment mfn when valid in xen_pt_update) Julien Grall
2019-06-11 20:24       ` Andrew Cooper
2019-06-12 12:47         ` Julien Grall
2019-06-12 15:57           ` Stefano Stabellini
2019-06-12  7:53       ` Jan Beulich
2019-05-14 12:31 ` [PATCH MM-PART3 v2 05/12] xen/arm: mm: Introduce _PAGE_PRESENT and _PAGE_POPULATE Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 22:35   ` Stefano Stabellini
2019-06-12 13:00     ` Julien Grall
2019-05-14 12:31 ` [PATCH MM-PART3 v2 06/12] xen/arm: mm: Sanity check any update of Xen page tables Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12  0:10   ` Stefano Stabellini
2019-06-12 14:48     ` Julien Grall
2019-06-12 15:54       ` Stefano Stabellini
2019-06-12 15:58         ` Julien Grall
2019-05-14 12:31 ` [PATCH MM-PART3 v2 07/12] xen/arm: mm: Rework xen_pt_update_entry to avoid use xenmap_operation Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12 22:22   ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 08/12] xen/arm: mm: Remove enum xenmap_operation Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-11 22:38   ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 09/12] xen/arm: mm: Use {, un}map_domain_page() to map/unmap Xen page-tables Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12 22:25   ` Stefano Stabellini
2019-06-13  8:07     ` Julien Grall
2019-06-13 17:55       ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 10/12] xen/arm: mm: Rework Xen page-tables walk during update Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12 22:52   ` Stefano Stabellini
2019-06-13  8:20     ` Julien Grall
2019-06-13 17:59       ` Stefano Stabellini
2019-06-13 21:32         ` Julien Grall
2019-06-13 22:57           ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 11/12] xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap() Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12 22:33   ` Stefano Stabellini
2019-06-13  8:31     ` Julien Grall
2019-06-13 18:51       ` Stefano Stabellini
2019-06-13 21:21         ` Julien Grall
2019-06-13 22:55           ` Stefano Stabellini
2019-05-14 12:31 ` [PATCH MM-PART3 v2 12/12] xen/arm: mm: Remove set_pte_flags_on_range() Julien Grall
2019-05-14 12:31   ` [Xen-devel] " Julien Grall
2019-06-12 22:41   ` Stefano Stabellini
2019-06-13  8:51     ` Julien Grall [this message]
2019-06-13 18:04       ` Stefano Stabellini
2019-06-13 21:22         ` Julien Grall
2019-05-29 17:23 ` [PATCH MM-PART3 v2 00/12] xen/arm: Provide a generic function to update Xen PT Julien Grall
2019-05-29 17:23   ` [Xen-devel] " Julien Grall
2019-06-10 10:08   ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9624343c-38ff-08bc-ec38-b46929a33843@arm.com \
    --to=julien.grall@arm.com \
    --cc=Andrii_Anisov@epam.com \
    --cc=Oleksandr_Tyshchenko@epam.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).