From patchwork Thu Feb 22 20:42:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=KXUG7fKq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglc54p5wz23d2 for ; Fri, 23 Feb 2024 07:48:53 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFum-0006vU-0v; Thu, 22 Feb 2024 15:43:32 -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 1rdFul-0006td-8R for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:31 -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 1rdFuj-0002Zb-0j for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:30 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d731314e67so460395ad.1 for ; Thu, 22 Feb 2024 12:43:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634607; x=1709239407; 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=6bGhiDlU0H1FunNKKdUnN7eps2A5T8/N/TZO0RrbQvI=; b=KXUG7fKqV+wD9Bd0gYjuGGkHLnN1Vb8hqhqy8PAQmrb0+SFXsWXecWt7RlHeSipmzq x+s+3etnKwc0po28IcZRiDZTsfTDvP4t1LRQfdRHUCzM7h1ePCSF/nXpuJGhW+BLoPfj fFe/9Zp6BrpTXRSdCdDecaJFZ0Y8CsPFioYXyRDmL/Y/km39C/isDpuPVa+bGxZcF/MY ZVjKojlOD5AXjbD5muSnvxjhdncUlyZl3++E3sQe9FHal39NxY4mZmqeVMIl5Vzk0VCg +oEOgxHIOPhZMfUnvfEJxkaV8uTG5LxKchxgCVJdnZdYaQ6WSIO5TLK36fEE/oFB3HvP DQRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634607; x=1709239407; 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=6bGhiDlU0H1FunNKKdUnN7eps2A5T8/N/TZO0RrbQvI=; b=JJ2MBV1nRrk79Te2YwIXvEiq8+wZdrdzmgkcOtQvuTUJkFZXNe+3ximSiopSVKED07 4/zJV0B68gTqboi8MWSPNvKVJwu4zr3xwZKx27iG3NOuatSdaFFCUbpApGEOC6RDVNQp WQCqexEwGU8jguX1tf86inEbArBTeeLZWxVwmAM8G8qdXdK1q5pZXYzSeHSAG9WYNjRK sy/nmTROzHcSBL0kV2IqCETshFWr23tBKX5fxwbJDH4RD18J4/xQOo/3Zb8IIgI5FFsc rPGNbcO1mXlciCRyvzTr13PW5A3ORYX15eyHPKZmfOZvf6yxBZxG1vCDQJVLvlQlG/aW Akpw== X-Gm-Message-State: AOJu0Yx76OogZTL1qkYO5szJbla2DdFQJPv/JczO05TLs/U9WOFoV/eG cuFNZscODTxjTP0NN5+4mYDPrL0ys04guJwgx1Tt1hfCn0lsRnuOArCV6xXYl8tYEKcc6sW9w+5 B X-Google-Smtp-Source: AGHT+IGV+DNcAIjYL2CRgDuAA3BrvJQe/tICE//QVX2rWx+a5IY5VlKzgBOyq+5AYqKF3vlIskqamA== X-Received: by 2002:a17:902:da8f:b0:1db:e7a4:9d4d with SMTP id j15-20020a170902da8f00b001dbe7a49d4dmr17151169plx.46.1708634607498; Thu, 22 Feb 2024 12:43:27 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 01/39] tcg/aarch64: Apple does not align __int128_t in even registers Date: Thu, 22 Feb 2024 10:42:45 -1000 Message-Id: <20240222204323.268539-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms When passing an argument with 16-byte alignment in integer registers, Apple platforms allow the argument to start in an odd-numbered xN register. The standard ABI requires it to begin in an even-numbered xN register. Cc: qemu-stable@nongnu.org Fixes: 5427a9a7604 ("tcg: Add TCG_TARGET_CALL_{RET,ARG}_I128") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2169 Signed-off-by: Richard Henderson Message-Id: <9fc0c2c7-dd57-459e-aecb-528edb74b4a7@linaro.org> Reviewed-by: Philippe Mathieu-Daudé --- tcg/aarch64/tcg-target.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h index ef5ebe91bd..85d5746e47 100644 --- a/tcg/aarch64/tcg-target.h +++ b/tcg/aarch64/tcg-target.h @@ -55,7 +55,11 @@ typedef enum { #define TCG_TARGET_CALL_STACK_OFFSET 0 #define TCG_TARGET_CALL_ARG_I32 TCG_CALL_ARG_NORMAL #define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL -#define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_EVEN +#ifdef CONFIG_DARWIN +# define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_NORMAL +#else +# define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_EVEN +#endif #define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_NORMAL #define have_lse (cpuinfo & CPUINFO_LSE) From patchwork Thu Feb 22 20:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yNhIpPPe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglVB0QZ2z23l3 for ; Fri, 23 Feb 2024 07:43:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFun-0006xS-L0; Thu, 22 Feb 2024 15:43:33 -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 1rdFum-0006vW-1R for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:32 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFuk-0002Zm-89 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:31 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dbb47852cdso580245ad.1 for ; Thu, 22 Feb 2024 12:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634609; x=1709239409; 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=riDxx/Iexj1qjgzxqR/EG3iYXorkzbFxBXBzbTLKvNo=; b=yNhIpPPe2TUFEU4hQVPE79G4RZfzCeGPK6Im71PSFrGvJ2NiQ0cKmxAvosIPrsWCKt eGTenUqYkfNHfS1Mh+6AUauwtaSbI/iwxHDW2EhOdCsGFifyKBhigGZKtReN1jEBB/3d KSUj/uVe5zi1zMJVTZl/4CvC/lVvD+wjQMgzGOTG1G3+G/zJm6zsJG/WFkwuaukX0Nhe iX2uC2XIfXilRMe8Y32EVM8h26qNs2P2hTUCCK5rpqVrTOi9h/XBShuU11XvQSJpeY1K xxehCEX6xYnqF/T7KbGu8OcjrT4em4r/qUShxPDZWFn0AfJja4MdXeN8n/EXJ2tWDb0l zL2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634609; x=1709239409; 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=riDxx/Iexj1qjgzxqR/EG3iYXorkzbFxBXBzbTLKvNo=; b=YBx3eaa+uP7bQ+jtPaNcA1aFxwPN02MhMJGyAy9MBQNrfSkdQho7KyCL9kBvFxWzqe 8StFFDVcZw7/VXW4nTVA59SIw7QPPjItHGDXRGUrYAT0gEDD2/nuAGZs1Aecak6toi/5 Nttx9/TpX0T0tPH9Ef+ht1Ba3kCOWcheh2lx5oyJy0dWZb3kkFOnU8yvPFZgk8Dde3FO tZ+TTAen4jFpkX34nMdTY5ZveWXBtr0B1HeAodO+clYXIcoogQdQWrcC5PP5UZwqEhJo 13EpvQqKn6/r+ftaCfjjQ6/67IoSkXcDBAI2ZEp+XR8cklJTwpaZ2gK4L67ojCG3vPiP SzWQ== X-Gm-Message-State: AOJu0YxnztMCOOh/IahrTE/5mLfmWdJESeXnphdpN9Rpv8cr60rqlWTo BTcbmO6uA4XMtQyqBzayPmvBuq1qezM+Qxhgc5jOVamMeOUnBsS9IJgH5xeww8didwpHS4gx4PL + X-Google-Smtp-Source: AGHT+IFTayTEfEFMciAD+6EPaRRK5cfQpJ10W5TGmNtU6UiQyNrqCn5Czg/EGKkqUMDMUg5eI2DMpg== X-Received: by 2002:a17:902:ec8b:b0:1dc:11f:d954 with SMTP id x11-20020a170902ec8b00b001dc011fd954mr13067965plg.54.1708634608825; Thu, 22 Feb 2024 12:43:28 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron Subject: [PULL 02/39] accel/tcg: Set can_do_io at at start of lookup_tb_ptr helper Date: Thu, 22 Feb 2024 10:42:46 -1000 Message-Id: <20240222204323.268539-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Maydell If a page table is in IO memory and lookup_tb_ptr probes the TLB it can result in a page table walk for the instruction fetch. If this hits IO memory and io_prepare falsely assumes it needs to do a TLB recompile. Avoid that by setting can_do_io at the start of lookup_tb_ptr. Link: https://lore.kernel.org/qemu-devel/CAFEAcA_a_AyQ=Epz3_+CheAT8Crsk9mOu894wbNW_FywamkZiw@mail.gmail.com/#t Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Signed-off-by: Jonathan Cameron Message-Id: <20240219173153.12114-2-Jonathan.Cameron@huawei.com> Signed-off-by: Richard Henderson --- accel/tcg/cpu-exec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 977576ca14..52239a441f 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -396,6 +396,14 @@ const void *HELPER(lookup_tb_ptr)(CPUArchState *env) uint64_t cs_base; uint32_t flags, cflags; + /* + * By definition we've just finished a TB, so I/O is OK. + * Avoid the possibility of calling cpu_io_recompile() if + * a page table walk triggered by tb_lookup() calling + * probe_access_internal() happens to touch an MMIO device. + * The next TB, if we chain to it, will clear the flag again. + */ + cpu->neg.can_do_io = true; cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); cflags = curr_cflags(cpu); From patchwork Thu Feb 22 20:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902957 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Yh86zrQp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglWv4mLzz23d2 for ; Fri, 23 Feb 2024 07:45:15 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFuo-0006xr-QI; Thu, 22 Feb 2024 15:43:34 -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 1rdFun-0006wq-GJ for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:33 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFul-0002bP-Ic for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:33 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d746ce7d13so727785ad.0 for ; Thu, 22 Feb 2024 12:43:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634610; x=1709239410; 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=GXv7UEq6yLB4cFzFbGG2vFz3ZhmdoWnqKW8J54cTadc=; b=Yh86zrQpkmYJsVH3YCQZl8Q2C40Xu8Lkbcr314yyzffaeLi2+CVjMemDE/CEUiFbj2 ZZclXdAJJU/vKjrgWdDrl+JJkmNrHHVZdRMa0n6JjTYgB7BXXZETK8b/01uTl+vj3OPm 4MamIxLkpxGdvVnFJNcMvcL1Ifv7cl8AFsl+TOdPJD9F6eG8dw7hUqi22mq+ynSdrUbF 9HiLtg78v8yYq0b/mw7K5k44tvYRhPyXbfIeczEa2rsjEkcW4TD7ij0R/TqY6o7/2BgX 76h1gDT7O49xuTZ7N3eSRlMio7vrCe2jirdLlAZC3JPLhJnuIJHox3KPI5Q3fk15rTiu FxJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634610; x=1709239410; 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=GXv7UEq6yLB4cFzFbGG2vFz3ZhmdoWnqKW8J54cTadc=; b=uVqVfq815DB6Nok0CmMt7B3i70aCOTnvtDrmwDSacAuDoPlE1QVG2qZsxFsvbdiE/N C9qOMEdk11TQXLnLlaUohHCDsP9MaafAyL/sbL1UbHwGIIgcz42/ZfXEUzgS73TYZlqS facbTMAkTOzp4hG014f+am1wEJ/qYsfA/dZBFEC+KSlXEa6mNIKqG+wYTLrj/ooqpR9L ZSG/woA2ASMVz3JCH5b8l8vLodXho+MiUiQi2IXzrcOH9+/fHTSwr2Yf5knvMroSumwg c2brguX3eGizfju3QuVcZjzsxQ0yGE8vmlbOVDzoxftDDm+D7p9OePvIXPn5P8FumkXQ HnYw== X-Gm-Message-State: AOJu0YzHvUrrYKapWUSBVB1Xg04kaFyadZkGq+veO8GNYHPiDDowytN9 h2lYMWytlCmvICenx3i6P+n2lRrcpXkz1BRnkwNyQxj+bFD0VY34vnQD2glK2v7ZI3FXodI2KVJ O X-Google-Smtp-Source: AGHT+IFtKHsfHsx52VPzd8sZOp3GZYtHSklvfPeR1BaHUwpnwVmmvLyeN1YId6aTeoleBa87s6lHiw== X-Received: by 2002:a17:902:c084:b0:1dc:7bc:3527 with SMTP id j4-20020a170902c08400b001dc07bc3527mr10953735pld.19.1708634610185; Thu, 22 Feb 2024 12:43:30 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Jonathan Cameron , Peter Maydell Subject: [PULL 03/39] tcg: Avoid double lock if page tables happen to be in mmio memory. Date: Thu, 22 Feb 2024 10:42:47 -1000 Message-Id: <20240222204323.268539-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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, T_SCC_BODY_TEXT_LINE=-0.01, WEIRD_PORT=0.001 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jonathan Cameron On i386, after fixing the page walking code to work with pages in MMIO memory (specifically CXL emulated interleaved memory), a crash was seen in an interrupt handling path. Useful part of backtrace 7 0x0000555555ab1929 in bql_lock_impl (file=0x555556049122 "../../accel/tcg/cputlb.c", line=2033) at ../../system/cpus.c:524 8 bql_lock_impl (file=file@entry=0x555556049122 "../../accel/tcg/cputlb.c", line=line@entry=2033) at ../../system/cpus.c:520 9 0x0000555555c9f7d6 in do_ld_mmio_beN (cpu=0x5555578e0cb0, full=0x7ffe88012950, ret_be=ret_be@entry=0, addr=19595792376, size=size@entry=8, mmu_idx=4, type=MMU_DATA_LOAD, ra=0) at ../../accel/tcg/cputlb.c:2033 10 0x0000555555ca0fbd in do_ld_8 (cpu=cpu@entry=0x5555578e0cb0, p=p@entry=0x7ffff4efd1d0, mmu_idx=, type=type@entry=MMU_DATA_LOAD, memop=, ra=ra@entry=0) at ../../accel/tcg/cputlb.c:2356 11 0x0000555555ca341f in do_ld8_mmu (cpu=cpu@entry=0x5555578e0cb0, addr=addr@entry=19595792376, oi=oi@entry=52, ra=0, ra@entry=52, access_type=access_type@entry=MMU_DATA_LOAD) at ../../accel/tcg/cputlb.c:2439 12 0x0000555555ca5f59 in cpu_ldq_mmu (ra=52, oi=52, addr=19595792376, env=0x5555578e3470) at ../../accel/tcg/ldst_common.c.inc:169 13 cpu_ldq_le_mmuidx_ra (env=0x5555578e3470, addr=19595792376, mmu_idx=, ra=ra@entry=0) at ../../accel/tcg/ldst_common.c.inc:301 14 0x0000555555b4b5fc in ptw_ldq (ra=0, in=0x7ffff4efd320) at ../../target/i386/tcg/sysemu/excp_helper.c:98 15 ptw_ldq (ra=0, in=0x7ffff4efd320) at ../../target/i386/tcg/sysemu/excp_helper.c:93 16 mmu_translate (env=env@entry=0x5555578e3470, in=0x7ffff4efd3e0, out=0x7ffff4efd3b0, err=err@entry=0x7ffff4efd3c0, ra=ra@entry=0) at ../../target/i386/tcg/sysemu/excp_helper.c:174 17 0x0000555555b4c4b3 in get_physical_address (ra=0, err=0x7ffff4efd3c0, out=0x7ffff4efd3b0, mmu_idx=0, access_type=MMU_DATA_LOAD, addr=18446741874686299840, env=0x5555578e3470) at ../../target/i386/tcg/sysemu/excp_helper.c:580 18 x86_cpu_tlb_fill (cs=0x5555578e0cb0, addr=18446741874686299840, size=, access_type=MMU_DATA_LOAD, mmu_idx=0, probe=, retaddr=0) at ../../target/i386/tcg/sysemu/excp_helper.c:606 19 0x0000555555ca0ee9 in tlb_fill (retaddr=0, mmu_idx=0, access_type=MMU_DATA_LOAD, size=, addr=18446741874686299840, cpu=0x7ffff4efd540) at ../../accel/tcg/cputlb.c:1315 20 mmu_lookup1 (cpu=cpu@entry=0x5555578e0cb0, data=data@entry=0x7ffff4efd540, mmu_idx=0, access_type=access_type@entry=MMU_DATA_LOAD, ra=ra@entry=0) at ../../accel/tcg/cputlb.c:1713 21 0x0000555555ca2c61 in mmu_lookup (cpu=cpu@entry=0x5555578e0cb0, addr=addr@entry=18446741874686299840, oi=oi@entry=32, ra=ra@entry=0, type=type@entry=MMU_DATA_LOAD, l=l@entry=0x7ffff4efd540) at ../../accel/tcg/cputlb.c:1803 22 0x0000555555ca3165 in do_ld4_mmu (cpu=cpu@entry=0x5555578e0cb0, addr=addr@entry=18446741874686299840, oi=oi@entry=32, ra=ra@entry=0, access_type=access_type@entry=MMU_DATA_LOAD) at ../../accel/tcg/cputlb.c:2416 23 0x0000555555ca5ef9 in cpu_ldl_mmu (ra=0, oi=32, addr=18446741874686299840, env=0x5555578e3470) at ../../accel/tcg/ldst_common.c.inc:158 24 cpu_ldl_le_mmuidx_ra (env=env@entry=0x5555578e3470, addr=addr@entry=18446741874686299840, mmu_idx=, ra=ra@entry=0) at ../../accel/tcg/ldst_common.c.inc:294 25 0x0000555555bb6cdd in do_interrupt64 (is_hw=1, next_eip=18446744072399775809, error_code=0, is_int=0, intno=236, env=0x5555578e3470) at ../../target/i386/tcg/seg_helper.c:889 26 do_interrupt_all (cpu=cpu@entry=0x5555578e0cb0, intno=236, is_int=is_int@entry=0, error_code=error_code@entry=0, next_eip=next_eip@entry=0, is_hw=is_hw@entry=1) at ../../target/i386/tcg/seg_helper.c:1130 27 0x0000555555bb87da in do_interrupt_x86_hardirq (env=env@entry=0x5555578e3470, intno=, is_hw=is_hw@entry=1) at ../../target/i386/tcg/seg_helper.c:1162 28 0x0000555555b5039c in x86_cpu_exec_interrupt (cs=0x5555578e0cb0, interrupt_request=) at ../../target/i386/tcg/sysemu/seg_helper.c:197 29 0x0000555555c94480 in cpu_handle_interrupt (last_tb=, cpu=0x5555578e0cb0) at ../../accel/tcg/cpu-exec.c:844 Peter identified this as being due to the BQL already being held when the page table walker encounters MMIO memory and attempts to take the lock again. There are other examples of similar paths TCG, so this follows the approach taken in those of simply checking if the lock is already held and if it is, don't take it again. Reviewed-by: Peter Maydell Suggested-by: Peter Maydell Signed-off-by: Jonathan Cameron Message-Id: <20240219173153.12114-4-Jonathan.Cameron@huawei.com> [rth: Use BQL_LOCK_GUARD] Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 047cd2cc0a..6243bcb179 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2022,7 +2022,6 @@ static uint64_t do_ld_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full, MemoryRegion *mr; hwaddr mr_offset; MemTxAttrs attrs; - uint64_t ret; tcg_debug_assert(size > 0 && size <= 8); @@ -2030,12 +2029,9 @@ static uint64_t do_ld_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full, section = io_prepare(&mr_offset, cpu, full->xlat_section, attrs, addr, ra); mr = section->mr; - bql_lock(); - ret = int_ld_mmio_beN(cpu, full, ret_be, addr, size, mmu_idx, - type, ra, mr, mr_offset); - bql_unlock(); - - return ret; + BQL_LOCK_GUARD(); + return int_ld_mmio_beN(cpu, full, ret_be, addr, size, mmu_idx, + type, ra, mr, mr_offset); } static Int128 do_ld16_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full, @@ -2054,13 +2050,11 @@ static Int128 do_ld16_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full, section = io_prepare(&mr_offset, cpu, full->xlat_section, attrs, addr, ra); mr = section->mr; - bql_lock(); + BQL_LOCK_GUARD(); a = int_ld_mmio_beN(cpu, full, ret_be, addr, size - 8, mmu_idx, MMU_DATA_LOAD, ra, mr, mr_offset); b = int_ld_mmio_beN(cpu, full, ret_be, addr + size - 8, 8, mmu_idx, MMU_DATA_LOAD, ra, mr, mr_offset + size - 8); - bql_unlock(); - return int128_make128(b, a); } @@ -2569,7 +2563,6 @@ static uint64_t do_st_mmio_leN(CPUState *cpu, CPUTLBEntryFull *full, hwaddr mr_offset; MemoryRegion *mr; MemTxAttrs attrs; - uint64_t ret; tcg_debug_assert(size > 0 && size <= 8); @@ -2577,12 +2570,9 @@ static uint64_t do_st_mmio_leN(CPUState *cpu, CPUTLBEntryFull *full, section = io_prepare(&mr_offset, cpu, full->xlat_section, attrs, addr, ra); mr = section->mr; - bql_lock(); - ret = int_st_mmio_leN(cpu, full, val_le, addr, size, mmu_idx, - ra, mr, mr_offset); - bql_unlock(); - - return ret; + BQL_LOCK_GUARD(); + return int_st_mmio_leN(cpu, full, val_le, addr, size, mmu_idx, + ra, mr, mr_offset); } static uint64_t do_st16_mmio_leN(CPUState *cpu, CPUTLBEntryFull *full, @@ -2593,7 +2583,6 @@ static uint64_t do_st16_mmio_leN(CPUState *cpu, CPUTLBEntryFull *full, MemoryRegion *mr; hwaddr mr_offset; MemTxAttrs attrs; - uint64_t ret; tcg_debug_assert(size > 8 && size <= 16); @@ -2601,14 +2590,11 @@ static uint64_t do_st16_mmio_leN(CPUState *cpu, CPUTLBEntryFull *full, section = io_prepare(&mr_offset, cpu, full->xlat_section, attrs, addr, ra); mr = section->mr; - bql_lock(); + BQL_LOCK_GUARD(); int_st_mmio_leN(cpu, full, int128_getlo(val_le), addr, 8, mmu_idx, ra, mr, mr_offset); - ret = int_st_mmio_leN(cpu, full, int128_gethi(val_le), addr + 8, - size - 8, mmu_idx, ra, mr, mr_offset + 8); - bql_unlock(); - - return ret; + return int_st_mmio_leN(cpu, full, int128_gethi(val_le), addr + 8, + size - 8, mmu_idx, ra, mr, mr_offset + 8); } /* From patchwork Thu Feb 22 20:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=SwfpMlbC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYj4rvWz23d2 for ; Fri, 23 Feb 2024 07:46:49 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFuq-0006yD-8p; Thu, 22 Feb 2024 15:43:36 -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 1rdFuo-0006xs-QX for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:34 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFun-0002bl-73 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:34 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d934c8f8f7so520585ad.2 for ; Thu, 22 Feb 2024 12:43:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634612; x=1709239412; 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=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; b=SwfpMlbChj9GimvK00b40lmzlQeHldHj7r499f+741B7BIeowbyP6D6si+/My+1Cfx RmKgqCK/QVkLZ8u5CftMrA4vjSdzIcwXVcRC5lTlBIedSiXBJ8PRiPdsLk2ouekQATc4 Z4lYMeKg/Xkwfq0mQOsDeG2YdondWjStf8SOu7/g0j6sD0QfZoM1aSYk27hf4GA0s6dV QGsZQT8FFMGS4hCwNbzgqEPlV5h+2NfSMqL2rcOwZWgzfbYIbLhW7JPnP9v3eGU2UgZ8 ceZ65KvMKlFg5Bj7NbWD+WZhbvJmAuRp36BZb8yrpg0I8nC3LY3ZzbCTcHuHOPILL4mh tzjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634612; x=1709239412; 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=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; b=j3CUbG4GqH3NVvoMfNouqz9Vo43wvUtvudhEIS0J+YdYJnS/LL5Z0Pi3OmsGinynSo vFf65Wt9Q0uTcwbw6qhEPD9xWq5n062VbS6LcAbnOK+gUQmn2NhstvVy/Nbxasi+3XPK w7WNVaSqFAHWUxG81m7yHjgTdtG6nnyCWDbc/t3+IIbEGjieMNrusfpv7wSh4Op1Skxq FS9Sgn8dbcxNpfH4A0mJOXRypxY2xfJ2JkjMQD2mXB4M8di+eXQ//8jQ1G/VYM5gr0gX T4fOL41InaF26ig/tavrhdxJPq9zcrJJ4Hh0OponFfvEtPzE0lfwPw0YtZ+IK/Kq9A0N 9sgA== X-Gm-Message-State: AOJu0YzXh9BAHPcjI5wpiIbgv+RvguIzyLdEc5h/g2jY69aet3C7mSO2 uu+NTVL4C7EpDubDPQorv20yqe8yiVjssq53YbpmHJooWdPNe6p9qSzpn4Cxdcv/R2GmC+xjiOH V X-Google-Smtp-Source: AGHT+IHslhyFBJCm6uPiyIGzPEI7Rf8m5cp/0bXtqZF8LH667ETcoPoyOEUE3pdQwWYdYkjOOSZzsQ== X-Received: by 2002:a17:902:6ac8:b0:1d9:f83e:3a54 with SMTP id i8-20020a1709026ac800b001d9f83e3a54mr17359368plt.64.1708634611972; Thu, 22 Feb 2024 12:43:31 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 04/39] accel/tcg: Remove qemu_host_page_size from page_protect/page_unprotect Date: Thu, 22 Feb 2024 10:42:48 -1000 Message-Id: <20240222204323.268539-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size instead. Except for the final mprotect within page_protect, we already handled host < target page size. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-2-richard.henderson@linaro.org> --- accel/tcg/user-exec.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 68b252cb8e..69b7429e31 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -651,16 +651,17 @@ void page_protect(tb_page_addr_t address) { PageFlagsNode *p; target_ulong start, last; + int host_page_size = qemu_real_host_page_size(); int prot; assert_memory_lock(); - if (qemu_host_page_size <= TARGET_PAGE_SIZE) { + if (host_page_size <= TARGET_PAGE_SIZE) { start = address & TARGET_PAGE_MASK; last = start + TARGET_PAGE_SIZE - 1; } else { - start = address & qemu_host_page_mask; - last = start + qemu_host_page_size - 1; + start = address & -host_page_size; + last = start + host_page_size - 1; } p = pageflags_find(start, last); @@ -671,7 +672,7 @@ void page_protect(tb_page_addr_t address) if (unlikely(p->itree.last < last)) { /* More than one protection region covers the one host page. */ - assert(TARGET_PAGE_SIZE < qemu_host_page_size); + assert(TARGET_PAGE_SIZE < host_page_size); while ((p = pageflags_next(p, start, last)) != NULL) { prot |= p->flags; } @@ -679,7 +680,7 @@ void page_protect(tb_page_addr_t address) if (prot & PAGE_WRITE) { pageflags_set_clear(start, last, 0, PAGE_WRITE); - mprotect(g2h_untagged(start), qemu_host_page_size, + mprotect(g2h_untagged(start), last - start + 1, prot & (PAGE_READ | PAGE_EXEC) ? PROT_READ : PROT_NONE); } } @@ -725,18 +726,19 @@ int page_unprotect(target_ulong address, uintptr_t pc) } #endif } else { + int host_page_size = qemu_real_host_page_size(); target_ulong start, len, i; int prot; - if (qemu_host_page_size <= TARGET_PAGE_SIZE) { + if (host_page_size <= TARGET_PAGE_SIZE) { start = address & TARGET_PAGE_MASK; len = TARGET_PAGE_SIZE; prot = p->flags | PAGE_WRITE; pageflags_set_clear(start, start + len - 1, PAGE_WRITE, 0); current_tb_invalidated = tb_invalidate_phys_page_unwind(start, pc); } else { - start = address & qemu_host_page_mask; - len = qemu_host_page_size; + start = address & -host_page_size; + len = host_page_size; prot = 0; for (i = 0; i < len; i += TARGET_PAGE_SIZE) { From patchwork Thu Feb 22 20:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=PfLkPevn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglVk4LPwz23l3 for ; Fri, 23 Feb 2024 07:44:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFus-0006z1-Kj; Thu, 22 Feb 2024 15:43:38 -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 1rdFuq-0006yM-Kr for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:36 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFup-0002by-3n for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:36 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d7232dcb3eso353865ad.2 for ; Thu, 22 Feb 2024 12:43:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634614; x=1709239414; 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=sNAOuzYKunseGhjt30zEM/eN7uq1Wl50v8pWc8K9LWs=; b=PfLkPevn825ugMpAo702PT0p+t/DiRPWWi5tRdvAsEwz8Kyr2X1SfG7nG9Mr3zGzzR ksxL2VORDPbAq4d4gt5uM/on0aGA0V2hSNKzRrVBzTaR5ZGS+8mVfY4qAFT4LIripzZT 3+td0U6EcgGp9US50orQeQcRJrahbgUF+E5R3yzBSVdXRRTD3O/qJDCDJWAIlw5RXawZ Xc3Pcl9gXRTNGTKUw19mjOxQLMoIsayFmpEOoRF+a6ZLIbkpSM26prwHKlcB9d87YdKd eK5qCT41wcPCS85J5XFgPoybMgBOgYXL3IH49l9BUMyw/7dZ1fJ4Xr51wJBPdexM+MG1 kiNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634614; x=1709239414; 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=sNAOuzYKunseGhjt30zEM/eN7uq1Wl50v8pWc8K9LWs=; b=kp6eBu23YiEqk/wrZ9kZuC6gxDbC70/Fc7TNv1Hh7eKoZjtx4urq7hV94OcLDUl+VP Ed9PBq8VXvb/4s//gaMSoEFyBteuuD1Y6fJoKf/mC0MBZOmOtv7P+QBY7hHC85iznTe6 ycxy+y8szdI5rod11MRExtv7SSNxcUh2QlskouUgkSG1K3vtBx9ji7XtX6I9CMG/Hg0g wpGSUpNUW2IYoz/KODqukVJ5oLY0JAi4tRmKPb4HpbWcKejbJJANabSc7mX/V1MZPQjg 0imgJBOxwD0doWQdxi2qJbY2mhlSMdXUN0IB0t2QwGQz3qK568HluiW8836muIbRTRZn gW0A== X-Gm-Message-State: AOJu0YyFoVoj9THP83ZTYj/iseqGIV+K1tAZwlD2/svCqPqUwOF0MH6B SWCm91py0O7AeExUdQoyAlErWaZ7gpHY28IYRvC8gf7IO9bldkkZrCJ0jmQPrd0WFFEoTlE7KQP R X-Google-Smtp-Source: AGHT+IF5q5UPALYgHWNKN4dHd3H6eNGItd9ca+N9As9VGDOe/3/wGV0sI09yoZ0wEYWIaBD1vQm1Tg== X-Received: by 2002:a17:902:7d84:b0:1d9:7095:7e3c with SMTP id a4-20020a1709027d8400b001d970957e3cmr19202644plm.57.1708634613748; Thu, 22 Feb 2024 12:43:33 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 05/39] linux-user: Adjust SVr4 NULL page mapping Date: Thu, 22 Feb 2024 10:42:49 -1000 Message-Id: <20240222204323.268539-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use TARGET_PAGE_SIZE and MAP_FIXED_NOREPLACE. We really should be attending to this earlier during probe_guest_base, as well as better detection and emulation of various Linux personalities. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-3-richard.henderson@linaro.org> --- linux-user/elfload.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b8eef893d0..e918a13748 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3912,8 +3912,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) and some applications "depend" upon this behavior. Since we do not have the power to recompile these, we emulate the SVr4 behavior. Sigh. */ - target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC, + MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); } #ifdef TARGET_MIPS info->interp_fp_abi = interp_info.fp_abi; From patchwork Thu Feb 22 20:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=anpyhmLp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglXL4wZkz23d2 for ; Fri, 23 Feb 2024 07:45:38 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFuv-000700-LB; Thu, 22 Feb 2024 15:43:41 -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 1rdFut-0006z5-8Z for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:39 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFur-0002c9-NW for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:39 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d73066880eso2070575ad.3 for ; Thu, 22 Feb 2024 12:43:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634615; x=1709239415; 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=4czMnwy4ONozXZRRucTuxGhHSF3+8ljKdOePhx3D1do=; b=anpyhmLpTbAXrCgl01JfOe98PpXZ6jVSSm19PoQ+fTrjYHyqLNTFNuWjBcZt2GpZTz lueict9CA5G0Go9AkP+u2i4GSpwSfW4uWCn9vzkX2TO+Az8wg4YWbNneg9q04a8HfBVi q0qOxfU7Szs+UUWgySNCE5aFye/1ADTSFhOBNU69AvLAojCpORpIrSVZ8H92373l1U8K vO6csWLOXXEes+uIJPUZI+G35elCYi/1sVTOVLaxfY86Yj9NcSEuZ9/ZUwe/4W030X0S b10u71flj/uKef38ZHFptHdvoVYne3oPAMttM100AReLo2tV+x9FCN7yEILwLWaOjQn6 jL/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634615; x=1709239415; 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=4czMnwy4ONozXZRRucTuxGhHSF3+8ljKdOePhx3D1do=; b=jHza5xslqljIYQtJzEs1x8Jha+4/yt1RkIvOrWEF2cScrvdlPWYL3VdjD6N+1QHomn 5SXpPzNw/RwdrFJx+B8D73i/HFEb1BFyJm3XTbXiQZdVF1krDC6IJZxCNvOMfxAWrHdS 9hVgZwmCMl6KskP+xZyDhxVEVmJr+trT5Vu9DSqDXbW6aZndqkmY+E5LaemJGv4K1JnO +eDYoa9Tb8Di8/PhvtpCCW7UrS6UhM25+jr1u+DrnnWboG7VVGaIOKCYk8tzSYYy2meF BuDbCnDzCGQ43OlgQOdJ9sVDGON7CxP6aLX2bdZI111QdT9Cbws/0QxGazbBEGjBIMJL QHog== X-Gm-Message-State: AOJu0YzWi00xYrvwYt086PBCq4wuP86IW5+pD1PXHwqstKPJ0GberX0A Dfz80Lb6SZpWFQoAmgWhbIKpWKismj2Rlp9SQyLGEdm6xvx9AJ4EX0UygBd6mwMGljq6t0Xo7RA + X-Google-Smtp-Source: AGHT+IH6fkUsuO7V5W/elbU7FrcWJw9+jn/TcS2Q+OEznwW02JUaE73O465WG9Zn5HBaRLp6rXW1bQ== X-Received: by 2002:a17:902:f68c:b0:1db:e9ea:31 with SMTP id l12-20020a170902f68c00b001dbe9ea0031mr15479254plg.62.1708634615327; Thu, 22 Feb 2024 12:43:35 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 06/39] linux-user: Remove qemu_host_page_{size, mask} in probe_guest_base Date: Thu, 22 Feb 2024 10:42:50 -1000 Message-Id: <20240222204323.268539-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The host SHMLBA is by definition a multiple of the host page size. Thus the remaining component of qemu_host_page_size is the target page size. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-4-richard.henderson@linaro.org> --- linux-user/elfload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e918a13748..e84a201448 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2893,7 +2893,7 @@ static bool pgb_addr_set(PGBAddrs *ga, abi_ulong guest_loaddr, /* Add any HI_COMMPAGE not covered by reserved_va. */ if (reserved_va < HI_COMMPAGE) { - ga->bounds[n][0] = HI_COMMPAGE & qemu_host_page_mask; + ga->bounds[n][0] = HI_COMMPAGE & qemu_real_host_page_mask(); ga->bounds[n][1] = HI_COMMPAGE + TARGET_PAGE_SIZE - 1; n++; } @@ -3075,7 +3075,7 @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, abi_ulong guest_hiaddr) { /* In order to use host shmat, we must be able to honor SHMLBA. */ - uintptr_t align = MAX(SHMLBA, qemu_host_page_size); + uintptr_t align = MAX(SHMLBA, TARGET_PAGE_SIZE); /* Sanity check the guest binary. */ if (reserved_va) { From patchwork Thu Feb 22 20:42:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=aPLPVX+N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglWD2htZz23l3 for ; Fri, 23 Feb 2024 07:44:40 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFux-00070K-G6; Thu, 22 Feb 2024 15:43:43 -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 1rdFuu-0006zU-4m for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:40 -0500 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFus-0002cL-J6 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:39 -0500 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5dc20645871so143271a12.1 for ; Thu, 22 Feb 2024 12:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634617; x=1709239417; 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=Bhq/S13VfihOVnnYi8cdcfrHcq4G1EwJdAWP437jNUw=; b=aPLPVX+N+7Whu647T+22YnYcLbBdXxwug5fBZiGehhqN5DuNOjRK+MyvykEdy2PV9Y dYWiv1JhnRSnSC/OWfYL/uyDDaIDfVJ9psY32YAr+amyXyOk82qORTgOD3LI6l6s8pDa p9cCI1MY/3J3zQ9KRdI0upMjbIr2uX7gIYfCj8FduObfqxXZxi6dWsa58cvtVnj5pKRT KetRwCj0MmVfTywSc0fI/QbzPI/k4nYqAYLAa9GbV48ZAUfRBxINgXvhwTofaTxXlZeq e74Deu8r2mtweCyEtZ99IhjAjjUAs8ic6cEcHMKCzAOU+UcOr0QmOU5NYiHOSn47mQfz i7kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634617; x=1709239417; 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=Bhq/S13VfihOVnnYi8cdcfrHcq4G1EwJdAWP437jNUw=; b=PKH7l34bl7+siozkVQy2vJkDXoXc2GJ3uG1L40jN58VzFo6JwepYOnSwhdLreO0tSA qN7ieEUcIjKNNJ8A96jxxFWvcdEx/RgqTfhmZVG6DetZDWmi58pQL8lQCg5R3hdnBz+y BxW2UaJgduWgmoiDUaqi3/3a96TUnmCJPuNxGzqIuIcWWg49L1kCidjqP28XAuM+C86N annuS8WecZqj8YqPLLO76Pv2haW47NO5ACKM91bC61ExRW0w9C1PBpBtVE5JdqegDZ2x htkml6o+vYgeaeFRHC52Z900fbduIcrtXgTq6DLx7i6vj/4F4LWj+7qN7w/zBdUUkitQ r2OA== X-Gm-Message-State: AOJu0Yxqh6W6aLK6ORe18+32v01TBrBIeKTzzmVUH5QYS6/a0oGf7/Op zHUvFlzt2rwWl9lzBLIGqbU3H/kZxyWi51debBlBwvyA0jajLPvJsMMpEkMqqkN6VATAf5ogqvj B X-Google-Smtp-Source: AGHT+IEjNSpaWRAUWmDhTwQS+MrN9qDrAUGuGYUCtX+eV8vSgKmG1IFuf1p4BYJbRNu7AJuYQVjxCQ== X-Received: by 2002:a17:903:1cd:b0:1db:beac:61af with SMTP id e13-20020a17090301cd00b001dbbeac61afmr270755plh.0.1708634617006; Thu, 22 Feb 2024 12:43:37 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 07/39] linux-user: Remove qemu_host_page_size from create_elf_tables Date: Thu, 22 Feb 2024 10:42:51 -1000 Message-Id: <20240222204323.268539-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org AT_PAGESZ is supposed to advertise the guest page size. The random adjustment made here using qemu_host_page_size does not match anything else within linux-user. The idea here is good, but should be done more systemically via adjustment to TARGET_PAGE_SIZE. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-5-richard.henderson@linaro.org> --- linux-user/elfload.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e84a201448..dfb152bfcb 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2679,13 +2679,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff)); NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr))); NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); - if ((info->alignment & ~qemu_host_page_mask) != 0) { - /* Target doesn't support host page size alignment */ - NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); - } else { - NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE, - qemu_host_page_size))); - } + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0)); NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); NEW_AUX_ENT(AT_ENTRY, info->entry); From patchwork Thu Feb 22 20:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=IXY3FNMl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYp3mMFz23d2 for ; Fri, 23 Feb 2024 07:46:54 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFuy-00070n-96; Thu, 22 Feb 2024 15:43:44 -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 1rdFuv-0006zp-9Q for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:41 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFut-0002cS-Mc for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:41 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d934c8f8f7so521735ad.2 for ; Thu, 22 Feb 2024 12:43:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634618; x=1709239418; 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=emMi1h1Qw5IeyN9nGFR+tElZTiLuS0cNV7Vg5JxneO0=; b=IXY3FNMlf5tD4tkHfrXxIkdWE84Lo257kMH4kL6eu1Xzbg93yqpbHxEv+x2pZYniSG iQY72bxqvGHmHh0j7i7kssPboxK47hZvHPYzAFutWAND8rrayWvLw26pUittbhFTG4cj Av7eKNujTyijnIeLBO63/oUWgtdOzyy1QGGemrXiidss+HYwFWOkTldu5mthHYusczVf 5axnJ1MF68461ZTTtg6f2+RjqwP4QxeiQJYonU95rHMYu5I94CvBfp9GA9D/Z5OmL0TJ hbMetGxTF/9B+aY0wDctjA2Pm6YnP5kkrFNNuJNA1qbNxZSaonerJC4eT54fCnKtLN9Z G8xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634618; x=1709239418; 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=emMi1h1Qw5IeyN9nGFR+tElZTiLuS0cNV7Vg5JxneO0=; b=fkdC63Zv6dxMqatm/tX6AI21Kxo3bFaYDIu/d82jX2j0K5iL3iceNMAdWNja2av8cY 0fPM7IsOEIOxRNs04ChoE1p44wX8io9CrZx5stKhmjCQNkKwpXff8kYrJM0/vLuPyEga IF8k/IGZEP3KhDnnGzQ3bWbD7Dif6/Ug0tEj2/RmNtZHagzcJX0L4D2oLWJa3m8Bnd0Z RNjTCASMz4Ikzob8SL/18PeBbVLYKbJX1gTw7BqVfPSEgC7g4UreNuELc0VpqWER0NI6 3Z3tL6khgbHpXif0IOOY6EPhUxxYV8yMpDqxX1+leU1AqveqBVdBvTqgjkz0sHbEhm1S 3VoQ== X-Gm-Message-State: AOJu0YxDPTbB62X4AVBarLPEN2HT03uZq3vA6PetobeVBn27n6xvx2lh udaJNI83guTSR4RM42EP3S3gXR1z2WqQ22vhP2H5W/AMdH4JrLMsV3AW8tG4kPZ2lJqBBXJA8xL S X-Google-Smtp-Source: AGHT+IHvM5bA684xWryyQ9GmZRMcHOL0zYp3ZGA35yzyBMWSzV8xKSyFi1lYd5I9fojNeQ9R+yXyZg== X-Received: by 2002:a17:903:1c6:b0:1db:d7a8:850b with SMTP id e6-20020a17090301c600b001dbd7a8850bmr16589191plh.25.1708634618559; Thu, 22 Feb 2024 12:43:38 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 08/39] linux-user/hppa: Simplify init_guest_commpage Date: Thu, 22 Feb 2024 10:42:52 -1000 Message-Id: <20240222204323.268539-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If reserved_va, then we have already reserved the entire guest virtual address space; no need to remap page. If !reserved_va, then use MAP_FIXED_NOREPLACE. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-6-richard.henderson@linaro.org> --- linux-user/elfload.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index dfb152bfcb..1893b3c192 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1970,16 +1970,20 @@ static inline void init_thread(struct target_pt_regs *regs, static bool init_guest_commpage(void) { - void *want = g2h_untagged(LO_COMMPAGE); - void *addr = mmap(want, qemu_host_page_size, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + /* If reserved_va, then we have already mapped 0 page on the host. */ + if (!reserved_va) { + void *want, *addr; - if (addr == MAP_FAILED) { - perror("Allocating guest commpage"); - exit(EXIT_FAILURE); - } - if (addr != want) { - return false; + want = g2h_untagged(LO_COMMPAGE); + addr = mmap(want, TARGET_PAGE_SIZE, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0); + if (addr == MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); + } + if (addr != want) { + return false; + } } /* From patchwork Thu Feb 22 20:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=VsdgqmSn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglW937Rzz23l3 for ; Fri, 23 Feb 2024 07:44:37 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv1-00075S-T4; Thu, 22 Feb 2024 15:43:47 -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 1rdFux-00070f-P8 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:44 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFuv-0002cm-4b for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:42 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dc13fb0133so400895ad.3 for ; Thu, 22 Feb 2024 12:43:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634620; x=1709239420; 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=on46I2b8riCprdxQ1GrqNDsO17YyckywkPgL9RszReM=; b=VsdgqmSn3KN7WNHhYg2ADbbWpZJ5QJzlpqs7sfR5UM3qZs/EyhvCXQXmt0BSu0oDoZ +0+t2nQyP3XSBX+Xh652ycNLFFoUuK/DTOjRMZyoCgAEI7i2yzQ6ZaO8E4odky4kU08a IZr43tmNNwSrYBIWQKtyLigYMoHSICKvzkQyG12AoF3wTTTCO7dorh4tjQml2RxiT2By HpV5Ws3334Ig+53Q6LH1U+BKWdaH0u53WQoUjk589Yn4rVwFxlCuYplQ1CwjP0ZPjQwR /zqLCNCH/wP2JaAJMrT2o02jZMmYuAUSG0TtkJCHDCcpXQzExj2hqDcVUz/ZQOpxBZIN M4UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634620; x=1709239420; 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=on46I2b8riCprdxQ1GrqNDsO17YyckywkPgL9RszReM=; b=w4HNIt8j12czhnS7NIZ8447ZmaEijK73armHAK59iW4DrGgG8bJzJC22Kq/ZdDPt5Z 9o+j+EXO7V3BGzyrvQfszTjNGUBjrzmBOr2OGcAOPHQ44KuymvhHNWD8EWOPEvng3pfz MvKet0Rsy41gwIUGm9kTDOdmIxFrEby2lerZypl5GMDAVR6CTt41TYLnq5g/LghMH/G9 tlfO101DA4h1kWBqEVxrNQUs4EKaIO2bIuVB3LveHancwTs/NJ3ycYud1aF2zkatc3Aa L5/1O9VyA84+Dj4Wt+OTADVKn8toTGL+lyhyhj1Glm0gTl9xjr9r5YyLoqQyi46qsKNp E3gw== X-Gm-Message-State: AOJu0YxbhpO7/mjGwOJHsq8Wew1GA6/l05KxrkLPHsBZ4skfcXNFHvHc FD3OJzD54EjbezjH4gnjeY/oY9U+Mh2vxSFPl+JFmQrvj+wVUKvdvYfmIYbQV1s02i7KVkgJzVs J X-Google-Smtp-Source: AGHT+IGFSz5KPcJYr2c4+rE8XHTN5WltgBYqhZTzmSsYXJRi2R6o+nCFd5HmCdadzd0RMNyVtlNFsw== X-Received: by 2002:a17:902:e551:b0:1db:be69:d037 with SMTP id n17-20020a170902e55100b001dbbe69d037mr22021957plf.46.1708634619854; Thu, 22 Feb 2024 12:43:39 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 09/39] linux-user/nios2: Remove qemu_host_page_size from init_guest_commpage Date: Thu, 22 Feb 2024 10:42:53 -1000 Message-Id: <20240222204323.268539-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size. If !reserved_va, use MAP_FIXED_NOREPLACE. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-7-richard.henderson@linaro.org> --- linux-user/elfload.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 1893b3c192..a9f1077861 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1532,10 +1532,14 @@ static bool init_guest_commpage(void) 0x3a, 0x68, 0x3b, 0x00, /* trap 0 */ }; - void *want = g2h_untagged(LO_COMMPAGE & -qemu_host_page_size); - void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + int host_page_size = qemu_real_host_page_size(); + void *want, *addr; + want = g2h_untagged(LO_COMMPAGE & -host_page_size); + addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | + (reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE), + -1, 0); if (addr == MAP_FAILED) { perror("Allocating guest commpage"); exit(EXIT_FAILURE); @@ -1544,9 +1548,9 @@ static bool init_guest_commpage(void) return false; } - memcpy(addr, kuser_page, sizeof(kuser_page)); + memcpy(g2h_untagged(LO_COMMPAGE), kuser_page, sizeof(kuser_page)); - if (mprotect(addr, qemu_host_page_size, PROT_READ)) { + if (mprotect(addr, host_page_size, PROT_READ)) { perror("Protecting guest commpage"); exit(EXIT_FAILURE); } From patchwork Thu Feb 22 20:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Njeeik9z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglXl2Qqsz23d2 for ; Fri, 23 Feb 2024 07:45:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv0-00074R-Al; Thu, 22 Feb 2024 15:43:46 -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 1rdFuy-00072X-Vn for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:45 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFux-0002cz-9C for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:44 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc139ed11fso10251345ad.0 for ; Thu, 22 Feb 2024 12:43:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634621; x=1709239421; 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=aaAlM/N1pdfPJQ0AFuX+476ixWIzFXGcl3gsIXYKRec=; b=Njeeik9zO19UpleMaIDKuJa5PCejUa3nrDoAGi3qUoDdjdRGOZ4BYwNWjvmuJdEOFf nwncKrZt5TXsiQQgu4HClU33N4pj1RcroDvLthoW18tq1BF+ukZCc+GneIPJOghFKiv+ 9SPYd2RoagkVV+6EqXnKelIYuRNhcEKYcVdxuXSSzsIIWVvDoM2O1Z21k/HSPe/YWSrm QUMPSO1MZEKGkSNCm0LdtRfEAD4Kb1wL7GbrF5+lTJL3PkxS5lH+4+NKbGoFRVD638nK dIh/ut7B4L+C157X1JRujb63xOihyTy7NYSjPVVROjBdQRFU/nKZNU53OzNkpkRRlZlZ BQcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634621; x=1709239421; 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=aaAlM/N1pdfPJQ0AFuX+476ixWIzFXGcl3gsIXYKRec=; b=NmpXdLwm0MTDpOvI7qKdprSCZLhNYNTc+qPX4ANpOS+4O/aeT3hBPd54X/cr0Tv2P5 37Uu9c/a6pGk0+N6BVKUR098Lu9I65lLbG5IlgdD+JztKqRK+ugcLEL5WYpAY+lo9CNJ +NYNEJkofwZ6RCXKVYdgrWTqQQQEL6o3UPX/9ff88atN/XidnwsLnyFu5TyGSRkjMCEJ A7IPVKjOTB2j47BqCIoqY3VWtaZZSZCT+GFxRPqhxscpWNhjxsUeJYrCzO9fWQOzrcPs K8x6ZX6+x0BlfOqZgBWQEnKWtTPCt/M2biFz0C3P2AeBW98jvJ2dlEHPu1Pya7zo+w/6 SUuA== X-Gm-Message-State: AOJu0Yyt5wIZKMRB7k26h+nKUZ5j3xZek68lA308HSORTLYZtLXg9mfM piRCLfIhMsgUOTdpzSOtrUGWfllNqOrnqjti+7uBbXHTRDPJmAfKSG4NWEcxANq3vq1xa7Gdayz y X-Google-Smtp-Source: AGHT+IEwJziSyEuRCWD5PkVaxtUS+nDgchiFl2JkjU3dNR7mB2TJyn6RO23QS3xB/01LGUzrjNPZvg== X-Received: by 2002:a17:902:ec83:b0:1db:2caa:6c5e with SMTP id x3-20020a170902ec8300b001db2caa6c5emr5538661plg.3.1708634621183; Thu, 22 Feb 2024 12:43:41 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 10/39] linux-user/arm: Remove qemu_host_page_size from init_guest_commpage Date: Thu, 22 Feb 2024 10:42:54 -1000 Message-Id: <20240222204323.268539-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size. If the commpage is not within reserved_va, use MAP_FIXED_NOREPLACE. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-8-richard.henderson@linaro.org> --- linux-user/elfload.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a9f1077861..f3f1ab4f69 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -460,6 +460,7 @@ enum { static bool init_guest_commpage(void) { ARMCPU *cpu = ARM_CPU(thread_cpu); + int host_page_size = qemu_real_host_page_size(); abi_ptr commpage; void *want; void *addr; @@ -472,10 +473,12 @@ static bool init_guest_commpage(void) return true; } - commpage = HI_COMMPAGE & -qemu_host_page_size; + commpage = HI_COMMPAGE & -host_page_size; want = g2h_untagged(commpage); - addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | + (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE), + -1, 0); if (addr == MAP_FAILED) { perror("Allocating guest commpage"); @@ -488,12 +491,12 @@ static bool init_guest_commpage(void) /* Set kernel helper versions; rest of page is 0. */ __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); - if (mprotect(addr, qemu_host_page_size, PROT_READ)) { + if (mprotect(addr, host_page_size, PROT_READ)) { perror("Protecting guest commpage"); exit(EXIT_FAILURE); } - page_set_flags(commpage, commpage | ~qemu_host_page_mask, + page_set_flags(commpage, commpage | (host_page_size - 1), PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; } From patchwork Thu Feb 22 20:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=fyOwwk1o; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglfz49zFz23l1 for ; Fri, 23 Feb 2024 07:51:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv2-00075h-RL; Thu, 22 Feb 2024 15:43:48 -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 1rdFv0-00074W-RP for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:46 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFuy-0002dc-Lx for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:46 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d932f6ccfaso1932215ad.1 for ; Thu, 22 Feb 2024 12:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634623; x=1709239423; 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=7FHxKdfDsfaKmMG5O+L7r4x4DJpI3IWY2MOpcFadlFM=; b=fyOwwk1oVImLseSw6eWTx/wO2b48zr/06VHOlfAIx3f6IOM+Vt5mNR880NcpnvdjP2 vGlzmv/JJhE0Kj/9wh/1R/+OQqE2UuMwyjpE8qEuyOTJt0IDtv4FIV1idaATBBndN8Pf YIevwM8kDEcZ9gMND0JjwL2w4xQoHDteuBmuSAJoWQYNEDSjC7RgV6pbC8usnDDuySvw dMTFOsd5rywHBsuPI3QQAOr7E4lJRLlrCnbJzD+EIuuHvwciZrc363jAROFABmL7kudC UOTZHukoY77QhUu0f7eP+04qReHTcTpMIGvQX4VwoK7DliLI6aal9T94LfuDyhJ0gCrV kmZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634623; x=1709239423; 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=7FHxKdfDsfaKmMG5O+L7r4x4DJpI3IWY2MOpcFadlFM=; b=Qw4M48H4ym87Rix+74zqh0AVZxA1KCEdAQr0l20gMhJOx3xuw4AF41oSFYmPES3BVo RORe6uP8w2isppnNJ0ilgweBBf77gMx6ewrvV7REnfP+jy5TPFzHfDNJhwXFfYF9ownb NGEFWlV2YvbaV7XQ31uhZvoHtvxhs3AYoAdraMnZdf+/YAdqiVPJuCOOqji2T1hEKvXr fCBCuxXCbG/XGVx7GnciQ0BKbngIvNOC3ZXqUQG7ezzNZGpn1kcXufE6Vw6X+mQLc3N4 vuG4GTtGplGvU8erATaCJ1Ezdom/Sf8AegXvl+vdEMDIa69FDtHXwFaR4rq8nN+F/zCC xZcA== X-Gm-Message-State: AOJu0YyRAtZ0GOUDzPA3Q+x6JaPysV7trS5i5Ss8zVLJ/jtb4tqEHKjH dLmxSuLmOw8RCWKDTHRXoNm756bQzJ+m2ueNE0Sf5HDR+689HtsqklkYAlQxbe7/gGx0HryKQoE s X-Google-Smtp-Source: AGHT+IFoDbPcEJdJI33eruKgutUBjX7fzVs+WDRlJt9Ex1cxlY6qrQKD4ZoKQ18NCWIUnSXnZnK4nQ== X-Received: by 2002:a17:902:9a83:b0:1dc:3d5:bdcc with SMTP id w3-20020a1709029a8300b001dc03d5bdccmr8527856plp.42.1708634623172; Thu, 22 Feb 2024 12:43:43 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 11/39] linux-user: Remove qemu_host_page_{size, mask} from mmap.c Date: Thu, 22 Feb 2024 10:42:55 -1000 Message-Id: <20240222204323.268539-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size instead. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-9-richard.henderson@linaro.org> --- linux-user/mmap.c | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 96c9433e27..4d3c8717b9 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -165,6 +165,7 @@ static int target_to_host_prot(int prot) /* NOTE: all the constants are the HOST ones, but addresses are target. */ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { + int host_page_size = qemu_real_host_page_size(); abi_ulong starts[3]; abi_ulong lens[3]; int prots[3]; @@ -189,13 +190,13 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } last = start + len - 1; - host_start = start & qemu_host_page_mask; + host_start = start & -host_page_size; host_last = HOST_PAGE_ALIGN(last) - 1; nranges = 0; mmap_lock(); - if (host_last - host_start < qemu_host_page_size) { + if (host_last - host_start < host_page_size) { /* Single host page contains all guest pages: sum the prot. */ prot1 = target_prot; for (abi_ulong a = host_start; a < start; a += TARGET_PAGE_SIZE) { @@ -205,7 +206,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) prot1 |= page_get_flags(a + 1); } starts[nranges] = host_start; - lens[nranges] = qemu_host_page_size; + lens[nranges] = host_page_size; prots[nranges] = prot1; nranges++; } else { @@ -218,10 +219,10 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) /* If the resulting sum differs, create a new range. */ if (prot1 != target_prot) { starts[nranges] = host_start; - lens[nranges] = qemu_host_page_size; + lens[nranges] = host_page_size; prots[nranges] = prot1; nranges++; - host_start += qemu_host_page_size; + host_start += host_page_size; } } @@ -233,9 +234,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } /* If the resulting sum differs, create a new range. */ if (prot1 != target_prot) { - host_last -= qemu_host_page_size; + host_last -= host_page_size; starts[nranges] = host_last + 1; - lens[nranges] = qemu_host_page_size; + lens[nranges] = host_page_size; prots[nranges] = prot1; nranges++; } @@ -270,6 +271,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, int prot, int flags, int fd, off_t offset) { + int host_page_size = qemu_real_host_page_size(); abi_ulong real_last; void *host_start; int prot_old, prot_new; @@ -286,7 +288,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return false; } - real_last = real_start + qemu_host_page_size - 1; + real_last = real_start + host_page_size - 1; host_start = g2h_untagged(real_start); /* Get the protection of the target pages outside the mapping. */ @@ -304,12 +306,12 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, * outside of the fragment we need to map. Allocate a new host * page to cover, discarding whatever else may have been present. */ - void *p = mmap(host_start, qemu_host_page_size, + void *p = mmap(host_start, host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); if (p != host_start) { if (p != MAP_FAILED) { - munmap(p, qemu_host_page_size); + munmap(p, host_page_size); errno = EEXIST; } return false; @@ -324,7 +326,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, /* Adjust protection to be able to write. */ if (!(host_prot_old & PROT_WRITE)) { host_prot_old |= PROT_WRITE; - mprotect(host_start, qemu_host_page_size, host_prot_old); + mprotect(host_start, host_page_size, host_prot_old); } /* Read or zero the new guest pages. */ @@ -338,7 +340,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, /* Put final protection */ if (host_prot_new != host_prot_old) { - mprotect(host_start, qemu_host_page_size, host_prot_new); + mprotect(host_start, host_page_size, host_prot_new); } return true; } @@ -373,17 +375,18 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, */ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) { + int host_page_size = qemu_real_host_page_size(); void *ptr, *prev; abi_ulong addr; int wrapped, repeat; - align = MAX(align, qemu_host_page_size); + align = MAX(align, host_page_size); /* If 'start' == 0, then a default start address is used. */ if (start == 0) { start = mmap_next_start; } else { - start &= qemu_host_page_mask; + start &= -host_page_size; } start = ROUND_UP(start, align); @@ -492,6 +495,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, off_t offset) { + int host_page_size = qemu_real_host_page_size(); abi_ulong ret, last, real_start, real_last, retaddr, host_len; abi_ulong passthrough_start = -1, passthrough_last = 0; int page_flags; @@ -537,8 +541,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } - real_start = start & qemu_host_page_mask; - host_offset = offset & qemu_host_page_mask; + real_start = start & -host_page_size; + host_offset = offset & -host_page_size; /* * If the user is asking for the kernel to find a location, do that @@ -567,8 +571,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, * may need to truncate file maps at EOF and add extra anonymous pages * up to the targets page boundary. */ - if ((qemu_real_host_page_size() < qemu_host_page_size) && - !(flags & MAP_ANONYMOUS)) { + if (host_page_size < TARGET_PAGE_SIZE && !(flags & MAP_ANONYMOUS)) { struct stat sb; if (fstat(fd, &sb) == -1) { @@ -595,11 +598,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, host_len = HOST_PAGE_ALIGN(host_len); host_prot = target_to_host_prot(target_prot); - /* - * Note: we prefer to control the mapping address. It is - * especially important if qemu_host_page_size > - * qemu_real_host_page_size. - */ + /* Note: we prefer to control the mapping address. */ p = mmap(g2h_untagged(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { @@ -665,7 +664,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, * aligned, so we read it */ if (!(flags & MAP_ANONYMOUS) && - (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) { + (offset & (host_page_size - 1)) != (start & (host_page_size - 1))) { /* * msync() won't work here, so we return an error if write is * possible while it is a shared mapping @@ -694,7 +693,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* handle the start of the mapping */ if (start > real_start) { - if (real_last == real_start + qemu_host_page_size - 1) { + if (real_last == real_start + host_page_size - 1) { /* one single host page */ if (!mmap_frag(real_start, start, last, target_prot, flags, fd, offset)) { @@ -703,21 +702,21 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto the_end1; } if (!mmap_frag(real_start, start, - real_start + qemu_host_page_size - 1, + real_start + host_page_size - 1, target_prot, flags, fd, offset)) { goto fail; } - real_start += qemu_host_page_size; + real_start += host_page_size; } /* handle the end of the mapping */ if (last < real_last) { - abi_ulong real_page = real_last - qemu_host_page_size + 1; + abi_ulong real_page = real_last - host_page_size + 1; if (!mmap_frag(real_page, real_page, last, target_prot, flags, fd, offset + real_page - start)) { goto fail; } - real_last -= qemu_host_page_size; + real_last -= host_page_size; } /* map the middle (easier) */ @@ -784,6 +783,7 @@ fail: static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) { + int host_page_size = qemu_real_host_page_size(); abi_ulong real_start; abi_ulong real_last; abi_ulong real_len; @@ -793,7 +793,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) int prot; last = start + len - 1; - real_start = start & qemu_host_page_mask; + real_start = start & -host_page_size; real_last = HOST_PAGE_ALIGN(last) - 1; /* @@ -802,7 +802,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) * The single page special case is required for the last page, * lest real_start overflow to zero. */ - if (real_last - real_start < qemu_host_page_size) { + if (real_last - real_start < host_page_size) { prot = 0; for (a = real_start; a < start; a += TARGET_PAGE_SIZE) { prot |= page_get_flags(a); @@ -818,14 +818,14 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) prot |= page_get_flags(a); } if (prot != 0) { - real_start += qemu_host_page_size; + real_start += host_page_size; } for (prot = 0, a = last; a < real_last; a += TARGET_PAGE_SIZE) { prot |= page_get_flags(a + 1); } if (prot != 0) { - real_last -= qemu_host_page_size; + real_last -= host_page_size; } if (real_last < real_start) { From patchwork Thu Feb 22 20:42:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Yefzncuf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYF3Rr9z23d2 for ; Fri, 23 Feb 2024 07:46:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv3-00076C-Uy; Thu, 22 Feb 2024 15:43:49 -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 1rdFv1-00074w-60 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:47 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFuz-0002eL-Pe for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:46 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d94b222a3aso1907475ad.2 for ; Thu, 22 Feb 2024 12:43:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634624; x=1709239424; 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=QqsG1I779d9YjbXcffYW5wImE5mXquA1bGyFgIG+R5A=; b=YefzncufOad2toW6MD2Us6LvBb1zDA/aUbJET7ef/SieWxd0bHhKSGuAUFxGcYCvZb 1QlctQM0vhXsvp5y42vSALv0V3WxKRPD0slOYlvtr+B+yfoAxoXb7/omFu2SpPGdbo75 l+WdWpXkEH2C1ecgMo1n3ybt+Fl5wLlgrAw6Y+yIX/tGD8R4Tu8rNHXPJu3B4B2oDN1J rQVAF5Kdy58J2e17cnFrPrglYgM4k4qvP03jY1bGI/WDd2bpqDN4D+Hw+O0mitrawo5i CK7ZS7DxeB9QpWy8ayCgy/peDSjJ66CkxooD7gQI0YqyZVTMIDdUe8Ckwu1m1XmQ/Nm2 DBXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634624; x=1709239424; 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=QqsG1I779d9YjbXcffYW5wImE5mXquA1bGyFgIG+R5A=; b=i7SuZ3vPfm1qTsSzrhowFcyoIPPMuPuIY8VR8EdBnKTfXODmW0dJ6DefaKvBBL3vvc U7FqyVBaRlreouF54caxjJ4XpryNAnn8jSSouWCBNCvNGusj6MJHTYCbx1QD0tohNlQJ v3Fd6tdcAE6IGvEoZrSED+1SKTrHAPC/bNiyEZL9S29YxnZnflKzyaVKEW2G45OWdMek IDxnUE0zJL/tdHHYT0RxOImAmUks9IaJkOE5/u+VE8lcq8jJQZQMXPB/eddNJ/IXBqz/ w6iVNTreKbSE3Erriw07q9wZMklop2PHJ2qx7YqH9MfdCNJduWDddPcmFt7uHXUSMbvM v1IA== X-Gm-Message-State: AOJu0Yxj8o+7/GpfKLoOJQZcprB22bVRrtZsCcB5vymExPXr5EC/8uPg ZHugOBx2/ZXNtfMobolcNoDi4n4/id1o8Kv09gf8RVFMdD0krooG7UeiJm2hBPc4teYqxcOiFeJ u X-Google-Smtp-Source: AGHT+IGLAQIiCdkn4JcgGvYppS43mkFBwl0pdDGUPCeFRj4Qp9DKME1aiwGDZPaRA7iUYIFtkjcPGw== X-Received: by 2002:a17:902:e789:b0:1db:fa84:9be3 with SMTP id cp9-20020a170902e78900b001dbfa849be3mr10994096plb.8.1708634624592; Thu, 22 Feb 2024 12:43:44 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:44 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 12/39] linux-user: Remove REAL_HOST_PAGE_ALIGN from mmap.c Date: Thu, 22 Feb 2024 10:42:56 -1000 Message-Id: <20240222204323.268539-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We already have qemu_real_host_page_size() in a local variable. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-10-richard.henderson@linaro.org> --- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 4d3c8717b9..53e5486cc8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -585,7 +585,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, * the hosts real pagesize. Additional anonymous maps * will be created beyond EOF. */ - len = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); + len = ROUND_UP(sb.st_size - offset, host_page_size); } } From patchwork Thu Feb 22 20:42:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=H+ajFqd8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglWw4rl1z23d2 for ; Fri, 23 Feb 2024 07:45:16 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv7-00078c-9K; Thu, 22 Feb 2024 15:43:53 -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 1rdFv3-00075k-1z for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:49 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv1-0002ej-El for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:48 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so2023715ad.1 for ; Thu, 22 Feb 2024 12:43:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634626; x=1709239426; 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=K5KQN5vcI0KBxXe8ErUYFGLj7ZU4KIuwkr3avJe+C4E=; b=H+ajFqd8obqTtbx1c/AzI2RPKxqKppZdW00DkdCHHyrdNkPmkzf3BoEGmjRoZEfEKt t9U4cGjvWedxF9X2VY6q0Fvua1+xGsgfNHjPAFctB8t+88U3KonDaxe0R8aJx2nyzEQ/ /URlWTBzVhOH8gv1+/l/68MpoNLcjdZBIfzdro1B/wKXp43tUf1Me8FeachzukFflsU3 3rgPv41MKzE1zT4ZVJ0LxPHAoC+dbObFCM6Z2fOmLfoFMuwA4T9km4367hbC9HLod/QV 7D2sU7K1ZC4zIeIYxZJ4XVPlENG+K8rLGU8FkHhs5FVDFmx61PxNIOI3ZnN2L/5hETAX /IiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634626; x=1709239426; 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=K5KQN5vcI0KBxXe8ErUYFGLj7ZU4KIuwkr3avJe+C4E=; b=jrYKosyfjTPMFh9PdqDc2mFe3a9BaMxSTh7TDRnANCNx27WfqUjjIYtsB5YJM8rpZa bR6uNd/6vACPIAotd0szQffwLean65WT5oyu4ie+mweyAgT70AQc9VEUMk6kYDVQJ/Yf 8LXhri4yOMY2v20nJQs8yYo1e+np88My344v2gJJZnUgvKRlNqF2ImsDaWSa707SU7cr TzTH8deELNOzglVya4T7xxXrsK6TtWujClZGZ/iIiuVrxwFDSevI7VGQRJr8MG7LHXgR PT5JEcxNqOIp+OvQDEZ6J8gg6QSZ9PTQ2x2NNhcSIoS0c3gq1K+GEM8kSH2H/K+SnnfY e2gw== X-Gm-Message-State: AOJu0Yz6MTpRrsfhdJDxXLcG78cyQv1nBvblHWrku3TrQ+OtMeKeXFZ/ 3nLb+CSuEjvzyJbDH1goHJJftEsWB+aia13598jHm9voBbTnMuzqjSiuaE5NiheVjVCnzWf7I89 n X-Google-Smtp-Source: AGHT+IFLfX0qbOK2LVfyUGGMQGn+LI4ZclT0Y6JaNDcP2mfDam5Vq3nk774ZD7BMOS8Qvpc6jVcIiA== X-Received: by 2002:a17:902:da92:b0:1db:f15c:85c0 with SMTP id j18-20020a170902da9200b001dbf15c85c0mr171752plx.33.1708634626133; Thu, 22 Feb 2024 12:43:46 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 13/39] linux-user: Remove HOST_PAGE_ALIGN from mmap.c Date: Thu, 22 Feb 2024 10:42:57 -1000 Message-Id: <20240222204323.268539-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This removes a hidden use of qemu_host_page_size, using instead the existing host_page_size local within each function. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-11-richard.henderson@linaro.org> --- linux-user/mmap.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 53e5486cc8..d11f758d07 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -191,7 +191,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) last = start + len - 1; host_start = start & -host_page_size; - host_last = HOST_PAGE_ALIGN(last) - 1; + host_last = ROUND_UP(last, host_page_size) - 1; nranges = 0; mmap_lock(); @@ -389,8 +389,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) start &= -host_page_size; } start = ROUND_UP(start, align); - - size = HOST_PAGE_ALIGN(size); + size = ROUND_UP(size, host_page_size); if (reserved_va) { return mmap_find_vma_reserved(start, size, align); @@ -550,7 +549,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, */ if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { host_len = len + offset - host_offset; - host_len = HOST_PAGE_ALIGN(host_len); + host_len = ROUND_UP(host_len, host_page_size); start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); if (start == (abi_ulong)-1) { errno = ENOMEM; @@ -595,7 +594,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, void *p; host_len = len + offset - host_offset; - host_len = HOST_PAGE_ALIGN(host_len); + host_len = ROUND_UP(host_len, host_page_size); host_prot = target_to_host_prot(target_prot); /* Note: we prefer to control the mapping address. */ @@ -625,7 +624,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } last = start + len - 1; - real_last = HOST_PAGE_ALIGN(last) - 1; + real_last = ROUND_UP(last, host_page_size) - 1; /* * Test if requested memory area fits target address space @@ -794,7 +793,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) last = start + len - 1; real_start = start & -host_page_size; - real_last = HOST_PAGE_ALIGN(last) - 1; + real_last = ROUND_UP(last, host_page_size) - 1; /* * If guest pages remain on the first or last host pages, From patchwork Thu Feb 22 20:42:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=g9JkkC78; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglVk551qz23nM for ; Fri, 23 Feb 2024 07:44:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFv9-0007HX-Nk; Thu, 22 Feb 2024 15:43:55 -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 1rdFv5-0007Cb-W0 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:53 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv3-0002fO-3H for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:50 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d73066880eso2072135ad.3 for ; Thu, 22 Feb 2024 12:43:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634627; x=1709239427; 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=z/9ie+RjhRAxWQRFAoaHPcdtrZYsCMJBCi3SaKV1dlk=; b=g9JkkC78kXu590aZzhZDQGh3vXufgZDGk/pLXVSNopNrqAow5tDlZitYpxgnT0+rbb 9nfupNRA/SApjE/uPonO1p1D/38Pi4NjyCLqk3RmZ7W3ekbWnOMC958TWzTjUaT7cdl/ hY4op/O3Rv+jrya4IRLxNDpda9oruJK582TYebSkb2WHN5+wtIFIukQbFKpbu/H+K9Wc +S8lQc0Aek6OfcfWU4mLeixWT2kOOJqTrc6+3IztWj60BDSTCUq/dZ3u+sPSgbetg1PR 3DskF6gxZe7XI8Km4l6z5/826fpFU5Jb9iIi9fuiu4xZrdPeJ4Um9Aa5rkj+2s9Kb6Qa nEIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634627; x=1709239427; 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=z/9ie+RjhRAxWQRFAoaHPcdtrZYsCMJBCi3SaKV1dlk=; b=khm1Nyo94WCwBtoXHdm13jrKika9TgQfiHk8qcGGyFUDJDUisk7YImq0ypw+ZEY5UA SH9+u4ex1CPBLQOxepE2OpFOyweyF6rX+6ufTon8B6O+/CdD5v8AinoInR5+neN2q9Zf KjIUR1aytKvgDF8jG2dhNvG9JCXpihH/twSxpq7lNvFGu1ckkw8Hp7veNXVBlZDXPx0G Q+3/CYA56HjtFyC8rt6U2K69WUU/dbbpylD1H7zWAAPTik0SrxRgn8VCJz8dMJ/S1CA3 M21EckiutgiTls3XcfJF/DsAIredUiBKGZdZm6izRRQd1sHmrGpjKruXVqfDxcsWEIxK iYBw== X-Gm-Message-State: AOJu0Ywkl726fbF/idHn8+Q4Kp1faOytkqbkwWz2Wps3caZLfEy2Ch6r yOqPJvst8Yy9AKwmmLfUtx9uXdXZYxFdTNL9uR/Tahl43Nw3riUCT4NJ4lqMqzwRQ2kYVI+qtMg p X-Google-Smtp-Source: AGHT+IGqMMl87NciX6E9cvagZpZTphc4TxdGyPnytQaCAzhuUuBo680g5GPhi/pDhdcbUkqWIO1odw== X-Received: by 2002:a17:902:6e0f:b0:1d9:167b:8e6c with SMTP id u15-20020a1709026e0f00b001d9167b8e6cmr20193636plk.46.1708634627595; Thu, 22 Feb 2024 12:43:47 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 14/39] migration: Remove qemu_host_page_size Date: Thu, 22 Feb 2024 10:42:58 -1000 Message-Id: <20240222204323.268539-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Replace with the maximum of the real host page size and the target page size. This is an exact replacement. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-12-richard.henderson@linaro.org> --- migration/ram.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 4649a81204..61c1488352 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2935,7 +2935,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) { RAMState **rsp = opaque; RAMBlock *block; - int ret; + int ret, max_hg_page_size; if (compress_threads_save_setup()) { return -1; @@ -2950,6 +2950,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } (*rsp)->pss[RAM_CHANNEL_PRECOPY].pss_channel = f; + /* + * ??? Mirrors the previous value of qemu_host_page_size, + * but is this really what was intended for the migration? + */ + max_hg_page_size = MAX(qemu_real_host_page_size(), TARGET_PAGE_SIZE); + WITH_RCU_READ_LOCK_GUARD() { qemu_put_be64(f, ram_bytes_total_with_ignored() | RAM_SAVE_FLAG_MEM_SIZE); @@ -2958,8 +2964,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) qemu_put_byte(f, strlen(block->idstr)); qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); qemu_put_be64(f, block->used_length); - if (migrate_postcopy_ram() && block->page_size != - qemu_host_page_size) { + if (migrate_postcopy_ram() && + block->page_size != max_hg_page_size) { qemu_put_be64(f, block->page_size); } if (migrate_ignore_shared()) { @@ -3792,6 +3798,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) int ret = 0; /* ADVISE is earlier, it shows the source has the postcopy capability on */ bool postcopy_advised = migration_incoming_postcopy_advised(); + int max_hg_page_size; assert(block); @@ -3809,9 +3816,16 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) return ret; } } + + /* + * ??? Mirrors the previous value of qemu_host_page_size, + * but is this really what was intended for the migration? + */ + max_hg_page_size = MAX(qemu_real_host_page_size(), TARGET_PAGE_SIZE); + /* For postcopy we need to check hugepage sizes match */ if (postcopy_advised && migrate_postcopy_ram() && - block->page_size != qemu_host_page_size) { + block->page_size != max_hg_page_size) { uint64_t remote_page_size = qemu_get_be64(f); if (remote_page_size != block->page_size) { error_report("Mismatched RAM page size %s " From patchwork Thu Feb 22 20:42:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=aiM9tOI6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglgQ2ZTXz23nM for ; Fri, 23 Feb 2024 07:51:46 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvC-0007Lg-1F; Thu, 22 Feb 2024 15:43:58 -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 1rdFv7-0007FJ-FA for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:53 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv4-0002fz-7Y for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:52 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1dc09556599so1893345ad.1 for ; Thu, 22 Feb 2024 12:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634629; x=1709239429; 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=9UuugcteI3wsnFXZ+gvu7oCS1Hb/WPFzjY9R5VsQ974=; b=aiM9tOI62KtGtR2JFQ3MF1GeIN7slAOqzVwX6Rob7pkxFNjB3uWjMfynuv+eUFYMGW KjXRqGB2eMBUBESL2/KKREiaOGDZ9AUR3qOFIHP4p9ZfvxpUvP8/xEdbGRFB65rHUhOJ fUG19UVzt491J1rPEuEoqLllh93B4GjsAM2RAEmzOZ23nTp0Y1gR2h+QZ5rkCY3nqoPU FVM3GKrYwFCwVU0kLIDyxZAqxkqggJBVS537DVk9+7knu44M/Da36eNJumuIgsBY6Lyq UHQ7C/+QDlVCkpzJrR6rriPpG6OAoSozrJLq2Iuu/Ze2rQFLq8BvtWFFNkI95qdOySdR 92xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634629; x=1709239429; 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=9UuugcteI3wsnFXZ+gvu7oCS1Hb/WPFzjY9R5VsQ974=; b=CcEe27B4MwqLSl9Dgiqn+qWK+uMAErPwNyGTWdgjsrLHaKZdKpL4bwPKvIvR97yN08 eOcr6tuE7wEfjxHI2yLhPT7wJX502fMhNwya7bORlV5XWlaCHJZX+Jqj9LuflI/Bx6WJ aK9trafHSRBw3sM8kg8xBu9DeYFyDzZUVrxW09GJHOFgNdzemTpSiCvYXJEeTrnjEF0n YZ2pGgcZIAtEtVyXonpBakMHdCUlyl5wjcIvPvfKb9BtLGuurSPRgCUM5zTPNzyFSi+z 0y54QlkmUk3vJZpt6Q2u+hbiaSudR7ZB109pLauK/56LDfEYfon5xXtcsd5P8u08EUaf LylA== X-Gm-Message-State: AOJu0YyfPopOlZ++YsPN+esXzF03xeFz4YCMTMzQ/k7uMHHpcOqqaLW8 yzHggiVf7RA85PQQr2r52TnZnOWjWcaz7cMWr56rOD5jcxCV2OO6Gg1BP8Lm3DWLRcO4Hn/7Ctt X X-Google-Smtp-Source: AGHT+IHTYa+a/K6CNDzmXH0Z1jnDBthB9dDd+QQD3FLFcEDaoJ6pEUulcrvICEysCwwB6cW3LcU/6g== X-Received: by 2002:a17:902:ecc7:b0:1dc:15db:bcca with SMTP id a7-20020a170902ecc700b001dc15dbbccamr10964375plh.55.1708634629026; Thu, 22 Feb 2024 12:43:49 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 15/39] hw/tpm: Remove HOST_PAGE_ALIGN from tpm_ppi_init Date: Thu, 22 Feb 2024 10:42:59 -1000 Message-Id: <20240222204323.268539-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This removes a hidden use of qemu_host_page_size, hoisting two uses of qemu_real_host_page_size to a local variable. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller --- hw/tpm/tpm_ppi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c index 7f74e26ec6..f27ed6c35e 100644 --- a/hw/tpm/tpm_ppi.c +++ b/hw/tpm/tpm_ppi.c @@ -47,8 +47,10 @@ void tpm_ppi_reset(TPMPPI *tpmppi) void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m, hwaddr addr, Object *obj) { - tpmppi->buf = qemu_memalign(qemu_real_host_page_size(), - HOST_PAGE_ALIGN(TPM_PPI_ADDR_SIZE)); + size_t host_page_size = qemu_real_host_page_size(); + + tpmppi->buf = qemu_memalign(host_page_size, + ROUND_UP(TPM_PPI_ADDR_SIZE, host_page_size)); memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi", TPM_PPI_ADDR_SIZE, tpmppi->buf); vmstate_register_ram(&tpmppi->ram, DEVICE(obj)); From patchwork Thu Feb 22 20:43:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=LhrWrRa5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglW16rbrz23pN for ; Fri, 23 Feb 2024 07:44:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvB-0007LA-QK; Thu, 22 Feb 2024 15:43:57 -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 1rdFv8-0007GP-Mz for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:54 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv6-0002gA-LC for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:54 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dc1ff697f9so1995085ad.0 for ; Thu, 22 Feb 2024 12:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634631; x=1709239431; 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=Utr6CY7GZcNfj8e7YUB3Ing2Y6m3UnMyzHBBd5nSQRo=; b=LhrWrRa5yphmSfgH8AFGg3m3J/K0a+zZpzn9L6X5jDFpxXTlHq+B629Nah2BMMFUty jhC/LsBfE+jWnCKYfozqx4Nq6BuSNeSwihGKnxFgX0JDvhSFPzZXODeg/cBVfQe84pr3 au/uSZy5Bzgdm6TKUH8KF6JclS+H5iH29Fgvf+Fk3dFfY7V+8H+fk3hbLpJaskwK1Ckc dRySbb038mqI9zPQCz27xhlDgODh5q3OiZjQ8z+2Eq46ECAKCJliTViawLsmnQxu8f/1 CV3QOMiO3V6MGXnhiVd8uEalmFhbTzzT+zhCTmohW4W/IUoN9vx6bK4qkTS/h6OyEFZr 3UYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634631; x=1709239431; 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=Utr6CY7GZcNfj8e7YUB3Ing2Y6m3UnMyzHBBd5nSQRo=; b=qD7hPwdGgFiPYlnQ7bMQ1F5Ir9LK9crJPVukYPhtVM6COosGDxQXbgdzWGbvsleCx/ EuEjRH5oPvmBoGkTE+UEUQ/mj3SkkZrDvi37K+dB3kXncU592YEohYXBVMCLBbEKfVzf iz1FSwev7QAG4h/XwAqRH+Zhit0m2A/nbVEW/o64JUw3VL3EjU/19lcYMQWes1n4uxHf tz6jcpo+28y7ORJDrUDswqAZH49NFN22O8skknjUYObe2fahVuxx5FiZizHBkns6sOd5 NxtcSTC0KQ6JFtHVr2QtssP0U41gyce9srHcZlgfbLSY3b5+ZLIYqpboFMg2a1juqFlI HQxA== X-Gm-Message-State: AOJu0Yw0OsflRsjP9ZEdMaSkPw7Bix/B0SRxpxw/YN+qk/5XAs7vzVrM 5GJop3lTg0rk3RzA3HulgQK0WXo0B/cx05no0XTKoXpgQNQDCEFKHhIC3xyDTeSh/EFKqEtNf7r s X-Google-Smtp-Source: AGHT+IGjZgQixJ+pWhtnY9g01dKeCbpIoA1KNjOhjs64feytNdPX1hjHmmQ4xu4xWt0nDAfm0dhpZQ== X-Received: by 2002:a17:903:2350:b0:1db:fc02:f96e with SMTP id c16-20020a170903235000b001dbfc02f96emr12801397plh.24.1708634630848; Thu, 22 Feb 2024 12:43:50 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 16/39] softmmu/physmem: Remove qemu_host_page_size Date: Thu, 22 Feb 2024 10:43:00 -1000 Message-Id: <20240222204323.268539-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size() instead. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-14-richard.henderson@linaro.org> --- system/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/physmem.c b/system/physmem.c index e3ebc19eef..3b08e064ff 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3511,7 +3511,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) * fallocate works on hugepages and shmem * shared anonymous memory requires madvise REMOVE */ - need_madvise = (rb->page_size == qemu_host_page_size); + need_madvise = (rb->page_size == qemu_real_host_page_size()); need_fallocate = rb->fd != -1; if (need_fallocate) { /* For a file, this causes the area of the file to be zero'd From patchwork Thu Feb 22 20:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZPcjilfw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglVq4HdFz23l3 for ; Fri, 23 Feb 2024 07:44:19 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvE-0007Ot-QW; Thu, 22 Feb 2024 15:44:00 -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 1rdFv9-0007IX-SW for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:56 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv7-0002hZ-Ky for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:55 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d71cb97937so2312355ad.3 for ; Thu, 22 Feb 2024 12:43:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634632; x=1709239432; 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=dE6xy9+D6Je1Etl+ajN+bavVnxpk9B7ygAyJhkrFQtk=; b=ZPcjilfwiB9pFaFEHttDEb2Zqa4XhyG/2l8moqjrSCn/w9R25x7xGFDkWu0w/kw1YI WEyxXOLWded6ejm55hxcbttaXTUOS+nYyj/LuKHA5AP7/lednII02b2YT1PECRiZv+DV nj65aUd9YtRwB7efmyKgT1eAjfmrqeqoRtwB9tdV3aU/49DehUz9oN4WbsgwNX8nv/a4 tcb+fl9XDTnoe3XZDteo0cd1hhttqaRMB3x3IlWIQNuWGqMILH2V4xuJJDcbxmPl81k8 54dWUX3dAQiZuT2Ek9R1ObdDBz72EnFoOUmnO6coEWQAQ5dCjexwLnllugQp87VN62f/ 8aSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634632; x=1709239432; 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=dE6xy9+D6Je1Etl+ajN+bavVnxpk9B7ygAyJhkrFQtk=; b=NNncZmAyFlsaDs8khgXNbEkEYq53ZB3/wVWgvnUUcTbYzRet4Zrn4qVLhjM7Jux/fM fhLkwJnfzaEPvKhhoyedxje5pfkTPOtb3elUuzGugSffxsOtxTJTcPzpiFZvRGX7TCF3 zg8KHG3xkLMqd2ztsRXHtEA8yPNNca4msc5aVgdLtcfb/Rh5YqLkwElR/mYvxz06YUFZ OcAEDp89SMpZMhXREn4RrPpVyd0iMwMZZIfviO5owA1eiv1ZlWeSlxTaO+IdTX9hshHx XmFTXUjKxH9+vemYdSXUvBY9JQF2xtBODk+rsLZMC0ORughHHIz4L4nVi3M9wh8RccOY 06nQ== X-Gm-Message-State: AOJu0Ywn+jxUxEYQ+4sM5tbzJCwe+AfFXK3lI9CklmMlfSYd+sZITyBn /hQrtidS5Qma/9eFLSdoj38Vu3sYKELx9PTho/37ROVGFzpY71jpRT82X28CV/JhGTtfflzzFAO g X-Google-Smtp-Source: AGHT+IG9+60t4gx+wBn0FPSNh0kEcv84Q0jrmCfcpRCHkWKGRJM2X453l6ukGYgTwNvpEz3GCpy3KA== X-Received: by 2002:a17:903:2442:b0:1db:fc18:2db9 with SMTP id l2-20020a170903244200b001dbfc182db9mr12395566pls.64.1708634632438; Thu, 22 Feb 2024 12:43:52 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PULL 17/39] softmmu/physmem: Remove HOST_PAGE_ALIGN Date: Thu, 22 Feb 2024 10:43:01 -1000 Message-Id: <20240222204323.268539-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Align allocation sizes to the maximum of host and target page sizes. Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-15-richard.henderson@linaro.org> --- system/physmem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 3b08e064ff..3adda08ebf 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1680,7 +1680,8 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) assert(block); - newsize = HOST_PAGE_ALIGN(newsize); + newsize = TARGET_PAGE_ALIGN(newsize); + newsize = REAL_HOST_PAGE_ALIGN(newsize); if (block->used_length == newsize) { /* @@ -1916,7 +1917,9 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, return NULL; } - size = HOST_PAGE_ALIGN(size); + size = TARGET_PAGE_ALIGN(size); + size = REAL_HOST_PAGE_ALIGN(size); + file_size = get_file_size(fd); if (file_size > offset && file_size < (offset + size)) { error_setg(errp, "backing store size 0x%" PRIx64 @@ -2014,13 +2017,17 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, { RAMBlock *new_block; Error *local_err = NULL; + int align; assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | RAM_NORESERVE)) == 0); assert(!host ^ (ram_flags & RAM_PREALLOC)); - size = HOST_PAGE_ALIGN(size); - max_size = HOST_PAGE_ALIGN(max_size); + align = qemu_real_host_page_size(); + align = MAX(align, TARGET_PAGE_SIZE); + size = ROUND_UP(size, align); + max_size = ROUND_UP(max_size, align); + new_block = g_malloc0(sizeof(*new_block)); new_block->mr = mr; new_block->resized = resized; From patchwork Thu Feb 22 20:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=RsyXnn73; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYT2s6yz23d2 for ; Fri, 23 Feb 2024 07:46:37 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvG-0007RX-Ao; Thu, 22 Feb 2024 15:44:02 -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 1rdFvA-0007Ji-UE for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:56 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFv9-0002i0-A2 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:56 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dbd32cff0bso2134855ad.0 for ; Thu, 22 Feb 2024 12:43:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634634; x=1709239434; 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=MJwI7j8qAfDRGrC+KBy3NdL40EXjR4qHacqKh2GDQwg=; b=RsyXnn73y57gyDkwUIBbtfDXsXCLbEgFRPqiHqLp6amJH+kLAIDmwi8MJjINWCFoME wXouhiMID6n8fYRH+kj1g3K1NL3wb6l98oacuiUY/q/8MPRteHv5kQNTlMNuu0H6sTFb GtPfSiTspdPDWlxXHtp7McSJvGQQK+hJ+yR/OCmIOIRNJi+4fUGzAOLMoVyNHTascPZR EgKDdgXYBU1suo1HRRPEuUh2HCnGyYzbgS8V8jCWFnjmofnhxAmLOdvsMQmWgA51qmIO PpEoAH7LMG8cDXGeMc1CbZ4UPJsuHAYw4VP6HP6hayayhybTDipNufgR2Zl+wIrjeqXH /xlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634634; x=1709239434; 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=MJwI7j8qAfDRGrC+KBy3NdL40EXjR4qHacqKh2GDQwg=; b=TT0DvIduE7/opdyHNJQvtK6Aqjp3VOTXbnJM9rZ8FZcuepVxEC05wGvwasrjf7enjJ fCrqr0P/ofnr/8jOBEjDBTeIkexHnWpp8ftnyj+ouV+zrwmxVsdhTSFeKvDeasDyUeKw aSeF8Nt4KD7g14AXv32QfB4bXafb5QZVdcDBrbHbMTqDxxyL9RwSQLawPMzWEh8XqLfP QqfXwP6f+znxmixs7q8EWeWyTUFpcgVO0hFBoyxxTDUoKGNre36WWP0GZPbFtcBPewOj 91gNcUWQoBhiT76/cKvYg9HUOH+khqDZGzx03pTavveLGkOH8Qdl602KbAzGA0yLLjaW 3qNg== X-Gm-Message-State: AOJu0YwjMxuokF7tlpMdosFfi0SNwNzcrw0+zP3bO0wbh4VmgCZXO7Q9 leZFyupzyJmp3dGGYjzVGBXq3raZygnBRBI+JoajwzXPlSxN7hgAOjwTKFCvchMn19NmrncQ26X L X-Google-Smtp-Source: AGHT+IF1Hzlxd2DbvHsKIwLQSpwa+5XE8Z79DClSdlRPbx+SPNUadnHfWBWfTGFtWORSGe1uLxHsjg== X-Received: by 2002:a17:902:ecc1:b0:1dc:43d:964 with SMTP id a1-20020a170902ecc100b001dc043d0964mr12783669plh.48.1708634633879; Thu, 22 Feb 2024 12:43:53 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:53 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 18/39] linux-user: Remove qemu_host_page_size from main Date: Thu, 22 Feb 2024 10:43:02 -1000 Message-Id: <20240222204323.268539-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_real_host_page_size() instead. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-16-richard.henderson@linaro.org> --- linux-user/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 74b2fbb393..e540acb84a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -781,7 +781,7 @@ int main(int argc, char **argv, char **envp) } cpu_type = parse_cpu_option(cpu_model); - /* init tcg before creating CPUs and to get qemu_host_page_size */ + /* init tcg before creating CPUs */ { AccelState *accel = current_accel(); AccelClass *ac = ACCEL_GET_CLASS(accel); @@ -804,8 +804,10 @@ int main(int argc, char **argv, char **envp) */ max_reserved_va = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { - if ((reserved_va + 1) % qemu_host_page_size) { - char *s = size_to_str(qemu_host_page_size); + int host_page_size = qemu_real_host_page_size(); + + if ((reserved_va + 1) % host_page_size) { + char *s = size_to_str(host_page_size); fprintf(stderr, "Reserved virtual address not aligned mod %s\n", s); g_free(s); exit(EXIT_FAILURE); @@ -902,7 +904,7 @@ int main(int argc, char **argv, char **envp) * If we're in a chroot with no /proc, fall back to 1 page. */ if (mmap_min_addr == 0) { - mmap_min_addr = qemu_host_page_size; + mmap_min_addr = qemu_real_host_page_size(); qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx (fallback)\n", mmap_min_addr); From patchwork Thu Feb 22 20:43:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=SN093ug6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYq0lgkz23nM for ; Fri, 23 Feb 2024 07:46:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvG-0007Rk-Ca; Thu, 22 Feb 2024 15:44:02 -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 1rdFvD-0007Ou-CN for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:00 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvB-0002iQ-CB for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:43:58 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e332bc65b3so48520b3a.3 for ; Thu, 22 Feb 2024 12:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634636; x=1709239436; 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=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; b=SN093ug67QNHP8bcCFYrCPXZ/l/yRHqIknj2FKResxWvxRc8rTJEYQvllgknLy98ls K2N1cTdkJ+q5Syrmm97djyTXjFqhqWatyMomkGskVkwJ4LNt8c2iBNrJBdzMPv0+4RL2 yqZOeFodS9NmWW9BtoWq0Zc7MOwGp+q0Ecnj5Qn8N5DGwmJ8REEQuuCU2EQjm7/zW8p3 QCxsTqpLgVjSCRQRUr3LkMOOSFi8vcAV9PB9bL3hv3VtHAcesvbHmPiRJpFCV2qHxZF9 +qA6HeZq73sHD6t/Pu6UIPdLzARSH+v4gbCN6p7Abf8rSI6mJFDK6nQWPgpmRw1ukVyy n61g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634636; x=1709239436; 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=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; b=n0PhXjINRx5PdmO74ZhI2GJmC9rUNG47pMNTpcaw45emenW4NZNvc9aZZRc2pvcb1M RTAm9iqRUMOpgnP8bEMI7FxOK/vyCWL0kCzqq5VnXksu0J7zg97fGV+maR1ZuZOX0FoN Rv2Z8az22ng6bEaLkFJvYI/IYBbgJzXQOH3uIcaiom7ZLIBftNAxBpJprrJVnEpQBqi3 KdafwGEAMdC0Q9ExS9jLGOamoRRPbB70uirSpp8y2Kbuv1foQ63OucjYsgky8wI86uJa ngCxT+Hr0BTTYFhI5mbFXO4WSDK8Excgi0chHYKBDOfJsjeui78qufyjsKr3/s58w69c erOw== X-Gm-Message-State: AOJu0YzZSp7HPIfxpiTb7tCn8ytl63IRdHvfcJJkw5WHGyg/V23pve7O 2eHbIEL4rFk28c7xZjFN7i5+Hr2wFjONO5TTRJ5/DcQotpXr/7B9OnPiHEwUud989v3+eAFnVha C X-Google-Smtp-Source: AGHT+IFFXHN1dGBUeQt3S7WWYjUKwWy6BH4V5AYK2bSxYlWgxgRd7kty/HWVVi5v1ObsVgI1C63q5Q== X-Received: by 2002:a05:6a20:c886:b0:1a0:73b9:85e2 with SMTP id hb6-20020a056a20c88600b001a073b985e2mr24059324pzb.10.1708634635881; Thu, 22 Feb 2024 12:43:55 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 19/39] linux-user: Split out target_mmap__locked Date: Thu, 22 Feb 2024 10:43:03 -1000 Message-Id: <20240222204323.268539-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org All "goto fail" may be transformed to "return -1". Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-17-richard.henderson@linaro.org> --- linux-user/mmap.c | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d11f758d07..b4c3cc65aa 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -490,9 +490,9 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } } -/* NOTE: all the constants are the HOST ones */ -abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, - int flags, int fd, off_t offset) +static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, + int target_prot, int flags, + int fd, off_t offset) { int host_page_size = qemu_real_host_page_size(); abi_ulong ret, last, real_start, real_last, retaddr, host_len; @@ -500,30 +500,27 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int page_flags; off_t host_offset; - mmap_lock(); - trace_target_mmap(start, len, target_prot, flags, fd, offset); - if (!len) { errno = EINVAL; - goto fail; + return -1; } page_flags = validate_prot_to_pageflags(target_prot); if (!page_flags) { errno = EINVAL; - goto fail; + return -1; } /* Also check for overflows... */ len = TARGET_PAGE_ALIGN(len); if (!len) { errno = ENOMEM; - goto fail; + return -1; } if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; - goto fail; + return -1; } /* @@ -553,7 +550,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); if (start == (abi_ulong)-1) { errno = ENOMEM; - goto fail; + return -1; } } @@ -574,7 +571,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, struct stat sb; if (fstat(fd, &sb) == -1) { - goto fail; + return -1; } /* Are we trying to create a map beyond EOF?. */ @@ -601,7 +598,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, p = mmap(g2h_untagged(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { - goto fail; + return -1; } /* update start so that it points to the file position at 'offset' */ host_start = (uintptr_t)p; @@ -610,7 +607,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, flags | MAP_FIXED, fd, host_offset); if (p == MAP_FAILED) { munmap(g2h_untagged(start), host_len); - goto fail; + return -1; } host_start += offset - host_offset; } @@ -621,7 +618,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } else { if (start & ~TARGET_PAGE_MASK) { errno = EINVAL; - goto fail; + return -1; } last = start + len - 1; real_last = ROUND_UP(last, host_page_size) - 1; @@ -633,14 +630,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, */ if (last < start || !guest_range_valid_untagged(start, len)) { errno = ENOMEM; - goto fail; + return -1; } if (flags & MAP_FIXED_NOREPLACE) { /* Validate that the chosen range is empty. */ if (!page_check_range_empty(start, last)) { errno = EEXIST; - goto fail; + return -1; } /* @@ -671,17 +668,17 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if ((flags & MAP_TYPE) == MAP_SHARED && (target_prot & PROT_WRITE)) { errno = EINVAL; - goto fail; + return -1; } retaddr = target_mmap(start, len, target_prot | PROT_WRITE, (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) { - goto fail; + return -1; } if (pread(fd, g2h_untagged(start), len, offset) == -1) { - goto fail; + return -1; } if (!(target_prot & PROT_WRITE)) { ret = target_mprotect(start, len, target_prot); @@ -696,14 +693,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* one single host page */ if (!mmap_frag(real_start, start, last, target_prot, flags, fd, offset)) { - goto fail; + return -1; } goto the_end1; } if (!mmap_frag(real_start, start, real_start + host_page_size - 1, target_prot, flags, fd, offset)) { - goto fail; + return -1; } real_start += host_page_size; } @@ -713,7 +710,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, if (!mmap_frag(real_page, real_page, last, target_prot, flags, fd, offset + real_page - start)) { - goto fail; + return -1; } real_last -= host_page_size; } @@ -739,7 +736,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, munmap(p, len1); errno = EEXIST; } - goto fail; + return -1; } passthrough_start = real_start; passthrough_last = real_last; @@ -773,11 +770,22 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, qemu_log_unlock(f); } } - mmap_unlock(); return start; -fail: +} + +/* NOTE: all the constants are the HOST ones */ +abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, + int flags, int fd, off_t offset) +{ + abi_long ret; + + trace_target_mmap(start, len, target_prot, flags, fd, offset); + mmap_lock(); + + ret = target_mmap__locked(start, len, target_prot, flags, fd, offset); + mmap_unlock(); - return -1; + return ret; } static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) From patchwork Thu Feb 22 20:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=XwPez6m+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tgldg0GKDz23l1 for ; Fri, 23 Feb 2024 07:50:15 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvI-0007XR-00; Thu, 22 Feb 2024 15:44:04 -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 1rdFvE-0007PE-KU for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:00 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvC-0002ie-Hs for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:00 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dbf1fe91fcso492055ad.3 for ; Thu, 22 Feb 2024 12:43:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634637; x=1709239437; 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=48MAJNKY8itF/Uvxdy9leMjwL6Lq94BoHatvMOlA6tE=; b=XwPez6m+ao/Dw3QS8JcMSGkKzWjx80/oQytGgHK2J8BKZCgdKCbfxy0wRwfhaW/7rb npoKdNIVCu99riSQPSfVw7TpU5sYyPVp21CnhwLSv5ey+7h6m07sCqWM3o2nm3/UP+l7 cTcXDTar9xuTD7fFUHIo3lup8nYAxiQxxsLugOJFYfikkkHMmMRc3wkvEZBSou6q/ONu UWeOtIT8VpbD3Fn04nfAjPwv7qgNks1rY4BHEyPr/DlgNVl7+1ltgGYHNvIg/aTtUHfn qZuqjlFtGFKXb+xm+p7JhAqFbs+vdl07ml+vRPOI56++OSf9RoCR/AHkb/J6OeDzpJLL 6e3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634637; x=1709239437; 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=48MAJNKY8itF/Uvxdy9leMjwL6Lq94BoHatvMOlA6tE=; b=Nq7b5AqhHGge51l/gUT319TDu4rlUOJELp8pcNM3uaGF/jSqepywHAFx5P1GpPx4Te mpH7aTeEPPVq1SyE3PcF1XbuUmG+fCJIa8tBg3k1q4G0/Dqyo8BazwTUWl67hs2cep9V YCTj+Qmiemp71r58/p3dazCBL41X5JYnxHGNJyDUk3KMDJfFnHChHh+McXgA1PvA0itR r6LsY4EfsFGvdOupQymvdS5i/VS1tUFoW0OkF1wCMzE9mW9/Q746LCvrO099etMYfzmw 8ygfZdPwIZoAeEW2iJB8JV3Aljtp7MWBUV3DNpNeX1mOLZxX1sQEC7ki9STiOwZQk/3B Vq1Q== X-Gm-Message-State: AOJu0Yz5ig/oNgwy5gV6u8Qxmr1Y3Tjp4B9ZKzg4WDqI0ed/1BuYgEc6 Atknpl4vBmQuQbSwvtPVa6R8noy/dEFQP9oKPMetZs2r/buJd3iYFRIWF4BF/5ABuT//KqpKZZ6 0 X-Google-Smtp-Source: AGHT+IFf3ay4fTeQQSa0LltVzFNHuf0JrjYlLsxRzEJl9iCH8bCvqOz/5ikRRAUH88sejUUxG1MHig== X-Received: by 2002:a17:903:286:b0:1db:c743:4687 with SMTP id j6-20020a170903028600b001dbc7434687mr19867029plr.1.1708634637332; Thu, 22 Feb 2024 12:43:57 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 20/39] linux-user: Move some mmap checks outside the lock Date: Thu, 22 Feb 2024 10:43:04 -1000 Message-Id: <20240222204323.268539-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Basic validation of operands does not require the lock. Hoist them from target_mmap__locked back into target_mmap. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-18-richard.henderson@linaro.org> --- linux-user/mmap.c | 107 +++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index b4c3cc65aa..fbaea832c5 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -491,52 +491,14 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, - int target_prot, int flags, + int target_prot, int flags, int page_flags, int fd, off_t offset) { int host_page_size = qemu_real_host_page_size(); abi_ulong ret, last, real_start, real_last, retaddr, host_len; abi_ulong passthrough_start = -1, passthrough_last = 0; - int page_flags; off_t host_offset; - if (!len) { - errno = EINVAL; - return -1; - } - - page_flags = validate_prot_to_pageflags(target_prot); - if (!page_flags) { - errno = EINVAL; - return -1; - } - - /* Also check for overflows... */ - len = TARGET_PAGE_ALIGN(len); - if (!len) { - errno = ENOMEM; - return -1; - } - - if (offset & ~TARGET_PAGE_MASK) { - errno = EINVAL; - return -1; - } - - /* - * If we're mapping shared memory, ensure we generate code for parallel - * execution and flush old translations. This will work up to the level - * supported by the host -- anything that requires EXCP_ATOMIC will not - * be atomic with respect to an external process. - */ - if (flags & MAP_SHARED) { - CPUState *cpu = thread_cpu; - if (!(cpu->tcg_cflags & CF_PARALLEL)) { - cpu->tcg_cflags |= CF_PARALLEL; - tb_flush(cpu); - } - } - real_start = start & -host_page_size; host_offset = offset & -host_page_size; @@ -616,23 +578,9 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, passthrough_start = start; passthrough_last = last; } else { - if (start & ~TARGET_PAGE_MASK) { - errno = EINVAL; - return -1; - } last = start + len - 1; real_last = ROUND_UP(last, host_page_size) - 1; - /* - * Test if requested memory area fits target address space - * It can fail only on 64-bit host with 32-bit target. - * On any other target/host host mmap() handles this error correctly. - */ - if (last < start || !guest_range_valid_untagged(start, len)) { - errno = ENOMEM; - return -1; - } - if (flags & MAP_FIXED_NOREPLACE) { /* Validate that the chosen range is empty. */ if (!page_check_range_empty(start, last)) { @@ -778,13 +726,64 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, off_t offset) { abi_long ret; + int page_flags; trace_target_mmap(start, len, target_prot, flags, fd, offset); + + if (!len) { + errno = EINVAL; + return -1; + } + + page_flags = validate_prot_to_pageflags(target_prot); + if (!page_flags) { + errno = EINVAL; + return -1; + } + + /* Also check for overflows... */ + len = TARGET_PAGE_ALIGN(len); + if (!len || len != (size_t)len) { + errno = ENOMEM; + return -1; + } + + if (offset & ~TARGET_PAGE_MASK) { + errno = EINVAL; + return -1; + } + if (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) { + if (start & ~TARGET_PAGE_MASK) { + errno = EINVAL; + return -1; + } + if (!guest_range_valid_untagged(start, len)) { + errno = ENOMEM; + return -1; + } + } + mmap_lock(); - ret = target_mmap__locked(start, len, target_prot, flags, fd, offset); + ret = target_mmap__locked(start, len, target_prot, flags, + page_flags, fd, offset); mmap_unlock(); + + /* + * If we're mapping shared memory, ensure we generate code for parallel + * execution and flush old translations. This will work up to the level + * supported by the host -- anything that requires EXCP_ATOMIC will not + * be atomic with respect to an external process. + */ + if (ret != -1 && (flags & MAP_TYPE) != MAP_PRIVATE) { + CPUState *cpu = thread_cpu; + if (!(cpu->tcg_cflags & CF_PARALLEL)) { + cpu->tcg_cflags |= CF_PARALLEL; + tb_flush(cpu); + } + } + return ret; } From patchwork Thu Feb 22 20:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=O4OP+juH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglfd2qbQz23l1 for ; Fri, 23 Feb 2024 07:51:05 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvK-0007Zd-5p; Thu, 22 Feb 2024 15:44:06 -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 1rdFvF-0007R6-Tp for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:02 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvE-0002ik-A4 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:01 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e4751b97eeso60704b3a.1 for ; Thu, 22 Feb 2024 12:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634639; x=1709239439; 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=aJy5WaQ99ApNqzP+t8EteVWeLJYZZHFF49xziucGjOo=; b=O4OP+juH4k/OmXO5yZxWjdIeFFQcilPrteiC49Pb2FvpG/Cay7gvm5zP3cfHrVMnnJ vDSkdvlNNi9To+FFHERq9yWRQ4g3H4QJICru6JioprVyHFkVnbF6fMBM1Nggjs6C/Zjj qD2FDF6JZrO/gNTQDKYBBC89X/5VrE9DB54LuUhhalyeVB1UXTDvVg5GkO18/uDx+ncM oZfN3urRb74CyRN0+PJ1KLdGgimkiDhAiN8T7n6Y3aMLXB0oSK7CtZlwIQsoz3Xy/m52 2BQRBEe4PKxuAPA7REwuKI4W8YHh6xLrTRivqE9Hw2/gSnRei4qp+jcn83oDRXJeEgw+ n4iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634639; x=1709239439; 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=aJy5WaQ99ApNqzP+t8EteVWeLJYZZHFF49xziucGjOo=; b=h9nIT442NE/BFTOpAGhtV2JjHSrAUEhli6k0lfJ8RS5I84YoSuSv+YhliKowfkzXvv L7QaYugGJOmacXKLcq0jkwyC/RLGGYraVqGh3uv+46XUzzImoCPwOFlsa2kmC/whGrTa JpIa/C3YXlsT4yWBkLEUS+SNNlJ/VflZ0heyzMJzCzNE4+puXRw7k2sTsv2rj9poHk/e rtN88yi/9vEDW4NScgfP034lLhEavHkmv7HHo4s/8n9bSYlfh8hjnmh1ITe8OHiSTj/Z LLViZKYfyHIF6i92v9XyvwsM936KEVc+/keczUTtnLIJZEl3R0rPErW8WbLn3ObpGTRc kNrg== X-Gm-Message-State: AOJu0YwpchpdSSfZY5tnQWHhD24ijSpZY5L15SrqfaHPYQV1H8PAOTWO BznbfnHf6nfUcqIolFYMhr8vxKNgzIRf978QCmuuKHXsqF/G6laOTJBTAlIEJPebnzAZQG8MbPH 9 X-Google-Smtp-Source: AGHT+IEzgNeSB9iEL73eJ6vutCstagS3fngCXf18kC2Ur9HNZ2WlFC9k2DkXFaWM7wkL/g7XuTHITQ== X-Received: by 2002:a05:6a20:9d94:b0:1a0:cd54:6d9f with SMTP id mu20-20020a056a209d9400b001a0cd546d9fmr4859887pzb.23.1708634638728; Thu, 22 Feb 2024 12:43:58 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 21/39] linux-user: Fix sub-host-page mmap Date: Thu, 22 Feb 2024 10:43:05 -1000 Message-Id: <20240222204323.268539-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We cannot skip over the_end1 to the_end, because we fail to record the validity of the guest page with the interval tree. Remove "the_end" and rename "the_end1" to "the_end". Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-19-richard.henderson@linaro.org> --- linux-user/mmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index fbaea832c5..48fcdd4a32 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -643,7 +643,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, target_prot, flags, fd, offset)) { return -1; } - goto the_end1; + goto the_end; } if (!mmap_frag(real_start, start, real_start + host_page_size - 1, @@ -690,7 +690,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, passthrough_last = real_last; } } - the_end1: + the_end: if (flags & MAP_ANONYMOUS) { page_flags |= PAGE_ANON; } @@ -708,7 +708,6 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, } } shm_region_rm_complete(start, last); - the_end: trace_target_mmap_complete(start); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { FILE *f = qemu_log_trylock(); From patchwork Thu Feb 22 20:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902952 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HtCZcS4r; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglW116bSz23nM for ; Fri, 23 Feb 2024 07:44:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvL-0007dJ-US; Thu, 22 Feb 2024 15:44:07 -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 1rdFvJ-0007ZV-W6 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:06 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvF-0002j6-C1 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:05 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dc1ff697f9so1996555ad.0 for ; Thu, 22 Feb 2024 12:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634640; x=1709239440; 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=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; b=HtCZcS4rnN0CRbolkLyb4UyZcW2xUNSay+3Pi0LecdOx09YpEOA0cFus3hGwRT3R9L 9R0d35j8/IPbr/vjQNrFNhznoTccB/5pM7l7C8lQkNDm0f0ghs8X+8KB/NCCZVlB3kac UHeHTfq58UFpzXXkFxJpmngPU5rvaaS3BAnUpmB+Zp7S70rdWP2BHCVBYguooSMmwv1z BOUZVerM+xt+EXD14EtW+4owSLgW/QStRJfqeW7DZTLh5HQa5HFRzXcPgLuvK8tRP2G+ ropee1sRsybOxO8t/r47aaUJqfvFVKBIo9UR2UuVNALeRhCB5SMB/lVc2XRabYLHXMve p1Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634640; x=1709239440; 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=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; b=xNUrLYXkcD/EAIXvVQg2LqFYniOs7PkIGlOgH8PHoknKC/9/HPw5f4AcRExbivePen MqgkZ3PndXhnyeV9SlMRR9bSRgshKMP3xDokYlfqlJyC61QNcCe5dvZWLw8oCrifmR6k JrT0fcUMuzCnCZuBaTRgLFqMEwN0eEpUt1+ObPdHSaMnAAdAirOZ0lcJlqwBVK4X8ifs x+vTFTqZ6SSIK2L4C4e+xOvo6+N7iwpKGRcfZwBWOeU68Xjfd3ZgffeWxcXd5cadL+nz paSpBPHCI3fDJ54Kkf84KVkjjPTt+QusYSCWNpo/pAOu1ywY4RxWrbrcDFZR7Ay0uCys 9Z1A== X-Gm-Message-State: AOJu0YwWsiVR142DWP0OSJ9/6fG3Wd+pBFFt4YBifDOvnETXS+AzUUv3 3iIeSSizLrA/1+Y3M6V7wXwPkaH3/ZVewbLmHAgc9D58E/RDRjfFqCAZVKZ16NUD6B9FWg4tGdv k X-Google-Smtp-Source: AGHT+IEQGIDVz2f2V1KJKPufMFaDh4njKgljOg58FS8lNAbMbimtmlEMz5vedB+yCXP1hfP5+X6qLg== X-Received: by 2002:a17:903:1c4:b0:1dc:685d:f0e2 with SMTP id e4-20020a17090301c400b001dc685df0e2mr379596plh.12.1708634640167; Thu, 22 Feb 2024 12:44:00 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:43:59 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 22/39] linux-user: Split out mmap_end Date: Thu, 22 Feb 2024 10:43:06 -1000 Message-Id: <20240222204323.268539-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use a subroutine instead of a goto within target_mmap__locked. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-20-richard.henderson@linaro.org> --- linux-user/mmap.c | 71 +++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 48fcdd4a32..cc983bedbd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -490,6 +490,43 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } } +/* + * Record a successful mmap within the user-exec interval tree. + */ +static abi_long mmap_end(abi_ulong start, abi_ulong last, + abi_ulong passthrough_start, + abi_ulong passthrough_last, + int flags, int page_flags) +{ + if (flags & MAP_ANONYMOUS) { + page_flags |= PAGE_ANON; + } + page_flags |= PAGE_RESET; + if (passthrough_start > passthrough_last) { + page_set_flags(start, last, page_flags); + } else { + if (start < passthrough_start) { + page_set_flags(start, passthrough_start - 1, page_flags); + } + page_set_flags(passthrough_start, passthrough_last, + page_flags | PAGE_PASSTHROUGH); + if (passthrough_last < last) { + page_set_flags(passthrough_last + 1, last, page_flags); + } + } + shm_region_rm_complete(start, last); + trace_target_mmap_complete(start); + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + FILE *f = qemu_log_trylock(); + if (f) { + fprintf(f, "page layout changed following mmap\n"); + page_dump(f); + qemu_log_unlock(f); + } + } + return start; +} + static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, int target_prot, int flags, int page_flags, int fd, off_t offset) @@ -632,7 +669,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, ret = target_mprotect(start, len, target_prot); assert(ret == 0); } - goto the_end; + return mmap_end(start, last, -1, 0, flags, page_flags); } /* handle the start of the mapping */ @@ -643,7 +680,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, target_prot, flags, fd, offset)) { return -1; } - goto the_end; + return mmap_end(start, last, -1, 0, flags, page_flags); } if (!mmap_frag(real_start, start, real_start + host_page_size - 1, @@ -690,34 +727,8 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, passthrough_last = real_last; } } - the_end: - if (flags & MAP_ANONYMOUS) { - page_flags |= PAGE_ANON; - } - page_flags |= PAGE_RESET; - if (passthrough_start > passthrough_last) { - page_set_flags(start, last, page_flags); - } else { - if (start < passthrough_start) { - page_set_flags(start, passthrough_start - 1, page_flags); - } - page_set_flags(passthrough_start, passthrough_last, - page_flags | PAGE_PASSTHROUGH); - if (passthrough_last < last) { - page_set_flags(passthrough_last + 1, last, page_flags); - } - } - shm_region_rm_complete(start, last); - trace_target_mmap_complete(start); - if (qemu_loglevel_mask(CPU_LOG_PAGE)) { - FILE *f = qemu_log_trylock(); - if (f) { - fprintf(f, "page layout changed following mmap\n"); - page_dump(f); - qemu_log_unlock(f); - } - } - return start; + return mmap_end(start, last, passthrough_start, passthrough_last, + flags, page_flags); } /* NOTE: all the constants are the HOST ones */ From patchwork Thu Feb 22 20:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ToZF6eZm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglft3tjyz23l1 for ; Fri, 23 Feb 2024 07:51:18 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvK-0007Zz-AD; Thu, 22 Feb 2024 15:44:06 -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 1rdFvI-0007Xq-KY for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:04 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvG-0002jP-WC for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:04 -0500 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so194343a12.0 for ; Thu, 22 Feb 2024 12:44:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634641; x=1709239441; 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=ZykOOhGWRLaDSZ6ojBtzy1ZtPjktUdeyK8bHHdP5Cx0=; b=ToZF6eZmeo0VzJRBOSANiVU9rNopyEErWWxC6hpA+ZwsTpzaKEVHPSEpdwzx2ZS6ks qEo1SbEgDgpj4W0CSM9V3+WxMGB3q+Yem49PmKnNLU81Z1RAxL31zsSFtzGZUINMbYLS JqDQj59zEtWXbnIrEykS8VWziCspwa11vLG87dN5ZH8jI7jV4odlcElx31VmA4TH/Fpj dZlFVxwcYd/moaVQWPX3f4+mB3g7FJYUt6iEo2ZteNJsLnDFN4jCrvx/1ScHV2q6xLjY o2vglr7jJUqCmLAWJGb/SOK2K82tBhPl3GPCrIwRoQiRoxpUUY+FkYRuDn/L9+HHA0ji y7Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634641; x=1709239441; 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=ZykOOhGWRLaDSZ6ojBtzy1ZtPjktUdeyK8bHHdP5Cx0=; b=ea0FfmPtGGKjiOHvv8xhbyPN94kaa/3Nyz+ED9deSQpwGG7fJ4eINw/Miq41hxl7u4 Btj8GV1z6fC6GVEBEFmSUI2a/6Wc5jyWrvNxU0AmNZw1WQSl03AqH3SyHu67TMhxoGLu 40l38AO3awEZqiUSNStOqCA+REzfF2f+AQxIHCPX4IQZrxpMTry8E2lzpejj0CcO5694 NLV1AgS4Lea0z/uVM+bav6E+0IMU7LcdhJcl7Ovq9zD+E41RkpwV+NUog3phssDZ2hxf WKqCeLNfm4YEtSnVmNNPenpJaiHVGTNKwYzZFFtOvoHwZ+ADe6f5zKUVmpBsWXewqoWO Bicw== X-Gm-Message-State: AOJu0YyZiARAj4dFrQaIkc3OSERp1IVRhnSVZm3OqMrEBinmpDJ+NRJT dXl2qV0uz9ZTesfssrWIQWcq1/T3LOjxaltyrCxOHtMhJiVtXQfl6GDlKaXFXkk4TmDqZJfZt/a k X-Google-Smtp-Source: AGHT+IFnVLLQSzQNJh53u4pqPvXtdjSGv0LEG5cfEwN9Tnmtoo9Mf6CgVpDh9rzgZ1hwXkUOcJIo/Q== X-Received: by 2002:a17:902:f545:b0:1d9:e1aa:f217 with SMTP id h5-20020a170902f54500b001d9e1aaf217mr146740plf.22.1708634641623; Thu, 22 Feb 2024 12:44:01 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 23/39] linux-user: Do early mmap placement only for reserved_va Date: Thu, 22 Feb 2024 10:43:07 -1000 Message-Id: <20240222204323.268539-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For reserved_va, place all non-fixed maps then proceed as for MAP_FIXED. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-21-richard.henderson@linaro.org> --- linux-user/mmap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index cc983bedbd..1bbfeb25b1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -540,17 +540,19 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, host_offset = offset & -host_page_size; /* - * If the user is asking for the kernel to find a location, do that - * before we truncate the length for mapping files below. + * For reserved_va, we are in full control of the allocation. + * Find a suitable hole and convert to MAP_FIXED. */ - if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + if (reserved_va && !(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { host_len = len + offset - host_offset; - host_len = ROUND_UP(host_len, host_page_size); - start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); + start = mmap_find_vma(real_start, host_len, + MAX(host_page_size, TARGET_PAGE_SIZE)); if (start == (abi_ulong)-1) { errno = ENOMEM; return -1; } + start += offset - host_offset; + flags |= MAP_FIXED; } /* From patchwork Thu Feb 22 20:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ltjVkg6Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tgldk3bpWz23l1 for ; Fri, 23 Feb 2024 07:50:18 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvN-0007ep-Rq; Thu, 22 Feb 2024 15:44:09 -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 1rdFvM-0007dQ-2W for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:08 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvK-0002jz-Dc for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:07 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e46dcd8feaso33295b3a.2 for ; Thu, 22 Feb 2024 12:44:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634643; x=1709239443; 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=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; b=ltjVkg6ZCBwum9isc65AA08IAdjByq17DfWWHgS+EoYnEo/zPiA+cGN95RBzLRugjC nxkdixDaVsDY2mNl9/tPoEU/U+T8TS0I+rVdRyqqvcaKzr2aGEkf41qgMUHB6yZCtUKt GojdiES3m9byY9BTrBPD1I7yhC6mCdvfcpFpB6nqgtGzxn2tDfueKMFrd4o38v8EWuFL cEcaQuWx7mjynmemFDRQuM3it6LAL7KRe6bsVgAJ7RwO9OgoIv4nyNXrY83FSmox88x+ baZXUu96SZDZhlB3PN3tuTTnru+U0CW+lr/pCaQdqUweBSxpg6D1j+KR0/9kSwxM48bk HLzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634643; x=1709239443; 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=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; b=GNlwLoPOHPA+cSup2DMl2UpOd2ZS51LY5Sq+5CKM6cDT8VkZCQ30MBJ9n0bQY04uzQ 2Scp3rXnbXcwul9fpOMYy4S3HHtJZ3T+FR3PtbgZKTX7Xs1i1Opc2MeNE0mPQHbIVrkG qZnb7Mdcewhr6X86VyVpPDHt+qQLT1tWNIDvkknLMi5QIA0ki0RcYnfwrSJPJ3TolZyN 5mZC8m6cG97IDXYWRuTlM5ZeyI1GcKWK4acFqE1mTDcSanklwmHuggzY6im7QGWYETkG QYRP4cOMRptF5bSEZ2G7aCBkLyvrZpyHXmp/ktn9xBgaxDE9rTlLAMg0LLvTz99SDKfn 5rnQ== X-Gm-Message-State: AOJu0YxRI8Coa3defe6N8W9J23VYlpcpN2sa3ObECRi14EH5Dt32NNH/ j46kmamSvqh/lBBPmw9AesSGtsFxOg+5wllmTBjhcVldRqFkuL4ELjqzOanVq0PPZtMh7lLuRCF c X-Google-Smtp-Source: AGHT+IFrHlkwexOK0vx8DQG+hs+3FnEgJusKWw+l9An1A48F1MSa43PjNFkrB79bTUfu9AdF0WcSCw== X-Received: by 2002:a17:902:9006:b0:1db:717e:d8ff with SMTP id a6-20020a170902900600b001db717ed8ffmr23933279plp.69.1708634643141; Thu, 22 Feb 2024 12:44:03 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:02 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 24/39] linux-user: Split out do_munmap Date: Thu, 22 Feb 2024 10:43:08 -1000 Message-Id: <20240222204323.268539-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mmap.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 1bbfeb25b1..8ebcca4444 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -267,6 +267,21 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) return ret; } +/* + * Perform munmap on behalf of the target, with host parameters. + * If reserved_va, we must replace the memory reservation. + */ +static int do_munmap(void *addr, size_t len) +{ + if (reserved_va) { + void *ptr = mmap(addr, len, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS + | MAP_PRIVATE | MAP_NORESERVE, -1, 0); + return ptr == addr ? 0 : -1; + } + return munmap(addr, len); +} + /* map an incomplete host page */ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, int prot, int flags, int fd, off_t offset) @@ -854,13 +869,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) real_len = real_last - real_start + 1; host_start = g2h_untagged(real_start); - if (reserved_va) { - void *ptr = mmap(host_start, real_len, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS - | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - return ptr == host_start ? 0 : -1; - } - return munmap(host_start, real_len); + return do_munmap(host_start, real_len); } int target_munmap(abi_ulong start, abi_ulong len) From patchwork Thu Feb 22 20:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902959 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=QG8/g7yv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglXG4lT5z23d2 for ; Fri, 23 Feb 2024 07:45:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvM-0007dy-Jw; Thu, 22 Feb 2024 15:44: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 1rdFvL-0007cE-8U for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:07 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvJ-0002kB-OB for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:07 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1dbae7b8ff2so1561925ad.3 for ; Thu, 22 Feb 2024 12:44:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634644; x=1709239444; 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=qMAzWUeeNJh47c4bkyOP/O/3UzvTHZWrc2G+MJg3FB0=; b=QG8/g7yvT+2v+FhhKtUPWtN34FEgxi2jLwF7nmB0aZs+YN7mG8taaRQjOjopBxGE9C eNI0cen+X2wB113lcF56aJdA9MEBD8UlhOnDN9t4Gm893C2Ijxmey+dd1pyAMBmfWBrt mCRE4dUcs/fPRFmHP64ULPZ8SPhc09dn5v5Rt/afeHkkLe83Whtb0cybAdp2AW6YoI/N ymITuXaqdHUn4uijOjqIy/s4MXyyAt4Ehpj5LD6dUlnQ8kChCy0ZVzAGWsm7UBRZe+6p P+utZwY9Uz2lH8NDqadSm8Ds6+LzJ6FucBVOpYYnCZhRmhsDol4WjunWdVCuPEsPAdTE ZfMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634644; x=1709239444; 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=qMAzWUeeNJh47c4bkyOP/O/3UzvTHZWrc2G+MJg3FB0=; b=FiB72rNP+r4U1gjrD7yMM/YQJ3cE6w2vLn7/k77Kbrm5QsFx3drQ4MS3ehD7sVkiss gu1lq14zhcPd6WdUC5oG1Y5iHu2xwZ+8Wk46l+Oeq7xIEo42JBjDiJnY+0uIlQkO3qBr Y8e3TIwBjhvYEeZWgUYmHTC5SSyiacUd3ekADmqUhH7jrf8kKLZUkHXGr2o6D7YbudmP 424Co8yGKBzppiFLD6FcUkrpTxVUyyl4TDqhgYcq8e/jt+v/sveh7bS6iHK0wsNjqvDh w0mZint3w9e4Q12DtNJ6WP96Sg6wB+76sACLp4vy61wrdyvFL5GpVq8m+R1aqoa7pmvc opig== X-Gm-Message-State: AOJu0Yw140J4JZ2pmiopuDFdLmRm0UDXY7U4zhndjXB9FoIuthlNvlEh 6OlQ4wjr4ry1DRma5venVaYrLlkL52sz7NzNftG0RdiEEuKFG411VlbPLMop11EhStBeDS88SdE p X-Google-Smtp-Source: AGHT+IFu5GjrHgItmCuhEUfHdFVm5SJvy2RHOWhOQzC6co8WwHNhTsSXE5cyCQmfHS/U6nKKkowzkA== X-Received: by 2002:a17:903:41c9:b0:1dc:38c7:ba1a with SMTP id u9-20020a17090341c900b001dc38c7ba1amr6134454ple.25.1708634644363; Thu, 22 Feb 2024 12:44:04 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:04 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 25/39] linux-user: Use do_munmap for target_mmap failure Date: Thu, 22 Feb 2024 10:43:09 -1000 Message-Id: <20240222204323.268539-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For the cases for which the host mmap succeeds, but does not yield the desired address, use do_munmap to restore the reserved_va memory reservation. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 8ebcca4444..cbcd31e941 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -326,7 +326,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, flags | MAP_ANONYMOUS, -1, 0); if (p != host_start) { if (p != MAP_FAILED) { - munmap(p, host_page_size); + do_munmap(p, host_page_size); errno = EEXIST; } return false; @@ -622,7 +622,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, p = mmap(g2h_untagged(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); if (p == MAP_FAILED) { - munmap(g2h_untagged(start), host_len); + do_munmap(g2h_untagged(start), host_len); return -1; } host_start += offset - host_offset; @@ -735,7 +735,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, flags, fd, offset1); if (p != want_p) { if (p != MAP_FAILED) { - munmap(p, len1); + do_munmap(p, len1); errno = EEXIST; } return -1; From patchwork Thu Feb 22 20:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=VIhlhAbp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYG105cz23nM for ; Fri, 23 Feb 2024 07:46:26 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvO-0007f3-KD; Thu, 22 Feb 2024 15:44:10 -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 1rdFvM-0007eF-Vl for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:09 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvL-0002kO-7l for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:08 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc1ff697f9so1997345ad.0 for ; Thu, 22 Feb 2024 12:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634646; x=1709239446; 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=F+mIi8OQkXxgV79040kdu3+FCdCNzpLRNnazUCypFlE=; b=VIhlhAbpL5iXGhnY5rZzpRWNY0dB9c7JHJjo5RkstGK5cE4Bt5jyppMQ/pvhDrPtos z2TT3rykEwUpzs8aiUz9GAUnRAkF5rsMMsaWjYzajz5somxEA3T+bvEZBPJT1vL9RsT7 SLOKQO5oH1I/j6gbasbs+1f5korRVytoEsXB+5oT6oCljXjIn5LDOcBCMirz5WE/1QnZ cbfl1xGuyU1sl+oxEE5TTsp2jfIRobDdEp9MlomipAUcKxiFI3sD36meSYxRIN2Y59Jq sN+znUNHvawe8tgzjWS+0sEQqbK31OotNBmAUIHgY93h2/TIsXVjiu8WSvvtK8n0fj4+ aTBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634646; x=1709239446; 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=F+mIi8OQkXxgV79040kdu3+FCdCNzpLRNnazUCypFlE=; b=Vhun6DuD4lGQuoiZYWrQguxFEosSz2PTewynWQ57eOJC0BUjjd9qiUryCvyJs+LOHo fMr8arYHhAd7WunroH+98Winvn26a/uPSOpSwiIl7L29M4gkBW5NNfd1tX1jO+eS8/Qf oQbLIlgeyaxCg9O2cs1H2VDSFXH2PGhS6dthQsucC+cc3JeTv5eKAXVhCcOBQ29eutv8 gy4m5EZBBrAyxWry1jTBuP3FXTM23/EozqpuVlw/bu3Kk1pU+YC5YNrWwkW5AIvLAbS9 tMKo36IX3enNS+ijTPoTGZr/F/cm+nBxa2uJczeiub7PwIcHH8OmdKgJ3f/FG7YeBMGq ULHg== X-Gm-Message-State: AOJu0YzvljaFM8fmmrC/deYpDWDU7H7X0LToisA2TzXgtIa+yn2s6TYB 0RTUfnHFvAlIfW0S8r3D2WcCA8fhY74eVQj1oqXT5SkI0z6QZHTojMIK36dILMBXV3VWZ+jKdTo e X-Google-Smtp-Source: AGHT+IGJQXINA+zntUgjfujiTO13Tk5er0M2KLyX3IG0XVpHUc1nAnPiwOxBID8VRbC4M2mZ5zlvnA== X-Received: by 2002:a17:903:1105:b0:1d9:8832:f800 with SMTP id n5-20020a170903110500b001d98832f800mr25026852plh.8.1708634645785; Thu, 22 Feb 2024 12:44:05 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:05 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 26/39] linux-user: Split out mmap_h_eq_g Date: Thu, 22 Feb 2024 10:43:10 -1000 Message-Id: <20240222204323.268539-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move the MAX_FIXED_NOREPLACE check for reserved_va earlier. Move the computation of host_prot earlier. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-22-richard.henderson@linaro.org> --- linux-user/mmap.c | 68 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index cbcd31e941..d3556bcc14 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -542,6 +542,33 @@ static abi_long mmap_end(abi_ulong start, abi_ulong last, return start; } +/* + * Special case host page size == target page size, + * where there are no edge conditions. + */ +static abi_long mmap_h_eq_g(abi_ulong start, abi_ulong len, + int host_prot, int flags, int page_flags, + int fd, off_t offset) +{ + void *p, *want_p = g2h_untagged(start); + abi_ulong last; + + p = mmap(want_p, len, host_prot, flags, fd, offset); + if (p == MAP_FAILED) { + return -1; + } + /* If the host kernel does not support MAP_FIXED_NOREPLACE, emulate. */ + if ((flags & MAP_FIXED_NOREPLACE) && p != want_p) { + do_munmap(p, len); + errno = EEXIST; + return -1; + } + + start = h2g(p); + last = start + len - 1; + return mmap_end(start, last, start, last, flags, page_flags); +} + static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, int target_prot, int flags, int page_flags, int fd, off_t offset) @@ -550,6 +577,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, abi_ulong ret, last, real_start, real_last, retaddr, host_len; abi_ulong passthrough_start = -1, passthrough_last = 0; off_t host_offset; + int host_prot; real_start = start & -host_page_size; host_offset = offset & -host_page_size; @@ -558,16 +586,33 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, * For reserved_va, we are in full control of the allocation. * Find a suitable hole and convert to MAP_FIXED. */ - if (reserved_va && !(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { - host_len = len + offset - host_offset; - start = mmap_find_vma(real_start, host_len, - MAX(host_page_size, TARGET_PAGE_SIZE)); - if (start == (abi_ulong)-1) { - errno = ENOMEM; - return -1; + if (reserved_va) { + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, start + len - 1)) { + errno = EEXIST; + return -1; + } + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } else if (!(flags & MAP_FIXED)) { + size_t real_len = len + offset - host_offset; + abi_ulong align = MAX(host_page_size, TARGET_PAGE_SIZE); + + start = mmap_find_vma(real_start, real_len, align); + if (start == (abi_ulong)-1) { + errno = ENOMEM; + return -1; + } + start += offset - host_offset; + flags |= MAP_FIXED; } - start += offset - host_offset; - flags |= MAP_FIXED; + } + + host_prot = target_to_host_prot(target_prot); + + if (host_page_size == TARGET_PAGE_SIZE) { + return mmap_h_eq_g(start, len, host_prot, flags, + page_flags, fd, offset); } /* @@ -603,12 +648,10 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { uintptr_t host_start; - int host_prot; void *p; host_len = len + offset - host_offset; host_len = ROUND_UP(host_len, host_page_size); - host_prot = target_to_host_prot(target_prot); /* Note: we prefer to control the mapping address. */ p = mmap(g2h_untagged(start), host_len, host_prot, @@ -731,8 +774,7 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, len1 = real_last - real_start + 1; want_p = g2h_untagged(real_start); - p = mmap(want_p, len1, target_to_host_prot(target_prot), - flags, fd, offset1); + p = mmap(want_p, len1, host_prot, flags, fd, offset1); if (p != want_p) { if (p != MAP_FAILED) { do_munmap(p, len1); From patchwork Thu Feb 22 20:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=vYcoB7I+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglZZ4f7Nz23d2 for ; Fri, 23 Feb 2024 07:47:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvQ-0007gf-Fr; Thu, 22 Feb 2024 15:44: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 1rdFvO-0007f9-NN for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:10 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvM-0002kt-P2 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:10 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dba94f9201so2033125ad.0 for ; Thu, 22 Feb 2024 12:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634647; x=1709239447; 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=I4UwZkIS26PhKHP+iY1jWw6KRSEUK2Dc0FNGbwDM3y4=; b=vYcoB7I+svat1gp4rABqsuXPL7k+lOamSGb8G5j4P25bOA9yiZv8V1cKvbpRcz7+I3 OVGgN+t7VUvMWtjICIH57xLuN30mv+PQRGgNCjkUFHkwl4pIxST2qOSTZcgvD6QxUjiS QCUV6fY1HgJ2QKvMMfO0Kvq/lThYiGkbUsnJmun4N72SYnVaT5TwOzrfWpGP4EZYqduJ e/vVL7TdF2WKzQB5jwuNyXdeIgB//2zajH9YA4wnbzBf3jUkusym84FvcwmFKUmcgiAu bUninxD2ghcTbD4n/Kt7olQkjX4smCSdWmhUvO7XXIvhruJp+kSNELsgm7Ap0uO9KST+ IJyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634647; x=1709239447; 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=I4UwZkIS26PhKHP+iY1jWw6KRSEUK2Dc0FNGbwDM3y4=; b=HUXX2vDcaWOJ4x+aNHm5VBCC9BuXd/XEV5CgLLD1UqvBi7JMGTGeRKrgUsYzx8BvhL 5HQSCMMjZN7jQHZ/PiMIOG26mZd2JLSxo4eFY5rOTXtpqdywYbgPF5bycBFXohsZZ3fu 0reK+aCMU3udl4m4dOGU7924y8YWK24Fp5CwXvTHCe1I4hrDPpafsDdvG/xI3QyFNrPx kWiOazmf8M5clQZusteW7cBf47sHlf4nuSim1j6YWRfKR29Lk0UNlLaUMNZ960JRkESh Gten/gwqNmby1QdauBJCxAcgeQZhB93EKH2HKu6peLxkdLchT/PLvn8W6nXhIDTrV3A1 oedw== X-Gm-Message-State: AOJu0Yyml2BX/GucMrDSo4hZLQDdXQaupQXqLHRn6y8ekP/VaO530XmI EtzPOsqL2oFSbyXFMq85tD4EftZCM6aiSEpySUKIkhg9I/RS7bCFT97MmT9NVeBqi8tTODiJIrJ R X-Google-Smtp-Source: AGHT+IF+l4iOQG0U0BFS83Mb/VCge+6IS/YLjeVIjqf6v3eoetL/Z/MNs5oCnM3RhCKyYqWuOsBAVQ== X-Received: by 2002:a17:902:ecc1:b0:1dc:673:1932 with SMTP id a1-20020a170902ecc100b001dc06731932mr13462931plh.38.1708634647523; Thu, 22 Feb 2024 12:44:07 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 27/39] linux-user: Split out mmap_h_lt_g Date: Thu, 22 Feb 2024 10:43:11 -1000 Message-Id: <20240222204323.268539-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Work much harder to get alignment and mapping beyond the end of the file correct. Both of which are excercised by our test-mmap for alpha (8k pages) on any 4k page host. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-23-richard.henderson@linaro.org> --- linux-user/mmap.c | 184 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 153 insertions(+), 31 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d3556bcc14..ff8f9f7ed0 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -569,6 +569,156 @@ static abi_long mmap_h_eq_g(abi_ulong start, abi_ulong len, return mmap_end(start, last, start, last, flags, page_flags); } +/* + * Special case host page size < target page size. + * + * The two special cases are increased guest alignment, and mapping + * past the end of a file. + * + * When mapping files into a memory area larger than the file, + * accesses to pages beyond the file size will cause a SIGBUS. + * + * For example, if mmaping a file of 100 bytes on a host with 4K + * pages emulating a target with 8K pages, the target expects to + * be able to access the first 8K. But the host will trap us on + * any access beyond 4K. + * + * When emulating a target with a larger page-size than the hosts, + * we may need to truncate file maps at EOF and add extra anonymous + * pages up to the targets page boundary. + * + * This workaround only works for files that do not change. + * If the file is later extended (e.g. ftruncate), the SIGBUS + * vanishes and the proper behaviour is that changes within the + * anon page should be reflected in the file. + * + * However, this case is rather common with executable images, + * so the workaround is important for even trivial tests, whereas + * the mmap of of a file being extended is less common. + */ +static abi_long mmap_h_lt_g(abi_ulong start, abi_ulong len, int host_prot, + int mmap_flags, int page_flags, int fd, + off_t offset, int host_page_size) +{ + void *p, *want_p = g2h_untagged(start); + off_t fileend_adj = 0; + int flags = mmap_flags; + abi_ulong last, pass_last; + + if (!(flags & MAP_ANONYMOUS)) { + struct stat sb; + + if (fstat(fd, &sb) == -1) { + return -1; + } + if (offset >= sb.st_size) { + /* + * The entire map is beyond the end of the file. + * Transform it to an anonymous mapping. + */ + flags |= MAP_ANONYMOUS; + fd = -1; + offset = 0; + } else if (offset + len > sb.st_size) { + /* + * A portion of the map is beyond the end of the file. + * Truncate the file portion of the allocation. + */ + fileend_adj = offset + len - sb.st_size; + } + } + + if (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) { + if (fileend_adj) { + p = mmap(want_p, len, host_prot, flags | MAP_ANONYMOUS, -1, 0); + } else { + p = mmap(want_p, len, host_prot, flags, fd, offset); + } + if (p != want_p) { + if (p != MAP_FAILED) { + /* Host does not support MAP_FIXED_NOREPLACE: emulate. */ + do_munmap(p, len); + errno = EEXIST; + } + return -1; + } + + if (fileend_adj) { + void *t = mmap(p, len - fileend_adj, host_prot, + (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED, + fd, offset); + + if (t == MAP_FAILED) { + int save_errno = errno; + + /* + * We failed a map over the top of the successful anonymous + * mapping above. The only failure mode is running out of VMAs, + * and there's nothing that we can do to detect that earlier. + * If we have replaced an existing mapping with MAP_FIXED, + * then we cannot properly recover. It's a coin toss whether + * it would be better to exit or continue here. + */ + if (!(flags & MAP_FIXED_NOREPLACE) && + !page_check_range_empty(start, start + len - 1)) { + qemu_log("QEMU target_mmap late failure: %s", + strerror(save_errno)); + } + + do_munmap(want_p, len); + errno = save_errno; + return -1; + } + } + } else { + size_t host_len, part_len; + + /* + * Take care to align the host memory. Perform a larger anonymous + * allocation and extract the aligned portion. Remap the file on + * top of that. + */ + host_len = len + TARGET_PAGE_SIZE - host_page_size; + p = mmap(want_p, host_len, host_prot, flags | MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) { + return -1; + } + + part_len = (uintptr_t)p & (TARGET_PAGE_SIZE - 1); + if (part_len) { + part_len = TARGET_PAGE_SIZE - part_len; + do_munmap(p, part_len); + p += part_len; + host_len -= part_len; + } + if (len < host_len) { + do_munmap(p + len, host_len - len); + } + + if (!(flags & MAP_ANONYMOUS)) { + void *t = mmap(p, len - fileend_adj, host_prot, + flags | MAP_FIXED, fd, offset); + + if (t == MAP_FAILED) { + int save_errno = errno; + do_munmap(p, len); + errno = save_errno; + return -1; + } + } + + start = h2g(p); + } + + last = start + len - 1; + if (fileend_adj) { + pass_last = ROUND_UP(last - fileend_adj, host_page_size) - 1; + } else { + pass_last = last; + } + return mmap_end(start, last, start, pass_last, mmap_flags, page_flags); +} + static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, int target_prot, int flags, int page_flags, int fd, off_t offset) @@ -613,37 +763,9 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, if (host_page_size == TARGET_PAGE_SIZE) { return mmap_h_eq_g(start, len, host_prot, flags, page_flags, fd, offset); - } - - /* - * When mapping files into a memory area larger than the file, accesses - * to pages beyond the file size will cause a SIGBUS. - * - * For example, if mmaping a file of 100 bytes on a host with 4K pages - * emulating a target with 8K pages, the target expects to be able to - * access the first 8K. But the host will trap us on any access beyond - * 4K. - * - * When emulating a target with a larger page-size than the hosts, we - * may need to truncate file maps at EOF and add extra anonymous pages - * up to the targets page boundary. - */ - if (host_page_size < TARGET_PAGE_SIZE && !(flags & MAP_ANONYMOUS)) { - struct stat sb; - - if (fstat(fd, &sb) == -1) { - return -1; - } - - /* Are we trying to create a map beyond EOF?. */ - if (offset + len > sb.st_size) { - /* - * If so, truncate the file map at eof aligned with - * the hosts real pagesize. Additional anonymous maps - * will be created beyond EOF. - */ - len = ROUND_UP(sb.st_size - offset, host_page_size); - } + } else if (host_page_size < TARGET_PAGE_SIZE) { + return mmap_h_lt_g(start, len, host_prot, flags, + page_flags, fd, offset, host_page_size); } if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { From patchwork Thu Feb 22 20:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jmMKvmWF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglgx0Nvhz23l1 for ; Fri, 23 Feb 2024 07:52:13 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvR-0007kz-KI; Thu, 22 Feb 2024 15:44:13 -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 1rdFvQ-0007gb-Ba for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:12 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvO-0002lr-7W for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:12 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d953fa3286so485075ad.2 for ; Thu, 22 Feb 2024 12:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634649; x=1709239449; 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=MfmBcNvAQcjDLvj9qNkCIuvVr8sl09md9gL9eOBPbro=; b=jmMKvmWF8WNZyVIOnP4VIOKJD5vEZbgdp5PXcTqmosoJpfgZgzcgLd4Yq8OfEgWZsb WXK3vrlkd9rS/HrfMgTDDkCpwMQ+wQxk1F6HMo7VPa06R7DmJgoCqQMd5O2DSqdiqrdb oeWmvHd/uAsB+NNmoOluDWVNanOOGcwEyd9Sw+Doa65UeVCOzdrLQYdBmOfYvmdsPdbG ZtWxYtuqenLvxBZZvnF1euG4XShhTSdV8318zYaHWUMCne1nghnWAsnc2t9OMAcZuEqq VrA996z7A+I+F65ov6BhS6mWoitEbtKxAtz6DkmBrPP31FYeLaDvHnU3+/bOKVXfBmgb sgjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634649; x=1709239449; 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=MfmBcNvAQcjDLvj9qNkCIuvVr8sl09md9gL9eOBPbro=; b=FQwu9gQMBCoizy6tK6YT/dxUkQ1KHO0F3Pd4DyK2dGflSZauTqW6ltOHx7ubkf28kM B0bQeR7GcFysG39TCUdI6Hv6xfNuOCcBojPKfdyDUqckdQpyXOwd8POCV99tBMznacDv iIKO1ORiVMNdivk5dcwWe59nzi6HPZ6UrD/hZ952J+PWoKJEA5D2oWv5NMabNKgOPhi4 RNy2OLVf0TFeHmmOS9FxyFe2640d0p5uJv7yMt6SaXSJZHassHRcuhOxrsCm1nhEhzWu 9vDnBwCUHFAUpmK39a++nVLLMArYLAQQNhdiExFEq51RutoK/RTLifwjhjPdJGLFLAJw L/pQ== X-Gm-Message-State: AOJu0YzKDiaf3tVqPoJn2cxY68Xurutc8PqCx+AzLmmNclmQwPa/vklc 1ctyzAiBeLRh8o9nJH9ud9W0E+Ly0zDk3lNCJJYzqjfofZf5acSbe8NZ2RotmntqEAgprW/LiWH O X-Google-Smtp-Source: AGHT+IG98EL4HHBXS6w+XbrUxwDgWhGqzZUMIvX9dz2+dFc2k5Zz2ihjyu3RKI5CIekSCa3LTTKshA== X-Received: by 2002:a17:903:298b:b0:1db:be69:d02d with SMTP id lm11-20020a170903298b00b001dbbe69d02dmr23269427plb.32.1708634648954; Thu, 22 Feb 2024 12:44:08 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 28/39] linux-user: Split out mmap_h_gt_g Date: Thu, 22 Feb 2024 10:43:12 -1000 Message-Id: <20240222204323.268539-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-24-richard.henderson@linaro.org> --- linux-user/mmap.c | 288 ++++++++++++++++++++++------------------------ 1 file changed, 139 insertions(+), 149 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index ff8f9f7ed0..82f4026283 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -282,7 +282,16 @@ static int do_munmap(void *addr, size_t len) return munmap(addr, len); } -/* map an incomplete host page */ +/* + * Map an incomplete host page. + * + * Here be dragons. This case will not work if there is an existing + * overlapping host page, which is file mapped, and for which the mapping + * is beyond the end of the file. In that case, we will see SIGBUS when + * trying to write a portion of this page. + * + * FIXME: Work around this with a temporary signal handler and longjmp. + */ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, int prot, int flags, int fd, off_t offset) { @@ -719,19 +728,138 @@ static abi_long mmap_h_lt_g(abi_ulong start, abi_ulong len, int host_prot, return mmap_end(start, last, start, pass_last, mmap_flags, page_flags); } +/* + * Special case host page size > target page size. + * + * The two special cases are address and file offsets that are valid + * for the guest that cannot be directly represented by the host. + */ +static abi_long mmap_h_gt_g(abi_ulong start, abi_ulong len, + int target_prot, int host_prot, + int flags, int page_flags, int fd, + off_t offset, int host_page_size) +{ + void *p, *want_p = g2h_untagged(start); + off_t host_offset = offset & -host_page_size; + abi_ulong last, real_start, real_last; + bool misaligned_offset = false; + size_t host_len; + + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { + /* + * Adjust the offset to something representable on the host. + */ + host_len = len + offset - host_offset; + p = mmap(want_p, host_len, host_prot, flags, fd, host_offset); + if (p == MAP_FAILED) { + return -1; + } + + /* Update start to the file position at offset. */ + p += offset - host_offset; + + start = h2g(p); + last = start + len - 1; + return mmap_end(start, last, start, last, flags, page_flags); + } + + if (!(flags & MAP_ANONYMOUS)) { + misaligned_offset = (start ^ offset) & (host_page_size - 1); + + /* + * The fallback for misalignment is a private mapping + read. + * This carries none of semantics required of MAP_SHARED. + */ + if (misaligned_offset && (flags & MAP_TYPE) != MAP_PRIVATE) { + errno = EINVAL; + return -1; + } + } + + last = start + len - 1; + real_start = start & -host_page_size; + real_last = ROUND_UP(last, host_page_size) - 1; + + /* + * Handle the start and end of the mapping. + */ + if (real_start < start) { + abi_ulong real_page_last = real_start + host_page_size - 1; + if (last <= real_page_last) { + /* Entire allocation a subset of one host page. */ + if (!mmap_frag(real_start, start, last, target_prot, + flags, fd, offset)) { + return -1; + } + return mmap_end(start, last, -1, 0, flags, page_flags); + } + + if (!mmap_frag(real_start, start, real_page_last, target_prot, + flags, fd, offset)) { + return -1; + } + real_start = real_page_last + 1; + } + + if (last < real_last) { + abi_ulong real_page_start = real_last - host_page_size + 1; + if (!mmap_frag(real_page_start, real_page_start, last, + target_prot, flags, fd, + offset + real_page_start - start)) { + return -1; + } + real_last = real_page_start - 1; + } + + if (real_start > real_last) { + return mmap_end(start, last, -1, 0, flags, page_flags); + } + + /* + * Handle the middle of the mapping. + */ + + host_len = real_last - real_start + 1; + want_p += real_start - start; + + if (flags & MAP_ANONYMOUS) { + p = mmap(want_p, host_len, host_prot, flags, -1, 0); + } else if (!misaligned_offset) { + p = mmap(want_p, host_len, host_prot, flags, fd, + offset + real_start - start); + } else { + p = mmap(want_p, host_len, host_prot | PROT_WRITE, + flags | MAP_ANONYMOUS, -1, 0); + } + if (p != want_p) { + if (p != MAP_FAILED) { + do_munmap(p, host_len); + errno = EEXIST; + } + return -1; + } + + if (misaligned_offset) { + /* TODO: The read could be short. */ + if (pread(fd, p, host_len, offset + real_start - start) != host_len) { + do_munmap(p, host_len); + return -1; + } + if (!(host_prot & PROT_WRITE)) { + mprotect(p, host_len, host_prot); + } + } + + return mmap_end(start, last, -1, 0, flags, page_flags); +} + static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, int target_prot, int flags, int page_flags, int fd, off_t offset) { int host_page_size = qemu_real_host_page_size(); - abi_ulong ret, last, real_start, real_last, retaddr, host_len; - abi_ulong passthrough_start = -1, passthrough_last = 0; - off_t host_offset; int host_prot; - real_start = start & -host_page_size; - host_offset = offset & -host_page_size; - /* * For reserved_va, we are in full control of the allocation. * Find a suitable hole and convert to MAP_FIXED. @@ -745,6 +873,8 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, } flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; } else if (!(flags & MAP_FIXED)) { + abi_ulong real_start = start & -host_page_size; + off_t host_offset = offset & -host_page_size; size_t real_len = len + offset - host_offset; abi_ulong align = MAX(host_page_size, TARGET_PAGE_SIZE); @@ -766,150 +896,10 @@ static abi_long target_mmap__locked(abi_ulong start, abi_ulong len, } else if (host_page_size < TARGET_PAGE_SIZE) { return mmap_h_lt_g(start, len, host_prot, flags, page_flags, fd, offset, host_page_size); - } - - if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { - uintptr_t host_start; - void *p; - - host_len = len + offset - host_offset; - host_len = ROUND_UP(host_len, host_page_size); - - /* Note: we prefer to control the mapping address. */ - p = mmap(g2h_untagged(start), host_len, host_prot, - flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { - return -1; - } - /* update start so that it points to the file position at 'offset' */ - host_start = (uintptr_t)p; - if (!(flags & MAP_ANONYMOUS)) { - p = mmap(g2h_untagged(start), len, host_prot, - flags | MAP_FIXED, fd, host_offset); - if (p == MAP_FAILED) { - do_munmap(g2h_untagged(start), host_len); - return -1; - } - host_start += offset - host_offset; - } - start = h2g(host_start); - last = start + len - 1; - passthrough_start = start; - passthrough_last = last; } else { - last = start + len - 1; - real_last = ROUND_UP(last, host_page_size) - 1; - - if (flags & MAP_FIXED_NOREPLACE) { - /* Validate that the chosen range is empty. */ - if (!page_check_range_empty(start, last)) { - errno = EEXIST; - return -1; - } - - /* - * With reserved_va, the entire address space is mmaped in the - * host to ensure it isn't accidentally used for something else. - * We have just checked that the guest address is not mapped - * within the guest, but need to replace the host reservation. - * - * Without reserved_va, despite the guest address check above, - * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite - * any host address mappings. - */ - if (reserved_va) { - flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; - } - } - - /* - * worst case: we cannot map the file because the offset is not - * aligned, so we read it - */ - if (!(flags & MAP_ANONYMOUS) && - (offset & (host_page_size - 1)) != (start & (host_page_size - 1))) { - /* - * msync() won't work here, so we return an error if write is - * possible while it is a shared mapping - */ - if ((flags & MAP_TYPE) == MAP_SHARED - && (target_prot & PROT_WRITE)) { - errno = EINVAL; - return -1; - } - retaddr = target_mmap(start, len, target_prot | PROT_WRITE, - (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) - | MAP_PRIVATE | MAP_ANONYMOUS, - -1, 0); - if (retaddr == -1) { - return -1; - } - if (pread(fd, g2h_untagged(start), len, offset) == -1) { - return -1; - } - if (!(target_prot & PROT_WRITE)) { - ret = target_mprotect(start, len, target_prot); - assert(ret == 0); - } - return mmap_end(start, last, -1, 0, flags, page_flags); - } - - /* handle the start of the mapping */ - if (start > real_start) { - if (real_last == real_start + host_page_size - 1) { - /* one single host page */ - if (!mmap_frag(real_start, start, last, - target_prot, flags, fd, offset)) { - return -1; - } - return mmap_end(start, last, -1, 0, flags, page_flags); - } - if (!mmap_frag(real_start, start, - real_start + host_page_size - 1, - target_prot, flags, fd, offset)) { - return -1; - } - real_start += host_page_size; - } - /* handle the end of the mapping */ - if (last < real_last) { - abi_ulong real_page = real_last - host_page_size + 1; - if (!mmap_frag(real_page, real_page, last, - target_prot, flags, fd, - offset + real_page - start)) { - return -1; - } - real_last -= host_page_size; - } - - /* map the middle (easier) */ - if (real_start < real_last) { - void *p, *want_p; - off_t offset1; - size_t len1; - - if (flags & MAP_ANONYMOUS) { - offset1 = 0; - } else { - offset1 = offset + real_start - start; - } - len1 = real_last - real_start + 1; - want_p = g2h_untagged(real_start); - - p = mmap(want_p, len1, host_prot, flags, fd, offset1); - if (p != want_p) { - if (p != MAP_FAILED) { - do_munmap(p, len1); - errno = EEXIST; - } - return -1; - } - passthrough_start = real_start; - passthrough_last = real_last; - } + return mmap_h_gt_g(start, len, target_prot, host_prot, flags, + page_flags, fd, offset, host_page_size); } - return mmap_end(start, last, passthrough_start, passthrough_last, - flags, page_flags); } /* NOTE: all the constants are the HOST ones */ From patchwork Thu Feb 22 20:43:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=a2fCnJs8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglg66Ms1z23l1 for ; Fri, 23 Feb 2024 07:51:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvU-0007zO-53; Thu, 22 Feb 2024 15:44:16 -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 1rdFvR-0007kj-EN for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:13 -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 1rdFvP-0002m6-JF for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:13 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d93edfa76dso526625ad.1 for ; Thu, 22 Feb 2024 12:44:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634650; x=1709239450; 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=2NxBdbDmPXvqTBcYichP7qzlXUZvSD7xiNQMCyXrUoI=; b=a2fCnJs8PWt2Eox79SovwMovZO914dkzb4e2G6hzIY5L4/ljkXfAawsSJc/cL/YMIm G3zWeNv3kYK/Te0KI0XInhDKeouNYrEVOAoaZwoPd2OhDrDXwyZh7PSkl1z4Ygb9Utej aTe74i8pokbd7CZ1W1BEzCCmgs6WOz/F4qtl0Cwt+5P38Q1j0JtEbsER1n5lmMs3LnCR Wd+HaCkXK8l4jIFZDJ1CPjZYYO1quqHl8iTDWG/S9CO5DlN4mDUq1Huap9tDsdeB3UGE +CcFdYwkhZ5HmsRs+UDB3PDJQRv6cSo8Hi3CffeVY/G6zQztyyoRujOUyrCtT1b90aVk MXwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634650; x=1709239450; 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=2NxBdbDmPXvqTBcYichP7qzlXUZvSD7xiNQMCyXrUoI=; b=DVZHUr3pXixw+mQF1AN9k0K+XxCNx6V5SJXWkRTChkU765Yf0oOawcdLgvsCq9wVS8 eFIWVON0PYcsyKpUF8R8Wh+L9HkvFe4uFc4rXfnteLSiWulmHtGHf1Oj1Er55eiQdWLl jkoAvKHEyb805InpMQpLN4bOhMwm97O7hFVAaL1dYNAoqSIFT0OLS2sPgY+OngfXve98 gntATD8550Y6fnZM8UzIIC3ipt8imMiInBpmcsg8HYCsajNWtCnMVKrnx7xRDEG97dSe G2yuDEJch+v4463aQjYPgztVQ7prKtzC7Rm3tC7cktEIkFacQu0pbS9zijB259iXx826 JdQA== X-Gm-Message-State: AOJu0Yz7ZQyFAJdU/H3EmtVRdLIFZKRLXBL5l8M7KxhK1DGRKIM942yd c/qNdU1oOyYdLClMLEpNmbwWQYWto46f61sL+HVAjK1Tx7W454BvCmQ1IbiHoiPNhrniv7l6fz4 O X-Google-Smtp-Source: AGHT+IHAXwfllyccLeApk6u5LeBSODnWRxxm8uOuSZoPdnLnssgyJ5LjVwuoTXt98+Yy78X/JdJq4g== X-Received: by 2002:a17:903:234a:b0:1dc:1831:8ecc with SMTP id c10-20020a170903234a00b001dc18318eccmr9975697plh.53.1708634650394; Thu, 22 Feb 2024 12:44:10 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 29/39] tests/tcg: Remove run-test-mmap-* Date: Thu, 22 Feb 2024 10:43:13 -1000 Message-Id: <20240222204323.268539-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These tests are confused, because -p does not change the guest page size, but the host page size. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-25-richard.henderson@linaro.org> --- tests/tcg/alpha/Makefile.target | 3 --- tests/tcg/arm/Makefile.target | 3 --- tests/tcg/hppa/Makefile.target | 3 --- tests/tcg/i386/Makefile.target | 3 --- tests/tcg/m68k/Makefile.target | 3 --- tests/tcg/multiarch/Makefile.target | 9 --------- tests/tcg/ppc/Makefile.target | 12 ------------ tests/tcg/sh4/Makefile.target | 3 --- tests/tcg/sparc64/Makefile.target | 6 ------ 9 files changed, 45 deletions(-) delete mode 100644 tests/tcg/ppc/Makefile.target delete mode 100644 tests/tcg/sparc64/Makefile.target diff --git a/tests/tcg/alpha/Makefile.target b/tests/tcg/alpha/Makefile.target index b94500a7d9..fdd7ddf64e 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -13,6 +13,3 @@ test-cmov: test-cond.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) run-test-cmov: test-cmov - -# On Alpha Linux only supports 8k pages -EXTRA_RUNS+=run-test-mmap-8192 diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target index 3473f4619e..0a1965fce7 100644 --- a/tests/tcg/arm/Makefile.target +++ b/tests/tcg/arm/Makefile.target @@ -79,6 +79,3 @@ sha512-vector: sha512.c ARM_TESTS += sha512-vector TESTS += $(ARM_TESTS) - -# On ARM Linux only supports 4k pages -EXTRA_RUNS+=run-test-mmap-4096 diff --git a/tests/tcg/hppa/Makefile.target b/tests/tcg/hppa/Makefile.target index cdd0d572a7..ea5ae2186d 100644 --- a/tests/tcg/hppa/Makefile.target +++ b/tests/tcg/hppa/Makefile.target @@ -2,9 +2,6 @@ # # HPPA specific tweaks - specifically masking out broken tests -# On parisc Linux supports 4K/16K/64K (but currently only 4k works) -EXTRA_RUNS+=run-test-mmap-4096 # run-test-mmap-16384 run-test-mmap-65536 - # This triggers failures for hppa-linux about 1% of the time # HPPA is the odd target that can't use the sigtramp page; # it requires the full vdso with dwarf2 unwind info. diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index 9906f9e116..bbe2c44b2a 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -71,9 +71,6 @@ endif I386_TESTS:=$(filter-out $(SKIP_I386_TESTS), $(ALL_X86_TESTS)) TESTS=$(MULTIARCH_TESTS) $(I386_TESTS) -# On i386 and x86_64 Linux only supports 4k pages (large pages are a different hack) -EXTRA_RUNS+=run-test-mmap-4096 - sha512-sse: CFLAGS=-msse4.1 -O3 sha512-sse: sha512.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) diff --git a/tests/tcg/m68k/Makefile.target b/tests/tcg/m68k/Makefile.target index 6ff214e60a..33f7b1b127 100644 --- a/tests/tcg/m68k/Makefile.target +++ b/tests/tcg/m68k/Makefile.target @@ -5,6 +5,3 @@ VPATH += $(SRC_PATH)/tests/tcg/m68k TESTS += trap denormal - -# On m68k Linux supports 4k and 8k pages (but 8k is currently broken) -EXTRA_RUNS+=run-test-mmap-4096 # run-test-mmap-8192 diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index e10951a801..f11f3b084d 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -51,18 +51,9 @@ run-plugin-vma-pthread-with-%: vma-pthread $(call skip-test, $<, "flaky on CI?") endif -# We define the runner for test-mmap after the individual -# architectures have defined their supported pages sizes. If no -# additional page sizes are defined we only run the default test. - -# default case (host page size) run-test-mmap: test-mmap $(call run-test, test-mmap, $(QEMU) $<, $< (default)) -# additional page sizes (defined by each architecture adding to EXTRA_RUNS) -run-test-mmap-%: test-mmap - $(call run-test, test-mmap-$*, $(QEMU) -p $* $<, $< ($* byte pages)) - ifneq ($(GDB),) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py diff --git a/tests/tcg/ppc/Makefile.target b/tests/tcg/ppc/Makefile.target deleted file mode 100644 index f5e08c7376..0000000000 --- a/tests/tcg/ppc/Makefile.target +++ /dev/null @@ -1,12 +0,0 @@ -# -*- Mode: makefile -*- -# -# PPC - included from tests/tcg/Makefile -# - -ifneq (,$(findstring 64,$(TARGET_NAME))) -# On PPC64 Linux can be configured with 4k (default) or 64k pages (currently broken) -EXTRA_RUNS+=run-test-mmap-4096 #run-test-mmap-65536 -else -# On PPC32 Linux supports 4K/16K/64K/256K (but currently only 4k works) -EXTRA_RUNS+=run-test-mmap-4096 #run-test-mmap-16384 run-test-mmap-65536 run-test-mmap-262144 -endif diff --git a/tests/tcg/sh4/Makefile.target b/tests/tcg/sh4/Makefile.target index 47c39a44b6..16eaa850a8 100644 --- a/tests/tcg/sh4/Makefile.target +++ b/tests/tcg/sh4/Makefile.target @@ -3,9 +3,6 @@ # SuperH specific tweaks # -# On sh Linux supports 4k, 8k, 16k and 64k pages (but only 4k currently works) -EXTRA_RUNS+=run-test-mmap-4096 # run-test-mmap-8192 run-test-mmap-16384 run-test-mmap-65536 - # This triggers failures for sh4-linux about 10% of the time. # Random SIGSEGV at unpredictable guest address, cause unknown. run-signals: signals diff --git a/tests/tcg/sparc64/Makefile.target b/tests/tcg/sparc64/Makefile.target deleted file mode 100644 index 408dace783..0000000000 --- a/tests/tcg/sparc64/Makefile.target +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: makefile -*- -# -# sparc specific tweaks - -# On Sparc64 Linux support 8k pages -EXTRA_RUNS+=run-test-mmap-8192 From patchwork Thu Feb 22 20:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=hZ/4CrhM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglgN3JRHz23l1 for ; Fri, 23 Feb 2024 07:51:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvU-00080U-AM; Thu, 22 Feb 2024 15:44:16 -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 1rdFvS-0007q3-Jo for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:14 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvR-0002mK-2h for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:14 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dc1e7c0e29so1599065ad.1 for ; Thu, 22 Feb 2024 12:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634652; x=1709239452; 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=e2NESTxnz6150SuLytNvY5Gmn2U5RKg4GfRtueQZH4I=; b=hZ/4CrhMaNF1HjeJrPF8OHuJNdFTLFA4fEx03C6PKPWV3gpdKvw5Kt9cMBDW8quEA8 VvO3b4fReqsO3wVD+JP56u8Kw2FcSPqbrZwwWJHtywSPyQgpCfct7+KQbDin5ITkl+7c KM0jCBW56pvhEO6bTfjhNwDDhdpFf30lcxqRxilPBTEAXKD7uXyqJ8Fuzj7IFI3JUz5P 5vqtUHb7fL1xcG42GcY/KNqr54sK1RgxEQpNrZch/FUdgLFjz222mZ2j/Am3gIDbNiSE bvjfEoBUBZNXVpplwge5cQ/qt9VD/vZN/PQZVenFTupjXYhHFGtFwMesL8/HqFDO7Raf orGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634652; x=1709239452; 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=e2NESTxnz6150SuLytNvY5Gmn2U5RKg4GfRtueQZH4I=; b=FzWKKGIR2/ZNrtlRJhVKDZL9T/fsqBzKmueZa+jdflkyGbvBlPs0aYlIgvWhJdqf2i yaxTlnFSTIPMRbudyzhgQ0be9830XZgxiMSSRMrioniQgqw8IsESlJpZMLFKaGhmPczL OWiUbhxU6fRl6wGiFcpi/kkN1Lm4v/Hf2l7M/nx1qccJCy6e6PldCd+RE45l4fLgOkCi OgmMKsOlztdQqKIDdJw9EU2/wGlIgk7cNrrRYbWHLo1Ksz7+jGyhsV0B3Yi5MDFTJ1og QW0McetP23CXjmvev0bIft7s2oI5tyAaVRM3RAlbfLb2vB4D6EfGwc4xuiEC5+j7so4m 6XLw== X-Gm-Message-State: AOJu0YzDFbJ7VHwhJUxD0TGzaMO7TumttotucJHO5PUS8ctne56pNyeI 8Fhi5elRaZhA3xU23xqXCvpqAW7RveA3Vhl3XqrHdCg2W0yhqNr0CJRF6fwHMzZVVOgJ0zCgppT M X-Google-Smtp-Source: AGHT+IFcuTy8EJ2o76Foed3DNGOgF7w8raPHKOVmlAW1Wx8ej7Aaizp3M8y5OQxUMBQueKGRfvMBWA== X-Received: by 2002:a17:902:ea0d:b0:1db:e792:bb38 with SMTP id s13-20020a170902ea0d00b001dbe792bb38mr15388661plg.63.1708634651868; Thu, 22 Feb 2024 12:44:11 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 30/39] tests/tcg: Extend file in linux-madvise.c Date: Thu, 22 Feb 2024 10:43:14 -1000 Message-Id: <20240222204323.268539-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When guest page size > host page size, this test can fail due to the SIGBUS protection hack. Avoid this by making sure that the file size is at least one guest page. Visible with alpha guest on x86_64 host. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-26-richard.henderson@linaro.org> --- tests/tcg/multiarch/linux/linux-madvise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tcg/multiarch/linux/linux-madvise.c b/tests/tcg/multiarch/linux/linux-madvise.c index 29d0997e68..539fb3b772 100644 --- a/tests/tcg/multiarch/linux/linux-madvise.c +++ b/tests/tcg/multiarch/linux/linux-madvise.c @@ -42,6 +42,8 @@ static void test_file(void) assert(ret == 0); written = write(fd, &c, sizeof(c)); assert(written == sizeof(c)); + ret = ftruncate(fd, pagesize); + assert(ret == 0); page = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE, fd, 0); assert(page != MAP_FAILED); From patchwork Thu Feb 22 20:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902951 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=BwJybVUg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglW10mVRz23l3 for ; Fri, 23 Feb 2024 07:44:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvW-00084k-RO; Thu, 22 Feb 2024 15:44:18 -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 1rdFvU-00081X-Dc for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:17 -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 1rdFvS-0002mh-LS for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:16 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1dbf1fe91fcso494295ad.3 for ; Thu, 22 Feb 2024 12:44:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634653; x=1709239453; 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=n/bmjjPgt+4cAZDZblP4w6A7Xhw+0ftgWcgfLTUC2AM=; b=BwJybVUgi2xnrQ57pHFLTv/mEiFALlbR3Kz7gHe3wtuRgyUpfyUYhUebVW0Bsx9lN4 Hi4YUv+1s801ld+UdygCPxTj0ylyXSGSbmx6J+jkgWdkE/fW3WiMBnWniXJy5GBPo//Z 8OovFSrrTPYa2r+F48xXssNYgr0+6qqK75NFAiwNosmub5YM6HuoKoiiZJI/FyfssQUZ qbJn0OusWMRiIGsv8DjvYtYoQZBEnOE3uAycxbL5NAE8/EROtum1f4BOjzIzfKFSWgl3 tSrWx8Y34zd9kM1yRRqzWNESoD67Vec2NQ9hrBrpPl3ROLsqCUZeQwR58i029ZpJGuw3 f3OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634653; x=1709239453; 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=n/bmjjPgt+4cAZDZblP4w6A7Xhw+0ftgWcgfLTUC2AM=; b=sxbZrgPHkgkv8ibZzli2IcHqf+iZ/FerzfYA8yyWdfu8RZY3Is3UM23J92ookDKexg c38pT047slUkgq7a/nEgmmTYcwFxUGQIbXIANeXVqycsMGZtVFCFi2UdVj2b3Ru9rolf WPE5MN0Re3vPTFMpMFUkKStodOrzb7VPmth+WcKHe4lGudeLal1vLQ4yAN+yyhA4iON2 qjc0H/rAj6Kr+nLZFEtnW6UdtKTMN38edmsBQSu/QQxztKPOawTfjbbURnJnIqRAeKQ/ clJT+ZJ0ndSFqQT4LG+Eil2rROtv4ft505yVmUmeOkkrdubbZ6cmpIUy46LGG44AmbsP Tpaw== X-Gm-Message-State: AOJu0YzgJfHfnSNpysJBRzzt9pagMcNplx/0GCQ3LRdjbH9qgj31+w7P FADr409BnqSPTlzA5EX+emCV3VeBQGGNK5SSIiuNc/3lGeEJVxwhnXkmGSkFcPHL7fPX4bIXv2k v X-Google-Smtp-Source: AGHT+IFqMyFOP8gtE5UCMwokSI/QEG1OFkBf+dEJPKGkf6xOmKlE0YZ5HDYu38aANzps+iYI+onbJg== X-Received: by 2002:a17:902:8207:b0:1db:51d6:5889 with SMTP id x7-20020a170902820700b001db51d65889mr20211659pln.64.1708634653347; Thu, 22 Feb 2024 12:44:13 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:12 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Warner Losh , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Helge Deller Subject: [PULL 31/39] *-user: Deprecate and disable -p pagesize Date: Thu, 22 Feb 2024 10:43:15 -1000 Message-Id: <20240222204323.268539-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This option controls the host page size. From the mis-usage in our own testsuite, this is easily confused with guest page size. The only thing that occurs when changing the host page size is that stuff breaks, because one cannot actually change the host page size. Therefore reject all but the no-op setting as part of the deprecation process. Reviewed-by: Warner Losh Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Acked-by: Helge Deller Message-Id: <20240102015808.132373-27-richard.henderson@linaro.org> --- docs/about/deprecated.rst | 10 ++++++++++ docs/user/main.rst | 3 --- bsd-user/main.c | 10 +++++----- linux-user/main.c | 12 ++++++------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 5a2305ccd6..3074303b9c 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -63,6 +63,16 @@ as short-form boolean values, and passed to plugins as ``arg_name=on``. However, short-form booleans are deprecated and full explicit ``arg_name=on`` form is preferred. +User-mode emulator command line arguments +----------------------------------------- + +``-p`` (since 9.0) +'''''''''''''''''' + +The ``-p`` option pretends to control the host page size. However, +it is not possible to change the host page size, and using the +option only causes failures. + QEMU Machine Protocol (QMP) commands ------------------------------------ diff --git a/docs/user/main.rst b/docs/user/main.rst index 7e7ad07409..d5fbb78d3c 100644 --- a/docs/user/main.rst +++ b/docs/user/main.rst @@ -87,9 +87,6 @@ Debug options: Activate logging of the specified items (use '-d help' for a list of log items) -``-p pagesize`` - Act as if the host page size was 'pagesize' bytes - ``-g port`` Wait gdb connection to port diff --git a/bsd-user/main.c b/bsd-user/main.c index e5efb7b845..521b58b880 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -364,11 +364,11 @@ int main(int argc, char **argv) } else if (!strcmp(r, "L")) { interp_prefix = argv[optind++]; } else if (!strcmp(r, "p")) { - qemu_host_page_size = atoi(argv[optind++]); - if (qemu_host_page_size == 0 || - (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { - fprintf(stderr, "page size must be a power of two\n"); - exit(1); + unsigned size, want = qemu_real_host_page_size(); + + if (qemu_strtoui(arg, NULL, 10, &size) || size != want) { + warn_report("Deprecated page size option cannot " + "change host page size (%u)", want); } } else if (!strcmp(r, "g")) { gdbstub = g_strdup(argv[optind++]); diff --git a/linux-user/main.c b/linux-user/main.c index e540acb84a..bad03f06d3 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -332,11 +332,11 @@ static void handle_arg_ld_prefix(const char *arg) static void handle_arg_pagesize(const char *arg) { - qemu_host_page_size = atoi(arg); - if (qemu_host_page_size == 0 || - (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { - fprintf(stderr, "page size must be a power of two\n"); - exit(EXIT_FAILURE); + unsigned size, want = qemu_real_host_page_size(); + + if (qemu_strtoui(arg, NULL, 10, &size) || size != want) { + warn_report("Deprecated page size option cannot " + "change host page size (%u)", want); } } @@ -496,7 +496,7 @@ static const struct qemu_argument arg_table[] = { {"D", "QEMU_LOG_FILENAME", true, handle_arg_log_filename, "logfile", "write logs to 'logfile' (default stderr)"}, {"p", "QEMU_PAGESIZE", true, handle_arg_pagesize, - "pagesize", "set the host page size to 'pagesize'"}, + "pagesize", "deprecated change to host page size"}, {"one-insn-per-tb", "QEMU_ONE_INSN_PER_TB", false, handle_arg_one_insn_per_tb, "", "run with one guest instruction per emulated TB"}, From patchwork Thu Feb 22 20:43:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=L35Wv8i/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglgP5clyz23l1 for ; Fri, 23 Feb 2024 07:51:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvX-00085X-Bp; Thu, 22 Feb 2024 15:44:19 -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 1rdFvV-00081v-Uk for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:17 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvU-0002nJ-74 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:17 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d746ce7d13so735305ad.0 for ; Thu, 22 Feb 2024 12:44:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634655; x=1709239455; 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=udP+pGil6gAHeo/JHSsvoaPGgz4MOYyC4J6GT3yPeXc=; b=L35Wv8i/oAv4rLRX/wwXGQupBb2keeJ7y0nozbetbqxu/OqL2PmZQuGhTFJTmC8g69 8eGmDRQWolb9Q+g5o1SQiugFKkjOHsbMmZZFzNvKuoXSIclYMATmhbfW470jJ1RFqn8l 9FSaOe0uAogfLHSmzUrt+YDV5Y6L13GS8f5We7wQRVvuSqfOgcMN0TUJ8tY91VF54u79 UwOjLbCyqass88YLN1S49x3S/90yRxDzxDFlnhSL+p2lxqTxV+oV1DPAinwxC200g5hy ajn/9e0jnYujrc/4/V3cqao8JBNHWU61Xl37JhYfC9qAXwpFhjV5GgENOEO9W5NBsLjv Hnew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634655; x=1709239455; 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=udP+pGil6gAHeo/JHSsvoaPGgz4MOYyC4J6GT3yPeXc=; b=HcLhG26E2OIoR1s/dnrfXS0Bpxo2Z0unDGjGmd49KNtzu92QGhm0zLOOA1679rgBvh 9zi6DaCGObo1WazZt6+VdplVgg9PS1tWTd4Vnn5GE7uElajBFx5DOApW+KffyAj4Rjen NCssTC+iV1zM+68fqOfw8H1+KGOl/y7/o+gfwFgZdL0KG7v1mcDfKmWByPVYRs/oHf42 E+sGLM9YnpqoPOomwsywnnm4X6iZgyn4DDX8xsFX3RKVH4SVGu3chQDHwkSmRHzaCjeZ eSKxTJYiCpx6HZAhOe4PBIR1BoRXioNywvkA8IAbLy91bRyfL2+viy9ewI+wilrfvvm/ 0bPw== X-Gm-Message-State: AOJu0YwB89Xb9XP28tLOFvw0t1ONNw0b9LuzXJYYBOWtTGATX5oEN7TU 08zo3Ab92597foXl4AYEvqUKVDvHmK4SVzDz5wo9sfHuB7t/TnSzsQBRcmpk7puBXT5Tu0H+tKm K X-Google-Smtp-Source: AGHT+IHmRldTC2Oj1M+mEVc2bPTfcjkS1elRciYvXqFJwyVQ53+rYoa+Y2PpqeDUwSY3raIPCecSsw== X-Received: by 2002:a17:902:6f08:b0:1db:8555:55b1 with SMTP id w8-20020a1709026f0800b001db855555b1mr16310209plk.37.1708634654987; Thu, 22 Feb 2024 12:44:14 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Warner Losh , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 32/39] cpu: Remove page_size_init Date: Thu, 22 Feb 2024 10:43:16 -1000 Message-Id: <20240222204323.268539-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move qemu_host_page_{size,mask} and HOST_PAGE_ALIGN into bsd-user. It should be removed from bsd-user as well, but defer that cleanup. Reviewed-by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Tested-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-28-richard.henderson@linaro.org> --- bsd-user/qemu.h | 7 +++++++ include/exec/cpu-common.h | 7 ------- include/hw/core/cpu.h | 2 -- accel/tcg/translate-all.c | 1 - bsd-user/main.c | 12 ++++++++++++ cpu-target.c | 13 ------------- system/vl.c | 1 - 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index dc842fffa7..c05c512767 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -39,6 +39,13 @@ extern char **environ; #include "qemu/clang-tsa.h" #include "qemu-os.h" +/* + * TODO: Remove these and rely only on qemu_real_host_page_size(). + */ +extern uintptr_t qemu_host_page_size; +extern intptr_t qemu_host_page_mask; +#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size) + /* * This struct is used to hold certain information about the image. Basically, * it replicates in user space what would be certain task_struct fields in the diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 9ead1be100..6346df17ce 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -20,13 +20,6 @@ void cpu_exec_init_all(void); void cpu_exec_step_atomic(CPUState *cpu); -/* Using intptr_t ensures that qemu_*_page_mask is sign-extended even - * when intptr_t is 32-bit and we are aligning a long long. - */ -extern uintptr_t qemu_host_page_size; -extern intptr_t qemu_host_page_mask; - -#define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size) #define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size()) /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */ diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 4385ce54c9..5c2d55f6d2 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -1179,8 +1179,6 @@ bool target_words_bigendian(void); const char *target_name(void); -void page_size_init(void); - #ifdef NEED_CPU_H #ifndef CONFIG_USER_ONLY diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 1c695efe02..c1f57e894a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -256,7 +256,6 @@ bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data) void page_init(void) { - page_size_init(); page_table_config_init(); } diff --git a/bsd-user/main.c b/bsd-user/main.c index 521b58b880..4d6ce59af4 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -49,6 +49,13 @@ #include "host-os.h" #include "target_arch_cpu.h" + +/* + * TODO: Remove these and rely only on qemu_real_host_page_size(). + */ +uintptr_t qemu_host_page_size; +intptr_t qemu_host_page_mask; + static bool opt_one_insn_per_tb; uintptr_t guest_base; bool have_guest_base; @@ -307,6 +314,9 @@ int main(int argc, char **argv) (void) envlist_setenv(envlist, *wrk); } + qemu_host_page_size = getpagesize(); + qemu_host_page_size = MAX(qemu_host_page_size, TARGET_PAGE_SIZE); + cpu_model = NULL; qemu_add_opts(&qemu_trace_opts); @@ -403,6 +413,8 @@ int main(int argc, char **argv) } } + qemu_host_page_mask = -qemu_host_page_size; + /* init debug */ { int mask = 0; diff --git a/cpu-target.c b/cpu-target.c index 86444cc2c6..8763da51ee 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -474,16 +474,3 @@ const char *target_name(void) { return TARGET_NAME; } - -void page_size_init(void) -{ - /* NOTE: we can always suppose that qemu_host_page_size >= - TARGET_PAGE_SIZE */ - if (qemu_host_page_size == 0) { - qemu_host_page_size = qemu_real_host_page_size(); - } - if (qemu_host_page_size < TARGET_PAGE_SIZE) { - qemu_host_page_size = TARGET_PAGE_SIZE; - } - qemu_host_page_mask = -(intptr_t)qemu_host_page_size; -} diff --git a/system/vl.c b/system/vl.c index b8469d9965..7913cc28aa 100644 --- a/system/vl.c +++ b/system/vl.c @@ -2118,7 +2118,6 @@ static void qemu_create_machine(QDict *qdict) } cpu_exec_init_all(); - page_size_init(); if (machine_class->hw_version) { qemu_set_hw_version(machine_class->hw_version); From patchwork Thu Feb 22 20:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=cewAROzR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglgq4Qxsz23l1 for ; Fri, 23 Feb 2024 07:52:07 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFva-0008Am-E6; Thu, 22 Feb 2024 15:44:22 -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 1rdFvY-00087p-Pu for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:20 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvW-0002nX-9v for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:20 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dc139ed11fso10254735ad.0 for ; Thu, 22 Feb 2024 12:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634657; x=1709239457; 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=nFLr/Nh9lR5RHGOKXL0ktJAFT8XYevI/jB1Fp1QCuj0=; b=cewAROzRJluIMgKQAMvQECa8EoX7t/lej6g/hIyeFwo5xXYmld45rmlh9RBd/AkK+5 /RM+sfWwS7nF5jPCyCjLoFJugOwMCmJAfkBrvY9m0IsL8ep84ffShbGzhuuRd5GMDKs9 BFH+lkT1rbSJgqxg8nuOYsERpXpE6SYeC4oEs7D0tCCDXhS8mzFVrINhQQ8MMFXvYRBO SvqZqoeX0dpu89SWqF8JkoaNyV3/LYCNG436INlQvFqiZZTqigj7UNREzgE7jUWM+5gW gfD0xNipQKIp9A+UiMTxQirzAIVjkO9JC0Z4HWgXIuO3b44yHEeVe2mPc9yDwJA52qy0 xkKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634657; x=1709239457; 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=nFLr/Nh9lR5RHGOKXL0ktJAFT8XYevI/jB1Fp1QCuj0=; b=A6LeiEgzGA89m+1QVgHHQokuKkcUUn91pLWas0Y73FoYw5rY9WeN7WJR6SDLYP9fjK ZT1ZxeaZdl9aB5w5YFflzqhBnhmPYzl51n6scllmFigi7alkApZjGMJ1Oa4ACbyYbMf9 Q9AEXEV24G4fIb/rnhJPocDvmHd7gIEljpm8eWwr38LHtw0MoPiQdy6lKRoD3KqPGEhM BNo/Ns08CbcI9F+7ki6s5Ztr27FUmmTwDnE7ClAc76MpASoo5M488V5rTgowO9hhG01j dZ00x0RGLNhrGopaDj0wlJOWY1+mJsYKCGc5HjETXMdIb9ixnxXnlLwvZL2ksAYcInXP nkIw== X-Gm-Message-State: AOJu0Yx8q1U2zMZ7BPKWQCNek/ggdDxpoKNumTvWxsKeycS6QgpOgcZL V/uhSmOLz1FFtLDvzMFXwzFp3gbG6wff2pFtTx5P6Yw90lVOpzy5ynkYy8KjDjdPJJ+iFrV8yEI M X-Google-Smtp-Source: AGHT+IGKmEqptejhuqQ8Xh4Axro+8zv2UVti17Bt2ZCSZ72RESjA2z2OXX5LRtpSVZ8PZ7zTWsTFGg== X-Received: by 2002:a17:902:da92:b0:1db:f15c:85c0 with SMTP id j18-20020a170902da9200b001dbf15c85c0mr173183plx.33.1708634656959; Thu, 22 Feb 2024 12:44:16 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 33/39] accel/tcg: Disconnect TargetPageDataNode from page size Date: Thu, 22 Feb 2024 10:43:17 -1000 Message-Id: <20240222204323.268539-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Dynamically size the node for the runtime target page size. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-29-richard.henderson@linaro.org> --- accel/tcg/user-exec.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 69b7429e31..3cac3a78c4 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -864,7 +864,7 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr, typedef struct TargetPageDataNode { struct rcu_head rcu; IntervalTreeNode itree; - char data[TPD_PAGES][TARGET_PAGE_DATA_SIZE] __attribute__((aligned)); + char data[] __attribute__((aligned)); } TargetPageDataNode; static IntervalTreeRoot targetdata_root; @@ -902,7 +902,8 @@ void page_reset_target_data(target_ulong start, target_ulong last) n_last = MIN(last, n->last); p_len = (n_last + 1 - n_start) >> TARGET_PAGE_BITS; - memset(t->data[p_ofs], 0, p_len * TARGET_PAGE_DATA_SIZE); + memset(t->data + p_ofs * TARGET_PAGE_DATA_SIZE, 0, + p_len * TARGET_PAGE_DATA_SIZE); } } @@ -910,7 +911,7 @@ void *page_get_target_data(target_ulong address) { IntervalTreeNode *n; TargetPageDataNode *t; - target_ulong page, region; + target_ulong page, region, p_ofs; page = address & TARGET_PAGE_MASK; region = address & TBD_MASK; @@ -926,7 +927,8 @@ void *page_get_target_data(target_ulong address) mmap_lock(); n = interval_tree_iter_first(&targetdata_root, page, page); if (!n) { - t = g_new0(TargetPageDataNode, 1); + t = g_malloc0(sizeof(TargetPageDataNode) + + TPD_PAGES * TARGET_PAGE_DATA_SIZE); n = &t->itree; n->start = region; n->last = region | ~TBD_MASK; @@ -936,7 +938,8 @@ void *page_get_target_data(target_ulong address) } t = container_of(n, TargetPageDataNode, itree); - return t->data[(page - region) >> TARGET_PAGE_BITS]; + p_ofs = (page - region) >> TARGET_PAGE_BITS; + return t->data + p_ofs * TARGET_PAGE_DATA_SIZE; } #else void page_reset_target_data(target_ulong start, target_ulong last) { } From patchwork Thu Feb 22 20:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=VurPbK1A; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglh55b9zz23l1 for ; Fri, 23 Feb 2024 07:52:21 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFva-0008Ay-IT; Thu, 22 Feb 2024 15:44:22 -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 1rdFvZ-00088o-6J for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:21 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvX-0002nk-Ln for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:20 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1d51ba18e1bso2648285ad.0 for ; Thu, 22 Feb 2024 12:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634658; x=1709239458; 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=iM2DWBTbIODm0qN2yhX9D3hAXXDtYwow0kqtsMcFoQE=; b=VurPbK1AbyR8HxdE5lor0PPsWgTMf+77WjbJQAKxVmnsOZ8tsDK0c2riN0yar3NTVa /tIBpakzQwPJjgEkHQwEnWh+4NCReswMRlK3I8A2wuobUheLcnF+8a6V/20jB41uv3mJ msf1i9kzBmlI5OlcbPsEYjla3GQTH9TCE012LUkkEOyfPgHdGX6nNknwYB3BkzqSlSrE 1Iqy6M37sUMKdgcS5DUBFoezem7bBRYNNwYjqiRq/0ZwEIZ+jgR0QRSYx+xoGWdxVZDg jUn0t0giIMhq8WuyzjKHnca8V9GRgZGItheEQ4dfbKGK2gjdUPiyzHy1FZ2rYkrP/FNY dj9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634658; x=1709239458; 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=iM2DWBTbIODm0qN2yhX9D3hAXXDtYwow0kqtsMcFoQE=; b=LBELrP/K9qDB+3VxUp8rQYQ45uRwrUbidXvTRwNUblHSxWTjcE7qAavED/OgY3D0O8 SGK2s/oh2Cz3b8Kul5l+LsOB6jLA8HEiwmQTJVnLxGDweR6L0yLZ9XqQ/ge1gkXfdDYs 0JCiZtTxPp2yt8XRE+b61KZmuQohTD2sUB9z87tpy9AXCH7dJmqJFw4p2P8mUBVGq/DZ 3WppPh7cWa1cCujxl3I79C2s18YqZ0F4Icun/g8V9C0bpVvizb8G3wo4Dnrh76G/H5+l Ayd13sLYOkhEClfJG9IJY27Zn4aO/H/uwtvgq+n5zQ4J9xaAMqHiRcO/KmtrkfNK93RT FKWw== X-Gm-Message-State: AOJu0Yw0FBZLGzEq03NTPwWGnk+QPyNZ6a3r0Z2jUn3ZJLgl3WcVd5vC /p8SS7rhW5A60bPWTce3C6BjNNza81TE98h1RnQIs6bUW7YZwowBl8iK99/ZUvBGfKDtbVa24TZ o X-Google-Smtp-Source: AGHT+IG06JrflUAQqv79rhFaLmJaLmi6UpqZx3lE75149ZTqxcXgRF/X2cpbYEMlac+PUPuLyMHCOw== X-Received: by 2002:a17:902:6b04:b0:1dc:5d2e:c18c with SMTP id o4-20020a1709026b0400b001dc5d2ec18cmr1608170plk.67.1708634658496; Thu, 22 Feb 2024 12:44:18 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Helge Deller Subject: [PULL 34/39] linux-user: Allow TARGET_PAGE_BITS_VARY Date: Thu, 22 Feb 2024 10:43:18 -1000 Message-Id: <20240222204323.268539-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If set, match the host and guest page sizes. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Helge Deller Message-Id: <20240102015808.132373-30-richard.henderson@linaro.org> --- linux-user/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index bad03f06d3..12bb839982 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -55,6 +55,7 @@ #include "loader.h" #include "user-mmap.h" #include "tcg/perf.h" +#include "exec/page-vary.h" #ifdef CONFIG_SEMIHOSTING #include "semihosting/semihost.h" @@ -680,6 +681,7 @@ int main(int argc, char **argv, char **envp) int i; int ret; int execfd; + int host_page_size; unsigned long max_reserved_va; bool preserve_argv0; @@ -791,6 +793,16 @@ int main(int argc, char **argv, char **envp) opt_one_insn_per_tb, &error_abort); ac->init_machine(NULL); } + + /* + * Finalize page size before creating CPUs. + * This will do nothing if !TARGET_PAGE_BITS_VARY. + * The most efficient setting is to match the host. + */ + host_page_size = qemu_real_host_page_size(); + set_preferred_target_page_bits(ctz32(host_page_size)); + finalize_target_page_bits(); + cpu = cpu_create(cpu_type); env = cpu_env(cpu); cpu_reset(cpu); @@ -804,8 +816,6 @@ int main(int argc, char **argv, char **envp) */ max_reserved_va = MAX_RESERVED_VA(cpu); if (reserved_va != 0) { - int host_page_size = qemu_real_host_page_size(); - if ((reserved_va + 1) % host_page_size) { char *s = size_to_str(host_page_size); fprintf(stderr, "Reserved virtual address not aligned mod %s\n", s); @@ -904,7 +914,7 @@ int main(int argc, char **argv, char **envp) * If we're in a chroot with no /proc, fall back to 1 page. */ if (mmap_min_addr == 0) { - mmap_min_addr = qemu_real_host_page_size(); + mmap_min_addr = host_page_size; qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx (fallback)\n", mmap_min_addr); From patchwork Thu Feb 22 20:43:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=MCW1gh4Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglWW2ZFYz23l3 for ; Fri, 23 Feb 2024 07:44:55 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvc-0008CR-1g; Thu, 22 Feb 2024 15:44:24 -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 1rdFva-0008BR-Ts for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:22 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvZ-0002o9-8G for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:22 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d7431e702dso2274875ad.1 for ; Thu, 22 Feb 2024 12:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634660; x=1709239460; 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=uW4mSrnyRkLcpmuT0B32llPRivoOZrRn2N/1ffLpPkI=; b=MCW1gh4Z6LvjG6XcVCAqvXJL25fVM5H1tIDHvZuA7ZwuTfXV9aW/aY7Meb9ykuV/qm BnYvJ37vhQwPfQ9ECPgkbJXwlMiDRG8rXe85hqSwgMLtB4hBWT/aCfhZZO+SZV79RTph /mwA0d/7WvpxrbYH1rBXiiFL0bN6DK0/XPVc/d29QqU2eub7b2acDFcnMnSEd7ouQUMS PjuhnQFa44F59OGsJhoBiHPC+GaAhJhSV8dFV+cM5lST9ubwgVpWv11Qm4/pCPoYAfy9 GTbJThp2vOhHKOb8q/fNwKN2Vbh9GwaF1ZaF/2bMGW16il9mrZCFM2Vvs0os0XAXM8kp oLMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634660; x=1709239460; 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=uW4mSrnyRkLcpmuT0B32llPRivoOZrRn2N/1ffLpPkI=; b=l9EXCDLNnX3Fkf+fH6TeejWGdk7/p8QIWswoTmUAN4es/YL2nTYaP8aNIOHme7zK4x dA6+1yGaDQdEk7hMZM4mDj4ytP97i45mUM3YnwzsdiHgzx1fkhd0HsDZPjQSzZccM9Lo TsFM4Do1bBwmTI2EPFKz0YhVzuBeHl+POEWZ6ULhYOl1rQyKgcmPnZ0QPWlAks5EbbPB 4Nd3DWSFiZtTZO2rYBmqrRWdAxH3z4WdAhvTWexmL/57rWNrF4TN6gzlPE9xTtO6PQ18 UqPyh0+EtCQZvfeR/+62ZQVPE0ZlV+7iwvgECzKCuDkjKPUhO+SUUe+dGLJF0gF9MEgr 6WDA== X-Gm-Message-State: AOJu0Yx5dxXk+6gfvU8NcpPnjPzJbU82Ovl+gSCL/Vz/cV5d3KJQmJrn wD37iVrZMM28NBHcQHCZlwNuCQ0rI7eNJaC9hS5UNqSHI8cnizJHg9ylOgLSKCmEXmzDVZcNmI5 b X-Google-Smtp-Source: AGHT+IEdWzwPJBH6227neRzvDAzwO+ClwUrkcp8wmtteXbAZ/uHB7QPYFxb5urDKVHJU1wyJO0tQ4A== X-Received: by 2002:a17:902:6504:b0:1dc:4aa1:df32 with SMTP id b4-20020a170902650400b001dc4aa1df32mr2747689plk.14.1708634659940; Thu, 22 Feb 2024 12:44:19 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:19 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PULL 35/39] target/arm: Enable TARGET_PAGE_BITS_VARY for AArch64 user-only Date: Thu, 22 Feb 2024 10:43:19 -1000 Message-Id: <20240222204323.268539-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since aarch64 binaries are generally built for multiple page sizes, it is trivial to allow the page size to vary. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Acked-by: Helge Deller Message-Id: <20240102015808.132373-31-richard.henderson@linaro.org> --- target/arm/cpu-param.h | 6 ++++- target/arm/cpu.c | 51 ++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index f9b462a98f..da3243ab21 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -19,9 +19,13 @@ #endif #ifdef CONFIG_USER_ONLY -#define TARGET_PAGE_BITS 12 # ifdef TARGET_AARCH64 # define TARGET_TAGGED_ADDRESSES +/* Allow user-only to vary page size from 4k */ +# define TARGET_PAGE_BITS_VARY +# define TARGET_PAGE_BITS_MIN 12 +# else +# define TARGET_PAGE_BITS 12 # endif #else /* diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5fa86bc8d5..2325d4007f 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1809,7 +1809,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) ARMCPU *cpu = ARM_CPU(dev); ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev); CPUARMState *env = &cpu->env; - int pagebits; Error *local_err = NULL; #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY) @@ -2100,28 +2099,36 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) !cpu_isar_feature(aa32_vfp_simd, cpu) || !arm_feature(env, ARM_FEATURE_XSCALE)); - if (arm_feature(env, ARM_FEATURE_V7) && - !arm_feature(env, ARM_FEATURE_M) && - !arm_feature(env, ARM_FEATURE_PMSA)) { - /* v7VMSA drops support for the old ARMv5 tiny pages, so we - * can use 4K pages. - */ - pagebits = 12; - } else { - /* For CPUs which might have tiny 1K pages, or which have an - * MPU and might have small region sizes, stick with 1K pages. - */ - pagebits = 10; - } - if (!set_preferred_target_page_bits(pagebits)) { - /* This can only ever happen for hotplugging a CPU, or if - * the board code incorrectly creates a CPU which it has - * promised via minimum_page_size that it will not. - */ - error_setg(errp, "This CPU requires a smaller page size than the " - "system is using"); - return; +#ifndef CONFIG_USER_ONLY + { + int pagebits; + if (arm_feature(env, ARM_FEATURE_V7) && + !arm_feature(env, ARM_FEATURE_M) && + !arm_feature(env, ARM_FEATURE_PMSA)) { + /* + * v7VMSA drops support for the old ARMv5 tiny pages, + * so we can use 4K pages. + */ + pagebits = 12; + } else { + /* + * For CPUs which might have tiny 1K pages, or which have an + * MPU and might have small region sizes, stick with 1K pages. + */ + pagebits = 10; + } + if (!set_preferred_target_page_bits(pagebits)) { + /* + * This can only ever happen for hotplugging a CPU, or if + * the board code incorrectly creates a CPU which it has + * promised via minimum_page_size that it will not. + */ + error_setg(errp, "This CPU requires a smaller page size " + "than the system is using"); + return; + } } +#endif /* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. * We don't support setting cluster ID ([16..23]) (known as Aff2 From patchwork Thu Feb 22 20:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902970 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=RrxczqX+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglbk43B9z23d2 for ; Fri, 23 Feb 2024 07:48:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvd-0008I4-Ku; Thu, 22 Feb 2024 15:44:25 -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 1rdFvc-0008CS-1u for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:24 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFva-0002pe-LL for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:23 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1dc139ed11fso10255355ad.0 for ; Thu, 22 Feb 2024 12:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634661; x=1709239461; 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=e+A2qkcrgjaI9rrkh97Ktn6PEwqN2bQkXlFCXE4NZ3E=; b=RrxczqX+DJ4rzVYxr7cCaSq6WYI4RSotzi5F4ezjurSAHy/rOrlKz/QZ+Ms3gWACOM 5gdI5crYQrQC8xBYi1dRR6N2NXU69uDGr9MqwNifraFl6rFXj+FFSCpA2Tq6aKPEJLdx sFDbZfOGzJtWFUC+8Nru1fAc4bPIgKnoo4jix9fcyDbXu9dO7miVUWegZMvQivG3bWaw nqlxT9WK/XJVoHV+/4L4kQY5e+ZpetnR0bQiduiYgxoBGq7InfIm5YX8S+5YjBYOiFCW hE5JfIJvVb7aVyea50WzeqQeMBrzma2G1fhZM8YyhCt7cMVQHKYgBiZaP+9Q4ko3aQmP YDAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634661; x=1709239461; 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=e+A2qkcrgjaI9rrkh97Ktn6PEwqN2bQkXlFCXE4NZ3E=; b=JukUD7LxSbbu0sOsp8+kQTMWd+YUvn6ckBQvgrOhYqJyNmkI2jcZ88GyW3Pc53BjaS mLY1lwsdGOyQ/LRk8XlQruAq3golS6hN+eO5gSLBSrWNa6R5RtaMjYIOHQvBuwEYf/4L wRsJAD6Ul9csef615dxnVqVy6VIbXDkq4y5tCpuCsuDCecLd2H47ymqgKc1jnJt4CJMo fy31gLqJjbQCLbOcx4nUcPi1fRgWgvPDLgj8/+3W4VhUnzJTqYj9uT/A4/yMJT9bTYie DHlcHvp86UjDzgX7+CzSaMtVbNNO5JNWtJrbQ16U2CcqZQ5HZfwHjo/ph+9mmdAXZsK8 pe0Q== X-Gm-Message-State: AOJu0YymqH3UIzp2VIfsr5oAoyn0ydsz3aC6kJrl2xj6QaXYjShbFolK goUhbkNu/Pr1WhS7rab3bBklKX/swjUxqHEhXfllHqJ4hsZMkbf4qiyqfCd0f16HS/i1dsRh7fc B X-Google-Smtp-Source: AGHT+IHj4x4KoLMrZPuSmly4HIFtIoXiJHEcY/4fxE7YzC+IG65DzjnX8lBKkrLmgEMYNB7kM/k/mw== X-Received: by 2002:a17:902:c942:b0:1db:b96f:4a50 with SMTP id i2-20020a170902c94200b001dbb96f4a50mr206635pla.14.1708634661426; Thu, 22 Feb 2024 12:44:21 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 36/39] linux-user: Bound mmap_min_addr by host page size Date: Thu, 22 Feb 2024 10:43:20 -1000 Message-Id: <20240222204323.268539-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Bizzarely, it is possible to set /proc/sys/vm/mmap_min_addr to a value below the host page size. Fix that. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-32-richard.henderson@linaro.org> --- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index 12bb839982..551acf1661 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -901,7 +901,7 @@ int main(int argc, char **argv, char **envp) if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) { unsigned long tmp; if (fscanf(fp, "%lu", &tmp) == 1 && tmp != 0) { - mmap_min_addr = tmp; + mmap_min_addr = MAX(tmp, host_page_size); qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx\n", mmap_min_addr); } From patchwork Thu Feb 22 20:43:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=QI42+2rj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tglcq2kMrz23d2 for ; Fri, 23 Feb 2024 07:49:31 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvh-0000Bu-9L; Thu, 22 Feb 2024 15:44:29 -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 1rdFvf-0008U3-Kn for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:27 -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 1rdFvc-0002pq-1M for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:27 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1dc5d0162bcso613605ad.0 for ; Thu, 22 Feb 2024 12:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634663; x=1709239463; 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=KYeT1V/wjgovpdrb0SONHx5NJHYkyLqzQDA/KKTsreA=; b=QI42+2rj+7GidUYbORxEOjUYcCvca6yba9mtOkpm4TIhiDR/A+IPE/EAmnKUMw47Y2 IFF0bOYlGd0xVssNDAo+7hcGY87ceNdm3lvaPWIEDyVP+mQhw/JLSto0F6s9m/QVeTmF d2+c90ZuGfcSwGv5htTHoeQxEmJfQHGcOn9l3nH2fQdUP6/jBR21PM671bpf1VsAzs+M HEMXWhKVuFh6Ntns0RxFzfEFCXHb48bkCnM5/mdp05sWRvi0n+ldL8RgSOaSkQFgYNLO jfn4pzGUUJ2v/o3J0R8jZAedHH2yWuy4Hx61ZgElht6dJg80Zhme+2pwgfrK+mesHq7W Y5Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634663; x=1709239463; 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=KYeT1V/wjgovpdrb0SONHx5NJHYkyLqzQDA/KKTsreA=; b=X3bC1pbOScLhCTbKo7mMZfC426DgI93tjlj7gLnlSr5wQVgIX8UDy1h3cOaOIYhjIq LXFWosbSdAYPu1Rds/xIIe20WJsjj+gy0fGBgXqqg73x6QjRjFRYVByszSVLpf0TTwlj S7JvAKMf6k98KCVr49yG5Jd78UFrc3r0usoG/qIj5eaapWbPmkc50q9YiKVCT2TDse5f yAv47R4HDbYWuuwhFMWM3jstlPniq1rWvKvMT1sQ1du883OW7jYTCDscY840hWkbWMYb XbibqYAK/gsT3GZeJ2FerQ9/G07ipeLwSAAACqVeeQvdtnpwsNxIcEx77iCAqjjetxiB QPVA== X-Gm-Message-State: AOJu0YyZgVw8mBZApzHBCsReAag0nzGBLJ+LDO4Ko4C/CLghAK4zdiRw 32UtbvO2EY+xK1Is8u4Iv3aet8fzRQNZm7hA8Ypr83p76Fzg01yZ4igeEtolg8DuYyLwnezK4Bm r X-Google-Smtp-Source: AGHT+IG4megIkJ/DOoXf3Swsa/+1KpgVYZ2p24cETZIU/FgFKa+qM2MtubqK6bETL4ILS90GdrccSQ== X-Received: by 2002:a17:902:6f10:b0:1db:9fa4:c770 with SMTP id w16-20020a1709026f1000b001db9fa4c770mr14920062plk.34.1708634662870; Thu, 22 Feb 2024 12:44:22 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PULL 37/39] target/ppc: Enable TARGET_PAGE_BITS_VARY for user-only Date: Thu, 22 Feb 2024 10:43:21 -1000 Message-Id: <20240222204323.268539-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since ppc binaries are generally built for multiple page sizes, it is trivial to allow the page size to vary. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-33-richard.henderson@linaro.org> --- target/ppc/cpu-param.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/ppc/cpu-param.h b/target/ppc/cpu-param.h index 0a0416e0a8..b7ad52de03 100644 --- a/target/ppc/cpu-param.h +++ b/target/ppc/cpu-param.h @@ -31,6 +31,13 @@ # define TARGET_PHYS_ADDR_SPACE_BITS 36 # define TARGET_VIRT_ADDR_SPACE_BITS 32 #endif -#define TARGET_PAGE_BITS 12 + +#ifdef CONFIG_USER_ONLY +/* Allow user-only to vary page size from 4k */ +# define TARGET_PAGE_BITS_VARY +# define TARGET_PAGE_BITS_MIN 12 +#else +# define TARGET_PAGE_BITS 12 +#endif #endif From patchwork Thu Feb 22 20:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=aapvMTa0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TgldF2pnKz23d2 for ; Fri, 23 Feb 2024 07:49:53 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvi-0000Q4-Dy; Thu, 22 Feb 2024 15:44:30 -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 1rdFvg-00008Z-Rc for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:28 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvf-0002qm-3u for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:28 -0500 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-53fa455cd94so77017a12.2 for ; Thu, 22 Feb 2024 12:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634665; x=1709239465; 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=nZgxz9sv+Wfw3NEh+PaVP4+cTZIcAB3l+Ojbwy+/FqY=; b=aapvMTa08l9dR6SGmYHP3k3nF1Jf7GTaTyZQI4KhzOYnjMQv1983H2ENRgrDL5wYDD lgSGkxCgLyW3qooo//o4xCb7Zkpm9fm0fdk5ITUx9OS9EPst87rsXXZ3ZRAGiRYuIp7h e+Jdjp7gv+51tnOZcbr96eAzV2EXRik61XXyyMYhqLZqidiDbznfWeSOvw+BCKcPUkzW pbuZIUlmdtF+SxI/HA1vwwUFVEgidvyIEinzwiAtmgQoiTdanBaxFyAM3G5Pn9NCPu/b ZTPCRrgm55BQW/jYJAC3JcrDeoBqF2TKNkV/e8ZGAZRFBJCAiVoGdI88XHFGGrGF4gfI 7FAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634665; x=1709239465; 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=nZgxz9sv+Wfw3NEh+PaVP4+cTZIcAB3l+Ojbwy+/FqY=; b=sjlbrruH3o+1wRpcU41imEqBF5aJjfepTMjKyz0EZoFC1cb3aBiIlXRZb5AUSg8rWb BTfJxWe8XczitLkUg5JGoL+6w863QcEAf6xsi0NtBR/rlNu2hc8sWrMuKiM4O+QqP6gT rpSZCHI/cWID1SqJ1gzk8NfYH2FjgQGRLlnx/YL8jpV3FbAmHMuKFK9fmqgTHEBhVMFI jNm0icW89ngo7NlqQZ0P9Hu6wcZadcTeU096SAWD/q5rK4TqoEq+573S+YBbJUF1Nq7J L1rI0XJXS/2ohpbq1rG+5TvozhPYr0JRed8OnHubHXMv3Ip+4TBrAS5nzl7eaiKKTVN+ 7OxA== X-Gm-Message-State: AOJu0YwpTmW/K8fOSeAhEP78puNF9/d5JhTmNzFrf9zXdJi9bTGFaKj1 L6WA4nFaoP7nSTsEPBaXEwBKG6q26lR3Hup8i/sSR8DttjVcjggLO+EYzm2I49ylqmuHAbP+cQp Q X-Google-Smtp-Source: AGHT+IGtk8U1oBd9J2hNINjlM3l+J+lqFhSsY3Q2lflLXPqzceAc/B1PsZTo/7Lifj7hZJAlFhQftw== X-Received: by 2002:a17:902:a3c3:b0:1dc:1ff5:3dfe with SMTP id q3-20020a170902a3c300b001dc1ff53dfemr7073216plb.27.1708634664745; Thu, 22 Feb 2024 12:44:24 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PULL 38/39] target/alpha: Enable TARGET_PAGE_BITS_VARY for user-only Date: Thu, 22 Feb 2024 10:43:22 -1000 Message-Id: <20240222204323.268539-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since alpha binaries are generally built for multiple page sizes, it is trivial to allow the page size to vary. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Ilya Leoshkevich Acked-by: Helge Deller Message-Id: <20240102015808.132373-34-richard.henderson@linaro.org> --- target/alpha/cpu-param.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/target/alpha/cpu-param.h b/target/alpha/cpu-param.h index 68c46f7998..c969cb016b 100644 --- a/target/alpha/cpu-param.h +++ b/target/alpha/cpu-param.h @@ -9,10 +9,22 @@ #define ALPHA_CPU_PARAM_H #define TARGET_LONG_BITS 64 -#define TARGET_PAGE_BITS 13 /* ??? EV4 has 34 phys addr bits, EV5 has 40, EV6 has 44. */ #define TARGET_PHYS_ADDR_SPACE_BITS 44 -#define TARGET_VIRT_ADDR_SPACE_BITS (30 + TARGET_PAGE_BITS) + +#ifdef CONFIG_USER_ONLY +/* + * Allow user-only to vary page size. Real hardware allows only 8k and 64k, + * but since any variance means guests cannot assume a fixed value, allow + * a 4k minimum to match x86 host, which can minimize emulation issues. + */ +# define TARGET_PAGE_BITS_VARY +# define TARGET_PAGE_BITS_MIN 12 +# define TARGET_VIRT_ADDR_SPACE_BITS 63 +#else +# define TARGET_PAGE_BITS 13 +# define TARGET_VIRT_ADDR_SPACE_BITS (30 + TARGET_PAGE_BITS) +#endif #endif From patchwork Thu Feb 22 20:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1902962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=zFvQBNZ4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TglYB3vVDz23d2 for ; Fri, 23 Feb 2024 07:46:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdFvk-0000cw-8v; Thu, 22 Feb 2024 15:44:32 -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 1rdFvh-0000Ap-3z for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:29 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdFvf-0002r9-C4 for qemu-devel@nongnu.org; Thu, 22 Feb 2024 15:44:28 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dc1ff3ba1aso392585ad.3 for ; Thu, 22 Feb 2024 12:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708634666; x=1709239466; 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=8IHP5ncEs8tF3IKC2tmO2/I2hmkIrpcpNSR+zNTTzRE=; b=zFvQBNZ4z+cZKLLa9HO6ZhSEqZszskTadS7m3eeKK3dFB9jzelPniaZwmrZNzCCTAG HvFEcWhGXXKoVahl1CtmQ3Toj+UuJTVNbdUx/lOrLsS+8INZ46AXUvoZ8cKEJ3ePSOAd WkFSOGxQgFo3duVha/WEyIsckNAYKtz0vhBz7u6QqjNhu5lbMNf5o+oJRzOqCNsdV7tw aeZLWG3eNUyjYGFAe0i1m3Fvi6Xu1iE8RyJNH0w9mvNcPg25gOukssv+YvW6BmlRXZz/ D43Gjq/4ffgUPnyRS1qw+ebM8BNGzb23KRc47pakqcDiqMVcAplNSv7UliURk3L7shIF ryag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708634666; x=1709239466; 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=8IHP5ncEs8tF3IKC2tmO2/I2hmkIrpcpNSR+zNTTzRE=; b=DXqqBlkP3DP33Io42TBFcs1afZ0VzPsOpo2GRuEf273PL9I11NmyRuEPsCwAZZa8zG VFRZq0PFSqXstymtY1t/oe1BUbyRbU7NY03If30d3adIqCkoiS+uLqStxiV5gfyZr+Pt UiFry3Nh6voa6xryeJFtJqi+0JU6nEZWffrUe0aTApvBSvQpmA8vRhKXiBkQKQotojgd yJmhU3QlH8yHcvljzUSbfQowZ1KgJh510IpOiEuZ28WQ3EvyO8NKWt7PSJqAMUlklmZd MU8vq6WjTHr9I/shT1BAjmNbzBT+d2sDVrbbpV38eALGLg+TNxj+wF3ip2zGfaqccxfR dHGg== X-Gm-Message-State: AOJu0YzpwjoMt00N8+8hBvUv1JbuFQqv4bUk80e5clBus4+bi9DS34n7 0BxZg7yv4QBIGHBorOLgcOPF6W1S64SEM2OlTMG6hOD70LPvH57X1/TDKxmE9gPIeB1mJR07V4v f X-Google-Smtp-Source: AGHT+IHFEOzU9Tg4swhd+twq6hRB7UvutgSNhHJxmwPp3XpdY3d92zeLvbYD805AhfB5jiFLMum8lg== X-Received: by 2002:a17:902:8eca:b0:1db:53cc:1b71 with SMTP id x10-20020a1709028eca00b001db53cc1b71mr19682143plo.45.1708634666121; Thu, 22 Feb 2024 12:44:26 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id l12-20020a170902d34c00b001d8f81ecebesm10275500plk.192.2024.02.22.12.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:44:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Alexey Sheplyakov , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PULL 39/39] linux-user: Remove pgb_dynamic alignment assertion Date: Thu, 22 Feb 2024 10:43:23 -1000 Message-Id: <20240222204323.268539-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222204323.268539-1-richard.henderson@linaro.org> References: <20240222204323.268539-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The assertion was never correct, because the alignment is a composite of the image alignment and SHMLBA. Even if the image alignment didn't match the image address, an assertion would not be correct -- more appropriate would be an error message about an ill formed image. But the image cannot be held to SHMLBA under any circumstances. Fixes: ee94743034b ("linux-user: completely re-write init_guest_space") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2157 Signed-off-by: Richard Henderson Reported-by: Alexey Sheplyakov Reviewed-by: Philippe Mathieu-Daudé --- linux-user/elfload.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f3f1ab4f69..d92d66ca1e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3022,8 +3022,6 @@ static void pgb_dynamic(const char *image_name, uintptr_t guest_loaddr, uintptr_t brk, ret; PGBAddrs ga; - assert(QEMU_IS_ALIGNED(guest_loaddr, align)); - /* Try the identity map first. */ if (pgb_addr_set(&ga, guest_loaddr, guest_hiaddr, true)) { brk = (uintptr_t)sbrk(0);