Re: How to contribute to latest -rc kernel?

2013-11-28 Thread Arvid Brodin
On 2013-11-28 09:11, Bjørn Mork wrote:
 Arvid Brodin arvid.bro...@alten.se writes:

 I thought the subsystem -next trees was for the next release of Linux? I.e., 
 what
 goes into the net-next tree now will find its way into mainline at the next
 release window, for linux-3.14-rc1?

 That's correct.

 If your series is for the networking subsystem *and* appropriate for an
 -rcX where X  1, then it should be based on

   https://git.kernel.org/cgit/linux/kernel/git/davem/net.git/

 and you should indicate that you want it applied to net instead of
 net-next.  I usually do that by including net in the subject prefix,
 like e. g.

  Subject: [PATCH net] foo: fix obvious bug

 but there are no strict rules about how to do this AFAIK.

 Note that the whole series must be applicable to net.  Don't be
 tempted to mix any features in there.  Split those out in a separate
 series instead and submit for net-next.  If they depend on any of the
 changes you made to net, then explain that dependency in the
 cover-letter.

 And yes, a cover-letter (PATCH 0/X) is always a good idea when posting
 more than 1 patch in a series. Davem use them as pseudo-merge commits,
 so whatever you write there is even recorded in the history.  This is a
 good place to explain why the series should be applied to net if that
 isn't 103% obvious (sometimes you need to know a driver pretty well to
 understand why something is a bugfix and not a feature).

 I believe all this is explained in more detail in the
 Documentation/networking/netdev-FAQ.txt document Fan Du pointed you to.
 That's a good place to start.  There are some small differences between
 networking and most other subsystems, like comment style and stable
 submissions.  There's usually no problem if you miss those details in
 the beginning - you'll just have to fix it later.  But reading the FAQ
 will give you a head start.


 Bjørn


Thank you Bjørn for a great answer!

Thanks also to Fan Du for pointing to the netdev-FAQ.


--
Arvid Brodin | Consultant (Linux)
ALTEN | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden
arvid.bro...@alten.se | www.alten.se/en/


Xdin has changed its name. From 25 November 2013 we are known as Alten. Read 
more at www.alten.se

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


Re: How to contribute to latest -rc kernel?

2013-11-27 Thread Arvid Brodin
On 2013-11-27 02:20, Fan Du wrote:


 On 2013年11月26日 05:17, Arvid Brodin wrote:
 Hi,

 How would I go ahead to send a patch for the latest -rc kernel?

 Specifically:

 * What tree to diff against? (Linus'?)
 * To which list do I send the patch?

 Background: I've contributed a new network driver that is now in 3.13-rc1. I
 would like to fix it so that it behaves better with iproute. Strictly 
 speaking
 this isn't a bug fix, but the driver is going to be quite useless without
 iproute support, and that won't be there until this fix is in the kernel.

 Almost every subsystem has its own next git tree, since it's a networking 
 driver
 issue, please verify your fix against net-next:

 https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/

 And send the patch to netdev maillist:
 http://vger.kernel.org/vger-lists.html#netdev

 You need also CC the driver maintainer by looking at 
 linux_source_code/MAINTAINERS,
 or using ./scripts/get_maintainer.pl.


Actually, part of the patch series is adding myself as the maintainer for the
driver. :)

I thought the subsystem -next trees was for the next release of Linux? I.e., 
what
goes into the net-next tree now will find its way into mainline at the next
release window, for linux-3.14-rc1?

