Supporting invocations of the rdtsc (read time-stamp counter) instruction by guest code within a secure hardware enclave
Abstract
Techniques for supporting invocations of the RDTSC (Read Time-Stamp Counter) instruction, or equivalents thereof, by guest program code running within a virtual machine (VM), including guest program code running within a secure hardware enclave of the VM, are provided. In one set of embodiments, a hypervisor can activate time virtualization heuristics for the VM, where the time virtualization heuristics cause accelerated delivery of system clock timer interrupts to a guest operating system (OS) of the VM. The hypervisor can further determine a scaling factor to be applied to timestamps generated by one or more physical CPUs, where the timestamps are generated in response to invocations of a CPU instruction made by guest program code running within the VM, and where the scaling factor is based on the activated time virtualization heuristics. The hypervisor can then program the scaling factor into the one or more physical CPUs.
Claims
exact text as granted — not AI-modifiedWhat is claimed is:
1 . A method comprising:
activating, by a hypervisor of a host system, time virtualization heuristics for a virtual machine (VM), the time virtualization heuristics causing accelerated delivery of system clock timer interrupts by the hypervisor to a guest operating system (OS) of the VM; upon activating the time virtualization heuristics, trapping, by the hypervisor, an invocation of a RDTSC (Read Time-Stamp Counter) instruction made by guest program code running within the VM; and in response to trapping of the RDTSC instruction:
deactivating, by the hypervisor, the time virtualization heuristics for the VM; and
advancing, by the hypervisor, a system clock counter of the VM to be consistent with real-world time, wherein the system clock counter indicates a system time of the VM and is based on the system clock timer interrupts delivered by the hypervisor.
2 . The method of claim 1 further comprising, prior to the trapping:
enabling a trap bit for trapping, by the hypervisor, invocations of the RDTSC instruction.
3 . The method of claim 2 further comprising, subsequently to advancing the system clock counter:
disabling the trap bit.
4 . The method of claim 1 wherein the guest program code comprises program code running within a secure hardware enclave of the VM.
5 . The method of claim 1 wherein advancing the system clock counter causes future RDTSC timestamps generated by one or more physical central processing units (CPUs) of the host system to be consistent with the system clock counter.
6 . The method of claim 1 wherein deactivating the time virtualization heuristics disables the accelerated delivery of the system clock timer interrupts.
7 . The method of claim 1 wherein advancing the system clock counter comprises:
issuing a remote procedure call (RPC) to an agent running within the VM requesting a forward clock correction of the system clock counter.
8 . A non-transitory computer readable storage medium having stored thereon program code executable by a hypervisor of a host system, the program code embodying a method comprising:
activating time virtualization heuristics for a virtual machine (VM), the time virtualization heuristics causing accelerated delivery of system clock timer interrupts by the hypervisor to a guest operating system (OS) of the VM; upon activating the time virtualization heuristics, trapping an invocation of a RDTSC (Read Time-Stamp Counter) instruction made by guest program code running within the VM; and in response to trapping of the RDTSC instruction:
deactivating the time virtualization heuristics for the VM; and
advancing a system clock counter of the VM to be consistent with real-world time, wherein the system clock counter indicates a system time of the VM and is based on the system clock timer interrupts delivered by the hypervisor.
9 . The non-transitory computer readable storage medium of claim 8 wherein the method further comprises, prior to the trapping:
enabling a trap bit for trapping, by the hypervisor, invocations of the RDTSC instruction.
10 . The non-transitory computer readable storage medium of claim 9 wherein the method further comprises, subsequently to advancing the system clock counter:
disabling the trap bit.
11 . The non-transitory computer readable storage medium of claim 8 wherein the guest program code comprises program code running within a secure hardware enclave of the VM.
12 . The non-transitory computer readable storage medium of claim 8 wherein advancing the system clock counter causes future RDTSC timestamps generated by one or more physical central processing units (CPUs) of the host system to be consistent with the system clock counter.
13 . The non-transitory computer readable storage medium of claim 8 wherein deactivating the time virtualization heuristics disables the accelerated delivery of the system clock timer interrupts.
14 . The non-transitory computer readable storage medium of claim 8 wherein advancing the system clock counter comprises:
issuing a remote procedure call (RPC) to an agent running within the VM requesting a forward clock correction of the system clock counter.
15 . A host system comprising:
one or more physical central processing units (CPUs); a hypervisor; and a non-transitory computer readable medium having stored thereon program code that, when executed, causes the hypervisor to:
activate time virtualization heuristics for a virtual machine (VM), the time virtualization heuristics causing accelerated delivery of system clock timer interrupts by the hypervisor to a guest operating system (OS) of the VM;
upon activating the time virtualization heuristics, trap an invocation of a RDTSC (Read Time-Stamp Counter) instruction made by guest program code running within the VM; and
in response to trapping of the RDTSC instruction:
deactivate the time virtualization heuristics for the VM; and
advance a system clock counter of the VM to be consistent with real-world time, wherein the system clock counter indicates a system time of the VM and is based on the system clock timer interrupts delivered by the hypervisor.
16 . The host system of claim 15 wherein the program code further causes the hypervisor to, prior to the trapping:
enable a trap bit for trapping invocations of the RDTSC instruction.
17 . The host system of claim 16 wherein the program code further causes the hypervisor to, subsequently to advancing the system clock counter:
disable the trap bit.
18 . The host system of claim 15 wherein the guest program code comprises program code running within a secure hardware enclave of the VM.
19 . The host system of claim 15 wherein advancing the system clock counter causes future RDTSC timestamps generated by the one or more CPUs to be consistent with the system clock counter.
20 . The host system of claim 15 wherein deactivating the time virtualization heuristics disables the accelerated delivery of the system clock timer interrupts.
21 . The host system of claim 15 wherein the program code that causes the hypervisor to advance the system clock counter comprises program code that causes the hypervisor to:
issue a remote procedure call (RPC) to an agent running within the VM requesting a forward clock correction of the system clock counter.Join the waitlist — get patent alerts
Track US2023082141A1 — get alerts on status changes and closely related new filings.
We store only your email — no account needed. See our privacy policy.