Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbdLEU5H (ORCPT ); Tue, 5 Dec 2017 15:57:07 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36179 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453AbdLEU5G (ORCPT ); Tue, 5 Dec 2017 15:57:06 -0500 X-Google-Smtp-Source: AGs4zMYBGYqqWhbJ9qrr7zTuDqjlQizRoyPzzXAf4XbmVzM1u1IXmz3XMCZIZwsRKZm2B8OwT8au5g== Date: Tue, 5 Dec 2017 23:57:11 +0300 From: Serge Semin To: Jon Mason Cc: Dave Jiang , "Hubbe, Allen" , "S-k, Shyam-sundar" , "Yu, Xiangliang" , Gary R Hook , Sergey.Semin@t-platforms.ru, linux-ntb , linux-kernel Subject: Re: [PATCH v2 03/15] NTB: Fix UB/bug in ntb_mw_get_align() Message-ID: <20171205205711.GK1701@mobilestation> References: <20171203191736.3399-1-fancer.lancer@gmail.com> <20171203191736.3399-4-fancer.lancer@gmail.com> <20171205175607.GD1701@mobilestation> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2549 Lines: 65 On Tue, Dec 05, 2017 at 01:08:44PM -0500, Jon Mason wrote: > On Tue, Dec 5, 2017 at 12:56 PM, Serge Semin wrote: > > On Tue, Dec 05, 2017 at 11:52:32AM -0500, Jon Mason wrote: > >> On Sun, Dec 3, 2017 at 2:17 PM, Serge Semin wrote: > >> > Simple (1 << pidx) operation causes undefined behaviour when > >> > pidx >= 32. It must be casted to u64 to match the actual return > >> > value of ntb_link_is_up() method, so to have all the possible > >> > peer indexes covered and to get rid of undefined behaviour. > >> > Additionally there are special macros in "linux/bitops.h" to perform > >> > the bit-set-shift operations, so it's recommended to have them used > >> > for proper bit setting. > >> > >> This looks good to me, but also seems like a bug fix. Please comment > >> on if this is not noticed. > >> > > > > The consequences of the bug isn't noticeable at the moment, but potentially > > it can be seen on the devices like Switchtec (when multi-portness is finally > > added). Anyway it's better to fix it now, than to wait for obvious bug. > > Additionally as I said the originator of the code should have used BIT_ULL > > instead of the pure bit shifting. > > This is more of a question of whether it should go into -stable and be > outside this patch set. If this is impossible to ever hit, then > including it here instead of fast tracking it in -stable is fine. > > Thanks, > Jon > Yeah, it can wait. Thanks, -Sergey > > > > Thanks, > > -Sergey > > > >> Thanks, > >> Jon > >> > >> > > >> > Signed-off-by: Serge Semin > >> > Reviewed-by: Logan Gunthorpe > >> > --- > >> > include/linux/ntb.h | 2 +- > >> > 1 file changed, 1 insertion(+), 1 deletion(-) > >> > > >> > diff --git a/include/linux/ntb.h b/include/linux/ntb.h > >> > index c1646f2c6344..488e586fb76c 100644 > >> > --- a/include/linux/ntb.h > >> > +++ b/include/linux/ntb.h > >> > @@ -764,7 +764,7 @@ static inline int ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int widx, > >> > resource_size_t *size_align, > >> > resource_size_t *size_max) > >> > { > >> > - if (!(ntb_link_is_up(ntb, NULL, NULL) & (1 << pidx))) > >> > + if (!(ntb_link_is_up(ntb, NULL, NULL) & BIT_ULL(pidx))) > >> > return -ENOTCONN; > >> > > >> > return ntb->ops->mw_get_align(ntb, pidx, widx, addr_align, size_align, > >> > -- > >> > 2.12.0 > >> >