Re: struct nbd_reply not packed = trouble?

2013-01-14 Thread


在 2013-1-11,0:42,Yann Droneaud ydrone...@opteya.com 写道:

 Hello kernel hackers,
 
 
 I noticed that in [linux]/include/uapi/linux/nbd.h the structure
 
   struct nbd_request {
   __be32 magic;
   __be32 type;/* == READ || == WRITE */
   char handle[8];
   __be64 from;
   __be32 len;
   } __attribute__((packed));
 
 is packed
 
 Given a target where ABI requires types to be aligned on their size (1 =
 1, 2 = 2, 4 = 4, 8 = 8, etc.)
 
 
 4 + 4 + 8 + 8 + 4 = 28 bytes
 
 To satisfy __be64 alignement (the strictest), it must be aligned on a 8
 bytes boundary, but 28 is not multiple of 8. 32 is. Padding is required.
 
 [The padding is required so that in a array of struct nbd_request[],
 all members of all structures are aligned to their requirement alignement]
 
 
 but its reply counter part
 
   struct nbd_reply {
   __be32 magic;
   __be32 error;/* 0 = ok, else error */
  char handle[8];  /* handle you got from request */
   };
 
 4 + 4 + 8 = 16 bytes.
 To satisfy __be32 alignement (the strictest), it must be aligned on a 4
 bytes boundary and 16 is a multiple of 4: no need for padding.
 
 is not.  Since Linux seems to read sizeof(nbd_reply) bytes from the
 network (see [1]), the number of bytes read varies with the number of
 bytes of the structure.
 
 
 It won't.
 
 
 So my understanding is that if the size of struct nbd_reply varies from
 platform/compiler to another that means trouble.  I wonder:
 
  - Is there anything about struct nbd_reply that would keep its size
equal everywhere or a reason why variance in size is no problem here?
 
  - Any ideas for a platform where you would expect struct nbd_reply to
be other than 4 + 4 + 8 = 16 bytes in size?
 
 Look for an ABI that require 'char' with either property:
 - size  1 byte
 - alignment  8 (16 bytes !)
 
 

  Do you mean this structure size will vary on different platform? If yes, 
why Linux does not packed here? Thanks


 Regards.
 
 -- 
 Yann Droneaud
 OPTEYA
 
 
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: What is asmlinkage ?

2013-01-11 Thread


