Skip to contentSkip to conversation

Display IO topology when PXM data is available (plus some cleanup)

PATCH Superseded Boris Ostrovsky 7 participants 49 messages Feb 9, 2015 – Feb 23, 2015 18 messages not in the archive Arm/actions semi architecture

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover Display IO topology when PXM data is available (plus some cleanup)

Changes in v3:
* Added patch #1 to more consistently define nodes as a u8 and properly use NUMA_NO_NODE.
* Make changes to xen_sysctl_numainfo, similar to those made to xen_sysctl_topologyinfo. (Q: I kept both sets of changes in the same patch #3 to avoid bumping interface version twice. Perhaps it's better to split it into two?)
* Instead of copying data for each loop index allocate a buffer and copy once for all three queries in sysctl.c.
* Move hypercall buffer management from libxl to libxc (as requested by Dario, patches #5 and #6).
* Report topology info for offlined CPUs as well
* Added LIBXL_HAVE_PCITOPO macro

Changes in v2:
* Split topology sysctls into two --- one for CPU topology and the other for devices
* Avoid long loops in the hypervisor by using continuations. (I am not particularly happy about using first_dev in the interface, suggestions for a better interface would be appreciated)
* Use proper libxl conventions for interfaces
* Avoid hypervisor stack corruption when copying PXM data from guest

A few patches that add interface for querying hypervisor about device topology and allow 'xl info -n' display this information if PXM object is provided by ACPI.

This series also makes some optimizations and cleanup of current CPU topology and NUMA sysctl queries.

Boris Ostrovsky (7):
x86/numa: Make use of NUMA_NO_NODE consistent
pci: Do not ignore device's PXM information
sysctl: Make topologyinfo and numainfo sysctls a little more
efficient
sysctl: Add sysctl interface for querying PCI topology libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer
management to libxc
libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management
to libxc
libxl: Add interface for querying hypervisor about PCI topology

 tools/libxc/include/xenctrl.h       |   11 ++-
 tools/libxc/xc_misc.c               |   84 ++++++++++++---
 tools/libxl/libxl.c                 |  152 ++++++++++++-------------
 tools/libxl/libxl.h                 |   14 +++
 tools/libxl/libxl_freebsd.c         |   14 +++
 tools/libxl/libxl_internal.h        |    5 +
 tools/libxl/libxl_linux.c           |   74 ++++++++++++
 tools/libxl/libxl_netbsd.c          |   14 +++
 tools/libxl/libxl_types.idl         |    7 +
 tools/libxl/libxl_utils.c           |    8 ++
 tools/libxl/xl_cmdimpl.c            |   44 ++++++-
 tools/misc/xenpm.c                  |   92 ++++++---------
 tools/python/xen/lowlevel/xc/xc.c   |  103 ++++++-----------
 xen/arch/x86/physdev.c              |   23 ++++-
 xen/arch/x86/smpboot.c              |    2 +-
 xen/arch/x86/srat.c                 |   39 ++++---
 xen/arch/x86/x86_64/mm.c            |    2 +-
 xen/common/sysctl.c                 |  214 ++++++++++++++++++++++++++---------
 xen/drivers/passthrough/pci.c       |   13 ++-
 xen/drivers/passthrough/vtd/iommu.c |    4 +-
 xen/include/asm-x86/numa.h          |    4 +-
 xen/include/public/physdev.h        |    6 +
 xen/include/public/sysctl.h         |  104 ++++++++++++-----
 xen/include/xen/pci.h               |    5 +-
 24 files changed, 698 insertions(+), 340 deletions(-)
#1 lore raw

PATCH v3 1/7 x86/numa: Make use of NUMA_NO_NODE consistent

Various pieces of code test whether node value is NUMA_NO_NODE even though pxm_to_node() may return (int)-1 for an invalid node.

Make pxm_to_node() and setup_node() return u8 and have them return NUMA_NO_NODE when necessary.

Adjust code that tests for (node == -1).

---
 xen/arch/x86/smpboot.c              |    2 +-
 xen/arch/x86/srat.c                 |   39 ++++++++++++++++++++++------------
 xen/arch/x86/x86_64/mm.c            |    2 +-
 xen/drivers/passthrough/vtd/iommu.c |    4 +-
 xen/include/asm-x86/numa.h          |    4 +-
 5 files changed, 31 insertions(+), 20 deletions(-)
xen/arch/x86/smpboot.c +1 -1
index c54be7e..97956be 100644
@@ -877,7 +877,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm)
 
     if ( !srat_disabled() )
     {
-        if ( (node = setup_node(pxm)) < 0 )
+        if ( (node = setup_node(pxm)) == NUMA_NO_NODE )
         {
             dprintk(XENLOG_WARNING,
                     "Setup node failed for pxm %x\n", pxm);
xen/arch/x86/srat.c +25 -14
index 29fc724..4dfa1c3 100644
@@ -21,13 +21,16 @@
 #include <asm/e820.h>
 #include <asm/page.h>
 
+#define MAX_PXM   255
+
 static struct acpi_table_slit *__read_mostly acpi_slit;
 
 static nodemask_t memory_nodes_parsed __initdata;
 static nodemask_t processor_nodes_parsed __initdata;
 static nodemask_t nodes_found __initdata;
 static struct node nodes[MAX_NUMNODES] __initdata;
-static u8 __read_mostly pxm2node[256] = { [0 ... 255] = NUMA_NO_NODE };
+static u8 __read_mostly pxm2node[MAX_PXM + 1] =
+    { [0 ... MAX_PXM] = NUMA_NO_NODE };
 
 
 static int num_node_memblks;
@@ -37,21 +40,29 @@ static int memblk_nodeid[NR_NODE_MEMBLKS];
 
 static int node_to_pxm(int n);
 
-int pxm_to_node(int pxm)
+u8 pxm_to_node(int pxm)
 {
-	if ((unsigned)pxm >= 256)
-		return -1;
-	/* Extend 0xff to (int)-1 */
-	return (signed char)pxm2node[pxm];
+	if ((unsigned)pxm > MAX_PXM)
+		return NUMA_NO_NODE;
+
+	return pxm2node[pxm];
 }
 
-__devinit int setup_node(int pxm)
+__devinit u8 setup_node(int pxm)
 {
-	unsigned node = pxm2node[pxm];
-	if (node == 0xff) {
+	u8 node;
+
+	/* NUMA_NO_NODE is 255 */
+	BUILD_BUG_ON(MAX_NUMNODES > 254);
+
+	if ((unsigned)pxm > MAX_PXM)
+		return NUMA_NO_NODE;
+
+	node = pxm2node[pxm];
+	if (node == NUMA_NO_NODE) {
 		if (nodes_weight(nodes_found) >= MAX_NUMNODES)
-			return -1;
-		node = first_unset_node(nodes_found); 
+			return NUMA_NO_NODE;
+		node = first_unset_node(nodes_found);
 		node_set(node, nodes_found);
 		pxm2node[pxm] = node;
 	}
@@ -175,7 +186,7 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 		return;
 	pxm = pa->proximity_domain;
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
@@ -208,7 +219,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 		pxm |= pa->proximity_domain_hi[2] << 24;
 	}
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
@@ -252,7 +263,7 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 	if (srat_rev < 2)
 		pxm &= 0xff;
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains.\n");
 		bad_srat();
 		return;
xen/arch/x86/x86_64/mm.c +1 -1
index d631aee..4817dad 100644
@@ -1353,7 +1353,7 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     if ( !mem_hotadd_check(spfn, epfn) )
         return -EINVAL;
 
-    if ( (node = setup_node(pxm)) == -1 )
+    if ( (node = setup_node(pxm)) == NUMA_NO_NODE )
         return -EINVAL;
 
     if ( !valid_numa_range(spfn << PAGE_SHIFT, epfn << PAGE_SHIFT, node) )
xen/drivers/passthrough/vtd/iommu.c +2 -2
index 19d8165..fd48f7b 100644
@@ -190,14 +190,14 @@ u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages)
     struct acpi_rhsa_unit *rhsa;
     struct page_info *pg, *cur_pg;
     u64 *vaddr;
-    int node = -1, i;
+    int node = NUMA_NO_NODE, i;
 
     rhsa = drhd_to_rhsa(drhd);
     if ( rhsa )
         node =  pxm_to_node(rhsa->proximity_domain);
 
     pg = alloc_domheap_pages(NULL, get_order_from_pages(npages),
-                             (node == -1 ) ? 0 : MEMF_node(node));
+                             (node == NUMA_NO_NODE ) ? 0 : MEMF_node(node));
     if ( !pg )
         return 0;
 
xen/include/asm-x86/numa.h +2 -2
index 5959860..2a43827 100644
@@ -21,7 +21,7 @@ struct node {
 
 extern int compute_hash_shift(struct node *nodes, int numnodes,
 			      int *nodeids);
-extern int pxm_to_node(int nid);
+extern u8 pxm_to_node(int nid);
 
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
 #define VIRTUAL_BUG_ON(x) 
@@ -33,7 +33,7 @@ extern int numa_off;
 
 extern int srat_disabled(void);
 extern void numa_set_node(int cpu, int node);
-extern int setup_node(int pxm);
+extern u8 setup_node(int pxm);
 extern void srat_detect_node(int cpu);
 
 extern void setup_node_bootmem(int nodeid, u64 start, u64 end);
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH v3 1/7] x86/numa: Make use of NUMA_NO_NODE consistent

Quoted 9 lines · Boris Ostrovsky

Various pieces of code test whether node value is NUMA_NO_NODE even though pxm_to_node() may return (int)-1 for an invalid node.

Make pxm_to_node() and setup_node() return u8 and have them return NUMA_NO_NODE when necessary.

Adjust code that tests for (node == -1).

Looks fine. A few minor comments.

Quoted 44 lines
---
 xen/arch/x86/smpboot.c              |    2 +-
 xen/arch/x86/srat.c                 |   39 ++++++++++++++++++++++------------
 xen/arch/x86/x86_64/mm.c            |    2 +-
 xen/drivers/passthrough/vtd/iommu.c |    4 +-
 xen/include/asm-x86/numa.h          |    4 +-
 5 files changed, 31 insertions(+), 20 deletions(-)
xen/arch/x86/smpboot.c +1 -1
index c54be7e..97956be 100644
@@ -877,7 +877,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm)
 
     if ( !srat_disabled() )
     {
-        if ( (node = setup_node(pxm)) < 0 )
+        if ( (node = setup_node(pxm)) == NUMA_NO_NODE )
         {
             dprintk(XENLOG_WARNING,
                     "Setup node failed for pxm %x\n", pxm);
xen/arch/x86/srat.c +4 -1
index 29fc724..4dfa1c3 100644
@@ -21,13 +21,16 @@
 #include <asm/e820.h>
 #include <asm/page.h>
 
+#define MAX_PXM   255
+
 static struct acpi_table_slit *__read_mostly acpi_slit;
 
 static nodemask_t memory_nodes_parsed __initdata;
 static nodemask_t processor_nodes_parsed __initdata;
 static nodemask_t nodes_found __initdata;
 static struct node nodes[MAX_NUMNODES] __initdata;
-static u8 __read_mostly pxm2node[256] = { [0 ... 255] = NUMA_NO_NODE };
+static u8 __read_mostly pxm2node[MAX_PXM + 1] =
+    { [0 ... MAX_PXM] = NUMA_NO_NODE };
 
 
 static int num_node_memblks;

xen/arch/x86/srat.c static int memblk_nodeid[NR_NODE_MEMBLKS]; · line 43

Quoted 5 lines
xen/arch/x86/srat.c +1 -1
@@ -37,21 +40,29 @@ static int memblk_nodeid[NR_NODE_MEMBLKS];
 
 static int node_to_pxm(int n);
 
-int pxm_to_node(int pxm)
+u8 pxm_to_node(int pxm)

You can make these parameters unsigned and do away with the unsigned casting. pxm appears to be unsigned in all the relevant call chains.

Quoted 82 lines
xen/arch/x86/srat.c +20 -12
 {
-	if ((unsigned)pxm >= 256)
-		return -1;
-	/* Extend 0xff to (int)-1 */
-	return (signed char)pxm2node[pxm];
+	if ((unsigned)pxm > MAX_PXM)
+		return NUMA_NO_NODE;
+
+	return pxm2node[pxm];
 }
 
-__devinit int setup_node(int pxm)
+__devinit u8 setup_node(int pxm)
 {
-	unsigned node = pxm2node[pxm];
-	if (node == 0xff) {
+	u8 node;
+
+	/* NUMA_NO_NODE is 255 */
+	BUILD_BUG_ON(MAX_NUMNODES > 254);
+
+	if ((unsigned)pxm > MAX_PXM)
+		return NUMA_NO_NODE;
+
+	node = pxm2node[pxm];
+	if (node == NUMA_NO_NODE) {
 		if (nodes_weight(nodes_found) >= MAX_NUMNODES)
-			return -1;
-		node = first_unset_node(nodes_found); 
+			return NUMA_NO_NODE;
+		node = first_unset_node(nodes_found);
 		node_set(node, nodes_found);
 		pxm2node[pxm] = node;
 	}
@@ -175,7 +186,7 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 		return;
 	pxm = pa->proximity_domain;
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
@@ -208,7 +219,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 		pxm |= pa->proximity_domain_hi[2] << 24;
 	}
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
 		bad_srat();
 		return;
@@ -252,7 +263,7 @@ acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
 	if (srat_rev < 2)
 		pxm &= 0xff;
 	node = setup_node(pxm);
-	if (node < 0) {
+	if (node == NUMA_NO_NODE) {
 		printk(KERN_ERR "SRAT: Too many proximity domains.\n");
 		bad_srat();
 		return;
xen/arch/x86/x86_64/mm.c +1 -1
index d631aee..4817dad 100644
@@ -1353,7 +1353,7 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     if ( !mem_hotadd_check(spfn, epfn) )
         return -EINVAL;
 
-    if ( (node = setup_node(pxm)) == -1 )
+    if ( (node = setup_node(pxm)) == NUMA_NO_NODE )
         return -EINVAL;
 
     if ( !valid_numa_range(spfn << PAGE_SHIFT, epfn << PAGE_SHIFT, node) )
xen/drivers/passthrough/vtd/iommu.c +0 -0
index 19d8165..fd48f7b 100644
@@ -190,14 +190,14 @@ u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages)
     struct acpi_rhsa_unit *rhsa;
     struct page_info *pg, *cur_pg;
     u64 *vaddr;

xen/drivers/passthrough/vtd/iommu.c u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages) · line 200

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-    int node = -1, i;
+    int node = NUMA_NO_NODE, i;
 
     rhsa = drhd_to_rhsa(drhd);
     if ( rhsa )
         node =  pxm_to_node(rhsa->proximity_domain);
 
     pg = alloc_domheap_pages(NULL, get_order_from_pages(npages),
-                             (node == -1 ) ? 0 : MEMF_node(node));
+                             (node == NUMA_NO_NODE ) ? 0 : MEMF_node(node));

Drop the stray space while you are editing this line.

xen/include/asm-x86/numa.h struct node { · line 24

Quoted 13 lines
xen/drivers/passthrough/vtd/iommu.c +0 -0
     if ( !pg )
         return 0;
 
xen/include/asm-x86/numa.h +1 -1
index 5959860..2a43827 100644
@@ -21,7 +21,7 @@ struct node {
 
 extern int compute_hash_shift(struct node *nodes, int numnodes,
 			      int *nodeids);
-extern int pxm_to_node(int nid);
+extern u8 pxm_to_node(int nid);

The parameter should presumably be named pxm?

~Andrew

Quoted 12 lines
xen/include/asm-x86/numa.h +1 -1
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
 #define VIRTUAL_BUG_ON(x) 
@@ -33,7 +33,7 @@ extern int numa_off;
 
 extern int srat_disabled(void);
 extern void numa_set_node(int cpu, int node);
-extern int setup_node(int pxm);
+extern u8 setup_node(int pxm);
 extern void srat_detect_node(int cpu);
 
 extern void setup_node_bootmem(int nodeid, u64 start, u64 end);
#3 lore raw

Re: [PATCH v3 1/7] x86/numa: Make use of NUMA_NO_NODE consistent

In reply to Boris Ostrovsky

xen/include/asm-x86/numa.h struct node { · line 24

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.02.15 at 21:04, <[email protected]> wrote:
xen/include/asm-x86/numa.h +1 -1
@@ -21,7 +21,7 @@ struct node {
 
 extern int compute_hash_shift(struct node *nodes, int numnodes,
 			      int *nodeids);
-extern int pxm_to_node(int nid);
+extern u8 pxm_to_node(int nid);

Perhaps introduce nodeid_t, so that once needed it can be widened?

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [PATCH v3 1/7] x86/numa: Make use of NUMA_NO_NODE consistent

Quoted 10 lines · Jan Beulich

xen/include/asm-x86/numa.h struct node { · line 24

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 09.02.15 at 21:04, <[email protected]> wrote:
xen/include/asm-x86/numa.h +1 -1
@@ -21,7 +21,7 @@ struct node {
 
  extern int compute_hash_shift(struct node *nodes, int numnodes,
  			      int *nodeids);
-extern int pxm_to_node(int nid);
+extern u8 pxm_to_node(int nid);

Perhaps introduce nodeid_t, so that once needed it can be widened?

Yes. I actually thing there are more references to node IDs throughout the code that may need adjusting.

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH v3 1/7] x86/numa: Make use of NUMA_NO_NODE consistent

Quoted 26 lines · Andrew Cooper
Quoted 24 lines · Boris Ostrovsky
xen/arch/x86/srat.c +4 -1
index 29fc724..4dfa1c3 100644
@@ -21,13 +21,16 @@
 #include <asm/e820.h>
 #include <asm/page.h>
 
+#define MAX_PXM   255
+
 static struct acpi_table_slit *__read_mostly acpi_slit;
 
 static nodemask_t memory_nodes_parsed __initdata;
 static nodemask_t processor_nodes_parsed __initdata;
 static nodemask_t nodes_found __initdata;
 static struct node nodes[MAX_NUMNODES] __initdata;
-static u8 __read_mostly pxm2node[256] = { [0 ... 255] = NUMA_NO_NODE };
+static u8 __read_mostly pxm2node[MAX_PXM + 1] =
+    { [0 ... MAX_PXM] = NUMA_NO_NODE };
 
 
 static int num_node_memblks;
@@ -37,21 +40,29 @@ static int memblk_nodeid[NR_NODE_MEMBLKS];
 
Quoted 8 lines

xen/arch/x86/srat.c static int memblk_nodeid[NR_NODE_MEMBLKS]; · line 43

Quoted 4 lines
xen/arch/x86/srat.c +1 -1
 static int node_to_pxm(int n);
 
-int pxm_to_node(int pxm)
+u8 pxm_to_node(int pxm)

You can make these parameters unsigned and do away with the unsigned casting. pxm appears to be unsigned in all the relevant call chains.

+1

Quoted 6 lines
Quoted 6 lines
xen/include/asm-x86/numa.h +0 -0
index 5959860..2a43827 100644
@@ -21,7 +21,7 @@ struct node {
 
Quoted 7 lines

xen/include/asm-x86/numa.h struct node { · line 24

Quoted 4 lines
xen/include/asm-x86/numa.h +1 -1
 extern int compute_hash_shift(struct node *nodes, int numnodes,
 			      int *nodeids);
-extern int pxm_to_node(int nid);
+extern u8 pxm_to_node(int nid);

The parameter should presumably be named pxm?

+1 :-)

Regards,
Dario

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

#8 lore raw

PATCH v3 2/7 pci: Do not ignore device's PXM information

In reply to Boris Ostrovsky

If ACPI provides PXM data for IO devices then dom0 will pass it to hypervisor during PHYSDEVOP_pci_device_add call. This information, however, is currently ignored.

We will store this information (in the form of nodeID) in pci_dev structure so that we can provide it, for example, to the toolstack when it adds support (in the following patches) for querying the hypervisor about device topology

We will also print it when user requests device information dump.

---
 xen/arch/x86/physdev.c        |   23 ++++++++++++++++++++---
 xen/drivers/passthrough/pci.c |   13 +++++++++----
 xen/include/public/physdev.h  |    6 ++++++
 xen/include/xen/pci.h         |    5 ++++-
 4 files changed, 39 insertions(+), 8 deletions(-)
xen/arch/x86/physdev.c +20 -3
index 6b3201b..ab92fa5 100644
@@ -565,7 +565,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(0, manage_pci.bus, manage_pci.devfn, NULL);
+        ret = pci_add_device(0, manage_pci.bus, manage_pci.devfn,
+                             NULL, NUMA_NO_NODE);
         break;
     }
 
@@ -597,13 +598,14 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
         ret = pci_add_device(0, manage_pci_ext.bus,
                              manage_pci_ext.devfn,
-                             &pdev_info);
+                             &pdev_info, NUMA_NO_NODE);
         break;
     }
 
     case PHYSDEVOP_pci_device_add: {
         struct physdev_pci_device_add add;
         struct pci_dev_info pdev_info;
+        u8 node;
 
         ret = -EFAULT;
         if ( copy_from_guest(&add, arg, 1) != 0 )
@@ -618,7 +620,22 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         }
         else
             pdev_info.is_virtfn = 0;
-        ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info);
+
+        if ( add.flags & XEN_PCI_DEV_PXM )
+        {
+            uint32_t pxm;
+            size_t optarr_off = offsetof(struct physdev_pci_device_add, optarr) /
+                                sizeof(add.optarr[0]);
+
+            if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) )
+                break;
+
+            node = pxm_to_node(pxm);
+        }
+        else
+            node = NUMA_NO_NODE;
+
+        ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, node);
         break;
     }
 
xen/drivers/passthrough/pci.c +9 -4
index 78c6977..43b4384 100644
@@ -568,7 +568,8 @@ static void pci_enable_acs(struct pci_dev *pdev)
     pci_conf_write16(seg, bus, dev, func, pos + PCI_ACS_CTRL, ctrl);
 }
 
