[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] libs/devicemodel: fix test for DM_OP availability


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Mon, 4 Jan 2021 15:12:02 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0ZHsFdt0b4td30Pp+KKcLpYYYNId4lE61/bzgQR+nls=; b=YomOvIUJZ3MNs6SFt+LyObQQ+GZ8XcwGgkvXteHTZOC7HEznui5QAyXxlCukJrDx9ehE6TpOfXl1bDzgBqBaT8SG61U7Je4wbt6RKtTReByBSU4T1FkFWFUEJ/gEO2FUOoRjNJvvXwt5T0d0/WYECA83/1zxcfFVOObwuP4MVvSasr/KoIzZffCWqqrFByt6onvn8WNDYl7AyPFQiky8piuWa/gANraTo62nc9HHgxEQ7oqhOrqNWdS2aOQfiWoPf61HR5oirMRDuJ6SVbtr/R23c5qx8txvlMClV2OBVUHaUQn1Wt1HYt3Hdsp7Ee+20kQKmeeabQAg9wSK1dtVHA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m4wnpVaE5JFKg0lo+6icpJIbGXyfHtXbKavfPI5Wre0uHUI6T1Dv3QDx9Fj0nyWzuHqhaTCVlFOMkXkyHhMw2YP9Q2efONtDI/+kBWpRm+dhbBo9T02RvHpRIazKVLhHsMTgGCkJrPP5rDqUvz1QUsUXtf9mOi1SjL3L2QlXgC5kzPPG6isqdagkISrPGhWipCRCCRB8FwSChOgbpMa5FQ0YgYaOSsgO+q4LyCOO5t1zUjFlWsqh4GSHDCL9+h9M5lXNB7jFVk/ybOETd7SG3mphztMVupTyKJezl2TiZqFRFtntWoJtLx5ZpjjKJNLQjjtl8BhOVgB1hGsZEN4DWQ==
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Mon, 04 Jan 2021 14:12:16 +0000
  • Ironport-sdr: /eeFS23n8oQvMNsPPlmyI5zUPaay53VVYU189mClnT1DaD7muhb/FKAiXkkijT52ZVMFxa2sB0 kzJqWvYNuotkFb8Sed5ARM8Ky33NxIYaIsm/fIkaDjvIuTDKOSkWRO11IEP0Hj3T19/wgeQtjA +K+ZtYZgCwZaEBUMQT2lC9fruPDsnRzB3fAWnYO948MUYZ6uSKKBoy1J/vReQwpZOPovjwEETC JTrWkKiHPEy167mzeyfmSeE3lj5ddN5nnhZm1Lw3GegiuH3J2PhXLWqjDQv6xKsqGsUbcjpJuy dQA=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Current check for DM_OP availability in osdep_xendevicemodel_open will
always fail, because using DOMID_INVALID as the domain parameter will
make the hypervisor return -ESRCH, which will disable the usage of
the DOM_OP interface.

Fix this by checking the errno code of the test ioctl against
the privcmd unimplemented errno.

Fixes: e7745d8ef58 ('tools/libxendevicemodel: introduce a Linux-specific 
implementation')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
I'm not sure when this was introduced, because it seems like it's been
broken from the start, as the hypervisor always had the
rcu_lock_remote_domain_by_id check and the userspace library also
seems to have always just checked that the test ioctl would return
success.
---
 tools/libs/devicemodel/linux.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/tools/libs/devicemodel/linux.c b/tools/libs/devicemodel/linux.c
index 0fdc7121f1..35050b493e 100644
--- a/tools/libs/devicemodel/linux.c
+++ b/tools/libs/devicemodel/linux.c
@@ -35,11 +35,16 @@
 #define O_CLOEXEC 0
 #endif
 
+static int get_unimplemented_errno(int fd)
+{
+    return ioctl(fd, IOCTL_PRIVCMD_UNIMPLEMENTED, NULL) == -1 ? errno : -1;
+}
+
 int osdep_xendevicemodel_open(xendevicemodel_handle *dmod)
 {
     int fd = open("/dev/xen/privcmd", O_RDWR | O_CLOEXEC);
     privcmd_dm_op_t uop;
-    int rc;
+    int rc, unimplemented_errno;
 
     if (fd < 0) {
         /*
@@ -54,6 +59,14 @@ int osdep_xendevicemodel_open(xendevicemodel_handle *dmod)
         return -1;
     }
 
+    unimplemented_errno = get_unimplemented_errno(fd);
+    if (unimplemented_errno < 0) {
+        xtl_log(dmod->logger, XTL_ERROR, -1, "xendevicemodel",
+                "privcmd ioctl should not be implemented");
+        close(fd);
+        return -1;
+    }
+
     /*
      * Check to see if IOCTL_PRIVCMD_DM_OP is implemented as we want to
      * use that in preference to libxencall.
@@ -63,7 +76,7 @@ int osdep_xendevicemodel_open(xendevicemodel_handle *dmod)
     uop.ubufs = NULL;
 
     rc = ioctl(fd, IOCTL_PRIVCMD_DM_OP, &uop);
-    if (rc < 0) {
+    if (rc < 0 && errno == unimplemented_errno) {
         close(fd);
         fd = -1;
     }
-- 
2.29.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.