Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1089277imu; Wed, 9 Jan 2019 11:25:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5DZFzew0cBB9vaF02Iv3o5hneSfXpRVxDpFn0D4Qx75VucWh93c9FHqWqBuGURwO1UlZVH X-Received: by 2002:a62:7892:: with SMTP id t140mr7182109pfc.237.1547061902907; Wed, 09 Jan 2019 11:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547061902; cv=none; d=google.com; s=arc-20160816; b=staQc7mwuV6oX1Ixx7R2imevxg2UnOnHikogFNInQ9eMBEu3CxrlE+A04KSUNisE4k hCRuCLG1rkJG0oQ6Uq5at+OUc5XzSqJC+aA+0CrYzQBpKVSbk49mylhkRQPJ6xDw6kYz o1FbIjK7RUqtxif6YN+ny1OLSrmd2qIDExtLTwhz5lz7/V07qUE7pPYiEcmSWXNxLl3u /sBeQWUbW0Nxz0S3i//lRe5jyKs3yNPKIXZALedsEpDdpUVSP+sf1PzYYTReQAYg/ctm x2maF/AlPImJercTa4RY9iDlxoEPCI0G8iWuvD60xbsSwWUYNXeOO2P3Dxg48FKP7ums FCgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=4qaE+3bTiS3rxx2nVpw7SEfAC15micjaKdFp1IiNdmI=; b=BiUw1CoRd7lA524KH2QfCjZQH/jypQRz5Y4+nnbQeUreQzhr3LQe0H/5tQ1n44fuMl VccAPg8vCYCsct4TCW9LZuI/9ns4eoOdTuyx5X4qTqa/9bVbAPCoepLGhP3FzNr1vH4h IqDOYQGPKTwHApJVz8m3fMD33O1TKvZq0Y6xiSdZrAgJ1t0cRoVYWnthj8fBgyfAPqZC x60xoylLypPLUbwbHFWDIt11l/ojKoDNKmDXWp9y/KVPVcgRA4qYYu3c33RWTket9yMZ lJkjMZQjnU72mkT0RLS9rjMqBjJ4tVEOwXxSSIauW7x5g3MlMqIlF4hc9UZJfaeXMQOI c5Lg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 44si8492930plc.110.2019.01.09.11.24.47; Wed, 09 Jan 2019 11:25:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728468AbfAITWv (ORCPT + 99 others); Wed, 9 Jan 2019 14:22:51 -0500 Received: from ale.deltatee.com ([207.54.116.67]:59738 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728215AbfAITWu (ORCPT ); Wed, 9 Jan 2019 14:22:50 -0500 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ghJR2-00053v-GD; Wed, 09 Jan 2019 12:22:49 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1ghJR1-0001Vw-OH; Wed, 09 Jan 2019 12:22:39 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, Jon Mason Cc: Allen Hubbe , Dave Jiang , Serge Semin , Logan Gunthorpe Date: Wed, 9 Jan 2019 12:22:32 -0700 Message-Id: <20190109192233.5752-8-logang@deltatee.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20190109192233.5752-1-logang@deltatee.com> References: <20190109192233.5752-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com, fancer.lancer@gmail.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH v3 7/8] NTB: perf: Fix race condition when run with ntb_test X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running ntb_test, the script tries to run the ntb_perf test immediately after probing the modules. Since adding multi-port support, this fails seeing the new initialization procedure in ntb_perf can not complete instantly. To fix this we add a completion which is waited on when a test is started. In this way, run can be written any time after the module is loaded and it will wait for the initialization to complete instead of sending an error. Fixes: 5648e56d03fa ("NTB: ntb_perf: Add full multi-port NTB API support") Signed-off-by: Logan Gunthorpe Acked-by: Allen Hubbe Tested-by: Alexander Fomichev --- drivers/ntb/test/ntb_perf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c index 7165f7ab8e35..2c11e513cf78 100644 --- a/drivers/ntb/test/ntb_perf.c +++ b/drivers/ntb/test/ntb_perf.c @@ -158,6 +158,8 @@ struct perf_peer { /* NTB connection setup service */ struct work_struct service; unsigned long sts; + + struct completion init_comp; }; #define to_peer_service(__work) \ container_of(__work, struct perf_peer, service) @@ -549,6 +551,7 @@ static int perf_setup_outbuf(struct perf_peer *peer) /* Initialization is finally done */ set_bit(PERF_STS_DONE, &peer->sts); + complete_all(&peer->init_comp); return 0; } @@ -639,6 +642,7 @@ static void perf_service_work(struct work_struct *work) perf_setup_outbuf(peer); if (test_and_clear_bit(PERF_CMD_CLEAR, &peer->sts)) { + init_completion(&peer->init_comp); clear_bit(PERF_STS_DONE, &peer->sts); if (test_bit(0, &peer->perf->busy_flag) && peer == peer->perf->test_peer) { @@ -1046,8 +1050,9 @@ static int perf_submit_test(struct perf_peer *peer) struct perf_thread *pthr; int tidx, ret; - if (!test_bit(PERF_STS_DONE, &peer->sts)) - return -ENOLINK; + ret = wait_for_completion_interruptible(&peer->init_comp); + if (ret < 0) + return ret; if (test_and_set_bit_lock(0, &perf->busy_flag)) return -EBUSY; @@ -1413,6 +1418,7 @@ static int perf_init_peers(struct perf_ctx *perf) peer->gidx = pidx; } INIT_WORK(&peer->service, perf_service_work); + init_completion(&peer->init_comp); } if (perf->gidx == -1) perf->gidx = pidx; -- 2.19.0