From nobody Mon Feb 9 11:34:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) client-ip=209.85.221.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1618668131; cv=none; d=zohomail.com; s=zohoarc; b=T5iavlfjUZb3KsS+nZPpr4VqPlO/jYyjpS5vIB4/NTQFbgOZhvDOcuKadyAqJAfO57gqDR3+gdHxBwyV/1ziUlFDDYcuYz7AhWonzb1uCOdn5DYWO/iUX2+Z9ONv7syTUzxKg9rRPFyRE9paSkv6qGJr1lT3kUbeLaGfGCdTl6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618668131; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Sender:Subject:To; bh=mG2CetGzS7CKTUwI5wgYD0g3r71RIHSxkx0UQfTG4DQ=; b=mOxKXVcD0WRqksIVTFze/NPiK462MHgChHviEG2dAW4kqQkzbhH+sgaJ6ciFWa4BpgqIgiJz8o+8jcEHFF2E7ZPmftLt1O2l+FsFzOXh1fvqw1Wx43roSSDQ0PQQvwRN2/7uOfN9cg9GDiL5N748Vx/b4TYzMR6x0dZdVP9ao8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.zohomail.com with SMTPS id 1618668131017459.511534531032; Sat, 17 Apr 2021 07:02:11 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id p6so22640690wrn.9 for ; Sat, 17 Apr 2021 07:02:10 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (39.red-81-40-121.staticip.rima-tde.net. [81.40.121.39]) by smtp.gmail.com with ESMTPSA id v4sm11835991wme.14.2021.04.17.07.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Apr 2021 07:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mG2CetGzS7CKTUwI5wgYD0g3r71RIHSxkx0UQfTG4DQ=; b=D/K8VfWZoBVEdljcXWaCU+Mjfboezn4VExREeLxxIv4OHdkTFueyfjMet7Sg0SJGlT cnYjjkWp8yfSzTyVT+v6oMTpIkVzNPmuHmCbzUdG2rDQRgTovneADjE09JcfrXKVwpBD nXEEc8b9sqaq5eJtkOfeIidNk5QqfjC5u+PQ9RV04tT760kb0csVd2KUndRbpC/VgnF4 QLyVfj38npid2AeTve0HyR0TsUUhfFp8ICDnSkD0n8D26M6tWFbCb9DC/i479JcMzYkc IruFmoiIg6IfPFmORAiRAHrqEdUh1ELrr1Lg+A1lM1+BUKXwRZcNUGP0plYGH2SsjOG1 16mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=mG2CetGzS7CKTUwI5wgYD0g3r71RIHSxkx0UQfTG4DQ=; b=TP3wIeuXOQWyrlYCi0MXItO/GrKX1eaLhit/JnZBFvTOAAdaiZmrtuMsjW5jAl1380 d3EzU1R+fn8UotLgLhPG3REMpQ4usFhp3kKT5JwD2RnN5OwipP/viTRJkfIKafUAZpnA zSdw5YK/thpckeMOQALJqAx0Vk6NbLkCLBxsOYZq6AKPuD/TuNb4J2DZOHojNXqOrqRW DJ35w/xzQzVBIN6uICW+HSyknpFx8waVSFOmwJCQ1t3FQq999aywRs47CDo/8dS7F6HD 5dQxW8QTp9z2jC+m4qUUoBLsXKWmduVVPJSadAbAwHcxaljTDAT+dSCMKR0FdJnRFmDQ Mrtw== X-Gm-Message-State: AOAM532TCf9fClEgbuoiYydghaX/MBKJRopkI9zvajX0XGD5H1Ubc+pS fmHQ3Zi0c9VQpbQ9praxhKI= X-Google-Smtp-Source: ABdhPJx1O4Boc38ZtAeU5ygI3n14EmywJT7vh9eFyjptL4vmBBmgrFT62CtVRxrZj9J4IDpjwbFepA== X-Received: by 2002:a5d:564a:: with SMTP id j10mr4563257wrw.108.1618668128757; Sat, 17 Apr 2021 07:02:08 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3] memory: Directly dispatch alias accesses on origin memory region Date: Sat, 17 Apr 2021 16:02:06 +0200 Message-Id: <20210417140206.673885-1-f4bug@amsat.org> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Since commit 2cdfcf272d ("memory: assign MemoryRegionOps to all regions"), all newly created regions are assigned with unassigned_mem_ops (which might be then overwritten). When using aliased container regions, and there is no region mapped at address 0 in the container, the memory_region_dispatch_read() and memory_region_dispatch_write() calls incorrectly return the container unassigned_mem_ops, because the alias offset is not used. The memory_region_init_alias() flow is: memory_region_init_alias() -> memory_region_init() -> object_initialize(TYPE_MEMORY_REGION) -> memory_region_initfn() -> mr->ops =3D &unassigned_mem_ops; Later when accessing the alias, the memory_region_dispatch_read() flow is: memory_region_dispatch_read(offset) -> memory_region_access_valid(mr) <- offset is ignored -> mr->ops->valid.accepts() -> unassigned_mem_accepts() <- false <- false <- MEMTX_DECODE_ERROR The caller gets a MEMTX_DECODE_ERROR while the access is OK. Fix by dispatching aliases recusirvely, accessing its origin region after adding the alias offset. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v3: - reworded, mentioning the "alias to container" case - use recursive call instead of while(), because easier when debugging therefore reset Richard R-b tag. v2: - use while() --- softmmu/memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/softmmu/memory.c b/softmmu/memory.c index d4493ef9e43..23bdbfac079 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1442,6 +1442,11 @@ MemTxResult memory_region_dispatch_read(MemoryRegion= *mr, unsigned size =3D memop_size(op); MemTxResult r; =20 + if (mr->alias) { + return memory_region_dispatch_read(mr->alias, + addr + mr->alias_offset, + pval, op, attrs); + } if (!memory_region_access_valid(mr, addr, size, false, attrs)) { *pval =3D unassigned_mem_read(mr, addr, size); return MEMTX_DECODE_ERROR; @@ -1486,6 +1491,11 @@ MemTxResult memory_region_dispatch_write(MemoryRegio= n *mr, { unsigned size =3D memop_size(op); =20 + if (mr->alias) { + return memory_region_dispatch_write(mr->alias, + addr + mr->alias_offset, + data, op, attrs); + } if (!memory_region_access_valid(mr, addr, size, true, attrs)) { unassigned_mem_write(mr, addr, data, size); return MEMTX_DECODE_ERROR; --=20 2.26.3