From nobody Sat Feb 7 09:04:05 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1770321597; cv=none; d=zohomail.com; s=zohoarc; b=dPGFI8QC+UlYV6HH9kv124dhULYzijUyjz8ejXfwuE/FqTU2yL2U9RQRz6uvi21CAcHnURlzN609gMOtQdPxVXgNhOi5rYehCW9RpCVepPTIMjM3UbQwgOda+qwrQ+ZvmCFezLEePwk1Ck89DuN+Wkwos1u9Pl/wwDXpOoYNqr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321597; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=MoW1lN8/MLfR1RTMULwKYB8IQ4Ik9APvPEEiwjwpHdoUQgpucTEWk6uzw21zLi31+wpMat9bZ6Hy+ohlI1uF8NrOkaN/0NJXi/1GR5dTzAPo2IY+gVU0SEFsG/0t2pT2vY90zYBCWJwv9kc9BJ4m6nsrasxHy+pB6jO/USCpTm4= 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 17703215978411007.178611179296; Thu, 5 Feb 2026 11:59:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VJ-0006i2-5d; Thu, 05 Feb 2026 14:59:05 -0500 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 1vo5VH-0006eV-Cl for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:03 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VF-00035x-Ip for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:03 -0500 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-4362507f396so846559f8f.0 for ; Thu, 05 Feb 2026 11:59:01 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321539; x=1770926339; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=DZAr8CVi8yZrUN7thYQlMAnwtgba8g+M/Ei8He6yI33I/wc7RAwmxFOVAH7iUMw9cb pl2KihRiyiOQtz/m4u4HnuTgQ+USrWUDZDgYsgsxYWTowxca6/Ii6/lKQIWuVUAyNE8Y ko6shiwvUkmXcD2BdQgTkrdNIcRXXXOGWytoZMhYitkoqye37b3IVskjOryZ0jrRTI99 crxz/mqPcWvVSHERvM6a7J3QYPHS3TVO5kQY8nOewS+QOmagWpcQdJeGZCUVHTzxv/F1 nzzSK5R7q6FJciXJJ3iWYoPMO8EVbZVVf+HXcPMn7wjWITBLAEQ+o7qWTCMG+EavFe7l 3sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321539; x=1770926339; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=EBWw8idFfYq+qDRAOih23Lsxsvfd4EJYBcAqzQ9FvEtXaCmOI1Hq4AxZY5azfaUGIK 3GifAm42VweL8zLgO7xWZQo6iGCEJ8qnsYjbYXmwT6cJ/8LYmrKJpFmyMzFuOuBYZTPM nuDnxrk/fV4oMqzZDJ1/Mf7jJw2rFqGnTJH38yimg/JnPGUQ0RjbRbrzI1IyTlKUjFO5 FB41nooPeSGaM2uaf04US7WjQG2/wUEOJMCAKV1TMnU3GXNFjedTE2dY8VcA5fwFfYJw fyY8CE8QhNPh4ZoY/YLz5Ov4XbZxsDY2jZIyaZK8GURpesuNa9tSurOyibHslZxMb6E/ j9LA== X-Gm-Message-State: AOJu0Ywv0tBSRG28mLlP0f+PvS1MbGiV/e0uHvpM2AvSiVHtzvWrLdxb BnPVlxQe5O+O3sq4Swvb28q4SFNhBzPLCzu7177M+0K9vQaxtP9UvpaCDGyO0vKKRB8= X-Gm-Gg: AZuq6aIMX2+wg2joNehqU2IF2NdAdKGCPXCrTCE+GU/hOrDGqufpTn4Ne/StcpwjHUr E8HrriUCTWdtxSc4DLmow1GNNyo6jtcp+SSyPdImozzK3aB9mKUz/788zDLfJU4DHv5m7J4FPlA E9PdnJUyfcNUpXVzXMSiej/jmJdqmMi2kl0B6mK+dKTStEfzirHtMmwnnUupZCl4K2dnWE2Y3tQ Pp5q/7PlWUc9JKBLd/0sUf6pjOSwk5yd9Np63s9Oz+zvdFxwbBbP0bt5dqesNdmIa3LmcOsTjeN eV1oWymhuAzgiY+iKbIPVMd86tEY4hymeaedlz0xiiYIAuxzkFQOX69o3jbKYW4E1ORzf4iWM6I YdNNd83PAY9VG2KBsPsGf3m3MklWVDcLWGG22a1/7NKqE9Nc85ubDQrgfFtH7tql7JAmZN5B3ls Mo9DQu5LWCyWVlLbFtcyQ= X-Received: by 2002:a5d:584c:0:b0:435:db9b:5883 with SMTP id ffacd0b85a97d-4362933a9b5mr679016f8f.2.1770321539186; Thu, 05 Feb 2026 11:58:59 -0800 (PST) From: Ruslan Ruslichenko To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, artem_mygaiev@epam.com, volodymyr_babchuk@epam.com, takahiro.nakata.wr@renesas.com, "Edgar E . Iglesias" , francisco.iglesias@amd.com, Ruslan_Ruslichenko@epam.com, "Edgar E . Iglesias" Subject: [PATCH 11/29] hw/core: Implement Remote Port response handling Date: Thu, 5 Feb 2026 20:58:06 +0100 Message-ID: <20260205195824.2610192-12-ruslichenko.r@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260205195824.2610192-1-ruslichenko.r@gmail.com> References: <20260205195824.2610192-1-ruslichenko.r@gmail.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=2a00:1450:4864:20::42e; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42e.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 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 @gmail.com) X-ZM-MESSAGEID: 1770321599435154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add infrastructure to handle transaction responses from remote peers. This patch enables QEMU to wait for replies when it initiates a memory access (Read/Write). It implements a mechanism to track outstanding transaction IDs and block the execution thread until the patching response is received. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 136 +++++++++++++++++++++++++++++++++- include/hw/core/remote-port.h | 29 ++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index e44d9249c3..00c9529348 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -59,6 +59,16 @@ static void rp_pkt_dump(const char *prefix, const char *= buf, size_t len) qemu_hexdump(stdout, prefix, buf, len); } =20 +void rp_rsp_mutex_lock(RemotePort *s) +{ + qemu_mutex_lock(&s->rsp_mutex); +} + +void rp_rsp_mutex_unlock(RemotePort *s) +{ + qemu_mutex_unlock(&s->rsp_mutex); +} + static void rp_fatal_error(RemotePort *s, const char *reason) { error_report("%s: %s", s->prefix, reason); @@ -104,6 +114,80 @@ static unsigned int rp_has_work(RemotePort *s) return work; } =20 +/* Response handling. */ +RemotePortRespSlot *rp_dev_timed_wait_resp(RemotePort *s, uint32_t dev, + uint32_t id, int timems) +{ + int i; + + assert(s->devs[dev]); + + /* Find a free slot. */ + for (i =3D 0; i < ARRAY_SIZE(s->dev_state[dev].rsp_queue); i++) { + if (s->dev_state[dev].rsp_queue[i].used =3D=3D false) { + break; + } + } + + if (i =3D=3D ARRAY_SIZE(s->dev_state[dev].rsp_queue) || + s->dev_state[dev].rsp_queue[i].used =3D=3D true) { + error_report("Number of outstanding transactions exceeded! %d", + RP_MAX_OUTSTANDING_TRANSACTIONS); + rp_fatal_error(s, "Internal error"); + } + + /* Got a slot, fill it in. */ + s->dev_state[dev].rsp_queue[i].id =3D id; + s->dev_state[dev].rsp_queue[i].valid =3D false; + s->dev_state[dev].rsp_queue[i].used =3D true; + + while (!s->dev_state[dev].rsp_queue[i].valid) { + rp_rsp_mutex_unlock(s); + rp_event_read(s); + rp_rsp_mutex_lock(s); + if (s->dev_state[dev].rsp_queue[i].valid) { + break; + } + if (!rp_has_work(s)) { + if (timems) { + if (!qemu_cond_timedwait(&s->progress_cond, &s->rsp_mutex, + timems)) { + /* + * TimeOut! + */ + break; + } + } else { + qemu_cond_wait(&s->progress_cond, &s->rsp_mutex); + } + } + } + return &s->dev_state[dev].rsp_queue[i]; +} + +RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t= id) +{ + return rp_dev_timed_wait_resp(s, dev, id, 0); +} + +RemotePortDynPkt rp_wait_resp(RemotePort *s) +{ + while (!rp_dpkt_is_valid(&s->rspqueue)) { + rp_rsp_mutex_unlock(s); + rp_event_read(s); + rp_rsp_mutex_lock(s); + /* Need to recheck the condition with the rsp lock taken. */ + if (rp_dpkt_is_valid(&s->rspqueue)) { + break; + } + D(qemu_log("%s: wait for progress\n", __func__)); + if (!rp_has_work(s)) { + qemu_cond_wait(&s->progress_cond, &s->rsp_mutex); + } + } + return s->rspqueue; +} + static void rp_cmd_hello(RemotePort *s, struct rp_pkt *pkt) { s->peer.version =3D pkt->hello.version; @@ -328,14 +412,52 @@ static bool rp_pt_process_pkt(RemotePort *s, RemotePo= rtDynPkt *dpkt) { struct rp_pkt *pkt =3D dpkt->pkt; =20 - D(qemu_log("%s: cmd=3D%x id=3D%d dev=3D%d\n", __func__, pkt->hdr.cmd, - pkt->hdr.id, pkt->hdr.dev)); + D(qemu_log("%s: cmd=3D%x id=3D%d dev=3D%d rsp=3D%d\n", __func__, pkt->= hdr.cmd, + pkt->hdr.id, pkt->hdr.dev, + pkt->hdr.flags & RP_PKT_FLAGS_response)); =20 if (pkt->hdr.dev >=3D ARRAY_SIZE(s->devs)) { /* FIXME: Respond with an error. */ return true; } =20 + if (pkt->hdr.flags & RP_PKT_FLAGS_response) { + uint32_t dev =3D pkt->hdr.dev; + uint32_t id =3D pkt->hdr.id; + int i; + + if (pkt->hdr.flags & RP_PKT_FLAGS_posted) { + printf("Drop response for posted packets\n"); + return true; + } + + qemu_mutex_lock(&s->rsp_mutex); + + /* Try to find a per-device slot first. */ + for (i =3D 0; i < ARRAY_SIZE(s->dev_state[dev].rsp_queue); i++) { + if (s->devs[dev] && s->dev_state[dev].rsp_queue[i].used =3D=3D= true + && s->dev_state[dev].rsp_queue[i].id =3D=3D id) { + break; + } + } + + if (i < ARRAY_SIZE(s->dev_state[dev].rsp_queue)) { + /* Found a per device one. */ + assert(s->dev_state[dev].rsp_queue[i].valid =3D=3D false); + + rp_dpkt_swap(&s->dev_state[dev].rsp_queue[i].rsp, dpkt); + s->dev_state[dev].rsp_queue[i].valid =3D true; + + qemu_cond_signal(&s->progress_cond); + } else { + rp_dpkt_swap(&s->rspqueue, dpkt); + qemu_cond_signal(&s->progress_cond); + } + + qemu_mutex_unlock(&s->rsp_mutex); + return true; + } + switch (pkt->hdr.cmd) { case RP_CMD_hello: rp_cmd_hello(s, pkt); @@ -389,6 +511,7 @@ static void *rp_protocol_thread(void *arg) =20 /* Make sure we have a decent bufsize to start with. */ rp_dpkt_alloc(&s->rsp, sizeof s->rsp.pkt->busaccess + 1024); + rp_dpkt_alloc(&s->rspqueue, sizeof s->rspqueue.pkt->busaccess + 1024); for (i =3D 0; i < ARRAY_SIZE(s->rx_queue.pkt); i++) { rp_dpkt_alloc(&s->rx_queue.pkt[i], sizeof s->rx_queue.pkt[i].pkt->busaccess + 1024); @@ -614,6 +737,7 @@ static void rp_prop_allow_set_link(const Object *obj, c= onst char *name, static void rp_init(Object *obj) { RemotePort *s =3D REMOTE_PORT(obj); + int t; int i; =20 for (i =3D 0; i < REMOTE_PORT_MAX_DEVS; ++i) { @@ -623,6 +747,14 @@ static void rp_init(Object *obj) rp_prop_allow_set_link, OBJ_PROP_LINK_STRONG); g_free(name); + + + for (t =3D 0; t < RP_MAX_OUTSTANDING_TRANSACTIONS; t++) { + s->dev_state[i].rsp_queue[t].used =3D false; + s->dev_state[i].rsp_queue[t].valid =3D false; + rp_dpkt_alloc(&s->dev_state[i].rsp_queue[t].rsp, + sizeof s->dev_state[i].rsp_queue[t].rsp.pkt->busaccess + 10= 24); + } } } =20 diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index 21dfbe89cd..c1b21eb573 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -53,6 +53,13 @@ typedef struct RemotePortDeviceClass { #define TYPE_REMOTE_PORT "remote-port" #define REMOTE_PORT(obj) OBJECT_CHECK(RemotePort, (obj), TYPE_REMOTE_PORT) =20 +typedef struct RemotePortRespSlot { + RemotePortDynPkt rsp; + uint32_t id; + bool used; + bool valid; +} RemotePortRespSlot; + struct RemotePort { DeviceState parent; =20 @@ -93,6 +100,13 @@ struct RemotePort { */ RemotePortDynPkt rsp; =20 + /* + * rspqueue holds received responses from the remote side. + * Only one for the moment but it might grow. + * Used by the master. + */ + RemotePortDynPkt rspqueue; + const char *prefix; const char *remote_prefix; =20 @@ -100,9 +114,24 @@ struct RemotePort { bool reset_done; =20 #define REMOTE_PORT_MAX_DEVS 1024 +#define RP_MAX_OUTSTANDING_TRANSACTIONS 32 + struct { + RemotePortRespSlot rsp_queue[RP_MAX_OUTSTANDING_TRANSACTIONS]; + } dev_state[REMOTE_PORT_MAX_DEVS]; + RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; }; =20 + +void rp_rsp_mutex_lock(RemotePort *s); +void rp_rsp_mutex_unlock(RemotePort *s); + +RemotePortDynPkt rp_wait_resp(RemotePort *s); + +RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t= id); +RemotePortRespSlot *rp_dev_timed_wait_resp(RemotePort *s, uint32_t dev, + uint32_t id, int timems); + void rp_process(RemotePort *s); =20 ssize_t rp_write(RemotePort *s, const void *buf, size_t count); --=20 2.43.0