I'm not sure though. It's a bit confusing. Aldo Iljazi said this:
  Arvid Brodin wrote:

 * What tree to diff against? (Linus'?)

 I believe that you need to diff against linux-next tree: 
 https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/?id=refs/tags/next-20131126

 * To which list do I send the patch?

 Well you can send it to the Linux Kernel Mailing List.
 -- Aldo Iljazi

Which seems reasonable to me. Is there anyone who can confirm this?


--
Arvid Brodin | Consultant (Linux)
ALTEN | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden
arvid.bro...@alten.se | www.alten.se/en/


Xdin has changed its name. From 25 November 2013 we are known as Alten. Read 
more at www.alten.se

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


How to contribute to latest -rc kernel?

2013-11-26 Thread Arvid Brodin
Hi,

How would I go ahead to send a patch for the latest -rc kernel?

Specifically:

* What tree to diff against? (Linus'?)
* To which list do I send the patch?

Background: I've contributed a new network driver that is now in 3.13-rc1. I
would like to fix it so that it behaves better with iproute. Strictly speaking
this isn't a bug fix, but the driver is going to be quite useless without
iproute support, and that won't be there until this fix is in the kernel.


--
Arvid Brodin | Consultant (Linux)
ALTEN | Knarrarnäsgatan 7 | SE-164 40 Kista | Sweden
arvid.bro...@alten.se | www.alten.se/en/

Xdin is changing its name. From 25 November 2013 we will be known as Alten. 
Read more at www.alten.se

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


Re: git pull fails on linux-next (out of memory)

2012-04-17 Thread Arvid Brodin
On 2012-03-31 08:50, Srivatsa Bhat wrote:
 Hi,
 
 On Sat, Mar 31, 2012 at 3:40 AM, Arvid Brodin arvid.bro...@enea.com
 mailto:arvid.bro...@enea.com wrote:
 
 Arvid Brodin wrote:
  On 2012-03-06, I cloned linux-next:
 
  $ git clone 
 git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
 http://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
 linux-next-20120306
 
 
  I now want to update this repository before posting patches, to make 
 sure
  they still apply cleanly. I first tried this on 20120328:
 
  
 Tracking linux-next is a little bit different from usual trees. In 
 particular, since
 Stephen Rothwell
 rebases it quite frequently, you shouldn't do a git pull on linux-next.
 
 See these articles for details on how to work with linux-next:
 http://linux.f-seidel.de/linux-next/pmwiki/pmwiki.php?n=Linux-next.FAQ
 http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-February/004498.html
 

Great links, thanks!

The first time I did 'git remote update' as described in the first link things 
worked
fine: I could git merge origin/master to be up to date with origin/master (or 
perhaps I
did a 'git rebase origin/master, I can't quite remember).

I tried the same thing ('git remote update; git merge origin/master') today, 
and got lots
of CONFLICTs. So I tried to get master back and after some time ended up 
running 'git
reset --hard; git clean -f -d', which I believe succeeded.

At this time 'git status' says the same as it did just after the remote update 
above:

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 569 and 3251 different commit(s) each, respectively.


Ok, so let's try a 'git rebase origin/master' instead:

$ git rebase origin/master
First, rewinding head to replay your work on top of it...
Applying: fsnotify: inline mark refcnt functions
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging fs/notify/mark.c
CONFLICT (content): Merge conflict in fs/notify/mark.c
Auto-merging include/linux/fsnotify_backend.h
Failed to merge in the changes.
Patch failed at 0001 fsnotify: inline mark refcnt functions

When you have resolved this problem run git rebase --continue.
If you would prefer to skip this patch, instead run git rebase --skip.
To restore the original branch and stop rebasing run git rebase --abort.


Huh?! I haven't touched that file! I just want to keep my linux-next tree up to 
date! How
hard should this be?!

/calming down/

Any ideas on what I've done wrong and how to solve it?

-- 
Arvid Brodin
Enea Services Stockholm AB - since February 16 a part of Xdin in the Alten 
Group. Soon we
will be working under the common brand name Xdin. Read more at www.xdin.com.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


git pull fails on linux-next (out of memory)

2012-03-30 Thread Arvid Brodin
 inexact rename 
detection
fatal: Out of memory? mmap failed: Cannot allocate memory

$ free
 total   used   free sharedbuffers cached
Mem:998920 309376 689544  0  10200 177252
-/+ buffers/cache: 121924 876996
Swap:  2923788 1619562761832

$ git --version
git version 1.6.3.3


I cannot find anything useful using Google. It's not like I'm doing anything
complicated, nor is my machine very low on memory. Do I really have to 
re-clone
the repository and re-apply my patches every time I want to keep the repository
up-to-date? (I've had the same problem before and used that solution.)

Or is there some other way to do this? Perhaps there is a way to perform the 
pull
a little bit at a time, e.g. pull linux-next-20120313, linux-next-20120320 etc?


-- 
Arvid Brodin
Enea Services Stockholm AB - since February 16 a part of Xdin in the Alten
Group. Soon we will be working under the common brand Xdin. Read more at
www.xdin.com.

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


Re: git pull fails on linux-next (out of memory)

2012-03-30 Thread Arvid Brodin
Arvid Brodin wrote:
 On 2012-03-06, I cloned linux-next:
 
 $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
 linux-next-20120306
 
 
 I now want to update this repository before posting patches, to make sure
 they still apply cleanly. I first tried this on 20120328:
 
 $ git pull
 remote: Counting objects: 63784, done.
 remote: Compressing objects: 100% (13595/13595), done.
 remote: Total 45829 (delta 38421), reused 38448 (delta 31414)
 Receiving objects: 100% (45829/45829), 9.87 MiB | 209 KiB/s, done.
 Resolving deltas: 100% (38421/38421), completed with 5695 local objects.
From git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next
  + 5a377dc...bc6f15c akpm-end   - origin/akpm-end  (forced update)
055bf38..de8856d  akpm-start - origin/akpm-start
  + a568b5f...7734592 master - origin/master  (forced update)
055bf38..de8856d  stable - origin/stable
  * [new tag] next-20120328 - next-20120328
From git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next
  * [new tag] v3.3   - v3.3
  * [new tag] v3.3-rc7   - v3.3-rc7
 warning: too many files (created: 1625 deleted: 423), skipping inexact rename 
 detection
 warning: too many files (created: 5127 deleted: 1509), skipping inexact 
 rename detection
 warning: too many files (created: 1134 deleted: 655), skipping inexact rename 
 detection
 warning: too many files (created: 4816 deleted: 3510), skipping inexact 
 rename detection
 warning: too many files (created: 1004 deleted: 544), skipping inexact rename 
 detection
 warning: too many files (created: 1734 deleted: 1778), skipping inexact 
 rename detection
 warning: too many files (created: 1069 deleted: 608), skipping inexact rename 
 detection
 warning: too many files (created: 1070 deleted: 764), skipping inexact rename 
 detection
 warning: too many files (created: 757 deleted: 405), skipping inexact rename 
 detection
 warning: too many files (created: 980 deleted: 542), skipping inexact rename 
 detection
 fatal: inflateInit: out of memory (no message)
 
 
 I then forgot about it for a little while, doing other stuff. Tried it 
 again today:
 
 
 $ git pull
 remote: Counting objects: 16816, done.
 remote: Compressing objects: 100% (1595/1595), done.
 remote: Total 9491 (delta 7901), reused 9254 (delta 7678)
 Receiving objects: 100% (9491/9491), 2.53 MiB | 299 KiB/s, done.
 Resolving deltas: 100% (7901/7901), completed with 3010 local objects.
From git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next
  + bc6f15c...73bd151 akpm-end   - origin/akpm-end  (forced update)
de8856d..1c03658  akpm-start - origin/akpm-start
  + 7734592...1dc85fe master - origin/master  (forced update)
de8856d..1c03658  stable - origin/stable
  * [new tag] next-20120330 - next-20120330
 warning: too many files (created: 1625 deleted: 423), skipping inexact rename 
 detection
 warning: too many files (created: 5127 deleted: 1509), skipping inexact 
 rename detection
 warning: too many files (created: 1134 deleted: 655), skipping inexact rename 
 detection
 warning: too many files (created: 4816 deleted: 3510), skipping inexact 
 rename detection
 warning: too many files (created: 1004 deleted: 544), skipping inexact rename 
 detection
 warning: too many files (created: 1734 deleted: 1778), skipping inexact 
 rename detection
 warning: too many files (created: 1069 deleted: 608), skipping inexact rename 
 detection
 warning: too many files (created: 1070 deleted: 764), skipping inexact rename 
 detection
 warning: too many files (created: 757 deleted: 405), skipping inexact rename 
 detection
 warning: too many files (created: 1084 deleted: 773), skipping inexact rename 
 detection
 warning: too many files (created: 980 deleted: 542), skipping inexact rename 
 detection
 fatal: Out of memory? mmap failed: Cannot allocate memory
 
 $ git gc
 Counting objects: 2609985, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (392553/392553), done.
 Writing objects: 100% (2609985/2609985), done.
 Total 2609985 (delta 2197683), reused 2602739 (delta 2190459)
 
 $ git pull
 warning: too many files (created: 1625 deleted: 423), skipping inexact rename 
 detection
 warning: too many files (created: 5127 deleted: 1509), skipping inexact 
 rename detection
 warning: too many files (created: 1134 deleted: 655), skipping inexact rename 
 detection
 warning: too many files (created: 4816 deleted: 3510), skipping inexact 
 rename detection
 warning: too many files (created: 1004 deleted: 544), skipping inexact rename 
 detection
 warning: too many files (created: 1734 deleted: 1778), skipping inexact 
 rename detection
 warning: too many files (created: 1069 deleted: 608), skipping inexact rename 
 detection
 warning: too many files (created: 1070 deleted: 764), skipping inexact rename 
 detection
 warning: too many files (created: 757 deleted: 405), skipping inexact rename 
 detection
 warning: too many

Re: Build scatterlist covering a process' text segment?

2011-06-16 Thread Arvid Brodin
Mulyadi Santosa wrote:
 Hi...
 
 On Sat, May 28, 2011 at 04:58, Arvid Brodin arvid.bro...@enea.com wrote:
 Ok. And looking at e.g. sg_set_buf(), the scatterlist expects a kernel 
 virtual
 address (it uses virt_to_page() on its buf parameter internally, which
 requires a kernel virtual adress, if I understand correctly).

 There seems to be no way to map process adresses to kernel addresses. (Well I
 guess one could follow the page tables to get the physical page, and then map
 back to kernel space, but this only works as long as the memory is paged in.)
 Please correct me if I'm wrong.
 
 I am not good at it, but I think at the first place, you might use
 get_user_pages() (take a look here
 :http://lxr.linux.no/#linux+v2.6.39/mm/memory.c#L1703)
 
 then once you get the pointer to the  pages (and making sure they're
 pinned by get_user_pages), I think you just need to use kmap().
 
 I suggest to really observe that scatter gather function and see if
 address in kernel address space is really needed if not, you can
 avoid using kmap() completely.
 

Many thanks for that tip! I've been reading LDD3 (Linux Device Drivers 3rd
edition) and Understanding the Linux Kernel as well as searching google and
of course reading code for many hours, and nowhere has there been a mention of
get_user_pages()! Obviously I haven't been using the right search terms...

(Also, for some reason your mail didn't reach my inbox, so I only saw it a few
days ago when looking at a mail list archive.) 

Anyway, the code looks like this now (below), and seems to work on 2.7.37.6. It
will probably have problems on systems with  896 MiB and high memory enabled
though; I'm thinking the scatterlist functions won't handle virtual kernel
addresses?

Any ideas for improvements are welcome; especially if I'm doing something
stupid that risks a kernel panic.


static int proc_pid_text_checksum(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
{
int retval;

int text_size;
int nr_pages, nr_pages_mapped;
int i;
struct page **pages;

struct scatterlist *sgl, *sg;

u8 result[MD5_DIGEST_SIZE + 2];
struct crypto_hash *tfm;
struct hash_desc desc;

retval = 0;

if (!task-mm)
return -EINVAL;

text_size = task-mm-end_code - task-mm-start_code;
nr_pages = (text_size + PAGE_SIZE - 1)  PAGE_SHIFT;


/ User page code /

pages = kmalloc(nr_pages * sizeof(*pages), GFP_KERNEL);
if (!pages) {
retval = -ENOMEM;
goto err_pages;
}

down_read(task-mm-mmap_sem);
nr_pages_mapped = get_user_pages(current, task-mm,
task-mm-start_code, nr_pages, 0, 0, pages, NULL);
up_read(task-mm-mmap_sem);

if (nr_pages_mapped  nr_pages) {
retval = -EBUSY; /* Weird error code for this,
couldn't find any better */
goto err_mapped;
}


/ Scatterlist code /

sgl = kmalloc(nr_pages_mapped * sizeof(*sgl), GFP_KERNEL);
if (!sgl) {
retval = -ENOMEM;
goto err_sg;
}

sg_init_table(sgl, nr_pages_mapped);

for_each_sg(sgl, sg, nr_pages_mapped, i)
sg_set_page(sg, pages[i], (i  nr_pages_mapped) ? PAGE_SIZE :
text_size  ~PAGE_MASK, 0);


/ Crypto code /

tfm = crypto_alloc_hash(md5, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm)) {
retval = -ENOMEM;
goto err_crypto;
}

desc.tfm = tfm;
desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;

memset(result, 0, MD5_DIGEST_SIZE + 2);
retval = crypto_hash_digest(desc, sgl, text_size, result);
if (retval)
goto err_digest;

for (i = 0; i  MD5_DIGEST_SIZE; i++)
seq_printf(m, %02x, result[i]);
seq_printf(m, \n);


err_digest:
crypto_free_hash(tfm);

err_crypto:
kfree(sgl);
for (i = 0; i  nr_pages_mapped; i++)
put_page(pages[i]);

err_sg:
err_mapped:
kfree(pages);

err_pages:
return retval;
}


-- 
Arvid Brodin
Enea Services Stockholm AB

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


Re: Build scatterlist covering a process' text segment?

2011-05-27 Thread Arvid Brodin
Mulyadi Santosa wrote:
 On 26/05/2011, Arvid Brodin arvid.bro...@enea.com wrote:
 Am I correct in that the addresses in (struct task_struct).mm-start_code
 and
 -end_code belong to the address space of the process whose task_struct I'm
 looking
 at?
 
 
 I believe yes
 

Ok. And looking at e.g. sg_set_buf(), the scatterlist expects a kernel virtual
address (it uses virt_to_page() on its buf parameter internally, which
requires a kernel virtual adress, if I understand correctly).

There seems to be no way to map process adresses to kernel addresses. (Well I 
guess one could follow the page tables to get the physical page, and then map
back to kernel space, but this only works as long as the memory is paged in.)
Please correct me if I'm wrong.

Perhaps a better idea is to do_mmap() the exe_file, (struct 
mm_struct).exe_file?
I'm still confused about this though:

1) do_mmap() returns unsigned long - not the void * expected by sg_set_buf().
   Is this a sign that I'm again mixing different address spaces, or is it ok
   just to cast this?

2) I believe do_mmap() maps a file into the address space of the current 
process,
   and that this address space is also the one used in kernel space at any 
moment.
   Is this correct, or is there an additional, kernel-only memory space that I
   should map the file to instead? If so, how do I do that?


Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


Re: How to use the cryptographic API (e.g. md5 checksum)?

2011-05-27 Thread Arvid Brodin
Peter Teoh wrote:
 On Tue, May 24, 2011 at 6:43 AM, Arvid Brodin arvid.bro...@enea.com wrote:
 Hi,

 I want to perform an md5 checksum on a process' text segment (I create a file
 /proc/pid/text_checksum that, when read, should give the md5sum).

 The crypto api documentation (Documentation/crypto/api-intro.txt) seems to be
 quite lacking. The only example is:

