From: "Jan Beulich" Subject: Re: [PATCH v4 5/9] sysctl: Add sysctl interface for querying PCI topology Date: Fri, 13 Mar 2015 16:03:29 +0000 Message-ID: <550318610200007800069E58@mail.emea.novell.com> References: <1425954475-4913-1-git-send-email-boris.ostrovsky@oracle.com> <1425954475-4913-6-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1425954475-4913-6-git-send-email-boris.ostrovsky@oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: elena.ufimtseva@oracle.com, wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, keir@xen.org List-Id: xen-devel@lists.xenproject.org >>> On 10.03.15 at 03:27, wrote: > + case XEN_SYSCTL_pcitopoinfo: > + { > + xen_sysctl_pcitopoinfo_t *ti = &op->u.pcitopoinfo; > + > + if ( guest_handle_is_null(ti->devs) || > + guest_handle_is_null(ti->nodes) || > + (ti->first_dev > ti->num_devs) ) > + { > + ret = -EINVAL; > + break; > + } > + > + for ( ; ti->first_dev < ti->num_devs; ti->first_dev++ ) > + { > + physdev_pci_device_t dev; > + uint8_t node; > + struct pci_dev *pdev; > + > + if ( copy_from_guest_offset(&dev, ti->devs, ti->first_dev, 1) ) > + { > + ret = -EFAULT; > + break; > + } > + > + spin_lock(&pcidevs_lock); > + pdev = pci_get_pdev(dev.seg, dev.bus, dev.devfn); > + if ( !pdev || (pdev->node == NUMA_NO_NODE) ) > + node = XEN_INVALID_NODE_ID; > + else > + node = pdev->node; > + spin_unlock(&pcidevs_lock); > + > + if ( copy_to_guest_offset(ti->nodes, ti->first_dev, &node, 1) ) > + { > + ret = -EFAULT; > + break; > + } > > + if ( hypercall_preempt_check() ) > + break; > + } > + > + if ( !ret ) > + { > + ti->first_dev++; This is correct in the preempt case, but it seems wrong to me in the completely-done one. Perhaps it would be better to put the increment right before the preempt check? > +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 XEN_INVALID_NODE_ID. > + */ > + XEN_GUEST_HANDLE_64(uint8) nodes; As said in earlier patches - let's not expose the 8-bit limitation to user space, avoiding needless changes going forward. Jan