-int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
+int pci_add_device(u16 seg, u8 bus, u8 devfn,
+                   const struct pci_dev_info *info, u8 node)
 {
     struct pci_seg *pseg;
     struct pci_dev *pdev;
@@ -586,7 +587,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
         pdev = pci_get_pdev(seg, info->physfn.bus, info->physfn.devfn);
         spin_unlock(&pcidevs_lock);
         if ( !pdev )
-            pci_add_device(seg, info->physfn.bus, info->physfn.devfn, NULL);
+            pci_add_device(seg, info->physfn.bus, info->physfn.devfn,
+                           NULL, node);
         pdev_type = "virtual function";
     }
     else
@@ -609,6 +611,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
     if ( !pdev )
         goto out;
 
+    pdev->node = node;
+
     if ( info )
         pdev->info = *info;
     else if ( !pdev->vf_rlen[0] )
@@ -1191,10 +1195,11 @@ static int _dump_pci_devices(struct pci_seg *pseg, void *arg)
 
     list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
     {
-        printk("%04x:%02x:%02x.%u - dom %-3d - MSIs < ",
+        printk("%04x:%02x:%02x.%u - dom %-3d - node %-3d - MSIs < ",
                pseg->nr, pdev->bus,
                PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
-               pdev->domain ? pdev->domain->domain_id : -1);
+               pdev->domain ? pdev->domain->domain_id : -1,
+               (pdev->node != NUMA_NO_NODE) ? pdev->node : -1);
         list_for_each_entry ( msi, &pdev->msi_list, list )
                printk("%d ", msi->irq);
         printk(">\n");
xen/include/public/physdev.h +6 -0
index d547928..309346b 100644
@@ -293,6 +293,12 @@ struct physdev_pci_device_add {
         uint8_t bus;
         uint8_t devfn;
     } physfn;
+
+    /*
+     * Optional parameters array.
+     * First element ([0]) is PXM domain associated with the device (if
+     * XEN_PCI_DEV_PXM is set)
+     */
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
     uint32_t optarr[];
 #elif defined(__GNUC__)
xen/include/xen/pci.h +4 -1
index 5f295f3..1acab53 100644
@@ -56,6 +56,8 @@ struct pci_dev {
 
     u8 phantom_stride;
 
+    u8 node; /* NUMA node */
+
     enum pdev_type {
         DEV_TYPE_PCI_UNKNOWN,
         DEV_TYPE_PCIe_ENDPOINT,
@@ -102,7 +104,8 @@ void setup_hwdom_pci_devices(struct domain *,
 int pci_release_devices(struct domain *d);
 int pci_add_segment(u16 seg);
 const unsigned long *pci_get_ro_map(u16 seg);
-int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *);
+int pci_add_device(u16 seg, u8 bus, u8 devfn,
+                   const struct pci_dev_info *, u8 node);
 int pci_remove_device(u16 seg, u8 bus, u8 devfn);
 int pci_ro_device(int seg, int bus, int devfn);
 void arch_pci_ro_device(int seg, int bdf);
Signature · 1 line
1.7.1
#9 lore raw

PATCH v3 3/7 sysctl: Make topologyinfo and numainfo sysctls a little more efficient

In reply to Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Clarify some somments in sysctl.h.

---
 tools/libxc/include/xenctrl.h     |    4 +-
 tools/libxc/xc_misc.c             |   10 ++--
 tools/libxl/libxl.c               |   71 +++++++------------
 tools/misc/xenpm.c                |   69 +++++++-----------
 tools/python/xen/lowlevel/xc/xc.c |   77 ++++++++------------
 xen/common/sysctl.c               |  141 ++++++++++++++++++++++---------------
 xen/include/public/sysctl.h       |   75 ++++++++++++--------
 7 files changed, 221 insertions(+), 226 deletions(-)
tools/libxc/include/xenctrl.h +2 -2
index 0ad8b8d..0cb6743 100644
@@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch,
 int xc_send_debug_keys(xc_interface *xch, char *keys);
 
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_sysctl_topologyinfo_t xc_topologyinfo_t;
+typedef xen_sysctl_cputopoinfo_t xc_cputopoinfo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
@@ -1237,7 +1237,7 @@ typedef uint64_t xc_node_to_memfree_t;
 typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
-int xc_topologyinfo(xc_interface *xch, xc_topologyinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, xc_cputopoinfo_t *info);
 int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
 
 int xc_sched_id(xc_interface *xch,
tools/libxc/xc_misc.c +5 -5
index e253a58..be68291 100644
@@ -177,20 +177,20 @@ int xc_physinfo(xc_interface *xch,
     return 0;
 }
 
-int xc_topologyinfo(xc_interface *xch,
-                xc_topologyinfo_t *put_info)
+int xc_cputopoinfo(xc_interface *xch,
+                   xc_cputopoinfo_t *put_info)
 {
     int ret;
     DECLARE_SYSCTL;
 
-    sysctl.cmd = XEN_SYSCTL_topologyinfo;
+    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
 
-    memcpy(&sysctl.u.topologyinfo, put_info, sizeof(*put_info));
+    memcpy(&sysctl.u.cputopoinfo, put_info, sizeof(*put_info));
 
     if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
         return ret;
 
-    memcpy(put_info, &sysctl.u.topologyinfo, sizeof(*put_info));
+    memcpy(put_info, &sysctl.u.cputopoinfo, sizeof(*put_info));
 
     return 0;
 }
tools/libxl/libxl.c +27 -44

132 lines not on this page · raw message

tools/misc/xenpm.c +27 -42

151 lines not on this page · raw message

tools/python/xen/lowlevel/xc/xc.c +30 -47

163 lines not on this page · raw message

xen/common/sysctl.c +85 -56

170 lines not on this page · raw message

xen/include/public/sysctl.h +45 -30

125 lines not on this page · raw message

Signature · 1 line
1.7.1
#10 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 14 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Clarify some somments in sysctl.h.

Quoted 7 lines
---
 tools/libxc/include/xenctrl.h     |    4 +-
 tools/libxc/xc_misc.c             |   10 ++--
 tools/libxl/libxl.c               |   71 +++++++------------
 tools/misc/xenpm.c                |   69 +++++++-----------
 tools/python/xen/lowlevel/xc/xc.c |   77 ++++++++------------

Are these mostly mechanical changes? I'm assuming yes.

Quoted 3 lines
 xen/common/sysctl.c               |  141 ++++++++++++++++++++++---------------
 xen/include/public/sysctl.h       |   75 ++++++++++++--------
 7 files changed, 221 insertions(+), 226 deletions(-)

[...]

tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5146

Quoted 4 lines
tools/libxl/libxl.c +2 -2
-        (ctx->xch, node_dists, sizeof(*node_dists) * max_nodes * max_nodes);
-    if ((memsize == NULL) || (memfree == NULL) || (node_dists == NULL)) {
+    meminfo = xc_hypercall_buffer_alloc(ctx->xch, meminfo, sizeof(*meminfo) * max_nodes);
+    distance = xc_hypercall_buffer_alloc(ctx->xch, distance, sizeof(*distance) * max_nodes * max_nodes);

Please wrap these two lines to <80 column.

Quoted 3 lines

+ if ((meminfo == NULL) || (distance == NULL)) {
LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
"Unable to allocate hypercall arguments");

[...]

tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds) · line 1231

Quoted 4 lines
tools/python/xen/lowlevel/xc/xc.c +1 -3
-    set_xen_guest_handle(tinfo.cpu_to_core, coremap);
-    set_xen_guest_handle(tinfo.cpu_to_socket, socketmap);
-    set_xen_guest_handle(tinfo.cpu_to_node, nodemap);
+    cputopo = xc_hypercall_buffer_alloc(self->xc_handle, cputopo, sizeof(*cputopo) * (MAX_CPU_INDEX+1));

Line too long.

Quoted 4 lines
tools/python/xen/lowlevel/xc/xc.c +3 -0
+    if ( cputopo == NULL )
+	goto out;
+    set_xen_guest_handle(tinfo.cputopo, cputopo);
     tinfo.max_cpu_index = MAX_CPU_INDEX;

[...]

tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_numainfo(XcObject *self) · line 1313

Quoted 4 lines
tools/python/xen/lowlevel/xc/xc.c +1 -3
-        goto out;
-    node_memfree = xc_hypercall_buffer_alloc(self->xc_handle, node_memfree, sizeof(*node_memfree)*(MAX_NODE_INDEX+1));
-    if ( node_memfree == NULL )
+    meminfo = xc_hypercall_buffer_alloc(self->xc_handle, meminfo, sizeof(*meminfo) * (MAX_NODE_INDEX+1));

Ditto.

tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_numainfo(XcObject *self) · line 1316

Quoted 5 lines
tools/python/xen/lowlevel/xc/xc.c +2 -2
+    if ( meminfo == NULL )
         goto out;
-    nodes_dist = xc_hypercall_buffer_alloc(self->xc_handle, nodes_dist, sizeof(*nodes_dist)*(MAX_NODE_INDEX+1)*(MAX_NODE_INDEX+1));
-    if ( nodes_dist == NULL )
+    distance = xc_hypercall_buffer_alloc(self->xc_handle, distance, sizeof(*distance)*(MAX_NODE_INDEX+1)*(MAX_NODE_INDEX+1));

Ditto.

Wei.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 15 lines · Wei Liu
Quoted 14 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Clarify some somments in sysctl.h.

Quoted 8 lines
Quoted 7 lines
---
  tools/libxc/include/xenctrl.h     |    4 +-
  tools/libxc/xc_misc.c             |   10 ++--
  tools/libxl/libxl.c               |   71 +++++++------------
  tools/misc/xenpm.c                |   69 +++++++-----------
  tools/python/xen/lowlevel/xc/xc.c |   77 ++++++++------------

Are these mostly mechanical changes? I'm assuming yes.

Pretty much, yes.

-boris

Quoted 5 lines
Quoted 4 lines
  xen/common/sysctl.c               |  141 ++++++++++++++++++++++---------------
  xen/include/public/sysctl.h       |   75 ++++++++++++--------
  7 files changed, 221 insertions(+), 226 deletions(-)
#13 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

In reply to Boris Ostrovsky
Quoted 8 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Quoted 8 lines

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Clarify some somments in sysctl.h.

AFAIUI, this patch will change, so I'll look at it again in next version. What I've seen here seemed all good to me.

Dario

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

#14 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 13 lines · Dario Faggioli
Quoted 12 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Quoted 6 lines
Quoted 4 lines

Clarify some somments in sysctl.h.

AFAIUI, this patch will change, so I'll look at it again in next version. What I've seen here seemed all good to me.

Jan and Andrew don't want to make changes that I describe in the first paragraph so that will probably be different in the next version.

-boris

#15 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

In reply to Boris Ostrovsky
Quoted 8 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Quoted 7 lines

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Clarify some somments in sysctl.h.

Was there a significant change in v3 which invalidated my tools ack from <[email protected]>?

Per-patch changelogs (after the ---) are very helpful for this sort of thing.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 13 lines · Ian Campbell
Quoted 12 lines · Boris Ostrovsky

Currently both of these sysctls make a copy to userspace for each index of various query arrays. We should try to copy whole arrays instead.

This requires some changes in sysctl's public data structure, thus bump interface version.

Report topology for all present (not just online) cpus.

Rename xen_sysctl_topologyinfo and XEN_SYSCTL_topologyinfo to reflect the fact that these are used for CPU topology. Subsequent patch will add support for PCI topology sysctl.

Quoted 5 lines
Quoted 3 lines

Clarify some somments in sysctl.h.

Was there a significant change in v3 which invalidated my tools ack from <[email protected]>?

Yes, because I merged changes that you ACKed together with (similar) changes for numa topology. Which will now have to unmerge because various people didn't like it. So I think your ACK will be restored.

Quoted 3 lines

Per-patch changelogs (after the ---) are very helpful for this sort of thing.

I should have at least mentioned this in the cover letter, sorry.

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 17:48, <[email protected]> wrote:
Quoted 2 lines · Ian Campbell

Per-patch changelogs (after the ---) are very helpful for this sort of thing.

I should have at least mentioned this in the cover letter, sorry.

Actually I also meant to suggest that you switch away from listing the changes (only) in the cover letter - reviewing, especially for later revisions, is easier when each patch lists what got changed.

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#21 lore raw

Re: [PATCH v3 3/7] sysctl: Make topologyinfo and numainfo sysctls a little more efficient

Quoted 11 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 17:48, <[email protected]> wrote:
Quoted 2 lines · Ian Campbell

Per-patch changelogs (after the ---) are very helpful for this sort of thing.

I should have at least mentioned this in the cover letter, sorry.

Actually I also meant to suggest that you switch away from listing the changes (only) in the cover letter - reviewing, especially for later revisions, is easier when each patch lists what got changed.

Please. I find it hard to figure out which patch a given change in the cover letter actually impacts, plus it means I need to keep two mails open to look at both...

#22 lore raw

PATCH v3 4/7 sysctl: Add sysctl interface for querying PCI topology

In reply to Boris Ostrovsky
---
 xen/common/sysctl.c         |   73 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h |   29 +++++++++++++++++
 2 files changed, 102 insertions(+), 0 deletions(-)
xen/common/sysctl.c +73 -0
index 30c5806..ea6557f 100644
@@ -384,7 +384,80 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         xfree(cputopo);
     }
     break;
+#ifdef HAS_PCI
+    case XEN_SYSCTL_pcitopoinfo:
+    {
+        xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo;
+        physdev_pci_device_t *devs;
+        uint8_t *nodes;
+        unsigned int first_dev, i;
+        int num_devs;
+
+        num_devs = ti->num_devs - ti->first_dev;
+
+        if ( guest_handle_is_null(ti->devs) ||
+             guest_handle_is_null(ti->nodes) ||
+             (num_devs <= 0) )
+        {
+            ret = -EINVAL;
+            break;
+        }
+
+        devs = xmalloc_array(physdev_pci_device_t, num_devs);
+        nodes = xmalloc_array(uint8_t, num_devs);
+        if ( !devs || !nodes )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -ENOMEM;
+            break;
+        }
+
+        first_dev = ti->first_dev;
+
+        if ( copy_from_guest_offset(devs, ti->devs, first_dev, num_devs) )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -EFAULT;
+            break;
+        }
 
+        for ( i = 0; i < num_devs; i++ )
+        {
+            struct pci_dev *pdev;
+
+            spin_lock(&pcidevs_lock);
+            pdev = pci_get_pdev(devs[i].seg, devs[i].bus, devs[i].devfn);
+            if ( !pdev || (pdev->node == NUMA_NO_NODE) )
+                nodes[i] = INVALID_NODE_ID;
+            else
+                nodes[i] = pdev->node;
+            spin_unlock(&pcidevs_lock);
+
+            if ( hypercall_preempt_check() )
+                break;
+        }
+
+        ti->first_dev += i + 1;
+
+        if ( __copy_field_to_guest(u_sysctl, op,
+                                   u.pcitopoinfo.first_dev) ||
+             copy_to_guest_offset(ti->nodes, first_dev, nodes,num_devs) )
+        {
+            ret = -EFAULT;
+            break;
+        }
+
+        if ( ti->first_dev < ti->num_devs )
+            ret = hypercall_create_continuation(__HYPERVISOR_sysctl,
+                                               "h", u_sysctl);
+
+        xfree(devs);
+        xfree(nodes);
+    }
+    break;
+#endif
 #ifdef TEST_COVERAGE
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_coverage_op(&op->u.coverage_op);
xen/include/public/sysctl.h +29 -0
index 7c78f81..044c3a1 100644
@@ -33,6 +33,7 @@
 
 #include "xen.h"
 #include "domctl.h"
+#include "physdev.h"
 
 #define XEN_SYSCTL_INTERFACE_VERSION 0x0000000C
 
@@ -494,6 +495,32 @@ struct xen_sysctl_cputopoinfo {
 typedef struct xen_sysctl_cputopoinfo xen_sysctl_cputopoinfo_t;
 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopoinfo_t);
 
+/* XEN_SYSCTL_pcitopoinfo */
+struct xen_sysctl_pcitopoinfo {
+    /* IN: Size of pcitopo array */
+    uint32_t num_devs;
+
+    /*
+     * IN/OUT: First element of pcitopo array that needs to be processed by
+     * hypervisor.
+     * This is used primarily by hypercall continuations and callers will
+     * typically set it to zero
+     */
+    uint32_t first_dev;
+
+    /* IN: list of devices */
+    XEN_GUEST_HANDLE_64(physdev_pci_device_t) devs;
+
+    /*
+     * OUT: node identifier for each device.
+     * If information for a particular device is not avalable then set
+     * to INVALID_NODE_ID.
+     */
+    XEN_GUEST_HANDLE_64(uint8) nodes;
+};
+typedef struct xen_sysctl_pcitopoinfo xen_sysctl_pcitopoinfo_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_pcitopoinfo_t);
+
 /* XEN_SYSCTL_numainfo */
 #define INVALID_MEM_SZ (~0U)
 
