All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kai Huang <kai.huang@linux.intel.com>
To: Tim Deegan <tim@xen.org>
Cc: "andrew.cooper3@citrix.com" <andrew.cooper3@citrix.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"jbeulich@suse.com" <jbeulich@suse.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [v2 06/11] vmx: add help functions to support PML
Date: Fri, 17 Apr 2015 17:29:23 +0800	[thread overview]
Message-ID: <5530D273.3010200@linux.intel.com> (raw)
In-Reply-To: <20150417083657.GA13724@deinos.phlegethon.org>



On 04/17/2015 04:36 PM, Tim Deegan wrote:
> At 11:32 +0800 on 17 Apr (1429270332), Kai Huang wrote:
>>
>> On 04/17/2015 08:10 AM, Tim Deegan wrote:
>>> At 22:57 +0000 on 16 Apr (1429225024), Tian, Kevin wrote:
>>>
>>>>> From: Kai Huang [mailto:kai.huang@linux.intel.com]
>>>>> +        if ( !p2m_change_type_one(v->domain, gfn, p2m_ram_logdirty,
>>>>> +                    p2m_ram_rw) )
>>>>> +            paging_mark_gfn_dirty(v->domain, gfn);
>>>> Should we handle error from p2m_change_type_one and consequently
>>>> making this flush function non-void?
>>> I don't think we need to return an error, but we should probably
>>> call mark_dirty here for anything except -EBUSY.
>> Hi Kevin, Tim,
>>
>> My intention here is to rule out the GFN with original type that is not
>> p2m_ram_logdirty, though with patch 11 it's not likely have such GFN
>> logged.
>>
>> Looks -EBUSY returns exactly when original type is not p2m_ram_logdirty,
>> so I think it might be OK to do as Tim suggested.
>>
>> But given the same thing has already been done in hap_track_dirty_vram
>> (hap_track_dirty_vram->paging_log_dirty_range, in which gfn is set in
>> bitmap with !p2m_change_type_one is true), and in EPT violation
>> (p2m_change_type_one is called unconditionally without checking return
>> value), I think it should be safe to do the current code here.
> The paging_log_dirty_range case is doing something quite different:
> it is making pages read-only so they can be tracked, and it needs to
> mark any page that couldn't be made read-only (because the guest can
> write to them).
Thanks for comprehensive reply. However, looks I can't agree on some points.

paging_log_dirty_range currently is only used by hap_track_dirty_vram 
for video ram tracking, and it doesn't call paging_mark_dirty in any 
case. Basically, paging_log_dirty_range only does below thing but 
nothing else:

     for ( i = 0, pfn = begin_pfn; pfn < begin_pfn + nr; i++, pfn++ )
         if ( !p2m_change_type_one(d, pfn, p2m_ram_rw, p2m_ram_logdirty) )
             dirty_bitmap[i >> 3] |= (1 << (i & 7));

 From which we can see the purpose of this function (and let us put PML 
away for now):

     - change GFN's type from p2m_ram_rw back to p2m_ram_logdirty, in 
order to be able to log the GFN again (more precisely, to track the GFN 
again in EPT violation), with the fact that the dirty page's p2m type 
has been changed from p2m_log_dirty to p2m_ram_rw, in EPT violation.
     - mark the dirty GFN to the bitmap only when above changing 
p2m_ram_logdirty to p2m_ram_rw is done successfully. It is reasonable, 
as only a successful changing from p2m_ram_rw to p2m_ram_dirty means the 
dirty page has been changed from p2m_ram_logdirty to p2m_ram_rw in EPT 
violation.

Btw, from which we can also note that currently video ram tracking is 
not via log-dirty radix tree but depends on p2m type change, this is the 
reason we must call p2m_type_change_one in vmx_vcpu_flush_pml_buffer.

> Its three cases are:
>   - change succeeded: no mark, we will trap any new writes
>   - EBUSY: mark, since we can't be sure we'll trap new writes
>   - other error: mark, since we can't be sure we'll trap new writes
Regarding to the above three cases, I assume you are referring to 
changing p2m_ram_rw back to p2m_ram_logdirty in paging_log_dirty_range , 
in which case the paging_mark_dirty is not called at all, as I mentioned 
above.

>
> In this case we _know_ the guest has written to the page (because it's
> in the PML log), so our only reason for not calling mark_dirty() is
> if we see that someone else has changed the p2m (EBUSY) and that
> someone else ought to already have DTRT.
I agree on this, given you said we can't be sure for the unsuccessful 
p2m type change.

