From patchwork Fri Mar 16 03:18:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10286259 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 17049601BE for ; Fri, 16 Mar 2018 03:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0E2E28CED for ; Fri, 16 Mar 2018 03:18:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E416728CEF; Fri, 16 Mar 2018 03:18:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4994F28CED for ; Fri, 16 Mar 2018 03:18:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932955AbeCPDSd (ORCPT ); Thu, 15 Mar 2018 23:18:33 -0400 Received: from mail-ve1eur01on0088.outbound.protection.outlook.com ([104.47.1.88]:35664 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932832AbeCPDSc (ORCPT ); Thu, 15 Mar 2018 23:18:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=yldy1mhGNtAV6EiR2O0a/QeHhGG5k88Et/hRqsOxMyA=; b=chEfWRVcwYCyK+2BItE1d+5TN6A4kJ4rkwR9+I4PkHAarYpjl5g+aPkizh2sWg2DCQ9gMqiLC7SuIdFBl3f6SmCYTaFESVNxSY4sv4CB485fvrQJWdv02yEXwRuHVs+jdkso/1I632dryyny4NedqxmWra31sqPv+ZO4XFl2aio= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jgg@mellanox.com; Received: from mlx.ziepe.ca (174.3.196.123) by VI1PR0501MB2861.eurprd05.prod.outlook.com (2603:10a6:800:9a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Fri, 16 Mar 2018 03:18:28 +0000 Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1ewfsk-000444-WD; Thu, 15 Mar 2018 21:18:14 -0600 Date: Thu, 15 Mar 2018 21:18:14 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org, Selvin Xavier , Devesh Sharma , Somnath Kotur , Sriharsha Basavapatna Subject: [PATCH] RDMA/bnxt: Fix structure layout for bnxt_re_pd_resp Message-ID: <20180316031814.GA15450@ziepe.ca> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [174.3.196.123] X-ClientProxiedBy: MWHPR13CA0037.namprd13.prod.outlook.com (2603:10b6:300:95::23) To VI1PR0501MB2861.eurprd05.prod.outlook.com (2603:10a6:800:9a::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5221ddb9-2ea8-43cf-0ac3-08d58aec96da X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2861; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2861; 3:fM4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YDM5FaV98BAWdI8qU4pw9vLvlgGPPdP6pZpvB44fUkPdtcS9rEerXr0Z5CfLoZ67rrUx2iIs5p3x1HXndLEaaQf1KMAJGweBgq5iJwBKGaLl0Ci0AoTcW9OAZhuhwsuFwwSWh6bHbVV2qGuW5djN4eYrlDSUF55OxP+bpdTOISSmoPfyrDUqo7DTPLTpKDzboOHHjrert9aAatjtnQPOREGQbb1LofEQKPBXwiADxGrY4lggjOGOTFP7x50tWlRaue36QU/ltEmyaSd6AG2J13uUs9cIXm8R39OZ30p2L+HZ4CqzYNFbE0mP8mclN9eNUFkoI8HIOR+iWoTUI; 4:zOovjY9f8xLQ/IKW+cjPBhZYRM0CGhOlXqV1g0kpKhnk/WAZOAxCl0Unie0xhEZdW2Mpe/EtAON4OZMXb2kEnBV9onZD4Mq+nqpL+BMChxGseyUTeDf6rbSCkWQXvTXqCkrSnoPlZDna5iRD1FWW7/Rn1whASqfqrrMh6QEdArjCZdNTd/zGH+VgV1+F1xLhruvwFv1dpb4Tb9v1ycR9JK9Nxs+uP4E1aybOXzcFCYv7F2XM6LX18kC+iEZz8Kuo5MbQM7V9CWq32l10UJQHbQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501244)(52105095)(3002001)(10201501046)(6055026)(6041310)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR0501MB2861; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2861; X-Forefront-PRVS: 0613912E23 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(39380400002)(366004)(396003)(376002)(189003)(199004)(36756003)(9686003)(53936002)(33656002)(7736002)(305945005)(97736004)(81166006)(33896004)(81156014)(58126008)(3846002)(110136005)(8936002)(68736007)(50466002)(59450400001)(1076002)(9786002)(23726003)(8676002)(52116002)(9746002)(1857600001)(26005)(186003)(316002)(47776003)(16586007)(83796002)(5660300001)(57986006)(6116002)(2906002)(105586002)(106356001)(575784001)(86362001)(66066001)(386003)(46656002)(122856001)(478600001)(69596002)(18370500001)(24400500001)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2861; H:mlx.ziepe.ca; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2861; 23:zWkH+xHT28g6v3664o1549mJUCCnEqd9i0O1gWc?= =?us-ascii?Q?ZMXXjpApBb16Gm7hW5rVhBvLXG02hjFRQfpZq+Ir2NOtRQo9aD/f8/DEBzK0?= =?us-ascii?Q?7EYCofLONXS7ceYmRo09ELRNJlpliKGBH8cjmFNxgcyLBr0iJa2fnuA4uj5z?= =?us-ascii?Q?W0Ru9aBkrzTm3d6dir4QsbfHpaASAUT1gYEgl19MkN8hdiUtYLbWLbzqfFha?= =?us-ascii?Q?C/lXbFruQywkX2qe8jQjrJABUbZvsdHHDODaNYOb/5B4MpyL/Go+9THr2Tum?= =?us-ascii?Q?+VmtKp+7l+ABes0NvDphOt4dD8HFz7/kRGP876t31Hcz1fyp5XMHyquxHmbb?= =?us-ascii?Q?2ZhTBrk+wDSQp2vO9BaslZICT7qkE4vFyuiKhBaMI9lgyxJ6zNF1xUpJ7vN4?= =?us-ascii?Q?4K9FSdELQbd8dTRd1lMX88P9hu6dbfjdLBC6m9x7x2BlqcCI1N468ifayRgF?= =?us-ascii?Q?JwjJcE2ttmGhzimhIA/mJxnaJ98FrF49LNycJyTdziut6+LqCmS+lrA+O8+T?= =?us-ascii?Q?NvXwDA4O22ugBQOq3Qf7G7v8NhbqEOaSw+9lM7ubOm5ZMnYnZQ0cniW2Ip6J?= =?us-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2 X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2861; 6:jRA5rPU72Wf2RJl7+V/BYurMLd0XsXNaQPSvYWnqBLpLjtqDHZCN/7YafArs5Bz+1hBGEM5tMjcMyCAd6/q0N969X1sVMTtsw9ER4sPxJdK1kN5RcZyT5ehCV7J7UFHdaQ1O45ec+2+EzGCVbEKEC7ErMf8+rjltMDBJIFOix/GVH5koKN9ur6vhAle0KLFURR4aCoS3QRhKVJsZylicAx7YOwm8IyB+CBv76lk17DhKwCkhUW9O8zj86tlu8FjSIbouR7hXRjsYXH1Yluiniwl781gARbGL6qr1Af8ZMpsA/5Y5NpdRymddFw2Omo4DyEsvB4d67CsDY1qGeRZoWvvOqll82A57gJjUgDEwU6U=; 5:iUVUz42DuXSflCHAqdyhHHpzi6oJTvaz/jwo8PZrFVjViUrHMZTE5M1nmDWEyjF8F4iZZmvc69fIENe/XtsH3l7mxHy97arqCR8fMSvblkQsT5ABdwnTuACPt0655WbyXwUizaGlq0gqYwITz7O/SYhCbn7nAhQM28wvW5dKXiI=; 24:GIZoTcrsB6pIjCqL6NaydEwCsyVydXdWzN3DnvlwWyO365gv55D0zhC1S+M7pYdGwJVqxjK3UGaicEy0iMa8JFZSsAQSQEy89pnWEakXeoM=; 7:42cvSyrtdIxx+RIoA6FwNlykhkhMh/KLgsLIlLbBkDdHiBntD1E1fHGOHCAZcshKD7ncyQMpO6OLhVTwvodh9sfZyw1aDiowUg4xVl2bSPpdxbP0XeomoAWAHMSk+XoesOlnUYHrxFeNnZ6MLZFSL/IZwoRSQo24zWBw3IeajgR+t22Itixok9dOc9EAa1qA6+ys+glgGu1H1Mz8Tf9jgLJLeyOZykZE+k222rcZ7WQaicw5Aob8klHPrS5Uf2lp SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2018 03:18:28.8548 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5221ddb9-2ea8-43cf-0ac3-08d58aec96da X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2861 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP What is going on here is a bit subtle, in the kernel there is no problem because the struct is copied using copy_from_user, so it can safely have an 8 byte alignment, however in userspace it must be constructed by concatenation with the ib_uverbs_alloc_pd_resp struct. This is due to the required memory layout to execute the command. Since ibv_uverbs_alloc_pd_resp is only 4 bytes long, this causes misalignment, and the user space will experience an unexpected padding. Currently it works around this via pointer maths. Make everything more robust by having the compiler reduce the alignment of the struct to 4. The userspace has assertions to ensure this works properly in all situations. Signed-off-by: Jason Gunthorpe --- include/uapi/rdma/bnxt_re-abi.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) I almost had a stroke when I saw this in rdma-core: if (ibv_cmd_alloc_pd(ibvctx, &pd->ibvpd, &cmd, sizeof(cmd), &resp.resp, sizeof(resp))) goto out; pd->pdid = resp.pdid; dbr = *(uint64_t *)((uint32_t *)&resp + 3); Something that crazy didn't even deserve a comment?!? Anyhow, the new userspace support for the kabi structs detected this when I converted your driver, so at least that get tested.. Jason diff --git a/include/uapi/rdma/bnxt_re-abi.h b/include/uapi/rdma/bnxt_re-abi.h index db54115be0447a..df6c8d5bf0dab8 100644 --- a/include/uapi/rdma/bnxt_re-abi.h +++ b/include/uapi/rdma/bnxt_re-abi.h @@ -53,11 +53,16 @@ struct bnxt_re_uctx_resp { __u32 rsvd; }; +/* + * This struct is placed after the ib_uverbs_alloc_pd_resp struct, which is + * not 8 byted aligned. To avoid undesired padding in various cases we have to + * set this struct to packed. + */ struct bnxt_re_pd_resp { __u32 pdid; __u32 dpi; __u64 dbr; -}; +} __attribute__((packed,aligned(4))); struct bnxt_re_cq_req { __u64 cq_va;