libxl: Allow copying smaller bitmap into a larger one
PATCH 1/1 libxl: Allow copying smaller bitmap into a larger one
When parsing bitmap objects JSON parser will create libxl_bitmap map of the smallest size needed.
This can cause problems when saved image file specifies CPU affinity. For example, if 'vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated and libxl_bitmap->size will be set to 1.
This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
We could allocate that bitmap of the same size as the source, however, it is later passed to xc_vcpu_setaffinity() which expects it to be sized to the max number of CPUs
Instead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_utils.c | 7 +++++++ tools/libxl/libxl_utils.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +2 -2
@@ -5319,7 +5319,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &hard, cpumap_hard); +libxl_bitmap_copy_partial (ctx, &hard, cpumap_hard); flags =XEN_VCPUAFFINITY_HARD ; }if (cpumap_soft) {
@@ -5327,7 +5327,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &soft, cpumap_soft); +libxl_bitmap_copy_partial (ctx, &soft, cpumap_soft); flags |=XEN_VCPUAFFINITY_SOFT ; }
tools/libxl/libxl_utils.c +7 -0
@@ -614,6 +614,13 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +assert (dptr->size >= sptr->size); +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*dptr->map)); +} +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr)
tools/libxl/libxl_utils.h +2 -0
@@ -80,6 +80,8 @@ void libxl_bitmap_copy_alloc(libxl_ctx *ctx, libxl_bitmap *dptr, const libxl_bitmap *sptr);void libxl_bitmap_copy (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr); +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr);int libxl_bitmap_is_full (const libxl_bitmap *bitmap);int libxl_bitmap_is_empty (const libxl_bitmap *bitmap);int libxl_bitmap_test (const libxl_bitmap *bitmap,int bit);
Signature · 1 line
1.7.1
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
What about copying large bitmap to a smaller one? Say, you migrate to a host whose number of cpus is smaller than the size of the source bitmap. Is this a valid use case?
Should we have a "best effort" copy function? That is,
size = min(source_size, destination_size)
copy(source, destination, size)
In any case I think this is a regression and should be fixed for 4.5.
Wei.
Quoted 62 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_utils.c | 7 +++++++ tools/libxl/libxl_utils.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)tools/libxl/libxl.c +2
-2@@ -5319,7 +5319,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &hard, cpumap_hard); +libxl_bitmap_copy_partial (ctx, &hard, cpumap_hard); flags =XEN_VCPUAFFINITY_HARD ; }if (cpumap_soft) {@@ -5327,7 +5327,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &soft, cpumap_soft); +libxl_bitmap_copy_partial (ctx, &soft, cpumap_soft); flags |=XEN_VCPUAFFINITY_SOFT ; }tools/libxl/libxl_utils.c +7
-0@@ -614,6 +614,13 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +assert (dptr->size >= sptr->size); +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*dptr->map)); +} +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr)tools/libxl/libxl_utils.h +2
-0@@ -80,6 +80,8 @@ void libxl_bitmap_copy_alloc(libxl_ctx *ctx, libxl_bitmap *dptr, const libxl_bitmap *sptr);void libxl_bitmap_copy (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr); +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr);int libxl_bitmap_is_full (const libxl_bitmap *bitmap);int libxl_bitmap_is_empty (const libxl_bitmap *bitmap);int libxl_bitmap_test (const libxl_bitmap *bitmap,int bit);Signature · 1 line
1.7.1
Quoted 20 lines · Wei Liu
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
Quoted 8 lines
What about copying large bitmap to a smaller one? Say, you migrate to a host whose number of cpus is smaller than the size of the source bitmap. Is this a valid use case?
Should we have a "best effort" copy function? That is,
size =
min(source_size, destination_size)
copy(source, destination, size)
Right, I haven't thought about it for the reversed case.
-boris
Quoted 67 lines
In any case I think this is a regression and should be fixed for 4.5.
Wei.
Quoted 62 lines
Signed-off-by Boris Ostrovsky <[email protected]>--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_utils.c | 7 +++++++ tools/libxl/libxl_utils.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)tools/libxl/libxl.c +2
-2@@ -5319,7 +5319,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &hard, cpumap_hard); +libxl_bitmap_copy_partial (ctx, &hard, cpumap_hard); flags =XEN_VCPUAFFINITY_HARD ; }if (cpumap_soft) {@@ -5327,7 +5327,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &soft, cpumap_soft); +libxl_bitmap_copy_partial (ctx, &soft, cpumap_soft); flags |=XEN_VCPUAFFINITY_SOFT ; }tools/libxl/libxl_utils.c +7
-0@@ -614,6 +614,13 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +assert (dptr->size >= sptr->size); +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*dptr->map)); +} +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr)tools/libxl/libxl_utils.h +2
-0@@ -80,6 +80,8 @@ void libxl_bitmap_copy_alloc(libxl_ctx *ctx, libxl_bitmap *dptr, const libxl_bitmap *sptr);void libxl_bitmap_copy (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr); +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr);int libxl_bitmap_is_full (const libxl_bitmap *bitmap);int libxl_bitmap_is_empty (const libxl_bitmap *bitmap);int libxl_bitmap_test (const libxl_bitmap *bitmap,int bit);Signature · 1 line
1.7.1
Quoted 5 lines · Boris Ostrovsky
tools/libxl/libxl_utils.c +0
-0
tools/libxl/libxl_utils.c void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr, · line 623
Quoted 10 lines
tools/libxl/libxl_utils.c +7
-0@@ -614,6 +614,13 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +assert (dptr->size >= sptr->size); +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*dptr->map)); +} +
Looking at other callers of libxl_bitmap_copy(), I think something like this makes sense for pretty much all of them.
And even abstracting from them, and thinking to how a function like 'libxl_bitmap_copy()' this should behave, copying only the "common part" makes sense to me.
So, should we make libxl_bitmap_copy() behave like implemented above, rather than introducing a new function. I know this is public stable API, but I think this is a fine behavioral change, isn't it?
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 20 lines · Dario Faggioli
Quoted 5 lines · Boris Ostrovsky
tools/libxl/libxl_utils.c +0
-0tools/libxl/libxl_utils.c void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr, · line 623
Quoted 10 lines
tools/libxl/libxl_utils.c +7
-0@@ -614,6 +614,13 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_partial (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +assert (dptr->size >= sptr->size); +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*dptr->map)); +} +Looking at other callers of
libxl_bitmap_copy(), I think something like this makes sense for pretty much all of them.
Quoted 7 lines
And even abstracting from them, and thinking to how a function like '
libxl_bitmap_copy()' this should behave, copying only the "common part" makes sense to me.So, should we make
libxl_bitmap_copy()behave like implemented above, rather than introducing a new function. I know this is public stable API, but I think this is a fine behavioral change, isn't it?
I did consider this but wasn't sure about it from the point of view of API behavior. If people feel it's OK to slightly change behavior here I'd rather go this route.
-boris
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
Here is some more thoughts on this issue:
This API is used by VCPU placement and NUMA placement logic in libxl. To fix the breakage, we don't necessary need to expose new API or change API behaviour, we only need to have a internal function to do it.
The reversed case (large bitmap to small one) is not valid in libxl, as in the pinning will fail. But bitmap copy happens before that, we would still need to deal with that. Dario, can you provide some input on the expected behaviour?
The partial copy function should explicitly zero-out all remaining bits.
Wei.
CC'ing Dario...
Quoted 35 lines · Wei Liu
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
Here is some more thoughts on this issue:
This API is used by VCPU placement and NUMA placement logic in libxl. To fix the breakage, we don't necessary need to expose new API or change API behaviour, we only need to have a internal function to do it.
The reversed case (large bitmap to small one) is not valid in libxl, as in the pinning will fail. But bitmap copy happens before that, we would still need to deal with that. Dario, can you provide some input on the expected behaviour?
The partial copy function should explicitly zero-out all remaining bits.
Wei.
Quoted 33 lines · Wei Liu
CC'ing Dario...
Quoted 30 lines · Wei Liu
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
Here is some more thoughts on this issue:
This API is used by VCPU placement and NUMA placement logic in libxl. To fix the breakage, we don't necessary need to expose new API or change API behaviour, we only need to have a internal function to do it.
The reversed case (large bitmap to small one) is not valid in libxl, as in the pinning will fail. But bitmap copy happens before that, we would still need to deal with that. Dario, can you provide some input on the expected behaviour?
I understand that hypervisor will ignore bits that are beyond what it knows about --- see xenctl_bitmap_to_bitmap(). And libxl will will issue a warning. But only if byte-sized bitmaps are the same. If they are not will will pop the assertion (in debug builds).
Quoted 2 lines
Quoted 2 lines
The partial copy function should explicitly zero-out all remaining bits.
I actually thought that partial copy function should do just that --- copy bits that it has and leave others unchanged. The caller, if desires so, should have cleared the mask prior to the call. (This is for the case when destination is larger than source, of course).
-boris
Quoted 10 lines · Boris Ostrovsky
Quoted 2 lines · Wei Liu
Quoted 2 lines
The partial copy function should explicitly zero-out all remaining bits.
I actually thought that partial copy function should do just that --- copy bits that it has and leave others unchanged. The caller, if desires so, should have cleared the mask prior to the call. (This is for the case when destination is larger than source, of course).
Agreed.
Anyway, AFAIU Wei's proposal, he's saying that this new _copy_partial() function can be an internal one, i.e., not part of the public API, or am I wrong, Wei?
If yes, I agree with that.
This leaves the question of whether we should change the behavior of the publicly exposed libxl_bitmap_copy(), which I'm still not sure about, but I guess, if we keep this internal, we can defer thinking to that to some other period not in between RCs?
Thanks and Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 11 lines · Dario Faggioli
Quoted 10 lines · Boris Ostrovsky
Quoted 2 lines · Wei Liu
Quoted 2 lines
The partial copy function should explicitly zero-out all remaining bits.
I actually thought that partial copy function should do just that --- copy bits that it has and leave others unchanged. The caller, if desires so, should have cleared the mask prior to the call. (This is for the case when destination is larger than source, of course).
Quoted 8 lines
Agreed.
Anyway, AFAIU Wei's proposal, he's saying that this new
_copy_partial()function can be an internal one, i.e., not part of the public API, or am I wrong, Wei?If yes, I agree with that.
You're right. I want to make it internal so that we don't need to worry about the public API for now.
Quoted 5 lines
This leaves the question of whether we should change the behavior of the publicly exposed
libxl_bitmap_copy(), which I'm still not sure about, but I guess, if we keep this internal, we can defer thinking to that to some other period not in between RCs?
Yes.
Wei.
Quoted 9 lines
Thanks and Regards,
DarioSignature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
Quoted 35 lines · Boris Ostrovsky
Quoted 33 lines · Wei Liu
CC'ing Dario...
Quoted 30 lines · Wei Liu
Quoted 11 lines · Boris Ostrovsky
When parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
Quoted 8 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsInstead, we should allow copying the (smaller) bitmap read by the parser and keep the rest of bytes in the destination map unmodified (zero in this case)
Here is some more thoughts on this issue:
This API is used by VCPU placement and NUMA placement logic in libxl. To fix the breakage, we don't necessary need to expose new API or change API behaviour, we only need to have a internal function to do it.
The reversed case (large bitmap to small one) is not valid in libxl, as in the pinning will fail. But bitmap copy happens before that, we would still need to deal with that. Dario, can you provide some input on the expected behaviour?
Quoted 5 lines
I understand that hypervisor will ignore bits that are beyond what it knows about --- see
xenctl_bitmap_to_bitmap(). And libxl will will issue a warning. But only if byte-sized bitmaps are the same. If they are not will will pop the assertion (in debug builds).
After a discussion on IRC with Dario, migrating from large host to small one is legit use case. That means we need to take care about the reversed case as well.
BTW, are you on xen-devel@freenode? It would be much faster if we can discuss on IRC.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
The partial copy function should explicitly zero-out all remaining bits.
I actually thought that partial copy function should do just that --- copy bits that it has and leave others unchanged. The caller, if desires so, should have cleared the mask prior to the call. (This is for the case when destination is larger than source, of course).
This is OK as long as this behaviour is documented.
I will prepare a patch shortly for you to test.
Wei.
Quoted 2 lines
-boris
And here it is.
Boris, can you give it a shot?
---8<---
Quoted 1 line
From
77531e31d239887b9f36c03e434300bc30683092Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 25 Nov 2014 10:59:47 +0000
Subject: [PATCH] libxl: allow copying between bitmaps of different sizes
When parsing bitmap objects JSON parser will create libxl_bitmap map of the smallest size needed.
This can cause problems when saved image file specifies CPU affinity. For example, if 'vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated and libxl_bitmap->size will be set to 1.
This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
We could allocate that bitmap of the same size as the source, however, it is later passed to xc_vcpu_setaffinity() which expects it to be sized to the max number of CPUs
To fix this issue, introduce an internal function to allowing copying between bitmaps of different sizes. Note that this function is only used in libxl_set_vcpuaffinity at the moment. Though NUMA placement logic invoke libxl_bitmap_copy as well there's no need to replace those invocations. NUMA placement logic comes into effect when no vcpu / node pinning is provided, so it always operates on bitmap of the same sizes (that is, size of maximum number of cpus /nodes).
---
This fixes a regression for 4.5. Can't think of obvious risk.
--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_internal.h | 11 +++++++++++ tools/libxl/libxl_utils.c | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +2 -2
@@ -5320,7 +5320,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &hard, cpumap_hard); +libxl__bitmap_copy_best_effort (gc, &hard, cpumap_hard); flags =XEN_VCPUAFFINITY_HARD ; }if (cpumap_soft) {
@@ -5328,7 +5328,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &soft, cpumap_soft); +libxl__bitmap_copy_best_effort (gc, &soft, cpumap_soft); flags |=XEN_VCPUAFFINITY_SOFT ; }
tools/libxl/libxl_internal.h +11 -0
@@ -3617,6 +3617,17 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_##type##_copy(CTX, DA_p, (dev)); \ }) +/* This function copies X bytes from source to destination bitmap, +* where X is the smaller of the two sizes. +* +* If destination's size is larger than source, the extra bytes are +* untouched. +* +* XXX This is introduced to fix a regression for 4.5. It shall +* be revisited in 4.6 time frame. +*/ +void libxl__bitmap_copy_best_effort (libxl__gc *gc,libxl_bitmap *dptr, +const libxl_bitmap *sptr);#endif /*
tools/libxl/libxl_utils.c +15 -0
@@ -614,6 +614,21 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +/* This function copies X bytes from source to destination bitmap, +* where X is the smaller of the two sizes. +* +* If destination's size is larger than source, the extra bytes are +* untouched. +*/ +void libxl__bitmap_copy_best_effort (libxl__gc *gc,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +int sz; + + sz = dptr->size < sptr->size ? dptr->size : sptr->size; +memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); +} +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr)
Signature · 1 line
1.7.10.4
Dario Faggioli
Reviewed-byQuoted 33 lines · Wei Liu
And here it is.
Boris, can you give it a shot?
---8<---
From77531e31d239887b9f36c03e434300bc30683092Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 25 Nov 2014 10:59:47 +0000
Subject: [PATCH] libxl: allow copying between bitmaps of different sizesWhen parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsTo fix this issue, introduce an internal function to allowing copying between bitmaps of different sizes. Note that this function is only used in
libxl_set_vcpuaffinityat the moment. Though NUMA placement logic invokelibxl_bitmap_copyas well there's no need to replace those invocations. NUMA placement logic comes into effect when no vcpu / node pinning is provided, so it always operates on bitmap of the same sizes (that is, size of maximum number of cpus /nodes).
Quoted 6 lines
Reported-by Boris Ostrovsky <[email protected]>Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Dario Faggioli <[email protected]>
If this end up being the approach, it can have the following:
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Boris Ostrovsky
Tested-byQuoted 40 lines · Dario Faggioli
Quoted 33 lines · Wei Liu
And here it is.
Boris, can you give it a shot?
---8<---
From77531e31d239887b9f36c03e434300bc30683092Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 25 Nov 2014 10:59:47 +0000
Subject: [PATCH] libxl: allow copying between bitmaps of different sizesWhen parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsTo fix this issue, introduce an internal function to allowing copying between bitmaps of different sizes. Note that this function is only used in
libxl_set_vcpuaffinityat the moment. Though NUMA placement logic invokelibxl_bitmap_copyas well there's no need to replace those invocations. NUMA placement logic comes into effect when no vcpu / node pinning is provided, so it always operates on bitmap of the same sizes (that is, size of maximum number of cpus /nodes).Quoted 6 lines
Reported-by Boris Ostrovsky <[email protected]>Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Dario Faggioli <[email protected]>
Quoted 3 lines
If this end up being the approach, it can have the following:
Reviewed-by Dario Faggioli <[email protected]>
Quoted 41 lines · Boris Ostrovsky
Quoted 40 lines · Dario Faggioli
Quoted 39 lines · Wei Liu
And here it is.
Boris, can you give it a shot?
---8<---
From77531e31d239887b9f36c03e434300bc30683092Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 25 Nov 2014 10:59:47 +0000
Subject: [PATCH] libxl: allow copying between bitmaps of different sizesWhen parsing bitmap objects JSON parser will create
libxl_bitmapmap of the smallest size needed.This can cause problems when saved image file specifies CPU affinity. For example, if '
vcpu_hard_affinity' in the saved image has only the first CPU specified, just a single byte will be allocated andlibxl_bitmap->sizewill be set to 1.This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsTo fix this issue, introduce an internal function to allowing copying between bitmaps of different sizes. Note that this function is only used in
libxl_set_vcpuaffinityat the moment. Though NUMA placement logic invokelibxl_bitmap_copyas well there's no need to replace those invocations. NUMA placement logic comes into effect when no vcpu / node pinning is provided, so it always operates on bitmap of the same sizes (that is, size of maximum number of cpus /nodes).Reported-by Boris Ostrovsky <[email protected]>Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Dario Faggioli <[email protected]>
Quoted 5 lines
Quoted 3 lines
If this end up being the approach, it can have the following:
Reviewed-by Dario Faggioli <[email protected]>Tested-by Boris Ostrovsky <[email protected]>
Thank you!
Quoted 2 lines
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Reported-by Boris Ostrovsky <[email protected]>Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Dario Faggioli <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
If this end up being the approach, it can have the following:
Reviewed-by Dario Faggioli <[email protected]>Tested-by Boris Ostrovsky <[email protected]>Release-Acked-by Konrad Rzeszutek Wilk <[email protected]>
Acked +Applied.
Quoted 2 lines · Wei Liu
This will result in assertion in libxl_set_vcpuaffinity()->libxl_bitmap_copy() since the destination bitmap is created for maximum number of CPUs.
FYI I'm also seeing this with libvirt (on ARM, but I don't think that matters) when the guest XML uses:
<vcpu placement='static' cpuset='0-7'>1</vcpu>
Results in:
libvirtd: libxl_utils.c:612: libxl_bitmap_copy: Assertion `dptr->size == sptr->size' failed.
Program received signal SIGABRT, Aborted.
[Switching to Thread 0xb67f9420 (LWP 3881)]
0xb6ab7f96 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
(gdb) bt
#0 0xb6ab7f96 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
#1 0xb6ac5f8a in raise () from /lib/arm-linux-gnueabihf/libc.so.6
#2 0xb6ac8428 in abort () from /lib/arm-linux-gnueabihf/libc.so.6
#3 0xb6ac101e in __assert_fail () from /lib/arm-linux-gnueabihf/libc.so.6
#4 0xb16caeb4 in libxl_bitmap_copy (ctx=<optimized out>, dptr=<optimized out>, sptr=<optimized out>) at libxl_utils.c:612
#5 0xb16af15c in libxl_set_vcpuaffinity (ctx=0x2, domid=3065494508, vcpuid=0, cpumap_hard=0xb67f8668, cpumap_soft=0x0) at libxl.c:5323
#6 0xb17195ae in libxlDomainSetVcpuAffinities () from /opt/libvirt/lib/libvirt/connection-driver/libvirt_driver_libxl.so
#7 0xb1719cf2 in libxlDomainStart () from /opt/libvirt/lib/libvirt/connection-driver/libvirt_driver_libxl.so
#8 0xb171b7c2 in libxlDomainCreateXML () from /opt/libvirt/lib/libvirt/connection-driver/libvirt_driver_libxl.so
#9 0xb6d28630 in virDomainCreateXML () from /opt/libvirt/lib/libvirt.so.0
[...snip...]libxlDomainSetVcpuAffinities does:
libxl_bitmap map;
[...]
map.size = cpumaplen;
map.map = cpumap;
if (libxl_set_vcpuaffinity(priv->ctx, def->id, vcpu, &map) != 0) {Applying this libxl patch fixes things.
I don't think we've explicitly outlawed looking "inside" a libxl_bitmap in this way anywhere, so I think libvirtd is within its rights to do so, but it does highlight that we need to be mindful within libxl that people may not be using libxl_cpu_bitmap_alloc.
Quoted 96 lines
We could allocate that bitmap of the same size as the source, however, it is later passed to
xc_vcpu_setaffinity()which expects it to be sized to the max number of CPUsTo fix this issue, introduce an internal function to allowing copying between bitmaps of different sizes. Note that this function is only used in
libxl_set_vcpuaffinityat the moment. Though NUMA placement logic invokelibxl_bitmap_copyas well there's no need to replace those invocations. NUMA placement logic comes into effect when no vcpu / node pinning is provided, so it always operates on bitmap of the same sizes (that is, size of maximum number of cpus /nodes).Reported-by Boris Ostrovsky <[email protected]>Signed-off-by Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>Cc Dario Faggioli <[email protected]>---
This fixes a regression for 4.5. Can't think of obvious risk.--- tools/libxl/libxl.c | 4 ++-- tools/libxl/libxl_internal.h | 11 +++++++++++ tools/libxl/libxl_utils.c | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-)tools/libxl/libxl.c +2
-2@@ -5320,7 +5320,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &hard, cpumap_hard); +libxl__bitmap_copy_best_effort (gc, &hard, cpumap_hard); flags =XEN_VCPUAFFINITY_HARD ; }if (cpumap_soft) {@@ -5328,7 +5328,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,if (rc) goto out; -libxl_bitmap_copy (ctx, &soft, cpumap_soft); +libxl__bitmap_copy_best_effort (gc, &soft, cpumap_soft); flags |=XEN_VCPUAFFINITY_SOFT ; }tools/libxl/libxl_internal.h +11
-0@@ -3617,6 +3617,17 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_##type##_copy(CTX, DA_p, (dev)); \ }) +/* This function copies X bytes from source to destination bitmap, +* where X is the smaller of the two sizes. +* +* If destination's size is larger than source, the extra bytes are +* untouched. +* +* XXX This is introduced to fix a regression for 4.5. It shall +* be revisited in 4.6 time frame. +*/ +void libxl__bitmap_copy_best_effort (libxl__gc *gc,libxl_bitmap *dptr, +const libxl_bitmap *sptr);#endif /* tools/libxl/libxl_utils.c +15
-0@@ -614,6 +614,21 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +/* This function copies X bytes from source to destination bitmap, +* where X is the smaller of the two sizes. +* +* If destination's size is larger than source, the extra bytes are +* untouched. +*/ +void libxl__bitmap_copy_best_effort (libxl__gc *gc,libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +int sz; + + sz = dptr->size < sptr->size ? dptr->size : sptr->size; +memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); +} +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr)