From: Gregory Haskins <gregory.haskins@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Gregory Haskins <ghaskins@novell.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
avi@redhat.com, mtosatti@redhat.com, paulmck@linux.vnet.ibm.com,
markmc@redhat.com
Subject: Re: [KVM PATCH v8 3/3] KVM: add iosignalfd support
Date: Mon, 22 Jun 2009 09:04:48 -0400 [thread overview]
Message-ID: <4A3F8170.7000508@gmail.com> (raw)
In-Reply-To: <20090622123022.GC12867@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 6068 bytes --]
Sorry, Michael. I missed that you had other comments after the
grammatical one. Will answer inline
Michael S. Tsirkin wrote:
> On Mon, Jun 22, 2009 at 08:13:48AM -0400, Gregory Haskins wrote:
>
>>>> + * notification when the memory has been touched.
>>>> + * --------------------------------------------------------------------
>>>> + */
>>>> +
>>>> +/*
>>>> + * Design note: We create one PIO/MMIO device (iosignalfd_group) which
>>>> + * aggregates one or more iosignalfd_items. Each item points to exactly one
>>>>
> ^^ ^^
>
>>>> + * eventfd, and can be registered to trigger on any write to the group
>>>> + * (wildcard), or to a write of a specific value. If more than one item is to
>>>>
> ^^
>
>>>> + * be supported, the addr/len ranges must all be identical in the group. If a
>>>>
> ^^
>
>>>> + * trigger value is to be supported on a particular item, the group range must
>>>> + * be exactly the width of the trigger.
>>>>
>>>>
>>> Some duplicate spaces in the text above, apparently at random places.
>>>
>>>
>>>
>> -ENOPARSE ;)
>>
>> Can you elaborate?
>>
>
>
> Marked with ^^
>
>
>>>> + */
>>>> +
>>>> +struct _iosignalfd_item {
>>>> + struct list_head list;
>>>> + struct file *file;
>>>> + u64 match;
>>>> + struct rcu_head rcu;
>>>> + int wildcard:1;
>>>> +};
>>>> +
>>>> +struct _iosignalfd_group {
>>>> + struct list_head list;
>>>> + u64 addr;
>>>> + size_t length;
>>>> + size_t count;
>>>> + struct list_head items;
>>>> + struct kvm_io_device dev;
>>>> + struct rcu_head rcu;
>>>> +};
>>>> +
>>>> +static inline struct _iosignalfd_group *
>>>> +to_group(struct kvm_io_device *dev)
>>>> +{
>>>> + return container_of(dev, struct _iosignalfd_group, dev);
>>>> +}
>>>> +
>>>> +static void
>>>> +iosignalfd_item_free(struct _iosignalfd_item *item)
>>>> +{
>>>> + fput(item->file);
>>>> + kfree(item);
>>>> +}
>>>> +
>>>> +static void
>>>> +iosignalfd_item_deferred_free(struct rcu_head *rhp)
>>>> +{
>>>> + struct _iosignalfd_item *item;
>>>> +
>>>> + item = container_of(rhp, struct _iosignalfd_item, rcu);
>>>> +
>>>> + iosignalfd_item_free(item);
>>>> +}
>>>> +
>>>> +static void
>>>> +iosignalfd_group_deferred_free(struct rcu_head *rhp)
>>>> +{
>>>> + struct _iosignalfd_group *group;
>>>> +
>>>> + group = container_of(rhp, struct _iosignalfd_group, rcu);
>>>> +
>>>> + kfree(group);
>>>> +}
>>>> +
>>>> +static int
>>>> +iosignalfd_group_in_range(struct kvm_io_device *this, gpa_t addr, int len,
>>>> + int is_write)
>>>> +{
>>>> + struct _iosignalfd_group *p = to_group(this);
>>>> +
>>>> + return ((addr >= p->addr && (addr < p->addr + p->length)));
>>>> +}
>>>>
>>>>
>>> What does this test? len is ignored ...
>>>
>>>
>>>
>> Yeah, I was following precedent with other IO devices. However, this
>> *is* sloppy, I agree. Will fix.
>>
>>
>>>> +
>>>> +static int
>>>>
>>>>
>>> This seems to be returning bool ...
>>>
>>>
>> Ack
>>
>>>
>>>
>>>> +iosignalfd_is_match(struct _iosignalfd_group *group,
>>>> + struct _iosignalfd_item *item,
>>>> + const void *val,
>>>> + int len)
>>>> +{
>>>> + u64 _val;
>>>> +
>>>> + if (len != group->length)
>>>> + /* mis-matched length is always a miss */
>>>> + return false;
>>>>
>>>>
>>> Why is that? what if there's 8 byte write which covers
>>> a 4 byte group?
>>>
>>>
>> v7 and earlier used to allow that for wildcards, actually. It of
>> course would never make sense to allow mis-matched writes for
>> non-wildcards, since the idea is to match the value exactly. However,
>> the feedback I got from Avi was that we should make the wildcard vs
>> non-wildcard access symmetrical and ensure they both conform to the size.
>>
>>>
>>>
>>>> +
>>>> + if (item->wildcard)
>>>> + /* wildcard is always a hit */
>>>> + return true;
>>>> +
>>>> + /* otherwise, we have to actually compare the data */
>>>> +
>>>> + if (!IS_ALIGNED((unsigned long)val, len))
>>>> + /* protect against this request causing a SIGBUS */
>>>> + return false;
>>>>
>>>>
>>> Could you explain what this does please?
>>>
>>>
>> Sure: item->match is a fixed u64 to represent all group->length
>> values. So it might have a 1, 2, 4, or 8 byte value in it. When I
>> write arrives, we need to cast the data-register (in this case
>> represented by (void*)val) into a u64 so the equality check (see [A],
>> below) can be done. However, you can't cast an unaligned pointer, or it
>> will SIGBUS on many (most?) architectures.
>>
>
> I mean guest access. Does it have to be aligned?
>
In order to work on arches that require alignment, yes. Note that I
highly suspect that the pointer is already aligned anyway. My
IS_ALIGNED check is simply for conservative sanity.
> You could memcpy the value...
>
Then you get into the issue of endianness and what pointer to use. Or
am I missing something?
>
>>> I thought misaligned accesses are allowed.
>>>
>>>
>> If thats true, we are in trouble ;)
>>
>
> I think it works at least on x86:
> http://en.wikipedia.org/wiki/Packed#x86_and_x86-64
>
Right, understood. What I meant specifically is that if the (void*)val
pointer is allowed to be misaligned we are in trouble ;). I haven't
studied the implementation in front of the MMIO callback recently, but I
generally doubt thats the case. More than likely this is some buffer
that was kmalloced and that should already be aligned to the machine word.
Kind Regards,
-Greg
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 266 bytes --]
next prev parent reply other threads:[~2009-06-22 13:04 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-19 0:30 [KVM PATCH v8 0/3] iosignalfd Gregory Haskins
2009-06-19 0:30 ` [KVM PATCH v8 1/3] KVM: make io_bus interface more robust Gregory Haskins
2009-06-25 14:22 ` Gregory Haskins
2009-06-25 14:53 ` Michael S. Tsirkin
2009-06-25 14:56 ` Gregory Haskins
2009-06-19 0:30 ` [KVM PATCH v8 2/3] KVM: add per-vm limit on the maximum number of io-devices supported Gregory Haskins
2009-06-19 0:30 ` [KVM PATCH v8 3/3] KVM: add iosignalfd support Gregory Haskins
2009-06-22 10:44 ` Michael S. Tsirkin
2009-06-22 12:13 ` Gregory Haskins
2009-06-22 12:26 ` Paolo Bonzini
2009-06-22 12:30 ` Michael S. Tsirkin
2009-06-22 12:56 ` Gregory Haskins
2009-06-22 13:08 ` Michael S. Tsirkin
2009-06-22 13:12 ` Gregory Haskins
2009-06-22 13:13 ` Avi Kivity
2009-06-22 13:04 ` Gregory Haskins [this message]
2009-06-22 13:13 ` Michael S. Tsirkin
2009-06-22 13:19 ` Gregory Haskins
2009-06-22 14:30 ` Avi Kivity
2009-06-22 14:39 ` Gregory Haskins
2009-06-22 14:28 ` Avi Kivity
2009-06-22 15:16 ` [PATCH RFC] pass write value to in_range pointers Michael S. Tsirkin
2009-06-22 15:45 ` Gregory Haskins
2009-06-22 16:08 ` Michael S. Tsirkin
2009-06-22 16:29 ` Gregory Haskins
2009-06-22 17:27 ` Michael S. Tsirkin
2009-06-23 4:04 ` Gregory Haskins
2009-06-23 11:44 ` Michael S. Tsirkin
2009-06-23 11:52 ` Gregory Haskins
2009-06-23 11:56 ` Avi Kivity
2009-06-23 12:01 ` Gregory Haskins
2009-06-23 12:19 ` Avi Kivity
2009-06-23 11:53 ` Avi Kivity
2009-06-23 9:54 ` Avi Kivity
2009-06-23 9:52 ` Avi Kivity
2009-06-23 11:41 ` Gregory Haskins
2009-06-23 11:46 ` Michael S. Tsirkin
2009-06-23 8:56 ` [KVM PATCH v8 3/3] KVM: add iosignalfd support Michael S. Tsirkin
2009-06-23 9:57 ` Avi Kivity
2009-06-23 10:48 ` Michael S. Tsirkin
2009-06-23 11:24 ` Avi Kivity
2009-06-23 11:33 ` Gregory Haskins
2009-06-23 11:36 ` Michael S. Tsirkin
2009-06-23 11:40 ` Gregory Haskins
2009-06-23 13:22 ` Gregory Haskins
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=4A3F8170.7000508@gmail.com \
--to=gregory.haskins@gmail.com \
--cc=avi@redhat.com \
--cc=ghaskins@novell.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=markmc@redhat.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=paulmck@linux.vnet.ibm.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