在 2013-1-11,11:16,Peter Teoh htmldevelo...@gmail.com 写道:

 asmlinkage is defined for almost all arch:
 
 grep asmlinkage arch/arm/*/* and u got the answer.
 
 It seemed that:
 
  http://kernelnewbies.org/FAQ/asmlinkage
 
 gave the impression that asmlinkage is only for system call, or associated 
 with it.   Not really, nothing to do with system call actually.
 
 Even though majority (or ALL) of syscall are defined with asmlinkage, but 
 there are many that are not, eg, in arch/arm subdirectory:
 
 kernel/irq.c:asmlinkage void __exception_irq_entry
 kernel/process.c:asmlinkage void ret_from_fork(void) __asm__(ret_from_fork);
 kernel/smp.c:asmlinkage void __cpuinit secondary_start_kernel(void)
 kernel/smp.c:asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct 
 pt_regs *regs)
 
 just a few examples.   Essentially, it is just declared so that the name, for 
 example, do_IPI can be called from assembly, for example in the following 
 pair (arch/arm assumed):
 
 /kernel/smp.c:
 asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
 
 ./include/asm/entry-macro-multi.S:
   bne do_IPI
 
 More info:
 
 http://stackoverflow.com/questions/10060168/is-asmlinkage-required-for-a-c-function-to-be-called-from-assembly
 
 From above, asmlinkage is also NOT the only way..
 
 

The link you provided is obviously specific for X86, rather than ARM.
Rajat mentioned that there is no definition of linkage in arch/arm.  This 
should be true.

And as I know, arm use register r7 to pass system call number, and use 
register r0~r3 to pass parameters. This is used by Google when they implement 
system call in Android. 
 And for calling C function from assembly code is also platform specific, 
in ARM, it has fixed standard ABI which defines the details about how assembly 
code calls C function, you can never ask GCC to compile C function by passing 
parameters on stack and then assume this function can be called from assembly 
code which is implemented by other developers who obeys standard ARM ABI.




 On Fri, Jan 4, 2013 at 6:29 PM, anish singh anish198519851...@gmail.com 
 wrote:
 On Fri, Jan 4, 2013 at 3:41 PM, Rajat Sharma fs.ra...@gmail.com wrote:
  Is this correct for all architectures?
 
  I guess not, asmlinkage is undefined for arm, so I assume this mechanism is
  not there for arm.
 then how do they do it?
 
 
 
  On Fri, Jan 4, 2013 at 2:24 PM, 卜弋天 bu...@live.cn wrote:
 
 
 
  在 2013-1-4,15:38,Rajat Sharma fs.ra...@gmail.com 写道:
 
   So with asmlinkage we request compiler to put args on stack. What is
   advantage of this to start_kernel or in general to other functions ?
 
  See its about implementation ease and little of performance too. Assuming
  the default model of keeping arguments in registers is used. lets say
  arguments are assumed to be in registers R1, R2, R3, R4, R5, R6 and beyond
  that in stack. Since system call number is a transparent argument which is
  chopped off when calling the actual kernel handler and if R1 had the 
  system
  call number, then you have to shift all register values and stack 
  arguments
  too.
 
 Is this correct for all architectures?
 
 As I remembered, ARM uses SWI instruction to implement the system call,
  it will pass system call number by register R7, and use normal register
  R0~R3 to pass parameters.
 
 
 
  Now consider that all arguments are pushed on stack (as enforced by
  asmlinkage), you have all function argument in the beginning of the stack
  and the system call number on top of the stack. you just need to pop out
  stack top to remove system call number from function argument.
 
  You might argue that why not always keep system call number on stack top
  and use registers for function arguments? But thats part of the compiler 
  ABI
  and if you had fewer arguments lets say 2 only and used up R1 and R2 only,
  you may not jump to stack top directly for storing system call as its turn
  for R3 as argument.
 
  So, isn't it simpler implementation with everything on stack?
 
  -Rajat
 
 
  On Fri, Jan 4, 2013 at 12:13 PM, Rahul Bedarkar rpal...@gmail.com wrote:
 
  Thanks. So with asmlinkage we request compiler to put args on stack. What
  is advantage of this to start_kernel or in general to other functions ?
 
  Regards,
  Rahul
 
 
  On Thu, Jan 3, 2013 at 9:34 PM, Mulyadi Santosa
  mulyadi.sant...@gmail.com wrote:
 
  On Thu, Jan 3, 2013 at 7:40 PM, Rahul Bedarkar rpal...@gmail.com
  wrote:
   Hi,
  
   I was searching for asmlinkage and found that it is already explained
   at
   http://kernelnewbies.org/FAQ/asmlinkage
  
   But I didn't get this. Can someone tell me about it in brief ?
 
  the point is, parameters which is usually passed via stack, is passed
  using different way.
 
  A good example is system call they are passed using registers IIRC
 
 
  --
  regards,
 
  Mulyadi Santosa
  Freelance Linux trainer and consultant
 
  blog: the-hydra.blogspot.com
  training

Re: Find out function arguments value from stack pointer

2012-12-12 Thread


在 2012-12-12,19:28,Manavendra Nath Manav mnm.ker...@gmail.com 写道:

 On Wed, Dec 12, 2012 at 4:38 PM, Fabio Pozzi pozzi.fa...@gmail.com wrote:
 When i call  print values at offsets starting from
 __builtin_frame_address (0) the function arguments start from offset
 2. How can I confirm that this behavior is always consistent.
 
 Arguments are pushed on the stack before the saved frame pointer, thus
 you have to add an offset equal to the frame pointer address size if
 you start from the beginning of the saved frame pointer record on the
 stack.
 
 Thanks Fabio!
 If I execute the same code on ARM arch, does it needs any changes?
 

Arm does not use stack to pass parameters when parameters are less than 4, it 
uses registers r0 to r3 to pass parameters, and at the beginning of subroutine, 
r0 to r3 are not stored on stack. So it is complicated to find out parameters 
from stack as I know.


 -- 
 Manavendra Nath Manav
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: kernel stack memory

2012-09-13 Thread

i don't know why you want to corrupt kernel stack by using this method, stack 
usually grow from high address to low address, if you allocate a buff in a 
function then use memset(), it is writing data from low address to high 
address.in your implementation, you allocate an array with 8000*4=32000 bytes ( 
int arr[8000]; ), then you try to corrupt stack by using memset(), which 
operate memory by bytes, rather than by int. so this memset() only corrupt the 
first 8192 bytes of the buffer, which is far away from your current task stack. 
   thread_info locates at the bottom of current task's stack, please 
reference the source code of current_thread_info() function of your platform. i 
think it is true for X86 or ARM.   if you really want to corrupt current 
kernel task's stack, please try below code, i did't test it but i think it 
should work, at least you can find something from the log:  char *sp_addr;
 struct thread_info *thread = current_thread_info(); sp_addr = (char*)thread;
 
 printk(sp_addr==thread:%p, task:%p\n, thread, thread-task);
 
 memset (sp_addr, 0x0, 1024);
 
 printk(after corrupt, task:%p, it is dying...\n, thread-task);

  Date: Thu, 13 Sep 2012 15:32:05 +0530
 Subject: Re: kernel stack memory
 From: mujeeb.a...@gmail.com
 To: getaru...@gmail.com
 CC: shubham20...@gmail.com; kernelnewbies@kernelnewbies.org
 
 Hi,
 
 On Thu, Sep 13, 2012 at 1:59 PM, Arun KS getaru...@gmail.com wrote:
  Hello Shubham,
 
  On Thu, Sep 13, 2012 at 12:15 PM, shubham sharma shubham20...@gmail.com
  wrote:
 
  Hi,
 
  As far as i know, the size of stack allocated in the kernel space is
  8Kb for each process. But in case i use more than 8Kb of memory from
  the stack then what will happen? I think that in that case the system
  would crash because i am accessing an illegal memory area. I wrote
  kernel module in which i defined an integer array whose size was 8000.
  But still it did not crash my system. Why?
 
  The module i wrote was as follows:
 
  #include linux/kernel.h
  #include linux/module.h
 
  int __init init_my_module(void)
  {
  int arr[8000];
  printk(%s:%d\tmodule initilized\n, __func__, __LINE__);
  arr[1] = 1;
  arr[4000] = 1;
  arr[7999] = 1;
 
  Instead do a memset.
  memset(arr, 0, 8192);
 
  If you do this the current calling process thread_info will be set to zero.
  This should cause a crash.
 
 I tried and this is also not causing any crash.
 
 Thanks,
 Adil
 
  Thanks,
  Arun
 
 
 
  printk(%s:%d\tarr[1]:%d, arr[4000]:%d, arr[7999]:%d\n, __func__,
  __LINE__, arr[1], arr[4000], arr[7999]);
  return 0;
  }
 
  void __exit cleanup_my_module(void)
  {
  printk(exiting\n);
  return;
  }
 
  module_init(init_my_module);
  module_exit(cleanup_my_module);
 
  MODULE_LICENSE(GPL);
 
  ___
  Kernelnewbies mailing list
  Kernelnewbies@kernelnewbies.org
  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
 
 
  ___
  Kernelnewbies mailing list
  Kernelnewbies@kernelnewbies.org
  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: setup_thread_stack

2012-07-17 Thread


 



Date: Tue, 17 Jul 2012 21:15:50 +0200
Subject: setup_thread_stack
From: francesco.sc...@gmail.com
To: kernelnewbies@kernelnewbies.org

Hi, 
I'm totally new to kernel code, just trying to understand the basics of the 
core subsystems.
During the do_fork call, there is a call to dup_task_struct, which in turn 
calls setup_thread_stack. 
What's  this call supposed to do? Inside I can see a call to the 
task_thread_info macro, but I don't quite understand it:


#define task_thread_info(task) ((struct thread_info *)(task)-stack)


can a task_struct be cast to a thread_info? perhaps my C knowledge should be 
improved..I know :(


Sorry for the trivial question..just trying to understand :)
 
it is nothing about C, but architecture of kernel. kernel put thread_info of 
every process at the bottom of stack.
please reference thread_info.h for your specific cpu architecture:
/*
 * how to get the thread information struct from C
 */
