0%

Llama 3 模型群 —— Llama 团队,Meta 的 AI 分支

现代人工智能(AI)系统的核心驱动力是基础模型。本文介绍了一组名为 Llama 3 的全新基础模型系列。这是一群原生支持多语言能力、编程、推理以及工具使用的语言模型。我们最大的模型是一个拥有 4050 亿参数和最多可达 12.8 万令牌上下文窗口的密集型 Transformer。本文详细展示了 Llama 3 的大规模实证评估。我们发现,Llama 3 在众多任务上提供了可与顶尖语言模型如 GPT-4 相媲美的质量表现。我们公开发布了 Llama 3,包括预训练和后训练版本的 4050 亿参数语言模型,以及我们的 Llama Guard 3 模型,用于输入和输出的安全保障。

此外,本文还展示了我们通过组合方法将图像、视频和语音能力融入 Llama 3 的实验结果。我们观察到,这种方法在图像、视频和语音识别任务上与最先进水平竞争表现优异。然而,这些融合了多媒体能力的模型目前尚未广泛发布,因为它们仍在开发阶段。

1 引言

基础模型是指那些通用的语言、视觉、语音或其他模态的模型,旨在支撑广泛的人工智能任务。它们构成了许多现代AI系统的基石。

现代基础模型的发展历经两大核心阶段:(1) 预训练阶段,模型通过大规模数据集进行训练,采用诸如下一个词预测或图片描述等直接任务;(2) 后训练阶段,模型被微调以遵循指令、与人类偏好对齐及提升特定能力,例如编程和推理。

本文介绍了一组新的语言基础模型——Llama 3系列。Llama 3模型群原生支持多语言、编程、推理及工具运用能力。其中最大的模型是一个密集型Transformer架构,拥有4050亿参数,能在长达12.8万个令牌的上下文窗口中处理信息。模型群的每个成员在表1中列出。本文所展示的所有成果均基于Llama 3.1模型,为简洁起见,我们将统一简称其为Llama 3。

我们认为,高质量基础模型的开发有三个关键要素:数据、规模以及复杂度管理。在开发过程中,我们致力于针对这三个要素进行优化:

  • 数据:相较于Llama的早期版本(Touvron等人,2023a,b),我们在预训练和后训练中使用的数据量和质量都有所提升。这些改进包括开发更加细致的预处理和精选管道以优化预训练数据,以及建立更严格的品质保证和过滤方法来处理后训练数据。Llama 3的预训练基于约1.5万亿个多语言令牌的数据集,相比之下,Llama 2使用的数据集为1.8万亿令牌。

  • 规模: 我们在远超以往Llama模型的规模上进行了训练:我们的旗舰语言模型预训练消耗了大约3.8×10^25次浮点运算(FLOPs),几乎是Llama 2最大版本的近50倍。具体而言,我们对一个拥有4050亿可训练参数的旗舰模型进行了预训练,使用了1.56万亿文本令牌的数据集。正如基础模型的规模法则所预期的那样,我们的旗舰模型在相同的训练流程下超越了规模较小的模型。尽管规模法则表明,对于我们的训练预算,旗舰模型大约处于计算最优的规模,但我们对小型模型的训练时间也远超计算最优时长。由此产生的模型在相同的推理预算下,表现优于计算最优模型。我们还利用旗舰模型在后训练阶段进一步提升了这些小型模型的质量。

  • 管理复杂性: 我们在设计选择上力求最大化模型开发过程的可扩展性。例如,我们选择了标准的密集型Transformer模型架构(Vaswani等人,2017年),仅做轻微调整,而不是混合专家模型(MoE,Shazeer等人,2017年),以此来最大限度地提高训练稳定性。同样地,我们采用了相对简单的后训练流程,基于监督微调(SFT)、拒绝采样(RS)和直接偏好优化(DPO,Rafailov等人,2023年),而非采用更复杂的强化学习算法(如Ouyang等人,2022年;Schulman等人,2017年),后者往往稳定性较差且难以规模化。

