All of lore.kernel.org
 help / color / mirror / Atom feed
From: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Mark Bloch <markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
	Jason Gunthorpe
	<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>,
	Steve Wise <swise-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>,
	Majd Dibbiny <majd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
	alonvi-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH 1/3] ib core: Make device counter infrastructure dynamic
Date: Mon, 16 May 2016 13:27:36 -0400	[thread overview]
Message-ID: <db1bf3dd-20b1-3f2f-eaa3-25e5e8aff35b@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1605161203010.26453-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 2366 bytes --]

On 05/16/2016 01:04 PM, Christoph Lameter wrote:
> On Mon, 16 May 2016, Doug Ledford wrote:
> 
>>>> Secondly, do *not* use a BUG_ON in this patch.  I saw at least two of
>>>> them.  There is nothing in this patch so serious that we should crash
>>>> the kernel.  Any failure here is something we can work around and keep
>>>> running.
>>>
>>> WARN_ON_ONCE then?
>> Yep.
> 
> BUILD_BUG_ON works even better once we have the enum. Revised patch
> follows:

There's still one BUG_ON.  See below...

> +static struct attribute_group *create_protocol_stats(struct ib_device *device,
> +						     struct kobject *kobj,
> +						     u8 port) {
> +	struct attribute_group *ag;
> +	struct rdma_protocol_stats stats = {0};

We allocated our struct on the stack.  We have a static length counter
array in this struct.

> +	u32 counters;
> +	u32 i;
> +	int ret;
> +
> +	ret = device->get_protocol_stats(device, &stats, port);

We then pass our struct to get_protocol_stats to fill out.

> +
> +	if (ret || !stats.name)
> +		return NULL;
> +
> +	ag = kzalloc(sizeof(*ag), GFP_KERNEL);
> +	if (!ag)
> +		return NULL;
> +
> +	ag->name = stats.dirname;
> +
> +	for (counters = 0; stats.name[counters]; counters++)
> +		;

We count how many names there are...

> +
> +	BUG_ON(counters > MAX_NR_PROTOCOL_STATS);

And we BUG_ON if there are more names than we allocated static counters
in our struct.  However, by now, it's too late.  The device's
get_protocol_stats function has already likely written beyond the end of
our array and smashed our stack.  Let's fix this another way entirely...


> +	/* Emsure we provided all values */

Typo in comment...

> +	BUILD_BUG_ON(NR_COUNTERS != (sizeof(names) / sizeof(char *)) - 1);

Here's where we ant to fix the problem.  We need a second BUILD_BUG_ON
that reads:

	BUILD_BUG_ON(NR_COUNTERS > MAX_NR_PROTOCOL_STATS);

Then we can safely reduce the size of the MAX_NR_PROTOCOL_STATS and know
that if we exceed our allocation, the build will fail and we can
increase it accordingly.  So in all of the get_stats routines we want
both build time checks to make sure that the counter structs are sized
appropriately and the name/enum list lengths match.


-- 
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
              GPG KeyID: 0E572FDD



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]

  parent reply	other threads:[~2016-05-16 17:27 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 15:54 [PATCH 0/3] Dynamically extendable device counter support Christoph Lameter
2016-03-15 15:54 ` [PATCH 1/3] ib core: Make device counter infrastructure dynamic Christoph Lameter
     [not found]   ` <20160315155455.173645653-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>
2016-03-16 15:47     ` Dennis Dalessandro
     [not found]       ` <20160316154738.GA26530-W4f6Xiosr+yv7QzWx2u06xL4W9x8LtSr@public.gmane.org>
2016-03-16 17:17         ` Christoph Lameter
     [not found]           ` <alpine.DEB.2.20.1603161213560.15010-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-03-16 17:45             ` Dennis Dalessandro
2016-03-17  7:23     ` Leon Romanovsky
     [not found]       ` <20160317072354.GB25216-2ukJVAZIZ/Y@public.gmane.org>
2016-03-17  8:17         ` Leon Romanovsky
     [not found]           ` <20160317081716.GD25216-2ukJVAZIZ/Y@public.gmane.org>
2016-03-18  1:57             ` Christoph Lameter
     [not found]               ` <alpine.DEB.2.20.1603172057030.18714-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-03-18  6:20                 ` Leon Romanovsky
     [not found]                   ` <20160318062009.GI25216-2ukJVAZIZ/Y@public.gmane.org>
2016-03-18 14:33                     ` Christoph Lameter
     [not found]                       ` <alpine.DEB.2.20.1603180932310.25235-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-03-18 15:51                         ` Leon Romanovsky
2016-03-18  1:56         ` Christoph Lameter
     [not found]           ` <alpine.DEB.2.20.1603172054540.18714-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-03-18  6:16             ` Leon Romanovsky
     [not found]               ` <20160318061659.GH25216-2ukJVAZIZ/Y@public.gmane.org>
2016-03-18 14:34                 ` Christoph Lameter
     [not found]                   ` <alpine.DEB.2.20.1603180933320.25235-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-03-18 15:42                     ` Leon Romanovsky
2016-05-13 19:18     ` Doug Ledford
     [not found]       ` <057c8ac8-1d34-e7b9-c0ad-91d805c81139-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-16 13:52         ` Christoph Lameter
     [not found]           ` <alpine.DEB.2.20.1605160851370.23895-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-16 15:43             ` Doug Ledford
     [not found]               ` <041c6da0-e022-2bd1-5f00-e569c077e154-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-16 17:04                 ` Christoph Lameter
     [not found]                   ` <alpine.DEB.2.20.1605161203010.26453-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-16 17:27                     ` Doug Ledford [this message]
     [not found]                       ` <db1bf3dd-20b1-3f2f-eaa3-25e5e8aff35b-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-16 17:49                         ` Christoph Lameter
     [not found]                           ` <alpine.DEB.2.20.1605161238560.10085-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-16 18:01                             ` Doug Ledford
     [not found]                               ` <102cd100-55f7-fa85-cd75-ba0db5b9fa34-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-17 14:19                                 ` Christoph Lameter
     [not found]                                   ` <alpine.DEB.2.20.1605170918080.9956-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-17 16:00                                     ` Doug Ledford
     [not found]                                       ` <3e9a3e19-58cb-c25f-89a1-f0e51df562d8-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-17 16:06                                         ` Steve Wise
2016-05-17 17:00                                         ` Jason Gunthorpe
     [not found]                                           ` <20160517170027.GC19976-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-17 17:34                                             ` Doug Ledford
     [not found]                                               ` <bc83cc75-aa2e-6fc6-e1c6-a0190b972013-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-18 17:25                                                 ` Jason Gunthorpe
     [not found]                                                   ` <20160518172542.GA15516-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-18 18:11                                                     ` Doug Ledford
     [not found]                                                       ` <12e991bc-aa9b-a8b0-3cd4-b56d58a44d60-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-18 18:17                                                         ` Steve Wise
2016-05-18 19:01                                                         ` Christoph Lameter
     [not found]                                                           ` <alpine.DEB.2.20.1605181401030.29313-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-18 20:27                                                             ` Steve Wise
2016-05-19 14:34                                                               ` Christoph Lameter
2016-05-19 19:24                                                               ` Doug Ledford
2016-05-18 21:11                                                         ` Jason Gunthorpe
2016-05-16 18:06                             ` Jason Gunthorpe
2016-05-16 18:27                             ` Steve Wise
2016-03-15 15:54 ` [PATCH 2/3] mlx4: Add support for protocol statistics Christoph Lameter
2016-03-15 15:54 ` [PATCH 3/3] mlx5: Implement new counter infrastructure Christoph Lameter
     [not found]   ` <20160315155455.397561811-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>
2016-05-13 19:18     ` Doug Ledford
     [not found]       ` <d01d42d9-08a8-968a-97f9-40188301170a-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-16 13:52         ` Christoph Lameter
     [not found]           ` <alpine.DEB.2.20.1605160852260.23895-wcBtFHqTun5QOdAKl3ChDw@public.gmane.org>
2016-05-16 15:44             ` Doug Ledford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db1bf3dd-20b1-3f2f-eaa3-25e5e8aff35b@redhat.com \
    --to=dledford-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=alonvi-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
    --cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=majd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=markb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=swise-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.