@@ -692,12 +719,14 @@ struct xen_sysctl {
 #define XEN_SYSCTL_scheduler_op                  19
 #define XEN_SYSCTL_coverage_op                   20
 #define XEN_SYSCTL_psr_cmt_op                    21
+#define XEN_SYSCTL_pcitopoinfo                   22
     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
     union {
         struct xen_sysctl_readconsole       readconsole;
         struct xen_sysctl_tbuf_op           tbuf_op;
         struct xen_sysctl_physinfo          physinfo;
         struct xen_sysctl_cputopoinfo       cputopoinfo;
+        struct xen_sysctl_pcitopoinfo       pcitopoinfo;
         struct xen_sysctl_numainfo          numainfo;
         struct xen_sysctl_sched_id          sched_id;
         struct xen_sysctl_perfc_op          perfc_op;
Signature · 1 line
1.7.1
#23 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

    Date:        Mon,  9 Feb 2015 15:04:32 -0500
    From:        Boris Ostrovsky <[email protected]>
    Message-ID:  <[email protected]>
  | +        num_devs = ti->num_devs - ti->first_dev;
  | +
  | +        if ( guest_handle_is_null(ti->devs) ||
  | +             guest_handle_is_null(ti->nodes) ||
  | +             (num_devs <= 0) )
  | +        {
  | +            ret = -EINVAL;
  | +            break;
  | +        }

Does that need a check that ti->first_dev <= ti_num_devs ?

(that is aside from the issue of subtracting one uint from another and hoping that you'll get a negative signed int if the one subtracted is bigger).

The (num_devs <= 0) test (even if it works - which it should on most rational architectures) isn't good enough, as it is possible to subtract a very big uint from a very small unit and end up with an int that is positive (and potentially, very big, consider (32bit): 2 - 0x80000001).

So, replace the (num_devs <= 0) test by (ti->first_dev <= ti->num_devs) ??

Or possibly include both tests, just in case ti->num_devs is very large and ti->first_dev is small (like 0) and when the large unsigned is converted to signed, it becomes negative - or is all of this just too impossible to worry about?

kre

#24 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

In reply to Boris Ostrovsky
Quoted 25 lines · Boris Ostrovsky
---
 xen/common/sysctl.c         |   73 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h |   29 +++++++++++++++++
 2 files changed, 102 insertions(+), 0 deletions(-)
xen/common/sysctl.c +11 -0
index 30c5806..ea6557f 100644
@@ -384,7 +384,80 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         xfree(cputopo);
     }
     break;
+#ifdef HAS_PCI
+    case XEN_SYSCTL_pcitopoinfo:
+    {
+        xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo;
+        physdev_pci_device_t *devs;
+        uint8_t *nodes;
+        unsigned int first_dev, i;
+        int num_devs;
+
+        num_devs = ti->num_devs - ti->first_dev;
+

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 407

Quoted 10 lines
xen/common/sysctl.c +10 -0
+        if ( guest_handle_is_null(ti->devs) ||
+             guest_handle_is_null(ti->nodes) ||
+             (num_devs <= 0) )
+        {
+            ret = -EINVAL;
+            break;
+        }
+
+        devs = xmalloc_array(physdev_pci_device_t, num_devs);
+        nodes = xmalloc_array(uint8_t, num_devs);

You can do all of this without any memory allocation at all, which will simplify your error handling substantially.

Something along the lines of

for(...)
{
copy one physdev_pci_device_t from the guest

do the lookup

copy one node id back to the guest
}

~Andrew

Quoted 116 lines
xen/common/sysctl.c +52 -0
+        if ( !devs || !nodes )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -ENOMEM;
+            break;
+        }
+
+        first_dev = ti->first_dev;
+
+        if ( copy_from_guest_offset(devs, ti->devs, first_dev, num_devs) )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -EFAULT;
+            break;
+        }
 
+        for ( i = 0; i < num_devs; i++ )
+        {
+            struct pci_dev *pdev;
+
+            spin_lock(&pcidevs_lock);
+            pdev = pci_get_pdev(devs[i].seg, devs[i].bus, devs[i].devfn);
+            if ( !pdev || (pdev->node == NUMA_NO_NODE) )
+                nodes[i] = INVALID_NODE_ID;
+            else
+                nodes[i] = pdev->node;
+            spin_unlock(&pcidevs_lock);
+
+            if ( hypercall_preempt_check() )
+                break;
+        }
+
+        ti->first_dev += i + 1;
+
+        if ( __copy_field_to_guest(u_sysctl, op,
+                                   u.pcitopoinfo.first_dev) ||
+             copy_to_guest_offset(ti->nodes, first_dev, nodes,num_devs) )
+        {
+            ret = -EFAULT;
+            break;
+        }
+
+        if ( ti->first_dev < ti->num_devs )
+            ret = hypercall_create_continuation(__HYPERVISOR_sysctl,
+                                               "h", u_sysctl);
+
+        xfree(devs);
+        xfree(nodes);
+    }
+    break;
+#endif
 #ifdef TEST_COVERAGE
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_coverage_op(&op->u.coverage_op);
xen/include/public/sysctl.h +29 -0
index 7c78f81..044c3a1 100644
@@ -33,6 +33,7 @@
 
 #include "xen.h"
 #include "domctl.h"
+#include "physdev.h"
 
 #define XEN_SYSCTL_INTERFACE_VERSION 0x0000000C
 
@@ -494,6 +495,32 @@ struct xen_sysctl_cputopoinfo {
 typedef struct xen_sysctl_cputopoinfo xen_sysctl_cputopoinfo_t;
 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopoinfo_t);
 
+/* XEN_SYSCTL_pcitopoinfo */
+struct xen_sysctl_pcitopoinfo {
+    /* IN: Size of pcitopo array */
+    uint32_t num_devs;
+
+    /*
+     * IN/OUT: First element of pcitopo array that needs to be processed by
+     * hypervisor.
+     * This is used primarily by hypercall continuations and callers will
+     * typically set it to zero
+     */
+    uint32_t first_dev;
+
+    /* IN: list of devices */
+    XEN_GUEST_HANDLE_64(physdev_pci_device_t) devs;
+
+    /*
+     * OUT: node identifier for each device.
+     * If information for a particular device is not avalable then set
+     * to INVALID_NODE_ID.
+     */
+    XEN_GUEST_HANDLE_64(uint8) nodes;
+};
+typedef struct xen_sysctl_pcitopoinfo xen_sysctl_pcitopoinfo_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_pcitopoinfo_t);
+
 /* XEN_SYSCTL_numainfo */
 #define INVALID_MEM_SZ (~0U)
 
@@ -692,12 +719,14 @@ struct xen_sysctl {
 #define XEN_SYSCTL_scheduler_op                  19
 #define XEN_SYSCTL_coverage_op                   20
 #define XEN_SYSCTL_psr_cmt_op                    21
+#define XEN_SYSCTL_pcitopoinfo                   22
     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
     union {
         struct xen_sysctl_readconsole       readconsole;
         struct xen_sysctl_tbuf_op           tbuf_op;
         struct xen_sysctl_physinfo          physinfo;
         struct xen_sysctl_cputopoinfo       cputopoinfo;
+        struct xen_sysctl_pcitopoinfo       pcitopoinfo;
         struct xen_sysctl_numainfo          numainfo;
         struct xen_sysctl_sched_id          sched_id;
         struct xen_sysctl_perfc_op          perfc_op;
#25 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 41 lines · Andrew Cooper
Quoted 25 lines · Boris Ostrovsky
---
  xen/common/sysctl.c         |   73 +++++++++++++++++++++++++++++++++++++++++++
  xen/include/public/sysctl.h |   29 +++++++++++++++++
  2 files changed, 102 insertions(+), 0 deletions(-)
xen/common/sysctl.c +11 -0
index 30c5806..ea6557f 100644
@@ -384,7 +384,80 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
          xfree(cputopo);
      }
      break;
+#ifdef HAS_PCI
+    case XEN_SYSCTL_pcitopoinfo:
+    {
+        xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo;
+        physdev_pci_device_t *devs;
+        uint8_t *nodes;
+        unsigned int first_dev, i;
+        int num_devs;
+
+        num_devs = ti->num_devs - ti->first_dev;
+

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 407

Quoted 10 lines
xen/common/sysctl.c +10 -0
+        if ( guest_handle_is_null(ti->devs) ||
+             guest_handle_is_null(ti->nodes) ||
+             (num_devs <= 0) )
+        {
+            ret = -EINVAL;
+            break;
+        }
+
+        devs = xmalloc_array(physdev_pci_device_t, num_devs);
+        nodes = xmalloc_array(uint8_t, num_devs);

You can do all of this without any memory allocation at all, which will simplify your error handling substantially.

Something along the lines of

Quoted 8 lines

for(...)
{
copy one physdev_pci_device_t from the guest

do the lookup

copy one node id back to the guest
}

I am trying to avoid doing multiple copies. For lots of devices (IIRC, you said you had a system with a few thousand), having two copies per loop will add up, I think.

If you look at changes to cputopolgy and numatopology in earlier patch (the one you said you'd postpone reviewing until I split the third patch) I you will see that I did the same thing there.

-boris

Quoted 120 lines

~Andrew

Quoted 116 lines
xen/common/sysctl.c +52 -0
+        if ( !devs || !nodes )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -ENOMEM;
+            break;
+        }
+
+        first_dev = ti->first_dev;
+
+        if ( copy_from_guest_offset(devs, ti->devs, first_dev, num_devs) )
+        {
+            xfree(devs);
+            xfree(nodes);
+            ret = -EFAULT;
+            break;
+        }
 
+        for ( i = 0; i < num_devs; i++ )
+        {
+            struct pci_dev *pdev;
+
+            spin_lock(&pcidevs_lock);
+            pdev = pci_get_pdev(devs[i].seg, devs[i].bus, devs[i].devfn);
+            if ( !pdev || (pdev->node == NUMA_NO_NODE) )
+                nodes[i] = INVALID_NODE_ID;
+            else
+                nodes[i] = pdev->node;
+            spin_unlock(&pcidevs_lock);
+
+            if ( hypercall_preempt_check() )
+                break;
+        }
+
+        ti->first_dev += i + 1;
+
+        if ( __copy_field_to_guest(u_sysctl, op,
+                                   u.pcitopoinfo.first_dev) ||
+             copy_to_guest_offset(ti->nodes, first_dev, nodes,num_devs) )
+        {
+            ret = -EFAULT;
+            break;
+        }
+
+        if ( ti->first_dev < ti->num_devs )
+            ret = hypercall_create_continuation(__HYPERVISOR_sysctl,
+                                               "h", u_sysctl);
+
+        xfree(devs);
+        xfree(nodes);
+    }
+    break;
+#endif
  #ifdef TEST_COVERAGE
      case XEN_SYSCTL_coverage_op:
          ret = sysctl_coverage_op(&op->u.coverage_op);
xen/include/public/sysctl.h +29 -0
index 7c78f81..044c3a1 100644
@@ -33,6 +33,7 @@
 
  #include "xen.h"
  #include "domctl.h"
+#include "physdev.h"
 
  #define XEN_SYSCTL_INTERFACE_VERSION 0x0000000C
 
@@ -494,6 +495,32 @@ struct xen_sysctl_cputopoinfo {
  typedef struct xen_sysctl_cputopoinfo xen_sysctl_cputopoinfo_t;
  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopoinfo_t);
 
+/* XEN_SYSCTL_pcitopoinfo */
+struct xen_sysctl_pcitopoinfo {
+    /* IN: Size of pcitopo array */
+    uint32_t num_devs;
+
+    /*
+     * IN/OUT: First element of pcitopo array that needs to be processed by
+     * hypervisor.
+     * This is used primarily by hypercall continuations and callers will
+     * typically set it to zero
+     */
+    uint32_t first_dev;
+
+    /* IN: list of devices */
+    XEN_GUEST_HANDLE_64(physdev_pci_device_t) devs;
+
+    /*
+     * OUT: node identifier for each device.
+     * If information for a particular device is not avalable then set
+     * to INVALID_NODE_ID.
+     */
+    XEN_GUEST_HANDLE_64(uint8) nodes;
+};
+typedef struct xen_sysctl_pcitopoinfo xen_sysctl_pcitopoinfo_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_pcitopoinfo_t);
+
  /* XEN_SYSCTL_numainfo */
  #define INVALID_MEM_SZ (~0U)
 