我们的工作成果是Llama 3:一组包含三个多语言模型的“羊驼群”,分别具有80亿、700亿和4050亿个参数。我们对Llama 3在涵盖广泛语言理解任务的关键基准数据集上的性能进行了评估。此外,我们还进行了深入的人类评估,将Llama 3与竞争对手的模型进行比较。旗舰Llama 3模型在关键基准上的性能概览见表2。实验评估表明,我们的旗舰模型在多种任务上与诸如GPT-4(OpenAI,2023a)等领先语言模型的表现相当,并接近达到当前技术前沿。我们的小型模型也是同类最佳,优于具有相似参数数量的替代模型(Bai等人,2023;Jiang等人,2023)。Llama 3相比其前身在有用性和无害性之间取得了更好的平衡(Touvron等人,2023b)。我们将在第5.4节详细介绍Llama 3的安全性分析。

我们正根据更新版的Llama 3社区许可协议公开发布所有三个Llama 3模型;详情请见https://llama.meta.com。这包括我们4050亿参数语言模型的预训练和后训练版本,以及输入和输出安全性的Llama Guard模型新版本(Inan等人,2023)。我们希望通过旗舰模型的开放发布激发研究界的创新浪潮,并加速负责任地迈向人工智能(AGI)总体发展的道路。

作为Llama 3开发过程的一部分,我们还开发了模型的多模态扩展,使模型具备图像识别、视频识别和语音理解的能力。这些多模态模型仍在积极开发中,尚未准备发布。除了语言建模的结果外,本文还展示了我们使用这些多模态模型的初步实验结果。

2 总体概述

Llama 3的模型架构如图1所示。我们Llama 3语言模型的开发包含两个主要阶段:

语言模型预训练

我们首先将大型多语言文本语料库转换为离散的令牌,并在此基础上预训练一个大型语言模型(LLM),以执行下一个令牌的预测任务。在语言模型预训练阶段,模型学习语言结构,并从其“阅读”的文本中获取大量关于世界的知识。为了有效实现这一目标,预训练是在大规模数据上进行的:我们使用8K令牌的上下文窗口,在15.6万亿个令牌的数据集上预训练一个拥有4050亿参数的模型。这一标准预训练阶段之后是持续预训练阶段,将支持的上下文窗口扩大到128K令牌。详情请参阅第3节。

语言模型后训练

预训练后的语言模型虽然对语言有了丰富的理解,但还不能遵循指令或像我们期望的助手那样行为。我们通过几轮人类反馈对其校准,每轮涉及在指令调优数据上的监督微调(SFT)和直接偏好优化(DPO,Rafailov等人,2024)。在这一后训练阶段,我们还整合了新能力,比如工具使用,并在编码、推理等领域观察到了显著的进步。详情请见第4节。最后,安全缓解措施也在后训练阶段被整合进模型中,具体细节在第5.4节描述。

最终产生的模型具备一系列丰富的能力。它们能够至少用八种语言回答问题、编写高质量的代码、解决复杂的推理问题,并能开箱即用或以零样本方式使用工具。

我们还进行了实验,通过一种组合方法向Llama 3添加了图像、视频和语音处理能力。我们研究的方法包括图28中所示的三个额外阶段:

多模态编码器预训练

我们分别为图像和语音训练独立的编码器。我们的图像编码器在大量的图像-文本对上进行训练,这教会模型视觉内容与其自然语言描述之间的关系。语音编码器则采用自监督方法进行训练,该方法会遮蔽语音输入的部分内容,并尝试通过离散令牌表示来重建被遮蔽的部分,从而使模型学习到语音信号的结构。图像编码器的详细信息请参见第7节,语音编码器的详细信息请参见第8节。

视觉适配器训练

我们训练了一个适配器,将预训练的图像编码器集成到预训练的语言模型中。该适配器包含一系列交叉注意力层,用于将图像编码器的表示馈入语言模型。适配器在文本-图像对上进行训练,这使得图像表示与语言表示对齐。在适配器训练期间,我们也会更新图像编码器的参数,但有意不更新语言模型的参数。我们还在图像适配器的基础上,使用配对的视频-文本数据训练了一个视频适配器,使模型能够在帧间聚合信息。更多细节请参阅第7节。

语音适配器训练

最后,我们通过一个适配器将语音编码器集成到模型中,该适配器将语音编码转换为可以直接输入到微调过的语言模型中的令牌表示。适配器和编码器的参数在监督微调阶段联合更新,以实现高质量的语音理解能力。在语音适配器训练期间,我们不对语言模型进行更改。我们还集成了一个文本转语音系统。详细信息请参见第8节。

