Kernel code review method and device integrating reinforcement learning and prompt word tuning

By integrating reinforcement learning and prompt word optimization, Linux kernel code review is conducted in stages, which solves the problems of context length limitations and insufficient cross-file logic recognition, improves the efficiency and accuracy of code review, and enables efficient discovery of complex logical defects and cross-file issues.

CN121597271APending Publication Date: 2026-03-03KYLIN CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511805900.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies for Linux kernel code review suffer from limitations in context length and insufficient ability to identify cross-file logic, resulting in insufficient review accuracy. This is especially true when reviewing large-scale, highly complex, and highly reliable code, making it difficult to detect deep-seated defects.

Method used

A method combining reinforcement learning and prompt word optimization is adopted. By receiving kernel code submission operations, patch metadata is extracted and code review tasks are established. Code review is carried out in stages. The primary review uses the primary review prompt template to generate file-level review results. The expert review combines the kernel knowledge base and the expert review prompt template to conduct a comprehensive review, generating a comprehensive review result for cross-file dependencies and timing consistency issues.

Benefits of technology

It improves the efficiency and accuracy of code review, effectively identifies complex logical defects and cross-file issues, ensures the integrity of the large language model's understanding of code semantics, and continuously improves review quality through self-optimization capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597271A_ABST
    Figure CN121597271A_ABST
Patent Text Reader

Abstract

The invention discloses a kernel code review method and device fusing reinforcement learning and prompt word tuning, and relates to the technical field of code review, and the method comprises the steps: extracting patch meta-information, building a code review task, extracting a code difference item and a necessary context thereof to form a to-be-reviewed target code segment, and carrying out the review of the to-be-reviewed target code segment; and forming a primary review prompt template, calling the code review large language model to perform primary code review, summarizing primary review results, forming a filled expert-level review prompt template in combination with the patch meta-information and the kernel knowledge base, and performing expert-level code review to generate a comprehensive review result. A code review process is constructed by applying a Boosting thought in machine learning, the code review efficiency is improved, it is ensured that single input content is located in a context window of a large language model, the integrity of code semantic understanding of the model is guaranteed, a preorder model is corrected by using a postorder model, and the code review efficiency is improved. And the discovery capability of complex logic defects and cross-file problems is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of code review technology, and in particular to a kernel code review method and apparatus that integrates reinforcement learning and prompt word optimization. Background Technology

[0002] The Linux operating system contains numerous potentially vulnerable code snippets that threaten the security and reliability of the system and its operational services. As the core of the Linux operating system, and with its codebase exceeding 40 million lines and continuing to grow, ensuring the reliability and stability of the kernel is paramount. The Linux kernel source code is continuously submitted by numerous developers. Introducing a code review process early in the submission process, after submission and before merging into the mainline, allows for rapid and effective verification of code quality. This helps identify logical errors, missing boundary conditions, concurrency vulnerabilities, and security flaws as early as possible, effectively reducing development and remediation costs.

[0003] Traditional code review relies on two main approaches: first, manual review by kernel maintainers, which is inefficient and prone to overlooking deep-seated defects due to human fatigue or knowledge gaps; second, static analysis tools (such as Sparse, Coccinelle, and Smatch) scan the source code based on predefined rules, or large language models (LLMs) are introduced to generate review results by inputting a complete patch or using git diff and leveraging the model's semantic understanding capabilities. Due to the large volume and complex logic of the Linux kernel, even when reviewing submitted code module by module, issues such as the inefficiency of manual review, fluctuations in the missed detection rate due to differences in reviewer experience, and the fixed rules of static tools result in a lack of effective detection methods for complex logic such as cross-file calls and configuration code consistency. Especially in the review of large-scale, highly complex, and highly reliable kernel code, the context length limitation of LLMs can lead to insufficient coverage, diluting the attention weight of critical modification areas, making it difficult to reach deep kernel characteristics, and ultimately affecting the accuracy of reviewing core code changes. Summary of the Invention

[0004] This invention provides a kernel code review method and apparatus that integrates reinforcement learning and prompt word optimization to solve the technical problem of insufficient kernel code review accuracy caused by context length limitations and insufficient cross-file logic recognition capabilities.

[0005] In a first aspect, embodiments of the present invention provide a kernel code review method that integrates reinforcement learning and prompt word optimization, including:

[0006] S101 receives and responds to kernel code submission operations, extracts patch metadata from the submitted kernel patches, and establishes code review tasks based on the patch metadata.

[0007] S102, Based on the code review task, extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed;

[0008] S103, Based on the target code segment to be reviewed and combined with the preset primary review prompt template, the code review big language model is invoked to conduct a primary code review and generate file-level review results;

[0009] S104: Based on the file-level review results, combined with patch metadata and the preset kernel knowledge base, extract relevant information about the current kernel patch and fill it into the preset expert-level review prompt template. Based on the filled-in expert-level review prompt template, call the code review language model to perform expert-level code review and generate a comprehensive review result.

[0010] Furthermore, S101 includes:

[0011] Based on the received kernel code submission operation, extract patch metadata from the submitted kernel patch;

[0012] Perform business analysis on patch metadata, and based on the results of the business analysis, use the patch metadata to generate code review tasks.

[0013] Furthermore, S102 includes:

[0014] Based on the code review task, parse the difference blocks of each patch code file to be reviewed, and determine the necessary context based on the difference blocks;

[0015] Based on the difference blocks, necessary context, and preset file review strategies, the target code segment to be reviewed is formed.

[0016] Furthermore, S102 also includes:

[0017] Based on the code review task, obtain the number of lines of code in the submitted kernel patch, and split the kernel patch that exceeds the preset maximum number of lines of code.

[0018] Furthermore, S103 includes:

[0019] Based on the target code segment to be reviewed, extract the fields for new / modified data, local context data, concurrency synchronization data, memory management data, error handling return code data, consistency boundary condition data, interface call constraint data, and conditional compilation relationship data.

[0020] All extracted fields are filled into the preset primary review prompt template to form the initial review input information, and then input into the code review language model for primary code review to generate file-level review results.

[0021] Furthermore, S104 includes:

[0022] The file-level review results are summarized, and the code commit description information and patch code file information of the current kernel patch are extracted based on the patch meta information. Then, the module relationship information, maintenance specification information and historical defect knowledge points of the current kernel patch are extracted based on the preset kernel knowledge base.

[0023] Using all the extracted information, fill in the preset expert-level review prompt template to form expert-level review input information, and input it into the code review big language model for cross-file integration and correction processing to obtain a comprehensive review result that includes cross-file dependency information and timing consistency issue information.

[0024] Furthermore, the method also includes:

[0025] Based on the comprehensive review results, groups are created and associated with patch pages to form a development and maintenance access point;

[0026] Utilizing the development and maintenance access portal, we receive and respond to the correction suggestions from development and maintenance personnel, and optimize the primary review prompt template and expert review prompt template based on these suggestions.

[0027] Secondly, embodiments of the present invention provide a kernel code review apparatus that integrates reinforcement learning and prompt word optimization, comprising:

[0028] The submission response module is used to receive and respond to kernel code submission operations, extract patch metadata, and establish code review tasks.

[0029] The review task parsing module is used to extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed, based on the code review task.

[0030] The primary review module is used to perform a primary code review based on the target code segment to be reviewed, combined with a preset primary review prompt template, and by calling the code review language model to generate file-level review results.

[0031] The expert-level review module is used to perform expert-level code review based on the file-level review results, combined with patch metadata, a preset kernel knowledge base, and a preset expert-level review prompt template, by calling the code review language model to generate a comprehensive review result.

[0032] Thirdly, embodiments of the present invention provide an electronic device, including:

[0033] One or more processors;

[0034] Storage device for storing one or more programs.

[0035] When the one or more programs are executed by the one or more processors, the one or more processors implement the kernel code review method that integrates reinforcement learning and prompt word tuning as described above.

[0036] Fourthly, embodiments of the present invention provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the aforementioned kernel code review method that integrates reinforcement learning and prompt word tuning.

[0037] This invention provides a kernel code review method and apparatus that integrates reinforcement learning and prompt word optimization. The method receives code submission events and automatically creates review tasks. It then extracts code differences and their necessary context at the file level, forming target code segments to be reviewed that conform to the constraints of a large language context window. A two-stage review strategy combining primary and expert reviews is employed. The primary review stage quickly scans for fundamental issues in each file, while the expert review stage utilizes a kernel knowledge base to generate expert review prompt templates, integrating and correcting the results of the primary review. By applying the Boosting concept from machine learning, a process of "receiving-parsing-primary review-generating expert templates-expert review" is constructed, improving code review efficiency. By ensuring that each input content is within the context window of the large language model, the integrity of the model's semantic understanding of the code is guaranteed. The subsequent model corrects the preceding model, effectively improving the ability to detect complex logical defects and cross-file issues. Attached Figure Description

[0038] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings:

[0039] Figure 1 This is a flowchart of a kernel code review method that integrates reinforcement learning and prompt word optimization, as described in Embodiment 1 of the present invention.

[0040] Figure 2 This is a flowchart of a kernel code review method that integrates reinforcement learning and prompt word optimization, as described in Embodiment 2 of the present invention.

[0041] Figure 3 This is a flowchart of a kernel code review method that integrates reinforcement learning and prompt word optimization, as described in Embodiment 3 of the present invention.

[0042] Figure 4 This is a schematic diagram of the structure of a kernel code review device that integrates reinforcement learning and prompt word optimization as described in Embodiment 4 of the present invention;

[0043] Figure 5This is a structural diagram of the electronic device described in Embodiment 5 of the present invention. Detailed Implementation

[0044] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.

[0045] When using large models to review kernel patches that design the kernel code, multiple kernel code files are typically involved. These files often have complex interrelationships, and kernel code differs from ordinary business logic, involving multiple complex logic codes at the operating system level. This leads to large models performing poorly in tasks involving kernel code. Furthermore, because kernel code is often quite long, inputting the entire kernel patch's code files into a large model often faces the limitation of the model's context length. An excessively long context length dilutes the attention weight of the patch's modifications. If only the git diff portion of the patch's modifications is input into the large model, the lack of a holistic understanding of the code results in unreliable results. Therefore, there is an urgent need for a code review scheme that can overcome context limitations, integrate domain knowledge, and possess self-optimization capabilities. This invention provides the following embodiments:

[0046] Example 1

[0047] Figure 1 The kernel code review method integrating reinforcement learning and prompt word optimization described in Embodiment 1 of this invention processes patch files one by one and introduces multi-stage machine learning for code review. Each stage uses pre-reviewed prompt word templates to form input information, solving problems such as cross-file association and missing key knowledge. The specific steps include:

[0048] S101 receives and responds to kernel code submission operations, extracts patch metadata from the submitted kernel patches, and establishes code review tasks based on the patch metadata.

[0049] When developers submit kernel patches or initiate pull requests to the Linux kernel repository on code hosting platforms (such as Gitee and GitHub), the system extracts patch metadata from the submitted kernel patch based on the monitored kernel code commit operation. This metadata includes: the target branch (e.g., linux-next or mainline), commit hash, commit message, and a list of modified files. Based on this metadata, code that meets business requirements is selected for the review process, and corresponding code review tasks are created. Patches on kernel code branches that are no longer under development or are only used for configuration file maintenance are filtered out. A unique identifier can also be assigned to each code review task for subsequent tracking and management.

[0050] S102, Based on the code review task, extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed.

[0051] For each modified kernel file in the kernel patch list for the code review task, version control tools (such as Git) can be used to parse and generate its code diff entries, representing the modifications made to each kernel file. To ensure that the modifications reflect complete code-level semantic information, it is also necessary to obtain the beginning and end of the modified parts relative to the function body, key variable definitions, and related conditional compilation macros, etc., as the "necessary context" for the code diff entries, forming a complete code semantic fragment, which is used as input to the review model, i.e., the target code segment to be reviewed.

[0052] S103: Based on the target code segment to be reviewed and combined with the preset primary review prompt template, the code review language model is invoked to conduct a primary code review and generate a file-level review result.

[0053] To improve the understanding of code content by the large language model for code review and ensure the accuracy of code review results, the target code segment to be reviewed is filled into the primary review prompt template using multiple preset review dimensions. The primary review prompt template contains multiple placeholders for filling in the git diff content of the patch code and the code file name. Then, the large language model (LLM, an open-source general-purpose large model) is invoked to perform a primary code review. The constructed prompt information is input along with the code segment. The large language model can independently analyze each kernel code file based on the input information and output file-level review results. The file-level review results identify problems in each kernel code file, such as memory leak risks and improper lock usage.

[0054] S104: Based on the file-level review results, combined with patch metadata and the preset kernel knowledge base, extract relevant information about the current kernel patch and fill it into the preset expert-level review prompt template. Based on the filled-in expert-level review prompt template, call the code review language model to perform expert-level code review and generate a comprehensive review result.

[0055] While file-level review results include review information for each kernel code file, they lack verification of cross-file dependencies, associations, and timing consistency. This paper first summarizes the file-level review results for all kernel code files. Then, combining patch metadata (especially commit notes, which often include patch purpose, functionality, and affected modules) and a pre-defined kernel knowledge base (stored for information such as subsystem architecture, maintainer guidelines, and historical major vulnerability CVE information), an expert-level review prompt template is generated for the current kernel patch. This template guides the large language model used for code review to analyze the entire kernel patch and related kernel modules from a global perspective. By invoking the large language model for code review, all generated file-level review results and the expert-level review prompt template are input together. The large language model performs an expert-level code review, focusing on cross-file logical integration and timing consistency verification. It identifies issues that cannot be detected by individual kernel code file reviews, such as cross-file function call timing errors and inconsistencies in global state management. Finally, a comprehensive review report is output.

[0056] This embodiment receives code submission events and automatically creates review tasks. It then extracts code differences and their necessary context at the file level, forming target code segments to be reviewed that conform to the constraints of a large language context window. A two-stage review strategy combining primary and expert reviews is employed. The primary review stage quickly scans for fundamental issues in each file, while the expert review stage utilizes the kernel knowledge base to generate expert review prompt templates, integrating and correcting the primary review results. By applying the Boosting concept from machine learning, a process of "receiving-parsing-primary review-generating expert templates-expert review" is constructed, improving code review efficiency. By ensuring that each input content is within the context window of the large language model, the completeness of the model's semantic understanding of the code is guaranteed. The use of subsequent models to correct preceding models effectively enhances the ability to detect complex logical defects and cross-file issues.

[0057] Optionally, the method further includes:

[0058] Based on the comprehensive review results, groups are created and linked to patch pages to form a development and maintenance access portal. This portal is used to receive and respond to feedback from development and maintenance personnel, and to optimize the primary and expert review prompt templates based on this feedback.

[0059] To ensure comprehensive code review, the basic and expert review prompt templates can be manually optimized, forming a closed-loop logic of "automatic code review by the model - manual optimization of prompt templates." The comprehensive review results are structured and grouped according to defect level, impact scope, location information, and suggested actions, and simultaneously published to the original kernel code patch review page, creating an entry point for developers and maintainers. When developers or maintainers find omissions or inappropriate aspects in the code review of the large language model after manually reviewing the report, they can submit correction suggestions through this entry point. The collected feedback from manually submitted correction suggestions is used to fine-tune and optimize the prompt words, instructions, and issues in the basic and expert review prompt templates. For example, if multiple feedback points out that the model has ignored a specific type of concurrency problem, the review instructions for this type of problem are strengthened in the prompt template, thereby achieving adaptive iteration of the prompt template. By introducing human feedback and adaptively iteratively optimizing the prompt templates, the entire system can continuously learn from historical review experience, continuously improve the quality of prompt templates and the relevance of the review model, forming a virtuous cycle that becomes more accurate with use, and possessing the vitality for long-term evolution.

[0060] Example 2

[0061] Figure 2 This is a flowchart of a kernel code review method integrating reinforcement learning and prompt word optimization as described in Embodiment 2 of the present invention. This embodiment is based on the above embodiment and optimized. In this embodiment, S102 is specifically optimized as follows:

[0062] Based on the code review task, parse the difference blocks of each patch code file to be reviewed, and determine the necessary context based on the difference blocks;

[0063] Based on the difference blocks, necessary context, and preset file review strategies, the target code segment to be reviewed is formed.

[0064] Accordingly, the kernel code review method that integrates reinforcement learning and prompt word optimization provided in this embodiment specifically includes:

[0065] S201 receives and responds to kernel code submission operations, extracts patch metadata from the submitted kernel patches, and establishes code review tasks based on the patch metadata.

[0066] Specifically, based on the received kernel code submission operation, patch metadata is extracted from the submitted kernel patch.

[0067] When a kernel patch is received from developers and maintainers, its metadata is extracted from the submitted kernel patch. Patch Meta InformationThis includes the target branch, commit ID, commit message, and a list of files involved in the modification. It indicates the location or function of the currently committed kernel patch, the changes made, and the kernel code files that need modification. The patch's description file, code file name, and the git diff content (i.e., patch metadata) can be obtained using the command `git show <patch commit id>`.

[0068] Perform business analysis on patch metadata, and based on the results of the business analysis, use the patch metadata to generate code review tasks.

[0069] The system primarily analyzes commit messages to determine the type of the submitted kernel patch: bug fix, feature addition, or code refactoring. Based on the analysis, it determines whether the patch should proceed to the next review stage. Kernel patch files submitted to branches where development has ceased and only configuration files are being maintained are filtered out. Only patch files from branches that meet business requirements are subject to further code review, conserving review resources. Different review task parameters can be configured for different commit types; for example, a stricter vulnerability rollback mode can be enabled for fix commits.

[0070] S202, based on the code review task, parse the difference blocks of each patch code file to be reviewed, and determine the necessary context based on the difference blocks.

[0071] Each patch code file to be reviewed is analyzed using a diff analysis tool (version control tool) to identify all specific code modification blocks (which can be determined through patch metadata, such as the @@...@@ area in the git diff output). For each modification block, not only are the newly added and deleted lines / segments of code extracted, but the entire function body to which the modification block belongs, the definitions of key data structures (such as variables) within the function body, related macro definitions, and comments at the beginning of the function are also located and extracted as "necessary context" for understanding this modification.

[0072] S203, based on the difference block and necessary context, as well as the preset file review strategy, forms the target code segment to be reviewed.

[0073] File reviews are conducted using difference blocks and necessary context. Based on pre-defined file review strategies, key, important, or sensitive code modifications are prioritized for review, considering factors such as whether they belong to core paths, involve concurrency / memory-sensitive areas, or affect external interfaces. This identifies which code files or segments conform to business logic and are poised for further review. Review priorities can also be determined based on the importance or criticality of code modifications. For example, the file review strategy includes the following rules: if a file path belongs to a core subsystem path, it is marked as high priority; if the modification involves kernel exported symbols (EXPORT_SYMBOL), memory management (file path contains / mm / ), or concurrency primitives (file path contains / kernel / locking / ), it is determined to "affect external interfaces," "involve memory-sensitive areas," or "involve concurrency synchronization," and is therefore considered a critical modification requiring focused review; if the commit message mentions specific keywords (such as "race condition," "use-after-free"), the associated files are marked as high-risk. Based on these strategies, the parsed files can be filtered and marked as critical files, and their difference blocks and necessary context can be combined to form a set of target code segments to be reviewed.

[0074] Optionally, based on the code review task, obtain the number of lines of code in the submitted kernel patch, and perform code splitting on kernel patches that exceed the preset maximum number of lines of code.

[0075] To prevent a single target code segment from being too long and exceeding the context window limit of the large model, when the amount of modification or the number of lines of code in a single kernel patch file exceeds a preset threshold, the code is split according to function boundaries, macro definitions, or logical blocks (such as a conditional compilation block #ifdef...#endif) to generate multiple target code segments that meet the context length limit of the large model.

[0076] S204: Based on the target code segment to be reviewed and combined with the preset primary review prompt template, the code review language model is invoked to conduct a primary code review and generate a file-level review result.

[0077] S205: Based on the file-level review results, combined with patch metadata and a preset kernel knowledge base, extract relevant information about the current kernel patch and fill it into a preset expert-level review prompt template. Based on the completed expert-level review prompt template, call the code review language model to perform expert-level code review and generate a comprehensive review result.

[0078] This embodiment identifies key files and code snippets requiring focused review through a preset file review strategy, improving the targeting and efficiency of code review. By parsing difference blocks and dynamically determining their necessary context, it provides the large language model for code review with the necessary semantic environment to understand the code modification intent and results, avoiding misjudgments and omissions caused by missing context, and improving the reliability of the initial review. By segmenting excessively long code, it can decompose large-scale patches that exceed the model's context window into multiple semantically independent subtasks that the model can process, solving the context window limitation problem of large language models and making them more applicable in kernel code review scenarios.

[0079] Example 3

[0080] Figure 3 This is a flowchart of a kernel code review method integrating reinforcement learning and prompt word optimization as described in Embodiment 3 of the present invention. This embodiment is based on the above embodiment and optimized. In this embodiment, S104 is specifically optimized as follows:

[0081] The file-level review results are summarized, and the code commit description information and patch code file information of the current kernel patch are extracted based on the patch meta information. Then, the module relationship information, maintenance specification information and historical defect knowledge points of the current kernel patch are extracted based on the preset kernel knowledge base.

[0082] Using all the extracted information, fill in the preset expert-level review prompt template to form expert-level review input information, and input it into the code review big language model for cross-file integration and correction processing to obtain a comprehensive review result that includes cross-file dependency information and timing consistency issue information.

[0083] Accordingly, the kernel code review method that integrates reinforcement learning and prompt word optimization provided in this embodiment specifically includes:

[0084] S301 receives and responds to kernel code submission operations, extracts patch metadata from the submitted kernel patches, and establishes code review tasks based on the patch metadata.

[0085] S302, based on the code review task, extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed.

[0086] S303: Based on the target code segment to be reviewed and combined with the preset primary review prompt template, the code review language model is invoked to conduct a primary code review and generate a file-level review result.

[0087] An optional implementation of this embodiment is to extract the following fields based on the target code segment to be reviewed: newly added / modified fields, local context fields, concurrency synchronization fields, memory management fields, error handling return code fields, consistency boundary condition fields, interface call constraint fields, and conditional compilation relationship fields.

[0088] When constructing the initial review prompt template, a structured information extraction process is used to identify and separate fields representing various meanings, functions, or modifications from the code segment. For example, by extracting the "Add / Modify" field, it can be determined which lines of code were added or modified in this submission; by extracting the local context field, it can be determined the function bodies, variable definitions, etc., surrounding the code difference block (modified code segment); and by extracting code features involving the kernel core dimension, such as: concurrency synchronization fields involving lock operations, memory management fields involving kmalloc / kfree, error code setting and return code fields, consistency boundary condition fields for loops and conditional statements, interface call constraint fields for function calls, and conditional compilation relationship fields related to #ifdef.

[0089] All extracted fields are filled into the preset primary review prompt template to form the initial review input information, and then input into the code review language model for primary code review to generate file-level review results.

[0090] The initial review prompt template contains structured instructions targeting kernel code characteristics. All the extracted fields representing different meanings are filled into the initial review prompt template, replacing the corresponding placeholders to form a clear, well-defined prompt that guides the model to review code from multiple key dimensions. By filling in the specific code content for each review dimension, the Large Language Model (LLM) can systematically and comprehensively review each kernel code file in terms of concurrency safety, memory management, and error handling during the initial review process, identifying potential problems in each kernel code file and outputting file-level review results for individual files.

[0091] S304 summarizes the file-level review results, and extracts the code submission description information and patch code file information of the current kernel patch based on the patch meta information. Then, it extracts the module relationship information, maintenance specification information, and key points of historical defect knowledge of the current kernel patch based on the preset kernel knowledge base.

[0092] The results of all file-level reviews of each kernel code file are compiled and integrated into a list. Simultaneously, the commit notes within the patch metadata are parsed to identify the target module of the patch (e.g., "optimize TCP congestion control for the network subsystem"). Furthermore, a pre-defined kernel knowledge base is consulted to obtain key information such as the architectural characteristics, maintenance specifications, and relevant historical vulnerability information of the target module corresponding to the current patch, forming a complete background knowledge system for the current patch. This includes information such as the maintainer of the module, the specific specifications followed by the code, historical CVE vulnerabilities, and their remediation methods.

[0093] S305. Using all the extracted information, fill in the preset expert-level review prompt template to form expert-level review input information, and input it into the code review big language model for cross-file integration and correction processing to obtain a comprehensive review result containing cross-file dependency information and timing consistency issue information.

[0094] By utilizing all extracted module information corresponding to the current patch, combined with the knowledge system of the current patch across various dimensions formed by the pre-set kernel knowledge base, and the list of file-level review results, all are integrated into an expert-level review prompt template. Through the pre-set structured cross-file analysis prompts in the template, the code review large language model (LLM) is guided to conduct a code review again. Through cross-file integration and correction, the integrity of the interface call chain between patch files, the consistency of global state management, and potential security vulnerabilities are identified. Finally, a comprehensive review result is generated, including the location of issues such as cross-file dependencies and timing consistency, as well as the analysis conclusions of the response impact of these issues and remediation suggestions. This result is used by developers and maintainers for reference in making decisions on the submitted current kernel code patches.

[0095] For example, the expert-level review prompt template includes the following prompt: "Based on your knowledge of the Linux kernel network subsystem domain, and considering the review results of all the above files, combined with the known CVE vulnerabilities in the knowledge base corresponding to the target kernel subsystem of the current patch, focus on reviewing whether there are similar resource management errors in the current patch. Also, analyze the newly added function calls in file A and the modified interface definitions in file B to determine if there are any risks of inconsistencies in call timing or parameter passing." The large language model can use this highly customized prompt, which incorporates domain knowledge, to perform reasoning or in-depth analysis, summarizing and correcting the file-level results of the initial code review, and outputting the final comprehensive review result. The comprehensive review result not only includes issues in each patch file but also points out dependencies between files, call timing / conditional compilation consistency, return code standardization, and other issues, and provides remediation suggestions.

[0096] This embodiment refines and structures the prompts in both the primary and expert stages of code review. In the primary review stage, specific fields from key kernel dimensions such as concurrency synchronization, memory management, and error handling are extracted and filled into the primary review prompt template. This creates a standardized review checklist with clear objectives and dimensions, guiding the model to conduct a systematic and in-depth inspection of the kernel code and avoiding potential dimensional omissions during general model reviews. In the expert review stage, not only are the primary review results summarized, but professional domain information such as module relationships, maintenance specifications, and key points of historical defects are extracted from the kernel knowledge base. This enriches the domain knowledge context of the expert review and improves the accuracy of identifying complex defects, especially those similar to historical vulnerability patterns. By integrating file-level review results, patch metadata, and kernel domain knowledge into the expert template, the code review language model can take a global perspective, strengthening its ability to discover cross-file logical relationships. This effectively identifies issues such as inconsistent interfaces, timing errors, and broken dependencies scattered across different files but logically closely related.

[0097] Example 4

[0098] Figure 4 This is a schematic diagram of the structure of a kernel code review device that integrates reinforcement learning and prompt word optimization according to Embodiment 4 of the present invention. In this embodiment, the kernel code review device that integrates reinforcement learning and prompt word optimization includes:

[0099] The submission response module 810 is used to receive and respond to kernel code submission operations, extract patch metadata, and establish code review tasks.

[0100] The review task parsing module 820 is used to extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed based on the code review task.

[0101] The primary review module 830 is used to perform a primary code review based on the target code segment to be reviewed, combined with a preset primary review prompt template, by calling the code review language model and generating file-level review results.

[0102] The expert-level review module 840 is used to perform expert-level code review by calling the code review big language model based on the file-level review results, combined with patch metadata, a preset kernel knowledge base, and a preset expert-level review prompt template, and to generate a comprehensive review result.

[0103] For example, the kernel code review device integrating reinforcement learning and prompt word optimization in this embodiment can be a boosting algorithm model, including a receive module, a review module, a generate module, a verify module, a feedback module, and an adaptive module. The receive module monitors Linux kernel patch submissions to the code hosting platform, receives the submitted kernel patches and their related submission information, and transmits them to the review service module, equivalent to the submission response module 810. The review module, at the file granularity, combines the submitted kernel patch-related content with a preset Prompt template A (primary review prompt template) and inputs it into the large language model for independent review, generating file-level review results, equivalent to the review task parsing module 820 and the primary review module 830. The generate and verify modules analyze patch filenames and commit information, call the agent to retrieve the kernel module knowledge base, combine a summary template to generate an expert Prompt template B (expert-level review prompt template), and call the large language model to perform comprehensive analysis and correction of the file-level review results based on the expert Prompt template B, generating a final review report, equivalent to the expert-level review module 840. The feedback module receives corrections from human maintainers and sends the corrections back to the large language model server. The adaptive module automatically updates template A and template B after receiving human corrections and re-executes the two-stage review process to achieve adaptive iterative optimization of the two templates.

[0104] This embodiment establishes a code review task by receiving and responding to kernel code submission operations and submitting patch metadata through a submission response module. A review task parsing module extracts code differences and necessary context from each patch file to form the target code segment to be reviewed. A primary review module performs a primary code review by calling a large-scale code review language model based on the target code segment and a primary review prompt template. An expert review module performs an expert-level code review by calling the large-scale code review language model based on the file-level review results, patch metadata, a preset kernel knowledge base, and an expert-level review prompt template, generating a comprehensive review result. By applying the Boosting concept from machine learning, a process of "receiving-parsing-primary review-generating expert-level templates-expert-level review" is constructed, improving code review efficiency. By ensuring that each input content is within the context window of the large-scale language model, the completeness of the model's understanding of code semantics is guaranteed. The use of subsequent models to correct preceding models effectively enhances the ability to detect complex logical defects and cross-file issues.

[0105] The kernel code review apparatus that integrates reinforcement learning and prompt word optimization provided in this embodiment of the invention can execute the kernel code review method that integrates reinforcement learning and prompt word optimization provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method.

[0106] Example 5

[0107] Figure 5 This is a structural diagram of an electronic device according to Embodiment 5 of the present invention. Figure 5 A block diagram is shown of an exemplary electronic device 12 suitable for implementing embodiments of the present invention. Figure 5 The electronic device 12 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0108] like Figure 5 As shown, the electronic device 12 is represented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).

[0109] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0110] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0111] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 5 Not shown; usually referred to as a "hard drive"). Although Figure 5Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.

[0112] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.

[0113] Electronic device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with the electronic device 12 / server / computer, and / or with any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, electronic device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. Figure 5 As shown, network adapter 20 communicates with other modules of electronic device 12 via bus 18. It should be understood that, although... Figure 5 As not shown, other hardware and / or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0114] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the kernel code review method that integrates reinforcement learning and prompt word optimization provided in the embodiments of the present invention.

[0115] Example 6

[0116] Embodiment 6 of the present invention also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the kernel code review method for integrating reinforcement learning and prompt word tuning as provided in the above embodiments.

[0117] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0118] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.

[0119] The program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0120] Computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0121] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.

Claims

1. A kernel code review method that integrates reinforcement learning and prompt word optimization, characterized in that, include: S101 receives and responds to kernel code submission operations, extracts patch metadata from the submitted kernel patches, and establishes code review tasks based on the patch metadata. S102, Based on the code review task, extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed; S103, Based on the target code segment to be reviewed and combined with the preset primary review prompt template, the code review big language model is invoked to conduct a primary code review and generate file-level review results; S104: Based on the file-level review results, combined with patch metadata and the preset kernel knowledge base, extract relevant information about the current kernel patch and fill it into the preset expert-level review prompt template. Based on the filled-in expert-level review prompt template, call the code review language model to perform expert-level code review and generate a comprehensive review result.

2. The method according to claim 1, characterized in that, S101 includes: Based on the received kernel code submission operation, extract patch metadata from the submitted kernel patch; Perform business analysis on patch metadata, and based on the results of the business analysis, use the patch metadata to generate code review tasks.

3. The method according to claim 1, characterized in that, S102 includes: Based on the code review task, parse the difference blocks of each patch code file to be reviewed, and determine the necessary context based on the difference blocks; Based on the difference blocks, necessary context, and preset file review strategies, key files are screened to form target code segments to be reviewed.

4. The method according to claim 1, characterized in that, S102 further includes: Based on the code review task, obtain the number of lines of code in the submitted kernel patch, and for kernel patches that exceed the preset maximum number of lines of code, split the code by function, macro or logic block.

5. The method according to claim 1, characterized in that, S103 includes: Based on the target code segment to be reviewed, extract the fields for new / modified data, local context data, concurrency synchronization data, memory management data, error handling return code data, consistency boundary condition data, interface call constraint data, and conditional compilation relationship data. All extracted fields are filled into the preset primary review prompt template to form the initial review input information, and then input into the code review language model for primary code review to generate file-level review results.

6. The method according to claim 1, characterized in that, S104 includes: The file-level review results are summarized, and the code commit description information and patch code file information of the current kernel patch are extracted based on the patch meta information. Then, the module relationship information, maintenance specification information and historical defect knowledge points of the current kernel patch are extracted based on the preset kernel knowledge base. Using all the extracted information, fill in the preset expert-level review prompt template to form expert-level review input information, and input it into the code review big language model for cross-file integration and correction processing to obtain a comprehensive review result that includes cross-file dependency information and timing consistency issue information.

7. The method according to claim 1, characterized in that, The method further includes: Based on the comprehensive review results, groups are created and associated with patch pages to form a development and maintenance access point; Utilizing the development and maintenance access portal, we receive and respond to the correction suggestions from development and maintenance personnel, and optimize the primary review prompt template and expert review prompt template based on these suggestions.

8. A kernel code review device integrating reinforcement learning and prompt word optimization, characterized in that, include: The submission response module is used to receive and respond to kernel code submission operations, extract patch metadata, and establish code review tasks. The review task parsing module is used to extract the code differences and their necessary context from each patch file to form the target code segment to be reviewed, based on the code review task. The primary review module is used to perform a primary code review based on the target code segment to be reviewed, combined with a preset primary review prompt template, and by calling the code review language model to generate file-level review results. The expert-level review module is used to perform expert-level code review based on the file-level review results, combined with patch metadata, a preset kernel knowledge base, and a preset expert-level review prompt template, by calling the code review language model to generate a comprehensive review result.

9. An electronic device, characterized in that, The electronic device includes: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the kernel code review method that integrates reinforcement learning and prompt word tuning as described in any one of claims 1-7.

10. A storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the kernel code review method for integrating reinforcement learning and prompt word tuning as described in any one of claims 1-7.