Skip to contentSkip to conversation

workqueue: Remove unnecessary kfree() call in rcu_free_wq()

PATCH Applied [email protected] 5 participants 17 messages May 27, 2020 – May 28, 2020 1 message not in the archive

Subsystems (2)

v5 of 7 Applied Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 workqueue: Remove unnecessary kfree() call in rcu_free_wq()

From: Zhang Qiang <[email protected]>

The data structure member "wq->rescuer" was reset to a null pointer in one if branch. It was passed to a call of the function "kfree" in the callback function "rcu_free_wq" (which was eventually executed). The function "kfree" does not perform more meaningful data processing for a passed null pointer (besides immediately returning from such a call). Thus delete this function call which became unnecessary with the referenced software update.

Fixes def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()")

---
v1->v2->v3->v4->v5:
Modify weakly submitted information.

 kernel/workqueue.c | 1 -
 1 file changed, 1 deletion(-)
kernel/workqueue.c +0 -1
index 891ccad5f271..a2451cdcd503 100644
@@ -3491,7 +3491,6 @@ static void rcu_free_wq(struct rcu_head *rcu)
 	else
 		free_workqueue_attrs(wq->unbound_attrs);
 
-	kfree(wq->rescuer);
 	kfree(wq);
 }
 
Signature · 1 line
2.24.1
#1 lore raw
Quoted 2 lines

Thus delete this function call which became unnecessary with the referenced software update.

…

Quoted 1 line

Would the tag “Co-developed-by” be more appropriate according to the patch review to achieve a more pleasing commit message?

Quoted 2 lines

v1->v2->v3->v4->v5:
Modify weakly submitted information.

Now I wonder about your wording choice “weakly”.

Regards,
Markus

A message that is not in the archive (sent off-list or not yet received): DM6PR11MB32573F3884A864ECD586235EFF8E0@DM6PR11MB3257.namprd11.prod.outlook.com

#3 lore raw

VGhhbmtzIGZvciB5b3VyIGd1aWRlLg0KSSB3aWxsIHRyeSB0byBjaGFuZ2UgdGhlIHdlYWtuZXNz IG9mIHdlYWsgd29yZGluZy4NCg0KX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fXw0Kt6K8/sjLOiBaaGFuZywgUWlhbmcgPFFpYW5nLlpoYW5nQHd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vdmUgdW5uZWNlc3Nh cnkga2ZyZWUoKSBjYWxsIGluIHJjdV9mcmVlX3dxKCkNCg0KPiBUaHVzIGRlbGV0ZSB0aGlzIGZ1 bmN0aW9uIGNhbGwgd2hpY2ggYmVjYW1lIHVubmVjZXNzYXJ5IHdpdGggdGhlIHJlZmVyZW5jZWQN Cj4gc29mdHdhcmUgdXBkYXRlLg0Koa0NCj4gU3VnZ2VzdGVkLWJ5OiBNYXJrdXMgRWxmcmluZyA8 TWFya3VzLkVsZnJpbmdAd2ViLmRlPg0KDQpXb3VsZCB0aGUgdGFnIKGwQ28tZGV2ZWxvcGVkLWJ5 obEgYmUgbW9yZSBhcHByb3ByaWF0ZSBhY2NvcmRpbmcgdG8gdGhlIHBhdGNoIHJldmlldw0KdG8g YWNoaWV2ZSBhIG1vcmUgcGxlYXNpbmcgY29tbWl0IG1lc3NhZ2U/DQoNCg0KPiAgdjEtPnYyLT52 My0+djQtPnY1Og0KPiAgTW9kaWZ5IHdlYWtseSBzdWJtaXR0ZWQgaW5mb3JtYXRpb24uDQoNCk5v dyBJIHdvbmRlciBhYm91dCB5b3VyIHdvcmRpbmcgY2hvaWNlIKGwd2Vha2x5obEuDQoNClJlZ2Fy ZHMsDQpNYXJrdXMNCg=

#4 lore raw

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

regards,
dan carpenter

maintainer
#5 lore raw
Quoted 4 lines · Dan Carpenter

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

Oops, missed that. Reverting.

Thanks.

Signature · 1 line
tejun
#6 lore raw
Quoted 6 lines
Quoted 4 lines

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

Oops, missed that. Reverting.

Can it matter to use separate callback functions for these cases?
https://elixir.bootlin.com/linux/v5.7-rc7/C/ident/rcu_free_pwq

Regards,
Markus

reviewer
#8 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

I'm also confused why they have been debating about the changelog after the patch was queued. My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch. But the changelog is wrong, even after the lengthened debating, and English is not my mother tongue, so I just looked on.

#9 lore raw
Quoted 12 lines · Lai Jiangshan
Quoted 6 lines · Dan Carpenter

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

I'm also confused why they have been debating about the changelog after the patch was queued. My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

Quoted 7 lines

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

It looks like there are lots of paths which call put_pwq() and put_pwq_unlocked().

  1168  static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, int color)
  1169  {
  1170          /* uncolored work items don't participate in flushing or nr_active */
  1171          if (color = WORK_NO_COLOR)
  1172                  goto out_put;
  1173  

We don't take an extra reference in this function.

  1200  out_put:
  1201          put_pwq(pwq);
  1202  }

I don't know this code well, so I will defer to your expertise if you say it is correct.

Quoted 5 lines

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch. But the changelog is wrong, even after the lengthened debating, and English is not my mother tongue, so I just looked on.

We have tried to tell Markus not to advise people about commit messages but he doesn't listen. He has discouraged some contributors. :/

regards,
dan carpenter

reviewer
#10 lore raw
Quoted 32 lines · Dan Carpenter
Quoted 12 lines · Lai Jiangshan
Quoted 6 lines · Dan Carpenter

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

I'm also confused why they have been debating about the changelog after the patch was queued. My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

Quoted 7 lines

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

It looks like there are lots of paths which call put_pwq() and put_pwq_unlocked().

  1168  static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, int color)
  1169  {
  1170          /* uncolored work items don't participate in flushing or nr_active */
  1171          if (color = WORK_NO_COLOR)
  1172                  goto out_put;
  1173
Quoted 8 lines

We don't take an extra reference in this function.

  1200  out_put:
  1201          put_pwq(pwq);
  1202  }

I don't know this code well, so I will defer to your expertise if you say it is correct.

wq owns the ultimate or permanent references to itself by owning references to wq->numa_pwq_tbl[node], wq->dfl_pwq. The pwq's references keep the pwq in wq->pwqs.

Only destroy_workqueue() can release these ultimate references and then (after maybe a period of time) deplete the wq->pwqs finally and then free itself in rcu callback.

Actually, in short, we don't need the care about the above detail. The responsibility to free rescuer is on destroy_workqueue(), and since it does the free early, it doesn't need to do it again later.

e2dca7adff8f moved the free of rescuer into rcu callback, and I didn't check all the changes between then and now. But at least now, the rescuer is not accessed in rcu mananer, so we don't need to free it in rcu mananer.

Quoted 12 lines
Quoted 6 lines

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch. But the changelog is wrong, even after the lengthened debating, and English is not my mother tongue, so I just looked on.

We have tried to tell Markus not to advise people about commit messages but he doesn't listen. He has discouraged some contributors. :/

regards,
dan carpenter

maintainer
#11 lore raw

Hello,

Quoted 3 lines · Lai Jiangshan

wq owns the ultimate or permanent references to itself by owning references to wq->numa_pwq_tbl[node], wq->dfl_pwq. The pwq's references keep the pwq in wq->pwqs.

Yeah, regardless of who puts a wq the last time, the base reference is put by destroy_workqueue() and thus it's guaranteed that a wq can't be rcu freed without going through destroy_workqueue(). lol I'm undoing the revert.

Thanks.

Signature · 1 line
tejun
#12 lore raw
Quoted 3 lines

Yeah, regardless of who puts a wq the last time, the base reference is put by destroy_workqueue() and thus it's guaranteed that a wq can't be rcu freed without going through destroy_workqueue(). lol I'm undoing the revert.

* Would you like to add such background information to the change description?

* How do you think about integrate a following patch version after the extra clarification?

Regards,
Markus

#13 lore raw
In reply to Lai Jiangshan
Quoted 55 lines · Lai Jiangshan
Quoted 32 lines · Dan Carpenter
Quoted 12 lines · Lai Jiangshan
Quoted 6 lines · Dan Carpenter

Guys, the patch is wrong. The kfree is harmless when this is called from destroy_workqueue() and required when it's called from pwq_unbound_release_workfn(). Lai Jiangshan already explained this already. Why are we still discussing this?