tfm = crypto_alloc_hash(md5, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm))
fail();

/* ... set up the scatterlists ... */

desc.tfm = tfm;
desc.flags = 0;

if (crypto_hash_digest(desc, sg, 2, result))
fail();

crypto_free_hash(tfm);

 Looking at some existing code, I see usage of crypto_hash_init(),
 crypto_hash_final(), desc.flag set to CRYPTO_TFM_REQ_MAY_SLEEP,
 ... (e.g. in fs/ecryptfs/crypto.c). Does anybody know what they do? Do I need
 
 http://www.redhat.com/archives/dm-devel/2005-August/msg00058.html

Thanks, that explains the CRYPTO_TFM_REQ_MAY_SLEEP flag!


 to, or should I, use them? The functions are are declared in 
 include/linux/crypto.h
 as some kind of wrapper functions, but lack documentation. Also, Google has 
 not
 been my friend here.
 
 http://www.linuxjournal.com/article/6451?page=0,0


This link is one I've found before, and it really does not explain anything 
about the usage of crypto_hash_{digest,init,update,final}() as far as I can
see. So I'm still looking for help on this!


Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


Re: Build scatterlist covering a process' text segment?

2011-05-25 Thread Arvid Brodin
Arvid Brodin wrote:
 Hi,
 
 How do I build a scatterlist covering the text segment of a process? I have
 found (struct task_struct).mm-start_code and -end_code, that gives the 
 address
 (in some - unknown to me - address space) of the text segment. Since my try to
 convert these addresses to an sglist:
 
   sg_init_one(sg, task-mm-start_code, length);
 
 failed miserably, I'm guessing these addresses need to be converted to some
 address space compatible with sg_init_one()/sg_set_buf() before use? (I 
 probably
 need to search for pages containing these addresses?)
 

