From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1es9bV-0007FE-EO for qemu-devel@nongnu.org; Sat, 03 Mar 2018 11:01:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1es9bU-0006mN-Ek for qemu-devel@nongnu.org; Sat, 03 Mar 2018 11:01:45 -0500 MIME-Version: 1.0 In-Reply-To: <57abe9de-1258-3624-2f8a-882f1de1d19d@weilnetz.de> References: <20180127134908.24095-1-anatoly.trosinenko@gmail.com> <20180127134908.24095-2-anatoly.trosinenko@gmail.com> <57abe9de-1258-3624-2f8a-882f1de1d19d@weilnetz.de> From: Anatoly Trosinenko Date: Sat, 3 Mar 2018 19:01:42 +0300 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [PATCH 1/1] tci: eliminate UB due to unaligned reads List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: Richard Henderson , qemu-devel@nongnu.org, qemu-trivial@nongnu.org 2018-03-03 18:41 GMT+03:00 Stefan Weil : > Am 03.03.2018 um 15:07 schrieb Anatoly Trosinenko: > > Can rewriting TCI in such a way that every operation is aligned at 4- or > > even 8-byte boundary fix the situation or are there some more serious > > problems? > > That's my preferred solution. Are there cases which would require 8-byte > alignment? > And what if create some function like uint8_t *align_and_increment(uint8_t **ptr, int pow2) { size_t size = 1 << pow2; uint8_t *result = (uint8_t*)((((uintptr)*ptr) + size - 1) & ~(size - 1)); *ptr = result + size; return result; } and rewrite get / put functions like this: static uint32_t tci_read_i32(uint8_t **tb_ptr) { uint32_t value = *(uint32_t *)align_and_increment(tb_ptr, 2); return value; } On one hand, it involves some slightly obscure pointer calculations (just in one place), on the other hand, no modifications will probably be required for TCI TCG backend or interpreter loop code (they can still be useful for **optimizations** of bytecode size, but it should just work as is). -- Best regards, Anatoly