xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Yu Zhang <yu.c.zhang@linux.intel.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Tim Deegan <tim@xen.org>,
	xen-devel@lists.xen.org, Paul Durrant <paul.durrant@citrix.com>,
	zhiyuan.lv@intel.com, Jun Nakajima <jun.nakajima@intel.com>
Subject: Re: [PATCH v9 2/5] x86/ioreq server: Add DMOP to map guest ram with p2m_ioreq_server to an ioreq server.
Date: Thu, 23 Mar 2017 11:23:04 +0800	[thread overview]
Message-ID: <58D33F98.4020704@linux.intel.com> (raw)
In-Reply-To: <58D2965D0200007800146496@prv-mh.provo.novell.com>



On 3/22/2017 10:21 PM, Jan Beulich wrote:
>>>> On 21.03.17 at 03:52, <yu.c.zhang@linux.intel.com> wrote:
>> ---
>>   xen/arch/x86/hvm/dm.c            | 37 ++++++++++++++++++--
>>   xen/arch/x86/hvm/emulate.c       | 65 ++++++++++++++++++++++++++++++++---
>>   xen/arch/x86/hvm/ioreq.c         | 38 +++++++++++++++++++++
>>   xen/arch/x86/mm/hap/nested_hap.c |  2 +-
>>   xen/arch/x86/mm/p2m-ept.c        |  8 ++++-
>>   xen/arch/x86/mm/p2m-pt.c         | 19 +++++++----
>>   xen/arch/x86/mm/p2m.c            | 74 ++++++++++++++++++++++++++++++++++++++++
>>   xen/arch/x86/mm/shadow/multi.c   |  3 +-
>>   xen/include/asm-x86/hvm/ioreq.h  |  2 ++
>>   xen/include/asm-x86/p2m.h        | 26 ++++++++++++--
>>   xen/include/public/hvm/dm_op.h   | 28 +++++++++++++++
>>   xen/include/public/hvm/hvm_op.h  |  8 ++++-
>>   12 files changed, 290 insertions(+), 20 deletions(-)
> Btw., isn't there a libdevicemodel wrapper missing here for this new
> sub-op?

Yes. I planed to add the wrapper code in another patch after this series 
is accepted.
Is this a must in this patchset?

>> @@ -177,8 +178,64 @@ static int hvmemul_do_io(
>>           break;
>>       case X86EMUL_UNHANDLEABLE:
>>       {
>> -        struct hvm_ioreq_server *s =
>> -            hvm_select_ioreq_server(curr->domain, &p);
>> +        /*
>> +         * Xen isn't emulating the instruction internally, so see if
>> +         * there's an ioreq server that can handle it. Rules:
>> +         *
>> +         * - PIO and "normal" MMIO run through hvm_select_ioreq_server()
>> +         * to choose the ioreq server by range. If no server is found,
>> +         * the access is ignored.
>> +         *
>> +         * - p2m_ioreq_server accesses are handled by the designated
>> +         * ioreq_server for the domain, but there are some corner
>> +         * cases:
>> +         *
>> +         *   - If the domain ioreq_server is NULL, assume there is a
>> +         *   race between the unbinding of ioreq server and guest fault
>> +         *   so re-try the instruction.
> And that retry won't come back here because of? (The answer
> should not include any behavior added by subsequent patches.)

You got me. :)
In this patch, retry will come back here. It should be after patch 4 or 
patch 5 that the retry
will be ignored(p2m type changed back to p2m_ram_rw after the unbinding).

>> +         */
>> +        struct hvm_ioreq_server *s = NULL;
>> +        p2m_type_t p2mt = p2m_invalid;
>> +
>> +        if ( is_mmio )
>> +        {
>> +            unsigned long gmfn = paddr_to_pfn(addr);
>> +
>> +            get_gfn_query_unlocked(currd, gmfn, &p2mt);
>> +
>> +            if ( p2mt == p2m_ioreq_server )
>> +            {
>> +                unsigned int flags;
>> +
>> +                /*
>> +                 * Value of s could be stale, when we lost a race
>> +                 * with dm_op which unmaps p2m_ioreq_server from the
>> +                 * ioreq server. Yet there's no cheap way to avoid
>> +                 * this, so device model need to do the check.
>> +                 */
>> +                s = p2m_get_ioreq_server(currd, &flags);
>> +
>> +                /*
>> +                 * If p2mt is ioreq_server but ioreq_server is NULL,
>> +                 * we probably lost a race with unbinding of ioreq
>> +                 * server, just retry the access.
>> +                 */
> This repeats the earlier comment - please settle on where to state
> this, but don't say the exact same thing twice within a few lines of
> code.

Thanks, will remove this comment.

>> +                if ( s == NULL )
>> +                {
>> +                    rc = X86EMUL_RETRY;
>> +                    vio->io_req.state = STATE_IOREQ_NONE;
>> +                    break;
>> +                }
>> +            }
>> +        }
>> +
>> +        /*
>> +         * Value of s could be stale, when we lost a race with dm_op
>> +         * which unmaps this PIO/MMIO address from the ioreq server.
>> +         * The device model side need to do the check.
> I think "will do" would be more natural here, or add "anyway" to
> the end of the sentence.
>

Got it. Thanks.

>> @@ -914,6 +916,42 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
>>       return rc;
>>   }
>>   
>> +int hvm_map_mem_type_to_ioreq_server(struct domain *d, ioservid_t id,
>> +                                     uint32_t type, uint32_t flags)
>> +{
>> +    struct hvm_ioreq_server *s;
>> +    int rc;
>> +
>> +    /* For now, only HVMMEM_ioreq_server is supported. */
>> +    if ( type != HVMMEM_ioreq_server )
>> +        return -EINVAL;
>> +
>> +    /* For now, only write emulation is supported. */
>> +    if ( flags & ~(XEN_DMOP_IOREQ_MEM_ACCESS_WRITE) )
> Stray parentheses.

Got it.
>> --- a/xen/arch/x86/mm/hap/nested_hap.c
>> +++ b/xen/arch/x86/mm/hap/nested_hap.c
>> @@ -172,7 +172,7 @@ nestedhap_walk_L0_p2m(struct p2m_domain *p2m, paddr_t L1_gpa, paddr_t *L0_gpa,
>>       if ( *p2mt == p2m_mmio_direct )
>>           goto direct_mmio_out;
>>       rc = NESTEDHVM_PAGEFAULT_MMIO;
>> -    if ( *p2mt == p2m_mmio_dm )
>> +    if ( *p2mt == p2m_mmio_dm || *p2mt == p2m_ioreq_server )
> Btw., how does this addition match up with the rc value being
> assigned right before the if()?

Well returning a NESTEDHVM_PAGEFAULT_MMIO in such case will trigger 
handle_mmio() later in
hvm_hap_nested_page_fault(). Guess that is what we expected.

>> --- a/xen/arch/x86/mm/p2m-ept.c
>> +++ b/xen/arch/x86/mm/p2m-ept.c
>> @@ -131,6 +131,13 @@ static void ept_p2m_type_to_flags(struct p2m_domain *p2m, ept_entry_t *entry,
>>               entry->r = entry->w = entry->x = 1;
>>               entry->a = entry->d = !!cpu_has_vmx_ept_ad;
>>               break;
>> +        case p2m_ioreq_server:
>> +            entry->r = 1;
>> +            entry->w = !(p2m->ioreq.flags & XEN_DMOP_IOREQ_MEM_ACCESS_WRITE);
> Is this effectively open coded p2m_get_ioreq_server() actually
> okay? If so, why does the function need to be used elsewhere,
> instead of doing direct, lock-free accesses?

Maybe your comments is about whether it is necessary to use the lock in 
p2m_get_ioreq_server()?
I still believe so, it does not only protect the value of ioreq server, 
but also the flag together with it.

Besides, it is used not only in the emulation process, but also the 
hypercall to set the mem type.
So the lock can still provide some kind protection against the 
p2m_set_ioreq_server() - even it does
not always do so.

>> +void p2m_destroy_ioreq_server(const struct domain *d,
>> +                              const struct hvm_ioreq_server *s)
>> +{
>> +    struct p2m_domain *p2m = p2m_get_hostp2m(d);
>> +
>> +    spin_lock(&p2m->ioreq.lock);
>> +
>> +    if ( p2m->ioreq.server == s )
>> +    {
>> +        p2m->ioreq.server = NULL;
>> +        p2m->ioreq.flags = 0;
>> +    }
>> +
>> +    spin_unlock(&p2m->ioreq.lock);
>> +}
> Is this function really needed? I.e. can't the caller simply call
> p2m_set_ioreq_server(d, 0, s) instead?

You are right, we can use p2m_set_ioreq_server(d, 0, s). :)

Yu
> Jan
>


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

  reply	other threads:[~2017-03-23  3:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21  2:52 [PATCH v9 0/5] x86/ioreq server: Introduce HVMMEM_ioreq_server mem type Yu Zhang
2017-03-21  2:52 ` [PATCH v9 1/5] x86/ioreq server: Release the p2m lock after mmio is handled Yu Zhang
2017-03-29 13:39   ` George Dunlap
2017-03-29 13:50     ` Jan Beulich
2017-03-21  2:52 ` [PATCH v9 2/5] x86/ioreq server: Add DMOP to map guest ram with p2m_ioreq_server to an ioreq server Yu Zhang
2017-03-22  7:49   ` Tian, Kevin
2017-03-22 10:12     ` Yu Zhang
2017-03-24  9:26       ` Tian, Kevin
2017-03-24 12:34         ` Yu Zhang
2017-03-22 14:21   ` Jan Beulich
2017-03-23  3:23     ` Yu Zhang [this message]
2017-03-23  8:57       ` Jan Beulich
2017-03-24  9:05         ` Yu Zhang
2017-03-24 10:19           ` Jan Beulich
2017-03-24 12:35             ` Yu Zhang
2017-03-24 13:09               ` Jan Beulich
2017-03-21  2:52 ` [PATCH v9 3/5] x86/ioreq server: Handle read-modify-write cases for p2m_ioreq_server pages Yu Zhang
2017-03-22 14:22   ` Jan Beulich
2017-03-21  2:52 ` [PATCH v9 4/5] x86/ioreq server: Asynchronously reset outstanding p2m_ioreq_server entries Yu Zhang
2017-03-21 10:05   ` Paul Durrant
2017-03-22  8:10   ` Tian, Kevin
2017-03-22 10:12     ` Yu Zhang
2017-03-24  9:37       ` Tian, Kevin
2017-03-24 12:45         ` Yu Zhang
2017-03-22 14:29   ` Jan Beulich
2017-03-23  3:23     ` Yu Zhang
2017-03-23  9:00       ` Jan Beulich
2017-03-24  9:05         ` Yu Zhang
2017-03-24 10:37           ` Jan Beulich
2017-03-24 12:36             ` Yu Zhang
2017-03-21  2:52 ` [PATCH v9 5/5] x86/ioreq server: Synchronously reset outstanding p2m_ioreq_server entries when an ioreq server unmaps Yu Zhang
2017-03-21 10:00   ` Paul Durrant
2017-03-21 11:15     ` Yu Zhang
2017-03-21 13:49       ` Paul Durrant
2017-03-21 14:14         ` Yu Zhang
2017-03-22  8:28   ` Tian, Kevin
2017-03-22  8:54     ` Jan Beulich
2017-03-22  9:02       ` Tian, Kevin
2017-03-22 14:39   ` Jan Beulich
2017-03-23  3:23     ` Yu Zhang
2017-03-23  9:02       ` Jan Beulich
2017-03-24  9:05         ` Yu Zhang

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=58D33F98.4020704@linux.intel.com \
    --to=yu.c.zhang@linux.intel.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=paul.durrant@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    --cc=zhiyuan.lv@intel.com \
    /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).