Skip to content

Commit

Permalink
lib/ukvmem/arch: Do not print error message if demand paging disabled
Browse files Browse the repository at this point in the history
In cases such as those of `lib/uknofault`, pafe faults may actually be
intentional. So, to avoid unnecessarily throwing out error messages,
check if on-demand paging was disabled prior to faulting.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: unikraft#1334
  • Loading branch information
mogasergiu authored and razvand committed Mar 18, 2024
1 parent cb80434 commit 4d97341
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/ukvmem/arch/arm/pagefault64.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <uk/arch/types.h>
#include <uk/print.h>
#include <uk/config.h>
#include <string.h>

static int vmem_arch_pagefault(void *data)
{
Expand All @@ -21,6 +22,7 @@ static int vmem_arch_pagefault(void *data)
};
unsigned int faulttype;
unsigned long dfsc;
struct uk_vas *vas;
int rc;

if (ctx->esr & ARM64_PF_ESR_WnR)
Expand All @@ -39,10 +41,13 @@ static int vmem_arch_pagefault(void *data)

rc = vmem_pagefault(vaddr, faulttype, ctx->regs);
if (unlikely(rc < 0)) {
uk_pr_crit("Cannot handle %s page fault at 0x%"__PRIvaddr
" (ec: 0x%lx): %d\n",
faultstr[faulttype & UK_VMA_FAULT_ACCESSTYPE],
vaddr, ctx->esr, rc);
vas = uk_vas_get_active();
if (unlikely(vas && !(vas->flags & UK_VAS_FLAG_NO_PAGING)))
uk_pr_crit("Cannot handle %s page fault at 0x%"
__PRIvaddr" (ec: 0x%x): %s (%d).\n",
faultstr[faulttype &
UK_VMA_FAULT_ACCESSTYPE],
vaddr, ctx->error_code, strerror(-rc), -rc);

return UK_EVENT_NOT_HANDLED;
}
Expand Down
15 changes: 10 additions & 5 deletions lib/ukvmem/arch/x86_64/pagefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <uk/arch/types.h>
#include <uk/print.h>
#include <uk/config.h>
#include <string.h>

static int vmem_arch_pagefault(void *data)
{
Expand All @@ -20,6 +21,7 @@ static int vmem_arch_pagefault(void *data)
"read", "write", "exec"
};
unsigned int faulttype;
struct uk_vas *vas;
int rc;

if (ctx->error_code & X86_PF_EC_WR)
Expand All @@ -35,11 +37,14 @@ static int vmem_arch_pagefault(void *data)
faulttype |= UK_VMA_FAULT_MISCONFIG;

rc = vmem_pagefault(vaddr, faulttype, ctx->regs);
if (unlikely(rc < 0)) {
uk_pr_crit("Cannot handle %s page fault at 0x%"__PRIvaddr
" (ec: 0x%x): %d\n",
faultstr[faulttype & UK_VMA_FAULT_ACCESSTYPE],
vaddr, ctx->error_code, rc);
if (rc < 0) {
vas = uk_vas_get_active();
if (unlikely(vas && !(vas->flags & UK_VAS_FLAG_NO_PAGING)))
uk_pr_crit("Cannot handle %s page fault at 0x%"
__PRIvaddr" (ec: 0x%x): %s (%d).\n",
faultstr[faulttype &
UK_VMA_FAULT_ACCESSTYPE],
vaddr, ctx->error_code, strerror(-rc), -rc);

return UK_EVENT_NOT_HANDLED;
}
Expand Down

0 comments on commit 4d97341

Please sign in to comment.