All of lore.kernel.org
 help / color / mirror / Atom feed
From: konrad@kernel.org
To: stefano.stabellini@eu.citrix.com, JBeulich@suse.com,
	andrew.cooper3@citrix.com, linux@eikelenboom.it,
	david.vrabel@citrix.com, xen-devel@lists.xenproject.org
Subject: [PATCH QEMU-XEN] xen/pt: Start with emulated PCI_COMMAND set to zero.
Date: Wed, 10 Jun 2015 16:53:11 -0400	[thread overview]
Message-ID: <1433969591-11202-1-git-send-email-konrad@kernel.org> (raw)
In-Reply-To: <5578438C020000780008309D@mail.emea.novell.com>

From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

For a passthrough device we maintain a state of emulated
registers value contained within d->config. We also consult
the host registers (and apply ro and write masks) whenever
the guest access the registers. This is done in xen_pt_pci_write_config
and xen_pt_pci_read_config.

Also in this picture we call pci_default_write_config which
updates the d->config and if the d->config[PCI_COMMAND] register
has PCI_COMMAND_MEMORY (or PCI_COMMAND_IO) acts on those changes.

Which is exactly what we do not want to do for 64-bit BARs
when the guest just wants to read the size of the BAR.

To get the size of 64-bit memory space BARs,  the guest has
to calculate ((BAR[x] & 0xFFFFFFF0) + ((BAR[x+1] & 0xFFFFFFFF) << 32))
which means it has to do two writes of ~0 to BARx and BARx+1.

Since (prior to this patch and with XSA120-addendum patch) the
PCI_COMMAND register is copied from the host it can have
PCI_COMMAND_MEMORY bit set which means that QEMU will try to
update the hypervisor's P2M with BARx+1 value to ~0 (0xffffffff)
instead of just having xen_pt_pci_write_config and xen_pt_bar_reg_write
apply the proper masks and return the size to the guest.

This fixes errors such as these:

(XEN) memory_map:add: dom2 gfn=fffe0 mfn=fbce0 nr=20
(DEBUG) 189 pci dev 04:0 BAR16 wrote ~0.
(DEBUG) 200 pci dev 04:0 BAR16 read 0x0fffe0004.
(XEN) memory_map:remove: dom2 gfn=fffe0 mfn=fbce0 nr=20
(DEBUG) 204 pci dev 04:0 BAR16 wrote 0x0fffe0004.
(DEBUG) 217 pci dev 04:0 BAR16 read upper 0x000000000.
(XEN) memory_map:add: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) p2m.c:883:d0v0 p2m_set_entry failed! mfn=ffffffffffffffff rc:-22
(XEN) memory_map:fail: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20 ret:-22
(XEN) memory_map:remove: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) p2m.c:920:d0v0 gfn_to_mfn failed! gfn=ffffffff00000 type:4
(XEN) p2m.c:920:d0v0 gfn_to_mfn failed! gfn=ffffffff00001 type:4
..
(XEN) memory_map: error -22 removing dom2 access to [fbce0,fbcff]
(DEBUG) 222 pci dev 04:0 BAR16 read upper 0x0ffffffff.
(XEN) memory_map:remove: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) memory_map: error -22 removing dom2 access to [fbce0,fbcff]

[The DEBUG is to illustate what the hvmloader was doing]

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
Suggested-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Suggested-by: Jan Beulich <JBeulich@suse.com>
---
 hw/xen/xen_pt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index 9d2b06b..72f4ca5 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -785,7 +785,9 @@ out:
         xen_host_pci_set_word(&s->real_device, PCI_COMMAND,
                               pci_get_word(d->config + PCI_COMMAND) | cmd);
     }
-
+    /* Until the guest enables the device use d->config values which will
+     * inhibit pci_bar_address & pci_update_mappings from triggering updates.*/
+    pci_set_word(d->config + PCI_COMMAND, 0);
     memory_listener_register(&s->memory_listener, &address_space_memory);
     memory_listener_register(&s->io_listener, &address_space_io);
     XEN_PT_LOG(d,
-- 
1.8.4.2

  parent reply	other threads:[~2015-06-10 19:46 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13  9:39 Dom0 linux 4.0 + devel/for-linus-4.1 branch: p2m.c:884:d0v0 gfn_to_mfn failed! gfn=ffffffff001ed type:4 Sander Eikelenboom
2015-04-13  9:50 ` David Vrabel
2015-04-13 11:21   ` Sander Eikelenboom
2015-04-13 12:07     ` David Vrabel
2015-04-13 12:14       ` Sander Eikelenboom
2015-04-13 12:21         ` David Vrabel
2015-04-13 12:27           ` Sander Eikelenboom
2015-04-13 15:11           ` Sander Eikelenboom
2015-04-14  9:44             ` David Vrabel
2015-04-14 20:42             ` Konrad Rzeszutek Wilk
2015-04-15 15:08               ` Sander Eikelenboom
2015-04-15 20:58                 ` Konrad Rzeszutek Wilk
2015-04-15 21:14                   ` Sander Eikelenboom
2015-06-10  1:02                     ` Is: qemu-xen mishandling upper 64-bit BAR compared to qemu-tradWas:Re: " Konrad Rzeszutek Wilk
2015-06-10  8:44                       ` Jan Beulich
2015-06-10 11:13                         ` Stefano Stabellini
2015-06-10 12:02                           ` Jan Beulich
2015-06-10 14:33                             ` Konrad Rzeszutek Wilk
2015-06-10 20:53                             ` konrad [this message]
2015-06-11  7:47                               ` [PATCH QEMU-XEN] xen/pt: Start with emulated PCI_COMMAND set to zero Jan Beulich
2015-06-11 11:19                                 ` Sander Eikelenboom
2015-06-12 13:37                                   ` Konrad Rzeszutek Wilk
2015-06-15 16:19                                 ` Stefano Stabellini
2015-06-15 18:46                                   ` Konrad Rzeszutek Wilk
2015-06-16  7:33                                   ` Jan Beulich
2015-06-24 15:59                                     ` Konrad Rzeszutek Wilk
2015-06-25  7:34                                       ` Jan Beulich
2015-06-25 12:08                                         ` Stefano Stabellini
2015-06-25 17:23                                         ` Konrad Rzeszutek Wilk
2015-06-26  6:10                                           ` Jan Beulich
2015-06-15 16:15                             ` Is: qemu-xen mishandling upper 64-bit BAR compared to qemu-tradWas:Re: Dom0 linux 4.0 + devel/for-linus-4.1 branch: p2m.c:884:d0v0 gfn_to_mfn failed! gfn=ffffffff001ed type:4 Stefano Stabellini

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=1433969591-11202-1-git-send-email-konrad@kernel.org \
    --to=konrad@kernel.org \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=david.vrabel@citrix.com \
    --cc=linux@eikelenboom.it \
    --cc=stefano.stabellini@eu.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 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.