From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Avi Kivity <avi@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH 2/5] qemu-kvm: msix: Only invoke msix_handle_mask_update on changes
Date: Tue, 18 Oct 2011 15:20:45 +0200 [thread overview]
Message-ID: <20111018132043.GR28776@redhat.com> (raw)
In-Reply-To: <4E9D749C.8080604@siemens.com>
On Tue, Oct 18, 2011 at 02:44:12PM +0200, Jan Kiszka wrote:
> On 2011-10-18 14:37, Michael S. Tsirkin wrote:
> > On Tue, Oct 18, 2011 at 02:22:38PM +0200, Jan Kiszka wrote:
> >> On 2011-10-18 14:11, Michael S. Tsirkin wrote:
> >>> On Tue, Oct 18, 2011 at 01:54:23PM +0200, Jan Kiszka wrote:
> >>>> On 2011-10-18 13:43, Michael S. Tsirkin wrote:
> >>>>> On Tue, Oct 18, 2011 at 09:50:51AM +0200, Jan Kiszka wrote:
> >>>>>> Reorganize msix_mmio_writel so that msix_handle_mask_update is only
> >>>>>> called on mask changes. Pass previous config space value to
> >>>>>> msix_write_config so that it can check if a mask change took place.
> >>>>>>
> >>>>>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> >>>>>
> >>>>> What we did in other cases is track the old value in device state.
> >>>>> This makes the API easier to use correctly.
> >>>>> I'm testing the following as a replacement - any comments?
> >>>>
> >>>> No concerns about caching the mask state, but...
> >>>>
> >>>>>
> >>>>> diff --git a/hw/msix.c b/hw/msix.c
> >>>>> index b15bafc..655a600 100644
> >>>>> --- a/hw/msix.c
> >>>>> +++ b/hw/msix.c
> >>>>> @@ -79,6 +79,7 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
> >>>>> /* Make flags bit writable. */
> >>>>> pdev->wmask[config_offset + MSIX_CONTROL_OFFSET] |= MSIX_ENABLE_MASK |
> >>>>> MSIX_MASKALL_MASK;
> >>>>> + pdev->msix_function_masked = false;
> >>>>> return 0;
> >>>>> }
> >>>>>
> >>>>> @@ -117,16 +118,11 @@ static void msix_clr_pending(PCIDevice *dev, int vector)
> >>>>> *msix_pending_byte(dev, vector) &= ~msix_pending_mask(vector);
> >>>>> }
> >>>>>
> >>>>> -static int msix_function_masked(PCIDevice *dev)
> >>>>> -{
> >>>>> - return dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK;
> >>>>> -}
> >>>>> -
> >>>>> static int msix_is_masked(PCIDevice *dev, int vector)
> >>>>> {
> >>>>> unsigned offset =
> >>>>> vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
> >>>>> - return msix_function_masked(dev) ||
> >>>>> + return dev->msix_function_masked ||
> >>>>> dev->msix_table_page[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT;
> >>>>> }
> >>>>>
> >>>>> @@ -144,6 +140,7 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
> >>>>> {
> >>>>> unsigned enable_pos = dev->msix_cap + MSIX_CONTROL_OFFSET;
> >>>>> int vector;
> >>>>> + bool fmsk;
> >>>>>
> >>>>> if (!range_covers_byte(addr, len, enable_pos)) {
> >>>>> return;
> >>>>> @@ -155,10 +152,12 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
> >>>>>
> >>>>> pci_device_deassert_intx(dev);
> >>>>>
> >>>>> - if (msix_function_masked(dev)) {
> >>>>> + fmsk = dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK;
> >>>>> + if (dev->msix_function_masked == fmsk) {
> >>>>
> >>>> ...this misses MSIX_MASKALL_MASK (but !MSIX_ENABLE_MASK) ->
> >>>> MSIX_ENABLE_MASK.
> >>>>
> >>>
> >>> Could you clarify please?
> >>> if (!msix_enabled(dev)) {
> >>> return;
> >>> }
> >>> is at start of this function so nothing happens if
> >>> MSIX is disabled.
> >>
> >> OK, missed that. But let's have a look again:
> >>
> >> ENABLE -> 0 => msix_function_masked := false
> >> 0 -> ENABLE => msix_function_masked remains false, thus no firing
> >> (while we did fire in the past and should do so in the future)
> >>
> >> Jan
> >
> > I'm not sure I get it. You mean mask was set when we enabled?
> > Then we can't send any interrupts so handlers do not fire.
> > What's wrong?
>
> I mean mask was NOT set when disabling, and will remain unset when
> enabling. Then we should fire the notifier although the mask bit was not
> changed physically.
> There should be no vectors pending at this point as
> they are supposed to be cleared when we disable MSI-X (as far as I
> understand the spec).
>
> Jan
>
Ah. Right. Good catch. It's probably best to just make that
state be !enabled || masked. Like the below? (compiled only):
--->
msix: track function masked in pci device state
Only go over the table when function is masked.
This optimization is not really important for qemu.git but helps
qemu-kvm.git.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/hw/msix.c b/hw/msix.c
index b15bafc..63b41b9 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -79,6 +79,7 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
/* Make flags bit writable. */
pdev->wmask[config_offset + MSIX_CONTROL_OFFSET] |= MSIX_ENABLE_MASK |
MSIX_MASKALL_MASK;
+ pdev->msix_function_masked = true;
return 0;
}
@@ -117,16 +118,11 @@ static void msix_clr_pending(PCIDevice *dev, int vector)
*msix_pending_byte(dev, vector) &= ~msix_pending_mask(vector);
}
-static int msix_function_masked(PCIDevice *dev)
-{
- return dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK;
-}
-
static int msix_is_masked(PCIDevice *dev, int vector)
{
unsigned offset =
vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
- return msix_function_masked(dev) ||
+ return dev->msix_function_masked ||
dev->msix_table_page[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT;
}
@@ -138,24 +134,34 @@ static void msix_handle_mask_update(PCIDevice *dev, int vector)
}
}
+static void msix_update_function_masked(PCIDevice *dev)
+{
+ dev->msix_function_masked = !msix_enabled(dev) ||
+ (dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK);
+}
+
/* Handle MSI-X capability config write. */
void msix_write_config(PCIDevice *dev, uint32_t addr,
uint32_t val, int len)
{
unsigned enable_pos = dev->msix_cap + MSIX_CONTROL_OFFSET;
int vector;
+ bool was_masked;
if (!range_covers_byte(addr, len, enable_pos)) {
return;
}
+ was_masked = dev->msix_function_masked;
+ msix_update_function_masked(dev);
+
if (!msix_enabled(dev)) {
return;
}
pci_device_deassert_intx(dev);
- if (msix_function_masked(dev)) {
+ if (dev->msix_function_masked == was_masked) {
return;
}
@@ -300,6 +306,7 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
msix_free_irq_entries(dev);
qemu_get_buffer(f, dev->msix_table_page, n * PCI_MSIX_ENTRY_SIZE);
qemu_get_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
+ msix_update_function_masked(dev);
}
/* Does device support MSI-X? */
diff --git a/hw/pci.h b/hw/pci.h
index 86a81c8..da4c9c3 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -178,6 +178,8 @@ struct PCIDevice {
unsigned *msix_entry_used;
/* Region including the MSI-X table */
uint32_t msix_bar_size;
+ /* MSIX function mask set or MSIX disabled */
+ bool msix_function_masked;
/* Version id needed for VMState */
int32_t version_id;
--
MST
next prev parent reply other threads:[~2011-10-18 13:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-18 7:50 [PATCH 0/5] qemu-kvm: MSI-X fixes Jan Kiszka
2011-10-18 7:50 ` [PATCH 1/5] qemu-kvm: msix: Don't fire notifier spuriously on set/unset Jan Kiszka
2011-10-18 11:06 ` Michael S. Tsirkin
2011-10-18 11:34 ` Jan Kiszka
2011-10-18 7:50 ` [PATCH 2/5] qemu-kvm: msix: Only invoke msix_handle_mask_update on changes Jan Kiszka
2011-10-18 11:43 ` Michael S. Tsirkin
2011-10-18 11:54 ` Jan Kiszka
2011-10-18 12:11 ` Michael S. Tsirkin
2011-10-18 12:22 ` Jan Kiszka
2011-10-18 12:37 ` Michael S. Tsirkin
2011-10-18 12:44 ` Jan Kiszka
2011-10-18 13:20 ` Michael S. Tsirkin [this message]
2011-10-18 13:49 ` Michael S. Tsirkin
2011-10-18 13:52 ` Jan Kiszka
2011-10-18 7:50 ` [PATCH 3/5] qemu-kvm: msix: Fire mask notifier on global mask changes Jan Kiszka
2011-10-18 7:50 ` [PATCH 4/5] msix: Don't process table changes while disabled Jan Kiszka
2011-10-18 11:18 ` Michael S. Tsirkin
2011-10-18 11:35 ` Jan Kiszka
2011-10-18 12:01 ` Michael S. Tsirkin
2011-10-18 11:26 ` Michael S. Tsirkin
2011-10-18 7:50 ` [PATCH 5/5] msix: Prevent bogus mask updates on MMIO accesses Jan Kiszka
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=20111018132043.GR28776@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.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).