From: Yu Zhang <yu.c.zhang@linux.intel.com>
To: Jan Beulich <JBeulich@suse.com>, Paul Durrant <paul.durrant@citrix.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, zhiyuan.lv@intel.com,
Jun Nakajima <jun.nakajima@intel.com>
Subject: Re: [PATCH v5 3/4] x86/ioreq server: Add HVMOP to map guest ram with p2m_ioreq_server to an ioreq server.
Date: Tue, 9 Aug 2016 15:39:38 +0800 [thread overview]
Message-ID: <57A988BA.5020104@linux.intel.com> (raw)
In-Reply-To: <57A8C4270200007800103E80@prv-mh.provo.novell.com>
On 8/8/2016 11:40 PM, Jan Beulich wrote:
>>>> On 12.07.16 at 11:02, <yu.c.zhang@linux.intel.com> wrote:
>> @@ -178,8 +179,34 @@ static int hvmemul_do_io(
>> break;
>> case X86EMUL_UNHANDLEABLE:
>> {
>> - struct hvm_ioreq_server *s =
>> - hvm_select_ioreq_server(curr->domain, &p);
>> + struct hvm_ioreq_server *s;
>> +
>> + if ( is_mmio )
>> + {
>> + unsigned long gmfn = paddr_to_pfn(addr);
>> + p2m_type_t p2mt;
>> +
>> + (void) get_gfn_query_unlocked(currd, gmfn, &p2mt);
>> +
>> + if ( p2mt == p2m_ioreq_server )
>> + {
>> + unsigned int flags;
>> +
>> + if ( dir != IOREQ_WRITE )
>> + s = NULL;
>> + else
>> + {
>> + s = p2m_get_ioreq_server(currd, &flags);
>> +
>> + if ( !(flags & P2M_IOREQ_HANDLE_WRITE_ACCESS) )
>> + s = NULL;
>> + }
>> + }
>> + else
>> + s = hvm_select_ioreq_server(currd, &p);
>> + }
>> + else
>> + s = hvm_select_ioreq_server(currd, &p);
> Wouldn't it both be more natural and make the logic even easier
> to follow if s got set to NULL up front, all the "else"-s dropped,
> and a simple
>
> if ( !s )
> s = hvm_select_ioreq_server(currd, &p);
>
> be done in the end?
Thanks, Jan. I'll have a try.
>> @@ -5447,6 +5452,21 @@ static int hvmop_set_mem_type(
>> if ( !is_hvm_domain(d) )
>> goto out;
>>
>> + if ( a.hvmmem_type == HVMMEM_ioreq_server )
>> + {
>> + unsigned int flags;
>> + struct hvm_ioreq_server *s;
>> +
>> + /* HVMMEM_ioreq_server is only supported for HAP enabled hvm. */
>> + if ( !hap_enabled(d) )
>> + goto out;
>> +
>> + /* Do not change to HVMMEM_ioreq_server if no ioreq server mapped. */
>> + s = p2m_get_ioreq_server(d, &flags);
>> + if ( s == NULL )
>> + goto out;
> Either drop s as an intermediate variable altogether (preferred), or
> constify it properly.
Got it.
>> +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_HVMOP_IOREQ_MEM_ACCESS_WRITE) )
>> + return -EINVAL;
>> +
>> + spin_lock(&d->arch.hvm_domain.ioreq_server.lock);
> This lock did get converted to a recursive one a little while back.
Oh. I see, should use the spin_lock_recursive/spin_unlock_recursive
pair. Thanks.
>> + rc = -ENOENT;
>> + list_for_each_entry ( s,
>> + &d->arch.hvm_domain.ioreq_server.list,
>> + list_entry )
>> + {
>> + if ( s == d->arch.hvm_domain.default_ioreq_server )
>> + continue;
>> +
>> + if ( s->id == id )
>> + {
>> + rc = p2m_set_ioreq_server(d, flags, s);
>> + if ( rc == 0 )
>> + dprintk(XENLOG_DEBUG, "%u %s type HVMMEM_ioreq_server.\n",
>> + s->id, (flags != 0) ? "mapped to" : "unmapped from");
> Is this really useful?
Sorry, are you referring to this debug message?
I believe it helps, especially when multiple ioreq servers are
claiming/disclaiming their ownership of
the HVMMEM_ioreq_server. :)
>> --- a/xen/arch/x86/mm/p2m-ept.c
>> +++ b/xen/arch/x86/mm/p2m-ept.c
>> @@ -132,6 +132,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 & P2M_IOREQ_HANDLE_WRITE_ACCESS);
>> + entry->x = 0;
>> + entry->a = !!cpu_has_vmx_ept_ad;
>> + entry->d = entry->w && cpu_has_vmx_ept_ad;
> For self-consistency, could this become
>
> entry->d = entry->w && entry->a;
>
> ?
Yep. Thanks. :)
>> --- a/xen/arch/x86/mm/shadow/multi.c
>> +++ b/xen/arch/x86/mm/shadow/multi.c
>> @@ -3225,8 +3225,7 @@ static int sh_page_fault(struct vcpu *v,
>> }
>>
>> /* Need to hand off device-model MMIO to the device model */
>> - if ( p2mt == p2m_mmio_dm
>> - || (p2mt == p2m_ioreq_server && ft == ft_demand_write) )
>> + if ( p2mt == p2m_mmio_dm )
> Could you remind me again what the code being removed here gets
> replaced by, or why it doesn't need any replacement?
HVMMEM_ioreq_server is now only supported for HAP enabled hvm, so
shadow code
does not need to handle this p2m type.
>> @@ -336,6 +336,23 @@ struct p2m_domain {
>> struct ept_data ept;
>> /* NPT-equivalent structure could be added here. */
>> };
>> +
>> + struct {
>> + spinlock_t lock;
>> + /*
>> + * ioreq server who's responsible for the emulation of
>> + * gfns with specific p2m type(for now, p2m_ioreq_server).
>> + */
>> + struct hvm_ioreq_server *server;
>> + /*
>> + * flags specifies whether read, write or both operations
>> + * are to be emulated by an ioreq server.
>> + */
>> + unsigned int flags;
>> +
>> +#define P2M_IOREQ_HANDLE_WRITE_ACCESS XEN_HVMOP_IOREQ_MEM_ACCESS_WRITE
>> +#define P2M_IOREQ_HANDLE_READ_ACCESS XEN_HVMOP_IOREQ_MEM_ACCESS_READ
> I think I did say so on a previous iteration already: I can't see the
> value of these two defines, or in fact I can see these being actively
> dangerous: The rest of your patch assume that each pair shares
> their values (as there's no translation between them, but also no
> BUILD_BUG_ON() ensuring they're identical).
Oh. I thought it was a coding style issue we were discussing -
previously, there was a
#define using the <underscore><uppercase> pattern, which should be
deprecated.
For the P2M_IOREQ_HANDLE_WRITE/READ_ACCESS definition, I agree they can
be removed.
>
>> --- a/xen/include/public/hvm/hvm_op.h
>> +++ b/xen/include/public/hvm/hvm_op.h
>> @@ -89,7 +89,9 @@ typedef enum {
>> HVMMEM_unused, /* Placeholder; setting memory to this type
>> will fail for code after 4.7.0 */
>> #endif
>> - HVMMEM_ioreq_server
>> + HVMMEM_ioreq_server /* Memory type claimed by an ioreq server; type
>> + changes to this value are only allowed after
>> + an ioreq server has claimed its ownership. */
> Wouldn't it be worth also noting in the comment that only changes
> to/from rw are permitted?
>
OK. Will add this comment in next version.
Yu
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-09 7:39 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 9:02 [PATCH v5 0/4] x86/ioreq server: Introduce HVMMEM_ioreq_server mem type Yu Zhang
2016-07-12 9:02 ` [PATCH v5 1/4] x86/ioreq server: Rename p2m_mmio_write_dm to p2m_ioreq_server Yu Zhang
2016-07-12 9:02 ` [PATCH v5 2/4] x86/ioreq server: Add new functions to get/set memory types Yu Zhang
2016-07-12 9:02 ` [PATCH v5 3/4] x86/ioreq server: Add HVMOP to map guest ram with p2m_ioreq_server to an ioreq server Yu Zhang
2016-08-08 15:40 ` Jan Beulich
2016-08-09 7:39 ` Yu Zhang [this message]
2016-08-09 8:11 ` Jan Beulich
2016-08-09 8:20 ` Paul Durrant
2016-08-09 8:51 ` Yu Zhang
2016-08-09 9:07 ` Paul Durrant
2016-08-10 8:09 ` Yu Zhang
2016-08-10 10:33 ` Jan Beulich
2016-08-10 10:43 ` Paul Durrant
2016-08-10 12:32 ` Yu Zhang
2016-08-10 10:43 ` Yu Zhang
2016-08-11 8:47 ` Yu Zhang
2016-08-11 8:58 ` Jan Beulich
2016-08-11 9:19 ` Yu Zhang
2016-07-12 9:02 ` [PATCH v5 4/4] x86/ioreq server: Reset outstanding p2m_ioreq_server entries when an ioreq server unmaps Yu Zhang
2016-08-08 16:29 ` Jan Beulich
2016-08-09 7:39 ` Yu Zhang
2016-08-09 8:13 ` Jan Beulich
2016-08-09 9:25 ` Yu Zhang
2016-08-09 9:45 ` Jan Beulich
2016-08-09 10:21 ` Yu Zhang
2016-08-16 13:35 ` George Dunlap
2016-08-16 13:54 ` Jan Beulich
2016-08-30 12:17 ` Yu Zhang
2016-09-02 11:00 ` Yu Zhang
2016-08-05 2:44 ` [PATCH v5 0/4] x86/ioreq server: Introduce HVMMEM_ioreq_server mem type Yu Zhang
2016-08-05 6:16 ` Jan Beulich
2016-08-05 12:46 ` George Dunlap
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=57A988BA.5020104@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 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.