Skip to contentSkip to conversation

lightnvm: pblk: avoid ref warning on cache creation

PATCH In review Javier González 4 participants 9 messages Nov 22, 2018 – Nov 30, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

Matias,

Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.

Thanks,
Javier

Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

 drivers/lightnvm/pblk-init.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 lightnvm: pblk: avoid ref warning on cache creation

The current kref implementation around pblk global caches triggers a false positive on refcount_inc_checked() (when called) as the kref is initialized to 0. Instead of usint kref_inc() on a 0 reference, which is in principle correct, use kref_init() to avoid the check. This is also more explicit about what actually happens on cache creation.

In the process, do a small refactoring to use kref helpers.

---
 drivers/lightnvm/pblk-init.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/lightnvm/pblk-init.c +5 -9
index 13822594647c..e225bd60cbb4 100644
@@ -350,23 +350,19 @@ static int pblk_create_global_caches(void)
 
 static int pblk_get_global_caches(void)
 {
-	int ret;
+	int ret = 0;
 
 	mutex_lock(&pblk_caches.mutex);
 
-	if (kref_read(&pblk_caches.kref) > 0) {
-		kref_get(&pblk_caches.kref);
-		mutex_unlock(&pblk_caches.mutex);
-		return 0;
-	}
+	if (kref_get_unless_zero(&pblk_caches.kref))
+		goto out;
 
 	ret = pblk_create_global_caches();
-
 	if (!ret)
-		kref_get(&pblk_caches.kref);
+		kref_init(&pblk_caches.kref);
 
+out:
 	mutex_unlock(&pblk_caches.mutex);
-
 	return ret;
 }
 
Signature · 1 line
2.7.4
#4 lore raw
In reply to Javier González
Quoted 6 lines · Javier González

Matias,

Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.

Quoted 9 lines

Thanks,
Javier

Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

  drivers/lightnvm/pblk-init.c | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)

It is too late to get it for 4.20. I'll pull it in for 4.21.

We can put on a Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" if you want Greg and friends to pick picked it up for stable kernels?

#5 lore raw
Quoted 16 lines · Matias Bjørling
Quoted 10 lines · Javier González

Matias,
Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.
Thanks,
Javier
Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

Quoted 2 lines
 drivers/lightnvm/pblk-init.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
Quoted 1 line

It is too late to get it for 4.20. I'll pull it in for 4.21.

Well, if it is a fix it’s not too late AFAIK. It also applies to a patch picked up in this series. We should have catches this before.

But I guess it’s your call.

Quoted 2 lines

We can put on a Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" if you want Greg and friends to pick picked it up for stable kernels?

I didn’t add it as it is not a bug in itself. But it is good to add it. Can you do it.

Javier.

#6 lore raw
Quoted 16 lines · Javier Gonzalez
Quoted 16 lines · Matias Bjørling
Quoted 12 lines · Javier González

Matias,
Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.
Thanks,
Javier
Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

  drivers/lightnvm/pblk-init.c | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)
Quoted 5 lines
Quoted 1 line

It is too late to get it for 4.20. I'll pull it in for 4.21.

Well, if it is a fix it’s not too late AFAIK. It also applies to a patch picked up in this series. We should have catches this before.

But I guess it’s your call.

There is a likelihood that Linus would catch it, with the result of fire & fury. I don't feel like using one of my cat life's for this one.

Quoted 6 lines
Quoted 3 lines

We can put on a Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" if you want Greg and friends to pick picked it up for stable kernels?

I didn’t add it as it is not a bug in itself. But it is good to add it. Can you do it.

I'll do it.

Quoted 2 lines

Javier.

#7 lore raw
Quoted 19 lines · Matias Bjørling
Quoted 14 lines · Javier Gonzalez
Quoted 14 lines · Matias Bjørling
Quoted 12 lines · Javier González

Matias,
Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.
Thanks,
Javier
Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

 drivers/lightnvm/pblk-init.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It is too late to get it for 4.20. I'll pull it in for 4.21.

Well, if it is a fix it’s not too late AFAIK. It also applies to a patch picked up in this series. We should have catches this before. But I guess it’s your call.

There is a likelihood that Linus would catch it, with the result of fire & fury. I don't feel like using one of my cat life's for this one.

I don’t get how a fix in rc3 will result in Jens or Linus complaining. But Ok, let’s release 4.20 with a false positive warning for use-after-free on pblk creation.

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

We can put on a Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" if you want Greg and friends to pick picked it up for stable kernels?

I didn’t add it as it is not a bug in itself. But it is good to add it. Can you do it.

I'll do it.

Thanks.

Javier.

#8 lore raw
Quoted 19 lines · Javier Gonzalez
Quoted 19 lines · Matias Bjørling
Quoted 14 lines · Javier Gonzalez
Quoted 14 lines · Matias Bjørling
Quoted 12 lines · Javier González

Matias,
Can you pick this up for 4.20? Even though it is not an error per se, it does trigger an ugly false positive warning when CONFIG_REFCOUNT_FULL is set.
Thanks,
Javier
Javier González (1):
lightnvm: pblk: avoid ref warning on cache creation

  drivers/lightnvm/pblk-init.c | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It is too late to get it for 4.20. I'll pull it in for 4.21.

Well, if it is a fix it’s not too late AFAIK. It also applies to a patch picked up in this series. We should have catches this before. But I guess it’s your call.

There is a likelihood that Linus would catch it, with the result of fire & fury. I don't feel like using one of my cat life's for this one.

I don’t get how a fix in rc3 will result in Jens or Linus complaining. But Ok, let’s release 4.20 with a false positive warning for use-after-free on pblk creation.

It is a warning that would trigger only for kernel developers. The REFCOUNT_FULL is used when debugging code, and is usually not on in production kernels.

To my understanding, the rc's, are meant for errors that would affect end-users.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

We can put on a Fixes: 1864de94ec9d6 "lightnvm: pblk: stop recreating global caches" if you want Greg and friends to pick picked it up for stable kernels?

I didn’t add it as it is not a bug in itself. But it is good to add it. Can you do it.

I'll do it.

Thanks.

Javier.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Javier González

Great catch Javier! Nice refactoring work too.

Quoted 50 lines · Javier González

The current kref implementation around pblk global caches triggers a false positive on refcount_inc_checked() (when called) as the kref is initialized to 0. Instead of usint kref_inc() on a 0 reference, which is in principle correct, use kref_init() to avoid the check. This is also more explicit about what actually happens on cache creation.

In the process, do a small refactoring to use kref helpers.

---
 drivers/lightnvm/pblk-init.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/lightnvm/pblk-init.c +5 -10
index 13822594647c..e225bd60cbb4 100644
@@ -350,23 +350,19 @@ static int pblk_create_global_caches(void)
 
 static int pblk_get_global_caches(void)
 {
-       int ret;
+       int ret = 0;
 
        mutex_lock(&pblk_caches.mutex);
 
-       if (kref_read(&pblk_caches.kref) > 0) {
-               kref_get(&pblk_caches.kref);
-               mutex_unlock(&pblk_caches.mutex);
-               return 0;
-       }
+       if (kref_get_unless_zero(&pblk_caches.kref))
+               goto out;
 
        ret = pblk_create_global_caches();
-
        if (!ret)
-               kref_get(&pblk_caches.kref);
+               kref_init(&pblk_caches.kref);
 
+out:
        mutex_unlock(&pblk_caches.mutex);
-
        return ret;
 }
 
--

2.7.4

#3 lore raw
Quoted 51 lines · Hans Holmberg

Great catch Javier! Nice refactoring work too.

Quoted 47 lines · Javier González

The current kref implementation around pblk global caches triggers a false positive on refcount_inc_checked() (when called) as the kref is initialized to 0. Instead of usint kref_inc() on a 0 reference, which is in principle correct, use kref_init() to avoid the check. This is also more explicit about what actually happens on cache creation.

In the process, do a small refactoring to use kref helpers.

---
  drivers/lightnvm/pblk-init.c | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)
drivers/lightnvm/pblk-init.c +5 -9
index 13822594647c..e225bd60cbb4 100644
@@ -350,23 +350,19 @@ static int pblk_create_global_caches(void)
 
  static int pblk_get_global_caches(void)
  {
-       int ret;
+       int ret = 0;
 
         mutex_lock(&pblk_caches.mutex);
 
-       if (kref_read(&pblk_caches.kref) > 0) {
-               kref_get(&pblk_caches.kref);
-               mutex_unlock(&pblk_caches.mutex);
-               return 0;
-       }
+       if (kref_get_unless_zero(&pblk_caches.kref))
+               goto out;
 
         ret = pblk_create_global_caches();
-
         if (!ret)
-               kref_get(&pblk_caches.kref);
+               kref_init(&pblk_caches.kref);
 
+out:
         mutex_unlock(&pblk_caches.mutex);
-
         return ret;
  }
 
Quoted 3 lines
Quoted 3 lines

--
2.7.4

Picked up for 4.21.