scieee AI-readable full text Open interactive document viewer

HSP-V: holistic static partitioning on RISC-V platforms

Sousa, João Miguel Costa

Abstract

No mundo dos sistemas embebidos, a virtualização apareceu como uma das soluções mais seguras, eficientes e económicas para consolidar os Mixed-Critical Systems (MCSs) na mesma plataforma de hard ware. Neste contexto, os hipervisores têm sido utilizados para enfrentar vários desafios de segurança, monitorizando os recursos de hardware e virtualizando as suas partições através de extensões de virtu alização. Tipicamente, o RISC-V, uma inovadora, livre, aberta e privilegiada Instruction Set Architecture (ISA), implementa estas tecnologias com uma extenção do modo supervisor (modo HS), fornecendo novos Control and Status Register (CSRs) e realizando a tradução de endereços em duas fases. Contudo, para evitar esta camada extra de tradução e empregar um sistema de partição estática nas plataformas RISC-V, esta dissertação utiliza um método para-virtualizado com o apoio da unidade Physical Memory Protection (PMP) e a técnica de trap-and-emulate. Para estabelecer um Holistic Static Partitioning on RISC-V platforms (HSP-V), esta dissertação explora uma camada fina de software, an Open-source implementation of the RISC-V Supervisor Binary Interface (OpenSBI). Este é responsável por estabelecer de comunicação entre camadas de nível superior com ca madas de nível inferior de privilégio. Além disso, trata as partições como instâncias de domínio e sofre da exposição componentes críticos da memória entre domínios. Entre eles está o controlador de interrupção externa RISC-V, o Platform-Level Interrupt Controller (PLIC), seguindo uma estrutura de Memory Mapped Input Output (MMIO). Como resultado, o HSP-V revela o reforço do isolamento entre domínios ao parti cionar a estrutura do PLIC e conectando diretamente as regiões mapeamento de MMIO, através da técnica de trap-and-emulate e da unidade de PMP. Para avaliar as modificações foi utilizada a placa MPFS-Icicle Kit, analisando: o desempenho de sobrecarga e interferência entre domínios (explorando métodos de bloqueio da cache), tempos de inicialização do sistema, latência de interrupção, e recursos de hardware em termos de maior complexidade do código OpenSBI, antes e depois de todo o melhoramento.

Full text

