xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Razvan Cojocaru <rcojocaru@bitdefender.com>, xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@intel.com>,
	Tamas K Lengyel <tamas@tklengyel.com>,
	Jan Beulich <jbeulich@suse.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Jun Nakajima <jun.nakajima@intel.com>,
	nd@arm.com
Subject: Re: [PATCH 08/15] xen/x86: p2m: Use typesafe gfn for the P2M callbacks get_entry and set_entry
Date: Wed, 13 Sep 2017 20:32:32 +0100	[thread overview]
Message-ID: <86da1f1f-dce8-1542-acdc-a11e81cb7b11@arm.com> (raw)
In-Reply-To: <6029578a-c722-7f6c-d0e8-9e8fd25199fc@bitdefender.com>

Hi,

On 13/09/2017 20:08, Razvan Cojocaru wrote:
>> @@ -142,7 +142,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
>>                            vm_event_request_t **req_ptr)
>>  {
>>      struct vcpu *v = current;
>> -    unsigned long gfn = gpa >> PAGE_SHIFT;
>> +    gfn_t gfn = gaddr_to_gfn(gpa);
>>      struct domain *d = v->domain;
>>      struct p2m_domain *p2m = NULL;
>>      mfn_t mfn;
>> @@ -215,7 +215,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
>>          *req_ptr = req;
>>
>>          req->reason = VM_EVENT_REASON_MEM_ACCESS;
>> -        req->u.mem_access.gfn = gfn;
>> +        req->u.mem_access.gfn = gfn_x(gfn);
>>          req->u.mem_access.offset = gpa & ((1 << PAGE_SHIFT) - 1);
>>          if ( npfec.gla_valid )
>>          {
>> @@ -247,7 +247,7 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
>>      unsigned long gfn_l = gfn_x(gfn);
>
> I'd drop gfn_l completely here and just use gfn_x(gfn) in the two places
> below where it's used. It would get rid of a line of code in this
> function. But I wouldn't hold the patch over this, so if nobody else has
> comments it's fine as is.

Technically more clean-up could be done in every functions. If you 
noticed it, I kept the changes minimal because this is already a boring 
but necessary job and I really don't want to explore all the possible 
clean-up in each single function... Feel free to do more clean-up.

>>      int rc;
>>
>> -    mfn = ap2m->get_entry(ap2m, gfn_l, &t, &old_a, 0, NULL, NULL);
>> +    mfn = ap2m->get_entry(ap2m, gfn, &t, &old_a, 0, NULL, NULL);
>>
>>      /* Check host p2m if no valid entry in alternate */
>>      if ( !mfn_valid(mfn) )
>> @@ -264,16 +264,16 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
>>          if ( page_order != PAGE_ORDER_4K )
>>          {
>>              unsigned long mask = ~((1UL << page_order) - 1);
>> -            unsigned long gfn2_l = gfn_l & mask;
>> +            gfn_t gfn2 = _gfn(gfn_l & mask);
>>              mfn_t mfn2 = _mfn(mfn_x(mfn) & mask);
>>
>> -            rc = ap2m->set_entry(ap2m, gfn2_l, mfn2, page_order, t, old_a, 1);
>> +            rc = ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, old_a, 1);
>>              if ( rc )
>>                  return rc;
>>          }
>>      }
>>
>> -    return ap2m->set_entry(ap2m, gfn_l, mfn, PAGE_ORDER_4K, t, a,
>> +    return ap2m->set_entry(ap2m, gfn, mfn, PAGE_ORDER_4K, t, a,
>>                           (current->domain != d));
>
> If you need to send V2, could you please also indent the last line so
> that '(' is under the 'a' in 'ap2m'? You don't have to, but it'd be a
> coding style fix coming in on top of this patch.

Will do.

>> diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
>> index 23c0518733..dff214cf7b 100644
>> --- a/xen/arch/x86/mm/p2m-ept.c
>> +++ b/xen/arch/x86/mm/p2m-ept.c
>> @@ -674,11 +674,12 @@ bool_t ept_handle_misconfig(uint64_t gpa)
>>   * Returns: 0 for success, -errno for failure
>>   */
>>  static int
>> -ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
>> +ept_set_entry(struct p2m_domain *p2m, gfn_t gfn_t, mfn_t mfn,
>>                unsigned int order, p2m_type_t p2mt, p2m_access_t p2ma,
>>                int sve)
>>  {
>>      ept_entry_t *table, *ept_entry = NULL;
>> +    unsigned long gfn = gfn_x(gfn_t);
>
> Should we call this gfn_l, as done above?
>
>>      unsigned long gfn_remainder = gfn;
>>      unsigned int i, target = order / EPT_TABLE_ORDER;
>>      unsigned long fn_mask = !mfn_eq(mfn, INVALID_MFN) ? (gfn | mfn_x(mfn)) : gfn;
>> @@ -910,11 +911,12 @@ out:
>>
>>  /* Read ept p2m entries */
>>  static mfn_t ept_get_entry(struct p2m_domain *p2m,
>> -                           unsigned long gfn, p2m_type_t *t, p2m_access_t* a,
>> +                           gfn_t gfn_t, p2m_type_t *t, p2m_access_t* a,
>>                             p2m_query_t q, unsigned int *page_order,
>>                             bool_t *sve)
>>  {
>>      ept_entry_t *table = map_domain_page(_mfn(pagetable_get_pfn(p2m_get_pagetable(p2m))));
>> +    unsigned long gfn = gfn_x(gfn_t);
>
> gfn_l here too?

[...]

>> diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c
>> index 0e63d6ed11..57878b1886 100644
>> --- a/xen/arch/x86/mm/p2m-pt.c
>> +++ b/xen/arch/x86/mm/p2m-pt.c
>> @@ -479,12 +479,13 @@ int p2m_pt_handle_deferred_changes(uint64_t gpa)
>>
>>  /* Returns: 0 for success, -errno for failure */
>>  static int
>> -p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
>> +p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_t, mfn_t mfn,
>>                   unsigned int page_order, p2m_type_t p2mt, p2m_access_t p2ma,
>>                   int sve)
>>  {
>>      /* XXX -- this might be able to be faster iff current->domain == d */
>>      void *table;
>> +    unsigned long gfn = gfn_x(gfn_t);
>
> gfn_l?
>
>>      unsigned long i, gfn_remainder = gfn;
>>      l1_pgentry_t *p2m_entry, entry_content;
>>      /* Intermediate table to free if we're replacing it with a superpage. */
>> @@ -731,11 +732,12 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
>>  }
>>
>>  static mfn_t
>> -p2m_pt_get_entry(struct p2m_domain *p2m, unsigned long gfn,
>> +p2m_pt_get_entry(struct p2m_domain *p2m, gfn_t gfn_t,
>>                   p2m_type_t *t, p2m_access_t *a, p2m_query_t q,
>>                   unsigned int *page_order, bool_t *sve)
>>  {
>>      mfn_t mfn;
>> +    unsigned long gfn = gfn_x(gfn_t);
>
> gfn_l?

If you do that you would have to rename all gfn to gfn_l in the function 
increase a bit more the size of this boring patch. The right solution 
would be to make the rest of the code typesafe, but that's not my plan. 
I have done enough typesafe clean-up myself, so I will leave it with

unsigned long gfn = gfn_x(gfn_);

Until someone step up and decide to do further clean-up.

Cheers,

-- 
Julien Grall

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

  reply	other threads:[~2017-09-13 19:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-13 17:59 [PATCH 00/15] xen/x86: Clean-up the PoD code Julien Grall
2017-09-13 17:59 ` [PATCH 01/15] xen/x86: p2m-pod: Clean-up includes Julien Grall
2017-09-13 17:59 ` [PATCH 02/15] xen/x86: p2m-pod: Remove trailing whitespaces Julien Grall
2017-09-13 17:59 ` [PATCH 03/15] xen/x86: p2m-pod: Fix coding style for comments Julien Grall
2017-09-13 17:59 ` [PATCH 04/15] xen/x86: p2m-pod: Fix coding style Julien Grall
2017-09-13 17:59 ` [PATCH 05/15] xen/x86: p2m-pod: Avoid redundant assignments in p2m_pod_demand_populate Julien Grall
2017-09-13 17:59 ` [PATCH 06/15] xen/x86: p2m-pod: Clean-up use of typesafe MFN Julien Grall
2017-09-13 17:59 ` [PATCH 07/15] xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_decrease_reservation Julien Grall
2017-09-13 17:59 ` [PATCH 08/15] xen/x86: p2m: Use typesafe gfn for the P2M callbacks get_entry and set_entry Julien Grall
2017-09-13 18:22   ` Andrew Cooper
2017-09-13 18:27     ` Julien Grall
2017-09-13 19:10       ` Razvan Cojocaru
2017-09-13 19:08   ` Razvan Cojocaru
2017-09-13 19:32     ` Julien Grall [this message]
2017-09-20  6:57   ` Tian, Kevin
2017-09-13 17:59 ` [PATCH 09/15] xen/x86: p2m: Use typesafe GFN in p2m_set_entry Julien Grall
2017-09-13 20:16   ` Tamas K Lengyel
2017-09-13 17:59 ` [PATCH 10/15] xen/x86: p2m-pod: Use typesafe GFN in pod_eager_record Julien Grall
2017-09-13 17:59 ` [PATCH 11/15] xen/x86: p2m-pod: Clean-up p2m_pod_zero_check Julien Grall
2017-09-13 17:59 ` [PATCH 12/15] xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_zero_check Julien Grall
2017-09-13 17:59 ` [PATCH 13/15] xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_demand_populate Julien Grall
2017-09-13 17:59 ` [PATCH 14/15] xen/x86: p2m-pod: Use typesafe gfn for the fields reclaim_single and max_guest Julien Grall
2017-09-13 17:59 ` [PATCH 15/15] xen/x86: p2m-pod: Rework prototype of p2m_pod_demand_populate Julien Grall
2017-09-13 18:30 ` [PATCH 00/15] xen/x86: Clean-up the PoD code Andrew Cooper

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=86da1f1f-dce8-1542-acdc-a11e81cb7b11@arm.com \
    --to=julien.grall@arm.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=nd@arm.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=tamas@tklengyel.com \
    --cc=xen-devel@lists.xen.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).