static inline struct thread_info *current_thread_info(void) __attribute_const__;
static inline struct thread_info *current_thread_info(void)
{
 register unsigned long sp asm (sp);
 return (struct thread_info *)(sp  ~(THREAD_SIZE - 1));
}

because kernel put thread_info at the bottom of stack, so when one process is 
running, kernel can use above inline
function to get the thread_info conveniently.
 

Regards,


Francesco


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


RE: Why can not processes switch in atomic context?

2012-07-05 Thread


 

 Date: Wed, 4 Jul 2012 08:12:25 -0700
 Subject: Re: Why can not processes switch in atomic context?
 From: dhyla...@gmail.com
 To: bu...@live.cn
 CC: mobile.parmeni...@gmail.com; kernelnewbies@kernelnewbies.org
 
 Hi,
 
 On Wed, Jul 4, 2012 at 3:44 AM, 弋天 卜 bu...@live.cn wrote:
 
 
  在 2012-7-3,22:26,Parmenides mobile.parmeni...@gmail.com 写道:
 
 ...snip...
  1. For the spinlock case, it is easy to get if preemption is allowed
  in critical section, the purpose of protection provided by spinlock
  can not be achieved readily.
 
  i think disable preemption in spinlock is not for safe, it is
  For efficiency. Spinlock should exit as soon as possible.
  If tank1 get spinlock and goto sleep for 100 seconds before
  Release spinlock, task2 which requests the same spinlock
  Should wait for 100 seconds, for this example, mutex should be used instead 
  of spinlock.
 
 Unless, of course, the interrupt that fired tried to acquire the
 spinlock it preempted, in which case you would have deadlock, even on
 an SMP system, if the same processor happened to be used for both.
 
 
yes, i think you are right, suppose task1 use spin_lock_irqsave() to get a 
spinlock, 
then call schedule() to sleep for a long time, the interrupt on this cpu core 
will be
enabled by kernel, and if there is an interrupt triggered on the same cpu and 
get the same spinlock, deadlock will happen.
 

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


RE: Why can not processes switch in atomic context?

2012-07-04 Thread


 

 Date: Wed, 4 Jul 2012 08:12:25 -0700
 Subject: Re: Why can not processes switch in atomic context?
 From: dhyla...@gmail.com
 To: bu...@live.cn
 CC: mobile.parmeni...@gmail.com; kernelnewbies@kernelnewbies.org
 
 Hi,
 
 On Wed, Jul 4, 2012 at 3:44 AM, 弋天 卜 bu...@live.cn wrote:
 
 
  在 2012-7-3,22:26,Parmenides mobile.parmeni...@gmail.com 写道:
 
 ...snip...
  1. For the spinlock case, it is easy to get if preemption is allowed
  in critical section, the purpose of protection provided by spinlock
  can not be achieved readily.
 
  i think disable preemption in spinlock is not for safe, it is
  For efficiency. Spinlock should exit as soon as possible.
  If tank1 get spinlock and goto sleep for 100 seconds before
  Release spinlock, task2 which requests the same spinlock
  Should wait for 100 seconds, for this example, mutex should be used instead 
  of spinlock.
 
 Unless, of course, the interrupt that fired tried to acquire the
 spinlock it preempted, in which case you would have deadlock, even on
 an SMP system, if the same processor happened to be used for both.
 
 
  we are talking about schedule in spinlock, but not the synchronization 
