Re: Need good starting point

2022-02-15 Thread Rohan Puri
On Tue, Feb 15, 2022 at 9:01 PM Ankit Pandey  wrote:
>
> Hello,
>
> I have gone through tutorials at kernelnewbies and was able to compile, build 
> and run the kernel on qemu. But I'm stuck now. I tried to look for style 
> fixes in drives/staging/ but most of them look good (and fixes that they need 
> are not trivial).
> I will be glad if someone can give me pointers for a good starting point to 
> contribute.
>
> Thanks,
> Ankit
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

couple of pointers,

books to read - LDD, UTLK
start writing simple modules
don't focus on style fixes
try to find your area of interest, like file systems, drivers, memory
management, etc
understand the concepts, code in that area
start with small modifications
once done all these, ask the maintainer of the module if he/she has
any simple work to begin with

I hope this helps.

- Rohan

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


Re: Mark dma buffer readonly

2018-01-31 Thread Rohan Puri
On 31-Jan-2018 11:36 PM, "Saket Sinha"  wrote:

>
>> However, I am using this in kthreads and I want to protect it without
>> using mutex/spilock.
>> Apart from protecting it with spinlock or mutex, is their anyway to
>> mark this dma buffer as read-only so that other threads(after
>> concerned thread has accessed it) cannot access the dma buffer.
>
> Basic locking theory states that if one section of code is already using
one
> type of locking primitive, and you want a lock on the resource, you need
to
> use the same type of lock, and the same instance.
>

I just love this above sentence, well put in a general sense, Valdis.

> In other words, you need to use a spinlock on dma_spin_lock as well, or
> things *will* fail (and when it's a DMA controller in question, the
failure will
> almost certainly be spectacular).  So using a mutex is probably out of
> the question.
>
> Have you considered restructuring your code so a spinlock is usable?
>

Thanks Valdis for the prompt reply.

I would go ahead and check if spinlock could work instead of mutex
which I am currently using.

However, let me also explain the context how I am using mutex by below
pseudo code-


MUTEX_INIT(dma_lock);

void dummy_worker_thread()
{
...
mutex_lock(&dma_lock)
CHECK_BIT(hw_register, nth_bit);
mutex_unlock(&dma_lock);

}

Lets suppose the nth_bit is set in hw_register every X ms.

Do you think spinlock will be more advantageous here than mutex ?

See basic difference between mutex and spinlock is, the former puts the
thread waiting on the lock to sleep and later does a busy wait.

Since the nth bit is set every X ms, I think sleeping and waking up would
turn out to be costly operations/overhead so no mutex. Spinlock would be
good enough here.



Note: I am on ARMv8 SMP system using kernel version 4.4 .


Regards,
Saket Sinha


Regards,
Saket Sinha

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


- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: VFS: mount_bdev and fill_super

2017-06-18 Thread Rohan Puri
On 19-Jun-2017 10:38 AM, "Shrikant Giridhar" 
wrote:

On Fri, 16 Jun 2017, Rohan Puri wrote:

> If s_root is set it means the superblock is already filled up so call
> fill_super() only if s_root is NULL meaning superblock is not filled yet.

I tried looking at the d_name of the s_root dentry when mounting a device
and
its always '/'. I presume this is due to it being the root dentry of the
subtree we're attaching to the main file hierarchy.

Yes.


Can the dentry of a superblock be something other than '/' on mounting it?

Are you talking about s_root field of struct super_block ? Then it ideally
should be of root. I checked some file systems implementation of
fill_super().

fill_super() is the method that sets the s_root field of super_block. I
found all of those file systems *rightly* calling d_make_root() API which
actually makes root dentry with name '/'.

So the question you should ask yourself is which file systems code are you
referring too, how is it setting the s_root field of super_block in their
fill_super method. You will get your answer. Unless some file system is
doing some very weird thing, I believe it would be calling d_make_root()
VFS API only which does the task for you.



Apologies if my question is a little vague. Any documentation about this
would
help too.

---
Shrikant


- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: VFS: mount_bdev and fill_super

2017-06-15 Thread Rohan Puri
On 16-Jun-2017 11:44 AM, "Shrikant Giridhar" 
wrote:

> I just had a quick look at mount_bdev() code for Linux v3.15, mount_bdev()
> can return only root dentry or error.

I'm sorry I should have been clearer. I was referring to the documentation
mount() where it says that the call can return something other than the root
dentry.

I have not looked at the doc.


More specifically, I don't understand how the what's the purpose of the if
condition checking for s_root in mount_bdev(). Apologies if this is a
trivial
question.

If s_root is set it means the superblock is already filled up so call
fill_super() only if s_root is NULL meaning superblock is not filled yet.

Tracking the calls all the way down didn't seem to make it clearer
and I couldn't find specific documentation about the interface.

> Also please include the kernel version to which you are referring.

I have the 4.12-rc5 kernel.

---
Shrikant


- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: VFS: mount_bdev and fill_super

2017-06-15 Thread Rohan Puri
On 16-Jun-2017 11:21 AM, "Shrikant Giridhar" 
wrote:

I'm a little confused about how the mount_bdev() call works.

The VFS documentation lists it as a generic method to mount a block device.
Based on what I understood from the source, it seems to open a block device
whose path is passed via the mount() syscall and later associates it with
the superblock, finally returning the corresponding dentry to the caller.

The documentation also mentions that mount() can return a subtree of an
existing filesystem on the block device. However, in the very next line it
mentions that the caller also receives a pointer to the dentry of the root
node. I can see from the source (fs/super.c:1099) that the mount_bdev call
does check if the superblock's s_root == NULL or not and proceeds to set a
new superblock if it is.

I know my question sounds a little vague but I'm having trouble
understanding
how mount() can return a dentry for something other than the root?

---
Shrikant

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


Hi Shrikant,

I just had a quick look at mount_bdev() code for Linux v3.15, mount_bdev()
can return only root dentry or error.

Also please include the kernel version to which you are referring.

- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to get the inode - no path_lookup

2015-09-17 Thread Rohan Puri
On 17 Sep 2015 04:02, "Greg KH"  wrote:
>
> On Fri, Sep 04, 2015 at 04:26:06PM +, priyamn wrote:
> >
> > Hi,
> >
> > I happened to come across this discussion. I am having a similar issue.
> > I am using Rhel7-3.10.0-123
> > kernel. I tried all the options that are mentioned above and none of
the api's
> > including kern_path() return valid dentry value.
> > My requirement is to fetch directory name from filepath.
>
> Why do you need a directory name from a filepath within the kernel?
> What problem are you trying to solve that you feel a directory name is
> the correct solution?
>
> And remember, namespaces, what does a "directory name" really mean... :)
>
> thanks,
>
> greg k-h
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Hi Priya,

Please make use of a single thread for one topic. There was another thread
by you on the same topic. Anyways, I am replying to this one.

Greg has asked questions that you should ask yourself before going on with
choosing one approach.

I had suggested you using kern_path() earlier, since it doesn't makes use
of nameidata, but as you are telling its not working too. Here I would like
to know the actual context of the approach so as to figure out if something
I know that can work for you or maybe you shouldn't be doing it that way.

Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to get the dentry value - no path_lookup

2015-09-07 Thread Rohan Puri
On 7 Sep 2015 23:25,  wrote:
>
> On Mon, 07 Sep 2015 12:10:56 +0530, Pria Mn said:
>
> > return valid dentry value. My requirement is to fetch directory name
from
> > filepath.
>
> First off, unless this is a class assignment, your *requirement* isn't
> to fetch a directory name.
>
> Fetching the directory name is a *solution* you're thinking of using for
> a problem you're trying to solve.
>
> So take a step back, and explain what you're trying to do, and why you
thought
> getting the directory name from filepath was a solution - it's quite
> likely that you should be using some other API and approach entirely.
>
> (I'd estimate that 75% of the "I can't get this API to work" questions
> on the Linux kernel are because the person should be using a different
API)
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Yes Valdis is absolutely right about being clear as to what you want to do
and why you would be doing that. Also for what does the api do you need to
understand the code and browse using tools(cscope ctags maybe others) to
check for other APIs doing the same and you would definitely find one for
your need.

The way I would suggest is don't rush through, enjoy the process and not
the result.

Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to get the dentry value - no path_lookup

2015-09-07 Thread Rohan Puri
On Mon, Sep 7, 2015 at 1:11 PM, Pria Mn  wrote:

> Hi Rohan,
>
> I am using 3.10.0-123.el7.x86_64 kernel (RHEL-7). I am trying to obtain
> 'dentry' value from file path information. For this: earlier I had written
> the code as below :
>
> #if(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39))
>
> err= kern_path_parent(tmp,nd);
>
> #else
>
> err= path_lookup(tmp, 0, nd);
>
> #endif
> Now that "nameidata" structure is not exposed with kernel version >= 3.6.0
> I used kern_path_create() which is returning invalid dentry value.
>
> dentry =kern_path_create(AT_FDCWD, tmp, path, 1);
>
> So, I tried using : user_path_at() , kern_path() which are not helping me.
>
> How to fetch 'dentry' data from file name ?
>
> On Mon, Sep 7, 2015 at 12:45 PM, Rohan Puri 
> wrote:
>
>>
>>
>> On Mon, Sep 7, 2015 at 12:10 PM, Pria Mn  wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>> I happened to come across the below discussion.
>>>
>>>
>>>
>>> http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-August/005914.html
>>>
>>>
>>> I am having a similar issue.
>>>
>>> I am using Rhel7-3.10.0-123
>>>
>>> kernel. I tried all the options that are mentioned above and none of the
>>> api's
>>>
>>> including kern_path()
>>>
>>> return valid dentry value. My requirement is to fetch directory name
>>> from filepath.
>>>
>>>
>>>
>>> Can anybody suggest a work-around for this ?
>>>
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>> Hi Pria,
>>
>> This is in regards with which kernel version? also what are you trying to
>> do, please be more detailed.
>>
>>
>> Enjoy life,
>> Rohan
>>
>
>
Hi Pria,

Yes, just checked nameidata is moved to fs/internal.h file, I think you can
make use of kern_path
<http://lxr.free-electrons.com/ident?v=2.6.34;i=kern_path>() here.

NOTE: Also please post reply at the bottom.

Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to get the dentry value - no path_lookup

2015-09-07 Thread Rohan Puri
On Mon, Sep 7, 2015 at 12:10 PM, Pria Mn  wrote:

> Hi,
>
>
>
> I happened to come across the below discussion.
>
>
>
> http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-August/005914.html
>
>
> I am having a similar issue.
>
> I am using Rhel7-3.10.0-123
>
> kernel. I tried all the options that are mentioned above and none of the
> api's
>
> including kern_path()
>
> return valid dentry value. My requirement is to fetch directory name from
> filepath.
>
>
>
> Can anybody suggest a work-around for this ?
>
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Pria,

This is in regards with which kernel version? also what are you trying to
do, please be more detailed.


Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: filesystem encryption problem.

2015-07-13 Thread Rohan Puri
On 13 Jul 2015 22:08, "Amir Hezarkhani"  wrote:
>
>
> On Jul 13, 2015 1:18 AM, "Rohan Puri"  wrote:
> >
> > No issues, you are welcome.
> >
> > Enjoy life,
> > Rohan
> >
> > On 13 Jul 2015 01:19, "Amir Hezarkhani"  wrote:
> >>
> >>
> >> On Jul 12, 2015 10:00 PM, "Rohan Puri"  wrote:
> >> >
> >> >
> >> > On 12 Jul 2015 22:20, "Amir Hezarkhani"  wrote:
> >> > >
> >> > > Thank for replies. About copy_to_user and copy_from_user, whats
the better way?
> >> > > I dont have much experience in kernel development but I'm trying
to learn. Can you recommend me some books, documents, etc so I can learn
more about filesystems in kernel. I am also interested to learn how mmap
works because I have problems with execution of binary files in my
encrypted filesystem.
> >> > >
> >> > > On Jul 12, 2015 8:30 PM, 
wrote:
> >> > >>
> >> > >>
> >> > >>
> >> > >> On Sun, Jul 12, 2015 at 8:08 PM, Freeman Zhang <
freeman.zhang1...@gmail.com> wrote:
> >> > >>>
> >> > >>>  Original Message 
> >> > >>> > hello
> >> > >>> > I am working on adding a simple encryption to file contents in
ext4 driver
> >> > >>> > (for learning purposes) I added simple XOR encryption to
aio_read and
> >> > >>> > aio_write functions and it worked until I faced this problem:
> >> > >>> >
> >> > >>> > when I open a file in encrypted filesystem using VIM text
editor and when I
> >> > >>> > try to save it it gives me this error:
> >> > >>> >
> >> > >>> >>> pointer block id wrong
> >> > >>> >>> can not find line 1
> >> > >>> >
> >> > >>> > and it just corrupts the entire file!
> >> > >>> >
> >> > >>> > this is my aio_write function:
> >> > >>> >
> >> > >>> > aio_write_enc(struct kiocb *iocb, const struct iovec *iov,
> >> > >>> > unsigned long nr_segs, loff_t pos)
> >> > >>> > {
> >> > >>> > size_t i;
> >> > >>> > ssize_t ret;
> >> > >>> > char *data=vmalloc(sizeof(char)*iov->iov_len);
> >> > >>> > copy_from_user(data,iov->iov_base,iov->iov_len);
> >> > >>> >
> >> > >>> > for(i=0;iiov_len;i++)
> >> > >>> > {
> >> > >>> > data[i]^=5;
> >> > >>> > }
> >> > >>> > struct iovec iov_enc= { .iov_base = iov->iov_base,
.iov_len =
> >> > >>> > iov->iov_len };
> >> > >>> >
> >> > >>> > copy_to_user(iov_enc.iov_base,data,iov->iov_len);
> >> > >>> > ret=ext4_file_write(iocb,&iov_enc,nr_segs,pos);
> >> > >>> > vfree(data);
> >> > >>> > return ret;
> >> > >>> > }
> >> > >>> >
> >> > >>> > this just changes the data and then calls original function.
> >> > >>> >
> >> > >>> > is there anything wrong with this function? can anyone help me?
> >> > >>> >
> >> > >>> >
> >> > >>> >
> >> > >>> Hi Amir,
> >> > >>>
> >> > >>> I'm not quite sure about what's wrong with your function, but
here are
> >> > >>> two suggestions I got from the list when I did similar things:
> >> > >>>
> >> > >>> 1. wrapfs
> >> > >>> 2. ecryptfs
> >> > >>>
> >> > >>> I think you should check these two stackable filesystems if you
haven't.
> >> > >>>
> >> > >>> Hope this can help a little bit!
> >> > >>>
> >> > >>> Freeman
> >> > >>>
> >> > >>>
> >> > >>> ___
> >> > >>> Kernelnewbies mailing list
> >> > >>> Kernelnewbies@ke

Re: filesystem encryption problem.

2015-07-12 Thread Rohan Puri
On 12 Jul 2015 22:20, "Amir Hezarkhani"  wrote:
>
> Thank for replies. About copy_to_user and copy_from_user, whats the
better way?
> I dont have much experience in kernel development but I'm trying to
learn. Can you recommend me some books, documents, etc so I can learn more
about filesystems in kernel. I am also interested to learn how mmap works
because I have problems with execution of binary files in my encrypted
filesystem.
>
> On Jul 12, 2015 8:30 PM,  wrote:
>>
>>
>>
>> On Sun, Jul 12, 2015 at 8:08 PM, Freeman Zhang <
freeman.zhang1...@gmail.com> wrote:
>>>
>>>  Original Message 
>>> > hello
>>> > I am working on adding a simple encryption to file contents in ext4
driver
>>> > (for learning purposes) I added simple XOR encryption to aio_read and
>>> > aio_write functions and it worked until I faced this problem:
>>> >
>>> > when I open a file in encrypted filesystem using VIM text editor and
when I
>>> > try to save it it gives me this error:
>>> >
>>> >>> pointer block id wrong
>>> >>> can not find line 1
>>> >
>>> > and it just corrupts the entire file!
>>> >
>>> > this is my aio_write function:
>>> >
>>> > aio_write_enc(struct kiocb *iocb, const struct iovec *iov,
>>> > unsigned long nr_segs, loff_t pos)
>>> > {
>>> > size_t i;
>>> > ssize_t ret;
>>> > char *data=vmalloc(sizeof(char)*iov->iov_len);
>>> > copy_from_user(data,iov->iov_base,iov->iov_len);
>>> >
>>> > for(i=0;iiov_len;i++)
>>> > {
>>> > data[i]^=5;
>>> > }
>>> > struct iovec iov_enc= { .iov_base = iov->iov_base, .iov_len =
>>> > iov->iov_len };
>>> >
>>> > copy_to_user(iov_enc.iov_base,data,iov->iov_len);
>>> > ret=ext4_file_write(iocb,&iov_enc,nr_segs,pos);
>>> > vfree(data);
>>> > return ret;
>>> > }
>>> >
>>> > this just changes the data and then calls original function.
>>> >
>>> > is there anything wrong with this function? can anyone help me?
>>> >
>>> >
>>> >
>>> Hi Amir,
>>>
>>> I'm not quite sure about what's wrong with your function, but here are
>>> two suggestions I got from the list when I did similar things:
>>>
>>> 1. wrapfs
>>> 2. ecryptfs
>>>
>>> I think you should check these two stackable filesystems if you haven't.
>>>
>>> Hope this can help a little bit!
>>>
>>> Freeman
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>
>> Hi Amir,
>>
>> I agree with Freeman Zhang over here. The way you are doing it is not
right. There is a mechanism to create stacks of file system and you should
go down that path.
>>
>> Having said this, you should definitely debug the issue that you are
facing. Some pointers : -
>> 1. As you have already mentioned that this is happening only for vim and
not while regular read(using cat, etc), you need to check what vim does
special to read a file. I would suggest make use of strace and do reading
with and without vim, maybe you will get something of interest.
>> 2. re-read code to check, you might be messing up while write or read.
>>
>> Apart from these some basic practices you need to follow is : -
>>
>> 1. check for error conditions, like you missed checking error from
vmalloc() and the below code will execute even if it failed, this should be
avoided.
>> 2. copy_from_user & again copying back to user is in-efficient.
>>
>>
>> Enjoy life,
>> Rohan
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hi Amir,

Please reply at the bottom. Regarding what's the better way would depend on
how you design stuff.

Following is my recommendation :-

For conceptual knowledge of general file systems the best would be OS book
by Prof Remzi Arpaci-Dusseau.
Excellently explained.

For linux kernel conceptual stuff get hold of Robert love Linux kernel
development.

Read lots of kernel generic filesystem code in FS dir. Lots of basic
functionality is implemented in helper functions present in this dir.

Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: filesystem encryption problem.

2015-07-12 Thread Rohan Puri
On Sun, Jul 12, 2015 at 8:08 PM, Freeman Zhang 
wrote:

>  Original Message 
> > hello
> > I am working on adding a simple encryption to file contents in ext4
> driver
> > (for learning purposes) I added simple XOR encryption to aio_read and
> > aio_write functions and it worked until I faced this problem:
> >
> > when I open a file in encrypted filesystem using VIM text editor and
> when I
> > try to save it it gives me this error:
> >
> >>> pointer block id wrong
> >>> can not find line 1
> >
> > and it just corrupts the entire file!
> >
> > this is my aio_write function:
> >
> > aio_write_enc(struct kiocb *iocb, const struct iovec *iov,
> > unsigned long nr_segs, loff_t pos)
> > {
> > size_t i;
> > ssize_t ret;
> > char *data=vmalloc(sizeof(char)*iov->iov_len);
> > copy_from_user(data,iov->iov_base,iov->iov_len);
> >
> > for(i=0;iiov_len;i++)
> > {
> > data[i]^=5;
> > }
> > struct iovec iov_enc= { .iov_base = iov->iov_base, .iov_len =
> > iov->iov_len };
> >
> > copy_to_user(iov_enc.iov_base,data,iov->iov_len);
> > ret=ext4_file_write(iocb,&iov_enc,nr_segs,pos);
> > vfree(data);
> > return ret;
> > }
> >
> > this just changes the data and then calls original function.
> >
> > is there anything wrong with this function? can anyone help me?
> >
> >
> >
> Hi Amir,
>
> I'm not quite sure about what's wrong with your function, but here are
> two suggestions I got from the list when I did similar things:
>
> 1. wrapfs
> 2. ecryptfs
>
> I think you should check these two stackable filesystems if you haven't.
>
> Hope this can help a little bit!
>
> Freeman
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Amir,

I agree with Freeman Zhang over here. The way you are doing it is not
right. There is a mechanism to create stacks of file system and you should
go down that path.

Having said this, you should definitely debug the issue that you are
facing. Some pointers : -
1. As you have already mentioned that this is happening only for vim and
not while regular read(using cat, etc), you need to check what vim does
special to read a file. I would suggest make use of strace and do reading
with and without vim, maybe you will get something of interest.
2. re-read code to check, you might be messing up while write or read.

Apart from these some basic practices you need to follow is : -

1. check for error conditions, like you missed checking error from
vmalloc() and the below code will execute even if it failed, this should be
avoided.
2. copy_from_user & again copying back to user is in-efficient.


Enjoy life,
Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to safely access inode/dentry obtained from struct page *?

2014-09-03 Thread Rohan Puri
On Thu, Sep 4, 2014 at 1:33 AM, Rohan Puri  wrote:
> On Wed, Sep 3, 2014 at 10:50 PM, Joshi  wrote:
>>
>> Thanks Pranay. Please see below-
>>
>> On Mon, Sep 1, 2014 at 10:19 AM, Pranay Srivastava  wrote:
>> >
>> > On 01-Sep-2014 10:18 AM, "Pranay Srivastava"  wrote:
>> >>
>> >>
>> >> On 30-Aug-2014 10:49 AM, "Joshi"  wrote:
>> >> >
>> >> > I am trying to obtain file name at block layer level (above IO
>> >> > scheduler).
>> >> > At this level I receive bio structure, within which page pointers are
>> >> > kept.
>> >> >
>> >> > Thereby I do following to obtain the inode and dentry -
>> >> >
>> >> > struct inode *inode_ptr = page->mapping->host;
>> >> > if (inode_ptr != NULL)
>> >> > /* Access dentry i.e. i_dentry in the inode */
>> >> >
>> >>
>> >> Are you doing this in readpage(s) or writepage(s) callback? If that's the
>> >> case your page would be locked and dentry/inode wouldn't go away.
>> >>
>> >> If you are doing something else then first make sure you do lock_page and
>> >> proceed only if you get that page lock.
>>
>> I am not operating at file-system level. I am operating on the bio
>> that file-system(or any other component above IO scheduler) might have
>> sent.
>> Do you think that page descriptor kept in bio (for write) is going to
>> vanish? I am not accessing the data of the page, just the
>> page->mapping pointer.

 Yes, it can happen. Race condition for your case can happen either due
 to page mapping removed or dentry removed from cache.Cases that I can
 think of are invalidations/truncation of page mapping happening
 (truncate, file delete, file hole punching) & as default IO is async
 so dentry can be evicted due to load as in fsstress by the time you
 print filename.

>>
>>
>> >> Second you can try dget and dput before you start working with dentry.
>>
>> I will try that.
>>
>> >> > This works usually. But problem is, inode and dentry may get released
>> >> > from inode and dentry cache at any time.
>> >> > While accessing inode/dentry I need to ensure that till the time I am
>> >> > accessing'em these structure remain valid in memory.
>> >> > Is it possible to ensure that? Which structures/locks I need to check
>> >> > for the purpose.
>> >>
>> >> is this your observation from your test case? Can you explain your test
>> >> case a bit.
>>
>> No, normally I obtain file name. But with fsstress, this causes crash.
>>
>> >>
>> > Have you seen d_alias and see if that can help you with filename?
>>
>> I do get filename from dentry. But while I am accessing that, it can
>> be freed by vfs.
>>
>> >
>> >> >
>> >> > Appreciate any help.
>> >> >
>> >> > Thanks!
>> >> >
>> >> > --
>> >> > Joshi
>> >> >
>> >> > ___
>> >> > Kernelnewbies mailing list
>> >> > Kernelnewbies@kernelnewbies.org
>> >> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>>
>> --
>> Joshi
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
 Make use of proper synchronization stuff as Pranay pointed out. Btw,
 what is the use case you need this for ? (just curious to know)

 - Rohan

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


Re: How to safely access inode/dentry obtained from struct page *?

