Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Intel RDT non-contiguous CBM support#830

Merged
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
Avenger-285714:intel_RDT_CBM
Jun 2, 2025
Merged

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Intel RDT non-contiguous CBM support#830
opsiff merged 4 commits into
deepin-community:linux-6.6.yfrom
Avenger-285714:intel_RDT_CBM

Conversation

@Avenger-285714
Copy link
Copy Markdown
Member

@Avenger-285714 Avenger-285714 commented Jun 1, 2025

bugzilla: https://bugzilla.openanolis.cn/show_bug.cgi?id=8085

About Intel RDT non-contiguous CBM support:

GNR and SRF support L3/L2 non-contiguous way masks. Linux kernel changes is needed to support this.

Legacy RDT only support contiguous bits in L3/L2 CAT Cache Bit Mask (CBM) when allocating L3/L2 cache. For example, 0x111 is a valid bit mask but 0x101 is an invalid bit mask. This is limitation of legacy RDT hardware. It limits user's capability to allocate L3/L2 cache efficiently and cause poor performance.

With non-contiguous bits in L3/L2 CAT, we can allocate L3/L2 cache in various ways and utilize the cache efficiently and improve user application performance.

About the patches:
There are 4 backported upstream patches:
aaa5fa3 Documentation/x86: Document resctrl's new sparse_masks
4dba8f1 x86/resctrl: Add sparse_masks file in info
0e3cd31 x86/resctrl: Enable non-contiguous CBMs in Intel CAT
39c6eed x86/resctrl: Rename arch_has_sparse_bitmaps

Passed tests:
Intel RDT non-contiguous CBM CAT tests: passed.

Link: https://gitee.com/anolis/cloud-kernel/pulls/2740

Summary by Sourcery

Enable and expose Intel RDT hardware support for non-contiguous cache bitmasks by backporting upstream sparse_masks functionality, updating validation logic, renaming internal fields, and updating documentation.

New Features:

  • Support non-contiguous cache bitmasks (CBMs) for Intel L2/L3 CAT based on CPUID sparse_masks capability
  • Expose a new "sparse_masks" info file under resctrl to report hardware support for non-contiguous CBMs

Enhancements:

  • Rename internal field from arch_has_sparse_bitmaps to arch_has_sparse_bitmasks
  • Update CBM validation to allow or reject non-contiguous bitmasks according to the new flag

Documentation:

  • Document the resctrl sparse_masks file and its semantics in the x86 resctrl documentation

Tests:

  • Add and pass Intel RDT non-contiguous CBM CAT tests

maciejwieczorretman and others added 4 commits June 2, 2025 01:17
ANBZ: #8085

commit 39c6eed upstream.

Rename arch_has_sparse_bitmaps to arch_has_sparse_bitmasks to ensure
consistent terminology throughout resctrl.

Intel-SIG: commit 39c6eed x86/resctrl: Rename arch_has_sparse_bitmaps.
Incremental backporting patches for Intel RDT on Intel Xeon platform.

Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Peter Newman <peternewman@google.com>
Link: https://lore.kernel.org/r/e330fcdae873ef1a831e707025a4b70fa346666e.1696934091.git.maciej.wieczor-retman@intel.com
[ Xiaochen Shen: amend commit log ]
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
ANBZ: #8085

commit 0e3cd31 upstream.

The setting for non-contiguous 1s support in Intel CAT is
hardcoded to false. On these systems, writing non-contiguous
1s into the schemata file will fail before resctrl passes
the value to the hardware.

In Intel CAT CPUID.0x10.1:ECX[3] and CPUID.0x10.2:ECX[3] stopped
being reserved and now carry information about non-contiguous 1s
value support for L3 and L2 cache respectively. The CAT
capacity bitmask (CBM) supports a non-contiguous 1s value if
the bit is set.

The exception are Haswell systems where non-contiguous 1s value
support needs to stay disabled since they can't make use of CPUID
for Cache allocation.

Intel-SIG: commit 0e3cd31 x86/resctrl: Enable non-contiguous CBMs in Intel CAT.
Incremental backporting patches for Intel RDT on Intel Xeon platform.

Originally-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Peter Newman <peternewman@google.com>
Link: https://lore.kernel.org/r/1849b487256fe4de40b30f88450cba3d9abc9171.1696934091.git.maciej.wieczor-retman@intel.com
[ Xiaochen Shen: amend commit log ]
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
ANBZ: #8085

commit 4dba8f1 upstream.

Add the interface in resctrl FS to show if sparse cache allocation
bit masks are supported on the platform. Reading the file returns
either a "1" if non-contiguous 1s are supported and "0" otherwise.
The file path is /sys/fs/resctrl/info/{resource}/sparse_masks, where
{resource} can be either "L2" or "L3".

Intel-SIG: commit 4dba8f1 x86/resctrl: Add sparse_masks file in info.
Incremental backporting patches for Intel RDT on Intel Xeon platform.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Peter Newman <peternewman@google.com>
Link: https://lore.kernel.org/r/7300535160beba41fd8aa073749ec1ee29b4621f.1696934091.git.maciej.wieczor-retman@intel.com
[ Xiaochen Shen: amend commit log ]
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
ANBZ: #8085

commit aaa5fa3 upstream.

The documentation mentions that non-contiguous bit masks are not
supported in Intel Cache Allocation Technology (CAT).

Update the documentation on how to determine if sparse bit masks are
allowed in L2 and L3 CAT.

Intel-SIG: commit aaa5fa3 Documentation/x86: Document resctrl's new sparse_masks.
Incremental backporting patches for Intel RDT on Intel Xeon platform.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Peter Newman <peternewman@google.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Peter Newman <peternewman@google.com>
Link: https://lore.kernel.org/r/3e9610997164f648e15c5c2e90d4944ce36504fe.1696934091.git.maciej.wieczor-retman@intel.com
[ Xiaochen Shen: amend commit log ]
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 1, 2025

Reviewer's Guide

Introduce Intel RDT non-contiguous CBM support by adding a new sparse_masks sysfs attribute, parsing the noncontiguous bit from CPUID, updating validation logic to accept sparse masks when supported, refactoring internal flags and data structures, and updating documentation accordingly.

Sequence Diagram for Reading sparse_masks Sysfs Attribute

sequenceDiagram
    actor User
    participant FS as "Kernel (sysfs)"
    participant RDT as "RDT Subsystem"

    User->>+FS: Read /sys/fs/resctrl/.../info/L<N>/sparse_masks
    FS->>+RDT: rdt_has_sparse_bitmasks_show(of, seq, v)
    RDT-->>RDT: Get resctrl_schema s = of->kn->parent->priv
    RDT-->>RDT: Get rdt_resource r = s->res
    RDT-->>RDT: Access r->cache.arch_has_sparse_bitmasks
    RDT->>-FS: Output value of arch_has_sparse_bitmasks (0 or 1)
    FS->>-User: Return "0" or "1"
Loading

Sequence Diagram: Initializing Non-Contiguous CBM Support (Intel)

sequenceDiagram
    participant KernelInit as "Kernel (RDT Init for Intel CPU)"
    participant CPUHardware as "CPU Hardware"

    KernelInit->>+KernelInit: Call rdt_get_cache_alloc_cfg(idx, r)
    KernelInit->>CPUHardware: Execute CPUID instruction (EAX=0x10, ECX=idx)
    CPUHardware-->>KernelInit: Return EAX, EBX, ECX, EDX registers
    KernelInit->>KernelInit: Parse ECX.split.noncont from returned ECX value
    KernelInit->>KernelInit: Set r->cache.arch_has_sparse_bitmasks = ecx.split.noncont
    KernelInit-->>KernelInit: Continue rdt_resource cache configuration
Loading

Sequence Diagram for CBM Validation with Non-Contiguous Mask Support

sequenceDiagram
    participant UserProcess as "User/Process (writing CBM)"
    participant RDT as "RDT Subsystem (ctrlmondata.c)"

    UserProcess->>+RDT: Attempt to configure CBM via schemata file
    RDT->>+RDT: cbm_validate(buf, data, r)
    RDT-->>RDT: Parse CBM string to get 'val'
    RDT-->>RDT: Determine if 'val' is non-contiguous
    RDT-->>RDT: Let is_mask_non_contiguous = (find_next_bit(&val, cbm_len, zero_bit) < cbm_len)
    alt is_mask_non_contiguous AND NOT r->cache.arch_has_sparse_bitmasks
        RDT-->>RDT: Mask is non-contiguous AND hardware does not support it
        RDT-->>RDT: Report error "The mask %lx has non-consecutive 1-bits"
        RDT-->>RDT: Validation fails (return false)
    else
        RDT-->>RDT: Mask is contiguous OR hardware supports non-contiguous masks
        RDT-->>RDT: (Perform other CBM validations if any)
        RDT-->>RDT: Validation passes (return true, if other checks pass)
    end
    RDT->>-UserProcess: Acknowledge or reject CBM configuration
Loading

Class Diagram for Updated RDT Data Structures