@@ -692,12 +719,14 @@ struct xen_sysctl {
  #define XEN_SYSCTL_scheduler_op                  19
  #define XEN_SYSCTL_coverage_op                   20
  #define XEN_SYSCTL_psr_cmt_op                    21
+#define XEN_SYSCTL_pcitopoinfo                   22
      uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
      union {
          struct xen_sysctl_readconsole       readconsole;
          struct xen_sysctl_tbuf_op           tbuf_op;
          struct xen_sysctl_physinfo          physinfo;
          struct xen_sysctl_cputopoinfo       cputopoinfo;
+        struct xen_sysctl_pcitopoinfo       pcitopoinfo;
          struct xen_sysctl_numainfo          numainfo;
          struct xen_sysctl_sched_id          sched_id;
          struct xen_sysctl_perfc_op          perfc_op;

A message that is not in the archive (sent off-list or not yet received): [email protected]

#27 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 49 lines · Boris Ostrovsky
Quoted 47 lines · Andrew Cooper
Quoted 27 lines · Boris Ostrovsky
---
  xen/common/sysctl.c         |   73
+++++++++++++++++++++++++++++++++++++++++++
  xen/include/public/sysctl.h |   29 +++++++++++++++++
  2 files changed, 102 insertions(+), 0 deletions(-)
xen/common/sysctl.c +11 -0
index 30c5806..ea6557f 100644
@@ -384,7 +384,80 @@ long
 do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
          xfree(cputopo);
      }
      break;
+#ifdef HAS_PCI
+    case XEN_SYSCTL_pcitopoinfo:
+    {
+        xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo;
+        physdev_pci_device_t *devs;
+        uint8_t *nodes;
+        unsigned int first_dev, i;
+        int num_devs;
+
+        num_devs = ti->num_devs - ti->first_dev;
+

xen/common/sysctl.c long · line 408

Quoted 10 lines
xen/common/sysctl.c +10 -0
+        if ( guest_handle_is_null(ti->devs) ||
+             guest_handle_is_null(ti->nodes) ||
+             (num_devs <= 0) )
+        {
+            ret = -EINVAL;
+            break;
+        }
+
+        devs = xmalloc_array(physdev_pci_device_t, num_devs);
+        nodes = xmalloc_array(uint8_t, num_devs);

You can do all of this without any memory allocation at all, which will simplify your error handling substantially.

Something along the lines of

for(...)
{
copy one physdev_pci_device_t from the guest

Quoted 8 lines
Quoted 4 lines

do the lookup

copy one node id back to the guest
}

I am trying to avoid doing multiple copies. For lots of devices (IIRC, you said you had a system with a few thousand), having two copies per loop will add up, I think.

copy_to/from_guest() is not expensive. It is a straight memcpy with an extable guards for pagefaults.

~Andrew

A message that is not in the archive (sent off-list or not yet received): [email protected]

#29 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 51 lines · Andrew Cooper
Quoted 50 lines · Boris Ostrovsky
Quoted 49 lines · Andrew Cooper
Quoted 27 lines · Boris Ostrovsky
---
   xen/common/sysctl.c         |   73
+++++++++++++++++++++++++++++++++++++++++++
   xen/include/public/sysctl.h |   29 +++++++++++++++++
   2 files changed, 102 insertions(+), 0 deletions(-)
xen/common/sysctl.c +11 -0
index 30c5806..ea6557f 100644
@@ -384,7 +384,80 @@ long
 do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
           xfree(cputopo);
       }
       break;
+#ifdef HAS_PCI
+    case XEN_SYSCTL_pcitopoinfo:
+    {
+        xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo;
+        physdev_pci_device_t *devs;
+        uint8_t *nodes;
+        unsigned int first_dev, i;
+        int num_devs;
+
+        num_devs = ti->num_devs - ti->first_dev;
+

xen/common/sysctl.c long · line 408

Quoted 10 lines
xen/common/sysctl.c +10 -0
+        if ( guest_handle_is_null(ti->devs) ||
+             guest_handle_is_null(ti->nodes) ||
+             (num_devs <= 0) )
+        {
+            ret = -EINVAL;
+            break;
+        }
+
+        devs = xmalloc_array(physdev_pci_device_t, num_devs);
+        nodes = xmalloc_array(uint8_t, num_devs);

You can do all of this without any memory allocation at all, which will simplify your error handling substantially.

Something along the lines of

for(...)
{
copy one physdev_pci_device_t from the guest

do the lookup

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

copy one node id back to the guest
}

I am trying to avoid doing multiple copies. For lots of devices (IIRC, you said you had a system with a few thousand), having two copies per loop will add up, I think.

copy_to/from_guest() is not expensive. It is a straight memcpy with an extable guards for pagefaults.

True, but still why do this inside a loop? xmalloc() of less than a page is not that expensive, is it?

(The downside is that when we have really lots of devices we may be asking for more than one page. I know that we try not to do this but again, I think the expense would be amortised over long loops.).

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#31 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 11 lines
Quoted 1 line
Quoted 1 line

Boris Ostrovsky <[email protected]> 02/10/15 4:07 PM >>>

Quoted 2 lines · Andrew Cooper

copy_to/from_guest() is not expensive. It is a straight memcpy with an extable guards for pagefaults.

True, but still why do this inside a loop? xmalloc() of less than a page is not that expensive, is it?

(The downside is that when we have really lots of devices we may be asking for more than one page. I know that we try not to do this but again, I think the expense would be amortised over long loops.).

And risk failing the hypercall because there isn't enough contiguous memory? And that perhaps only on really large systems where debugging may end up being difficult? No, please don't.

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#33 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line

Boris Ostrovsky <[email protected]> 02/10/15 4:07 PM >>>

Quoted 2 lines · Andrew Cooper

copy_to/from_guest() is not expensive. It is a straight memcpy with an extable guards for pagefaults.

True, but still why do this inside a loop? xmalloc() of less than a page is not that expensive, is it?

Quoted 6 lines
Quoted 3 lines

(The downside is that when we have really lots of devices we may be asking for more than one page. I know that we try not to do this but again, I think the expense would be amortised over long loops.).

And risk failing the hypercall because there isn't enough contiguous memory? And that perhaps only on really large systems where debugging may end up being difficult? No, please don't.

Indeed. This hypercall is not part of a fastpath. It can afford not to amortise the cost in the name of making the code more simple and less liable to fail.

~Andrew

#34 lore raw

PATCH v3 5/7 libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

In reply to Boris Ostrovsky
---
 tools/libxc/include/xenctrl.h     |    4 +-
 tools/libxc/xc_misc.c             |   23 +++++++++++-----
 tools/libxl/libxl.c               |   32 +++++------------------
 tools/misc/xenpm.c                |   51 ++++++++++++++++---------------------
 tools/python/xen/lowlevel/xc/xc.c |   23 ++++++-----------
 5 files changed, 55 insertions(+), 78 deletions(-)
tools/libxc/include/xenctrl.h +2 -2
index 0cb6743..d94571d 100644
@@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch,
 int xc_send_debug_keys(xc_interface *xch, char *keys);
 
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_sysctl_cputopoinfo_t xc_cputopoinfo_t;
+typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
@@ -1237,7 +1237,7 @@ typedef uint64_t xc_node_to_memfree_t;
 typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
-int xc_cputopoinfo(xc_interface *xch, xc_cputopoinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);
 int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
 
 int xc_sched_id(xc_interface *xch,
tools/libxc/xc_misc.c +16 -7
index be68291..4c654f3 100644
@@ -177,22 +177,31 @@ int xc_physinfo(xc_interface *xch,
     return 0;
 }
 
-int xc_cputopoinfo(xc_interface *xch,
-                   xc_cputopoinfo_t *put_info)
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus,
+                   xc_cputopo_t *cputopo)
 {
     int ret;
     DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(cputopo, *max_cpus * sizeof(*cputopo),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
 
-    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
+    if ((ret = xc_hypercall_bounce_pre(xch, cputopo)))
+        goto out;
 
-    memcpy(&sysctl.u.cputopoinfo, put_info, sizeof(*put_info));
+    sysctl.u.cputopoinfo.max_cpu_index = *max_cpus;
+    set_xen_guest_handle(sysctl.u.cputopoinfo.cputopo, cputopo);
+
+    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
 
     if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
-        return ret;
+        goto out;
 
-    memcpy(put_info, &sysctl.u.cputopoinfo, sizeof(*put_info));
+    *max_cpus = sysctl.u.cputopoinfo.max_cpu_index + 1;
 
-    return 0;
+out:
+    xc_hypercall_bounce_post(xch, cputopo);
+
+    return ret;
 }
 
 int xc_numainfo(xc_interface *xch,
tools/libxl/libxl.c +7 -25
index b05c0bb..f8d64c2 100644
@@ -5072,38 +5072,23 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 {
     GC_INIT(ctx);
-    xc_cputopoinfo_t tinfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
+    xc_cputopo_t *cputopo;
     libxl_cputopology *ret = NULL;
-    int i;
-    int max_cpus;
+    int i, max_cpus;
 
     max_cpus = libxl_get_max_cpus(ctx);
-    if (max_cpus < 0)
-    {
+    if (max_cpus < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
-        ret = NULL;
         goto out;
     }
 
-    cputopo = xc_hypercall_buffer_alloc(ctx->xch, cputopo,
-                                        sizeof(*cputopo) * max_cpus);
-    if (cputopo == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");
-        goto fail;
-    }
+    cputopo = libxl__zalloc(gc, sizeof(*cputopo) * max_cpus);
 
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = max_cpus - 1;
-    if (xc_cputopoinfo(ctx->xch, &tinfo) != 0) {
+    if (xc_cputopoinfo(ctx->xch, &max_cpus, cputopo) != 0) {
         LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "CPU topology info hypercall failed");
-        goto fail;
+        goto out;
     }
 
-    if (tinfo.max_cpu_index < max_cpus - 1)
-        max_cpus = tinfo.max_cpu_index + 1;
-
     ret = libxl__zalloc(NOGC, sizeof(libxl_cputopology) * max_cpus);
 
     for (i = 0; i < max_cpus; i++) {
@@ -5115,11 +5100,8 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 #undef V
     }
 
-fail:
-    xc_hypercall_buffer_free(ctx->xch, cputopo);
+    *nb_cpu_out = max_cpus;
 
-    if (ret)
-        *nb_cpu_out = max_cpus;
  out:
     GC_FREE;
     return ret;
tools/misc/xenpm.c +22 -29

124 lines not on this page · raw message

tools/python/xen/lowlevel/xc/xc.c +8 -15
index 4275968..6e49dc5 100644
@@ -1221,31 +1221,24 @@ static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds)
 static PyObject *pyxc_topologyinfo(XcObject *self)
 {
 #define MAX_CPU_INDEX 255
-    xc_cputopoinfo_t tinfo = { 0 };
-    int i, max_cpu_index;
+    xc_cputopo_t *cputopo;
+    int i, max_cpus;
     PyObject *ret_obj = NULL;
     PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
 
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-
-    cputopo = xc_hypercall_buffer_alloc(self->xc_handle, cputopo, sizeof(*cputopo) * (MAX_CPU_INDEX+1));
+    max_cpus = MAX_CPU_INDEX + 1;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
 	goto out;
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = MAX_CPU_INDEX;
 
-    if ( xc_cputopoinfo(self->xc_handle, &tinfo) != 0 )
+    if ( xc_cputopoinfo(self->xc_handle, &max_cpus, cputopo) != 0 )
         goto out;
 
-    max_cpu_index = tinfo.max_cpu_index;
-    if ( max_cpu_index > MAX_CPU_INDEX )
-        max_cpu_index = MAX_CPU_INDEX;
-
     /* Construct cpu-to-* lists. */
     cpu_to_core_obj = PyList_New(0);
     cpu_to_socket_obj = PyList_New(0);
     cpu_to_node_obj = PyList_New(0);
-    for ( i = 0; i <= max_cpu_index; i++ )
+    for ( i = 0; i < max_cpus; i++ )
     {
         if ( cputopo[i].core == INVALID_CORE_ID )
         {
@@ -1281,7 +1274,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
         }
     }
 
-    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpu_index);
+    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpus - 1);
 
     PyDict_SetItemString(ret_obj, "cpu_to_core", cpu_to_core_obj);
     Py_DECREF(cpu_to_core_obj);
@@ -1293,7 +1286,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
     Py_DECREF(cpu_to_node_obj);
 
 out:
-    xc_hypercall_buffer_free(self->xc_handle, cputopo);
+    free(cputopo);
     return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
 #undef MAX_CPU_INDEX
 }
Signature · 1 line
1.7.1
#35 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

Quoted 14 lines · Boris Ostrovsky
---
 tools/libxc/include/xenctrl.h     |    4 +-
 tools/libxc/xc_misc.c             |   23 +++++++++++-----
 tools/libxl/libxl.c               |   32 +++++------------------
 tools/misc/xenpm.c                |   51 ++++++++++++++++---------------------
 tools/python/xen/lowlevel/xc/xc.c |   23 ++++++-----------
 5 files changed, 55 insertions(+), 78 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 0cb6743..d94571d 100644

tools/libxc/include/xenctrl.h int xc_readconsolering(xc_interface *xch, · line 1229

Quoted 5 lines
tools/libxc/include/xenctrl.h +1 -1
@@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch,
 int xc_send_debug_keys(xc_interface *xch, char *keys);
 
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_sysctl_cputopoinfo_t xc_cputopoinfo_t;
+typedef xen_sysctl_cputopo_t xc_cputopo_t;

The sysctl structure is still named xen_sysctl_cputopoinfo_t. Where does xen_sysctl_cputopo_t come from?

tools/libxc/include/xenctrl.h typedef uint64_t xc_node_to_memfree_t; · line 1240

Quoted 9 lines
tools/libxc/include/xenctrl.h +1 -1
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
@@ -1237,7 +1237,7 @@ typedef uint64_t xc_node_to_memfree_t;
 typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
-int xc_cputopoinfo(xc_interface *xch, xc_cputopoinfo_t *info);
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);

max_cpus is the length of the cputopo array, and is therefore an unsigned value.

~Andrew

Quoted 304 lines
tools/libxc/include/xenctrl.h +0 -0
 int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
 
 int xc_sched_id(xc_interface *xch,
tools/libxc/xc_misc.c +16 -7
index be68291..4c654f3 100644
@@ -177,22 +177,31 @@ int xc_physinfo(xc_interface *xch,
     return 0;
 }
 
-int xc_cputopoinfo(xc_interface *xch,
-                   xc_cputopoinfo_t *put_info)
+int xc_cputopoinfo(xc_interface *xch, int *max_cpus,
+                   xc_cputopo_t *cputopo)
 {
     int ret;
     DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(cputopo, *max_cpus * sizeof(*cputopo),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
 
-    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
+    if ((ret = xc_hypercall_bounce_pre(xch, cputopo)))
+        goto out;
 
-    memcpy(&sysctl.u.cputopoinfo, put_info, sizeof(*put_info));
+    sysctl.u.cputopoinfo.max_cpu_index = *max_cpus;
+    set_xen_guest_handle(sysctl.u.cputopoinfo.cputopo, cputopo);
+
+    sysctl.cmd = XEN_SYSCTL_cputopoinfo;
 
     if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
-        return ret;
+        goto out;
 
-    memcpy(put_info, &sysctl.u.cputopoinfo, sizeof(*put_info));
+    *max_cpus = sysctl.u.cputopoinfo.max_cpu_index + 1;
 
-    return 0;
+out:
+    xc_hypercall_bounce_post(xch, cputopo);
+
+    return ret;
 }
 
 int xc_numainfo(xc_interface *xch,
tools/libxl/libxl.c +7 -25
index b05c0bb..f8d64c2 100644
@@ -5072,38 +5072,23 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 {
     GC_INIT(ctx);
-    xc_cputopoinfo_t tinfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
+    xc_cputopo_t *cputopo;
     libxl_cputopology *ret = NULL;
-    int i;
-    int max_cpus;
+    int i, max_cpus;
 
     max_cpus = libxl_get_max_cpus(ctx);
-    if (max_cpus < 0)
-    {
+    if (max_cpus < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
-        ret = NULL;
         goto out;
     }
 
-    cputopo = xc_hypercall_buffer_alloc(ctx->xch, cputopo,
-                                        sizeof(*cputopo) * max_cpus);
-    if (cputopo == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");
-        goto fail;
-    }
+    cputopo = libxl__zalloc(gc, sizeof(*cputopo) * max_cpus);
 
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = max_cpus - 1;
-    if (xc_cputopoinfo(ctx->xch, &tinfo) != 0) {
+    if (xc_cputopoinfo(ctx->xch, &max_cpus, cputopo) != 0) {
         LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "CPU topology info hypercall failed");
-        goto fail;
+        goto out;
     }
 
-    if (tinfo.max_cpu_index < max_cpus - 1)
-        max_cpus = tinfo.max_cpu_index + 1;
-
     ret = libxl__zalloc(NOGC, sizeof(libxl_cputopology) * max_cpus);
 
     for (i = 0; i < max_cpus; i++) {
@@ -5115,11 +5100,8 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 #undef V
     }
 
-fail:
-    xc_hypercall_buffer_free(ctx->xch, cputopo);
+    *nb_cpu_out = max_cpus;
 
-    if (ret)
-        *nb_cpu_out = max_cpus;
  out:
     GC_FREE;
     return ret;
tools/misc/xenpm.c +22 -29
index f7fe620..1d1eb40 100644
@@ -355,12 +355,11 @@ static void signal_int_handler(int signo)
     int i, j, k;
     struct timeval tv;
     int cx_cap = 0, px_cap = 0;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-    xc_cputopoinfo_t info = { 0 };
-
-    cputopo = xc_hypercall_buffer_alloc(xc_handle, cputopo,
-                                        sizeof(*cputopo) * MAX_NR_CPU);
+    xc_cputopo_t *cputopo;
+    int max_cpus;
 
+    max_cpus = MAX_NR_CPU;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
     {
 	fprintf(stderr, "failed to allocate hypercall buffers\n");
@@ -445,29 +444,26 @@ static void signal_int_handler(int signo)
             printf("  Avg freq\t%d\tKHz\n", avgfreq[i]);
     }
 
-    set_xen_guest_handle(info.cputopo, cputopo);
-    info.max_cpu_index = MAX_NR_CPU - 1;
-
-    if ( cx_cap && !xc_cputopoinfo(xc_handle, &info) )
+    if ( cx_cap && !xc_cputopoinfo(xc_handle, &max_cpus, cputopo) )
     {
         uint32_t socket_ids[MAX_NR_CPU];
         uint32_t core_ids[MAX_NR_CPU];
         uint32_t socket_nr = 0;
         uint32_t core_nr = 0;
 
-        if ( info.max_cpu_index > MAX_NR_CPU - 1 )
-            info.max_cpu_index = MAX_NR_CPU - 1;
+        if ( max_cpus > MAX_NR_CPU )
+            max_cpus = MAX_NR_CPU;
         /* check validity */
-        for ( i = 0; i <= info.max_cpu_index; i++ )
+        for ( i = 0; i < max_cpus; i++ )
         {
             if ( cputopo[i].core == INVALID_CORE_ID ||
                  cputopo[i].socket == INVALID_SOCKET_ID )
                 break;
         }
-        if ( i > info.max_cpu_index )
+        if ( i >= max_cpus )
         {
             /* find socket nr & core nr per socket */
-            for ( i = 0; i <= info.max_cpu_index; i++ )
+            for ( i = 0; i < max_cpus; i++ )
             {
                 for ( j = 0; j < socket_nr; j++ )
                     if ( cputopo[i].socket == socket_ids[j] )
@@ -494,7 +490,7 @@ static void signal_int_handler(int signo)
                 unsigned int n;
                 uint64_t res;
 
-                for ( j = 0; j <= info.max_cpu_index; j++ )
+                for ( j = 0; j < max_cpus; j++ )
                 {
                     if ( cputopo[j].socket == socket_ids[i] )
                         break;
@@ -513,7 +509,7 @@ static void signal_int_handler(int signo)
                 }
                 for ( k = 0; k < core_nr; k++ )
                 {
-                    for ( j = 0; j <= info.max_cpu_index; j++ )
+                    for ( j = 0; j < max_cpus; j++ )
                     {
                         if ( cputopo[j].socket == socket_ids[i] &&
                              cputopo[j].core == core_ids[k] )
@@ -551,7 +547,7 @@ static void signal_int_handler(int signo)
     free(sum);
     free(avgfreq);
 out:
-    xc_hypercall_buffer_free(xc_handle, cputopo);
+    free(cputopo);
     xc_interface_close(xc_handle);
     exit(0);
 }
@@ -958,22 +954,19 @@ void scaling_governor_func(int argc, char *argv[])
 
 void cpu_topology_func(int argc, char *argv[])
 {
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-    xc_cputopoinfo_t info = { 0 };
+    xc_cputopo_t *cputopo;
+    int max_cpus;
     int i, rc = ENOMEM;
 
-    cputopo = xc_hypercall_buffer_alloc(xc_handle, cputopo,
-                                        sizeof(*cputopo) * MAX_NR_CPU);
+    max_cpus = MAX_NR_CPU;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
     {
 	fprintf(stderr, "failed to allocate hypercall buffers\n");
 	goto out;
     }
 
-    set_xen_guest_handle(info.cputopo, cputopo);
-    info.max_cpu_index = MAX_NR_CPU-1;
-
-    if ( xc_cputopoinfo(xc_handle, &info) )
+    if ( xc_cputopoinfo(xc_handle, &max_cpus, cputopo) )
     {
         rc = errno;
         fprintf(stderr, "Cannot get Xen CPU topology (%d - %s)\n",
@@ -981,11 +974,11 @@ void cpu_topology_func(int argc, char *argv[])
         goto out;
     }
 
-    if ( info.max_cpu_index > (MAX_NR_CPU-1) )
-        info.max_cpu_index = MAX_NR_CPU-1;
+    if ( max_cpus > MAX_NR_CPU )
+        max_cpus = MAX_NR_CPU;
 
     printf("CPU\tcore\tsocket\tnode\n");
-    for ( i = 0; i <= info.max_cpu_index; i++ )
+    for ( i = 0; i < max_cpus; i++ )
     {
         if ( cputopo[i].core == INVALID_CORE_ID )
             continue;
@@ -994,7 +987,7 @@ void cpu_topology_func(int argc, char *argv[])
     }
     rc = 0;
 out:
-    xc_hypercall_buffer_free(xc_handle, cputopo);
+    free(cputopo);
     if ( rc )
         exit(rc);
 }
tools/python/xen/lowlevel/xc/xc.c +8 -15
index 4275968..6e49dc5 100644
@@ -1221,31 +1221,24 @@ static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds)
 static PyObject *pyxc_topologyinfo(XcObject *self)
 {
 #define MAX_CPU_INDEX 255
-    xc_cputopoinfo_t tinfo = { 0 };
-    int i, max_cpu_index;
+    xc_cputopo_t *cputopo;
+    int i, max_cpus;
     PyObject *ret_obj = NULL;
     PyObject *cpu_to_core_obj, *cpu_to_socket_obj, *cpu_to_node_obj;
 
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
-
-    cputopo = xc_hypercall_buffer_alloc(self->xc_handle, cputopo, sizeof(*cputopo) * (MAX_CPU_INDEX+1));
+    max_cpus = MAX_CPU_INDEX + 1;
+    cputopo = calloc(max_cpus, sizeof(*cputopo));
     if ( cputopo == NULL )
 	goto out;
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = MAX_CPU_INDEX;
 
-    if ( xc_cputopoinfo(self->xc_handle, &tinfo) != 0 )
+    if ( xc_cputopoinfo(self->xc_handle, &max_cpus, cputopo) != 0 )
         goto out;
 
-    max_cpu_index = tinfo.max_cpu_index;
-    if ( max_cpu_index > MAX_CPU_INDEX )
-        max_cpu_index = MAX_CPU_INDEX;
-
     /* Construct cpu-to-* lists. */
     cpu_to_core_obj = PyList_New(0);
     cpu_to_socket_obj = PyList_New(0);
     cpu_to_node_obj = PyList_New(0);
-    for ( i = 0; i <= max_cpu_index; i++ )
+    for ( i = 0; i < max_cpus; i++ )
     {
         if ( cputopo[i].core == INVALID_CORE_ID )
         {
@@ -1281,7 +1274,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
         }
     }
 
-    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpu_index);
+    ret_obj = Py_BuildValue("{s:i}", "max_cpu_index", max_cpus - 1);
 
     PyDict_SetItemString(ret_obj, "cpu_to_core", cpu_to_core_obj);
     Py_DECREF(cpu_to_core_obj);
@@ -1293,7 +1286,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
     Py_DECREF(cpu_to_node_obj);
 
 out:
-    xc_hypercall_buffer_free(self->xc_handle, cputopo);
+    free(cputopo);
     return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
 #undef MAX_CPU_INDEX
 }
#36 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

Quoted 12 lines · Andrew Cooper
tools/libxc/include/xenctrl.h +1 -1
index 0cb6743..d94571d 100644
@@ -1226,7 +1226,7 @@ int xc_readconsolering(xc_interface *xch,
  int xc_send_debug_keys(xc_interface *xch, char *keys);
 
  typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_sysctl_cputopoinfo_t xc_cputopoinfo_t;
+typedef xen_sysctl_cputopo_t xc_cputopo_t;
Quoted 2 lines

The sysctl structure is still named xen_sysctl_cputopoinfo_t. Where does xen_sysctl_cputopo_t come from?

It's in patch 3 (the one you skipped), sysctl.h:

+struct xen_sysctl_cputopo {

+    uint32_t core;
+    uint32_t socket;
+    uint8_t node;

+};
+typedef struct xen_sysctl_cputopo xen_sysctl_cputopo_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopo_t);

-boris

Reviewed-by on v3 5/7
#37 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

In reply to Boris Ostrovsky
Quoted 2 lines · Boris Ostrovsky

Just one thing:

Quoted 28 lines
tools/libxl/libxl.c +3 -12
@@ -5072,38 +5072,23 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 {
     GC_INIT(ctx);
-    xc_cputopoinfo_t tinfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_cputopo_t, cputopo);
+    xc_cputopo_t *cputopo;
     libxl_cputopology *ret = NULL;
-    int i;
-    int max_cpus;
+    int i, max_cpus;
 
     max_cpus = libxl_get_max_cpus(ctx);
-    if (max_cpus < 0)
-    {
+    if (max_cpus < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
-        ret = NULL;
         goto out;
     }
 
-    cputopo = xc_hypercall_buffer_alloc(ctx->xch, cputopo,
-                                        sizeof(*cputopo) * max_cpus);
-    if (cputopo == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");

tools/libxl/libxl.c int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo) · line 5089

Quoted 10 lines
tools/libxl/libxl.c +2 -5
-        goto fail;
-    }
+    cputopo = libxl__zalloc(gc, sizeof(*cputopo) * max_cpus);
 
-    set_xen_guest_handle(tinfo.cputopo, cputopo);
-    tinfo.max_cpu_index = max_cpus - 1;
-    if (xc_cputopoinfo(ctx->xch, &tinfo) != 0) {
+    if (xc_cputopoinfo(ctx->xch, &max_cpus, cputopo) != 0) {
         LIBXL__LOG_ERRNO(ctx, XTL_ERROR, "CPU topology info hypercall failed");
 

While at it, you probably can convert this to the new LOGE() error reporting style.

Regards,
Dario

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

#38 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

In reply to Boris Ostrovsky

On Mon, 2015-02-09 at 15:04 -0500, Boris Ostrovsky wrote:

What is the rationale for this change? (i.e. it should be part of the commit message)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

Quoted 3 lines · Ian Campbell

On Mon, 2015-02-09 at 15:04 -0500, Boris Ostrovsky wrote:

What is the rationale for this change?

libxl is not the right place to handle hypervisor-specific details like buffer management (most, if not all, of other services that libxl provides push these sort of things to libxc).

Quoted 2 lines

(i.e. it should be part of the
commit message)

Yes.

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#42 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

Quoted 8 lines · Boris Ostrovsky
Quoted 3 lines · Ian Campbell

On Mon, 2015-02-09 at 15:04 -0500, Boris Ostrovsky wrote:

What is the rationale for this change?

libxl is not the right place to handle hypervisor-specific details like buffer management (most, if not all, of other services that libxl provides push these sort of things to libxc).

It is acceptable for callers to do the buffer management themselves in principal. The primary reason to do so would be high frequency calls where the bouncing would be unacceptable overhead on every iteration (i.e. it allows callers to preallocate a single buffer).

There aren't many such interfaces though and as you say most of them are in libxc (as it happens).

Nonetheless the argument for this changw should be made in terms of the interface not being called frequently and therefore being tolerant of the bouncing overhead which simplifies things for the caller at the expense of the performance.

That's assuming these interfaces are indeed tolerant of the performance hit...

Quoted 7 lines
Quoted 3 lines

(i.e. it should be part of the
commit message)

Yes.

-boris

#43 lore raw

Re: [PATCH v3 5/7] libxl/libxc: Move libxl_get_cpu_topology()'s hypercall buffer management to libxc

Quoted 16 lines · Ian Campbell
Quoted 7 lines · Boris Ostrovsky
Quoted 3 lines · Ian Campbell

On Mon, 2015-02-09 at 15:04 -0500, Boris Ostrovsky wrote:

What is the rationale for this change?

libxl is not the right place to handle hypervisor-specific details like buffer management (most, if not all, of other services that libxl provides push these sort of things to libxc).

It is acceptable for callers to do the buffer management themselves in principal. The primary reason to do so would be high frequency calls where the bouncing would be unacceptable overhead on every iteration (i.e. it allows callers to preallocate a single buffer).

There aren't many such interfaces though and as you say most of them are in libxc (as it happens).

Quoted 7 lines

Nonetheless the argument for this changw should be made in terms of the interface not being called frequently and therefore being tolerant of the bouncing overhead which simplifies things for the caller at the expense of the performance.

That's assuming these interfaces are indeed tolerant of the performance hit...

These interfaces should be called once per domain creation or as a query from commandline so they don't appear to be not performance-critical.

-boris

#44 lore raw

PATCH v3 6/7 libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management to libxc

In reply to Boris Ostrovsky
---
 tools/libxc/include/xenctrl.h     |    4 ++-
 tools/libxc/xc_misc.c             |   29 ++++++++++++++++++++------
 tools/libxl/libxl.c               |   36 ++++++++-------------------------
 tools/python/xen/lowlevel/xc/xc.c |   39 +++++++++++++++---------------------
 4 files changed, 50 insertions(+), 58 deletions(-)
tools/libxc/include/xenctrl.h +3 -1
index d94571d..4466cd7 100644
@@ -1228,6 +1228,7 @@ int xc_send_debug_keys(xc_interface *xch, char *keys);
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
 typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
+typedef xen_sysctl_meminfo_t xc_meminfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
 typedef uint32_t xc_cpu_to_socket_t;
@@ -1238,7 +1239,8 @@ typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
 int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);
-int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
+int xc_numainfo(xc_interface *xch, int *max_nodes,
+                xc_meminfo_t *meminfo, uint8_t *distance);
 
 int xc_sched_id(xc_interface *xch,
                 int *sched_id);
tools/libxc/xc_misc.c +22 -7
index 4c654f3..2dd5e13 100644
@@ -204,22 +204,37 @@ out:
     return ret;
 }
 
-int xc_numainfo(xc_interface *xch,
-                xc_numainfo_t *put_info)
+int xc_numainfo(xc_interface *xch, int *max_nodes,
+                xc_meminfo_t *meminfo, uint8_t *distance)
 {
     int ret;
     DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(meminfo, *max_nodes * sizeof(*meminfo),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(distance,
+                             *max_nodes * *max_nodes * sizeof(*distance),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
 
-    sysctl.cmd = XEN_SYSCTL_numainfo;
+    if ((ret = xc_hypercall_bounce_pre(xch, meminfo)))
+        goto out;
+    if ((ret = xc_hypercall_bounce_pre(xch, distance)))
+        goto out;
 
-    memcpy(&sysctl.u.numainfo, put_info, sizeof(*put_info));
+    sysctl.u.numainfo.max_node_index = *max_nodes - 1;
+    set_xen_guest_handle(sysctl.u.numainfo.meminfo, meminfo);
+    set_xen_guest_handle(sysctl.u.numainfo.distance, distance);
 
+    sysctl.cmd = XEN_SYSCTL_numainfo;
     if ((ret = do_sysctl(xch, &sysctl)) != 0)
-        return ret;
+        goto out;
 
-    memcpy(put_info, &sysctl.u.numainfo, sizeof(*put_info));
+    *max_nodes = sysctl.u.numainfo.max_node_index + 1;
 
-    return 0;
+out:
+    xc_hypercall_bounce_post(xch, meminfo);
+    xc_hypercall_bounce_post(xch, distance);
+
+    return ret;
 }
 
 
tools/libxl/libxl.c +9 -27
index f8d64c2..9c1c949 100644
@@ -5110,41 +5110,25 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
 {
     GC_INIT(ctx);
-    xc_numainfo_t ninfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_meminfo_t, meminfo);
-    DECLARE_HYPERCALL_BUFFER(uint8_t, distance);
+    xc_meminfo_t *meminfo;
+    uint8_t *distance;
     libxl_numainfo *ret = NULL;
     int i, j, max_nodes;
 
     max_nodes = libxl_get_max_nodes(ctx);
-    if (max_nodes < 0)
-    {
+    if (max_nodes < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of NODES");
-        ret = NULL;
         goto out;
     }
 
-    meminfo = xc_hypercall_buffer_alloc(ctx->xch, meminfo, sizeof(*meminfo) * max_nodes);
-    distance = xc_hypercall_buffer_alloc(ctx->xch, distance, sizeof(*distance) * max_nodes * max_nodes);
-    if ((meminfo == NULL) || (distance == NULL)) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");
-        goto fail;
-    }
+    meminfo = libxl__zalloc(gc, sizeof(*meminfo) * max_nodes);
+    distance = libxl__zalloc(gc, sizeof(*distance) * max_nodes * max_nodes);
 
-    set_xen_guest_handle(ninfo.meminfo, meminfo);
-    set_xen_guest_handle(ninfo.distance, distance);
-    ninfo.max_node_index = max_nodes - 1;
-    if (xc_numainfo(ctx->xch, &ninfo) != 0) {
+    if (xc_numainfo(ctx->xch, &max_nodes, meminfo, distance) != 0) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting numainfo");
-        goto fail;
+        goto out;
     }
 
-    if (ninfo.max_node_index < max_nodes - 1)
-        max_nodes = ninfo.max_node_index + 1;
-
-    *nr = max_nodes;
-
     ret = libxl__zalloc(NOGC, sizeof(libxl_numainfo) * max_nodes);
     for (i = 0; i < max_nodes; i++)
         ret[i].dists = libxl__calloc(NOGC, max_nodes, sizeof(*distance));
@@ -5156,13 +5140,11 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
         ret[i].free = V(memfree, i);
         ret[i].num_dists = max_nodes;
         for (j = 0; j < ret[i].num_dists; j++)
-            ret[i].dists[j] = distance[i*max_nodes + j];
+            ret[i].dists[j] = distance[i * max_nodes + j];
 #undef V
     }
 
- fail:
-    xc_hypercall_buffer_free(ctx->xch, meminfo);
-    xc_hypercall_buffer_free(ctx->xch, distance);
+    *nr = max_nodes;
 
  out:
     GC_FREE;
tools/python/xen/lowlevel/xc/xc.c +16 -23
index 6e49dc5..3fd4805 100644
@@ -1294,39 +1294,32 @@ out:
 static PyObject *pyxc_numainfo(XcObject *self)
 {
 #define MAX_NODE_INDEX 31
-    xc_numainfo_t ninfo = { 0 };
-    int i, j, max_node_index, invalid_node;
+    int i, j, max_nodes, invalid_node;
     uint64_t free_heap;
     PyObject *ret_obj = NULL, *node_to_node_dist_list_obj;
     PyObject *node_to_memsize_obj, *node_to_memfree_obj;
     PyObject *node_to_dma32_mem_obj, *node_to_node_dist_obj;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_meminfo_t, meminfo);
-    DECLARE_HYPERCALL_BUFFER(uint8_t, distance);
+    xc_meminfo_t *meminfo;
+    uint8_t *distance;
 
-    meminfo = xc_hypercall_buffer_alloc(self->xc_handle, meminfo, sizeof(*meminfo) * (MAX_NODE_INDEX+1));
-    if ( meminfo == NULL )
+    max_nodes = MAX_NODE_INDEX + 1;
+    meminfo = calloc(max_nodes, sizeof(*meminfo));
+    distance = calloc(max_nodes * max_nodes, sizeof(*distance));
+    if ( meminfo == NULL || distance == NULL)
         goto out;
-    distance = xc_hypercall_buffer_alloc(self->xc_handle, distance, sizeof(*distance)*(MAX_NODE_INDEX+1)*(MAX_NODE_INDEX+1));
-    if ( distance == NULL )
-        goto out;
-
-    set_xen_guest_handle(ninfo.meminfo, meminfo);
-    set_xen_guest_handle(ninfo.distance, distance);
-    ninfo.max_node_index = MAX_NODE_INDEX;
 
-    if ( xc_numainfo(self->xc_handle, &ninfo) != 0 )
+    if ( xc_numainfo(self->xc_handle, &max_nodes, meminfo, distance) != 0 )
         goto out;
 
-    max_node_index = ninfo.max_node_index;
-    if ( max_node_index > MAX_NODE_INDEX )
-        max_node_index = MAX_NODE_INDEX;
+    if ( max_nodes > MAX_NODE_INDEX + 1 )
+        max_nodes = MAX_NODE_INDEX + 1;
 
     /* Construct node-to-* lists. */
     node_to_memsize_obj = PyList_New(0);
     node_to_memfree_obj = PyList_New(0);
     node_to_dma32_mem_obj = PyList_New(0);
     node_to_node_dist_list_obj = PyList_New(0);
-    for ( i = 0; i <= max_node_index; i++ )
+    for ( i = 0; i < max_nodes; i++ )
     {
         PyObject *pyint;
 
@@ -1349,9 +1342,9 @@ static PyObject *pyxc_numainfo(XcObject *self)
         /* Node to Node Distance */
         node_to_node_dist_obj = PyList_New(0);
         invalid_node = (meminfo[i].memsize == INVALID_MEM_SZ);
-        for ( j = 0; j <= max_node_index; j++ )
+        for ( j = 0; j < max_nodes; j++ )
         {
-            uint32_t dist = distance[i * (max_node_index + 1) + j];
+            uint32_t dist = distance[i * max_nodes + j];
             if ( invalid_node )
             {
                 PyList_Append(node_to_node_dist_obj, Py_None);
@@ -1367,7 +1360,7 @@ static PyObject *pyxc_numainfo(XcObject *self)
         Py_DECREF(node_to_node_dist_obj);
     }
 
-    ret_obj = Py_BuildValue("{s:i}", "max_node_index", max_node_index);
+    ret_obj = Py_BuildValue("{s:i}", "max_node_index", max_nodes - 1);
 
     PyDict_SetItemString(ret_obj, "node_memsize", node_to_memsize_obj);
     Py_DECREF(node_to_memsize_obj);
@@ -1383,8 +1376,8 @@ static PyObject *pyxc_numainfo(XcObject *self)
     Py_DECREF(node_to_node_dist_list_obj);
 
 out:
-    xc_hypercall_buffer_free(self->xc_handle, meminfo);
-    xc_hypercall_buffer_free(self->xc_handle, distance);
+    free(meminfo);
+    free(distance);
     return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
 #undef MAX_NODE_INDEX
 }
Signature · 1 line
1.7.1
#45 lore raw

PATCH v3 7/7 libxl: Add interface for querying hypervisor about PCI topology

In reply to Boris Ostrovsky

.. and use this new interface to display it along with CPU topology and NUMA information when 'xl info -n' command is issued

The output will look like
...
cpu_topology :
cpu: core socket node
0: 0 0 0
...
device topology :
device node
0000:00:00.0 0
0000:00:01.0 0
...

---
 tools/libxc/include/xenctrl.h |    3 ++
 tools/libxc/xc_misc.c         |   32 +++++++++++++++++
 tools/libxl/libxl.c           |   49 +++++++++++++++++++++++++++
 tools/libxl/libxl.h           |   14 ++++++++
 tools/libxl/libxl_freebsd.c   |   14 ++++++++
 tools/libxl/libxl_internal.h  |    5 +++
 tools/libxl/libxl_linux.c     |   74 +++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_netbsd.c    |   14 ++++++++
 tools/libxl/libxl_types.idl   |    7 ++++
 tools/libxl/libxl_utils.c     |    8 ++++
 tools/libxl/xl_cmdimpl.c      |   44 ++++++++++++++++++++----
 11 files changed, 257 insertions(+), 7 deletions(-)
tools/libxc/include/xenctrl.h +3 -0
index 4466cd7..9ba40eb 100644
@@ -1229,6 +1229,7 @@ typedef xen_sysctl_physinfo_t xc_physinfo_t;
 typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
 typedef xen_sysctl_meminfo_t xc_meminfo_t;
+typedef xen_sysctl_pcitopoinfo_t xc_pcitopoinfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
 typedef uint32_t xc_cpu_to_socket_t;
@@ -1241,6 +1242,8 @@ int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
 int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);
 int xc_numainfo(xc_interface *xch, int *max_nodes,
                 xc_meminfo_t *meminfo, uint8_t *distance);
+int xc_pcitopoinfo(xc_interface *xch, int num_devs,
+                   physdev_pci_device_t *devs, uint8_t *nodes);
 
 int xc_sched_id(xc_interface *xch,
                 int *sched_id);
tools/libxc/xc_misc.c +32 -0
index 2dd5e13..a8266d7 100644
@@ -204,6 +204,38 @@ out:
     return ret;
 }
 
+int xc_pcitopoinfo(xc_interface *xch, int num_devs,
+                   physdev_pci_device_t *devs,
+                   uint8_t *nodes)
+{
+    int ret;
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(devs, num_devs * sizeof(*devs),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    DECLARE_HYPERCALL_BOUNCE(nodes, num_devs* sizeof(*nodes),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+
+    if ((ret = xc_hypercall_bounce_pre(xch, devs)))
+        goto out;
+    if ((ret = xc_hypercall_bounce_pre(xch, nodes)))
+        goto out;
+
+    sysctl.u.pcitopoinfo.first_dev = 0;
+    sysctl.u.pcitopoinfo.num_devs = num_devs;
+    set_xen_guest_handle(sysctl.u.pcitopoinfo.devs, devs);
+    set_xen_guest_handle(sysctl.u.pcitopoinfo.nodes, nodes);
+
+    sysctl.cmd = XEN_SYSCTL_pcitopoinfo;
+
+    ret = do_sysctl(xch, &sysctl);
+
+ out:
+    xc_hypercall_bounce_post(xch, devs);
+    xc_hypercall_bounce_post(xch, nodes);
+
+    return ret;
+}
+
 int xc_numainfo(xc_interface *xch, int *max_nodes,
                 xc_meminfo_t *meminfo, uint8_t *distance)
 {
tools/libxl/libxl.c +49 -0

55 lines not on this page · raw message

tools/libxl/libxl.h +14 -0
index 0a123f1..12d9fb9 100644
@@ -692,6 +692,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
 #define LIBXL_HAVE_PSR_CMT 1
 #endif
 
+/*
+ * LIBXL_HAVE_PCITOPO
+ *
+ * If this is defined, we have interfaces to query hypervisor about PCI device
+ * topology
+ */
+#define  LIBXL_HAVE_PCITOPO 1
+
 typedef char **libxl_string_list;
 void libxl_string_list_dispose(libxl_string_list *sl);
 int libxl_string_list_length(const libxl_string_list *sl);
@@ -1070,6 +1078,12 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm);
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out);
 void libxl_cputopology_list_free(libxl_cputopology *, int nb_cpu);
 
+#ifdef  LIBXL_HAVE_PCITOPO
+#define LIBXL_PCITOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
+libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs);
+void libxl_pcitopology_list_free(libxl_pcitopology *, int num_devs);
+#endif
+
 #define LIBXL_NUMAINFO_INVALID_ENTRY (~(uint32_t)0)
 libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr);
 void libxl_numainfo_list_free(libxl_numainfo *, int nr);
tools/libxl/libxl_freebsd.c +14 -0
index e8b88b3..68d7b71 100644
@@ -131,3 +131,17 @@ libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
 {
     return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
 }
+
+#ifdef  LIBXL_HAVE_PCITOPO
+int libxl__pci_numdevs(libxl__gc *gc)
+{
+    return ERROR_NI;
+}
+
+int libxl__pci_topology_init(libxl__gc *gc,
+                             physdev_pci_device_t *devs,
+                             int num_devs)
+{
+    return ERROR_NI;
+}
+#endif
tools/libxl/libxl_internal.h +5 -0
index 9695f18..5a3a2c5 100644
@@ -1168,6 +1168,11 @@ _hidden int libxl__try_phy_backend(mode_t st_mode);
 
 _hidden char *libxl__devid_to_localdev(libxl__gc *gc, int devid);
 
+_hidden int libxl__pci_numdevs(libxl__gc *gc);
+_hidden int libxl__pci_topology_init(libxl__gc *gc,
+                                     physdev_pci_device_t *devs,
+                                     int num_devs);
+
 /* from libxl_pci */
 
 _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);
tools/libxl/libxl_linux.c +74 -0

77 lines not on this page · raw message

tools/libxl/libxl_netbsd.c +14 -0
index 898e160..25c1701 100644
@@ -95,3 +95,17 @@ libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
 {
     return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
 }
+
+#ifdef  LIBXL_HAVE_PCITOPO
+int libxl__pci_numdevs(libxl__gc *gc)
+{
+    return ERROR_NI;
+}
+
+int libxl__pci_topology_init(libxl__gc *gc,
+                             physdev_pci_device_t *devs,
+                             int num_devs)
+{
+    return ERROR_NI;
+}
+#endif
tools/libxl/libxl_types.idl +7 -0
index f7fc695..e49b5f8 100644
@@ -642,6 +642,13 @@ libxl_cputopology = Struct("cputopology", [
     ("node", uint32),
     ], dir=DIR_OUT)
 
+libxl_pcitopology = Struct("pcitopology", [
+    ("seg", uint16),
+    ("bus", uint8),
+    ("devfn", uint8),
+    ("node", uint32),
+    ], dir=DIR_OUT)
+
 libxl_sched_credit_params = Struct("sched_credit_params", [
     ("tslice_ms", integer),
     ("ratelimit_us", integer),
tools/libxl/libxl_utils.c +8 -0
index 7095b58..c31407f 100644
@@ -877,6 +877,14 @@ void libxl_cputopology_list_free(libxl_cputopology *list, int nr)
     free(list);
 }
 
+void libxl_pcitopology_list_free(libxl_pcitopology *list, int nr)
+{
+    int i;
+    for (i = 0; i < nr; i++)
+        libxl_pcitopology_dispose(&list[i]);
+    free(list);
+}
+
 void libxl_numainfo_list_free(libxl_numainfo *list, int nr)
 {
     int i;
tools/libxl/xl_cmdimpl.c +37 -7

61 lines not on this page · raw message

Signature · 1 line
1.7.1
#46 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

On Mon, Feb 09, 2015 at 03:04:35PM -0500, Boris Ostrovsky wrote:
[...]

tools/libxl/libxl.c libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out) · line 5121

Quoted 12 lines
tools/libxl/libxl.c +12 -0
+#ifdef  LIBXL_HAVE_PCITOPO
+libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs)
+{
+    GC_INIT(ctx);
+    physdev_pci_device_t *devs;
+    uint8_t *nodes;
+    libxl_pcitopology *ret = NULL;
+    int i, rc;
+
+    *num_devs = libxl__pci_numdevs(gc);
+    if (*num_devs <= 0) {
+        LOG(ERROR, "Unable to determine number of PCI devices");

Is 0 an error? What if the system actually have no PCI devices?

The rest looks OK to me.

Wei.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#48 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

Quoted 15 lines · Wei Liu

On Mon, Feb 09, 2015 at 03:04:35PM -0500, Boris Ostrovsky wrote:
[...]

tools/libxl/libxl.c libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out) · line 5121

Quoted 12 lines
tools/libxl/libxl.c +12 -0
+#ifdef  LIBXL_HAVE_PCITOPO
+libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs)
+{
+    GC_INIT(ctx);
+    physdev_pci_device_t *devs;
+    uint8_t *nodes;
+    libxl_pcitopology *ret = NULL;
+    int i, rc;
+
+    *num_devs = libxl__pci_numdevs(gc);
+    if (*num_devs <= 0) {
+        LOG(ERROR, "Unable to determine number of PCI devices");

Is 0 an error? What if the system actually have no PCI devices?

Right, zero should be a non-error value.

-boris

Quoted 4 lines

The rest looks OK to me.

Wei.

#49 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

In reply to Boris Ostrovsky
Quoted 15 lines · Boris Ostrovsky

.. and use this new interface to display it along with CPU topology and NUMA information when 'xl info -n' command is issued

The output will look like
...
cpu_topology :
cpu: core socket node
0: 0 0 0
...
device topology :
device node
0000:00:00.0 0
0000:00:01.0 0
...

Cool, I like this! :-)

At some point, we may want to think about gathering most of/all NUMA related information and create appropriate xl commands, but for now, I think it is fine to have this info here.

Quoted 5 lines
tools/libxl/libxl.h +0 -0
@@ -692,6 +692,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
 #define LIBXL_HAVE_PSR_CMT 1
 #endif

tools/libxl/libxl.h void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); · line 703

Quoted 10 lines
tools/libxl/libxl.h +8 -0
 
+/*
+ * LIBXL_HAVE_PCITOPO
+ *
+ * If this is defined, we have interfaces to query hypervisor about PCI device
+ * topology
+ */
+#define  LIBXL_HAVE_PCITOPO 1
+
 

This is probably not a big deal, but the majority of the definitions of these macros have a wording like this: "FOO indicates that ...". E.g.:

/*
* LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY indicates that a 'cpumap_soft'
* field (of libxl_bitmap type) is present in libxl_vcpuinfo,
* containing the soft affinity of a vcpu.
*/
#define LIBXL_HAVE_VCPUINFO_SOFT_AFFINITY 1

and homogeneity and consistency has some value here, I think.

In any case, you have an extra space between #define and LIBXL_HAVE_PCITOPO. :-)

tools/libxl/libxl.h void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm); · line 1086

Quoted 10 lines
tools/libxl/libxl.h +6 -0
@@ -1070,6 +1078,12 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm);
 libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out);
 void libxl_cputopology_list_free(libxl_cputopology *, int nb_cpu);
 
+#ifdef  LIBXL_HAVE_PCITOPO
+#define LIBXL_PCITOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
+libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs);
+void libxl_pcitopology_list_free(libxl_pcitopology *, int num_devs);
+#endif
+

Is there the need to gate new APIs like this? I've never done that, and I don't think there is. AFAIUI, these are (apart from a few exceptions like LIBXL_HAVE_NO_SUSPEND_RESUME) intended for being used by libxl consumers, not libxl own implementation.

Quoted 13 lines
tools/libxl/libxl_freebsd.c +4 -0
index e8b88b3..68d7b71 100644
@@ -131,3 +131,17 @@ libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
 {
     return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
 }
+
+#ifdef  LIBXL_HAVE_PCITOPO
+int libxl__pci_numdevs(libxl__gc *gc)
+{

tools/libxl/libxl_freebsd.c libxl_device_model_version libxl__default_device_model(libxl__gc *gc) · line 147

Quoted 10 lines
tools/libxl/libxl_freebsd.c +10 -0
+    return ERROR_NI;
+}
+
+int libxl__pci_topology_init(libxl__gc *gc,
+                             physdev_pci_device_t *devs,
+                             int num_devs)
+{
+    return ERROR_NI;
+}
+#endif

And the same for internal functions, and elsewhere.

Quoted 29 lines
tools/libxl/libxl_freebsd.c +19 -3
@@ -5209,12 +5214,37 @@ static void output_topologyinfo(void)
     printf("cpu:    core    socket     node\n");
 
     for (i = 0; i < nr; i++) {
-        if (info[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY)
+        if (cpuinfo[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY)
             printf("%3d:    %4d     %4d     %4d\n", i,
-                   info[i].core, info[i].socket, info[i].node);
+                   cpuinfo[i].core, cpuinfo[i].socket, cpuinfo[i].node);
+    }
+
+    libxl_cputopology_list_free(cpuinfo, nr);
+
+#ifdef  LIBXL_HAVE_PCITOPO
+    pciinfo = libxl_get_pci_topology(ctx, &nr);
+    if (cpuinfo == NULL) {
+        fprintf(stderr, "libxl_get_pci_topology failed.\n");
+        return;
     }
 
-    libxl_cputopology_list_free(info, nr);
+    printf("device topology        :\n");
+    printf("device           node\n");
+    for (i = 0; i < nr; i++) {
+        if (pciinfo[i].node != LIBXL_PCITOPOLOGY_INVALID_ENTRY) {
+            printf("%04x:%02x:%02x.%01x      %d\n", pciinfo[i].seg,
+                   pciinfo[i].bus,
+                   ((pciinfo[i].devfn >> 3) & 0x1f), (pciinfo[i].devfn & 7),
+                   pciinfo[i].node);

tools/libxl/libxl_freebsd.c static void output_topologyinfo(void) · line 5248

Quoted 10 lines
tools/libxl/libxl_freebsd.c +9 -0
+            valid_devs++;
+        }
+    }
+
+    if (valid_devs == 0)
+        printf("No device topology data available\n");
+
+    libxl_pcitopology_list_free(pciinfo, nr);
+#endif
 

And for implementation too, I think.

In fact, if I'm not missing something obvious, since we're always distributing xl and libxl together, this will always be "#ifdef 1", wouldn't it?

Also, ISTR that the first change that actually changes the API should bump the MAJOR in libxl's Makefile. I'm not sure this change qualifies as such, as you're adding stuff, not altering existing data structs (e.g., by adding fields, etc). Personally, I think it does, but I'm leaving this to tools maintainers.

Regards,
Dario

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

#50 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

Quoted 74 lines · Dario Faggioli

tools/libxl/libxl.h void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm); · line 1086

Quoted 12 lines
tools/libxl/libxl.h +6 -0
@@ -1070,6 +1078,12 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nb_vm);
  libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out);
  void libxl_cputopology_list_free(libxl_cputopology *, int nb_cpu);
 
+#ifdef  LIBXL_HAVE_PCITOPO
+#define LIBXL_PCITOPOLOGY_INVALID_ENTRY (~(uint32_t)0)
+libxl_pcitopology *libxl_get_pci_topology(libxl_ctx *ctx, int *num_devs);
+void libxl_pcitopology_list_free(libxl_pcitopology *, int num_devs);
+#endif
+

Is there the need to gate new APIs like this? I've never done that, and I don't think there is. AFAIUI, these are (apart from a few exceptions like LIBXL_HAVE_NO_SUSPEND_RESUME) intended for being used by libxl consumers, not libxl own implementation.

Quoted 13 lines
tools/libxl/libxl_freebsd.c +4 -0
index e8b88b3..68d7b71 100644
@@ -131,3 +131,17 @@ libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
  {
      return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
  }
+
+#ifdef  LIBXL_HAVE_PCITOPO
+int libxl__pci_numdevs(libxl__gc *gc)
+{

tools/libxl/libxl_freebsd.c libxl_device_model_version libxl__default_device_model(libxl__gc *gc) · line 147

Quoted 10 lines
tools/libxl/libxl_freebsd.c +10 -0
+    return ERROR_NI;
+}
+
+int libxl__pci_topology_init(libxl__gc *gc,
+                             physdev_pci_device_t *devs,
+                             int num_devs)
+{
+    return ERROR_NI;
+}
+#endif

And the same for internal functions, and elsewhere.

Quoted 32 lines
tools/libxl/libxl_freebsd.c +22 -3
@@ -5209,12 +5214,37 @@ static void output_topologyinfo(void)
      printf("cpu:    core    socket     node\n");
 
      for (i = 0; i < nr; i++) {
-        if (info[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY)
+        if (cpuinfo[i].core != LIBXL_CPUTOPOLOGY_INVALID_ENTRY)
              printf("%3d:    %4d     %4d     %4d\n", i,
-                   info[i].core, info[i].socket, info[i].node);
+                   cpuinfo[i].core, cpuinfo[i].socket, cpuinfo[i].node);
+    }
+
+    libxl_cputopology_list_free(cpuinfo, nr);
+
+#ifdef  LIBXL_HAVE_PCITOPO
+    pciinfo = libxl_get_pci_topology(ctx, &nr);
+    if (cpuinfo == NULL) {
+        fprintf(stderr, "libxl_get_pci_topology failed.\n");
+        return;
      }
 
-    libxl_cputopology_list_free(info, nr);
+    printf("device topology        :\n");
+    printf("device           node\n");
+    for (i = 0; i < nr; i++) {
+        if (pciinfo[i].node != LIBXL_PCITOPOLOGY_INVALID_ENTRY) {
+            printf("%04x:%02x:%02x.%01x      %d\n", pciinfo[i].seg,
+                   pciinfo[i].bus,
+                   ((pciinfo[i].devfn >> 3) & 0x1f), (pciinfo[i].devfn & 7),
+                   pciinfo[i].node);
+            valid_devs++;
+        }
+    }
Quoted 8 lines

tools/libxl/libxl_freebsd.c static void output_topologyinfo(void) · line 5248

Quoted 7 lines
tools/libxl/libxl_freebsd.c +6 -0
+
+    if (valid_devs == 0)
+        printf("No device topology data available\n");
+
+    libxl_pcitopology_list_free(pciinfo, nr);
+#endif
 

And for implementation too, I think.

I am not sure what the standard practice is for LIBXL_HAVE_ macros. I see a couple of examples where '#ifdef LIBXL_HAVE_*" is used in libxl code, which is why I have it here as well.

This is probably question for maintainers.

Quoted 10 lines

In fact, if I'm not missing something obvious, since we're always distributing xl and libxl together, this will always be "#ifdef 1", wouldn't it?

Also, ISTR that the first change that actually changes the API should bump the MAJOR in libxl's Makefile. I'm not sure this change qualifies as such, as you're adding stuff, not altering existing data structs (e.g., by adding fields, etc). Personally, I think it does, but I'm leaving this to tools maintainers.

libxl.h seems to suggest that API version is changed only when we make an incompatible change to the library. In my mind new interface is does not break compatibility so I didn't think a bump would be necessary.

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#52 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

Quoted 4 lines · Boris Ostrovsky

I am not sure what the standard practice is for LIBXL_HAVE_ macros. I see a couple of examples where '#ifdef LIBXL_HAVE_*" is used in libxl code, which is why I have it here as well.

Yes, that is the case for two of them, AFAICS:

* LIBXL_HAVE_NO_SUSPEND_RESUME
* LIBXL_HAVE_PSR_CMT

If you look at how these two are defined, you'll see that the definition is actually conditional:

#if defined(__arm__) || defined(__aarch64__)
#define LIBXL_HAVE_NO_SUSPEND_RESUME 1
#endif

#if defined(__i386__) || defined(__x86_64__)
#define LIBXL_HAVE_PSR_CMT 1
#endif

Which is, IMO, why we need to take special care of them in libxl and xl code. All other macros, which are always and unconditionally #defined to 1, we just forget about them, and leave it to the caller.

Quoted 2 lines

This is probably question for maintainers.

Sure! :-)

Quoted 10 lines
Quoted 5 lines

Also, ISTR that the first change that actually changes the API should bump the MAJOR in libxl's Makefile. I'm not sure this change qualifies as such, as you're adding stuff, not altering existing data structs (e.g., by adding fields, etc). Personally, I think it does, but I'm leaving this to tools maintainers.

libxl.h seems to suggest that API version is changed only when we make an incompatible change to the library. In my mind new interface is does not break compatibility so I didn't think a bump would be necessary.

Yeah, that was why I was not sure. Re-thinking about it, you probably are right, no need for it for now.

Regards,
Dario

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

#53 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

In reply to a message not in the archive

On Mon, Feb 16, 2015 at 10:54:11AM -0500, Boris Ostrovsky wrote:
[...]

Quoted 9 lines
Quoted 7 lines

tools/libxl/xl_cmdimpl.c static void output_topologyinfo(void) · line 5247

Quoted 6 lines
tools/libxl/xl_cmdimpl.c +5 -0
+    if (valid_devs == 0)
+        printf("No device topology data available\n");
+
+    libxl_pcitopology_list_free(pciinfo, nr);
+#endif

And for implementation too, I think.

Quoted 6 lines

I am not sure what the standard practice is for LIBXL_HAVE_ macros. I see a couple of examples where '#ifdef LIBXL_HAVE_*" is used in libxl code, which is why I have it here as well.

This is probably question for maintainers.

They are not needed inside libxl. They are also not needed in xl, if your new feature works on all architectures etc, because xl is shipped with libxl and will always use the latest API.

Sorry for not mentioning this earlier.

Quoted 18 lines
Quoted 11 lines

In fact, if I'm not missing something obvious, since we're always distributing xl and libxl together, this will always be "#ifdef 1", wouldn't it?

Also, ISTR that the first change that actually changes the API should bump the MAJOR in libxl's Makefile. I'm not sure this change qualifies as such, as you're adding stuff, not altering existing data structs (e.g., by adding fields, etc). Personally, I think it does, but I'm leaving this to tools maintainers.

libxl.h seems to suggest that API version is changed only when we make an incompatible change to the library. In my mind new interface is does not break compatibility so I didn't think a bump would be necessary.

-boris

#54 lore raw

Re: [PATCH v3 7/7] libxl: Add interface for querying hypervisor about PCI topology

In reply to Boris Ostrovsky

tools/libxl/libxl.c libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out) · line 5110

Quoted 9 lines · Boris Ostrovsky
tools/libxl/libxl.c +1 -0
index 9c1c949..c3b6c8a 100644
@@ -5107,6 +5107,55 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
     return ret;
 }
 
