All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Jan Beulich <JBeulich@suse.com>, Tim Deegan <tim@xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH 04/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn
Date: Fri, 10 May 2019 14:07:40 +0100	[thread overview]
Message-ID: <3afc26ea-3cad-fb63-78f3-10084bd4f417@arm.com> (raw)
In-Reply-To: <5CD56B61020000780022D7FB@prv1-mh.provo.novell.com>

Hi Jan,

On 10/05/2019 13:15, Jan Beulich wrote:
>>>> On 07.05.19 at 17:14, <julien.grall@arm.com> wrote:
>> mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former
>> is using mfn_t.
> 
> ... and gfn_t (return type) as of patch 3.
> 
>> Furthermore, the naming of the former is more consistent with the
>> current naming scheme (GFN/MFN). So use replace mfn_to_gmfn with
>> mfn_to_gfn in x86 code.
> 
> Nit: Either "use" or "replace with", but not both.
> 
>> @@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d)
>>       ASSERT( owner == d );
>>   
>>       mfn = page_to_mfn(page);
>> -    gfn = mfn_to_gmfn(d, mfn_x(mfn));
>> +    gfn = mfn_to_gfn(d, mfn);
>>   
>>       /*
>>        * gfn == INVALID_GFN indicates that the shared_info page was never mapped
>>        * to the domain's address space and there is nothing to replace.
>>        */
>> -    if ( gfn == gfn_x(INVALID_GFN) )
>> +    if ( gfn_eq(gfn, INVALID_GFN) )
>>           goto exit_put_page;
>>   
>> -    if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) )
>> +    if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) )
>>       {
>> -        printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n",
>> -               d->domain_id, gfn);
>> +        printk(XENLOG_G_ERR
>> +               "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n",
> 
> I'd recommend to drop the parentheses from the format string at the
> same time.
> 
>> @@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d)
>>       new_page = alloc_domheap_page(d, 0);
>>       if ( !new_page )
>>       {
>> -        printk(XENLOG_G_ERR "Failed to alloc a page to replace"
>> -               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
>> +        printk(XENLOG_G_ERR
>> +               "Failed to alloc a page to replace %pd's shared_info frame %"PRI_gfn"\n",
> 
> s/frame/GFN/ to better match the earlier one? Same in the further log
> messages here then.
> 
>> --- a/xen/arch/x86/mm.c
>> +++ b/xen/arch/x86/mm.c
>> @@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type,
>>   {
>>   #ifdef CONFIG_PV
>>       struct domain *owner = page_get_owner(page);
>> -    unsigned long gmfn;
>>       int rc;
>>   
>>       if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) )
>>       {
>> +        gfn_t gfn;
>> +
>>           /* A page table is dirtied when its type count becomes zero. */
>>           paging_mark_dirty(owner, page_to_mfn(page));
>>   
>>           ASSERT(!shadow_mode_refcounts(owner));
>>   
>> -        gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page)));
>> -        if ( VALID_M2P(gmfn) )
>> -            shadow_remove_all_shadows(owner, _mfn(gmfn));
>> +        gfn = mfn_to_gfn(owner, page_to_mfn(page));
>> +        if ( VALID_M2P(gfn_x(gfn)) )
>> +            shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn)));
>>       }
> 
> This is a highly suspicious change imo (albeit the code was bogus
> already before): It certainly isn't GFN here even if we were to assume
> translated mode could be in use. One other caller of
> the function, sh_page_fault() passes a variable named gmfn as well,
> but typed mfn_t (and this gmfn gets set from get_gfn(), i.e. is _not_
> a GFN). The 3rd one, shadow_prepare_page_type_change(), clearly
> passes an MFN.
> 
> I think the best course of action here is to split out the change,
> just to explain why removing the mfn_to_gmfn() here altogether
> is appropriate nowadays: PV guests can't be in translated mode
> anymore, and hence mfn_to_gmfn() doesn't do any translation. At
> that point the VALID_M2P() check can go away as well, so you'll be
> able to simply do
> 
>          shadow_remove_all_shadows(owner, page_to_mfn(page));
> 
> perhaps with another !shadow_mode_translate() assertion added
> next to the one that's already there. Tim, thoughts?
> 
> With this split out and irrespective of whether you decide to follow
> the format string suggestions further up

I don't have enough experience with x86 to provide the patch you suggest.

I am happy to rebase on top of any patch you provide. Alternatively I can drop 
this and keep mfn_to_gmfn on x86 but replaces the one in common code with 
mfn_to_gfn.

> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Cheers,

-- 
Julien Grall

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

WARNING: multiple messages have this Message-ID (diff)
From: Julien Grall <julien.grall@arm.com>
To: Jan Beulich <JBeulich@suse.com>, Tim Deegan <tim@xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH 04/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn
Date: Fri, 10 May 2019 14:07:40 +0100	[thread overview]
Message-ID: <3afc26ea-3cad-fb63-78f3-10084bd4f417@arm.com> (raw)
Message-ID: <20190510130740.Hcaodxh_cU1w01l1NNSdJmFXvSnH-JH8mZHxwDDaP4E@z> (raw)
In-Reply-To: <5CD56B61020000780022D7FB@prv1-mh.provo.novell.com>

Hi Jan,

On 10/05/2019 13:15, Jan Beulich wrote:
>>>> On 07.05.19 at 17:14, <julien.grall@arm.com> wrote:
>> mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former
>> is using mfn_t.
> 
> ... and gfn_t (return type) as of patch 3.
> 
>> Furthermore, the naming of the former is more consistent with the
>> current naming scheme (GFN/MFN). So use replace mfn_to_gmfn with
>> mfn_to_gfn in x86 code.
> 
> Nit: Either "use" or "replace with", but not both.
> 
>> @@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d)
>>       ASSERT( owner == d );
>>   
>>       mfn = page_to_mfn(page);
>> -    gfn = mfn_to_gmfn(d, mfn_x(mfn));
>> +    gfn = mfn_to_gfn(d, mfn);
>>   
>>       /*
>>        * gfn == INVALID_GFN indicates that the shared_info page was never mapped
>>        * to the domain's address space and there is nothing to replace.
>>        */
>> -    if ( gfn == gfn_x(INVALID_GFN) )
>> +    if ( gfn_eq(gfn, INVALID_GFN) )
>>           goto exit_put_page;
>>   
>> -    if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) )
>> +    if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) )
>>       {
>> -        printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n",
>> -               d->domain_id, gfn);
>> +        printk(XENLOG_G_ERR
>> +               "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n",
> 
> I'd recommend to drop the parentheses from the format string at the
> same time.
> 
>> @@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d)
>>       new_page = alloc_domheap_page(d, 0);
>>       if ( !new_page )
>>       {
>> -        printk(XENLOG_G_ERR "Failed to alloc a page to replace"
>> -               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
>> +        printk(XENLOG_G_ERR
>> +               "Failed to alloc a page to replace %pd's shared_info frame %"PRI_gfn"\n",
> 
> s/frame/GFN/ to better match the earlier one? Same in the further log
> messages here then.
> 
>> --- a/xen/arch/x86/mm.c
>> +++ b/xen/arch/x86/mm.c
>> @@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type,
>>   {
>>   #ifdef CONFIG_PV
>>       struct domain *owner = page_get_owner(page);
>> -    unsigned long gmfn;
>>       int rc;
>>   
>>       if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) )
>>       {
>> +        gfn_t gfn;
>> +
>>           /* A page table is dirtied when its type count becomes zero. */
>>           paging_mark_dirty(owner, page_to_mfn(page));
>>   
>>           ASSERT(!shadow_mode_refcounts(owner));
>>   
>> -        gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page)));
>> -        if ( VALID_M2P(gmfn) )
>> -            shadow_remove_all_shadows(owner, _mfn(gmfn));
>> +        gfn = mfn_to_gfn(owner, page_to_mfn(page));
>> +        if ( VALID_M2P(gfn_x(gfn)) )
>> +            shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn)));
>>       }
> 
> This is a highly suspicious change imo (albeit the code was bogus
> already before): It certainly isn't GFN here even if we were to assume
> translated mode could be in use. One other caller of
> the function, sh_page_fault() passes a variable named gmfn as well,
> but typed mfn_t (and this gmfn gets set from get_gfn(), i.e. is _not_
> a GFN). The 3rd one, shadow_prepare_page_type_change(), clearly
> passes an MFN.
> 
> I think the best course of action here is to split out the change,
> just to explain why removing the mfn_to_gmfn() here altogether
> is appropriate nowadays: PV guests can't be in translated mode
> anymore, and hence mfn_to_gmfn() doesn't do any translation. At
> that point the VALID_M2P() check can go away as well, so you'll be
> able to simply do
> 
>          shadow_remove_all_shadows(owner, page_to_mfn(page));
> 
> perhaps with another !shadow_mode_translate() assertion added
> next to the one that's already there. Tim, thoughts?
> 
> With this split out and irrespective of whether you decide to follow
> the format string suggestions further up

I don't have enough experience with x86 to provide the patch you suggest.

I am happy to rebase on top of any patch you provide. Alternatively I can drop 
this and keep mfn_to_gmfn on x86 but replaces the one in common code with 
mfn_to_gfn.

> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Cheers,

-- 
Julien Grall

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

  reply	other threads:[~2019-05-10 13:07 UTC|newest]

Thread overview: 154+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-07 15:14 [PATCH 00/14] xen/arm: Properly disable M2P on Arm Julien Grall
2019-05-07 15:14 ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 01/14] xen/arm: Use mfn_to_pdx instead of pfn_to_pdx when possible Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-09 17:50   ` Stefano Stabellini
2019-05-09 17:50     ` [Xen-devel] " Stefano Stabellini
2019-05-07 15:14 ` [PATCH 02/14] xen/x86: Constify the parameter "d" in mfn_to_gfn Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-10 11:35   ` Jan Beulich
2019-05-10 11:35     ` [Xen-devel] " Jan Beulich
2019-05-10 13:02     ` Julien Grall
2019-05-10 13:02       ` [Xen-devel] " Julien Grall
2019-05-10 13:24       ` Jan Beulich
2019-05-10 13:24         ` [Xen-devel] " Jan Beulich
2019-05-10 13:25         ` Julien Grall
2019-05-10 13:25           ` [Xen-devel] " Julien Grall
2019-05-20 15:13           ` Julien Grall
2019-05-20 15:13             ` [Xen-devel] " Julien Grall
2019-05-28 17:29             ` George Dunlap
2019-05-28 17:29               ` [Xen-devel] " George Dunlap
2019-05-29 11:39               ` Julien Grall
2019-05-29 11:39                 ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 04/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-10 12:15   ` Jan Beulich
2019-05-10 12:15     ` [Xen-devel] " Jan Beulich
2019-05-10 13:07     ` Julien Grall [this message]
2019-05-10 13:07       ` Julien Grall
2019-05-07 15:14 ` [PATCH 05/14] xen/grant-table: Make arch specific macros typesafe Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-09 17:54   ` Stefano Stabellini
2019-05-09 17:54     ` [Xen-devel] " Stefano Stabellini
2019-05-07 15:14 ` [PATCH 06/14] xen: Convert hotplug page function to use typesafe MFN Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-09 18:01   ` Stefano Stabellini
2019-05-09 18:01     ` [Xen-devel] " Stefano Stabellini
2019-05-09 18:10     ` Julien Grall
2019-05-09 18:10       ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 07/14] xen: Convert is_xen_fixed_mfn " Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-24 15:16   ` George Dunlap
2019-05-24 15:16     ` [Xen-devel] " George Dunlap
2019-05-07 15:14 ` [PATCH 08/14] xen: Convert is_xen_heap_mfn " Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-24 15:15   ` George Dunlap
2019-05-24 15:15     ` [Xen-devel] " George Dunlap
2019-05-07 15:14 ` [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-09 18:06   ` Stefano Stabellini
2019-05-09 18:06     ` [Xen-devel] " Stefano Stabellini
2019-05-09 18:12     ` Julien Grall
2019-05-09 18:12       ` [Xen-devel] " Julien Grall
2019-05-09 18:16       ` Stefano Stabellini
2019-05-09 18:16         ` [Xen-devel] " Stefano Stabellini
2019-05-09 18:29         ` Julien Grall
2019-05-09 18:29           ` [Xen-devel] " Julien Grall
2019-05-09 19:49           ` Stefano Stabellini
2019-05-09 19:49             ` [Xen-devel] " Stefano Stabellini
2019-05-10 12:31   ` Jan Beulich
2019-05-10 12:31     ` [Xen-devel] " Jan Beulich
2019-05-10 13:22     ` Julien Grall
2019-05-10 13:22       ` [Xen-devel] " Julien Grall
2019-05-10 13:32       ` Jan Beulich
2019-05-10 13:32         ` [Xen-devel] " Jan Beulich
2019-05-10 13:41         ` Julien Grall
2019-05-10 13:41           ` [Xen-devel] " Julien Grall
2019-05-10 13:45           ` Jan Beulich
2019-05-10 13:45             ` [Xen-devel] " Jan Beulich
2019-05-10 14:04             ` Julien Grall
2019-05-10 14:04               ` [Xen-devel] " Julien Grall
2019-05-10 14:19               ` Jan Beulich
2019-05-10 14:19                 ` [Xen-devel] " Jan Beulich
2019-05-10 14:34                 ` Julien Grall
2019-05-10 14:34                   ` [Xen-devel] " Julien Grall
2019-05-22 16:03                   ` Julien Grall
2019-05-22 16:03                     ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 10/14] xen: Remove mfn_to_gmfn macro Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-10 12:43   ` Jan Beulich
2019-05-10 12:43     ` [Xen-devel] " Jan Beulich
2019-05-10 13:27     ` Julien Grall
2019-05-10 13:27       ` [Xen-devel] " Julien Grall
2019-05-10 13:35       ` Jan Beulich
2019-05-10 13:35         ` [Xen-devel] " Jan Beulich
2019-05-10 13:41         ` Julien Grall
2019-05-10 13:41           ` [Xen-devel] " Julien Grall
2019-05-10 13:48           ` Jan Beulich
2019-05-10 13:48             ` [Xen-devel] " Jan Beulich
2019-05-10 14:05             ` Julien Grall
2019-05-10 14:05               ` [Xen-devel] " Julien Grall
2019-05-10 14:21               ` Jan Beulich
2019-05-10 14:21                 ` [Xen-devel] " Jan Beulich
2019-05-10 14:48                 ` Julien Grall
2019-05-10 14:48                   ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 12/14] xen/x86: pv: Convert update_intpte() to use typesafe MFN Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-10 12:54   ` Jan Beulich
2019-05-10 12:54     ` [Xen-devel] " Jan Beulich
2019-05-10 13:28     ` Julien Grall
2019-05-10 13:28       ` [Xen-devel] " Julien Grall
2019-05-07 15:14 ` [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() " Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-07 20:27   ` Tamas K Lengyel
2019-05-07 20:27     ` [Xen-devel] " Tamas K Lengyel
2019-05-09 18:19   ` Stefano Stabellini
2019-05-09 18:19     ` [Xen-devel] " Stefano Stabellini
2019-05-10 13:21   ` Jan Beulich
2019-05-10 13:21     ` [Xen-devel] " Jan Beulich
2019-05-10 13:27     ` Andrew Cooper
2019-05-10 13:27       ` [Xen-devel] " Andrew Cooper
2019-05-10 13:34     ` Julien Grall
2019-05-10 13:34       ` [Xen-devel] " Julien Grall
2019-05-10 13:41       ` Jan Beulich
2019-05-10 13:41         ` [Xen-devel] " Jan Beulich
2019-05-10 13:46         ` Julien Grall
2019-05-10 13:46           ` [Xen-devel] " Julien Grall
2019-05-10 14:02           ` Jan Beulich
2019-05-10 14:02             ` [Xen-devel] " Jan Beulich
2019-05-10 14:05             ` Andrew Cooper
2019-05-10 14:05               ` [Xen-devel] " Andrew Cooper
2019-05-10 14:08               ` Julien Grall
2019-05-10 14:08                 ` [Xen-devel] " Julien Grall
2019-05-10 14:09                 ` Andrew Cooper
2019-05-10 14:09                   ` [Xen-devel] " Andrew Cooper
2019-05-10 14:14               ` Jan Beulich
2019-05-10 14:14                 ` [Xen-devel] " Jan Beulich
2019-05-10 14:27                 ` Andrew Cooper
2019-05-10 14:27                   ` [Xen-devel] " Andrew Cooper
2019-05-24 16:24     ` George Dunlap
2019-05-24 16:24       ` [Xen-devel] " George Dunlap
2019-05-29 16:27       ` Julien Grall
2019-05-29 16:27         ` [Xen-devel] " Julien Grall
2019-05-29 16:29         ` George Dunlap
2019-05-29 16:29           ` [Xen-devel] " George Dunlap
2019-05-24 16:35   ` George Dunlap
2019-05-24 16:35     ` [Xen-devel] " George Dunlap
2019-05-07 15:14 ` [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P Julien Grall
2019-05-07 15:14   ` [Xen-devel] " Julien Grall
2019-05-09 18:20   ` Stefano Stabellini
2019-05-09 18:20     ` [Xen-devel] " Stefano Stabellini
2019-05-10 13:28   ` Jan Beulich
2019-05-10 13:28     ` [Xen-devel] " Jan Beulich
2019-05-10 13:29     ` Julien Grall
2019-05-10 13:29       ` [Xen-devel] " Julien Grall
2019-05-10 13:37       ` Jan Beulich
2019-05-10 13:37         ` [Xen-devel] " Jan Beulich
2019-05-10 13:38         ` Julien Grall
2019-05-10 13:38           ` [Xen-devel] " Julien Grall
2019-05-24 16:51   ` George Dunlap
2019-05-24 16:51     ` [Xen-devel] " George Dunlap

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=3afc26ea-3cad-fb63-78f3-10084bd4f417@arm.com \
    --to=julien.grall@arm.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.