xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Kevin Tian" <kevin.tian@intel.com>, "Wei Liu" <wl@xen.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Julien Grall" <jgrall@amazon.com>, "Tim Deegan" <tim@xen.org>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Jun Nakajima" <jun.nakajima@intel.com>,
	xen-devel@lists.xenproject.org,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH 05/17] xen/x86: Remove the non-typesafe version of pagetable_* helpers
Date: Sat, 28 Mar 2020 10:52:30 +0000	[thread overview]
Message-ID: <2be87441-05a6-6b58-23e3-da467230ffe7@xen.org> (raw)
In-Reply-To: <b0d29ded-f0e8-013b-de43-22788cd8f599@suse.com>

Hi Jan,

On 26/03/2020 15:39, Jan Beulich wrote:
> On 22.03.2020 17:14, julien@xen.org wrote:
>> --- a/xen/arch/x86/domain.c
>> +++ b/xen/arch/x86/domain.c
>> @@ -952,25 +952,27 @@ int arch_set_info_guest(
>>       }
>>       else
>>       {
>> -        unsigned long pfn = pagetable_get_pfn(v->arch.guest_table);
>> +        mfn_t mfn = pagetable_get_mfn(v->arch.guest_table);
>>           bool fail;
>>   
>>           if ( !compat )
>>           {
>> -            fail = xen_pfn_to_cr3(pfn) != c.nat->ctrlreg[3];
>> +            fail = mfn_to_cr3(mfn) != c.nat->ctrlreg[3];
> 
> The patch, besides a few other comments further down, looks fine
> on its own, but I don't think it can be acked without seeing the
> effects of the adjustments pending to the patch introducing
> mfn_to_cr3() and friends.
> 
>> @@ -3116,24 +3116,24 @@ int vcpu_destroy_pagetables(struct vcpu *v)
>>   
>>       /* Free that page if non-zero */
>>       do {
>> -        if ( mfn )
>> +        if ( !mfn_eq(mfn, _mfn(0)) )
> 
> I admit I'm not fully certain either, but at the first glance
> 
>          if ( mfn_x(mfn) )
> 
> would seem more in line with the original code to me (and then
> also elsewhere).

It is doing *exactly* the same things. The whole point of typesafe is to 
use typesafe helper not open-coding test everywhere.

It is also easier to spot any use of MFN 0 within the code as you know 
could grep "_mfn(0)".

Therefore I will insist to the code as-is.

> 
>> @@ -3560,19 +3561,18 @@ long do_mmuext_op(
>>               if ( unlikely(rc) )
>>                   break;
>>   
>> -            old_mfn = pagetable_get_pfn(curr->arch.guest_table_user);
>> +            old_mfn = pagetable_get_mfn(curr->arch.guest_table_user);
>>               /*
>>                * This is particularly important when getting restarted after the
>>                * previous attempt got preempted in the put-old-MFN phase.
>>                */
>> -            if ( old_mfn == op.arg1.mfn )
>> +            if ( mfn_eq(old_mfn, new_mfn) )
>>                   break;
>>   
>> -            if ( op.arg1.mfn != 0 )
>> +            if ( !mfn_eq(new_mfn, _mfn(0)) )
> 
> At least here I would clearly prefer the old code to be kept.

See above.

> 
>> @@ -3580,19 +3580,19 @@ long do_mmuext_op(
>>                       else if ( rc != -ERESTART )
>>                           gdprintk(XENLOG_WARNING,
>>                                    "Error %d installing new mfn %" PRI_mfn "\n",
>> -                                 rc, op.arg1.mfn);
>> +                                 rc, mfn_x(new_mfn));
> 
> Here I'm also not sure I see the point of the conversion.

op.arg1.mfn and mfn are technically not the same type. The former is a 
xen_pfn_t, whilst the latter is mfn_t.

In practice they are both unsigned long on x86, so it should be fine to 
use PRI_mfn. However, I think this is an abuse and we should aim to use 
the proper PRI_* for a type.

> 
>> @@ -2351,11 +2351,11 @@ int sh_safe_not_to_sync(struct vcpu *v, mfn_t gl1mfn)
>>       ASSERT(mfn_valid(smfn));
>>   #endif
>>   
>> -    if ( pagetable_get_pfn(v->arch.shadow_table[0]) == mfn_x(smfn)
>> +    if ( mfn_eq(pagetable_get_mfn(v->arch.shadow_table[0]), smfn)
>>   #if (SHADOW_PAGING_LEVELS == 3)
>> -         || pagetable_get_pfn(v->arch.shadow_table[1]) == mfn_x(smfn)
>> -         || pagetable_get_pfn(v->arch.shadow_table[2]) == mfn_x(smfn)
>> -         || pagetable_get_pfn(v->arch.shadow_table[3]) == mfn_x(smfn)
>> +         || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[1]), smfn)
>> +         || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[2]), smfn)
>> +         || mfn_eq(pagetable_get_mfn(v->arch.shadow_table[3]), smfn)
>>   #endif
>>           )
> 
> While here moving the || to their designated places would make
> the code look worse overall, ...
> 
>> @@ -3707,7 +3707,7 @@ sh_update_linear_entries(struct vcpu *v)
>>   
>>       /* Don't try to update the monitor table if it doesn't exist */
>>       if ( shadow_mode_external(d)
>> -         && pagetable_get_pfn(v->arch.monitor_table) == 0 )
>> +         && pagetable_is_null(v->arch.monitor_table) )
> 
> ... could I talk you into moving the && here to the end of the
> previous line, as you're touching this anyway?