+#ifdef  LIBXL_HAVE_PCITOPO

No need for this conditional anywhere within libxl itself, nor in libxl.h or in xl_cmdimpl.c either, it's for external app convenience only.

tools/libxl/libxl.c libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out) · line 5117

Quoted 7 lines
tools/libxl/libxl.c +7 -0
+/*
+ * LIBXL_HAVE_PCITOPO
+ *
+ * If this is defined, we have interfaces to query hypervisor about PCI device
+ * topology
+ */
+#define  LIBXL_HAVE_PCITOPO 1

Can we call it PCI_TOPOLOGY here please.

tools/libxl/libxl_linux.c libxl_device_model_version libxl__default_device_model(libxl__gc *gc) · line 284

Quoted 11 lines
tools/libxl/libxl_linux.c +3 -0
index ea5d8c1..f558dba 100644
@@ -279,3 +279,77 @@ libxl_device_model_version libxl__default_device_model(libxl__gc *gc)
 {
     return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
 }
+
+#ifdef  LIBXL_HAVE_PCITOPO
+/* These two routines are "inspired" by pciutils */

Unless you've actually copied code (with the attention to licensing which that requires) then please just drop this comment since it's only purpose is to make me suspicious about the licensing status of these functions.

Or if you did copy (although you previously said not) then the comment should be expanded to clarify the apparent licensing disparity.

