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

[PATCH] libxc: remove / adjust xc_get_cpufreq_para()'s BUILD_BUG_ON()s


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 23 Aug 2023 15:47:05 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CIxt7hMLQ6hhZMWbOHJvcK1Rpe3xiwvE+0oqWF42BV4=; b=eYBb/s1xYJNvfQMW080hqyIZRMSihFE+Pw6vDYsDtq1wYyyLEcHUA7kHNm5HUho9woNL4TOC6DyBsL49tBW+c9/oQ47NJgXrti4Z8R8XYTIXdnYYzX4TfOYI8LS5uzHVGOBg2/fhu/5Z1y9GA3/GfowaZao974xuHJVwfw4KqVZ+8561unkkdnI/WRDhiDHQ07J/4rVSZ2VEI9GkwyyX4fBb5WFaQV6Ug6P0r0M6t1vDYylaz3YFqnj18kadwBWGjEMxLTj6rtNKo/JKb3g4132ppi5lLFYmQn6Qaa0kSt+/zaDGz+wXlbp7hQNkWFnp2AzslvmQDAS3eBKzanJ7nA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mhFIuCCn14JoP471XYPI40x07aBjXBtR91iNRCasHiuFjfvPb350rHyHpSaaTWKPCVuKm3qWewH2xW9HKGCAKgeu1/UcXLS3FHr9zazrjTZFs9PXMNfztyF85qGVG4Hnkb4rolfVugbjwN/dRzH6bvV8Cnch7CvMhZ2nUpUiUu3VsqaIChK6RSeXAptw8mvK/oBGGBvfzRiKtgy+JLP9XbxfEkbKXhHgd6+AG9FK/skza0tYmv95x9l27a9hMGkK0TOLA9hHNa4Ks/meINTykeLUd7wdpLVvYYuXD6latgPRARIm3CmWcjA6F6n7O4bs4FrQ/4+WKXmhSdNQ+8FeUw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Anthony Perard <anthony.perard@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Jason Andryuk <jandryuk@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Wed, 23 Aug 2023 13:47:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The full structures cannot match in layout, as soon as a 32-bit tool
stack build comes into play. But it also doesn't need to; the part of
the layouts that needs to match is merely the union that we memcpy()
from the sysctl structure to the xc one. Keep (in adjusted form) only
the relevant ones.

Since the whole block needs touching anyway, move it closer to the
respective memcpy() and use a wrapper macro to limit verbosity.

Fixes: 2381dfab083f ("xen/sysctl: Nest cpufreq scaling options")
Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/tools/libs/ctrl/xc_pm.c
+++ b/tools/libs/ctrl/xc_pm.c
@@ -248,45 +248,6 @@ int xc_get_cpufreq_para(xc_interface *xc
     sys_para->freq_num = user_para->freq_num;
     sys_para->gov_num  = user_para->gov_num;
 
-    /* Sanity check struct layout */
-    BUILD_BUG_ON(sizeof(*user_para) != sizeof(*sys_para));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), cpu_num) !=
-                 offsetof(typeof(*sys_para),  cpu_num));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), freq_num) !=
-                 offsetof(typeof(*sys_para),  freq_num));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), gov_num) !=
-                 offsetof(typeof(*sys_para),  gov_num));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), affected_cpus) !=
-                 offsetof(typeof(*sys_para),  affected_cpus));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_available_frequencies) !=
-                 offsetof(typeof(*sys_para),  scaling_available_frequencies));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_available_governors) !=
-                 offsetof(typeof(*sys_para),  scaling_available_governors));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_driver) !=
-                 offsetof(typeof(*sys_para),  scaling_driver));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_cur_freq) !=
-                 offsetof(typeof(*sys_para),  cpuinfo_cur_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_max_freq) !=
-                 offsetof(typeof(*sys_para),  cpuinfo_max_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_min_freq) !=
-                 offsetof(typeof(*sys_para),  cpuinfo_min_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_cur_freq) !=
-                 offsetof(typeof(*sys_para),  u.s.scaling_cur_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_governor) !=
-                 offsetof(typeof(*sys_para),  u.s.scaling_governor));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_max_freq) !=
-                 offsetof(typeof(*sys_para),  u.s.scaling_max_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_min_freq) !=
-                 offsetof(typeof(*sys_para),  u.s.scaling_min_freq));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.u.userspace) !=
-                 offsetof(typeof(*sys_para),  u.s.u.userspace));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.u.ondemand) !=
-                 offsetof(typeof(*sys_para),  u.s.u.ondemand));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), u.cppc_para) !=
-                 offsetof(typeof(*sys_para),  u.cppc_para));
-    BUILD_BUG_ON(offsetof(typeof(*user_para), turbo_enabled) !=
-                 offsetof(typeof(*sys_para),  turbo_enabled));
-
     ret = xc_sysctl(xch, &sysctl);
     if ( ret )
     {
@@ -316,6 +277,22 @@ int xc_get_cpufreq_para(xc_interface *xc
         BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) !=
                     sizeof(((struct xen_get_cpufreq_para *)0)->u));
 
+        /* Sanity check layout of the union subject to memcpy() below. */
+        BUILD_BUG_ON(sizeof(user_para->u) != sizeof(sys_para->u));
+#define CHK_FIELD(fld) \
+        BUILD_BUG_ON(offsetof(typeof(user_para->u), fld) != \
+                     offsetof(typeof(sys_para->u),  fld))
+
+        CHK_FIELD(s.scaling_cur_freq);
+        CHK_FIELD(s.scaling_governor);
+        CHK_FIELD(s.scaling_max_freq);
+        CHK_FIELD(s.scaling_min_freq);
+        CHK_FIELD(s.u.userspace);
+        CHK_FIELD(s.u.ondemand);
+        CHK_FIELD(cppc_para);
+
+#undef CHK_FIELD
+
         memcpy(&user_para->u, &sys_para->u, sizeof(sys_para->u));
     }
 



 


Rackspace

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