between
normal process and interrupt.
  in your example, it is kernel developer's responsibility to make this 
correct, this is
why kernel give us the API spin_lock_irqsave(). if normal process and interrupt 
handler
will acquire the same spinlock, please use spin_lock_irqsave() instead of 
spin_lock().
 

  2. For the interrupt context case, I think when processing interrupt,
  kernel can be preempted in principle. But, this really increases the
  interrupt processing time which further cause longer response time and
  data missing in device. Except that, is there any other reasons?
 
  You are right, kernel can schedule in interrupt context, but that will 
  delay the completion of interrupt, which does not make sense, so kernel 
  will not do like this.
  Note! Kernel can, but should not schedule in interrupt context.
 
 Scheduling in an interrupt can hang the system. Lets suppose that A
 acquires a resource, disabled interrupts and calls schedule. Then B
 gets scheduled and wants the resource that A is holding so it blocks.
 But since interrupts were disabled, the timer tick will never fire and
 you're back into a deadlock situation again.
 
 
   in your example here, i think A is the interrupt handler, rather than a 
normal
task, because we are talking about scheduleing in interrupt handler. if A
calls schedule, the interrupted task, let's suppose it is usb task, will go
to sleep. let's suppose cpu0 handles the interrupt handler A, and usb task runs
on cpu0 also. after A go to sleep, which equals the usb task go to sleep, there 
must be another new task will be waked up by function switch_to(), let's suppose
this lucky guy is BT task, the interrupt on cpu0 could be re-enalbed by 
function svc_exit() 
before BT task(or some other tasks) runs. 
 
i think disable interrupt on cpu0 inside A does not mean the interrupt can 
only be re-enabled by A. 
 
i am not saying it is good to schedule inside interrupt handler, i just 
want to make it clear that
this can be done, but is not a good behavior and make no sense.
 

 -- 
 Dave Hylands
 Shuswap, BC, Canada
 http://www.davehylands.com
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


how to get create/compile time of vmlinux

2012-04-20 Thread




Hi All:i have a vmlinux file, how can i know when it is created/compiled?   
thanks.  Best Regards ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: how to use the memory allocated in kernel?

2012-04-18 Thread

Hi :you can find out the meaning in vmalloc.c, function vmalloc().
vmalloc accept only one parameter, the size of memory that you want to 
allocate.   this function will return the virtual address which you can use to 
read/write data inside it.   vmalloc hides some implementation details about 
real memory allocation, for example: the virtual address thatreturned from 
vmalloc() function is continuous, but physical memory can not continuous.  
vmalloc() will first call function alloc_vmap_area(), which you mentioned 
before, this function will occupy a continuousvirtuall address space in VMALLOC 
region, note that it only occupies virtual address space, no physical memory 
are mapped tothese virtual address at this moment. so if you operate at this 
virtual address as you did before, it is a bug! vmalloc() then call 
function __vmalloc_area_node(), which will find out enough non-continuous 
physical memory, then modifyPTEs of current task, map the virtual address to 
real physical memory. after this, you can operate at the address returned 
byalloc_vmap_area(). the example code you did lacks this action, you can try to 
add this and test again. i suggest that you use kmalloc() and vmalloc() 
directly. if you want to allocate small and physical continuous memory, use 
kmalloc().if you want to allocate very large(e.g. 10MB) and physical 
non-continuous memory, use vmalloc().  Best Regards
 Date: Wed, 18 Apr 2012 18:00:03 +0800
Subject: Re: how to use the memory allocated in kernel?
From: summer...@gmail.com
To: dhyla...@gmail.com
CC: kernelnewbies@kernelnewbies.org

Hi Dave,

Thanks for reply. My English is not very good, and so I want to ask about a 
term:map. Does map mean that create a relationship between the virtual space 
and physical memory?

Thanks again!


在 2012年4月18日 下午4:17,Dave Hylands dhyla...@gmail.com写道:

Hi ,



On Wed, Apr 18, 2012 at 12:44 AM, 夏业添 summer...@gmail.com wrote:

 Hi everyone,



 there are some functions can alloc memory in kernel, but it seems that I

 cannot use it directly. Here is my code:



 static int mytest_vm(){



 struct vm_struct *v_start;



 v_start=alloc_vm_area(PAGE_SIZE,NULL); //the kernel api has changed,

 I don't understand why there is a second parameter

 if(v_start==NULL){

 printk(cannot alloc page\n);

 return -1;

 }



 sprintf((char *)v_start-addr,this is a test.\n);

 printk(after sprintk:%s,(char *)v_start-addr);



 free_vm_area(v_start);



 return 0;

 }

 module_init(mytest_vm);



 but it just got a kernel Oops. Can anyone explain this to me? Thanks very

 much!



If my understanding of things is correct, this just allocates virtual

space. That virtual space isn't backed by any physical pages.