Ian.

#55 lore raw
In reply to Boris Ostrovsky
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.15 at 21:04, <[email protected]> wrote:

* Make changes to xen_sysctl_numainfo, similar to those made to xen_sysctl_topologyinfo. (Q: I kept both sets of changes in the same patch #3 to avoid bumping interface version twice. Perhaps it's better to split it into two?)

There's no need to bump it more than once between releases. Hence yes - splitting would be better.

Jan

#56 lore raw
Quoted 7 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.15 at 21:04, <[email protected]> wrote:

* Make changes to xen_sysctl_numainfo, similar to those made to xen_sysctl_topologyinfo. (Q: I kept both sets of changes in the same patch #3 to avoid bumping interface version twice. Perhaps it's better to split it into two?)

There's no need to bump it more than once between releases. Hence yes - splitting would be better.

I will wait until patch 3 is split to do an in-depth review, but one thing you need to fix is that the INVALID_$FOO identifiers need a XEN_ prefix to put them in the same namespace as the other identifiers.

~Andrew

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#58 lore raw

Re: [PATCH v3 2/7] pci: Do not ignore device's PXM information

Quoted 4 lines · Boris Ostrovsky

If ACPI provides PXM data for IO devices then dom0 will pass it to hypervisor during PHYSDEVOP_pci_device_add call. This information, however, is currently ignored.

Quoted 8 lines

We will store this information (in the form of nodeID) in pci_dev structure so that we can provide it, for example, to the toolstack when it adds support (in the following patches) for querying the hypervisor about device topology

We will also print it when user requests device information dump.

Quoted 148 lines
---
 xen/arch/x86/physdev.c        |   23 ++++++++++++++++++++---
 xen/drivers/passthrough/pci.c |   13 +++++++++----
 xen/include/public/physdev.h  |    6 ++++++
 xen/include/xen/pci.h         |    5 ++++-
 4 files changed, 39 insertions(+), 8 deletions(-)
xen/arch/x86/physdev.c +20 -3
index 6b3201b..ab92fa5 100644
@@ -565,7 +565,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
             break;
 
-        ret = pci_add_device(0, manage_pci.bus, manage_pci.devfn, NULL);
+        ret = pci_add_device(0, manage_pci.bus, manage_pci.devfn,
+                             NULL, NUMA_NO_NODE);
         break;
     }
 
@@ -597,13 +598,14 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
         ret = pci_add_device(0, manage_pci_ext.bus,
                              manage_pci_ext.devfn,
-                             &pdev_info);
+                             &pdev_info, NUMA_NO_NODE);
         break;
     }
 
     case PHYSDEVOP_pci_device_add: {
         struct physdev_pci_device_add add;
         struct pci_dev_info pdev_info;
+        u8 node;
 
         ret = -EFAULT;
         if ( copy_from_guest(&add, arg, 1) != 0 )
@@ -618,7 +620,22 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         }
         else
             pdev_info.is_virtfn = 0;
