From nobody Fri May 17 02:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1651132432; cv=none; d=zohomail.com; s=zohoarc; b=fEIWk0TfPXZc6RpX0fRTocooF6+99UHqjRljThYIrUMY2H46ZwlUb17hieczbZBcLVPQ/X788of7dJ9w+nOyjdw0GYzGEygGYqymuNyH6Rnn2HjOWn69qcy2VAUSVjrWJWyqSfIApIKshqKSqpZGP82Ij9KVdcvP4xLWdMuT6ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651132432; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FZ3HQWGQIijrKpRTy/DK1bE6hLtaRKbTQP99RtUeXZU=; b=WCGLL2pdIiiCqhcTsSw0s8nkShPfwTsAwesJcEWxQVGsMpqJeDUugbsjluDSP9sekN87RCMXLaYt8Bd6XJHIqgxeRiN6E16ma71MKXWD1JBvrg5K5pzEASiU7xTC7DOCm82Q9e5WIFv7a17ln+wNuoUvLkkjpGAVs5vKrEg0AMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651132432831588.381818640431; Thu, 28 Apr 2022 00:53:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.316084.534825 (Exim 4.92) (envelope-from ) id 1njyxv-00043Q-O1; Thu, 28 Apr 2022 07:53:31 +0000 Received: by outflank-mailman (output) from mailman id 316084.534825; Thu, 28 Apr 2022 07:53:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njyxv-00042b-FO; Thu, 28 Apr 2022 07:53:31 +0000 Received: by outflank-mailman (input) for mailman id 316084; Thu, 28 Apr 2022 07:53:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njyxt-0003jr-I3 for xen-devel@lists.xenproject.org; Thu, 28 Apr 2022 07:53:29 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 49c964a4-c6c8-11ec-8fc3-03012f2f19d4; Thu, 28 Apr 2022 09:53:27 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6F77A1F88A; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3CDA913AF8; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aAN4DfdHamIoHAAAMHmgww (envelope-from ); Thu, 28 Apr 2022 07:53:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 49c964a4-c6c8-11ec-8fc3-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651132407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FZ3HQWGQIijrKpRTy/DK1bE6hLtaRKbTQP99RtUeXZU=; b=ECk+vYsxELyggamzu+fuy1Zg+vf3nxF8Xo8jfyaBEZ5MSiWoM3kjkusDS3n/hYiRHbrfRf Nf3kM6vz9MrZAUvcswEVd/h4c+g3zQxeLSzcaiBTOfK5cX0KozAVYCpMadi+hLPF/edAtj bo9+5HS5avOOL7Uemt9gJLBheTHiTYk= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v2 1/4] xen: update vscsiif.h Date: Thu, 28 Apr 2022 09:53:20 +0200 Message-Id: <20220428075323.12853-2-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220428075323.12853-1-jgross@suse.com> References: <20220428075323.12853-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651132434878100003 Content-Type: text/plain; charset="utf-8" Update include/xen/interface/io/vscsiif.h to its newest version. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- include/xen/interface/io/vscsiif.h | 133 ++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 4 deletions(-) diff --git a/include/xen/interface/io/vscsiif.h b/include/xen/interface/io/= vscsiif.h index 1f6047d3de44..7ea4dc9611c4 100644 --- a/include/xen/interface/io/vscsiif.h +++ b/include/xen/interface/io/vscsiif.h @@ -43,7 +43,7 @@ * * A string specifying the backend device: either a 4-tuple "h:c:t:l" * (host, controller, target, lun, all integers), or a WWN (e.g. - * "naa.60014054ac780582"). + * "naa.60014054ac780582:0"). * * v-dev * Values: string @@ -87,6 +87,75 @@ * response structures. */ =20 +/* + * Xenstore format in practice + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + * + * The backend driver uses a single_host:many_devices notation to manage d= omU + * devices. Everything is stored in /local/domain//backend/= vscsi/. + * The xenstore layout looks like this (dom0 is assumed to be the backend_= domid): + * + * //feature-host =3D "0" + * //frontend =3D "/local/domain//device/vscsi/0" + * //frontend-id =3D "" + * //online =3D "1" + * //state =3D "4" + * //vscsi-devs/dev-0/p-dev =3D "8:0:2:1" or "naa.wwn:lu= n" + * //vscsi-devs/dev-0/state =3D "4" + * //vscsi-devs/dev-0/v-dev =3D "0:0:0:0" + * //vscsi-devs/dev-1/p-dev =3D "8:0:2:2" + * //vscsi-devs/dev-1/state =3D "4" + * //vscsi-devs/dev-1/v-dev =3D "0:0:1:0" + * + * The frontend driver maintains its state in + * /local/domain//device/vscsi/. + * + * /backend =3D "/local/domain/0/backend/vscsi//" + * /backend-id =3D "0" + * /event-channel =3D "20" + * /ring-ref =3D "43" + * /state =3D "4" + * /vscsi-devs/dev-0/state =3D "4" + * /vscsi-devs/dev-1/state =3D "4" + * + * In addition to the entries for backend and frontend these flags are sto= red + * for the toolstack: + * + * //vscsi-devs/dev-1/p-devname =3D "/dev/$device" + * //libxl_ctrl_index =3D "0" + * + * + * Backend/frontend protocol + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + * + * To create a vhost along with a device: + * //feature-host =3D "0" + * //frontend =3D "/local/domain//device/vscsi/0" + * //frontend-id =3D "" + * //online =3D "1" + * //state =3D "1" + * //vscsi-devs/dev-0/p-dev =3D "8:0:2:1" + * //vscsi-devs/dev-0/state =3D "1" + * //vscsi-devs/dev-0/v-dev =3D "0:0:0:0" + * Wait for //state + //vscsi-devs/dev-0/state= become 4 + * + * To add another device to a vhost: + * //state =3D "7" + * //vscsi-devs/dev-1/p-dev =3D "8:0:2:2" + * //vscsi-devs/dev-1/state =3D "1" + * //vscsi-devs/dev-1/v-dev =3D "0:0:1:0" + * Wait for //state + //vscsi-devs/dev-1/state= become 4 + * + * To remove a device from a vhost: + * //state =3D "7" + * //vscsi-devs/dev-1/state =3D "5" + * Wait for //state to become 4 + * Wait for //vscsi-devs/dev-1/state become 6 + * Remove //vscsi-devs/dev-1/{state,p-dev,v-dev,p-devname} + * Remove //vscsi-devs/dev-1/ + * + */ + /* Requests from the frontend to the backend */ =20 /* @@ -117,7 +186,8 @@ * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segme= nt * elements referencing the target data buffers is calculated from the len= gths * of the seg[] elements (the sum of all valid seg[].length divided by the - * size of one scsiif_request_segment structure). + * size of one scsiif_request_segment structure). The frontend may use a m= ix of + * direct and indirect requests. */ #define VSCSIIF_ACT_SCSI_CDB 1 =20 @@ -154,12 +224,14 @@ =20 /* * based on Linux kernel 2.6.18, still valid + * * Changing these values requires support of multiple protocols via the ri= ngs * as "old clients" will blindly use these values and the resulting struct= ure * sizes. */ #define VSCSIIF_MAX_COMMAND_SIZE 16 #define VSCSIIF_SENSE_BUFFERSIZE 96 +#define VSCSIIF_PAGE_SIZE 4096 =20 struct scsiif_request_segment { grant_ref_t gref; @@ -167,7 +239,8 @@ struct scsiif_request_segment { uint16_t length; }; =20 -#define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segm= ent)) +#define VSCSIIF_SG_PER_PAGE (VSCSIIF_PAGE_SIZE / \ + sizeof(struct scsiif_request_segment)) =20 /* Size of one request is 252 bytes */ struct vscsiif_request { @@ -207,6 +280,58 @@ struct vscsiif_response { uint32_t reserved[36]; }; =20 +/* SCSI I/O status from vscsiif_response->rslt */ +#define XEN_VSCSIIF_RSLT_STATUS(x) ((x) & 0x00ff) + +/* Host I/O status from vscsiif_response->rslt */ +#define XEN_VSCSIIF_RSLT_HOST(x) (((x) & 0x00ff0000) >> 16) +#define XEN_VSCSIIF_RSLT_HOST_OK 0 +/* Couldn't connect before timeout */ +#define XEN_VSCSIIF_RSLT_HOST_NO_CONNECT 1 +/* Bus busy through timeout */ +#define XEN_VSCSIIF_RSLT_HOST_BUS_BUSY 2 +/* Timed out for other reason */ +#define XEN_VSCSIIF_RSLT_HOST_TIME_OUT 3 +/* Bad target */ +#define XEN_VSCSIIF_RSLT_HOST_BAD_TARGET 4 +/* Abort for some other reason */ +#define XEN_VSCSIIF_RSLT_HOST_ABORT 5 +/* Parity error */ +#define XEN_VSCSIIF_RSLT_HOST_PARITY 6 +/* Internal error */ +#define XEN_VSCSIIF_RSLT_HOST_ERROR 7 +/* Reset by somebody */ +#define XEN_VSCSIIF_RSLT_HOST_RESET 8 +/* Unexpected interrupt */ +#define XEN_VSCSIIF_RSLT_HOST_BAD_INTR 9 +/* Force command past mid-layer */ +#define XEN_VSCSIIF_RSLT_HOST_PASSTHROUGH 10 +/* Retry requested */ +#define XEN_VSCSIIF_RSLT_HOST_SOFT_ERROR 11 +/* Hidden retry requested */ +#define XEN_VSCSIIF_RSLT_HOST_IMM_RETRY 12 +/* Requeue command requested */ +#define XEN_VSCSIIF_RSLT_HOST_REQUEUE 13 +/* Transport error disrupted I/O */ +#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_DISRUPTED 14 +/* Transport class fastfailed */ +#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_FAILFAST 15 +/* Permanent target failure */ +#define XEN_VSCSIIF_RSLT_HOST_TARGET_FAILURE 16 +/* Permanent nexus failure on path */ +#define XEN_VSCSIIF_RSLT_HOST_NEXUS_FAILURE 17 +/* Space allocation on device failed */ +#define XEN_VSCSIIF_RSLT_HOST_ALLOC_FAILURE 18 +/* Medium error */ +#define XEN_VSCSIIF_RSLT_HOST_MEDIUM_ERROR 19 +/* Transport marginal errors */ +#define XEN_VSCSIIF_RSLT_HOST_TRANSPORT_MARGINAL 20 + +/* Result values of reset operations */ +#define XEN_VSCSIIF_RSLT_RESET_SUCCESS 0x2002 +#define XEN_VSCSIIF_RSLT_RESET_FAILED 0x2003 + DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response= ); =20 -#endif /*__XEN__PUBLIC_IO_SCSI_H__*/ + +#endif /*__XEN__PUBLIC_IO_SCSI_H__*/ --=20 2.34.1 From nobody Fri May 17 02:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1651132433; cv=none; d=zohomail.com; s=zohoarc; b=UK2QAMtO2mwVjfU+zqXwfmyuChLUoNYYqbsbDQFSRkcU24AiX88WkDOZBVY3j5m9ek0xsKmNTNrVcNsh/IqudgPdnVI7iRtmWMVKdcl6cqWfdwzOOGRxlPdEAu1gipc/auVLIyOTPayMZyJG+2AXFRa1XjxCW2av5uiR5s+M37I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651132433; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e7smBjs6Cs54j9gtj63aB2bUTDoqIo4j1UzSK6xvBWg=; b=ZkBrBl5U9O/6/JLmFrGg4xcWJbOVAzRQBhyHzdVoBWget9S2zt1/sOhp7Z7rmneAa3HzvlX8w3Qxh31FuVE1R8Fsx7/FD7mHF8dHU1fOZ1ayOXAXbt7j5TGI4crKUuaiaiRgvZXJxXfu/ghlEQHI8v0MAxmFI+HNBmH3vaOsn3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651132433077188.00540535851917; Thu, 28 Apr 2022 00:53:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.316083.534818 (Exim 4.92) (envelope-from ) id 1njyxv-0003zp-9h; Thu, 28 Apr 2022 07:53:31 +0000 Received: by outflank-mailman (output) from mailman id 316083.534818; Thu, 28 Apr 2022 07:53:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njyxv-0003zi-6P; Thu, 28 Apr 2022 07:53:31 +0000 Received: by outflank-mailman (input) for mailman id 316083; Thu, 28 Apr 2022 07:53:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1njyxt-0003js-47 for xen-devel@lists.xenproject.org; Thu, 28 Apr 2022 07:53:29 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 49eb4655-c6c8-11ec-a405-831a346695d4; Thu, 28 Apr 2022 09:53:28 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AACEE21870; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7707F13AF8; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QDOoG/dHamIoHAAAMHmgww (envelope-from ); Thu, 28 Apr 2022 07:53:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 49eb4655-c6c8-11ec-a405-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651132407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e7smBjs6Cs54j9gtj63aB2bUTDoqIo4j1UzSK6xvBWg=; b=rpwyrV9E6S/d9bU0Olq3d0lZ/V4hx2lhfq8AigAGZwgiad+EOGLOiKyt3wOw0lACnEj/Gr 7XLQTGdTp6LuN7zjo3FEYVQEXr1TbhFcR68hqxGB320Bs6nK+htjcjCLxPBzEmSU/kYSB3 PFGspBJj5GfMqbXPksQC1qLa2e2SWs0= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v2 2/4] xen/scsiback: use new command result macros Date: Thu, 28 Apr 2022 09:53:21 +0200 Message-Id: <20220428075323.12853-3-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220428075323.12853-1-jgross@suse.com> References: <20220428075323.12853-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1651132435102100009 Content-Type: text/plain; charset="utf-8" Instead of using the kernel's values for the result of PV scsi operations use the values of the interface definition. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- V2: - fix scsiback_result() to pass through lowest 16 bits of result - use XEN_VSCSIIF_RSLT_HOST() instead of open coding it (Boris Ostrovsky) --- drivers/xen/xen-scsiback.c | 82 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 0c5e565aa8cf..7a0c93acc2c5 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -280,6 +280,82 @@ static void scsiback_free_translation_entry(struct kre= f *kref) kfree(entry); } =20 +static int32_t scsiback_result(int32_t result) +{ + int32_t host_status; + + switch (XEN_VSCSIIF_RSLT_HOST(result)) { + case DID_OK: + host_status =3D XEN_VSCSIIF_RSLT_HOST_OK; + break; + case DID_NO_CONNECT: + host_status =3D XEN_VSCSIIF_RSLT_HOST_NO_CONNECT; + break; + case DID_BUS_BUSY: + host_status =3D XEN_VSCSIIF_RSLT_HOST_BUS_BUSY; + break; + case DID_TIME_OUT: + host_status =3D XEN_VSCSIIF_RSLT_HOST_TIME_OUT; + break; + case DID_BAD_TARGET: + host_status =3D XEN_VSCSIIF_RSLT_HOST_BAD_TARGET; + break; + case DID_ABORT: + host_status =3D XEN_VSCSIIF_RSLT_HOST_ABORT; + break; + case DID_PARITY: + host_status =3D XEN_VSCSIIF_RSLT_HOST_PARITY; + break; + case DID_ERROR: + host_status =3D XEN_VSCSIIF_RSLT_HOST_ERROR; + break; + case DID_RESET: + host_status =3D XEN_VSCSIIF_RSLT_HOST_RESET; + break; + case DID_BAD_INTR: + host_status =3D XEN_VSCSIIF_RSLT_HOST_BAD_INTR; + break; + case DID_PASSTHROUGH: + host_status =3D XEN_VSCSIIF_RSLT_HOST_PASSTHROUGH; + break; + case DID_SOFT_ERROR: + host_status =3D XEN_VSCSIIF_RSLT_HOST_SOFT_ERROR; + break; + case DID_IMM_RETRY: + host_status =3D XEN_VSCSIIF_RSLT_HOST_IMM_RETRY; + break; + case DID_REQUEUE: + host_status =3D XEN_VSCSIIF_RSLT_HOST_REQUEUE; + break; + case DID_TRANSPORT_DISRUPTED: + host_status =3D XEN_VSCSIIF_RSLT_HOST_TRANSPORT_DISRUPTED; + break; + case DID_TRANSPORT_FAILFAST: + host_status =3D XEN_VSCSIIF_RSLT_HOST_TRANSPORT_FAILFAST; + break; + case DID_TARGET_FAILURE: + host_status =3D XEN_VSCSIIF_RSLT_HOST_TARGET_FAILURE; + break; + case DID_NEXUS_FAILURE: + host_status =3D XEN_VSCSIIF_RSLT_HOST_NEXUS_FAILURE; + break; + case DID_ALLOC_FAILURE: + host_status =3D XEN_VSCSIIF_RSLT_HOST_ALLOC_FAILURE; + break; + case DID_MEDIUM_ERROR: + host_status =3D XEN_VSCSIIF_RSLT_HOST_MEDIUM_ERROR; + break; + case DID_TRANSPORT_MARGINAL: + host_status =3D XEN_VSCSIIF_RSLT_HOST_TRANSPORT_MARGINAL; + break; + default: + host_status =3D XEN_VSCSIIF_RSLT_HOST_ERROR; + break; + } + + return (host_status << 16) | (result & 0x00ffff); +} + static void scsiback_send_response(struct vscsibk_info *info, char *sense_buffer, int32_t result, uint32_t resid, uint16_t rqid) @@ -295,7 +371,7 @@ static void scsiback_send_response(struct vscsibk_info = *info, ring_res =3D RING_GET_RESPONSE(&info->ring, info->ring.rsp_prod_pvt); info->ring.rsp_prod_pvt++; =20 - ring_res->rslt =3D result; + ring_res->rslt =3D scsiback_result(result); ring_res->rqid =3D rqid; =20 if (sense_buffer !=3D NULL && @@ -555,7 +631,7 @@ static void scsiback_device_action(struct vscsibk_pend = *pending_req, struct scsiback_nexus *nexus =3D tpg->tpg_nexus; struct se_cmd *se_cmd =3D &pending_req->se_cmd; u64 unpacked_lun =3D pending_req->v2p->lun; - int rc, err =3D FAILED; + int rc, err =3D XEN_VSCSIIF_RSLT_RESET_FAILED; =20 init_completion(&pending_req->tmr_done); =20 @@ -569,7 +645,7 @@ static void scsiback_device_action(struct vscsibk_pend = *pending_req, wait_for_completion(&pending_req->tmr_done); =20 err =3D (se_cmd->se_tmr_req->response =3D=3D TMR_FUNCTION_COMPLETE) ? - SUCCESS : FAILED; + XEN_VSCSIIF_RSLT_RESET_SUCCESS : XEN_VSCSIIF_RSLT_RESET_FAILED; =20 scsiback_do_resp_with_sense(NULL, err, 0, pending_req); transport_generic_free_cmd(&pending_req->se_cmd, 0); --=20 2.34.1 From nobody Fri May 17 02:41:13 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43EDFC433EF for ; Thu, 28 Apr 2022 07:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343604AbiD1H5A (ORCPT ); Thu, 28 Apr 2022 03:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343527AbiD1H4o (ORCPT ); Thu, 28 Apr 2022 03:56:44 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46EC65F243; Thu, 28 Apr 2022 00:53:29 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EF0AC1F88B; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651132407; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MG3xPy2sxwW3smkj4Gb01xXTe3bOEE9V2zLYcAQe4m4=; b=W2PKreHag+faFXtZey1DQtRyCfjXUvaiwNS4vQn8a9/RMSSRl4hUzerhLBlCJHRDA/Veop c47OwwShTQAf6Xz2U43FD86iGylFxlV1n1Nv4KUZtuKQzB1Nb66rGK+fbbjQHML7oBzImb oOOMnK/kvlNQZgqkYK3Uaheqd2NufII= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B26F113AF8; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yDYnKvdHamIoHAAAMHmgww (envelope-from ); Thu, 28 Apr 2022 07:53:27 +0000 From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH v2 3/4] xen/scsifront: use new command result macros Date: Thu, 28 Apr 2022 09:53:22 +0200 Message-Id: <20220428075323.12853-4-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220428075323.12853-1-jgross@suse.com> References: <20220428075323.12853-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a translation layer for the command result values. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- drivers/scsi/xen-scsifront.c | 64 +++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c index 12109e4c73d4..8511bfc62963 100644 --- a/drivers/scsi/xen-scsifront.c +++ b/drivers/scsi/xen-scsifront.c @@ -243,6 +243,56 @@ static void scsifront_gnttab_done(struct vscsifrnt_inf= o *info, kfree(shadow->sg); } =20 +static unsigned int scsifront_host_byte(int32_t rslt) +{ + switch (XEN_VSCSIIF_RSLT_HOST(rslt)) { + case XEN_VSCSIIF_RSLT_HOST_OK: + return DID_OK; + case XEN_VSCSIIF_RSLT_HOST_NO_CONNECT: + return DID_NO_CONNECT; + case XEN_VSCSIIF_RSLT_HOST_BUS_BUSY: + return DID_BUS_BUSY; + case XEN_VSCSIIF_RSLT_HOST_TIME_OUT: + return DID_TIME_OUT; + case XEN_VSCSIIF_RSLT_HOST_BAD_TARGET: + return DID_BAD_TARGET; + case XEN_VSCSIIF_RSLT_HOST_ABORT: + return DID_ABORT; + case XEN_VSCSIIF_RSLT_HOST_PARITY: + return DID_PARITY; + case XEN_VSCSIIF_RSLT_HOST_ERROR: + return DID_ERROR; + case XEN_VSCSIIF_RSLT_HOST_RESET: + return DID_RESET; + case XEN_VSCSIIF_RSLT_HOST_BAD_INTR: + return DID_BAD_INTR; + case XEN_VSCSIIF_RSLT_HOST_PASSTHROUGH: + return DID_PASSTHROUGH; + case XEN_VSCSIIF_RSLT_HOST_SOFT_ERROR: + return DID_SOFT_ERROR; + case XEN_VSCSIIF_RSLT_HOST_IMM_RETRY: + return DID_IMM_RETRY; + case XEN_VSCSIIF_RSLT_HOST_REQUEUE: + return DID_REQUEUE; + case XEN_VSCSIIF_RSLT_HOST_TRANSPORT_DISRUPTED: + return DID_TRANSPORT_DISRUPTED; + case XEN_VSCSIIF_RSLT_HOST_TRANSPORT_FAILFAST: + return DID_TRANSPORT_FAILFAST; + case XEN_VSCSIIF_RSLT_HOST_TARGET_FAILURE: + return DID_TARGET_FAILURE; + case XEN_VSCSIIF_RSLT_HOST_NEXUS_FAILURE: + return DID_NEXUS_FAILURE; + case XEN_VSCSIIF_RSLT_HOST_ALLOC_FAILURE: + return DID_ALLOC_FAILURE; + case XEN_VSCSIIF_RSLT_HOST_MEDIUM_ERROR: + return DID_MEDIUM_ERROR; + case XEN_VSCSIIF_RSLT_HOST_TRANSPORT_MARGINAL: + return DID_TRANSPORT_MARGINAL; + default: + return DID_ERROR; + } +} + static void scsifront_cdb_cmd_done(struct vscsifrnt_info *info, struct vscsiif_response *ring_rsp) { @@ -250,7 +300,6 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_inf= o *info, struct scsi_cmnd *sc; uint32_t id; uint8_t sense_len; - int result; =20 id =3D ring_rsp->rqid; shadow =3D info->shadow[id]; @@ -261,12 +310,8 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_in= fo *info, scsifront_gnttab_done(info, shadow); scsifront_put_rqid(info, id); =20 - result =3D ring_rsp->rslt; - if (result >> 24) - set_host_byte(sc, DID_ERROR); - else - set_host_byte(sc, host_byte(result)); - set_status_byte(sc, result & 0xff); + set_host_byte(sc, scsifront_host_byte(ring_rsp->rslt)); + set_status_byte(sc, XEN_VSCSIIF_RSLT_STATUS(ring_rsp->rslt)); scsi_set_resid(sc, ring_rsp->residual_len); =20 sense_len =3D min_t(uint8_t, VSCSIIF_SENSE_BUFFERSIZE, @@ -290,7 +335,10 @@ static void scsifront_sync_cmd_done(struct vscsifrnt_i= nfo *info, shadow->wait_reset =3D 1; switch (shadow->rslt_reset) { case RSLT_RESET_WAITING: - shadow->rslt_reset =3D ring_rsp->rslt; + if (ring_rsp->rslt =3D=3D XEN_VSCSIIF_RSLT_RESET_SUCCESS) + shadow->rslt_reset =3D SUCCESS; + else + shadow->rslt_reset =3D FAILED; break; case RSLT_RESET_ERR: kick =3D _scsifront_put_rqid(info, id); --=20 2.34.1 From nobody Fri May 17 02:41:13 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E98C43219 for ; Thu, 28 Apr 2022 07:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343555AbiD1H4s (ORCPT ); Thu, 28 Apr 2022 03:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343529AbiD1H4o (ORCPT ); Thu, 28 Apr 2022 03:56:44 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0DD85F256; Thu, 28 Apr 2022 00:53:29 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 410E81F88C; Thu, 28 Apr 2022 07:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1651132408; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQy1x+fRNHgv0+hbA7kZO4avv6jlEcwjeAC24DRrSzI=; b=aT2gbQ4cLusb6bFR/NVvfh2fUPPiBfScImg4BQauGsfXBe4tL9IvgxoXAd1IB/RhKzgOdZ sJJ8KvFn5k04VCyST136HD4Mo7vqC1tdff9LRZ+bWfwxN0JB29OJLWU0Fim4lB8nn62eQK x71dMrdYjnsr0/Cra1B4XnCmpFJ8P8E= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0412813AF8; Thu, 28 Apr 2022 07:53:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uGFaO/dHamIoHAAAMHmgww (envelope-from ); Thu, 28 Apr 2022 07:53:27 +0000 From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH v2 4/4] xen/scsifront: harden driver against malicious backend Date: Thu, 28 Apr 2022 09:53:23 +0200 Message-Id: <20220428075323.12853-5-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220428075323.12853-1-jgross@suse.com> References: <20220428075323.12853-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of relying on a well behaved PV scsi backend verify all meta data received from the backend and avoid multiple reads of the same data from the shared ring page. In case any illegal data from the backend is detected switch the PV device to a new "error" state and deactivate it for further use. Use the "lateeoi" variant for the event channel in order to avoid event storms blocking the guest. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- V2: - only remove spurious flag from eoiflag (Boris Ostrovsky) --- drivers/scsi/xen-scsifront.c | 104 +++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c index 8511bfc62963..56173beecbc6 100644 --- a/drivers/scsi/xen-scsifront.c +++ b/drivers/scsi/xen-scsifront.c @@ -83,6 +83,8 @@ struct vscsifrnt_shadow { uint16_t rqid; uint16_t ref_rqid; =20 + bool inflight; + unsigned int nr_grants; /* number of grants in gref[] */ struct scsiif_request_segment *sg; /* scatter/gather elements */ struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE]; @@ -104,7 +106,11 @@ struct vscsifrnt_info { struct xenbus_device *dev; =20 struct Scsi_Host *host; - int host_active; + enum { + STATE_INACTIVE, + STATE_ACTIVE, + STATE_ERROR + } host_active; =20 unsigned int evtchn; unsigned int irq; @@ -217,6 +223,8 @@ static int scsifront_do_request(struct vscsifrnt_info *= info, for (i =3D 0; i < (shadow->nr_segments & ~VSCSIIF_SG_GRANT); i++) ring_req->seg[i] =3D shadow->seg[i]; =20 + shadow->inflight =3D true; + RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(ring, notify); if (notify) notify_remote_via_irq(info->irq); @@ -224,6 +232,13 @@ static int scsifront_do_request(struct vscsifrnt_info = *info, return 0; } =20 +static void scsifront_set_error(struct vscsifrnt_info *info, const char *m= sg) +{ + shost_printk(KERN_ERR, info->host, KBUILD_MODNAME "%s\n" + "Disabling device for further use\n", msg); + info->host_active =3D STATE_ERROR; +} + static void scsifront_gnttab_done(struct vscsifrnt_info *info, struct vscsifrnt_shadow *shadow) { @@ -234,9 +249,8 @@ static void scsifront_gnttab_done(struct vscsifrnt_info= *info, =20 for (i =3D 0; i < shadow->nr_grants; i++) { if (unlikely(!gnttab_try_end_foreign_access(shadow->gref[i]))) { - shost_printk(KERN_ALERT, info->host, KBUILD_MODNAME - "grant still in use by backend\n"); - BUG(); + scsifront_set_error(info, "grant still in use by backend"); + return; } } =20 @@ -308,6 +322,8 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_inf= o *info, BUG_ON(sc =3D=3D NULL); =20 scsifront_gnttab_done(info, shadow); + if (info->host_active =3D=3D STATE_ERROR) + return; scsifront_put_rqid(info, id); =20 set_host_byte(sc, scsifront_host_byte(ring_rsp->rslt)); @@ -348,9 +364,7 @@ static void scsifront_sync_cmd_done(struct vscsifrnt_in= fo *info, scsifront_wake_up(info); return; default: - shost_printk(KERN_ERR, info->host, KBUILD_MODNAME - "bad reset state %d, possibly leaking %u\n", - shadow->rslt_reset, id); + scsifront_set_error(info, "bad reset state"); break; } spin_unlock_irqrestore(&info->shadow_lock, flags); @@ -361,28 +375,41 @@ static void scsifront_sync_cmd_done(struct vscsifrnt_= info *info, static void scsifront_do_response(struct vscsifrnt_info *info, struct vscsiif_response *ring_rsp) { - if (WARN(ring_rsp->rqid >=3D VSCSIIF_MAX_REQS || - test_bit(ring_rsp->rqid, info->shadow_free_bitmap), - "illegal rqid %u returned by backend!\n", ring_rsp->rqid)) + struct vscsifrnt_shadow *shadow; + + if (ring_rsp->rqid >=3D VSCSIIF_MAX_REQS || + !info->shadow[ring_rsp->rqid]->inflight) { + scsifront_set_error(info, "illegal rqid returned by backend!"); return; + } + shadow =3D info->shadow[ring_rsp->rqid]; + shadow->inflight =3D false; =20 - if (info->shadow[ring_rsp->rqid]->act =3D=3D VSCSIIF_ACT_SCSI_CDB) + if (shadow->act =3D=3D VSCSIIF_ACT_SCSI_CDB) scsifront_cdb_cmd_done(info, ring_rsp); else scsifront_sync_cmd_done(info, ring_rsp); } =20 -static int scsifront_ring_drain(struct vscsifrnt_info *info) +static int scsifront_ring_drain(struct vscsifrnt_info *info, + unsigned int *eoiflag) { - struct vscsiif_response *ring_rsp; + struct vscsiif_response ring_rsp; RING_IDX i, rp; int more_to_do =3D 0; =20 - rp =3D info->ring.sring->rsp_prod; - rmb(); /* ordering required respective to dom0 */ + rp =3D READ_ONCE(info->ring.sring->rsp_prod); + virt_rmb(); /* ordering required respective to backend */ + if (RING_RESPONSE_PROD_OVERFLOW(&info->ring, rp)) { + scsifront_set_error(info, "illegal number of responses"); + return 0; + } for (i =3D info->ring.rsp_cons; i !=3D rp; i++) { - ring_rsp =3D RING_GET_RESPONSE(&info->ring, i); - scsifront_do_response(info, ring_rsp); + RING_COPY_RESPONSE(&info->ring, i, &ring_rsp); + scsifront_do_response(info, &ring_rsp); + if (info->host_active =3D=3D STATE_ERROR) + return 0; + *eoiflag &=3D ~XEN_EOI_FLAG_SPURIOUS; } =20 info->ring.rsp_cons =3D i; @@ -395,14 +422,15 @@ static int scsifront_ring_drain(struct vscsifrnt_info= *info) return more_to_do; } =20 -static int scsifront_cmd_done(struct vscsifrnt_info *info) +static int scsifront_cmd_done(struct vscsifrnt_info *info, + unsigned int *eoiflag) { int more_to_do; unsigned long flags; =20 spin_lock_irqsave(info->host->host_lock, flags); =20 - more_to_do =3D scsifront_ring_drain(info); + more_to_do =3D scsifront_ring_drain(info, eoiflag); =20 info->wait_ring_available =3D 0; =20 @@ -416,20 +444,28 @@ static int scsifront_cmd_done(struct vscsifrnt_info *= info) static irqreturn_t scsifront_irq_fn(int irq, void *dev_id) { struct vscsifrnt_info *info =3D dev_id; + unsigned int eoiflag =3D XEN_EOI_FLAG_SPURIOUS; + + if (info->host_active =3D=3D STATE_ERROR) { + xen_irq_lateeoi(irq, XEN_EOI_FLAG_SPURIOUS); + return IRQ_HANDLED; + } =20 - while (scsifront_cmd_done(info)) + while (scsifront_cmd_done(info, &eoiflag)) /* Yield point for this unbounded loop. */ cond_resched(); =20 + xen_irq_lateeoi(irq, eoiflag); + return IRQ_HANDLED; } =20 static void scsifront_finish_all(struct vscsifrnt_info *info) { - unsigned i; + unsigned int i, dummy; struct vscsiif_response resp; =20 - scsifront_ring_drain(info); + scsifront_ring_drain(info, &dummy); =20 for (i =3D 0; i < VSCSIIF_MAX_REQS; i++) { if (test_bit(i, info->shadow_free_bitmap)) @@ -586,6 +622,9 @@ static int scsifront_queuecommand(struct Scsi_Host *sho= st, unsigned long flags; int err; =20 + if (info->host_active =3D=3D STATE_ERROR) + return SCSI_MLQUEUE_HOST_BUSY; + sc->result =3D 0; =20 shadow->sc =3D sc; @@ -638,6 +677,9 @@ static int scsifront_action_handler(struct scsi_cmnd *s= c, uint8_t act) struct vscsifrnt_shadow *shadow, *s =3D scsi_cmd_priv(sc); int err =3D 0; =20 + if (info->host_active =3D=3D STATE_ERROR) + return FAILED; + shadow =3D kzalloc(sizeof(*shadow), GFP_NOIO); if (!shadow) return FAILED; @@ -709,6 +751,9 @@ static int scsifront_sdev_configure(struct scsi_device = *sdev) struct vscsifrnt_info *info =3D shost_priv(sdev->host); int err; =20 + if (info->host_active =3D=3D STATE_ERROR) + return -EIO; + if (info && current =3D=3D info->curr) { err =3D xenbus_printf(XBT_NIL, info->dev->nodename, info->dev_state_path, "%d", XenbusStateConnected); @@ -784,7 +829,7 @@ static int scsifront_alloc_ring(struct vscsifrnt_info *= info) goto free_gnttab; } =20 - err =3D bind_evtchn_to_irq(info->evtchn); + err =3D bind_evtchn_to_irq_lateeoi(info->evtchn); if (err <=3D 0) { xenbus_dev_fatal(dev, err, "bind_evtchn_to_irq"); goto free_gnttab; @@ -914,7 +959,7 @@ static int scsifront_probe(struct xenbus_device *dev, goto free_sring; } info->host =3D host; - info->host_active =3D 1; + info->host_active =3D STATE_ACTIVE; =20 xenbus_switch_state(dev, XenbusStateInitialised); =20 @@ -982,10 +1027,10 @@ static int scsifront_remove(struct xenbus_device *de= v) pr_debug("%s: %s removed\n", __func__, dev->nodename); =20 mutex_lock(&scsifront_mutex); - if (info->host_active) { + if (info->host_active !=3D STATE_INACTIVE) { /* Scsi_host not yet removed */ scsi_remove_host(info->host); - info->host_active =3D 0; + info->host_active =3D STATE_INACTIVE; } mutex_unlock(&scsifront_mutex); =20 @@ -1009,9 +1054,9 @@ static void scsifront_disconnect(struct vscsifrnt_inf= o *info) */ =20 mutex_lock(&scsifront_mutex); - if (info->host_active) { + if (info->host_active !=3D STATE_INACTIVE) { scsi_remove_host(host); - info->host_active =3D 0; + info->host_active =3D STATE_INACTIVE; } mutex_unlock(&scsifront_mutex); =20 @@ -1029,6 +1074,9 @@ static void scsifront_do_lun_hotplug(struct vscsifrnt= _info *info, int op) unsigned int hst, chn, tgt, lun; struct scsi_device *sdev; =20 + if (info->host_active =3D=3D STATE_ERROR) + return; + dir =3D xenbus_directory(XBT_NIL, dev->otherend, "vscsi-devs", &dir_n); if (IS_ERR(dir)) return; --=20 2.34.1