2014-09-03 Thread Rohan Puri
On Wed, Sep 3, 2014 at 10:50 PM, Joshi  wrote:
>
> Thanks Pranay. Please see below-
>
> On Mon, Sep 1, 2014 at 10:19 AM, Pranay Srivastava  wrote:
> >
> > On 01-Sep-2014 10:18 AM, "Pranay Srivastava"  wrote:
> >>
> >>
> >> On 30-Aug-2014 10:49 AM, "Joshi"  wrote:
> >> >
> >> > I am trying to obtain file name at block layer level (above IO
> >> > scheduler).
> >> > At this level I receive bio structure, within which page pointers are
> >> > kept.
> >> >
> >> > Thereby I do following to obtain the inode and dentry -
> >> >
> >> > struct inode *inode_ptr = page->mapping->host;
> >> > if (inode_ptr != NULL)
> >> > /* Access dentry i.e. i_dentry in the inode */
> >> >
> >>
> >> Are you doing this in readpage(s) or writepage(s) callback? If that's the
> >> case your page would be locked and dentry/inode wouldn't go away.
> >>
> >> If you are doing something else then first make sure you do lock_page and
> >> proceed only if you get that page lock.
>
> I am not operating at file-system level. I am operating on the bio
> that file-system(or any other component above IO scheduler) might have
> sent.
> Do you think that page descriptor kept in bio (for write) is going to
> vanish? I am not accessing the data of the page, just the
> page->mapping pointer.

Yes, it can happen. Race condition for your case can happen either due
to page mapping removed or dentry removed from cache.Cases that I can
think of are invalidations/truncation of page mapping happening
(truncate, file delete, file hole punching) & as default IO is async
so dentry can be evicted due to load as in fsstress by the time you
print filename.

>
>
> >> Second you can try dget and dput before you start working with dentry.
>
> I will try that.
>
> >> > This works usually. But problem is, inode and dentry may get released
> >> > from inode and dentry cache at any time.
> >> > While accessing inode/dentry I need to ensure that till the time I am
> >> > accessing'em these structure remain valid in memory.
> >> > Is it possible to ensure that? Which structures/locks I need to check
> >> > for the purpose.
> >>
> >> is this your observation from your test case? Can you explain your test
> >> case a bit.
>
> No, normally I obtain file name. But with fsstress, this causes crash.
>
> >>
> > Have you seen d_alias and see if that can help you with filename?
>
> I do get filename from dentry. But while I am accessing that, it can
> be freed by vfs.
>
> >
> >> >
> >> > Appreciate any help.
> >> >
> >> > Thanks!
> >> >
> >> > --
> >> > Joshi
> >> >
> >> > ___
> >> > Kernelnewbies mailing list
> >> > Kernelnewbies@kernelnewbies.org
> >> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> --
> Joshi
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Make use of proper synchronization stuff as Pranay pointed out. Btw,
what is the use case you need this for ? (just curious to know)

- Rohan

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


Re: fd type from number

2014-08-22 Thread Rohan Puri
On Sat, Aug 23, 2014 at 12:33 AM, Loris Degioanni  wrote:
> On 8/20/2014 2:33 AM, Rohan Puri wrote:
>>
>> On Tue, Aug 19, 2014 at 10:04 PM, Loris Degioanni 
>> wrote:
>>>
>>> Sure, here's some more context.
>>>
>>> I'm one of the developers of sysdig (www.sysdig.org), a tool that
>>> captures system calls and uses them to offer advanced system monitoring.
>>> One of the features that our diver offers is the tcpdump-derived concept
>>> of "snaplen": when a system call with a buffer is captured, it's
>>> possible to choose how many bytes of that buffer are copied to the
>>> driver capture buffer. This makes it possible to tune buffer utilization
>>> and CPU usage vs completeness of data.
>>>
>>> Since this feature is important and heavily used, I'd like to extend it
>>> so that the user has per-fd-type snaplen control. A typical use case is:
>>> "I want 1000 bytes of each socket buffer, because I'm interested in
>>> looking at protocol activity, but I don't care about files and so I'm ok
>>> with just 20 bytes from them". In order for this feature to be useful,
>>> it needs to be very fast: we use tracepoints to capture system calls, so
>>> we slow down the original process if we take too long.
>>>
>>> And since I'm here, let me expand my question. Another useful thing to
>>> do would be per-filename snaplen. Use case: "I want the whole content of
>>> reads and writes to files that are in /etc, but I want only 20 bytes
>>> from any other system call". This would I guess involve unpacking the
>>> file structure and retrieving the full file name. Is there any way to do
>>> it safely and efficiently?
>>>
>>> Thanks,
>>> Loris
>>>
>>>
>>> On 8/19/2014 9:02 AM, valdis.kletni...@vt.edu wrote:
>>>>
>>>> On Tue, 19 Aug 2014 08:38:24 -0700, Loris Degioanni said:
>>>>
>>>>> I'm looking for an efficient way to determine the type of an fd (file,
>>>>> socket...) given its number, from a kernel module.
>>>>
>>>> What problem are you trying to solve here?  There may be a better API
>>>> for
>>>> your problem.  So step back - what are you trying to accomplish?
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> Hi Loris,
>>
>> You can get the file type from the fd by doing something like this : -
>>
>> struct file *file = fget(fd);
>> if(!file)
>>  return error;
>> assert(file->f_inode != NULL);
>> file_type = (file->f_inode->i_mode & S_IFMT) >> 12;
>>
>> Also, you can make use of S_IS*(mode) macros, to check for file types.
>>
>> NOTE: fget() makes use of current process's file_struct.
>>
>> Regards,
>> - Rohan
>
>
> Thanks Rohan,
> and for kernels more recent than 3.14 I assume I need to use fdget instead
> of fget, right?
fdget() calls __fget_light() internally & if you check out the definition
of __fget_light(), there is a comment there. Pasting it over here : -
/*
 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
 *
 * You can use this instead of fget if you satisfy all of the following
 * conditions:
 * 1) You must call fput_light before exiting the syscall and returning
control
 *to userspace (i.e. you cannot remember the returned struct file *
after
 *returning to userspace).
 * 2) You must not call filp_close on the returned struct file * in between
 *calls to fget_light and fput_light.
 * 3) You must not clone the current task in between the calls to fget_light
 *and fput_light.
 *
 * The fput_needed flag returned by fget_light should be passed to the
 * corresponding fput_light.
 */

fdget() is different from fget() in 2 ways, if fd table is not shared,
meaning files_struct->count is 1 : -
1. Doesnt take rcu_read_lock()
2. Doesnt increment struct file->f_count.

else it behaves the same as fget(), *so yes i think you can use fdget().*
>
> Loris
>

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


Re: fd type from number

2014-08-20 Thread Rohan Puri
On Tue, Aug 19, 2014 at 10:04 PM, Loris Degioanni  wrote:
> Sure, here's some more context.
>
> I'm one of the developers of sysdig (www.sysdig.org), a tool that
> captures system calls and uses them to offer advanced system monitoring.
> One of the features that our diver offers is the tcpdump-derived concept
> of "snaplen": when a system call with a buffer is captured, it's
> possible to choose how many bytes of that buffer are copied to the
> driver capture buffer. This makes it possible to tune buffer utilization
> and CPU usage vs completeness of data.
>
> Since this feature is important and heavily used, I'd like to extend it
> so that the user has per-fd-type snaplen control. A typical use case is:
> "I want 1000 bytes of each socket buffer, because I'm interested in
> looking at protocol activity, but I don't care about files and so I'm ok
> with just 20 bytes from them". In order for this feature to be useful,
> it needs to be very fast: we use tracepoints to capture system calls, so
> we slow down the original process if we take too long.
>
> And since I'm here, let me expand my question. Another useful thing to
> do would be per-filename snaplen. Use case: "I want the whole content of
> reads and writes to files that are in /etc, but I want only 20 bytes
> from any other system call". This would I guess involve unpacking the
> file structure and retrieving the full file name. Is there any way to do
> it safely and efficiently?
>
> Thanks,
> Loris
>
>
> On 8/19/2014 9:02 AM, valdis.kletni...@vt.edu wrote:
>> On Tue, 19 Aug 2014 08:38:24 -0700, Loris Degioanni said:
>>
>>> I'm looking for an efficient way to determine the type of an fd (file,
>>> socket...) given its number, from a kernel module.
>> What problem are you trying to solve here?  There may be a better API for
>> your problem.  So step back - what are you trying to accomplish?
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Hi Loris,

You can get the file type from the fd by doing something like this : -

struct file *file = fget(fd);
if(!file)
return error;
assert(file->f_inode != NULL);
file_type = (file->f_inode->i_mode & S_IFMT) >> 12;

Also, you can make use of S_IS*(mode) macros, to check for file types.

NOTE: fget() makes use of current process's file_struct.

Regards,
- Rohan

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


Re: Bad Patches and Issues with other devolopers

2014-08-05 Thread Rohan Puri
On Tue, Aug 5, 2014 at 11:55 PM, Sudip Mukherjee
 wrote:
>
> On Aug 5, 2014 11:14 PM, "Nick Krause"  wrote:
>>
>> I have sent out just ten bad patches and the developers seem very
>> annoyed with me and
>> think I am trolling. If someone on this list can find a way for me to
>> improve my relationship
>> with them and let me continue my work here that would be great.
>> Nick
>
> i saw that you sent a patch regarding videobuf2 on 3rd august , the reaction
> of that patch continues till 4th. on 4th you write that you will not send a
> patch again without testing.
> but surprisingly again on 5th you send a patch , which as usual , fails to
> build. have you really tested the patch before sending?? did you try to
> compile the kernel after making your modifications?? i think - no.
>
>>
>> ___
>> 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
>

Hi Nick,

The advice developers have given you is very valuable. As the above
ppl have also said, please do hurry through submitting incorrect
patches, you should really know what you are fixing and why that needs
to be fixed. It should be compiled and tested.

Above all, you need to ask yourself a question, why do you really want
to do this? Please do not do this if you want to be famous or show
that even you can do something technical. Do this only if you are
really interested and have liking about OS development & stuff. Then
it will not matter that you have submitted 100s of patches in a month
or just 1 patch in a year. Results should not matter, your goal should
be to learn something new every day about linux kernel. This should be
done through lots of conceptual & code reading, using & testing the
kernel.

To start of please read good books like : -
1. Linux kernel development
2. Understanding linux kernel
3. Linux device drivers
4. There are more but these 3 are enough for beginning.

Once done, you would be interested in particular sub-system, then try
to explore that sub-system more by code reading, making small changes
not necessarily bug-fixes, validate your code understanding through
those changes.

Enjoy learning!

- Rohan

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


Re: Beginner guide

2014-06-11 Thread Rohan Puri
On Wed, Jun 11, 2014 at 12:35 PM, Pranay Srivastava 
wrote:

> On Wed, Jun 11, 2014 at 11:58 AM, Prudhvee Narasimha Sadha
>  wrote:
> > Hi,
> >   My name is Prudhvee and I'm purusing my undergraduate second year.
> I'm
> > intrested in kernel development but I'm unable to understand how to get
> into
> > it.
> > Can you please help me to become a kernel developer.
>
> I would suggest get the foundations right first and let's hope you know
> good C,
> tricks are good to know but you should be able to understand code
> written by others and be able to integrate the knowledge with what you
> already know.
>
> Agree. Ways to do this : -
1. Read/write/understand K&R C language.
2. To understand code written by others you have to start doing that. (I
mean practice it).


> If you haven't used semaphores or mutexes in user space code then do
> that first, understand why is the need. For example why you need to
> have a sycall to get a semaphore
> but when working with pthreads you probably don't need that.
>
> Understand compiler and make it your friend. Errors you get while
> compiling, and things you can do for example why  ((struct
> mystruct*)(0))->member fails when you run code but &(((struct
> mystruct*)(0))->member) works.
>
>

>
> Basic idea is to get to understand how would you do it yourself, get
> some ideas in your mind see if they should work or not. You may be
> able to write code maybe without going through all that but in the
> long run it would help.
>
> >
> >  I just want to know what I should learn and any suggested books to
> > learn kernel programming.
> >
>
> Take an operating system course first. Get to know the basics then you
> can try to understand kernel code. You can start with LDD, i think a
> new version is available now, but take an OS course in parallel or
> read yourself.
>
Agree. Ways to do this : -
Get an OS course done, search for courses online, 2 of ones which I know
are : -
1. http://www.cs.cmu.edu/~213/
2. CMUs OS course.

>
> >  Thank you,
> >  Prudhvee.
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
>
>
> --
> ---P.K.S
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

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


Re: Reset due to emergency remount r/o

2014-02-26 Thread Rohan Puri
On Wed, Feb 19, 2014 at 6:14 PM, Priyaranjan Das
 wrote:
> Hi All,
>
> I am facing an kernel restart due to emergency remount. Could anybody tell
> me general techniques to go head with the debugging?
>
> Below are the logs which are seen during a reboot.
>
> [ 425.832395,1] SysRq : Emergency Remount R/O
> [ 425.876210,1] EXT4-fs (mmcblk0p36): re-mounted. Opts: (null)
> [ 425.925899,1] EXT4-fs (mmcblk0p33): re-mounted. Opts: (null)
> [ 425.928731,1] EXT4-fs (mmcblk0p29): re-mounted. Opts: (null)
> [ 425.955762,1] Emergency Remount complete
>
> [ 426.187136,0] Restarting system with command 'bootloader'.
> [ 426.187327,0] Current task:init(1) Parent task:swapper/0(0)
> [ 426.187430,0] Going down for restart now
>
>
> Regards,
>
> Priyaranjan
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Adding the linux-ext4 mailing list too.

- Regards,
  Rohan

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


Re: query on VFS busy inode

2014-02-25 Thread Rohan Puri
On Wed, Feb 26, 2014 at 1:08 AM, Abhishek Dave  wrote:
> Hello All,
>
> Can some one please help me to understand meaning of below code
>
> 
>
> if (!list_empty(&sb->s_inodes)) {
> 406 printk("VFS: Busy inodes after unmount of %s. "
> 407"Self-destruct in 5 seconds.  Have a nice
> day...\n",
> 408sb->s_id);
> 409 }
>
> 
>
> Are we doing here?
>
> Thanks,
>
> Dave
>
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hi Abhishek,

This code gets called during unmounting of a filesystem. During
unmounting, if there are busy inodes present in the list contained in
superblock (s_inodes field), just log the error through the printk &
go forward through the unmounting process.

- Regards,
 Rohan

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


Re: Determining 32bit or 64bit OS from a running kernel module

2013-10-23 Thread Rohan Puri
On Wed, Oct 23, 2013 at 2:42 PM, Nuno Martins wrote:

> Hi Saket,
>
> At code level you can check the size of a long. If you are in 32 bit it
> will be 4 bytes, if you are in 64 bit it will be 8 bytes.
>
> Probably there will be better ways and functions already with this test.
>
> If you want to check it you just have to include the file that has those
> defines and put your code under a #if .
>
> Best regards,
> Nuno Martins
>
>
>
> On Wed, Oct 23, 2013 at 6:46 AM, Saket Sinha wrote:
>
>> Hi,
>>
>> I want to write a kernel module which depends on the kernel type (32 or
>> 64 bit). There are some lines of code which I want to be included in the
>> module if and only if the kernel is 32 bit and some lines of code which
>> should be included if kernel is 64 bit.
>>
>> Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
>> for this case ?
>>
>> I know we have CONFIG_X86_64 and CONFIG_X86_32 for  x86 architecture but
>> how do I exactly check it in my module code?
>>
>> Regards,
>>
>> Saket Sinha
>>
>>
>>
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>
>
> --
> Nuno Martins
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi,

You could see for proc fs or sys fs providing any facility that you can
make use of. I am sure there has to be some.

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


Re: lg_local_lock issue

2013-09-12 Thread Rohan Puri
On Thu, Sep 12, 2013 at 10:14 AM, Saket Sinha wrote:

>   I am facing some issue on a filesystem-driver I ported from 2.6.18
> kernel to 3.8. Now a lot has changed in the VFS since 2.6.18 to 3.8, which
> has caused a lot of problem for this driver. One of the biggest core change
> is the change in Path resolution.
>
> *LET ME GIVE SOME Basic Information*
> Path resolution is the finding a dentry corresponding to a path name
> string, by performing a path walk.
> Paths are resolved by walking the namespace tree, starting with the first
> component of the pathname (eg. root or cwd) with a known dentry, then
> finding the child of that dentry, which is named the next component in the
> path string. Then repeating the lookup from the child dentry and finding
> its child with the next element, and so on.
> Kindly have a look at the below image-
> http://lwn.net/images/ns/kernel/dentry.png
>
> In my driver code it is done here in the function-
> int get_full_path_d(const struct dentry *dentry, char *real_path) at the
> below link-
> https://github.com/disdi/hepunion/blob/master/fs/hepunion/helpers.c#L375
> *I would like to point out here that I had dcache_lock on 2.6.18 kernel
> to protect this lookup but on 3.8 kernel, I haven't found a suitable
> replacement
> *
>
> The entire code flow chart of my driver can be found here-
> https://github.com/disdi/hepunion/issues/6
>
> Since 2.6.38, RCU is used to make a significant part of the entire path
> walk (including dcache look-up) completely "store-free" (so, no locks,
> atomics, or even stores into cachelines of common dentries). This is known
> as "rcu-walk" path walking. rcu-walk uses a d_seq protected snapshot. When
> looking up a child of this parent snapshot, we open d_seq critical section
> on the child before closing d_seq critical section on the parent. This
> gives an interlocking ladder of snapshots to walk down.
> Something like the below link-
> http://spatula-city.org/~im14u2c/images/man_running_up_crumbling_stairs.jpg
>
> *PROBLEM*
> Since this filesystem does not follow RCU-lookup as of now or since I have
> not done anything to upgrade our driver to tell VFS whether we follow RCU
> or not and simply ported the driver to 3.8 kernel by changing the kernel
> functions or APIs but the respective replacements. Now there is no
> compilier error but at runtime, I find myself caught in some endless loop
> and in the stack or dmesg I see something called *lg_local_lock.*
>
> The entire kernel stack of my driver can be found here -
> https://github.com/disdi/hepunion/issues/5
>
> I searched and found the following link describing it thoroughly-
> http://lwn.net/Articles/401738/
>
> To sum up
> 1. This thing has come up with the new RCU-lookup change.
> 2. lglocks is to *protect the list of open files* which is attached to
> each superblock structure.
>
> Since this filesystem driver is failing when I do a "ls in mount point"
> and if we do a strace on "ls" we have
>  open("/scratch", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
> and in the stack after it hangs, it shows lg_lock
>
> 3.And most importanly
> "The real reason that the per-superblock open files list exists is to let
> the kernel check for writable files when a filesystem is being remounted
> read-only."
>
> I have a union of filesystems in this filesystem, where one is Read Only
> and the other is Read-Write. I think I am violating some of this kernel
> protection mechanism and find mydriver stuck.
>
> If you can have a look at this issue, I shall be grateful to you.
>
> Regards,
> Saket Sinha
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Saket,

There are some cases where you cannot do rcu_walk of path_lookup and you
need to revert back to reference lookup. One among this is if you have your
i_permission method defined.

To implement this do the following : -

const struct dentry_operations your_fs_dentry_ops = {
.d_revalidate = your_fs_dentry_revalidate,
};

static int your_fs_dentry_revalidate(struct dentry *dentry, unsigned int
flags)
{
/* Switch back to reference walk, since rcu_walk not possible iff
i_permission() defined.
if (flags & LOOKUP_RCU)
return -ECHILD;
return 0;
}

Also hook these operations to your sb in fill_super() like this sb->s_d_op
= &your_fs_dentry_ops;

Compile & run, let me know the outcome.

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


Re: IOCTLs versus netlink

2013-09-05 Thread Rohan Puri
On Mon, Sep 2, 2013 at 1:30 AM, Kristian Evensen  wrote:

> On Sun, Sep 1, 2013 at 3:16 PM, Greg Freemyer 
> wrote:
> >
> >
> > Kevin Wilson  wrote:
> >>Hi,
> >>Can someone please explain why are netlink sockets a better
> >>communication method between kernel space and userspace ?
> >>
>
> Another reason is to make things easier to extend. Adding a parameter
> to a netlink message is as easy as adding an additional netlink
> attribute. User space applications that has not been updated to
> support your change, will not see this parameter as it is unknown to
> them when processing the attributes. Extending an ioctl would mean
> adding new paramteres to the struct that is passed to/from the kernel,
> which will cause all kinds of problems. For example, how to avoid
> overflows when returning it to user space.
>
> -Kristian
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hi,

This should give you a lot of insight
http://people.ee.ethz.ch/~arkeller/linux/kernel_user_space_howto.html

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


Re: How to configure bullseye code coverage on windows driver

2013-08-30 Thread Rohan Puri
On Fri, Aug 30, 2013 at 11:32 AM, Nitin Kshirsagar <
nitin.kshirsagar2...@gmail.com> wrote:

> Hello All,
>
> I am configuring bullseye code coverage for windows MSI build.
> I am able to get user code coverage but not driver code coverage.
> Please let me know if any one configured bullseye on windows.
> --
> Thanks & Regards,
> Nitin Kshirsagar
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Nitin,

This is linux kernel mailing list, your question is for windows i guess,
you need to post it to some other relevant mailing list. If you want
coverage and other testing tools for linux, vist
http://ltp.sourceforge.net/tooltable.php/

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


Re: Has anyone worked with PF_RING

2013-08-08 Thread Rohan Puri
On Mon, Jul 22, 2013 at 5:54 PM, Robert Clove  wrote:

> Hi ALL,
>
> I have to understand the PF_RING part.
> I mean why it is being used,is it available in kernel freely?
> What are the benefits of PF_RING and what are the disadvantages of using
> it?
> Why we normally don't use it?
>
> If anyone has any clues please share.
>
> Thanks
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Robert,

I have not worked on it, but a quick search gave me this link: -
http://www.ntop.org/products/pf_ring/
It answers most of your questions.

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


Re: Driver laboratory classes on university

2013-08-07 Thread Rohan Puri
On Thu, Aug 8, 2013 at 1:51 AM, Grzegorz Dwornicki  wrote:

> Thank you all for this materials. I will read them all.
>
> As for grading students for fixing bug or writing a driver. This looks
> reasonable. The only problem is with bugs. I am not aware of any bug needed
> to fix list on Linux. As for drivers for new devices. This will require
> constant amount of money from University. This may be a problem in the long
> run.
> 7 sie 2013 11:22, "Rohan Puri"  napisał(a):
>
>
>>
>>
>> On Wed, Aug 7, 2013 at 12:09 AM, Grzegorz Dwornicki wrote:
>>
>>> Hi
>>>
>>> I'm working on own phd thesis. It includes some kernel hacking for
>>> practical application of my research. I wish to make some progress with
>>> programming classes on my university. We have a lot of high level
>>> programing like object oriented languages but none on low level and kernel
>>> programing.
>>>
>>> I wish to know how other universities run classes on operating systems.
>>> I have named this topic about drivers because I think this will be most fun
>>> for the students. But fell free to give me any advices. I have more than
>>> one year to write conspect and get the required hardware. But first I need
>>> to learn myself all I can.
>>>
>>> I don't know where to start. Do I need to know electronic and physics
>>> good? Is there some easy to program hardware but at the same time easy to
>>> show how this is done from scratch? At first this would be an optional
>>> classes but I know there are a lot of interested students in this subjects
>>> soo this may become a part of operating systems laboratory classes. They
>>> are as you may expect -  mandatory. I wish to give them a least a good
>>> start.
>>>
>>> This isn't as simple as decide what I need to know for my thesis...
>>> Links for articles, hardware on some stores or just it's prod. Id will be
>>> helpful.
>>>
>>> Thanks for help
>>> Gregory
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>> Hi Gregory,
>>
>> The one which I know and really like personally is OS by Prof Remzi
>> Arpaci-Dusseau at University of wisconsin. The reference material the book
>> written by the Prof. himself is available on his website for free download.
>> His webpage is pages.cs.wisc.edu/~*remzi*/. They use the xv6 operating
>> system (unix like) link http://pdos.csail.mit.edu/6.828/2012/xv6.html
>> developed at MIT.
>>
>> - Rohan
>>
>
One way to look for bugs is go through the list in bugzilla. link
https://bugzilla.kernel.org/

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


Re: Driver laboratory classes on university

2013-08-07 Thread Rohan Puri
On Wed, Aug 7, 2013 at 12:09 AM, Grzegorz Dwornicki wrote:

> Hi
>
> I'm working on own phd thesis. It includes some kernel hacking for
> practical application of my research. I wish to make some progress with
> programming classes on my university. We have a lot of high level
> programing like object oriented languages but none on low level and kernel
> programing.
>
> I wish to know how other universities run classes on operating systems. I
> have named this topic about drivers because I think this will be most fun
> for the students. But fell free to give me any advices. I have more than
> one year to write conspect and get the required hardware. But first I need
> to learn myself all I can.
>
> I don't know where to start. Do I need to know electronic and physics
> good? Is there some easy to program hardware but at the same time easy to
> show how this is done from scratch? At first this would be an optional
> classes but I know there are a lot of interested students in this subjects
> soo this may become a part of operating systems laboratory classes. They
> are as you may expect -  mandatory. I wish to give them a least a good
> start.
>
> This isn't as simple as decide what I need to know for my thesis... Links
> for articles, hardware on some stores or just it's prod. Id will be
> helpful.
>
> Thanks for help
> Gregory
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Gregory,

The one which I know and really like personally is OS by Prof Remzi
Arpaci-Dusseau at University of wisconsin. The reference material the book
written by the Prof. himself is available on his website for free download.
His webpage is pages.cs.wisc.edu/~*remzi*/. They use the xv6 operating
system (unix like) link http://pdos.csail.mit.edu/6.828/2012/xv6.html
developed at MIT.

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


Re: System-call in Kernel Space

2013-07-19 Thread Rohan Puri
On Fri, Jul 19, 2013 at 1:33 PM, SandeepKsinha wrote:

>
>
> On Fri, Jul 19, 2013 at 1:29 PM, Saket Sinha wrote:
>
>>   We all know that system-calls are for user-space.
>> I have a file-system driver where I have to use system calls in
>> kernel-space.
>>
>>  Normally, we DON'T do any high level IOs from Kernel space (file
>> creation/reading, and so on). But here in my driver I am  stacking FS
>> drivers, I can't avoid this. This is partly because Linux kernel can't
>> handle FS stacking (this wouldn't be an issue for Windows, for instance,
>> which supports stacking),
>>
>>
> Provide complete context of what you are trying to do.
>
>
>> The simple (and legal) way to create a dir/file whatever is to call
>> system calls, like, for instance sys_mkdir. The problem is that I am not in
>> a context where I can call these. Because they expect a call from user
>> mode, while I am in kernel mode. This is even why I implemented macros such
>> as:
>> https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/hepunion.h#L399.
>> This one disables all checks from user mode calls, since I am in kernel.
>> And this allows calling system calls.
>>
>>  This is not a good way so is there any alternative.
>>
>> Regards,
>> Saket Sinha
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>
>
> --
> Regards,
> Sandeep.
>
>
>
>
>
>
> “To learn is to change. Education is a process that changes the learner.”
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Saket,

fs stacking is possible in linux also, see stackable file systems for
linux. Main research was done at Stony Brook by Prof. Erez Zadok. Search
for fs known as wrapfs, which implements bare minimum infrastructure to do
this. Also, there are examples of this in linux, go through ecryptfs. I
think unionfs also does the same thing.

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


Re: How to benchmark my OS

2013-07-16 Thread Rohan Puri
On Tue, Jul 16, 2013 at 11:03 PM, shiek kaleem wrote:

> Hi Guys ,
>
> Just the same question from my side is there any guidelines i can follow
> if I have created my own OS.(LFS)
>
>
> On Mon, Jul 15, 2013 at 12:26 PM, bill4carson wrote:
>
>> Hello Steven
>>
>> On 2013年07月15日 10:56, Steven Zhou wrote:
>> > Hi,
>> >
>> > We have developed our private OS and we want to benchmark the
>> performance of it, including time of context switch, interrupt latency, IO
>> output and so on ...
>>  ^^^
>> To what degree does "private" goes? Is your private OS an
>> newly created one from scratch or based on one of open source version?
>>
>>
>> >
>> > We want to study from Linux firstly, so could you guys give me some
>> guide of Linux benchmark testing, including test methodologies, test code
>> and so on.
>> >
>> > Thanks in advance.
>> >
>> > --
>> > Best Regards.
>> >
>> >
>> >
>> > ___
>> > Kernelnewbies mailing list
>> > Kernelnewbies@kernelnewbies.org
>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> --
>> 八百里秦川尘土飞扬,三千万老陕齐吼秦腔。
>>
>> --bill
>>
>> ___
>> 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
>
>
Hi,

Benchmarking is a difficult ask. You need to define the matrix of what all
things you would be measure and for what kind of workload. This data should
be directly influenced by the application of the OS, where and how your OS
would be used, what are critical performance areas you need to focus on.

First of all whats the type of kernel you guys have implemented. The main
thing is, what were the design decisions taken while implementing the
policies, how should they perform in theory. After listing all these things
down, you need to design benchmarking software modules for that though you
can have a look at some existing once for the other OSes.

For linux,

1. systemtap.
2. perf.
3. Vtunes from intel.
4. ftrace.

Also, you would be required to emulate the workload to the real load that
would be on your OS and do benchmarking.

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


Re: System call porting

2013-07-12 Thread Rohan Puri
On Fri, Jul 12, 2013 at 11:50 AM, Saket Sinha wrote:

>
> This is to discuss the problems I am facing with porting  a driver from a
> 2.6.18 kernel to 3.8.3 kernel.
> Apart from the APIs and functions that have changed(which I have more or
> less replaced), the system call implementation has changed.
>
> http://lxr.linux.no/linux+v2.6.18/arch/i386/kernel/syscall_table.S#L41
> http://lxr.linux.no/linux+v3.8.3/arch/x86/syscalls/syscall_64.tbl#L92
>
> Now due to this, some unnecessary warnings and errors are coming.
>
> To explain this I am providing the compiler error which is not coming on
> 2.6.18 kernel but is coming on 3.8.3 kernel.
>
> the below line is generating
>
> https://github.com/HeisSpiter/hepunion/blob/master/fs/hepunion/helpers.c#L492
> mode &= ~current->fs->umask;
> the following error-
>  ERROR:Derefencing pointer to incomplete type
>
AFAIK, this error seems like the 'fs'  structures definition is not known
to the code present in this file.
 This can happen because of the header which you included was as per 2.6.18
kernel and in 3.8.3 kernel that struct maybe moved to some where else. The
error indicates the type of the pointer is not known and you are trying to
deference it.


>
> This has nothing to do with any APIs or change in the structure in the
> newer kernel.
> This just the importation of mkdir code from the linux kernel. Likely to
> be sys_mkdir, IIRC. Talking of which, I'd think that I must sync ALL the
> importations from the Linux kernel with mine.
>
>
> Regards,
> Saket Sinha
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: for interested folks, i'll announce new kernel tutorials via twitter

2013-03-17 Thread Rohan Puri
On Sun, Mar 17, 2013 at 7:07 PM, Robert P. J. Day wrote:

>
>   as i don't want to seem like i'm spamming this list with notes about
> new, posted kernel tutorials, people who want to stay on top of these
> are welcome to follow me on twitter at @rpjday. everything written and
> posted will be freely available (creative commons license), and even
> after it's incorporated into future training courses, even those
> courses will be released under the CC so you'll never lose access to
> any of it. so feel free to play along.
>
> 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
>

Hi Robert,

Its fine with me also, by sending it on this list, I think lots of people
would be benefited.

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


Re: set_super_anon in fs/super.c

2012-10-24 Thread Rohan Puri
On Thu, Oct 25, 2012 at 9:40 AM, Abhijit Pawar wrote:

>  On 10/24/2012 01:50 PM, Rohan Puri wrote:
>
> Look inline for comments.
>
> On Tue, Oct 23, 2012 at 7:30 PM, Abhijit Chandrakant Pawar <
> abhi.c.pa...@gmail.com> wrote:
>
>>  Hi Rohan,
>>
>>
>> On Tue, 2012-10-23 at 18:47 +0530, Rohan Puri wrote:
>>
>>
>>
>> On Tue, Oct 23, 2012 at 6:33 PM, Abhijit Chandrakant Pawar <
>> abhi.c.pa...@gmail.com> wrote:
>>
>> I am working on the layered file systems. I came across a function called
>> set_super_anon.
>> This is a callback to the sget function to compare the superblock . This
>> function accepts two parameters. first is superblock * and second is void
>> *.  If you look at the definition of this function, the void* is never
>> used.
>> Many filesystem uses this function when they are mounting the superblock.
>> Some pass NULL and some pass actual data.I have looked till 2.6.31 but
>> there isnt any trace of the usage of second parameter.
>>
>> If it is never used then why its added to the function param list?  Is
>> there any historical reason during the older kernel days?
>>
>> Regards,
>> Abhijit Pawar
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>> Hi Abhijit,
>>
>> See the issue is this function is passed as an argument to sget(), now
>> their are many other file-systems that defined their own set_super function
>> & for that they need data argument where they usually pass mount-related
>> data
>>
>> For eg. see the definition and usage of function nfs_set_super().
>>
>> So, the prototype of the sget() should contain function ptr (set_super())
>> and this function ptr should have data argument also. Now one usage can
>> imply NO USE of the data parameter, which is set_super_anon, but other
>> file-systems may require, so the sget() prototype should be generic to
>> support, both the cases.
>>
>>   Yes... thats what I thought.   many are passing data un-necessarily to
>> this function wherein they already have captured the required information
>> for their purpose in their own defined function.
>>
>  Do you mean to say, each fs's own set_super function makes a call to
> set_anon_super() with data parameter as their specific data, but
> set_anon_super makes no use of it?
>
>>
>> Wouldnt that cause stack to store the value un-necessarily? It would be
>> good if everybody passes NULL as second param.
>>
>>  Yes, each fs's set_super, if makes a call to anon_super() should pass
> NULL as the second parameter(void *data) since anon_super doesnt make use
> of this parameter, need for this parameter just arises to match the
> prototype of sget()'s function ptr agrument. Also do remember the pointer
> to this data is passed, so only a word-size of extra stack is utilized when
> a call to this function is made.
>
> I have made a patch for those filesystems and submitted to the kernel
> list.
>
> - Rohan
>>
>>
> - Rohan
>
>
>  Cool :)

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


