From nobody Thu Apr 2 15:43:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774646893; cv=none; d=zohomail.com; s=zohoarc; b=Tsljvljp/JfrfJcRv3aOoWJKnP98lxMVyzRAOBkBmHAZccbc/v6LnDkfk64m/P6SCK0N5LQGGiXg+lJIYROeOD6k+bJ1sSYE4fKEwmdfrjfOj9wg+fSHypQPGAScxxwWH0APhS/uWJ3JpjkDXTUBQuPX1AmydbKNOOmpMXcXWMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774646893; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=64HjyIw3YSOllArTTqZkAithVHrT5AIrg1J84ohe30s=; b=QFDZMguc5/xT04jHRgzal9xDz9tYFDezGYrCpN/VIwVHLv2XiXzZ8rf0uoy1HAbk23R8ksD7oTFBi2wQ2MWApbUl2X8Mo+SsjIILlWCqT553g1xADcT/ZgRPS1a/UbjA1WivRFEhnw01Ay2/w8Tm77ezmE47tGPvLqSzptkoZhc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774646893985150.06125478849685; Fri, 27 Mar 2026 14:28:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w6EiR-0006jf-GN; Fri, 27 Mar 2026 17:27:39 -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 1w6EiP-0006Sg-CV for qemu-devel@nongnu.org; Fri, 27 Mar 2026 17:27:37 -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 1w6EiN-0003rI-Ho for qemu-devel@nongnu.org; Fri, 27 Mar 2026 17:27:37 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-cps7H3i9MPSJMSaccNPM_Q-1; Fri, 27 Mar 2026 17:27:32 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-486fcc05b20so17776225e9.3 for ; Fri, 27 Mar 2026 14:27:32 -0700 (PDT) Received: from [192.168.10.48] ([151.49.85.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722c9506dsm112708875e9.7.2026.03.27.14.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 14:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774646855; h=from:from:reply-to:subject:subject: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=64HjyIw3YSOllArTTqZkAithVHrT5AIrg1J84ohe30s=; b=WkN5nqrokkzpOkXW63o0+n92FCI8yIsFnaXDZhjUywfNpX+ov4SQHjxSsOpbwy5ME/sWRN LpSepOMQ5G4BZJOP+beqV81jtzHl+KO25m8j/7myuXooO8ZE9zeL50GFIPkI6zK/clDyt1 HgvAXRRW6EG/B5XSltb/Rh/AqzQyJGA= X-MC-Unique: cps7H3i9MPSJMSaccNPM_Q-1 X-Mimecast-MFC-AGG-ID: cps7H3i9MPSJMSaccNPM_Q_1774646851 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774646848; x=1775251648; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=64HjyIw3YSOllArTTqZkAithVHrT5AIrg1J84ohe30s=; b=G2LLFIsQFMR4a0rGW510A8gngRubwYeBlrvDeGfdvD3K4yP5I3p+HCIFeQZY0cbGGL 16v3zfsSD/EIM/uGaI/1NSPc913Bl4wqXWsKbJdvwth6Yk1ykZZMDXBu3hQ9Zuy61tMX ObB7u9RN8/WPDYWg7zNw/nFSc1INbJw3+rSZtI5g+oqgaoDZzbN7jxChn4IhuT4RuXg5 lg8wRTnRsXmdXmlQWyQv6iEepGDDtfUbrGFynRlIrptzZxqHXreKfsRjHGE2nx/VMFIN nqbmGJhi1dkfGB6R5di+gyNHOxQf9d8gguM//fCBVisNcN4lLjQmCMOpdVFYIcxHxfvY akhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774646848; x=1775251648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=64HjyIw3YSOllArTTqZkAithVHrT5AIrg1J84ohe30s=; b=dF7ie5M4cknNWoxrWAWNlYDV+OdNx5GJDNL59CIxTHXGo6CDUFGwHgnuVPFrBBKY56 1ogMKkTji6CSvlU3ITmzFsMeySxDLPOdZOLNAT7JxXu613NbDLT8y74D8xNeKZgJnUBh /Bg0olY53nmgMod9hs23mGnNmBYHQliOyP3RTdlveDohXUtPDmiBMgmLFxO8RM0iB7Sc o/K/1bOGeg3yPH7/BG3tYR8jY+Twb+euUiFr49JOprAcskRgDddse1pW/obHRhbq5PVm of3w638ktBuxBdlgebUUVQ+xBOjswMxrOPzRFar8YtnKIwb2GDMUeoFJ0XSOtA2RQ2Lp D9ZA== X-Gm-Message-State: AOJu0Yxk4adozl7ytqtdRTOz8TtELwQmp16fRnC7IL6w0v5cyV6iMAls D3HiZ2nUOlnXuGw35+A5vhk/YJ7lCQKVjxX6sRV8ZChJDTkHD7b2rohTNToDftx0RUI6aIp5msh UmLgHVcIFO0m3CDdUZV42PFZPPT41mcNhTldFPlMUlrsuLYv7w/Xz653heHwBL/Rja3nQlkAId6 sdEVJbSARkxpUROc5JzNaqRLZuMPxPccBLXcI5z2J1 X-Gm-Gg: ATEYQzzPSEFWlfAmDwz43tz4uDmtqzoC2z1gUUFRMaY048raIH35LI07XMCwx0OkQKm exqwsILPFUdpmNrICTs0sqDHyANjSOSzXr71j3b3X1cNF8B0r3+qlcNB+YgEaYQp1cuLIMLwxxm QveItue50b82TNPp3PCDuDeZRrs5m14Xoy6RHl+1RN5kS1XRCrSn8z/tM2/kbTncNI4Tjvxj9MR ZUcGXNdsQd6TOb9PqTckBu+HcfrJze8dIzZso+VXiOvTAEJxqeWbELC85cM2Y9Eu+gVhC4RVrUk SSyKT+RN/MdRORowN/ynXFhVYkyLiKYa29Tot13a2vw7wCMo99LwDHZcP6YJRPiEoB7hG9NhWdQ T/+L0z1jRnGl3DRwOKEKOrl3bjoeNpNTKTGijuVbKm+cQpECGmEa159zJwQhuRbcVd4te+e2ADS oEuBhgdpA73e7vwPuWq6nu90NK X-Received: by 2002:a05:600c:3e88:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-48727ee9897mr62252185e9.2.1774646848459; Fri, 27 Mar 2026 14:27:28 -0700 (PDT) X-Received: by 2002:a05:600c:3e88:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-48727ee9897mr62251915e9.2.1774646847953; Fri, 27 Mar 2026 14:27:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 15/16] ncr710: copy reference counting fixes over from lsi53c895a Date: Fri, 27 Mar 2026 22:25:46 +0100 Message-ID: <20260327212547.460420-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327212547.460420-1-pbonzini@redhat.com> References: <20260327212547.460420-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@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_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774646894605158500 Content-Type: text/plain; charset="utf-8" These are mostly the smae, with only the "if (p =3D=3D s->current) case of ncr710_command_complete needing some care to check that it's safe to remove. s->current is dereferenced: - in ncr710_clear_pending_irq - guarded by if (s->current), just to free it - in ncr710_do_dma - guarded by assert (s->current); only called from Data In/Data Out phases, which are entered after scsi_req_new and left after scsi_req_cancel - in ncr710_command_complete - guarded by if (p), command is not complete - in ncr710_transfer_data - coming from the req field of NCR710Request, with assertion that !p->orphan - in ncr710_transfer_data, later - guarded by if (!s->current) return - in ncr710_do_command, after assignment - in ncr710_do_msgout - guarded by if (current_req), would be bad if the request is already complete - in ncr710_reselection_retry_callback - guarded by short-circuiting s->current check - in ncr710_execute_script - guarded by if (s->current) - in ncr710_reg_readb - guarded by short-circuiting s->current check Nothing relies on the post-completion s->current being alive, so get rid of this case and clear s->current immediately as in the lsi53c895a device. Signed-off-by: Paolo Bonzini --- hw/scsi/ncr53c710.h | 1 + hw/scsi/ncr53c710.c | 65 ++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/hw/scsi/ncr53c710.h b/hw/scsi/ncr53c710.h index ee6980753d5..b15e331f060 100644 --- a/hw/scsi/ncr53c710.h +++ b/hw/scsi/ncr53c710.h @@ -133,6 +133,7 @@ struct NCR710Request { bool active; uint8_t *dma_buf; bool out; + bool orphan; uint32_t resume_offset; uint32_t saved_dnad; }; diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c index ea114a0cb40..f7b1e153960 100644 --- a/hw/scsi/ncr53c710.c +++ b/hw/scsi/ncr53c710.c @@ -299,7 +299,7 @@ static const char *ncr710_reg_name(int offset); static void ncr710_script_scsi_interrupt(NCR710State *s, int stat0); static void ncr710_update_irq(NCR710State *s); static void ncr710_script_dma_interrupt(NCR710State *s, int stat); -static void ncr710_request_free(NCR710State *s, NCR710Request *p); +static void ncr710_request_orphan(NCR710State *s, NCR710Request *p); static inline void ncr710_dma_read(NCR710State *s, uint32_t addr, void *buf, uint32_t len); static inline void ncr710_dma_write(NCR710State *s, uint32_t addr, @@ -316,7 +316,7 @@ static inline int ncr710_irq_on_rsl(NCR710State *s) static void ncr710_clear_pending_irq(NCR710State *s) { if (s->current) { - ncr710_request_free(s, s->current); + ncr710_request_orphan(s, s->current); } } =20 @@ -683,42 +683,52 @@ static void ncr710_do_dma(NCR710State *s, int out) uint32_t count; uint32_t addr; SCSIDevice *dev; + SCSIRequest *req; + NCR710Request *p; + assert(s->current); if (!s->current->dma_len) { /* We wait until data is available. */ return; } =20 - dev =3D s->current->req->dev; + p =3D s->current; + req =3D scsi_req_ref(p->req); + dev =3D req->dev; assert(dev); =20 count =3D s->dbc; - if (count > s->current->dma_len) { - count =3D s->current->dma_len; + if (count > p->dma_len) { + count =3D p->dma_len; } =20 addr =3D s->dnad; =20 s->dnad +=3D count; s->dbc -=3D count; - if (s->current->dma_buf =3D=3D NULL) { - s->current->dma_buf =3D scsi_req_get_buf(s->current->req); + if (p->dma_buf =3D=3D NULL) { + p->dma_buf =3D scsi_req_get_buf(req); } /* ??? Set SFBR to first data byte. */ if (out) { - ncr710_dma_read(s, addr, s->current->dma_buf, count); + ncr710_dma_read(s, addr, p->dma_buf, count); } else { - ncr710_dma_write(s, addr, s->current->dma_buf, count); + ncr710_dma_write(s, addr, p->dma_buf, count); } - s->current->dma_len -=3D count; - if (s->current->dma_len =3D=3D 0) { - s->current->dma_buf =3D NULL; - s->current->pending =3D 0; - s->waiting =3D NCR710_WAIT_DMA; - scsi_req_continue(s->current->req); + if (p->orphan) { + scsi_req_unref(req); return; + } + scsi_req_unref(req); + + p->dma_len -=3D count; + if (p->dma_len =3D=3D 0) { + p->dma_buf =3D NULL; + p->pending =3D 0; + s->waiting =3D NCR710_WAIT_DMA; + scsi_req_continue(req); } else { - s->current->dma_buf +=3D count; + p->dma_buf +=3D count; s->waiting =3D NCR710_WAIT_NONE; ncr710_execute_script(s); } @@ -733,14 +743,18 @@ static void ncr710_add_msg_byte(NCR710State *s, uint8= _t data) } } =20 -static void ncr710_request_free(NCR710State *s, NCR710Request *p) +static void ncr710_request_orphan(NCR710State *s, NCR710Request *p) { - p->req->hba_private =3D NULL; + p->orphan =3D true; if (p =3D=3D s->current) { s->current =3D NULL; } scsi_req_unref(p->req); - g_free(p); +} + +static void ncr710_free_request(SCSIBus *bus, void *priv) +{ + g_free(priv); } =20 void ncr710_request_cancelled(SCSIRequest *req) @@ -748,7 +762,7 @@ void ncr710_request_cancelled(SCSIRequest *req) NCR710State *s =3D ncr710_from_scsi_bus(req->bus); NCR710Request *p =3D (NCR710Request *)req->hba_private; if (p) { - ncr710_request_free(s, p); + ncr710_request_orphan(s, p); } } =20 @@ -790,11 +804,7 @@ void ncr710_command_complete(SCSIRequest *req, size_t = resid) ncr710_set_phase(s, PHASE_ST); =20 if (p) { - if (p =3D=3D s->current) { - req->hba_private =3D NULL; - } else { - ncr710_request_free(s, p); - } + ncr710_request_orphan(s, p); } =20 if (s->waiting =3D=3D NCR710_WAIT_RESELECT || s->waiting =3D=3D NCR710= _WAIT_DMA) { @@ -806,11 +816,11 @@ void ncr710_command_complete(SCSIRequest *req, size_t= resid) void ncr710_transfer_data(SCSIRequest *req, uint32_t len) { NCR710State *s =3D ncr710_from_scsi_bus(req->bus); + NCR710Request *p =3D (NCR710Request *)req->hba_private; =20 - assert(req->hba_private); + assert(!p->orphan); =20 if (s->waiting =3D=3D NCR710_WAIT_DMA) { - NCR710Request *p =3D (NCR710Request *)req->hba_private; if (p) { p->dma_len =3D len; } @@ -2248,6 +2258,7 @@ static const struct SCSIBusInfo ncr710_scsi_info =3D { .transfer_data =3D ncr710_transfer_data, .complete =3D ncr710_command_complete, .cancel =3D ncr710_request_cancelled, + .free_request =3D ncr710_free_request, }; =20 static const MemoryRegionOps ncr710_mmio_ops =3D { --=20 2.53.0