Re: memory management with mmap

2012-10-27 Thread Sengottuvelan S
Hi Mulyadi

I am able to do mmap and access virual-memory address and pages for a
single process from user-space and working fine. I am not sure how to do it
for multiple processes for shared resources using mmap.  I better explain
in detail here what I am experimenting it.

for example:

Kernel allocates kmalloc or vmalloc of 100 pages and set those pages
as reserved. Kernel uses these pages to send/receive data to Process A or B
depends on a condition.

Process A and B do mmap those region to get/set data on those
virtual-addresses/pages because I want faster access from userpace to
kernel.

Anyone knows if this will work with mmap?. Please let me know  if anyother
way to do it.

On Sat, Oct 27, 2012 at 10:57 PM, Mulyadi Santosa  wrote:

> Hi...
>
> On Thu, Oct 18, 2012 at 3:02 AM, Sengottuvelan S
>  wrote:
> > For example,
> >
> > I have 2 different user space process A,B etc. I have to allocate memory
> in
> > Kernel for each of those processes (for example 2 pages) .  Each process
> is
> > allowed to use only 1 page using mmap from user space.
> >
> > Is it possible to do with mmap?.
>
> Not sure, but I guess better to do it directly with page_alloc...or at
> least kmalloc() to better utilize slab.
>
> The thing that I think is hard to do, is to implement protection
> scheme to make sure say process A won't access page allocated by
> process B.
>
> Hopefully I understand your goal correctly.
>
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>



-- 
Regards,
S. Sengottuvelan.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: memory management with mmap

2012-10-27 Thread Mulyadi Santosa
Hi...

On Thu, Oct 18, 2012 at 3:02 AM, Sengottuvelan S
 wrote:
> For example,
>
> I have 2 different user space process A,B etc. I have to allocate memory in
> Kernel for each of those processes (for example 2 pages) .  Each process is
> allowed to use only 1 page using mmap from user space.
>
> Is it possible to do with mmap?.

Not sure, but I guess better to do it directly with page_alloc...or at
least kmalloc() to better utilize slab.

The thing that I think is hard to do, is to implement protection
scheme to make sure say process A won't access page allocated by
process B.

Hopefully I understand your goal correctly.


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

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


Re: Tools for checking incorrect usage of locking techniques in k-space

2012-10-27 Thread Kumar amit mehta
On Sat, Oct 27, 2012 at 09:26:51PM +0530, Srivatsa Bhat wrote:
> On Sat, Oct 27, 2012 at 10:11 AM, Kumar amit mehta  
> wrote:
> > Hi,
> >
> > I recently came across this tool called KEDR[1] for checking memory leak in
> > kernel modules. I'm using it to check If my trivial kernel modules (based on
> > LDD3 examples) are leaking memory. I was wondering if there exist a similar
> > tool for checking incorrect usage of locking techniques implemented by 
> > kernel
> > module.
> >
> 
> You can make use of the in-kernel "lockdep" framework to check your locking.
> Just enable it in your .config, and build and boot your kernel. Lockdep 
> detects
> a variety of locking problems at run time and warns you if there is a
> possibility
> of deadlock etc.
> 
> Regards,
> Srivatsa S. Bhat
Thank you Srivatsa. It seems that lockdep framework is enabled on my running
kernel.


amit@ubuntu:/boot$ egrep -i "debug_kernel|lockdep" config-3.2.0-29-generic-pae 
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_DEBUG_KERNEL=y


If above configuration is all that I need, then should I be seeing warning/error
messages in kernel logs(/var/log/kern.log) when there is inconsistency in
locking ? To test my hypothesis, I modified my simple kernel module to
deliberately induce locking error (After initializing read-write semaphore, I 
call 
down_write() and do not free this semaphore lock by commenting out up_write() 
invocation). But still I don't see any error or warning message trace in kernel
logs, I think, I'm missing something. I've just now found out that there is a 
tutorial on runtime locking correctness validator[1] under Documentation. I'll 
go through it.

On the other hand, I found this KEDR utility very simple and accurate in finding
out the erroneous memory handling. For example, this is how the KEDR reports
memory leakage in my kernel module:

2670043 Oct 27 06:32:38 ubuntu kernel: [16963.930621] Inside echo_exit: kfree()
2670044 Oct 27 06:32:38 ubuntu kernel: [16963.930886] [leak_check] LeakCheck has
detected possible memory leaks:
2670045 Oct 27 06:32:38 ubuntu kernel: [16963.930897] [leak_check] Address:
0xeeafbb70, size: 9; stack trace of the allocation:
2670046 Oct 27 06:32:38 ubuntu kernel: [16963.930907] [leak_check] []
echo_write+0x42/0xd0 [echo] 
2670047 Oct 27 06:32:38 ubuntu kernel: [16964.001413] [leak_check] []
vfs_write+0x8f/0x160
2670048 Oct 27 06:32:38 ubuntu kernel: [16964.001421] [leak_check] []
sys_write+0x3d/0x70
2670049 Oct 27 06:32:38 ubuntu kernel: [16964.002214] [leak_check] []
sysenter_do_call+0x12/0x28
2670050 Oct 27 06:32:38 ubuntu kernel: [16964.002238] [leak_check] []
0x
2670051 Oct 27 06:32:38 ubuntu kernel: [16964.002242] [leak_check]

2670052 Oct 27 06:32:38 ubuntu kernel: [16964.002248] [leak_check] Totals:
2670053 Oct 27 06:32:38 ubuntu kernel: [16964.002251] [leak_check] Allocations:
3
2670054 Oct 27 06:32:38 ubuntu kernel: [16964.002255] [leak_check] Possible
leaks: 1
2670055 Oct 27 06:32:38 ubuntu kernel: [16964.002257] [leak_check] Unallocated
frees: 0
2670056 Oct 27 06:32:38 ubuntu kernel: [16964.002260] [leak_check]  end
of LeakCheck report 

As you can see that with reports generated by KEDR like above, it becomes easy
to detect the memory leak and therefore I'm looking at something similar like 
KEDR
for detecting locking errors in kernel module.

-Amit
[1] http://lxr.linux.no/#linux+v3.6.3/Documentation/lockdep-design.txt

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


Re: Tools for checking incorrect usage of locking techniques in k-space

2012-10-27 Thread Srivatsa Bhat
Hi,

On Sat, Oct 27, 2012 at 10:11 AM, Kumar amit mehta  wrote:
> Hi,
>
> I recently came across this tool called KEDR[1] for checking memory leak in
> kernel modules. I'm using it to check If my trivial kernel modules (based on
> LDD3 examples) are leaking memory. I was wondering if there exist a similar
> tool for checking incorrect usage of locking techniques implemented by kernel
> module.
>

You can make use of the in-kernel "lockdep" framework to check your locking.
Just enable it in your .config, and build and boot your kernel. Lockdep detects
a variety of locking problems at run time and warns you if there is a
possibility
of deadlock etc.

Regards,
Srivatsa S. Bhat

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


a quick wiki page on kernel-doc

2012-10-27 Thread Robert P. J. Day

http://www.crashcourse.ca/wiki/index.php/Kernel-doc

  this also represents potential for cleanup since, when you run
something like

  $ make htmldocs

you'll get warnings when the inline documentation doesn't match the
corresponding function/structure/enum, etc.  so let's of room for
documentation cleanup.

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday


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


IO operations and MOV to/from CR3

2012-10-27 Thread Onkar N Mahajan
Hi List, 

I prepared some notes for CR3 involvement in different IO
operations, so here are the notes

- memory-mapped IO & DMA IO: 
- Each such operation involves MOV to/from CR3 :
- MOV from CR3 causes "Unconditional VM exit"
- MOV to CR3 causes "Conditional VM exit" :
- The MOV to CR3 instruction causes a VM exit unless the 
  value of its source operand is equal to one of the 
  CR3-target values specified in the VMCS (controlled by 
  Hypervisor). This feature allows a guest kernel to 
  change the CR3 value without causing a world switch to   
  the hypervisor, provided that the value written into 
  the CR3 register was previously specified by the 
  hypervisor in the CR3-Target registers. An execution of 
  MOV to CR3 in VMX non-root operation does not cause a VM 
  exit if its source operand matches one of these 
  previsously stored values. If the CR3-target count is n, 
  only the first n (0 .. (n-1)) CR3-target 
  values do not cause VM-Exit. nth value causes VM-Exit. 
  if n=0 , MOV to CR3 always causes VM-Exit.

Please comment if I understood something incorrectly here.

Regards,
K Arun Kumar


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


IO operations and MOV to/from CR3

2012-10-27 Thread K Arun Kumar
Hi List, 

I prepared some notes for CR3 involvement in different IO
operations, so here are the notes

-   memory-mapped IO & DMA IO:  
-   Each such operation involves MOV to/from CR3 :
-   MOV from CR3 causes "Unconditional VM exit"
 -  MOV to CR3 causes "Conditional VM exit" :
-   The MOV to CR3 instruction causes a VM exit unless the 
value
of its
source operand is equal to one of the CR3-target values 
specified in 
the VMCS (controlled by Hypervisor). This feature 
allows a guest
kernel to 
change the CR3 value without causing a world switch to 
the
hypervisor,
provided that the value written into the CR3 register 
was previously 
specified by the hypervisor in the CR3-Target 
registers. An
execution 
of MOV to CR3 in VMX non-root operation does not cause 
a VM exit if 
its source operand matches one of these previsously 
stored values. 
If the CR3-target count is n, only the first n (0 .. 
(n-1))
CR3-target 
values do not cause VM-Exit. nth value causes VM-Exit. 
if n=0 , 
 MOV to CR3 always causes VM-Exit.

Please comment if I understood something incorrectly here.

Regards,
K Arun Kumar 
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Etiquette of submitting patches for fixing coding style.

2012-10-27 Thread Robert P. J. Day
On Fri, 26 Oct 2012, Greg Freemyer wrote:

> fyi: Robert Day just asked for help cleaning up the Doc Book stuff.
>
> Doc Book pull comments out of the .c files and creates documentation.
> To clean it up, patches to the source files will be required.  These
> are more likely to be accepted.
>
> So you could to a doc book series like:
>
> 0/2 a patch series to correct the documentation for xyz subsystem
> 1/2 checkpatch cleanup of the 2 files with doc updates
> 2/2 doc updates

  if you want to get started making fixes and submitting patches, i
suggest doc fixes as an easy way to jump in for the simple reason that
just making changes to documentation shouldn't break anything. :-)
there is a separate list just for kernel documentation:

  http://vger.kernel.org/vger-lists.html#linux-doc

so you know you'll be on-topic there chatting about documentation.
from the perspective of someone who has no *official* connection with
the kernel but who's submitted lots of pedantic patches over the
years, let me make a couple suggestions.

  first, a *lot* of what's under the Documentation/ directory is
absurdly old and worthless, and should probably be just deleted.
ignore that stuff. other stuff under there is perfectly up-to-date,
and should be left alone.

  the middle ground is the stuff that can be updated to reflect the
current kernel, so pick a single file under there that reflects
something you're interested in, start going through it, make
corrections, and submit the final patch to the linux-doc list.  try to
work with a single file or topic at a time, it's easier to get your
patches accepted.

  post on the kernel-doc stuff coming shortly, for the interested.

rday

-- 


Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca

Twitter:   http://twitter.com/rpjday
LinkedIn:   http://ca.linkedin.com/in/rpjday


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


Re: linux segment

2012-10-27 Thread Jun Hu
Can you post out your codes ?

From: Fan Yang 
Sent: Wednesday, October 24, 2012 8:04 PM
To: kernelnewbies@kernelnewbies.org 
Subject: linux segment

Hi all: 
I print the cs ds and ss register in the user space, and it is same as the 
__USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the kernel 
__KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print this two 
value in my kernel module, I get 60 and 7b. Why ? It should be 60 and 68, 
shouldn't it? 






___
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