Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of fault handler #366

Closed
wants to merge 16 commits into from
Closed

Conversation

WenyuanShao
Copy link
Contributor

Summary of this Pull Request (PR)

This PR is the implementation of user_level fault handlers. When a fault happens, it will make a sinv call to the user_level fault handler to handle the fault.

  1. Modified the invstk and set a bit into the captbl of the component on the top of the stack to indicate whether this is a sinv call to fault handlers or not.
  2. Created a new type for sinv cap to the fault handlers, so we can get rid of a branch in the fast path.
  3. Expanded the thd_introspect to get the register information in user_level and print these register information when fault happens.
  4. Create an interface for fault handlers so different components can implement fault handlers differently.

Intent for your PR

Choose one (Mandatory):

  • This PR is for a code-review and is intended to get feedback, but not to be pulled yet.
  • This PR is mature, and ready to be integrated into the repo.

Reviewers (Mandatory):

@gparmer , @hungry-foolish , @phanikishoreg

Code Quality

As part of this pull request, I've considered the following:

Style:

  • Comments adhere to the Style Guide (SG)
  • Spacing adhere's to the SG
  • Naming adhere's to the SG
  • All other aspects of the SG are adhered to, or exceptions are justified in this pull request
  • I have run the auto formatter on my code before submitting this PR (see doc/auto_formatter.md for instructions)

Code Craftsmanship:

  • I've made an attempt to remove all redundant code
  • I've considered ways in which my changes might impact existing code, and cleaned it up
  • I've formatted the code in an effort to make it easier to read (proper error handling, function use, etc...)
  • I've commented appropriately where code is tricky
  • I agree that there is no "throw-away" code, and that code in this PR is of high quality

Testing

I've tested the code using the following test programs (provide list here):

-I have run llbooter_pong.sh, llbooter_test.sh, microboot.sh, unit_schedcomp.sh and unit_schedtest.sh tests.

Copy link
Collaborator

@gparmer gparmer left a comment

Choose a reason for hiding this comment

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

You're missing one major piece of functionality: I believe we need to make sure that sinv_activate cannot be used on the range of capability addresses used for the fault handlers. Do you agree?

void
fault_div_by_zero(unsigned long sp, unsigned long ip, unsigned long fault_addr, unsigned long fault_type)
{
PRINTLOG(PRINT_DEBUG, "in div by zero error fault handler, fault happens in component:%u\n\n", cos_inv_token());
Copy link
Collaborator

Choose a reason for hiding this comment

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

@phanikishoreg Why did the PRINTLOG start getting pervasively used? What functionality does it provide? This isn't an API we ever discussed. Not necessarily a problem here, but I'm curious.

@@ -67,8 +67,8 @@ hypercall_comp_initaep_get(spdid_t spdid, int is_sched, struct cos_aep_info *aep
}

/* capid_t though is unsigned long, only assuming it occupies 16bits for packing */
ret = cos_sinv(BOOT_CAPTBL_SINV_CAP, 0, HYPERCALL_COMP_INITAEP_GET,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this old code doing!!!! Is this just as broken as it looks?

#ifndef FAULT_HANDLER_H
#define FAULT_HANDLER_H

#include <cos_kernal_api.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this compile?

Is this tested?

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, just checked. This isn't part of any DEPENDENCIES, so is essentially untested.

The complexity here is that this is in some way a "virtual" API. In some sense every component should depend on this, so we shouldn't have to list it in DEPENDENCIES. It should be the build system that adds the dependency automatically. However, that dependency doesn't do much at build time...only when the system is composed together via sinvs. So this interface is in a strange place. However, it might be nice to have, if only to document the shape of the API. That said, the code should compile....


.text

cos_asm_server_stub(fault_div_by_zero)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oddly, these don't make much sense as they can never be used...

@@ -969,8 +970,7 @@ composite_syscall_handler(struct pt_regs *regs)
/* fast path: invocation return (avoiding captbl accesses) */
if (cap == COS_DEFAULT_RET_CAP) {
/* No need to lookup captbl */
sret_ret(thd, regs, cos_info);
return 0;
return sret_ret(thd, regs, cos_info);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are the semantics around this correct? This is a functional change. Is it fixing a bug? What behavior is it changing?

return thd_invstk_current(thd, ip, sp, cos_info);
/*
* This is the only time we might use the in_fault flag.
* We can reset the captbl after we get the in_fault flag.
Copy link
Collaborator

Choose a reason for hiding this comment

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

again, I'm not sure how useful this comment is without broader context. Perhaps add that broader context into the data-structure (struct) location so that people can understand? I don't see how it is relevant here as this is "outside" of the abstraction.

@@ -584,6 +637,57 @@ thd_introspect(struct thread *t, unsigned long op, unsigned long *retval)
case THD_GET_TID:
*retval = t->tid;
break;
case THD_GET_FAULT_REG1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make a macro to do this.

cos_info = thd_invstk_current(curr_thd, &ip, &sp, ci);
fh = captbl_lkup(cos_info->captbl, cap);
__userregs_sinvargset(regs, regs->sp, regs->ip, fault_addr, cap);
/* This is a software fault and should be fixed in the future. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add FIXME in the comment.

unsigned long ip, sp;
u32_t fault_addr = 0, errcode, eip;

fault_regs_save (regs, curr_thd);
Copy link
Collaborator

Choose a reason for hiding this comment

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

no space

int
div_by_zero_err_fault_handler(struct pt_regs *regs)
{
print_regs_state(regs);
die("FAULT: Divide by Zero Error\n\n");
fault_handler_sinv(regs, FAULT_CAPTBL_DIVZERO);
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe a macro to generate all of these as well?

@gparmer
Copy link
Collaborator

gparmer commented Aug 20, 2018

@WenyuanShao this is a REALLY strong first PR. Some minor issues to clear up, but this is almost ready!

@gparmer gparmer closed this Aug 20, 2018
WenyuanShao added a commit to WenyuanShao/composite that referenced this pull request Aug 28, 2018
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.

2 participants