Skip to content

Morello fixes for copy_*_user with caps#21

Open
heshamelmatary wants to merge 4 commits into
codasip-cheri-riscv-7.0from
morello-fixes
Open

Morello fixes for copy_*_user with caps#21
heshamelmatary wants to merge 4 commits into
codasip-cheri-riscv-7.0from
morello-fixes

Conversation

@heshamelmatary
Copy link
Copy Markdown
Collaborator

This PR fixes broken integration of Morello support specifically to copy in/out capabilities to/from the user. e56f377 missed most parts and there are missing commits as well.

While here, also sync with latest Morello Linux and add a latest commit to support R_MORELLO_FUNC_RELATIVE

kevin-brodsky-arm and others added 4 commits May 19, 2026 14:41
This patch implements the low-level tag-preserving uaccess routines.
Most of the existing logic for __arch_copy_{from,to}_user() is reused to
implement the new __arch_copy_{from,to}_user_with_captags().

copy_template.S is extended to copy capability tags for the
*_with_captags() variants (controlled by the COPY_CAPTAGS macro).
The approach is the same as a generic tag-preserving memcpy()
implementation (i.e. copy tags whenever possible, which requires at
least the source and destination addresses to be mutually aligned).

The existing {ldr,str}1 assembler macros can be reused as-is to
operate on capabilities, unfortunately this is not the case of
{ldp,stp}1, because they need to know the register size (8 for X, 16
for C). user_{ldp,stp} are extended and a new {ldp,stp}c1 pair
introduced accordingly.

Note: the implementation of __arch_copy_{from,to}_user() remains
unchanged (i.e. they never preserve tags).

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
copy_template currently copies the destination pointer to x6 then
operates on that copy, while it directly operates on the source
pointer (x1). In both cases a copy of the original pointer is
required for the final fixup in copy_*_user, but not in
copy_template itself.

Make things a little easier to follow by saving both pointers
in copy_*_user, letting copy_template operate on the original
pointers (x0 and x1) directly.

While at it, remove the "Returns" comment in copy_template, which is
irrelevant.

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
We have already amended {get,put}_user so that they access user
memory directly via the user capability in PCuABI; now is time to
convert copy_*_user too. As a result, the copy will be aborted if
the user capability is unsuitable to perform the access (potentially
partway, in case the tail of the targeted region is out of bounds).

__arch_copy_{from,to}_user present an additional challenge in
that they are implemented fully in assembly. Fortunately, the
registers holding the source and destination pointers are mostly
used as base registers for load/store instructions. After switching
to C64, such instructions operate on C registers instead of X, so it
becomes simply a matter of modifying the register aliases in PCuABI;
the req_reg_pcuabi macro is introduced for that purpose. Explicit
ADD instructions are also used in the user_{ldst,ldp,stp} helpers;
those are unproblematic as they can operate on both X and C
registers.

In the few situations where the pointers are being somehow
inspected, we keep operating on their address only, by using the
corresponding X register; srcx and dstx are introduced for that
purpose. This is necessary in some cases due to the instruction
simply not accepting C registers (e.g. TST), while in others it is
rather a matter of convenience, as it means we don't need to convert
additional register aliases to capabilities (CMP, SUB).

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Morello LLVM allows opting into distinguishing between function pointers
(which may be interposed on by a compartmentalisation runtime) and code
pointers (which always directly point to specific instructions, for
cases like C++ landing pads and GNU C indirect goto). Supporting both
relocations (which are equivalent for kselftest's non-compartmentalised
purposes) will allow for Morello LLVM to make this opt-in behaviour
always-on, reducing the number of ABI combinations.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Copy link
Copy Markdown

@jrtc27 jrtc27 left a comment

Choose a reason for hiding this comment

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

(For applying my R_MORELLO_FUNC_RELATIVE commit)

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.

3 participants