Linux and interrupts. How do they work?

2015-02-20 Thread Farm Dve
My question pertains interrupts in SoCs, smartphones etc.

I am examining some drivers and the code for the architecture in
arch/arch and I see code that defines a struct resource with .start
and .end members that are the same, with .flags = IORESOURCE_IRQ.

Where .start and .end is some value like 0x234, my question is if this
is an address of the phone's memory(RAM) or is it something else? I am
simply trying to figure out how various hardware issue interrupts, is
0x234 a memory address or a value that the CPU sees somehow(but from,
where?) and tries to find a handler for this specific interrupt.
My specific issue here is that I have a SoC that has an ARM cpu that
runs the Linux kernel and everything else, but the SoC also has
another chip that has a separate embedded arm CPU inside it running
some ARM code, which when it has some work to send it issues an
interrupt. And I am simply trying to understand how that works.
I apologize if my question is too generic and does not pertain to Linux at all.

Thank  you.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


overview of bust_spinlocks

2015-02-20 Thread manty kuma
What is the concept of bust_spinlocks()
In do_kernel_fault() function of ARM 64, we can see the following code

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/mm/fault.c?id=refs/tags/v3.19#n85

static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,
  unsigned int esr, struct pt_regs *regs){
/*   * Are we prepared to handle this kernel fault?  */
if (fixup_exception(regs))
return;

/*   * No handler, we'll have to terminate things with extreme
prejudice.   */*bust_spinlocks(1);*
pr_alert(Unable to handle kernel %s at virtual address %08lx\n,
 (addr  PAGE_SIZE) ? NULL pointer dereference :
 paging request, addr);

show_pte(mm, addr);
die(Oops, regs, esr);
bust_spinlocks(0);
do_exit(SIGKILL);}


I have looked into its definition. It is as follows:

void __attribute__((weak)) bust_spinlocks(int yes){
if (yes) {
++oops_in_progress;
} else {#ifdef CONFIG_VT
unblank_screen();#endif
console_unblank();
if (--oops_in_progress == 0)
wake_up_klogd();
}}

So basically when i am saying bust_spinlocks(1), it is just
incrementing the oops)_in_progress variable. How is it serving the
purposr of a lock here?

Best Regards,

Manty
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel Mocking

2015-02-20 Thread Kenneth Adam Miller
Thanks for your expedient answer!

So, I was discussing an alternative to mocking; function hooking. But in a
benign way. Is there any way to, at runtime replace the functionality of
code in order that you specify what it does for any given kernel function?

On Fri, Feb 20, 2015 at 3:24 PM, Greg KH g...@kroah.com wrote:

 On Fri, Feb 20, 2015 at 02:51:25PM -0500, Kenneth Adam Miller wrote:
  So, in userland development, the idea of mocking is used to isolate
 context
  management and machine configuration into a single class or set of
 functions
  that can be reused, and also facilitate testing much easier. Google mock
 is a
  great example.
 
  Say I develop a kernel module, and I want that module to have some
 result X
  after some returned result, whatever that might be. Is there anything
 similar
  for kernel code?

 Not really, sorry.  Running in the kernel means you don't have much room
 for simulation.  But you can use qemu, or other virtual machines and a
 debugger to test your code if you really want to.

 Good luck!

 greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel Mocking

2015-02-20 Thread Greg KH
On Fri, Feb 20, 2015 at 02:51:25PM -0500, Kenneth Adam Miller wrote:
 So, in userland development, the idea of mocking is used to isolate context
 management and machine configuration into a single class or set of functions
 that can be reused, and also facilitate testing much easier. Google mock is a
 great example.
 
 Say I develop a kernel module, and I want that module to have some result X
 after some returned result, whatever that might be. Is there anything similar
 for kernel code? 

Not really, sorry.  Running in the kernel means you don't have much room
for simulation.  But you can use qemu, or other virtual machines and a
debugger to test your code if you really want to.

Good luck!

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: Kernel Mocking

2015-02-20 Thread Jeff Haran


From: kernelnewbies-boun...@kernelnewbies.org 
[mailto:kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Kenneth Adam 
Miller
Sent: Friday, February 20, 2015 12:49 PM
To: kernelnewbies@kernelnewbies.org
Subject: Re: Kernel Mocking

Well I think that a function or system call semantics replacement facility 
would be useful to unit testers everywhere. It would be benign of course, 
requiring that the unit testing framework request of the kernel that it replace 
the kernel facilities specified prior to the test, and automatically replace 
them afterward. So, this isn't anything akin to doing anything malicious, it 
requires user cooperation in order to hook. It's not like something forcibly 
done. I'm thinking of an intel pin for kernel level code.

Kenneth,

Please refrain from top posting. 8^)