Universidade do Minho Escola de Engenharia julho de 2022 João Miguel Costa Sousa HSP-V: Holistic Static Partitioning on RISC-V Platforms João Miguel Costa Sousa HSP-V: Holistic Static Partitioning on RISC-V Platforms Dissertação de Mestrado Engenharia Eletrónica Industrial e Computadores Sistemas Embebidos e Computadores Trabalho efetuado sob a orientação de Professor Doutor Sandro Emanuel Salgado Pinto Professor Doutor João Luís Marques Pereira Monteiro Universidade do Minho Escola de Engenharia julho de 2022 DIREITOS DE AUTOR E CONDIÇÕES DE UTILIZAÇÃO DO TRABALHO POR TERCEIROS Este é um trabalho académico que pode ser utilizado por terceiros desde que respeitadas as regras e boas práticas internacionalmente aceites, no que concerne aos direitos de autor e direitos conexos. Assim, o presente trabalho pode ser utilizado nos termos previstos na licença abaixo indicada. Caso o utilizador necessite de permissão para poder fazer um uso do trabalho em condições não previstas no licenciamento indicado, deverá contactar o autor, através do RepositóriUM da Universidade do Minho. Agradecimentos É nesta altura que oficialmente finalizo uma etapa nobre. Uma etapa cheia de luta, de altos e baixos, de medos que se transformaram em conhecimento, de insegurança que virou confiança e de uma completa transformação. Certamente que doravante na minha carreira me irei lembrar de muitos momentos vividos nestes anos: da ansiedade pre testes, dos ditotes de cada professor, dos projetos realizados, do bar da Bertina (mãezinha), dos momentos de laboratório, dos lanches no bar, dos jogos de xadrez, do caderno mítico do lab. Por isso um agradecimento especial ao Antrapunas (Samuel Pereira), ao Elon Felps (André Campos), DJ’Review (Luís Cunha), O’Mestre (Diogo Costa) e ao irmão, mas não de sangue (Pedro Sousa). Estas pessoas fizeram o meu percurso, e merecem um especial agradecimento porque se não existissem, iria ter que as inventar. Foram aqueles que estiveram sempre lá para me tirar dúvidas; para me dar vícios; para me distrair; para me dizerem que estavam a sofrer (fazendo-me acreditar que não estava na luta sozinho); para me anestesiar com todas as conversas de criptomoedas, empreendedorismo, política, futebol, etc. Foram mais que colegas de trabalho, foram amigos! Numa vertente mais técnica, recordo-me do dia em que entrei naquele laboratório de prestígio pela primeira vez, o dia em que me expus a escolher a orientação. Entrei a tremer, com noção da decisão que tomava. Hoje, entro naquele laboratório com confiança, ”segurança”, com vontade e orgulho. Por isso deixo também um agradecimento especial aos meus orientadores: Professor Doutor Sandro Pinto, pelas vezes que me disse para bater com a cabeça, pela exigência, pela paciência, por todo o suporte e claro pela excelente orientação; Mestre José Martins, agradeço pela paciência, pela partilha de conhecimento, pela disponibilidade, pela exigência e claro também pela excelente orientação. Ainda numa parte técnica quero agradecer a uma pessoa que apareceu em alguns momentos difíceis, ao Mestre Bruno Sã que esteve lá para suportar algumas dúvidas, mesmo cheio de trabalho. Uma orientação que me fez acreditar que ”é sempre” possível, mesmo que demore tempo. Por último, mas não menos importante, queria agradecer a uma parte de suporte mais pessoal: Mãe, por fazer o meu tempo mais organizado e pela preocupação incansável; Pai, pelo suporte mental e por me mostrar que sou capaz daquilo que ainda nem sequer acredito; avós, madrinha, tios e primos, pelo apoio e pressão, que me fez não sair do foco; e Diana, que esteve lá nos momentos que ninguém viu, sempre pronta a sorrir (fosse em momentos de sol ou momentos nublados), pela sua paciência e pelos seus conselhos. i STATEMENT OF INTEGRITY I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the University of Minho. ii Resumo Particionamento Estático Holístico em Plataformas RISC-V No mundo dos sistemas embebidos, a virtualização apareceu como uma das soluções mais seguras, eficientes e económicas para consolidar os Mixed-Critical Systems (MCSs) na mesma plataforma de hardware. Neste contexto, os hipervisores têm sido utilizados para enfrentar vários desafios de segurança, monitorizando os recursos de hardware e virtualizando as suas partições através de extensões de virtualização. Tipicamente, o RISC-V, uma inovadora, livre, aberta e privilegiada Instruction Set Architecture (ISA), implementa estas tecnologias com uma extenção do modo supervisor (modo HS), fornecendo novos Control and Status Register (CSRs) e realizando a tradução de endereços em duas fases. Contudo, para evitar esta camada extra de tradução e empregar um sistema de partição estática nas plataformas RISC-V, esta dissertação utiliza um método para-virtualizado com o apoio da unidade Physical Memory Protection (PMP) e a técnica de trap-and-emulate. Para estabelecer um Holistic Static Partitioning on RISC-V platforms (HSP-V), esta dissertação explora uma camada fina de software, an Open-source implementation of the RISC-V Supervisor Binary Interface (OpenSBI). Este é responsável por estabelecer de comunicação entre camadas de nível superior com camadas de nível inferior de privilégio. Além disso, trata as partições como instâncias de domínio e sofre da exposição componentes críticos da memória entre domínios. Entre eles está o controlador de interrupção externa RISC-V, o Platform-Level Interrupt Controller (PLIC), seguindo uma estrutura de Memory Mapped Input Output (MMIO). Como resultado, o HSP-V revela o reforço do isolamento entre domínios ao particionar a estrutura do PLIC e conectando diretamente as regiões mapeamento de MMIO, através da técnica de trap-and-emulate e da unidade de PMP. Para avaliar as modificações foi utilizada a placa MPFS-Icicle- Kit, analisando: o desempenho de sobrecarga e interferência entre domínios (explorando métodos de bloqueio da cache), tempos de inicialização do sistema, latência de interrupção, e recursos de hardware em termos de maior complexidade do código OpenSBI, antes e depois de todo o melhoramento. Palavras-chave: Sistemas Embebidos, RISC-V, Sistemas de criticidade mista, Virtualização, OpenSBI, PLIC, Particionamento Estático iii Abstract Holistic Static Partitioning on RISC-V Platforms. In the world of embedded systems, virtualization has appeared as one of the most secure, efficient, and cost-effective solution to consolidate Mixed-Critical Systems (MCSs) onto the same hardware platform. Hereupon, hypervisors have been used to face several security challenges by monitoring hardware resources and virtualizing their partitions through virtualization extensions. Typically, the RISC-V, an innovative, free, open ISA and privileged computer architecture, implements these technologies with the hypervisor-extended supervisor mode (HS-mode), by providing new Control Status Registers (CSRs) and performing the two-stage-address translation. However, to avoid this extra translation layer and employ a static partitioning system in RISC-V platforms, this dissertation uses a para-virtualized method with the support of the Physical Memory Protection (PMP) unit and the trap-and-emulate technique. To establish a Holistic Static Partitioning system over RISC-V platforms (HSP-V), this dissertation enhances a thin layer of software, the Open-source Supervisor Binary Interface (OpenSBI). This is responsible for communication establishment between high and low-privileged layers. In addition, it treats partitions as domain instances and suffers from exposing critical memory components between domains. Between them is the RISC-V external interrupt controller, the Platform-Level Interrupt Controller (PLIC), following a Memory Mapped Input/Output (MMIO) structure. As a result, the HSP-V reveals the reinforcement of the inter-domain isolation by partitioning the PLIC structure and direct assigning the device MMIO regions through domain instances by leveraging the PMP unit and the trap-and-emulate technique. To evaluate HSP-V implementations was used the MPFS-Icicle-Kit board to analyze: performance in terms of overhead and inter-domain interference (leveraging the cache locking methods), boot overhead, interrupt latency, and hardware resources in terms of enhanced OpenSBI code complexity, before and afterward all enhancement. Keywords: Embedded Systems, RISC-V, MCSs, Virtualization, OpenSBI, PLIC, Static Partitioning. iv Contents List of Figures vii List of Tables viii Glossary ix 1 Introduction 1 1.1 MainGoal ...................................... 2 1.2 DissertationStructure................................. 3 2 Background and Related Work 4 2.1 Virtualization ..................................... 4 2.1.1 Virtualization for embedded systems . . . . . . . . . . . . . . . . . . . . . 4 2.1.2 Virtual Machine Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.3 Trap-and-emulate virtualization technique . . . . . . . . . . . . . . . . . . . 6 2.1.4 Memory Virtualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 RISC-V ........................................ 8 2.2.1 RISC-V specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2.2 PrivilegedModes............................... 8 2.2.3 Software Stack Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.4 RISC-VCSRs................................. 10 2.2.5 RISC-V Memory Protection Support . . . . . . . . . . . . . . . . . . . . . . 12 2.2.6 RISC-VInterrupts............................... 15 2.2.6.1 CLINT .............................. 15 2.2.6.2 PLIC ............................... 15 2.3 OpenSBI ....................................... 17 2.3.1 OpenSBI as a Runtime stage . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.3.2 SBISpecifications .............................. 19 2.3.3 Multi-platform support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.3.4 OpenSBIdomains .............................. 21 v Contents vi 2.3.5 DTConfiguration............................... 22 2.4 Relatedwork ..................................... 24 3 HSP-V: Design 28 3.1 MCSs with OpenSBI Domain System . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2 OpenSBIDomainSupport............................... 29 3.3 PLICPartitioning ................................... 31 3.3.1 PLIC Registers Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.3.2 PLIC Memory Regions Automatic Assignment . . . . . . . . . . . . . . . . . 33 3.4 Trap-and-emulate Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.5 MCSs with enhanced OpenSBI Domain System . . . . . . . . . . . . . . . . . . . . 35 4 HSP-V: Implementation 37 4.1 DeviceTreeBinding.................................. 37 4.2 Automatic Integration of Device MMIO Regions . . . . . . . . . . . . . . . . . . . . . 41 4.3 Automatic Integration of PLIC Regions Over Partitions . . . . . . . . . . . . . . . . . 42 4.4 Trap-and-emulate Mechanism Implementation . . . . . . . . . . . . . . . . . . . . . 43 5 HSP-V: Evaluation and Results 49 5.1 FunctionalValidation ................................. 51 5.1.1 Functional Validation: Domain Instance Configuration . . . . . . . . . . . . . 51 5.1.2 Functional Validation: Automatic Memory Assignment . . . . . . . . . . . . . 52 5.1.3 Functional Validation: Emulation of Critical PLIC Accesses . . . . . . . . . . . 53 5.2 CodeSize ...................................... 54 5.3 BootOverhead .................................... 55 5.4 Performance Overhead and Interference . . . . . . . . . . . . . . . . . . . . . . . . 58 5.5 InterruptLatency ................................... 59 5.6 Discussion ...................................... 60 6 Conclusion 62 6.1 FutureWork ..................................... 63 References 65 Chapter 1. Introduction 2 typically used to run an Operating System (OS) and provides virtual memory capabilities through a dedicated Memory Management Unit (MMU); and (iii) the user mode (U-mode), for conventional applications. For hypervisor support and to contribute to the virtualization efficiency, the S-mode can be extended for hypervisor-extended supervisor mode (HS-mode) [18, 19]. Inevitably, HS-mode introduces memory translation support through a two-stage address translation, from a Virtual Address (VA) to a Physical Address (PA). This process splits into two stages: (i) the Guest Virtual Address (GVA) to Guest Physical Address (GPA), through the OS; and (ii) the GPA to PA, through the hypervisor. On the other hand, due to other architectural support, i.e., the Physical Memory Protection (PMP) unit, it is possible to avoid this two-stage address translation [20]. The PMP unit grants/suppress access permissions to low privileged layers (S or U-mode), and each hart (essentially a core in RISC-V terminology) can manage different accesses without passing through a hypervisor layer while providing isolation between partitions [21, 22]. When running a GPOS over the S-Mode privileged layer, the address translation is done directly from VA to PA through the MMU. To establish static partitioning systems in RISC-V without hypervisor extensions, Open-source implementation of the RISC-V Supervisor Binary Interface (OpenSBI) provides a thin layer of software running in M-mode. It integrates a partitioning system, the OpenSBI domains systems, which assign memory regions to one or several harts. Each domain establishes its memory regions during Second-Stage Boot Loader (SSBL) through to the PMP unit. Additionally, the OpenSBI offers run-time services through a Supervisor Binary Interface (SBI) between low and higher privileged levels (following RISC-V SBI specifications). Despite the well-provided inter-domain isolation and due to the PMP constraints, OpenSBI does not protect all domain resources, as is the case of the RISC-V external interrupt controller, the Platform-Level Interrupt Controller (PLIC). Because the PLIC is an Memory Mapped Input Output (MMIO) structure and needs to be shared among all domains, when a malicious domain tries to access it, it can compromise other domains and break the spacial isolation. Aiming to tackle this issue, this dissertation contributes to the protection of this memory component by enhancing the OpenSBI with additional features such as, the partitioning PLIC, as the direct assignment of device MMIO regions to domains and integrating a virtualization technique, the trap-and-emulate, to establish inter-domain isolation. 1.1 Main Goal This dissertation aims to develop an Holistic Static Partitioning on RISC-V platforms (HSP-V), which enhances the OpenSBI, either (i) in the configuration of OpenSBI domain instances, (ii) in automatic direct device MMIO assignment, and (iii) the partitioning of PLIC structure. The main goals of this dissertation are outlined below: •Implement a RISC-V static partitioning system without hypervisor extension by enhancing OpenSBI configuration and adding virtualization techniques (e.g., the trap-and-emulate) to improve the external interrupt controller isolation between partitions/domains; Chapter 1. Introduction 3 •Evaluate the enhanced OpenSBI over a multi-core environment, in a real Commercial Off-The-Shelf (COTS) RISC-V platform, while supporting different combinations of subsystems (e.g., a GPOS with an RTOS; a RTOS with a bare-metal application; a bare-metal application with a GPOS); •Evaluate the following metrics: performance in terms of inter-domain interference (with and without cache locking); boot overhead; interrupt latency; and hardware resources in terms of complexity of the code of OpenSBI, previously and afterward all changes; 1.2 Dissertation Structure This dissertation is structured as follows: Chapter 2 starts by giving a background of the virtualization, going through several concepts, presenting its impact in embedded system and different approaches of its use. Next, it goes through the used architecture, the RISC-V, which reveals all of its specifications, privileged modes, stack terminology and its interrupt controllers. Lastly, describes the main target software, i.e., the OpenSBI, going through its contributions, its functionalities and its configuration details (e.g., how it statically instantiates different partitions in same hardware platform). Last but not least, this chapter ends by specifying the related work and comparing their contributions and their protection methods with the used by this dissertation. After the first contextualization, Chapter 3 begins by examining a multi-domain scenario formed by the original OpenSBI. It analyzes the isolation of OpenSBI domains and reveals some of their critical memory regions. Next, it proposes a design solution adopted by this dissertation, i.e., the HSP-V. This solution essentially consists in enhancement of the OpenSBI in different aspects: (i) by adding a OpenSBI configuration feature and (ii) by enhancing the isolation through architecture capabilities (the PMP) or though a virtualization technique (the trap-and-emulate). To close the chapter, it analyzed a multiple domains’ scenario with the proposed design. Chapter 4, shows the implementation details of the proposed design, leveraging all topics mention in previous chapter. Chapter 5, evaluate the results over a specific RISC-V platform by leveraging several topics like: functional validation tests; code complexity; boot overhead; interrupt latency; performance overhead and interference. At the end of this chapter, this dissertation discusses the obtained results going through each of them. Last but not least, Chapter 6 leverages all work, arguing about all changes and mention all obtained contributions. At the end, this dissertation finishes by mention some work that could possibly be added to reinforce the HSP-V. 2. Background and Related Work 2.1 Virtualization The concept of virtualization emerged between the years 1960-1970 when IBM launched time-sharing solutions [23]. Time-sharing solutions refer to the pooling of computer resources between several users, enabling better efficiency and cost savings. This process resulted in a breakthrough in computer technology, affecting sectors such as the avionics and automotive industry [24, 25], which drove virtualization to the point where it has emerged as the greatest solution for increasing resource usage. With virtualization, industries can achieve competitive advantages [26] by increasing efficiency and reducing production costs. However, the required consolidation of several subsystems onto a single hardware platform brings the form of MCSs [27]. When combining components with different levels of criticality, embedded systems face challenges in security, safety, and resource-sharing efficiency. 2.1.1 Virtualization for embedded systems As the complexity and real-time needs have increased, virtualization has become more prevalent in embedded systems. These have changed from single functionality and single-purpose to sophisticated and diverse/complex purposes systems [28, 29]. For example, network-connected infotainment and air conditioning are typically integrated into automotive or avionics alongside safety-critical control systems [30, 31]. Therefore, system virtualization designers must pay special attention while combining these subsystems to ensure truly spatial and temporal isolation between partitions. Spatial isolation exists when partitions are unable to modify one another’s code or private data [32], and it is typically disrupted when shared resources are exposed (memory buses, cache, and others). On the other hand, if the execution time of a partition is not affected by other partitions, the system is termed temporally isolated [33]. Nowadays, the struggle to realize the integration of MCSs on the same hardware platform has created immense challenges in computing [34, 35]. Challenges in the trustworthiness of partitions with the absence of catastrophic failures based on non-deliberate acts or circumstances, safety [36], or even when exposed to malicious attacks on deliberated actions, security [36]. However, virtualization appears as a natural solution with hypervisors (also known as VMM) like Xen [37], KVM [38], and Bao [39] to achieve consolidation and integration or even focus on safety and security functionalities. 4 Chapter 2. Background and Related Work 5 2.1.2 Virtual Machine Monitor Hypervisors appear as an additional layer of software responsible for monitoring hardware resources of its partitions and idealize them that they are running in a separated hardware, as similar as possible compared to the original [40]. These underlying hardware subsystems that use a virtualized interface, and that are monitored by hypervisors, are called Virtual Machine (VM)s. In MCSs, the hypervisor typically have complete control over the underlying hardware platform [40, 41]. As seen in Figure 2.1, the hypervisor is placed closest to the hardware (type-1 hypervisors), while the OSs are confined to lower privilege levels. The virtualized computing stack highlights how several concurrent guests may be consolidated while being isolated from the underlying global hardware, contrarily to a regular computing stack, which only supports a single OS. Alternatively, a hypervisor can be installed on top of an OS (type-2 hypervisors). In this scenario, the operating system is in charge of controlling the hardware, and the hypervisor is viewed as just another application, allowing many Virtual Machines (VMs) to operate on top of it. (a) Regular Computing Stack (b) Virtualized Computing Stack Figure 2.1: System stack with (b) and without (a) virtualization. A type-1 hypervisor follows three certain characteristics: (i) essentially identical , (ii) efficient , and (iii) resource control . [40]: •Essentially identical - A hypervisor complies with the essential identical property when all applications running under it, behave exactly as if it were operating on the original machine; •Efficient - A hypervisor complies with the efficient property when the current processor executes a significant portion of the virtual instructions directly into VMs, without software interference from the VMM; •Resource control - A hypervisor complies with the resource control property when it controls the VMs and their entire resources; In virtualized architectures, there is the requirement for a processor that supports multiple privilege levels, where typically OSs run at a high privilege levels and applications run at a low privilege levels. Vertical transitions between the privilege levels occur through synchronous events called traps [18], in which they Chapter 2. Background and Related Work 6 manage the control of the processor mode. Depending on the current machine context, the execution of architecture instructions has different classifications concerning classical virtualization [40, 41, 42]: •Privileged instructions: instructions that are restricted for higher privileged levels, occurring trap when executed under low privileged levels then the delegated; •Sensitive instructions: critical instructions capable of controling resources at a machine privileged level; •Innocuous instructions: instructions that are not classified privileged or sensitive. Typically those whose not depend on a specific context processor; Due to the resource control property, a VMM takes control of critical instructions, i.e., it control of all sensitive instructions (instructions required for proper virtualization) that are mutually considered privileged instructions (instructions susceptible to trap). As a result, VMM must have a higher privilege level than their guests. In virtualization, the execution context can switch to a higher privileged mode following two main virtualization techniques: •Fullvirtualization: In this approach, VMs have no notion that they are running in a virtualized environment. The fundamental advantage of this method is its portability, as it allows the execution of an unmodified OS. The hypervisor completely simulates the underlying hardware environments by employing two-stage address translation over sensitive instructions and allowing direct execution of non-sensitive instructions. Multiple hypervisors such as KVM [38], XEN [43], HYPER-V [44], between others explore these virtualization techniques; •Paravirtualization: In this approach, VMs are aware that they are running in a virtualized environment. This technique is less portable than fullvirtualization since the guest OS requires modifications. However, since OSs rely on hypercalls to execute sensitive instructions, they show better performance. Specific versions of Xen use this approach [45]; 2.1.3 Trap-and-emulate virtualization technique As already mentioned, using virtualization, the VMs operates at lower privilege levels with a restricted behavior controlled by VMM (over critical resources), i.e., VMM controls all sensitive or privileged instructions’ execution by VMs. Executing these instructions at a lower privilege level will make the system trap, and VMM will perform the trap-and-emulate technique [42]. This technique consists of taking the necessary actions at the VMM level, when sensitive or privileged instructions are executed on the guests located at low privileges levels. Figure 2.2 depicts the system behavior when a trap occurs. First, the execution the Guest-OS tries to execute a sensitive/privileged instructions. Then, the VMM traps the event and emulates the expected behavior by protecting the system integrity. To complete, the VMM returns the control to the Guest-OS, switching the context to a lower privileged level. Chapter 2. Background and Related Work 7 M-MODE (OpenSBI) S-MODE (kernel) 12 3 Trap return Execution time line Emulation process Trap entry Figure 2.2: Trap-and-emulate steps flow. It’s important to highlight the high overhead that these transitions bring to the performance evaluation of the system [46] [47]. These transitions between the hypervisor and its guests bring latency problems, forcing hypervisor designers to implement strategies to reduce the frequency and cost of these transitions as much as possible [19] [48]. Latency of transactions When a trap occurs, multiple steps are performed: (i) the CPU collects and saves its prior state; (ii) jumps to a hypervisor privileged layer; and then (iii) restores the state before trap. All process impose direct costs on the system, requiring CPUs to switch consequently between multiple modes and privilege levels. Furthermore, the cache gets filled with instructions and data belonging to the different execution layers, resulting in a phenomenon known as cache pollution [49]. One way of reducing the frequency of traps is to direct mapping the device memories to guests. This method is implemented by the Xen hypervisor when producing a privileged guest to whom the device drivers are allocated [48]. Additionally, this process mitigates the risk of device driver failure/misbehavior and tackles issues with I/O device dependability, maintainability, and management [49]. 2.1.4 Memory Virtualization Nowadays, Arm satisfies memory virtualization requirements. Its design includes a hypervisor mode to manage the physical hardware while ensuring the security of guests and adds a virtualization extension (Arm VE) [50, 51] for VM support. The hypervisor mode enables the simplest feasible design of hypervisors and chooses the level layer handling of each event. For example, when software executes in the hypervisor mode, it can configure whether to perform memory access at the hypervisor privilege level or the guest privilege level. Chapter 2. Background and Related Work 8 Arm enables memory translation via virtualization extensions, either through software support, using shadow tables, or through hardware support, by employing a two-stage address translation and an MMU. This latter consists of two stages, wherein the first stage, the OS performs translations from VAs to GPAs, and in the second stage, the hypervisor performs translation of GPAs into a PAs. The shadow tables technique [47] does not use the MMU and the hypervisor, which is responsible for handling the Translation Lookaside Buffer (TLB), directly mapping the VA to a PA (eliminating one level of indirection). With two-stage translation, the hypervisor no longer has to maintain shadow tables in memory, leaving address translation to MMU. This results in considerable performance advantages since there is a significant reduction in the VM exit frequency and performance overall [46]. 2.2 RISC-V The RISC-V is an open standard ISA based on the principles of the Reduced Instruction Set Computer (RISC) [14]. It was created in 2010 in response to the need for a readily expandable architecture, facing market commercial designs, extremely complicated and fraught with legal issues [14]. Being classified as an open ISA, it can be freely used, enabling companies and individuals to implement their own RISC-V core without the need of paying any royalties. Due to its widespread expansion, it has been used to solve embedded systems issues in the academic and industry [20, 52, 53]. 2.2.1 RISC-V specifications The RISC-V ISA is made of two specifications: unprivileged [54] and privileged specifications [18]. The unprivileged specification covers the implementations with non-privileged base instructions. In RISC-V, unprivileged instructions are typically executed in the user mode (U-mode), involving standard extensions described as I (Integer), M (Integer Multiplication and Division), A (Atomic), F (Single-Precision Floating-Point), D (Double-Precision Floating Point), G (General Purpose, I+M+A+F+D), and C (Compressed Instructions), where each, defines the instruction set on a given implementation. On the other hand, the privileged specification includes privileged instructions dedicated for privileged modes, including the machine mode (M-mode), which executes the most trusted code, and the supervisor mode (S-mode), which supports OSs such as FreeBSD, Linux, and Windows. 2.2.2 Privileged Modes The privilege level dictates the number of features that the current hart can access. The RISC-V architecture supports three distinct privilege levels [18]: (i) the M-mode, (ii) the S-mode, and (iii) the U- mode. The highest privilege level and only mandatory is the M-mode, commonly intended for firmware devices while acting directly in the hardware. Typically, firmware executes in M-mode, operating only with PAs, and not using virtual address translation. Other privileged levels are the S and U-mode, where both Chapter 2. Background and Related Work 9 protect Supervisor Execution Environment (SEE) from OS, and OS from their applications, respectively [17, 18]. Typically, the S-mode privileged level is used to run OSs and provides VM capabilities through a dedicated MMU, and the U-mode for conventional applications. In summary, privilege levels exist to protect the different components of the software stack. Each privileged level enables the execution of specific extension-related instructions, and in an attempt to perform operations not allowed by the current privilege mode, the system will cause an exception. To enable efficient hosting of guest OS on top of a type-1 or type-2 hypervisors, the S-mode level extends to the hypervisor-extended supervisor mode (HS-mode) [18]. The HS-mode behaves similarly to S-mode but with supplementary instructions and Control and Status Register (CSR)s that regulate the twostage address translation, allowing the guest OS to host in virtual S-mode (VS-mode) [21]. As mentioned in Chapter 2.1.4, the two-stage address translation process splits into two stages: (i) GVA to GPA through OS; and (ii) the GPA to PA through the hypervisor. One of the main goals of this dissertation is to avoid the HS-mode extension by only use M, S and U-mode levels, and consequently perform the address translation in only one stage. As a result of this para-virtualization approach, the partitions are aware that they are running in a physical memory and its interaction with the host is optimized to avoid excessive trapping. 2.2.3 Software Stack Terminology Due to this dissertation’s privilege levels RISC-V architecture handles a stack terminology, with each layer presenting a system running either in U, S or M-mode. A system operating at a higher privilege level must have more permissions than a system operating at a lower privilege level. As a result, they must be able to access their functionality without the need for a communication interface. However, the contrary is not applicable; for a lower privilege level to interact with a higher privilege level, it requires a communication binary interface. Figure 2.3 illustrates a stack model that boils down to an Computer Application (APP) running on top of an execution environment. To communicate with the Aplication Execution Environment (AEE), APP uses an Aplication Binary Interface (ABI), which provides a set of user-level ISA and where is normally used to abstract the details of the AEE from the APP itself. Figure 2.3: Stack model of an Application Execution Environment. In comparison to Figure 2.3, Figure 2.4 depicts a traditional system stack capable of operating numerous APPs reporting a more complex stack model. It incorporates the previously described paradigm, in which the APPs communicate with AEE via ABI and add an OS together with an SEE, which composes the AEE. As a result, the OS manages its APPs and services for secure system execution; the APPs interact with the OS via ABI, and the OS communicates with its SEE via SBI. The SEE can be assumed as a Chapter 2. Background and Related Work 10 hypervisor provider on a high-end server or even a thin layer of software capable of providing to the OSs, all run-time services after boot. Figure 2.4: Stack model of a Supervisor Execution Environment. 2.2.4 RISC-V CSRs CSRs in the RISC-V architecture take control of execution mode behavior and trap handling, composing the majority of the privileged specification [18]. To modify the state of CSRs, it is required to leverage pseudo-instructions like Atomic Read and Set Bits in CSR (CSRRS), Atomic Read and Clear Bits in CSR (CSRRC), and Atomic Read/Write CSR (CSRRW) [54]. Harts observe their own CSRs, producing illegal instructions when trying to execute non-associated privilege mode instructions. As this dissertation only touches on M, S, or U-mode privileged levels, below, there is a description of some RISC-V architecture CSRs crucial for its development. The letter X represents the privileged mode, either M or S. •Xstatus (Status Register): The Xstatus register contains the most important information about the execution context. It enables/disables global interrupts; It stores context execution prior to the trap; It enables virtual-memory management operations; •Xie/Xip (Interrupt Enable/Interrupt Pending Register): The Xie and Xip control software, timer, and external interrupts independently. Bits in the Xie register enable/disable the interrupts in the associated privileged layer. In the interrupt trigger event, it is natural that one of the present bits in the Xip register change to set, holding the interrupt until being claimed by an interrupt routine; •Xcause (Xcause Register): Each trap sent by the system, whether synchronous or asynchronous, may be decoded as an interrupt or exception respectively, as seen in Table 2.1 (Adapted from [18]). The CSR xcause register is a register that indicates the cause of the trap event, with each bit allocated to a different cause; •mideleg/medeleg (machine trap delegation registers): By default, M-mode is used to handle all traps regardless of the privilege level. The medeleg and mideleg CSRs enable the delegation of exceptions and interrupts to lower privilege levels, respectively. To force an interrupt/exception to Chapter 2. Background and Related Work 11 Table 2.1: Machine cause register ( mcause ) values after trap. Interrupt Exception Code Description 1 0 Reserved 1 1 Supervisor software interrupt 1 2 Reserved 1 3 Machine software interrupt 1 4 Reserved 1 5 Supervisor timer interrupt 1 6 Reserved 1 7 Machine timer interrupt 1 8 Reserved 1 9 Supervisor external interrupt 1 10 Reserved 1 11 Machine external interrupt 1 12–15 Reserved 1 16 Designated for platform use 0 0 Instruction address misaligned 0 1 Instruction access fault 0 2 Illegal instruction 0 3 Breakpoint 0 4 Load address misaligned 0 5 Load access fault 0 6 Store/AMO address misaligned 0 7 Store/AMO access fault 0 8 Environment call from U-mode 0 9 Environment call from S-mode 0 10 Reserved 0 11 Environment call from M-mode 0 12 Instruction page fault 0 13 Load page fault 0 14 Reserved 0 15 Store/AMO page fault 0 16–23 Reserved 0 24–31 Designated for custom use 0 32–47 Reserved 0 48–63 Designated for custom use 0 64 Reserved Chapter 2. Background and Related Work 18 •Establish communication between different privilege layers through the runtime services in M-mode. Ensuring security and protection against sensitive instructions; •Open-Source; •Support the platform adaption for several multiple RISC-V platforms. Providing reusable common code of different RISC-V platforms, aiming to assist a secure boot; 2.3.1 OpenSBI as a Runtime stage Before any operating system can start, a boot flow with numerous boot stages must commit a set of system requirements. Any embedded system will always have a multistage boot flow [60], with each stage devoted to a specific set of tasks. A typical boot sequence is represented in Figure 2.7, where the first stage is referred to as the (i) Zero-Stage Boot Loader (ZSBL) or the ROM since it operates on the ROM. It initializes clocks, manages system power, and resets the system. After the voltages have steadied and the hardware is ready to begin booting, the processor initializes the hardware buses and peripherals. It is the initial code run by the CPU, and it embeds all of the logic required for the following boot stage through external peripherals such as an embedded Multi-Media Card (eMMC), microSD card, or even via specialized protocols on a bus for data transfer (like USB, UART, and others). Nextly has presented the (ii) LOADER , commonly known as the First-Stage Boot Loader (FSBL). It initializes the DDRs and loads the subsequent stages, including the RUNTIME stage. Though the FSBL does not need regular updates, any change may result in unexpected behavior and could jeopardize the board. The (iii) RUNTIME stage executes all safe boot flow components on top of the on-chip Static Random Access Memory (SRAM), and it is assumed to be the second stage boot loader. Software layers such as U-Boot 5, and OpenSBI may commit to this, as well as being responsible to provides runtime services to the OSs following system boot. Figure 2.7: Common Boot Flow to RISC-V Boot Flow. 5The universal boot loader: http://www.denx.de/wiki/U-Boot Chapter 2. Background and Related Work 19 Runtime services: It translates as runtime services 6to all the communication services that lower privilege layers do to higher privilege layers. Typically, they are carried out in S-mode using the previously stated ECall instructions through an SBI layer. The penultimate boot stage contains the (iv) BOOTLOADER , which loads kernel images from media like SD cards or networks. Grub [61] is an example of a software bootloader capable of loading Linux kernel images from Multi-Media Card (MMC) devices. The last step introduces the (v) OS, which typically operates in S-mode and handles all non-privileged applications. Regarding all boot stages, this dissertation will focus on the RUNTIME boot stage, where OpenSBI operates in M-mode and provide services to lower privilege levels, as seen in Figure 2.7, where it supports both U-Boot and Linux OS running in S-mode. 2.3.2 SBI Specifications In RISC-V, (i) to establish inter privileged layers communication, (ii) make the S-mode privilege level transferable across many implementations, and (iii) to provide run-time services, M and S-mode must comprehend SBI specifications 7[62]. The OpenSBI contains additional code to answer the ECall instructions from S-mode, providing run-time services and complying with the SBI specifications. These are composed of extensions and functions, which are binary encoded by registers a6and a7. Each function value, the SBI Funtion ID (FID), is represented by register a6for a particular extension value in a7, the SBI Extension ID (EID), indicating that each extension has several functions. S-MODE M-MODE mret ecall SBI interface Figure 2.8: SBI interface between privileged layers. When S-mode software executes an ECall, a transition from a lower privilege level to a higher privilege level occurs and encoded information by registers EIDs and FIDs reaches the implementation of these SBI services. As seen in Figure 2.8, each time the processor executes an ECall instruction in S-mode, the machine’s state transits from S to M-mode. On the other hand, after performing a run-time service, the machine’s state is transferred from M-mode to S-mode through mret instruction. In the case of an unsuccessful return, the system follows the calling convention return type, where the return error goes to register a1, and the associated value goes to a0register, accordingly to Table 2.2. As an example case, the executing of an ECall instruction that does not correctly encode the SBI extension through register a7, the value −2is returned, corresponding to the error SBI_ERR_NOT_SUPPORTED . 6OpenSBI Bootflow: https://www.youtube.com/watch?v=sPjtvqfGjnY&t=2364s 7RISC-V SBI Specifications: https://github.com/riscv-non-isa/riscv-sbi-do Chapter 2. Background and Related Work 20 Table 2.2: SBI specifications: associated returned values. Error Type Value SBI_SUCCESS 0 SBI_ERR_FAILED -1 SBI_ERR_NOT_SUPPORTED -2 SBI_ERR_INVALID_PARAM -3 SBI_ERR_DENIED -4 SBI_ERR_INVALID_ADDRESS -5 SBI_ERR_ALREADY_AVAILABLE -6 SBI_ERR_ALREADY_STARTED -7 SBI_ERR_ALREADY_STOPPED -8 OpenSBI adheres to several functionalities presented in several extensions as: •Base extension: Since base extensions do not report errors, any RISC-V implementation can perform base extensions. They examine information about the implemented extensions, and it can identify by the EID 0x10; •Legacy extension: Legacy extensions are represented by EIDs between 0x0to 0xf. This extension provides significant support for S-mode implementations like (i) updating the timer values through the stime_value parameter (since timer register handling is only possible in M-mode [19]), providing (ii) access to the serial port connected to the OpenSBI, allowing the reception and sending of characters through the SBI ECall instructions, providing (iii) IPI’s functionalities, used for example in FreeRTOS environments when tasks yield and need signaling current hart for task scheduling [63], providing (iv) synchronization in the execution of instructions by the different harts through the FENCE instructions, and finally, allowing (v) the system shut down through a simple system call; •Hart State Management Extension: A current platform hart assumes a state that reveals its activity. A hart state can be characterized as started , which initiates normal execution, stopped , which suspends execution in S and U-mode, or suspended , which consumes less power [62]. When hart is transitioning from the stopped to the started state, it may enter the start pending state. In contrast, the hart can enter the stop pending state when it is transitioning from the started to the stopped state. When its transition from started to the suspended state, it assumes the suspended pending state, and when it transitions from suspended to started , it assumes the resume pending intermediate state. This module adds a collection of functions to the S-mode environment for controlling the state of the harts and their transitions. This extension provides functions for initializing, suspending, and terminating the execution of harts, as well as their state. Their return value may indicate success, an invalid argument, an invalid address, that the resource is already available, that the resource has failed, or that the resource is unsupported; Chapter 2. Background and Related Work 21 •System Reset Extension: In some specific cases like system failure, SBI implementation-specific reset reason, or vendor or platform-specific reset reason the system needs to execute the reset functionality to restore normal execution. The system reset extension allows the reset of both SEE and SBI implementation in M-mode. In other words, it is possible to reset the system both in OpenSBI and in S-mode; 2.3.3 Multi-platform support Due to the manufacturers describe their hardware platforms in different specifications, it forces the development of modular and adaptable software systems for any platform. One of the OpenSBI advantages is the multi RISC-V platform support through distinct configurations. Typically, these configurations are done at the boot stage and follow two methodologies, either by inserting a pre-compiled DT, which depends on a default generic platform, or selecting one of the available platform implementations through compiler arguments. Due to the higher configuration flexibility, the platform portability, and the OpenSBI domain support, this dissertation will focus only on configuration via the DT 8with a generic platform. The generic, because contrary to the other provided platforms, the OpenSBI implements the domain system via Flattened Device Tree (FDT). 2.3.4 OpenSBI domains OpenSBI includes an integrated system capable of aggregating and associating a collection of memory regions to one or more harts, denominated as OpenSBI domains 9. Therefore, the more harts available on the hardware platform, the more domains may be produced. To establish each domain memory region OpenSBI leverage the PMP unit following a non-conflicting memory region rule, i.e., do not allow domain memory regions overleaping. Over a domain, multiple domain memory regions might assign the same domain, and consequently, the more domain memory regions associated, the higher the probability of memory overlapping. The overlap of two or more memories happens when part of the memories coincide between them. In case of memory overlapping, one of the regions should be a sub-region of another, not having the same size and access flags. The domain memory regions establishment occurs thanks to the PMP unit capabilities, which establishes various non-conflicting memory regions to individual harts. The domain support is done in M-mode, during boot time, and through DT configuration. 8DT: https://www.devicetree.org/specifications/ 9OpenSBI domain system: https://github.com/riscv-software-src/opensbi/blob/master/docs/domain_support.md Chapter 2. Background and Related Work 22 2.3.5 DT Configuration The DT is a tree-like data structure that describes machine hardware, following a child-parent hierarchy with numerous configurable properties inside each child (i.e. node), as illustrated in Figure 2.9. The top node of the DT hierarchy, also termed the root node, is denoted by the character ”/” and indicates the / memregion1 tdomain #address-cells = <0x02>; #size-cells = <0x02>; compatible = "opensbi,domain,memregion"; base = <0x0 0x80100000>; order = <20>; chosen compatible = "opensbi,domain,config"; compatible = "opensbi,domain,instance"; possible-harts = <&cpu0>; regions = <&memregion1 0x7>; boot-hart = <&cpu0>; next-arg1 = <0x0 0x0>; next-addr = <0x0 0x80100000>; next-mode = <0x0>; system-reset-allowed; CPUs CPU0 reg = <0x0>; .... cpu0_intc compatible = "riscv,cpu-intc"; interrupt-controller; serial0 SOC #address-cells = <0x02>; #size-cells = <0x02>; compatible = "ns16550a"; reg = <0x00 0x20000000 0x00 0x400>; reg-io-width = <0x04>; reg-shift = <0x02>; interrupt-parent = <&plic>; interrupts = <0x5a>; PLIC compatible = "sifive,plic-1.0.0"; reg = <0x00 0xc000000 0x00 0x4000000>;riscv,maxpriority = <0x07>; riscv,ndev = <0xba>; interrupt-controller; interrupts-extended = < &cpu0_intc 11 &cpu0_intc 9>; Figure 2.9: Example of OpenSBI domain system configuration over a DT. start of the DT description. Inside this node are described their children, represented as CPUs, memories, devices, interrupt controllers, and others. As depicted in Figure 2.9, between these nodes is also the chosen node. The chosen node is not a physical device, but it is the DT location for transmitting data between firmware and the OS, such as boot parameters. Furthermore, this node is also leverage by OpenSBI to collect and support domains configurations. DT Domain Configuration Two distinct components define the OpenSBI domain configuration: the domain instances and the domain memory regions . Domain memory regions present the base of the static partitioning system Chapter 2. Background and Related Work 23 used in this dissertation. Typically, it encompasses device regions and MMIO regions. To establish them, OpenSBI (i) agglomerate all domain memory regions , (ii) sort them, and (iii) create a PMP entry for each. According to this approach, the lowest the regions, the lowest the number of the PMP entry and consequently, the higher the priority [18]. Regarding its configuration, each domain memory region must compose a base address value, a size value defined by 2order, and the compatible syntax value: ”opensbi, domain, memregion”. Table 2.3: Description of OpenSBI domain instances properties. Property Description compatible It should assume value: ”Opensbi,domain,instance”; possible-harts It defines which harts are allowed to manage this instance; All the harts described in this property are exclusively linked to this domain; regions It describes all domain memory regions assigned to this domain and their permissions; All domain memory regions described in this property follow the accesses encoded by the last four bits. The write/execute/read accesses are defined by the three least significant bits and bit fourth defines if the access is locked in M-Mode or not. This association is only possible thanks to the Locked bit mentioned in Section. boot-hart It defines which hart is responsible for booting the domain instance ; If the primary hart is connected to this domain instance , the value set in this property will be ignored, and the primary hart will take over the startup of the next booting stage. next-arg1 It sets the arg1 of the next booting stage. When DT configuration is available, its memory address is set in this property. If no DT is detected, this property is set to 0x0by default; next-addr It sets the address of the next booting stage. After the boot stage is complete, OpenSBI firmware will pass the execution context to the address located at next-addr . next-mode It defines the next boot stage privilege mode. As privileged modes for the next boot stage, S and U-Mode can be selected. If this property is not given and primary hart is not assigned to this domain, the default value 0x01 (S-Mode) is assumed; if this property is not given and primary hart is defined in this domain, the next booting stage of the primary hart is taken as the default value. system-reset-allowed It sets this domain instance can reset the system. Regarding the domain instances , they are responsible to provide each partition, associated with one or more exclusive harts and with one or more associated and non-conflicting domain memory regions , followed by their permissions. Figure 2.9 illustrates some configuration instance node properties, where tdomain has an associated hart (i.e. CPU0) with all permissions above an associated domain memory region , the memregion1 . Regarding domain instances configuration, the following Table 2.3 contains all conceivable parametrization and their meanings. Chapter 2. Background and Related Work 24 OpenSBI Root Domain Since the OpenSBI is present directly over the hardware memory, and since each domain instance should be aware of its incubated domain memories , OpenSBI should also have a domain instance reserved for its firmware storage. For this purpose, by default, at a very early boot process, OpenSBI establishes the root domain, a domain instance that does not depend on DT configuration; if there are no domain instances in DT, this domain will support OpenSBI by associating all platform harts and memories to it. OpenSBI always produces a root domain instance, even when configuration deliberates domain instance establishments. When domain instances are defined, the customization can range from none to several domain instances , as similarly occurs with the assignment of harts. OpenSBI assigns the harts to a domain instance from none to several harts. In a domain instance with no harts assigned, the root domain will support them and let them remain in it until the system is modified. DT specifications Besides this this OpenSBI domain parametrization, the DT example depicted in Figure 2.9 it describes one CPU node, one serial device node, and an external interrupt controller node, the PLIC. All of them are composed by different properties that describe the hardware in different ways. Starting by their memory position, the reg property, where its syntax is established by #address-cell and #size-cell properties, specifing how many cells are in each field of any reg child node. The reg property follows the syntax: reg =<[address1length1] [address2length2] [address3length3] ... >. In Figure 2.9, both the #address-cells and #size-cells assume the value of two, meaning that each reg property of any root child node needs two fields to represent the base location and two fields to represent its length. Taking the PLIC node as an example, its base address assumes a value of 0xc000000 and a length value of 0x40000000. Along with these properties, other device-specific interpretation properties contribute to development of this dissertation, such as compatible , interrupts , interrupt-parent , interruptcontroller , and interrupt-extended properties, where all are described over Table 2.4. 2.4 Related work There are several solutions available today that aim to provide partitioning [22, 39, 43, 64] by using the strong primitives of the RISC-V Privileged architecture. There are RISC-V solutions that make use of the hypervisor extension, while others may be implemented on RISC-V systems without hardware virtualization support. This section leverages some of these types by classifying and comparing them with this dissertation work. Chapter 2. Background and Related Work 25 Table 2.4: Description of common DT properties. Property Description compatible Used to bind devices; It is mandatory; In some cases also informs the device version; Any DT node must contain this property to be identified by the OS or the boot entity; interrupts Used to identify the interrupt value triggered by the device, ranging from one to multiple values. interrupt-parent Used to identify the interrupt controller to which the devices’ interrupts are wired; In Figure 2.9, the serial device interrupt-parent property connects with the PLIC; interrupt-controller Every node that includes this property must be able to behave as an interrupt controller. interrupt-extended Determines interrupt values triggered by the interrupt-controller and whether many or single interrupt controllers will handle them. In Figure, the PLIC will be able to trigger interrupts with the values 0x11 and 0x09. As its interrupt controller, the DT presents the cpu0_intc in CPU0 node. XVisor XVisor [64] is a type-1 RISC-V hypervisor targeting embedded systems with soft real-time requirements. It has a complete monolithic design that supports both full virtualization and para-virtualization. This hypervisor was tested in QEMU 10 with H-Extension and provides features like CPU virtualization, guest I/O emulation, background threads, para-virtualization services, and device drivers run as a single software layer with no prerequisite tool or binary file. Xen The Xen [43] is an open-source type-1 hypervisor that already gives its preliminary steps in RISC-V. It boots from a bootloader like U-boot and produces VMs denominated as domains. Between domains is the Dom0, which controls the guest OS and Hypervisor at a privileged level, and the non-privileged VMs (DomUs). Recently, the Xilin has been working at dom0-lessx 11, which enables static partitioning configuration, reduces the boot time, and implies the device assignment, to each domain. Similarly to this dissertation, domain setup is performed through DT and incorporates the domain’s boot and device assignment, which reduces hypercalls in paravirtualization processes. Siemens’ Jailhouse Siemens’ Jailhouse [65] pioneered the static partitioning hypervisor design. This design employs a minimum software layer that statically separates all platform resources and allocates them to a single VM instance using hardware-assisted virtualization technologies. Because each virtual core is statically pinned 10QEMU: https://www.qemu.org/docs/master/ 11Dom0-less: https://xenproject.org/2019/12/16/true-static-partitioning-with-xen-dom0-less/ Chapter 2. Background and Related Work 26 to a single physical CPU, no scheduler is required, and no expensive semantic services are supplied, reducing size and complexity. Although it may compromise the necessity for optimal resource use, static partitioning provides higher assurances in terms of isolation and real-time. Despite its design philosophy, Jailhouse falls short by relying on Linux to boot the system and operate, which suffers from the same other hypervisors’ limitations. This hypervisor already ports to RISC-V by leveraging hypervisor extensions. Recently, SELENE [66] made use of Linux in cooperation with the SIEMENS Jailhouse to develop an open-source software layer on RISC-V platforms while allowing functional and temporal isolation properties between different critical applications. Bao Bao [39] is a security static partitioning type-1 hypervisor that aims to facilitate the consolidation of mixed-critical systems, thus focusing on providing strong safety and security guarantees. It is composed of a thin layer of privileged software that exploits ISA virtualization extensions to partition the hardware. It includes hardware-based methods such as cache coloring that help prevent interference between numerous guests. Bao is mainly developed for Armv8 architecture. However, it has been ported to RISC-V on QEMU and to RISC-V cores with hardware virtualization support (e.g., Rocket, CVA6). [19]. RVirt RVirt 12 is an S-mode trap-and-emulate RISC-V hypervisor designed on QEMU and partially supports HiFive Unleashed. It is developed in Rust because it is a comfortable language and enables for direct targeting of bare-metal platforms. It has the problem of including a large amount of dangerous code during VM startup and entry/exit. This dissertation, as RVirt, is not using virtualization extensions and also use the virtualization trap-and-emulate approach. VOSySmonitoRV VOSySmonitoRV [67] presents as a RISC-V solution for mixed-critical systems allowing the co-execution of two or more OSs isolated from each other without implementing hypervisor extensions. It operates in M- mode meaning that it is responsible for managing the PMP entries to establish a security boundary between partitions. Similar to this dissertation, VOSySmonitoRV applies a similar static partitioning system, with an equal focus on security and fault-containment without H-extensions. The work proposed in this dissertation distinguishes VOSySmonitorRV by automatically partitioning the interrupt controller component among multiple harts during the device assignment process and leveraging the trap-and-emulation technique. Moreover, since this dissertation was developed over OpenSBI it carries its RISC-V platform modularity advantages and a static partitioning configuration through the DT. 12RISC-V hypervisor written in Rust: <https://github.com/mit-pdos/RVirt Chapter 2. Background and Related Work 27 Keystone Keystone [22] is presented as a RISC-V open framework for Trusted execution environment (TEE)s. It utilizes a security monitor to enforce TEE guarantees and uses the PMP feature of RISC-V to isolate individual enclaves. Although the Keystone seems to be a trusted hypervisor, it is just considered a reference monitor. It does not implement or execute resource management, virtualization, or scheduling [22], and it simply verifies if its untrusted OS and enclaves are processing shared resources correctly. Keystone additionally includes a shared memory method for communication between the supervisor mode runtime and the security monitor. Similarly, this dissertation utilizes the PMP approach to create isolated static partitioning systems on RISC-V. However, instead of keystone, OpenSBI is used as a secure monitor. Diosix Diosix 13 is presented as a work in progress of a lightweight, fast, and secure multiprocessor baremetal hypervisor written in Rust for 64-bit RISC-V computers. It leverages the PMP unit to achieve isolation between capsules (domains). Just as in OpenSBI, it parses DT for capsules configuration and to provide information about the available hardware, it provides an SBI syscall interface to communicate between system services. seL4 The seL4 [68] is an open-source, high-performance, microkernel and hypervisor with the most comprehensive mathematical proofs of correctness and security. It is a microkernel and not an OS because of its minimal amount of privileged code. It provides control communication between different system components by following its principle of isolating applications from each other and executing them on a safe and trusted platform. As a hypervisor, it supports virtual machines by leveraging hypervisor extensions. However, recent implementations [69, 70] show that seL4 can avoid virtualization extensions while operating as a secure monitor at the M-mode level and establish boundaries between trusted and untrusted worlds through the PMP unit. 13Diosix: https://github.com/diodesign/diosix Chapter 3. HSP-V: Design 34 to access the PLIC structure, the system will behave in one of two unique ways. It will directly access the interrupt controller space when PMP entry conditions are favorable (when accessing correspondent non-critical PLIC regions), or it will trap and request access to the higher privileged layer (when accessing critical PLIC regions). As already presented in 2.1.3, the trap-and-emulate mechanism emerges as a virtualization technique capable of solving isolation problems. In this dissertation, this technique will be adopted to isolate critical PLIC regions. When domains try to access the suppressed regions, i.e., the critical PLIC regions, the system will trap through synchronous events, and then, the execution emulates or ignores the accesses attempts by the domain instances . To emulate all critical PLIC accesses, this dissertation will enhance the OpenSBI trap handler space, at M-mode, by integrating the decoding and emulation of any access to the critical PLIC registers. Emulation of Critical PLIC Acesses Figure 3.4 depicts the trap-and-emulate stages. First, (1) the system executes a load/store instruction access over a critical PLIC region (suppressed by the PMP unit). As a result of a PMP entry violation, (2) a synchronous event occurs ( trap_entry ), and the execution state change from S-Mode to M-mode. Due to the mtvec establishment, the execution jumps to the OpenSBI trap handler, which preserves the generic registers, the stack pointer, the mepc , and the mstatus . Next, (3) the exception is decoded and verified if it treats as a load-access fault (i.e. mcause with a value of five) or as a store-access fault ( mcause with a value of seven). Following, OpenSBI performs the emulation of the critical PLIC accesses. This approach can either emulate the access, if validated emulation conditions (detailed in Section 4.4), or can ignore the access, in case of a malicious domain access attempts. For example, when a malicious domain tries to access a critical PLIC register assigned to an adjacent domain instance , the OpenSBI just ignores the access and maintains the system integrity. To conclude this phase, the OpenSBI restore the preserved register in point (2) and, (4) the system switch from M to S-mode using the mret and mstatus CSRs ( trap_exit ). In the last trap-and-emulate stage (5), the machine resumes the execution to the point that was left. The trap-and-emulate technique enforces the inter-domain isolation in OpenSBI domain systems by supporting the control of PLIC accesses. Depending on the critical PLIC registers, the OpenSBI emulates the accesses differently. The emulation of write/read operations over Priority registers depends on the mtval value address, which specify the address that the domain is attempting to access, and the possibledevices property values, which specify the possible source Priority registers that the domain is allowed to access. In case of mtval value match with one of the possible source Priority registers, OpenSBI performs the emulation, in the opposite scenario, the OpenSBI ignores the access. Regarding the Pending and Enable registers, the process is similar. The difference is that the possible-devices property indicates the possible bits of these registers that the domain is allowed to access. This approach allows the domain to Chapter 3. HSP-V: Design 35 M-MODE (OpenSBI) S-MODE (kernel) 1 2 3 4 5 Trap exit Execution time line Emulate PLIC accesss Trap entry Figure 3.4: Trap-and-emulate technique behavior to emulate critical PLIC accesses. write/read the masked bits of possible-devices in Enable / Pending registers. The information details about this kind of filter are explained in Section 4.4. 3.5 MCSs with enhanced OpenSBI Domain System This section leverages analysis of the proposed static partitioning system through the enhancement of the OpenSBI. The design in Figure 3.5 configures two domains (e.g. Domain1 and Domain2 ) using a DT configuration. It starts by deliberately allocating one hart and one domain memory region (e.g. Application1 and Application2 ) for each domain instance . Furthermore, OpenSBI automatically assigns domain memory regions , i.e., the MMIO device regions of devices defined in the possible-devices property and the respective non-critical PLIC regions. With assignment of devices in property possible-devices, OpenSBI assigns the device with interrupt ID 10 to Domain1 and the device with interrupt ID 35 to Domain2 . Regarding inter-domain visibility, the Domain1 and Domain2 do not have access to critical PLIC registers and to domain memory regions of each other. The Domain1 1have visibility over (i) their configured domain memory regions (i.e. the Application1); (ii) over regions of the devices presented in possibledevices configuration property (i.e. the memory of the device with ID 10); and (iii) over their assigned non-critical PLIC regions (i.e. the Claim/Complete and Threshold memories). The isolation is established when the Domain1 has not access to Domain2 memories, as well the opposite. In this scenario, the system will trap every time that one of the domain instances tries to access adjacent domain memory regions , i.e., every time the execution provokes a Load/Store access fault by an attentive to execute an instruction 1The visibility case repeats for Domain2. Domain2 has visibility over (i) Application2, (ii) over regions of the devices presented in possible-devices configuration property, i.e., the memory of the device with ID 35, and (iii) over their assigned non-critical PLIC regions. Chapter 3. HSP-V: Design 36 DOMAIN 1 dtb. Device id=10 Complete Threshold Mem-regions DOMAIN 2 Device id=35 Complete Threshold Mem-regions Domain 2 visibility Domain 1 visibility Application1 Application2 x Priority Pending Enable Claim/Complete Threshold Claim/Complete Threshold Application1 Application2 ID=10 ID=10 ID=35ID=35 x Priority Pending Enable Claim/Complete Threshold Claim/Complete Threshold Application1 Application2 Figure 3.5: Automatic domain configuration by integrating all proposed solutions. that access a suppressed PMP entry. Furthermore, besides these automated memory assign techniques improve the inter-domain isolation, it also offers an improvement in OpenSBI correct configuration. At this point, OpenSBI will safeguard the critical PLIC register accesses by just do not assign them to domains. With this approach, when S or U-mode environments try to access any critical PLIC registers, the machine will trigger synchronous events, i.e., the exceptions load/store access faults. Any attempt to execute a load/store operation over the critical PLIC register will force the execution to change the machine state from the S or U-mode to M-mode (where OpenSBI trap handler operates). At this privileged level is performed the trap-and-emulate process to protect each critical PLIC register. As mentioned in Section 3.4, the OpenSBI trap handler will emulate the accesses by performing them or ignoring them. Several CSRs and the information collected in the possible-devices property will support the validation of this access attempt. After the emulation process, the execution return to the point where it was before the trap. According to this analysis, the proposed OpenSBI enhancement is enough to improve the inter-domain isolation. Including a flexible and straightforward configuration through the DT, an automatic MMIO device assignment mechanism, an automatic non-critical PLIC partitioning, and a trap-and-emulate technique to emulate critical PLIC registers. 4. HSP-V: Implementation In Chapter 3, we have proposed a solution through the OpenSBI enhancement to achieve a RISC-V static partitioning system across different platforms. This chapter aims to describe its implementation: (i) the DT binding enhancement; (ii) automatic device MMIO regions assignment; (iii) automatic non-critical PLIC partitioning; and the trap-and-emulate technique. 4.1 Device Tree Binding Two approaches establish the OpenSBI configuration (Chapter 2.3.5); however, the previous Chapter mention that not all configuration approaches generate robust and isolated systems. Due to its flexibility, its easy platform adaptation, and its OpenSBI domain system feature, this Chapter starts by exploring the DT configuration. The goal of this implementation stage is to add one more configuration property to the DT domain system configuration by providing to OpenSBI an association mechanism between domains and devices, not precluding the external interrupt controller space of devices. OpenSBI Domains Parameterization According to the parameterization analysis outlined in Chapter 2.3.5, there is no configuration property to assign devices to domain instances . This Chapter starts by developing a method to link devices with domain instances by adding a property to the OpenSBI domain configuration, i.e., the possible-devices . The goal is to ensure that the assigned devices are inaccessible to adjacent domain instances , enforcing security and isolation to the system. To develop this process, this implementation employ the OpenSBI functionalities following the OpenSBI code structure, as well as its nomenclature. This implementation start locating the code where the OpenSBI binds domain instances properties, in other words, the place where OpenSBI will be enhanced with a new binding process. Due to possibledevices being applied over each domain instance , make sense add its binding process during the the DT bind of domain instances properties. 37 Chapter 4. HSP-V: Implementation 38 Binding of ”possible-devices” Property The pseudocode described in Algorithm 1 analyzes how the additional attribute was bound. Initially, a vector of domains was established with each entry defining an independent domain instance , the implemented_domains . Each entry of this vector contains a domain instance property, which includes the new DT configuration feature, the possible-devices property. Next, was established the vector implemented_devices which will support this algorithm to prevent multiple device assignation into the same domain instance . Last, but not least, was established a vector of Devices , which will contain the DT location nodes of devices defined in possible-devices property. Algorithm 1 Interpretation of DT’s properties Require: implemented_domains : Vector of already implemented domains implemented_devices : Vector of already implemented devices Devices : Vector of device locations in DT for dom ∈implemented_domains do implemented_devices ←get_implemented_devices(dom) end for Devices ←get_properties(”possible-devices”) for dev_num ∈Devices do while ¬last_dev_id do dev_id, dev_id_size ←fdt_parse_device_id(dev_num) if device_is_implemented(dev_id, implemented_devices)then id_already_assigned ←true end if if ¬(id_already_assigned)then set_device_to_domain(dev_id, dev_mask) else report error end if if dev_id =dev_id_size then last_dev_id ←true end if end while end for To start, the Algorithm 1 collects already implemented_devices defined in adjacent domain instances Chapter 4. HSP-V: Implementation 39 through get_implemented_devices function. Essentially, the execution goes through all already implemented domain instances and collect the possible-devices property of each of them. Posteriorly, the function returns all device IDs to implemented_devices vector, where each bit represents an interrupt ID or IDs of each already implemented device. Next, to bind the possible-devices property of the domain instance under analysis, this implementation use the function get_properties . This function binds the new property, i.e., the possible-devices , by applying a parser in DT, and returns DT location nodes of each defined device to the variable Devices . In other words, each Devices position contains a location of a device in the DT. After collecting the device nodes’ locations, OpenSBI goes through each Devices node through the variable dev_num and collects their IDs. As HSP-V enhances pretend to protect the PLIC regions associated with external device interrupts, it is necessary to collect each interrupt ID triggered by each dev_num device, and associate it exclusively with a domain instance . The property interrupts inside each device node contains its device interrupt ID or IDs. To collect either each Device ID and the number of IDs in a device node, this algorithm executes the function fdt_parse_device_id , returning the variables dev_id and dev_id_size , respectively. While not last ID in device dev_num , this algorithm connects each of them to the domain instances if not assigned in implemented_devices . Otherwise, to guarantee inter-domain isolation and avoid misconfigurations, the devices in possible-devices must pass through a mechanism that avoids multiple domain instance assignation. The goal is to ensure that each device is assigned to one exclusive domain. If the dev_num is already defined in other domain instances , an error will be reported by OpenSBI, informing that the user is configuring the same device in different domains. In a valid scenario, where the dev_id is not between the possible-devices of adjacent domain instances , each device is linked to the domain instance under analysis through the function set_device_to_domain , where each bit of a variable dev_mask will correspond to the interrupt ID or IDs of devices in possible-devices . For example, if the dev_mask variable specifies the value two, it means that the domain has permission to access the interrupt with ID one (bit zero corresponds to interrupt ID zero). The dev_mask of each domain instance will support either in the access validation by the trap-and-emulate technique or in the automatic device MMIO regions assignment. Implemented IDs From Adjacent Domain Instances As already mentioned, to ensure that devices already linked and not repeatedly assigned in different domain instances , the function get_implemented_devices runs through all the domains to collect each of implemented_devices , as shown in Algorithm 2. For each domain, the value of the variable possibledevices is analyzed and collected bit by bit, filling the variable implemented_devices. At the end of this process, the variable implemented_devices will contain all device IDs previously linked to other domains. After implementing the illustrated functions, it is possible to extend the DT configuration with the possible-devices property to assign device associated interrupts to domain instances . As already mentioned in the previous Section 3.2, Figure 3.2 depicts a configuration example, in which uart and i2c Chapter 4. HSP-V: Implementation 40 Algorithm 2 get_implemented_devices function for dom ∈implemented_domains do for bit ∈max_device_bits do bit_value ←test_bit(bit, dom.possible_devices) implemented_devices ←(bit_value ≪bit) end for end for device nodes are connected to the domain instance tdomain . In this scenario, tdomain has access to the PLIC information about interrupts of uart and i2c devices, i.e., interrupt IDs 0xaand 0xbrespectively. During get_implemented_devices function execution, during boot time, the implemented_devices will contain the value 0xC00 (with bits 11 and 12 active). Device ID Parsing The following subsections illustrate in detail each function referenced in the previous Algorithm 1. The function fdt_parse_device_id presented in Algorithm 3 returns the device interrupt ID or IDs, as well the number of IDs in the device dev_num . To begin, it determines if the evaluated device contains the interrupt controller PLIC as an interrupt-parent property. To check this condition, the value of this property is Algorithm 3 fdt_parse_device_id function Require: str1: String to compare with value ”sifive,plic1.0.0” str2: String to compare with value ”sifive,fu540c000plic” str3: String to compare with value ”sifive,plic0” implemented_domains : Vector of domains already implemented device_offset: Offset to localize node in DT id_offset : Offset value of multiple IDs into a device interrupt_parent_phandle ←get_phandle(device_offset, ”interrupt-parent”) interrupt_parent_offset ←get_offset_by_phandle(interrupt_parent_phandle) property_value ←get_property(interrupt_parent_offset, ”compatible”) if property_value =str1∨property_value =str2∨property_value =str3then val, number_of_ids ←get_property(device_offset, ”interrupts”) dev_id ←val[id_offset] return val, number_of_ids else return error end if Chapter 4. HSP-V: Implementation 41 collected, and then followed by a check to verify if it contains one of the available PLIC compatible property (sifive,plic1.0.0”, ”sifive,fu540c000plic” and ”riscv,plic0”). In a negative case, an error is reported by the OpenSBI informing that the interrupt parent is not the PLIC and consequently, the device is not assigned to the domain instance . In the positive case, it returns the associated interrupt ID in the device node and the number of IDs. 4.2 Automatic Integration of Device MMIO Regions With possible-devices configuration property, each domain can attach multiple external interrupt device IDs to it, but it must also include the device MMIO regions associated with these IDs. Otherwise, the execution tends to trap each time the domain tries to access the MMIO region of these devices. A mechanism for linking these regions to domain instances was developed, streamlining the partitioning process and decreasing the possibility of user configuration errors. The purpose is to automatically add domain memory regions associated with devices in possible-devices property. The implementation is done by reusing a few lines of code from the OpenSBI source code at domain instance creation time. After binding the possible-devices property from DT, OpenSBI executes the function create_device_memregion outlined in Algorithm 4, which creates domain memory regions associated with the values of this property. This procedure starts by iterating and sorting all device offsets of Devices , a vector previously collected in Algorithm 1. Next, to avoid the creation of multiple identical MMIO regions, the OpenSBI proceeds to a comparison of each vector entry to the succeeding vector position, skipping the equal Devices values. The OpenSBI determines the MMIO base address region, the size, and the necessary flags for the PMP entry creation. Finally, to sanitize domain instances with these new regions, Algorithm 4 create_device_memregion function Require: Devices: Vector of device locations in DT Devices ←sort_vector(Devices) for dev ∈Devices do if Devices[dev]=Devices[dev + 1] then dev_base_addr, size ←parse_addr_and_size_property(dev) order ←log_base_two_of(size) flags ←(Read_access and W rite_access) add_region_to_domain_regions(dev_base_addr, order, flags) increment_count_regions end if end for Chapter 4. HSP-V: Implementation 42 OpenSBI adds the MMIO region to the domain memory regions and increases the count_regions variable. When OpenSBI collects all domain instances with all domain memory regions , it sanitizes each of them, checking if there is anything wrong or misconfigured. It checks if any of the domain memory regions has a null range; if any of them has an invalid base address/order/flags; and even the presence of the firmware region. 4.3 Automatic Integration of PLIC Regions Over Partitions To partition PLIC and rectify the problem in Chapter 3.1, this implementation separate critical and non-critical PLIC regions. Due to the reasons mentioned in chapter 3.3.1, the non-critical PLIC regions are the Claim / Complete and Threshold registers; and the critical PLIC regions are the Priority , Pending , and Enable registers. This section demonstrates how we enhance OpenSBI to automatically isolate the non-critical PLIC regions between different domains. To protect them, this implementation adopt the direct memory assignment of the non-critical PLIC regions to domains by establishing a PMP entry for each region. To follow the PMP entry creation requirements, i.e., the base address, size, and flags definition, was implemented the get_non_critical_plic_regions function, represented by Algorithm 5. This function starts to collect the PLIC base address from the DT by parsing and searching its compatible property. In case of not finding any compatible property with Algorithm 5 Get non-critical PLIC regions Require: str1: String to identify PLIC node in DT with value ”sifive,plic1.0.0” str2: String to identify PLIC node in DT with value ”sifive,fu540c000plic” str3: String to identify PLIC node in DT with value ”sifive,plic0” plic ←found_PLIC_node_in_DT(str1) if ¬plic.addr then plic ←found_PLIC_node_in_DT (str2) if ¬plic.addr then plic ←found_PLIC_node_in_DT (str3) else report error end if end if reg.base ←calculate_noncriticalregion_base_addr(plic.addr, cntxt) reg.order ←define_memory_size reg.flags ←define_memory_acesses Chapter 4. HSP-V: Implementation 43 provided strings, the system returns and reports an error. Otherwise, (i) it calculates the PMP entry base address through base_addr =plic_base_addr + 0x200000 +(context×0x1000); (ii) it set the write and read flags; and (iii) it defines the size of the region with an order value of 12. After creating these regions, OpenSBI combines them with other domain memory regions . As a result of entrusting only non-critical PLIC regions to domain instances , the domains make the system trap when accessing the critical PLIC regions. Moreover, since the user does not have to worry about creating any domain memory regions to isolate non-critical PLIC regions, this automatic approach assists the OpenSBI configuration by preventing possible user misconfiguration. 4.4 Trap-and-emulate Mechanism Implementation Now that the non-critical PLIC regions are protected, this section will focus on the critical PLIC regions by implementing the trap-and-emulate technique. The trap-and-emulate approach is executed at the M- Mode level during the OpenSBI trap handler and helps to preventing domains to control external interrupts that are not assigned to them. The OpenSBI trap handler’s flow is depicted in Figure 4.1, where it starts by collecting and saving the contents of several registers, including the Stack Pointer (SP), PC, and some CSRs. Then, OpenSBI executes a trap routine named TRAP_CALL_C_ROUTINE , which covers various critical services such as, run-time services, SBI ECalls handling, virtual-to-physical memory translations, and the trap-and-emulate mechanism. Figure 4.1: Flowchart of the OpenSBI trap handler flow. When the system executes the TRAP_CALL_C_ROUTINE , OpenSBI executes the trap handler process to handle either interrupts or exceptions, respectively described in Algorithms 6 and 7. Firstly, the OpenSBI Chapter 5. HSP-V: Evaluation and Results 50 Scratchpad or L2-Cache space. When a way is enabled and locked, it works as L2-Cache. When a way is enabled but not locked, it is addressable in Scratchpad space, i.e., a space of main memory, as L2-LIM, reserved to be always in cache. The difference between Scratchpad and L2-LIM is that the Scratchpad is also cacheable to L1 data cache, resulting in faster access. In conclusion, in this dissertation, four ways (512 MiB) are reserved for Scratchpad and L2-LIM, and the remaining 12 ways (1.512 MiB) to manage the way locking method. Evaluation tools The evaluation tools used are as follows: (i) Device Tree Compiler (DTC) 3, to compile the DT scripts, which have a crucial impact in system configuration; (ii) GCC 4(with first level of compile optimization), to compile all HSP-V files; (iii) Buildroot 5, to build and compile Linux images; (iv) SoftConsole 6, to compile the HSS 7, configure primary PMP entries and define the cache locking mechanism; (v) QEMU 8, to simulate hardware platforms; (vi) Gnu DeBugger (GDB) 9, to enable debugging capabilities; (vii) Open On-Chip Debugger (OpenOCD) 10, to extend GDB functionalities by enabling remote debug access through OpenOCD server support; and (viii) PUTTY 11, to interact with platform used in this dissertation and display serial interfaces. Table 5.1 depicts each tool version. Table 5.1: Description of the tool versions. Tool Version DTC 1.5.0 GCC 8.3.0 Buildroot 2021.08.01 SoftConsole 2021.1 QEMU 6.0.90 GDB 8.3.0 OpenOCD 0.10.0 Putty 0.73 3DTC: https://elinux.org/Device_Tree_Reference 4GCC: https://gcc.gnu.org/ 5Buildroot: https://buildroot.org/ 6SoftConsole: https://www.microsemi.com/document-portal/doc_download/130766-softconsole-faq 7HSS: https://github.com/polarfire-soc/hart-software-services 8QEMU: https://www.qemu.org/docs/master/ 9GDB: https://lists.gnu.org/archive/html/info-gnu/2019-05/msg00007.html 10OpenOCD: https://openocd.org 11Putty: https://www.putty.org/ Chapter 5. HSP-V: Evaluation and Results 51 5.1 Functional Validation This dissertation was implemented iteratively and tested through a debug process by finding and solving implementation bugs. Therefore, the validation tests were performed over a simulated platform in QEMU and then passed to the real hardware platform. To prove its effectiveness, this section presents the functional validation of the system. It composes a set of intermediate tests: (i) tests to validate domain instance configuration; (ii) tests to validate the automatic device memory allocation to domain instances ; and (iii) tests to validate the trap-and-emulate technique. 5.1.1 Functional Validation: Domain Instance Configuration As mentioned in previous chapters, this dissertation adds to OpenSBI DT configuration a new property to bind, the possible-devices . This section intends to prove the correct binding process through the Figure 5.1. This figure depicts a simple domain system configuration in the DT at left side, which assign the uart device to the domain instance tdomain , and presents a debugging analysis during the execution of the binding function at right side, i.e., the inspection of fdt_parse_device_id behavior. Since this function is responsible to bind each ID over devices in possible-devices property, if it collects an ID number in accordance to the DT configuration, it proves the correct behavior of the binding function. As a result of this debugging process, the OpenSBI identifies the interrupt ID in accordance to the interrupt ID of the uart device ( dev_id = 10 ), and simultaneously assign it to the domain instance ( tdomain ). In this case, / tdomain #address-cells = <0x02>; #size-cells = <0x02>; Chosen compatible = "opensbi,domain,config"; compatible = "opensbi,domain,instance"; possible-harts = <&cpu1>; regions = <&memregion1 0x7>; ... possible-devices = <&uart>; uart SoC compatible = "ns16550a"; reg = <0x0 0x20100000 0x0 0x4000>; interrupt-parent = <&plic>; interrupts = 0xa; .... "possible_devices" "possible-devices" Figure 5.1: Result of Functional Validation: Domain Instance Configuration. Chapter 5. HSP-V: Evaluation and Results 52 the device ID belongs to a serial device and has the value 0xaas the interrupt ID value, validating the possible-devices property binding. 5.1.2 Functional Validation: Automatic Memory Assignment Another provided feature to OpenSBI is the automatic memory assignment mechanism. According to implementation and design phase, the memory regions to automatic assign are (i) the non-critical PLIC regions and (ii) the device MMIO regions in property possible-devices . The following Figure 5.1, depicts a DT configuration on left side, and an OpenSBI configuration result in right side. This configuration provides a partitioned environment composed by two domain instances , each running a from the scratch application operating in S-mode. On the configuration side, the domain instance nodes identify their domain memory regions . The bare1-domain identifies one domain memory region at 0x80200000, with the size of 220 bytes, and the bare2-domain identifies one domain memory region at 0x80100000, with the size of 220 bytes. Regarding possible-devices values of each domain instance , both domains have only one dedicated and assigned device, i.e, serial1 and serial2 devices. To validate the automatic memory assignment mechanism, the OpenSBI logger on the right side identifies not one but three domain memory regions to each domain instance . The red color identifies the bare1-domain memories and the green color identifies the bare2- domain domains. This provided mechanism automatically creates and assigns (i) the associated / #address-cells = <0x02>; #size-cells = <0x02>; Chosen compatible = "opensbi,domain,config"; serial1 SoC compatible = "ns16550a"; reg = <0x0 0x20100000 0x0 0x4000>; interrupt-parent = <&plic>; interrupts = 0xa; .... serial2 compatible = "ns16550a"; reg = <0x0 0x20102000 0x0 0x4000>; interrupt-parent = <&plic>; interrupts = 0xb; .... compatible = "opensbi,domain,instance"; possible-harts = <&cpu3>; regions = <&membare2 0x7>; ... possible-devices = <&serial2>; bare2-domain membare1 compatible = "opensbi,domain,memregion"; base = <0x0 0x80200000>; order = <20>; membare2 compatible = "opensbi,domain,memregion"; base = <0x0 0x80100000>; order = <20>; bare1-domain compatible = "opensbi,domain,instance"; possible-harts = <&cpu1>; regions = <&membare1 0x7>; ... possible-devices = <&serial1>; Figure 5.2: Result of Functional Validation: Automatic Memory Assignment. Chapter 5. HSP-V: Evaluation and Results 53 non-critical PLIC memories according to their contexts, (ii) the serial device MMIO regions defined in possible-devices , and (iii) the application memory at DT configuration. This screenshot proves the proper automatic memory assignment according to the DT configuration. 5.1.3 Functional Validation: Emulation of Critical PLIC Accesses In the example scenario of Figure 5.3, the OpenSBI configures two domain instances : (i) the bare1- domain , a bare-metal application executed by CPU1, containing a serial device with interrupt ID 91; and (ii) the bare2-domain , a bare-metal application executed by CPU3, containing a serial device with interrupt ID 92. Each domain instance is meant to execute a periodic loop that waits for an external interrupt. When Setup: Set Priority Setup: Set Enable Valid. test: Get Enable interrupt ID 91 Valid. test: Get Enable interrupt ID 92 Valid. test: Get Prio interrupt ID 91 Valid. test: Get Prio interrupt ID 92 OpenSBI Bare CPU1 Bare CPU3 Figure 5.3: Result of Functional Validation: Emulation of Critical PLIC Accesses. Chapter 5. HSP-V: Evaluation and Results 54 injecting characters to the respective serial device, the respective domain instance interrupts the infinite loop and executes the interrupt handler. Both domain instances start the execution with a set of functionalities to initialize the system: (i) initializing the PLIC, by defining the Threshold register value; (ii) preparing the IRQ handlers (the UART and timer handlers); (iii) configuring the UART device; (iv) configuring the frequency of timer; and (v) establishing the Priority and Enable registers of the associated serial device. Due to the latter covers critical PLIC regions, OpenSBI performs trap-and-emulate technique when domain instances execute them. Following the initialization, the execution runs several validation tests over the trap-and-emulate technique. Both domain instances execute read accesses over Enable and Priority registers related to interrupt IDs 91 and 92. Looking at the OpenSBI logger, the trap-and-emulate mechanism has completed the access of interrupt 91 when executed by bare1-domain ; and completed the access of interrupt 92 when executed by bare2-domain . Besides this system example, this dissertation proves the PLIC partitioning over several combinations of MCSs: (i) a bare-metal application alongside an RTOS system, both running in S-mode; (ii) a bare-metal application alongside a GPOS (Linux 5.9), both running in S-mode; and (iii) a RTOS alongside a GPOS, both running in S-mode. Due to the limited number of harts provided by HSS to OpenSBI (two harts), the partitioning system is limited to a number of two domain instances . 5.2 Code Size This dissertation extended the open-source code of OpenSBI, following its code structure and enhancing it with additional features. This section analyzes the contribution of this dissertation by evaluating the code complexity using Source Lines of Code (SLoC). The OpenSBI code is divided into four main sections: the utils and the platform directories contain target-specific functionality (e.g. DT parser functionalities, drivers for platforms), while the sbi and firmware directories feature the main secure monitor logic and utilities (e.g., perform run-time services, managing domain instances , perform trap-and-emulate technique). Table 5.2 presents the SLoC and final binary sizes for each directory of the original and the HSP-V OpenSBI. Table 5.2 shows that, for the target platform, i.e., the generic platform, the original implementation comprises a total of 16.265 KSLoC. This small code base reflects the overall low degree of complexity of the system. Most of the code is written in C, although functionalities such as low-level initialization and context save/restore (exception entry and exit) are written in assembly language. The sbi folder contains the most of the total SLoC provided by the original OpenSBI (The majority of additional code is SLoC). Regarding all changes of HSP-V, the OpenSBI increases about 10% of its source code (1.656 KSLoC). The majority of additional code is in the utils folder, i.e., in the parsing management over DT and in the automatic device MMIO and non-critical PLIC regions assignment. Moreover, in terms of the trap-and- emulate technique insertion, this also has a remarkable impact with its 623 SLoC. These results prove Chapter 5. HSP-V: Evaluation and Results 55 the small amount of additional code, contributing to the system security, with a small attack surface over code that operates in M-mode level. Table 5.2: Source lines of code (SLoC) and binary size (bytes). SLoC Size (bytes) c asm Total .text .data .bss Total OpenSBI (original) utils 6236 27 6263 41597 1240 13224 56061 platform/generic 373 0 373 2247 192 544 2983 sbi 8507 229 8736 52010 816 128376 181202 firmware 33 860 893 49695 120 0 49815 Total 15149 1116 16265 145549 2368 142144 290061 OpenSBI (HSP-V) utils 7159 27 7186 44532 1240 15624 61396 platform/generic 480 0 480 2273 320 40 2633 sbi 9130 229 9359 54680 824 128376 183880 firmware 33 863 896 49691 120 0 49811 Total 16802 1119 17921 151176 2504 144040 297720 The resulting binary size is detailed in the rightmost section of Table 5.2. To get each table value, the compiler operates with moderate optimizations, i.e., optimizes quite effectively but does not greatly impact compilation time. The total size of statically allocated memory is about 290 KiB and 298 KiB in the original and the HSP-V OpenSBI, respectively. Note that the large .bss section size (before and after OpenSBI changes) is mainly due to the static allocation of the hardware and firmware events data to support the Physical Memory Unit (PMU) (125 KiB). Ignoring it, this brings the total size of the final binary to be loaded to about 165 KiB on original OpenSBI and 173 KiB in enhanced one. Therefore, these results reveal a lightweight increase of binary size with just 8 KiB. 5.3 Boot Overhead This section evaluates the enhanced OpenSBI’s overhead on boot time (not the system’s overall boot time). The complete boot flow includes several platform-specific boot stages mentioned in Chapter 2.2.4: (i) a ZSBL, which performs low-level initializations and loads the FSBL (the HSS) to on-chip memory from an eMMC; (ii) the FSBL, which prepare the DDRs, manage the cache locking, and loads the SSBL (the OpenSBI); (iii) the SSBL, which runs the OpenSBI and prepare all domain system; and then (iv) the last boot stage, which runs each domain instance . The evaluated boot overhead includes the SSBL, i.e., the OpenSBI boot time (coldboot and warmboot time), and the last boot stage, i.e., the boot overhead imposed by each domain instance (e.g., the Linux boot time). The coldboot and warmboot terms describe the boot of primary and secondary harts, respectively. Typically, the OpenSBI completes the coldboot first, while Chapter 5. HSP-V: Evaluation and Results 56 secondary harts wait for the coldboot to finish. After coldboot time, the secondary harts perform the warmboot, which boots the rest of the platform-defined harts. Regarding these boot overhead measurements, these are only approximate values to the platform’s total boot time, as they do not take into account the ZSBL and the FSBL time. Furthermore, results include measurements on both the original and enhanced OpenSBI, the HSP-V, allowing the awareness of imposed boot overhead in a system with or without PLIC partition. For the measurements performed in this evaluation, it was used the processor frequency and rdcycle pseudo-instruction, which reads the clock cycles executed by the processor core. The system environment consider two cases: (i) a small domain (310 KiB image size and 16 MiB of memory) running FreeRTOS, and (ii) a large domain (20 MiB image size and 52 MiB of memory) running Linux. For each domain instance , a considered a single-core S-mode execution scenarios with cache locking disabled and enabled ( solo and solo-lock , respectively). When cache locking is enabled, 8 ways are locked/assigned to the large domain and four ways to the small domain. The remaining ways are assigned to the remaining L2 cache configurations, i.e, to the scratchpad when target ways are enabled, and to L2-LIM when target ways are disabled. Figure 5.4 depicts an overview diagram representing the boot flow of OpenSBI, FreeRTOS, and Linux. During SSBL, OpenSBI initializes the primary hart through the coldboot time, followed by the initialization of the secondary harts through the warmboot time, while simultaneously launching the small domain scenario. At the end of warmboot, OpenSBI launches the large domain scenario. Moreover, during each S- mode boot initialization, the OpenSBI performs the trap-and-emulate technique over critical PLIC accesses, represented in the figure with the label ”T.A.E” . The measured time are: (i) the OpenSBI initialization ( OpenSBI init. time of each scenario), the time taken from the first instruction executed by the OpenSBI until to the moment it passes the control to the domain instance , i.e., the time taken from coldboot and M-MODE (OpenSBI) S-MODE (kernel) Execution time line Linux FreeRTOS T.A.E T.A.E OpenSBI coldboot OpenSBI warmboot Linux boot Linux boot FreeRTOS boot FreeRTOS boot OpenSBI init. time (Linux) OpenSBI init. time (FreeRTOS) Total boot time (FreeRTOS) Total boot time (Linux) Figure 5.4: Execution time representation of the boot and initialization flow. Chapter 5. HSP-V: Evaluation and Results 57 warmboot, and (ii) the Total boot time , the time taken from the first instruction executed by the OpenSBI until to the first application inside the domain instance . Table 5.3 shows the average results of 20 samples for each measurement, considering each scenario running in the original and HSP-V OpenSBI. The boot flow of the original OpenSBI, i.e., the OpenSBI init. time , have significant values in terms of coldboot and warmboot (74ms and 195ms, respectively). The warmboot takes 121ms more than coldboot. In the small domain case, the Total boot time prevailed approximately the same, with 89ms, in solo and solo-lock scenarios. The difference between the Total boot time and coldboot time revel 15ms to boot the small domain, i.e., the time taken to boot FreeRTOS. On the other hand, in the large domain scenarios, the Total boot time increases by approximately 50 ms when comparing solo with solo-lock scenarios. The difference between the Total boot time and warmboot time revel 6,842sto boot the large domain scenario, i.e., the time taken to boot Linux. Regarding measurements in enhanced OpenSBI (the HSP-V scenarios), the first point to highlight is the difference in coldboot overhead. HSP-V OpenSBI init. time spends 108ms more than the original OpenSBI. This is because all DT parser process is done during the coldboot time and due to the addition of new features to DT configuration, the coldboot need more time to perform the new parser functionalities. Furthermore, coldboot also needs to perform the non-critical PLIC partition and the creation of device MMIO regions. A second point to highlight is the coldboot time being always smaller than warmboot, either in original and in HSP-V scenarios. This is because the secondary harts only resume from suspended execution after the completion of primary hart initialization by the OpenSBI coldboot. Third, is the slight increase between solo-lock face solo cases in Total boot time of both original and HSP-V OpenSBI values. This is mainly because the shared cache space available is decreased due to partitioning using cache locking. Last but not least, the values of Total boot time in HSP-V being higher than the original OpenSBI. The increase of these values is due to the virtualization overhead imposed by trap-and-emulate technique, which have notary impact of approximately 136ms and 2.8sin small and large cases, respectively. Table 5.3: OpenSBI initialization time (ms) and total boot time (ms). Scenario OpenSBI init. time (ms) Total boot time (ms) avg std-dev avg std-dev OpenSBI (original) freertos solo 74.22 0.009 89.11 0.05 freertos solo-lock 74.31 0.021 89.21 0.08 linux solo 195.11 0.108 6793.80 7.35 linux solo-lock 195.11 0.183 6842.62 4.52 OpenSBI (HSP-V) freertos solo 182.44 0.030 225.72 0.03 freertos solo-lock 182.44 0.074 225.76 0.04 linux solo 195.21 0.094 9590.27 5.67 linux solo-lock 195.22 0.288 9642.01 7.77 Chapter 5. HSP-V: Evaluation and Results 58 5.4 Performance Overhead and Interference To assess performance overhead and inter-domain interference, this dissertation adopts the use of MiBench Embedded Benchmark Suite. MiBench is a collection of 35 benchmarks divided into six subgroups, with each subset focusing on a particular embedded industry segment: automotive (including industrial control), consumer devices, office automation, networking, security, and telecommunications. This dissertation focus the evaluation on the automotive subset, as this is one of the main application domains targeted by related work (e.g. Bao). The automotive suite includes three high memory-intensive benchmarks, that are more susceptible to interference due to LLC and memory contention ( qsort , susan corners , and susan edges ). Each benchmark was ran for four different system configurations targeting a dual-core design: (i) a single hart running a domain instance ( solo ); (ii) a single hart running a domain instance with cache locking enable( solo-lock ); (iii) two domain instances , each with a single hart assigned, one being the target and the other injecting interference ( interf ); (iv) two domain instances , each with a single hart assigned, one being the target and the other injecting interference, with cache locking enable ( interf-lock ). Hosted scenarios with cache locking aim at evaluating the effects of partitioning micro-architectural resources at the domain level and to what extent it can mitigate interference. The target benchmark executes in a Linux-based domain running in one hart, and adding interference with other domain also running in one hart, running a bare-metal application. To add interference, the ad-hoc bare-metal application continuously writes and reads a 3 MiB array with a stride equal to the cache line size (64 bytes). The platform’s cache topology allows for 16 ways, each way consisting of 128 KiB. When enabling locking, this evaluation follow the same cache lock approach in Section 5.3, assigning four ways (512 KiB) to bare-metal and eight ways (1 MiB) to Linux-based domain. The remaining four ways were reserved for the HSS (L2-LIM) and for OpenSBI scratchpad space (as mentioned in begin of Section 5.3). Figure 5.5 presents the results as performance normalized to solo scenario, meaning that higher values report worse results. Each bar represents the average value of 100 samples on top of solo bar. For each benchmark, is mentioned the execution time (i.e., absolute performance) at the top of the solo execution bar. This evaluation take five main conclusions. Firstly, when cache locking ( solo-lock ) is enabled, the performance overhead is further increased. This extra overhead is explained by the fact that only part of the LLC cache is available for the target domain. Secondly, when the system is under significant interference ( interf ), there is a considerable decrease of performance, in particular, for the memory-intensive benchmarks, i.e., qsort (small), susan corners (small), and susan edges (small). For instance, for the susan corners (small) benchmark, the performance overhead increases by 22%. Thirdly, cache locking can reduce the interference ( interf-lock ) by almost 2%. Fourthly, the less memory-intensive benchmarks, i.e., basicmath and bitcount, are less vulnerable to cache interference. Lastly, benchmarks which handle smaller datasets are more susceptible to interference. Chapter 5. HSP-V: Evaluation and Results 59 Figure 5.5: Relative performance overhead of MiBench automotive suite. 5.5 Interrupt Latency To measure interrupt latency, this evaluation crafted a minimal bare-metal benchmark application. This bare-metal application continuously read the value of rdcycle (reference cycle instant) while waiting for an external interrupt (triggered when a serial device receives a character). When the external interrupt is triggered, the latency equals the difference between the reference cycle instant and the first cycle instant inside the interrupt handler. The latter preserves the number of executed cycles to start handling the interrupt. Then, the latency time is obtained by dividing the number of cycles by the processor’s frequency (625MHz). Figure 5.6 summarizes the 500 sample results for both scenarios, i.e., (i) Interrupt latency in Figure 5.6: Interrupt latency measurements before, and after OpenSBI modifications. REFERENCES 66 Science of Security , pp. 1–2, 2020. [12] L. Gwennap,”Deterministic Processing for Mission-Critical Applications”, The Linley Group , 2020, [online] Available at: <https://www.linleygroup.com/uploads/sifive-deterministic-processing-wp.pdf>. [13] N. Suzuki, H. Kim, D. De Niz, B. Andersson, L. Wrage, M. Klein, and R. Rajkumar, “Coordinated bank and cache coloring for temporal protection of memory accesses,” in 2013 IEEE 16th International Conference on Computational Science and Engineering , pp. 685–692, 2013. [14] K. Asanović and D. A. Patterson, “Instruction sets should be free: The case for risc-v,” EECS Department, University of California, Berkeley, Tech. Rep. UCB/EECS-2014-146 , 2014. [15] R. Uhlig, G. Neiger, D. Rodgers, A. Santoni, F. Martins, A. Anderson, S. Bennett, A. Kagi, F. Leung, and L. Smith, “Intel virtualization technology,” Computer , vol. 38, no. 5, pp. 48–56, 2005. [16] D. Seal, ARM architecture reference manual . 2001. [17] D. Kanter, “RISC-V offers simple, modular ISA,” Microprocessor Report , 2016. [18] A. Waterman, Y. Lee, R. Avizienis, D. A. Patterson, and K. Asanović, “The RISC-V Instruction Set Manual Volume II: Privileged Architecture Version 1.9,” Tech. Rep. UCB/EECS-2016-129, EECS Department, University of California, Berkeley, 2016. [19] B. Sá, J. Martins, and S. E. S. Pinto, “A First Look at RISC-V Virtualization from an Embedded Systems Perspective,” IEEE Transactions on Computers , 2021. [20] C. Garlati and S. Pinto, “Secure IoT Firmware For RISC-V Processors,” Embbedded world 2021 , 2021. [21] B. Sá, RISC-V lightweight virtualization extensions . PhD thesis, Universidade do Minho, 2021. [22] D. Lee, D. Kohlbrenner, S. Shinde, K. Asanović, and D. Song, “Keystone: An open framework for architecting trusted execution environments,” in Proceedings of the Fifteenth European Conference on Computer Systems , pp. 1–16, 2020. [23] F. R. Yu, J. Liu, Y. He, P. Si, and Y. Zhang, “Virtualization for Distributed Ledger Technology (vDLT),” IEEE Access , vol. 6, pp. 25019–25028, 2018. [24] D. Muench, M. Paulitsch, and A. Herkersdorf, “Iompu: Spatial separation for hardware-based i/o virtualization for mixed-criticality embedded real-time systems using non-transparent bridges,” in 2015 IEEE 17th International Conference on High Performance Computing and Communications, 2015 IEEE 7th International Symposium on Cyberspace Safety and Security, and 2015 IEEE 12th International Conference on Embedded Software and Systems , pp. 1037–1044, 2015. [25] M. Strobl, M. Kucera, A. Foeldi, T. Waas, N. Balbierer, and C. Hilbert, “Towards automotive virtualization,” in 2013 International Conference on Applied Electronics , pp. 1–6, 2013. [26] A. Galluccio and P. J. Agrell, “Industry 4.0 in focus: The Adidas Speedfactory,” Université catholique de Louvain , pp. 21–32, 2022. REFERENCES 67 [27] C. Garlati and S. Pinto, “A clean slate approach to Linux security RISC-V enclaves,” in Embedded World Conference , p. 5, 2020. [28] Vinay T R and A. A. Chikkamannur, “A methodology for migration of software from single-core to multi-core machine,” in 2016 International Conference on Computation System and Information Technology for Sustainable Solutions (CSITSS) , pp. 367–369, 2016. [29] E. Qaralleh, D. Lima, T. Gomes, A. Tavares, and S. Pinto, “HcM-FreeRTOS: hardware-centric FreeR- TOS for ARM multicore,” in 2015 IEEE 20th Conference on Emerging Technologies & Factory Automation (ETFA) , pp. 1–4, 2015. [30] P. Burgio, M. Bertogna, I. S. Olmedo, P. Gai, A. Marongiu, and M. Sojka, “A Software Stack for Next-Generation Automotive Systems on Many-Core Heterogeneous Platforms,” in 2016 Euromicro Conference on Digital System Design (DSD) , pp. 55–59, 2016. [31] R. Ernst and M. Di Natale, “Mixed Criticality Systems—A History of Misconceptions?,” IEEE Design Test , vol. 33, no. 5, pp. 65–74, 2016. [32] E. Armbrust, J. Song, G. Bloom, and G. Parmer, “On spatial isolation for mixed criticality, embedded systems,” in Proc. 2nd Workshop on Mixed Criticality Systems (WMC), RTSS , pp. 15–20, 2014. [33] B. Cilku and P. Puschner, “Towards temporal and spatial isolation in memory hierarchies for mixedcriticality systems with hypervisors,” Proc. ReTiMiCS, RTCSA , pp. 25–28, 2013. [34] S. Pinto, A. Oliveira, J. Pereira, J. Cabral, J. Monteiro, and A. Tavares, “Lightweight multicore virtualization architecture exploiting ARM TrustZone,” in IECON 2017-43rd Annual Conference of the IEEE Industrial Electronics Society , pp. 3562–3567, 2017. [35] J. Martins, J. Alves, J. Cabral, A. Tavares, and S. Pinto, “µRTZVisor: a secure and safe real-time hypervisor,” Electronics , vol. 6, no. 4, p. 93, 2017. [36] E. Schoitsch, “Design for Safety and Security of Complex Embedded Systems: A Unified Approach,” In: Proceedings of the NATO advanced research workshop on cyberspace security and defense , 2004. [37] J.-Y. Hwang, S.-B. Suh, S.-K. Heo, C.-J. Park, J.-M. Ryu, S.-Y. Park, and C.-R. Kim, “Xen on ARM: System virtualization using Xen hypervisor for ARM-based secure mobile phones,” in 2008 5th IEEE Consumer Communications and Networking Conference , pp. 257–261, 2008. [38] C. Dall and J. Nieh, “KVM/ARM: the design and implementation of the linux ARM hypervisor,” Acm Sigplan Notices , vol. 49, no. 4, pp. 333–348, 2014. [39] J. Martins, A. Tavares, M. Solieri, M. Bertogna, and S. Pinto, “Bao: A Lightweight Static Partitioning Hypervisor for Modern Multi-Core Embedded Systems,” in Workshop on Next Generation Real-Time Embedded Systems (NG-RES 2020) (M. Bertogna and F. Terraneo, eds.), vol. 77 of OpenAccess Series in Informatics (OASIcs) , (Dagstuhl, Germany), pp. 3:1–3:14, 2020. REFERENCES 68 [40] G. J. Popek and R. P. Goldberg, “Formal Requirements for Virtualizable Third Generation Architectures,” Commun. ACM , vol. 17, no. 7, p. 412–421, 1974. [41] G. Heiser, “The role of virtualization in embedded systems,” ACM , pp. 11–16, 2008. [42] T. Xia, J.-C. Prevotet, and F. Nouvel, “Mini-NOVA: A Lightweight ARM-based Virtualization Microkernel Supporting Dynamic Partial Reconfiguration,” in 2015 IEEE International Parallel and Distributed Processing Symposium Workshop , pp. 71–80, 2015. [43] P. Barham, B. Dragovic, K. Fraser, S. Hand, T. Harris, A. Ho, R. Neugebauer, I. Pratt, and A. Warfield, “Xen and the art of virtualization,” ACM SIGOPS operating systems review , vol. 37, no. 5, pp. 164– 177, 2003. [44] Z. H. Shah, “Windows Server 2012 Hyper-V: Deploying the Hyper-V Enterprise Server Virtualization Platform,” Packt Publishing , 2013. [45] H. Fayyad-Kazan, L. Perneel, and M. Timmerman, “Full and para-virtualization with Xen: a performance comparison,” Journal of Emerging Trends in Computing and Information Sciences , vol. 4, no. 9, pp. 719–727, 2013. [46] P. F. R. Garcia, “Hybrid hypervisor partially deployed on FPGA,” repositorium , 2015. [47] S. M. Jain, “Virtualization basics,” in Linux containers and virtualization , pp. 1–14, 2020. [48] L. Abeni and D. Faggioli, “Using Xen and KVM as real-time hypervisors,” Journal of Systems Architecture , vol. 106, p. 101709, 2020. [49] A. Landau, M. Ben-Yehuda, and A. Gordon, “SplitX: Split Guest/Hypervisor Execution on Multi-Core,” in 3rd Workshop on I/O Virtualization (WIOV 11) , 2011. [50] J. T. Lim, C. Dall, S.-W. Li, J. Nieh, and M. Zyngier, “NEVE: Nested virtualization extensions for ARM,” in Proceedings of the 26th Symposium on Operating Systems Principles , pp. 201–217, 2017. [51] L. Jünger, J. L. M. Bölke, S. Tobies, R. Leupers, and A. Hoffmann, “ARM-on-ARM: leveraging virtualization extensions for fast virtual platforms,” in 2020 Design, Automation & Test in Europe Conference & Exhibition (DATE) , pp. 1508–1513, 2020. [52] E. De Mulder, S. Gummalla, and M. Hutter, “Protecting RISC-V against side-channel attacks,” in 2019 56th ACM/IEEE Design Automation Conference (DAC) , pp. 1–4, 2019. [53] M. Silva, T. Gomes, and S. Pinto, “Leveraging RISC-V to build an open-source (hardware) OS framework for reconfigurable IoT devices,” CARRV2021 , vol. 6, 2021. [54] A. Waterman, Y. Lee, D. A. Patterson, and K. Asanovi, “The risc-v instruction set manual. volume 1: User-level isa, version 2.0,” tech. rep., California Univ Berkeley Dept of Electrical Engineering and Computer Sciences, 2014. [55] S. Chadwick, S. Graham, and J. Dean, “Performance Implications for Multi-Core RISC-V Systems with Dedicated Security Hardware,” in International Conference on Cyber Warfare and Security , vol. 17, REFERENCES 69 pp. 440–448, 2022. [56] K. Cheang, C. Rasmussen, D. Lee, D. W. Kohlbrenner, K. Asanovic, and S. A. Seshia, “Verifying RISC-V physical memory protection,” in IEEE International Symposium on Performance Analysis of Systems and Software (ISPASS) Workshop on Secure RISC-V Architecture Design , 2020. [57] S. Pinto and C. Garlati, “User mode interrupts: A must for securing embedded systems,” in Embedded World Conference , 2019. [58] S. Pinto and J. Martins, “The industry-first secure IoT stack for RISC-V: a research project,” in RISC-V Workshop,(Zurich) , 2019. [59] F. Arakawa, A. Tsukamoto, K. Suzaki, and M. Ikeda, “Examination of applicability of RISC-V security specifications to low-end processors,” 2020. [60] P. Lucas, K. Chappuis, M. Paolino, N. Dagieu, and D. Raho, “Vosysmonitor, a low latency monitor layer for mixed-criticality systems on armv8-a,” in 29th Euromicro Conference on Real-Time Systems (ECRTS 2017) , 2017. [61] Y. Babar, “GRUB Bootloader,” in Hands-on Booting , pp. 133–181, 2020. [62] T. Lu, “A survey on risc-v security: Hardware and architecture,” arXiv preprint arXiv:2107.04175 , 2021. [63] P. Chandrasekaran, K. B. Shibu Kumar, R. L. Minz, D. D’Souza, and L. Meshram, “A multi-core version of FreeRTOS verified for datarace and deadlock freedom,” in 2014 Twelfth ACM/IEEE Conference on Formal Methods and Models for Codesign (MEMOCODE) , pp. 62–71, 2014. [64] A. Patel, M. Daftedar, M. Shalan, and M. W. El-Kharashi, “Embedded hypervisor xvisor: A comparative analysis,” in 2015 23rd Euromicro International Conference on Parallel, Distributed, and Network- Based Processing , pp. 682–691, 2015. [65] R. Ramsauer, J. Kiszka, D. Lohmann, and W. Mauerer, “Look mum, no VM exits!(almost),” arXiv preprint arXiv:1705.06932 , 2017. [66] C. Hernandez, J. Flieh, R. Paredes, C.-A. Lefebvre, I. Allende, J. Abella, D. Trillin, M. Matschnig, B. Fischer, K. Schwarz, et al. , “SELENE: Self-monitored dependable platform for high-performance safetycritical systems,” in 2020 23rd Euromicro Conference on Digital System Design (DSD) , pp. 370–377, 2020. [67] F. Caforio, P. Iannicelli, M. Paolino, and D. Raho, “Vosysmonitorv: a mixed-criticality solution on linux-capable risc-v platforms,” in 2021 10th Mediterranean Conference on Embedded Computing (MECO) , pp. 1–4, 2021. [68] G. Heiser, G. Klein, and J. Andronick, “seL4 in Australia: from research to real-world trustworthy systems,” Communications of the ACM , vol. 63, no. 4, pp. 72–75, 2020. [69] M. Boubakri, F. Chiatante, and B. Zouari, “Open Portable Trusted Execution Environment framework REFERENCES 70 for RISC-V,” in 2021 IEEE 19th International Conference on Embedded and Ubiquitous Computing (EUC) , pp. 1–8, 2021. [70] M. Boubakri, F. Chiatante, and B. Zouari, “Towards a firmware TPM on RISC-V,” in 2021 Design, Automation & Test in Europe Conference & Exhibition (DATE) , pp. 647–650, 2021. [71] A. Waterman, Y. Lee, D. A. Patterson, and K. Asanović, “The RISC-V compressed instruction set manual, version 1.7,” EECS Department, University of California, Berkeley, UCB/EECS-2015-157 , 2015.