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

kprobes: Make kprobe register via symbol name #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

kprobes: Make kprobe register via symbol name #135

wants to merge 1 commit into from

Conversation

louisom
Copy link
Contributor

@louisom louisom commented Oct 20, 2016

In Linux kernel, kprobe can choose to register by address or symbol name,
but currently F9 microkernel can only register by address.

In F9 microkernel, it can include ksymbols when compiling kernel with
CONFIG_SYMMAP, which means F9 microkernel can support regiser kprobe via
symbol name, too.

This commit change two parts in F9 microkernel, ksym and kprobes.

  • ksym
    • Adding ksym_lookup_name to search function address via symbol name.
  • kprobes
    • Adding new field symbol_name in struct kprobe.
    • When kprobe is registering, it will get the correct address via
      help function kprobe_addr, kprobe_addr will return correct
      function address. Also, kprobe_addr will failed when it cannot
      match the symbol name in symtab, or address and symbol name are
      used in the same time.

Example usage:

static struct kprobe kp = {
    .symbol_name = "ktimer_handler"
};

or

extern void ktimer_handler(void);
static struct kprobe kp = {
    .addr = ktimer_handler
};

@jserv
Copy link
Member

jserv commented Oct 20, 2016

CI fails because of incorrect linkage.

Copy link
Member

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Follow consistent coding style.

void *addr = kp->addr;

/* Cannot use address and symbol name at the same time */
if ((kp->addr && kp->symbol_name) ||
Copy link
Member

Choose a reason for hiding this comment

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

You can rewrite by following to comply with consistent coding style:

    if ((kp->addr && kp->symbol_name) ||
        (!kp->addr && !kp->symbol_name))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll need to make a script to check this kind of hard find coding style problem......

{
int i;

for (i = 0; i < __ksym_count; ++i) {
Copy link
Member

Choose a reason for hiding this comment

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

Use C99 style initializer. That is, for (int i = 0; i < __ksym_count; ++i) {.

Copy link
Contributor Author

@louisom louisom left a comment

Choose a reason for hiding this comment

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

I'm not sure how to resolve incorrect linkage problem. In kernel, there is a strcmp, and in l4test, there is another strcmp, too.

It seems we can't split out kernel space and user space here.

void *addr = kp->addr;

/* Cannot use address and symbol name at the same time */
if ((kp->addr && kp->symbol_name) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll need to make a script to check this kind of hard find coding style problem......

@@ -78,3 +78,21 @@ void *ksym_id2addr(int symid)
{
return __ksym_tbl[symid].addr;
}

static inline int strcmp(const char *l, const char *r)
Copy link
Member

Choose a reason for hiding this comment

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

Remove it since we already have functional implementation in file kernel/lib/strcmp.c.

In Linux kernel, kprobe can register by function address or symbol name,
but currently in F9 microkernel, can only register by address.

9 microkernel already include ksymbols when compiling kernel with
CONFIG_SYMMAP, which means F9 microkernel have the ability to regiser kprobe
via symbol name, too.

This commit change two parts in F9 microkernel, ksym and kprobes.

* ksym
    - Adding ksym_lookup_name to search function address via symbol name.

* kprobes
    - Adding new field `symbol_name` in struct kprobe.
    - When kprobe is registering, it will get the correct address via
      help function `kprobe_addr`, `kprobe_addr` will return correct
      function address. Also, `kprobe_addr` will failed when it cannot
      match the symbol name in symtab, or address and symbol name are
      used in the same time.

Example usage:

static struct kprobe kp = {
    .symbol_name = "ktimer_handler"
};

or

extern void ktimer_handler(void);
static struct kprobe kp = {
    .addr = ktimer_handler
};
@louisom
Copy link
Contributor Author

louisom commented Jan 30, 2017

@jserv How could I prevent kernel / user function multiple define?

l4test and kernel all define the name strcmp

build/discoveryf4/user/apps/l4test/string.o: In function `strcmp':
/home/travis/build/f9micro/f9-kernel/user/apps/l4test/string.c:21: multiple definition of `strcmp'
build/discoveryf4/kernel/lib/strcmp.o:/home/travis/build/f9micro/f9-kernel/kernel/lib/strcmp.c:12: first defined here
make: *** [build/discoveryf4/f9_nosym.elf] Error 1

@jserv
Copy link
Member

jserv commented Feb 1, 2017

@grapherd, there should be only one implementation providing strcmp: kernel/lib/strcmp.c. You would need appropriate declarations where user applications include include/lib/string.h

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