* [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names
@ 2017-05-23 19:42 Mike Marciniszyn
0 siblings, 0 replies; 5+ messages in thread
From: Mike Marciniszyn @ 2017-05-23 19:42 UTC (permalink / raw)
To: stable; +Cc: linux-rdma, stable-commits
From: Tadeusz Struk <tadeusz.struk@intel.com>
commit 62eed66e98b4c2286fef2ce5911d8d75b7515f7b upstream.
Protect the global dev_cntr_names and port_cntr_names with the global
mutex as they are allocated and freed in a function called per device.
Otherwise there is a danger of double free and memory leaks.
Cc: stable <stable@vger.kernel.org> # v4.11
Fixes: Commit b7481944b06e ("IB/hfi1: Show statistics counters under IB stats interface")
Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: Easwar Hariharan <easwar.hariharan@intel.com>
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
---
v2 - fix upstream commit id
drivers/infiniband/hw/hfi1/verbs.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
index 16ef7b1..1c67745 100644
--- a/drivers/infiniband/hw/hfi1/verbs.c
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -1524,6 +1524,7 @@ static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str,
"DRIVER_EgrHdrFull"
};
+static DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */
static const char **dev_cntr_names;
static const char **port_cntr_names;
static int num_driver_cntrs = ARRAY_SIZE(driver_cntr_names);
@@ -1578,6 +1579,7 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
{
int i, err;
+ mutex_lock(&cntr_names_lock);
if (!cntr_names_initialized) {
struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
@@ -1586,8 +1588,10 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
num_driver_cntrs,
&num_dev_cntrs,
&dev_cntr_names);
- if (err)
+ if (err) {
+ mutex_unlock(&cntr_names_lock);
return NULL;
+ }
for (i = 0; i < num_driver_cntrs; i++)
dev_cntr_names[num_dev_cntrs + i] =
@@ -1601,10 +1605,12 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
if (err) {
kfree(dev_cntr_names);
dev_cntr_names = NULL;
+ mutex_unlock(&cntr_names_lock);
return NULL;
}
cntr_names_initialized = 1;
}
+ mutex_unlock(&cntr_names_lock);
if (!port_num)
return rdma_alloc_hw_stats_struct(
@@ -1823,9 +1829,13 @@ void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
del_timer_sync(&dev->mem_timer);
verbs_txreq_exit(dev);
+ mutex_lock(&cntr_names_lock);
kfree(dev_cntr_names);
kfree(port_cntr_names);
+ dev_cntr_names = NULL;
+ port_cntr_names = NULL;
cntr_names_initialized = 0;
+ mutex_unlock(&cntr_names_lock);
}
void hfi1_cnp_rcv(struct hfi1_packet *packet)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names
@ 2017-05-23 19:44 Mike Marciniszyn
2017-05-23 19:55 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Mike Marciniszyn @ 2017-05-23 19:44 UTC (permalink / raw)
To: stable; +Cc: linux-rdma, stable-commits
From: Tadeusz Struk <tadeusz.struk@intel.com>
commit 62eed66e98b4c2286fef2ce5911d8d75b7515f7b upstream.
Protect the global dev_cntr_names and port_cntr_names with the global
mutex as they are allocated and freed in a function called per device.
Otherwise there is a danger of double free and memory leaks.
Cc: stable <stable@vger.kernel.org> # v4.10
Fixes: Commit b7481944b06e ("IB/hfi1: Show statistics counters under IB stats interface")
Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: Easwar Hariharan <easwar.hariharan@intel.com>
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
---
v2 - fix upstream commit id.
drivers/infiniband/hw/hfi1/verbs.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
index 6002aa9..5105b95 100644
--- a/drivers/infiniband/hw/hfi1/verbs.c
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -1605,6 +1605,7 @@ static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str,
"DRIVER_EgrHdrFull"
};
+static DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */
static const char **dev_cntr_names;
static const char **port_cntr_names;
static int num_driver_cntrs = ARRAY_SIZE(driver_cntr_names);
@@ -1659,6 +1660,7 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
{
int i, err;
+ mutex_lock(&cntr_names_lock);
if (!cntr_names_initialized) {
struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
@@ -1667,8 +1669,10 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
num_driver_cntrs,
&num_dev_cntrs,
&dev_cntr_names);
- if (err)
+ if (err) {
+ mutex_unlock(&cntr_names_lock);
return NULL;
+ }
for (i = 0; i < num_driver_cntrs; i++)
dev_cntr_names[num_dev_cntrs + i] =
@@ -1682,10 +1686,12 @@ static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
if (err) {
kfree(dev_cntr_names);
dev_cntr_names = NULL;
+ mutex_unlock(&cntr_names_lock);
return NULL;
}
cntr_names_initialized = 1;
}
+ mutex_unlock(&cntr_names_lock);
if (!port_num)
return rdma_alloc_hw_stats_struct(
@@ -1903,9 +1909,13 @@ void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
del_timer_sync(&dev->mem_timer);
verbs_txreq_exit(dev);
+ mutex_lock(&cntr_names_lock);
kfree(dev_cntr_names);
kfree(port_cntr_names);
+ dev_cntr_names = NULL;
+ port_cntr_names = NULL;
cntr_names_initialized = 0;
+ mutex_unlock(&cntr_names_lock);
}
void hfi1_cnp_rcv(struct hfi1_packet *packet)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names
2017-05-23 19:44 Mike Marciniszyn
@ 2017-05-23 19:55 ` Greg KH
2017-05-23 19:59 ` Marciniszyn, Mike
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2017-05-23 19:55 UTC (permalink / raw)
To: Mike Marciniszyn; +Cc: stable, linux-rdma, stable-commits
On Tue, May 23, 2017 at 03:44:29PM -0400, Mike Marciniszyn wrote:
> From: Tadeusz Struk <tadeusz.struk@intel.com>
>
> commit 62eed66e98b4c2286fef2ce5911d8d75b7515f7b upstream.
>
> Protect the global dev_cntr_names and port_cntr_names with the global
> mutex as they are allocated and freed in a function called per device.
> Otherwise there is a danger of double free and memory leaks.
>
> Cc: stable <stable@vger.kernel.org> # v4.10
Why resend this???
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names
2017-05-23 19:55 ` Greg KH
@ 2017-05-23 19:59 ` Marciniszyn, Mike
2017-05-23 20:06 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Marciniszyn, Mike @ 2017-05-23 19:59 UTC (permalink / raw)
To: Greg KH
Cc: stable@vger.kernel.org, linux-rdma@vger.kernel.org,
stable-commits@vger.kernel.org
> > Cc: stable <stable@vger.kernel.org> # v4.10
>
> Why resend this???
There are two patches, one for 4.10 and one for 4.11.
Each of the v2's should have had a different version on the stable cc line in the signoff block.
Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names
2017-05-23 19:59 ` Marciniszyn, Mike
@ 2017-05-23 20:06 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2017-05-23 20:06 UTC (permalink / raw)
To: Marciniszyn, Mike
Cc: stable@vger.kernel.org, linux-rdma@vger.kernel.org,
stable-commits@vger.kernel.org
On Tue, May 23, 2017 at 07:59:21PM +0000, Marciniszyn, Mike wrote:
> > > Cc: stable <stable@vger.kernel.org> # v4.10
> >
> > Why resend this???
>
> There are two patches, one for 4.10 and one for 4.11.
>
> Each of the v2's should have had a different version on the stable cc line in the signoff block.
But I already emailed you saying, 4.10 is end-of-life, no one is doing
anything with it, so why resend it?
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-05-23 20:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 19:42 [PATCH v2] IB/hfi1: Protect the global dev_cntr_names and port_cntr_names Mike Marciniszyn
-- strict thread matches above, loose matches on Subject: below --
2017-05-23 19:44 Mike Marciniszyn
2017-05-23 19:55 ` Greg KH
2017-05-23 19:59 ` Marciniszyn, Mike
2017-05-23 20:06 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).