From nobody Mon Apr 6 09:13:58 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1774881135; cv=none; d=zohomail.com; s=zohoarc; b=nrtJITz1MFEwNLXiM+LlcBtovPeebwJDDbuObATTgQ1IUcyt4v7QlVJzVgadgbjvO3AFxPsPB1UwbvZyGxBJAFypTTk0hJzPgB29+/mT2zWvxWqCo25M7N68N+Rly9JSbOODNv3s6IGn7fqDpXZEDUfEWRrMN9BLvJFUoQ7TY1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774881135; 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=FPfexUg//huq83MvV9fAvc/hO7xuXpj/vqxDNr67Au8=; b=hlvIggpu+Xzs8FhsU2qbGfi8rbdbTYOXHgbK/ZUBBkGDokjfifvxeJ7zBBDWncdcFi/aQGO34PfE1okvuMR+CNAhg0WKv+likdVPb9r/bztiW70LegH2XkjbGXELPCnAzA+lMspDENpKLGbiThbF30ZL2VV5ZEzY2Z2dl5uhFNs= 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 1774881135162295.8043530902754; Mon, 30 Mar 2026 07:32:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w7DeW-00015P-3l; Mon, 30 Mar 2026 10:31:45 -0400 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 1w7DeO-00014x-TV for qemu-devel@nongnu.org; Mon, 30 Mar 2026 10:31:33 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w7DeK-0002d6-Ac for qemu-devel@nongnu.org; Mon, 30 Mar 2026 10:31:30 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-486fda2a389so37033205e9.1 for ; Mon, 30 Mar 2026 07:31:27 -0700 (PDT) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722d49c18sm279767145e9.14.2026.03.30.07.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 07:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774881087; x=1775485887; 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=FPfexUg//huq83MvV9fAvc/hO7xuXpj/vqxDNr67Au8=; b=X1+l1hPiC5RKz6MBxFBtoSHQzz2SnaZHslNO2ZVrV5RoBDLUKBMZxzTyTyexFi/cfs MBHo5Wmu683OH22SW0YwqdVG/1t3s4tLGw++MktrIcl52HhRApDoy34+a2M/8SPiri7y kPrv134oqhBmk5D9zOKbYefzEN3imGpolx+eCS9eNLoaQQdiDDM8K6p4MttF0dRZ8Efy t1WnJS0Gdd5wNgAb8WasTi45sFxW/20KE3gDADYofBosyIJHQsCro6JYJtopGOLLX75l 9TV0VUtaFnk9gwWCbm95UB2hN1QOoE3RxHaEudG1BLZsJ1G9KtOdWfn7XPm9Y8eLDIzH bDiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774881087; x=1775485887; 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=FPfexUg//huq83MvV9fAvc/hO7xuXpj/vqxDNr67Au8=; b=YSHLQGs+xOnCAAxOSCbOVYEJTmK/53Wwujl09qiAvEtNyRCWnxTUB8dKXy9FnGHrqj 0wBUReq93VHHBUPf140fozdCn3EikkJq2LKfppghZc3ol8gDXk8aokDa5J2sLHsnhdgI zUplQ1itblRQeMU2AlBxYWCWm5ZwlEkNNzDCA2Kh2jqbiGKspPusl+grH2kojdYHNh4A 9VX23kwNRT75b84mfTe5IZcsqDkLr812+iYIEWv6t82bJuqts6bhhGhWmH6Al+3zxQcX NTjTOy88ob1xbcDG2mkWMTBWDeWItSTP8YikBO+0NaZFTIxrqJvyDPZvyEo7cxw8ya5q FRXw== X-Gm-Message-State: AOJu0YzO3YoQkKvtf3TdrlcDzRAop4gygM9wYeXy/aB/Mt72IJaieGgI GhXWWNNC/sNZvxE4IVFE88uKm7VhUnhmsh2/WW+jqGn337jSTRArzwg4bRceimFQo4DdW3dVqEK 0G7ezvoA= X-Gm-Gg: ATEYQzzke5zUa5cDr4uPs3H8jHSoJzPx5qsw724ocQNlsCqYbIB+Ket7jjV280sdcE6 dldCSXa7SYMULGaX34y3l0lvmx6GDPcgczH/0u6iICeeH69TBA5rXX53XQ0963A7XX7JQXOjSb7 scQSMu0MRpOKAFoBPAnxxo4bb6VeX6kji3LYz8cRLSPp7J+CtbR11W3nvd0IPLodBdSe9XbWAex BmI7s1ZN04Z+EoohLmsD3yC28kyrljBRyK8mH63C/JdOnTzIRVjpEAAAjhlXhchs+6QXq10LUUI pI0YzL7z3101aNA5Bd7yZX39Q8rX6k0dJ0kF6x9QmfnJ7vY+TtorHk/x82IpSdxm56RvhD//cRX HtGjyc/qqv18WcUcBeMbf+6pT42l5d2KEUWRiqjU+k3HbTMT9DNuz5kgGx8786wqNwGMprurF0R KakPStG0HPkmr+6/Hz8X73lb7L9iffcmxoqnoBBiXrlS9/sT9T53fGCjtJR5BIjUPnXCxNBSFh8 7VRy+htOR/plJ3+KxuFSkASPRBBMEhFhXO334PA3A== X-Received: by 2002:a05:600c:4e15:b0:485:2ce2:4c8a with SMTP id 5b1f17b1804b1-48727d67a21mr203850625e9.1.1774881086527; Mon, 30 Mar 2026 07:31:26 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , Warner Losh , Kyle Evans , Laurent Vivier , Pierrick Bouvier Subject: [PATCH 1/2] include: Don't include guest-host.h in cpu-ldst.h Date: Mon, 30 Mar 2026 15:31:22 +0100 Message-ID: <20260330143123.1685142-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260330143123.1685142-1-peter.maydell@linaro.org> References: <20260330143123.1685142-1-peter.maydell@linaro.org> 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::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.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, 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 @linaro.org) X-ZM-MESSAGEID: 1774881137593158500 Content-Type: text/plain; charset="utf-8" We currently include user/guest-host.h from accel/tcg/cpu-ldst.h. However that file doesn't need anything from guest-host.h, since we removed the uses of g2h() in commit 9b74d403b30e ("accel/tcg: Move user-only tlb_vaddr_to_host out of line"). Move the include of guest-host.h to where it's actually needed. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- This isn't needed for the following bugfix patch, but it made it a bit easier for me to understand where we're actually using the functions. --- bsd-user/qemu.h | 1 + include/accel/tcg/cpu-ldst.h | 4 ---- linux-user/qemu.h | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 2c586e546f..b0b2c249fb 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -27,6 +27,7 @@ #include "user/abitypes.h" #include "user/cpu_loop.h" #include "user/page-protection.h" +#include "user/guest-host.h" =20 extern char **environ; =20 diff --git a/include/accel/tcg/cpu-ldst.h b/include/accel/tcg/cpu-ldst.h index a5711bc15a..ea2cbf40fe 100644 --- a/include/accel/tcg/cpu-ldst.h +++ b/include/accel/tcg/cpu-ldst.h @@ -71,10 +71,6 @@ #include "accel/tcg/cpu-mmu-index.h" #include "exec/abi_ptr.h" =20 -#if defined(CONFIG_USER_ONLY) -#include "user/guest-host.h" -#endif /* CONFIG_USER_ONLY */ - static inline uint32_t cpu_ldub_mmuidx_ra(CPUArchState *env, abi_ptr addr, int mmu_idx, uintptr_t= ra) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 85e68eff7b..cfe5f45fc4 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -10,6 +10,7 @@ #include "syscall_defs.h" #include "target_syscall.h" #include "accel/tcg/vcpu-state.h" +#include "user/guest-host.h" =20 /* * This is the size of the host kernel's sigset_t, needed where we make --=20 2.43.0 From nobody Mon Apr 6 09:13:58 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1774881142; cv=none; d=zohomail.com; s=zohoarc; b=V6pVJtDvlTqkIMJHwHoz+mqumx/U0zF4v7Fd0JhihkVQbptAf6aKhQAmXBL/jgCbOPUbXHiX8BSDqC8D/6Ddua722IUY5uvsUB57reCBWx5lI5yuxfhkWcVWds6sJMhBTQsn87XMFUR7Ooyr+rkXNAXK2R3NqVGXUnysBaFhyOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774881142; 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=FyGLkbR92NTumPuyUeCJS2oJhBp8cITIz5HhLWLYSAU=; b=adHwYcUvyjKRpkKrHW3/TPNUGe0+OynFnLHonc1HxUoQ4EPZNnEHM89N7hxHBxo4eDCiubYpCAhDqsprZX+gN218LY2IcBzk2OihwS/rMtxv+sBSV5pV9YvJD5oJpGX3SHa8Wr+7Bgt/KDOjxgg78BlrC71TiSw3f9hGvwdaf48= 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 1774881142685326.550846271802; Mon, 30 Mar 2026 07:32:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w7Deq-0001Aa-RX; Mon, 30 Mar 2026 10:32:00 -0400 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 1w7DeS-00015S-M7 for qemu-devel@nongnu.org; Mon, 30 Mar 2026 10:31:39 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w7DeM-0002dO-Nt for qemu-devel@nongnu.org; Mon, 30 Mar 2026 10:31:34 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-48557c8ad47so34809085e9.0 for ; Mon, 30 Mar 2026 07:31:30 -0700 (PDT) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722d49c18sm279767145e9.14.2026.03.30.07.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 07:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774881089; x=1775485889; 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=FyGLkbR92NTumPuyUeCJS2oJhBp8cITIz5HhLWLYSAU=; b=jUnDI7FRjkaXoaHRp7sPfQcoldAh6Wz4CaXm5U4HTuKwtxJq7r4h82Py5RlXq13AhX dA+PNwHB5BQDnfQ/uAPVOq9WWi0kwQtjr63OXgJiua/qt96IEL4H+7gYdLLJRFqq8n5P 1mwGssqotHI6RG/yhxXRxHJklnQxIaMV2wmFAh6zDSADBzVrb2GYRkVi8XyDbK3UhvVY FcjefGY6MdLm1/iQU3+dH8tj8oOKcHqlB+PzSxJ5EwfkA/NzniUNUBYgNqx3szjxImp+ AqpmN+OkpgLL5J+57OUUPFXqo+3iFWBLvi3RXfBqknYLGQMPJ+UnFvQtmaHd58gLLC7Z r6xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774881089; x=1775485889; 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=FyGLkbR92NTumPuyUeCJS2oJhBp8cITIz5HhLWLYSAU=; b=d+dnrPEyX30UG9ZzWu+EwB4bI/1xe84S+EWbKxsRwjeapLkx2FdwwT8trlKmtp0n/0 0QS0P7G8CBzxQRyxm0+1tofZQ3J9me902N3W+FduQZL/yT+Bi32greIhsfMIAo87W2Cq IH6zlR+Munzx1JzwsEjYaCtFcYj0PM8jHqF6U/VtSWEN6FDX6s5ttaFDtv4TFTBPBVGa HzSTUWZ0SxDbsfard0bTU7OvWuUa5Zw9SlY8TDzO2ThVEJFot9RTMz/vw9v6Rhy7VGec 43fb1KLymrKFh/x49fqUlOcJ8BvxhLZvYVCFlUUa5+zgUZjixRk0nXCVtL6WRl9E5Yth 2axQ== X-Gm-Message-State: AOJu0Ywsb+Uw19eZL1RbVu9+0QyD7eTpRL0tPv2yhHwUvhmrfYxoWe2N PmX6wKJTUFWjm5yeToLvgDBSvVXRRit6dWDqIKpt+k90rVWRbIRVekT1MsD484V61Q0DYn3dzB0 a+SgvctY= X-Gm-Gg: ATEYQzzl4KFPvZ5XM895ZPSEnJ2Fz7L8CzMfoStydJCBCyQlIHWhuOPjFSodXPmTaSz l5TATVO8QkroNlYpJlTySMxbxOq7qEljWAHhTBNnxiKRhC2fgX0RRYGcbfg8DyFFH3ORr3PPPzo 8pHjrNefhq22TKKSVAIsBQ0W0Q9Q8sE+uxzkKsqb+4Z+tYoZHhFe3bZril6RoGK80P7/GYuhqYd ozoJ9eYceA0r8J+bayYHFvzBbVc6O4EcWnR5Ynv9Le/fumYpC2xf/dRYOmPydnowarAV1rOv4ML g0syb/hYkhR9Gd7jmKe9B6+ff31zcoryEOnEdUzPnC7EnarukMH635S2tWvbHiFhme+fc30IL/w VcHlz3TUNb4HpjSLPqL3OaX7g1Wh7HKXICdEsIuSjoEOnyhhK6lI/KvZyeblZXmla6LALsVujuu UzFq9E025O4zAcqDPjXLrszstT3YEpNDTKdBGRd1uylKhoqwcYZjWOQ+Q4GY0bAno2Il6dN5KcL gOi94saRUMOS7vLLo2mDKhYP9r2cCI= X-Received: by 2002:a05:600c:a06:b0:487:1108:48af with SMTP id 5b1f17b1804b1-48727d59ce3mr229984535e9.4.1774881088735; Mon, 30 Mar 2026 07:31:28 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , Warner Losh , Kyle Evans , Laurent Vivier , Pierrick Bouvier Subject: [PATCH 2/2] include/user/guest-host.h: Provide g2h etc for both abi_ptr and vaddr Date: Mon, 30 Mar 2026 15:31:23 +0100 Message-ID: <20260330143123.1685142-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260330143123.1685142-1-peter.maydell@linaro.org> References: <20260330143123.1685142-1-peter.maydell@linaro.org> 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::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.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, 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 @linaro.org) X-ZM-MESSAGEID: 1774881143754158500 Content-Type: text/plain; charset="utf-8" In commit 7804c84a ("include/user: Use vaddr in guest-host.h") we changed all the functions in guest-host.h that took or returned their guest address argument in type abi_ptr to instead use vaddr. This introduced regressions for the case of a 32-bit guest and an address above 2GB for the common situation where the address is a syscall argument stored in a variable of type 'abi_long'. With abi_ptr (which will be an unsigned 32-bit type for 32-bit guests), the address is cast to unsigned 32-bit, and then zero-extended to 64-bits in g2h_untagged_vaddr(). With the switch to vaddr (which is always a 64-bit unsigned type), the guest address will instead be sign-extended to 64 bits, which gives the wrong answer. Fix this by providing two versions of the affected functions: the standard names (g2h(), g2h_untagged(), guest_addr_valid_untagged(), guest_range_valid_untagged(), cpu_untagged_addr()) return to using the logically-correct abi_ptr type; new versions with a _vaddr() prefix use the vaddr type. accel/tcg/user-exec.c must change to use the _vaddr() versions; this is the only file that uses guest-host.h that we want to compile once. All the other uses are in linux-user and bsd-user code that inherently has to know the sizes of target-ABI types. Cc: qemu-stable@nongnu.org Fixes: 7804c84a ("include/user: Use vaddr in guest-host.h") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3333 Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- accel/tcg/user-exec.c | 26 ++++++++-------- include/user/guest-host.h | 62 +++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index f8b4a26711..d283d3cc72 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -647,7 +647,7 @@ void tb_lock_page0(tb_page_addr_t address) =20 if (prot & PAGE_WRITE) { pageflags_set_clear(start, last, 0, PAGE_WRITE); - mprotect(g2h_untagged(start), last - start + 1, + mprotect(g2h_untagged_vaddr(start), last - start + 1, prot & (PAGE_READ | PAGE_EXEC) ? PROT_READ : PROT_NONE); } } @@ -734,7 +734,7 @@ int page_unprotect(CPUState *cpu, tb_page_addr_t addres= s, uintptr_t pc) if (prot & PAGE_EXEC) { prot =3D (prot & ~PAGE_EXEC) | PAGE_READ; } - mprotect((void *)g2h_untagged(start), len, prot & PAGE_RWX); + mprotect((void *)g2h_untagged_vaddr(start), len, prot & PAGE_RWX); } mmap_unlock(); =20 @@ -763,7 +763,7 @@ static int probe_access_internal(CPUArchState *env, vad= dr addr, g_assert_not_reached(); } =20 - if (guest_addr_valid_untagged(addr)) { + if (guest_addr_valid_untagged_vaddr(addr)) { int page_flags =3D page_get_flags(addr); if (page_flags & acc_flag) { if (access_type !=3D MMU_INST_FETCH @@ -792,7 +792,7 @@ int probe_access_flags(CPUArchState *env, vaddr addr, i= nt size, =20 g_assert(-(addr | TARGET_PAGE_MASK) >=3D size); flags =3D probe_access_internal(env, addr, size, access_type, nonfault= , ra); - *phost =3D (flags & TLB_INVALID_MASK) ? NULL : g2h(env_cpu(env), addr); + *phost =3D (flags & TLB_INVALID_MASK) ? NULL : g2h_vaddr(env_cpu(env),= addr); return flags; } =20 @@ -805,13 +805,13 @@ void *probe_access(CPUArchState *env, vaddr addr, int= size, flags =3D probe_access_internal(env, addr, size, access_type, false, r= a); g_assert((flags & ~TLB_MMIO) =3D=3D 0); =20 - return size ? g2h(env_cpu(env), addr) : NULL; + return size ? g2h_vaddr(env_cpu(env), addr) : NULL; } =20 void *tlb_vaddr_to_host(CPUArchState *env, vaddr addr, MMUAccessType access_type, int mmu_idx) { - return g2h(env_cpu(env), addr); + return g2h_vaddr(env_cpu(env), addr); } =20 tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr, @@ -822,7 +822,7 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *e= nv, vaddr addr, flags =3D probe_access_internal(env, addr, 1, MMU_INST_FETCH, false, 0= ); g_assert(flags =3D=3D 0); =20 - *hostp =3D g2h_untagged(addr); + *hostp =3D g2h_untagged_vaddr(addr); return addr; } =20 @@ -938,7 +938,7 @@ static void *cpu_mmu_lookup(CPUState *cpu, vaddr addr, cpu_loop_exit_sigbus(cpu, addr, type, ra); } =20 - ret =3D g2h(cpu, addr); + ret =3D g2h_vaddr(cpu, addr); set_helper_retaddr(ra); return ret; } @@ -968,7 +968,7 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, } if (is_write) { if (flags & PAGE_WRITE) { - memcpy(g2h(cpu, addr), buf, l); + memcpy(g2h_vaddr(cpu, addr), buf, l); } else { /* Bypass the host page protection using ptrace. */ if (fd =3D=3D -1) { @@ -987,13 +987,13 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, */ tb_invalidate_phys_range(NULL, addr, addr + l - 1); written =3D pwrite(fd, buf, l, - (off_t)(uintptr_t)g2h_untagged(addr)); + (off_t)(uintptr_t)g2h_untagged_vaddr(addr= )); if (written !=3D l) { goto out_close; } } } else if (flags & PAGE_READ) { - memcpy(buf, g2h(cpu, addr), l); + memcpy(buf, g2h_vaddr(cpu, addr), l); } else { /* Bypass the host page protection using ptrace. */ if (fd =3D=3D -1) { @@ -1003,7 +1003,7 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, } } if (pread(fd, buf, l, - (off_t)(uintptr_t)g2h_untagged(addr)) !=3D l) { + (off_t)(uintptr_t)g2h_untagged_vaddr(addr)) !=3D l) { goto out_close; } } @@ -1231,7 +1231,7 @@ static void *atomic_mmu_lookup(CPUState *cpu, vaddr a= ddr, MemOpIdx oi, cpu_loop_exit_atomic(cpu, retaddr); } =20 - ret =3D g2h(cpu, addr); + ret =3D g2h_vaddr(cpu, addr); set_helper_retaddr(retaddr); return ret; } diff --git a/include/user/guest-host.h b/include/user/guest-host.h index 8f7ef75896..ef83ad8a18 100644 --- a/include/user/guest-host.h +++ b/include/user/guest-host.h @@ -29,7 +29,12 @@ extern unsigned long reserved_va; */ extern unsigned long guest_addr_max; =20 -static inline vaddr cpu_untagged_addr(CPUState *cs, vaddr x) +/* + * These functions take the guest virtual address as a vaddr, + * and are suitable for use from target-independent code. + */ + +static inline vaddr cpu_untagged_addr_vaddr(CPUState *cs, vaddr x) { const TCGCPUOps *tcg_ops =3D cs->cc->tcg_ops; if (tcg_ops->untagged_addr) { @@ -39,22 +44,22 @@ static inline vaddr cpu_untagged_addr(CPUState *cs, vad= dr x) } =20 /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -static inline void *g2h_untagged(vaddr x) +static inline void *g2h_untagged_vaddr(vaddr x) { return (void *)((uintptr_t)(x) + guest_base); } =20 -static inline void *g2h(CPUState *cs, vaddr x) +static inline void *g2h_vaddr(CPUState *cs, vaddr x) { - return g2h_untagged(cpu_untagged_addr(cs, x)); + return g2h_untagged_vaddr(cpu_untagged_addr_vaddr(cs, x)); } =20 -static inline bool guest_addr_valid_untagged(vaddr x) +static inline bool guest_addr_valid_untagged_vaddr(vaddr x) { return x <=3D guest_addr_max; } =20 -static inline bool guest_range_valid_untagged(vaddr start, vaddr len) +static inline bool guest_range_valid_untagged_vaddr(vaddr start, vaddr len) { return len - 1 <=3D guest_addr_max && start <=3D guest_addr_max - len = + 1; } @@ -73,4 +78,49 @@ static inline bool guest_range_valid_untagged(vaddr star= t, vaddr len) h2g_nocheck(x); \ }) =20 +#ifdef COMPILING_PER_TARGET + +/* + * These functions take the guest virtual address as an abi_ptr. This + * is an important difference from a vaddr for the common case where + * the address is a syscall argument in a variable of type abi_long, + * which may be smaller than the vaddr type. If you pass an address in + * an abi_long to these functions then the value will be converted to + * an unsigned type and then zero extended to give the vaddr. If you + * use the g2h_vaddr() and similar functions which take an argument of + * type vaddr, then the value will be sign-extended, giving the wrong + * answer for addresses above the 2GB mark on 32-bit guests. + * + * Providing these functions with their traditional QEMU semantics is + * less bug-prone than requiring many callsites to remember to cast + * their abi_long variable to an abi_ptr before calling. + */ + +static inline void *g2h(CPUState *cs, abi_ptr x) +{ + return g2h_vaddr(cs, x); +} + +static inline void *g2h_untagged(abi_ptr x) +{ + return g2h_untagged_vaddr(x); +} + +static inline bool guest_addr_valid_untagged(abi_ptr x) +{ + return guest_addr_valid_untagged_vaddr(x); +} + +static inline bool guest_range_valid_untagged(abi_ptr start, abi_ptr len) +{ + return guest_range_valid_untagged_vaddr(start, len); +} + +static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) +{ + return cpu_untagged_addr_vaddr(cs, x); +} + +#endif + #endif --=20 2.43.0