From nobody Mon May 6 16:29:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538008001570264.9813538180472; Wed, 26 Sep 2018 17:26:41 -0700 (PDT) Received: from localhost ([::1]:33138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5K8T-0005sY-0I for importer@patchew.org; Wed, 26 Sep 2018 20:26:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5K6g-0004xC-To for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5K6d-00010A-AV for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:38 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5K6d-0000zy-3v for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:35 -0400 Received: by mail-wr1-x444.google.com with SMTP id v16-v6so644083wro.11 for ; Wed, 26 Sep 2018 17:24:35 -0700 (PDT) Received: from x1.local (106.red-88-7-90.staticip.rima-tde.net. [88.7.90.106]) by smtp.gmail.com with ESMTPSA id x14-v6sm559668wmc.36.2018.09.26.17.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 17:24:33 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=c7e+xDsE7xq6CBI9sCFeSw0mLtK8wo6hvJI0/TR6UFk=; b=UW1CCdcrb4C0hpVJPRSJZ1sO5oI9kqwb8f+4fPeWr5vKXMT7P4UVGHARaBsjKvWOs0 g/HQcxKVkLHcuMSzvxri4xaV/Q9k+aAaojIc9j8ycuVeyXFF9mSEyk8Ai2y6pmnD61pj WbyouL9QWK08DXKlkA+kREcKqoWdYbN2SqeaPdendglIpvCWT0Fg4mSvabB2MiMAkAmL y+zzKwH78By2GLrV8e1NLU86KeGG49SuVun9uknmQw2fxyDN2wLlXE9cQretec6q/fs4 iG7mVbV8b87YADRtiWe93H96/w2TfHbC5lcHigGa1j2d+kgoxgFT3qNiOWfmiXm7+ddQ ixog== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=c7e+xDsE7xq6CBI9sCFeSw0mLtK8wo6hvJI0/TR6UFk=; b=Z9T9k276/Tq8o31CTM8z46JhRx8UqUITk1fPIXrQ8PKQxP/ch716m3+HCHL69cB6Ir Rfo6mHGDk4ZVppcBPFN2iqTZyFVqKgYlcsZt0EojC1R/f37EtNnNUnQDdmqfSr+85Mzz FhYw+2pP6LPxiowf2gZ7u8Ybq+JRPENy+ThY6q/ABWxEuuGQkrz6KwfwMoVgggftlbQa UbYm6Ps44nhP1VNucFv8ONymzgI9/fBjXspsY+Ivx5G9d+9pueLE6yuaDl2INPLVjgqK UQT0nC2J96u6TXCq4rCoaTZlHq9zbt9aYWlXYRsJOdO1Q4qMT/b96UP8iHbd6pbRvdUN KQmA== X-Gm-Message-State: ABuFfog8ofjJNZ3Qxgvl3+bP5534KfwrOhKT6wY2Roqzpb2zADhFDNwr XL6J4siTouojovpovl9tKRk= X-Google-Smtp-Source: ACcGV60GX6n9TRk9D6AgRoFEJ6VCGL/8dI3U+WQ197BhWinlh1ncItBiPGbBkUaRAWZGILit++5PEg== X-Received: by 2002:adf:b112:: with SMTP id l18-v6mr7099864wra.101.1538007874092; Wed, 26 Sep 2018 17:24:34 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Paolo Bonzini , Peter Maydell Date: Thu, 27 Sep 2018 02:24:14 +0200 Message-Id: <20180927002416.1781-2-f4bug@amsat.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927002416.1781-1-f4bug@amsat.org> References: <20180927002416.1781-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 1/3] memory: Use MAKE_64BIT_MASK() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , KONRAD Frederic , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell --- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 9b73892768..385b9d3590 100644 --- a/memory.c +++ b/memory.c @@ -582,7 +582,7 @@ static MemTxResult access_with_adjusted_size(hwaddr add= r, =20 /* FIXME: support unaligned access? */ access_size =3D MAX(MIN(size, access_size_max), access_size_min); - access_mask =3D -1ULL >> (64 - access_size * 8); + access_mask =3D MAKE_64BIT_MASK(0, access_size * 8); if (memory_region_big_endian(mr)) { for (i =3D 0; i < size; i +=3D access_size) { r |=3D access_fn(mr, addr + i, value, access_size, --=20 2.19.0 From nobody Mon May 6 16:29:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538008106821957.5065713962283; Wed, 26 Sep 2018 17:28:26 -0700 (PDT) Received: from localhost ([::1]:33146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5KAL-0007Jj-Gm for importer@patchew.org; Wed, 26 Sep 2018 20:28:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5K6g-0004xD-Up for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5K6e-00010d-Hd for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:38 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:42802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5K6e-00010I-B6 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:36 -0400 Received: by mail-wr1-x42e.google.com with SMTP id b11-v6so655972wru.9 for ; Wed, 26 Sep 2018 17:24:36 -0700 (PDT) Received: from x1.local (106.red-88-7-90.staticip.rima-tde.net. [88.7.90.106]) by smtp.gmail.com with ESMTPSA id x14-v6sm559668wmc.36.2018.09.26.17.24.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 17:24:34 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=+GD3z/eIrVCqie1m7U9g0zWeFiwEEBNETij89vpHNQM=; b=pbw4RGSHwE+A/SAPGOsJKrIjR+EDWSQ1qqI397q7L8/1qo5ezNrtz+mMKmkpSbSE/Z KxBgYkPVyDLgaksMrHLjQZzT0+k59lVgaZujUyl41qzqi+T7Z+FvYeusIXeTHcnkKotB CrjW9zDq2FqXarRivz//ennW0iVdA5GrPscSU1Y3qXZLNJkQd8QZwFn9dy27OSlaWo5y TCysAUrLQOCVlXki+DcYoHN+ENKcZkV/odqufCEqryiNPYDuy6NNBfN7pi+tlK/wHTzo NuvYx/9Qm3VoRea3b3gOrjE1xkDxlotKMLsrX1QAxzhCD4iXHPHJrI7AjAo+VHA3mi+U zK4g== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=+GD3z/eIrVCqie1m7U9g0zWeFiwEEBNETij89vpHNQM=; b=VNtQ8Yo41xryqO0FX/tR1pfTipOq+HcOGwJabyeelFTpdAIwqnlZGKm0uGb0/UvG1w /54GIysoAfYiTCoXNtxqJl9Pf4l/lgIAT7or0eCFCzshYV58U2COLk9cwDcgSM6Xp8Ji dZjmRePnGCQmWQHFosLPNVziV1uxGBG+XJ+AwsfcSU5Wx58CJfS3dkRTsXCDZbO2b7Ob n3nTJ9BAT2X0nxglY7ZebNSg+G8JQrNsSQXKBg3zPgVQX6rwyUHsU8ZbrpueUjri0Ogb zlabeBAYnxB8+CDyJpGhXvG8/X0uvBXHujonowhP8SsnI3CjbSwncyb6cs8CxtxyjakK PlQg== X-Gm-Message-State: ABuFfohxxy5O+e+9+3mJCjpoj09orVJZcaA2N1P3HKF3R0EmfnJSENKd xvAFSvZ/bTdRleGcM3cbiX0= X-Google-Smtp-Source: ACcGV62Pt1CDO1rZGGsf67zGWlMfsNDzLNimQM56h1eaHh3J0cH4TRFBjx+BzTtad+ZBm7RbYsP94A== X-Received: by 2002:adf:8103:: with SMTP id 3-v6mr6722752wrm.213.1538007875302; Wed, 26 Sep 2018 17:24:35 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Paolo Bonzini , Peter Maydell Date: Thu, 27 Sep 2018 02:24:15 +0200 Message-Id: <20180927002416.1781-3-f4bug@amsat.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927002416.1781-1-f4bug@amsat.org> References: <20180927002416.1781-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [PATCH 2/3] memory: Refactor common shifting code from accessors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , KONRAD Frederic , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Peter Maydell --- memory.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/memory.c b/memory.c index 385b9d3590..48edf7dc23 100644 --- a/memory.c +++ b/memory.c @@ -374,6 +374,21 @@ static void adjust_endianness(MemoryRegion *mr, uint64= _t *data, unsigned size) } } =20 +static inline void memory_region_shift_read_access(uint64_t *value, + unsigned shift, + uint64_t mask, + uint64_t tmp) +{ + *value |=3D (tmp & mask) << shift; +} + +static inline uint64_t memory_region_shift_write_access(uint64_t *value, + unsigned shift, + uint64_t mask) +{ + return (*value >> shift) & mask; +} + static hwaddr memory_region_to_absolute_addr(MemoryRegion *mr, hwaddr offs= et) { MemoryRegion *root; @@ -418,7 +433,7 @@ static MemTxResult memory_region_oldmmio_read_accessor(= MemoryRegion *mr, hwaddr abs_addr =3D memory_region_to_absolute_addr(mr, addr); trace_memory_region_ops_read(get_cpu_index(), mr, abs_addr, tmp, s= ize); } - *value |=3D (tmp & mask) << shift; + memory_region_shift_read_access(value, shift, mask, tmp); return MEMTX_OK; } =20 @@ -444,7 +459,7 @@ static MemTxResult memory_region_read_accessor(MemoryR= egion *mr, hwaddr abs_addr =3D memory_region_to_absolute_addr(mr, addr); trace_memory_region_ops_read(get_cpu_index(), mr, abs_addr, tmp, s= ize); } - *value |=3D (tmp & mask) << shift; + memory_region_shift_read_access(value, shift, mask, tmp); return MEMTX_OK; } =20 @@ -471,7 +486,7 @@ static MemTxResult memory_region_read_with_attrs_access= or(MemoryRegion *mr, hwaddr abs_addr =3D memory_region_to_absolute_addr(mr, addr); trace_memory_region_ops_read(get_cpu_index(), mr, abs_addr, tmp, s= ize); } - *value |=3D (tmp & mask) << shift; + memory_region_shift_read_access(value, shift, mask, tmp); return r; } =20 @@ -483,9 +498,8 @@ static MemTxResult memory_region_oldmmio_write_accessor= (MemoryRegion *mr, uint64_t mask, MemTxAttrs attrs) { - uint64_t tmp; + uint64_t tmp =3D memory_region_shift_write_access(value, shift, mask); =20 - tmp =3D (*value >> shift) & mask; if (mr->subpage) { trace_memory_region_subpage_write(get_cpu_index(), mr, addr, tmp, = size); } else if (mr =3D=3D &io_mem_notdirty) { @@ -509,9 +523,8 @@ static MemTxResult memory_region_write_accessor(MemoryR= egion *mr, uint64_t mask, MemTxAttrs attrs) { - uint64_t tmp; + uint64_t tmp =3D memory_region_shift_write_access(value, shift, mask); =20 - tmp =3D (*value >> shift) & mask; if (mr->subpage) { trace_memory_region_subpage_write(get_cpu_index(), mr, addr, tmp, = size); } else if (mr =3D=3D &io_mem_notdirty) { @@ -535,9 +548,8 @@ static MemTxResult memory_region_write_with_attrs_acces= sor(MemoryRegion *mr, uint64_t mask, MemTxAttrs attr= s) { - uint64_t tmp; + uint64_t tmp =3D memory_region_shift_write_access(value, shift, mask); =20 - tmp =3D (*value >> shift) & mask; if (mr->subpage) { trace_memory_region_subpage_write(get_cpu_index(), mr, addr, tmp, = size); } else if (mr =3D=3D &io_mem_notdirty) { --=20 2.19.0 From nobody Mon May 6 16:29:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538008001634153.5427244145967; Wed, 26 Sep 2018 17:26:41 -0700 (PDT) Received: from localhost ([::1]:33139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5K8U-0005uT-N5 for importer@patchew.org; Wed, 26 Sep 2018 20:26:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5K6g-0004xF-Ur for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5K6f-00011B-Q6 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:38 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38453) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5K6f-00010t-GM for qemu-devel@nongnu.org; Wed, 26 Sep 2018 20:24:37 -0400 Received: by mail-wr1-x444.google.com with SMTP id j8-v6so677728wrw.5 for ; Wed, 26 Sep 2018 17:24:37 -0700 (PDT) Received: from x1.local (106.red-88-7-90.staticip.rima-tde.net. [88.7.90.106]) by smtp.gmail.com with ESMTPSA id x14-v6sm559668wmc.36.2018.09.26.17.24.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 17:24:35 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=JQlWVQRgXbBmK4B504HDYOvr3PiUiayxnNsOP5+/zWo=; b=kI7pPbC0ccUVIwjGSs+5b+E17kQENLTh9ltn3LZ2Ha3y72xmk6RSZHIMbFvO+mJk/4 SlnczZ9WsiMEwat0+FGrsueieaqujUwFmSbkm/vS1tHcR/KfZmRLjbo/f4Lk2XlgfAX8 mO+bhcLXwUS0NSyvXW6X/aIYB5G2dqKxCo/3WO/eIbhvt4v8ZJPz5ozh+aI3umi6Vnci oGCezh5xqleXEXkkBy7MtUtK+3QP8IE5VDDZmIpvOHQI3gXNeSik5YdKcX2zI2mzHlUb CAEtgigQQKnsgb48CtfrQbAQ4UcS9jm8gCXcGyg+khkUULIDEidzndSyIcSYfIY15ZmT 3dTw== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=JQlWVQRgXbBmK4B504HDYOvr3PiUiayxnNsOP5+/zWo=; b=LDrmbQ6GIchEUkAvNVmOhEVSvrjMhfwR87c2mUgXuqQPge0Dy2bEuEWAvWgj9DM6SM QKzJtniNcPaip8Ku3VFtGA79ivVWyZIFu2OAF6/ha9enPITEltdQWxCA5phnPWFwEY4G BW2EMEB73MSIgvA4utzzVJM+XvI6wa6+4MZFytNI/O2wyC7IWA+YXLEHrEDqc13J29rH PjKcVTenJ15CA2SEnPy+Qmf85apn5XHOepzt0tCXIyem2sNP6r333dUFJpI/2gMX+kRK yMQ0mzOQbXidOY0qB92szNIs5d7b4kDvqcSd11zNcgcE7Lo5KL+szSuY0WkzWcJ9sfsG klvQ== X-Gm-Message-State: ABuFfojc3pteHOHERAdnYrdCAjNIoxScjdJ+vZ4c1J8BHf2PrvjxE+8l GfXmMkCzEOjggoqXpm5Im7o= X-Google-Smtp-Source: ACcGV639409mStFr0CQDWuHj6vhLpXYvAH5NWQ3yhZo8v+s/Q0L+xE1ETYlMUFBwm9vTfZvfg+tmyg== X-Received: by 2002:adf:8206:: with SMTP id 6-v6mr6749302wrb.160.1538007876486; Wed, 26 Sep 2018 17:24:36 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Paolo Bonzini , Peter Maydell Date: Thu, 27 Sep 2018 02:24:16 +0200 Message-Id: <20180927002416.1781-4-f4bug@amsat.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927002416.1781-1-f4bug@amsat.org> References: <20180927002416.1781-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 3/3] memory: Fix access_with_adjusted_size(small size) on big-endian memory regions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , KONRAD Frederic , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Memory regions configured as DEVICE_BIG_ENDIAN (or DEVICE_NATIVE_ENDIAN on big-endian guest) behave incorrectly when the memory access 'size' is small= er than the implementation 'access_size'. In the following code segment from access_with_adjusted_size(): if (memory_region_big_endian(mr)) { for (i =3D 0; i < 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) * 8 is the number of bits that will arithmetic shift the current value. Currently we can only 'left' shift a read() access, and 'right' shift a wri= te(). When the access 'size' is smaller than the implementation, we get a negative number of bits to shift. For the read() case, a negative 'left' shift is a 'right' shift :) However since the 'shift' type is unsigned, there is currently no way to right shift. Fix this by changing the access_fn() prototype to handle signed shift value= s, and modify the memory_region_shift_read|write_access() helpers to correctly arithmetic shift the opposite direction when the 'shift' value is negative. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell --- memory.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/memory.c b/memory.c index 48edf7dc23..a9f0fdc440 100644 --- a/memory.c +++ b/memory.c @@ -375,18 +375,30 @@ static void adjust_endianness(MemoryRegion *mr, uint6= 4_t *data, unsigned size) } =20 static inline void memory_region_shift_read_access(uint64_t *value, - unsigned shift, + signed shift, uint64_t mask, uint64_t tmp) { - *value |=3D (tmp & mask) << shift; + if (shift >=3D 0) { + *value |=3D (tmp & mask) << shift; + } else { + *value |=3D (tmp & mask) >> -shift; + } } =20 static inline uint64_t memory_region_shift_write_access(uint64_t *value, - unsigned shift, + signed shift, uint64_t mask) { - return (*value >> shift) & mask; + uint64_t tmp; + + if (shift >=3D 0) { + tmp =3D (*value >> shift) & mask; + } else { + tmp =3D (*value << -shift) & mask; + } + + return tmp; } =20 static hwaddr memory_region_to_absolute_addr(MemoryRegion *mr, hwaddr offs= et) @@ -415,7 +427,7 @@ static MemTxResult memory_region_oldmmio_read_accessor(= MemoryRegion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs) { @@ -441,7 +453,7 @@ static MemTxResult memory_region_read_accessor(MemoryR= egion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs) { @@ -467,7 +479,7 @@ static MemTxResult memory_region_read_with_attrs_access= or(MemoryRegion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs) { @@ -494,7 +506,7 @@ static MemTxResult memory_region_oldmmio_write_accessor= (MemoryRegion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs) { @@ -519,7 +531,7 @@ static MemTxResult memory_region_write_accessor(MemoryR= egion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs) { @@ -544,7 +556,7 @@ static MemTxResult memory_region_write_with_attrs_acces= sor(MemoryRegion *mr, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attr= s) { @@ -574,7 +586,7 @@ static MemTxResult access_with_adjusted_size(hwaddr add= r, hwaddr addr, uint64_t *value, unsigned size, - unsigned shift, + signed shift, uint64_t mask, MemTxAttrs attrs), MemoryRegion *mr, --=20 2.19.0