Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2028141ybh; Fri, 13 Mar 2020 11:38:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsYwi9WTLPL4eN5cfCFDJvNRzcMroD+HnVVBcUtrYTWLf2qQqhEj+VgNZh7P7PSvTbYjf0l X-Received: by 2002:a9d:6c0b:: with SMTP id f11mr11868791otq.182.1584124704981; Fri, 13 Mar 2020 11:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584124704; cv=none; d=google.com; s=arc-20160816; b=RV8SAiOoMdC13ESzEhBGWJlpaJEFiuIyXHXM5UOVO6EieqFAWxcKeB4yQnvJSNVBme 4VlmgSfJcifDAQyppTsr4I9L74oFCWC9BzyOSsKi0KVAEv5WMB+hTs/j4kEn1UdEQNoW rrMCZWQiR/KECxkX44bqVCCmi6uCmfoHr7YrrSEUtHBokq1rw61GkmduOuyrj0ojGY6+ nIKziFfvX3CsLwHCYGTMnWMrFwJ5mKdieKBJdX6PThlDCdDPIOkl4VWbn+0vkCXfaVtB GAcLoAPjq4PBsPsAz7b2J93N3uTIH8PciNy6tR18oc9Hu5dJ+HGzG3ltQOE35sHu02X4 TFyw== 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:message-id:date:cc:to:from; bh=GWQ/O8HVQ0uEU9z4soY1t2z2J0vBRwLPWS1+YpudCvg=; b=XEyU+w3ki3gefcWrh4eft6u5KjLypehaOtcwih5vbQBlqDYtG1fzWo33ZawUwDtT2p GUkx+BS7bpL9VYxqGI2HVUzpxLrj303xyngSCqNV5M0WxgAEh3E42oAcboqOfwGBeesN +bq2yCDCvwkfuX0EU5tPSur1IQzpAznU+Y7ekXXqEB9SXjJzw7UefXexDY5wcfp65o1v x/EmP86fmO+K846tJ3arTO41FA5oyBWWyDTWe0lLCKaa804iWkqwcXVObjHUZXmLgddg ts63hIJuN6D4LVaG/JA9te8cFQg6cZqrB384XYwjOf9ixdx6bH1VuPSRyIviv9vLKD5m gYmg== 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 y17si5049596oto.70.2020.03.13.11.38.12; Fri, 13 Mar 2020 11:38:24 -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 S1726757AbgCMSgv (ORCPT + 99 others); Fri, 13 Mar 2020 14:36:51 -0400 Received: from ale.deltatee.com ([207.54.116.67]:60254 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgCMSgv (ORCPT ); Fri, 13 Mar 2020 14:36:51 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jCpAv-0002bu-Ds; Fri, 13 Mar 2020 12:36:50 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1jCpAv-0000hP-0P; Fri, 13 Mar 2020 12:36:49 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bjorn Helgaas Cc: Sebastian Andrzej Siewior , Logan Gunthorpe Date: Fri, 13 Mar 2020 12:36:08 -0600 Message-Id: <20200313183608.2646-1-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 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-pci@vger.kernel.org, bhelgaas@google.com, bigeasy@linutronix.de, 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,SURBL_BLOCKED,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH] PCI/switchtec: Fix init_completion race condition with poll_wait() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +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 The call to init_completion() in mrpc_queue_cmd() can theoretically race with the call to poll_wait() in switchtec_dev_poll(). poll() write() switchtec_dev_poll() switchtec_dev_write() poll_wait(&s->comp.wait); mrpc_queue_cmd() init_completion(&s->comp) init_waitqueue_head(&s->comp.wait) To my knowledge, no one has hit this bug, but we should fix it for correctness. Fix this by using reinit_completion() instead of init_completion() in mrpc_queue_cmd(). Fixes: 080b47def5e5 ("MicroSemi Switchtec management interface driver") Reported-by: Sebastian Andrzej Siewior Signed-off-by: Logan Gunthorpe --- drivers/pci/switch/switchtec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c index a823b4b8ef8a..81dc7ac01381 100644 --- a/drivers/pci/switch/switchtec.c +++ b/drivers/pci/switch/switchtec.c @@ -175,7 +175,7 @@ static int mrpc_queue_cmd(struct switchtec_user *stuser) kref_get(&stuser->kref); stuser->read_len = sizeof(stuser->data); stuser_set_state(stuser, MRPC_QUEUED); - init_completion(&stuser->comp); + reinit_completion(&stuser->comp); list_add_tail(&stuser->list, &stdev->mrpc_queue); mrpc_cmd_submit(stdev); -- 2.20.1