Am I correct in that the addresses in (struct task_struct).mm-start_code and
-end_code belong to the address space of the process whose task_struct I'm 
looking
at?

-- 
Arvid Brodin
Enea Services Stockholm AB

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


How to use the cryptographic API (e.g. md5 checksum)?

2011-05-23 Thread Arvid Brodin
Hi,

I want to perform an md5 checksum on a process' text segment (I create a file
/proc/pid/text_checksum that, when read, should give the md5sum).

The crypto api documentation (Documentation/crypto/api-intro.txt) seems to be
quite lacking. The only example is:

tfm = crypto_alloc_hash(md5, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm))
fail();

/* ... set up the scatterlists ... */

desc.tfm = tfm;
desc.flags = 0;

if (crypto_hash_digest(desc, sg, 2, result))
fail();

crypto_free_hash(tfm);

Looking at some existing code, I see usage of crypto_hash_init(),
crypto_hash_final(), desc.flag set to CRYPTO_TFM_REQ_MAY_SLEEP,
... (e.g. in fs/ecryptfs/crypto.c). Does anybody know what they do? Do I need
to, or should I, use them? The functions are are declared in 
include/linux/crypto.h
as some kind of wrapper functions, but lack documentation. Also, Google has not
been my friend here.

Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


Build scatterlist covering a process' text segment?