Re: set_super_anon in fs/super.c

2012-10-24 Thread Rohan Puri
Look inline for comments.

On Tue, Oct 23, 2012 at 7:30 PM, Abhijit Chandrakant Pawar <
abhi.c.pa...@gmail.com> wrote:

> **
> Hi Rohan,
>
>
> On Tue, 2012-10-23 at 18:47 +0530, Rohan Puri wrote:
>
>
>
> On Tue, Oct 23, 2012 at 6:33 PM, Abhijit Chandrakant Pawar <
> abhi.c.pa...@gmail.com> wrote:
>
> I am working on the layered file systems. I came across a function called
> set_super_anon.
> This is a callback to the sget function to compare the superblock . This
> function accepts two parameters. first is superblock * and second is void
> *.  If you look at the definition of this function, the void* is never
> used.
> Many filesystem uses this function when they are mounting the superblock.
> Some pass NULL and some pass actual data.I have looked till 2.6.31 but
> there isnt any trace of the usage of second parameter.
>
> If it is never used then why its added to the function param list?  Is
> there any historical reason during the older kernel days?
>
> Regards,
> Abhijit Pawar
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> Hi Abhijit,
>
> See the issue is this function is passed as an argument to sget(), now
> their are many other file-systems that defined their own set_super function
> & for that they need data argument where they usually pass mount-related
> data
>
> For eg. see the definition and usage of function nfs_set_super().
>
> So, the prototype of the sget() should contain function ptr (set_super())
> and this function ptr should have data argument also. Now one usage can
> imply NO USE of the data parameter, which is set_super_anon, but other
> file-systems may require, so the sget() prototype should be generic to
> support, both the cases.
>
>  Yes... thats what I thought.   many are passing data un-necessarily to
> this function wherein they already have captured the required information
> for their purpose in their own defined function.
>
Do you mean to say, each fs's own set_super function makes a call to
set_anon_super() with data parameter as their specific data, but
set_anon_super makes no use of it?

>
> Wouldnt that cause stack to store the value un-necessarily? It would be
> good if everybody passes NULL as second param.
>
> Yes, each fs's set_super, if makes a call to anon_super() should pass NULL
as the second parameter(void *data) since anon_super doesnt make use of
this parameter, need for this parameter just arises to match the prototype
of sget()'s function ptr agrument. Also do remember the pointer to this
data is passed, so only a word-size of extra stack is utilized when a call
to this function is made.

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


Re: set_super_anon in fs/super.c

2012-10-23 Thread Rohan Puri
On Tue, Oct 23, 2012 at 6:33 PM, Abhijit Chandrakant Pawar <
abhi.c.pa...@gmail.com> wrote:

> **
> I am working on the layered file systems. I came across a function called
> set_super_anon.
> This is a callback to the sget function to compare the superblock . This
> function accepts two parameters. first is superblock * and second is void
> *.  If you look at the definition of this function, the void* is never
> used.
> Many filesystem uses this function when they are mounting the superblock.
> Some pass NULL and some pass actual data.I have looked till 2.6.31 but
> there isnt any trace of the usage of second parameter.
>
> If it is never used then why its added to the function param list?  Is
> there any historical reason during the older kernel days?
>
> Regards,
> Abhijit Pawar
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi Abhijit,

See the issue is this function is passed as an argument to sget(), now
their are many other file-systems that defined their own set_super function
& for that they need data argument where they usually pass mount-related
data

For eg. see the definition and usage of function nfs_set_super().

So, the prototype of the sget() should contain function ptr (set_super())
and this function ptr should have data argument also. Now one usage can
imply NO USE of the data parameter, which is set_super_anon, but other
file-systems may require, so the sget() prototype should be generic to
support, both the cases.

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


Re: Regarding the Kernel Configuration Options

2012-10-22 Thread Rohan Puri
On Tue, Oct 23, 2012 at 8:48 AM, supratim chakraborty
wrote:

> I was looking for some resources on the explanation on all (or even some
> for that matter) kernel configuration options that come up in the pre-
> compilation phase (make menuconfig ) . I looked over but couldnt find such
> a guide
>
> Can somebody point me in the right direction ?
>
>
>
> -Supratim Chakraborty
> (techturning.in)
> (about.me/borax12 )
> (facebook.com/techturning)
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Supratim,

I dont think that you would find, such a guide. It would be much better if
you ask make more specific query about a particular kernel configuration
option, that you did not understand what does it mean. In that way we could
help you out.

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


Re: where are the bug ?

2012-10-20 Thread Rohan Puri
On Sat, Oct 20, 2012 at 7:35 AM, Fan Yang  wrote:

>
>
> 2012/10/19 Rohan Puri 
>
>>
>>
>> On Fri, Oct 19, 2012 at 7:38 PM, Anuz Pratap Singh Tomar <
>> chambilketha...@gmail.com> wrote:
>>
>>>
>>>
>>> On Fri, Oct 19, 2012 at 2:46 PM, Fan Yang  wrote:
>>>
>>>>
>>>>
>>>> 2012/10/19 Arun KS 
>>>> >
>>>> > Hi Fan,
>>>> >
>>>> > On Fri, Oct 19, 2012 at 6:50 PM, Fan Yang 
>>>> wrote:
>>>> >>
>>>> >> HI ALL:
>>>> >> I just run a module on my machine, but it  can't work. When the
>>>> module run the kernel will painc. I don't know where is wrong. This is my
>>>> code:
>>>> >>
>>>> >>  1 #include
>>>> >>   2 #include
>>>> >>   3 #include
>>>> >>   4 #include
>>>> >>   5
>>>> >>   6 int input = 1;
>>>> >>   7 module_param (input, int, S_IRUGO);
>>>> >>   8
>>>> >>   9 static int __init printvma_init (void)
>>>> >>  10 {
>>>> >>  11 struct vm_area_struct *p, *start;
>>>> >>  12 int i;
>>>> >>  13 struct task_struct *thread;
>>>>
>>>> >>  14
>>>> >>  15 thread = current;
>>>> >>  16
>>>> >>  17 while (1)
>>>> >>  18 {
>>>> >>  19 if (thread->pid == input)
>>>> >>  20 break;
>>>> >>  21 thread = list_entry (thread->tasks.next, struct
>>>> task_struct, tasks);
>>>> >>  22 }
>>>> >>  23 p = thread->mm->mmap;
>>>> >>  24
>>>> >>  25 do{
>>>> >>  26 printk ("%lx\t%lx\t%s\n", p->vm_start,\
>>>> >>  27 p->vm_end, p->vm_file->f_path.dentry->d_iname);
>>>> >>  28 p = p->vm_next;
>>>> >>  29 }while (p != NULL);
>>>> >>  30
>>>> >>  31 printk ("vm_file address is:%d\tf_path address is:%d\
>>>> >>  32 \tname is:%s",& p->vm_file->f_path,\
>>>> >>  33 p->vm_file->f_path.dentry->d_iname);
>>>> >>  34
>>>> >>  35 printk ("info from the kernel space:%s\n", thread->comm);
>>>> >>  36 return 0;
>>>> >>  37 }
>>>> >>  38
>>>> >>  39 static void __exit printvma_exit (void)
>>>> >>  40 {
>>>> >>  41 printk ("the module will leave the kernel space..\n");
>>>> >>  42 }
>>>> >>  43
>>>> >>  44 module_init (printvma_init);
>>>> >>  45 module_exit (printvma_exit);
>>>> >>  46 MODULE_LICENSE ("GPL");
>>>> >>
>>>> >>
>>>> >> what's wrong?
>>>> >
>>>> >
>>>> > It would be good if you paste your crash log here.
>>>> >
>>>> > Thanks,
>>>> > Arun
>>>> >>
>>>> >>
>>>> >> thanks
>>>> >>
>>>> >> ___
>>>> >> Kernelnewbies mailing list
>>>> >> Kernelnewbies@kernelnewbies.org
>>>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>> >>
>>>> >
>>>> The module run in a virtual machine, I can't control the machine when
>>>> it crashed, so I just got a picture when the kernel panic.
>>>>
>>>> you can run the module under uml, it wont be hard to copy  the crash
>>> log from terminal in uml.
>>>
>>>>
>>>>
>>>>
>>>>
>>>> Thanks
>>>> Fan
>>>>
>>>> ___
>>>> 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
>>>
>>>
>> Hi Fan,
>>
>> See the issue is thread->mm is NULL in your case. The simplest way to
>> test this in your case is by the following : -
>>
>> Put these statements after the while loop
>>
>> if(!thread->mm) { printk("thread->mm is NULL\n"); return 0; }
>>
>> After this compile and load the module, you will see this statement
>> printed in dmesg command output.
>>
>>
>> General programming practice : -
>>
>> Always make checks for NULL pointer in your code, before dereferencing
>> your code.
>>
>> - Rohan
>>
> Hi Rohan,
>
> I don't think the thread->mm is NULL, because when I print the several
> vm_area_struct of the thread->mm it work well, but if put the code in the
> loop to print all the vma, it crashed.
>
> Thinks
> Fan
>

Hi Fan,

Yes Fan, you are right, its NOT thread->mm NULL, but p->vm_file is NULL, to
verify put the following as the fist statement in do {}while; loop

if(!p->vm_file) { printk("p->vm_file NULL\n"); return 0;}


This message gets printed to kernel log buffer.

Also, you still need to NULL check pointer before dereferencing them. Let
me know, whats the result on your system.

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


Re: where are the bug ?

2012-10-19 Thread Rohan Puri
On Fri, Oct 19, 2012 at 7:38 PM, Anuz Pratap Singh Tomar <
chambilketha...@gmail.com> wrote:

>
>
> On Fri, Oct 19, 2012 at 2:46 PM, Fan Yang  wrote:
>
>>
>>
>> 2012/10/19 Arun KS 
>> >
>> > Hi Fan,
>> >
>> > On Fri, Oct 19, 2012 at 6:50 PM, Fan Yang  wrote:
>> >>
>> >> HI ALL:
>> >> I just run a module on my machine, but it  can't work. When the
>> module run the kernel will painc. I don't know where is wrong. This is my
>> code:
>> >>
>> >>  1 #include
>> >>   2 #include
>> >>   3 #include
>> >>   4 #include
>> >>   5
>> >>   6 int input = 1;
>> >>   7 module_param (input, int, S_IRUGO);
>> >>   8
>> >>   9 static int __init printvma_init (void)
>> >>  10 {
>> >>  11 struct vm_area_struct *p, *start;
>> >>  12 int i;
>> >>  13 struct task_struct *thread;
>>
>> >>  14
>> >>  15 thread = current;
>> >>  16
>> >>  17 while (1)
>> >>  18 {
>> >>  19 if (thread->pid == input)
>> >>  20 break;
>> >>  21 thread = list_entry (thread->tasks.next, struct
>> task_struct, tasks);
>> >>  22 }
>> >>  23 p = thread->mm->mmap;
>> >>  24
>> >>  25 do{
>> >>  26 printk ("%lx\t%lx\t%s\n", p->vm_start,\
>> >>  27 p->vm_end, p->vm_file->f_path.dentry->d_iname);
>> >>  28 p = p->vm_next;
>> >>  29 }while (p != NULL);
>> >>  30
>> >>  31 printk ("vm_file address is:%d\tf_path address is:%d\
>> >>  32 \tname is:%s",& p->vm_file->f_path,\
>> >>  33 p->vm_file->f_path.dentry->d_iname);
>> >>  34
>> >>  35 printk ("info from the kernel space:%s\n", thread->comm);
>> >>  36 return 0;
>> >>  37 }
>> >>  38
>> >>  39 static void __exit printvma_exit (void)
>> >>  40 {
>> >>  41 printk ("the module will leave the kernel space..\n");
>> >>  42 }
>> >>  43
>> >>  44 module_init (printvma_init);
>> >>  45 module_exit (printvma_exit);
>> >>  46 MODULE_LICENSE ("GPL");
>> >>
>> >>
>> >> what's wrong?
>> >
>> >
>> > It would be good if you paste your crash log here.
>> >
>> > Thanks,
>> > Arun
>> >>
>> >>
>> >> thanks
>> >>
>> >> ___
>> >> Kernelnewbies mailing list
>> >> Kernelnewbies@kernelnewbies.org
>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >>
>> >
>> The module run in a virtual machine, I can't control the machine when it
>> crashed, so I just got a picture when the kernel panic.
>>
>> you can run the module under uml, it wont be hard to copy  the crash log
> from terminal in uml.
>
>>
>>
>>
>>
>> Thanks
>> Fan
>>
>> ___
>> 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
>
>
Hi Fan,

See the issue is thread->mm is NULL in your case. The simplest way to test
this in your case is by the following : -

Put these statements after the while loop

if(!thread->mm) { printk("thread->mm is NULL\n"); return 0; }

After this compile and load the module, you will see this statement printed
in dmesg command output.


General programming practice : -

Always make checks for NULL pointer in your code, before dereferencing your
code.

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


Re: an online kernel crash book, and wondering what's deprecated

2012-09-26 Thread Rohan Puri
On Wed, Sep 26, 2012 at 8:11 PM, Mulyadi Santosa
wrote:

> Hi Rob...
>
> On Wed, Sep 26, 2012 at 6:33 PM, Robert P. J. Day 
> wrote:
> >   along those lines, i'm just digging into ftrace and was wondering if
> > it in any way obsoleted systemtap, but i've heard from more than one
> > source that while ftrace is allegedly more powerful, systemtap still
> > has its place and is worth talking about.
>
> since systemtap is still included in Redhat Enterprise Linux, I could
> firmly say SystemTap is still highly relevant these days. So is
> kdump/kexec.
>
> >   so ... if one was going to put together a (small) toolbox of kernel
> > debugging tools, what's worth covering?  interested in any feedback.
>
> IMHO, the most important part is the art of understanding oops message
> and its related stack trace.
>
> I agree :)

> Or worst, what if the system just hangsdivide and conquer things
> like disabling acpi, sysrq, might be the skills we need here.
>
> Not sure if you agree with me here, but I just deliver my ideas.
>
>
>
> --
> 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
>

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


Re: an online kernel crash book, and wondering what's deprecated

2012-09-26 Thread Rohan Puri
On Wed, Sep 26, 2012 at 5:03 PM, Robert P. J. Day wrote:

>
>   in my online travels yesterday, i ran across this gem, "Linux Kernel
> Crash Book":
>
>   http://www.dedoimedo.com/computers/crash-book.html
>
> and am now wondering about what would constitute a reasonable (and
> minimal?) list of canonical kernel debugging tools.
>
>   first, while the book above covers Linux Kernel Crash Dump (LKCD),
> the author freely admits that it's been pretty much obsoleted by the
> more recent and flexible kdump, so there seems to be little value in
> digging into LKCD (or, in my case, adding any coverage of it to a
> kernel debugging course, which i am currently designing).
>
>   next, someone else's course i'm teaching next week has a kernel
> debugging chapter which opens with netdump and diskdump before moving
> onto kdump and kexec, but those earlier utilities are *also*
> deprecated these days,
>
>
> http://serverfault.com/questions/181554/how-should-i-capture-linux-kernel-panic-stack-traces
>
> so i would be tempted to skip any coverage of netdump and diskdump in
> favour of additional and more advanced coverage of kdump and kexec.
>
>   along those lines, i'm just digging into ftrace and was wondering if
> it in any way obsoleted systemtap, but i've heard from more than one
> source that while ftrace is allegedly more powerful, systemtap still
> has its place and is worth talking about.
>
>   so ... if one was going to put together a (small) toolbox of kernel
> debugging tools, what's worth covering?  interested in any feedback.
>
> 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
>

Hi Robert,

Good to know that you are preparing material. For linux kernel debugging, I
would love if you could include, kdb, kgdb and also their setup
environment, like now most people do development on Virtual Machine. So the
debugger needs to be setup on the VM and its serial port to the host
machine, where the debugging logs would be displayed.

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


Re: How to get the inode - no path_lookup

2012-08-13 Thread Rohan Puri
On Mon, Aug 13, 2012 at 2:17 PM, Rishi Agrawal wrote:

>
>
> On Thu, Aug 9, 2012 at 12:39 PM, Rohan Puri wrote:
>
>>
>>
>> On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal 
>> wrote:
>>
>>>
>>>
>>> On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri wrote:
>>>
>>>>
>>>>
>>>> On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <
>>>> rishi.b.agra...@gmail.com> wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>>
>>>>> I had a module which used the path_lookup function to print the
>>>>> details of any file's inode. I now want to rewrite that module in order to
>>>>> show some juniors how to write some code in kernel.
>>>>>
>>>>> I am using 3.4.6 kernel, I tried finding out path_lookup but google
>>>>> showed that it has been removed.
>>>>>
>>>>> I tried the following code then which did not work
>>>>>
>>>>> .
>>>>> .
>>>>> .
>>>>> dentry = kern_path_create(AT_FDCWD, filename, &path, 1);
>>>>>
>>>>> if (IS_ERR(dentry)) {
>>>>>   printk("Failed to obtain the dentry");
>>>>>return;
>>>>>}
>>>>>
>>>>> its not returning dentry
>>>>>
>>>>> I again tried after seeing the implementation of vfs_stat function
>>>>>
>>>>> user_path_at(AT_FDCWD, filename, lookup_flags, &path);
>>>>>
>>>>> but this also fails.
>>>>>
>>>>>
>>>>> I am using a proc interface to pass the filename, and copying the
>>>>> filename into a kernel buffer.
>>>>>
>>>>> How can I get a copy of vfs inode for a file name.
>>>>>
>>>>>
>>>>> Need to use vfs_path_lookup for this, present in fs/namei.c file,
>>>> which would give you filled nameidata nd that contais inodes pointer.
>>>>
>>>>> --
>>>>> Regards,
>>>>> Rishi Agrawal
>>>>>
>>>>>
>>>>> ___
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies@kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>>
>>>> - Rohan
>>>>
>>>
>>> vfs_path_lookup needs a dentry/mountpoint for the current path.
>>>
>>> How will I get those.
>>>
>>>
>>> /**
>>>  * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount
>>> pair
>>>  * @dentry:  pointer to dentry of the base directory
>>>  * @mnt: pointer to vfs mount of the base directory
>>>  * @name: pointer to file name
>>>  * @flags: lookup flags
>>>  * @path: pointer to struct path to fill
>>>  */
>>>
>>>
>>> --
>>> Regards,
>>> Rishi Agrawal
>>>
>>> If you dont have vfsmount's ptr, then you can make use of kern_path api
>> with the LOOKUP_FOLLOW as second parameter. This will return the struct
>> path ptr which contains vfsmount and the dentry's ptr. Now the dentry's ptr
>> will contain the inode that you require.
>>
>> - Rohan
>>
>
> Thanks, used that and its working now
>
> --
> Regards,
> Rishi Agrawal
>
> Good to know :)

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


Re: How to get the inode - no path_lookup

2012-08-09 Thread Rohan Puri
On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal wrote:

>
>
> On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri wrote:
>
>>
>>
>> On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal 
>> wrote:
>>
>>> Hi All,
>>>
>>>
>>> I had a module which used the path_lookup function to print the details
>>> of any file's inode. I now want to rewrite that module in order to show
>>> some juniors how to write some code in kernel.
>>>
>>> I am using 3.4.6 kernel, I tried finding out path_lookup but google
>>> showed that it has been removed.
>>>
>>> I tried the following code then which did not work
>>>
>>> .
>>> .
>>> .
>>> dentry = kern_path_create(AT_FDCWD, filename, &path, 1);
>>>
>>> if (IS_ERR(dentry)) {
>>>   printk("Failed to obtain the dentry");
>>>return;
>>>}
>>>
>>> its not returning dentry
>>>
>>> I again tried after seeing the implementation of vfs_stat function
>>>
>>> user_path_at(AT_FDCWD, filename, lookup_flags, &path);
>>>
>>> but this also fails.
>>>
>>>
>>> I am using a proc interface to pass the filename, and copying the
>>> filename into a kernel buffer.
>>>
>>> How can I get a copy of vfs inode for a file name.
>>>
>>>
>>> Need to use vfs_path_lookup for this, present in fs/namei.c file, which
>> would give you filled nameidata nd that contais inodes pointer.
>>
>>> --
>>> Regards,
>>> Rishi Agrawal
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>> - Rohan
>>
>
> vfs_path_lookup needs a dentry/mountpoint for the current path.
>
> How will I get those.
>
>
> /**
>  * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
>  * @dentry:  pointer to dentry of the base directory
>  * @mnt: pointer to vfs mount of the base directory
>  * @name: pointer to file name
>  * @flags: lookup flags
>  * @path: pointer to struct path to fill
>  */
>
>
> --
> Regards,
> Rishi Agrawal
>
> If you dont have vfsmount's ptr, then you can make use of kern_path api
with the LOOKUP_FOLLOW as second parameter. This will return the struct
path ptr which contains vfsmount and the dentry's ptr. Now the dentry's ptr
will contain the inode that you require.

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


Re: How to get the inode - no path_lookup

2012-08-08 Thread Rohan Puri
On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal wrote:

> Hi All,
>
>
> I had a module which used the path_lookup function to print the details of
> any file's inode. I now want to rewrite that module in order to show some
> juniors how to write some code in kernel.
>
> I am using 3.4.6 kernel, I tried finding out path_lookup but google showed
> that it has been removed.
>
> I tried the following code then which did not work
>
> .
> .
> .
> dentry = kern_path_create(AT_FDCWD, filename, &path, 1);
>
> if (IS_ERR(dentry)) {
>   printk("Failed to obtain the dentry");
>return;
>}
>
> its not returning dentry
>
> I again tried after seeing the implementation of vfs_stat function
>
> user_path_at(AT_FDCWD, filename, lookup_flags, &path);
>
> but this also fails.
>
>
> I am using a proc interface to pass the filename, and copying the filename
> into a kernel buffer.
>
> How can I get a copy of vfs inode for a file name.
>
>
> Need to use vfs_path_lookup for this, present in fs/namei.c file, which
would give you filled nameidata nd that contais inodes pointer.

> --
> Regards,
> Rishi Agrawal
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
- Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Changing the page attributes

2012-07-10 Thread rohan puri
On Tue, Jul 10, 2012 at 9:42 PM, Mulyadi Santosa
wrote:

> Hi..
>
> On Tue, Jul 10, 2012 at 6:51 PM, Arun KS  wrote:
> > Hello Experts,
> >
> > I have a requirement to change __log_buf memory(kernel printk buffer)
> > as non cacheable memory.
> > How can I change the page attributes for changing cache policy to non
> cacheable?
>
> I just can give short clue. I think somehow you must find its PTE
> entry...there, IIRC there is page attribute that can be changed to
> make it uncacheable.
>
> cross check the Intel processor manual for further clarification (if
> it's indeed x86 arch)
>
> --
> 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
>


The __log_buf is a static array. Will it be in cacheable page? And by
cacheable here, I guess we mean entry present in page cache, right?

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


Re: kernel_sendpage query.

2012-06-09 Thread rohan puri
On Sat, Jun 9, 2012 at 8:26 PM, Pranay Kumar Srivastava <
pranay.shrivast...@hcl.com> wrote:

> Hi,
>
> I've been trying to understand kernel_sendpage but I've not been able to
> figure it out completely and hopefully someone else knows better so please
> help me out on this.
>
> I'm using kernel_sendpage for a TCP connection and it works well when
> there are lesser number of kernel threads trying to send data using it.
> Now the page I hand over to kernel_sendpage is reused again for reading
> data from the socket and then processing it and then again resending the
> processed data in the same page again. It's at maximum 2KB data and never
> lesser than 120 bytes.
>
> As I see it in the code, the page isn't copied in the skb frags array it's
> just assigned and get_page is called to increment the page reference count.
> (I don't free it anyway until the thread is stopped and it never is unless
> it gets a signal).
>
> Now I don't know wether kernel_sendpage will wait for the page to be sent
> or it won't. I've tried with MSG_DONTWAIT and passing 0 for flags but after
> every now and then the problem occurs at client which I'm describing below
> with the best explanation I could think of...
>
>When too many kernel threads are trying to send data using
> kernel_sendpage, with NO MSG_DONTWAIT flag, then also it seems that this
> call succeeds? However since I'm reusing the page the data can get
> overridden by the next sock_recvmsg and when the network stack is ready to
> send my page it gets garbage data at client?
>
> The same issue I observed with MSG_DONTWAIT set even in that case the
> client sometimes get garbage data.
>
> So my query is,
>
> To use kernel_sendpage what I need to do in order to be sure that network
> stack indeed has sent my page and that I can reuse it for sock_recvmsg
> again.
>
> Thanks a lot for reading!
>
>
>
>
> Regards,
> Pranay Kr. Srivastava
> pranay.shrivast...@hcl.com
> Software Engineer
> ERS,HCL Technologies
> A-5, Sector 24, Noida 201301, U.P. (India)
>
>
>
> ::DISCLAIMER::
>
> 
>
> The contents of this e-mail and any attachment(s) are confidential and
> intended for the named recipient(s) only.
> E-mail transmission is not guaranteed to be secure or error-free as
> information could be intercepted, corrupted,
> lost, destroyed, arrive late or incomplete, or may contain viruses in
> transmission. The e mail and its contents
> (with or without referred errors) shall therefore not attach any liability
> on the originator or HCL or its affiliates.
> Views or opinions, if any, presented in this email are solely those of the
> author and may not necessarily reflect the
> views or opinions of HCL or its affiliates. Any form of reproduction,
> dissemination, copying, disclosure, modification,
> distribution and / or publication of this message without the prior
> written consent of authorized representative of
> HCL is strictly prohibited. If you have received this email in error
> please delete it and notify the sender immediately.
> Before opening any email and/or attachments, please check them for viruses
> and other defects.
>
>
> 
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hi,

I had a brief look at the kernel_sendpage() function. It can call either
sock->ops->sendpage() if this is set or calls

sock_no_sendpage() otherwise. If sock_no_sendpage() code path is executed
then,

sock_no_sendpage() (kunmaps the page)-> kernel_sendmsg() -> sock_sendmsg()
(waits for data to be synced). So, I think you are OK if this is the code
path.

You need to check this in case of sock->ops->sendpage().

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


Re: Encfs detailed design guide?!! [hope this is relevant to this forum]

2012-05-25 Thread rohan puri
On Fri, May 25, 2012 at 7:24 PM, Bill Traynor  wrote:

> On Fri, May 25, 2012 at 9:36 AM, SaNtosh kuLkarni
>  wrote:
> > Any help regarding Encfs (encrypted file system) detailed design.
> > Any suitable link would be helpful.Thanks.
>
> See:  http://en.wikipedia.org/wiki/ECryptfs
>
> And relevant references therein.
>
> >
> > --
> > Regards,
> > Santosh
> >
> >
> > ___
> > 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
>

Hi Santosh,

The basic design concept is of stackable file system. You can get the paper
for wrapfs by Prof. Erez Zadok (which is also a stackable file system) from
internet.

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


Re: Why I can't compile a simple netfilter hook module?

2012-05-08 Thread rohan puri
On Tue, May 8, 2012 at 9:37 AM, Chir0n  wrote:

> I'm using this Makefile:
>
> *obj-m += hello.o
>
> all:
>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
>
> clean:
>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean*
>
>
> The hello.c is this:
>
> *#include 
> #include 
> #include 
> #include 
>
> static struct nf_hook_ops nfho; //struct holding set of hook
> function options
>
> //function to be called by hook
> unsigned int hook_func(unsigned int hooknum, struct sk_buff **skb, const
> struct net_device *in, const struct net_device *out, int (*okfn)(struct
> sk_buff *))
> {
>  printk(KERN_INFO "packet dropped\n");
> //log to var/log/messages
>  return NF_DROP;
> //drops the packet
> }
>
> //Called when module loaded using 'insmod'
> int init_module()
> {
>  nfho.hook = hook_func;   //function to call when
> conditions below met
>  nfho.hooknum = NF_IP_PRE_ROUTING;//called right after packet
> recieved, first hook in Netfilter
>  nfho.pf = PF_INET;   //IPV4 packets
>  nfho.priority = NF_IP_PRI_FIRST; //set to highest priority
> over all other hook functions
>  nf_register_hook(&nfho); //register hook
>
>  return 0;//return 0 for success
> }
>
> //Called when module unloaded using 'rmmod'
> void cleanup_module()
> {
>  nf_unregister_hook(&nfho); //cleanup – unregister hook
> }*
>
>
> Here are the error message:
>
> *$ make
> make -C /lib/modules/3.3.2-6.fc16.x86_64/build
> M=/home/fabio/Desktop/modules modules
> make[1]: Entering directory `/usr/src/kernels/3.3.2-6.fc16.x86_64'
>  CC [M]  /home/fabio/Desktop/modules/hello.o
> /home/fabio/Desktop/modules/hello.c: In function ‘init_module’:
> /home/fabio/Desktop/modules/hello.c:18:13: warning: assignment from
> incompatible pointer type [enabled by default]
> *

you may have declared the header, thn check whether the path is correct or
the symbol name spelling.

> * /home/fabio/Desktop/modules/hello.c:19:18: error: ‘NF_IP_PRE_ROUTING’
> undeclared (first use in this function)
> /home/fabio/Desktop/modules/hello.c:19:18: note: each undeclared
> identifier is reported only once for each function it appears in
> make[2]: *** [/home/fabio/Desktop/modules/hello.o] Error 1
> make[1]: *** [_module_/home/fabio/Desktop/modules] Error 2
> make[1]: Leaving directory `/usr/src/kernels/3.3.2-6.fc16.x86_64'
> make: *** [all] Error 2*
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Also dont delete previous mail thread contents.

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


Re: Why I can't compile a simple netfilter hook module?

2012-05-07 Thread rohan puri
On Tue, May 8, 2012 at 9:37 AM, Chir0n  wrote:

> I'm using this Makefile:
>
> *obj-m += hello.o
>
> all:
>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
>
> clean:
>make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean*
>
>
> The hello.c is this:
>
> *#include 
> #include 
> #include 
> #include 
>
> static struct nf_hook_ops nfho; //struct holding set of hook
> function options
>
> //function to be called by hook
> unsigned int hook_func(unsigned int hooknum, struct sk_buff **skb, const
> struct net_device *in, const struct net_device *out, int (*okfn)(struct
> sk_buff *))
> {
>  printk(KERN_INFO "packet dropped\n");
> //log to var/log/messages
>  return NF_DROP;
> //drops the packet
> }
>
> //Called when module loaded using 'insmod'
> int init_module()
> {
>  nfho.hook = hook_func;   //function to call when
> conditions below met
>  nfho.hooknum = NF_IP_PRE_ROUTING;//called right after packet
> recieved, first hook in Netfilter
>  nfho.pf = PF_INET;   //IPV4 packets
>  nfho.priority = NF_IP_PRI_FIRST; //set to highest priority
> over all other hook functions
>  nf_register_hook(&nfho); //register hook
>
>  return 0;//return 0 for success
> }
>
> //Called when module unloaded using 'rmmod'
> void cleanup_module()
> {
>  nf_unregister_hook(&nfho); //cleanup – unregister hook
> }*
>
>
> Here are the error message:
>
> *$ make
> make -C /lib/modules/3.3.2-6.fc16.x86_64/build
> M=/home/fabio/Desktop/modules modules
> make[1]: Entering directory `/usr/src/kernels/3.3.2-6.fc16.x86_64'
>  CC [M]  /home/fabio/Desktop/modules/hello.o
> /home/fabio/Desktop/modules/hello.c: In function ‘init_module’:
> /home/fabio/Desktop/modules/hello.c:18:13: warning: assignment from
> incompatible pointer type [enabled by default]
> /home/fabio/Desktop/modules/hello.c:19:18: error: ‘NF_IP_PRE_ROUTING’
> undeclared (first use in this function)
> /home/fabio/Desktop/modules/hello.c:19:18: note: each undeclared
> identifier is reported only once for each function it appears in
> make[2]: *** [/home/fabio/Desktop/modules/hello.o] Error 1
> make[1]: *** [_module_/home/fabio/Desktop/modules] Error 2
> make[1]: Leaving directory `/usr/src/kernels/3.3.2-6.fc16.x86_64'
> make: *** [all] Error 2*
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi,

You need to include header which defines "*NF_IP_PRE_ROUTING"*
*
*
*- *Rohan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem of workqueue

2012-05-03 Thread rohan puri
On Fri, May 4, 2012 at 6:55 AM, 夏业添  wrote:

> Hi Chetan,
>
> Thanks for reply and it works. And I want to verify some other things.
>
> Is it a good way to use workqueue to do this job: send data to user
> space through netlink socket from kernel?
>
> Thanks!
>
> 2012/5/4 Chetan Nanda :
> >
> > On May 3, 2012 8:37 PM, "夏业添"  wrote:
> >>
> >> Hi,
> >>
> >> I want to use workqueue in my irq handler. Some materials say that I can
> >> use
> >>
> >>INIT_WORK( &work, function, &data );
> >>
> >> to initialize work, whose type is struct work_struct, and data is
> >> something should be passed to function.
> >> however, it seems that now the macro INIT_WORK() only accept two
> >> parameters:&work and function.
> >>
> >> My problem is how to pass data to the function and why they change that
> >> macro?
> >>
> >> Thanks!
> >>
> > May be you are looking for something like this:
> >
> http://www.linuxforums.org/forum/kernel/183688-init_work-two-arguments.html
> >
> > ~chetan  ___
> >> 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
>
Hi,
To send data from kernel space and user-space see kernel's notification
mechanism like fanotify which works on by creating an anonymous fd in the
user-space process's context which then might perform normal read() and
write() call to receive and send data to kernel.

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


Re: Hooking a system call.

2012-03-27 Thread rohan puri
On Wed, Mar 28, 2012 at 9:16 AM, V.Ravikumar
wrote:

>
>
> On Mon, Mar 26, 2012 at 1:18 PM, Mulyadi Santosa <
> mulyadi.sant...@gmail.com> wrote:
>
>> Hi...
>>
>> On Mon, Mar 26, 2012 at 11:45, V.Ravikumar 
>> wrote:
>> > As part of auditing purpose I need to intercept/hook open/read/write
>> system
>> > calls.
>> >
>> > As I was lack of knowledge into kernel development.Could somebody help
>> me
>> > out here ?
>> > I'm working on RHEL-5 machine with Linux kernel version 2.6.18
>> > Thanks & Regards,
>> > Ravi
>>
>> IMHO you better use SystemTap, which is based on Kprobes. It can be
>> used to hook into almost every part of kernel system, with very less
>> overhead.
>>
>>
> Yes SystemTap is one of the elegant way to hook system calls.
>
> But I need one help while hooking write system call. I need to print the
> file name also, but file name is not passed to write system call. How can I
> get the file for write (or sys_write ) system call.
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi,

One way to do this is to map the physical page to new virtual page and make
that page RW and then replace with ur handlers. Refer vmap()

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


Re: does anyone know how to communicate between domUs on xen?

2012-02-20 Thread rohan puri
On Mon, Feb 20, 2012 at 7:17 PM, summerxyt  wrote:

> **
> hi,
>I'm not very sure about if I can ask questions about xen here. I have
> tow questions.
>The first one is that I'm looking for methods about inter-domain
> communication for xen. I know besides network, VMs on the same physical
> machine can exchange information by event channel and grant table. But are
> these two ways working in kernel mode as part of drivers, or can I directly
> use them just like network socket in user mode?   I've tried to google it
> but only got something I can't fully understand.
>The second questions is I want to do some extra jobs (like check tcp/ip
> header and change some bits) to packages in the virtual network of xen. As
> all domUs' packages are passing the back driver of dom0, I want to put this
> extra action to network back driver of dom0. But I'm not sure which part of
> the source code has the function of receiving packages from front driver. I
> think it may be function  
> xen_netbk_tx_action.
> I'll be very appreciated if someone knows the answer. Thanks!
>
> --
> summerxyt
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Check the website of xen, they might have something. One which I knew was
xensocket, but I guess you would need to port it to latest xen kernel as it
was not part of it. There may be other mechanisms also.

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


Re: Current Thread mapping

2012-01-15 Thread rohan puri
On Sun, Jan 15, 2012 at 3:02 PM, SaNtosh kuLkarni <
santosh.yesop...@gmail.com> wrote:

> HI everyone just wanted to know whats the current implementation of user||
> kernel space thread mapping ...is it 1:1 or does it depend on the needs ?
> For example say if i have 12k user space thread running ,,,how many kernel
> space thread would be managing them... as far as i know there is 1:1 mappin
>
> Thanks
>
> --
> *Regards,
> Santi*
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
Hi,
It basically depends on the threading library's implementation, AFAIK, for
pthreads its 1:1 mapping.

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


Re: Kernel user communication mechanism

2011-12-16 Thread rohan puri
On Fri, Dec 16, 2011 at 8:49 PM, Greg KH  wrote:

> On Fri, Dec 16, 2011 at 10:56:16AM +0530, rohan puri wrote:
> >
> >
> > On Thu, Dec 15, 2011 at 5:54 PM, Konstantin Zertsekel <
> zertse...@gmail.com>
> > wrote:
> >
> > > Was having a look at the netlink sockets. What will be the
> behaviour for
> > > sending an event which is blocking on the response from user-space
> the
> > queue
> > > is full. How this case will be handled.
> > >
> > > Also fanotify makes use of fsnotify's notification mechanism to
> send
> > events
> > > and get response from kernel. Is it possible to send event from
> > user-space
> > > to kernel space in -case of fanotify.
> >
> > Why is it interesting?
> > What is the story behind?
> > --- Kosta
> >
> >
> > I need to move the IP in user-space which currently is as a proprietary
> module
> > and release the kernel component as GPL.
> >
> > So for decision making I require this communication.
>
> Please consult a lawyer as to if this is really a proper separation that
> will hold up to the GPL requirements of the kernel.
>
> good luck,
>
> greg k-h
>

Thanks greg for the suggestion. Companies manager are looking into those
legal matters. I as a developer have been told to work on U-K & K-U
communication mechanism. Would love to have your suggestion as to how to go
about it?

Thanks & Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel user communication mechanism

2011-12-15 Thread rohan puri
On Thu, Dec 15, 2011 at 5:54 PM, Konstantin Zertsekel
wrote:

> > Was having a look at the netlink sockets. What will be the behaviour for
> > sending an event which is blocking on the response from user-space the
> queue
> > is full. How this case will be handled.
> >
> > Also fanotify makes use of fsnotify's notification mechanism to send
> events
> > and get response from kernel. Is it possible to send event from
> user-space
> > to kernel space in -case of fanotify.
>
> Why is it interesting?
> What is the story behind?
> --- Kosta
>

I need to move the IP in user-space which currently is as a proprietary
module and release the kernel component as GPL.

So for decision making I require this communication.

Any help in terms of ideas or existing solutions would be appreciable.

Also Greg please if you could help me out :)

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Kernel user communication mechanism

2011-12-14 Thread rohan puri
Hello Guys,

I want to implement a kernel-user communication mechanism in which kernel
can send events to user space (both blocking and non-blocking). Blocking
events would require response which the kernel will interpret. Also
user-space can also send the events to the kernel and get the response.

Was having a look at the netlink sockets. What will be the behaviour for
sending an event which is blocking on the response from user-space the
queue is full. How this case will be handled.

Also fanotify makes use of fsnotify's notification mechanism to send events
and get response from kernel. Is it possible to send event from user-space
to kernel space in -case of fanotify.

I there any other way present which is better than these two above ways.

Any ideas to implement a new mechanism are also appreciated.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Storage and I/O subsystem

2011-12-14 Thread rohan puri
On Wed, Dec 14, 2011 at 3:22 PM, RKK  wrote:

> Hello all,
> I want to  start learning  the Linux Block I/O stack about how it
> handles I/O requests and about the storage subsystem  .anybody has any
> documents with that ? any pointers for where to start ? and how to
> start? thanks.
> --
> Warm Regards,
> Ravi .
> "I don't Know is not a excuse , its an opportunity to know."
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

You can start with Understanding Linux kernel

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: What is Backing device used for?

2011-12-04 Thread rohan puri
On Sun, Dec 4, 2011 at 9:50 PM, Mulyadi Santosa
wrote:

> On Sun, Dec 4, 2011 at 18:22, loody  wrote:
> > Dear all:
> > Is there any document which explain what "backing device" used for?
>
> such as "backing block device" in caching?
>
> --
> 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
>

Backing device in linux is a block device.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: What is RTNL lock?

2011-11-27 Thread rohan puri
On Mon, Nov 28, 2011 at 12:19 PM, Vimal  wrote:

> Hi Rohan
>
> Yes, I understood this part, but I am wondering what is the purpose of
> this lock.   I am guessing it's to protect all network related
> operations from critical events, for e.g.: protecting a packet
> transmit during device removal, protecting routing table entry during
> route lookup, etc., but I can't find its precise documentation
> anywhere.   Thanks,
>
> On 27 November 2011 22:44, rohan puri  wrote:
> >
> >
> > On Sun, Nov 27, 2011 at 10:37 PM, Vimal  wrote:
> >>
> >> Hi all,
> >>
> >> In the Linux networking code, I see a lot of comments that say "Must
> >> be called with RTNL lock."
> >>
> >> What is this lock?  I tried searching for it but couldn't find any
> >> explanation on what it is...
> >>
> >> Thanks
> >> --
> >> Vimal
> >>
> >> ___
> >> Kernelnewbies mailing list
> >> Kernelnewbies@kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> > Hello Vimal,
> > This is a mutex named rtnl_mutex. Refer file net/core/rtnetlink.c
> > static DEFINE_MUTEX(rtnl_mutex);
> >
> > void rtnl_lock(void)
> > {
> > mutex_lock(&rtnl_mutex);
> > }
> > EXPORT_SYMBOL(rtnl_lock);
> > Where ever you see those comments indicate that this mutex is to be held
> > before execution of that code path.
> > Regards,
> > Rohan
>
>
>
> --
> Vimal
>
This lock is used to serialize changes to net_device instances from runtime
events, conf changes

Refer book understanding Linux network internals for more details.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Ownership of sk_buff

2011-11-23 Thread rohan puri
On Thu, Nov 24, 2011 at 5:33 AM, Vimal  wrote:

> Hi all,
>
> When a protocol like TCP or UDP creates an sk_buff and passes it down
> to the layer 3 and layer 2 protocol functions, which module has
> ownership of the buffer as it gets passed down?   Is it the
> responsibility of the caller, or the callee to free the sk_buff?  Are
> there any exceptions?
>
> Thanks,
> --
> Vimal
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hello Vimal,

Refer
http://www.linuxfoundation.org/collaborate/workgroups/networking/skbuff

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to hook the system call?

2011-11-23 Thread rohan puri
On Wed, Nov 23, 2011 at 11:35 PM, Geraint Yang wrote:

> Hi,
> I have tried the LSM framework,but when I make my module , I got
> "waining:'register_security' undefined", then I check security/security.c
> and found out that register_security is not exported ! So if I want to use
> this function ,I must hack kernel by exporting and recompiling kernel which
> is allowed for me.
> So ...well, it seems that LSM doesn't work for module without modifying
> the kernel source.
>
>
>
> This function is declared as extern in header linux/security.h, you can
include this header in your code and call this function.

>
> On Thu, Nov 24, 2011 at 12:59 AM, Alexandru Juncu 
> wrote:
>
>> On Wed, Nov 23, 2011 at 6:50 PM, Geraint Yang 
>> wrote:
>> > Hi,
>> > Thank all of you for helping me with problem!
>> > I don't want to modify my kernel source so I am trying to learn to use
>> LSM
>> > security hook even though it seems that it couldn't hook all the system
>> > calls, I think it should be enough for me.
>> > Thanks again!
>>
>> I know that AppArmor can hock syscalls like read, write and memory
>> mapping and can deny or accept them. I am not sure if you can make it
>> do something else when hocked, but I know it has a script-like
>> configuration, so maybe you can take some other actions.
>>
>
>
>
> --
> Geraint Yang
> Tsinghua University Department of Computer Science and Technology
>
>
> Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to hook the system call?

2011-11-23 Thread rohan puri
On Wed, Nov 23, 2011 at 3:57 PM, Alexandru Juncu wrote:

> On Wed, Nov 23, 2011 at 12:10 PM, Daniel Baluta 
> wrote:
> > On Wed, Nov 23, 2011 at 11:22 AM, Alexandru Juncu 
> wrote:
> >> On Wed, Nov 23, 2011 at 10:40 AM, Geraint Yang 
> wrote:
> >>> Hello everyone,
> >>>
> >>> I am going to hook a system call like 'read' or 'send' by modifying the
> >>> sys_call_table, but it seems that the sys_call_table is in read only
> page,
> >>> how can I set modify the sys_call_table ? Or if there any method that
> I can
> >>> use to hook a system call in module without modify the kernel source?
> >>>
> >>> Thanks!
> >>
> >> On a 2.6.35 kernel, it worked for me just by changing an entry in the
> >> sys_call_table, within a kernel module.  Something like this:
> >
> > Alex,
> > I am pretty sure that you are using a hacked version of 2.6.35.
> >
> > Geraint,
> > In order to be able to hook a syscall you must do the following:
> >
> > 1. export syscall_table in arch/x86/kernel/i386_ksyms_32.c
> >
> > extern void* sys_call_table[];
> > EXPORT_SYMBOL(sys_call_table);
> >
> > 2. make sys_call_table writebale. In arch/x86/kernel/entry_32.S
> > you must have:
> >
> > .section .data,"a"
> > #include "syscall_table_32.S"
> >
> > thanks,
> > Daniel.
> >
>
> Ah, Daniel is right... I forgot about that part...
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

You can get the address of the sys_call_table from the /proc/kallsyms and
regarding the read-only section of the this symbol you can re-map the
addresses by making use of vmap api in kernel. This will avoid the need for
the compilation of the kernel. But I would not recommend you to do this.
Their is LSM framework specifically available for this try to see if you
can make use of that.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: how set_user_nice() function is called

2011-11-23 Thread rohan puri
On Tue, Nov 22, 2011 at 3:53 PM, Enes Albay - انس الباى  wrote:

> Thanks for reply.
>
> I also asked that set_user_nice where and when is called(file and line).
> I think it is not called after each forking operation, isn't it? Could you
> give calling order between functions from do_fork() like that
> func1()->func2()->...
>
> Regards.
>
> On Mon, Nov 21, 2011 at 3:59 AM, Mulyadi Santosa <
> mulyadi.sant...@gmail.com> wrote:
>
>> On Mon, Nov 21, 2011 at 00:31, Enes Albay - انس الباى
>>  wrote:
>> > Hi!
>> >
>> > anybody knows that where is set_user_nice() function called in the
>> kernel?
>> > i couldn't find that.  i just found that in forking operation
>> > do_fork()->copy_process()->
>> > dup_task_struct() called then set_user_nice()
>> > called but i couldn't find that where. Also how/where do_fork() function
>> > called in kernel i couldn't find.
>>
>> In x86, do_fork() is called from sys_fork()... check :
>> http://lxr.linux.no/#linux+v3.1.1/arch/x86/kernel/process.c#L235
>>
>> While sys_fork() itself, since it's a syscall handler, is called from
>> entry.S. Please refer to:
>> http://lxr.linux.no/#linux+v3.1.1/arch/x86/ia32/ia32entry.S#L475
>>
>>
>>
>> --
>> regards,
>>
>> Mulyadi Santosa
>> Freelance Linux trainer and consultant
>>
>> blog: the-hydra.blogspot.com
>> training: mulyaditraining.blogspot.com
>>
>
>
>
> --
> Enes Albay
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> make use of cscope to get the locations from whr set_user_nice() is
called. I did egrep pattern search using cscope and could see it getting
called from many locations : -

0 loop.c   578 set_user_nice(current, -20);
1 nbd.c505 set_user_nice(current, -20);
2 pktcdvd.c   1567 set_user_nice(current, -20);
3 ipmi_si_intf.c  1012 set_user_nice(current, 19);
4 dmatest.c291 set_user_nice(current, 10);
5 ap_bus.c1563 set_user_nice(current, 19);
6 bnx2fc_fcoe.c436 set_user_nice(current, -20);
7 bnx2fc_fcoe.c567 set_user_nice(current, -20);
8 fcoe.c  1646 set_user_nice(current, -20);
9 ibmvfc.c4438 set_user_nice(current, -20);
a ibmvscsi.c  1891 set_user_nice(current, -20);
b lpfc_hbadisc.c   715 set_user_nice(current, -20);
c qla_os.c3314 set_user_nice(current, -20);
d main.c  2322 set_user_nice(speakup_task, 10);
e target_core_transport.c 6091 set_user_nice(current, -20);
f tfc_cmd.c702 set_user_nice(current, -20);
g fs-writeback.c   902 set_user_nice(current, 0);
h background.c  83 set_user_nice(current, 10);
i heartbeat.c 1093 set_user_nice(current, -20);
j sched.h 2037 extern void set_user_nice(struct task_struct
*p, long nice);
k exit.c   350 set_user_nice(current, 0);
l hung_task.c  195 set_user_nice(current, 0);
m kmod.c   157 set_user_nice(current, 0);
n rcutorture.c 867 set_user_nice(current, 19);
o rcutorture.c 910 set_user_nice(current, 19);
p rcutorture.c 993 set_user_nice(current, 19);
q rcutree_plugin.h1452 set_user_nice(current, 19);
r rtmutex-tester.c 307 set_user_nice(current, 0);
s sched.c 4880 void set_user_nice(struct task_struct *p,
long nice)
t sched.c 4925 EXPORT_SYMBOL(set_user_nice);
u sched.c 4977 set_user_nice(current, nice);
v sched.c 8271 set_user_nice(p, 0);
w sys.c168 set_user_nice(p, niceval);
x ring_buffer_benchmark.c  453 set_user_nice(consumer, consumer_nice);
y ring_buffer_benchmark.c  462 set_user_nice(producer, producer_nice);
z workqueue.c 2034 set_user_nice(current, RESCUER_NICE_LEVEL);
A backing-dev.c272 set_user_nice(current, 0);

रेगार्ड्स,
रोहन पूरी
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: sd_prep_fn

2011-11-10 Thread rohan puri
On Thu, Nov 10, 2011 at 6:26 PM, sumeet gandhare
wrote:

>
>
> On Thu, Nov 10, 2011 at 6:13 PM, rohan puri wrote:
>
>>
>>
>> On Thu, Nov 10, 2011 at 4:50 PM, sumeet gandhare <
>> sumeetgandh...@gmail.com> wrote:
>>
>>> Hi All,
>>>   I am trying to understand the scsi upper layer and middle layer code
>>> and found the function sd_prep_fn which seems to convert a request to a
>>> scsi command. I want to know when this function sd_prep_fn gets invoked.
>>>
>>> It seems sd_probe_async invokes
>>>
>>>blk_queue_prep_rq 
>>> <http://lxr.linux.no/linux+*/+code=blk_queue_prep_rq>(sdp 
>>> <http://lxr.linux.no/linux+*/+code=sdp>->request_queue 
>>> <http://lxr.linux.no/linux+*/+code=request_queue>, sd_prep_fn 
>>> <http://lxr.linux.no/linux+*/+code=sd_prep_fn>);
>>>
>>>
>>>
>>> Further following code is invoking the prep_rq_fn
>>>
>>> which is the blk_peek_request
>>>
>>> http://lxr.linux.no/#linux+v3.1/block/blk-core.c#L1879 
>>> <http://lxr.linux.no/#linux+v3.1/block/blk-core.c%23L1879>
>>>
>>>
>>>
>>> and blk_peek_request is getting invoked from
>>>
>>> scsi_request_fn
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1493 
>>> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1493>
>>>
>>>
>>>
>>> scsi_request_fn is registered with the block layer as a request function at 
>>> the following code
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1688 
>>> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1688>
>>>
>>>
>>>
>>> And scsi_alloc_queue is invoked from scsi_alloc_sdev
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L238 
>>> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L238>
>>>
>>>
>>>
>>> scsi_alloc_sdev is invoked as a part of scsi lun discovery from lots of 
>>> places
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1004 
>>> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1004>
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1306 
>>> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1306>
>>>
>>>
>>>
>>> The confusion I have is that the sd.c upper layer driver has not registered 
>>> for a request function using blk_init_queue
>>>
>>> Any help would be appreciated.
>>>
>>> Thanks
>>> Sumeet
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> Hello Sumeet,
>>
>> sd_prep_fn function is set to the request queue's prep_rq_fn member as
>> you have mentioned.
>>
>> Now this function gets called in
>>
>> ret = q->prep_rq_fn(q, rq); in function blk_peek_request() which is
>> called from scsi_request_fn() in file scsi_lib.c
>>
>> Regards,
>> Rohan Puri
>>
>
> Hi Rohan,
>  Thanks for your response and help.
>  It seems there is scsi_prep_fn too. I thought the blk_peek_request()
> invokes scsi_prep_fn and not sd_prep_fn.
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1248<http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1248>
>
> scsi_prep_fn is registered here
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1684<http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1684>
>
>
> Please could you confirm.
>
> Thanks
> Sumeet
>

Whenever a new scsi device is attached sd_probe is called sd_async_probe()
is the async part of sd_probe() So when this is called the prep_fn is set
to sd_prep_fn and hence this will be called.

sd_prep_fn is for scsi disk, similarly there is a function sr_prep_fn which
gets called for scsi cd-rom.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: sd_prep_fn

2011-11-10 Thread rohan puri
On Thu, Nov 10, 2011 at 4:50 PM, sumeet gandhare
wrote:

> Hi All,
>   I am trying to understand the scsi upper layer and middle layer code and
> found the function sd_prep_fn which seems to convert a request to a scsi
> command. I want to know when this function sd_prep_fn gets invoked.
>
> It seems sd_probe_async invokes
>
>blk_queue_prep_rq 
> <http://lxr.linux.no/linux+*/+code=blk_queue_prep_rq>(sdp 
> <http://lxr.linux.no/linux+*/+code=sdp>->request_queue 
> <http://lxr.linux.no/linux+*/+code=request_queue>, sd_prep_fn 
> <http://lxr.linux.no/linux+*/+code=sd_prep_fn>);
>
> Further following code is invoking the prep_rq_fn
>
> which is the blk_peek_request
>
> http://lxr.linux.no/#linux+v3.1/block/blk-core.c#L1879 
> <http://lxr.linux.no/#linux+v3.1/block/blk-core.c%23L1879>
>
> and blk_peek_request is getting invoked from
>
> scsi_request_fn
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1493 
> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1493>
>
>
> scsi_request_fn is registered with the block layer as a request function at 
> the following code
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1688 
> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1688>
>
> And scsi_alloc_queue is invoked from scsi_alloc_sdev
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L238 
> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L238>
>
> scsi_alloc_sdev is invoked as a part of scsi lun discovery from lots of places
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1004 
> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1004>
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1306 
> <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1306>
>
> The confusion I have is that the sd.c upper layer driver has not registered 
> for a request function using blk_init_queue
>
> Any help would be appreciated.
>
> Thanks
> Sumeet
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hello Sumeet,

sd_prep_fn function is set to the request queue's prep_rq_fn member as you
have mentioned.

Now this function gets called in

ret = q->prep_rq_fn(q, rq); in function blk_peek_request() which is called
from scsi_request_fn() in file scsi_lib.c

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Spinlocks and interrupts

2011-11-09 Thread rohan puri
On Thu, Nov 10, 2011 at 3:10 AM, Dave Hylands  wrote:

> Hi Kai,
>
> On Wed, Nov 9, 2011 at 1:07 PM, Kai Meyer  wrote:
> > When I readup on spinlocks, it seems like I need to choose between
> > disabling interrupts and not. If a spinlock_t is never used during an
> > interrupt, am I safe to leave interrupts enabled while I hold the lock?
> > (Same question for read/write locks if it is different.)
>
> So the intention behind using a spinlock is to provide mutual exclusion.
>
> A spinlock by itself only really provides mutual exclusion between 2
> cores, and not within the same core. To provide the mutual exclusion
> within the same core, you need to disable interrupts.
>
> Normally, you would disable interrupts and acquire the spinlock to
> guarantee that mutual exclusion, and the only reason you would
> normally use the spinlock without disabling interrupts is when you
> know that interrupts are already disabled.
>
> The danger of acquiring a spinlock with interrupts enabled is that if
> another interrupt fired (or the same interrupt fired again) and it
> tried to acquire the same spinlock, then you could have deadlock.
>
> If no interrupts touch the spinlock, then you're probably using the
> wrong mutual exclusion mechanism. spinlocks are really intended to
> provide mutual exclsion between interrupt context and non-interrupt
> context.
>
> Also remember, that on a non-SMP (aka UP) build, spinlocks become
> no-ops (except when certain debug checking code is enabled).
>
> --
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Nice explanation Dave.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Guidance on writing device drivers

2011-11-09 Thread rohan puri
On Wed, Nov 9, 2011 at 10:40 PM, suraj khurana wrote:

> Hi all,
> I am a newbie in linux world and want to learn linux device drivers.
>
> I am currently reading book - "Linux Device Drivers" by O'reilly.
>
> Does anyone has any problem statements based on device drivers for practice
> so that I can enhance my skills in writing device drivers.
>
>
> Thanks,
> Suraj
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hello Suraj,
I would suggest complete reading the book with the examples given in the
book.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Char device initialization

2011-11-09 Thread rohan puri
On Wed, Nov 9, 2011 at 7:22 PM, Alexandru Juncu wrote:

> On Wed, Nov 9, 2011 at 3:41 PM, Daniel Hilst Selli
>  wrote:
> > I'm trying to create a example char device. The example compiles fine,
> > but when I try to "cat" I got "No such device or address". I have
> > reviewed the code thousend times and can't see what I'm missing
> >
> > Here is the code -> http://pastebin.com/Td03U0fK
> >
> > The read method is not good, I know, but is never called.
> >
> > I use my own running kenrel to test, I know that is danger. I'm building
> > a qemu enviroment to test this better.
> >
> > Here is uname -a:
> > Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011
> > x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux
> >
> > Any idea?
> >
> > Thanks
>
> You tried to 'cat' a /dev/my_device file, right?
> Was that device file created with the mknod command?
>
> --
> Alexandru Juncu
>
> ROSEdu
> http://rosedu.org
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>


Hello Daniel,

I had the look at the code. The issue is with the cdev_add() call in
init_gcdev() function.

int cdev_add(struct cdev *p, dev_t dev, unsigned count) is the prototype

Now the problem was  *instead of passing second argument of type dev_t you
were passing minor number macro.

*Fix : - Do following additions : -

1. static int major; // Declare a global major no var.

2. In init_gcdev() after call to alloc_chrdev_region() get major no and
store in major var.

major = MAJOR(gcdev->dev);

3. Replace cdev_add() call like this : -

 cdev_add(&gcdev->cdev, MKDEV(major, FIRST_MINOR), 1);

Now its running and your read methos is getting called.

Hello Alexandru,

That error was due to improper args passed to cdev_add(). If device file is
not present (no mknod done) error would be "No such file or dir"

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Getting a block from a block device?

2011-11-08 Thread rohan puri
On Tue, Nov 8, 2011 at 8:48 PM, Manish Katiyar  wrote:

> On Tue, Nov 8, 2011 at 6:02 AM, Dan Luedtke 
> wrote:
> > Thanks for all the answers!
> >
> >> You need to look at other block-based file systems in the kernel
> sources in fs dir for examples and understand how they do it.
> > I looked at fs/minix/* fs/fat/* and peeked into fs/ext2/, but got more
> > confused so I decided to ask for a starting point.
>
> Hi Dan,
>
> You may find https://github.com/mkatiyar/testfs helpful.
>
> >
> >> Also i think if you are interested in reading the first sector
> >> then you can probably check the block/genhd.c file
> >> get the disk (i.e struct genhd) then the partition (struct hdpart)
> >> you will be able to get the first sector.
> > Thanks, a well documented source file. However, shouldn't I get the
> > right partition (I called it block device in previously sent mails,
> > thought of e.g. /dev/sda2 as a device not a partition) from VFS when a
> > user requestes mounting it?
> >
> >> That's an old assignment from my uni.
> > Wow, exactly what I needed! Thanks for this starting point.
> >
> >> I would redirect you to learn about struct gendisk and struct bio.
> > Noted, I will take a look after studying the vvfs-files from Stephens
> link.
> >
> >> Can you tell what are you trying to achieve?
> > I'd like to implement a filesystem as kernel modul (like fat, ext2,
> > ...). The filesystem is a very simple one, based on chained blocks
> > (similar to linked lists in c). I "invented" it when I tried to write
> > a bootloader that does not require a second stage to read an kernel
> > image. (This is all more or less a "because we can"-project, no
> > commercial background, just learning).
> >
> > Once again, thank you guys!
> >
> > Greetings,
> >
> > Dan
> > --
> > Dan Luedtke
> > http://www.danrl.de
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
>
>
> --
> Thanks -
> Manish
>

Nice reference manish :)

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Getting a block from a block device?

2011-11-08 Thread rohan puri
On Tue, Nov 8, 2011 at 5:26 PM, Dan Luedtke wrote:

> Hallo,
>
> On Tue, Nov 8, 2011 at 12:27 PM, Stephen Gream 
> wrote:
> > Once you have the device registered (on /sys or /dev), register a read
> > callback on the file and use copy_to_user to output the data
>
> I read that article you referred to, but I don't think it addresses my
> problem, as I may have been more clear on what I want to achieve
> before. Sorry for that!
> I want to eventually implement a file system, and therefore I am
> studying the kernel sources to get an idea about all that.
>
> Here is my general understanding on how thinks may work :)
>
> virtual file system (VFS) <-[1]-> my file system implementation
> <-[2]-> a block device
>
> As I understood, all these subsystems are running in kernel mode.
>
> For [1] I read vfs.txt and learned about the VFS-API
> For [2] I have no idea where I can find the API documentation, however
> there were some hints on the book "Linux Driver Development" from
> O'Reilly in chapter "block devices". Nothing really helpful, as they
> were talking about registering new block devices. I want to use
> already present devices where I expect my filesystem to be present on.
> To check that, I have to read the first 512 bytes.
>
> The userspace implementation I was talking about previously is
> something like a mkfs.myfilesystem, that's why i referred to fopen()
> there.
>
> Thank you!
>
> Greetings,
>
> Dan
> --
> Dan Luedtke
> http://www.danrl.de
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
Dan,

You need to look at other block-based file systems in the kernel sources in
fs dir for examples and understand how they do it.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Understanding memcpy

2011-10-19 Thread rohan puri
On Thu, Oct 20, 2011 at 3:04 AM, Kai Meyer  wrote:

> I'm trying to poke around an ext4 file system. I can submit a bio for
> the correct block, and read in what seems to be the correct information,
> but when I try to memcpy my char *buffer to a reference to a struct I've
> made, it just doesn't seem to work. The relevant code looks like this:
>
> typedef struct ext2_superblock {
> /* 00-03 */ uint32_t e2sb_inode_count;
> /* 04-07 */ uint32_t e2sb_block_count;
> /* 08-11 */ uint32_t e2sb_blocks_reserved;
> /* 12-15 */ uint32_t e2sb_unallocated_blocks;
> /* 16-19 */ uint32_t e2sb_unallocated_inodes;
> /* 20-23 */ uint32_t e2sb_sb_block;
> /* 24-27 */ uint32_t e2sb_log_block_size;
> /* 28-31 */ uint32_t e2sb_log_fragment_size;
> /* 32-35 */ uint32_t e2sb_num_blocks_per_group;
> /* 36-39 */ uint32_t e2sb_num_frag_per_group;
> /* 40-43 */ uint32_t e2sb_num_inodes_per_group;
> /* 44-47 */ uint32_t e2sb_last_mount_time;
> /* 48-51 */ uint32_t e2sb_last_written_time;
> /* 52-53 */ uint16_t e2sb_num_mounted;
> /* 54-55 */ uint16_t e2sb_num_allowed_mounts;
> /* 56-57 */ uint16_t e2sb_signature;
> /* 58-59 */ uint16_t e2sb_fs_state;
> /* 60-61 */ uint16_t e2sb_error_action;
> /* 62-63 */ uint16_t e2sb_ver_minor;
> /* 64-67 */ uint32_t e2sb_last_check;
> /* 68-71 */ uint32_t e2sb_time_between_checks;
> /* 72-75 */ uint32_t e2sb_os_id;
> /* 76-79 */ uint32_t e2sb_ver_major;
> /* 80-81 */ uint16_t e2sb_uid;
> /* 82-83 */ uint16_t e2sb_gid;
> } e2sb;
>
>
> char *buffer;
> uint32_t *pointer;
> e2sb sb;
> buffer = __bio_kmap_atomic(bio, 0, KM_USER0);
> pointer = (uint32_t *)buffer;
> printk(KERN_DEBUG "sizeof pbd->sb %lu\n", sizeof(bpd->sb));
> printk(KERN_DEBUG "Inode Count: %u\n", pointer[0]); /* Works! */
> printk(KERN_DEBUG "Block Count: %u\n", pointer[1]); /* Works! */
> printk(KERN_DEBUG "Block Reserved: %u\n", pointer[2]); /* Works! */
> printk(KERN_DEBUG "Unallocated blocks: %u\n", pointer[3]); /* Works! */
> printk(KERN_DEBUG "Unallocated inodes: %u\n", pointer[4]); /* Works! */
> memcpy(buffer, &sb, sizeof(sb));
>
This should be : -
memcpy(&sb, buffer, sizeof(sb));


> __bio_kunmap_atomic(bio, KM_USER0);
> printk(KERN_DEBUG "e2sb_debug: Total number of inodes in file system
> %u\n", sb->e2sb_inode_count);/* Doesn't work! */
> printk(KERN_DEBUG "e2sb_debug: Total number of blocks in file
> system%u\n", sb->e2sb_block_count); /* Doesn't work! */
>
> My code is actually much more verbose. The values I get from indexing
> into pointer are correct, and match what I get from dumpe2fs. The values
> I get from the e2sb struct are not. They are usually 0. I would imagine
> that memcpy is the fastest way to copy data from buffer instead of
> casting the pointer to something else, and using array indexing to get
> the values.
>
> I struggled to find where ext4 actually does this, so I'm making this up
> as I go along. Any thing that you see that I should be doing a different
> way that isn't actually part of my question is welcome too.
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Trouble removing character device

2011-10-19 Thread rohan puri
On Thu, Oct 20, 2011 at 2:25 AM, Kai Meyer  wrote:

> Unfortunately I can't share the source code, it belongs to the company I
> work for.
>
> All of cdev_init, cdev_del, and unregister_chrdev_region are void
> functions, so they have no return value.
>
> I check the return value of alloc_chrdev_region and cdev_add and check
> for errors with BUG_ON (for now).
>
> -Kai Meyer
>
> On 10/19/2011 02:18 PM, Daniel Baluta wrote:
> > On Wed, Oct 19, 2011 at 7:04 PM, Kai Meyer  wrote:
> >> I can't seem to get my character device to remove itself from the
> >> /proc/devices list. I'm calling all of the following functions like so:
> >>
> >> alloc_chrdev_region(&dev, 0, 5, "my_char");
> >> cdev_init(&my_cdev,&my_ops);
> >> cdev_add(&my_cdev, MKDEV(my_major, my_minor), 1);
> >> cdev_del(&my_cdev);
> >> unregister_chrdev_region(my_major, 5);
> >>
> >> It seems like I'm missing something, but I can't find it. I'm
> >> referencing the Linux Device Drivers v3, chapter 3. In the example code,
> >> the scull_cleanup_module function calls cdev_dell and
> >> unregister_chrdev_region, just like I do.
> >>
> >> To be clear, after I unload my module (after calling cdev_del and
> >> unregister_chrdev_region), my "my_char" string still shows up in
> >> /proc/devices.
> > Did you check  return codes for all functions?
> > Also, can you post a link to the code?
> >
> > thanks,
> > Daniel.
> >
> > ___
> > 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
>

During cleanup i think you need to call function unregister_chrdev_region().

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Heap memory is not re-claiming.

2011-10-18 Thread rohan puri
On Sat, Oct 15, 2011 at 9:31 AM, Mulyadi Santosa
wrote:

> Hi :)
>
> On Fri, Oct 14, 2011 at 16:15, pankaj singh  wrote:
> > Nice doc ...:)
> >
> > On Fri, Oct 14, 2011 at 10:28 AM, rohan puri 
> wrote:
> >> Reference to an article by Mulayadi Santosa :-
> >>
> >>
> http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html
> >>
> >> AWESOME ARTICLE SIR :)
>
>
> Thank you, thank you very much for your appreciation :) I just hope,
> besides getting adequate money, you all got something meaningful from
> that article. And I believe, as long as there are people who have same
> concerned, that article will be refined over and over and overall will
> be better through the time :)
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>

Right :)

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Heap memory is not re-claiming.

2011-10-18 Thread rohan puri
On Tue, Oct 18, 2011 at 10:04 AM, V.Ravikumar
wrote:

> On Sat, Oct 15, 2011 at 9:31 AM, Mulyadi Santosa <
> mulyadi.sant...@gmail.com> wrote:
>
>> Hi :)
>>
>> On Fri, Oct 14, 2011 at 16:15, pankaj singh  wrote:
>> > Nice doc ...:)
>> >
>> > On Fri, Oct 14, 2011 at 10:28 AM, rohan puri 
>> wrote:
>> >> Reference to an article by Mulayadi Santosa :-
>> >>
>> >>
>> http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html
>> >>
>> >> AWESOME ARTICLE SIR :)
>>
>>
>> Thank you, thank you very much for your appreciation :) I just hope,
>> besides getting adequate money, you all got something meaningful from
>> that article. And I believe, as long as there are people who have same
>> concerned, that article will be refined over and over and overall will
>> be better through the time :)
>>
>> --
>> 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
>>
>
>  Hi,
>
> It's really a fabulous article.
> Many many thanks to  Mulyadi for such a great article and thank for Rohan
> for sharing the link.
>
> I read the article and correlate contents  with my current issue.
> Here are my observations. Do please correct me if I'm wrong at any point.
>
> The leak  which I was observed in my program is due to big memory buffers
> of size 5MB allocation from heap.I've 6 such character buffers.
>
> So as per below lines from the article memory should be allocated with mmap
> and it immediately releases memory to kernel  upon free/delete call from
> user land process.
>
> The allocator uses two functions to get a chunk of memory from the kernel:
>
>- brk() sets the end of the process's data segment.
>- mmap() creates a new VMA and passes it to the allocator.
>
> The decision on whether to use brk() or mmap() requires one simple check.
> If the request is equal or larger than M_MMAP_THRESHOLD, the allocator
> uses mmap(). If it is smaller, the allocator calls brk(). By default,
> M_MMAP_THRESHOLD is 128KB
>
> But It seems I'm landed with a case which uses brk() for allocation and so
> it just marks as free when I my program frees the memory and hence 30 MB
> memory (I've 6 , 5MB buffers from heap)was kept on allocator's control
> leading to a 30MB leak of user land process.
> Please note that I'm freeing memory for 6 buffers (I'm sure about that).
>
> Regards,
> Ravi
>
>
> Yes I think thats the case.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to avoid volatiles

2011-10-14 Thread rohan puri
On Fri, Oct 14, 2011 at 2:51 PM, Prabhakar Lad
wrote:

> Hi everyone,
>
> I had question in want eradicate volatile from here:  for example:
>
>
>#define 0x01c40800
>
>
> if ((volatile void *)pllbase == (volatile void
> *)DAVINCI_PLL_CNTRL0_BASE) /**HERE**/
> return 8;
> else
> return pll_div(pllbase, PLLC_PREDIV);
>
>
> Thanks.
>
>
> Regards
> --Prabhakar
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi,

volatile keyword is make use of to enforce compiler that not to optimize the
code that contains this qualifier.

In this case maybe any of the two compared values could be changed in an
unknowing way to the compiler which are to be considered and no optimization
is required, hence volatile keyword is made use of.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Heap memory is not re-claiming.

2011-10-13 Thread rohan puri
On Thu, Oct 13, 2011 at 2:36 PM, V.Ravikumar
wrote:

>
>
> On Thu, Oct 13, 2011 at 2:12 PM, Jeff Donner wrote:
>
>> On Thu, Oct 13, 2011 at 1:26 AM, V.Ravikumar
>>  wrote:
>> > I've a daemon process and I'm allocating heap memory for big character
>> > buffers using malloc/free.
>> > Each can take 5MB.
>> >
>> > Though I freed/deleted memory allocated for the buffers, the increased
>> > memory during the allocation time is not re-claiming back.This I
>> observed
>> > using top command.
>>
>> Yes, I think it's glibc - it may keep your memory, with the idea that
>> you'll request it again soon anyway.
>>
>If this is the case then memory should not keep on increase albeit how
> long process may run. right?
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Ravi,


When you ask for a memory block, usually by using malloc(), you're asking
the runtime C library whether a preallocated block is available. This
block's size must *at least* equal the user request. If there is already a
memory block available, malloc() will assign this block to the user and mark
it as "used." Otherwise, malloc() must allocate more memory by extending the
heap. All requested blocks go in an area called the *heap.

Reference to an article by Mulayadi Santosa :-

http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html

AWESOME ARTICLE SIR :)

*Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: dma_alloc_coherent

2011-10-12 Thread rohan puri
On Wed, Oct 12, 2011 at 11:47 PM, bob jonny  wrote:

>  In dma_alloc_coherent(), where is it allocating memory from, and how does
> it know that that memory is cache coherent? Does every device have it's
> cache coherent memory? I got lost at function pointer struct dma_map_ops
> ops, is there an easy way to figure out what ops->alloc_coherent() points
> to?
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Bob,

dma_alloc_coherent() invokes the alloc_coherent method for the particular
device which is the first parameter.

So to see from where the memory is getting allocated, you need to see that
device's dma_map_op's alloc_coherent method.

I went through some of them, they tend to alloc memory by calling either
__get_free_pages() or alloc_pages() functions.

To maintain cache coherency, the pages which are allocated in these
functions have to be uncached and if they where cached earlier then they
have to be flushed.

Following function explains all these : -

void *dma_generic_alloc_coherent(struct device *dev, size_t size,
 dma_addr_t *dma_handle, gfp_t gfp)
{
void *ret, *ret_nocache;
int order = get_order(size);

gfp |= __GFP_ZERO;

ret = (void *)__get_free_pages(gfp, order);
if (!ret)
return NULL;

/*
 * Pages from the page allocator may have data present in
 * cache. So flush the cache before using uncached memory.
 */
dma_cache_sync(dev, ret, size, DMA_BIDIRECTIONAL);

ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret),
size);
if (!ret_nocache) {
free_pages((unsigned long)ret, order);
return NULL;
}

split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);

*dma_handle = virt_to_phys(ret);

return ret_nocache;
}

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: kernel version incorporating a particular feature

2011-10-12 Thread rohan puri
On Wed, Oct 12, 2011 at 2:14 PM, amit mehta  wrote:

> How do i find the linux kernel version from which a certain
> feature was first incorporated. For example , How do i find the
> first kernel version which had support for
> GRO (generic receive offload) ?
>
> Thanks,
> Amit
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
Hi Amit,

Kernel version is 2.6.29 refer http://lwn.net/Articles/358910/

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: File change notification along with user

2011-10-12 Thread rohan puri
On Wed, Oct 12, 2011 at 12:17 PM, V.Ravikumar
wrote:

>
> On Wed, Oct 12, 2011 at 12:04 PM, rohan puri wrote:
>
>>
>>
>> On Wed, Oct 12, 2011 at 10:50 AM, V.Ravikumar <
>> ravikumar.valla...@gmail.com> wrote:
>>
>>> Other than fanotify , I can achieve my requirement through a
>>> driver/module. If this can be achieved through a driver/module please
>>> provide me inputs to start.
>>>
>>> Thanks,
>>> Ravi
>>>
>>> On Wed, Sep 21, 2011 at 10:27 AM, rohan puri wrote:
>>>
>>>>
>>>>
>>>> On Wed, Sep 21, 2011 at 10:03 AM, V.Ravikumar <
>>>> ravikumar.valla...@gmail.com> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> Is it possible to write a module/driver which notifies file/directory
>>>>> change asynchronously along with user name(or with uid) who modified it.
>>>>>
>>>>> inotify will do change notification but it will not provide uid who
>>>>> modified/created the file.
>>>>>
>>>>> audit and inotify combination can work, but I'm looking for a better
>>>>> option than this.
>>>>>
>>>>> Please help me.
>>>>>
>>>>> Thanks,
>>>>> Ravi
>>>>>
>>>>> ___
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies@kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>> You can have a look at fanotify.
>>>>
>>>> Refer http://lwn.net/Articles/339253/
>>>>
>>>> Regards,
>>>> Rohan Puri
>>>>
>>>
>>> Hi Ravi,
>>
>> See, first of all if you want to notify file/dir change you need to the
>> control after the invocation of that i_ops or f_ops. So there are two ways
>> in which you can do : -
>>
>> 1. Easy & recommended : -
>>
>> Write a stackable file system module. The aim of this module will be to
>> intercept vfs-calls on files/dirs & then call the underlying file systems
>> specific operations. Now after completion of this operation, you would
>> generate the change event here which will be used to notify.
>>
>>
>> Note : - stackable file system research work was done by Professor *Erez
>> Zadok.
>>
>> *
>> refer ecryptfs for an example.
>>
>
> This is more helpful for me.
>
>>
>> 2. Complex & not recommended : -
>>
>> Instead of writing a stackable file system, you hook the mount sys call to
>> get the control of the fs related structs. Then replace the original i_ops
>> and f_ops pointer with your own defined ops. save the originals somewhere.
>> Then when from user-space when some change operation is called, internally
>> your ops will be called and now you call the original stored one and
>> contruct the notification events
>>
>>
>  Even I've this in my mind. As it is not  recommended,I had dropped this
> choice
>
> 3. See if the module making use of LSM infrastructure will be able to do
>> this or not.
>>
>> Regards,
>> Rohan Puri
>>
> Hi Rohan
>
> Thank you for your valuable inputs. I will through the ecryptfs
>
> Thanks
> Ravi
>

Hi Ravi,

Good :). One more thing about that first approach, that stackable file
system has to be mounted on the top-level directory, for which (sub-dirs and
files) you need the notifications. This acts as the stacking trigger point.

Was just keen to know, where are you requiring it?

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: File change notification along with user

2011-10-11 Thread rohan puri
On Wed, Oct 12, 2011 at 10:50 AM, V.Ravikumar
wrote:

> Other than fanotify , I can achieve my requirement through a driver/module.
> If this can be achieved through a driver/module please provide me inputs to
> start.
>
> Thanks,
> Ravi
>
> On Wed, Sep 21, 2011 at 10:27 AM, rohan puri wrote:
>
>>
>>
>> On Wed, Sep 21, 2011 at 10:03 AM, V.Ravikumar <
>> ravikumar.valla...@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> Is it possible to write a module/driver which notifies file/directory
>>> change asynchronously along with user name(or with uid) who modified it.
>>>
>>> inotify will do change notification but it will not provide uid who
>>> modified/created the file.
>>>
>>> audit and inotify combination can work, but I'm looking for a better
>>> option than this.
>>>
>>> Please help me.
>>>
>>> Thanks,
>>> Ravi
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> You can have a look at fanotify.
>>
>> Refer http://lwn.net/Articles/339253/
>>
>> Regards,
>> Rohan Puri
>>
>
> Hi Ravi,

See, first of all if you want to notify file/dir change you need to the
control after the invocation of that i_ops or f_ops. So there are two ways
in which you can do : -

1. Easy & recommended : -

Write a stackable file system module. The aim of this module will be to
intercept vfs-calls on files/dirs & then call the underlying file systems
specific operations. Now after completion of this operation, you would
generate the change event here which will be used to notify.


Note : - stackable file system research work was done by Professor *Erez
Zadok.

*
refer ecryptfs for an example.

2. Complex & not recommended : -

Instead of writing a stackable file system, you hook the mount sys call to
get the control of the fs related structs. Then replace the original i_ops
and f_ops pointer with your own defined ops. save the originals somewhere.
Then when from user-space when some change operation is called, internally
your ops will be called and now you call the original stored one and
contruct the notification events

3. See if the module making use of LSM infrastructure will be able to do
this or not.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Finding out when a process has died

2011-10-10 Thread rohan puri
On Tue, Oct 11, 2011 at 8:57 AM, MK  wrote:

> Hi,
>
> I want to write a process (hopefully userspace) which will "watch"
> other processes and do something when a process dies. What is a good
> way to do this? A simple solution would be to have a stream/tcp
> connection between the watcher and other processes and when the
> connection is broken, you know the other side has died. Is there a
> better way to do this possibly involving a kernel mod?
>
> Thanks!!
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
Hi,

I think you can make use of user-defined signal handlers.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: problem mapping physical address from /dev/mem

2011-10-07 Thread rohan puri
On Fri, Oct 7, 2011 at 3:51 PM, rohan puri  wrote:

>
>
> On Fri, Oct 7, 2011 at 3:29 PM, rohan puri  wrote:
>
>>
>>
>> On Fri, Oct 7, 2011 at 12:41 PM, Vaibhav Jain  wrote:
>>
>>> On Thu, Oct 6, 2011 at 9:42 PM, rohan puri wrote:
>>>
>>>>
>>>>
>>>> On Fri, Oct 7, 2011 at 4:13 AM, Vaibhav Jain wrote:
>>>>
>>>>>
>>>>>
>>>>> On Thu, Oct 6, 2011 at 11:28 AM, Mulyadi Santosa <
>>>>> mulyadi.sant...@gmail.com> wrote:
>>>>>
>>>>>> Hi...
>>>>>>
>>>>>> On Thu, Oct 6, 2011 at 02:34, Vaibhav Jain 
>>>>>> wrote:
>>>>>> > Hi,
>>>>>> >
>>>>>> > I am trying to run a program that scans memory from a given physical
>>>>>> address
>>>>>> > using /dev/mem.
>>>>>> > It uses mmap to map physical address from /dev/mem. So to start with
>>>>>> I used
>>>>>> > /proc/iomem to look up the
>>>>>> > physical memory mapping and found the address 0001 to be the
>>>>>> starting
>>>>>> > address for System ram. But whenever I
>>>>>> > provide this address to the program it throws an error of "Operation
>>>>>> not
>>>>>> > permitted".
>>>>>>
>>>>>> Probably this could also due to mmap NULL dereferencing protection (at
>>>>>> least that's how I name it :) )
>>>>>>
>>>>>> By default, the lowest 65536 byte (1 in hex) is protected from
>>>>>> mapping etc. It practically render such null dererefencing useless.
>>>>>>
>>>>>>
>>>>>> --
>>>>>> regards,
>>>>>>
>>>>>> Mulyadi Santosa
>>>>>> Freelance Linux trainer and consultant
>>>>>>
>>>>>> blog: the-hydra.blogspot.com
>>>>>> training: mulyaditraining.blogspot.com
>>>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I tried the same with other addresses (greater than 0x1 ) also but
>>>>> it is throwing the same error.
>>>>> Is there a way to get over this ?
>>>>>
>>>>> Thanks
>>>>> Vaibhav Jain
>>>>>
>>>>>
>>>>>
>>>>> ___
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies@kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>> Hi Vaibhav,
>>>>
>>>> This is how it can be done. Refer link
>>>> http://www.theknotter.net/system-memory-dumps-on-linux/
>>>>
>>>> I have attached the modified code which disables the socket creation
>>>> part and dumps the output in a file.
>>>>
>>>> Regards,
>>>> Rohan Puri
>>>>
>>>
>>>
>>> Thanks Rohan for the code but I already have a code that reads memory
>>> using /dev/mem and mmap.
>>> Only difference is I have to manually change the starting address in
>>> program. The problem is whenver I give
>>> any System RAM address the mmap call fails with 'Operation not
>>> permitted'. I googled a little and found that normally
>>> this operation is not allowed and the kernel has to be compiled with
>>> CONFIG_STRICT_DEVMEM disabled to read any memory
>>> location in this way. I also found out about the boot option
>>> 'strict-devmem =0'. I tried both these options but none of them seems to
>>> working.
>>> So I am trying to figure out if there is some other setting that I need
>>> to change.
>>> I am doing this on Fedora 15 - 2.6.38 kernel.
>>>
>>> Thanks
>>> Vaibhav Jain
>>>
>>>
>> Hi Vaibhav,
>>
>> My iomem file : -
>>
>> - : reserved
>> *0001-0009f3ff : System RAM*
>> 0009f400-0009 : reserved
>> 000c-000c7fff : Video ROM
>> 000cc000-000ccfff : Adapter ROM
>> 000cd000-000c : pnp 00:0c
>> 000e-000e : pnp 00:0c
>> 000f-000f : reserved
>>   000f-000f : System ROM
>> *0010-cf6d : System RAM*
>>   0100-015dadf2 : Kernel code
>>   015dadf3-01ab907f : Kernel data
>>   01bb1000-01d04fff : Kernel bss
>>
>> Now the program which i sent you, with that I am able to read the 1st part
>> of System RAM successfully. I am getting the operation not permitted error
>> from mmap  for second part of System RAM. Can you verify the same on your
>> system. I mean are you able to read the 1st part (if your System RAM is
>> divided) or not ?
>>
>> Regards,
>> Rohan Puri
>>
>
> Another way to get the memory map is install crash module on your system
> and access the memory by accessing the new device /dev/crash instead of
> /dev/mem
>
> Regards,
> Rohan Puri
>

Even I tried after disabling the option CONFIG_STRICT_DEVMEM, but still
cannot access the 2nd part of System RAM. Also my linux is for x86_64 arch,
hence maybe I am able to access the 1st part of System RAM though that is
above 1 MB.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: problem mapping physical address from /dev/mem

2011-10-07 Thread rohan puri
On Fri, Oct 7, 2011 at 3:29 PM, rohan puri  wrote:

>
>
> On Fri, Oct 7, 2011 at 12:41 PM, Vaibhav Jain  wrote:
>
>> On Thu, Oct 6, 2011 at 9:42 PM, rohan puri wrote:
>>
>>>
>>>
>>> On Fri, Oct 7, 2011 at 4:13 AM, Vaibhav Jain  wrote:
>>>
>>>>
>>>>
>>>> On Thu, Oct 6, 2011 at 11:28 AM, Mulyadi Santosa <
>>>> mulyadi.sant...@gmail.com> wrote:
>>>>
>>>>> Hi...
>>>>>
>>>>> On Thu, Oct 6, 2011 at 02:34, Vaibhav Jain  wrote:
>>>>> > Hi,
>>>>> >
>>>>> > I am trying to run a program that scans memory from a given physical
>>>>> address
>>>>> > using /dev/mem.
>>>>> > It uses mmap to map physical address from /dev/mem. So to start with
>>>>> I used
>>>>> > /proc/iomem to look up the
>>>>> > physical memory mapping and found the address 0001 to be the
>>>>> starting
>>>>> > address for System ram. But whenever I
>>>>> > provide this address to the program it throws an error of "Operation
>>>>> not
>>>>> > permitted".
>>>>>
>>>>> Probably this could also due to mmap NULL dereferencing protection (at
>>>>> least that's how I name it :) )
>>>>>
>>>>> By default, the lowest 65536 byte (1 in hex) is protected from
>>>>> mapping etc. It practically render such null dererefencing useless.
>>>>>
>>>>>
>>>>> --
>>>>> regards,
>>>>>
>>>>> Mulyadi Santosa
>>>>> Freelance Linux trainer and consultant
>>>>>
>>>>> blog: the-hydra.blogspot.com
>>>>> training: mulyaditraining.blogspot.com
>>>>>
>>>>
>>>> Hi,
>>>>
>>>> I tried the same with other addresses (greater than 0x1 ) also but
>>>> it is throwing the same error.
>>>> Is there a way to get over this ?
>>>>
>>>> Thanks
>>>> Vaibhav Jain
>>>>
>>>>
>>>>
>>>> ___
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies@kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>> Hi Vaibhav,
>>>
>>> This is how it can be done. Refer link
>>> http://www.theknotter.net/system-memory-dumps-on-linux/
>>>
>>> I have attached the modified code which disables the socket creation part
>>> and dumps the output in a file.
>>>
>>> Regards,
>>> Rohan Puri
>>>
>>
>>
>> Thanks Rohan for the code but I already have a code that reads memory
>> using /dev/mem and mmap.
>> Only difference is I have to manually change the starting address in
>> program. The problem is whenver I give
>> any System RAM address the mmap call fails with 'Operation not permitted'.
>> I googled a little and found that normally
>> this operation is not allowed and the kernel has to be compiled with
>> CONFIG_STRICT_DEVMEM disabled to read any memory
>> location in this way. I also found out about the boot option
>> 'strict-devmem =0'. I tried both these options but none of them seems to
>> working.
>> So I am trying to figure out if there is some other setting that I need to
>> change.
>> I am doing this on Fedora 15 - 2.6.38 kernel.
>>
>> Thanks
>> Vaibhav Jain
>>
>>
> Hi Vaibhav,
>
> My iomem file : -
>
> - : reserved
> *0001-0009f3ff : System RAM*
> 0009f400-0009 : reserved
> 000c-000c7fff : Video ROM
> 000cc000-000ccfff : Adapter ROM
> 000cd000-000c : pnp 00:0c
> 000e-000e : pnp 00:0c
> 000f-000f : reserved
>   000f-000f : System ROM
> *0010-cf6d : System RAM*
>   0100-015dadf2 : Kernel code
>   015dadf3-01ab907f : Kernel data
>   01bb1000-01d04fff : Kernel bss
>
> Now the program which i sent you, with that I am able to read the 1st part
> of System RAM successfully. I am getting the operation not permitted error
> from mmap  for second part of System RAM. Can you verify the same on your
> system. I mean are you able to read the 1st part (if your System RAM is
> divided) or not ?
>
> Regards,
> Rohan Puri
>

Another way to get the memory map is install crash module on your system and
access the memory by accessing the new device /dev/crash instead of /dev/mem

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: problem mapping physical address from /dev/mem

2011-10-07 Thread rohan puri
On Fri, Oct 7, 2011 at 12:41 PM, Vaibhav Jain  wrote:

> On Thu, Oct 6, 2011 at 9:42 PM, rohan puri  wrote:
>
>>
>>
>> On Fri, Oct 7, 2011 at 4:13 AM, Vaibhav Jain  wrote:
>>
>>>
>>>
>>> On Thu, Oct 6, 2011 at 11:28 AM, Mulyadi Santosa <
>>> mulyadi.sant...@gmail.com> wrote:
>>>
>>>> Hi...
>>>>
>>>> On Thu, Oct 6, 2011 at 02:34, Vaibhav Jain  wrote:
>>>> > Hi,
>>>> >
>>>> > I am trying to run a program that scans memory from a given physical
>>>> address
>>>> > using /dev/mem.
>>>> > It uses mmap to map physical address from /dev/mem. So to start with I
>>>> used
>>>> > /proc/iomem to look up the
>>>> > physical memory mapping and found the address 0001 to be the
>>>> starting
>>>> > address for System ram. But whenever I
>>>> > provide this address to the program it throws an error of "Operation
>>>> not
>>>> > permitted".
>>>>
>>>> Probably this could also due to mmap NULL dereferencing protection (at
>>>> least that's how I name it :) )
>>>>
>>>> By default, the lowest 65536 byte (1 in hex) is protected from
>>>> mapping etc. It practically render such null dererefencing useless.
>>>>
>>>>
>>>> --
>>>> regards,
>>>>
>>>> Mulyadi Santosa
>>>> Freelance Linux trainer and consultant
>>>>
>>>> blog: the-hydra.blogspot.com
>>>> training: mulyaditraining.blogspot.com
>>>>
>>>
>>> Hi,
>>>
>>> I tried the same with other addresses (greater than 0x1 ) also but it
>>> is throwing the same error.
>>> Is there a way to get over this ?
>>>
>>> Thanks
>>> Vaibhav Jain
>>>
>>>
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> Hi Vaibhav,
>>
>> This is how it can be done. Refer link
>> http://www.theknotter.net/system-memory-dumps-on-linux/
>>
>> I have attached the modified code which disables the socket creation part
>> and dumps the output in a file.
>>
>> Regards,
>> Rohan Puri
>>
>
>
> Thanks Rohan for the code but I already have a code that reads memory using
> /dev/mem and mmap.
> Only difference is I have to manually change the starting address in
> program. The problem is whenver I give
> any System RAM address the mmap call fails with 'Operation not permitted'.
> I googled a little and found that normally
> this operation is not allowed and the kernel has to be compiled with
> CONFIG_STRICT_DEVMEM disabled to read any memory
> location in this way. I also found out about the boot option 'strict-devmem
> =0'. I tried both these options but none of them seems to working.
> So I am trying to figure out if there is some other setting that I need to
> change.
> I am doing this on Fedora 15 - 2.6.38 kernel.
>
> Thanks
> Vaibhav Jain
>
>
Hi Vaibhav,

My iomem file : -

- : reserved
*0001-0009f3ff : System RAM*
0009f400-0009 : reserved
000c-000c7fff : Video ROM
000cc000-000ccfff : Adapter ROM
000cd000-000c : pnp 00:0c
000e-000e : pnp 00:0c
000f-000f : reserved
  000f-000f : System ROM
*0010-cf6d : System RAM*
  0100-015dadf2 : Kernel code
  015dadf3-01ab907f : Kernel data
  01bb1000-01d04fff : Kernel bss

Now the program which i sent you, with that I am able to read the 1st part
of System RAM successfully. I am getting the operation not permitted error
from mmap  for second part of System RAM. Can you verify the same on your
system. I mean are you able to read the 1st part (if your System RAM is
divided) or not ?

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: problem mapping physical address from /dev/mem

2011-10-06 Thread rohan puri
On Fri, Oct 7, 2011 at 4:13 AM, Vaibhav Jain  wrote:

>
>
> On Thu, Oct 6, 2011 at 11:28 AM, Mulyadi Santosa <
> mulyadi.sant...@gmail.com> wrote:
>
>> Hi...
>>
>> On Thu, Oct 6, 2011 at 02:34, Vaibhav Jain  wrote:
>> > Hi,
>> >
>> > I am trying to run a program that scans memory from a given physical
>> address
>> > using /dev/mem.
>> > It uses mmap to map physical address from /dev/mem. So to start with I
>> used
>> > /proc/iomem to look up the
>> > physical memory mapping and found the address 0001 to be the
>> starting
>> > address for System ram. But whenever I
>> > provide this address to the program it throws an error of "Operation not
>> > permitted".
>>
>> Probably this could also due to mmap NULL dereferencing protection (at
>> least that's how I name it :) )
>>
>> By default, the lowest 65536 byte (1 in hex) is protected from
>> mapping etc. It practically render such null dererefencing useless.
>>
>>
>> --
>> regards,
>>
>> Mulyadi Santosa
>> Freelance Linux trainer and consultant
>>
>> blog: the-hydra.blogspot.com
>> training: mulyaditraining.blogspot.com
>>
>
> Hi,
>
> I tried the same with other addresses (greater than 0x1 ) also but it
> is throwing the same error.
> Is there a way to get over this ?
>
> Thanks
> Vaibhav Jain
>
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Vaibhav,

This is how it can be done. Refer link
http://www.theknotter.net/system-memory-dumps-on-linux/

I have attached the modified code which disables the socket creation part
and dumps the output in a file.

Regards,
Rohan Puri
/* 
 * Copyright (c) 2010, digital 
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#define _GNU_SOURCE 1

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define MEM_FILE "/dev/mem"
#define IOM_FILE "/proc/iomem"

int main(/*int argc, char *argv[]*/)
{
	FILE *map_file;
	int mem_fd, sock;
	long unsigned int r0, r1;
	long unsigned int count;
	long unsigned int chunk;
	char *ptr, *mem;
	size_t n;
	int rohan;
//	struct sockaddr_in addr;

/*	if (argc != 3) {
		printf("USAGE: %s  \n", argv[0]);
		return -1;		
	}
*/
	if (!(map_file = fopen(IOM_FILE, "r"))) {
		perror("fopen");
		return -1;
	}

	if ((mem_fd = open(MEM_FILE, O_RDONLY)) < 0) {
		perror("fopen");
		return -1;
	}
	if ((rohan = open("./rohan.txt", O_WRONLY | O_CREAT)) < 0) {
perror("fopen");
return -1;
}


/*	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
		perror("socket");
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(argv[1]);
	addr.sin_port = htons(atoi(argv[2]));

	if (connect(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
		perror("connect");
		return -1;
	}
*/
	for (ptr = NULL; getline(&ptr, &n, map_file) > 0;) {
		if (ptr[0] == ' ' || !strstr(ptr, "System RAM"))
			continue;

		if (sscanf(ptr, "%lx-%lx", &r0, &r1) != 2) {

			return -1;
		}

		if (r1 % 4096)
			r1 = (r1 - (r1 % 4096)) + 4096;

		count = r1 - r0;

		for (ch

Re: Current and correct CPU clock and asm("cpuid")

2011-10-03 Thread rohan puri
On Tue, Oct 4, 2011 at 12:03 AM, Peter Senna Tschudin  wrote:

> Hi Rohan.
>
> It is really good reference. Thanks!
>
> Peter
>
> On Mon, Oct 3, 2011 at 1:17 AM, rohan puri  wrote:
> >
> >
> > On Mon, Oct 3, 2011 at 6:57 AM, Peter Senna Tschudin <
> peter.se...@gmail.com>
> > wrote:
> >>
> >> Dear list members,
> >>
> >> I'm following:
> >>
> >> http://people.virginia.edu/~chg5w/page3/assets/MeasuringUnix.pdf
> >>
> >> And I'm trying to measure executing time of simple operations with
> RDTSC.
> >>
> >> See the code below:
> >>
> >> #include 
> >> #define CPU_THOUSAND_HZ 80
> >> typedef unsigned long long ticks;
> >> static __inline__ ticks getticks(void) {
> >>unsigned a, d;
> >>asm("cpuid");
> >>asm volatile("rdtsc" : "=a" (a), "=d" (d));
> >>return (((ticks)a) | (((ticks)d) << 32));
> >> }
> >>
> >> void main() {
> >>ticks tickBegin, tickEnd;
> >>tickBegin = getticks();
> >>
> >>// code to time
> >>
> >>tickEnd = getticks();
> >>double time = (tickEnd-tickBegin)/CPU_THOUSAND_HZ;
> >>
> >>printf ("%Le\n", time);
> >> }
> >>
> >> How can the C code detects the correct value for CPU_THOUSAND_HZ? The
> >> problems I see are:
> >>  - It is needed to collect the information for the CPU that will run
> >> the process. On Core i7 processors, different cores can run at
> >> different clock speed at same time.
> >>  - If the clock changes during the execution of process, what should
> >> it do? When is the best time for collecting the clock speed?
> >>
> >> The authors of the paper are not sure about the effects of
> >> "asm("cpuid");" Does it ensure that the entire process will run on the
> >> same CPU, and will serialize it avoiding out of order execution by the
> >> CPU?
> >>
> >> Thank you very much! :-)
> >>
> >> Peter
> >>
> >>
> >> --
> >> Peter Senna Tschudin
> >> peter.se...@gmail.com
> >> gpg id: 48274C36
> >>
> >> ___
> >> Kernelnewbies mailing list
> >> Kernelnewbies@kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> > Hi Peter,
> >
> > Excellent reference http://en.wikipedia.org/wiki/Time_Stamp_Counter
> >
> > Also, your interpretation is right. There are lots of things which need
> to
> > be considered instead of setting CPU_THOUSAND_HZ to any particular value,
> > some of them are whether its multi-core or single core CPU. On multi-core
> > its quite difficult to get the correct answers, The problems are
> mentioned
> > in the above wiki link.
> >
> > Regards,
> > Rohan Puri
> >
>
>
>
> --
> Peter Senna Tschudin
> peter.se...@gmail.com
> gpg id: 48274C36
>

Welcome :)

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Current and correct CPU clock and asm("cpuid")

2011-10-02 Thread rohan puri
On Mon, Oct 3, 2011 at 6:57 AM, Peter Senna Tschudin
wrote:

> Dear list members,
>
> I'm following:
>
> http://people.virginia.edu/~chg5w/page3/assets/MeasuringUnix.pdf
>
> And I'm trying to measure executing time of simple operations with RDTSC.
>
> See the code below:
>
> #include 
> #define CPU_THOUSAND_HZ 80
> typedef unsigned long long ticks;
> static __inline__ ticks getticks(void) {
>unsigned a, d;
>asm("cpuid");
>asm volatile("rdtsc" : "=a" (a), "=d" (d));
>return (((ticks)a) | (((ticks)d) << 32));
> }
>
> void main() {
>ticks tickBegin, tickEnd;
>tickBegin = getticks();
>
>// code to time
>
>tickEnd = getticks();
>double time = (tickEnd-tickBegin)/CPU_THOUSAND_HZ;
>
>printf ("%Le\n", time);
> }
>
> How can the C code detects the correct value for CPU_THOUSAND_HZ? The
> problems I see are:
>  - It is needed to collect the information for the CPU that will run
> the process. On Core i7 processors, different cores can run at
> different clock speed at same time.
>  - If the clock changes during the execution of process, what should
> it do? When is the best time for collecting the clock speed?
>
> The authors of the paper are not sure about the effects of
> "asm("cpuid");" Does it ensure that the entire process will run on the
> same CPU, and will serialize it avoiding out of order execution by the
> CPU?
>
> Thank you very much! :-)
>
> Peter
>
>
> --
> Peter Senna Tschudin
> peter.se...@gmail.com
> gpg id: 48274C36
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
Hi Peter,

Excellent reference http://en.wikipedia.org/wiki/Time_Stamp_Counter

Also, your interpretation is right. There are lots of things which need to
be considered instead of setting CPU_THOUSAND_HZ to any particular value,
some of them are whether its multi-core or single core CPU. On multi-core
its quite difficult to get the correct answers, The problems are mentioned
in the above wiki link.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: What is "__attribute__()" in kernel code

2011-09-30 Thread rohan puri
On Fri, Sep 30, 2011 at 3:53 PM, anish singh wrote:

> On Fri, Sep 30, 2011 at 3:28 PM, sandeep kumar
>  wrote:
> > Hi all,
> >
> > I was wondering what __attribute__ does in the kernel code?
> > I found several definitions but couldnot come to one conclusion..
> >
> > __releases(x)  is defined in compiler.h. What does this mean??
> > # define __releases(x)  __attribute__((context(x,1,0)))
> GCC directive ?
> > Thanking you
> > --
> > With regards,
> > Sandeep Kumar Anantapalli,
> >
> >
> > ___
> > 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
>
Hi Anish,

Refer link http://www.unixwiz.net/techtips/gnu-c-attributes.html

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: regarding disable of CONFIG_DEBUG_FS

2011-09-29 Thread rohan puri
On Fri, Sep 30, 2011 at 11:02 AM, Vladimir Murzin wrote:

> On Tue, Sep 20, 2011 at 8:57 AM, Amit Nagal 
> wrote:
> > On Tue, Sep 20, 2011 at 10:21 AM, rohan puri 
> wrote:
> >>
> >>
> >> On Tue, Sep 20, 2011 at 10:09 AM, Amit Nagal 
> wrote:
> >>>
> >>> Hi ,
> >>>
> >>> i already tried manual editing .
> >>> but when i call make to build image after manual edit ,
> >>> CONFIG_DEBUG_FS is turned on again .
> >>>
> >>> i tried manual editing in linux - x86 PC   also .
> >>> i manually edited arch/x86/configs/i386_defconfig file to disable
> >>> CONFIG_DEBUG_FS ,
> >>> but when i call make to build image , CONFIG_DEBUG_FS is turned on
> again .
> >>> >
> >>
> >> Ok. You can try commenting the CONFIG_DEBUG_FS from the Makefile of the
> >> relevant kernel source which your module is interacting with.
> >>
> >
> > Well  i am doing the same for time being for my testing . but its not
> > the right way to do and can't be adopted .
> >
> > Regards
> > Amit Nagal
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
> Hi!
>
> It's not clear why you can't disable CONFIG_DEBUG_FS via "make
> menuconfig" or stuff like this?
> This option is located under Kernel Haking -> Debuging Filesystems.
> I've attached the diff of .config for this option.
>
> Best wishes,
> Vladimir Murzin
>

Hi Vladimir,

AFAIK, the reason why one cant disable debugfs from make menuconfig and
other similar ways to make changes to config file, is that debugfs is being
used by many kernel code which are in-built in the kernel and not as a
module. Hence i think because of this it is kept tightly coupled with the
kernel.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Prevent a process from opening a file more than once

2011-09-28 Thread rohan puri
On Wed, Sep 28, 2011 at 11:11 AM, Michael Blizek <
mic...@michaelblizek.twilightparadox.com> wrote:

> Hi!
>
> On 21:41 Tue 27 Sep , Venkatram Tummala wrote:
> > On Tue, Sep 27, 2011 at 9:19 PM, rohan puri 
> wrote:
> ...
> > > in device_open() ->
> > >
> > > if(var)
> > >   return -EBUSY
> > > var++
> > >
> > > &
> > >
> > > in device_release() ->
> > >
> > > var--
> > >
> > >
> > > I think this should do the job.
> > >
> > This will prevent other processes to open the file until a process
> releases
> > it. This is not what i need. Only the threads in a process shouldn't be
> able
> > to open the file if it is already opened in the process. Other processes
> > should be able to open it.
>
> You could create something like this:
>
> DEFINE_MUTEX(pidlist_lock);
> LIST_HEAD(pidlist);
>
> struct pidlist_node{
>struct list_head lh;
>pid_t pid;
> }
>
> static struct pidlist_node *get_pin(void)
> {
>struct list_head *curr = pidlist.next;
>while (curr != pidlist) {
>struct struct pidlist_node *pin = container_of(curr, struct
> pidlist_node, lh);
>if (pin->pid == current->pid) {
>
Instead of pid check, AFAIK here tgid comparison should be done. Threads in
a single process may have different pid but same tgid and we want to
restrict access to only one thread in a single process. Right?

>return pin;
>}
>}
>return 0;
> }
>
> int open(void)
> {
>struct pidlist_node *pin;
>
>mutex_lock(&pidlist_lock);
>
>pin = get_pin();
>if (pin != 0) {
>mutex_unlock(&pidlist_lock);
>return -EBUSY;
>}
>
>pin = kmalloc(sizeof(struct pidlist_node), GFP_KERNEL);
>if (pin == 0) {
>mutex_unlock(&pidlist_lock);
>return -ENOMEM;
>}
>
>pin->pid = current->pid;
>list_add(&(pin->lh), &pidlist);
>
>mutex_unlock(&pidlist_lock);
> }
>
> int close(void)
> {
>struct pidlist_node *pin;
>
>mutex_lock(&pidlist_lock);
>
>pin = get_pin();
>if (pin != 0) {
>list_del(&(pin->lh));
>kfree(pin);
>}
>
>mutex_unlock(&pidlist_lock);
> }
>
>-Michi
> --
> programing a layer 3+4 network protocol for mesh networks
> see http://michaelblizek.twilightparadox.com
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Evicting Anonymous pages.

2011-09-27 Thread rohan puri
On Tue, Sep 27, 2011 at 11:56 PM, Prateek Sharma wrote:

> On Tue, Sep 27, 2011 at 11:42 PM, Mulyadi Santosa
>  wrote:
> > Hi :)
> >
> > On Wed, Sep 28, 2011 at 00:14, Prateek Sharma 
> wrote:
> >> Hello everyone,
> >>  I am trying to understand the kernel page frame reclaiming
> >> mechanism, but one thing's bothering me:
> >> How does the kernel 'know' which anonymous pages to evict? In the LRU
> >> scheme,  'referenced/used' information for each page is required
> >> (AFAIK). But anonymous pages can be used by user processes 'at any
> >> time' without the kernel knowing about it.
>
(AFAIK) Anonymous pages do not correspond to any file. It may be part of a
program's data area or stack & is written to the swap area.
When a process tries to access the anonymous pages it notifies the swapper
to get back the swap area in mem. In case of a process which holds the swap
token, swapping of anonymous pages is avoided.

> >
> > Same question hog my mind too so far :)
> >
> > The only satisfying self answer I could deduce is:
> > kernel can't track every access to pages when you do it like e.g mov
> > %ax,8(%esp). What kernel could track is when you access data via
> > wrappers. I forgot which ones, but remember some of them are updating
> > those "referenced" etc flags. Perhaps something like get_pages or
> > alike.
> >
> > --
> > regards,
> >
> > Mulyadi Santosa
> > Freelance Linux trainer and consultant
> >
>
> page_referenced_anon is called for anonymous pages by page_referenced.
> And as far as i could figure out, that uses mmu_notifiers. [calls
> pmdp_clear_flush_young_notify]
>
> Whether every anonymous page access is trapped, or only a few of them,
> i have not yet figured out.
>
> Linux-mm seems to be full of magic!
>
> ___
> 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: Prevent a process from opening a file more than once

2011-09-27 Thread rohan puri
On Wed, Sep 28, 2011 at 10:11 AM, Venkatram Tummala
wrote:

> On Tue, Sep 27, 2011 at 9:19 PM, rohan puri wrote:
>
>>
>>
>> On Wed, Sep 28, 2011 at 6:17 AM, Venkatram Tummala <
>> venkatram...@gmail.com> wrote:
>>
>>> On Tue, Sep 27, 2011 at 5:40 PM, Jeff Haran wrote:
>>>
>>>>
>>>>
>>>> From: kernelnewbies-boun...@kernelnewbies.org
>>>> [mailto:kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Venkatram
>>>> Tummala
>>>> Sent: Tuesday, September 27, 2011 5:31 PM
>>>> To: Mulyadi Santosa
>>>> Cc: kernelnewbies
>>>> Subject: Re: Prevent a process from opening a file more than once
>>>>
>>>> On Tue, Sep 27, 2011 at 5:22 PM, Mulyadi Santosa
>>>>  wrote:
>>>> Hi :)
>>>>
>>>> On Wed, Sep 28, 2011 at 06:56, Venkatram Tummala
>>>>  wrote:
>>>> > Hi All,
>>>> > I have a simple device driver which creates a /dev/XYZ file. I need to
>>>> > prevent a process from opening the file more than once. However,
>>>> multiple
>>>> > processes can open the file simultaneously. Is there any any elegant
>>>> way to
>>>> > do this other than checking all opened files in the process ?
>>>> Uhm, keep a reference count and increment it on every file open in
>>>> your module? How does that sound?
>>>> Well, which refcount should i use? I can't use the refcount in the file
>>>> object as the file objects passed to me are different each time the file
>>>> is opened in the process.
>>>>
>>>> When you say "I need to prevent a process from opening the file more
>>>> than once.", do you mean a single process opening the file, closing it
>>>> and then opening it again would be disallowed?
>>>
>>> No. If the file is already opened in the process, the process shouldn't
>>>  be allowed to open the file again. It is fine if the process opens, closes
>>> & then opens the file again.
>>>
>>>> Or do you mean that a
>>>> single process opening the file, keeping it open and then opening it
>>>> again under another fd would be disallowed?
>>>>
>>> Yes, this is what i am looking for.
>>>
>>>>
>>>> How about multiple threads within the same process? Are they treated as
>>>> the same process by these rules?
>>>>
>>> Yes. Threads are treated as the same process. So, if one thread has the
>>> file already opened, another thread in the same process shouldn't be able to
>>> open it.
>>>
>>> Venkat
>>>
>>>
>>> _______
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> Hi Venkatram,
>>
>> I agree with Mulyadi, you maintain a static global variable (int),
>>
>> in device_open() ->
>>
>> if(var)
>>   return -EBUSY
>> var++
>>
>> &
>>
>> in device_release() ->
>>
>> var--
>>
>>
>> I think this should do the job.
>>
> This will prevent other processes to open the file until a process releases
> it. This is not what i need. Only the threads in a process shouldn't be able
> to open the file if it is already opened in the process. Other processes
> should be able to open it.
>
> Venkat
>
>>
>> Regards,
>> Rohan Puri
>>
>
> Hi Venkat,

If you want only threads in a process should not be able to open the file,
heres an untidy solution :-


1. in open store the tgid in a hash table ( or any other data structure),

if (storing sucessful) -> do the opening.
else if(storing op return -EEXISTS) -> return -EBUSY

2. in release remove the tgid entry from the hash.


Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Prevent a process from opening a file more than once

2011-09-27 Thread rohan puri
On Wed, Sep 28, 2011 at 6:17 AM, Venkatram Tummala
wrote:

> On Tue, Sep 27, 2011 at 5:40 PM, Jeff Haran  wrote:
>
>>
>>
>> From: kernelnewbies-boun...@kernelnewbies.org
>> [mailto:kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Venkatram
>> Tummala
>> Sent: Tuesday, September 27, 2011 5:31 PM
>> To: Mulyadi Santosa
>> Cc: kernelnewbies
>> Subject: Re: Prevent a process from opening a file more than once
>>
>> On Tue, Sep 27, 2011 at 5:22 PM, Mulyadi Santosa
>>  wrote:
>> Hi :)
>>
>> On Wed, Sep 28, 2011 at 06:56, Venkatram Tummala
>>  wrote:
>> > Hi All,
>> > I have a simple device driver which creates a /dev/XYZ file. I need to
>> > prevent a process from opening the file more than once. However,
>> multiple
>> > processes can open the file simultaneously. Is there any any elegant
>> way to
>> > do this other than checking all opened files in the process ?
>> Uhm, keep a reference count and increment it on every file open in
>> your module? How does that sound?
>> Well, which refcount should i use? I can't use the refcount in the file
>> object as the file objects passed to me are different each time the file
>> is opened in the process.
>>
>> When you say "I need to prevent a process from opening the file more
>> than once.", do you mean a single process opening the file, closing it
>> and then opening it again would be disallowed?
>
> No. If the file is already opened in the process, the process shouldn't  be
> allowed to open the file again. It is fine if the process opens, closes &
> then opens the file again.
>
>> Or do you mean that a
>> single process opening the file, keeping it open and then opening it
>> again under another fd would be disallowed?
>>
> Yes, this is what i am looking for.
>
>>
>> How about multiple threads within the same process? Are they treated as
>> the same process by these rules?
>>
> Yes. Threads are treated as the same process. So, if one thread has the
> file already opened, another thread in the same process shouldn't be able to
> open it.
>
> Venkat
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Hi Venkatram,

I agree with Mulyadi, you maintain a static global variable (int),

in device_open() ->

if(var)
  return -EBUSY
var++

&

in device_release() ->

var--


I think this should do the job.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Hooking exec system call

2011-09-26 Thread rohan puri
On Mon, Sep 26, 2011 at 1:00 PM, Abhijit Pawar wrote:

>  On 09/26/2011 12:57 PM, rohan puri wrote:
>
>
>
> On Mon, Sep 26, 2011 at 12:29 PM, Abhijit Pawar wrote:
>
>>   On 09/26/2011 12:26 PM, rohan puri wrote:
>>
>>
>>
>> On Mon, Sep 26, 2011 at 12:02 PM, Abhijit Pawar 
>> wrote:
>>
>>>   On 09/23/2011 03:11 PM, rohan puri wrote:
>>>
>>>
>>>
>>> On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar 
>>> wrote:
>>>
>>>>   On 09/23/2011 02:04 PM, rohan puri wrote:
>>>>
>>>>
>>>>
>>>> On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar 
>>>> wrote:
>>>>
>>>>>  On 09/23/2011 01:01 PM, Rajat Sharma wrote:
>>>>>
>>>>>>  Untidy way : -
>>>>>>> Yes, you can do that by registering a new binary format handler.
>>>>>>> Whenever
>>>>>>> exec is called, a list of registered binary format handlers is
>>>>>>> scanned, in
>>>>>>> the same way you can hook the load_binary&  load_library function
>>>>>>> pointers
>>>>>>> of the already registered binary format handlers.
>>>>>>>
>>>>>> Challenge with this untidy way is to identify the correct format, for
>>>>>> example if you are interested in only hooking ELF format, there is no
>>>>>> special signature withing the registered format handler to identify
>>>>>> that, however if one format handler recognizes the file header, its
>>>>>> load_binary will return 0. This can give you the hint that you are
>>>>>> sitting on top of correct file format. Long time back I had written
>>>>>> the similar module in Linux to do the same, but can't share the code
>>>>>> :)
>>>>>>
>>>>>> -Rajat
>>>>>>
>>>>>> On Thu, Sep 22, 2011 at 3:14 PM, rohan puri
>>>>>>  wrote:
>>>>>>
>>>>>>>
>>>>>>> On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawar<
>>>>>>> apawar.li...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> hi list,
>>>>>>>> Is there any way to hook the exec system call on Linux box apart
>>>>>>>> from
>>>>>>>> replacing the call in System Call table?
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Abhijit Pawar
>>>>>>>>
>>>>>>>> ___
>>>>>>>> Kernelnewbies mailing list
>>>>>>>> Kernelnewbies@kernelnewbies.org
>>>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>>>>
>>>>>>> Tidy way : -
>>>>>>>
>>>>>>> You can do that from LSM (Linux security module).
>>>>>>>
>>>>>>> Untidy way : -
>>>>>>> Yes, you can do that by registering a new binary format handler.
>>>>>>> Whenever
>>>>>>> exec is called, a list of registered binary format handlers is
>>>>>>> scanned, in
>>>>>>> the same way you can hook the load_binary&  load_library function
>>>>>>> pointers
>>>>>>> of the already registered binary format handlers.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Rohan Puri
>>>>>>>
>>>>>>> ___
>>>>>>> Kernelnewbies mailing list
>>>>>>> Kernelnewbies@kernelnewbies.org
>>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>>>
>>>>>>>
>>>>>>>   So If I use the binary format handler, then I can hook the exec
>>>>> call. however I need to register this. Does that mean that I need to 
>>>>> return
>>>>> the negative value so as to have actual ELF handler to be loaded?
>>>>>
>>>>> Regards,
>>>>>  Abhijit Pawar
>>>>>
>>>>>  Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html this
>>>> might help
>>>>
>>&