>
> Now that I've written it out, and since we expect these races to be
> very rare, I've changed my mind: we should _always_ call mark_dirty
> here.  The extra cost should be negligible, and a missing mark is
> extremely difficult to debug.
Which is also good to me, and in this case we should also call 
p2m_change_type_one(.., p2m_ram_logdirty, p2m_ram_rw) unconditionally, 
as this is required for video ram tracking.

Thanks,
-Kai
>
> Cheers,
>
> Tim.

  reply	other threads:[~2015-04-17  9:29 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15  7:03 [v2 00/11] PML (Paging Modification Logging) support Kai Huang
2015-04-15  7:03 ` [v2 01/11] vmx: add new boot parameter to control PML enabling Kai Huang
2015-04-15 10:12   ` Andrew Cooper
2015-04-15 12:20   ` Jan Beulich
2015-04-15 13:20     ` Kai Huang
2015-04-15 13:47       ` Jan Beulich
2015-04-15  7:03 ` [v2 02/11] doc: add description for new PML boot parameter Kai Huang
2015-04-15 10:15   ` Andrew Cooper
2015-04-15 12:17     ` Jan Beulich
2015-04-16  4:47     ` Kai Huang
2015-04-16 14:49       ` Andrew Cooper
2015-04-15  7:03 ` [v2 03/11] log-dirty: add new paging_mark_gfn_dirty Kai Huang
2015-04-15  7:03 ` [v2 04/11] vmx: add PML definition and feature detection Kai Huang
2015-04-16 22:35   ` Tian, Kevin
2015-04-17  2:14     ` Kai Huang
2015-04-15  7:03 ` [v2 05/11] vmx: add new data structure member to support PML Kai Huang
2015-04-16 15:33   ` Jan Beulich
2015-04-17  2:12     ` Kai Huang
2015-04-16 22:39   ` Tian, Kevin
2015-04-17  2:31     ` Kai Huang
2015-04-21  6:04       ` Kai Huang
2015-04-21 13:10         ` Tian, Kevin
2015-04-15  7:03 ` [v2 06/11] vmx: add help functions " Kai Huang
2015-04-16 15:42   ` Jan Beulich
2015-04-17  3:10     ` Kai Huang
2015-04-17  6:23       ` Jan Beulich
2015-04-17  6:51         ` Kai Huang
2015-04-17  6:58           ` Jan Beulich
2015-04-17  7:23             ` Kai Huang
2015-04-17  7:37               ` Jan Beulich
2015-04-17  7:45                 ` Kai Huang
2015-04-24  6:32                 ` Kai Huang
2015-04-24  7:30                   ` Jan Beulich
2015-04-24  7:41                     ` Kai Huang
2015-04-16 22:57   ` Tian, Kevin
2015-04-17  0:10     ` Tim Deegan
2015-04-17  3:32       ` Kai Huang
2015-04-17  8:36         ` Tim Deegan
2015-04-17  9:29           ` Kai Huang [this message]
2015-04-20  8:29             ` Tim Deegan
2015-04-20 10:08               ` Kai Huang
2015-04-20 10:13                 ` Tim Deegan
2015-04-17  3:15     ` Kai Huang
2015-04-16 22:59   ` Tian, Kevin
2015-04-15  7:03 ` [v2 07/11] vmx: handle PML buffer full VMEXIT Kai Huang
2015-04-15  7:03 ` [v2 08/11] vmx: handle PML enabling in vmx_vcpu_initialise Kai Huang
2015-04-15  7:03 ` [v2 09/11] vmx: disable PML in vmx_vcpu_destroy Kai Huang
2015-04-15  7:03 ` [v2 10/11] log-dirty: refine common code to support PML Kai Huang
2015-04-16 15:51   ` Jan Beulich
2015-04-16 23:07     ` Tian, Kevin
2015-04-17  2:47       ` Kai Huang
2015-04-17  2:46     ` Kai Huang
2015-04-17  6:28       ` Jan Beulich
2015-04-17  6:55         ` Kai Huang
2015-04-15  7:03 ` [v2 11/11] p2m/ept: enable PML in p2m-ept for log-dirty Kai Huang
2015-04-16 15:54   ` Jan Beulich
2015-04-17  2:40     ` Kai Huang
2015-04-17  6:28       ` Jan Beulich
2015-04-17  7:10         ` Kai Huang
2015-04-17  7:33           ` Jan Beulich
2015-04-16 14:41 ` [v2 00/11] PML (Paging Modification Logging) support Tim Deegan
2015-04-16 15:18   ` Kai Huang

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=5530D273.3010200@linux.intel.com \
    --to=kai.huang@linux.intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=tim@xen.org \
    --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 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.