From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 055C7C77B7E for ; Tue, 2 May 2023 15:22:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptrp2-0001th-H9; Tue, 02 May 2023 11:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptroz-0001tY-L1 for qemu-devel@nongnu.org; Tue, 02 May 2023 11:21:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptrox-0006wZ-1L for qemu-devel@nongnu.org; Tue, 02 May 2023 11:21:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683040897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O1kjfWbyj3zykPV4mxkot03UoMaYj696sk4Wl0CL1mY=; b=fnRZT/SH9AkUZCONGJ/Moikw3vUJBeji49kUbhVptbRSF4UcdpygHg/EppYhGNSvDjQKiq 8DJ1xlwQrC9Byh7FLEJ/9hHWcK+nbGbHiItgWimJ5zyBjeVPTJbPflO9K5meaB6Cur2bxC ZuYLyE54WhG9pu9vFY9P1nF6wz41mq4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-js-j9vUPNr-JzXSEn51u-w-1; Tue, 02 May 2023 11:21:07 -0400 X-MC-Unique: js-j9vUPNr-JzXSEn51u-w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC73E18E5312; Tue, 2 May 2023 15:19:53 +0000 (UTC) Received: from redhat.com (unknown [10.39.193.211]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7EB52026D25; Tue, 2 May 2023 15:19:47 +0000 (UTC) Date: Tue, 2 May 2023 17:19:46 +0200 From: Kevin Wolf To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, Daniel =?iso-8859-1?Q?P=2E_Berrang=E9?= , Juan Quintela , Julia Suvorova , xen-devel@lists.xenproject.org, eesposit@redhat.com, Richard Henderson , Fam Zheng , "Michael S. Tsirkin" , Coiby Xu , David Woodhouse , Marcel Apfelbaum , Peter Lieven , Paul Durrant , "Richard W.M. Jones" , qemu-block@nongnu.org, Stefano Garzarella , Anthony Perard , Stefan Weil , Xie Yongji , Paolo Bonzini , Aarushi Mehta , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , Eduardo Habkost , Stefano Stabellini , Hanna Reitz , Ronnie Sahlberg , Daniil Tatianin Subject: Re: [PATCH v4 03/20] virtio-scsi: avoid race between unplug and transport event Message-ID: References: <20230425172716.1033562-1-stefanha@redhat.com> <20230425172716.1033562-4-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230425172716.1033562-4-stefanha@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Am 25.04.2023 um 19:26 hat Stefan Hajnoczi geschrieben: > Only report a transport reset event to the guest after the SCSIDevice > has been unrealized by qdev_simple_device_unplug_cb(). > > qdev_simple_device_unplug_cb() sets the SCSIDevice's qdev.realized field > to false so that scsi_device_find/get() no longer see it. > > scsi_target_emulate_report_luns() also needs to be updated to filter out > SCSIDevices that are unrealized. > > These changes ensure that the guest driver does not see the SCSIDevice > that's being unplugged if it responds very quickly to the transport > reset event. > > Reviewed-by: Paolo Bonzini > Reviewed-by: Michael S. Tsirkin > Reviewed-by: Daniil Tatianin > Signed-off-by: Stefan Hajnoczi > @@ -1082,6 +1073,15 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, > blk_set_aio_context(sd->conf.blk, qemu_get_aio_context(), NULL); > virtio_scsi_release(s); > } > + > + if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { > + virtio_scsi_acquire(s); > + virtio_scsi_push_event(s, sd, > + VIRTIO_SCSI_T_TRANSPORT_RESET, > + VIRTIO_SCSI_EVT_RESET_REMOVED); > + scsi_bus_set_ua(&s->bus, SENSE_CODE(REPORTED_LUNS_CHANGED)); > + virtio_scsi_release(s); > + } > } s, sd and s->bus are all unrealized at this point, whereas before this patch they were still realized. I couldn't find any practical problem with it, but it made me nervous enough that I thought I should comment on it at least. Should we maybe have documentation on these functions that says that they accept unrealized objects as their parameters? Kevin