Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Sunway] 6.6: update patches for sw64 architecture #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 8, 2025

Conversation

Avenger-285714
Copy link
Collaborator

@Avenger-285714 Avenger-285714 commented Jul 7, 2025

sw64: adjust the notrace in the code
sw64: pci: add base address of devmn
sw64: acpi: select HAVE_ACPI_APEI when ACPI is set
sw64: fix for executing syscall(-1)
sw64: pci: remove zx200 dma mask reset
...

Summary by Sourcery

Refine SW64 architecture support by adjusting PCI initialization and host bridge mappings, fixing syscall(-1) behavior under ptrace, cleaning up notrace annotations on string routines, enhancing KVM/perf integration, and updating build test inclusion.

New Features:

  • Add support for mapping device memory base (devmn) for Junzhang V3 PCI host bridge

Bug Fixes:

  • Ensure ptrace skip for syscall(-1) sets return value to -ENOSYS
  • Correct KVM vCPU kernel-mode detection for the C3B subarchitecture

Enhancements:

  • Guard PCI bus number setup, config-space remapping, and IRQ setup to skip in guest or emulated contexts
  • Remove ZX200 DMA bus-limit fixup and streamline PCI controller property parsing
  • Reorder notrace annotations on memcpy and memset variants for proper attribute placement
  • Add acpi_disable_cmcff compatibility define for SW64 ACPI support
  • Register perf callbacks during KVM Core3 and Core4 initialization

Build:

  • Move libunwind-sw_64 from basic to extra feature tests in tools/build Makefile

Gao Chen and others added 9 commits July 7, 2025 16:22
Change "void notrace *" to "void * notrace" to make the syntax more
standardized.

Signed-off-by: Gao Chen <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
There are some registers for configuring PCIe controller in the devmn
module on Sunway platform.

Signed-off-by: Jing Li <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
Signed-off-by: Jing Li <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
If a task executes syscall(-1), we intercept this early and force r0 to
be -ENOSYS so that we don't need to distinguish this scenario from one
where the nr is -1 because a tracer wants to skip the system call using
ptrace. With the return value set, the return path is the same as the
skip case.

Signed-off-by: Gu Zitao <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Remove the unnecessary reset of zx200's dma mask to DMA_BIT_MASK(32).

