Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4561278pja; Thu, 21 Nov 2019 21:54:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyg5DBqDghEHMXiufYkturiDg/6CQXU+A3ywDRF2FpTh/P+zUhK9n8xwyrX1YvWgMqk8o7L X-Received: by 2002:a17:906:d9db:: with SMTP id qk27mr3246430ejb.309.1574402046076; Thu, 21 Nov 2019 21:54:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574402046; cv=none; d=google.com; s=arc-20160816; b=wbEGwwN3XyUfazFIHkfMx+USm69zZ7FUJwhIMxGqCG12uPFIkRuRHPnDmANSzzKqR0 pxU/IRVqXpWuq56HmLiyFluV3MfXEY2PcJRchN7lFT5MZdDsblpc3zIwj++bu7P6I/+H mUEGWd4SgTqIAS2p10WA+SE2iTxn8oD6FI1T2ntQHOkUbxe2o6nTV7yote8KsEqDtR0f 9qu1JCUGGjzhcWH4CleQUELoZ+BjUm3izfPIcTyFHSXJRoXjlm0MnpL/m3hTqR2kp+/k d/Eg2CC+ERF7wX03LAJYDFxRlhQT1bnEHFlsr3Foal1yuCpvFPAzkUMeN7UWyZqbE7wl a4YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bZ+UBoBSilCx7GE20R84+rLEKmxEA8A9xznnhDzkhRc=; b=ZYdXOY6pRFkQwtERsz0ulgEnDEwwYUDdLrlM2N8eM367n98sV4QdtcHwWQCvU58ZWh ksp+4u0LqzGMtbSieWOf9EAC6nT67PfcabuhS7m9H/aiOimf7pFZx+60ca77NEiUusoG wQkxhdazT0Ap366PRPJDIZW44PVsTbQN0J7eHxENvBHutcTHhyM6igjZ60ibt7lbkbSa eyEhxYka7NSDalgot+v5smqg7WjU8DDjBHq3TE0Q35IVwroWzB+Kw8sbCsWuIvLiTeap VGDVxaSwGPSccACimCieAnRHMjRVdWU4wd+74VEgvFAGDXCYgoFeUwQUST/Tl+qUir4j PBpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OrrS6k9e; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si4336085eda.375.2019.11.21.21.53.41; Thu, 21 Nov 2019 21:54:06 -0800 (PST) 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=@kernel.org header.s=default header.b=OrrS6k9e; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbfKVFvo (ORCPT + 99 others); Fri, 22 Nov 2019 00:51:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:56826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726865AbfKVFvh (ORCPT ); Fri, 22 Nov 2019 00:51:37 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 862962071F; Fri, 22 Nov 2019 05:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401897; bh=D8uedxp58DJdJ5NOweYsrKV1g/NMpFA8GPf5Tgpbrtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrrS6k9evWzNsTxr9oOuld9p8bcXnknpIGzHGQhFi/q2phcLTDE9ic/K4LCK8Wyz6 oO8vpn2BZq7jcfSmUjTi6Ru30kUW+I/yu23F2dzRBHD9HKHuTKawHvCUBzIZ0xbeXL SFZgz54zV4iPGukBCv0elpozB8G3DYVf6gsA2Bi4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Parav Pandit , Jason Gunthorpe , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 129/219] IB/rxe: Make counters thread safe Date: Fri, 22 Nov 2019 00:47:41 -0500 Message-Id: <20191122054911.1750-122-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Parav Pandit [ Upstream commit d5108e69fe013ff47ab815b849caba9cc33ca1e5 ] Current rxe device counters are not thread safe. When multiple QPs are used, they can be racy. Make them thread safe by making it atomic64. Fixes: 0b1e5b99a48b ("IB/rxe: Add port protocol stats") Signed-off-by: Parav Pandit Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_hw_counters.c | 2 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_hw_counters.c b/drivers/infiniband/sw/rxe/rxe_hw_counters.c index 6aeb7a165e469..ea4542a9d69e6 100644 --- a/drivers/infiniband/sw/rxe/rxe_hw_counters.c +++ b/drivers/infiniband/sw/rxe/rxe_hw_counters.c @@ -59,7 +59,7 @@ int rxe_ib_get_hw_stats(struct ib_device *ibdev, return -EINVAL; for (cnt = 0; cnt < ARRAY_SIZE(rxe_counter_name); cnt++) - stats->value[cnt] = dev->stats_counters[cnt]; + stats->value[cnt] = atomic64_read(&dev->stats_counters[cnt]); return ARRAY_SIZE(rxe_counter_name); } diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 3b731c7682e5b..a61782df4e805 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -408,16 +408,16 @@ struct rxe_dev { spinlock_t mmap_offset_lock; /* guard mmap_offset */ int mmap_offset; - u64 stats_counters[RXE_NUM_OF_COUNTERS]; + atomic64_t stats_counters[RXE_NUM_OF_COUNTERS]; struct rxe_port port; struct list_head list; struct crypto_shash *tfm; }; -static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters cnt) +static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters index) { - rxe->stats_counters[cnt]++; + atomic64_inc(&rxe->stats_counters[index]); } static inline struct rxe_dev *to_rdev(struct ib_device *dev) -- 2.20.1