[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: Tue, 5 Apr 2022 09:51:10 +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=XItcJLea+9/iugA0x5KWXlb5ZZGxIDQXLt3Q3Qo4eJk=; b=VN/fumIXvK0FiW28tv/MtPdsZdEwb66mbY9iMKOlUCV6gM97buPSu5v/7xL6cbUzfSYNH9oXH+tbmAntnkR5B5SjJT6ZlY792NllTqSg4NZP1V1UTLv9WMTttk//Clyaiy5FHbqHEZgERjlGLr0RciK4DcVCRo9Bk/wHNfC373eyc1B2PkfqNkvw8OwUuPOgJ/D/zElJw2MaUNy0lYk3u1l/82mpuqXOuEVkPYGpkuPgY3VITGyw2aQvTUbgWNskXmfvY06dcM4KXZWNBHhiticLsWSF99J2HVhxj9qVzKis1TJiygAv3TzrB2za3ww2B16OsFyGG/8jhPOnWVq2yg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fD1VfFDswT5xiN/lR4KE3LfAzn4o0vs2tHGRdkmjH/EpD6AdkwkTT4wb98fzD1x7X/fCWppEFcXa17TWvTfCrlBQ5nR6XPDBxsua9ff9qQ4ZQQIJWCnqpgxpgWwUHd/iuuxhiKq1ZVZeaEkxLQv9iBJmcA4uHKzZZ4RZ0UCyiC7Yl3N8NCQX2bw09/PZqMk59VA8+AofbQ/rIepJcaIVYI7sxJJ1chUwl6pM6DStHBH0JW8tYHwYlBye9m2Eir+kMlKFShD24z9+ACfTkzRodDpD9Ez0htvowaBaE+Uo/xFM2lvrsewonUfs9avlGDk+h5YKT1Ce8qzPBJF6FaaTlQ==
- Authentication-results: esa1.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: Tue, 05 Apr 2022 07:51:30 +0000
- Ironport-data: A9a23:Qoc+UKpOkjLFI6Il2HRzumT5aVFeBmIPZRIvgKrLsJaIsI4StFCzt garIBnXOqmMYmenKIpyPIy//RwB7ZKBzYI3Sgs4/nsyHngXopuZCYyVIHmrMnLJJKUvbq7GA +byyDXkBJppJpMJjk71atANlVEliefQAOCU5NfsYkidfyc9IMsaoU8lyrZRbrJA24DjWVvR4 Y6q+qUzBXf+s9JKGjNMg068gEsHUMTa4Fv0aXRnOJinFHeH/5UkJMp3yZOZdhMUcaENdgKOf M7RzanRw4/s10xF5uVJMFrMWhZirrb6ZWBig5fNMkSoqkAqSicais7XOBeAAKv+Zvrgc91Zk b1wWZKMpQgBZYTgpOIPdz9iCXt1EoBI++6YGH3grpnGp6HGWyOEL/RGCUg3OcsT+/ptAHEI/ vsdQNwPRknd3aTsmuv9E7QywJR4RCXoFNp3VnVI1zbWAOxgWZnea67L+cVZzHE7gcUm8fP2O ZpFM2YxN02ojxtnM2ZLWLEdrueTqmjScyJhummNioAJ2j2GpOB2+Oe0a4eEEjCQfu1Kmm6Iq 2SA+H72ajkKOdraxTeb/3aEgu7UgTi9SI8UDKe/9PNhnBuU3GN7IB8cWEa/oPK5olWjQN8ZI EsRkhfCtoBrqhbtFIOkGUTl/jjU5XbwRua8DcVhwS2xzLjwxTyDXGMrYzBCOYMfsZApEGlCO kCyo/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t3ck4klfbMkcAIDaeRCdg18Kc=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Mon, Apr 04, 2022 at 05:33:04PM +0200, Jan Beulich wrote:
> On 04.04.2022 15:22, Roger Pau Monné wrote:
> > 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?
>
> There's no data -> function pointer conversion for the comparisons; the
> situation there is even less pleasant. What I referred to was actually
> the initializer, where there would be a data -> function pointer
> conversion if I used void *.
I see, there are architectures with different sizes for function and
data pointers. It's also not clear all compilers will be happy with
the conversion.
> >> ---
> >> 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.
>
> I'll be happy to name it something like this; the primary thing to
> settle on is the type to use.
I think it's safer to use a function pointer type like you currently
have from a correctness PoV, but in order to prevent stray calls to
read_tsc() I would rename to READ_TSC_PTR_POISON. This was already
static, so I guess it's hard anyway for any of such direct calls to
appear without us realizing.
With that:
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Thanks, Roger.
|