xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>, Paul Durrant <paul.durrant@citrix.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v2 2/2] x86/hvm/emulate: make sure rep I/O emulation does not cross GFN boundaries
Date: Wed, 15 Aug 2018 13:46:27 +0100	[thread overview]
Message-ID: <28dabc69-e7bd-ebda-e39d-036e7b1d933e@citrix.com> (raw)
In-Reply-To: <5B741F9302000078001DE5C5@prv1-mh.provo.novell.com>

On 15/08/18 13:41, Jan Beulich wrote:
>>>> On 10.08.18 at 16:48, <paul.durrant@citrix.com> wrote:
>> When emulating a rep I/O operation it is possible that the ioreq will
>> describe a single operation that spans multiple GFNs. This is fine as long
>> as all those GFNs fall within an MMIO region covered by a single device
>> model, but unfortunately the higher levels of the emulation code do not
>> guarantee that. This is something that should almost certainly be fixed,
>> but in the meantime this patch makes sure that MMIO is truncated at GFN
>> boundaries and hence the appropriate device model is re-evaluated for each
>> target GFN.
>>
>> NOTE: This patch does not deal with the case of a single MMIO operation
>>       spanning a GFN boundary. That is more complex to deal with and is
>>       deferred to a subsequent patch.
>>
>> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> with a type change request:
>
>> --- a/xen/arch/x86/hvm/emulate.c
>> +++ b/xen/arch/x86/hvm/emulate.c
>> @@ -184,6 +184,25 @@ static int hvmemul_do_io(
>>          hvmtrace_io_assist(&p);
>>      }
>>  
>> +    /*
>> +     * Make sure that we truncate rep MMIO at any GFN boundary. This is
>> +     * necessary to ensure that the correct device model is targetted
>> +     * or that we correctly handle a rep op spanning MMIO and RAM.
>> +     */
>> +    if ( unlikely(p.count > 1) && p.type == IOREQ_TYPE_COPY )
>> +    {
>> +        unsigned long off = p.addr & ~PAGE_MASK;
> If this was "unsigned int", all calculations below could be slightly
> cheaper 32-bit ones and ...
>
>> +        if ( PAGE_SIZE - off < p.size ) /* single rep spans GFN */
>> +            p.count = 1;
>> +        else
>> +            p.count = min_t(unsigned long,
> ... this could be just min(), as long as ...
>
>> +                            p.count,
>> +                            ((p.df ? (off + p.size) : (PAGE_SIZE - off)) /
> ... the 3rd arg of the ?: gets cast to unsigned int. If you agree, I'd
> be fine doing the adjustments while committing.

Paul is OoO for a while now.  In lieu, I'd say "yes please" to these
suggestions.

~Andrew

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

  reply	other threads:[~2018-08-15 12:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 14:48 [PATCH v2 0/2] MMIO emulation fixes Paul Durrant
2018-08-10 14:48 ` [PATCH v2 1/2] x86/hvm/ioreq: MMIO range checking completely ignores direction flag Paul Durrant
2018-08-10 14:48 ` [PATCH v2 2/2] x86/hvm/emulate: make sure rep I/O emulation does not cross GFN boundaries Paul Durrant
2018-08-15 12:41   ` Jan Beulich
2018-08-15 12:46     ` Andrew Cooper [this message]
2018-08-16  7:33   ` Jan Beulich
2018-08-23  8:47     ` Paul Durrant

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=28dabc69-e7bd-ebda-e39d-036e7b1d933e@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=paul.durrant@citrix.com \
    --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 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).