From nobody Sun Dec 28 08:37:30 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1702278854; cv=none; d=zohomail.com; s=zohoarc; b=g/PKTwEDZGU/F+HhEzB1L7Ioo9da/8IpUK+IpVvA9VkG/dN11wSoozXwSKecKM0skOH4tLqUygYsfiCueQXg/8w3NJ6sYL2H7Yowr4o6vXmvZhCqf6V093dhjgmHwHX+qD7uq+RMrYdrS+CZ86AlAvnm6VvoOJnn7cvG6dB+VxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702278854; 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=D+K7EXH6z5cxbjBPNRPPoIKGz7ihR0RlHvVKrh/SMeM=; b=Nvuzj/JmNnrSJv/4AVTpDDYaqqTPe9YuYoa3ZO4s0CHG1/dlPgjo9pc61QDcC2Dh7hCPDdWE8Ddsg+MyMDmLF8cGfj3/B1Qf6pvwhDbQqddcLxaoR4hj7Sw0ZUWYaH1o3dLY9D/iD0mP7jV5lE7AWsSM382ZUql4AB4YMgnprlU= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1702278854328317.59410291337883; Sun, 10 Dec 2023 23:14:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCaTU-0007Tg-8C; Mon, 11 Dec 2023 02:13:08 -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 1rCaTQ-0007S6-Dd for qemu-devel@nongnu.org; Mon, 11 Dec 2023 02:13:05 -0500 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rCaTN-0005O0-RJ for qemu-devel@nongnu.org; Mon, 11 Dec 2023 02:13:03 -0500 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ce6b62746dso2344900b3a.2 for ; Sun, 10 Dec 2023 23:13:01 -0800 (PST) Received: from ThinkPad-T14-hirose.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id v23-20020a170902e8d700b001d08e080042sm5842150plg.43.2023.12.10.23.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 23:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20230601.gappssmtp.com; s=20230601; t=1702278780; x=1702883580; 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=D+K7EXH6z5cxbjBPNRPPoIKGz7ihR0RlHvVKrh/SMeM=; b=uYNb1i0Fk7OxZxHNvJLxegG2b81xlNQjTCkEuHZOpbAC174Fuwffwt1v4oQGzEg/Ab acTxeOMwYIQNFFlb4AboAIyfSY7SWxvOaJar4/NHQDxLi99Y7AbIyZjQygyIlgGmTbzs bvAbFOGgcRIxXXut0GinZ0saF9exYWP+rVxiX6MYvej48eOSuuaKoUTs1BAdoCKeSqLd gnp955XqZCizxQgxuWes8ciNeMgzARZshAIriTPYR5zBBVWzodAI2s9UlPo/LoNKYgzi 322b3REZlPdec4gKiRMZd10g3VUm7J6Oiu9b2GE0a3UUTR7eIMO2sYRi0JiwJz0pJ1nE bKbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702278780; x=1702883580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D+K7EXH6z5cxbjBPNRPPoIKGz7ihR0RlHvVKrh/SMeM=; b=nP+pghalwn1nAqkQW49lsbgrMI0syunIHELdqJN213I7gQA3W8YeXTbMw8WF8bi0JD blTMZQu6VnWZOAdzj3wvI0zAv8X2MMzNskqyIF98MAyJOjAXpHKLRl9rvbpYj4ZpJH+M llOdOHEQiV70X8Vuxy884DT0JVi8OP0WJDOHTd6J0FtGHRIOOv6JgZkkr9h70HlIwhGN HRw0Zy3sKXVRhYm97cny5/9SvPo8mX0C2MkiXGzrXP6fx6rTYrwey+dwTvxjLvJRotO1 7zH+mWwKCIwrEWmLXP8w1h48aj61InlnWRxMhEy2jmbnhxpgQA37Y4lPWiq5f5hEZPVi L9+g== X-Gm-Message-State: AOJu0Ywcv24Nc86xnoCe59xZHrsve6BW9UEUJrOp3dV7+u3XNb5C97mG tEqkO5hK/hElYwpW2kx9Jg43HSYcgK9jARLgrVc= X-Google-Smtp-Source: AGHT+IGbqbN/ZyMX0ZzzsTkekSiiE1iqMPRNOOYmrDi8GQqrD/Ot8Vm6gG8rYvyzYUWOwwx93FGAag== X-Received: by 2002:a05:6a20:1047:b0:187:1015:bf9c with SMTP id gt7-20020a056a20104700b001871015bf9cmr1530395pzc.10.1702278780385; Sun, 10 Dec 2023 23:13:00 -0800 (PST) From: Tomoyuki HIROSE To: qemu-devel@nongnu.org Cc: Tomoyuki HIROSE , Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 1/2] system/memory.c: support unaligned access Date: Mon, 11 Dec 2023 16:12:03 +0900 Message-Id: <20231211071204.30156-2-tomoyuki.hirose@igel.co.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211071204.30156-1-tomoyuki.hirose@igel.co.jp> References: <20231211071204.30156-1-tomoyuki.hirose@igel.co.jp> 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::434; envelope-from=tomoyuki.hirose@igel.co.jp; helo=mail-pf1-x434.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @igel-co-jp.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1702278854804100003 Content-Type: text/plain; charset="utf-8" The previous code ignored 'impl.unaligned' and handled unaligned accesses as is. But this implementation cannot emulate specific registers of some devices that allow unaligned access such as xHCI Host Controller Capability Registers. This commit checks 'impl.unaligned' and if it is false, QEMU emulates unaligned access with multiple aligned access. Signed-off-by: Tomoyuki HIROSE --- system/memory.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/system/memory.c b/system/memory.c index 798b6c0a17..b0caa90fef 100644 --- a/system/memory.c +++ b/system/memory.c @@ -539,6 +539,9 @@ static MemTxResult access_with_adjusted_size(hwaddr add= r, unsigned i; MemTxResult r =3D MEMTX_OK; bool reentrancy_guard_applied =3D false; + hwaddr aligned_addr; + unsigned corrected_size =3D size; + signed align_diff =3D 0; =20 if (!access_size_min) { access_size_min =3D 1; @@ -560,18 +563,25 @@ static MemTxResult access_with_adjusted_size(hwaddr a= ddr, reentrancy_guard_applied =3D true; } =20 - /* FIXME: support unaligned access? */ access_size =3D MAX(MIN(size, access_size_max), access_size_min); access_mask =3D MAKE_64BIT_MASK(0, access_size * 8); + if (!mr->ops->impl.unaligned) { + aligned_addr =3D addr & ~(access_size - 1); + align_diff =3D addr - aligned_addr; + corrected_size =3D size < access_size ? access_size : + size + (align_diff > 0 ? access_size : 0); + addr =3D aligned_addr; + } if (memory_region_big_endian(mr)) { - for (i =3D 0; i < size; i +=3D access_size) { + for (i =3D 0; i < corrected_size; i +=3D access_size) { r |=3D access_fn(mr, addr + i, value, access_size, - (size - access_size - i) * 8, access_mask, attrs); + (size - access_size - i + align_diff) * 8, + access_mask, attrs); } } else { - for (i =3D 0; i < size; i +=3D access_size) { - r |=3D access_fn(mr, addr + i, value, access_size, i * 8, - access_mask, attrs); + for (i =3D 0; i < corrected_size; i +=3D access_size) { + r |=3D access_fn(mr, addr + i, value, access_size, + ((signed)i - align_diff) * 8, access_mask, attrs); } } if (mr->dev && reentrancy_guard_applied) { --=20 2.39.2 From nobody Sun Dec 28 08:37:30 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1702278833; cv=none; d=zohomail.com; s=zohoarc; b=nPgh/Dp9iOssMZURMfyrw/s5lBGA+N7CGhdLT8wRnOgz2c5HK5dqVjaDV2jekb+AO2IiWwBraPX0PZ6J/r/fmKOXiVYTyEo9Ve8aA/+MSsfP+lhpygATmcgCvlYX1zYoM9sQhd7g5ybhz9aFq714WVDe20iN4KXcTEFf8eqZ37o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702278833; 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=n76IMce3vLufNQdY3USLbCOIA4KvM6PYInLd1jOjkBA=; b=GOsfOCRPvYQfBwB6IAc4tSfwp5Lu3vXw9iOV55lN1vgaiKsbkj/sKNAbdMJRBkFrhKomyr6s0u2iPDJSR3/vRE/VsrOiMa5kk51e15ER9RYse9HF/glx/7Qbq0sKP3rYwPv8q59Jqp2iCPVcUkRL82Dw7QaNYvp6QI/eSc3qJfI= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1702278833260780.9787673814814; Sun, 10 Dec 2023 23:13:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCaTX-0007UO-4v; Mon, 11 Dec 2023 02:13:12 -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 1rCaTU-0007Ti-7x for qemu-devel@nongnu.org; Mon, 11 Dec 2023 02:13:08 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rCaTS-0005Qe-Fb for qemu-devel@nongnu.org; Mon, 11 Dec 2023 02:13:07 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d053c45897so36329945ad.2 for ; Sun, 10 Dec 2023 23:13:06 -0800 (PST) Received: from ThinkPad-T14-hirose.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id v23-20020a170902e8d700b001d08e080042sm5842150plg.43.2023.12.10.23.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 23:13:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20230601.gappssmtp.com; s=20230601; t=1702278785; x=1702883585; 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=n76IMce3vLufNQdY3USLbCOIA4KvM6PYInLd1jOjkBA=; b=0I316LdvYl/4r9EgOOKy1W7ultmZ8tGxgyxAEoMyw12d9vzuf1JAbQYv048Ady+eFh d0F7Wvdt2hZbLRjqsQCvZeleDMugMtZLt7gAe584K6T8YXoqnaxkSSIAzi/1MIAfESy4 Luqh0Z5u919lfUixdX/3lzewhP3eDc0XcS2qiDZVwHl2s4MjLPvpbnSvKpMR3YPXXmRD z/2Jq+wxzC30HaEyKs2YD8yzslR9M1QbR5oeF2m/K9jQWWKhf4pkinh6dxs9bFpcgPmu x+U3t1FoOcelF4tarxO8g00+dMwGXrTnFbsbkUyRrw6lfb0JNyYpOAB2EipKvGp10NJ1 SMlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702278785; x=1702883585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n76IMce3vLufNQdY3USLbCOIA4KvM6PYInLd1jOjkBA=; b=jvYh7vNJWwF7+Ihfm/LIbnTh8yUA4Dn059NWf/eLFjWjy8MvxhrPLSBLzZWUms69W/ zf/iGRY+WOi5sVMB+jNp4SNlVJWofVRTkZCWMxEYAmFmcZB0F/WbGwbFFj2RKgRl9dXM RmtmGUq4m1BNnSdyrS9MzoVS6fjfDChhsgRiBp6tXMVUSd5YQh6gucZbFGX25j9vU4JJ wU8R2Nonj17U6Vt77BA3OPM/EZTVDLF1Z7IMlh8pj2IC+V5fVstI4qs6CIFfEFvVl80e D1IOJPJcNpg+iBxuYoSFKs/1zgJrK++lNvPid+wzap1bGcu+GJaIUSMoPRjoyNwa+Mmu 5/xA== X-Gm-Message-State: AOJu0Yzk1izULQ7gvAMtHoMrluSB1CpOmRh7RiEiHwXFDjP5/+JXxmab qZ4If/CPyF0J8UaygVjfaiJ6e9MYgYrYMyl79fM= X-Google-Smtp-Source: AGHT+IHxKbI22OS6/KS+W3pnCOoWNzmovNJhK1dCgoQIo9rQoaGdM4sjObX18QVpXhCvSN+7946eQw== X-Received: by 2002:a17:902:a517:b0:1d0:6ffd:9e28 with SMTP id s23-20020a170902a51700b001d06ffd9e28mr3228380plq.122.1702278784908; Sun, 10 Dec 2023 23:13:04 -0800 (PST) From: Tomoyuki HIROSE To: qemu-devel@nongnu.org Cc: Tomoyuki HIROSE , Gerd Hoffmann Subject: [PATCH 2/2] hw/usb/hcd-xhci.c: allow unaligned access to Capability Registers Date: Mon, 11 Dec 2023 16:12:04 +0900 Message-Id: <20231211071204.30156-3-tomoyuki.hirose@igel.co.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211071204.30156-1-tomoyuki.hirose@igel.co.jp> References: <20231211071204.30156-1-tomoyuki.hirose@igel.co.jp> 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::630; envelope-from=tomoyuki.hirose@igel.co.jp; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @igel-co-jp.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1702278834713100007 Content-Type: text/plain; charset="utf-8" According to xHCI spec rev 1.2, unaligned access to xHCI Host Controller Capability Registers is not prohibited. In Addition, the limit of access size is also unspecified. Actually, some real devices allow unaligned access and 8-byte access to these registers. This commit makes it possible to unaligned access and 8-byte access to Host Controller Capability Registers. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/143 Signed-off-by: Tomoyuki HIROSE --- hw/usb/hcd-xhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 4b60114207..41abeb9ac5 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3181,9 +3181,11 @@ static const MemoryRegionOps xhci_cap_ops =3D { .read =3D xhci_cap_read, .write =3D xhci_cap_write, .valid.min_access_size =3D 1, - .valid.max_access_size =3D 4, + .valid.max_access_size =3D 8, + .valid.unaligned =3D true, .impl.min_access_size =3D 4, .impl.max_access_size =3D 4, + .impl.unaligned =3D false, .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 --=20 2.39.2