Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3151389imm; Fri, 20 Jul 2018 11:01:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfQJHjfYnkEjgRxoBZi3D8uSEoKAWoJxeobPbLDmT37xrHQYadl4pFlNLu8vlHCmkIdTMdz X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr3002899plu.211.1532109701953; Fri, 20 Jul 2018 11:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532109701; cv=none; d=google.com; s=arc-20160816; b=YQ9stzK/7UaJ+36gGTMj9cVyExwJw1u38o6jSt0TtT9FYrBc1eNrLZNgxkg7JQzmoc mo6ZYiNYG7xc9zlTS8joNN3oSSZjd0/5tOX2oQ/rkZp8+OL0PfTIyEVgdnpNLAJOdAEi q7kuBwTCkAcn18Qq4yoIa0VjK0/aRP+7u/7zYUrRG0/P4tA+fJGg/6ZJ4HFu2poFU4AH Viwr0ekEqpmqqp2xV5CAbuinmLXIegllASLeI18x7tgUTG4UrfrQ+e9WBfIeNT/eEUXH IYUyuhsrjpmwt41w26eZ3inhcs6YzYJvNRkG2nRbZ8/3RErAo9XjasZr3+hg8TVGnATX EyPA== 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=B3ylhWtMNbOwULGzCBEztD3RqYLdu5Cb6eNoqivBiaCX0gtYwbMNcGlxiBO8lXwuCO vw7M2IzTCzOuMJ5dhi/5UnpKHPiAsOqRnwvKO/CgR2NjOeryrGmVwDlp9xHAz1HEBr3M WFNQZG9JQ19R8UqdAguooA0jA0cStpufiCSj765pHfdnwZaycjjfla/sFC01gvsPNO1a tAWR6wTyq9aUnkyBCJsdZbl4AQ5XzWQ4nwTzy9NjxZKhb3DkIvvFXY1iwKW5BUF7gABR nZ0ega7J3YB8NkMhDr+/BX2FyBREPDU3xJllc3FU2dN8aQk1tgMp4JYNeB5nmigfNlBq PYLg== 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 n38-v6si2261947pgb.536.2018.07.20.11.01.26; Fri, 20 Jul 2018 11:01:41 -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 S2388434AbeGTSuI (ORCPT + 99 others); Fri, 20 Jul 2018 14:50:08 -0400 Received: from ale.deltatee.com ([207.54.116.67]:38404 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388357AbeGTSuH (ORCPT ); Fri, 20 Jul 2018 14:50:07 -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 1fgZhn-0008E7-0b; Fri, 20 Jul 2018 12:00:44 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1fgZhl-000135-CF; Fri, 20 Jul 2018 12:00:37 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-ntb@googlegroups.com, Jon Mason Cc: Allen Hubbe , Serge Semin , Shyam Sundar S K , Shuah Khan , Doug Meyer , Logan Gunthorpe Date: Fri, 20 Jul 2018 12:00:33 -0600 Message-Id: <20180720180034.3964-8-logang@deltatee.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180720180034.3964-1-logang@deltatee.com> References: <20180720180034.3964-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, allenbh@gmail.com, fancer.lancer@gmail.com, Shyam-sundar.S-k@amd.com, shuah@kernel.org, dmeyer@gigaio.com, 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 v2 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