Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1714622pxf; Fri, 19 Mar 2021 13:56:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYANdLUC8KOKwOKfQmQhnecgEIrRERKd7MJf8nzdvdD4D4NaNFNtCPRfVYV1wvBaBQfIN2 X-Received: by 2002:aa7:cd54:: with SMTP id v20mr11979380edw.80.1616187393254; Fri, 19 Mar 2021 13:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616187393; cv=none; d=google.com; s=arc-20160816; b=axY6qnGgv+lmfvwjCDn8Wxf+o1TkyQkWNKnENcuROqGydZdFukH2T2f5ENclCttXHu TpPiwcoiAlyKYBBjaEUqHJiDZPylB1I07mEYsY/J5yOP/sNY2SuQpfIyIXeZcGbpSX5d uC5rKRgFJUo3h24ylQSx22Yv8uLrUWiVZGyfb1d/nzN2rT7EzO632mTkUO5Ou9KMrH4r DTrPMBsiPbRVJnYxM9JqexHOO5r/fIrWjU19Z6ngwobuHagbCauT5ykVlYnkJ1q3TkVZ NmISnNZ8RfK2ckXQ5W8IhpOhJI/8HRvmvAxwrnxnO8Wh+dNe5keAJC2hgjR2+XK+dmD9 iBGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H67d/giVwtfDKYWyd9uBTueyHWko0R99XUloYzHBBp4=; b=ZMdggU02SXKZzrvsKo3W6QzmRyh+CXzzEd5p9ahCdAqcP1nHeIWSsgYv0TIZJsWzie ryywygbM23eoyB+qQ/RonAvStJM3BKE8Hf0eEhVTldj0bMUJfraU+SXqhUi+2uo4RbOW Q1y4oetglax9AF62Vk1RWjEtIEAU5muK9/tDu2ArnNwqMX/QjvSlI6Yl0RoYN9I7BihL afGKYVF8i++F51cuSfgKtSUhWWroq9rJq7ZXepzT0+7K3blvbldOt6edpUbresLJFqtA fXBoywKgb2g61/OjHlkNbbDegeI+NSF/kwyx09i5yGIliF4dRjFeYXXb0MkLenBdyV+e 5e4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=qvV0vOFS; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx25si5020473ejc.382.2021.03.19.13.56.09; Fri, 19 Mar 2021 13:56:33 -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=@ibm.com header.s=pp1 header.b=qvV0vOFS; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbhCSUvR (ORCPT + 99 others); Fri, 19 Mar 2021 16:51:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:29864 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbhCSUul (ORCPT ); Fri, 19 Mar 2021 16:50:41 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12JKY8d3108786; Fri, 19 Mar 2021 16:50:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=H67d/giVwtfDKYWyd9uBTueyHWko0R99XUloYzHBBp4=; b=qvV0vOFS11ehK3BhSdaMWsfCxXDk9RAtlKNk8/gV2v+toonswst/Hx4syq4VALMCKQDW BYwR5FVTtxkZEJp1qUKQwDkxm3po6mUosq9ZMdAST0XqCurhZspcx9xAGcAb7+RB67Il aP/OpHrtZiHGM7tOoVDcvw+xuS43y3vjePM6zA+flH/lZTRy3AbbsqGV96czQxElHsAy bROiDIfZ9D/ak9WvefUephse3QyidNZ6xQ0qrA2I66/2t6AkQVkNmsbTq9taDdRxL9Fk a77p3YpZm58XSkXpfRR8ADrVqA7pEuS4FXUThp9qQR1HwgqEOKBx1wTZ4ZFLFO9L5jQY FA== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 37cw8v2edj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Mar 2021 16:50:34 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 12JKm4Cg022499; Fri, 19 Mar 2021 20:50:33 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma03dal.us.ibm.com with ESMTP id 378n1a4vay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Mar 2021 20:50:33 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 12JKoVJq19071442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Mar 2021 20:50:31 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 881B06E054; Fri, 19 Mar 2021 20:50:31 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B4536E04C; Fri, 19 Mar 2021 20:50:31 +0000 (GMT) Received: from vios4361.aus.stglabs.ibm.com (unknown [9.3.43.61]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 19 Mar 2021 20:50:31 +0000 (GMT) From: Tyrel Datwyler To: james.bottomley@hansenpartnership.com Cc: martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, brking@linux.ibm.com, Tyrel Datwyler Subject: [PATCH 1/2] ibmvfc: fix potential race in ibmvfc_wait_for_ops Date: Fri, 19 Mar 2021 14:50:28 -0600 Message-Id: <20210319205029.312969-2-tyreld@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319205029.312969-1-tyreld@linux.ibm.com> References: <20210319205029.312969-1-tyreld@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-19_10:2021-03-19,2021-03-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103190140 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For various EH activities the ibmvfc driver uses ibmvfc_wait_for_ops() to wait for the completion of commands that match a given criteria be it cancel key, or specific LUN. With recent changes commands are completed outside the lock in bulk by removing them from the sent list and adding them to a private completion list. This introduces a potential race in ibmvfc_wait_for_ops() since the criteria for a command to be oustsanding is no longer simply being on the sent list, but instead not being on the free list. Avoid this race by scanning the entire command event pool and checking that any matching command that ibmvfc needs to wait on is not already on the free list. Fixes: 1f4a4a19508d ("scsi: ibmvfc: Complete commands outside the host/queue lock") Signed-off-by: Tyrel Datwyler --- drivers/scsi/ibmvscsi/ibmvfc.c | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c index f140eafc0d6a..5414b465a92f 100644 --- a/drivers/scsi/ibmvscsi/ibmvfc.c +++ b/drivers/scsi/ibmvscsi/ibmvfc.c @@ -2371,6 +2371,24 @@ static int ibmvfc_match_lun(struct ibmvfc_event *evt, void *device) return 0; } +/** + * ibmvfc_event_is_free - Check if event is free or not + * @evt: ibmvfc event struct + * + * Returns: + * true / false + **/ +static bool ibmvfc_event_is_free(struct ibmvfc_event *evt) +{ + struct ibmvfc_event *loop_evt; + + list_for_each_entry(loop_evt, &evt->queue->free, queue_list) + if (loop_evt == evt) + return true; + + return false; +} + /** * ibmvfc_wait_for_ops - Wait for ops to complete * @vhost: ibmvfc host struct @@ -2385,7 +2403,7 @@ static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device, { struct ibmvfc_event *evt; DECLARE_COMPLETION_ONSTACK(comp); - int wait; + int wait, i; unsigned long flags; signed long timeout = IBMVFC_ABORT_WAIT_TIMEOUT * HZ; @@ -2393,10 +2411,13 @@ static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device, do { wait = 0; spin_lock_irqsave(&vhost->crq.l_lock, flags); - list_for_each_entry(evt, &vhost->crq.sent, queue_list) { - if (match(evt, device)) { - evt->eh_comp = ∁ - wait++; + for (i = 0; i < vhost->crq.evt_pool.size; i++) { + evt = &vhost->crq.evt_pool.events[i]; + if (!ibmvfc_event_is_free(evt)) { + if (match(evt, device)) { + evt->eh_comp = ∁ + wait++; + } } } spin_unlock_irqrestore(&vhost->crq.l_lock, flags); @@ -2407,10 +2428,13 @@ static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device, if (!timeout) { wait = 0; spin_lock_irqsave(&vhost->crq.l_lock, flags); - list_for_each_entry(evt, &vhost->crq.sent, queue_list) { - if (match(evt, device)) { - evt->eh_comp = NULL; - wait++; + for (i = 0; i < vhost->crq.evt_pool.size; i++) { + evt = &vhost->crq.evt_pool.events[i]; + if (!ibmvfc_event_is_free(evt)) { + if (match(evt, device)) { + evt->eh_comp = NULL; + wait++; + } } } spin_unlock_irqrestore(&vhost->crq.l_lock, flags); -- 2.27.0