All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Jann Horn <jannh@google.com>, Tim Deegan <tim@xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v2] x86/mm: also flush TLB when putting writable foreign page reference
Date: Tue, 25 Apr 2017 05:59:10 -0600	[thread overview]
Message-ID: <58FF562E0200007800153E6D@prv-mh.provo.novell.com> (raw)
In-Reply-To: <20170425105954.GB43635@deinos.phlegethon.org>

>>> On 25.04.17 at 12:59, <tim@xen.org> wrote:
> Hi,
> 
> At 02:59 -0600 on 25 Apr (1493089158), Jan Beulich wrote:
>> Jann's explanation of the problem:
>> 
>> "start situation:
>>  - domain A and domain B are PV domains
>>  - domain A and B both have currently scheduled vCPUs, and the vCPUs
>>    are not scheduled away
>>  - domain A has XSM_TARGET access to domain B
>>  - page X is owned by domain B and has no mappings
>>  - page X is zeroed
>> 
>>  steps:
>>  - domain A uses do_mmu_update() to map page X in domain A as writable
>>  - domain A accesses page X through the new PTE, creating a TLB entry
>>  - domain A removes its mapping of page X
>>    - type count of page X goes to 0
>>    - tlbflush_timestamp of page X is bumped
>>  - domain B maps page X as L1 pagetable
>>    - type of page X changes to PGT_l1_page_table
>>    - TLB flush is forced using domain_dirty_cpumask of domain B
>>    - page X is mapped as L1 pagetable in domain B
>> 
>>  At this point, domain B's vCPUs are guaranteed to have no
>>  incorrectly-typed stale TLB entries for page X, but AFAICS domain A's
>>  vCPUs can still have stale TLB entries that map page X as writable,
>>  permitting domain A to control a live pagetable of domain B."
> 
> AIUI this patch solves the problem by immediately flushing domain A's
> TLB entries at the point where domain A removes its mapping of page X.
> 
> Could we, instead, bitwise OR domain A's domain_dirty_cpumask into
> domain B's domain_dirty_cpumask at the same point?
> 
> Then when domain B flushes TLBs in the last step (in __get_page_type())
> it will catch any stale TLB entries from domain A as well.  But in the
> (hopefully common) case where there's a delay between domain A's
> __put_page_type() and domain B's __get_page_type(), the usual TLB
> timestamp filtering will suppress some of the IPIs/flushes.

Oh, I see. Yes, I think this would be fine. However, we don't have
a suitable cpumask accessor allowing us to do this ORing atomically,
so we'd have to open code it. Do you think such a slightly ugly
approach would be worth it here? Foreign mappings shouldn't be
_that_ performance critical...

And then, considering that this will result in time stamp based filtering
again, I'm no longer sure I was right to agree with Jann on the flush
here needing to be unconditional. Regardless of page table owner
matching page owner, the time stamp stored for the page will always
be applicable (it's a global property). So we wouldn't even need to
OR in the whole dirty mask here, but could already pre-filter (or if we
stayed with the flush-on-put approach, then v1 would have been
correct).

Jan


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

  reply	other threads:[~2017-04-25 11:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25  8:59 [PATCH v2] x86/mm: also flush TLB when putting writable foreign page reference Jan Beulich
2017-04-25 10:59 ` Tim Deegan
2017-04-25 11:59   ` Jan Beulich [this message]
2017-04-26  8:44     ` Tim Deegan
2017-04-26  9:01       ` Jan Beulich
2017-04-26 14:07   ` Jan Beulich
2017-04-26 14:25     ` Tim Deegan
2017-04-27  9:23       ` Jan Beulich
2017-04-27  9:51         ` Tim Deegan
2017-04-28 10:52           ` Jan Beulich
2017-05-02  8:32             ` Tim Deegan
2017-05-02  8:50               ` Jan Beulich
2017-05-02  9:43                 ` Tim Deegan
2017-05-02 17:37                   ` Andrew Cooper
2017-05-03  7:21                     ` Jan Beulich
2017-05-03  9:55                       ` Andrew Cooper
2017-05-05 18:16                         ` Marcus Granado
2017-05-05 18:29                           ` 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=58FF562E0200007800153E6D@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jannh@google.com \
    --cc=julien.grall@arm.com \
    --cc=tim@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 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.