From patchwork Tue May 17 05:16:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 9109391 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF2619F1C1 for ; Tue, 17 May 2016 05:17:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04F8920279 for ; Tue, 17 May 2016 05:17:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 819FB201C0 for ; Tue, 17 May 2016 05:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751369AbcEQFRN (ORCPT ); Tue, 17 May 2016 01:17:13 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:34660 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750963AbcEQFRN (ORCPT ); Tue, 17 May 2016 01:17:13 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u4H5H0VG022351 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 May 2016 05:17:01 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u4H5H08Q021381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 May 2016 05:17:00 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u4H5GvmQ013911; Tue, 17 May 2016 05:16:59 GMT Received: from shamir-net-srv.us.oracle.com (/10.211.3.248) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 May 2016 22:16:57 -0700 From: shamir.rabinovitch@oracle.com To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, dledford@redhat.com, sean.hefty@intel.com, hal.rosenstock@gmail.com, shamir.rabinovitch@oracle.com Subject: [PATCH v2 1/1] IB/mlx4: Unaligned access in send_reply_to_slave Date: Tue, 17 May 2016 01:16:38 -0400 Message-Id: <1463462198-15674-1-git-send-email-shamir.rabinovitch@oracle.com> X-Mailer: git-send-email 1.7.1 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shamir Rabinovitch The problem is that the function 'send_reply_to_slave' get the 'req_sa_mad' as pointer whose address can be unaligned to 8 bytes. In this case the compiler cannot know in advance what will be the alignment of the 'data' field. Sowmini Varadhan pointed to this reply from Dave Miller that say that memcpy should not be used to solve alignment issues: https://lkml.org/lkml/2015/10/21/352 The reason why memcpy works here is because we memcpy someting that is bigger then 8 bytes and so the compiler cannot optimize this to 'ldx' instruction. Signed-off-by: Shamir Rabinovitch --- drivers/infiniband/hw/mlx4/mcg.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c index 99451d8..180f76b 100644 --- a/drivers/infiniband/hw/mlx4/mcg.c +++ b/drivers/infiniband/hw/mlx4/mcg.c @@ -319,8 +319,9 @@ static int send_reply_to_slave(int slave, struct mcast_group *group, struct ib_sa_mad *req_sa_mad, u16 status) { struct ib_sa_mad mad; + struct ib_sa_mcmember_data req_data; struct ib_sa_mcmember_data *sa_data = (struct ib_sa_mcmember_data *)&mad.data; - struct ib_sa_mcmember_data *req_sa_data = (struct ib_sa_mcmember_data *)&req_sa_mad->data; + struct ib_sa_mcmember_data *req_sa_data = &req_data; int ret; memset(&mad, 0, sizeof mad); @@ -343,6 +344,11 @@ static int send_reply_to_slave(int slave, struct mcast_group *group, /* reconstruct VF's requested join_state and port_gid */ sa_data->scope_join_state &= 0xf0; sa_data->scope_join_state |= (group->func[slave].join_state & 0x0f); + BUILD_BUG_ON(sizeof(req_sa_mad->data) < sizeof(req_data)); + /* req_sa_mad is packed structure whose start address is not + * aligned to 8 + */ + memcpy(&req_data, &req_sa_mad->data, sizeof(req_data)); memcpy(&sa_data->port_gid, &req_sa_data->port_gid, sizeof req_sa_data->port_gid); ret = send_mad_to_slave(slave, group->demux, (struct ib_mad *)&mad);