I will do.

> 
> Also, seeing there's quite a few conversions to pagetable_is_null()
> and also seeing that this patch is quite big - could this
> conversion be split out?

I will have a look.

> 
>> @@ -213,17 +214,17 @@ static inline l4_pgentry_t l4e_from_paddr(paddr_t pa, unsigned int flags)
>>   #ifndef __ASSEMBLY__
>>   
>>   /* Page-table type. */
>> -typedef struct { u64 pfn; } pagetable_t;
>> -#define pagetable_get_paddr(x)  ((paddr_t)(x).pfn << PAGE_SHIFT)
>> +typedef struct { mfn_t mfn; } pagetable_t;
>> +#define PAGETABLE_NULL_MFN      _mfn(0)
> 
> I'd prefer to get away without this constant.
I would rather keep the constant as it makes easier to understand what 
_mfn(0) means in the context of the pagetable.

Cheers,

-- 
Julien Grall


  reply	other threads:[~2020-03-28 10:53 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22 16:14 [Xen-devel] [PATCH 00/17] Bunch of typesafe conversion julien
2020-03-22 16:14 ` [Xen-devel] [PATCH 01/17] xen/x86: Introduce helpers to generate/convert the CR3 from/to a MFN/GFN julien
2020-03-25 14:46   ` Jan Beulich
2020-03-28 10:14     ` Julien Grall
2020-03-30  7:38       ` Jan Beulich
2020-04-16 11:50         ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 02/17] xen/x86_64: Convert do_page_walk() to use typesafe MFN julien
2020-03-25 14:51   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 03/17] xen/mm: Move the MM types in a separate header julien
2020-03-25 15:00   ` Jan Beulich
2020-03-25 18:09     ` Julien Grall
2020-03-26  9:02       ` Jan Beulich
2020-03-28 10:15         ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 04/17] xen: Convert virt_to_mfn() and mfn_to_virt() to use typesafe MFN julien
2020-03-25 15:27   ` Jan Beulich
2020-03-25 18:21     ` Julien Grall
2020-03-26  9:09       ` Jan Beulich
2020-03-28 10:33         ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 05/17] xen/x86: Remove the non-typesafe version of pagetable_* helpers julien
2020-03-26 15:39   ` Jan Beulich
2020-03-28 10:52     ` Julien Grall [this message]
2020-03-30  7:52       ` Jan Beulich
2020-04-18 10:23         ` Julien Grall
2020-04-20  9:16           ` Jan Beulich
2020-04-20 10:10             ` Julien Grall
2020-04-20 12:14               ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 06/17] xen/x86: mm: Fix the comment on top put_page_from_l2e() to use 'mfn' julien
2020-03-26 15:51   ` Jan Beulich
2020-04-18 10:54     ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 07/17] xen/x86: traps: Convert __page_fault_type() to use typesafe MFN julien
2020-03-26 15:54   ` Jan Beulich
2020-04-18 11:01     ` Julien Grall
2020-04-18 11:43       ` Julien Grall
2020-04-20  9:19         ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 08/17] xen/x86: traps: Convert show_page_walk() " julien
2020-03-22 16:14 ` [Xen-devel] [PATCH 09/17] xen/x86: Reduce the number of use of l*e_{from, get}_pfn() julien
2020-03-27 10:52   ` Jan Beulich
2020-03-28 10:53     ` Julien Grall
2020-03-22 16:14 ` [Xen-devel] [PATCH 10/17] xen/x86: pv: Use maddr_to_mfn(...) instead of the open-coding version julien
2020-03-27 11:34   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 11/17] xen/x86: nested_ept: Fix typo in the message in nept_translate_l2ga() julien
2020-03-27 11:35   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 12/17] xen/x86: p2m: Remove duplicate error message in p2m_pt_audit_p2m() julien
2020-03-27 11:35   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 13/17] xen/x86: p2m: Reflow P2M_PRINTK()s " julien
2020-03-27 11:36   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 14/17] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function julien
2020-03-27 12:44   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 15/17] xen/x86: p2m: Rework printk format in audit_p2m() julien
2020-03-27 12:45   ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 16/17] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN julien
2020-03-23 12:11   ` Hongyan Xia
2020-03-23 12:26     ` Julien Grall
2020-03-27 13:15   ` Jan Beulich
2020-03-28 11:14     ` Julien Grall
2020-03-30  8:10       ` Jan Beulich
2020-03-22 16:14 ` [Xen-devel] [PATCH 17/17] xen: Switch parameter in get_page_from_gfn to use typesafe gfn julien
2020-03-23  8:37   ` Paul Durrant
2020-03-23 10:26     ` Julien Grall
2020-03-27 13:50   ` Jan Beulich
2020-03-27 13:59     ` 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=2be87441-05a6-6b58-23e3-da467230ffe7@xen.org \
    --to=julien@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=roger.pau@citrix.com \
    --cc=tim@xen.org \
    --cc=wl@xen.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).