Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1424393 > unrolled thread

[BUG] act_ife: sleeping functions called in atomic context

Started byAlexey Khoroshilov <khoroshilov@ispras.ru>
First post2016-06-16 23:00 +0200
Last post2016-06-18 16:50 +0200
Articles 10 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [BUG] act_ife: sleeping functions called in atomic context Alexey Khoroshilov <khoroshilov@ispras.ru> - 2016-06-16 23:00 +0200
    Re: [BUG] act_ife: sleeping functions called in atomic context Cong Wang <xiyou.wangcong@gmail.com> - 2016-06-16 23:50 +0200
      Re: [BUG] act_ife: sleeping functions called in atomic context Jamal Hadi Salim <jhs@mojatatu.com> - 2016-06-17 02:40 +0200
        Re: [BUG] act_ife: sleeping functions called in atomic context Cong Wang <xiyou.wangcong@gmail.com> - 2016-06-17 04:20 +0200
          Re: [BUG] act_ife: sleeping functions called in atomic context Cong Wang <xiyou.wangcong@gmail.com> - 2016-06-17 07:40 +0200
            Re: [BUG] act_ife: sleeping functions called in atomic context Alexey Khoroshilov <khoroshilov@ispras.ru> - 2016-06-17 13:10 +0200
              Re: [BUG] act_ife: sleeping functions called in atomic context Cong Wang <xiyou.wangcong@gmail.com> - 2016-06-17 19:20 +0200
            Re: [BUG] act_ife: sleeping functions called in atomic context Jamal Hadi Salim <jhs@mojatatu.com> - 2016-06-17 13:10 +0200
              Re: [BUG] act_ife: sleeping functions called in atomic context Cong Wang <xiyou.wangcong@gmail.com> - 2016-06-17 19:40 +0200
                Re: [BUG] act_ife: sleeping functions called in atomic context Jamal Hadi Salim <jhs@mojatatu.com> - 2016-06-18 16:50 +0200

#1424393 — [BUG] act_ife: sleeping functions called in atomic context

FromAlexey Khoroshilov <khoroshilov@ispras.ru>
Date2016-06-16 23:00 +0200
Subject[BUG] act_ife: sleeping functions called in atomic context
Message-ID<rKMym-4B7-3@gated-at.bofh.it>
tcf_ife_init() contains a big chunk of code executed with
ife->tcf_lock spinlock held. But that code contains several calls
to sleeping functions:
  populate_metalist() and use_all_metadata()
    -> add_metainfo()
      -> find_ife_oplist(metaid)
        -> read_lock()
        -> try_module_get(o->owner)
      -> kzalloc(sizeof(*mi), GFP_KERNEL);
      -> ops->alloc(mi, metaval);
      -> module_put(ops->owner);
  _tcf_ife_cleanup()
    -> module_put()

The same problem is actual for tcf_ife_cleanup() as well.

Found by Linux Driver Verification project (linuxtesting.org).

--
Alexey Khoroshilov
Linux Verification Center, ISPRAS
web: http://linuxtesting.org

[toc] | [next] | [standalone]


#1424480

FromCong Wang <xiyou.wangcong@gmail.com>
Date2016-06-16 23:50 +0200
Message-ID<rKNkK-5aq-39@gated-at.bofh.it>
In reply to#1424393
On Thu, Jun 16, 2016 at 1:50 PM, Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> tcf_ife_init() contains a big chunk of code executed with
> ife->tcf_lock spinlock held. But that code contains several calls
> to sleeping functions:
>   populate_metalist() and use_all_metadata()
>     -> add_metainfo()
>       -> find_ife_oplist(metaid)
>         -> read_lock()
>         -> try_module_get(o->owner)
>       -> kzalloc(sizeof(*mi), GFP_KERNEL);

Hmm, we don't need to hold that spinlock when we create a new ife action,
since we haven't inserted it yet. We do need it when we modify an existing
one. So I am thinking if we can refactor that code to avoid spinlock
whenever possible.

>       -> ops->alloc(mi, metaval);
>       -> module_put(ops->owner);
>   _tcf_ife_cleanup()
>     -> module_put()
>
> The same problem is actual for tcf_ife_cleanup() as well.
>

Huh? Both module_put() and kfree() should not sleep, right?

[toc] | [prev] | [next] | [standalone]


#1424565

FromJamal Hadi Salim <jhs@mojatatu.com>
Date2016-06-17 02:40 +0200
Message-ID<rKPZf-7Fj-29@gated-at.bofh.it>
In reply to#1424480

[Multipart message — attachments visible in raw view] — view raw

On 16-06-16 05:43 PM, Cong Wang wrote:
> On Thu, Jun 16, 2016 at 1:50 PM, Alexey Khoroshilov
> <khoroshilov@ispras.ru> wrote:
>> tcf_ife_init() contains a big chunk of code executed with
>> ife->tcf_lock spinlock held. But that code contains several calls
>> to sleeping functions:
>>    populate_metalist() and use_all_metadata()
>>      -> add_metainfo()
>>        -> find_ife_oplist(metaid)
>>          -> read_lock()
>>          -> try_module_get(o->owner)
>>        -> kzalloc(sizeof(*mi), GFP_KERNEL);
>
> Hmm, we don't need to hold that spinlock when we create a new ife action,
> since we haven't inserted it yet. We do need it when we modify an existing
> one. So I am thinking if we can refactor that code to avoid spinlock
> whenever possible.
>

Does attached (compile tested) patch help?

>>        -> ops->alloc(mi, metaval);
>>        -> module_put(ops->owner);
>>    _tcf_ife_cleanup()
>>      -> module_put()
>>
>> The same problem is actual for tcf_ife_cleanup() as well.
>>
>
> Huh? Both module_put() and kfree() should not sleep, right?
>

I dont think there is any sleeping there ;->

cheers,
jamal

[toc] | [prev] | [next] | [standalone]


#1424614

FromCong Wang <xiyou.wangcong@gmail.com>
Date2016-06-17 04:20 +0200
Message-ID<rKRy2-ov-13@gated-at.bofh.it>
In reply to#1424565
On Thu, Jun 16, 2016 at 5:38 PM, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> On 16-06-16 05:43 PM, Cong Wang wrote:
>>
>> On Thu, Jun 16, 2016 at 1:50 PM, Alexey Khoroshilov
>> <khoroshilov@ispras.ru> wrote:
>>>
>>> tcf_ife_init() contains a big chunk of code executed with
>>> ife->tcf_lock spinlock held. But that code contains several calls
>>> to sleeping functions:
>>>    populate_metalist() and use_all_metadata()
>>>      -> add_metainfo()
>>>        -> find_ife_oplist(metaid)
>>>          -> read_lock()
>>>          -> try_module_get(o->owner)
>>>        -> kzalloc(sizeof(*mi), GFP_KERNEL);
>>
>>
>> Hmm, we don't need to hold that spinlock when we create a new ife action,
>> since we haven't inserted it yet. We do need it when we modify an existing
>> one. So I am thinking if we can refactor that code to avoid spinlock
>> whenever possible.
>>
>
> Does attached (compile tested) patch help?

You at least miss the unlock in load_metaops_and_vet()?

I think we can just remove that tcf_lock, I am testing a patch now.

[toc] | [prev] | [next] | [standalone]


#1424683

FromCong Wang <xiyou.wangcong@gmail.com>
Date2016-06-17 07:40 +0200
Message-ID<rKUFA-2px-43@gated-at.bofh.it>
In reply to#1424614

[Multipart message — attachments visible in raw view] — view raw

On Thu, Jun 16, 2016 at 7:14 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> I think we can just remove that tcf_lock, I am testing a patch now.

Please try the attached patch, I will do more tests tomorrow.

Thanks!

[toc] | [prev] | [next] | [standalone]


#1424941

FromAlexey Khoroshilov <khoroshilov@ispras.ru>
Date2016-06-17 13:10 +0200
Message-ID<rKZOV-5LU-11@gated-at.bofh.it>
In reply to#1424683
On 17.06.2016 08:38, Cong Wang wrote:
> On Thu, Jun 16, 2016 at 7:14 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>>
>> I think we can just remove that tcf_lock, I am testing a patch now.
> 
> Please try the attached patch, I will do more tests tomorrow.
> 
> Thanks!
> 

Looks good with two notes:
1. add_metainfo() still contains
ret = ops->alloc(mi, metaval);
that allocates memory with GFP_KERNEL.
So, I would add gfpflag argument to alloc() operation.

2. It makes sense to mention ife_mod_lock in the comment before
add_metainfo(), because ife_mod_lock is the reason to use GFP_ATOMIC there.

--
Alexey

[toc] | [prev] | [next] | [standalone]


#1425332

FromCong Wang <xiyou.wangcong@gmail.com>
Date2016-06-17 19:20 +0200
Message-ID<rL5AZ-W1-3@gated-at.bofh.it>
In reply to#1424941
On Fri, Jun 17, 2016 at 4:05 AM, Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> On 17.06.2016 08:38, Cong Wang wrote:
>> On Thu, Jun 16, 2016 at 7:14 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>>>
>>> I think we can just remove that tcf_lock, I am testing a patch now.
>>
>> Please try the attached patch, I will do more tests tomorrow.
>>
>> Thanks!
>>
>
> Looks good with two notes:
> 1. add_metainfo() still contains
> ret = ops->alloc(mi, metaval);
> that allocates memory with GFP_KERNEL.
> So, I would add gfpflag argument to alloc() operation.

I thought about this too, but we just allocate 32+ bytes here,
not sure if it is really worth to pass a gfp flag.

>
> 2. It makes sense to mention ife_mod_lock in the comment before
> add_metainfo(), because ife_mod_lock is the reason to use GFP_ATOMIC there.

Don't worry, it is in a separated patch, I will explain this
in the changelog. (I sent a combined patch just for review/tests.)

Thanks!

[toc] | [prev] | [next] | [standalone]


#1424942

FromJamal Hadi Salim <jhs@mojatatu.com>
Date2016-06-17 13:10 +0200
Message-ID<rKZOV-5LU-9@gated-at.bofh.it>
In reply to#1424683
On 16-06-17 01:38 AM, Cong Wang wrote:
> On Thu, Jun 16, 2016 at 7:14 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>>
>> I think we can just remove that tcf_lock, I am testing a patch now.
>
> Please try the attached patch, I will do more tests tomorrow.
>
> Thanks!
>

Cong, What tree are you using? I dont see the time aggregation patches
that I sent (and Dave took in) in your changes.

Comments:
Is GFP_ATOMIC really necessary? Thats user->kernel interface. GFP_KERNEL 
should be sufficient.
Also, it would be nice to kill the lock - but this feels like two
patches in one. 1) to fix the alloc not to be under the lock 2) to
kill said lock. Maybe split it as such for easier review.
I am using this action extensively so will be happy to test.
I think my patch is a good beginning to #1 - if you fix the forgotten
unlock and ensure we lock around updating ife fields when it exists
already (you said it in your earlier email and I thought about
that afterwards).

cheers,
jamal

[toc] | [prev] | [next] | [standalone]


#1425349

FromCong Wang <xiyou.wangcong@gmail.com>
Date2016-06-17 19:40 +0200
Message-ID<rL5Um-12z-23@gated-at.bofh.it>
In reply to#1424942
On Fri, Jun 17, 2016 at 4:07 AM, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> On 16-06-17 01:38 AM, Cong Wang wrote:
>>
>> On Thu, Jun 16, 2016 at 7:14 PM, Cong Wang <xiyou.wangcong@gmail.com>
>> wrote:
>>>
>>>
>>> I think we can just remove that tcf_lock, I am testing a patch now.
>>
>>
>> Please try the attached patch, I will do more tests tomorrow.
>>
>> Thanks!
>>
>
> Cong, What tree are you using? I dont see the time aggregation patches
> that I sent (and Dave took in) in your changes.

My patch is against -net. (I see you already figured out your patch is
missing in -net-next.)

Or are you suggesting to rebase it for -net-next? I think it fixes some real
bug so -net is better, although it is slightly large as a bug fix.

>
> Comments:
> Is GFP_ATOMIC really necessary? Thats user->kernel interface. GFP_KERNEL
> should be sufficient.

I added a read_lock(ife_mod_lock), this is why we need
GFP_ATOMIC.

Again, don't worry, this change should be in a separated patch,
you will not miss it again when I send them formally. ;)


> Also, it would be nice to kill the lock - but this feels like two
> patches in one. 1) to fix the alloc not to be under the lock 2) to
> kill said lock. Maybe split it as such for easier review.
> I am using this action extensively so will be happy to test.
> I think my patch is a good beginning to #1 - if you fix the forgotten
> unlock and ensure we lock around updating ife fields when it exists
> already (you said it in your earlier email and I thought about
> that afterwards).

Yes, it makes sense too. Your patch is smaller, if you plan to
backport it to stable, we can use your patch for -net  and -stable
and I am happy to rebase mine for -net-next.

I am fine with either way.

Thanks!

[toc] | [prev] | [next] | [standalone]


#1425734

FromJamal Hadi Salim <jhs@mojatatu.com>
Date2016-06-18 16:50 +0200
Message-ID<rLpJo-5ix-5@gated-at.bofh.it>
In reply to#1425349

[Multipart message — attachments visible in raw view] — view raw

On 16-06-17 01:31 PM, Cong Wang wrote:

> My patch is against -net. (I see you already figured out your patch is
> missing in -net-next.)
>

Ok, should have re-read this email before working on the patch;->

> Or are you suggesting to rebase it for -net-next? I think it fixes some real
> bug so -net is better, although it is slightly large as a bug fix.
>

I am conflicted. There are a lot of changes in net-next at the moment;
adding this to -net seems like will definetely cause merge issues for
Dave.

Ok, Cong - patch attached and tested. Let me know what you think.

cheers,
jamal


[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web