我们的多模态实验产生了能够识别图像和视频内容,并通过语音接口支持交互的模型。这些模型仍处于开发阶段,尚未准备好发布。

3 预训练

语言模型预训练包括以下步骤:(1) 大规模训练语料库的策划与过滤,(2) 模型架构的开发及确定模型大小的相应规模法则,(3) 大规模高效预训练技术的开发,以及(4) 预训练方案的制定。下面我们将逐一介绍这些组成部分。

3.1 预训练数据

我们从包含截至2023年底知识的多种数据源创建语言模型预训练数据集。对每个数据源应用多种去重方法和数据清洗机制,以获得高质量的令牌。我们移除含有大量个人可识别信息(PII)的领域,以及已知含有成人内容的领域。

3.1.1 网络数据策划

我们使用的大部分数据来源于网络,以下是我们的数据清洗流程。

PII和安全过滤

除其他缓解措施外,我们实施了旨在移除可能含有不安全内容或大量PII的网站数据的过滤器,移除按照Meta安全标准被评为有害的域名,以及已知含有成人内容的域名。

文本提取与清洗

我们处理非截断网页文档的原始HTML内容,以提取高质量且多样化的文本。为此,我们构建了一个自定义解析器,用于提取HTML内容,并优化去除模板内容的精确度和内容召回率。我们通过人工评估来验证解析器的质量,将其与优化文章类内容的第三方HTML解析器进行对比,结果表现良好。我们仔细处理含有数学和代码内容的HTML页面,以保留这类内容的结构。我们保留图像alt属性文本,因为在数学内容常以预渲染图像形式出现时,数学内容也会在alt属性中提供。我们实验性地评估了不同的清洗配置,发现相比于纯文本,Markdown格式对主要在网页数据上训练的模型性能不利,因此我们移除了所有Markdown标记。

去重

我们在URL、文档和行级别上应用了几轮去重:

  • URL级去重:在整个数据集中执行URL级别的去重,为每个URL对应的页面保留最新版本。
  • 文档级去重:在整个数据集上执行全局MinHash(Broder, 1997)去重,移除近似重复的文档。
  • 行级去重:执行类似于ccNet(Wenzek等人,2019)的激进行列级去重。移除在每个3000万文档桶中出现超过6次的行。尽管手动定性分析显示,行级去重不仅去除了来自各网站的剩余模板内容(如导航菜单、Cookie警告),也可能移除了频繁出现的高质量文本,但我们的实证评估显示了显著的性能提升。
启发式过滤

我们开发启发式方法来删除更多低质量文档、异常值和重复内容过多的文档。一些启发式例子包括:

  • 我们采用重复n-gram覆盖率比例(Rae等人,2021)来删除包含重复内容如日志或错误信息的行。这些行可能非常长且独特,因此无法通过行去重过滤。
  • 我们使用“脏词”计数(Raffel等人,2020)来过滤不受域名屏蔽列表覆盖的成人网站。
  • 我们使用令牌分布的Kullback-Leibler散度来过滤与训练语料库分布相比含有过多异常令牌的文档。
基于模型的质量过滤

我们进一步尝试应用多种基于模型的质量分类器来筛选高质量的文本片段。这包括使用快速分类器,如fasttext(Joulin等人,2017年),该分类器被训练以识别给定文本是否会被维基百科引用(Touvron等人,2023a),以及计算密集型的Roberta-based分类器(Liu等人,2019a),这些分类器在Llama 2的预测数据上进行训练。为了基于Llama 2训练一个质量分类器,我们创建了一个经过清理的网页文档训练集,并描述了质量要求,然后指导Llama 2的聊天模型判断文档是否满足这些要求。出于效率考虑,我们使用DistilRoberta(Sanh等人,2019年)为每个文档生成质量分数。我们通过实验评估了不同质量过滤配置的有效性。

代码与推理数据处理