Signed-off-by: Zheng Chongzhen <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
This patch extends commit fcbfe81("Kconfig: introduce HAS_IOPORT
option and select it as necessary") to sw64.

Signed-off-by: Zheng Chongzhen <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
This patch:
 - Register callback for monitoring guest info to enable perf kvm
   correctly.
 - For core4, we determine the running mode of the vcpu through
   the CPU mode bit of the PC rather than PS.

Signed-off-by: Min Fanlei <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
RC and PIU components are not used in VM or emulator, so we add
judgment to skip the I/O access of RC and PIU components.

Signed-off-by: Yu Jiayi <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
As it is not normally available on x86_64 not being tested on test-all.c
but being in FEATURE_TESTS_BASIC ends up implying that those features
are present, which leads to trying to link with those libraries and a
build failure now that test-all.c is finally again building
successfully:

  /usr/bin/ld: cannot find -lunwind-sw_64
  collect2: error: ld returned 1 exit status

So remove those features from there and explicitely test them.

Signed-off-by: He Chuyue <[email protected]>
Reviewed-by: He Sheng <[email protected]>
Signed-off-by: Gu Zitao <[email protected]>
@Avenger-285714 Avenger-285714 requested review from opsiff and Copilot July 7, 2025 08:25
Copy link

sourcery-ai bot commented Jul 7, 2025

Reviewer's Guide

This PR refines SW64 Linux 6.6 support by updating PCI host controller logic with guest/emulation gating and devmn_base mapping, adjusting notrace attributes in string routines, fixing NO_SYSCALL return handling, enhancing KVM/perf callbacks, adding ACPI compatibility macros, and revising libunwind-sw64 build features.

Class diagram for updated pci_controller structure (devmn_base addition)

classDiagram
    class pci_controller {
        unsigned long sparse_mem_base
        unsigned long dense_mem_base
        unsigned long sparse_io_base
        unsigned long dense_io_base
        void __iomem *ep_config_space_base
        void __iomem *rc_config_space_base
        void __iomem *piu_ior0_base
        void __iomem *piu_ior1_base
        void __iomem *devmn_base
        unsigned long index
        unsigned long node
        ...
    }
Loading

Class diagram for string function signatures with notrace adjustment

classDiagram
    class string {
        +void * notrace memcpy(void *dest, const void *src, size_t n)
        +void * notrace __memcpy(void *dest, const void *src, size_t n)
        +void * notrace __constant_c_memset(void *s, unsigned long c, size_t n)
        +void * notrace ___memset(void *s, int c, size_t n)
        +void * notrace __memset(void *s, int c, size_t n)
        +void * notrace memset(void *s, int c, size_t n)
        +void * notrace __memsetw(void *dest, unsigned short c, size_t count)
    }
Loading

Class diagram for ACPI compatibility macro addition

classDiagram
    class acpi {
        +int acpi_strict
        +int acpi_disabled
        +int acpi_pci_disabled
        +#define acpi_disable_cmcff 1
    }
Loading

File-Level Changes

Change Details Files
Guard PCI host bridge initialization and extend devmn_base support
  • Conditionally write primary bus number only in non-guest/emulation contexts
  • Remove legacy ZX200 bus_dma_limit reset fixup
  • Add PROP_DEVMN_BASE property and map devmn_base for Junzhang v3
  • Wrap ioremap of rc_config_space and PIU IOR regions in non-guest check
  • Conditionally invoke set_pcieport_service_irq only on host
  • Define SUNWAY_DEVMN_SIZE and add devmn_base field to pci_controller
arch/sw_64/pci/pci.c
drivers/pci/controller/pci-sunway.c
arch/sw_64/include/asm/pci.h
drivers/irqchip/irq-sunway-pci-intx.c
Adjust notrace placement for memcpy/memset variants
  • Move 'notrace' qualifier to follow return type for all memcpy and memset symbols
arch/sw_64/lib/string.c
Fix skip-syscall (-1) handling in do_entSys
  • Detect NO_SYSCALL and explicitly set return register to -ENOSYS before tracing
arch/sw_64/kernel/sys_sw64.c
Enhance KVM/perf integration and guest PMI detection
  • Refactor kvm_arch_vcpu_in_kernel to handle SUBARCH_C3B differently
  • Expose unified kvm_arch_pmi_in_guest inline in kvm_host.h
  • Register perf callbacks in kvm_core3 and kvm_core4 init functions
arch/sw_64/kvm/perf.c
arch/sw_64/include/asm/kvm_host.h
arch/sw_64/kvm/kvm_core3.c
arch/sw_64/kvm/kvm_core4.c
Add ACPI compatibility macro
  • Define acpi_disable_cmcff for SW64 to match IA-32 compatibility
arch/sw_64/include/asm/acpi.h
Update libunwind-sw_64 feature placement in build configs
  • Remove libunwind-sw_64 from basic feature tests
  • Re-add libunwind-sw_64 under extra feature tests
  • Sync tools/perf Makefile with updated feature list
tools/build/Makefile.feature
tools/perf/Makefile.config

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

deepin pr auto review

代码审查意见:

  1. arch/sw_64/include/asm/acpi.h文件中,acpi_disable_cmcff的定义可能不适用于sw_64架构,因为它在注释中提到只用于IA-32架构。如果这个宏在sw_64架构中不需要,应该移除或提供更明确的注释说明。

  2. arch/sw_64/include/asm/kvm_host.h文件中,kvm_arch_pmi_in_guest函数的注释应该更详细地解释其用途和返回值的含义。

  3. arch/sw_64/include/asm/pci.h文件中,SUNWAY_DEVMN_SIZE的定义应该添加注释说明其用途。

  4. arch/sw_64/kernel/sys_sw64.c文件中,do_entSys函数的注释应该更详细地解释为什么在nr == NO_SYSCALL时需要设置r0-ENOSYS

  5. arch/sw_64/kvm/Kconfig文件中,select GUEST_PERF_EVENTS if PERF_EVENTS的注释应该更详细地解释为什么需要这个选择。

  6. arch/sw_64/kvm/kvm_core3.carch/sw_64/kvm/kvm_core4.c文件中,kvm_register_perf_callbacks(NULL);的调用应该添加注释说明其用途。

  7. arch/sw_64/kvm/perf.c文件中,kvm_arch_vcpu_in_kernel函数的实现应该添加注释说明其逻辑和返回值的含义。

  8. arch/sw_64/lib/string.c文件中,memcpy__memcpy__constant_c_memset___memset__memset__memsetw函数的实现应该添加notrace关键字,以避免不必要的内核函数跟踪。

  9. arch/sw_64/pci/pci.c文件中,fix_bus_dma_limit函数的实现应该添加注释说明其用途和逻辑。

  10. drivers/irqchip/irq-sunway-pci-intx.c文件中,setup_intx_irqs函数的实现应该添加注释说明其用途和逻辑。

  11. drivers/pci/controller/pci-sunway.c文件中,pci_prepare_controller函数的实现应该添加注释说明其用途和逻辑。

  12. tools/build/Makefile.feature文件中,libunwind-sw_64的添加应该添加注释说明其用途。

  13. tools/perf/Makefile.config文件中,FEATURE_CHECK_LDFLAGS-libunwind-sw_64的添加应该添加注释说明其用途。

以上是针对代码审查意见的总结,具体的代码审查意见需要根据代码的具体实现和上下文来给出。

Copy link

@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!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `drivers/pci/controller/pci-sunway.c:843` </location>
<code_context>

 	/* Get necessary properties of Root Complex */
 	for (i = 0; i < PROP_NUM; ++i) {
+		if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
+			break;
+
 		ret = fwnode_property_read_u64(fwnode, prop_names[i],
</code_context>

<issue_to_address>
Breaking out of property loop early may skip required properties.

Using 'break' here will prevent processing any properties after PROP_DEVMN_BASE for non-junzhang_v3 platforms, which could cause issues if more properties are added later. Use 'continue' to skip only the current property.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
		if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
			break;
=======
		if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
			continue;
>>>>>>> REPLACE

</suggested_fix>

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.

Comment on lines +843 to +844
if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
break;
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Breaking out of property loop early may skip required properties.

Using 'break' here will prevent processing any properties after PROP_DEVMN_BASE for non-junzhang_v3 platforms, which could cause issues if more properties are added later. Use 'continue' to skip only the current property.

Suggested change
if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
break;
if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
continue;

Copy link

@Copilot 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 updates the SW64 support in Linux 6.6 by refining function instrumentation, extending PCI host controller mappings, enhancing ACPI/KVM configuration, and fixing syscall(-1) handling.

  • Introduce PROP_DEVMN_BASE and map the DEVMN region in the Sunway PCI host controller.
  • Adjust notrace placement for memcpy/memset variants in the SW64 string library.
  • Enable ACPI APEI and guest perf events, register perf callbacks, and correct ptrace syscall skipping.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/perf/Makefile.config Add SW64 libunwind link flags and feature check
tools/build/Makefile.feature Move libunwind-sw_64 from basic to extra tests
drivers/pci/controller/pci-sunway.c Add PROP_DEVMN_BASE, conditional devmn_base mapping, guard allocs for guests
drivers/irqchip/irq-sunway-pci-intx.c Guard set_pcieport_service_irq behind !is_guest_or_emul()
arch/sw_64/pci/pci.c Remove zx200 DMA fixup, guard bus number init under non-guest
arch/sw_64/lib/string.c Reposition notrace attribute on memcpy/memset functions
arch/sw_64/kvm/perf.c Update kvm_arch_vcpu_in_kernel logic for CONFIG_SUBARCH_C3B
arch/sw_64/kvm/kvm_core3.c, kvm_core4.c Register perf callbacks before kvm_init
arch/sw_64/kvm/Kconfig Select GUEST_PERF_EVENTS when PERF_EVENTS
arch/sw_64/kernel/sys_sw64.c Fix syscall(-1) skip logic in ptrace path
arch/sw_64/include/asm/pci.h Define SUNWAY_DEVMN_SIZE and add devmn_base field
arch/sw_64/include/asm/kvm_host.h Add kvm_arch_pmi_in_guest inline helper
arch/sw_64/include/asm/acpi.h Define acpi_disable_cmcff for compatibility
arch/sw_64/Kconfig Select HAS_IOPORT and HAVE_ACPI_APEI when ACPI
Comments suppressed due to low confidence (1)

arch/sw_64/include/asm/pci.h:86

  • [nitpick] Add a brief comment describing what SUNWAY_DEVMN_SIZE represents (e.g., the size of the DEVMN MMIO region) to improve readability and future maintenance.
#define SUNWAY_DEVMN_SIZE	0x3480UL

@@ -838,6 +840,9 @@ static int pci_prepare_controller(struct pci_controller *hose,

/* Get necessary properties of Root Complex */
for (i = 0; i < PROP_NUM; ++i) {
if ((i == PROP_DEVMN_BASE) && !is_junzhang_v3())
break;
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Using break here exits the loop entirely when PROP_DEVMN_BASE is hit; consider using continue to skip only this index and preserve the loop for any future properties.

Suggested change
break;
continue;

Copilot uses AI. Check for mistakes.

Comment on lines +881 to 883
if (is_junzhang_v3())
hose->devmn_base = ioremap(props[PROP_DEVMN_BASE], SUNWAY_DEVMN_SIZE);

Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

ioremap may return NULL on failure; consider checking the returned pointer (or using IS_ERR/PTR_ERR) and handling errors to avoid potential null pointer dereferences.

Suggested change
if (is_junzhang_v3())
hose->devmn_base = ioremap(props[PROP_DEVMN_BASE], SUNWAY_DEVMN_SIZE);
if (is_junzhang_v3()) {
hose->devmn_base = ioremap(props[PROP_DEVMN_BASE], SUNWAY_DEVMN_SIZE);
if (!hose->devmn_base) {
pr_err("Failed to map devmn_base at 0x%lx\n", props[PROP_DEVMN_BASE]);
return -ENOMEM;
}
}

Copilot uses AI. Check for mistakes.

Comment on lines +260 to +261
if (!is_guest_or_emul())
set_pcieport_service_irq(hose);
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Wrap the single-line if statement with braces for clarity and to comply with kernel coding style, e.g., if (!is_guest_or_emul()) { set_pcieport_service_irq(hose); }.

Suggested change
if (!is_guest_or_emul())
set_pcieport_service_irq(hose);
if (!is_guest_or_emul()) {
set_pcieport_service_irq(hose);
}

Copilot uses AI. Check for mistakes.

*/
static inline bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu)
{
return IS_ENABLED(CONFIG_GUEST_PERF_EVENTS) && !!vcpu;
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Using !!vcpu to test pointer non-null is concise but may be unclear; consider replacing it with vcpu != NULL for better readability.

Suggested change
return IS_ENABLED(CONFIG_GUEST_PERF_EVENTS) && !!vcpu;
return IS_ENABLED(CONFIG_GUEST_PERF_EVENTS) && (vcpu != NULL);

Copilot uses AI. Check for mistakes.

Comment on lines 12 to +15
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
{
return (vcpu->arch.regs.ps & 8) != 0;
if (IS_ENABLED(CONFIG_SUBARCH_C3B))
return (vcpu->arch.regs.ps & 0x8) == 0;
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic mask 0x8 could be replaced with a named constant or documented to clarify which status bit is tested—and why the logic is inverted for CONFIG_SUBARCH_C3B.

Copilot uses AI. Check for mistakes.

@opsiff opsiff merged commit a9ffc49 into deepin-community:linux-6.6.y Jul 8, 2025
9 of 10 checks passed
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: opsiff

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

The pull request process is described here

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants