From: Jan Kiszka <jan.kiszka@web.de>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Avi Kivity <avi@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [RFC][PATCH 28/45] qemu-kvm: msix: Drop tracking of used vectors
Date: Wed, 19 Oct 2011 00:13:49 +0200 [thread overview]
Message-ID: <4E9DFA1D.4050905@web.de> (raw)
In-Reply-To: <20111018214006.GB7216@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 7787 bytes --]
On 2011-10-18 23:40, Michael S. Tsirkin wrote:
> On Tue, Oct 18, 2011 at 09:37:14PM +0200, Jan Kiszka wrote:
>> On 2011-10-18 20:40, Michael S. Tsirkin wrote:
>>> On Tue, Oct 18, 2011 at 08:24:39PM +0200, Jan Kiszka wrote:
>>>> On 2011-10-18 19:06, Michael S. Tsirkin wrote:
>>>>> On Tue, Oct 18, 2011 at 05:55:54PM +0200, Jan Kiszka wrote:
>>>>>> On 2011-10-18 17:22, Jan Kiszka wrote:
>>>>>>> What KVM has to do is just mapping an arbitrary MSI message
>>>>>>> (theoretically 64+32 bits, in practice it's much of course much less) to
>>>>>>
>>>>>> ( There are 24 distinguishing bits in an MSI message on x86, but that's
>>>>>> only a current interpretation of one specific arch. )
>>>>>
>>>>> Confused. vector mask is 8 bits. the rest is destination id etc.
>>>>
>>>> Right, but those additional bits like the destination make different
>>>> messages. We have to encode those 24 bits into a unique GSI number and
>>>> restore them (by table lookup) on APIC injection inside the kernel. If
>>>> we only had to encode 256 different vectors, we would be done already.
>>>
>>> Right. But in practice guests always use distinct vectors (from the
>>> 256 available) for distinct messages. This is because
>>> the vector seems to be the only thing that gets communicated by the APIC
>>> to the software.
>>>
>>> So e.g. a table with 256 entries, with extra 1024-256
>>> used for spill-over for guests that do something unexpected,
>>> would work really well.
>>
>> Already Linux manages vectors on a pre-CPU basis. For efficiency
>> reasons, it does not exploit the full range of 256 vectors but actually
>> allocates them in - IIRC - steps of 16. So I would not be surprised to
>> find lots of vector number "collisions" when looking over a full set of
>> CPUs in a system.
>>
>> Really, these considerations do not help us. We must store all 96 bits,
>> already for the sake of other KVM architectures that want MSI routing.
>>>
>>>
>>>>>
>>>>>>> a single GSI and vice versa. As there are less GSIs than possible MSI
>>>>>>> messages, we could run out of them when creating routes, statically or
>>>>>>> lazily.
>>>>>>>
>>>>>>> What would probably help us long-term out of your concerns regarding
>>>>>>> lazy routing is to bypass that redundant GSI translation for dynamic
>>>>>>> messages, i.e. those that are not associated with an irqfd number or an
>>>>>>> assigned device irq. Something like a KVM_DELIVER_MSI IOCTL that accepts
>>>>>>> address and data directly.
>>>>>>
>>>>>> This would be a trivial extension in fact. Given its beneficial impact
>>>>>> on our GSI limitation issue, I think I will hack up something like that.
>>>>>>
>>>>>> And maybe this makes a transparent cache more reasonable. Then only old
>>>>>> host kernels would force us to do searches for already cached messages.
>>>>>>
>>>>>> Jan
>>>>>
>>>>> Hmm, I'm not all that sure. Existing design really allows
>>>>> caching the route in various smart ways. We currently do
>>>>> this for irqfd but this can be extended to ioctls.
>>>>> If we just let the guest inject arbitrary messages,
>>>>> that becomes much more complex.
>>>>
>>>> irqfd and kvm device assignment do not allow us to inject arbitrary
>>>> messages at arbitrary points. The new API offers kvm_msi_irqfd_set and
>>>> kvm_device_msix_set_vector (etc.) for those scenarios to set static
>>>> routes from an MSI message to a GSI number (+they configure the related
>>>> backends).
>>>
>>> Yes, it's a very flexible API but it would be very hard to optimize.
>>> GSIs let us do the slow path setup, but they make it easy
>>> to optimize target lookup in kernel.
>>
>> Users of the API above have no need to know anything about GSIs. They
>> are an artifact of the KVM-internal interface between user space and
>> kernel now - thanks to the MSIRoutingCache encapsulation.
>
> Yes but I am saying that the API above can't be implemented
> more efficiently than now: you will have to scan all apics on each MSI.
> The GSI implementation can be optimized: decode the vector once,
> if it matches a single vcpu, store that vcpu and use when sending
> interrupts.
Sorry, missed that you switched to kernel.
What information do you want to cache there that cannot be easily
obtained by looking at a concrete message? I do not see any. Once you
checked that the delivery mode targets a specific cpu, you could address
it directly. Or are you thinking about some cluster mode?
>
>
>>>
>>> An analogy would be if read/write operated on file paths.
>>> fd makes it easy to do permission checks and slow lookups
>>> in one place. GSI happens to work like this (maybe, by accident).
>>
>> Think of an opaque file handle as a MSIRoutingCache object. And it
>> encodes not only the routing handle but also other useful associated
>> information we need from time to time - internally, not in the device
>> models.
>
> Forget qemu abstractions, I am talking about data path
> optimizations in kernel in kvm. From that POV the point of an fd is not
> that it is opaque. It is that it's an index in an array that
> can be used for fast lookups.
>
>>>>>
>>>>> Another concern is mask bit emulation. We currently
>>>>> handle mask bit in userspace but patches
>>>>> to do them in kernel for assigned devices where seen
>>>>> and IMO we might want to do that for virtio as well.
>>>>>
>>>>> For that to work the mask bit needs to be tied to
>>>>> a specific gsi or specific device, which does not
>>>>> work if we just inject arbitrary writes.
>>>>
>>>> Yes, but I do not see those valuable plans being negatively affected.
>>>>
>>>> Jan
>>>>
>>>
>>> I do.
>>> How would we maintain a mask/pending bit in kernel if we are not
>>> supplied info on all available vectors even?
>>
>> It's tricky to discuss an undefined interface (there only exists an
>> outdated proposal for kvm device assignment). But I suppose that user
>> space will have to define the maximum number of vectors when creating an
>> in-kernel MSI-X MMIO area. The device already has to tell this to msix_init.
>>
>> The number of used vectors will correlate with the number of registered
>> irqfds (in the case of vhost or vfio, device assignment still has
>> SET_MSIX_NR). As kernel space would then be responsible for mask
>> processing, user space would keep vectors registered with irqfds, even
>> if they are masked. It could just continue to play the trick and drop
>> data=0 vectors.
>
> Which trick? We don't play any tricks except for device assignment.
>
>> The point here is: All those steps have _nothing_ to do with the generic
>> MSI-X core. They are KVM-specific "side channels" for which KVM provides
>> an API. In contrast, msix_vector_use/unuse were generic services that
>> were actually created to please KVM requirements. But if we split that
>> up, we can address the generic MSI-X requirements in a way that makes
>> more sense for emulated devices (and particularly msix_vector_use makes
>> no sense for emulation).
>>
>> Jan
>>
>
> We need at least msix_vector_unuse
Not at all. We rather need some qemu_irq_set(level) for MSI. The spec
requires that the device clears pending when the reason for that is
removed. And any removal that is device model-originated should simply
be signaled like an irq de-assert. Vector "unusage" is just one reason here.
> - IMO it makes more sense than "clear
> pending vector". msix_vector_use is good to keep around for symmetry:
> who knows whether we'll need to allocate resources per vector
> in the future.
For MSI[-X], the spec is already there, and we know that there no need
for further resources when emulating it. Only KVM has special needs.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2011-10-18 22:13 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 9:27 [Qemu-devel] [RFC][PATCH 00/45] qemu-kvm: MSI layer rework for in-kernel irqchip support Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 01/45] msi: Guard msi/msix_write_config with msi_present Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 02/45] msi: Guard msi_reset " Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 03/45] msi: Use msi/msix_present more consistently Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 04/45] msi: Invoke msi/msix_reset from PCI core Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 05/45] msi: Invoke msi/msix_write_config " Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 06/45] msix: Prevent bogus mask updates on MMIO accesses Jan Kiszka
2011-10-17 11:10 ` Michael S. Tsirkin
2011-10-17 11:23 ` Jan Kiszka
2011-10-17 11:57 ` Michael S. Tsirkin
2011-10-17 12:07 ` Jan Kiszka
2011-10-17 12:50 ` Michael S. Tsirkin
2011-10-17 19:11 ` Jan Kiszka
2011-10-17 19:43 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 07/45] msi: Generalize msix_supported to msi_supported Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 08/45] Introduce MSIMessage structure Jan Kiszka
2011-10-17 11:46 ` Michael S. Tsirkin
2011-10-17 11:51 ` Jan Kiszka
2011-10-17 12:04 ` Michael S. Tsirkin
2011-10-17 12:09 ` Jan Kiszka
2011-10-17 13:01 ` Michael S. Tsirkin
2011-10-17 19:14 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 09/45] msi: Factor out msi_message_from_vector Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 10/45] msix: Factor out msix_message_from_vector Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 11/45] msi: Factor out delivery hook Jan Kiszka
2011-10-17 10:56 ` Avi Kivity
2011-10-17 11:15 ` Jan Kiszka
2011-10-17 11:22 ` Avi Kivity
2011-10-17 11:29 ` Jan Kiszka
2011-10-17 12:14 ` Avi Kivity
2011-10-17 18:59 ` Jan Kiszka
2011-10-17 13:41 ` Michael S. Tsirkin
2011-10-17 13:41 ` Avi Kivity
2011-10-17 13:48 ` Michael S. Tsirkin
2011-10-17 19:18 ` Jan Kiszka
2011-10-17 13:43 ` Michael S. Tsirkin
2011-10-17 19:15 ` Jan Kiszka
2011-10-18 12:05 ` Michael S. Tsirkin
2011-10-18 12:23 ` Jan Kiszka
2011-10-18 12:38 ` Michael S. Tsirkin
2011-10-18 12:41 ` Jan Kiszka
2011-10-18 12:44 ` malc
2011-10-18 12:49 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 12/45] msi: Introduce MSIRoutingCache Jan Kiszka
2011-10-17 11:06 ` Avi Kivity
2011-10-17 11:19 ` Jan Kiszka
2011-10-17 11:25 ` Avi Kivity
2011-10-17 11:31 ` Jan Kiszka
2011-10-17 12:17 ` Avi Kivity
2011-10-17 15:37 ` Michael S. Tsirkin
2011-10-17 19:19 ` Jan Kiszka
2011-10-18 12:17 ` Michael S. Tsirkin
2011-10-18 12:26 ` Jan Kiszka
2011-10-17 15:43 ` Michael S. Tsirkin
2011-10-17 19:23 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 13/45] hpet: Use msi_deliver Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 14/45] qemu-kvm: Drop useless kvm_clear_gsi_routes Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 15/45] qemu-kvm: Drop unused kvm_del_irq_route Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 16/45] qemu-kvm: Use MSIMessage and MSIRoutingCache Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 17/45] qemu-kvm: Track MSIRoutingCache in KVM routing table Jan Kiszka
2011-10-17 11:13 ` Avi Kivity
2011-10-17 11:25 ` Jan Kiszka
2011-10-17 12:15 ` Avi Kivity
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 18/45] qemu-kvm: Hook into MSI delivery at APIC level Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 19/45] qemu-kvm: Factor out kvm_msi_irqfd_set Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 20/45] qemu-kvm: msix: Only invoke msix_handle_mask_update on changes Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 21/45] qemu-kvm: msix: Don't fire notifier spuriously on set/unset Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 22/45] qemu-kvm: msix: Fire mask notifier on global mask changes Jan Kiszka
2011-10-17 12:16 ` Michael S. Tsirkin
2011-10-17 19:00 ` Jan Kiszka
2011-10-18 12:40 ` Michael S. Tsirkin
2011-10-18 12:45 ` Jan Kiszka
2011-10-18 12:57 ` Michael S. Tsirkin
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 23/45] qemu-kvm: Rework MSI-X mask notifier to generic MSI config notifiers Jan Kiszka
2011-10-17 11:40 ` Michael S. Tsirkin
2011-10-17 11:45 ` Jan Kiszka
2011-10-17 12:39 ` Michael S. Tsirkin
2011-10-17 19:08 ` Jan Kiszka
2011-10-18 13:46 ` Michael S. Tsirkin
2011-10-18 13:49 ` Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 24/45] qemu-kvm: msix: Don't handle mask updated while disabled Jan Kiszka
2011-10-17 9:27 ` [Qemu-devel] [RFC][PATCH 25/45] qemu-kvm: Update MSI cache on kvm_msi_irqfd_set Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 26/45] qemu-kvm: Use g_realloc for irq_routes extension Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 27/45] qemu-kvm: Lazily update MSI caches Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 28/45] qemu-kvm: msix: Drop tracking of used vectors Jan Kiszka
2011-10-17 15:48 ` Michael S. Tsirkin
2011-10-17 19:28 ` Jan Kiszka
2011-10-18 11:58 ` Michael S. Tsirkin
2011-10-18 12:08 ` Jan Kiszka
2011-10-18 12:33 ` Michael S. Tsirkin
2011-10-18 12:38 ` Jan Kiszka
2011-10-18 12:48 ` Michael S. Tsirkin
2011-10-18 13:00 ` Jan Kiszka
2011-10-18 13:37 ` Michael S. Tsirkin
2011-10-18 13:46 ` Jan Kiszka
2011-10-18 14:01 ` Michael S. Tsirkin
2011-10-18 14:08 ` Jan Kiszka
2011-10-18 15:08 ` Michael S. Tsirkin
2011-10-18 15:22 ` Jan Kiszka
2011-10-18 15:55 ` Jan Kiszka
2011-10-18 17:06 ` Michael S. Tsirkin
2011-10-18 18:24 ` Jan Kiszka
2011-10-18 18:40 ` Michael S. Tsirkin
2011-10-18 19:37 ` Jan Kiszka
2011-10-18 21:40 ` Michael S. Tsirkin
2011-10-18 22:13 ` Jan Kiszka [this message]
2011-10-19 0:56 ` Michael S. Tsirkin
2011-10-19 6:41 ` Jan Kiszka
2011-10-19 9:03 ` Michael S. Tsirkin
2011-10-19 11:17 ` Jan Kiszka
2011-10-20 22:02 ` Michael S. Tsirkin
2011-10-21 7:09 ` Jan Kiszka
2011-10-21 7:54 ` Michael S. Tsirkin
2011-10-21 9:27 ` Jan Kiszka
2011-10-21 10:57 ` Michael S. Tsirkin
2011-10-18 18:26 ` Jan Kiszka
2011-10-18 15:56 ` Michael S. Tsirkin
2011-10-18 15:58 ` Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 29/45] pci-assign: Drop kvm_assigned_irq::host_irq initialization Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 30/45] pci-assign: Rename assign_irq to assign_intx Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 31/45] qemu-kvm: Refactor kvm_deassign_irq to kvm_device_irq_deassign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 32/45] pci-assign: Factor out deassign_irq Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 33/45] qemu-kvm: Factor out kvm_device_intx_assign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 34/45] qemu-kvm: Factor out kvm_device_msi_assign Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 35/45] pci-assign: Polish assigned_dev_update_msix_mmio Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 36/45] qemu-kvm: Factor out kvm_device_msix_* services Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 37/45] qemu-kvm: Clean up irqrouting API Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 38/45] msi: Implement config notifiers for legacy MSI Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 39/45] pci-assign: Use generic MSI support Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 40/45] qemu-kvm: msix: Drop check for preexisting cap from msix_add_config Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 41/45] msix: Drop unused msix_bar_size Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 42/45] msix: Introduce msix_init_simple Jan Kiszka
2011-10-17 11:22 ` Michael S. Tsirkin
2011-10-17 11:27 ` Jan Kiszka
2011-10-17 14:28 ` Michael S. Tsirkin
2011-10-17 19:21 ` Jan Kiszka
2011-10-18 10:52 ` Michael S. Tsirkin
2011-10-18 11:02 ` Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 43/45] msix: Allow to customize capability on init Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 44/45] pci-assign: Use generic MSI-X support Jan Kiszka
2011-10-17 9:28 ` [Qemu-devel] [RFC][PATCH 45/45] pci-assign: Fix coding style issues Jan Kiszka
2011-10-17 12:18 ` [Qemu-devel] [RFC][PATCH 00/45] qemu-kvm: MSI layer rework for in-kernel irqchip support Avi Kivity
2011-10-17 15:57 ` Michael S. Tsirkin
2011-10-17 19:35 ` 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=4E9DFA1D.4050905@web.de \
--to=jan.kiszka@web.de \
--cc=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.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).