diff mbox

[v2,1/2] kvm tools: Fix VHOST_SET_MEM_TABLE failure

Message ID 1342022894-1034-1-git-send-email-asias.hejun@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He July 11, 2012, 4:08 p.m. UTC
VHOST_SET_MEM_TABLE failed: Operation not supported

In vhost_set_memory(), We have

        if (mem.padding)
                return -EOPNOTSUPP;

So, we need to zero struct vhost_memory.

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/virtio/net.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Avi Kivity July 11, 2012, 4:09 p.m. UTC | #1
On 07/11/2012 07:08 PM, Asias He wrote:
> VHOST_SET_MEM_TABLE failed: Operation not supported
> 
> In vhost_set_memory(), We have
> 
>         if (mem.padding)
>                 return -EOPNOTSUPP;
> 
> So, we need to zero struct vhost_memory.
> 

Is this due to a change in vhost?
Asias He July 12, 2012, 2:46 a.m. UTC | #2
On Thu, Jul 12, 2012 at 12:09 AM, Avi Kivity <avi@redhat.com> wrote:
> On 07/11/2012 07:08 PM, Asias He wrote:
>> VHOST_SET_MEM_TABLE failed: Operation not supported
>>
>> In vhost_set_memory(), We have
>>
>>         if (mem.padding)
>>                 return -EOPNOTSUPP;
>>
>> So, we need to zero struct vhost_memory.
>>
>
> Is this due to a change in vhost?

Seems we have this bit in the very beginning (commit 3a4d5c94).
Avi Kivity July 12, 2012, 8:19 a.m. UTC | #3
On 07/12/2012 05:46 AM, Asias He wrote:
> On Thu, Jul 12, 2012 at 12:09 AM, Avi Kivity <avi@redhat.com> wrote:
>> On 07/11/2012 07:08 PM, Asias He wrote:
>>> VHOST_SET_MEM_TABLE failed: Operation not supported
>>>
>>> In vhost_set_memory(), We have
>>>
>>>         if (mem.padding)
>>>                 return -EOPNOTSUPP;
>>>
>>> So, we need to zero struct vhost_memory.
>>>
>>
>> Is this due to a change in vhost?
> 
> Seems we have this bit in the very beginning (commit 3a4d5c94).

Okay, so it's a documentation problem.  Michael, where is the
documentation for vhost-net?

Note we have to initialize it with memset(); presumably when we
repurpose it the name will change, and anonymous unions are not very
portable.
Michael S. Tsirkin July 12, 2012, 11:27 p.m. UTC | #4
On Thu, Jul 12, 2012 at 11:19:47AM +0300, Avi Kivity wrote:
> On 07/12/2012 05:46 AM, Asias He wrote:
> > On Thu, Jul 12, 2012 at 12:09 AM, Avi Kivity <avi@redhat.com> wrote:
> >> On 07/11/2012 07:08 PM, Asias He wrote:
> >>> VHOST_SET_MEM_TABLE failed: Operation not supported
> >>>
> >>> In vhost_set_memory(), We have
> >>>
> >>>         if (mem.padding)
> >>>                 return -EOPNOTSUPP;
> >>>
> >>> So, we need to zero struct vhost_memory.
> >>>
> >>
> >> Is this due to a change in vhost?
> > 
> > Seems we have this bit in the very beginning (commit 3a4d5c94).
> 
> Okay, so it's a documentation problem.  Michael, where is the
> documentation for vhost-net?

Most fields are documented in include/linux/vhost.h
Yes the approach vhost consistently takes is to require all unused
fields to be zeroed out.

> Note we have to initialize it with memset();

We can also use = {} if we want to avoid naming it.

> presumably when we
> repurpose it the name will change, and anonymous unions are not very
> portable.

Looks like in the new C standard they are :)
I'm not sure what we'll do, exactly, if we need to reuse this padding
for something else, but not breaking build for old userspace
will be a priority.

> -- 
> error compiling committee.c: too many arguments to function
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index ae17eb5..aa769d9 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -471,7 +471,7 @@  static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)
 	if (ndev->vhost_fd < 0)
 		die_perror("Failed openning vhost-net device");
 
-	mem = malloc(sizeof(*mem) + sizeof(struct vhost_memory_region));
+	mem = calloc(1, sizeof(*mem) + sizeof(struct vhost_memory_region));
 	if (mem == NULL)
 		die("Failed allocating memory for vhost memory map");