-        ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info);
+
+        if ( add.flags & XEN_PCI_DEV_PXM )
+        {
+            uint32_t pxm;
+            size_t optarr_off = offsetof(struct physdev_pci_device_add, optarr) /
+                                sizeof(add.optarr[0]);
+
+            if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) )
+                break;
+
+            node = pxm_to_node(pxm);
+        }
+        else
+            node = NUMA_NO_NODE;
+
+        ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, node);
         break;
     }
 
xen/drivers/passthrough/pci.c +9 -4
index 78c6977..43b4384 100644
@@ -568,7 +568,8 @@ static void pci_enable_acs(struct pci_dev *pdev)
     pci_conf_write16(seg, bus, dev, func, pos + PCI_ACS_CTRL, ctrl);
 }
 
-int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
+int pci_add_device(u16 seg, u8 bus, u8 devfn,
+                   const struct pci_dev_info *info, u8 node)
 {
     struct pci_seg *pseg;
     struct pci_dev *pdev;
@@ -586,7 +587,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
         pdev = pci_get_pdev(seg, info->physfn.bus, info->physfn.devfn);
         spin_unlock(&pcidevs_lock);
         if ( !pdev )
-            pci_add_device(seg, info->physfn.bus, info->physfn.devfn, NULL);
+            pci_add_device(seg, info->physfn.bus, info->physfn.devfn,
+                           NULL, node);
         pdev_type = "virtual function";
     }
     else