Re: Hooking exec system call

2011-09-26 Thread rohan puri
On Mon, Sep 26, 2011 at 12:29 PM, Abhijit Pawar wrote:

>  On 09/26/2011 12:26 PM, rohan puri wrote:
>
>
>
> On Mon, Sep 26, 2011 at 12:02 PM, Abhijit Pawar wrote:
>
>>   On 09/23/2011 03:11 PM, rohan puri wrote:
>>
>>
>>
>> On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar wrote:
>>
>>>   On 09/23/2011 02:04 PM, rohan puri wrote:
>>>
>>>
>>>
>>> On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar 
>>> wrote:
>>>
>>>>  On 09/23/2011 01:01 PM, Rajat Sharma wrote:
>>>>
>>>>>  Untidy way : -
>>>>>> Yes, you can do that by registering a new binary format handler.
>>>>>> Whenever
>>>>>> exec is called, a list of registered binary format handlers is
>>>>>> scanned, in
>>>>>> the same way you can hook the load_binary&  load_library function
>>>>>> pointers
>>>>>> of the already registered binary format handlers.
>>>>>>
>>>>> Challenge with this untidy way is to identify the correct format, for
>>>>> example if you are interested in only hooking ELF format, there is no
>>>>> special signature withing the registered format handler to identify
>>>>> that, however if one format handler recognizes the file header, its
>>>>> load_binary will return 0. This can give you the hint that you are
>>>>> sitting on top of correct file format. Long time back I had written
>>>>> the similar module in Linux to do the same, but can't share the code
>>>>> :)
>>>>>
>>>>> -Rajat
>>>>>
>>>>> On Thu, Sep 22, 2011 at 3:14 PM, rohan puri
>>>>>  wrote:
>>>>>
>>>>>>
>>>>>> On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawar>>>>> >
>>>>>> wrote:
>>>>>>
>>>>>>> hi list,
>>>>>>> Is there any way to hook the exec system call on Linux box apart from
>>>>>>> replacing the call in System Call table?
>>>>>>>
>>>>>>> Regards,
>>>>>>> Abhijit Pawar
>>>>>>>
>>>>>>> ___
>>>>>>> Kernelnewbies mailing list
>>>>>>> Kernelnewbies@kernelnewbies.org
>>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>>>
>>>>>> Tidy way : -
>>>>>>
>>>>>> You can do that from LSM (Linux security module).
>>>>>>
>>>>>> Untidy way : -
>>>>>> Yes, you can do that by registering a new binary format handler.
>>>>>> Whenever
>>>>>> exec is called, a list of registered binary format handlers is
>>>>>> scanned, in
>>>>>> the same way you can hook the load_binary&  load_library function
>>>>>> pointers
>>>>>> of the already registered binary format handlers.
>>>>>>
>>>>>> Regards,
>>>>>> Rohan Puri
>>>>>>
>>>>>> ___
>>>>>> Kernelnewbies mailing list
>>>>>> Kernelnewbies@kernelnewbies.org
>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>>
>>>>>>
>>>>>>   So If I use the binary format handler, then I can hook the exec
>>>> call. however I need to register this. Does that mean that I need to return
>>>> the negative value so as to have actual ELF handler to be loaded?
>>>>
>>>> Regards,
>>>>  Abhijit Pawar
>>>>
>>>>  Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html this
>>> might help
>>>
>>> Regards,
>>> Rohan Puri
>>>
>>>  Thanks Rohan. I tried creating a hooking module on the similar line. I
>>> am able to load the module but whenever I am launching any application , its
>>> load_binary is not being called.
>>> here is the source for the module attached.
>>>
>>> Regards,
>>>  Abhijit Pawar
>>>
>>>
>>>
>> Hi Abhijit,
>>
>> I have made the change, try to compile and execute this code, it works.
>>
>> Also, I am just curious enough to know that where d

Re: Hooking exec system call

2011-09-25 Thread rohan puri
On Mon, Sep 26, 2011 at 12:02 PM, Abhijit Pawar wrote:

>  On 09/23/2011 03:11 PM, rohan puri wrote:
>
>
>
> On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar wrote:
>
>>   On 09/23/2011 02:04 PM, rohan puri wrote:
>>
>>
>>
>> On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar wrote:
>>
>>>  On 09/23/2011 01:01 PM, Rajat Sharma wrote:
>>>
>>>>  Untidy way : -
>>>>> Yes, you can do that by registering a new binary format handler.
>>>>> Whenever
>>>>> exec is called, a list of registered binary format handlers is scanned,
>>>>> in
>>>>> the same way you can hook the load_binary&  load_library function
>>>>> pointers
>>>>> of the already registered binary format handlers.
>>>>>
>>>> Challenge with this untidy way is to identify the correct format, for
>>>> example if you are interested in only hooking ELF format, there is no
>>>> special signature withing the registered format handler to identify
>>>> that, however if one format handler recognizes the file header, its
>>>> load_binary will return 0. This can give you the hint that you are
>>>> sitting on top of correct file format. Long time back I had written
>>>> the similar module in Linux to do the same, but can't share the code
>>>> :)
>>>>
>>>> -Rajat
>>>>
>>>> On Thu, Sep 22, 2011 at 3:14 PM, rohan puri
>>>>  wrote:
>>>>
>>>>>
>>>>> On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawar
>>>>> wrote:
>>>>>
>>>>>> hi list,
>>>>>> Is there any way to hook the exec system call on Linux box apart from
>>>>>> replacing the call in System Call table?
>>>>>>
>>>>>> Regards,
>>>>>> Abhijit Pawar
>>>>>>
>>>>>> ___
>>>>>> Kernelnewbies mailing list
>>>>>> Kernelnewbies@kernelnewbies.org
>>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>>
>>>>> Tidy way : -
>>>>>
>>>>> You can do that from LSM (Linux security module).
>>>>>
>>>>> Untidy way : -
>>>>> Yes, you can do that by registering a new binary format handler.
>>>>> Whenever
>>>>> exec is called, a list of registered binary format handlers is scanned,
>>>>> in
>>>>> the same way you can hook the load_binary&  load_library function
>>>>> pointers
>>>>> of the already registered binary format handlers.
>>>>>
>>>>> Regards,
>>>>> Rohan Puri
>>>>>
>>>>> ___
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies@kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>>>
>>>>>   So If I use the binary format handler, then I can hook the exec
>>> call. however I need to register this. Does that mean that I need to return
>>> the negative value so as to have actual ELF handler to be loaded?
>>>
>>> Regards,
>>>  Abhijit Pawar
>>>
>>>  Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html this
>> might help
>>
>> Regards,
>> Rohan Puri
>>
>>  Thanks Rohan. I tried creating a hooking module on the similar line. I
>> am able to load the module but whenever I am launching any application , its
>> load_binary is not being called.
>> here is the source for the module attached.
>>
>> Regards,
>>  Abhijit Pawar
>>
>>
>>
> Hi Abhijit,
>
> I have made the change, try to compile and execute this code, it works.
>
> Also, I am just curious enough to know that where do you need to do this
> hooking.
>
> Regards,
> Rohan Puri
>
> Hi Rohan,
> I have been looking at Windows worlds ability to support DLL Injection and
> API hooking. I was just wondering if this could be something to be done in
> Linux as well.  I am not sure if there is any special use of this module
> apart from learning the binary handler. May be it could be used as a
> security module for your own binary handler.
>
> Regards,
> Abhijit Pawar
>

Hi Abhijit,

I am not familiar with windows. Special use-case of this hacking is for
security companies whitelisting software solutions, where they want to
control execution of only authorized binaries on the system and deny the
execution of others.


Although this approach is untidy, since there is available LSM hooks in
linux kernel which needs to be made use of for doing this.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: download 2.6.11 ver.

2011-09-25 Thread rohan puri
On Mon, Sep 26, 2011 at 12:16 PM, rohan puri  wrote:

>
>
> On Mon, Sep 26, 2011 at 10:01 AM, esmaeil mirzaee <
> esmaeil.deb...@gmail.com> wrote:
>
>> thank you for your reply
>> but when I try git clone
>> https://github.com/torvalds/linux/tree/v2.6.12 i found below error
>> fatal: https://github.com/torvalds/linux/tree/v2.6.12/info/refs not
>> found: did you run git update-server-info on the server?
>>
>> On Sun, Sep 25, 2011 at 11:59 PM, rohan puri 
>> wrote:
>> >
>> >
>> > On Mon, Sep 26, 2011 at 9:17 AM, esmaeil mirzaee <
>> esmaeil.deb...@gmail.com>
>> > wrote:
>> >>
>> >> Hi
>> >> apologize for weak English.
>> >>
>> >> I'm reading the Understand Linux Kernel 3rd edition, according to that
>> >> book for accomplishment understand I need 2.6.11 version of linux. How
>> >> can I download it?
>> >> As you know the kernel.org is under maintain.
>> >>
>> >> --
>> >> Best
>> >> Esmaeil
>> >> https://sites.google.com/site/esmaeilmirzaee
>> >>
>> >> ___
>> >> Kernelnewbies mailing list
>> >> Kernelnewbies@kernelnewbies.org
>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >
>> > Hi,
>> >
>> > You can get it from following link : -
>> >
>> > https://github.com/torvalds/linux/tree/v2.6.12 This is for 2.6.12 as
>> 2.6.11
>> > link is present but not accessible.
>> >
>> > You may use 2.6.12 kernel and can get started.
>> >
>> > Regards,
>> > Rohan Puri
>> >
>>
>>
>>
>> --
>> Best
>> Esmaeil
>> https://sites.google.com/site/esmaeilmirzaee
>>
> Hi,
>
> Its have cloned the repo successfully.
>
> The log s: -
>
> rohan@rohan-HP-dx2700-MT-RC738AV:~/linux-source$ git clone
> https://github.com/torvalds/linux.git
> Cloning into linux...
> remote: Counting objects: 2137969, done.
> remote: Compressing objects: 100% (531113/531113), done.
> remote: Total 2137969 (delta 1768127), reused 1954860 (delta 1586973)
> Receiving objects: 100% (2137969/2137969), 589.33 MiB | 109 KiB/s, done.
> Resolving deltas: 100% (1768127/1768127), done.
>
> Regards,
> Rohan Puri
>

Also,

After doing this clone command run command "git checkout v2.6.12"

and then run git log, you will see in comment it shows linux 2.6.12

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: download 2.6.11 ver.

2011-09-25 Thread rohan puri
On Mon, Sep 26, 2011 at 10:01 AM, esmaeil mirzaee
wrote:

> thank you for your reply
> but when I try git clone
> https://github.com/torvalds/linux/tree/v2.6.12 i found below error
> fatal: https://github.com/torvalds/linux/tree/v2.6.12/info/refs not
> found: did you run git update-server-info on the server?
>
> On Sun, Sep 25, 2011 at 11:59 PM, rohan puri 
> wrote:
> >
> >
> > On Mon, Sep 26, 2011 at 9:17 AM, esmaeil mirzaee <
> esmaeil.deb...@gmail.com>
> > wrote:
> >>
> >> Hi
> >> apologize for weak English.
> >>
> >> I'm reading the Understand Linux Kernel 3rd edition, according to that
> >> book for accomplishment understand I need 2.6.11 version of linux. How
> >> can I download it?
> >> As you know the kernel.org is under maintain.
> >>
> >> --
> >> Best
> >> Esmaeil
> >> https://sites.google.com/site/esmaeilmirzaee
> >>
> >> ___
> >> Kernelnewbies mailing list
> >> Kernelnewbies@kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> > Hi,
> >
> > You can get it from following link : -
> >
> > https://github.com/torvalds/linux/tree/v2.6.12 This is for 2.6.12 as
> 2.6.11
> > link is present but not accessible.
> >
> > You may use 2.6.12 kernel and can get started.
> >
> > Regards,
> > Rohan Puri
> >
>
>
>
> --
> Best
> Esmaeil
> https://sites.google.com/site/esmaeilmirzaee
>
Hi,

Its have cloned the repo successfully.

The log s: -

rohan@rohan-HP-dx2700-MT-RC738AV:~/linux-source$ git clone
https://github.com/torvalds/linux.git
Cloning into linux...
remote: Counting objects: 2137969, done.
remote: Compressing objects: 100% (531113/531113), done.
remote: Total 2137969 (delta 1768127), reused 1954860 (delta 1586973)
Receiving objects: 100% (2137969/2137969), 589.33 MiB | 109 KiB/s, done.
Resolving deltas: 100% (1768127/1768127), done.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: download 2.6.11 ver.

2011-09-25 Thread rohan puri
On Mon, Sep 26, 2011 at 9:17 AM, esmaeil mirzaee
wrote:

> Hi
> apologize for weak English.
>
> I'm reading the Understand Linux Kernel 3rd edition, according to that
> book for accomplishment understand I need 2.6.11 version of linux. How
> can I download it?
> As you know the kernel.org is under maintain.
>
> --
> Best
> Esmaeil
> https://sites.google.com/site/esmaeilmirzaee
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
Hi,

You can get it from following link : -

https://github.com/torvalds/linux/tree/v2.6.12 This is for 2.6.12 as 2.6.11
link is present but not accessible.

You may use 2.6.12 kernel and can get started.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to traverse or walk, the kernel's page table without mem_map?

2011-09-23 Thread rohan puri
On Fri, Sep 23, 2011 at 2:13 PM, Jeff Donner wrote:

> Hi;
>
>  I have a 4 CPU machine, x86_64, with 8GB of ram, and am using the
> 3.0 kernel. I'm taking a kernel class and one of my assignments is to
> print the address of mem_map and its number of entries and then,
> translate that address to physical and, walk the whole kernel page
> table counting some flags (just to do it). My problem is, that I
> cannot see mem_map from my exercise module, and it's because my kernel
> is .config'd to NEED_MULTIPLE_NODES, and in mm/memory.c:
>
> #ifndef CONFIG_NEED_MULTIPLE_NODES
> /* use the per-pgdat data instead for discontigmem - mbligh */
> unsigned long max_mapnr;
> struct page *mem_map;
>
> EXPORT_SYMBOL(max_mapnr);
> EXPORT_SYMBOL(mem_map);
> #endif
>
> So, with my configuration the kernel isn't letting me see a mem_map.
>
> Now in mm/Kconfig, NEED_MULTIPLE_NODES seems to depend on DISCONTIGMEM
> config NEED_MULTIPLE_NODES
>def_bool y
>depends on DISCONTIGMEM || NUMA
>
> Which may not have anything to do with anything, but I'm leery of
> changing such a deep setting.
>
> I'd like to, if possible,
> a) find out the right way to traverse the global kernel page table (ie
> to complete the task as stated), adapted to how my kernel is now
> -- or --
> b) I have the idea that the lack of mem_map is due to DISCONTIGMEM,
> which may be due to its being an x86_64 machine (my guess). I'd like
> to find out what I need to do to simplify my kernel so that I can just
> walk along mem_map as originally instructed.
>
> I appreciate any ideas;
> Thanks,
> Jeff
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

Hi Jeff,

The global exported symbol mem_map is available only when the memory model
is of type FLATMEM

There are 3 memory models : -

1. FLATMEM. is used in case of UMA
2. DISCONTIGMEM is used in case of NUMA
3. SPARSEMEM is used in case of NUMA

During kernel configuration you can select the type of the memory model, in
processor type and features -> memory model


Try doing this and see, if you are able to access the symbol mem_map.

If CONFIG_NUMA is set, Flat memory model does not makes sense and hence is
not used.

Some conceptual information : -

RAM memory is divided into nodes. Node to processor mapping is one-to-one.
Nodes are maintained using singly linked list.

Node is represented by pg_data_t struct in linux kernel.

Each node is split into 3 zones.(DMA, NORMAL, HIGHMEM) On 64 bit systems,
HIGHMEM zone is not required.

pg_data_t structure contains a member known as "node_mem_map", which is a
ptr to array of page instances used to describe all physical pages of the
node. Includes pages of all the zones in that node.

So, if for NUMA i mean for DISCONTIGMEM, you want to mem_map ptr, then that
would be maintained per node (per processor), so you need to get hold of all
the nodes in the system, in this way you can complete your assigment.

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Hooking exec system call

2011-09-23 Thread rohan puri
On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar wrote:

>  On 09/23/2011 02:04 PM, rohan puri wrote:
>
>
>
> On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar wrote:
>
>>  On 09/23/2011 01:01 PM, Rajat Sharma wrote:
>>
>>>  Untidy way : -
>>>> Yes, you can do that by registering a new binary format handler.
>>>> Whenever
>>>> exec is called, a list of registered binary format handlers is scanned,
>>>> in
>>>> the same way you can hook the load_binary&  load_library function
>>>> pointers
>>>> of the already registered binary format handlers.
>>>>
>>> Challenge with this untidy way is to identify the correct format, for
>>> example if you are interested in only hooking ELF format, there is no
>>> special signature withing the registered format handler to identify
>>> that, however if one format handler recognizes the file header, its
>>> load_binary will return 0. This can give you the hint that you are
>>> sitting on top of correct file format. Long time back I had written
>>> the similar module in Linux to do the same, but can't share the code
>>> :)
>>>
>>> -Rajat
>>>
>>> On Thu, Sep 22, 2011 at 3:14 PM, rohan puri
>>>  wrote:
>>>
>>>>
>>>> On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawar
>>>> wrote:
>>>>
>>>>> hi list,
>>>>> Is there any way to hook the exec system call on Linux box apart from
>>>>> replacing the call in System Call table?
>>>>>
>>>>> Regards,
>>>>> Abhijit Pawar
>>>>>
>>>>> ___
>>>>> Kernelnewbies mailing list
>>>>> Kernelnewbies@kernelnewbies.org
>>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>>
>>>> Tidy way : -
>>>>
>>>> You can do that from LSM (Linux security module).
>>>>
>>>> Untidy way : -
>>>> Yes, you can do that by registering a new binary format handler.
>>>> Whenever
>>>> exec is called, a list of registered binary format handlers is scanned,
>>>> in
>>>> the same way you can hook the load_binary&  load_library function
>>>> pointers
>>>> of the already registered binary format handlers.
>>>>
>>>> Regards,
>>>> Rohan Puri
>>>>
>>>> ___
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies@kernelnewbies.org
>>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>>
>>>>
>>>>   So If I use the binary format handler, then I can hook the exec call.
>> however I need to register this. Does that mean that I need to return the
>> negative value so as to have actual ELF handler to be loaded?
>>
>> Regards,
>>  Abhijit Pawar
>>
>>  Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html this
> might help
>
> Regards,
> Rohan Puri
>
> Thanks Rohan. I tried creating a hooking module on the similar line. I am
> able to load the module but whenever I am launching any application , its
> load_binary is not being called.
> here is the source for the module attached.
>
> Regards,
> Abhijit Pawar
>
>
>
Hi Abhijit,

I have made the change, try to compile and execute this code, it works.

Also, I am just curious enough to know that where do you need to do this
hooking.

Regards,
Rohan Puri
#include 
#include
#include
#include 
#include 


/*The Hooker function*/
static int load_hook(struct linux_binprm *bprm, struct pt_regs *regs)
{
  printk("\nAbhijit::The file execution hooked");
  
  printk("\nAbhijit::The file being launched is : %s", bprm->filename);
   /*return search_binary_handler(bprm,regs);*/
  return -ENOEXEC;
  
}

int hook_shlib(int fd)
{
  printk("\nAbhijit::hooking shared lib ");
  return -1;
};
  
int hook_core_dump(long signr, struct pt_regs * regs)
{
  printk("\nAbhijit::hooking core dump");
  return -1;
}

/*The structure to override the hook*/

struct linux_binfmt hook_format = {
  .module = THIS_MODULE,
  .load_binary = load_hook,
  .load_shlib = hook_shlib,
  .core_dump = hook_core_dump,
};

static int __init init_hooking_module(void)
{
  printk("\nAbhijit::Registering the hooking module");
  
  int err = 0;
   err = insert_binfmt(&hook_format);
   
   printk("\nAbhijit::The format register returned %d", err);
   
   return err;
}


static void __exit exit_hooking_module(void)
{
  printk("\nAbhijit::unregistering  the hooking module");
  
unregister_binfmt(&hook_format);
 }

module_init(init_hooking_module);
module_exit(exit_hooking_module);

MODULE_AUTHOR("Abhijit Pawar ");
MODULE_DESCRIPTION("A module to hook the application execution");
MODULE_LICENSE("GPL");
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Hooking exec system call

2011-09-23 Thread rohan puri
On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar wrote:

> On 09/23/2011 01:01 PM, Rajat Sharma wrote:
>
>> Untidy way : -
>>> Yes, you can do that by registering a new binary format handler. Whenever
>>> exec is called, a list of registered binary format handlers is scanned,
>>> in
>>> the same way you can hook the load_binary&  load_library function
>>> pointers
>>> of the already registered binary format handlers.
>>>
>> Challenge with this untidy way is to identify the correct format, for
>> example if you are interested in only hooking ELF format, there is no
>> special signature withing the registered format handler to identify
>> that, however if one format handler recognizes the file header, its
>> load_binary will return 0. This can give you the hint that you are
>> sitting on top of correct file format. Long time back I had written
>> the similar module in Linux to do the same, but can't share the code
>> :)
>>
>> -Rajat
>>
>> On Thu, Sep 22, 2011 at 3:14 PM, rohan puri
>>  wrote:
>>
>>>
>>> On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawar
>>> wrote:
>>>
>>>> hi list,
>>>> Is there any way to hook the exec system call on Linux box apart from
>>>> replacing the call in System Call table?
>>>>
>>>> Regards,
>>>> Abhijit Pawar
>>>>
>>>> __**_
>>>> Kernelnewbies mailing list
>>>> Kernelnewbies@kernelnewbies.**org 
>>>> http://lists.kernelnewbies.**org/mailman/listinfo/**kernelnewbies<http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies>
>>>>
>>> Tidy way : -
>>>
>>> You can do that from LSM (Linux security module).
>>>
>>> Untidy way : -
>>> Yes, you can do that by registering a new binary format handler. Whenever
>>> exec is called, a list of registered binary format handlers is scanned,
>>> in
>>> the same way you can hook the load_binary&  load_library function
>>> pointers
>>> of the already registered binary format handlers.
>>>
>>> Regards,
>>> Rohan Puri
>>>
>>> __**_
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.**org 
>>> http://lists.kernelnewbies.**org/mailman/listinfo/**kernelnewbies<http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies>
>>>
>>>
>>>  So If I use the binary format handler, then I can hook the exec call.
> however I need to register this. Does that mean that I need to return the
> negative value so as to have actual ELF handler to be loaded?
>
> Regards,
> Abhijit Pawar
>
> Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html this might
help

Regards,
Rohan Puri
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


  1   2   >