EPK: Scalable and Efficient Memory Protection Keys

Jinyu Gu, Hao Li, Wentai Li, Yubin Xia, Haibo ChenUSENIX ATC 2022

TL;DR

This paper introduces EPK, a novel hardware-assisted mechanism that significantly scales Intel's Memory Protection Keys (MPK) from 16 to 7,680 memory protection domains. By cleverly combining MPK with Extended Page Tables (EPT) and virtualization exceptions, EPK achieves this massive scalability with minimal performance overhead, making fine-grained memory isolation practical for a much wider range of applications.

What Problem Does This Paper Address?

Intel's Memory Protection Keys (MPK) offer a highly efficient way to isolate memory regions within a single process, providing benefits for security, isolation, and performance. However, MPK is severely limited by its support for only 16 distinct memory domains. This limitation makes it impractical for many real-world scenarios, such as handling numerous concurrent clients in server applications, protecting sensitive data in persistent memory, or isolating the many components within complex software like operating system kernels. Existing solutions to overcome this limitation either incur significant performance overhead (software-based) or require infeasible hardware modifications.

Methods

EPK's core innovation lies in its combination of two existing hardware features: Intel MPK and Extended Page Tables (EPT) with Virtual Machine Function (VMFUNC).

  • Extended Protection Keys (EPK): Instead of relying solely on MPK's 16 protection keys (pkeys), EPK extends the concept by creating "extended protection keys." These are formed by combining a pkey with an EPT index. This allows multiple memory domains to share the same pkey as long as they reside in different EPTs.
  • Leveraging EPTs: EPK utilizes multiple EPTs (up to 512) for a virtual machine (VM). Each EPT can then host up to 15 domains (domain-0 is shared). This allows for a massive increase in the total number of available domains (15 domains/EPT * 512 EPTs = 7,680 domains).
  • Virtualization Exceptions (VE): To handle the complexity of accessing domains across different EPTs, EPK employs Virtualization Exceptions (VE). When a thread attempts to access a domain in a different EPT, an EPT violation triggers a VE, allowing the guest OS to transparently switch to the correct EPT and resume execution. This avoids expensive VMExits.
  • Shadow Address Space: To manage GPA-to-HPA mappings across multiple EPTs and distinguish between legal and illegal EPT violations, EPK introduces a "shadow address space" by using a fixed offset for domain memory. This simplifies EPT management and allows the hypervisor to detect illegal accesses.
  • User-Level Library and Kernel Module: EPK provides a user-friendly library with APIs similar to MPK, abstracting away the underlying hardware complexity. A kernel module in the guest OS handles domain page faults and interacts with the hypervisor.

Datasets

Not discussed in the paper. The paper focuses on micro-benchmarks and macro-benchmarks using existing applications and workloads.

Key Insights and Ideas

  • Hardware Synergy: The paper demonstrates the power of combining seemingly orthogonal hardware features (MPK and EPT/VMFUNC) to achieve a result far greater than the sum of its parts.
  • Scalability through Virtualization: By leveraging the virtualization infrastructure (EPTs), EPK unlocks a massive increase in protection domains without requiring fundamental changes to the CPU architecture itself.
  • Transparent Multi-Domain Access: The use of Virtualization Exceptions (VE) is crucial for enabling threads to seamlessly access memory across different EPTs, a key feature for many applications.
  • Abstraction is Key: The success of EPK relies heavily on its user-level library, which hides the complex EPT management from application developers, making it easy to adopt.

Key Results

  • Massive Domain Scalability: EPK supports up to 7,680 memory protection domains, a ~480x increase over MPK's 16 domains.
  • Minimal Performance Overhead:
    • In server applications (NGINX), EPK introduces only 4.3% to 5.8% overhead compared to native execution, outperforming other solutions.
  • For Memcached, EPK incurs at most 0.7% overhead for SET operations and up to 2.9% for GET operations, with extremely low overhead when EPT switches are not on the critical path.
  • In data structure benchmarks (B+-tree, Linked List, Hashtable), EPK's overhead is generally low, often outperforming libmpk by orders of magnitude, especially when domain numbers exceed 15.
  • In microkernel IPC benchmarks (SQLite3), HyBridge (EPK-based IPC) achieves significant speedups, up to 9x for Zircon.
  • Outperforms Existing Solutions: EPK consistently outperforms libmpk (a software extension for MPK) and VMFUNC-only solutions in terms of performance and scalability.

Limitations and Future Work

  • Kernel Involvement for Multi-EPT Access: While VE enables transparent access across EPTs, accessing multiple domains in different EPTs still requires kernel involvement (a "slow path").
  • Reclaiming Pages in Shadow Address Space: The current implementation of EPK does not fully support reclaiming pages mapped in the shadow address space, which is a limitation for hypervisor memory management.
  • Hardware Modifications for Other Architectures: While the core idea of EPK is extensible to other architectures like ARM, efficient hardware-assisted fast switching for stage-2 page tables would be needed.
  • Future Work: The authors suggest exploring the extensibility of EPK to other architectures and further optimizing the multi-domain access mechanism. They also highlight the need for OS awareness of MPK to prevent certain attacks.

Summary updated

BibTeX
@inproceedings{gu2022epk,
  author = {Jinyu Gu and Hao Li and Wentai Li and Yubin Xia and Haibo Chen},
  title = {{EPK: Scalable and Efficient Memory Protection Keys}},
  booktitle = {USENIX ATC},
  year = {2022},
  url = {https://openreview.net/forum?id=KFUteYlxuK},
}
Figure