From patchwork Wed Apr 12 19:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liming Sun X-Patchwork-Id: 1768249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=gQ597XbR; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PxXxb51THz1yhV for ; Thu, 13 Apr 2023 05:35:47 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pmgFr-0005VT-Fa; Wed, 12 Apr 2023 19:35:43 +0000 Received: from mail-bn8nam11on2041.outbound.protection.outlook.com ([40.107.236.41] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pmgFq-0005UO-4z for kernel-team@lists.ubuntu.com; Wed, 12 Apr 2023 19:35:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dNLTgxrNuaqKxuZmrz/8neXtBNe8V+k3lf+N+TfRosxp99MM74UOaxm6uNd4NSkEg8lNafugqcco9qQM2F/FV8YPyevh2kmfXTIydtOjwHqQDi7tAYWYznHhC5sx8v8a4ogmYMqPICgr/TRNRWYcI2tuLJjrVrFHUrDMyULhZGB8fE0dWYIF9uHv2sLzsJ0KFnP0wDIs91ZlaPvel4DPMplYe4lTO29GV7KW+Yfd8DwtF6AtOTZYYQHaHBdl2E0ik8UAm7Ufvo9/tRJYVdAGraeiGqI3Oz4LnOgBswTWCHyezJO8/cfLnB1IdGv65TnUtFhvvnRy80IGPukewWJDJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GAY0iT9V9LvY0cbJ5ExFBvSrfnXNRq8bj1btUjrTN8A=; b=dvwlp4xvD1D2DRWhwa6kPTZqXtTP/tiNa6i1ekU+M6yJpIF52NjAFQFhloEkmDIHNt44+YaszuFgdKfx9W4ql1xzSU3QjTfsnCCswyY1QlCetsEVIuVai629lfif1Wvoln3cILXye2MOrfYbVQE7Wxo3l4nBp+NWgHENsTIOXUTdCPwB+qVClmZPUrMZ/JBRuNgKLvqzD4ffEDFDA7gjnCmsBxufSFEhg/l1nRSSHSTnUxhJZd8UKwyX/ppwJV/PwFqb1Nbjz7gIzY0RVawX7fHsiDXvbLzBTOUv67gLINs+54LZotxva0weQf0XW9KwJqPzFRAMc4mZGHt5zGmbVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GAY0iT9V9LvY0cbJ5ExFBvSrfnXNRq8bj1btUjrTN8A=; b=gQ597XbRyz0VaQyKGJscRL+QQJDnBzf3k+Q7ONPUkAgGvErLFXmteiYGAq9jFks10rENIdieE5aZ1NLKHck0U+FYF66Pq1Pl1mhhcB4tFpnBnf6l3PiYYQTlpt+dVyuk6qddJKLTWR5zX6HdwKiXerSht9aqNzLmnjEY+ylcKGH2GfpUpnLy8UjaXr8e4OY4mhSkE+3JNHzY5dd7PjRZUg+cPFCuM9aukU+yO6cYHsiL986XENPjANqu7gJwYbjDWK/mezE5oDj7w47fVpk01zSfvvLHVwXSXnJejuq+yC80dPOfVc9ywyuJ3wphMpeOcPYjdZ8UpabaAGEfSunFvA== Received: from MW4PR04CA0053.namprd04.prod.outlook.com (2603:10b6:303:6a::28) by CH0PR12MB5060.namprd12.prod.outlook.com (2603:10b6:610:e3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Wed, 12 Apr 2023 19:35:39 +0000 Received: from CO1NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::84) by MW4PR04CA0053.outlook.office365.com (2603:10b6:303:6a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30 via Frontend Transport; Wed, 12 Apr 2023 19:35:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1NAM11FT056.mail.protection.outlook.com (10.13.175.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30 via Frontend Transport; Wed, 12 Apr 2023 19:35:39 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 12 Apr 2023 12:35:19 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 12 Apr 2023 12:35:19 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Wed, 12 Apr 2023 12:35:18 -0700 From: Liming Sun To: Subject: [PATCH v1 1/1] [SRU][J:linux-bluefield][PATCH v1 1/1] UBUNTU: SAUCE: mlxbf-tmfifo: fix potential race Date: Wed, 12 Apr 2023 15:35:02 -0400 Message-ID: <8a37b9da7c896a630feab127807275f7cd7f107e.1681327632.git.limings@nvidia.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT056:EE_|CH0PR12MB5060:EE_ X-MS-Office365-Filtering-Correlation-Id: 91284fdd-4595-446d-e50b-08db3b8d18ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DnrgmF0GdkHKmUiktZtyVOor61gn8SLP6M/m/CDvnWYUa1eQ4WiQk8oEyqqQjKIToN4udE42OqTB4Vq8/pOv689eh1W0QnClO/wSUFZu2Yi60R87MlFFuxMxu2bq0IIZdFpo5xfCFfNvXQPJVJtxeO7Fg6ROh0fJe/n7MLNeNUbKNXy1Ez3H4huDDO1LlII8j/SYJH7n97SDNOjVWzeEWFXMXk0p5H2Blpcca/4TluL3IzhoD02aVqzogFmaGWBkL0G88gONWYoASAyIiEWCV+WkbhIV65I0jlqM/dK6+euSWzKjgsupZU9pWWeq3B0NhFv/XSlWHF846q7RlJclQNBSUc33lbJU1j1bHOywWNasrfkpV+uDu9gqOzeT8UmXm2dXskeCJLEotUakoWpAJjl9GAfVhGKs9zCjGP2aCpNqOm43cJEMnSUwIhVF+uUZf+Aw4CMrnYYAR8K4RHxU8bM18aQgAExebYociYp+4etc+XY3R76X4HyHsfTlk/0REjG+YLHlDyAdk75o0X6qf/ARVYb2VX4Pzhpr0VdI5BA9L5OKGPEAoC66aF4++KEMU70RW/uMNPWNY4DinLwvRGyDM0hhNGcuOmPrJ5zA30lGmr2aDbtcG1prH6ItNuGz3pR34hET+vf4RGHrOxePqf+/tDJkI9/0+/2jxOvtWPEPL/BP2GUnbhnyvuscr/ZjD2L1I98Wm1WmhBsy2S2vp+0DnQV9S7SCb1whUVnq3v9QIsRGNQ3U++iaiHmneLxjoLGogbtnLRcr6svuYtaf1vKXFNRS0PLKm3j4UCwvzvAP+zU2luaVYekm+BTPxmqnZjZsMdjPyfFBIag8TabrFg== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(136003)(376002)(39860400002)(346002)(396003)(451199021)(40470700004)(46966006)(36840700001)(40460700003)(316002)(41300700001)(26005)(6666004)(7696005)(186003)(966005)(86362001)(47076005)(34020700004)(107886003)(7636003)(2616005)(356005)(82310400005)(36860700001)(82740400003)(36756003)(426003)(336012)(83380400001)(40480700001)(6916009)(4326008)(70586007)(70206006)(8676002)(8936002)(5660300002)(2906002)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2023 19:35:39.6922 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91284fdd-4595-446d-e50b-08db3b8d18ef X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5060 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Sun Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/ubuntu/+source/linux-bluefield/+bug/2016039 The fix adds memory barrier for the 'is_ready' flag and the 'vq' pointer in mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to out-of-order memory write. Signed-off-by: Liming Sun Acked-by: Tim Gardner --- drivers/platform/mellanox/mlxbf-tmfifo.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c index 97956c9c9d4c..19d539fc99ae 100644 --- a/drivers/platform/mellanox/mlxbf-tmfifo.c +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c @@ -922,7 +922,7 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) fifo = vring->fifo; /* Return if vdev is not ready. */ - if (!fifo->vdev[devid]) + if (!fifo || !fifo->vdev[devid]) return; /* Return if another vring is running. */ @@ -1119,9 +1119,13 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev, goto error; } + vq->priv = vring; + + /* Make vq update visible before using it. */ + virtio_mb(false); + vqs[i] = vq; vring->vq = vq; - vq->priv = vring; } return 0; @@ -1426,6 +1430,9 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev) mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); + /* Make all updates visible before the 'is_ready' flag. */ + virtio_mb(false); + fifo->is_ready = 1; return 0;