1caab277bSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */ 20aea86a2SCatalin Marinas/* 3344323e0SRobin Murphy * Copyright (C) 2021 Arm Ltd. 40aea86a2SCatalin Marinas */ 5338d4f49SJames Morse 6344323e0SRobin Murphy#include <linux/linkage.h> 756c08ec5SMark Rutland#include <asm/assembler.h> 80aea86a2SCatalin Marinas 90aea86a2SCatalin Marinas .text 100aea86a2SCatalin Marinas 11f71c2ffcSWill Deacon/* Prototype: int __arch_clear_user(void *addr, size_t sz) 120aea86a2SCatalin Marinas * Purpose : clear some user memory 130aea86a2SCatalin Marinas * Params : addr - user memory address to clear 140aea86a2SCatalin Marinas * : sz - number of bytes to clear 150aea86a2SCatalin Marinas * Returns : number of bytes NOT cleared 160aea86a2SCatalin Marinas * 170aea86a2SCatalin Marinas * Alignment fixed up by hardware. 180aea86a2SCatalin Marinas */ 19344323e0SRobin Murphy 20344323e0SRobin Murphy .p2align 4 21344323e0SRobin Murphy // Alignment is for the loop, but since the prologue (including BTI) 22344323e0SRobin Murphy // is also 16 bytes we can keep any padding outside the function 233ac0f452SMark BrownSYM_FUNC_START(__arch_clear_user) 24344323e0SRobin Murphy add x2, x0, x1 250aea86a2SCatalin Marinas subs x1, x1, #8 260aea86a2SCatalin Marinas b.mi 2f 270aea86a2SCatalin Marinas1: 28344323e0SRobin MurphyUSER(9f, sttr xzr, [x0]) 29344323e0SRobin Murphy add x0, x0, #8 300aea86a2SCatalin Marinas subs x1, x1, #8 31344323e0SRobin Murphy b.hi 1b 32344323e0SRobin MurphyUSER(9f, sttr xzr, [x2, #-8]) 33344323e0SRobin Murphy mov x0, #0 34344323e0SRobin Murphy ret 35344323e0SRobin Murphy 36344323e0SRobin Murphy2: tbz x1, #2, 3f 37344323e0SRobin MurphyUSER(9f, sttr wzr, [x0]) 38344323e0SRobin MurphyUSER(8f, sttr wzr, [x2, #-4]) 39344323e0SRobin Murphy mov x0, #0 40344323e0SRobin Murphy ret 41344323e0SRobin Murphy 42344323e0SRobin Murphy3: tbz x1, #1, 4f 43344323e0SRobin MurphyUSER(9f, sttrh wzr, [x0]) 44344323e0SRobin Murphy4: tbz x1, #0, 5f 45344323e0SRobin MurphyUSER(7f, sttrb wzr, [x2, #-1]) 460aea86a2SCatalin Marinas5: mov x0, #0 470aea86a2SCatalin Marinas ret 480aea86a2SCatalin Marinas 49*35d67794SMark Rutland // Exception fixups 50344323e0SRobin Murphy7: sub x0, x2, #5 // Adjust for faulting on the final byte... 51344323e0SRobin Murphy8: add x0, x0, #4 // ...or the second word of the 4-7 byte case 52344323e0SRobin Murphy9: sub x0, x2, x0 530aea86a2SCatalin Marinas ret 54*35d67794SMark RutlandSYM_FUNC_END(__arch_clear_user) 55*35d67794SMark RutlandEXPORT_SYMBOL(__arch_clear_user) 56