2011-05-23 Thread Arvid Brodin
Hi,

How do I build a scatterlist covering the text segment of a process? I have
found (struct task_struct).mm-start_code and -end_code, that gives the address
(in some - unknown to me - address space) of the text segment. Since my try to
convert these addresses to an sglist:

sg_init_one(sg, task-mm-start_code, length);

failed miserably, I'm guessing these addresses need to be converted to some
address space compatible with sg_init_one()/sg_set_buf() before use? (I probably
need to search for pages containing these addresses?)


Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


Debug kernel panic with gdb?

2011-03-24 Thread Arvid Brodin
Hi,

I'm trying to debug a kernel panic (something like this):

Unable to handle kernel NULL pointer dereference at virtual address 0014
ptbr = 93959000 pgd = 93a0a000
Oops: Kernel access of bad area, sig: 11 [#1]
FRAME_POINTER chip: 0x01f:0x1e82 rev 2
Modules linked in: ftdi_sio usbserial
PC is at isp1760_irq+0xda/0x7f0
LR is at isp1760_irq+0x492/0x7f0
pc : [901408be]lr : [90140c76]Not tainted
sp : 93aa399c  r12: fffe  r11: 
r10:   r9 : fffe  r8 : 
r7 : 93aa3a08  r6 : 93406400  r5 : 00820004  r4 : 0003
r3 : 0008  r2 : 0002  r1 : fffd  r0 : 93837000

Call trace:
 [90134abc] usb_hcd_irq+0x50/0x54
 [900383da] handle_IRQ_event+0x1e/0x40
 [90039098] handle_level_irq+0x78/0x8c
...

This is on an AVR32 platform, and I'm building the kernel myself (cross
compiling). The image is then converted to a uImage before being loaded
to the target. Is there a way to get the following to work in this context?

$ gdb arch/avr32/boot/images/vmlinux.elf 
...
Reading symbols from 
/home/.../linux-2.6.37/arch/avr32/boot/images/vmlinux.elf...done.
(gdb) list *isp1760_irq+0xda
0x9017ac36 is in isp1760_irq (include/linux/spinlock.h:285).
280 raw_spin_lock_init((_lock)-rlock);\
281 } while (0)
282 
283 static inline void spin_lock(spinlock_t *lock)
284 {
285 raw_spin_lock(lock-rlock);
286 }
287 
288 static inline void spin_lock_bh(spinlock_t *lock)
289 {


The problem is that the line reported is totally wrong (this being very 
unhelpful
and confusing indeed - it tool me awhile to realise this!). I've also tried to
use gdb from the avr32 toolchain with the same result.

Is there a way to get this to work?

Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


Re: inconsistent lock state on call to kmem_cache_zalloc()

2011-03-17 Thread Arvid Brodin
Daniel Baluta wrote:
 On Thu, Mar 17, 2011 at 10:59 PM, Arvid Brodin arvid.bro...@enea.com wrote:
 Hi,

 Daniel Baluta wrote:
 Hello,

 The call to kmem_cache_zalloc() never returns; the printk() text on the 
 line
 after is never displayed and the system locks up. The printk() om the line
 before displays.
 What flags are you passing to kmem_cache_zalloc?
 I'm using the flags passed to the urb_enqueue() function; a printk reveals
 the value is 16, which would be GFP_NOIO if I read include/linux/gfp.h 
 correctly.
 
 Hmm, I guess this is not quite OK. You hold a spinlock, and you can sleep
 while allocating memory.

I can see why this is not a good idea, and indeed using GFP_ATOMIC gets rid of 
the

=
[ INFO: inconsistent lock state ]
2.6.37 #116
-
inconsistent {IN-HARDIRQ-W} - {HARDIRQ-ON-W} usage.
...

message. Many thanks!

To the list in general:

Still, I would have expected some kind of You're sleeping while holding a
spinlock / with interrupts disabled! message (I have DEBUG_SPINLOCK_SLEEP
enabled), not a message from the lock debug code. Well... perhaps one of the
'W's in the message stands for wait? Also, the call stack in my original
mail shows the interrupt routine being called despite having disabled
interrupts - are they automatically enabled by functions that sleep?

 
 Daniel.

-- 
Arvid Brodin
Enea Services Stockholm AB

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


Another ISP1761 / FTDI / serial problem

2011-02-08 Thread Arvid Brodin
Hi!

I get weird problems when I use a null modem cable between the two ports 
on a FT232BM (2-port FTDI USB-to-serial converter) with an isp1761 host 
controller. The same thing does not happen with an EHCI host controller. 
Lengthy details follows:

With the EHCI host controller:
=

[Terminal 1]
$ cat /dev/ttyUSB1

[Terminal 2]
$ echo Something seems wrong here  /dev/ttyUSB0
$ echo Something seems wrong here  /dev/ttyUSB0

[Terminal 1]
Something seems wrong here

Something seems wrong here

^C
$

Observe the extra new line after the strings. I'm not sure if this is a 
bug in the ftdi driver, some other part of the serial subsystem, or if 
it is the result of some terminal setting; with a USB analyzer I observe 
the following sequence of packets (#-# == device-endpoint):

3-2 OUT: Something seems wrong here
3-2 OUT: 0x0D 0x0A
4-1 IN: 0x01 0x60 'S'
4-1 IN: 0x01 0x60 'o'
...
4-1 IN: 0x01 0x60 0x0D
4-1 IN: 0x01 0x60 0x0A
4-2 OUT: 'S' # The echo from the reading side starts here
4-2 OUT: 'o'
...
4-2 OUT: 0x0D 0x0A
4-2 OUT: 0x0D 0x0A # The newline pair is echoed twice - perhaps both 
'CR' and 'NL' are converted to CRNL in the echo?

Anyway, since 3-1 is never read, no feedback loop is created by the two 
echoing devices.


With the isp1761 host controller, driver from 2.6.35.7 backported to 
2.6.27.54 and modified for platform endianness:
=

[Terminal 1]
$ cat /dev/ttyUSB1

[Terminal 2]
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# echo This is isp1761 and something is wrong  /dev/ttyUSB0

[Terminal 1]
This is isp1761 and something is wrong

This is isp1761 and something is wrong

This is isp1761 and something is wrong

This is isp1761 and something is wrong

This is isp1761 and something is wrong

and something is wrong
(blank line x7)
This is isp1761 and something is wrong

^C
# echo This is isp1761 and something is wrong  /dev/ttyUSB0
# cat /dev/ttyUSB1
  is wrong
(blank line x30 ca)
TThis is isp1761 and something is wrong

^C
#

The exact look of the error differs, but it is quite easy to trigger by 
echoing text several times in a row; also breaking the cat execution, 
echoing some more text, and then starting cat again seems to trigger the 
error often.

On the bus the traffic looks something like this:

7-2 OUT: This is isp1761 and something is wrong
7-2 OUT: 0x0D
7-2 OUT: 0x0A (NAK) # The CRNL pair is split here and the NL is not 
directly accepted by the device
7-2 OUT: 0x0A (NAK)
Following this is lots and lots of 0x0A NAKs intermixed with traffic 
that looks quite like the EHCI case except that much of the traffic has 
to be re-sent lots of times before it is accepted. The 0x0A is finally 
accepted after all text has been received by 8-1 and echoed from 8-2. 
This exact pattern is repeated every time text is written to the serial 
port.

Device 8 receives the characters and echoes them back to 7-1 as in the 
EHCI case. But with isp1761, after a while device 7 for some reason 
starts echoing parts of the received echo-text back. My guess is that 
this should not happen since device 7 is never read from. Anyway, this 
creates a feedback loop which would be the source of the spurious 
characters in the cat run above and that sometimes is powerful enough 
to make the terminal unresponsible.

I've been trying to figure this thing out for a while now but quite 
frankly I'm stumped; I can't figure out where and why things goes wrong. 
Any ideas are welcome! Perhaps the NAK problem/bug triggers a 
problem/bug somewhere in linux' serial terminal code?

The terminal settings are the defaults and are the same during all 
examples above on both serial ports:

$ stty -a -F /dev/ttyUSB0
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = undef; 
eol2 = undef; swtch = undef;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; 
flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon 
-ixoff -iuclc -ixany -imaxbel
-iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 
vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop 
-echoprt echoctl echoke

$ stty -g -F /dev/ttyUSB0
500:5:cbd:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

--
Arvid Brodin
Enea Services Stockholm AB

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


Re: Another ISP1761 / FTDI / serial problem

2011-02-08 Thread Arvid Brodin
Sorry, this was intended for the linux-usb list.

-- 
Arvid

Arvid Brodin wrote:
 Hi!
 
 I get weird problems when I use a null modem cable between the two ports 
 on a FT232BM (2-port FTDI USB-to-serial converter) with an isp1761 host 
 controller. The same thing does not happen with an EHCI host controller. 
 Lengthy details follows:
 
 With the EHCI host controller:
 =
 
 [Terminal 1]
 $ cat /dev/ttyUSB1
 
 [Terminal 2]
 $ echo Something seems wrong here  /dev/ttyUSB0
 $ echo Something seems wrong here  /dev/ttyUSB0
 
 [Terminal 1]
 Something seems wrong here
 
 Something seems wrong here
 
 ^C
 $
 
 Observe the extra new line after the strings. I'm not sure if this is a 
 bug in the ftdi driver, some other part of the serial subsystem, or if 
 it is the result of some terminal setting; with a USB analyzer I observe 
 the following sequence of packets (#-# == device-endpoint):
 
 3-2 OUT: Something seems wrong here
 3-2 OUT: 0x0D 0x0A
 4-1 IN: 0x01 0x60 'S'
 4-1 IN: 0x01 0x60 'o'
 ...
 4-1 IN: 0x01 0x60 0x0D
 4-1 IN: 0x01 0x60 0x0A
 4-2 OUT: 'S' # The echo from the reading side starts here
 4-2 OUT: 'o'
 ...
 4-2 OUT: 0x0D 0x0A
 4-2 OUT: 0x0D 0x0A # The newline pair is echoed twice - perhaps both 
 'CR' and 'NL' are converted to CRNL in the echo?
 
 Anyway, since 3-1 is never read, no feedback loop is created by the two 
 echoing devices.
 
 
 With the isp1761 host controller, driver from 2.6.35.7 backported to 
 2.6.27.54 and modified for platform endianness:
 =
 
 [Terminal 1]
 $ cat /dev/ttyUSB1
 
 [Terminal 2]
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 
 [Terminal 1]
 This is isp1761 and something is wrong
 
 This is isp1761 and something is wrong
 
 This is isp1761 and something is wrong
 
 This is isp1761 and something is wrong
 
 This is isp1761 and something is wrong
 
 and something is wrong
 (blank line x7)
 This is isp1761 and something is wrong
 
 ^C
 # echo This is isp1761 and something is wrong  /dev/ttyUSB0
 # cat /dev/ttyUSB1
   is wrong
 (blank line x30 ca)
 TThis is isp1761 and something is wrong
 
 ^C
 #
 
 The exact look of the error differs, but it is quite easy to trigger by 
 echoing text several times in a row; also breaking the cat execution, 
 echoing some more text, and then starting cat again seems to trigger the 
 error often.
 
 On the bus the traffic looks something like this:
 
 7-2 OUT: This is isp1761 and something is wrong
 7-2 OUT: 0x0D
 7-2 OUT: 0x0A (NAK) # The CRNL pair is split here and the NL is not 
 directly accepted by the device
 7-2 OUT: 0x0A (NAK)
 Following this is lots and lots of 0x0A NAKs intermixed with traffic 
 that looks quite like the EHCI case except that much of the traffic has 
 to be re-sent lots of times before it is accepted. The 0x0A is finally 
 accepted after all text has been received by 8-1 and echoed from 8-2. 
 This exact pattern is repeated every time text is written to the serial 
 port.
 
 Device 8 receives the characters and echoes them back to 7-1 as in the 
 EHCI case. But with isp1761, after a while device 7 for some reason 
 starts echoing parts of the received echo-text back. My guess is that 
 this should not happen since device 7 is never read from. Anyway, this 
 creates a feedback loop which would be the source of the spurious 
 characters in the cat run above and that sometimes is powerful enough 
 to make the terminal unresponsible.
 
 I've been trying to figure this thing out for a while now but quite 
 frankly I'm stumped; I can't figure out where and why things goes wrong. 
 Any ideas are welcome! Perhaps the NAK problem/bug triggers a 
 problem/bug somewhere in linux' serial terminal code?
 
 The terminal settings are the defaults and are the same during all 
 examples above on both serial ports:
 
 $ stty -a -F /dev/ttyUSB0
 speed 9600 baud; rows 0; columns 0; line = 0;
 intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = undef; 
 eol2 = undef; swtch = undef;
 start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; 
 flush = ^O; min = 1; time = 0;
 -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon 
 -ixoff -iuclc -ixany -imaxbel
 -iutf8
 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 
 vt0 ff0
 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop 
 -echoprt echoctl echoke
 
 $ stty -g -F /dev/ttyUSB0
 500:5:cbd:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
 
 --
 Arvid Brodin
 Enea Services Stockholm AB
 
 ___
 Kernelnewbies

inconsistent lock state

2011-01-27 Thread Arvid Brodin
Hello,

I'm using spinlocks (spin_lock_irqsave() / spin_unlock_irqrestore()) to 
protect shared resources between softirq, hardirq and non-irq kernel 
contexts. When I configure PROVE_LOCKING I get

  =
[ INFO: inconsistent lock state ]
2.6.27.54 #148
-
inconsistent {softirq-on-W} - {in-softirq-W} usage.
khubd/85 [HC0[0]:SC1[1]:HE0:SE0] takes:
  (priv-lock){-+..}, at: [90152430] schedule_ptds+0x54/0x564
{softirq-on-W} state was registered at:
   [9003856e] trace_hardirqs_on_caller+0x92/0xc4
   [900385a8] trace_hardirqs_on+0x8/0xc
   [90058fc2] __slab_alloc+0xee/0x3e4
   [90059f9c] kmem_cache_alloc+0x30/0x70

etc...

I don't understand why. Assuming that {softirq-on-W} - {in-softirq-W} 
means that the problem is that the lock was taken in softirq on (irqs 
enabled) state, and at some later time in softirq context, then what is 
the problem? spin_lock_irqsave() disables irqs, right? So after the lock 
is taken in non-irq context, softirq cannot interrupt?

There are code paths like this:

{
spin_lock_irqsave(...);
...
spin_unlock()
...
spin_lock()
...
spin_unlock_irqrestore(...);
}

in both non-irq and softirq contexts. Could this be a problem? If I 
understand correctly, spin_lock() and spin_unlock() does not touch irq 
settings, so the usage above should be fine, right?

Thanks,
Arvid Brodin
Enea Services Stockholm AB

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


How to create dev files in sysfs?

2011-01-19 Thread Arvid Brodin
Hello,

How do I make my platform device a character device that
can be handled by udev?

Background:

I've written a driver for a very simple platform device (a jumper
connected to an input pin on the processor). Today I can read the status
of the pin through a driver attribute file in sysfs at:

/sys/devices/platform/msel/

As a learning experience I want to get udev to detect this device and
create a character device file under /dev for it, that I could read to
get the pin status. If I understand correctly, udev looks for files
named dev in sysfs, which contains the major and minor device numbers
which udev use to create the device node.

 From the kernel code it seems that ((struct platform_device *)
my_platform_device)-dev-devt would have to be set to contain the major
 minor device numbers when the device is created for a dev file to
appear, which is not possible in this case since the device is
registered in board setup code where it seems wrong to get device
numbers by calling call alloc_chrdev_region() (right?).

I found a few previous questions about this same problem in these
kernelnewbies threads:

http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg08461.html
http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg06807.html

Using that info, and looking at the hpet driver code, I initialised a
struct miscdevice and called misc_register(). This gives me a
/sys/class/misc/msel_chrdev/ folder with the required dev and
uevent files. udev also picks up this and creates the corresponding file
in /dev.


Is this the correct way to do this? One device for the hardware and
one or more devices for the userland interface(s)? Also, looking at my
desktop system, there's one device under /sys/devices/platform that also
has dev files:

/sys/devices/platform/serial8250/tty/ttyS1/dev
/sys/devices/platform/serial8250/tty/ttyS2/dev
/sys/devices/platform/serial8250/tty/ttyS3/dev

I notice that these dev files appear as subfolders under the platform
device's own folder, and not under /sys/class/. Perhaps this is more
correct? The source for 8250 is ~223K in 14 different files so I have
not been able to decode how they do this.

(Please CC me directly if you respond!)

Thanks for reading all this,
Arvid Brodin
Enea Services Stockholm AB



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