类似于DeepSeek-AI等(2024年)的工作,我们构建了针对特定领域的管道,用于提取包含代码和数学相关内容的网页。具体而言,无论是代码还是推理分类器,都是基于DistilledRoberta模型,该模型在由Llama 2标注的网络数据上进行训练。与上述通用质量分类器不同,我们进行了提示调整,以便针对性地搜索包含数学推导、STEM领域中的推理以及自然语言中穿插的代码的网页。鉴于代码和数学的令牌分布与自然语言有显著差异,这些管道实现了领域特定的HTML抽取、定制的文本特征和过滤启发式规则。

多语言数据处理

与上述针对英语的数据处理流程相仿,我们也实施了过滤机制,以移除可能包含个人身份信息(PII)或不安全内容的网站数据。我们的多语言文本处理管道具备以下独特特性:

• 利用基于fasttext的语言识别模型,将文档归类到176种语言中。
• 针对每种语言的数据,分别在文档级别和行级别执行去重复操作。
• 应用针对各语言的特定启发式规则及基于模型的过滤器,以排除低质量文档。

此外,我们采用基于多语言Llama 2的分类器对多语言文档进行质量排序,确保优先考虑高质量内容。通过实验确定预训练中使用的多语言令牌数量,以平衡模型在英语和多语言基准测试上的性能表现。

3.1.2 数据组合的确定

为了获得高质量的语言模型,仔细决定预训练数据混合中不同数据来源的比例至关重要。我们确定此数据混合的主要工具是知识分类和规模法则实验。

知识分类。 我们开发了一种分类器,用于分类网络数据中所含信息的类型,以便更有效地确定数据组合。我们利用该分类器对网络上过度代表的数据类别进行下采样,例如艺术与娱乐类内容。

数据混合的规模法则。 为确定最佳数据组合,我们执行规模法则实验,即在不同的数据组合上训练多个小型模型,并以此预测大型模型在该组合上的性能(参见第3.2.1节)。我们为不同的数据组合多次重复这一过程,以选择新的数据组合候选。随后,在这个候选数据组合上训练一个更大的模型,并评估其在几个关键基准测试上的表现。

数据组合概述。 最终的数据组合大约包含50%的一般知识令牌,25%的数学与推理令牌,17%的代码令牌,以及8%的多语言令牌。

3.1.3 数据退火

实验上,我们发现对少量高质量的代码和数学数据进行退火(参见第3.4.3节)可以提升预训练模型在关键基准上的性能。类似于Li等人(2024b),我们在特定领域内对高质量数据进行上采样的数据混合上执行退火。我们的退火数据中不包含任何来自常用基准测试的训练集。这使我们能够评估Llama 3真正的少量样本学习能力和跨领域的泛化能力。

效仿OpenAI(2023a),我们在GSM8k(Cobbe等人,2021)和MATH(Hendrycks等人,2021b)训练集上进行退火,并评估退火的效果。我们发现,退火使预训练的Llama 3 8B模型在GSM8k和MATH验证集上的性能分别提高了24.0%和6.4%。然而,对于405B模型,改进微乎其微,表明我们的旗舰模型拥有强大的上下文内学习和推理能力,不需要特定领域的训练样本即可获得强劲的性能。

利用退火评估数据质量。 类似于Blakeney等人(2024),我们发现退火使我们能够评判小规模领域特定数据集的价值。我们通过线性地将一个已训练50%的Llama 3 8B模型的学习率退火至0,处理400亿个令牌,以此来衡量这类数据集的价值。在这些实验中,新数据集被赋予30%的权重,剩余70%的权重分配给默认数据混合。相比为每个小数据集执行规模法则实验,使用退火评估新数据源更为高效。

3.2 模型架构

Llama 3采用了标准的稠密Transformer架构(Vaswani等人,2017年)。就模型架构而言,它与Llama及Llama 2(Touvron等人,2023a,b)并无显著偏离;我们的性能提升主要得益于数据质量和多样性的改进,以及训练规模的扩大。

相较于Llama 3,我们做出了一些较小的修改:

• 我们采用了分组查询注意力(Grouped Query Attention,简称GQA;Ainslie等人,2023年),并设置了8个键值头,以提高推理速度并减少解码期间键值缓存的大小。
• 我们使用了一种注意力掩码,防止序列中不同文档之间的自注意力。我们发现在标准预训练过程中,这一改动的影响有限,但在针对非常长序列的持续预训练中,我们发现它非常重要。

– BIOS boot done –
[ 0.000000] Booting Linux on physical CPU 0x0100000000 [0x410fd8e0]
[ 0.000000] Linux version 6.6.7+ (root@j66e01291.sqa.eu95) (gcc (GCC) 10.2.1 20200825 (Alibaba 10.2.1-3 2.17), GNU ld version 2.35-12.2.alios7) #13 SMP Wed Feb 21 15:11:08 CST 2024
[ 0.000000] KASLR disabled due to lack of seed
[ 0.000000] earlycon: pl11 at MMIO 0x000000002a401000 (options ‘’)
[ 0.000000] printk: bootconsole [pl11] enabled
[ 0.000000] efi: need at least one option
[ 0.000000] Malformed early option ‘efi’
[ 0.000000] efi: EFI v2.7 by EDK II
[ 0.000000] efi: SMBIOS 3.0=0xf9810000 ACPI 2.0=0xf4530018 MEMATTR=0xf7ca7018 INITRD=0xf40f7f18 MEMRESERVE=0xf40f7f98
[ 0.000000] ACPI: Early table checksum verification disabled
[ 0.000000] ACPI: RSDP 0x00000000F4530018 000024 (v02 PTG )
[ 0.000000] ACPI: XSDT 0x00000000F453FE98 000094 (v01 PTG PTG01 00000000 “ “ 01000013)
[ 0.000000] ACPI: FACP 0x00000000F453FB98 000114 (v06 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: DSDT 0x00000000F4537518 006A14 (v02 PTG PTG01 00000000 INTL 20230331)
[ 0.000000] ACPI: AGDI 0x00000000F453FF98 000030 (v00 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: DBG2 0x00000000F453FA98 00005E (v00 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: GTDT 0x00000000F453E998 000104 (v03 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: MCFG 0x00000000F453FE18 00003C (v01 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SLIT 0x00000000F453F998 00003C (v01 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SPCR 0x00000000F453FA18 000050 (v02 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SDEI 0x00000000F453FD18 000024 (v01 PTG PTG01 00000000 INTL 20230331)
[ 0.000000] ACPI: APIC 0x00000000F453F598 000334 (v05 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SRAT 0x00000000F453EB18 000140 (v03 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: IORT 0x00000000F453F318 00012C (v00 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: PPTT 0x00000000F453EC98 0003E6 (v02 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: MPAM 0x00000000F4530098 0004A4 (v00 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SPMI 0x00000000F453FD98 000041 (v05 PTG PTG01 00000000 PTG 20200717)
[ 0.000000] ACPI: SPCR: console: pl011,mmio32,0x2a400000,115200
[ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x80000000-0xffffffff]
[ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x900000000-0x187fffffff]
[ 0.000000] NUMA: NODE_DATA [mem 0x1877fc1b00-0x1877fc6fff]

阅读全文 »

This is an example about dummy syscall test in linux kernel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <sys/utsname.h>
#include <errno.h>
#include <time.h>
#include <sched.h>
#include <stdalign.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <syscall.h>
#include <signal.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <sys/wait.h>


int main(void)
{
unsigned long i = 0;
int nr_mysyscall;
struct utsname buffer;
struct timespec tstart={0,0}, tend={0,0};

errno = 0;
if (uname(&buffer) != 0) {
perror("uname");
exit(EXIT_FAILURE);
}

if (buffer.release[0] == '5') {
printf("5.10 kernel\n");
clock_gettime(CLOCK_MONOTONIC, &tstart);
for (i=0; i<30000000; i++)
syscall(335);
clock_gettime(CLOCK_MONOTONIC, &tend);
printf("took about %.5f seconds\n",
((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) -
((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec));
} else {
printf("4.19 kernel\n");
clock_gettime(CLOCK_MONOTONIC, &tstart);
for (i=0; i<30000000; i++)
syscall(438);
clock_gettime(CLOCK_MONOTONIC, &tend);
printf("took about %.5f seconds\n",
((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) -
((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec));

}

return 0;
}

This article collects prompts for Stable Diffusion’s automatic drawing tool.

1
2
3
1girl, the whole body, standing, thin waist, slender waist, fully naked, (completely nude:1.2), collarbone, medium breasts, showing breasts, round breasts, nipples, glowing nipples, pussy, vaginal, no bra, no panties, no bikini, smile, outdoor, best quality ,masterpiece, illustration, an extremely delicate and beautiful, extremely detailed ,CG ,unity ,8k wallpaper, Amazing, finely detail, best quality, official art, extremely detailed CG unity 8k wallpaper, absurdres, huge filesize , ultra-detailed, highres, beautiful detailed girl, extremely detailed eyes and face, beautiful detailed eyes, light on face, realistic, perfect fingers, <perfectPussy_newb0001:1> , <breastinclassBetter_v13:0.5>

multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, colorful tongue, black tongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game, 3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawn feet, fused feet, missing feet, extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves, fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly, bad face, fused face, poorly drawn face, cloned face, big face, long face, bad eyes, fused eyes poorly drawn eyes, extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples, poorly drawn nipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs, missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand, more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs, extra calf, fused calf, extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth, fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too long tongue, black tongue, big mouth, cracked mouth, bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, bad pantie, yellow teeth, thick lips, bad cameltoe, colorful cameltoe, bad asshole, poorly drawn asshole, fused asshole, missing asshole, bad anus, bad pussy, bad crotch, bad crotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch, fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorly drawn crotch seam, bad thigh gap, missing thigh gap, fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone, liquid collarbone, strong girl, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles, split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored, safety panties, safety knickers, beard, furry ,pony, pubic hair, mosaic, excrement, faeces, shit

Kprobes in Linux Kernel

Kprobes is a dynamic tracing and analysis tool in the Linux kernel, which allows developers to insert breakpoints into running kernel code without stopping or recompiling the kernel. Kprobes is designed to minimize its impact on the performance of the target code.

kprobe_insn_page

kprobe_insn_page is a memory page used to store copies of the original instructions that are replaced by Kprobes breakpoints. It serves as a cache for these instructions so that they can be executed without affecting the original code location.

ModR/M Byte

The ModR/M byte is part of the x86 instruction set architecture, providing a compact way to encode certain instructions that involve registers and memory operands. The ModR/M byte is used in combination with other bytes to specify the complete behavior of an instruction.

Kprobes Event Handling

Kprobes inserts a breakpoint (e.g., INT3 instruction) at the target code address. When the breakpoint is triggered, the processor transfers the execution to a predefined Kprobes handler function. The handler function modifies the instruction pointer register (regs->ip) to point to the memory location containing the copy of the original instruction. The CPU executes the original instruction copy, triggering the INT3 breakpoint again, allowing Kprobes to take control once more before resuming execution.

kprobe_ctlblk

kprobe_ctlblk (Kprobe Control Block) is a kernel data structure used to store control information for each CPU during Kprobes event handling. Each CPU has an instance of kprobe_ctlblk, which contains temporary state and information such as:

  • Status flags indicating the current state of Kprobes event handling.
  • Saved register values, such as the instruction pointer register (ip).
  • Other temporary data related to the Kprobes handler function.

The main purpose of kprobe_ctlblk is to save and restore CPU register values and other context information during Kprobes event handling.

KPROBE_HIT_SS

KPROBE_HIT_SS is a Kprobes status flag that indicates a Single Step Trap was triggered during Kprobe event handling on x86 architecture. This flag is used to signify this situation so that the Kprobes handler function can correctly handle the single step trap.

When a single step trap is detected during Kprobes event handling, the KPROBE_HIT_SS flag is set to true. The Kprobes handler function can then use this flag to determine how to handle the single step trap, such as whether specific actions need to be performed or how to resume execution after event handling is complete.

In summary, the KPROBE_HIT_SS flag is used during Kprobes event handling to indicate a triggered single step trap so that the Kprobes handler function can correctly handle the situation. This helps ensure that target code execution can continue without being affected by Kprobes after the handler function is complete.

We can lauch vm through qemu quickly. These steps are:

1
qemu-system-x86_64 -nographic -enable-kvm -cpu host,+x2apic,pmu=on -smp 32,sockets=2,cores=16,threads=1 -m 64G -device virtio-net-pci,netdev=n1 -netdev user,id=n1,hostfwd=tcp::1688-:22 -drive file=/home/zhaoguanjun.zgj/aliyun_3_x64_20G_nocloud_alibase_20211025.qcow2,if=none,id=virtio-disk0 -device virtio-blk-pci,drive=virtio-disk0 -monitor pty -cpu host -machine q35 -drive file=/dev/sdb1,if=none,id=drive-virtio-disk2,format=raw,cache=none,aio=native -device virtio-blk-pci,scsi=off,num-queues=4,config-wce=off,drive=drive-virtio-disk2,id=virtio-disk1 -gdb tcp::1111

Some params and the related meanings:

  • -nographic, Disable graphical output and redirect serial I/Os to console
  • -daemonize, Daemonize the qemu thread

If you want to add a mdev device, you should:

1
2
3
1. uuid # For example, a6613d90-c944-11ed-a67e-00e04c84d2c4
2. echo "a6613d90-c944-11ed-a67e-00e04c84d2c4" > /sys/bus/pci/devices/0000:6d:00.0/mdev_supported_types/dlb2-dlb/create
3. add "-device vfio-pci,sysfsdev=/sys/bus/pci/devices/0000:6d:00.0/a6613d90-c944-11ed-a67e-00e04c84d2c4/" to the qemu boot line

Live migration from A to B:

1
2
3
4
5
6
7
8
A: Launch VM, source
- qemu-system-x86_64 -nographic -enable-kvm -cpu host,+x2apic,pmu=on -smp 32,sockets=2,cores=16,threads=1 -m 64G -device virtio-net-pci,netdev=n1 -netdev user,id=n1,hostfwd=tcp::1688-:22 -drive file=/home/zhaoguanjun.zgj/aliyun_3_x64_20G_nocloud_alibase_20211025.qcow2,if=none,id=virtio-disk0 -device virtio-blk-pci,drive=virtio-disk0 -monitor pty -cpu host -machine q35 -drive file=/dev/sdb1,if=none,id=drive-virtio-disk2,format=raw,cache=none,aio=native -device virtio-blk-pci,scsi=off,num-queues=4,config-wce=off,drive=drive-virtio-disk2,id=virtio-disk1 -gdb tcp::1111

B: Migrate to, destination
- qemu-system-x86_64 -nographic -enable-kvm -cpu host,+x2apic,pmu=on -smp 32,sockets=2,cores=16,threads=1 -m 64G -device virtio-net-pci,netdev=n1 -netdev user,id=n1,hostfwd=tcp::1688-:22 -drive file=/home/zhaoguanjun.zgj/aliyun_3_x64_20G_nocloud_alibase_20211025.qcow2,if=none,id=virtio-disk0 -device virtio-blk-pci,drive=virtio-disk0 -monitor pty -cpu host -machine q35 -drive file=/dev/sdb1,if=none,id=drive-virtio-disk2,format=raw,cache=none,aio=native -device virtio-blk-pci,scsi=off,num-queues=4,config-wce=off,drive=drive-virtio-disk2,id=virtio-disk1 -gdb tcp::1111 -incoming tcp:(A IP):(A PORT)
- ./qemu-system-x86_64 -monitor stdio
(qemu) migrate tcp:(A IP):(A PORT)
(qemu) info migrate

Then, if migration status echo ‘completed’, the VM migrate from A to B successfully.

A example about how to use docker to run your task. That is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1. Pull the images or repository from registry
docker pull reg.docker.alibaba-inc.com/alinux/kdevel-x64:3.230303.1

2. List the images
docker images

3. Start the container and interact through terminal
docker run -itd --net host -v /mnt/sdb/zhaoguanjun.zgj/:/root/workspace reg.docker.alibaba-inc.com/alinux/kdevel-x64 bash

4. List all the containers
docker ps -a

5. Execute the container
docker exec -it [container-id] bash

6. Exit the container
Execute 'exit' in docker terminal

7. Kill the container
docker kill [container-id]

8. Remove the container or images
docker rm [container-id]

This document will be continuously improved.

这是一篇加密文章,需要密码才能继续阅读。
阅读全文 »

做梦我也被公司干掉了,不像其他人收到HRG正式谈话通知,只有小智(化名)口头说他记得也有我。

一开始没有当回事,因为觉得不可能自己不可能被C,晚一些的时候发现内网权限突然消失。于是联系小丁(化名)和师兄,他们都觉得非常震惊。

阅读全文 »