From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D9ADC4320A for ; Thu, 19 Aug 2021 16:48:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FDD3610A5 for ; Thu, 19 Aug 2021 16:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229804AbhHSQsg (ORCPT ); Thu, 19 Aug 2021 12:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbhHSQsg (ORCPT ); Thu, 19 Aug 2021 12:48:36 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865C1C061575 for ; Thu, 19 Aug 2021 09:47:59 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id bk29so2078374qkb.8 for ; Thu, 19 Aug 2021 09:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PRHyIH4ijXf+mY+7Vzztn6Pqcrl1CNKx+frAJCQ2Has=; b=dvp/j6HxEOhxjJeYtRuITNLUFUiXaR12Gjf8/ktdKok1mdPSqBAuwZQe5cZNMP2mDW 3XfbKhK5yP5sXbvvgiRAJLySLRNXDSdWgdpIlJ+p1nb8B/xTAZATOdWzyKh3+ivgYCqx 8oZP3fpWWL1vXVtmf+rKQ6CTdO5XEJdXVeXt2fAqXtYhfo9t+pN17guOHmzXCrch0SjV BbcNWpQeXixu5hFl3i4TO87exvR7v19wOfyomnTLv0qVBV8dT8wAG8LfOqoP7y+u3kYd /SnsOmmjTd5AIZnCCCKduJeONImiY/HiZFdLHTFk9UNfDVqiBBtPTkZAeJw6idovNHIn m6lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PRHyIH4ijXf+mY+7Vzztn6Pqcrl1CNKx+frAJCQ2Has=; b=tzZp2RwqlZKy0n1YBGolf5NPL3MQjzF8c7fJNSdR3xdbJejHdaE6dMWEwQ4AvHeNny wArCK86QJHynLabVh6gH1Sz5Tw0QsdAllBOztpr0mUe9JzPTkaKJVHPR7XZEithhozpn Lmxjd+mTUJonUHRnZWth+QfMifEdcWs+lHdldnpVjdJn3Xom+Rpx0RcvU3m1ilUP8RjD DY1fsUC5UtOYhXgbZsxRZ8l7y8v/Bfr1B+sedvplYqS0MvBeqh4DnhtQgMaN1YYQKoeR ORc7+Lnk1Z+yCyceJ4Zekrc3fIzeFXOyO5Hhs6sUOfJGLU50Dzm8+sA68IhICgbMASXK bxsQ== X-Gm-Message-State: AOAM53246h6Q9vu8lsJnMylFORjQ4i37pc1/2W1V8zw4xKlkyrfj2js4 P9ya04jUNN9y2Z0rSxEbnEEUjA== X-Google-Smtp-Source: ABdhPJwj157bJQx4yOUhNfsxgTN1x3aSuRlBknKFgP45+xvMm65JsiwY8VNQc1a5fM1ZgYeoBo5u0g== X-Received: by 2002:a05:620a:1221:: with SMTP id v1mr4584134qkj.357.1629391678741; Thu, 19 Aug 2021 09:47:58 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id c67sm1770032qke.113.2021.08.19.09.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 09:47:58 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mGlCv-001See-95; Thu, 19 Aug 2021 13:47:57 -0300 Date: Thu, 19 Aug 2021 13:47:57 -0300 From: Jason Gunthorpe To: Kees Cook Cc: linux-kernel@vger.kernel.org, Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, "Gustavo A. R. Silva" , Greg Kroah-Hartman , Andrew Morton , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, Rasmus Villemoes , linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 56/63] RDMA/mlx5: Use struct_group() to zero struct mlx5_ib_mr Message-ID: <20210819164757.GS543798@ziepe.ca> References: <20210818060533.3569517-1-keescook@chromium.org> <20210818060533.3569517-57-keescook@chromium.org> <20210819122716.GP543798@ziepe.ca> <202108190916.7CC455DA@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202108190916.7CC455DA@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu, Aug 19, 2021 at 09:19:08AM -0700, Kees Cook wrote: > On Thu, Aug 19, 2021 at 09:27:16AM -0300, Jason Gunthorpe wrote: > > On Tue, Aug 17, 2021 at 11:05:26PM -0700, Kees Cook wrote: > > > In preparation for FORTIFY_SOURCE performing compile-time and run-time > > > field bounds checking for memset(), avoid intentionally writing across > > > neighboring fields. > > > > > > Add struct_group() to mark region of struct mlx5_ib_mr that should be > > > initialized to zero. > > > > > > Cc: Leon Romanovsky > > > Cc: Doug Ledford > > > Cc: Jason Gunthorpe > > > Cc: linux-rdma@vger.kernel.org > > > Signed-off-by: Kees Cook > > > drivers/infiniband/hw/mlx5/mlx5_ib.h | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h > > > index bf20a388eabe..f63bf204a7a1 100644 > > > +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h > > > @@ -644,6 +644,7 @@ struct mlx5_ib_mr { > > > struct ib_umem *umem; > > > > > > /* This is zero'd when the MR is allocated */ > > > + struct_group(cleared, > > > union { > > > /* Used only while the MR is in the cache */ > > > struct { > > > @@ -691,12 +692,13 @@ struct mlx5_ib_mr { > > > bool is_odp_implicit; > > > }; > > > }; > > > + ); > > > }; > > > > > > /* Zero the fields in the mr that are variant depending on usage */ > > > static inline void mlx5_clear_mr(struct mlx5_ib_mr *mr) > > > { > > > - memset(mr->out, 0, sizeof(*mr) - offsetof(struct mlx5_ib_mr, out)); > > > + memset(&mr->cleared, 0, sizeof(mr->cleared)); > > > } > > > > Why not use the memset_after(mr->umem) here? > > I can certainly do that instead. In this series I've tended to opt > for groupings so the position of future struct member additions are > explicitly chosen. (i.e. reducing the chance that a zeroing of the new > member be a surprise.) I saw the earlier RDMA patches where using other memset techniques though? Were there flex arrays or something that made groups infeasible? Jason