I'm also confused why they have been debating about the changelog after the patch was queued. My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

Quoted 7 lines

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

It looks like there are lots of paths which call put_pwq() and put_pwq_unlocked().

  1168  static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, int color)
  1169  {
  1170          /* uncolored work items don't participate in flushing or nr_active */
  1171          if (color = WORK_NO_COLOR)
  1172                  goto out_put;
  1173
Quoted 8 lines

We don't take an extra reference in this function.

  1200  out_put:
  1201          put_pwq(pwq);
  1202  }

I don't know this code well, so I will defer to your expertise if you say it is correct.

wq owns the ultimate or permanent references to itself by owning references to wq->numa_pwq_tbl[node], wq->dfl_pwq. The pwq's references keep the pwq in wq->pwqs.

Only destroy_workqueue() can release these ultimate references and then (after maybe a period of time) deplete the wq->pwqs finally and then free itself in rcu callback.

Actually, in short, we don't need the care about the above detail. The responsibility to free rescuer is on destroy_workqueue(), and since it does the free early, it doesn't need to do it again later.

Quoted 5 lines

e2dca7adff8f moved the free of rescuer into rcu callback, and I didn't check all the changes between then and now. But at least now, the rescuer is not accessed in rcu mananer, so we don't need to free it in rcu mananer.

Ah... Thanks for the explanation!

regards,
dan carpenter

#14 lore raw
In reply to Dan Carpenter
Quoted 6 lines
Quoted 4 lines

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch. But the changelog is wrong, even after the lengthened debating, and English is not my mother tongue, so I just looked on.

We have tried to tell Markus not to advise people about commit messages

A few concerns were mentioned.

Quoted 1 line

but he doesn't listen.

I am still listening as usual.

I am offering constructive patch reviews for selected topics.

Quoted 1 line

He has discouraged some contributors. :/

There are the usual risks that additional views are occasionally not picked up in positive ways.

Regards,
Markus

#15 lore raw
In reply to Lai Jiangshan
Quoted 2 lines

I'm also confused why they have been debating about the changelog after the patch was queued.

I suggest to take another look at the provided patch review comments.

Quoted 2 lines

My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

The commit message was accordingly adjusted, wasn't it?

Quoted 10 lines

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch.

Thanks for such a feedback.

Quoted 1 line

But the changelog is wrong, even after the lengthened debating,

Do you expect any corresponding improvements?

Quoted 1 line

and English is not my mother tongue, so I just looked on.

How will the patch review evolve further despite of this information?

Regards,
Markus

#16 lore raw
In reply to Lai Jiangshan
Quoted 2 lines

I'm also confused why they have been debating about the changelog after the patch was queued.

I suggest to take another look at the provided patch review comments.

Quoted 2 lines

My statement was about "the patch is a correct cleanup, but the changelog is totally misleading".

The commit message was accordingly adjusted, wasn't it?

Quoted 10 lines

destroy_workqueue(percpu_wq) -> rcu_free_wq()
or
destroy_workqueue(unbound_wq) -> put_pwq() ->
pwq_unbound_release_workfn() -> rcu_free_wq()

So the patch is correct to me. Only can destroy_workqueue() lead to rcu_free_wq().

Still, the kfree(NULL) is harmless. But it is cleaner to have the patch.

Thanks for such a feedback.

Quoted 1 line

But the changelog is wrong, even after the lengthened debating,

Do you expect any corresponding improvements?

Quoted 1 line

and English is not my mother tongue, so I just looked on.

How will the patch review evolve further despite of this information?

Regards,
Markus

maintainer Applied
#17 lore raw
In reply to [email protected]
Quoted 10 lines · On Wed, May 27, 2020 at 03:57:15PM +0800, [email protected] wrote:

From: Zhang Qiang <[email protected]>

The data structure member "wq->rescuer" was reset to a null pointer in one if branch. It was passed to a call of the function "kfree" in the callback function "rcu_free_wq" (which was eventually executed). The function "kfree" does not perform more meaningful data processing for a passed null pointer (besides immediately returning from such a call). Thus delete this function call which became unnecessary with the referenced software update.

Quoted 4 lines
Fixes def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()")

Applied to wq/for-5.8.

Thanks.

Signature · 1 line
tejun