The normal kernel allocators are things like kmalloc and vmalloc.



--

Dave Hylands

Shuswap, BC, Canada

http://www.davehylands.com




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


RE: static I/O device mapping of UART for early prints console

2012-03-11 Thread


  Date: Sun, 11 Mar 2012 12:29:44 +0530
 Subject: static I/O device mapping of UART for early prints  console
 From: pcuser.ma...@gmail.com
 To: kernelnewbies@kernelnewbies.org
 
 I'm doing kernel porting to arm926 based FPGA board (similar to
 samsung-s3c6410 board). I'm trying to setup UART for early print and
 console.
 I gone through some reference boards(samsung-s3c6410) for setting up
 uart for early print  console.
 
 I can't trace the virtual mapping for UART registers in adduart
 macro in debug-macro.S file
 
 .macro addruart, rp, rv
  ldr \rp, = S3C_PA_UART
  ldr \rv, = S3C_VA_UART
 
 
 Basically,I want to know how to calculate this virtual
 address(S3C_VA_UART)  from the physical address(S3C_PA_UART)
actually, this is io_virtual_address map to io_physical_address, it is not 
equal to kernel_virtual_adressmap to kernel_physical_address.differenct 
platform providers such as Qualcomm, TI, STE, Samsung use different fomula to 
map IO address. for example, for OMAP1, TI use a very simple fomula to map from 
io_virtual_address to io_physical_address:io_virtual_address = 
io_physical_address-0x0100 so suppose TI's uart0 physical address is 
0xFFFB, then the virtial address of uart0 is 0xFEFB. for Samsung 
S3c64XX: 1. both physical and virtual address of uart is defined in 
map.h:#define S3C_PA_UART  (0x7F005000)
/* See notes on UART VA mapping in debug-macro.S */
#define S3C_VA_UARTx(x) (S3C_VA_UART + (S3C_PA_UART  0xf) + ((x) * 
S3C_UART_OFFSET))#define S3C_VA_UART0  S3C_VA_UARTx(0)
#define S3C_VA_UART1  S3C_VA_UARTx(1)
#define S3C_VA_UART2  S3C_VA_UARTx(2)
#define S3C_VA_UART3  S3C_VA_UARTx(3) 2. so for uart0, the virtual address will 
be:virtual_uart0_address = S3C_VA_UART + (S3C_PA_UART  0xf) and in 
map-base.h:#define S3C_ADDR_BASE (0xF400)
#define S3C_VA_UART S3C_ADDR(0x0100) /* UART */
so S3C_VA_UART = 0xF500 3. at last:virtual_uart0_address = S3C_VA_UART + 
(S3C_PA_UART  0xf)= 0xF500 + (0x7F005xf) = 0xF5005000 
please do not try to use  __phys_to_virt, this is for kernel virtual address to 
kernel physical address translation, rather than IO address map.
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


How to avoid kernel Oops 0x81F in function do_alignment() ?

2012-03-03 Thread




Hi experts:   an user application generates a un-alignment data abort, then 
in function do_alignment, kernel read the instruction from the address where 
data abort occurs by:  fault = __get_user(instr, (u32 *)instrptr);after 
this sentence, instr is the error instruction that generate data abort.i 
change this instruction from strict alignment check instruction to not strict 
alignmentcheck instruction by:   instr = instr030;at last i write this 
instruction back to ram, and let cpu execute this instruction again:
*((u32*)instrptr) = instr;it works on kernel 2.6.35, but on version 3.0, it 
failed, the last sentence above generates a Oops: [   58.966552] Unable to 
handle kernel paging request at virtual address 84ec
[   58.974029] pgd = db9f4000
[   58.976806] [84ec] *pgd=1b9db831, *pte=0ae5f59f, *ppte=0ae5fe7e
[   58.986877] Internal error: Oops: 81f [#1] PREEMPT SMP1. it seems that 
kernel 3.0 can not modify user mode program instructions directly even underSVC 
mode.   2. how can i change the page permisson before write back instruction of 
user mode application?  for example, find out the page tables of current 
application, find out the pte which representsthe instruction that generate 
data abort, then modify pte, write back instruction, restore pte, done.how 
to do these? please advise, thanks very much.  Best Regards 
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


is there any Android APK that generate the SIGBUG error because of ARM NEON instructions?

2012-02-24 Thread


Hi All:
 
anybody who met such error of Android application? the logcat will be 
something like below:
 
signal 7 (SIGBUS), code 128 (?), fault addr 

#00  pc 00015cec  /data/data/com.pccw.mobile.sip/lib/libavcodec.so
--this lib use ARM NEON instructions
 
 
 
   i found that Linux Kernel(even in latest 3.2 version) does not support 
un-alignment NEON instruction in data abort handler, if anybody who are 
interested in this topic, please contact me, i can provide the patch to 
workaroud it.

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


RE: SA_INTERRUPT or SA_SHIRQ

2012-02-23 Thread

Hi Devendra:can you please tell me your kernel version?   SA_INTERRUPT is 
deprecated for many years. it is changed to be IRQF_DISABLED, which is also 
deprecated since 2.6.35.   in kernel 2.6.35, top half interrupt handler will be 
called with interrupts disabled, and for SA_SHIRQ, it is changed to be 
IRQF_SHARED, you should check the return value of request_irq() to see whether 
your irq can be shared with formerregistered irq which use the same int 
line. suppose you are registering irq19 for usb, and the BT module has 
reigstered irq19 with IRQF_SHARED flag, then you are lucky enough to reigter 
correctly for usb. opposite, if BT module registered irq19 without IRQF_SHARED 
flag, then BT will use irq19 alone, it means your register for usb will fail .  
Best Regards
 Date: Wed, 22 Feb 2012 14:56:41 +0530
Subject: SA_INTERRUPT or SA_SHIRQ
From: devendra.rawat.si...@gmail.com
To: kernelnewbies@kernelnewbies.org

Hi All,

If I register an ISR using both the flags SA_INTERRUPT and SA_SHIRQ set, what 
kind of interrupt line will I get a dedicated one or a shared one ?
the exact definition is

request_irq(dev-pci_dev-irq, soc_intr, SA_INTERRUPT | SA_SHIRQ,

  MODULE_NAME, dev);

thanks in advance,
Devendra


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


RE: pagetables used in interrupt context

2012-02-23 Thread

Hi Subin: for kernel version 2.6.35, ARM architecture, when interrupt 
occurs, kernel will change from USER/SVC mode to IRQ mode,backup some registers 
and change to SVC mode immediately, handle the real interrupt handler in SVC 
mode, which people say in interrupt context.kernel will use the 
stack(interrupt context) of interrupted thread to handle the interrupt, and 
there is no MMU operation which do page table switch.so the thread which is 
interrupted by interrupt, it's kernel mode stack will be choosed as the 
interrupt context of current interrupt.   Date: Tue, 21 Feb 2012 19:18:32 -0700
 Subject: Re: pagetables used in interrupt context
 From: subingangadha...@gmail.com
 To: dhyla...@gmail.com
 CC: kernelnewbies@kernelnewbies.org
 
 Thank you for clearing my doubt.
 
 On Mon, Feb 20, 2012 at 8:39 PM, Dave Hylands dhyla...@gmail.com wrote:
  Hi Subin,
 
  On Mon, Feb 20, 2012 at 6:47 PM, subin gangadharan
  subingangadha...@gmail.com wrote:
  Hi All,
 
  Please correct me if I am wrong. In linux each process will have its
  own page tables, so when a interrupt happens processor will switch to
  interrupt context
  and execute the proper handler. So my doubt, if this is the case,
  interrupt hanlder will be using the pagetables of the interrupted
  process or is there a separate page table for this.
 
  Yep - that's right. Conceptually you can imagine that the kernel page
  tables are replicated in each process, so when the interrupt occurs,
  the kernel mappings will always be in effect regardless of which task
  is running. How this is actually achieved may vary from architecture
  to architecture.
 
  --
  Dave Hylands
  Shuswap, BC, Canada
  http://www.davehylands.com
 
 
 
 -- 
 With Regards
 Subin Gangadharan
 
 I am not afraid and I am also not afraid of being afraid.
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: pagetables used in interrupt context

2012-02-23 Thread

Hi : for ARM architecture, from the point of my view, interrupt can be 
handled in IRQ, SVC, or SYSTEM modes.1.if kernel handles interrupt in IRQ 
mode, it can use separate specific stack of IRQ mode to handle interrupt,but it 
cannot support nest interupt, suppose you are running interrupt handler in IRQ 
mode, a new coming interrupt will corrupt the lr_irq which is used for current 
function.2. if kernel handles interrupt in SYSTEM mode, the sequences will 
be : hardware interrupt occurs--IRQ mode--SYSTEM mode --call interrupt 
handler.   kernel can support nest interrupt well by this way, the problem 
is SYSTEM mode use the same register with USER mode, which means kernel will 
use the  interrupted thread's user mode stack, this will leake information of 
kernel to user space, so it is not a good idea, although i did this for many 
years for OMAP chipset(the OS is not linux, it is mixed by REX and my own 
design.).3. Linux kernel choose the last one, handle interrupt in SVC mode, 
which can support nest interrupt if it wants(2.6.35 does not support this). and 
it is very simple to use the interrupted thread's kernel mode stack as the 
interrupt context. if kernel use a specific stack which is for interrupt only, 
the sequences will be : hardware interrupt occurs--IRQ mode--SVC 
mode--backup sp register of interrupted thread to it's TCB---set sp register 
to be the specific kernel stack address--call interrupt handler---restore sp 
of interrupted thread---return from interrupt.this is a little 
complicated compared with the current design. so i agree with the current 
design.  Best Regards
  Date: Thu, 23 Feb 2012 08:41:28 -0600
 Subject: Re: pagetables used in interrupt context
 From: c.a.subraman...@gmail.com
 To: bu...@live.cn
 CC: dhyla...@gmail.com; subingangadha...@gmail.com; 
 kernelnewbies@kernelnewbies.org
 
 On Thu, Feb 23, 2012 at 6:52 AM, 卜弋天 bu...@live.cn wrote:
  Hi Subin:
 
  for kernel version 2.6.35, ARM architecture, when interrupt occurs,
  kernel will change from USER/SVC mode to IRQ mode,backup some registers and
  change to SVC mode immediately, handle the real interrupt handler in SVC
  mode, which people say in interrupt context.
  kernel will use the stack(interrupt context) of interrupted thread to
  handle the interrupt, and there is no MMU operation which do page table
  switch.
  so the thread which is interrupted by interrupt, it's kernel mode stack
  will be choosed as the interrupt context of current interrupt.
 
 Thanks ! thats a terse explanation! Can you please mention why we do
 not have a IRQ stack (in terms of size of the stack) to do the
 processing?
 
  Date: Tue, 21 Feb 2012 19:18:32 -0700
  Subject: Re: pagetables used in interrupt context
  From: subingangadha...@gmail.com
  To: dhyla...@gmail.com
  CC: kernelnewbies@kernelnewbies.org
 
 
  Thank you for clearing my doubt.
 
  On Mon, Feb 20, 2012 at 8:39 PM, Dave Hylands dhyla...@gmail.com wrote:
   Hi Subin,
  
   On Mon, Feb 20, 2012 at 6:47 PM, subin gangadharan
   subingangadha...@gmail.com wrote:
   Hi All,
  
   Please correct me if I am wrong. In linux each process will have its
   own page tables, so when a interrupt happens processor will switch to
   interrupt context
   and execute the proper handler. So my doubt, if this is the case,
   interrupt hanlder will be using the pagetables of the interrupted
   process or is there a separate page table for this.
  
   Yep - that's right. Conceptually you can imagine that the kernel page
   tables are replicated in each process, so when the interrupt occurs,
   the kernel mappings will always be in effect regardless of which task
   is running. How this is actually achieved may vary from architecture
   to architecture.
  
   --
   Dave Hylands
   Shuswap, BC, Canada
   http://www.davehylands.com
 
 
 
  --
  With Regards
  Subin Gangadharan
 
  I am not afraid and I am also not afraid of being afraid.
 
  ___
  Kernelnewbies mailing list
  Kernelnewbies@kernelnewbies.org
  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
  ___
  Kernelnewbies mailing list
  Kernelnewbies@kernelnewbies.org
  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RE: pagetables used in interrupt context

2012-02-23 Thread

Hi Subin:
 
 i am not familiar with other architecture, but for ARM, Linux Kernel 
2.6.35, i checked the function handle_level_irq()and handle_edge_irq() in 
chip.c, both of them will call handle_IRQ_event() which is in handle.c. and the 
function handle_IRQ_event() will call the interrupt handler written by user. 
Kernel does not open interrupt(ARM CPSR I bit)when calling interrupt handler in 
handle_IRQ_event() function. this is only for top-half interrupt handling.  for 
bottom-half, it is no doubt that the interrupt will be opened.
 
 so if you register a interrupt by request_irq(), the interrupt handler 
will be called with irq disabled. i tested on Cortex-A9 dual core platform, it 
is right.
 

 

 Date: Thu, 23 Feb 2012 11:12:06 -0600
 Subject: Re: pagetables used in interrupt context
 From: subingangadha...@gmail.com
 To: bu...@live.cn
 CC: c.a.subraman...@gmail.com; dhyla...@gmail.com; 
 kernelnewbies@kernelnewbies.org
 
 Hi ,
 
  can support nest interrupt if it wants(2.6.35 does not support this). and it
  is very simple to use the interrupted thread's kernel mode stack as the
  interrupt context. if kernel use a specific stack which is for interrupt
 
 Thanks for the crystal clear explanation of the page table usage in
 interrupt context. I have one more doubt, so in 2.6.35 as you said it
 doesn't support
 nested interrupt, does it mean that all other interrupts are
 completely disabled, (I mean no other can interrupt the processor)
 while executing an interrupt handler.
 
 
 
 2012/2/23 卜弋天 bu...@live.cn:
  Hi :
 
  for ARM architecture, from the point of my view, interrupt can be
  handled in IRQ, SVC, or SYSTEM modes.
  1.if kernel handles interrupt in IRQ mode, it can use separate specific
  stack of IRQ mode to handle interrupt,but it cannot support nest interupt,
  suppose you are running interrupt handler in IRQ mode, a new coming
  interrupt will corrupt the lr_irq which is used for current function.
  2. if kernel handles interrupt in SYSTEM mode, the sequences will be :
  hardware interrupt occurs--IRQ mode--SYSTEM mode --call
  interrupt handler.
  kernel can support nest interrupt well by this way, the problem is
  SYSTEM mode use the same register with USER mode, which means kernel will
  use the interrupted thread's user mode stack, this will leake information
  of kernel to user space, so it is not a good idea, although i did this for
  many years for OMAP chipset(the OS is not linux, it is mixed by REX and my
  own design.).
  3. Linux kernel choose the last one, handle interrupt in SVC mode, which
  can support nest interrupt if it wants(2.6.35 does not support this). and it
  is very simple to use the interrupted thread's kernel mode stack as the
  interrupt context. if kernel use a specific stack which is for interrupt
  only, the sequences will be : hardware interrupt occurs--IRQ mode--SVC
  mode--backup sp register of interrupted thread to it's TCB---set sp
  register to be the specific kernel stack address--call interrupt
  handler---restore sp of interrupted thread---return from interrupt.
  this is a little complicated compared with the current design. so i
  agree with the current design.
 
 
  Best Regards
 
  Date: Thu, 23 Feb 2012 08:41:28 -0600
 
  Subject: Re: pagetables used in interrupt context
  From: c.a.subraman...@gmail.com
  To: bu...@live.cn
  CC: dhyla...@gmail.com; subingangadha...@gmail.com;
  kernelnewbies@kernelnewbies.org
 
 
  On Thu, Feb 23, 2012 at 6:52 AM, 卜弋天 bu...@live.cn wrote:
   Hi Subin:
  
   for kernel version 2.6.35, ARM architecture, when interrupt occurs,
   kernel will change from USER/SVC mode to IRQ mode,backup some registers
   and
   change to SVC mode immediately, handle the real interrupt handler in SVC
   mode, which people say in interrupt context.
   kernel will use the stack(interrupt context) of interrupted thread to
   handle the interrupt, and there is no MMU operation which do page table
   switch.
   so the thread which is interrupted by interrupt, it's kernel mode stack
   will be choosed as the interrupt context of current interrupt.
  
  Thanks ! thats a terse explanation! Can you please mention why we do
  not have a IRQ stack (in terms of size of the stack) to do the
  processing?
  
   Date: Tue, 21 Feb 2012 19:18:32 -0700
   Subject: Re: pagetables used in interrupt context
   From: subingangadha...@gmail.com
   To: dhyla...@gmail.com
   CC: kernelnewbies@kernelnewbies.org
  
  
   Thank you for clearing my doubt.
  
   On Mon, Feb 20, 2012 at 8:39 PM, Dave Hylands dhyla...@gmail.com
   wrote:
Hi Subin,
   
On Mon, Feb 20, 2012 at 6:47 PM, subin gangadharan
subingangadha...@gmail.com wrote:
Hi All,
   
Please correct me if I am wrong. In linux each process will have its
own page tables, so when a interrupt happens processor will switch
to
interrupt context
and execute the proper handler. So my doubt, if this is the case,
interrupt hanlder will be using

RE: arm assembly doubt

2012-02-18 Thread

Hi:  the  SWI is used for system APIs such as open, read, write. user mode 
applications call system APIs via SWI, which will change ARM mode from USER to 
SVC. so when vector_swi is called, Linux will do as below: 1. store 
r0~r12, these registers are universal for USR mode SVC mode. 2. store r13 
and r14 of USER mode. Note, SWI is triggered from USER mode, so here Linux 
store USER mode's r13 and r14, rather than SVC's. for your two 
questions:  1. the ^ means to get USER mode registers, rather than current 
mode.
 2. no matter how you arrange registers in opcode {}, stmdb will always 
push lr first, then sp. so after line 348, the stack view is as 
below:lr_usrsp_usrr12...r0   Date: Thu, 16 Feb 2012 19:35:17 -0700
 Subject: Re: arm assembly doubt
 From: subingangadha...@gmail.com
 To: su...@gatech.edu
 CC: kernelnewbies@kernelnewbies.org
 
 Thanks for the answer. Actually this is what I am trying to understand.
 
 ENTRY(vector_swi)
 345 sub sp, sp, #S_FRAME_SIZE
 346 stmia   sp, {r0 - r12}  @ Calling r0 - r12
 347  ARM(   add r8, sp, #S_PC   )
 348  ARM(   stmdb   r8, {sp, lr}^   )   @ Calling sp, lr
 349  THUMB( mov r8, sp  )
 350  THUMB( store_user_sp_lr r8, r10, S_SP  )   @ calling sp, lr
 351 mrs r8, spsr@ called from
 non-FIQ mode, so ok.
 352 str lr, [sp, #S_PC] @ Save calling PC
 353 str r8, [sp, #S_PSR]@ Save CPSR
 354 str r0, [sp, #S_OLD_R0]
 
 In this case after the line number 348(if its in arm mode),will the
 kernel stack have the contents
 r0-r12,sp,lr in this order or r0-r12,lr,sp this one. Beccause I
 believe stmdb r8, {sp, lr}^ will push the sp first then lr. In that
 case sp and lr will be interchanged in struct pt_regs.
 
 Please correct me if I am wrong.
 
 
 
 
 
 On Wed, Feb 15, 2012 at 9:34 PM, Surenkumar Nihalani su...@gatech.edu wrote:
  Hi,
  On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:
 
  Hi ,
 
  I am trying to understand how system call is implmented in linux for
  arm.And I am not that familiar with arm assembly.
 
  Could any body please help me to understand what exactly this ^ does
  in this instruction stmdb r8,{sp,lr}^
 
  --
  With Regards
  Subin Gangadharan
 
  I am not afraid and I am also not afraid of being afraid.
 
  ___
  Kernelnewbies mailing list
  Kernelnewbies@kernelnewbies.org
  http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
 
  Example:
 LDFMD sp!, {r0-r12, pc}^
  - The ^ qualifier specifies that the CPSR is restored from the SPSR.
It must be used only from a privileged mode.
 
 
 
 
 -- 
 With Regards
 Subin Gangadharan
 
 I am not afraid and I am also not afraid of being afraid.
 
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies