Received: by 10.213.65.68 with SMTP id h4csp2147246imn; Sun, 8 Apr 2018 20:56:41 -0700 (PDT) X-Google-Smtp-Source: AIpwx49IVFeuV5LWpVgqj0wtsevK0tijkALPkDmp6kznuIms0RRLQ7xYBQLaGCLVz0IlErfQFHa3 X-Received: by 2002:a17:902:4001:: with SMTP id b1-v6mr36468675pld.273.1523246201910; Sun, 08 Apr 2018 20:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523246201; cv=none; d=google.com; s=arc-20160816; b=IVHbp4G+pXAlHtLzgkHnMcBFTV7wheuIwGuvpc1M9rNbL+kkQxX/Xn2BGgcKhWi4pL Mnt6BxKbUWE5oN9lWCbHoCcnTLNLx4HEmRqFnqvL2OSAaJv0GwxhwU27Tti0VV5LiPnq U0I3nN7tW+js4tT0+G0zUsgTt/48VL1pcYf3X9ISqEn64gDgjqHfdbzqjq0SejWU05d1 13c7MSKfUh8HCaujTS50I1LMtcReVup8G7PP7UKKPXKP4eNNoKwbUfmrGAVfLUZtbPxN N4s2JnmJFcQSs2EGU0wDQhFQuZLa9enzSaiLqKPRrI75kY6VFaeFo6s53GRTK/TRTzgc GnnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Y15dqUYV6z0EUpgzIGUpKOsJgSGCgtRXk1KsZ8ud9UE=; b=I+1w8CGupy8E1W81LBWBGbIpOErIwpJqzBxgRWHyRVpI/6+UROI/Jx6oWEmggm4Ib3 GVYzMcfzenr0EpGLOdQDeomA67NwS0oxsdbzis/iXXyBnF9u6agS7JwhiTZ+7aG/Uuix 0gZybaorXYTj/vV1tng7XhTmEklA8It0ywDjmdMT7FlqClqKqfOhGDUNnJC1XK0JtntI G/4F0466L6ADc3U9MEGhV4+n7xUFf4p0jzF95fPIiLaX9CjMmiYNEVo2C2e45uSPFjZt ECGD93UmCz3yof8cyVcJTL89vBaw9DUPFp469JsBi6VCEE8ALnK+kYSTOO/yOD5rMZH1 2POw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=YwJk3dAg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si10394025pgu.454.2018.04.08.20.56.05; Sun, 08 Apr 2018 20:56:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=YwJk3dAg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754521AbeDIDuf (ORCPT + 99 others); Sun, 8 Apr 2018 23:50:35 -0400 Received: from mail-bn3nam01on0100.outbound.protection.outlook.com ([104.47.33.100]:20288 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754055AbeDIAT3 (ORCPT ); Sun, 8 Apr 2018 20:19:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Y15dqUYV6z0EUpgzIGUpKOsJgSGCgtRXk1KsZ8ud9UE=; b=YwJk3dAgl+n1eYTLSioO82HexxXPZwamR8/20mo9mqp6DWjAhbQBhgajxyGcwsyCLEunY1qtCS9dFaNOe/DH6eTBtfeJdbcAi9yJ3dP3yUVLJ3nRTpV3Y+/JObMYKpMtJjgSuSnC61lrBz1nIjiPGnFS2Dt9qmc7dWynDM3rSdg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1063.namprd21.prod.outlook.com (52.132.128.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:19:23 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:19:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Logan Gunthorpe , Jon Mason , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 106/189] ntb_hw_switchtec: Check for alignment of the buffer in mw_set_trans() Thread-Topic: [PATCH AUTOSEL for 4.15 106/189] ntb_hw_switchtec: Check for alignment of the buffer in mw_set_trans() Thread-Index: AQHTz5g94RiWsAj6lUin796tWIIR3g== Date: Mon, 9 Apr 2018 00:18:09 +0000 Message-ID: <20180409001637.162453-106-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1063;7:Viq8ArFNVnSr0QlCZhtV3kQecmc3dl46xHCEmFwghDDLfa5qt/ONSRG/jmYrRvH2mKgbwBuKWn6zlSnA+o+59/yTnIphNoY8narPYv+5HKAKv8g42xnmK7LfOd2cd5oIZ3XNqHI+LKBHlgstAay0reHDtqYxOr+0r7i1J36M6GckulgqmYiG6zOICW0SmBODrDzGCkgkEsarcSIHCA6D1uherjICU546IcDkLyV2G514TgxuC2P/MfSeltks6o4H;20:sPTg/th+7KlVLUAOzaUOgaIoec9t9CpZD5lcT6JTbfvUicC+ugUTCIY+Nb4dnFNYQoJNQYQpIWerLA2uVY3oHHkMtCF6HtXNWHORC0agv2no/egbhROQ+C5cJ3Lguzt1zMKngmzVpaBeKqlyG69bEket3jfMf9SqoRnWILvdAsE= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: d57f589f-dca4-407f-2db7-08d59daf8bb8 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1063; x-ms-traffictypediagnostic: DM5PR2101MB1063: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1063;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1063; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(376002)(396003)(366004)(189003)(199004)(2900100001)(6436002)(7736002)(10090500001)(102836004)(3660700001)(6506007)(76176011)(305945005)(4326008)(5250100002)(97736004)(26005)(25786009)(6512007)(2906002)(81166006)(106356001)(107886003)(68736007)(14454004)(86612001)(66066001)(10290500003)(59450400001)(6666003)(5660300001)(81156014)(478600001)(476003)(486006)(6486002)(72206003)(3280700002)(99286004)(105586002)(36756003)(1076002)(2616005)(11346002)(53936002)(446003)(8676002)(186003)(3846002)(54906003)(6116002)(2501003)(8936002)(316002)(110136005)(575784001)(86362001)(22452003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1063;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 7CIGUlCQvFtjILvFZdKVBIBBDlzQFjgQHHuWkFDKIT6UQAgJa799tDXa3RObnV9ic0Fi/dJ07sB1zdji2rN4OqcIacqKo4kdBt/UtAeGYnhbokhxAqv2MPZoPMo7w68fgRZPS4MdTU/ToYBdab1ThbzcEq8eHySH2/82X0ztQzL0UfnSnpoaCjDR0N4CEEj5iTGiQkFLfY/OKKh2aqeBn5AGs6HmCFShFmll5u51xNfAriPbbL/rcpkG7GM6KeBrqAS0WDl348+L0R2jECBP1FhyspVIoc5zfmJ/q71jMQWUPSXQ6+HHQvMKAhJqbKLLr9swxnI2tP5nUNKnxdxlO1ZJhMooiNcLQMYCS0WwfLbuDfCj4uvQDcvAjTcDdpKbApnfkEtryyXcf/rwcwYJMPpoUwQ+T2D0+/kMqwWdszI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d57f589f-dca4-407f-2db7-08d59daf8bb8 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:09.6625 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1063 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Logan Gunthorpe [ Upstream commit 1e2fd202f8593985cdadca32e0c322f98e7fe7cb ] With Switchtec hardware, the buffer used for a memory window must be aligned to its size (the hardware only replaces the lower bits). In certain circumstances dma_alloc_coherent() will not provide a buffer that adheres to this requirement like when using the CMA and CONFIG_CMA_ALIGNMENT is set lower than the buffer size. When we get an unaligned buffer mw_set_trans() should return an error. We also log an error so we know the cause of the problem. Signed-off-by: Logan Gunthorpe Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/n= tb_hw_switchtec.c index ca0334a6b759..fc9ce0a31c04 100644 --- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c +++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c @@ -315,6 +315,19 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *= ntb, int pidx, int widx, if (xlate_pos < 12) return -EINVAL; =20 + if (!IS_ALIGNED(addr, BIT_ULL(xlate_pos))) { + /* + * In certain circumstances we can get a buffer that is + * not aligned to its size. (Most of the time + * dma_alloc_coherent ensures this). This can happen when + * using large buffers allocated by the CMA + * (see CMA_CONFIG_ALIGNMENT) + */ + dev_err(&sndev->stdev->dev, + "ERROR: Memory window address is not aligned to it's size!\n"); + return -EINVAL; + } + rc =3D switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK, NTB_CTRL_PART_STATUS_LOCKED); if (rc) --=20 2.15.1