[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 4/4] x86/time: use fake read_tsc()
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- Date: Mon, 4 Apr 2022 15:22:09 +0200
- 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dM5NPhdrVPEHQ1C0IQMR/V+vTg+RJY68DtxFMMsm7ts=; b=f1Wfu5PB+kfup3uZLj5T4AQvJjLNY6zwsa49NvN/nc0SoTkK5TVQ+UUYTLssH4yNKZ9a8Tlk8Bebxjtc1BzZpJRwOAfaZ4E7XGwYZUDtkLTdKn7a9erejy6nsVHLPJGF96FlvotYxtGuAqgBszirn+F30DSb5LQK8oon/dQHlI4w/ehs/ydAmdPyVlpmkc8byFL0/WyvMuGG8gKtw3TJA53dpy3uhi54zCEEHXqn28nI8d5DQ8SXR7k6PbduzK65pUwLKzFFAnrgsa5zqezBPgJgLW2c0g9tHTcXIoJ7hjIIMi9eJ/zZf7jSIPR+Rgn2uR7yOUYiJ0BqGndzbXzPRg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QiqWDIPDp/bDlZu8I2uZD7bdcvlwuSmJJyxOqeWtH9JwQGfr0IpmY/8I7YK7+VVsrkL5E5sWNyKdeiqWLd3W0mDHE0jcmMRnF4f0Aa5rvkBTEZlzNlnMloEUvvoQPh7APY859d2Yy0/xx/75DU+4S+g4zHauPbuQcpgWx4gR1kZuk6mWuOzhAE50UFdBhQ4o+FIQH4YLdbPXZx25Rp1qvK3ONdDuQMJBbD06I7mJW/Lh4yWkWo2941wfDSzLTJswGTE2ZvIJamY5dn5+p8Q1FfBdP/w5EP1p2jPE5ho5bFsfoC0DdAA7JzH2qmKlWMuGOUQ2xhZBunwAgLYZ3dsuaw==
- Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Mon, 04 Apr 2022 13:22:30 +0000
- Ironport-data: A9a23:xMumFKgvvgW1lSI8Yzbec97hX161dxAKZh0ujC45NGQN5FlHY01je htvXT3SbvnZYGfwKNogO4i38x5XscXRzYVnQAtprCpmEywb9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oDJ9CU6jefSLlbFILas1hpZHGeIcw98z0M78wIFqtQw24LhX1vR4 YqaT/D3YzdJ5RYlagr41IrbwP9flKyaVOQw5wFWiVhj5TcyplFNZH4tDfjZw0jQG+G4KtWSV efbpIxVy0uCl/sb5nFJpZ6gGqECaua60QFjERO6UYD66vRJjnRaPqrWqJPwwKqY4tmEt4kZ9 TlDiXC/YTw3EaTGmMIlaRoCHXB6eoBDwb3JO3fq5KR/z2WeG5ft6/BnDUVwNowE4OdnR2pJ8 JT0KhhUMErF3bjvhuvmFK883azPL+GyVG8bkmtnwjzDS+4vXLjIQrnQ5M8e1zA17ixLNaiBP JVBNGM/BPjGSxhWPEoGT5tjpum5uFT7UTlJpmio5oNitgA/yyQuieOwYbI5YOeiWsF9jkue4 GXc8AzREhwccdCS1zeB2natnfPU2zP2XpoIE7+1/eIsh0ecrkQRAhALUVqwodGil1WzHdlYL iQpFjEG9PZoshbxF5+kAkP+8CXsUgMgt8R4KPMV4QuN7JLu4FyXV2xDYzt4atI8u5pjLdA17 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xen developer discussion <xen-devel.lists.xenproject.org>
On Thu, Mar 31, 2022 at 11:31:38AM +0200, Jan Beulich wrote:
> 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.
I think it's slightly better to avoid being able to call the function,
hence using void * would be my preference. What's wrong with the data
-> function pointer conversion for the comparisons?
> ---
> 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)
Instead of naming this like a suitable function, I would rather use
READ_TSC_PTR_POISON or some such.
Thanks, Roger.
|