From nobody Sun Nov 24 01:52:58 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=1727443654; cv=none; d=zohomail.com; s=zohoarc; b=dJcBVu5PAfzyvmykUJ4pNWfFuz113FOM+nxzrxDK7uRe4HQ6D1weERo25LYnzwk34N7eb+66LdtPMyAhNwnVc94lHi699tytgB8z07dpOCi0GpWm0F7tSj5EwFYjjWZanhNo8qFn5sOHT5zX6NW2No78SiyNI/69yDbRLL3CUc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727443654; 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=TvI9qw5LAWNZpYaJ0urC7M+CoFwaemgKRzivOqo/UZc=; b=CvB4eRnbLPVRfflusJ7mfHZcMWG2naYgaoeYZ7kZyClIxi0RuzqT5U2rSA0GAZ9zHrn1NPcbc2akUx4EyBHv+gjjseRQBZoXZ+UFUVAEfZ0bSAZWrAiEKptaN7hWxaPuWAcPiIqh0Lo5WpwwQ7jsU5cPIyr8Yisg/hyxbQGTOP8= 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 1727443654181848.4485708800286; Fri, 27 Sep 2024 06:27:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suAz8-0005BJ-0A; Fri, 27 Sep 2024 09:26:14 -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 1su50L-0000OU-QD; Fri, 27 Sep 2024 03:03:05 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1su50J-0000oQ-Jb; Fri, 27 Sep 2024 03:03:04 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-710e910dd7dso1191699a34.2; Fri, 27 Sep 2024 00:03:02 -0700 (PDT) Received: from localhost.localdomain ([124.16.141.247]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db294ebdsm947830a12.19.2024.09.27.00.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 00:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727420581; x=1728025381; 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=TvI9qw5LAWNZpYaJ0urC7M+CoFwaemgKRzivOqo/UZc=; b=fGENAApT+U9uADkTUQHazMOud22EOm4HR/JfEJoKc175jOTPkKN+Q53eqPfz9y4Gag GTQIBqaWeZWISZuXS28BubRGDCiY/Mrh6F2rUg3waqJR7IfrtzN7v1Z+iL7gSugO9zHX +MSxyq2yWG1BRZnqDr5eYYWU89uO1Ry/TsXp/UJ4ycEJbDkjMjD0ai6RhuZ9hKWJXTXQ MQKJiCwHOfRTa4NKeuykBLHQbUAIIj9KLVsnDSkrHwDdmaS0ES/e4vVHGv3bsqVicqvJ fe5eaZ4AMDAckRc3E2yljclUmdcHhsIkp2NAN+RMNgtnvzdRn3FOw8uHYUQ5FUx5lHX9 BRgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727420581; x=1728025381; 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=TvI9qw5LAWNZpYaJ0urC7M+CoFwaemgKRzivOqo/UZc=; b=LgoshaDjgc7HPTLoxIWNzC09vYhCmrjOwuuiBe6m73Tgc1XU+tWD05f+zpQNlYTZhv HgHxfX5e4oAHcrYRyL2d6owGUOyOHv9kAfdLnmENDWhgtoN7AhAfnKOYcll4G57QLfwI gJTbONSJ37z4mjLeO6GQDMPJQxfg13sc1SyqJvqfIWMt0U4hWEoI6C6zl3pddEQkx2qE JR9x/T6uf1W75XlfZnJKdus3c7REBcQLqteFnM5KJxHSIOwDXgDG1YXPx5n9HM2up1Sc 5vaIvJWaju20D3/UiblQRVh41yeFVZhtmxbHLvEZuFy/Yr7nIe09lJDIHbFTpiY7yZB6 S5tA== X-Gm-Message-State: AOJu0YzjWZAhTceUTEB70yR30pc7ZvYEmS1AcEPFxFLxFboZbHkbmQTS LBrxyAZqRr8+6zz1lX+uDG5gh/2yM4Wskfq46J126Er8LcjBuQpdKfHBf4AbJbk= X-Google-Smtp-Source: AGHT+IGdrX7rjZgBcko51d9fxy+GqiQi2O7d1vBrLdA3tBEqGISwObz+mT2hZ8/tj36n4jpNzuyu7Q== X-Received: by 2002:a05:6358:784:b0:1b1:acd5:dd98 with SMTP id e5c5f4694b2df-1becbc4b5f1mr164103755d.7.1727420580871; Fri, 27 Sep 2024 00:03:00 -0700 (PDT) From: MingZhu Yan X-Google-Original-From: MingZhu Yan To: qemu-riscv@nongnu.org Cc: qemu-devel@nongnu.org, trdthg47@gmail.com, MingZhu Yan Subject: [PATCH] hw/char/riscv_htif: Fix htif_mm_write that causes infinite loop in ACT. Date: Fri, 27 Sep 2024 15:00:18 +0800 Message-Id: <20240927070018.10121-1-yanmingzhu@iscas.ac.cn> 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=2607:f8b0:4864:20::332; envelope-from=trdthg47@gmail.com; helo=mail-ot1-x332.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 27 Sep 2024 09:25:49 -0400 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: 1727443656275116600 Content-Type: text/plain; charset="utf-8" Applications sometimes only write the lower 32-bit payload bytes, this is u= sed in ACT tests. As a workaround, this refers to the solution of sail-riscv. if the payload is written a few times with the same value, we process the w= hole htif command anyway. Signed-off-by: MingZhu Yan --- hw/char/riscv_htif.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 9bef60def1..d74cce3bef 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -65,16 +65,8 @@ void htif_symbol_callback(const char *st_name, int st_in= fo, uint64_t st_value, { if (strcmp("fromhost", st_name) =3D=3D 0) { fromhost_addr =3D st_value; - if (st_size !=3D 8) { - error_report("HTIF fromhost must be 8 bytes"); - exit(1); - } } else if (strcmp("tohost", st_name) =3D=3D 0) { tohost_addr =3D st_value; - if (st_size !=3D 8) { - error_report("HTIF tohost must be 8 bytes"); - exit(1); - } } else if (strcmp("begin_signature", st_name) =3D=3D 0) { begin_sig_addr =3D st_value; } else if (strcmp("end_signature", st_name) =3D=3D 0) { @@ -290,18 +282,26 @@ static void htif_mm_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { HTIFState *s =3D opaque; - if (addr =3D=3D TOHOST_OFFSET1) { - if (s->tohost =3D=3D 0x0) { - s->allow_tohost =3D 1; - s->tohost =3D value & 0xFFFFFFFF; + int htif_cmd_write =3D 0; + if (size =3D=3D 8 && addr =3D=3D TOHOST_OFFSET1) { + htif_cmd_write =3D 1; + s->tohost =3D value; + htif_handle_tohost_write(s, s->tohost); + } else if (size =3D=3D 4 && addr =3D=3D TOHOST_OFFSET1) { + if ((value) =3D=3D (s->tohost & 0xFFFF)) { + s->allow_tohost =3D s->allow_tohost + 1; } else { s->allow_tohost =3D 0; } - } else if (addr =3D=3D TOHOST_OFFSET2) { - if (s->allow_tohost) { - s->tohost |=3D value << 32; - htif_handle_tohost_write(s, s->tohost); + s->tohost =3D deposit64(s->tohost, 0, 32, value); + } else if (size =3D=3D 4 && addr =3D=3D TOHOST_OFFSET2) { + if ((value & 0xFF) =3D=3D (s->tohost & 0xFF00)) { + s->allow_tohost =3D s->allow_tohost + 1; + } else { + s->allow_tohost =3D 1; } + htif_cmd_write =3D 1; + s->tohost =3D deposit64(s->tohost, 32, 32, value); } else if (addr =3D=3D FROMHOST_OFFSET1) { s->fromhost_inprogress =3D 1; s->fromhost =3D value & 0xFFFFFFFF; @@ -312,6 +312,9 @@ static void htif_mm_write(void *opaque, hwaddr addr, qemu_log("Invalid htif write: address %016" PRIx64 "\n", (uint64_t)addr); } + if ((s->tohost =3D=3D 1 && htif_cmd_write) || s->allow_tohost > 2) { + htif_handle_tohost_write(s, s->tohost); + } } =20 static const MemoryRegionOps htif_mm_ops =3D { --=20 2.34.1