public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@leon.nu>
To: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>,
	Max Gurtovoy <maxg@mellanox.com>,
	matanb@mellanox.com, sagi@grimberg.me,
	linux-rdma@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] IB/core: Fix different types mix in ib_device_cap_flags structure values
Date: Tue, 31 May 2016 20:30:33 +0300	[thread overview]
Message-ID: <20160531173033.GC7477@leon.nu> (raw)
In-Reply-To: <20160531171306.GA6618@obsidianresearch.com>

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

On Tue, May 31, 2016 at 11:13:06AM -0600, Jason Gunthorpe wrote:
> On Tue, May 31, 2016 at 08:35:10AM -0700, Bart Van Assche wrote:
> > On 05/30/16 03:09, Max Gurtovoy wrote:
> > >ib_device_cap_flags 64-bit expansion caused a possible caps overlapping
> > >(depending on machine endianness) and made consumers read wrong device
> > >capabilities. For example IB_DEVICE_SG_GAPS_REG was falsely read by the
> > >iser driver causing it to use a non-existing capability. Fix this by
> > >casting ib_device_cap_flags enumerations to ULL.
> > >
> > > [ ... ]
> > >diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> > >[ ... ]
> > > enum ib_device_cap_flags {
> > >       [ ... ]
> > > 	IB_DEVICE_SG_GAPS_REG			= (1ULL << 32),
> > >      [ ... ]
> > > };
> > 
> > How can this patch make a difference? The presence of any constant
> > in an enum that does not fit in a 32-bit integer makes an enum 64
> > bits wide. In other words, all the changes from "1" into "1ULL" in
> > this patch do not have
> 
> The expressions are evaluated before the enum type is decided, the
> enum type has no impact on the type of the expressions.

It is machine/compiler dependent.

Bart,
Can you share your source of C-standard?

This link [1] states in chapter "6.7.2.2 Enumeration specifiers"

"Each enumerated type shall be compatible with char, a signed integer type,
or an unsigned integer type. The choice of type is implementation-defined (110),
but shall be capable of representing the values of all the members of the enumeration.
The enumerated type is incomplete until after the } that terminates the list of enumerator
declarations."

And the footnote (110):
"An implementation **may** delay the choice of which integer type until all enumeration
constants have been seen."

[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf


> 
> (1<<32) is always undefined behavior because '1' is only a 32 bit type.
> 
> I'm confused why we didn't get any static checker hits on the shift
> overflow - modern compilers warn on that??
> 
> Jason

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-05-31 17:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 10:09 [PATCH] IB/core: Fix different types mix in ib_device_cap_flags structure values Max Gurtovoy
2016-05-31 15:35 ` Bart Van Assche
2016-05-31 17:13   ` Jason Gunthorpe
2016-05-31 17:30     ` Leon Romanovsky [this message]
2016-05-31 18:05       ` Bart Van Assche
2016-05-31 18:12         ` Leon Romanovsky
2016-05-31 18:21           ` Jason Gunthorpe
2016-05-31 18:54             ` Leon Romanovsky
2016-05-31 19:39               ` Jason Gunthorpe
2016-06-01 12:04                 ` Max Gurtovoy
2016-06-01 15:35                   ` Sagi Grimberg
2016-05-31 18:43           ` Bart Van Assche
2016-05-31 18:16         ` Jason Gunthorpe
2016-05-31 15:36 ` Bart Van Assche
2016-05-31 19:14   ` Max Gurtovoy
2016-05-31 19:16 ` Robert LeBlanc

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=20160531173033.GC7477@leon.nu \
    --to=leon@leon.nu \
    --cc=bart.vanassche@sandisk.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=matanb@mellanox.com \
    --cc=maxg@mellanox.com \
    --cc=sagi@grimberg.me \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox