xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Paul Durrant <Paul.Durrant@citrix.com>, Jan Beulich <JBeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Keir (Xen.org)" <keir@xen.org>
Subject: Re: [PATCH v6 02/16] x86/hvm: remove multiple open coded 'chunking' loops
Date: Wed, 8 Jul 2015 17:43:58 +0100	[thread overview]
Message-ID: <559D534E.7030704@citrix.com> (raw)
In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02F4A5B79@AMSPEX01CL03.citrite.net>

On 08/07/2015 16:57, Paul Durrant wrote:
>> -----Original Message-----
>> From: xen-devel-bounces@lists.xen.org [mailto:xen-devel-
>> bounces@lists.xen.org] On Behalf Of Jan Beulich
>> Sent: 08 July 2015 16:53
>> To: Andrew Cooper; Paul Durrant
>> Cc: xen-devel@lists.xenproject.org; Keir (Xen.org)
>> Subject: Re: [Xen-devel] [PATCH v6 02/16] x86/hvm: remove multiple open
>> coded 'chunking' loops
>>
>>>>> On 03.07.15 at 18:25, <paul.durrant@citrix.com> wrote:
>>> +static int hvmemul_linear_mmio_access(
>>> +    unsigned long gla, unsigned int size, uint8_t dir, uint8_t *buffer,
>>> +    uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, bool_t
>> known_gpfn)
>>> +{
>>> +    struct hvm_vcpu_io *vio = &current->arch.hvm_vcpu.hvm_io;
>>> +    unsigned long offset = gla & ~PAGE_MASK;
>>> +    unsigned int chunk;
>>> +    paddr_t gpa;
>>> +    unsigned long one_rep = 1;
>>> +    int rc;
>>> +
>>> +    chunk = min_t(unsigned int, size, PAGE_SIZE - offset);
>>> +
>>> +    if ( known_gpfn )
>>> +        gpa = pfn_to_paddr(vio->mmio_gpfn) | offset;
>>> +    else
>>> +    {
>>> +        rc = hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec,
>>> +                                    hvmemul_ctxt);
>>> +        if ( rc != X86EMUL_OKAY )
>>> +            return rc;
>>> +    }
>>> +
>>> +    for ( ;; )
>>> +    {
>>> +        rc = hvmemul_phys_mmio_access(gpa, chunk, dir, buffer);
>>> +        if ( rc != X86EMUL_OKAY )
>>> +            break;
>>> +
>>> +        gla += chunk;
>>> +        buffer += chunk;
>>> +        size -= chunk;
>>> +
>>> +        if ( size == 0 )
>>> +            break;
>>> +
>>> +        ASSERT((gla & ~PAGE_MASK) == 0);
>> Does this really matter for the code below?
>>
>>> +        chunk = min_t(unsigned int, size, PAGE_SIZE);
>> Iirc Andrew had asked for this, but I still don't see why: "size" is the
>> width of an instruction operand, and hence won't even come close
>> to PAGE_SIZE.

The original version of the code asserted that size was less than
PAGE_SIZE around here.  This is not true in the general case, given a
for loop like this and can in principle be hit if we ever got into a
position of emulating an xsave instruction to an MMIO region.

This specific example is not as far fetched as it seems.  The VM
instrospection people are looking to emulate more and more instructions,
while the GVT-g are working on the mmio_write_dm side of things which
causes real RAM to be treated as MMIO from Xens point of view.

If we had some blanket sanity checks for size at the top of the
emulation calltree it would be less of an issue, but we don't and I have
a nagging feeing that assumptions like this are going to bite us in an
XSA-kind-of-way.

~Andrew

  parent reply	other threads:[~2015-07-08 16:44 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-03 16:25 [PATCH v6 00/16] x86/hvm: I/O emulation cleanup and fix Paul Durrant
2015-07-03 16:25 ` [PATCH v6 01/16] x86/hvm: make sure emulation is retried if domain is shutting down Paul Durrant
2015-07-03 16:25 ` [PATCH v6 02/16] x86/hvm: remove multiple open coded 'chunking' loops Paul Durrant
2015-07-03 17:17   ` Andrew Cooper
2015-07-08 15:52   ` Jan Beulich
2015-07-08 15:57     ` Paul Durrant
2015-07-08 16:18       ` Jan Beulich
2015-07-08 16:43       ` Andrew Cooper [this message]
2015-07-09  6:53         ` Jan Beulich
2015-07-09  8:15           ` Paul Durrant
2015-07-09  9:19             ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 03/16] x86/hvm: change hvm_mmio_read_t and hvm_mmio_write_t length argument Paul Durrant
2015-07-03 16:25 ` [PATCH v6 04/16] x86/hvm: restrict port numbers to uint16_t and sizes to unsigned int Paul Durrant
2015-07-08 15:57   ` Jan Beulich
2015-07-08 15:59     ` Paul Durrant
2015-07-03 16:25 ` [PATCH v6 05/16] x86/hvm: unify internal portio and mmio intercepts Paul Durrant
2015-07-08 16:11   ` Jan Beulich
2015-07-08 16:28   ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 06/16] x86/hvm: add length to mmio check op Paul Durrant
2015-07-03 16:25 ` [PATCH v6 07/16] x86/hvm: unify dpci portio intercept with standard portio intercept Paul Durrant
2015-07-08 16:29   ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 08/16] x86/hvm: unify stdvga mmio intercept with standard mmio intercept Paul Durrant
2015-07-08 16:17   ` Jan Beulich
2015-07-09  9:40     ` Paul Durrant
2015-07-09  8:53   ` Jan Beulich
2015-07-09  9:00     ` Paul Durrant
2015-07-09  9:21       ` Jan Beulich
2015-07-09  9:17   ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 09/16] x86/hvm: limit reps to avoid the need to handle retry Paul Durrant
2015-07-03 17:18   ` Andrew Cooper
2015-07-09 10:05   ` Jan Beulich
2015-07-09 11:11     ` Paul Durrant
2015-07-09 12:04       ` Jan Beulich
2015-07-09 12:50         ` Paul Durrant
2015-07-09 13:38           ` Jan Beulich
2015-07-09 13:42             ` Paul Durrant
2015-07-09 14:00             ` Paul Durrant
2015-07-09 14:19               ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 10/16] x86/hvm: only call hvm_io_assist() from hvm_wait_for_io() Paul Durrant
2015-07-03 16:25 ` [PATCH v6 11/16] x86/hvm: split I/O completion handling from state model Paul Durrant
2015-07-09 10:09   ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 12/16] x86/hvm: remove HVMIO_dispatched I/O state Paul Durrant
2015-07-09 10:13   ` Jan Beulich
2015-07-03 16:25 ` [PATCH v6 13/16] x86/hvm: remove hvm_io_state enumeration Paul Durrant
2015-07-03 16:25 ` [PATCH v6 14/16] x86/hvm: use ioreq_t to track in-flight state Paul Durrant
2015-07-03 16:25 ` [PATCH v6 15/16] x86/hvm: always re-emulate I/O from a buffer Paul Durrant
2015-07-03 16:25 ` [PATCH v6 16/16] x86/hvm: track large memory mapped accesses by buffer offset Paul Durrant
2015-07-09 10:33   ` Jan Beulich
2015-07-09 10:36     ` Paul Durrant
2015-07-09 10:34   ` Jan Beulich
2015-07-08 15:44 ` [PATCH v6 00/16] x86/hvm: I/O emulation cleanup and fix Jan Beulich
2015-07-09 11:31   ` Paul Durrant
2015-07-09 11:43     ` David Vrabel

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=559D534E.7030704@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=Paul.Durrant@citrix.com \
    --cc=keir@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 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).