Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1443640pxu; Thu, 8 Oct 2020 11:35:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzgtj9RQasc+VQ65C3fHo9Fhn2yxxP23OZVBeCW1+2iy+b1AgrcDwec234lyoMryMfOtyJ X-Received: by 2002:aa7:d30f:: with SMTP id p15mr10125912edq.256.1602182107935; Thu, 08 Oct 2020 11:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602182107; cv=none; d=google.com; s=arc-20160816; b=Nd+NE+ZHS2oJem+NU6Kq4OUoV+735UBDPYDnVFUzkScO6lg2eFgS2Xgflx2X898d2T 1SRJs1gb1ucIx9h93qtNMLLKGBx4IDreCXCGuFYYU9d/osTY+bSPUlsb0x8eDPdV9547 w8g0HW07Ep3Qe3nS06A2VTum6FGKHZ+QoMyLrVcgxxrzVAOQl1+UYGoGv1ZvfGBCriFP 6OrBNxWjTBY15USvFPlFhSWlk0crcrft7UgbskpHn9z2PSG3TCgkY9n9ZkUXQQARNUuj rA3Rk0ZNEFe0U+35UBuHagocAJzX4HFWy/TDlFUPYbgK1CDtddFOhtgmZx6nFyVRwEYM l3ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=YFmg0lJdUbAFjHtInWo6Z7HAeezH7FiwCiDQdlKA67k=; b=n9/lPNSD15r1pk4xJh/AHByvhsXPeBWIGg0EnkHLUui7l8DdvlUeeGP6lh2WzQ/yKz Tcd7cCQVqt+lvlMwNfi4oq72WgzDupx7+GwGHpvE9TVhu61Dlha0y41W2jhZG+nPaef3 ciZ4Qyj7GoUTHYhrNfKbd1NcUy9NlWVXPjU9wnWiMGTw5MTtJPAfJd7lzoCJybpRM84Y 1n8LdjQaolq8NB9jGaAjC5SjFpqVno0S+XZd2ek2uo0Qxmy8f2BpkPm+cbfQvC9Z4aA/ xxlZn01KZwphPR6QDIEUid6HMWEdJaZPfTFWEa9Zw2J5ZuRK5D5SiGJEjk81Hptzr9ht FR3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=KZwG7Q8s; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si4323530ejf.306.2020.10.08.11.34.44; Thu, 08 Oct 2020 11:35:07 -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=@oracle.com header.s=corp-2020-01-29 header.b=KZwG7Q8s; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731775AbgJHRLc (ORCPT + 99 others); Thu, 8 Oct 2020 13:11:32 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:48092 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730942AbgJHRLb (ORCPT ); Thu, 8 Oct 2020 13:11:31 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 098GsLY1177179; Thu, 8 Oct 2020 17:11:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=YFmg0lJdUbAFjHtInWo6Z7HAeezH7FiwCiDQdlKA67k=; b=KZwG7Q8s/PvRBPFfsWAtJlkoDBxQVV5wu138nlB0AytnhI/suD8+wr4OZ/xC2OZ9jiCO +6RaPdDOptmFe5/nL13GLsIsxj1b4B2lXhp8sWC5nairV+Rdo/iM4rCXcV9MOAJkaEun 0wbp5aZgHSxMj1KMHrueP+VmmqEF/fr7D1Kh/qUm9m5hNRxwBP13xs3Pjk+zwQUttpaU 79/xBgoVJlSY08Q9V5Ts7lJS9fErSaujfJycnTS8zzDCx+EoA4vB77V+Oy5q88xrN0cV Ennqdv2yR05GJMdWvOZhxPFN9/mqJsHZPDhGJ6yZKMiH8JIq0YEGDknnxbJtzSOXHbnp wA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 33xetb9391-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 08 Oct 2020 17:11:25 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 098GtOIL043089; Thu, 8 Oct 2020 17:11:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 33y2vrajqq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Oct 2020 17:11:25 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 098HBNRC025791; Thu, 8 Oct 2020 17:11:23 GMT Received: from [20.15.0.202] (/73.88.28.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Oct 2020 10:11:23 -0700 Subject: Re: [PATCH v2 1/1] scsi: libiscsi: fix NOP race condition To: lduncan@suse.com, linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, open-iscsi@googlegroups.com, martin.petersen@oracle.com, mchristi@redhat.com, hare@suse.com References: <02b452b2e33d0728091d27d44794934c134a803e.1601058301.git.lduncan@suse.com> From: Mike Christie Message-ID: <5e1fb4eb-dd10-dbad-3da9-e8affc4f5cf0@oracle.com> Date: Thu, 8 Oct 2020 12:11:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <02b452b2e33d0728091d27d44794934c134a803e.1601058301.git.lduncan@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9768 signatures=668681 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 malwarescore=0 suspectscore=2 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010080126 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9768 signatures=668681 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxscore=0 clxscore=1011 priorityscore=1501 adultscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 malwarescore=0 suspectscore=2 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010080126 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/25/20 1:41 PM, lduncan@suse.com wrote: > From: Lee Duncan > > iSCSI NOPs are sometimes "lost", mistakenly sent to the > user-land iscsid daemon instead of handled in the kernel, > as they should be, resulting in a message from the daemon like: > >> iscsid: Got nop in, but kernel supports nop handling. > > This can occur because of the forward- and back-locks > in the kernel iSCSI code, and the fact that an iSCSI NOP > response can be processed before processing of the NOP send > is complete. This can result in "conn->ping_task" being NULL > in iscsi_nop_out_rsp(), when the pointer is actually in > the process of being set. > > To work around this, we add a new state to the "ping_task" > pointer. In addition to NULL (not assigned) and a pointer > (assigned), we add the state "being set", which is signaled > with an INVALID pointer (using "-1"). > > Signed-off-by: Lee Duncan > --- > drivers/scsi/libiscsi.c | 13 ++++++++++--- > include/scsi/libiscsi.h | 3 +++ > 2 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c > index 1e9c3171fa9f..cade108c33b6 100644 > --- a/drivers/scsi/libiscsi.c > +++ b/drivers/scsi/libiscsi.c > @@ -738,6 +738,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, > task->conn->session->age); > } > > + if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK)) > + WRITE_ONCE(conn->ping_task, task); > + > if (!ihost->workq) { > if (iscsi_prep_mgmt_task(conn, task)) > goto free_task; I think the API gets a little weird now where in some cases __iscsi_conn_send_pdu checks the opcode to see what type of request it is but above we the caller sets the ping_task. For login, tmfs and passthrough, we assume the __iscsi_conn_send_pdu has sent or cleaned up everything. I think it might be nicer to just have __iscsi_conn_send_pdu set the ping_task field before doing the xmit/queue call. It would then work similar to the conn->login_task case where that function knows about that special task too. So in __iscsi_conn_send_pdu add a "if (opcode == ISCSI_OP_NOOP_OUT)", and check if it's a nop we need to track. If so set conn->ping_task.