classDiagram
    class resctrl_cache {
        +unsigned int cbm_len
        +unsigned int min_cbm_bits
        +unsigned int shareable_bits
        +bool arch_has_sparse_bitmasks
        +bool arch_has_per_cpu_cfg
    }

    class CPUID_0x10_x_ECX_Split {
        <<struct>>
        +unsigned int reserved_bits
        +unsigned int noncont_bit
    }

    class cpuid_0x10_x_ecx {
        <<union>>
        +CPUID_0x10_x_ECX_Split split
        +unsigned int full
    }

    cpuid_0x10_x_ecx ..> CPUID_0x10_x_ECX_Split : contains

    class rdt_resource {
        +resctrl_cache cache
        # other fields...
    }
    rdt_resource *-- resctrl_cache : contains
Loading

File-Level Changes

Change Details Files
Expose sparse bitmask support via new sysfs interface
  • Add rdt_has_sparse_bitmasks_show seq_show callback
  • Register 'sparse_masks' attribute in resctrl info files
arch/x86/kernel/cpu/resctrl/rdtgroup.c
Allow non-contiguous CBMs in validation logic
  • Update comments to reflect CPUID-based detection on Intel
  • Switch validation to use arch_has_sparse_bitmasks flag
arch/x86/kernel/cpu/resctrl/ctrlmondata.c
Detect and initialize sparse bitmask capability via CPUID
  • Initialize arch_has_sparse_bitmasks to false in Haswell probe
  • Parse ECX.noncont from CPUID.0x10 and assign to flag
  • Remove legacy arch_has_sparse_bitmaps assignments
arch/x86/kernel/cpu/resctrl/core.c
Refactor internal data structures for sparse bitmasks
  • Introduce union cpuid_0x10_x_ecx for ECX noncont bit
  • Rename arch_has_sparse_bitmaps to arch_has_sparse_bitmasks
arch/x86/kernel/cpu/resctrl/internal.h
include/linux/resctrl.h
Update resctrl documentation for sparse_masks
  • Document the new sparse_masks file in info tree
  • Describe non-contiguous CBM support in resctrl.rst
Documentation/arch/x86/resctrl.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

关键摘要:

  • resctrl.h文件中,arch_has_sparse_bitmaps被更正为arch_has_sparse_bitmasks,这是一个重要的命名更改,需要确保所有相关的代码都已经更新以反映这一变化。
  • core.c文件中,新增了一个成员变量arch_has_sparse_bitmasks,并在rdt_get_cache_alloc_cfg函数中根据CPUID的结果设置其值。这是一个合理的改动,但需要确保所有相关的逻辑都已经更新以处理这个新成员变量。
  • ctrlmondata.c文件中,cbm_validate函数的注释和逻辑已经更新,以反映对非连续1s值的支持情况。这是一个重要的更新,需要确保所有相关的测试用例都已经更新以覆盖新的逻辑。
  • rdtgroup.c文件中,新增了一个名为sparse_masks的文件操作,用于显示arch_has_sparse_bitmasks的值。这是一个合理的改动,但需要确保这个新文件操作已经添加到所有相关的资源中。
  • Documentation/arch/x86/resctrl.rst文件中,新增了对sparse_masks的解释,这是一个好的做法,可以帮助用户更好地理解这个新特性。

是否建议立即修改:

  • 所有提到的更改都需要立即进行,以确保代码的一致性和正确性。特别是命名更改和新增的成员变量,需要确保所有相关的代码都已经更新以反映这些变化。
  • 新增的文件操作和文档更新也需要立即进行,以确保用户能够正确地使用这些新特性。

@Avenger-285714 Avenger-285714 requested review from Copilot and opsiff June 1, 2025 17:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR backports upstream changes to support Intel RDT non-contiguous cache bitmask (CBM) functionality. Key changes include renaming internal fields from "sparse_bitmaps" to "sparse_bitmasks", updating CPUID parsing and CBM validation logic, and adding a new "sparse_masks" info file with corresponding documentation updates.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
include/linux/resctrl.h Renames the field to reflect non-contiguous bitmask support.
arch/x86/kernel/cpu/resctrl/rdtgroup.c Introduces a new info file entry to expose the sparse bitmask capability.
arch/x86/kernel/cpu/resctrl/internal.h Adds a CPUID union for non-contiguous bitmask support.
arch/x86/kernel/cpu/resctrl/ctrlmondata.c Updates CBM validation logic to reflect the new sparse bitmask flag.
arch/x86/kernel/cpu/resctrl/core.c Revises CPUID extraction and sets the sparse bitmask flag appropriately for Intel CPUs.
Documentation/arch/x86/resctrl.rst Documents the new "sparse_masks" file and explains the non-contiguous bitmask support.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Avenger-285714 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@opsiff opsiff merged commit a9efb6b into deepin-community:linux-6.6.y Jun 2, 2025
6 of 7 checks passed
@Avenger-285714 Avenger-285714 deleted the intel_RDT_CBM branch June 2, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants