Skip to content

[linux 6.18.y] [deepin] LoongArch: Export some signal functions#1637

Open
Kingwkl wants to merge 3 commits intodeepin-community:linux-6.18.yfrom
Kingwkl:linux-6.18.y
Open

[linux 6.18.y] [deepin] LoongArch: Export some signal functions#1637
Kingwkl wants to merge 3 commits intodeepin-community:linux-6.18.yfrom
Kingwkl:linux-6.18.y

Conversation

@Kingwkl
Copy link
Copy Markdown

@Kingwkl Kingwkl commented Apr 20, 2026

Export some signal functions

Summary by Sourcery

Export LoongArch signal and register helper functions for use by external code and modules.

New Features:

  • Add a new LoongArch extern.c module providing wrapper symbols around core signal and altstack helpers.

Enhancements:

  • Make LoongArch ptrace register accessors, user read/write helpers, and signal frame setup functions globally visible instead of file-local.
  • Adjust LoongArch FPU and LBT context management function declarations to be externally visible C symbols.
  • Wire the new extern.o object into the LoongArch kernel build.

Like the other relevant symbols, export them and put the function
declarations in header files rather than source files.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Kanglong Wang <wangkanglong@loongson.cn>
So that they can be probed in the kernel modules to do something.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Kanglong Wang <wangkanglong@loongson.cn>
So that they can be called in the kernel modules to do something.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Kanglong Wang <wangkanglong@loongson.cn>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 20, 2026

Reviewer's Guide

Exports several LoongArch signal and register helper routines for external use by making previously static functions globally visible, adjusting FPU/LBT context helper declarations, and adding a new wrapper module that exports selected core signal helpers via GPL symbols.

Sequence diagram for external use of exported LoongArch signal helpers

sequenceDiagram
participant ExternalModule
participant LoongArchExtern as loongarch_extern_o
participant CoreSignal as Core_signal_helpers

ExternalModule->>LoongArchExtern: loongarch_copy_siginfo_to_user(to, from)
LoongArchExtern->>CoreSignal: copy_siginfo_to_user(to, from)
CoreSignal-->>LoongArchExtern: result
LoongArchExtern-->>ExternalModule: result

ExternalModule->>LoongArchExtern: loongarch___save_altstack(uss, sp)
LoongArchExtern->>CoreSignal: __save_altstack(uss, sp)
CoreSignal-->>LoongArchExtern: result
LoongArchExtern-->>ExternalModule: result

ExternalModule->>LoongArchExtern: loongarch_restore_altstack(uss)
LoongArchExtern->>CoreSignal: restore_altstack(uss)
CoreSignal-->>LoongArchExtern: result
LoongArchExtern-->>ExternalModule: result

ExternalModule->>LoongArchExtern: loongarch_set_current_blocked(newset)
LoongArchExtern->>CoreSignal: set_current_blocked(newset)
CoreSignal-->>LoongArchExtern: void
LoongArchExtern-->>ExternalModule: void
Loading

Class diagram for exported LoongArch signal and register helpers

classDiagram
class LoongArchExternModule {
  +void loongarch_set_current_blocked(sigset_t* newset)
  +int loongarch_copy_siginfo_to_user(siginfo_t* to, kernel_siginfo_t* from)
  +int loongarch___save_altstack(stack_t* uss, unsigned long sp)
  +int loongarch_restore_altstack(const stack_t* uss)
}

class CoreSignalHelpers {
  +void set_current_blocked(sigset_t* newset)
  +int copy_siginfo_to_user(siginfo_t* to, const kernel_siginfo_t* from)
  +int __save_altstack(stack_t* uss, unsigned long sp)
  +int restore_altstack(const stack_t* uss)
}

class LoongArchPtraceHelpers {
  +int gpr_get(struct task_struct* target, const struct user_regset* regset, struct membuf to)
  +int gpr_set(struct task_struct* target, const struct user_regset* regset, unsigned int pos, unsigned int count, const void* kbuf, const void* ubuf)
  +int read_user(struct task_struct* target, unsigned long addr, unsigned long* data)
  +int write_user(struct task_struct* target, unsigned long addr, unsigned long data)
}

class LoongArchSignalHelpers {
  +int setup_rt_frame(void* sig_return, struct ksignal* ksig, struct pt_regs* regs, sigset_t* set)
}

class LoongArchFpuContextHelpers {
  +int _save_fp_context(void* fpregs, void* fcc, void* csr)
  +int _restore_fp_context(void* fpregs, void* fcc, void* csr)
  +int _save_lsx_context(void* fpregs, void* fcc, void* fcsr)
  +int _restore_lsx_context(void* fpregs, void* fcc, void* fcsr)
  +int _save_lasx_context(void* fpregs, void* fcc, void* fcsr)
  +int _restore_lasx_context(void* fpregs, void* fcc, void* fcsr)
}

class LoongArchLbtContextHelpers {
  +int _save_lbt_context(void* regs, void* eflags)
  +int _restore_lbt_context(void* regs, void* eflags)
  +int _save_ftop_context(void* ftop)
  +int _restore_ftop_context(void* ftop)
}

LoongArchExternModule --> CoreSignalHelpers : calls
Loading

File-Level Changes

Change Details Files
Make LoongArch ptrace register accessors and user memory helpers globally visible instead of file-local.
  • Remove static/inline restriction from gpr_get, gpr_set, read_user, and write_user in the ptrace implementation so they can be referenced from other compilation units
  • Add non-static function prototypes for these helpers immediately before their definitions to provide declarations for external callers
arch/loongarch/kernel/ptrace.c
Relax linkage of LoongArch FPU and LBT context save/restore helpers to allow external references.
  • Change several asmlinkage int declarations in the FPU header to extern int so they can be linked from other C files while keeping their calling convention
  • Similarly change LBT context helper declarations to extern int to expose them to other LoongArch kernel code
arch/loongarch/include/asm/fpu.h
arch/loongarch/include/asm/lbt.h
Export LoongArch signal/altstack helper wrappers as GPL symbols from a new kernel object.
  • Implement thin wrapper functions around set_current_blocked, copy_siginfo_to_user, __save_altstack, and restore_altstack which simply forward to the core signal helpers
  • Mark these wrapper functions with EXPORT_SYMBOL_GPL so they are available to other modules
  • Add the new extern.o object file to the LoongArch kernel Makefile so the wrappers are built and linked into the kernel
arch/loongarch/kernel/extern.c
arch/loongarch/kernel/Makefile
Expose setup_rt_frame for use outside signal.c.
  • Remove static from setup_rt_frame and add a prototype before its definition to make the signal frame setup helper available to other LoongArch code
arch/loongarch/kernel/signal.c

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

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 - I've left some high level feedback:

  • The new non-static functions like gpr_get/gpr_set/read_user/write_user/setup_rt_frame are declared directly above their definitions rather than in a common header, which makes external use brittle; consider moving their prototypes into an appropriate exported header instead of duplicating them in the C file.
  • In arch/loongarch/include/asm/{fpu.h,lbt.h} the save_context/restore_context functions have been changed from asmlinkage to extern, which alters calling convention annotations; if these are still implemented in assembly you likely want to keep the asmlinkage attribute on the prototypes and add extern only if necessary.
  • The new extern.c wrappers (loongarch_set_current_blocked, loongarch_copy_siginfo_to_user, etc.) are thin pass-throughs to existing helpers; where possible it may be cleaner to export the underlying symbols directly or document why wrapper symbols are required instead of using EXPORT_SYMBOL on the originals.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new non-static functions like gpr_get/gpr_set/read_user/write_user/setup_rt_frame are declared directly above their definitions rather than in a common header, which makes external use brittle; consider moving their prototypes into an appropriate exported header instead of duplicating them in the C file.
- In arch/loongarch/include/asm/{fpu.h,lbt.h} the _save_*_context/_restore_*_context functions have been changed from asmlinkage to extern, which alters calling convention annotations; if these are still implemented in assembly you likely want to keep the asmlinkage attribute on the prototypes and add extern only if necessary.
- The new extern.c wrappers (loongarch_set_current_blocked, loongarch_copy_siginfo_to_user, etc.) are thin pass-throughs to existing helpers; where possible it may be cleaner to export the underlying symbols directly or document why wrapper symbols are required instead of using EXPORT_SYMBOL on the originals.

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.

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

Exports LoongArch signal-related helpers intended for use by external code/modules by adding an arch-local wrapper/export unit and widening visibility of several LoongArch signal/ptrace/FPU/LBT helpers.

Changes:

  • Add arch/loongarch/kernel/extern.c exporting wrapper symbols around core signal and altstack helpers.
  • Make selected LoongArch signal (setup_rt_frame) and ptrace helpers (gpr_get/gpr_set/read_user/write_user) non-static (globally visible).
  • Adjust LoongArch FPU/LBT context helper declarations and wire extern.o into the LoongArch kernel build.

Reviewed changes

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

Show a summary per file
File Description
arch/loongarch/kernel/signal.c Makes setup_rt_frame globally visible.
arch/loongarch/kernel/ptrace.c Makes regset helpers and user read/write helpers globally visible.
arch/loongarch/kernel/extern.c New wrapper/export layer for signal + altstack helpers.
arch/loongarch/kernel/Makefile Adds extern.o to built-in objects.
arch/loongarch/include/asm/lbt.h Adjusts LBT context helper declarations.
arch/loongarch/include/asm/fpu.h Adjusts FPU context helper declarations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-2.0
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

EXPORT_SYMBOL_GPL is used in this file but no header is included that defines it. Add the appropriate include (e.g., <linux/export.h> or <linux/module.h>) so this compiles in all configurations.

Suggested change
// SPDX-License-Identifier: GPL-2.0
// SPDX-License-Identifier: GPL-2.0
#include <linux/export.h>

Copilot uses AI. Check for mistakes.

void loongarch_set_current_blocked(sigset_t *newset)
{
return set_current_blocked(newset);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This function returns void but uses return set_current_blocked(newset);, which triggers a compiler diagnostic ('return with a value, in function returning void'). Call set_current_blocked(newset) and use a plain return; (or omit the return statement).

Suggested change
return set_current_blocked(newset);
set_current_blocked(newset);

Copilot uses AI. Check for mistakes.
@Kingwkl Kingwkl changed the title Linux 6.18.y [linux 6.18.y] [deepin] LoongArch: Export some signal functions Apr 20, 2026
@opsiff
Copy link
Copy Markdown
Member

opsiff commented Apr 21, 2026

1、3补丁有问题,Auther和signoff-by对不上

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.

4 participants