I was just thinking you might be able to leverage that gcc profiling mcount() 
function trick that ftrace uses.

I don’t understand that well enough to say whether it would be applicable for 
what you want to do,
but it would be something you could look into. You should check out ftrace in 
any case if you are
interested in this kind of thing. It’s a way cool facility and comes already 
enabled on many distros.

Jeff Haran

On Fri, Feb 20, 2015 at 3:45 PM, Greg KH 
g...@kroah.commailto:g...@kroah.com wrote:
On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
 Thanks for your expedient answer!

 So, I was discussing an alternative to mocking; function hooking. But in a
 benign way. Is there any way to, at runtime replace the functionality of code
 in order that you specify what it does for any given kernel function?

Not really, but there are some hacks you can do if you _really_ know
what you are doing.

Hint, don't do this, just write normal tests for your kernel code, we
have lots of them already in the source tree, look in tools/selftests/.

Best of luck,

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Beginner in Kernel Development

2015-02-20 Thread sahil aggarwal
Hi all,

I am using linux since past 9-10 months and have good programming skills in
C/C++. Since past few weeks i am looking for good source to dive in kernel
development but could not find the starting point and proper order of
learning to be followed to join the community. I will be grateful if
someone could point me in right direction.

Thanks
Regards
Sahil
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Beginner in Kernel Development

2015-02-20 Thread Sudip Mukherjee
On Sat, Feb 21, 2015 at 10:36 AM, sahil aggarwal sahil.ag...@gmail.com wrote:
 Hi all,

 I am using linux since past 9-10 months and have good programming skills in
 C/C++. Since past few weeks i am looking for good source to dive in kernel
 development but could not find the starting point and proper order of
 learning to be followed to join the community. I will be grateful if someone
 could point me in right direction.

i found the best way to start is The Eudyptula Challenge ,

regards
sudip

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel Mocking

2015-02-20 Thread Kenneth Adam Miller
Well I think that a function or system call semantics replacement facility
would be useful to unit testers everywhere. It would be benign of course,
requiring that the unit testing framework request of the kernel that it
replace the kernel facilities specified prior to the test, and
automatically replace them afterward. So, this isn't anything akin to doing
anything malicious, it requires user cooperation in order to hook. It's not
like something forcibly done. I'm thinking of an intel pin for kernel level
code.

On Fri, Feb 20, 2015 at 3:45 PM, Greg KH g...@kroah.com wrote:

 On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
  Thanks for your expedient answer!
 
  So, I was discussing an alternative to mocking; function hooking. But in
 a
  benign way. Is there any way to, at runtime replace the functionality of
 code
  in order that you specify what it does for any given kernel function?

 Not really, but there are some hacks you can do if you _really_ know
 what you are doing.

 Hint, don't do this, just write normal tests for your kernel code, we
 have lots of them already in the source tree, look in tools/selftests/.

 Best of luck,

 greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel Mocking

2015-02-20 Thread Greg KH
On Fri, Feb 20, 2015 at 03:26:40PM -0500, Kenneth Adam Miller wrote:
 Thanks for your expedient answer!
 
 So, I was discussing an alternative to mocking; function hooking. But in a
 benign way. Is there any way to, at runtime replace the functionality of code
 in order that you specify what it does for any given kernel function?

Not really, but there are some hacks you can do if you _really_ know
what you are doing.

Hint, don't do this, just write normal tests for your kernel code, we
have lots of them already in the source tree, look in tools/selftests/.

Best of luck,

greg k-h

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Kernel Mocking

2015-02-20 Thread Kenneth Adam Miller
So, in userland development, the idea of mocking is used to isolate context
management and machine configuration into a single class or set of
functions that can be reused, and also facilitate testing much easier.
Google mock is a great example.

Say I develop a kernel module, and I want that module to have some result X
after some returned result, whatever that might be. Is there anything
similar for kernel code?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


memcpy and restrict

2015-02-20 Thread Tolga Ceylan
Looking through the kernel source, I rarely see any usage
of __restrict C99 keyword.

Is there any convention or agreement for not using it?

Regards,
Tolga Ceylan

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies