Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp972866ybt; Wed, 17 Jun 2020 19:32:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNgd0/1PHmbo3IE/rwIxQszgjyGLCLRlY9a9eU5rGRIxxMynZEMGEImF1QY5U4E5MdRhNY X-Received: by 2002:a17:906:33c5:: with SMTP id w5mr1891917eja.275.1592447571882; Wed, 17 Jun 2020 19:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592447571; cv=none; d=google.com; s=arc-20160816; b=ZghPtsfYibMd8skbiREjcr+x4zcIMtVAB5i7xAGjwA6pPDoTA0w2UuLdTaC0mlwLku xifzvqq2N4ntPzNNOmVDnDeTg/3qtGSFFa0SpTM0xvF743PoaAzmB5F4z4ohc0f8nUd4 H7U9RwkGpS/M6mJs7xzKonRJqK+k2d0YZTelMyNJ5sGjW+ObJHLXmKhbBORigqn6IRln mkNoAhESOlm7cFrneS4Ucr5qqF2GkZyj3CsePkMNk5On4fgztgmlHMD1KztuF1kVVF3f GU4K7KxxbLn1aGPMlh7KIxtBauMKV/Z7W9o6+4ZFdxnkt8xatrDyE+WmcxOw/84lTXCg cClA== 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=b0N2/JqRUoVCkOUNKOJnY+iSI5IT8YjKG5cKcx2FUaw=; b=jeAFZWE5doPuCUS5KUxEJCUl+o4lB+pgN5trneqb5YiJXTTFt/zQvOqTO0ybF/ulOW pg2r6GeJYVi84mq9tGWvH7ktGPUSOF0UX0rzvmFnESEB0JdangFwZt4znSF1xR1aHZmc rP3S454o4xXjwE5PkbG7YxhVD6KfxskR76hIWXb8E2otRyxqx36XfIFIs9so0x6q3bDO MTtNybSHn65Ec4FJV7wMxPRjNcjpq3Ak3Br+I0QD8YousAc+S+XxnJx4MBfkWzMhx+pN FzaV7xhN3rcT+baMZwRSkJ8j1EH82gkbeALosWK0QYGRHml6v7nPF6354+aSenpKeduh 9KpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u+AJcvb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j2si1101531ejm.51.2020.06.17.19.32.29; Wed, 17 Jun 2020 19:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u+AJcvb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2387710AbgFRCas (ORCPT + 99 others); Wed, 17 Jun 2020 22:30:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:45988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728450AbgFRBPn (ORCPT ); Wed, 17 Jun 2020 21:15:43 -0400 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 AAE5321D79; Thu, 18 Jun 2020 01:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442942; bh=fAt8arPsk10vlHfV7fzglD1mjYS2ObhiDsvpwLieti0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u+AJcvb3zqgFtagVxPH79FwkVyCI/kfcukRbRn7qVdOnZpdAu5hotES22ErnZeONo dQJbq1grTHayDqpJ7WydZvhNFP4oJL7yiSqajSsqm10+/PEm5Qc6lN9UOk/vy2YUKF fWIFdE3Sj4h12crAvKibsf1EcaiKrmShyTNDo0xI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Logan Gunthorpe , Allen Hubbe , Alexander Fomichev , Jon Mason , Sasha Levin , linux-ntb@googlegroups.com Subject: [PATCH AUTOSEL 5.7 353/388] NTB: perf: Fix race condition when run with ntb_test Date: Wed, 17 Jun 2020 21:07:30 -0400 Message-Id: <20200618010805.600873-353-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-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: Logan Gunthorpe [ Upstream commit 34d8673a01b053b6231a995a4eec9341163d63be ] 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 Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- 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 0b1eae07b133..528751803419 100644 --- a/drivers/ntb/test/ntb_perf.c +++ b/drivers/ntb/test/ntb_perf.c @@ -159,6 +159,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) @@ -547,6 +549,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; } @@ -638,6 +641,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) { @@ -1084,8 +1088,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; @@ -1456,6 +1461,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.25.1