Re: Can interrupt be missed between interrupt disable/enable window?

2016-03-21 Thread Chetan Nanda
On Mon, Mar 21, 2016 at 12:41 PM, Vishwas Srivastava
 wrote:
> Kernel code heavily uses the spinlock primitives
> spin_lock_irqsave/restore plus local interrupt disabling/ enabling, all
> across the code.
> Is there a possibility that the interrupts might get
> missed in this small window
>
> disable interrupts
> .
> .<<<<<<<<<<<--
> interrupts is trigerred here
>
> enable interrupts
>

As per my understanding, During disable period interrupt delivery to a
local core is disabled.
So, when interrupts are enabled (for that core) again then interrupt
will be delivered to that core .So no interrupt missed.

But if there are multiple interrupt from same source during the
disabled period then core will be interrupted once after interrupts
enabled again, i.e. all interrupt except one are missed by core,

Thanks,
Chetan Nanda

>
> specially when the irq
> affinity has been set to the same core on which the
> above mentioned code (disabling / enabling the irq's)
> runs?
> How the linux deals with this kind of scenario?
>
> ___
> 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: owner not checked in mutex_unlock

2016-03-15 Thread Chetan Nanda
On 15-Mar-2016 7:19 pm, "Cihangir Akturk"  wrote:
>
> On Thu, Mar 10, 2016 at 02:59:31PM +0530, Chetan Nanda wrote:
> > Hi,
> >
> > As per book (Linux kernel development)
> >
> > "Whoever locked a mutex must unlock it.That is, you cannot lock a mutex
in one
> > context and then unlock it in another
> > "
> > but 'mutex_unlock' code is not checking the owner field at all.
>
> If you look at the definition of mutex structure in mutex.h:50,
> you'll see that the owner field will be compiled in if one of
> CONFIG_DEBUG_MUTEXES or CONFIG_MUTEX_SPIN_ON_OWNER is defined.
>
> And debug_mutex_unlock function in mutex-debug.c:72 will check
> the owner and emits warning if it finds out that the mutex isn't
> unlocked by its owner.
>
> http://lxr.free-electrons.com/source/include/linux/mutex.h#L50
> http://lxr.free-electrons.com/source/kernel/locking/mutex-debug.c#L72
>
Thanks for your mail, in my kernel CONFIG_MUTEX_SPIN_ON_OWNER is enabled
but CONFIG_DEBUG_MUTEX is not enabled.
So there are no warning messages in logs.

Also,  it don't seems to be a real performance hit by adding a single check
of owner with current in unlock code.
> >
> > Also, I tried with locking the mutex from normal process context and
> > unlocking from separate context (work context) and it is allowed
> > without any error from kernel.
> >
> > Is it the mutex user responsibility to keep track of it? Ideally
> > mutex_unlock should check if owner is same as current?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


owner not checked in mutex_unlock

2016-03-10 Thread Chetan Nanda
Hi,

As per book (Linux kernel development)

"Whoever locked a mutex must unlock it.That is, you cannot lock a mutex in one
context and then unlock it in another
"
but 'mutex_unlock' code is not checking the owner field at all.

Also, I tried with locking the mutex from normal process context and
unlocking from separate context (work context) and it is allowed
without any error from kernel.

Is it the mutex user responsibility to keep track of it? Ideally
mutex_unlock should check if owner is same as current?

Thanks,
Chetan Nanda

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


Videobuf2's vb2_dqbuf return (-EINVAL) error on streamoff

2015-09-09 Thread Chetan Nanda
Hi,

I am working on a V4L2 based video decoder driver,

At user side there are two contexts.
One is queuing/dequeuing buffers from driver (in a separate thread) and
other is the main context, from where I am calling streamon, streamoff.

When I call a streamoff from main context and thread is blocking on dqbuf,
This cause the blocking thread to unblock from dqbuf with an error (EINVAL).

Seems this error coming from videobuf2-core, as streamoff will unblock the
waiting thread, and this thread will go and check (in
function __vb2_wait_for_done_vb) for q->streaming and will return error as
q->streaming will be set to false on streamoff.

Is it the right behavior of vb2_dqbuf to return error when streamoff is
called?

Or is it a right way to have this kind of mechanism i.e.on userside one
thread is queue/dequeue buffers while another is doing streamoff.

Thanks for your help and idea.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: [Off-topic] SCM using git

2015-08-18 Thread Chetan Nanda
On Tue, Aug 18, 2015 at 3:16 PM, amit mehta  wrote:

> Hello All,
>
> This query is not about Linux kernel, but is rather generic query on
> development framework with git. Since, Linux Kernel project is
> significantly large, with astonishing number of people involved and
> large number of branches, I'm assuming that people have faced
> similar situation and your advice and guidance would be of great help
> to me.
>
> I'm currently pursuing Masters program and also working in a small
> tech Startup in the IOT domain. I'm involved in Firmware Development
> on ARM based SOCs and our team comprise three Engineers.
> We use git for SCM. Since we are in a very early phase and have
> very little turnaround time, from the requirement to final integration,
> we do not have a proper review process and hence everyone is allowed
> to commit in the master branch, or create, delete a branch, or a tag
> at will. We also do not have much insight into, how long a feature
> based branch would last. In last couple of months, I've seen some
> stale branches on which the development stopped quite early and
> some very active branch as well. Without much insight and probably
> due to not so well defined process, It is already becoming difficult
> to properly maintain the code consistency, filtering etc across
> several branches. For example, I create a feature remote branch
> (say origin/featureX) on which I continue my development and soon
> I realize that part (There is no way to pick partial commit) or a
> full commit that I recently made for the featureX should also go into
> another branches such as master and say featureY branch as well.
> But since, my colleague has been working on master, I get conflicts
> when I try to cherry-pick (At this moment, I do not want to rebase
> or merge two branches, I only need few of the commits from featureX
> branch to go into master and featureY). I resolve the conflicts and
> life goes on, but problem happens again later in future, if the two
> branches divert too much and a further need for cherry-picking or
> rebasing or merging is required.
>
> The point is that I also believe that it is a very good idea to maintain
> separate branches, based on feature or some other requirements, but
> it is also a n00bs nightmare when the conflicts are very high. There
> are also incidents when somebody forgot to add a particular commit
> to another branch and realized only later, when he was faced with
> debugging a issue and had to go through the git history, to figure
> out the issue. It would be nice, If for example a particular commit
> can be automatically propagated to other branches in this case.
>
> Please pitch in your suggestions, rule of thumb, tools and your way
> of countering such issue with less pain.
>
>
Few suggestions:

1. Better to have a proper review process in place, gerrit is one of the
best tools I have used so far for reviewing,
2. Keep a master branch always compilable (run able) and merge rights
should be only to integrator.
once a feature is developed (on a feature branch) and ready to get into
master, create a new commit for master branch for merging (of course after
validating against the new head)


> Thanks,
> Amit
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel options to boot root over NFS (kernel-4.1.fc22/linux-4.1.3-200.fc22.x86_64)

2015-08-06 Thread Chetan Nanda
On Fri, Aug 7, 2015 at 6:10 AM, Nestor Waldyd  wrote:

> Hello,
>
> I would like to compile a kernel bzImage in order to boot root over NFS. I
> am using the fedora kernel source package
> (kernel-4.1.fc22/linux-4.1.3-200.fc22.x86_64). What kernel options should i
> modify in Kernel Configuration in order to do so? (I have already
> configured both tftp and dhcp server, and PXELINUX)
>
> Best Regards,
>
> Nestor Waldyd
>

AFAIK, NFS client support needs to be selected as built-in during
configuration.
Rest is through kernel command line parameters.

There is a good description in 'Documentation/filesystems/nfs/nfsroot.txt'

___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> ~Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Is there any tool can format source code according to kernel coding rule?

2015-08-02 Thread Chetan Nanda
On Mon, Aug 3, 2015 at 9:05 AM, Nan Xiao  wrote:

> Hi all,
>
> I am just wondering whether there is a script/tool which format source
> code
> according to kernel coding rule automatically? Such as tab, space, brace,
> etc.
>
> Thanks very much in advance!
>

Bit of  googleing give you the lots of suggestion,
One such script is present inside linux tree 'scripts/Lindent'


>
Best Regards
> Nan Xiao
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> ~ Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Data inconsistency observed while performing to-device DMA with spi-nor (m25p80)

2015-07-26 Thread Chetan Nanda
On Sun, Jul 26, 2015 at 5:02 PM, AYAN KUMAR HALDER 
wrote:

> Hi,
>
> I am doing a DMA transfer (to device) using pl330 driver from
> memory(DDR) to device(m25p80, spi- nor). I am sending data in chunks
> of 256 bytes ( m25p80 - writesize) using scatter-gather mechanism.
>
> I see that when I try to write 8K of data, one or the other 256
> bytes(or lesser) are not written or are partially written with 0s.
>
> This problem is observed only when I perform a to-device DMA transfer.
> When I perform a from-device DMA transfer, I am able to read correct
> data.
>
>
There could be multiple issues like
- In buffers allocations, is the buffer used for to-device DMA is
physically contiguous?
- Caching issue, buffer should be un-cacheable.
- Any other programming error.

- Chetan Nanda

Regards,
> Ayan Kumar Halder
>
> ___
> 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: Option CONFIG_DEBUG_SET_MODULE_RONX not working for kernel 3.10

2014-08-17 Thread Chetan Nanda
On Fri, Aug 15, 2014 at 4:19 PM, Paul Bolle  wrote:
> On Thu, 2014-08-14 at 09:38 -0400, Valdis Kletnieks wrote:
>> On Thu, 14 Aug 2014 16:46:22 +0530, Chetan Nanda said:
>> > I am trying to enable 'CONFIG_DEBUG_SET_MODULE_RONX' config option on
>> > 3.10 kernel (for ARM arch) via writing  CONFIG_DEBUG_SET_MODULE_RONX=y
>> > at the end of
>> > board specific config file.
>> >
>> > But .config generated after kernel build do not have this option enabled.
>> >
>> > Do I need to enable any other option also before enabling this one?
>>
>> Go into 'make menuconfig', Enter a '/'.  In the textbox, enter a substring
>> of the symbol (I entered 'MODULE_RONX').
>>
>> At least on x86_64, this shows me:
>>
>>   x Symbol: DEBUG_SET_MODULE_RONX [=y]   
>>x
>>   x Type  : boolean  
>>x
>>   x Prompt: Set loadable kernel module data as NX and text as RO 
>>x
>>   x   Location:  
>>x
>>   x (1) -> Kernel hacking
>>x
>>   x   Defined at arch/x86/Kconfig.debug:112  
>>x
>>   x   Depends on: MODULES [=y]
>>
>> Perhaps it's different on ARM - seems pretty silly to enable MODULE_RONX
>> if your kernel doesn't have CONFIG_MODULES=y in the build.
>
> DEBUG_SET_MODULE_RONX was added for ARM in v3.14:
> $ git grep -nw DEBUG_SET_MODULE_RONX v3.13
> v3.13:arch/s390/Kconfig.debug:32:config DEBUG_SET_MODULE_RONX
> v3.13:arch/x86/Kconfig.debug:103:config DEBUG_SET_MODULE_RONX
> $ git grep -nw DEBUG_SET_MODULE_RONX v3.14
> v3.14:arch/arm/Kconfig.debug:1198:config DEBUG_SET_MODULE_RONX
> v3.14:arch/s390/Kconfig.debug:32:config DEBUG_SET_MODULE_RONX
> v3.14:arch/x86/Kconfig.debug:103:config DEBUG_SET_MODULE_RONX
>
> See commit dca9aa92fc7c ("ARM: add DEBUG_SET_MODULE_RONX option to
> Kconfig"). So using that Kconfig symbol in v3.10 is pointless (for ARM).
>
>> But in general, you should *NOT* simply edit the config file, because
>> that does *not* do any checking of select/depend as you make the change.
>>
>> Then when you actually make the kernel, it *will* re-drive the select/depend
>> logic, and convert the provided .config to a self-consistent form.
>
> And, as Chetan noticed, it will also drop Kconfig symbols that are
> unknown for that build (as, in this case, DEBUG_SET_MODULE_RONX).
>
>> Of course,
>> there is zero guarantee that the self-consistent form corresponds to your
>> intentions
>
Hi Valdis, Paul,

Thanks for your mails.
I would try to backport 'DEBUG_SET_MODULE_RONX' support from v3.14

Thanks,
Chetan Nanda
>
> Paul Bolle
>

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


Option CONFIG_DEBUG_SET_MODULE_RONX not working for kernel 3.10

2014-08-14 Thread Chetan Nanda
Hi,

I am trying to enable 'CONFIG_DEBUG_SET_MODULE_RONX' config option on
3.10 kernel (for ARM arch) via writing  CONFIG_DEBUG_SET_MODULE_RONX=y
at the end of
board specific config file.

But .config generated after kernel build do not have this option enabled.

Do I need to enable any other option also before enabling this one?


Thanks,
Chetan Nanda

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


Re: How to prevent a module from unloading when in used

2014-07-20 Thread Chetan Nanda
On Mon, Jul 21, 2014 at 9:52 AM, Greg KH  wrote:

> On Mon, Jul 21, 2014 at 09:09:02AM +0530, Chetan Nanda wrote:
> > I try to debug the hang when unloading of driver. I am using kernel v3.10
> > and it hangs in 'wait_for_zero_refcount'.
> > I checked that this function has been removed in kernel 3.13.
> > But I am not able to find the patch for this change.
> >
> > Is there an easy way to find the patch which cause removal of wait from
> > module unloading in v3.13.
>
> You have the full git tree, it should be very easy to find, you don't
> need help from me.
>
> Hi Greg,

Thanks for your mail,

I have found a thread with the discussion and a patch for removing the
wait_for_zero_refcount from module unloading, But not able to find this
patch being merged on v3.13. (have checked all patches between 3.12 and
3.13)
http://www.gossamer-threads.com/lists/linux/kernel/1783584?do=post_view_threaded#1783584

Thanks,
Chetan Nanda


> good luck,
>
> greg k-h
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to prevent a module from unloading when in used

2014-07-20 Thread Chetan Nanda
On Fri, Jul 18, 2014 at 11:59 AM, Chetan Nanda 
wrote:

>
>
>
> On Fri, Jul 18, 2014 at 9:47 AM, Greg KH  wrote:
>
>> On Fri, Jul 18, 2014 at 09:43:48AM +0530, Chetan Nanda wrote:
>> >
>> >
>> >
>> > On Wed, Jul 16, 2014 at 9:51 PM, Greg KH  wrote:
>> >
>> > On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:
>> > >
>> > >
>> > >
>> > > On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda <
>> chetanna...@gmail.com>
>> > wrote:
>> > >
>> > >
>> > >
>> > > On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza <
>> j...@jjdev.com>
>> > wrote:
>> > >
>> > > On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda
>> wrote:
>> > > > A depends on B, so B is automatically loaded when A is
>> loaded.
>> > > > B module is also directly being used by the user side
>> code via
>> > misc
>> > > > interface.
>> > > >.
>> > > > Now when I am unloading module A, via "modprobe -r A"
>> it is
>> > also
>> > > unloading
>> > > > the module B which is being used by the application and
>> > resulting in
>> > > the
>> > > > kernel crash.
>> > >
>> > > You said that A depends on B, right?  Why do you have A
>> dependng
>> > on B?
>> > > If it A needs to have B then it makes sense that you can
>> not
>> > remove A
>> > > while
>> > > B is in use.  If A doesn't need B, why not remove the
>> dependency.
>> > >
>> > >
>> > > A is calling few APIs defined by B.
>> > >
>> > > But why when user space application is already using  module B.
>> (it has
>> > already
>> > > open its device fd) kernel allows to remove it.
>> > >
>> > > I tried with doing try_module_get() in the module's open
>> function, it
>> > prevent
>> > > module B unloading but cause thread doing modprobe -r to hang
>> > > Is there any other way to mark module as busy when being used by
>> user
>> > > application?
>> >
>> > Never use try_module_get(), that is racy.
>> >
>> > What is the user/kernel interface you are using, and why doesn't it
>> > automatically increase the module count when userspace opens the
>> > interface?  It should all be done in a way that your module doesn't
>> need
>> > to do anything special.
>> >
>> >
>> > Hi Greg,
>> >
>> > Thanks for your mail.
>> >
>> > Module is using misc driver interface to export its functionality to
>> > userspace,
>> >
>> > Need to debug further why module count is not getting incremented
>> automatically
>> > when module is open by userspace application via open system call.
>>
>> Are you properly setting the .owner field of your file operations
>> structure to be THIS_MODULE?  If not, try fixing that up.  If you are,
>> try posting your code for review.
>>
>> greg k-h
>>
>
> Hi Greg,
>
> Thanks for the hint, indeed that was the issue, .owner field was not set
> in file operation structure.
> After setting that, 'modprobe -r A' is hanging. As the module B in use and
> can't be removed.
>
> I am using busybox on embedded Linux, I think this could be a modprobe
> utility issue.
> Ideally modprobe should not try to remove the module in used.
>
> I try to debug the hang when unloading of driver. I am using kernel v3.10
and it hangs in 'wait_for_zero_refcount'.
I checked that this function has been removed in kernel 3.13.
But I am not able to find the patch for this change.

Is there an easy way to find the patch which cause removal of wait from
module unloading in v3.13.



> Thanks,
> Chetan Nanda
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to prevent a module from unloading when in used

2014-07-17 Thread Chetan Nanda
On Fri, Jul 18, 2014 at 9:47 AM, Greg KH  wrote:

> On Fri, Jul 18, 2014 at 09:43:48AM +0530, Chetan Nanda wrote:
> >
> >
> >
> > On Wed, Jul 16, 2014 at 9:51 PM, Greg KH  wrote:
> >
> > On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:
> > >
> > >
> > >
> > > On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda <
> chetanna...@gmail.com>
> > wrote:
> > >
> > >
> > >
> > > On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza <
> j...@jjdev.com>
> > wrote:
> > >
> > > On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda
> wrote:
> > > > A depends on B, so B is automatically loaded when A is
> loaded.
> > > > B module is also directly being used by the user side
> code via
> > misc
> > > > interface.
> > > >.
> > > > Now when I am unloading module A, via "modprobe -r A" it
> is
> > also
> > > unloading
> > > > the module B which is being used by the application and
> > resulting in
> > > the
> > > > kernel crash.
> > >
> > > You said that A depends on B, right?  Why do you have A
> dependng
> > on B?
> > > If it A needs to have B then it makes sense that you can
> not
> > remove A
> > > while
> > > B is in use.  If A doesn't need B, why not remove the
> dependency.
> > >
> > >
> > > A is calling few APIs defined by B.
> > >
> > > But why when user space application is already using  module B.
> (it has
> > already
> > > open its device fd) kernel allows to remove it.
> > >
> > > I tried with doing try_module_get() in the module's open function,
> it
> > prevent
> > > module B unloading but cause thread doing modprobe -r to hang
> > > Is there any other way to mark module as busy when being used by
> user
> > > application?
> >
> > Never use try_module_get(), that is racy.
> >
> > What is the user/kernel interface you are using, and why doesn't it
> > automatically increase the module count when userspace opens the
> > interface?  It should all be done in a way that your module doesn't
> need
> > to do anything special.
> >
> >
> > Hi Greg,
> >
> > Thanks for your mail.
> >
> > Module is using misc driver interface to export its functionality to
> > userspace,
> >
> > Need to debug further why module count is not getting incremented
> automatically
> > when module is open by userspace application via open system call.
>
> Are you properly setting the .owner field of your file operations
> structure to be THIS_MODULE?  If not, try fixing that up.  If you are,
> try posting your code for review.
>
> greg k-h
>

Hi Greg,

Thanks for the hint, indeed that was the issue, .owner field was not set in
file operation structure.
After setting that, 'modprobe -r A' is hanging. As the module B in use and
can't be removed.

I am using busybox on embedded Linux, I think this could be a modprobe
utility issue.
Ideally modprobe should not try to remove the module in used.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to prevent a module from unloading when in used

2014-07-17 Thread Chetan Nanda
On Wed, Jul 16, 2014 at 9:51 PM, Greg KH  wrote:

> On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:
> >
> >
> >
> > On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda 
> wrote:
> >
> >
> >
> > On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza 
> wrote:
> >
> > On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda wrote:
> > > A depends on B, so B is automatically loaded when A is loaded.
> > > B module is also directly being used by the user side code via
> misc
> > > interface.
> > >.
> > > Now when I am unloading module A, via "modprobe -r A" it is
> also
> > unloading
> > > the module B which is being used by the application and
> resulting in
> > the
> > > kernel crash.
> >
> > You said that A depends on B, right?  Why do you have A dependng
> on B?
> > If it A needs to have B then it makes sense that you can not
> remove A
> > while
> > B is in use.  If A doesn't need B, why not remove the dependency.
> >
> >
> > A is calling few APIs defined by B.
> >
> > But why when user space application is already using  module B. (it has
> already
> > open its device fd) kernel allows to remove it.
> >
> > I tried with doing try_module_get() in the module's open function, it
> prevent
> > module B unloading but cause thread doing modprobe -r to hang
> > Is there any other way to mark module as busy when being used by user
> > application?
>
> Never use try_module_get(), that is racy.
>
> What is the user/kernel interface you are using, and why doesn't it
> automatically increase the module count when userspace opens the
> interface?  It should all be done in a way that your module doesn't need
> to do anything special.
>
> Hi Greg,

Thanks for your mail.

Module is using misc driver interface to export its functionality to
userspace,

Need to debug further why module count is not getting incremented
automatically when module is open by userspace application via open system
call.

Thanks
Chetan Nanda

thanks,
>
> greg k-h
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to prevent a module from unloading when in used

2014-07-16 Thread Chetan Nanda
On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda  wrote:

>
>
> On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza  wrote:
>
>> On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda wrote:
>> > A depends on B, so B is automatically loaded when A is loaded.
>> > B module is also directly being used by the user side code via misc
>> > interface.
>> >.
>> > Now when I am unloading module A, via "modprobe -r A" it is also
>> unloading
>> > the module B which is being used by the application and resulting in the
>> > kernel crash.
>>
>> You said that A depends on B, right?  Why do you have A dependng on B?
>> If it A needs to have B then it makes sense that you can not remove A
>> while
>> B is in use.  If A doesn't need B, why not remove the dependency.
>
>
A is calling few APIs defined by B.

But why when user space application is already using  module B. (it has
already open its device fd) kernel allows to remove it.

I tried with doing try_module_get() in the module's open function, it
prevent module B unloading but cause thread doing modprobe -r to hang
Is there any other way to mark module as busy when being used by user
application?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to prevent a module from unloading when in used

2014-07-16 Thread Chetan Nanda
Hi,

I am  facing an issues with module unloading,
I have two modules say A, B

A depends on B, so B is automatically loaded when A is loaded.
B module is also directly being used by the user side code via misc
interface.

Now when I am unloading module A, via "modprobe -r A" it is also unloading
the module B which is being used by the application and resulting in the
kernel crash.

Also, lsmod ouput shows driver B is not used by anybody. Seems "Used By" of
lsmod output is not getting updated.

How to prevent unloading of module B in used. When unloading module 'A' via
modprobe -r

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Release DMA Memory

2014-03-10 Thread Chetan Nanda
On Mar 11, 2014 7:57 AM, "Matt Davis"  wrote:
>
> I have a kernel module that communicates to a PCI device via DMA.  The
> module allocates the shared memory using dma_alloc_coherent().  When
> the module is unloaded, a call to dma_free_coherent() is executed.
>
> My question is, since the DMA memory is not explicitly zeroed before
> deallocation, is there a chance that the PCI device could still read
> (non-zeroed data) and act upon the DMA memory after the module unloads
> and calls dma_free_coherent()?
>
Ideally you should stop the device before freeing the memory.
If device is allowed to run and access the memory after memory is free this
may leads to memory coruption that would be hard to debug.

> Thanks!
>
> -Matt
>
>
-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


Loading / Unloading kernel module from another module

2014-02-02 Thread Chetan Nanda
Hi,

Is there a way to load and unload a module from another module?
I know 'request_module' can be used to load but what is the API for
unloading a module.

Thanks for your help.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: About exporting symbols from an external module

2014-01-14 Thread Chetan Nanda
On Tue, Jan 14, 2014 at 6:38 PM, Le Tan  wrote:

> Sorry, forgive me. I don't know how to reply the email like you.
> My linux kernel version is 3.11, and I do not touch the kvm makefile. Now
> let me show you in detail.
> First I put the files of my module in " /arch/x86/logger ", "logger" is
> the directory I create. The Makefile in " /arch/x86/kvm/" I think is the
> Makefile of kvm. It is like this:
>
> ccflags-y += -Ivirt/kvm -Iarch/x86/kvm
>
> CFLAGS_x86.o := -I.
> CFLAGS_svm.o := -I.
> CFLAGS_vmx.o := -I.
>
> KVM := ../../../virt/kvm
>
> kvm-y += $(KVM)/kvm_main.o $(KVM)/ioapic.o \
> $(KVM)/coalesced_mmio.o $(KVM)/irq_comm.o \
>  $(KVM)/eventfd.o $(KVM)/irqchip.o
> kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += $(KVM)/assigned-dev.o
> $(KVM)/iommu.o
> kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
>
> kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
>i8254.o cpuid.o pmu.o
> kvm-intel-y += vmx.o
> kvm-amd-y += svm.o
>
> obj-$(CONFIG_KVM) += kvm.o
> obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
> obj-$(CONFIG_KVM_AMD) += kvm-amd.o
>
> And the Makefile of my module in "/arch/x86/logger" is like this:
>
> ifneq ($(KERNELRELEASE),)
> obj-m := logger.o
>  logger-objs := logger_main.o
> else
>
> KERNELDIR ?= /lib/modules/$(shell uname -r)/build
> PWD := $(shell pwd)
>
> modules:
> $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
> endif
>
> clean:
> rm -rf *.o *.ko *.mod.c
>
> So I compile my module first by running "make", then insmod it. I don't
> install it because I don't know if it is necessary. Then I go to the root
> of my linux code, and run a shell containing "make modules". Then it will
> show that :
>
> make -j 16 modules
> make[1]: Nothing to be done for `all'.
>   CHK include/generated/uapi/linux/version.h
> make[1]: Nothing to be done for `relocs'.
>   CHK include/generated/utsrelease.h
>   CALLscripts/checksyscalls.sh
>   CC [M]  arch/x86/kvm/x86.o
>   LD [M]  arch/x86/kvm/kvm.o
>   LD [M]  arch/x86/kvm/kvm-intel.o
>   LD [M]  arch/x86/kvm/kvm-amd.o
>   Building modules, stage 2.
>   MODPOST 2832 modules
> ERROR: "print_record" [arch/x86/kvm/kvm.ko] undefined!
> make[1]: *** [__modpost] Error 1
> make: *** [modules] Error 2
> rmmod kvm_intel
> rmmod kvm
> cp
> /home/tanle/study/replay/linux-log/linux-3.11-replay/arch/x86/kvm/kvm.ko
> /lib/modules/3.11.0+/kernel/arch/x86/kvm/kvm.ko
> cp
> /home/tanle/study/replay/linux-log/linux-3.11-replay/arch/x86/kvm/kvm-intel.ko
> /lib/modules/3.11.0+/kernel/arch/x86/kvm/kvm-intel.ko
> modprobe kvm
> modprobe kvm_intel
>
> Notice that I add two sentences to the /arch/x86/kvm/x86.c:
>
> extern void print_record(char *format);   //This functino is
> defined in my module, this sentence is global
>
> print_record(NULL);//Call this function in the
> vcpu_enter_guest() function
>
> So I don't know how to deal with this. I have poor knowledge about
> makefile and KBuild.
> Thanks for helping me again!
>
> How you are specifying kvm module to use symbol which is exported by some
other module?

After compiling your logger module, it must have generated a Module.symvers
file containing symbols exported by your module,
Please try with adding following in kvm module make file and compile again:

*KBUILD_EXTRA_SYMBOLS+= /Module.symvers *


2014/1/14 Chetan Nanda 
>
>>
>>
>>
>> On Tue, Jan 14, 2014 at 12:38 PM, Le Tan  wrote:
>>
>>> Thanks very much! I will try that later. What you mentioned is another
>>> amazing sight. But I am confused that why it can't work if I export a
>>> function from my module and call it in the kvm? Do I have to modify the
>>> makefile of kvm? How? I have referenced to the doc of KBuild. It said that :
>>>  Sometimes, an external module uses exported symbols from
>>> another external module. kbuild needs to have full knowledge of
>>> all symbols to avoid spliitting out warnings about undefined
>>> symbols. Three solutions exist for this situation.
>>>
>>> NOTE: The method with a top-level kbuild file is recommended
>>> but may be impractical in certain situations.
>>>
>>> Use a top-level kbuild file
>>> If you have two modules, foo.ko and bar.ko, where
>>> foo.ko needs symbols from bar.ko, you can use a
>>> common top-level kbuild file so both modules are
>>> compiled in the same build. Consider the following
>>> directory layout:
>>>
>>> ./foo/ <= contains

Re: About exporting symbols from an external module

2014-01-14 Thread Chetan Nanda
On Tue, Jan 14, 2014 at 12:38 PM, Le Tan  wrote:

> Thanks very much! I will try that later. What you mentioned is another
> amazing sight. But I am confused that why it can't work if I export a
> function from my module and call it in the kvm? Do I have to modify the
> makefile of kvm? How? I have referenced to the doc of KBuild. It said that :
>  Sometimes, an external module uses exported symbols from
> another external module. kbuild needs to have full knowledge of
> all symbols to avoid spliitting out warnings about undefined
> symbols. Three solutions exist for this situation.
>
> NOTE: The method with a top-level kbuild file is recommended
> but may be impractical in certain situations.
>
> Use a top-level kbuild file
> If you have two modules, foo.ko and bar.ko, where
> foo.ko needs symbols from bar.ko, you can use a
> common top-level kbuild file so both modules are
> compiled in the same build. Consider the following
> directory layout:
>
> ./foo/ <= contains foo.ko
> ./bar/ <= contains bar.ko
>
> The top-level kbuild file would then look like:
>
> #./Kbuild (or ./Makefile):
> obj-y := foo/ bar/
>
> And executing
>
> $ make -C $KDIR M=$PWD
>
> will then do the expected and compile both modules with
> full knowledge of symbols from either module.
>
> Use an extra Module.symvers file
> When an external module is built, a Module.symvers file
> is generated containing all exported symbols which are
> not defined in the kernel. To get access to symbols
> from bar.ko, copy the Module.symvers file from the
> compilation of bar.ko to the directory where foo.ko is
> built. During the module build, kbuild will read the
> Module.symvers file in the directory of the external
> module, and when the build is finished, a new
> Module.symvers file is created containing the sum of
> all symbols defined and not part of the kernel.
>
> Use "make" variable KBUILD_EXTRA_SYMBOLS
> If it is impractical to copy Module.symvers from
> another module, you can assign a space separated list
> of files to KBUILD_EXTRA_SYMBOLS in your build file.
> These files will be loaded by modpost during the
> initialization of its symbol tables.
>
> But I have tried those methods. They don't work. Why?
> Thanks for your help very much!
>

Please show your kvm module makefile,


>
>

>
> 2014/1/14 Henrique Rodrigues 
>
>> Hi Le,
>>
>> You can do that by exporting a function pointer from the kvm code that is
>> only called if it is not null. Then, when you load your module, you set
>> that exported function pointer (I'm assuming that you want to call your
>> module's function from the kvm code... ). Here is a post on how to do that:
>>
>>
>> http://stackoverflow.com/questions/11463184/how-to-use-exported-symbols-in-the-linux-kernel
>>
>> http://stackoverflow.com/questions/1196944/can-i-replace-a-linux-kernel-function-with-a-module
>>
>> Best,
>> --
>> Henrique Rodrigues
>> http://www.dcc.ufmg.br/~hsr
>>
>>
>> On Mon, Jan 13, 2014 at 2:47 AM, Le Tan  wrote:
>>
>>> Hello! I am writing a device driver module. I define some functions in
>>> the module, for example print_record(). I am doing something in the kvm, so
>>> I want to call print_record() in the file of kvm module, for example, I may
>>> call print_record() in file /arch/x86/kvm/x86.c to put something into my
>>> device driver module.
>>> Now comes the question.
>>> 1. Where should I put the codes of my device driver module? It's the
>>> first time I write the device driver.
>>> 2. After compiling my module, I encounter an error when I compile the
>>> kvm module.
>>>  ERROR: "print_record" [arch/x86/kvm/kvm.ko] undefined!
>>> I use EXPORT_SYMBOL(print_record) in my module file. I use "extern"
>>> to declare print_record() and then call print_record()  in file x86.c.
>>> To solve this problem, I have tried to copy the Module.symvers from
>>> my module folder to /arch/x86/kvm/. But it doesn't work. I have also tried
>>> to add *KBUILD_EXTRA_SYMBOLS *to the Makefile of kvm. It doesn't work
>>> either.
>>> I cat /proc/kallsyms and find that the type of symbol "print_record"
>>> is "t" ( local text). What should I do? How to call functions defined in my
>>> own module from kvm? Maybe there is something wrong in Makefiles?
>>>
>>> Any suggestion is appreciated!
>>> Thanks!
>>>
>>> ___
>>> 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
>
>
___
Kerneln

Re: Issue while unloading modules via modprobe

2013-12-03 Thread Chetan Nanda
On Tue, Dec 3, 2013 at 2:17 PM, Mandeep Sandhu
wrote:

> >
> > error =  system("modprobe -rv A");
> >
> > This returns an error = 256.
>
> Hi Mandeep,

thanks for your mail

What does 'perror' show (if anything) ?
>
> Also, if you try the same via a shel, whats the return value ('echo
> $?') printed?
>
> echo $? show 1 (EPERM? most probably, operation not permitted for common
module).


> BTW, why are you using the '-v' option when invoking modprobe
> programatically?
>
> yes, -v option can be removed (behaviour is same even after removing -v
option)

-mandeep
>

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Issue while unloading modules via modprobe

2013-12-03 Thread Chetan Nanda
Hi,

I am getting an error while unloading modules via modprobe. Here is the
description of issue.

I have a module 'A' that depends on Module 'C' and 'D'.
And another module 'B' that depends on Module 'C' and 'E'

I loaded these modules from code via 'system' function as

error = system("modprobe -v A");
error = system("modprobe -v B");

After this all my modules A, B, C, D, and E are loaded properly.

Now when i tried to unload module A via

error =  system("modprobe -rv A");

This returns an error = 256.

But my module A and D is unloaded successfully. 'C' is not unloaded as it
is still in used by 'B'.
Is the error returned by system function is caused due to not unloading of
module 'C'? This is a valid scenario and error should not have returned in
this case.

I am still trying to find the reason for an error. If anyone has some
information on this then please help to share.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Can mm_struct of a process be null?

2013-11-17 Thread Chetan Nanda
Yes, current->mm points to user space context for the current process.
Now for a kernel threads there is no user space context and for them
current->mm would be NULL.

Thanks,
Chetan Nanda


On Fri, Nov 15, 2013 at 9:54 PM, Paul Davies C wrote:

>  Hi,
> I happen to find this code snippet in the kernel source :
>
>
>
>
>
>
>
>
>
> *struct mm_struct *mm=current->mm; /* some other code */ if(mm){
> /*<==Why is this here? */ /*read the contents by locking*/ } *
> The* if  *checks whether the mm_struct of the current process is NULL or
> not. That means the mm_struct of a process can become NULL. How can that
> happen?
>
> ___
> 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: How to find out which part of code is changing a particular data structure.

2013-11-07 Thread Chetan Nanda
You may attach debugger (like Lauterbach) and use its data breakpoint
functionality.

Thanks,
Chetan Nanda


On Fri, Nov 8, 2013 at 6:16 AM, Rajat Jain  wrote:

> Hi folks,
>
> I have a memory location (One of the fields in a kernel data structure)
> and I want to track down the code that changes the value of that particular
> location. Some thing like a "watchpoint".
>
> And this is early while I am still booting up. Can some one tell me if it
> is possible to do so?
>
> Thanks,
>
> Rajat
>
>
>
>
> ___
> 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


i2c_add_driver and i2c_new_device handling

2013-10-04 Thread Chetan Nanda
Hi,

I am writting a driver to control an i2c device.
Is it possible to call 'i2c_add_driver' and 'i2c_new_device' back to back
from module init function?

Currently i am getting error 'Bug scheduling while atomic' on calling
i2c_new_device.
Any pointer to debug furthe will be very helpful.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: I2C Adapters

2013-09-09 Thread Chetan Nanda
On Sat, Sep 7, 2013 at 1:05 AM, Jeshwanth Kumar N K
wrote:

> Hello All,
>
> From the architecture mentioned in below link.
>
>
> http://www.embexperts.com/attachments/forumid_9/11012316293acb53699d289750.png
>
> I have some questions:
>
> In the Kernel space:
>
> 1. Client driver is refers to Driver for Each connected devices - Example:
> EEPROM, I2c_LCD etc.
> 2. i2c-core - The I2C core layer manages bus adapters, device drivers and
> device clients
> 3. I2c Adapters - ?? I didn't get what it is actually. Can somebody please
> explain ?
>

AFAIK, I2C Adapter is basically HOST side I2C controller. And I2C core is
containing some common code (routines) being used by both I2C client (I2C
devices) driver and I2C adapter (controller) driver.

Thanks,
Chetan Nanda

Thanks
>
>
>
> --
> Regards
> Jeshwanth Kumar N K
> Bangalore, India
> ___
> 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: Use of copy_to_user() and copy_from_user() functions

2013-02-11 Thread Chetan Nanda
On Mon, Feb 11, 2013 at 5:25 PM, anish singh wrote:

>
>
> On Mon, Feb 11, 2013 at 4:51 PM, पारस  wrote:
> > Hi All,
> >
> > To read/write data to user-space from kernel-space we use
> copy_from_user()
> > and copy_to_user() functions.
> >
> > What is the use of these function?
> > Why kernel can't directly access user address and read/write on to it?
> what will happen if the user space process gets scheduled out while
> you were using it?
>
> copy_to/from_user should always be called from process context. So even if
a process is scheduled out there is not impact, as when process schedule
back in copying will resume to/from correct page.


> > Can any one explain why kernel can't directly access the user-space
> address.
> >
> > Thanks
> >
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: memory management with mmap

2012-10-31 Thread Chetan Nanda
On Oct 28, 2012 11:49 AM, "Sengottuvelan S" 
wrote:
>
>
> Hi Mulyadi
>
> I am able to do mmap and access virual-memory address and pages for a
single process from user-space and working fine. I am not sure how to do it
for multiple processes for shared resources using mmap.  I better explain
in detail here what I am experimenting it.
>
> for example:
>
> Kernel allocates kmalloc or vmalloc of 100 pages and set those pages
as reserved. Kernel uses these pages to send/receive data to Process A or B
depends on a condition.
>
> Process A and B do mmap those region to get/set data on those
virtual-addresses/pages because I want faster access from userpace to
kernel.
>
> Anyone knows if this will work with mmap?. Please let me know  if
anyother way to do it.
>
Not sure about your actual requiremnent, but there are other better way of
sharing data between processes already exist. E.g. Shared memory.
Advisable to use them instead of writing a new one

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


Re: Regarding high mem

2012-10-17 Thread Chetan Nanda
On Oct 17, 2012 2:22 PM, "Kshemendra KP"  wrote:
>
>
>
>
> On Wed, Oct 17, 2012 at 2:04 PM, Chetan Nanda 
wrote:
>>
>>
>>
>> On Tue, Oct 16, 2012 at 5:47 PM, Kshemendra KP 
wrote:
>>>
>>>
>>>On x86 kernel is normally split into 3GB (user) : 1 GB (Kernel)
spaces. Kernel can only directly
>>>manipulate 1 GB (around 889 MB) from the PAGE_OFFSET (0xC000).
The user space
>>>memofy below PAGE_OFFSET kernel can't directly access, it considers
this memory as
>>>high memory. Kernel needs to kmap()/kmap_atomic() map user page and
access that region.
>>
>>
>> As per my understanding, if kernel code is running under a process
context then it can access lower 3GB address space, provided address in
0-3GB is in process address space.  And its not a high memory.
>> High memory is a virtual address space with 1GB kernel space to map RAM
pages beyond 896MB.
>
>
> One thing not clear to me is, during boot,  kernel is copied to 1st MB of
the RAM in x86 architecture as this  architecture
> has ISA mem map hole (640k -to 1MB). From 1st BM till 896MB is occupied
by the kernel. Then user space will be
> made available beyond 896 MB.  With this reasoning, it is not clear to
me, whether user space which is present
> beyond 896 MB is in high memory.

On x86 kernel will be loaded in RAM from 1st MB. But kernel code and data
will not go upto 896MB.
Kernel code + data will be loaded in ram from 1MB - end_data (IIRC). and
address space between end_data to 896Mb is used for dynamic allocation
(kmalloc ) etc...

I would recomend you to read 2nd chapter of understanding linux kernel.
This chapter contain detailed info on memory addressing used by kernel on
x86
>>
>>
>>
>>>
>>>If the memory is above 4 GB with page extension, it is clear that
kernel can't access it as
>>>kernel uses "void *" and/or  "unsigned long" to hold the address.
But it is not clear for me
>>>why kernel's can't directly access memory below PAGE_OFFSET ( 0-3GB)
directly.
>>
>>
>> Kernel can access 0-3GB memory, take an example of application sending
data to kernel via system call e.g. write.
>> in Write system call pointer to the buffer will be in 0-3Gb address
space of calling application. And kernel will access this address to write
data to drivers/etc ..
>>
>>>
>>>
>>> Regards
>>>
>>> Kshemendra
>>>
>>> ___
>>> Kernelnewbies mailing list
>>> Kernelnewbies@kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Regarding high mem

2012-10-17 Thread Chetan Nanda
On Tue, Oct 16, 2012 at 5:47 PM, Kshemendra KP wrote:

>
>On x86 kernel is normally split into 3GB (user) : 1 GB (Kernel) spaces.
> Kernel can only directly
>manipulate 1 GB (around 889 MB) from the PAGE_OFFSET (0xC000). The
> user space
>memofy below PAGE_OFFSET kernel can't directly access, it considers
> this memory as
>high memory. Kernel needs to kmap()/kmap_atomic() map user page and
> access that region.
>

As per my understanding, if kernel code is running under a process context
then it can access lower 3GB address space, provided address in 0-3GB is in
process address space.  And its not a high memory.
High memory is a virtual address space with 1GB kernel space to map RAM
pages beyond 896MB.



>If the memory is above 4 GB with page extension, it is clear that
> kernel can't access it as
>kernel uses "void *" and/or  "unsigned long" to hold the address. But
> it is not clear for me
>why kernel's can't directly access memory below PAGE_OFFSET ( 0-3GB)
> directly.
>

Kernel can access 0-3GB memory, take an example of application sending data
to kernel via system call e.g. write.
in Write system call pointer to the buffer will be in 0-3Gb address space
of calling application. And kernel will access this address to write data
to drivers/etc ..


>
> Regards
>
> Kshemendra
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Issue in ioctl func call of character driver.

2012-06-02 Thread Chetan Nanda
On Sat, Jun 2, 2012 at 5:45 PM, KARTHIK SEKURU wrote:

> Hi,
> I am new to kernel device drivers.
>
> I wrote a simple character driver built statically having the fops as
> shown:
>
> *static const struct file_operations mfcfpga65_usb_fops = {*
> * .owner = THIS_MODULE,*
> * .open = mfcfpga65_usb_open,*
> * .read = mfcfpga65_usb_read,*
> * .unlocked_ioctl = mfcfpga65_usb_ioctl,*
> * .release = mfcfpga65_usb_close,*
> *};*
>
> All the driver registrations are done properly.
>
> I wrote a sample application to test these drivers implementing open,read
> and ioctl calls.
>
> open and read are working fine whereas ioctl is not behaving as expected.
>
> The application code is as shown:
>
> *int main()*
> *{*
> * printf("Enterred main function : \n");*
> * int fd=0,ret=0;*
> * char buff[80]="";*
> * *
> * fd=open("/dev/usbmod",O_RDONLY);*
> * if(fd<0) *
> * {*
> * printf("fd value is less than 0\n");*
> * }*
> * *
> * printf("fd :%d\n",fd);*
> * *
> * ret=read(fd,buff,10);*
> * buff[ret]='\0';*
> *
> *
> *printf("The commands passed are %d and
>  %d\n",IOCTL_USB_READ,IOCTL_USB_OPEN );*
> * ret = ioctl(fd,IOCTL_USB_READ);*
> * ret = ioctl(fd,IOCTL_USB_OPEN); *
> *
> *
> * close(fd);*
> *}*
>
> The cmds in ioctl are defined in seperate header file which is included in
> driver as well as in the applicatin.That definations are as shown
>
> *#define MFCFPGA65_NUM 254*
> *
> *
> *#define IOCTL_USB_OPEN   _IO(MFCFPGA65_NUM,0)*
> *#define IOCTL_USB_READ   _IO(MFCFPGA65_NUM,1)*
> *#define IOCTL_USB_WRITE  _IO(MFCFPGA65_NUM,2)*
>
>
> The IOCTL call in driver does nothing except printk in each switch case
> showing to which case statement it entered .This ioctls implementation in
> driver  is as shown below:
>
> *static long mfcfpga65_usb_ioctl(struct inode *inode, struct file *file,
> unsigned int iocmd,*
> * unsigned long ioarg)*
>

Syntax for unlocked ioctl is different then what you are using, there is no
'inode' parameter in the new syntax.
Try with the below line, hopefully it will fix the error you are getting:
*static long mfcfpga65_usb_ioctl *(struct file *file, unsigned int cmd_in,
unsigned long arg)

*{*
> *   *
> * void __user *arg = (void __user *)ioarg;*
> * unsigned int* stream;*
> * unsigned int size;*
> * *
> * printk(KERN_INFO "In IOCTL function of USB character driver with cmd as
> %d : \n",iocmd);*
> * *
> * printk(KERN_INFO "The switch case cmds are %d %d
> %d\n",IOCTL_USB_OPEN,IOCTL_USB_READ,IOCTL_USB_WRITE);*
> *
> *
> * switch (iocmd) {*
> *
> *
> * case IOCTL_USB_OPEN:*
> * *
> * printk(KERN_INFO "In IOCTL case1 of USB character driver: \n");*
> * return 0;*
> * break;*
> * *
> * case IOCTL_USB_READ:*
> * *
> * printk(KERN_INFO "In IOCTL case2 of USB character driver: \n");*
> * return 0;*
> * break;*
> * *
> * case IOCTL_USB_WRITE:*
> * *
> * printk(KERN_INFO "In IOCTL case3 of USB character driver: \n");*
> * return 0;*
> *break;*
> * *
> *}*
> *}*
>
> From application i made sure that i am passing proper cmd arguments.The
> control goes to the ioctl function call in driver but doesn't go to the
> proper switch cases.
>
> This is because the iocmd argument received in the ioctl implementation is
> getting corrupted i.e eventhough from application i am passing *IOCTL_USB_READ
> , **IOCTL_USB_OPEN *parameters,when i check them in
> ioctl function in drivers the values are changed and through printk in the
> ioctl i could see that the iocmd received in the function is 4096 value
> which doesn't match to IOCTL_USB_READ or
> IOCTL_USB_OPEN.
>
> Please let me know how can the command argument passes via ioctl call in
> application is modified/corrupted before it reaches the actual ioctl
> implementation in drivers.
>
>
Thanks,
Chetan Nanda


> thanks,
> Karthik.
>
>
> ___
> 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: Module vs Kernel main performacne

2012-05-31 Thread Chetan Nanda
On May 31, 2012 9:37 PM, "Abu Rasheda"  wrote:
>
> On Wed, May 30, 2012 at 10:35 PM, Mulyadi Santosa
>  wrote:
> > Hi...
> >
> > On Thu, May 31, 2012 at 4:44 AM, Abu Rasheda 
wrote:
> >> as I increase size of buffer, insns per cycle keep decreasing. Here is
the data:
> >>
> >>1k 0.90  insns per cycle
> >>8k 0.43  insns per cycle
> >>  43k 0.18  insns per cycle
> >> 100k 0.08  insns per cycle
> >>
> >> Showing that copy_from_user is more efficient when copy data is small,
> >> why it is so ?
> >
> > you meant, the bigger the buffer, the fewer the instructions, right?
>
> yes
>
If the buffer at user side is more then a page, then it may be that
complete user space buffer is not available in memory and kernel spend time
in processing page fault
> >
> > Not sure why, but I am sure it will reach some peak point.
> >
> > Anyway, you did kmalloc and then kfree()? I think that's why...bigger
> > buffer will grab large chunk from slab...and again likely it's
> > physically contigous. Also, it will be placed in the same cache line.
> >
> > Whereas the smaller onewill hit allocate/free cycle more...thus
> > flushing the L1/L2 cache even more.
>
> It seems to be doing opposite, bigger the allocation / copy longer stall
is.
>
> ___
> 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: user virtual address to physical address

2012-05-08 Thread Chetan Nanda
On Wed, May 9, 2012 at 5:40 AM, Fredrick  wrote:

> Hi,
>
> I need to convert a user virtual address to its
> corresponding physical address.
> I know that if the virtual address is from kernel,
> we could use virt_to_phys.
> Is there a similar helper function
> to convert user virtual address.?
>
> Hi Fredrick,

Please elaborate the purpose,

User-space application allowed to have virtual address upto 3GB, assuming
1:3 address space split.
And its not mandatory for all user-space address to be valid and to have
all user-space address to have a valid physical address mapping.


Thanks,
Chetan

Thanks,
> Fredrick
>
>
> ___
> 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: Problem of workqueue

2012-05-03 Thread 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


Writing a single buffer in kernel ring buffer take 6-8 ms

2012-05-03 Thread Chetan Nanda
Hi,

We are working on ARM based SOC.
Currently we are implementing a efficient tracing mechanism to logs
messages from a dedicated MCU.

For this, we share a circular buffer between ARM and MCU and messages
stored in the buffer will be put into kernel ring-buffer and then output
via dmesg call.
Strangely wringing a single log message in the kernel ring-buffer cost
around 6-8ms.

Please help to confirm this, or we are doing something wrong.

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Kernel threads and system usage metric.

2012-03-12 Thread Chetan Nanda
On Mar 9, 2012 11:57 PM, "Mulyadi Santosa" 
wrote:
>
> Hi :)
>
> On Fri, Mar 9, 2012 at 18:39, Daniel Hilst  wrote:
> > The processes that appear in top with brackets are the kernel threads?
>
> Yup :)
>
> > If so, this threads spend all its time on system mode, right?
>
> Yes, it supposed to ...
>
> >By the
> > system mode I mean the %sy on top header, since kernel threads hasn't
> > any memory mapped to user space, it can't run on user space at any time,
> > right?
>
> IIRC, kernel thread simply "borrow" any previous scheduled task's
> address space. In that matter, it also has user address space. So, if
> wanted, kernel thread could access user space. But normally it doesn't
> do it.
>
AFAIK kernel threads do not have any userspace context. As it is never
gaurnted which userspace process was previously running when kernel thread
scheduled to run.

> >
> >
> > So the total of system mode usage is the sum of all processes processing
> > in kernel space, plus the kernel threads processing, right?
>
> remember that kernel threads are also processes, so no need to
> differentiate between normal processes and kernel threads, especially
> when we talk about CPU utilization.
>
> --
> 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
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux camera drivers

2012-03-06 Thread Chetan Nanda
Hi,
AFAIK imx036 is a raw bayer camera, and would be outputting data on mipi
data line.
So one needs a dedicated hardware such as mipi rx and then Isp etc.. And i
dont think drivers for these would be available in linux. I might be wrong
...
On Mar 5, 2012 2:18 PM, "Prabhakar Lad" 
> Mayank,
>
>
> On Sat, Mar 3, 2012 at 9:51 AM, Mayank Agarwal <
> mayank77fromin...@gmail.com> wrote:
>
>>
>>
>> On Fri, Mar 2, 2012 at 10:08 AM, Mayank Agarwal <
>> mayank77fromin...@gmail.com> wrote:
>>
>>> 1.I think the device supports i2c or spi protocol.I want to know how the
>>> i2c or spi is taking data
>>>  from image sensor and giving it to video buffers.
>>> Most of the cameras support i2c or csi.
>>>
>>
>
>> 2.I want to understand the whole data flow from image sensor to the
>>> display buffer and the role of linux kernel
>>> camera drivers in that.
>>> For this you need to understand the V4L2 Framework, Or later Media
>>> Controller Framework.
>>>
>>
>
>> 3.Currently i am looking at Sony IMX036,Aptima MT9P031.
>>
>>   You can find in directory /drivers/media/video/
>MT9p031 support is there in current kernel but no idea about
> imx036.
>
> Regards,
> ---Prabhakar Lad
> Mob: +91-9611756433
> http://in.linkedin.com/pub/prabhakar-lad/19/92b/955
>
>
>>> Thanks and Regards,
>>> Mayank
>>>
>>>
>>> On Thu, Mar 1, 2012 at 8:22 PM, Greg KH  wrote:
>>>
 On Thu, Mar 01, 2012 at 05:57:52PM +0530, Mayank Agarwal wrote:
 > Hi all,
 >
 > I have following questions regarding camera drivers in  linux kernel.
 >
 > 1.which are the files/folder in kernel directory where camera drivers
 support
 > is provided in linux kernel.

 It depends, which type of protocol does your device support?

 > 2.Are they customisable according to different SOC requirements.

 It depends on what the requirements are.  As it's software, it's always
 able to be changed :)

 > 3.Are there any tutorials/pdfs to understand camera drivers in linux
 kernel.

 What is wrong with the code itself?

 > 4.At present which sensor (i mean aptina/sony/omnivision) drivers are
 supported
 > in linux kernel.

 What sensor are you looking for exactly?

 What device do you need to support, and what protocol does your camera
 use to talk to the hardware?

 greg k-h

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


Re: Issue with ioctl commands - Linux version 2.6.35.7+

2011-12-28 Thread Chetan Nanda
On Wed, Dec 28, 2011 at 8:22 PM, autif khan  wrote:

> Hi Chetan,
>
> I was wondering if switching to unlocked_ioctl() fixed the issue.
>
> I will be developing a hardware driver and would like to know how you
> made out. Please let me know if the 'cmd' is passed correctly.
>
> Thanks for sharing.
>
> Autif
>

Hi Autif,
Please go through the link:
http://lwn.net/Articles/119652/

Problem with my dummy driver was that i am using unlocked_ioctl, but
defined the ioctl function with wrong syntax (i.e. with syntax of normal
ioctl function.)

Thanks,
Chetan Nanda

>
> On Tue, Dec 27, 2011 at 10:34 PM, Chetan Nanda 
> wrote:
> >
> >
> > On Tue, Dec 27, 2011 at 11:25 PM, Dave Hylands 
> wrote:
> >>
> >> Hi Chetan,
> >>
> >> On Tue, Dec 27, 2011 at 3:39 AM, Chetan Nanda 
> >> wrote:
> >> > Hi All,
> >> >
> >> > I am facing a strange issue with the ioctl commands, and not able to
> >> > find
> >> > what wrong I am doing.
> >> > I am trying with a dummy kernel driver and implemented ioctl command
> as
> >> > follow:
> >> >
> >> > in my_ioctl.h
> >> > #define READHWREG_MAGIC_NUMBER 0x15
> >> > #define READHWREG_CAM_READPE _IOR(READHWREG_MAGIC_NUMBER, 1, int*)
> >> >
> >> > But the value of 'READHWREG_CAM_READPE' is comes out to be different
> in
> >> > userspace (in the application) and kernel space (in the driver).
> >> >
> >> > In userspace I used ioctl as
> >> > ...
> >> >printf("\ncommand %x \n",READHWREG_CAM_READPE); <-- command
> 80041501
> >> >error = ioctl(g_DevFileId, READHWREG_CAM_READPE);
> >> > ..
> >> >
> >> > In kernel space
> >> >
> >> > int readHwReg_ioctl(struct inode *node, struct file *filp, unsigned
> int
> >> > cmd,  unsigned long arg)
> >> > {
> >> > ...
> >> >printk("\n%d %s cmd = %x\n",__LINE__,__FUNCTION__,cmd); <--- cmd =
> >> > bee6a9d4
> >>
> >> Back in 2.6.36, the ioctl member of the struct file_operations
> >> structure  (which took 4 arguments) was finally deprecated, replaced
> >> with unlocked_ioctl (which only takes 3 arguments).
> >>
> >> If you just renamed and ignored the compiler warnings, then that
> >> explains your problem.
> >>
> > Thanks Dave for pointing out 'unlocked_ioctl'
> > I come across this link:
> > http://lwn.net/Articles/119652/
> >
> >> --
> >> Dave Hylands
> >> Shuswap, BC, Canada
> >> http://www.davehylands.com
> >
> >
> > Thanks,
> > Chetan Nanda
> >
> > ___
> > 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: Issue with ioctl commands - Linux version 2.6.35.7+

2011-12-27 Thread Chetan Nanda
On Tue, Dec 27, 2011 at 11:25 PM, Dave Hylands  wrote:

> Hi Chetan,
>
> On Tue, Dec 27, 2011 at 3:39 AM, Chetan Nanda 
> wrote:
> > Hi All,
> >
> > I am facing a strange issue with the ioctl commands, and not able to find
> > what wrong I am doing.
> > I am trying with a dummy kernel driver and implemented ioctl command as
> > follow:
> >
> > in my_ioctl.h
> > #define READHWREG_MAGIC_NUMBER 0x15
> > #define READHWREG_CAM_READPE _IOR(READHWREG_MAGIC_NUMBER, 1, int*)
> >
> > But the value of 'READHWREG_CAM_READPE' is comes out to be different in
> > userspace (in the application) and kernel space (in the driver).
> >
> > In userspace I used ioctl as
> > ...
> >printf("\ncommand %x \n",READHWREG_CAM_READPE); <-- command 80041501
> >error = ioctl(g_DevFileId, READHWREG_CAM_READPE);
> > ..
> >
> > In kernel space
> >
> > int readHwReg_ioctl(struct inode *node, struct file *filp, unsigned int
> > cmd,  unsigned long arg)
> > {
> > ...
> >printk("\n%d %s cmd = %x\n",__LINE__,__FUNCTION__,cmd); <--- cmd =
> > bee6a9d4
>
> Back in 2.6.36, the ioctl member of the struct file_operations
> structure  (which took 4 arguments) was finally deprecated, replaced
> with unlocked_ioctl (which only takes 3 arguments).
>
> If you just renamed and ignored the compiler warnings, then that
> explains your problem.
>
> Thanks Dave for pointing out 'unlocked_ioctl'
I come across this link:
http://lwn.net/Articles/119652/

--
> Dave Hylands
> Shuswap, BC, Canada
> http://www.davehylands.com
>

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Issue with ioctl commands - Linux version 2.6.35.7+

2011-12-27 Thread Chetan Nanda
On 12/27/11, Alexandru Juncu  wrote:
> On Tue, Dec 27, 2011 at 1:57 PM, Chetan Nanda  wrote:
>>
>>
>> On Tue, Dec 27, 2011 at 5:23 PM, Alexandru Juncu 
>> wrote:
>>>
>>> On Tue, Dec 27, 2011 at 1:39 PM, Chetan Nanda 
>>> wrote:
>>> > Hi All,
>>> >
>>> > I am facing a strange issue with the ioctl commands, and not able to
>>> > find
>>> > what wrong I am doing.
>>> > I am trying with a dummy kernel driver and implemented ioctl command as
>>> > follow:
>>> >
>>> > in my_ioctl.h
>>> > #define READHWREG_MAGIC_NUMBER 0x15
>>> > #define READHWREG_CAM_READPE _IOR(READHWREG_MAGIC_NUMBER, 1, int*)
>>> >
>>> > But the value of 'READHWREG_CAM_READPE' is comes out to be different in
>>> > userspace (in the application) and kernel space (in the driver).
>>> >
>>> > In userspace I used ioctl as
>>> > ...
>>> >printf("\ncommand %x \n",READHWREG_CAM_READPE); <-- command 80041501
>>> >error = ioctl(g_DevFileId, READHWREG_CAM_READPE);
>>> > ..
>>> >
>>> > In kernel space
>>> >
>>> > int readHwReg_ioctl(struct inode *node, struct file *filp, unsigned int
>>> > cmd,  unsigned long arg)
>>> > {
>>> > ...
>>> >printk("\n%d %s cmd = %x\n",__LINE__,__FUNCTION__,cmd); <--- cmd =
>>> > bee6a9d4
>>> > ...
>>> > }
>>> >
>>> >
>>> > I am not able to figure out the root cause,
>>> > Please help to check...
>>>
>>> I think that the command is actually sent via the arg parameter, which
>>> is an address (it's a pointer to the value your are sending to kernel
>>> space).
>>
>>
>> Yes, even I observe this now. But how this can happen.
>> 'command' is the second argument for ioctl call.
>
> As far as I remember, you can send an integer through the cmd, but
> other things (like structures or buffers) through their address (and
> copy_from_user-ed). But, maybe, on new implementations (or on some
> architectures) everything is send via address.

What I have observed, third argument of the ioctl system call is
reaching the driver as a command.
ioctl(g_DevFileId, READHWREG_CAM_READPE, xx);

In driver:
int readHwReg_ioctl(struct inode *node, struct file *filp, unsigned
int cmd,  unsigned long arg)
cmd is equal to xx

Am I missing something in the driver/application.

Thanks,
Chetan Nanda

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


Issue with ioctl commands - Linux version 2.6.35.7+

2011-12-27 Thread Chetan Nanda
Hi All,

I am facing a strange issue with the ioctl commands, and not able to find
what wrong I am doing.
I am trying with a dummy kernel driver and implemented ioctl command as
follow:

in my_ioctl.h
#define READHWREG_MAGIC_NUMBER 0x15
#define READHWREG_CAM_READPE _IOR(READHWREG_MAGIC_NUMBER, 1, int*)

But the value of 'READHWREG_CAM_READPE' is comes out to be different in
userspace (in the application) and kernel space (in the driver).

In userspace I used ioctl as
...
   printf("\ncommand %x \n",READHWREG_CAM_READPE); <-- command 80041501
   error = ioctl(g_DevFileId, READHWREG_CAM_READPE);
..

In kernel space

int readHwReg_ioctl(struct inode *node, struct file *filp, unsigned int
cmd,  unsigned long arg)
{
...
   printk("\n%d %s cmd = %x\n",__LINE__,__FUNCTION__,cmd); <--- cmd =
bee6a9d4
...
}


I am not able to figure out the root cause,
Please help to check...

Thanks,
Chetan Nanda
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: When is to preempt safe?

2011-10-07 Thread Chetan Nanda
On 7 Oct 2011 16:58, "Parmenides"  wrote:
>
> Hi,
>
>   Preemption has two cases: user preemption and kernel preemption. I
> have tow questions about them.
>
> 1. According to Love, "If the kernel is returning to user-space, it
> knows it is in a safe quiescent state. In other words, if it is safe
> to continue executing the current task, it is also safe to pick a new
> task to execute." What's the meaning of user preemption's safety? How
> can we deduce safety of schedule from the current task going on?
>
> 2. Another statement from Love is that "the kernel can preempt a task
> running in the kernel so long as it does not hold a lock". Why is it
> not safe while kernel code holding lock?
New task pick by scheduler may try to get the same lock resulting in
deadlock
>
> ___
> 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