Ambroise Vincent | 9660dc1 | 2019-07-12 13:47:03 +0100 | [diff] [blame] | 1 | ======== |
| 2 | Debug FS |
| 3 | ======== |
| 4 | |
| 5 | .. contents:: |
| 6 | |
| 7 | Overview |
| 8 | -------- |
| 9 | |
| 10 | The *DebugFS* feature is primarily aimed at exposing firmware debug data to |
| 11 | higher SW layers such as a non-secure component. Such component can be the |
| 12 | TFTF test payload or a Linux kernel module. |
| 13 | |
| 14 | Virtual filesystem |
| 15 | ------------------ |
| 16 | |
| 17 | The core functionality lies in a virtual file system based on a 9p file server |
| 18 | interface (`Notes on the Plan 9 Kernel Source`_). The implementation permits |
| 19 | exposing virtual files, firmware drivers, and file blobs. |
| 20 | |
| 21 | Namespace |
| 22 | ~~~~~~~~~ |
| 23 | |
| 24 | Two namespaces are exposed: |
| 25 | |
| 26 | - # is used as root for drivers (e.g. #t0 is the first uart) |
| 27 | - / is used as root for virtual "files" (e.g. /fip, or /dev/uart) |
| 28 | |
| 29 | 9p interface |
| 30 | ~~~~~~~~~~~~ |
| 31 | |
| 32 | The associated primitives are: |
| 33 | |
| 34 | - Unix-like: |
| 35 | |
| 36 | - open(): create a file descriptor that acts as a handle to the file passed as |
| 37 | an argument. |
| 38 | - close(): close the file descriptor created by open(). |
| 39 | - read(): read from a file to a buffer. |
| 40 | - write(): write from a buffer to a file. |
| 41 | - seek(): set the file position indicator of a file descriptor either to a |
| 42 | relative or an absolute offset. |
| 43 | - stat(): get information about a file (type, mode, size, ...). |
| 44 | |
| 45 | .. code:: c |
| 46 | |
| 47 | int open(const char *name, int flags); |
| 48 | int close(int fd); |
| 49 | int read(int fd, void *buf, int n); |
| 50 | int write(int fd, void *buf, int n); |
| 51 | int seek(int fd, long off, int whence); |
| 52 | int stat(char *path, dir_t *dir); |
| 53 | |
| 54 | - Specific primitives : |
| 55 | |
| 56 | - mount(): create a link between a driver and spec. |
| 57 | - create(): create a file in a specific location. |
| 58 | - bind(): expose the content of a directory to another directory. |
| 59 | |
| 60 | .. code:: c |
| 61 | |
| 62 | int mount(char *srv, char *mnt, char *spec); |
| 63 | int create(const char *name, int flags); |
| 64 | int bind(char *path, char *where); |
| 65 | |
| 66 | This interface is embedded into the BL31 run-time payload when selected by build |
| 67 | options. The interface multiplexes drivers or emulated "files": |
| 68 | |
| 69 | - Debug data can be partitioned into different virtual files e.g. expose PMF |
| 70 | measurements through a file, and internal firmware state counters through |
| 71 | another file. |
| 72 | - This permits direct access to a firmware driver, mainly for test purposes |
| 73 | (e.g. a hardware device that may not be accessible to non-privileged/ |
| 74 | non-secure layers, or for which no support exists in the NS side). |
| 75 | |
| 76 | SMC interface |
| 77 | ------------- |
| 78 | |
| 79 | The communication with the 9p layer in BL31 is made through an SMC conduit |
| 80 | (`SMC Calling Convention PDD`_), using a specific SiP Function Id. An NS shared |
| 81 | buffer is used to pass path string parameters, or e.g. to exchange data on a |
| 82 | read operation. Refer to `ARM SiP Services`_ for a description of the SMC |
| 83 | interface. |
| 84 | |
| 85 | Security considerations |
| 86 | ----------------------- |
| 87 | |
| 88 | - Due to the nature of the exposed data, the feature is considered experimental |
| 89 | and importantly **shall only be used in debug builds**. |
| 90 | - Several primitive imply string manipulations and usage of string formats. |
| 91 | - Special care is taken with the shared buffer to avoid TOCTOU attacks. |
| 92 | |
| 93 | Limitations |
| 94 | ----------- |
| 95 | |
| 96 | - In order to setup the shared buffer, the component consuming the interface |
| 97 | needs to allocate a physical page frame and transmit its address. |
| 98 | - In order to map the shared buffer, BL31 requires enabling the dynamic xlat |
| 99 | table option. |
| 100 | - Data exchange is limited by the shared buffer length. A large read operation |
| 101 | might be split into multiple read operations of smaller chunks. |
| 102 | - On concurrent access, a spinlock is implemented in the BL31 service to protect |
| 103 | the internal work buffer, and re-entrancy into the filesystem layers. |
| 104 | - Notice, a physical device driver if exposed by the firmware may conflict with |
| 105 | the higher level OS if the latter implements its own driver for the same |
| 106 | physical device. |
| 107 | |
| 108 | Applications |
| 109 | ------------ |
| 110 | |
| 111 | The SMC interface is accessible from an NS environment, that is: |
| 112 | |
| 113 | - a test payload, bootloader or hypervisor running at NS-EL2 |
| 114 | - a Linux kernel driver running at NS-EL1 |
| 115 | - a Linux userspace application through the kernel driver |
| 116 | |
| 117 | References |
| 118 | ---------- |
| 119 | |
| 120 | .. [#] `SMC Calling Convention PDD`_ |
| 121 | .. [#] `Notes on the Plan 9 Kernel Source`_ |
| 122 | .. [#] `Linux 9p remote filesystem protocol`_ |
| 123 | .. [#] `ARM SiP Services`_ |
| 124 | |
| 125 | -------------- |
| 126 | |
| 127 | *Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.* |
| 128 | |
| 129 | .. _SMC Calling Convention PDD: http://infocenter.arm.com/help/topic/com.arm.doc.den0028b/ |
| 130 | .. _Notes on the Plan 9 Kernel Source: http://lsub.org/who/nemo/9.pdf |
| 131 | .. _Linux 9p remote filesystem protocol: https://www.kernel.org/doc/Documentation/filesystems/9p.txt |
| 132 | .. _ARM SiP Services: arm-sip-service.rst |