泰晓科技 -- 聚焦 Linux - 追本溯源,见微知著!
网站地址:https://tinylab.org

泰晓 Linux 实验盘全系 6 大 Linux 发行版已全部支持自动快照并集成 Linux Lab v1.0
请稍侯

RISC-V 缺失的 Linux 内核功能

unknown 创作于 2022/09/23

Author: 牛工 - 通天塔 985400330@qq.com Date: 2022/08/28 Revisor: Falcon falcon@ruma.tech; iOSDevLog iosdevlog@iosdevlog.com Project: RISC-V Linux 内核剖析 Proposal: Missing Features/Tools for RISC-V Sponsor: PLCT Lab, ISCAS

前言

RISC-V 架构下还是存在非常多的功能需要大家填坑,很多的功能都是优先在 x86、ARM 上进行了实现,有很多的新功能都还几乎没有资料,需要大家一起去建设,以下是我从内核 Documents 上找到的 RISC-V 下的各类 TODO 功能,并做了简单分析,提供了一些资料,希望大家能找到自己感兴趣的方向,早日向社区提交自己的补丁!

KMSAN (Kernel Feature)

  • 功能:

    KernelMemorySanitizer (KMSAN) is a detector of errors related to uses of uninitialized memory. It relies on compile-time Clang instrumentation (similar to MSan in the userspace) and tracks the state of every bit of kernel memory, being able to report an error if uninitialized value is used in a condition, dereferenced, or escapes to userspace, USB or DMA.

    KernelMemorySanitizer (KMSAN) 是一个用于检测 使用未初始化内存 的错误检测器。它依赖于编译时的 Clang 工具(类似于用户空间中的 MSan),并跟踪内核内存每一比特的状态,如果在条件中使用了未初始化的值、解引用或转义到用户空间、USB 或 DMA 时,能够报告错误。

    KMSAN has reported more than 300 bugs in the past few years, most of them with the help of syzkaller. Such bugs keep getting introduced into the kernel despite new compiler warnings and other analyses (the 5.16 cycle already resulted in several KMSAN-reported bugs). Mitigations like total stack and heap initialization are unfortunately very far from being deployable.

    KMSAN 在过去几年中报告了 300 多个错误,其中大部分是在 syzkaller 的帮助下发生的。尽管有新的编译器警告和其他分析(5.16 周期已经导致了几个 kmsan 报告的错误),但这样的错误仍然被引入内核。不幸的是,像全部的堆栈初始化检测这样的缓解措施离部署还很远。

    The proposed patchset contains KMSAN runtime implementation together with small changes to other subsystems needed to make KMSAN work.

    申请合入的补丁集包含 KMSAN 运行时的实现,以及使 KMSAN 工作所需的其他子系统的小更改。

  • 状态

  • 资料

optprobes(Kernel Feature)

  • 功能:

    If your kernel is built with CONFIG_OPTPROBES=y (currently this flag is automatically set ‘y’ on x86/x86-64, non-preemptive kernel) and the “debug.kprobes_optimization” kernel parameter is set to 1 (see sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump instruction instead of a breakpoint instruction at each probepoint.

    如果您的内核是使用 CONFIG_OPTPROBES=y(当前该标志在 x86/x86-64 非抢占内核上自动设置为’ y ‘)和内核参数 kprobes_optimization 设置为 1(请参阅 sysctl(8)),Kprobes 将试图通过在每个探测点使用跳转指令而不是断点指令来减少探测访问开销。

    Kprobes enables you to dynamically break into any kernel routine and collect debugging and performance information non-disruptively. You can trap at almost any kernel code address , specifying a handler routine to be invoked when the breakpoint is hit.

    Kprobes 使您能够动态地进入任何内核程序,并在不中断的情况下收集调试和性能信息。您可以在几乎任何内核代码地址中设置陷阱,指定在遇到断点时要调用的处理程序。

  • 状态
  • 资料

user-ret-profiler(Kernel Feature)

queued-spinlocks(Kernel Feature)

membarrier-sync-core(Kernel Feature)

virt-cpuacct(Kernel Feature)

batch-unmap-tlb-flush(Kernel Feature)

  • 功能:

    ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
    

    arch supports deferral of TLB flush until multiple pages are unmapped.

    架构支持延迟刷新 TLB,直到多个页面取消映射之后。

    For architectures that prefer to flush all TLBs after a number of pages are unmapped instead of sending one IPI per page to flush. The architecture must provide guarantees on what happens if a clean TLB cache entry is written after the unmap. Details are in mm/rmap.c near the check for should_defer_flush. The architecture should also consider if the full flush and the refill costs are offset by the savings of sending fewer IPIs.

    适用于倾向于取消多个页面映射后刷新所有 TLB,而不是在每个页面发送一个 IPI 来刷新的架构。如果在 unmap 之后写入干净的 TLB 缓存入口,架构必须保证会触发的事件。详细信息在 mm/rmap.c 中为 should_defer_flush 检查附近。该架构还应该考虑是否可以通过减少发送 IPI 来抵消完全刷新和重新填充的成本。

  • 状态
  • 资料

huge-vmap(Kernel Feature)

ioremap_prot(Kernel Feature)

PG_uncached(Kernel Feature)

小结

本文针对内核文档中的 RISC-V 架构下需要做的内核功能进行了梳理,很多功能的资料非常的稀少,是一些前沿的技术,我根据有限的信息结合自己的理解,对功能进行了概述,做这篇文章的最大困难在于很多的应用场景找不到,导致对于功能的理解不到位,希望大家能够在后面找到各个功能的应用场景,进一步的对功能进行剖析,然后在 RISC-V 架构上进行实现,早日实现为 Linux 社区提交补丁的目标!

参考资料



Read Album:

Read Related:

Read Latest: