From nobody Mon Nov 25 08:44:44 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1716247545; cv=none; d=zohomail.com; s=zohoarc; b=d+D0764uyS74K05hY6k6np3waR/xq5Vo/FJArC42EPdJk1+SXfYa1yEL3DO86/7Eit+OY6iU6aM6UPDGk8GBXvGN+7NhkMYrrDP3OGFsUQksIWnpbHwGAhzwd/+E/p0GnuqDMt7Gjv1/1BL1GYSxZqLUZfGhfHef70Fg/6jS+0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716247545; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Sb5gskDTc9Zd2NG0KxNpeYakIpCxke5KbIAJR8+R1pk=; b=MYGekXmz48XkGuBDiNJn3l8XcGBVz2bmTvqOx5Otgchnuza8bUfeYaozSEZHYc47YwwqOMffnT+iwn0ZtKpFucOZjMbpgJ/Wcl7rU8dC87W3n7KEZusbeCcamR8GTCmIAEPlCnpYf2DKLkaOPwAXIBlDocxhr81cSrETVkiGKzc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716247545825284.3001203093372; Mon, 20 May 2024 16:25:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9CN7-0001WP-3C; Mon, 20 May 2024 19:24:49 -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 1s9CN5-0001WF-Pe for qemu-devel@nongnu.org; Mon, 20 May 2024 19:24:47 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9CN3-0007vA-UJ for qemu-devel@nongnu.org; Mon, 20 May 2024 19:24:47 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-24544cfbc69so1424547fac.3 for ; Mon, 20 May 2024 16:24:45 -0700 (PDT) Received: from mintleaf.lan ([136.49.150.227]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f142e3fdf2sm941544a34.52.2024.05.20.16.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716247484; x=1716852284; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Sb5gskDTc9Zd2NG0KxNpeYakIpCxke5KbIAJR8+R1pk=; b=geZSBPkRXYskfeX3RRaAzXnoBCMzTYxKp1rFIeaT8UophAD7RyH5OF8DvhA9/mopeH rOa4ng9MmH1zzRTsDWz1OmEFvsoOoMcjmQkiOw042j47ggb51VH7yi8fLBi26No4Ef1w v2Ug63H9DSK7w+X5URqjJx4Algz8yN0rNYhldjbb96YhxjxFbLKirZqWbXW5QouxWPmu n9Wj4bWwYiHyp9rPuL185NQzgkYLpLeWI9gJIF5FbOQGTabyOlya5adxQQfe0y3dymgI 7CDD1ggndRY9rzEJ9LTsHmVvfgEW/K3zjNIALyaCIlDPbPXfv0DECQBMCEZdej0njgn6 tKsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716247484; x=1716852284; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Sb5gskDTc9Zd2NG0KxNpeYakIpCxke5KbIAJR8+R1pk=; b=IfkAp6ZpfJ5w3PmT6+/f8Qpm0OT0/790KT8VKSEyXZgaNdc0NMxiqpBlFrWxYvVRwm NcuxWc+Q5j/HcX7RA2POUhADkG9fW4YLKWHUdnj0XwkDAWUE1xZ6hKFXstrunPVoM8us Ls9hlkXq2T5BtUHJk909l0z+hL4ir2PL8b6JHBKPExvKQkg31zRRtcf5An/6iTNKRZyN aletyngMH6UvOyR7KHdDBLpvZMWMxa2t970mYb2OzyULeVQARlRRiwsSayUX/BYZvOlU 1eTXihPgBls0hG69Jagoc6PsyMt6yiJ4TGp7sG/Yp/cjr8spOHNxH1HbT70jwiL8+X3x JHxQ== X-Gm-Message-State: AOJu0Yz8e1+gOlJQ7PGWTykVtX35U9DhmxHcyYfi1yraEimOKHKHasWN 3vCgntdPGpdIkGYpfcBhrR3p+G32oauxgYo/xrgbp7ILzgOb8JuQly8/zA== X-Google-Smtp-Source: AGHT+IEJZCYC6NB5WcBiHT9tSEVmbK5CWaYKgYd6gmvYosYG4FInY3PxuVSvtHXHCPjrXuwCdW5ULw== X-Received: by 2002:a05:6871:4408:b0:239:52f9:7f15 with SMTP id 586e51a60fabf-24172bb6e18mr37660172fac.26.1716247484134; Mon, 20 May 2024 16:24:44 -0700 (PDT) From: David Hubbard To: qemu-devel@nongnu.org, Peter Maydell Cc: Philippe Mathieu-Daude , Michael Tokarev , Gerd Hoffmann , Cord Amfmgm Subject: [PATCH] hw/usb/hcd-ohci: Fix ohci_service_td: accept valid TDs Date: Mon, 20 May 2024 18:24:34 -0500 Message-Id: <20240520232434.317879-1-dmamfmgm@gmail.com> X-Mailer: git-send-email 2.34.1 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=2001:4860:4864:20::36; envelope-from=dmamfmgm@gmail.com; helo=mail-oa1-x36.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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 @gmail.com) X-ZM-MESSAGEID: 1716247548082100003 Content-Type: text/plain; charset="utf-8" From: Cord Amfmgm This changes the way the ohci emulation handles a Transfer Descriptor with "Current Buffer Pointer" set to "Buffer End" + 1. The OHCI spec 4.3.1.2 Table 4-2 allows td.cbp to be one byte more than td.be to signal the buffer has zero length. Currently qemu only accepts zero-leng= th Transfer Descriptors if the td.cbp is equal to 0, while actual OHCI hardware accepts both cases. The qemu ohci emulation has a regression in ohci_service_td. Version 4.2 and earlier matched the spec. (I haven't taken the time to bisect exactly where the logic was changed.) With a tiny OS[1] that boots and executes a test, the issue can be seen: * OS that sends USB requests to a USB mass storage device but sends td.cbp =3D td.be + 1 * qemu 4.2 * qemu HEAD (4e66a0854) * Actual OHCI controller (hardware) Command line: qemu-system-x86_64 -m 20 \ -device pci-ohci,id=3Dohci \ -drive if=3Dnone,format=3Draw,id=3Dd,file=3Dtestmbr.raw \ -device usb-storage,bus=3Dohci.0,drive=3Dd \ --trace "usb_*" --trace "ohci_*" -D qemu.log Results are: qemu 4.2 | qemu HEAD | actual HW ------------+------------+------------ works fine | ohci_die() | works fine Tip: if the flags "-serial pty -serial stdio" are added to the command line the test will output USB requests like this: Testing qemu HEAD: > Free mem 2M ohci port2 conn FS > setup { 80 6 0 1 0 0 8 0 } > ED info=3D80000 { mps=3D8 en=3D0 d=3D0 } tail=3Dc20920 > td0 c20880 nxt=3Dc20960 f2000000 setup cbp=3Dc20900 be=3Dc20907 > td1 c20960 nxt=3Dc20980 f3140000 in cbp=3Dc20908 be=3Dc2090f > td2 c20980 nxt=3Dc20920 f3080000 out cbp=3Dc20910 be=3Dc2090f ohci20 = host err > usb stopped And in qemu.log: usb_ohci_iso_td_bad_cc_overrun ISO_TD start_offset=3D0x00c20910 > next_offs= et=3D0x00c2090f Testing qemu 4.2: > Free mem 2M ohci port2 conn FS > setup { 80 6 0 1 0 0 8 0 } > ED info=3D80000 { mps=3D8 en=3D0 d=3D0 } tail=3D620920 > td0 620880 nxt=3D620960 f2000000 setup cbp=3D620900 be=3D620907 c= bp=3D0 be=3D620907 > td1 620960 nxt=3D620980 f3140000 in cbp=3D620908 be=3D62090f c= bp=3D0 be=3D62090f > td2 620980 nxt=3D620920 f3080000 out cbp=3D620910 be=3D62090f c= bp=3D0 be=3D62090f > rx { 12 1 0 2 0 0 0 8 } > setup { 0 5 1 0 0 0 0 0 } tx {} > ED info=3D80000 { mps=3D8 en=3D0 d=3D0 } tail=3D620880 > td0 620920 nxt=3D620960 f2000000 setup cbp=3D620900 be=3D620907 c= bp=3D0 be=3D620907 > td1 620960 nxt=3D620880 f3100000 in cbp=3D620908 be=3D620907 c= bp=3D0 be=3D620907 > setup { 80 6 0 1 0 0 12 0 } > ED info=3D80001 { mps=3D8 en=3D0 d=3D1 } tail=3D620960 > td0 620880 nxt=3D6209c0 f2000000 setup cbp=3D620920 be=3D620927 c= bp=3D0 be=3D620927 > td1 6209c0 nxt=3D6209e0 f3140000 in cbp=3D620928 be=3D620939 c= bp=3D0 be=3D620939 > td2 6209e0 nxt=3D620960 f3080000 out cbp=3D62093a be=3D620939 c= bp=3D0 be=3D620939 > rx { 12 1 0 2 0 0 0 8 f4 46 1 0 0 0 1 2 3 1 } > setup { 80 6 0 2 0 0 0 1 } > ED info=3D80001 { mps=3D8 en=3D0 d=3D1 } tail=3D620880 > td0 620960 nxt=3D6209a0 f2000000 setup cbp=3D620a20 be=3D620a27 c= bp=3D0 be=3D620a27 > td1 6209a0 nxt=3D6209c0 f3140004 in cbp=3D620a28 be=3D620b27 c= bp=3D620a48 be=3D620b27 > td2 6209c0 nxt=3D620880 f3080000 out cbp=3D620b28 be=3D620b27 c= bp=3D0 be=3D620b27 > rx { 9 2 20 0 1 1 4 c0 0 9 4 0 0 2 8 6 50 0 7 5 81 2 40 0 0 7 5 2 2 40= 0 0 } > setup { 0 9 1 0 0 0 0 0 } tx {} > ED info=3D80001 { mps=3D8 en=3D0 d=3D1 } tail=3D620900 > td0 620880 nxt=3D620940 f2000000 setup cbp=3D620a00 be=3D620a07 c= bp=3D0 be=3D620a07 > td1 620940 nxt=3D620900 f3100000 in cbp=3D620a08 be=3D620a07 c= bp=3D0 be=3D620a07 [1] The OS disk image has been emailed to philmd@linaro.org, mjt@tls.msk.ru, and kraxel@redhat.com: * testCbpOffBy1.img.xz * sha256: f87baddcb86de845de12f002c698670a426affb40946025cc32694f9daa3abed Signed-off-by: Cord Amfmgm --- hw/usb/hcd-ohci.c | 4 ++-- hw/usb/trace-events | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index acd6016980..86caf5e43b 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -941,8 +941,8 @@ static int ohci_service_td(OHCIState *ohci, struct ohci= _ed *ed) if ((td.cbp & 0xfffff000) !=3D (td.be & 0xfffff000)) { len =3D (td.be & 0xfff) + 0x1001 - (td.cbp & 0xfff); } else { - if (td.cbp > td.be) { - trace_usb_ohci_iso_td_bad_cc_overrun(td.cbp, td.be); + if (td.cbp > td.be + 1) { + trace_usb_ohci_td_bad_buf(td.cbp, td.be); ohci_die(ohci); return 1; } diff --git a/hw/usb/trace-events b/hw/usb/trace-events index fd7b90d70c..fe282e7876 100644 --- a/hw/usb/trace-events +++ b/hw/usb/trace-events @@ -29,6 +29,7 @@ usb_ohci_iso_td_data_underrun(int ret) "DataUnderrun %d" usb_ohci_iso_td_nak(int ret) "got NAK/STALL %d" usb_ohci_iso_td_bad_response(int ret) "Bad device response %d" usb_ohci_td_bad_pid(const char *s, uint32_t edf, uint32_t tdf) "Bad pid %s= : ed.flags 0x%x td.flags 0x%x" +usb_ohci_td_bad_buf(uint32_t cbp, uint32_t be) "Bad cbp =3D 0x%x > be =3D = 0x%x" usb_ohci_port_attach(int index) "port #%d" usb_ohci_port_detach(int index) "port #%d" usb_ohci_port_wakeup(int index) "port #%d" --=20 2.34.1