From patchwork Wed Jul 12 13:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1806824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T6n3NJnc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1JsB1MKBz20cd for ; Wed, 12 Jul 2023 23:45:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJa8Z-0002Xb-PB; Wed, 12 Jul 2023 09:44:11 -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 1qJa8X-0002XA-V1 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJa8W-0002Ze-8x for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689169447; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s9aMupYmNN0Xiu9XjEFaMh2461cUjzeIVCaTLR5usdQ=; b=T6n3NJncm3fPquYyhhO1PoqSuPHoVtcyF7D/Y/B6u788acY4HAtR/kOcwY9n95EYjrFPFN /6Gvvqj6lNfqQDRbuaLrQkXdnkiutyJD6PdtfSDYXM9lSiSKEYAMpk+79MiAr6GrCX6anq 3vueQnm+/LCSC4RIk+u30lyIhmVErxE= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-6iehIVldMuidtAkPZXEtAQ-1; Wed, 12 Jul 2023 09:44:05 -0400 X-MC-Unique: 6iehIVldMuidtAkPZXEtAQ-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-94a35b0d4ceso401935866b.3 for ; Wed, 12 Jul 2023 06:44:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689169444; x=1691761444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s9aMupYmNN0Xiu9XjEFaMh2461cUjzeIVCaTLR5usdQ=; b=HVGZNyUtFrvxmVQ9L4L4LyBUQcj//IIpvMtUhsSTucIAkvVF7iDpGaMcteXpsu0alf gsVqlaBaVWmSof6bkQBIQIkqS7SF/B2xpPeeQTgEMlCSwwy69WW0ept7Zn1YrF3DZ/4f 6OcPyrFW1ylSwBFIDtVCjeAtxGV1Ki6eCduvQn4dMsIp+oweTklIS0TOzCsKp4UReJyI LV0BeYpghw8tNjnvoirvVsWzJzs3SebMUsNAEGnLufARMOp58N7kmjph3mWSJzjhkL2V MofAYzCSoSZzrJ5yLQsZUbS6KwcyPE6Bdseb0MwnoPxzz6slJYFEYYBe4ZcWHCqWLK6m oh+A== X-Gm-Message-State: ABy/qLYh4EsF0+o+797/kTPUMAVssaochMnGE6YLZdI34S6hdYH0AVcU 3p6SG9LtZMfWDStvOZYXdaMkW++Wy+zkP2tSyN+SoYehgKKiRWDyUUo4kWW8JnqjXo59vfOy4oG C3fkYyP+GASQ051KZ2wUPDEVhGTKGQPYt9NQBxCvwFTNXsPnZeam6Wr4n0k1j9JHnxxQH/FR7Bu 8= X-Received: by 2002:a17:907:b9d3:b0:993:6382:6e34 with SMTP id xa19-20020a170907b9d300b0099363826e34mr15482205ejc.72.1689169444256; Wed, 12 Jul 2023 06:44:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlHso9fjy3BFLz7SDgq4IL0TJ87+yDLxF3B7jADKfkoP4bGyDyccU1S7Xb/4+0uAnDOhdMPzww== X-Received: by 2002:a17:907:b9d3:b0:993:6382:6e34 with SMTP id xa19-20020a170907b9d300b0099363826e34mr15482174ejc.72.1689169443737; Wed, 12 Jul 2023 06:44:03 -0700 (PDT) Received: from localhost.localdomain (host-82-53-134-6.retail.telecomitalia.it. [82.53.134.6]) by smtp.gmail.com with ESMTPSA id e19-20020a170906081300b009929d998ab6sm2568035ejd.131.2023.07.12.06.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 06:44:03 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Mike Christie , Paolo Bonzini , Stefan Hajnoczi , "Michael S . Tsirkin" , Thomas Huth , Mark Kanda , Fam Zheng , Stefano Garzarella Subject: [PATCH 1/3] scsi: fetch unit attention when creating the request Date: Wed, 12 Jul 2023 15:43:50 +0200 Message-ID: <20230712134352.118655-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712134352.118655-1-sgarzare@redhat.com> References: <20230712134352.118655-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Commit 1880ad4f4e ("virtio-scsi: Batched prepare for cmd reqs") split calls to scsi_req_new() and scsi_req_enqueue() in the virtio-scsi device. This had no drawback, until commit 8cc5583abe ("virtio-scsi: Send "REPORTED LUNS CHANGED" sense data upon disk hotplug events") added a bus unit attention. Having the two calls separated, all requests in the batch were prepared calling scsi_req_new() to report a sense. Then only the first one submitted calling scsi_req_enqueue() reported the right sense and reset it to NO_SENSE. The others reported NO_SENSE, causing SCSI errors in Linux. To solve this issue, let's fetch the unit attention as early as possible when we prepare the request, that way only the first request in the batch will carry the right sense. Fixes: 1880ad4f4e ("virtio-scsi: Batched prepare for cmd reqs") Fixes: 8cc5583abe ("virtio-scsi: Send "REPORTED LUNS CHANGED" sense data upon disk hotplug events") Reported-by: Thomas Huth Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2176702 Co-developed-by: Paolo Bonzini Signed-off-by: Stefano Garzarella --- include/hw/scsi/scsi.h | 1 + hw/scsi/scsi-bus.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index e2bb1a2fbf..3692ca82f3 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -108,6 +108,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); /* scsi-bus.c */ struct SCSIReqOps { size_t size; + void (*init_req)(SCSIRequest *req); void (*free_req)(SCSIRequest *req); int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); void (*read_data)(SCSIRequest *req); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index f80f4cb4fc..f083373021 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -412,19 +412,35 @@ static const struct SCSIReqOps reqops_invalid_opcode = { /* SCSIReqOps implementation for unit attention conditions. */ -static int32_t scsi_unit_attention(SCSIRequest *req, uint8_t *buf) +static void scsi_fetch_unit_attention_sense(SCSIRequest *req) { + SCSISense *ua = NULL; + if (req->dev->unit_attention.key == UNIT_ATTENTION) { - scsi_req_build_sense(req, req->dev->unit_attention); + ua = &req->dev->unit_attention; } else if (req->bus->unit_attention.key == UNIT_ATTENTION) { - scsi_req_build_sense(req, req->bus->unit_attention); + ua = &req->bus->unit_attention; } + + /* + * Fetch the unit attention sense immediately so that another + * scsi_req_new does not use reqops_unit_attention. + */ + if (ua) { + scsi_req_build_sense(req, *ua); + *ua = SENSE_CODE(NO_SENSE); + } +} + +static int32_t scsi_unit_attention(SCSIRequest *req, uint8_t *buf) +{ scsi_req_complete(req, CHECK_CONDITION); return 0; } static const struct SCSIReqOps reqops_unit_attention = { .size = sizeof(SCSIRequest), + .init_req = scsi_fetch_unit_attention_sense, .send_command = scsi_unit_attention }; @@ -699,6 +715,11 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, object_ref(OBJECT(d)); object_ref(OBJECT(qbus->parent)); notifier_list_init(&req->cancel_notifiers); + + if (reqops->init_req) { + reqops->init_req(req); + } + trace_scsi_req_alloc(req->dev->id, req->lun, req->tag); return req; } @@ -798,6 +819,15 @@ uint8_t *scsi_req_get_buf(SCSIRequest *req) static void scsi_clear_unit_attention(SCSIRequest *req) { SCSISense *ua; + + /* + * scsi_fetch_unit_attention_sense() already cleaned the unit attention + * in this case. + */ + if (req->ops == &reqops_unit_attention) { + return; + } + if (req->dev->unit_attention.key != UNIT_ATTENTION && req->bus->unit_attention.key != UNIT_ATTENTION) { return; From patchwork Wed Jul 12 13:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1806821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JohvBBcU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1Jrk5bshz20cD for ; Wed, 12 Jul 2023 23:44:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJa8d-0002YL-LE; Wed, 12 Jul 2023 09:44:15 -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 1qJa8b-0002Xz-EP for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJa8Z-0002aE-TJ for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689169450; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GQ/mOfPK6LROxwR4/v8NGbbNQBqo4JCfc2aPuyAhXlI=; b=JohvBBcUsxdIBg48t5dTLAok84rVyY/2xPAdOnTyEW22hWZ20DJW7Xr2JIJqMkTF6B5r56 ZpVSVxnvkhBWTEG8z5w98Vw79LJnIA1o7izmkvliF+qPY7WQNr/o63ar65C504CjouxgMx F+38jZ2pH7dQau67hJCUctUqK8S9UO0= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-EBqGScqcMsGYqY9VixpdSA-1; Wed, 12 Jul 2023 09:44:09 -0400 X-MC-Unique: EBqGScqcMsGYqY9VixpdSA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-993c24f3246so105378466b.1 for ; Wed, 12 Jul 2023 06:44:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689169448; x=1691761448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GQ/mOfPK6LROxwR4/v8NGbbNQBqo4JCfc2aPuyAhXlI=; b=PAFz0rK2Atl96CBwbB3bRHKshaHXUgEvc7PrZfl7sQcNkF20g9MX6f3dwbu3UqGj/k Xfkjh+kLwHbcImYqLgAX12pg9I/otnBzInbsBPMqNfIvU2hv9Z9MT1UVrJTnm3ys/E+7 YrP/iPuthgbzmWgRqYEPCqv/7DmuZdtICNZaFYRY6Z/v2jgfpFOXPXwcn0FWj1aY8S+7 XohaD5twBV5R6oZJtGKkq5cW1d34/iiOWGtyvMkVD5THF4xtsJVEyGwD4aK6l3n58V5V MQ3zCLESlAautc1cOv5Uf7QRlOLqGY9JRLrIRxFTRi6S1GkEO2gW4vG8CuRnMmb7VhiJ VQtw== X-Gm-Message-State: ABy/qLamgirC5BmtIOqcqgov/Lalh/M7AkXadCWQYZ2Bl6A489JNRJ5W KUaEd4CUQ/HJ5AePIBQ4u6JLQuVBBJkctEinYYbYcAZopCDW4VWgO+CuxjnBW1zabaIS5uWCCT8 10B98Y5siEMjlKHalPKFduf2W6JDPVLQBhrwI0jaAKTrH5+JImlRQ11ZyvSs6SfErB+6I2dl4dX M= X-Received: by 2002:a17:906:5352:b0:993:eee4:e704 with SMTP id j18-20020a170906535200b00993eee4e704mr2710891ejo.38.1689169447891; Wed, 12 Jul 2023 06:44:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlE1Gi5HZ+69llj4rGtYbFEzgMRK69+s+UN1zq/V4cAam2qZPYnMz9L0OKU5dtOKAF2Ou7siRA== X-Received: by 2002:a17:906:5352:b0:993:eee4:e704 with SMTP id j18-20020a170906535200b00993eee4e704mr2710862ejo.38.1689169447642; Wed, 12 Jul 2023 06:44:07 -0700 (PDT) Received: from localhost.localdomain (host-82-53-134-6.retail.telecomitalia.it. [82.53.134.6]) by smtp.gmail.com with ESMTPSA id qo11-20020a170907212b00b00992b0745548sm2553416ejb.152.2023.07.12.06.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 06:44:06 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Mike Christie , Paolo Bonzini , Stefan Hajnoczi , "Michael S . Tsirkin" , Thomas Huth , Mark Kanda , Fam Zheng , Stefano Garzarella Subject: [PATCH 2/3] scsi: cleanup scsi_clear_unit_attention() Date: Wed, 12 Jul 2023 15:43:51 +0200 Message-ID: <20230712134352.118655-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712134352.118655-1-sgarzare@redhat.com> References: <20230712134352.118655-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The previous commit moved the unit attention clearing when we create the request. So now we can clean scsi_clear_unit_attention() to handle only the case of the REPORT LUNS command. Suggested-by: Paolo Bonzini Signed-off-by: Stefano Garzarella --- hw/scsi/scsi-bus.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index f083373021..f9c95dfb50 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -828,26 +828,12 @@ static void scsi_clear_unit_attention(SCSIRequest *req) return; } - if (req->dev->unit_attention.key != UNIT_ATTENTION && - req->bus->unit_attention.key != UNIT_ATTENTION) { - return; - } - - /* - * If an INQUIRY command enters the enabled command state, - * the device server shall [not] clear any unit attention condition; - * See also MMC-6, paragraphs 6.5 and 6.6.2. - */ - if (req->cmd.buf[0] == INQUIRY || - req->cmd.buf[0] == GET_CONFIGURATION || - req->cmd.buf[0] == GET_EVENT_STATUS_NOTIFICATION) { - return; - } - if (req->dev->unit_attention.key == UNIT_ATTENTION) { ua = &req->dev->unit_attention; - } else { + } else if (req->bus->unit_attention.key == UNIT_ATTENTION) { ua = &req->bus->unit_attention; + } else { + return; } /* @@ -856,12 +842,10 @@ static void scsi_clear_unit_attention(SCSIRequest *req) * with an additional sense code of REPORTED LUNS DATA HAS CHANGED. */ if (req->cmd.buf[0] == REPORT_LUNS && - !(ua->asc == SENSE_CODE(REPORTED_LUNS_CHANGED).asc && - ua->ascq == SENSE_CODE(REPORTED_LUNS_CHANGED).ascq)) { - return; + ua->asc == SENSE_CODE(REPORTED_LUNS_CHANGED).asc && + ua->ascq == SENSE_CODE(REPORTED_LUNS_CHANGED).ascq) { + *ua = SENSE_CODE(NO_SENSE); } - - *ua = SENSE_CODE(NO_SENSE); } int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len) From patchwork Wed Jul 12 13:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1806823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c1sjLC22; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1Js94msrz20bt for ; Wed, 12 Jul 2023 23:45:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJa8p-0002Zb-Jj; Wed, 12 Jul 2023 09:44:27 -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 1qJa8f-0002YZ-K9 for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:17 -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 1qJa8d-0002b6-VZ for qemu-devel@nongnu.org; Wed, 12 Jul 2023 09:44:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689169455; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4nl9r8RrPFumzNpG2l6zIAWnHuTPJLt25EVA/SzjGHM=; b=c1sjLC22iGhqcAQNgR2HiyyXInFUmfKmsbCNsYcbpB2yTwm2tIoXk1cNRA3b2nARu73Oic c/r7nhbrm9aRfrctBnUbHM2ZF0LHDcAcVUCxGLJqnUcxUt35bJgd5j0CszPvfeYXGqO4iU mX/J3ZUbBU+uh0aFZI2s+1AGvwn45dE= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-Jki_zHLhNNG4V5wxBLJoQg-1; Wed, 12 Jul 2023 09:44:14 -0400 X-MC-Unique: Jki_zHLhNNG4V5wxBLJoQg-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2b6fbf1305fso68981471fa.2 for ; Wed, 12 Jul 2023 06:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689169452; x=1691761452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4nl9r8RrPFumzNpG2l6zIAWnHuTPJLt25EVA/SzjGHM=; b=fLxef1Ky2XJ32VH9xfi1faxNe3uIcIduh33m9cxDfO/1wVPzS1h+ckhsua6ZCnUITf xXpXTTORjfnXmEt1Z1fieeKk9crBwSydj+xyai4h4xBnZpIKdv6JHd8Iwo7vK2MqqQuK 5CBH2A5FOCV1JNQbVvBREpjVRFMHvjGNQgzG3WkOMwM00cR+Bo8goD5Nl4y0A3E/qKIt zQwdJ1fNDTHjS7etHJaQuH8n5q0BzweJYTjCqARArxnxJyZVilVoRkCAbVI8Xptcg9nF wqwhMT7xBs0YQGzy02GEWcy3CUS13l2rNCCkb/7V34PL854CYhQ+oLL83C2gkJ/uBttw am1Q== X-Gm-Message-State: ABy/qLZMHth9YBaWN9qSBP0CEBmZNg/ygV69X8BzprcJ1e0ucAuDJoEy qaGwAYtR+U/HUNfcuK3/FM6ISZzhLQgzMiNvWpbwff9wwvtHnrjEqCTHxZF0QFE4Malnzg+ZK4q Nl418vMHmpZJluuB9u2A0mp+1Q+Zdx9DCUzSaZWYtdfm7SfHVUI36FSi2jA8lkgwwQWCX4CiSPL 0= X-Received: by 2002:a2e:8455:0:b0:2b6:fca2:fc6e with SMTP id u21-20020a2e8455000000b002b6fca2fc6emr12907936ljh.42.1689169452055; Wed, 12 Jul 2023 06:44:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/0bkrrvsQwMdPQfkJ91FxfdlwumdlVtGWAIDfOTZDIbn4JkewFvae9vz4Br2RdgBZwenm9w== X-Received: by 2002:a2e:8455:0:b0:2b6:fca2:fc6e with SMTP id u21-20020a2e8455000000b002b6fca2fc6emr12907906ljh.42.1689169451576; Wed, 12 Jul 2023 06:44:11 -0700 (PDT) Received: from localhost.localdomain (host-82-53-134-6.retail.telecomitalia.it. [82.53.134.6]) by smtp.gmail.com with ESMTPSA id d2-20020a1709064c4200b0099290e2c15esm2595893ejw.75.2023.07.12.06.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 06:44:10 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Mike Christie , Paolo Bonzini , Stefan Hajnoczi , "Michael S . Tsirkin" , Thomas Huth , Mark Kanda , Fam Zheng , Stefano Garzarella Subject: [PATCH 3/3] scsi: clear unit attention only for REPORT LUNS commands Date: Wed, 12 Jul 2023 15:43:52 +0200 Message-ID: <20230712134352.118655-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712134352.118655-1-sgarzare@redhat.com> References: <20230712134352.118655-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org scsi_clear_unit_attention() now only handles REPORTED LUNS DATA HAS CHANGED. This only happens when we handle REPORT LUNS commands, so let's rename the function in scsi_clear_reported_luns_changed() and call it only in scsi_target_emulate_report_luns(). Suggested-by: Paolo Bonzini Signed-off-by: Stefano Garzarella --- hw/scsi/scsi-bus.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index f9c95dfb50..fc4b77fdb0 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -22,6 +22,7 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev); static void scsi_req_dequeue(SCSIRequest *req); static uint8_t *scsi_target_alloc_buf(SCSIRequest *req, size_t len); static void scsi_target_free_buf(SCSIRequest *req); +static void scsi_clear_reported_luns_changed(SCSIRequest *req); static int next_scsi_bus; @@ -518,6 +519,14 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r) /* store the LUN list length */ stl_be_p(&r->buf[0], len - 8); + + /* + * If a REPORT LUNS command enters the enabled command state, [...] + * the device server shall clear any pending unit attention condition + * with an additional sense code of REPORTED LUNS DATA HAS CHANGED. + */ + scsi_clear_reported_luns_changed(&r->req); + return true; } @@ -816,18 +825,10 @@ uint8_t *scsi_req_get_buf(SCSIRequest *req) return req->ops->get_buf(req); } -static void scsi_clear_unit_attention(SCSIRequest *req) +static void scsi_clear_reported_luns_changed(SCSIRequest *req) { SCSISense *ua; - /* - * scsi_fetch_unit_attention_sense() already cleaned the unit attention - * in this case. - */ - if (req->ops == &reqops_unit_attention) { - return; - } - if (req->dev->unit_attention.key == UNIT_ATTENTION) { ua = &req->dev->unit_attention; } else if (req->bus->unit_attention.key == UNIT_ATTENTION) { @@ -836,13 +837,7 @@ static void scsi_clear_unit_attention(SCSIRequest *req) return; } - /* - * If a REPORT LUNS command enters the enabled command state, [...] - * the device server shall clear any pending unit attention condition - * with an additional sense code of REPORTED LUNS DATA HAS CHANGED. - */ - if (req->cmd.buf[0] == REPORT_LUNS && - ua->asc == SENSE_CODE(REPORTED_LUNS_CHANGED).asc && + if (ua->asc == SENSE_CODE(REPORTED_LUNS_CHANGED).asc && ua->ascq == SENSE_CODE(REPORTED_LUNS_CHANGED).ascq) { *ua = SENSE_CODE(NO_SENSE); } @@ -1528,13 +1523,6 @@ void scsi_req_complete(SCSIRequest *req, int status) req->dev->sense_is_ua = false; } - /* - * Unit attention state is now stored in the device's sense buffer - * if the HBA didn't do autosense. Clear the pending unit attention - * flags. - */ - scsi_clear_unit_attention(req); - scsi_req_ref(req); scsi_req_dequeue(req); req->bus->info->complete(req, req->residual);