@@ -609,6 +611,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info)
     if ( !pdev )
         goto out;
 
+    pdev->node = node;
+
     if ( info )
         pdev->info = *info;
     else if ( !pdev->vf_rlen[0] )
@@ -1191,10 +1195,11 @@ static int _dump_pci_devices(struct pci_seg *pseg, void *arg)
 
     list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
     {
-        printk("%04x:%02x:%02x.%u - dom %-3d - MSIs < ",
+        printk("%04x:%02x:%02x.%u - dom %-3d - node %-3d - MSIs < ",
                pseg->nr, pdev->bus,
                PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
-               pdev->domain ? pdev->domain->domain_id : -1);
+               pdev->domain ? pdev->domain->domain_id : -1,
+               (pdev->node != NUMA_NO_NODE) ? pdev->node : -1);
         list_for_each_entry ( msi, &pdev->msi_list, list )
                printk("%d ", msi->irq);
         printk(">\n");
xen/include/public/physdev.h +6 -0
index d547928..309346b 100644
@@ -293,6 +293,12 @@ struct physdev_pci_device_add {
         uint8_t bus;
         uint8_t devfn;
     } physfn;
+
+    /*
+     * Optional parameters array.
+     * First element ([0]) is PXM domain associated with the device (if
+     * XEN_PCI_DEV_PXM is set)
+     */
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
     uint32_t optarr[];
 #elif defined(__GNUC__)
xen/include/xen/pci.h +4 -1
index 5f295f3..1acab53 100644
@@ -56,6 +56,8 @@ struct pci_dev {
 
     u8 phantom_stride;
 
+    u8 node; /* NUMA node */
+
     enum pdev_type {
         DEV_TYPE_PCI_UNKNOWN,
         DEV_TYPE_PCIe_ENDPOINT,
@@ -102,7 +104,8 @@ void setup_hwdom_pci_devices(struct domain *,
 int pci_release_devices(struct domain *d);
 int pci_add_segment(u16 seg);
 const unsigned long *pci_get_ro_map(u16 seg);
-int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *);
+int pci_add_device(u16 seg, u8 bus, u8 devfn,
+                   const struct pci_dev_info *, u8 node);
 int pci_remove_device(u16 seg, u8 bus, u8 devfn);
 int pci_ro_device(int seg, int bus, int devfn);
 void arch_pci_ro_device(int seg, int bdf);
Acked-by
#59 lore raw

Re: [PATCH v3 2/7] pci: Do not ignore device's PXM information

In reply to a message not in the archive
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 09.02.15 at 21:04, <[email protected]> wrote:

If ACPI provides PXM data for IO devices then dom0 will pass it to hypervisor during PHYSDEVOP_pci_device_add call. This information, however, is currently ignored.

Quoted 8 lines

We will store this information (in the form of nodeID) in pci_dev structure so that we can provide it, for example, to the toolstack when it adds support (in the following patches) for querying the hypervisor about device topology

We will also print it when user requests device information dump.

I disagree with the title - you still effectively ignore the value. Displaying it upon debug key request doesn't really count as a use. The patch itself, otoh is fine, so with the title adjusted to state reality

Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#61 lore raw

Re: [PATCH v3 6/7] libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management to libxc

Quoted 46 lines · Boris Ostrovsky
---
 tools/libxc/include/xenctrl.h     |    4 ++-
 tools/libxc/xc_misc.c             |   29 ++++++++++++++++++++------
 tools/libxl/libxl.c               |   36 ++++++++-------------------------
 tools/python/xen/lowlevel/xc/xc.c |   39 +++++++++++++++---------------------
 4 files changed, 50 insertions(+), 58 deletions(-)
tools/libxc/include/xenctrl.h +3 -1
index d94571d..4466cd7 100644
@@ -1228,6 +1228,7 @@ int xc_send_debug_keys(xc_interface *xch, char *keys);
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
 typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
+typedef xen_sysctl_meminfo_t xc_meminfo_t;
 
 typedef uint32_t xc_cpu_to_node_t;
 typedef uint32_t xc_cpu_to_socket_t;
@@ -1238,7 +1239,8 @@ typedef uint32_t xc_node_to_node_dist_t;
 
 int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
 int xc_cputopoinfo(xc_interface *xch, int *max_cpus, xc_cputopo_t *cputopo);
-int xc_numainfo(xc_interface *xch, xc_numainfo_t *info);
+int xc_numainfo(xc_interface *xch, int *max_nodes,
+                xc_meminfo_t *meminfo, uint8_t *distance);
 
 int xc_sched_id(xc_interface *xch,
                 int *sched_id);
tools/libxc/xc_misc.c +3 -2
index 4c654f3..2dd5e13 100644
@@ -204,22 +204,37 @@ out:
     return ret;
 }
 
-int xc_numainfo(xc_interface *xch,
-                xc_numainfo_t *put_info)
+int xc_numainfo(xc_interface *xch, int *max_nodes,
+                xc_meminfo_t *meminfo, uint8_t *distance)
 {
     int ret;
     DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(meminfo, *max_nodes * sizeof(*meminfo),

tools/libxc/xc_misc.c out: · line 221

Quoted 10 lines
tools/libxc/xc_misc.c +8 -1
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    DECLARE_HYPERCALL_BOUNCE(distance,
+                             *max_nodes * *max_nodes * sizeof(*distance),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
 
-    sysctl.cmd = XEN_SYSCTL_numainfo;
+    if ((ret = xc_hypercall_bounce_pre(xch, meminfo)))
+        goto out;
+    if ((ret = xc_hypercall_bounce_pre(xch, distance)))
+        goto out;

You can safely combine these two together with an ||

tools/libxc/xc_misc.c out: · line 222

Quoted 3 lines
tools/libxc/xc_misc.c +1 -1
-    memcpy(&sysctl.u.numainfo, put_info, sizeof(*put_info));
+    sysctl.u.numainfo.max_node_index = *max_nodes - 1;

As you have you have already changed these hypercalls, can we fix the length handling so it doesn't require +1 or -1. Xen should receive the length of the arrays, and return the number of elements written, with no further adjustment necessary.

~Andrew

Quoted 176 lines
tools/libxc/xc_misc.c +10 -3
+    set_xen_guest_handle(sysctl.u.numainfo.meminfo, meminfo);
+    set_xen_guest_handle(sysctl.u.numainfo.distance, distance);
 
+    sysctl.cmd = XEN_SYSCTL_numainfo;
     if ((ret = do_sysctl(xch, &sysctl)) != 0)
-        return ret;
+        goto out;
 
-    memcpy(put_info, &sysctl.u.numainfo, sizeof(*put_info));
+    *max_nodes = sysctl.u.numainfo.max_node_index + 1;
 
-    return 0;
+out:
+    xc_hypercall_bounce_post(xch, meminfo);
+    xc_hypercall_bounce_post(xch, distance);
+
+    return ret;
 }
 
 
tools/libxl/libxl.c +9 -27
index f8d64c2..9c1c949 100644
@@ -5110,41 +5110,25 @@ libxl_cputopology *libxl_get_cpu_topology(libxl_ctx *ctx, int *nb_cpu_out)
 libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
 {
     GC_INIT(ctx);
-    xc_numainfo_t ninfo;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_meminfo_t, meminfo);
-    DECLARE_HYPERCALL_BUFFER(uint8_t, distance);
+    xc_meminfo_t *meminfo;
+    uint8_t *distance;
     libxl_numainfo *ret = NULL;
     int i, j, max_nodes;
 
     max_nodes = libxl_get_max_nodes(ctx);
-    if (max_nodes < 0)
-    {
+    if (max_nodes < 0) {
         LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of NODES");
-        ret = NULL;
         goto out;
     }
 
-    meminfo = xc_hypercall_buffer_alloc(ctx->xch, meminfo, sizeof(*meminfo) * max_nodes);
-    distance = xc_hypercall_buffer_alloc(ctx->xch, distance, sizeof(*distance) * max_nodes * max_nodes);
-    if ((meminfo == NULL) || (distance == NULL)) {
-        LIBXL__LOG_ERRNOVAL(ctx, XTL_ERROR, ENOMEM,
-                            "Unable to allocate hypercall arguments");
-        goto fail;
-    }
+    meminfo = libxl__zalloc(gc, sizeof(*meminfo) * max_nodes);
+    distance = libxl__zalloc(gc, sizeof(*distance) * max_nodes * max_nodes);
 
-    set_xen_guest_handle(ninfo.meminfo, meminfo);
-    set_xen_guest_handle(ninfo.distance, distance);
-    ninfo.max_node_index = max_nodes - 1;
-    if (xc_numainfo(ctx->xch, &ninfo) != 0) {
+    if (xc_numainfo(ctx->xch, &max_nodes, meminfo, distance) != 0) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting numainfo");
-        goto fail;
+        goto out;
     }
 
-    if (ninfo.max_node_index < max_nodes - 1)
-        max_nodes = ninfo.max_node_index + 1;
-
-    *nr = max_nodes;
-
     ret = libxl__zalloc(NOGC, sizeof(libxl_numainfo) * max_nodes);
     for (i = 0; i < max_nodes; i++)
         ret[i].dists = libxl__calloc(NOGC, max_nodes, sizeof(*distance));
@@ -5156,13 +5140,11 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
         ret[i].free = V(memfree, i);
         ret[i].num_dists = max_nodes;
         for (j = 0; j < ret[i].num_dists; j++)
-            ret[i].dists[j] = distance[i*max_nodes + j];
+            ret[i].dists[j] = distance[i * max_nodes + j];
 #undef V
     }
 
- fail:
-    xc_hypercall_buffer_free(ctx->xch, meminfo);
-    xc_hypercall_buffer_free(ctx->xch, distance);
+    *nr = max_nodes;
 
  out:
     GC_FREE;
tools/python/xen/lowlevel/xc/xc.c +16 -23
index 6e49dc5..3fd4805 100644
@@ -1294,39 +1294,32 @@ out:
 static PyObject *pyxc_numainfo(XcObject *self)
 {
 #define MAX_NODE_INDEX 31
-    xc_numainfo_t ninfo = { 0 };
-    int i, j, max_node_index, invalid_node;
+    int i, j, max_nodes, invalid_node;
     uint64_t free_heap;
     PyObject *ret_obj = NULL, *node_to_node_dist_list_obj;
     PyObject *node_to_memsize_obj, *node_to_memfree_obj;
     PyObject *node_to_dma32_mem_obj, *node_to_node_dist_obj;
-    DECLARE_HYPERCALL_BUFFER(xen_sysctl_meminfo_t, meminfo);
-    DECLARE_HYPERCALL_BUFFER(uint8_t, distance);
+    xc_meminfo_t *meminfo;
+    uint8_t *distance;
 
-    meminfo = xc_hypercall_buffer_alloc(self->xc_handle, meminfo, sizeof(*meminfo) * (MAX_NODE_INDEX+1));
-    if ( meminfo == NULL )
+    max_nodes = MAX_NODE_INDEX + 1;
+    meminfo = calloc(max_nodes, sizeof(*meminfo));
+    distance = calloc(max_nodes * max_nodes, sizeof(*distance));
+    if ( meminfo == NULL || distance == NULL)
         goto out;
-    distance = xc_hypercall_buffer_alloc(self->xc_handle, distance, sizeof(*distance)*(MAX_NODE_INDEX+1)*(MAX_NODE_INDEX+1));
-    if ( distance == NULL )
-        goto out;
-
-    set_xen_guest_handle(ninfo.meminfo, meminfo);
-    set_xen_guest_handle(ninfo.distance, distance);
-    ninfo.max_node_index = MAX_NODE_INDEX;
 
-    if ( xc_numainfo(self->xc_handle, &ninfo) != 0 )
+    if ( xc_numainfo(self->xc_handle, &max_nodes, meminfo, distance) != 0 )
         goto out;
 
-    max_node_index = ninfo.max_node_index;
-    if ( max_node_index > MAX_NODE_INDEX )
-        max_node_index = MAX_NODE_INDEX;
+    if ( max_nodes > MAX_NODE_INDEX + 1 )
+        max_nodes = MAX_NODE_INDEX + 1;
 
     /* Construct node-to-* lists. */
     node_to_memsize_obj = PyList_New(0);
     node_to_memfree_obj = PyList_New(0);
     node_to_dma32_mem_obj = PyList_New(0);
     node_to_node_dist_list_obj = PyList_New(0);
-    for ( i = 0; i <= max_node_index; i++ )
+    for ( i = 0; i < max_nodes; i++ )
     {
         PyObject *pyint;
 
@@ -1349,9 +1342,9 @@ static PyObject *pyxc_numainfo(XcObject *self)
         /* Node to Node Distance */
         node_to_node_dist_obj = PyList_New(0);
         invalid_node = (meminfo[i].memsize == INVALID_MEM_SZ);
-        for ( j = 0; j <= max_node_index; j++ )
+        for ( j = 0; j < max_nodes; j++ )
         {
-            uint32_t dist = distance[i * (max_node_index + 1) + j];
+            uint32_t dist = distance[i * max_nodes + j];
             if ( invalid_node )
             {
                 PyList_Append(node_to_node_dist_obj, Py_None);
@@ -1367,7 +1360,7 @@ static PyObject *pyxc_numainfo(XcObject *self)
         Py_DECREF(node_to_node_dist_obj);
     }
 
-    ret_obj = Py_BuildValue("{s:i}", "max_node_index", max_node_index);
+    ret_obj = Py_BuildValue("{s:i}", "max_node_index", max_nodes - 1);
 
     PyDict_SetItemString(ret_obj, "node_memsize", node_to_memsize_obj);
     Py_DECREF(node_to_memsize_obj);
@@ -1383,8 +1376,8 @@ static PyObject *pyxc_numainfo(XcObject *self)
     Py_DECREF(node_to_node_dist_list_obj);
 
 out:
-    xc_hypercall_buffer_free(self->xc_handle, meminfo);
-    xc_hypercall_buffer_free(self->xc_handle, distance);
+    free(meminfo);
+    free(distance);
     return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
 #undef MAX_NODE_INDEX
 }

A message that is not in the archive (sent off-list or not yet received): [email protected]

#63 lore raw

Re: [PATCH v3 6/7] libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management to libxc

Quoted 8 lines · Andrew Cooper

Review

Quoted 4 lines
(quoted diff) +1 -1
-    memcpy(&sysctl.u.numainfo, put_info, sizeof(*put_info));
+    sysctl.u.numainfo.max_node_index = *max_nodes - 1;

As you have you have already changed these hypercalls, can we fix the length handling so it doesn't require +1 or -1. Xen should receive the length of the arrays, and return the number of elements written, with no further adjustment necessary.

Yes, I should change this too.

-boris

A message that is not in the archive (sent off-list or not yet received): [email protected]

#66 lore raw

Re: [PATCH v3 4/7] sysctl: Add sysctl interface for querying PCI topology

Quoted 25 lines · Robert Elz
     Date:        Mon,  9 Feb 2015 15:04:32 -0500
     From:        Boris Ostrovsky <[email protected]>
     Message-ID:  <[email protected]>
   | +        num_devs = ti->num_devs - ti->first_dev;
   | +
   | +        if ( guest_handle_is_null(ti->devs) ||
   | +             guest_handle_is_null(ti->nodes) ||
   | +             (num_devs <= 0) )
   | +        {
   | +            ret = -EINVAL;
   | +            break;
   | +        }

Does that need a check that ti->first_dev <= ti_num_devs ?

(that is aside from the issue of subtracting one uint from another and hoping that you'll get a negative signed int if the one subtracted is bigger).

The (num_devs <= 0) test (even if it works - which it should on most rational architectures) isn't good enough, as it is possible to subtract a very big uint from a very small unit and end up with an int that is positive (and potentially, very big, consider (32bit): 2 - 0x80000001).

Quoted 6 lines

So, replace the (num_devs <= 0) test by (ti->first_dev <= ti->num_devs) ??

Or possibly include both tests, just in case ti->num_devs is very large and ti->first_dev is small (like 0) and when the large unsigned is converted to signed, it becomes negative - or is all of this just too impossible to worry about?

For the latter, I'll just keep num_devs as uint32. The only reason I declared it as a signed int was for (num_devs <= 0) test.

-boris