Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1460705imm; Fri, 8 Jun 2018 17:11:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJISa79Fsrc4UQpxLnyVysPwvGA9kOcINvUwzFXTwZndcBCmEW7vwJ++Mum2CmDqxcXe4Zu X-Received: by 2002:a63:ab05:: with SMTP id p5-v6mr6956250pgf.280.1528503108820; Fri, 08 Jun 2018 17:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528503108; cv=none; d=google.com; s=arc-20160816; b=tcKBW3PJ1ii2CQg2uqb3ZX4H5uBp9QgSeiguniMkNUXoTM6Zx+LfE+AjK+bjOmmp0G gmsfb6ZuxBNRzSsj3rS8XQEysbz/PTVwAi7AZDUD1E9RdQsLXbTtOJSWAtpvLu5/PMZ0 hCst8OF3nnnoEKMvwKlwGpUS7jMrFYJptVAAIB53WzK5AtzKpUBZ3IA2RK5HhJnXHikN JiuDKiBn7sEMCLGO0vy+Nv+b+XHoOR0aDW5cZMRj898GwXfHPcft/ZHFPubAnmglfxQd O7P39DeTWudp7UZ+95W0v7qNWV0gWIH2k/TywoaSRepvWslZ1EzLbPG4NXTaZsABD7IJ Wuuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=2CrgTHKYVi3NXlWHwdfiWsvn8o0O4aIOVCxrXjSLfQ0=; b=Qm0hIxIiwGbiFfDXrKAGdyTxymMAr8ISnZZ4YOkWjBvKQE+HRQYfQbK4CYjkkdkIOM iY+oM0LxA+P1eP7YHsE7SsiwZWwhW0mnUh7UByN+NUSpX4yxjB6vTpZETv4GeQ7voWFx vnHhP9Aqv4YoTJfxkWJScYKJdehmu99zX6T4+ODel7YOICRN6zul0ynApbp9anAR9iNG mb29Errfv3dE9E0N5QagwAvyRPqkKmuj83G19f1APPZXEgt2GnvXxV3KX4MSgTtCsioQ eCwM2PuQ8EqWMUW4HIxWuk/JPm5qHIc6t8+hpgfyS/gROxqgB4aX5/4xNh6gM8AFdI8b kXKg== 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 j129-v6si7372708pgc.186.2018.06.08.17.11.34; Fri, 08 Jun 2018 17:11:48 -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; 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 S932295AbeFIAJe (ORCPT + 99 others); Fri, 8 Jun 2018 20:09:34 -0400 Received: from ale.deltatee.com ([207.54.116.67]:60550 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752945AbeFIAI1 (ORCPT ); Fri, 8 Jun 2018 20:08:27 -0400 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 1fRRQd-00043u-2S; Fri, 08 Jun 2018 18:08:25 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1fRRQc-0003d8-AJ; Fri, 08 Jun 2018 18:08:22 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com Cc: Jon Mason , Dave Jiang , Allen Hubbe , Serge Semin , Shyam Sundar S K , Shuah Khan , Logan Gunthorpe Date: Fri, 8 Jun 2018 18:08:18 -0600 Message-Id: <20180609000819.13883-9-logang@deltatee.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180609000819.13883-1-logang@deltatee.com> References: <20180609000819.13883-1-logang@deltatee.com> 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, Shyam-sundar.S-k@amd.com, shuah@kernel.org, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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.1 Subject: [PATCH 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 --- 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 6285cb8515ac..8e2b7630ecc9 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.11.0