Skip to contentSkip to conversation

Fix xm vcpu-pin command

PATCH In review Masaki Kanno 2 participants 4 messages Feb 19, 2008 – Feb 20, 2008 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix xm vcpu-pin command

Hi,

When I tested xm vcpu-pin command, I encountered the following strange problem. I encountered it on x86, but I didn't encounter it on ia64.

On x86:

 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     0   -b-      31.3 any cpu
 Domain-0                             0     1     1   r--      30.1 any cpu
 # xm vcpu-pin Domain-0 0 64
 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     0   -b-      31.5 0
 Domain-0                             0     1     1   r--      31.1 any cpu
 # xm vcpu-pin Domain-0 0 65
 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     1   -b-      32.0 1
 Domain-0                             0     1     0   r--      31.6 any cpu

On ia64:

 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     0   r--      13.2 any cpu
 Domain-0                             0     1     1   -b-      10.8 any cpu
 # xm vcpu-pin Domain-0 0 64
 Error: Cannot pin vcpu: 0 to cpu: [64] - (22, 'Invalid argument')
 Usage: xm vcpu-pin <Domain> <VCPU|all> <CPUs|all>

Set which CPUs a VCPU can use.

 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     0   r--      13.5 any cpu
 Domain-0                             0     1     1   -b-      11.0 any cpu
 # xm vcpu-pin Domain-0 0 65
 Error: Cannot pin vcpu: 0 to cpu: [65] - (22, 'Invalid argument')
 Usage: xm vcpu-pin <Domain> <VCPU|all> <CPUs|all>

Set which CPUs a VCPU can use.

 # xm vcpu-list
 Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
 Domain-0                             0     0     0   r--      13.7 any cpu
 Domain-0                             0     1     1   -b-      11.3 any cpu

I could not understand why the problem occurs. But I would like to solve the problem, so I send an ad hoc patch. If you can solve the problem, I hope that the problem is solved by your patch.

Best regards,
Kan

tools/python/xen/lowlevel/xc/xc.c +11 -1
diff -r 8848d9e07584 tools/python/xen/lowlevel/xc/xc.c
@@ -214,6 +214,7 @@ static PyObject *pyxc_vcpu_setaffinity(X
 {
     uint32_t dom;
     int vcpu = 0, i;
+    long cpu = 0;
     uint64_t  cpumap = ~0ULL;
     PyObject *cpulist = NULL;
 
@@ -227,7 +228,16 @@ static PyObject *pyxc_vcpu_setaffinity(X
     {
         cpumap = 0ULL;
         for ( i = 0; i < PyList_Size(cpulist); i++ ) 
-            cpumap |= (uint64_t)1 << PyInt_AsLong(PyList_GetItem(cpulist, i));
+        {
+            cpu = PyInt_AsLong(PyList_GetItem(cpulist, i));
+            if ( cpu >= 64 )
+            {
+                errno = EINVAL;
+                PyErr_SetFromErrno(xc_error_obj);
+                return NULL;
+            }
+            cpumap |= (uint64_t)1 << cpu;
+        }
     }
   
     if ( xc_vcpu_setaffinity(self->xc_handle, dom, vcpu, cpumap) != 0 )

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines · Masaki Kanno

I could not understand why the problem occurs. But I would like to solve the problem, so I send an ad hoc patch. If you can solve the problem, I hope that the problem is solved by your patch.

In C, shifting by more bits than the width of the value being shifted is undefined. This explains the difference in behaviour between ia64 and x86. Your patch seems sensible.

-- Keir

#2 lore raw
Quoted 9 lines · Keir Fraser
Quoted 3 lines · Masaki Kanno

I could not understand why the problem occurs. But I would like to solve the problem, so I send an ad hoc patch. If you can solve the problem, I hope that the problem is solved by your patch.

In C, shifting by more bits than the width of the value being shifted is undefined. This explains the difference in behaviour between ia64 and x86. Your patch seems sensible.

Well, then could you apply my patch?

Best regards,
Kan

#3 lore raw

It's in the queue

Quoted 18 lines · Masaki Kanno
Quoted 9 lines · Keir Fraser
Quoted 3 lines · Masaki Kanno

I could not understand why the problem occurs. But I would like to solve the problem, so I send an ad hoc patch. If you can solve the problem, I hope that the problem is solved by your patch.

In C, shifting by more bits than the width of the value being shifted is undefined. This explains the difference in behaviour between ia64 and x86. Your patch seems sensible.

Well, then could you apply my patch?

Best regards,
Kan