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

[PATCH v4 4/4] x86/time: use fake read_tsc()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 31 Mar 2022 11:31:38 +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=jBAjZm98iC0F+YOWTsR9A+UOqJAYXH4F89jCY3IBJtM=; b=bHjVanWlzBfP53Td+x0yDE0dnh1+aPixi3xC0EZxcWIFgzD7K6ZzgAWkZFECB8fsctseuzVavRXqil7gGvHhpvm0V4XXXPR6FnAhvjfzgIt9d9FT4Qh2Irgd0Vc6BcxozA9F3uEB71WAqLw55KM1ocV3GicQTCHbtvWXLxiGQjIsThwwrX21rrCCG0S9S0hwpjtXAlQ/Q8oxGsYklaBzxKiWGbZlTrr6bxHhooacrp9f3nwuTDnuf2qo0FxKppXPca6YwRl2/LFCsqpKxmJ/hbHZ3w0obtjbfcOQzTiB9syjsHn1pW1y7i4zaf6/LwPqHoppKBL++EMu/H6pPWbX4w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eWSzYQcP5ZqG3Qi3jahptgK2O58ET3PmQl1yPJyoFoe+vleYXO34scJlHOaTGLnWXl6zAhLIbAVBMVvwB4ToGGYC8ImvLNxGcfqBFxe6RKjaPpKjtrmnibAK5V5AMW/bGVat3mASL8BLKaTqdUAR6r7uQi8oMwkJmUdIJVGxIypWsGwHbzkeYi+aopnQ3VmzxD+GhcDvh5WvXMWDLh1/NXxQ6tyy3UPZ2t6nDfzhfVnuTkXdHOOrrN7CPRvsEwOSWr7QdJOmK8EhWg4CEnwHrwaQ0fTFl0hs8ZosvqEoGUivEPiqCeQcwHeeXkRVpdfImV2EXwKFQUDnvnX57Sgw7Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 31 Mar 2022 09:31:46 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Go a step further than bed9ae54df44 ("x86/time: switch platform timer
hooks to altcall") did and eliminate the "real" read_tsc() altogether:
It's not used except in pointer comparisons, and hence it looks overall
more safe to simply poison plt_tsc's read_counter hook.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I wasn't really sure whether it would be better to use simply void * for
the type of the expression, resulting in an undesirable data -> function
pointer conversion, but making it impossible to mistakenly try and call
the (fake) function directly.
---
v2: Comment wording.

--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -607,10 +607,12 @@ static s64 __init cf_check init_tsc(stru
     return ret;
 }
 
-static uint64_t __init cf_check read_tsc(void)
-{
-    return rdtsc_ordered();
-}
+/*
+ * plt_tsc's read_counter hook is not (and should not be) invoked via the
+ * struct field. To avoid carrying an unused, indirectly reachable function,
+ * poison the field with an easily identifiable non-canonical pointer.
+ */
+#define read_tsc ((uint64_t(*)(void))0x75C75C75C75C75C0ul)
 
 static struct platform_timesource __initdata_cf_clobber plt_tsc =
 {




 


Rackspace

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