From patchwork Sun Mar 18 13:33:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Bloch X-Patchwork-Id: 10291153 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 93B42600F6 for ; Sun, 18 Mar 2018 13:33:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8456128FD3 for ; Sun, 18 Mar 2018 13:33:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78B7C28FDC; Sun, 18 Mar 2018 13:33:53 +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 00A7628FD3 for ; Sun, 18 Mar 2018 13:33:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753919AbeCRNdv (ORCPT ); Sun, 18 Mar 2018 09:33:51 -0400 Received: from mail-db5eur01on0079.outbound.protection.outlook.com ([104.47.2.79]:60803 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752372AbeCRNdt (ORCPT ); Sun, 18 Mar 2018 09:33:49 -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=4wv2jQpZe+tMygqulTdTK4gJiVWfJFKzD/uSUTkRtKg=; b=PLi+QI/o+KHWTc/YFMUGj8tRCMY9+jQYKMl2CnTYk67faODp3xaTma1ckF7k5O0H3GzMx0gi3hIY4xjxn1wMUdcZRbgNpYNWnlo8Vqoih77xdnyRQWLm+O92h8pK/g1e20ScoOds9Ae7ENsFlWmpBZP4/YpWfWShySXZ8YsfnQ4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=markb@mellanox.com; Received: from r-vrt-26-1.mtr.labs.mlnx (37.142.13.130) by AM3PR05MB1331.eurprd05.prod.outlook.com (2a01:111:e400:586e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Sun, 18 Mar 2018 13:33:45 +0000 From: Mark Bloch To: jgg@mellanox.com, dledford@redhat.com Cc: majd@mellanox.com, leonro@mellanox.com, linux-rdma@vger.kernel.org, clameter@jumptrading.com Subject: [RFC rdma-next 1/1] IB/core: Protect against concurrent access to hardware stats Date: Sun, 18 Mar 2018 13:33:32 +0000 Message-Id: <1521380012-64924-2-git-send-email-markb@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1521380012-64924-1-git-send-email-markb@mellanox.com> References: <1521380012-64924-1-git-send-email-markb@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR08CA0207.eurprd08.prod.outlook.com (2603:10a6:802:15::16) To AM3PR05MB1331.eurprd05.prod.outlook.com (2a01:111:e400:586e::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 95376435-1d75-4fed-52a8-08d58cd4e022 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:AM3PR05MB1331; X-Microsoft-Exchange-Diagnostics: 1; AM3PR05MB1331; 3:t1cxFHwAGxGq6nLJ036ElDDummH4tcavvUnvEr+V31sMi6fGrEf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LB1lxIzmYtURgYZtiRWcNbwwJUC2qOAfgA9GyWpQ6S+UN9Vmh/GfPXS2V9WdR9P7NKUwNa7HAicCMd5QsgvxDZhu6lIMi3/gFs8i0a8M0uFFzjjRXvRyxX+diYWoiOVneks8J/lQ9j0uHpw7Q32YxiKmLksf0UPkBTwIjH+BDqNqJm2z+xoG9G89iDgqFkiiqIIzPSwVcvmPfsM970eVT16FKV10IJDWXsAdcrm+7gTKL6pguxr84TmNW09gzRTVapPybpZmP3JTx/Z04CWjO/zcpsZzuXx; 4:5Kj4KqBJ2qR7NHAl0pZv+/PuzJTymGBHX/1AbJGkpnsSn8s1kDVl+LYs7Z9FH2aXMuW6ve3DX7WZL+spLdnuJvMY4jwxysPuHYr6Ct3aN1F+qnHdnJrDR4cDrVNGm8JsQWlJAneFlUVE07wVXxhjAI3m2Mwb0ydszU7ZLhWBPfdEChDiLu0liHhXPBAR6XpWo2wSkOqU+rakcZs0bOfRLeR6tX6paeoL1QSX68IIpO2L71BoJy601u+y4PV16fNHrio3n0D0FeBOTW33n+IiJQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(6055026)(6041310)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:AM3PR05MB1331; BCL:0; PCL:0; RULEID:; SRVR:AM3PR05MB1331; X-Forefront-PRVS: 06157D541C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39380400002)(396003)(39860400002)(366004)(346002)(189003)(199004)(386003)(4326008)(2906002)(50466002)(16586007)(48376002)(8936002)(25786009)(5660300001)(4720700003)(97736004)(8676002)(76176011)(2950100002)(26005)(6512007)(6506007)(59450400001)(316002)(478600001)(50226002)(16526019)(66066001)(68736007)(86362001)(3846002)(105586002)(6486002)(36756003)(53936002)(81156014)(106356001)(81166006)(6666003)(52116002)(305945005)(6116002)(47776003)(51416003)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR05MB1331; H:r-vrt-26-1.mtr.labs.mlnx; 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; AM3PR05MB1331; 23:3b5NA61BeWUdL/rWLdOqBv3ahP5yv5QO0vSqt21hS?= =?us-ascii?Q?sLpVShObDuW9TAn+xLtR7c4/++tkajLlFdzZWdDmBsVs8cbgmZNoZyxnihg5?= =?us-ascii?Q?eP5G+hxqZsgATEBXJ7Y/8AjXDV0HiUI3VeCDmkhGz+e4wLX7u9iQMdhMHhTO?= =?us-ascii?Q?oGXEfDJLESQWREa0+vkqc9zOI4xi4U0Z3NI0QSL5tesfgxyReDlliKOtMbpt?= =?us-ascii?Q?z5Bv72NBied/oJr7vPPQwWb8yF7aiQrbzXmYlTAMZY1lnquKxDzsHYrSe3zN?= =?us-ascii?Q?onRdG1BEgc0I9l4Mvq/t5EPaelUL9lmyxsI6ODkTbc1USrxYsF+v6p4Vz4Jj?= =?us-ascii?Q?kxvSipBp0aihIV0tq+kEeXZqqeU+J5NsD9kBuEO3EBG3tMeTWIorpTBMFjRG?= =?us-ascii?Q?oxjWUnCyi/0xUP5WEr/+X499FQpeenaNiaLyyk6XuZCnCLRldKYBXtSFswGa?= =?us-ascii?Q?TNMzGi+SFVBZ/QHDQCs6RSMl7EKK8+np3ZdBDpf33te/N7VMHfMlfqwdw599?= =?us-ascii?Q?3PSNj9C1Zae4PvaCkAuPTmkJj0/Fzzu4Th06l28fTd+iG4jgt89+lKHlVTK2?= =?us-ascii?Q?1CVlaLt5ILlGtvah/sLdP4nI06bfJyob4c+sl6SoIQFdhIQG0vOk7mhq3UsE?= =?us-ascii?Q?BeV/anUKMISFYSokEd+x1qNig0TzMmKw80okodI0c1O4wIrn+BOcC1UilmST?= =?us-ascii?Q?720JyM+1D8rqyFd/o4OZDBdu/NKPTy9xhkOR9884Vmp1RG9qM3WLOq2uILFv?= =?us-ascii?Q?tlVeTwJX4oN7Bf25qHP4SrKzQtK6SntcZ4ebKeZKBTBBVssN7yXwnXYsacWI?= =?us-ascii?Q?8dMhWAMRkoHHyZPVFWB9561C2p0GbeKpu808nBuHUqinkH5mqnLIW3+nbxYm?= =?us-ascii?Q?GJ2jtYQC9VrfiSps8UrbCTePJwby33FdmAj6IrPy01PbL76rlxzOwsEfJEiX?= =?us-ascii?Q?osaCnBlSzd6+Qoi/2zDn3Rdo4YSTOba/IcdLxYnj977xMv/Ej8aEvbg7xRlT?= =?us-ascii?Q?In9m8jkpt32JWI+auZm9NOM0R80QoVl9uIWsM0ghbIkiB7cTnR87bJrnWSgX?= =?us-ascii?Q?ZeFdxAb3IHF8UAoGutAr9t97YJqq6xsLAgJidLqQWp8QDDnnjwHEZ8qIrA0a?= =?us-ascii?Q?65DSmkxcio=3D?= X-Microsoft-Antispam-Message-Info: bOlGTUjca6vTKORQMiNLHaFpXPnbte9B/IaiNrpOKD4Uu9OhyjIMLOzosSiapfmPsg/YdEms9tVIuD8QN/hWBxHdHAdlLcZ5yScONHFtUqelm6WvYS3B1Ydys5Hfty1afDhZxsIPDShMbCfTdmSFUGtKOXQpV1/V985kBoR4Rb6uKVz+x59r3fAUO4B64APo X-Microsoft-Exchange-Diagnostics: 1; AM3PR05MB1331; 6:XUtaKjIa+xnl9XRZkLmsaq33erasydWyf2N9ISvf75LxkgSE45/hDbMJHVuP6srmcaC5TYapbY57RsRvmJ96lHPsKnARTz8X5+Gp+QXzhH+etZUwpEQpqi++oER98BqrSTuVxwf8O6YZo5ERDSC8Xa80iaqsI2rtWFQwmt8SsuT9n31fLJi01Q8zOzICTxOxmxCNfQKcxrN+S/W1lhL7lDtvESvoi0iz6gBRT5CBDudA7f+u1UCfFHqEIBRF+Qa5vLCD+eamK5oDMFW96P4lSt/rw+IgbklNOeLlZ8SNlR10J2iAIjAr7M8kyLnoNDNIRv56yMo7C07jmSRfbBzKPLtdsJhmQ0L5oTlPwo5Jcoc=; 5:1Luak2bErLrtR2UEIDvUSzYWiM0YaUyG+fVMl7cMQJpcM6OGwxdQo6tZVVTFBPGh7nSl/IJ0T3hrUWpSQH2n+HoV9HHwdTOv2BoRA9T0HofiJTdyBzjeAPdGlZy4QgtLZ7uGLZ7rqwROCkf9tKzp6E4MNgO6SN7HxAHr3UQqbCQ=; 24:ydZr8pqOG+wNek4nVZunytLgdX0E7qLPHitOuzObzeeswEQ8LFCU01L51SzlhqA5ZdX2rLJvibVogXXfRPK5LYa96cZ/1R7p/XD0lBkFWGQ=; 7:zF8UCVq97OAKJ6502Rttty4bYmg4TfJTdxjPTyoKrexY4/GXCBNX+niAf2HhubYVm2T1GIODeN/MTuPnnKU/u/WvJqhXEhlgDgKtRLhx5f1Pbb+H6xeH+FjeN1YvzVs0JZfzt8CCoOKPBPhigvuV9tmZsx+xqI0BYOjdbL9B3v+3V+kMm8XQkxnEdADzqo5t8GSYG7/iQQ880Tf/zgXViGvkJMDPnlqR+PGR9uWgBqPAtl/6EQWomVYxTzoYH1i/ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2018 13:33:45.3000 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95376435-1d75-4fed-52a8-08d58cd4e022 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR05MB1331 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 Currently access to hardware stats buffer isn't protected, this can result in multiple writes and reads at the same time to the same memory location. This can lead to providing an incorrect value to the user. Add a mutex to protect against it. Signed-off-by: Mark Bloch --- drivers/infiniband/core/sysfs.c | 10 ++++++++-- include/rdma/ib_verbs.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 8ae1308e..b769d61 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c @@ -810,10 +810,15 @@ static ssize_t show_hw_stats(struct kobject *kobj, struct attribute *attr, dev = port->ibdev; stats = port->hw_stats; } + mutex_lock(&stats->lock); ret = update_hw_stats(dev, stats, hsa->port_num, hsa->index); if (ret) - return ret; - return print_hw_stat(stats, hsa->index, buf); + goto unlock; + ret = print_hw_stat(stats, hsa->index, buf); +unlock: + mutex_unlock(&stats->lock); + + return ret; } static ssize_t show_stats_lifespan(struct kobject *kobj, @@ -951,6 +956,7 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port, sysfs_attr_init(hsag->attrs[i]); } + mutex_init(&stats->lock); /* treat an error here as non-fatal */ hsag->attrs[i] = alloc_hsa_lifespan("lifespan", port_num); if (hsag->attrs[i]) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 73b2387..33fbccb 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -484,6 +484,7 @@ enum ib_port_speed { * filled in by the drivers get_stats routine */ struct rdma_hw_stats { + struct mutex lock; unsigned long timestamp; unsigned long lifespan; const char * const *names;