Skip to content

Commit

Permalink
arm64: demand_paging: allow page fault processing with IRQs enabled
Browse files Browse the repository at this point in the history
Convention is to call k_mem_page_fault() with IRQs enabled if they were
enabled when the fault occurred.

(cherry picked from commit 79428bc)

Original-Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
GitOrigin-RevId: 79428bc
Cr-Build-Id: 8736917283475341809
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8736917283475341809
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I543efa2a52419279745c9ddc87a7f1a7753c33b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5856311
Commit-Queue: Keith Short <keithshort@chromium.org>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
  • Loading branch information
Nicolas Pitre authored and Chromeos LUCI committed Sep 13, 2024
1 parent 9634545 commit 4a907c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion arch/arm64/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void z_arm64_fatal_error(unsigned int reason, struct arch_esf *esf)

if (IS_ENABLED(CONFIG_DEMAND_PAGING) &&
reason != K_ERR_STACK_CHK_FAIL &&
z_arm64_do_demand_paging(esr, far)) {
z_arm64_do_demand_paging(esf, esr, far)) {
return;
}

Expand Down
22 changes: 19 additions & 3 deletions arch/arm64/core/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,24 @@ void arch_mem_scratch(uintptr_t phys)
}
}

static bool do_mem_page_fault(struct arch_esf *esf, uintptr_t virt)
{
/*
* The k_mem_page_fault() code expects to be called with IRQs enabled
* if the fault happened in a context where IRQs were enabled.
*/
if (arch_irq_unlocked(esf->spsr)) {
enable_irq();
}

bool ok = k_mem_page_fault((void *)virt);

disable_irq();
return ok;
}

/* Called from the fault handler. Returns true if the fault is resolved. */
bool z_arm64_do_demand_paging(uint64_t esr, uint64_t far)
bool z_arm64_do_demand_paging(struct arch_esf *esf, uint64_t esr, uint64_t far)
{
uintptr_t virt = far;
uint64_t *pte, desc;
Expand All @@ -1591,12 +1607,12 @@ bool z_arm64_do_demand_paging(uint64_t esr, uint64_t far)
pte = get_pte_location(&kernel_ptables, virt);
if (!pte) {
/* page mapping doesn't exist, let the core code do its thing */
return k_mem_page_fault((void *)virt);
return do_mem_page_fault(esf, virt);
}
desc = *pte;
if ((desc & PTE_DESC_TYPE_MASK) != PTE_PAGE_DESC) {
/* page is not loaded/mapped */
return k_mem_page_fault((void *)virt);
return do_mem_page_fault(esf, virt);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/core/paging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
#ifndef Z_ARM64_PAGING_H
#define Z_ARM64_PAGING_H

bool z_arm64_do_demand_paging(uint64_t esr, uint64_t far);
bool z_arm64_do_demand_paging(struct arch_esf *esf, uint64_t esr, uint64_t far);

#endif /* Z_ARM64_PAGING_H */

0 comments on commit 4a907c2

Please sign in to comment.