pussuw commented on code in PR #12922: URL: https://github.com/apache/nuttx/pull/12922#discussion_r1724946715
########## arch/arm64/src/common/arm64_addrenv_perms.c: ########## @@ -0,0 +1,156 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_addrenv_perms.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <assert.h> + +#include <nuttx/addrenv.h> +#include <nuttx/arch.h> +#include <nuttx/pgalloc.h> + +#include <sys/mman.h> + +#include "barriers.h" +#include "pgalloc.h" +#include "arm64_arch.h" +#include "arm64_mmu.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define CLR_MASK (PTE_BLOCK_DESC_AP_MASK | PTE_BLOCK_DESC_UXN) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int modify_region(uintptr_t vstart, uintptr_t vend, uintptr_t setmask) +{ + uintptr_t l1vaddr; + uintptr_t lnvaddr; + uintptr_t entry; + uintptr_t paddr; + uintptr_t vaddr; + uint32_t ptlevel; + + /* Must perform a reverse table walk */ + + l1vaddr = arm64_pgvaddr(mmu_get_ttbr0_pgbase()); + + if (!l1vaddr) + { + /* Oops, there is no address environment to modify at all ? */ + + return -EINVAL; + } + + /* Invalidate D-Cache so that we read from the physical memory */ + + up_invalidate_dcache(vstart, vend); Review Comment: This is wrong, we want to read the page tables from RAM, not the user physical memory. ########## arch/arm64/src/common/arm64_addrenv_perms.c: ########## @@ -0,0 +1,156 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_addrenv_perms.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <assert.h> + +#include <nuttx/addrenv.h> +#include <nuttx/arch.h> +#include <nuttx/pgalloc.h> + +#include <sys/mman.h> + +#include "barriers.h" +#include "pgalloc.h" +#include "arm64_arch.h" +#include "arm64_mmu.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define CLR_MASK (PTE_BLOCK_DESC_AP_MASK | PTE_BLOCK_DESC_UXN) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int modify_region(uintptr_t vstart, uintptr_t vend, uintptr_t setmask) +{ + uintptr_t l1vaddr; + uintptr_t lnvaddr; + uintptr_t entry; + uintptr_t paddr; + uintptr_t vaddr; + uint32_t ptlevel; + + /* Must perform a reverse table walk */ + + l1vaddr = arm64_pgvaddr(mmu_get_ttbr0_pgbase()); + + if (!l1vaddr) + { + /* Oops, there is no address environment to modify at all ? */ + + return -EINVAL; + } + + /* Invalidate D-Cache so that we read from the physical memory */ + + up_invalidate_dcache(vstart, vend); + + for (vaddr = vstart; vaddr < vend; vaddr += MM_PGSIZE) + { + for (ptlevel = 1, lnvaddr = l1vaddr; + ptlevel < MMU_PGT_LEVELS; + ptlevel++) + { + paddr = mmu_pte_to_paddr(mmu_ln_getentry(ptlevel, lnvaddr, vaddr)); + lnvaddr = arm64_pgvaddr(paddr); + if (!lnvaddr) + { + return -EINVAL; + } + } + + /* Get entry and modify the flags */ + + entry = mmu_ln_getentry(ptlevel, lnvaddr, vaddr); + entry &= ~CLR_MASK; + entry |= setmask | PTE_BLOCK_DESC_AP_USER; + + /* Restore the entry */ + + mmu_ln_restore(ptlevel, lnvaddr, vaddr, entry); + } + + /* When all is set and done, flush the data cache */ + + up_flush_dcache(vstart, vend); Review Comment: Also wrong -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
