From patchwork Fri Mar 1 23:05: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: 777074 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1600774wrn; Fri, 1 Mar 2024 15:07:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVd0RdHVVFzPnSKVl+z7l95FONkjpBhXSthRe+sT17YV5dZApV/xIFgU3Zc+kgf8Ngpm7dYiWFjNZ5+RLaTeDXS X-Google-Smtp-Source: AGHT+IFezRhd4qdaIumsRaX4arUPIo21PdBsmHY+KxPsWYa2i8x8QcX6fK34POSFSgIpElFJE4G/ X-Received: by 2002:a0c:f64e:0:b0:68f:89fe:28f2 with SMTP id s14-20020a0cf64e000000b0068f89fe28f2mr3102557qvm.9.1709334425676; Fri, 01 Mar 2024 15:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334425; cv=none; d=google.com; s=arc-20160816; b=OpGJMovqVB7GpOzCoSOKagqqE6y7roj7aeV+Zsj7aHtY5KzuRJJhtX3eimmJ1hG/UP Jasdnhvi09Vu4kCJw/vdmeZJvxdC9iJDhsaR9AbWItDhMzWi6pozglujSxwNtShfyJmc tNLxpi2N2FjHNjC2W4YON6f/1C+KyzHXvHeYRxnJOkenAm7dioizgA0CDe2UebPC+glv 2xXdT5/qUKswGIplZriquTeKt7s+ZEnrjdkHONgDAP/UKiaPaAedgxE9EIx2Nw0OrnAV VRulFkNICiJzo0QIQuRmZTuC2Logh3eufjVUjQMUnWJ9jr86OqtHEPe5PXoqXo0XjaHR gFpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WHvhcE4xVUGsA+1z7u9QEyHKVjaKd5k7EQymbD1rMkw=; fh=eu2DY09p+eeddYDiV+DalJS3Vr0kxK5BujclYkgWvDw=; b=RTpx4ri7MpwRixC8UtZzAWvcY02+PCQxMxntHwOI7tU4JvdCQNrJBFmL2mj1lqcSgg QL9a2nCPIOVAHHhxLBUBKqsAdkYcSzURkdBJJX8fsTkl9m90N8wZ3RYyiXcCNNR64/z3 JeVL6cKHwNwwKdB8UwCZv9YdSGpwZDu96okZ3/mZnK9zdIWc1YfF2AGJNaIQmiwB//IA bP1rh6ONXK040RtOYQ4kJvL9Mc/qHc/kw27sVuan3w+KXqb88pTwTiYoPEazJva2N3P6 dgpt92C+H4TtqhHZJ1my7x9FZDs9a/VDQvB4XvhZSm4ByzjOEIDQ7Cntdm0QA0jntTHB mVTw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GEJwmsmZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o3-20020ad45c83000000b0068fbf29117asi4841376qvh.225.2024.03.01.15.07.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:07:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GEJwmsmZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxW-0004q0-3S; Fri, 01 Mar 2024 18:06: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 1rgBxT-0004pP-5o for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:27 -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 1rgBxR-0004CG-IC for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:26 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc1ff3ba1aso22774735ad.3 for ; Fri, 01 Mar 2024 15:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334384; x=1709939184; 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=WHvhcE4xVUGsA+1z7u9QEyHKVjaKd5k7EQymbD1rMkw=; b=GEJwmsmZnQu65aynPosZz4upVsiwc13h9zIiSXBGoaI20iaH6GV2ACvhgPtpwZB/L5 3VeqC4grZxzs0FF/04knQYU2RVFTahE72WCk/al0xsFCcEBXGOOQb8HbEKbPLgbyAfAO gPnA+2o5xPK/uD95X70NVX54SMWVT0Vh32owOxoIOUAUdwn+/ayMnmUvLFyq20Fl5WQe I1rYir96NZhnphnRzOLCEmN9JsMvl74yAukn+XMtvMvfnH6kKbwYDljr0hjHz7CZ4SIw DPcRCbvAcymfN4hKSrIB26XItFZx0WewmElLWzDsda5/qd8/lxzXWpmhHJMiBnfaNqFd h6hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334384; x=1709939184; 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=WHvhcE4xVUGsA+1z7u9QEyHKVjaKd5k7EQymbD1rMkw=; b=C7eCdMtWdrajWTvsP2OJUSV+0cWlvyQiJId/Inpeug/JnDrsLnUguWjC+LiD+53RIR 5Cb3Ff0ad4zSO3Pvd2IBvfso7Fr9mRyV+xD1r4iWXj5gtbHpIABVYzFmYuOeowccaFcY v16PfU9MOS52oMm14i+gy2+DtOB30k1yJ2Jg7tS312ui417KgxK9+Zc/y49MsBwKQ4nV 4/gjkz1LdiGUuIkl7A9RpKobDwaAj12fl6CxiUmW/ulbDhLdwS2XUyFHV7DYtWQ7QRK/ g+pg+QM0Ozu0iknFo4AcP4IUeZwTj/WIUUVFOcwgpC0bDSyuDPAhGSsGOjokMxhbykIW tzOw== X-Gm-Message-State: AOJu0YzIVMm8OYHt2IdgDuqGKvTfu1mluKIMW55SBWMZV/c1UVFrHQLb yYD8RJ2drM+90+hfCawyEErx11Fiz8JaSrSQMmTYsZc5FddsKoxEyqRNJJ+j5rAlCrEElXENift N X-Received: by 2002:a17:902:d491:b0:1db:c6a0:d023 with SMTP id c17-20020a170902d49100b001dbc6a0d023mr3659462plg.8.1709334383888; Fri, 01 Mar 2024 15:06:23 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:23 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH 01/60] linux-user/elfload: Disable core dump if getrlimit fails Date: Fri, 1 Mar 2024 13:05:20 -1000 Message-Id: <20240301230619.661008-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not dump core at all if getrlimit fails; this ensures that dumpsize is valid throughout the function, not just for the initial test vs rlim_cur. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b8eef893d0..fb47fe39c9 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4673,7 +4673,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) return 0; } - if (getrlimit(RLIMIT_CORE, &dumpsize) == 0 && dumpsize.rlim_cur == 0) { + if (getrlimit(RLIMIT_CORE, &dumpsize) < 0 || dumpsize.rlim_cur == 0) { return 0; } From patchwork Fri Mar 1 23:05: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: 777075 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1600771wrn; Fri, 1 Mar 2024 15:07:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVPHAYC5OHO+WCt2ED9miQ2iLg5iJIknAWV7vFOVUfUFQdBu14lOP1SS6JjSI4Tf+8ZBV9zsATH6ZvtKuEwSO/w X-Google-Smtp-Source: AGHT+IEOyGHCbq3nKd5txB6lrlKIL72+y02TD5a/cSzk8fyBu4wVIM7HjwSxVS3haA0K3XbxXYCc X-Received: by 2002:a05:620a:1786:b0:787:e42f:124a with SMTP id ay6-20020a05620a178600b00787e42f124amr3901837qkb.36.1709334425516; Fri, 01 Mar 2024 15:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334425; cv=none; d=google.com; s=arc-20160816; b=KeqXseTAFAJ5QA1N9DUryTzFylj+3xReXWlqv46kRonmmsiSO8NhBHyHR/9bzmjz6v 9EvKpimud0j8Yf1ovhEG0FmAiKsix9a8M1O+MBAhWnB0miJ0WXtChbBP4yS9XXjp6mn4 TogeutfHSQXH9pJtgoemAuf+gb68/Hn4BC480KECL1vSZNvnGWWGrouNOBEy2b9tV0rt ZpNj3GgTDf6gbLK//3rg0CSqyqXuHmzFjseHH+/k3g8F2FJce7UWMFsoRkP0osu6MQap +pyD6+D4tq7iXTB11GXLtQR9PQr6DxEdoosz9USlbz+YcpEQjKBtYCHXzfy+zpqMKV0q 8ftg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c1WCKXawMTZMOrVqL/DhlUtKi+hfbHIEOTuyKivWJBk=; fh=eu2DY09p+eeddYDiV+DalJS3Vr0kxK5BujclYkgWvDw=; b=QbxuI/KuaFp9M4VvfcCff+L/5YNNP3YrCEBUgtoOdZUDrOkOdOtA9pItXueN5DbL2h lIOGB6IIM4OXOzyoNp8EyX359osCoCKMpgBt+cGpUUfG8xZCiZR8vuYGU/QisZCO1Orb xP0EtkJBU6RpV17QTjF4d0HfQLRyg2aKBln3XhYSdO9xqtoaPC0aJbeCcmlZza7dF0wB jWk6jKsTq0HxmLYFn95KqQ+GkGgP6v2beOAQHT36B2M2HLFBok+QiXV/janAJfFMpSUs QwvbQJw2LNXRHXQRqGD46FqD+mapf5bDsccIDSvID8FYuJfaHTO+PxmZE01L6T0wEAzP Xcsw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q5IUtvV7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bi4-20020a05620a318400b0078819a3098csi185929qkb.372.2024.03.01.15.07.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:07:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q5IUtvV7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxY-0004qo-Te; Fri, 01 Mar 2024 18:06: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 1rgBxU-0004pm-9P for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:29 -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 1rgBxS-0004CK-Se for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:28 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dcad814986so23696845ad.0 for ; Fri, 01 Mar 2024 15:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334385; x=1709939185; 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=c1WCKXawMTZMOrVqL/DhlUtKi+hfbHIEOTuyKivWJBk=; b=q5IUtvV72ltONvA3wjmO4J7+0yBxTs4zRFqXZl4BD/GD3U9BYvy868l+ZkjzERNZVX 3Tn14kD9Vi+5M1onqgkdTEmX0b7/7xicBlQRu7dw9BLgj4gMmpp5t2U/rnO+3z5zyKko pYj4aDYnmyFG5lfyh88P/kzFVmSeqjYncCFLkNHrVac6B5MBykgOwr0071Gp3QWBYFMC aG6wlGO9kSWmibvrseAOD7i30yV3QaZY0Fb6UWNDPlBkAnVkb8sBAEq7uDTxjVmAbO/S IJFMSkGqJS+JNq7p/XkYmncmfddaYzwXFFXbYFVAT3zYRduNiQ/clIUrC7smyEWHa8bJ oPBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334385; x=1709939185; 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=c1WCKXawMTZMOrVqL/DhlUtKi+hfbHIEOTuyKivWJBk=; b=UQQoSRWgEw/KWyihMfH4nVvVZfZ+HpR6TQyWFubYJQJznqvfOMjJ2VWOlwxLDnbdlB USiwigGG5NBtGBgZdAoeW6Gec+uwNMqfTu2BubnPl9N4vV613ij9EyVDlxuzAWT5FQXn R0R8X3nrOilLDYuMveUR5QOcf7XkevUp6EF96+ixKDeW+OE9neQF8Gtg3NtK+pUENaUW M2yzfUuBbZbUY4AF76LAsoCc7OwcnxJMyEF26Hf+3Gq+ppRgoGpikwMsmX/V5+aRfNgh Xa5HFeZL/Od0cmbZdN90JlT14SSxjWVaUr3HX4HLOZnnzG26kf5ZlAZjpPExQUbOUoH7 6ryA== X-Gm-Message-State: AOJu0YyZ6as8eJzixMQY1uFWww6S1kzVsjsF3a+Dk9GKcYoWpGSwNfcn WfyZ22aeoFFGUxYEwE/cI8usZYFQQQsRIhjS7zqd6pDZAx7l2beWEPzSHUCBVkew9LrVwMh4/pR k X-Received: by 2002:a17:902:d58b:b0:1dc:b6bf:fae8 with SMTP id k11-20020a170902d58b00b001dcb6bffae8mr4337694plh.59.1709334385266; Fri, 01 Mar 2024 15:06:25 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH 02/60] linux-user/elfload: Merge init_note_info and fill_note_info Date: Fri, 1 Mar 2024 13:05:21 -1000 Message-Id: <20240301230619.661008-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/elfload.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fb47fe39c9..7b3a2c20f2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4514,16 +4514,6 @@ static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env info->notes_size += note_size(&ets->notes[0]); } -static void init_note_info(struct elf_note_info *info) -{ - /* Initialize the elf_note_info structure so that it is at - * least safe to call free_note_info() on it. Must be - * called before calling fill_note_info(). - */ - memset(info, 0, sizeof (*info)); - QTAILQ_INIT(&info->thread_list); -} - static int fill_note_info(struct elf_note_info *info, long signr, const CPUArchState *env) { @@ -4532,6 +4522,9 @@ static int fill_note_info(struct elf_note_info *info, TaskState *ts = (TaskState *)cpu->opaque; int i; + memset(info, 0, sizeof (*info)); + QTAILQ_INIT(&info->thread_list); + info->notes = g_new0(struct memelfnote, NUMNOTES); if (info->notes == NULL) return (-ENOMEM); @@ -4665,8 +4658,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) int segs = 0; int fd = -1; - init_note_info(&info); - errno = 0; if (prctl(PR_GET_DUMPABLE) == 0) { From patchwork Fri Mar 1 23:05: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: 777084 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601729wrn; Fri, 1 Mar 2024 15:09:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU30nwWLrVDJFPzjHe8ZDQCommSvc075Juxwuj55uGuqfedARoFP2gUyCwO0m36lYjophqpd7o29EDoJC1c4rit X-Google-Smtp-Source: AGHT+IFqgeEz6heBYHXPHWzLPoTRJ8QtEivANrUZe+qjcs7VmDdDp8tFcZn9NbAUjWhIiHJNUg+p X-Received: by 2002:a05:620a:b8b:b0:787:cecb:626f with SMTP id k11-20020a05620a0b8b00b00787cecb626fmr2769277qkh.70.1709334592261; Fri, 01 Mar 2024 15:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334592; cv=none; d=google.com; s=arc-20160816; b=p5PDEKA+2Px+W8E6+TFOr7MNVNDqb9oSZlhH6TZL4V5YkzgKBb7w6Eokg/iJJrp+fe VDzt3Q4AFXl35MVSAB1JA0K/0ekGIWkKPu1bfaqb3LE19yBIXK5rpsO1BM29TqsoKP8P JHn7vwdiEZuv5Ie87FlEAA/+B7AAbyupsbuc25m7FLi9sIjT40ELEnSBw2KnqjfC9bZn paUpYWX7wXOA+0UfyoQp2FADH6PW9FAEXDp7A2LAGoHmJ5yFZArGEchEmPqJYpp0efR6 9YlCeH8bRFoygmUJjiuy7Ebs4VTNWnHBJla6p9kahqY+/zvoeIR5dU2lOVBvxGxd+BWI F0Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=FzASAb+vPP9L2ZUMSMccfl1J94xcqvWt8jVrhxqajRM4Wgr423z2Zu+NjnuiAm28yF k03SbATNka01E/KiMJQIwpw40O9FEC8tDKJpb3n/YLN4gIJrgFUnfWBI47W2X8Y3Vfks 0T59//PTXvHyUhWY8KTIMnHLwARL1eFxCtBiWnY+mAaKAvb1kjiQRMSusm2Qr8xwFhyW B7MrE+Nh4hZJDLRDeBIYfsQSUHXzG5LoqfzxY6aQvedSmW0UYjnYtDyaVPlRN7NLg/+h 3/pU+kti9H4I4SP6fZny0dQ3j19MiMAwJBOu5w9RKT4JooLiKZ+HtXBS7iL6qhxolD7o wOkg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YHLl4gCr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ye6-20020a05620a3b8600b0078768158e32si4451233qkn.476.2024.03.01.15.09.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:09:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YHLl4gCr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxa-0004qx-HE; Fri, 01 Mar 2024 18:06: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 1rgBxW-0004qH-7m for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:30 -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 1rgBxU-0004CX-6N for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:29 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc13fb0133so22382215ad.3 for ; Fri, 01 Mar 2024 15:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334386; x=1709939186; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=YHLl4gCrVPOOvaM/W99Bar1O8CqMDh9crOyBtgsqT9/J4LGAOfMaF+I1ZvtsqnqFL3 nM5HRbBMoyxK0hEZABHDtZywJhUpTsRruPOz9Kd5E5wzGrznPqADJov/B5hxT7CotfSM iY9pEhDUprcPhAgDXHY1p6BbquYr6ThNReZa4SPnYGNYdgtzKGDHA9VPyZm3mHBPEOZE K9JAAireTgHzVYTV2l7GEuIk+VJHNIDsMXsNIl07RYw82a8lItewo9/8viciDVtqcrvi 8MuEH2yN3dg5OUzDUVRg9iGU7ejr8npQld000RjIAYjuE4xZCdjDAR4FSBPp/lgeG1Fu UKRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334386; x=1709939186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=ijGAF+WuHNnxpXISihfhfKT0h51OoHrBtB5BZuRVXTfstFtf74n/9qf6wxMhYbGPcV X5Tr6vngZ00+btVfIjlJ9Qjl0RTUUVoZVHgD+lL68/L9iV0zdBl+/KOQrmezu81ETwR3 cxlF3/ua4JpTsB77ETI0x7YVoOGW/Ovbo8t1wrDJ0wOwodvVcmUliGUpWS+1t+nwW6zV eC6at4UzSxc/Pe1nnrEEQlE2PKtEV7JS6HAxSONBP+69KCEwsvMBG/vv0+WEMDW4p9nF WLjR/+C1x61c7nvuBsTVlB0PbZXkLsxOkXBvPBGYxX3VZ8OLBdFjHnl25cnbYrc3BQXC fJ+A== X-Gm-Message-State: AOJu0YwEU+c3GYzFu1zwwTCFfyNzSPJzapKb9NN6n0q2k4VTieO/sGxC ttkt3CnsVBHA7QifkJGwokVLmOvNo5yKiCD7w+/o/2if73Q8JTeVhCdi3xeZEcsA5Cu20g3zy1Y P X-Received: by 2002:a17:902:e807:b0:1dc:696d:ec64 with SMTP id u7-20020a170902e80700b001dc696dec64mr3982507plg.22.1709334386531; Fri, 01 Mar 2024 15:06:26 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/60] linux-user/elfload: Tidy fill_note_info and struct elf_note_info Date: Fri, 1 Mar 2024 13:05:22 -1000 Message-Id: <20240301230619.661008-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In fill_note_info, there were unnecessary checks for success of g_new/g_malloc. But these structures do not need to be dyamically allocated at all, and can in fact be statically allocated within the parent structure. This removes all error paths from fill_note_info, so change the return type to void. Change type of signr to match both caller (elf_core_dump) and callee (fill_prstatus), which both use int for signr. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 48 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 7b3a2c20f2..cc43487a37 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4066,10 +4066,12 @@ struct elf_thread_status { int num_notes; }; +#define NUMNOTES 3 + struct elf_note_info { - struct memelfnote *notes; - struct target_elf_prstatus *prstatus; /* NT_PRSTATUS */ - struct target_elf_prpsinfo *psinfo; /* NT_PRPSINFO */ + struct memelfnote notes[NUMNOTES]; + struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ + struct target_elf_prpsinfo psinfo; /* NT_PRPSINFO */ QTAILQ_HEAD(, elf_thread_status) thread_list; #if 0 @@ -4117,7 +4119,7 @@ static void fill_auxv_note(struct memelfnote *, const TaskState *); static void fill_elf_note_phdr(struct elf_phdr *, int, off_t); static size_t note_size(const struct memelfnote *); static void free_note_info(struct elf_note_info *); -static int fill_note_info(struct elf_note_info *, long, const CPUArchState *); +static void fill_note_info(struct elf_note_info *, int, const CPUArchState *); static void fill_thread_info(struct elf_note_info *, const CPUArchState *); static int dump_write(int, const void *, size_t); @@ -4514,44 +4516,33 @@ static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env info->notes_size += note_size(&ets->notes[0]); } -static int fill_note_info(struct elf_note_info *info, - long signr, const CPUArchState *env) +static void fill_note_info(struct elf_note_info *info, + int signr, const CPUArchState *env) { -#define NUMNOTES 3 CPUState *cpu = env_cpu((CPUArchState *)env); TaskState *ts = (TaskState *)cpu->opaque; - int i; memset(info, 0, sizeof (*info)); QTAILQ_INIT(&info->thread_list); - info->notes = g_new0(struct memelfnote, NUMNOTES); - if (info->notes == NULL) - return (-ENOMEM); - info->prstatus = g_malloc0(sizeof (*info->prstatus)); - if (info->prstatus == NULL) - return (-ENOMEM); - info->psinfo = g_malloc0(sizeof (*info->psinfo)); - if (info->prstatus == NULL) - return (-ENOMEM); - /* * First fill in status (and registers) of current thread * including process info & aux vector. */ - fill_prstatus(info->prstatus, ts, signr); - elf_core_copy_regs(&info->prstatus->pr_reg, env); + fill_prstatus(&info->prstatus, ts, signr); + elf_core_copy_regs(&info->prstatus.pr_reg, env); fill_note(&info->notes[0], "CORE", NT_PRSTATUS, - sizeof (*info->prstatus), info->prstatus); - fill_psinfo(info->psinfo, ts); + sizeof(info->prstatus), &info->prstatus); + fill_psinfo(&info->psinfo, ts); fill_note(&info->notes[1], "CORE", NT_PRPSINFO, - sizeof (*info->psinfo), info->psinfo); + sizeof(info->psinfo), &info->psinfo); fill_auxv_note(&info->notes[2], ts); info->numnote = 3; info->notes_size = 0; - for (i = 0; i < info->numnote; i++) + for (int i = 0; i < info->numnote; i++) { info->notes_size += note_size(&info->notes[i]); + } /* read and fill status of all threads */ WITH_QEMU_LOCK_GUARD(&qemu_cpu_list_lock) { @@ -4562,8 +4553,6 @@ static int fill_note_info(struct elf_note_info *info, fill_thread_info(info, cpu_env(cpu)); } } - - return (0); } static void free_note_info(struct elf_note_info *info) @@ -4575,10 +4564,6 @@ static void free_note_info(struct elf_note_info *info) QTAILQ_REMOVE(&info->thread_list, ets, ets_link); g_free(ets); } - - g_free(info->prstatus); - g_free(info->psinfo); - g_free(info->notes); } static int write_note_info(struct elf_note_info *info, int fd) @@ -4694,8 +4679,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) goto out; /* fill in the in-memory version of notes */ - if (fill_note_info(&info, signr, env) < 0) - goto out; + fill_note_info(&info, signr, env); offset += sizeof (elf); /* elf header */ offset += (segs + 1) * sizeof (struct elf_phdr); /* program headers */ From patchwork Fri Mar 1 23:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777081 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601310wrn; Fri, 1 Mar 2024 15:08:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUQxqUpQw8Rrl7B7QCIC7wMS1l5seME7UZwWanHNOjZ4WQWa5GmhzKYa6C/6hWib5n/kQgcFrpGS1aSr8xE3VMz X-Google-Smtp-Source: AGHT+IHPjlKDJdMfVPVnKaQk4I2vvZbt5OAi8VFZhBt9Yr+qa4Yi+fhz9WhwYirblilzA1eKCNy+ X-Received: by 2002:a05:620a:28d1:b0:787:ecce:1757 with SMTP id l17-20020a05620a28d100b00787ecce1757mr10697411qkp.4.1709334517314; Fri, 01 Mar 2024 15:08:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334517; cv=none; d=google.com; s=arc-20160816; b=h2O+Yg9vTjMWXCsYlXnaAE3Dfzo2b6sxxIhVevbzyWfF4ezs2JsVoSPftVFrRmANzH +vt4m/FXAi3/UQnvaJ4st3S+wfMM/AZ7mpGvOCh1dD5FanAh/morEHUGPDkDwx7qJRnn PFd8y4njVlQ9VcYVHDn7Y1M7tkr47p5mBFOyCq1IM0mUdkfUUI0F1XI6LSb4amdF9eLE qK37llyDUvw+DWXWQcOY9Lxoq8svwKMIXUUjbHIUcoNYuPaVQb9u4YmC1z8g4nviEKTK aSGBXcEkF4m5I+5edQX8BlswGBtrS2grGtV4NtxrrfGOlG1EjbX9gYXNQqfNOsVUKwUs 8ocA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=PHLCWd422qq6Ph6R/D7Eg3QZjkdLaOKxqoQguFbPZ6rhG3v7CKduqbnSfGAlFk+UrK gXfgel+74SWvk861cS3Cw+2D2ejKt0fcQGgdzN8J8KaQ+cXE6w7//OVg1OU1k1sg4UkG kXA6ODLOvpP4zLD7b+ulKs9Vv+R3zOIAD+IMaTpaJ2tFZdpOpwNQf0T7U/pG5i1o8Oub EV7IKAmyc7b9YNcqJTkjNMoweG3kOaIiJWH2xnDJ1ujkjJ+hjeFGZUtgYyZrAuH5YL6p N4AmlA3nmp0npwYDngcb09KOm9NNkEdXOSpR/aK/fP0dPB/TSSSH8KZXrGIOGPwnC/je IsxQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PB9EjzNw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bb2-20020a05622a1b0200b0042e875cdfb4si4940938qtb.43.2024.03.01.15.08.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:08:37 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PB9EjzNw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxi-0004t5-VN; Fri, 01 Mar 2024 18:06: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 1rgBxX-0004qU-Mt for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:31 -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 1rgBxW-0004Co-4N for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:31 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so23771625ad.1 for ; Fri, 01 Mar 2024 15:06:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334388; x=1709939188; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=PB9EjzNw4+NNo/r7ILU/XW4K8BIXsGue2sjOwBuYukLQAdy0Ib67UueXkqSiXx8aB+ VLOC6soi0HY9DJGoHwzXkVr044D82ymw57jeXGD61FYTqzpl0C3T2zyTTOW+aWoyNOob Bl8HJ8jz9bTrz5rv1CJ/FfB4P+2sPqXmtIIGPvT6C1B7WUu+y1RW4tFQmfTyt0rrwyXJ /lMaWCJmvhMpqgjjzJ3cFOVx+wh3Kz4KZCQzordgYufAhEdI2a62Hm4YrUVEOM07pmM4 69cG31S462xYENZ4CVwtgxd7/1LxvxGz6tl9Q1YEQgAMnRn6iIZwsTEKhOh1z0jGF46N qhgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334388; x=1709939188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=keqqLzVNAo4uH25B4sgF/a/mk1kxuvixDsagaZwoXEA=; b=BBTVgrwjERFMD0WzpQp17D+q46zWc4St2LlXNRZXkHf4D8s6heckFZ1hGCgJygtDgP m4oM9acC8+FlO0RLfNdaBMV3IWC8gVDO1SHQjC1L/aqhyzIkuJles/Bdlu7Xb/OcChnm hFvf/kz2cD7RobvFMI66VHV/utCJycDVHSFF0Ta0EJooFlGfo+a5ewHUjFewAHkLQvr4 mkMMdORyK6SNMnu00XIwE0L8bcZgzIbcXupFC0ZWY6+GOh7TlCFJgX6JsWK8U14RCZsd upqNYnRwpxEsmwMWyTWEmeUct6wXMaO+WvWPFV4dsKqrqeEibrfjYQDdZ4BcqsivJYr0 w4VA== X-Gm-Message-State: AOJu0YzK+6igmV5yJK7uCFQaPSzadskPRi5x+5qITOxThSBMKJ7Uxyec UoURVNNCB9VAfBJaBtBeV/6y+8pdCxOQhcrLb1X7M461ALFODEWB0HAd7a2gaLHYWA8fqLj5Lrh 3 X-Received: by 2002:a17:903:190:b0:1db:b8dc:a016 with SMTP id z16-20020a170903019000b001dbb8dca016mr4261042plg.7.1709334387715; Fri, 01 Mar 2024 15:06:27 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 04/60] linux-user/elfload: Stack allocate struct mm_struct Date: Fri, 1 Mar 2024 13:05:23 -1000 Message-Id: <20240301230619.661008-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ignoring the fact that g_malloc cannot fail, the structure is quite small and might as well be allocated locally. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index cc43487a37..98b82b1a49 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4099,7 +4099,7 @@ struct mm_struct { int mm_count; /* number of mappings */ }; -static struct mm_struct *vma_init(void); +static void vma_init(struct mm_struct *); static void vma_delete(struct mm_struct *); static int vma_add_mapping(struct mm_struct *, target_ulong, target_ulong, abi_ulong); @@ -4174,17 +4174,10 @@ static inline void bswap_note(struct elf_note *en) { } * thread that received the signal is stopped. */ -static struct mm_struct *vma_init(void) +static void vma_init(struct mm_struct *mm) { - struct mm_struct *mm; - - if ((mm = g_malloc(sizeof (*mm))) == NULL) - return (NULL); - mm->mm_count = 0; QTAILQ_INIT(&mm->mm_mmap); - - return (mm); } static void vma_delete(struct mm_struct *mm) @@ -4195,7 +4188,6 @@ static void vma_delete(struct mm_struct *mm) QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); g_free(vma); } - g_free(mm); } static int vma_add_mapping(struct mm_struct *mm, target_ulong start, @@ -4638,7 +4630,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) struct elfhdr elf; struct elf_phdr phdr; struct rlimit dumpsize; - struct mm_struct *mm = NULL; + struct mm_struct mm; off_t offset = 0, data_offset = 0; int segs = 0; int fd = -1; @@ -4664,11 +4656,10 @@ static int elf_core_dump(int signr, const CPUArchState *env) * set up structure containing this information. After * this point vma_xxx functions can be used. */ - if ((mm = vma_init()) == NULL) - goto out; + vma_init(&mm); - walk_memory_regions(mm, vma_walker); - segs = vma_get_mapping_count(mm); + walk_memory_regions(&mm, vma_walker); + segs = vma_get_mapping_count(&mm); /* * Construct valid coredump ELF header. We also @@ -4701,7 +4692,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) * Write program headers for memory regions mapped in * the target process. */ - for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) { + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { (void) memset(&phdr, 0, sizeof (phdr)); phdr.p_type = PT_LOAD; @@ -4738,7 +4729,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) /* * Finally we can dump process memory into corefile as well. */ - for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) { + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { abi_ulong addr; abi_ulong end; @@ -4767,8 +4758,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) out: free_note_info(&info); - if (mm != NULL) - vma_delete(mm); + vma_delete(&mm); (void) close(fd); if (errno != 0) From patchwork Fri Mar 1 23:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777096 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602828wrn; Fri, 1 Mar 2024 15:13:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCURfbiDFbJJxb7hT/o4zZoBJo0DAXhfnELsIvhzcVSzVfTZSr+Cs8bWwJtZoOcdzwJZ6PRi77lclX12NKA+iP98 X-Google-Smtp-Source: AGHT+IFtOe6m6KfTnA5iW3j1aWEwkpAUl1i2KAVFC/1AjIbZVCywbLR8oL+zpPzoiqukyPA1FOgi X-Received: by 2002:a05:6358:3a1a:b0:17b:f91d:7e93 with SMTP id g26-20020a0563583a1a00b0017bf91d7e93mr3253126rwe.14.1709334814941; Fri, 01 Mar 2024 15:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334814; cv=none; d=google.com; s=arc-20160816; b=0YM17y2+n0i1fZqE4kIFmQKh20LGtW6hZrtMX9y9lZpqrDng7BgkrXHda6bBJeWVTd 70k0LchwBFrGhp0v//qRUueh2PAsA2qcmshU9NaV+r+FNBpLdVxPzy/hk+e1YIEVy8tI XaxZ4t5Aqi70UPBN2rfxqPDi5/l5PezyEu0dkzP4XYE2G2lmmI+cCv5Ygk7Ko9AzQFoH PGNseb+wFGvgxUkAxv1bjT4pMAtuE6fS9tM7g+yJ4JhgivwitwgIg0xa9Szw1e27CKdc 0dnYFPyYfChkajm5iV1uX7h3Z30j0JOad6oZEviVepwO90zL0fyVw/+68/b+m5OOIxyo gFeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=NtIM56gZ9Kc5VRBu6EX04JT5YioCSQCXU711n85hmK8mDIKEsyWJIu8givqERJHUsh lky92dL16rD7gYWwpZKmx5IrbKGAk/X2bJzzHuHIIuKSXd00FxFBOVsDbiaUD/jLRtZp f/6rXF2nwm92XyguSfk9xS3P/qS37CQUEqDbOc9qk1rKvLQKDIVqdabokYCAxluzjo9J NYj8gEwGD1taKnyB3ZePuDtTTQyRDLOFhKQl+abvT0LkoKg3GsiOnYLtrvqPHbL07pAP VYLioPKa/J6Lvm9aS8ygdDsUI/qcbdOO/ZC96OC6fCe5K79GlWAJOnW1i80XJD/wTexf 8VPw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nOf4jPsq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 8-20020ad45b88000000b0068ffe6c5191si4306364qvp.284.2024.03.01.15.13.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nOf4jPsq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxd-0004rO-Oy; Fri, 01 Mar 2024 18:06: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 1rgBxY-0004qh-19 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:32 -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 1rgBxW-0004Cx-IR for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:31 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc1e7c0e29so10569485ad.1 for ; Fri, 01 Mar 2024 15:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334389; x=1709939189; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=nOf4jPsqFqYBsTdgCrg4Y6c4SGVpaJ5NSqdzpNIQCugZ/oVp2OgE29WoJqQBgq7fsE qtrW4rSK7QLa19bPUEQTL6L2kMXBLEsR1tvgPyLn66JdfL3ShPBvRixMU7XVnZEpKUFO xJRYGTicvGdydqQNp/CAjUHrmdJE9fcEdkt2YEK8IeomIXzUr2HL3LzY0m0fQk+A9Doz 6dSiIk5CPRqysCJPgbH2IbtIWN70qDToD2pOSkzOSmakltmGZErA+NGdPpWYx5Oja9wB eN5CBlkkp4YBhsNdXmNxOYu/A++4xY6+2P7fs3J5nEi03efAulx8dFlRqPm8qEXPThtJ KYVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334389; x=1709939189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=pgFQ2VvvIY+U8BGWMxpT4aeBZbk95eikuEGHYpj+LGm5niGEdyK6P2w9IGFjNTH3S1 EAHfWU4L8+AyLqUz38oO60+YdV3dMOedXmomIk4JLnmHKJE6ayp6o7vVVJvPAnL62ApY 3nQoGH8PXb+cE5E8SLDScuRYw8bdWHz1xv92O+xXk5uk948hRHINJWq83RjdVcBZCZyF vz1DrrL0+67rkw8+hdL8xbRHnjKy4GCOpB8mindDWHAgiAVG0IsZuHLeZwVH7BVTcld+ 5Pt2VPp52bE53a2fUIRSSAiQKCtHt/GMuadq0dYiHngnOi/nWJ31uWqOtHFLTWkGTFe/ GjoA== X-Gm-Message-State: AOJu0YwzIdOtDsNE9wEACqfzeStOIM7d2ZSBl74RuBhNCS8td8HFT2sD DBYmEvmsP4aJ6wgByGpoFEmIWzeyHyFhnY+cTqrUUW5SRYAOTxRVA4qhZ6YO1Zdn7+p9J7R316P O X-Received: by 2002:a17:903:187:b0:1dc:adb2:628c with SMTP id z7-20020a170903018700b001dcadb2628cmr4097679plg.34.1709334388934; Fri, 01 Mar 2024 15:06:28 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 05/60] linux-user/elfload: Latch errno before cleanup in elf_core_dump Date: Fri, 1 Mar 2024 13:05:24 -1000 Message-Id: <20240301230619.661008-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org On the off-chance that one of the cleanup functions changes errno, latch the errno that we want to return beforehand. Flush errno to 0 upon success, rather than at the beginning. No need to avoid negation of 0. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 98b82b1a49..39d9ef9acc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4634,8 +4634,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) off_t offset = 0, data_offset = 0; int segs = 0; int fd = -1; - - errno = 0; + int ret; if (prctl(PR_GET_DUMPABLE) == 0) { return 0; @@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchState *env) goto out; } } + errno = 0; out: + ret = -errno; free_note_info(&info); vma_delete(&mm); - (void) close(fd); - - if (errno != 0) - return (-errno); - return (0); + close(fd); + return ret; } #endif /* USE_ELF_CORE_DUMP */ From patchwork Fri Mar 1 23:05:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777107 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603716wrn; Fri, 1 Mar 2024 15:16:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXwnKOUjwOcloJyVjtuWoySHT8ybQ/fIr5iWQCfA5YnzRCxcSwAFUOe/l7cA+KxDLMUDMCYZelAbNaWOIOcij0h X-Google-Smtp-Source: AGHT+IFsCqtD0hGls5DrDWbusvRDOivUZeTOWzdbEr9ohQ5IzJTz6hRqa+ANGZn7KYon1cbXxFuT X-Received: by 2002:a05:620a:4105:b0:788:4f8:ef74 with SMTP id j5-20020a05620a410500b0078804f8ef74mr3337876qko.35.1709334986217; Fri, 01 Mar 2024 15:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334986; cv=none; d=google.com; s=arc-20160816; b=kpXDni6byufMBDugPplB0ZiRYSQyI+/eKLaTkTVXJWzlsrlow4vK1474A9nSlQrh5g tpLfrPiVnM/Nb+aTy80/hrNQ4qjJYvOrD2kDMwvaV7loQBdTWzX+54sMzZz/QeUrtHzR ihSKwSvxfvZuYj4agW4SZQ0MDdAFNTRuK8dQEOM4CqihzAmWZyhJQQPDQ9BMAJFUx8vF GoaO5LVaYFka+kvBqE0MDv+NKXiDWxkaUok4VXniB91iqt/yVUAAZk+bOH1eD/icQZwu T1Vnkzn4lATP2tq4MHmNqHNK1xAoEKGX8hi4R7r/c76SfNYvbIkIpcQmSVg8CaCaVRHF O9rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=xAkvGqVbfRd5zxHj8oE3VdS/l7Vb2jGWse9T5Pk1O/geJe/TYCZi8Hhr8kfdGxyNPQ ynAMd3mo9JxsABHNoKjMTDprQGQSg+PNuLnhdA1aek+FUPJGC+Du+jHxJy+Pw6aojuMY OsxUBnebWwdSv6LnkPIr3CwLmLTLXWXJIkQjOU5M1Eqrr7spW+XHUaOMAxMUF1hv7Yq+ sT9au/P2K55NgaXje9RjzY7dg2SsxXk8fCQqtb09URGkRf9XYEVn6w+WbqZ0Rgsfov3n kfRGw8pDFGgmAkVkQDQ06xqfTz0nUgvLpSCywFEzm+tc+KQgyqZa67rjgCoBcalsQFAS 8BHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JHzXef83; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bm21-20020a05620a199500b00787d6675f46si351537qkb.431.2024.03.01.15.16.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JHzXef83; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxn-0004uD-Jj; Fri, 01 Mar 2024 18:06: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 1rgBxd-0004ri-Sp for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxX-0004D8-QO for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:36 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dca3951ad9so25117755ad.3 for ; Fri, 01 Mar 2024 15:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334390; x=1709939190; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=JHzXef831+oBIR4Mb2YWjTCS9cbsRJ8yBA5n4PK7uWhMudwM85T4fYv1B7ln7fGJGF xSyH5hwomaXyhIdAVqI1uJjpACaH6oKvkhsA2dHZV9d90Jqwd6u3HiXcB3gWRANEk6cc yC/vBJs3Mtm6AkXHKS/hzUTph2Toj9QsSTKmgEz4dS7piYEj6eHjjzqnxTAByy1z42IT CFNa5K9/aYSxwlt0zxMLjqORTTqiesxrbPKEl1nZS9yqi6OJBFPrFnbkNzP6pfbwX6eX 1kT5zk1mbIMi65S9HCAbh54Xecvz9L6jTik1rAPw9NoiYfwzQvrb0qSn8C3FeMy+m5mD KuXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334390; x=1709939190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HjNGmK53xTEM4PEP/wzxcWkZ/m9cBOwh2M6e53eVpiA=; b=Q5cKSBYDwzLL8GxM+mXE1uU/Qx8+Xfg8tBbVaSE36l3DYx/Wjk2hGWcJLhcKlnkSNb T5+4PhYVk+tf03ubPfN58xQ5Uuzk+4E7G8Oj24JAPI4Q7KpAv1i8Ba5jN29p+Vl3uwwO GZltU90yN3aJ9BsjSjSqH3oMCCcKDgn8x2nfkNJyf/ovAJEiHdTZ532dr/k3//ct9Acp uK13b75CNnvExpNyHxaZkWlwIYccmJ3flafFFnS/x4CZ81p73UUPmkI3OHv2LzU8j+o2 eqfvJs3iwh+a4a8xXp+CtGiWYSf3xV4pNQblO7Jp9h4+sQwfvG1CLGDZRzMWNSNH4R6+ tQgw== X-Gm-Message-State: AOJu0YzZTM6imEg66Eboe2p+I42CJdnFVkXy3fslVQwMQoqxNZQeIAIt /iRpfhysXpl86Zjo9PJGyKPA1yGkLUYrt1s2JdU+FjiFS2VyMFCsyRxC1layEcYP9tlWICqqKiP 8 X-Received: by 2002:a17:902:db02:b0:1dc:4bf6:7eb4 with SMTP id m2-20020a170902db0200b001dc4bf67eb4mr3923448plx.31.1709334390302; Fri, 01 Mar 2024 15:06:30 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 06/60] linux-user/elfload: Open core file after vma_init Date: Fri, 1 Mar 2024 13:05:25 -1000 Message-Id: <20240301230619.661008-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Swap the ordering of vma_init and open. This will be necessary for further changes, and adjusts the error cleanup path. Narrow the scope of corefile, as the variable can be freed immediately after use in open(). Signed-off-by: Richard Henderson --- linux-user/elfload.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 39d9ef9acc..877799e9c7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4625,7 +4625,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; struct vm_area_struct *vma = NULL; - g_autofree char *corefile = NULL; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; @@ -4644,12 +4643,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) return 0; } - corefile = core_dump_filename(ts); - - if ((fd = open(corefile, O_WRONLY | O_CREAT, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) - return (-errno); - /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4657,6 +4650,15 @@ static int elf_core_dump(int signr, const CPUArchState *env) */ vma_init(&mm); + { + g_autofree char *corefile = core_dump_filename(ts); + fd = open(corefile, O_WRONLY | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + if (fd < 0) { + goto out; + } + walk_memory_regions(&mm, vma_walker); segs = vma_get_mapping_count(&mm); From patchwork Fri Mar 1 23:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777078 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601220wrn; Fri, 1 Mar 2024 15:08:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX/bm+0Nw7QI3214vGXefB+K0gOHDf8w/MWiwObO997J2B8EpqAlLbP+y1EM4kc6M3eNvDaKpfn5uHfLvU5ZIoa X-Google-Smtp-Source: AGHT+IE1afy6158CFHDJ7yhMlSAy9mT26klvYXkiAJWsZRDKlkqcTV2z3do6yKEvqbw7I7uEKmJx X-Received: by 2002:a05:620a:c0c:b0:787:fb5d:489e with SMTP id l12-20020a05620a0c0c00b00787fb5d489emr2747813qki.30.1709334504222; Fri, 01 Mar 2024 15:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334504; cv=none; d=google.com; s=arc-20160816; b=mMZPikyjW2rIZNVxkZ0vXnEGOlqJa/FfNBBB0D32nP6gfs/W4GdbnIDxY9+CYM69w9 lcuDbOJQurBC6mICTnBtXQUr0lnSuxpzgnGOmxXqbpa5JslMu12wiXzegzPh8rjrHiqR rg7h322p5PkjW6JoIdySdxWO5mtYEipYSSwuBgWb9sIyo9WkrmFzkfbWl5T9j12yDxl+ 3BX3OFVOp8d/DHmhvUFNQmNDh4W2YthW2ez5T7mGn3mY8NQCrGpwJziK+6A3Gq/ptNAY tgkyS6SC9/H6BtIBZjvC6MpQXPPpe88ySUmOx+hG/3w3wSHHwvqOVOhdckVKiXDEUXYO 4TMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=eMscwg9pIXCahfaLxUimeGoU/iOVrwk7ZLyAkiVhH/KddsXSL97vyo98ZMF2jEa0WO gHbGqCRKFF8R7RPhR9kdttDbAdhQoi84FTVnbnaWzQJQnJCEaWERpPYo2YtsXaVnvZmK MspgxXFxg2dAMcKCffVbEPdp5DjTYnQMI4Vgd3jBa4jbJUOHtQxZzOPgwMZyqVfidvH4 XWR6Vkn4UfTfWRF7cV05YMrzif1TiKEgLRKl+ZIGpQvBlNtId6M4e7Z+AyVSRFedvWP2 0b54jVqIfyb8kutn+RhlvFx6ZkRbd77mwz8k2h3f+mxEYp2K/VZCI5eE+EO5+0+FKejC iDAA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xhmLORuf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c26-20020a05620a201a00b00787da0bf045si4403701qka.719.2024.03.01.15.08.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:08:24 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xhmLORuf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy9-0005SR-7k; Fri, 01 Mar 2024 18:07: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 1rgBxb-0004rK-Dp for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:37 -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 1rgBxZ-0004DK-VV for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:35 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dcd0431f00so20092965ad.3 for ; Fri, 01 Mar 2024 15:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334391; x=1709939191; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; b=xhmLORufVFrs4Wlyc1lAnnduiPw2cZI3KC6yuNbI0pneuPJ8XUa4N2AzAai+aLxvnK 5icri/0GhBeIsWpJGPC0feazGh7l+CvFm609Ck2EhGx9z03Immb31sz1zuec1SuNMBVk ErZn2BldOLgeSohUjSG7/GpJA4G32tGh1LDylQLcpEallPgXR/Ap8VKzqeQOsHEcNEoG tWmTV5KaHllStVigB2lMcOJbI+iWHkVgn6DZc2d+99qFKaI62kj3DrPKY/nrCp6nCelg XCwVQGo/UG1ewu5U0v+cBmfHf4yHKYlW5vRQs75+QQl2Ha3oRaWWIsZsCMtnL2RE6jzL X2eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334391; x=1709939191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zYkpQqoaMHDWxrt9KPP15xrK5H9LSGOtZoW36Ee0L04=; b=EEM4jXTHIep5EHhb3SNsHIBRga6EZEE7hMbSBdbKyz+f35VUAq0CRTT64ildgMZRw5 3koFAjiOzpLMVAwyUGDeHJYJDX8t1GdAdCf7Xwxrx3JItW3wOcyu2Z6m7sgSQGsNkfa5 q+ssyIgL1TtwjZye/EhRIEGY9crJdojeaFHSkVh86YJuO5xr+HYtt35OhS1fU7kDxZdL h8ROvM9Y/AvG1KJoCxkN/rnIrHPmlnAxx6OgFwGHBpcAmU5wLjZ5IfMzFjiQDeZuUgv2 5xnDzKz4pEPWQtL7n8/Urwhaw8e959VpbEgc+CZFRAqLXnOitoTPFH4QgyJcp5cPFl/W wTag== X-Gm-Message-State: AOJu0Yyc8vwAMjKYM9aPJHRI7FyMz1qRi8HHZB+QV8Gge4Y2xO8LjEqn +VaFkIJZC2mORYFIo9dNiPwyGpsRjq1iE+YnqllXafnQQcGScfYDRff0Rmm6DF5/1aKdyl6xMUb n X-Received: by 2002:a17:902:c94f:b0:1db:5c84:9523 with SMTP id i15-20020a170902c94f00b001db5c849523mr3765895pla.67.1709334391394; Fri, 01 Mar 2024 15:06:31 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 07/60] linux-user/elfload: Truncate core file on open Date: Fri, 1 Mar 2024 13:05:26 -1000 Message-Id: <20240301230619.661008-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org While we usually create a new corefile, truncate otherwise. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 877799e9c7..16dd08a828 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4652,7 +4652,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) { g_autofree char *corefile = core_dump_filename(ts); - fd = open(corefile, O_WRONLY | O_CREAT, + fd = open(corefile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } if (fd < 0) { From patchwork Fri Mar 1 23:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777109 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603733wrn; Fri, 1 Mar 2024 15:16:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWCU2sZKPEIC1e8dQPOmt3i82rUK982DwraA09W1p814lqYG/BVIdDThGUHiNzHBN3iwof/aJFUyL7GZvTOZVyI X-Google-Smtp-Source: AGHT+IGVb6Nf1/TM9YaO/OgefE/I03u9zPSnAE/tfspaaI0+uvhIZrNsBmLkNJFSee0E6VUySsDg X-Received: by 2002:a05:620a:4090:b0:787:91fc:f940 with SMTP id f16-20020a05620a409000b0078791fcf940mr4050347qko.48.1709334991084; Fri, 01 Mar 2024 15:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334991; cv=none; d=google.com; s=arc-20160816; b=nTIWgsU0Gx50yr3HQAdP2vRmBLSOoobrZN3Dk4YP/eZUofnu3fVDh17PjGOhqVYB8w 8U68OkgNfp2RKKXvQ1yOMGPr+WGpjffaju+kYPMBTRCvaIEWhFaf1T0y4KqB3om8j7Tu DjybruHKqFaySEIsqHj69EbzY+WqTBGssaT+qqOXspCq98nENmi6jlxF/7PuPb+FU3Lu VKim/aKQbaOm2ZzHMIEYCeyYVFN0PB62B42mYXFCulF8TPX6dJfIFazl/iF3rr1yNq3y KKJ+JjoHhK0SmUYJ+Onm0W1V0o7mIvKhP+nDIdG1S/930m5fs4j11xL7wXM1yREqz2m+ uMAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jFfW1DmYHFMf19W3HAUQWeg/5lBH99MdAkdqkDNLv3I=; fh=eu2DY09p+eeddYDiV+DalJS3Vr0kxK5BujclYkgWvDw=; b=LtPN2qV3Dv3WE7NTok+J1S1doBKWNdc5lB0AAUpqsVT368ypsaVvVlsXjKq/attAMm VWA4/goNQr5vSlcVhSru1bXfEgXKAhz+q+U0Q6V/FstN9Q7G6dvpvE25Q7rtVLgzNcki GRTUKjYaDRyU4L3mwjFVicd5FwyxTF87w0cTvZ0kEy0nZ01KJcesMOyd1vBAT45fEoB8 ps6gwSY6CzxpSk/xKRZOreKdwraKwDKAbO6oHMdlhuYj0R6PYX3bLGPt9K5G8vxJLEof ONeN//PSBcXGYR86ydkZMdvtmgvNy9mfnyCj47buEPaz1cdZMGM3Ia8bh4UwnAZSsRxd FnOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QaWCJ4tq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i13-20020a05620a0a0d00b00787c5bfbe6esi4588681qka.343.2024.03.01.15.16.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QaWCJ4tq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxn-0004uC-KK; Fri, 01 Mar 2024 18:06: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 1rgBxd-0004rt-UN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxa-0004DV-Ry for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:37 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc5d0162bcso25434825ad.0 for ; Fri, 01 Mar 2024 15:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334392; x=1709939192; 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=jFfW1DmYHFMf19W3HAUQWeg/5lBH99MdAkdqkDNLv3I=; b=QaWCJ4tqxnwojuuu2XZbWDjRPNE8LZs9erbE1yxXt7g7r0TfMZzcLMQhmP9POdh016 mFKHwA0KCx99uPZOTlE8HJ8sDxuHXj4a2tB/nSyIlzMjktTmBYwBnKu55IOIMq9266g7 YYrNwqVEPcU5n7SRGCRx2N+3lTUCh++USkL9AHoNPpXUIvsWCiI6HCRKdvN9VA8CWfvO srS96wOEIqhdFlGR2OYPUcOvp5w4E5h5y46TN4JpzNYf23fIHIlEFsTPDR41Vt9GV0mD d3VzmFGasZ5TWwOJXa/yVorbTPhTaxwHfJGnAMlZ6SG0MMxCKyJGFG001S2YWOuHu23u 9Naw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334392; x=1709939192; 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=jFfW1DmYHFMf19W3HAUQWeg/5lBH99MdAkdqkDNLv3I=; b=WCzUx9hLNB5ohBrv1Yv47cdWaqJbGYZZ6GIOPNKJTq4Kk24dcwU42AyULrcbDGM4kr Kvvybk/EXe+sH9NGsIg1YZzTb6d0EoZmo7rwf5nHKxBUjGoN7EedHLp0K6dKNIgYR3Ng DUSEw5RZdy7gttOJJXgzgqI24GZVvXQ/BGTGD7MV58kvJoIA2Q6Xr8Wyb6mRTCXOOw9R 8lvAm5FkP0+ZN9atg1dFvlMMOcrQi8yzg/lGwAvsiqmivmztOXgyfocE8X+CHjSXPtSU /KQA7d3Cofc09HGb7wGIk1eMHRvvAWnWJefRrP70hkljHHQu41NdI7h4EJi7+YB4qBTw S8jQ== X-Gm-Message-State: AOJu0Yy2PlRsyHjsP+u3NdbzIyfKcJ50S0oqQOt5KrBWPvVz4z6jLEEH sGVeSrk33Ha6W9Qtxl3bdv+cjDDoyQWttcmG8L78acXoZdgAn04RMhbj6eR/BK7XY1GfkjO2wq8 S X-Received: by 2002:a17:903:41ca:b0:1db:d66e:cd15 with SMTP id u10-20020a17090341ca00b001dbd66ecd15mr4038015ple.59.1709334392669; Fri, 01 Mar 2024 15:06:32 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH 08/60] linux-user/elfload: Lock cpu list and mmap during elf_core_dump Date: Fri, 1 Mar 2024 13:05:27 -1000 Message-Id: <20240301230619.661008-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not allow changes to the set of cpus and memory regions while we are dumping core. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/elfload.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 16dd08a828..6f9da721d7 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4537,13 +4537,11 @@ static void fill_note_info(struct elf_note_info *info, } /* read and fill status of all threads */ - WITH_QEMU_LOCK_GUARD(&qemu_cpu_list_lock) { - CPU_FOREACH(cpu) { - if (cpu == thread_cpu) { - continue; - } - fill_thread_info(info, cpu_env(cpu)); + CPU_FOREACH(cpu) { + if (cpu == thread_cpu) { + continue; } + fill_thread_info(info, cpu_env(cpu)); } } @@ -4643,6 +4641,9 @@ static int elf_core_dump(int signr, const CPUArchState *env) return 0; } + cpu_list_lock(); + mmap_lock(); + /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4760,6 +4761,8 @@ static int elf_core_dump(int signr, const CPUArchState *env) out: ret = -errno; + mmap_unlock(); + cpu_list_unlock(); free_note_info(&info); vma_delete(&mm); close(fd); From patchwork Fri Mar 1 23:05:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777115 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603797wrn; Fri, 1 Mar 2024 15:16:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX0aCCcJWFuu6ixt6MLwa/X8kTmOFwjQe6JYeNp9YJcOsMaOSy8RoWZtsvg1zZn/ALRVrQ2sYRZk97kqSBnpaB+ X-Google-Smtp-Source: AGHT+IGNZLDuubXnbCUOth2ILugbB0Auqg8hSUkmGHBhfb7PhEZtvKl4sAlJFO0yYhpb9YVZ/Y3P X-Received: by 2002:a05:620a:400b:b0:788:150f:2da with SMTP id h11-20020a05620a400b00b00788150f02damr1474847qko.13.1709335003431; Fri, 01 Mar 2024 15:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335003; cv=none; d=google.com; s=arc-20160816; b=J7/SkAccrr3PNjdjT6O2HuvGKh3i9l/MzH8niXXVjhIJkYJLBDfnGzyzCzLiDZBGQK q/fFFSwyiGAHQvYY2MTWryL7HBSXmNfUXJe/97C0U2uKy0gntnRLenkY7mQ0ae9zWSmT 7BSHEWbQ1kzBg5IBfV6L00ESeSYeeX1g1QtrYrefhI6brGvA3RyjFSJgS+TF3U7ELkFm DQHtYvCAY0punTUvc7VqARFLN7+2d2pipv0TSArlfnNGxyEFDSNqlXsjlAXaSiAp/vJ2 dmKiSsW+H3yV6V4g4ZChSAYBqKqfMPuA2XkGcS6C99t0COWaGJTdgonkzhrr17dm5rNe MU0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=jGv8o430yvbaSWq03pPI7mviXUu+LiK8ALv/FUuU9roCl6qTwqJuYa3HV0nsN1gbfW 9ap2sLw70CnQvGUc0JfdxoFOFWCFog6u7lEC6IIHGVylTzzBOj8lFvW8S3Jk4lTS1o4i MdRf5GHPW/8S/O3WNEDVduYfd0ZqaJzucU1iT+79M+ABiWVDkL1KVuIjjSYjAxgkIY4S +tG4etsijW3hsCFVbz5BKlABvNdZYH8Ghw3V/Uvs7Vs3twzzZ61vg7eT/q3WcByvqg4d q0T2CyF+eiVndG3BuIY0fe39uLQ7F7NDs9NzfDQ4cJs/biGFdXBohofgcXYMG2BFK3Gh be4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUZKnmVb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bi3-20020a05620a318300b0078816d4f794si591721qkb.559.2024.03.01.15.16.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUZKnmVb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxo-0004v5-GP; Fri, 01 Mar 2024 18:06: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 1rgBxf-0004ru-As for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxb-0004DX-DN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:38 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1dc1e7c0e29so10569735ad.1 for ; Fri, 01 Mar 2024 15:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334394; x=1709939194; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; b=VUZKnmVb4gRnkIfqOOA3tmn2P7jczQKV0KdZk/F77Wj+QrSKvo4d5e/TrtMnHXpyVv /fMJERW/1zXpqFop1Uwd4/LTSfaqmQVr/hlXfJeWJCtU8okQx7GTj9l8Ngfzf+vsRX2e Ync08Dly4gQ1E89W0LPI3XyjialFHo7QP2rRE6bAW67zmWXpWgJlir/Ah+2xE12Yz6Z8 LGj1Da5h2xYx2O3FlKImpp/TqhrmnBrjR2o8UDi9Wyku7WgR6oTIZ7r0EurnRsh9eCIh 2jGPJI6Xykicngj3VLHLmfp9KSisC/M2tWzyAWFCL5ukgtDbR3AldZhbT1ALRKDIHnVG Q+7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334394; x=1709939194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXgOJaiR1gNovC/J+sG7U6tnXruxoEFoxj+FOnROhG4=; b=KViexqNvB2Fyy7ukrXSgZlbv3CrkIBZmuFrIG3e1l0bwUqkVEzKcn6OdIEI4ORSus0 1e020yWhV9wxnHypPgGQEAEbBma1nJORRvxxemlvhmKM58Qu60h+zCewGaLxcjjY4tSg /IMwOjSuqMKmlSNIxAT9kUCuCt3Oyc0Fv0pzazhUZrEpLP368ti0IIsHbeF8hmdCC2lw Z4qpAbs8VtTFWXecO6TDBBoqXr6EQ+Xjv3ygnlPHeAcPPKTdlOPvxpUpbpE48J49B2g7 YEKXvnrPLu6I7jeb8y4k0pwbzGP4qYRVDxX1ekYWKwmTFx3ApoRAB4rz/tbX83S5Lzkc /UGA== X-Gm-Message-State: AOJu0YwhTlTi3ydRoxWKm8JVTw5YATNe3TpMcLPyTwoQ1UhNG7tBAGTT l9rnYLDOwbGi0pE80ywc03SsT6WKQZIwJD+plu6lr0XboytWC2RDktbDCUGrmDaqnrvVKDDA5NN w X-Received: by 2002:a17:902:ccc2:b0:1dc:f16c:de0c with SMTP id z2-20020a170902ccc200b001dcf16cde0cmr2469911ple.65.1709334393861; Fri, 01 Mar 2024 15:06:33 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/60] linux-user/elfload: Size corefile before opening Date: Fri, 1 Mar 2024 13:05:28 -1000 Message-Id: <20240301230619.661008-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Verify the size of the corefile vs the rlimit before opening and creating the core file at all. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 83 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 6f9da721d7..bad01bd2ef 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4270,6 +4270,16 @@ static int vma_walker(void *priv, target_ulong start, target_ulong end, return (0); } +static size_t size_note(const char *name, size_t datasz) +{ + size_t namesz = strlen(name) + 1; + + namesz = ROUND_UP(namesz, 4); + datasz = ROUND_UP(datasz, 4); + + return sizeof(struct elf_note) + namesz + datasz; +} + static void fill_note(struct memelfnote *note, const char *name, int type, unsigned int sz, void *data) { @@ -4428,27 +4438,9 @@ static int dump_write(int fd, const void *ptr, size_t size) { const char *bufp = (const char *)ptr; ssize_t bytes_written, bytes_left; - struct rlimit dumpsize; - off_t pos; bytes_written = 0; - getrlimit(RLIMIT_CORE, &dumpsize); - if ((pos = lseek(fd, 0, SEEK_CUR))==-1) { - if (errno == ESPIPE) { /* not a seekable stream */ - bytes_left = size; - } else { - return pos; - } - } else { - if (dumpsize.rlim_cur <= pos) { - return -1; - } else if (dumpsize.rlim_cur == RLIM_INFINITY) { - bytes_left = size; - } else { - size_t limit_left=dumpsize.rlim_cur - pos; - bytes_left = limit_left >= size ? size : limit_left ; - } - } + bytes_left = size; /* * In normal conditions, single write(2) should do but @@ -4622,16 +4614,15 @@ static int elf_core_dump(int signr, const CPUArchState *env) { const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; - struct vm_area_struct *vma = NULL; + struct vm_area_struct *vma; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; struct rlimit dumpsize; struct mm_struct mm; - off_t offset = 0, data_offset = 0; - int segs = 0; + off_t offset, note_offset, data_offset; + int segs, cpus, ret; int fd = -1; - int ret; if (prctl(PR_GET_DUMPABLE) == 0) { return 0; @@ -4646,10 +4637,36 @@ static int elf_core_dump(int signr, const CPUArchState *env) /* * Walk through target process memory mappings and - * set up structure containing this information. After - * this point vma_xxx functions can be used. + * set up structure containing this information. */ vma_init(&mm); + walk_memory_regions(&mm, vma_walker); + segs = vma_get_mapping_count(&mm); + + cpus = 0; + CPU_FOREACH(cpu) { + cpus++; + } + + offset = sizeof(struct elfhdr); + offset += (segs + 1) * sizeof(struct elf_phdr); + note_offset = offset; + + offset += size_note("CORE", ts->info->auxv_len); + offset += size_note("CORE", sizeof(struct target_elf_prpsinfo)); + offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus; + offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE); + data_offset = offset; + + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { + offset += vma_dump_size(vma); + } + + /* Do not dump if the corefile size exceeds the limit. */ + if (dumpsize.rlim_cur != RLIM_INFINITY && dumpsize.rlim_cur < offset) { + errno = 0; + goto out; + } { g_autofree char *corefile = core_dump_filename(ts); @@ -4660,9 +4677,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) goto out; } - walk_memory_regions(&mm, vma_walker); - segs = vma_get_mapping_count(&mm); - /* * Construct valid coredump ELF header. We also * add one more segment for notes. @@ -4674,26 +4688,17 @@ static int elf_core_dump(int signr, const CPUArchState *env) /* fill in the in-memory version of notes */ fill_note_info(&info, signr, env); - offset += sizeof (elf); /* elf header */ - offset += (segs + 1) * sizeof (struct elf_phdr); /* program headers */ - /* write out notes program header */ - fill_elf_note_phdr(&phdr, info.notes_size, offset); + fill_elf_note_phdr(&phdr, info.notes_size, note_offset); - offset += info.notes_size; if (dump_write(fd, &phdr, sizeof (phdr)) != 0) goto out; - /* - * ELF specification wants data to start at page boundary so - * we align it here. - */ - data_offset = offset = roundup(offset, ELF_EXEC_PAGESIZE); - /* * Write program headers for memory regions mapped in * the target process. */ + offset = data_offset; for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { (void) memset(&phdr, 0, sizeof (phdr)); From patchwork Fri Mar 1 23:05:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777087 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602262wrn; Fri, 1 Mar 2024 15:11:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUNilggVVeU4ENQRdiIOgvBwaQREHvfVtG/QTfqixUv2kPVu6ZWLOX8rMsvPM5eqRHBwL/DbNL08wEUfEcH55F1 X-Google-Smtp-Source: AGHT+IGOCgCBJrzpLrZV+ANZYzVAjmKrn3d192t/l6I79EArAWHLcQnEMdFDIrqdFLMpWARL9dn1 X-Received: by 2002:a05:622a:1ba5:b0:42e:996d:28ad with SMTP id bp37-20020a05622a1ba500b0042e996d28admr3140309qtb.54.1709334690432; Fri, 01 Mar 2024 15:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334690; cv=none; d=google.com; s=arc-20160816; b=TzlOdgFFaSmVkO5qy2RXxBUjKBEAuS7KfSUNxAydY278oz1ogHlYiP2a/IgNWMTd/B LQJXWTCH/3jnwzLfWv1d5Yyxc/d87U6JwZLvckuL80Q8meBkpAjsDgO0qpNjgzkSOYc1 IdGFyggWEjr1PhvZItOHPgsCAiRL5I4PEKGWZlaVa/ps5+ozcy1Z9uSzyZSMl4U5F/xS KVGvddDb6ZHDgMGObvACmcxOnIoi5GjjWt++u8sZaFG2GdwxUxCZa/EEd97HJZN5JboT JJEXb7dUpcFgZ7Pxf+dWhHRR06Y9/Zq3joD5NOrlP93cjiOJBVD9vXaOleblTJiSLO7J URLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=VohLNoh4hFEV4HPivc+YS7vNrlJOTLgl+4GJFbPy6Mk=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=ORsKMU/qZcwrAc5LTXJxsA2OiO96VL/T4jO0JFbi6ypPvpJTsu84rXwFLBBeWCAWKX qPQ0a5xyfpdAueDgGzCZnf4Re1tpWNi4n7SNi2dCRuaRxjsihfx+ucrvgIhBj8MMJjd8 KE1rSzJjPwoH3Rjt1Ls4VIo0RWDEOI20kaB3hbuC360OKpT2yqfWfDTnrZ1567vdw7eo Y8xqZbdDwUZra869/QCGUydj1Tu0Ep90eCmVVD9UEOQA2Sr/WiLuE24ioN+RxmDCvD7R tjdc0AtSxIPd9HTZZRXW0DR51vR0rmoaF0fL5hQLhl8oTcd5CCKuQSwX+WpejhsciKE1 Brlw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jAHvx9FK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e20-20020ac84e54000000b0042ecbb5a263si2148545qtw.155.2024.03.01.15.11.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:11:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jAHvx9FK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByM-0005kY-RU; Fri, 01 Mar 2024 18:07:23 -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 1rgBxg-0004s3-91 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxd-0004E1-Ky for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:40 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc1ff3ba1aso22775485ad.3 for ; Fri, 01 Mar 2024 15:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334395; x=1709939195; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VohLNoh4hFEV4HPivc+YS7vNrlJOTLgl+4GJFbPy6Mk=; b=jAHvx9FKJmomvKZDma16EqfuP497f2/pS18+kpWHtUFoHM2bvu0LLx8ic1Q5v6xIiM w1/IpVbup1B4QECtJHvvwHoufcBSbVcJaA7DonsPGPkvNZLFH3BR7NWUI6b9EMMk6Dgh zZy61SIUAVuuOc+4zbxrLdYxw920DeKu5wcoMhPKcx/9o92ANsvK+HAwi7+SthJYuu6d zfQPA7RXQQwVYLlU0DJkXKMeqa1F9rqQ7nX3RIvlkgQ7nPZkgfNxsHbMsu2+3nyd3HVH TpeMRgQGACI39nelm0z1c2S9m7592Ksd/y6VGp/YRBOud+f5dJdj9m4nnfhdq7VRsYFs p/BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334395; x=1709939195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VohLNoh4hFEV4HPivc+YS7vNrlJOTLgl+4GJFbPy6Mk=; b=XrhAJb1mKWKTKeQ5FY13OIu0uQCobDEVAokM/+c5+3dR3uhLNhVkXNpESIFfb19/sz 9M8WvLo2sN2kZqZmG7ioBV/ljnhHQ4epPl9EbtnUJBOiKpQm5rUxuuIPVcp9dgLEVvQ/ DwLIxgXxRX/vj1bBwtopMAOWUVdl3UAHmuI0qD2Oanq6mwnvx7+4qtFHxcLHol8thKko BkYDTEm/SGnDUAbYcDfu7keuClmueqL/2OJcCbTBuYzu/++ErAlHa6gsxUeoJIjviiQ4 jhLFB9tLjoKnUEcOfj7EfQilETjw7qPBxa8W5z7/swS2wRGTU8RKkIqOufbWwy9H05XP bTtg== X-Gm-Message-State: AOJu0YwEGSumETaurzW9MZ4VsqL4ghgnJIxO/O5cY6CKMvkLBuxEeayE 6ocwouV0Ifk1njju9mlDBRQkslzvrc+eIcbCzzq8h63jpKZCwpt4yix+Kuu1NmQwKbY9nMQ5F+u q X-Received: by 2002:a17:902:e5c3:b0:1dc:f986:9bf5 with SMTP id u3-20020a170902e5c300b001dcf9869bf5mr484608plf.4.1709334395233; Fri, 01 Mar 2024 15:06:35 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 10/60] linux-user/elfload: Write corefile elf header in one block Date: Fri, 1 Mar 2024 13:05:29 -1000 Message-Id: <20240301230619.661008-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Fixes a bug in which write_note() wrote namesz_rounded and datasz_rounded bytes, even though name and data pointers contain only the unrounded number of bytes. Instead of many small writes, allocate a block to contain all of the elf headers and all of the notes. Copy the data into the block piecemeal and the write it to the file as a chunk. This also avoids the need to lseek forward for alignment. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 410 ++++++++++++------------------------------- 1 file changed, 113 insertions(+), 297 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index bad01bd2ef..b8d07d8054 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4002,18 +4002,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * Example for ARM target is provided in this file. */ -/* An ELF note in memory */ -struct memelfnote { - const char *name; - size_t namesz; - size_t namesz_rounded; - int type; - size_t datasz; - size_t datasz_rounded; - void *data; - size_t notesz; -}; - struct target_elf_siginfo { abi_int si_signo; /* signal number */ abi_int si_code; /* extra code */ @@ -4053,40 +4041,6 @@ struct target_elf_prpsinfo { char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; -/* Here is the structure in which status of each thread is captured. */ -struct elf_thread_status { - QTAILQ_ENTRY(elf_thread_status) ets_link; - struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ -#if 0 - elf_fpregset_t fpu; /* NT_PRFPREG */ - struct task_struct *thread; - elf_fpxregset_t xfpu; /* ELF_CORE_XFPREG_TYPE */ -#endif - struct memelfnote notes[1]; - int num_notes; -}; - -#define NUMNOTES 3 - -struct elf_note_info { - struct memelfnote notes[NUMNOTES]; - struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ - struct target_elf_prpsinfo psinfo; /* NT_PRPSINFO */ - - QTAILQ_HEAD(, elf_thread_status) thread_list; -#if 0 - /* - * Current version of ELF coredump doesn't support - * dumping fp regs etc. - */ - elf_fpregset_t *fpu; - elf_fpxregset_t *xfpu; - int thread_status_size; -#endif - int notes_size; - int numnote; -}; - struct vm_area_struct { target_ulong vma_start; /* start vaddr of memory region */ target_ulong vma_end; /* end vaddr of memory region */ @@ -4110,22 +4064,6 @@ static abi_ulong vma_dump_size(const struct vm_area_struct *); static int vma_walker(void *priv, target_ulong start, target_ulong end, unsigned long flags); -static void fill_elf_header(struct elfhdr *, int, uint16_t, uint32_t); -static void fill_note(struct memelfnote *, const char *, int, - unsigned int, void *); -static void fill_prstatus(struct target_elf_prstatus *, const TaskState *, int); -static int fill_psinfo(struct target_elf_prpsinfo *, const TaskState *); -static void fill_auxv_note(struct memelfnote *, const TaskState *); -static void fill_elf_note_phdr(struct elf_phdr *, int, off_t); -static size_t note_size(const struct memelfnote *); -static void free_note_info(struct elf_note_info *); -static void fill_note_info(struct elf_note_info *, int, const CPUArchState *); -static void fill_thread_info(struct elf_note_info *, const CPUArchState *); - -static int dump_write(int, const void *, size_t); -static int write_note(struct memelfnote *, int); -static int write_note_info(struct elf_note_info *, int); - #ifdef BSWAP_NEEDED static void bswap_prstatus(struct target_elf_prstatus *prstatus) { @@ -4280,35 +4218,32 @@ static size_t size_note(const char *name, size_t datasz) return sizeof(struct elf_note) + namesz + datasz; } -static void fill_note(struct memelfnote *note, const char *name, int type, - unsigned int sz, void *data) +static void *fill_note(void **pptr, int type, const char *name, size_t datasz) { - unsigned int namesz; + void *ptr = *pptr; + struct elf_note *n = ptr; + size_t namesz = strlen(name) + 1; - namesz = strlen(name) + 1; - note->name = name; - note->namesz = namesz; - note->namesz_rounded = roundup(namesz, sizeof (int32_t)); - note->type = type; - note->datasz = sz; - note->datasz_rounded = roundup(sz, sizeof (int32_t)); + n->n_namesz = namesz; + n->n_descsz = datasz; + n->n_type = type; + bswap_note(n); - note->data = data; + ptr += sizeof(*n); + memcpy(ptr, name, namesz); - /* - * We calculate rounded up note size here as specified by - * ELF document. - */ - note->notesz = sizeof (struct elf_note) + - note->namesz_rounded + note->datasz_rounded; + namesz = ROUND_UP(namesz, 4); + datasz = ROUND_UP(datasz, 4); + + *pptr = ptr + namesz + datasz; + return ptr + namesz; } static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine, uint32_t flags) { - (void) memset(elf, 0, sizeof(*elf)); + memcpy(elf->e_ident, ELFMAG, SELFMAG); - (void) memcpy(elf->e_ident, ELFMAG, SELFMAG); elf->e_ident[EI_CLASS] = ELF_CLASS; elf->e_ident[EI_DATA] = ELF_DATA; elf->e_ident[EI_VERSION] = EV_CURRENT; @@ -4326,95 +4261,79 @@ static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine, bswap_ehdr(elf); } -static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset) +static void fill_elf_note_phdr(struct elf_phdr *phdr, size_t sz, off_t offset) { phdr->p_type = PT_NOTE; phdr->p_offset = offset; - phdr->p_vaddr = 0; - phdr->p_paddr = 0; phdr->p_filesz = sz; - phdr->p_memsz = 0; - phdr->p_flags = 0; - phdr->p_align = 0; bswap_phdr(phdr, 1); } -static size_t note_size(const struct memelfnote *note) +static void fill_prstatus_note(void *data, const TaskState *ts, + CPUState *cpu, int signr) { - return (note->notesz); + /* + * Because note memory is only aligned to 4, and target_elf_prstatus + * may well have higher alignment requirements, fill locally and + * memcpy to the destination afterward. + */ + struct target_elf_prstatus prstatus = { + .pr_info.si_signo = signr, + .pr_cursig = signr, + .pr_pid = ts->ts_tid, + .pr_ppid = getppid(), + .pr_pgrp = getpgrp(), + .pr_sid = getsid(0), + }; + + elf_core_copy_regs(&prstatus.pr_reg, cpu_env(cpu)); + bswap_prstatus(&prstatus); + memcpy(data, &prstatus, sizeof(prstatus)); } -static void fill_prstatus(struct target_elf_prstatus *prstatus, - const TaskState *ts, int signr) -{ - (void) memset(prstatus, 0, sizeof (*prstatus)); - prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; - prstatus->pr_pid = ts->ts_tid; - prstatus->pr_ppid = getppid(); - prstatus->pr_pgrp = getpgrp(); - prstatus->pr_sid = getsid(0); - - bswap_prstatus(prstatus); -} - -static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts) +static void fill_prpsinfo_note(void *data, const TaskState *ts) { + /* + * Because note memory is only aligned to 4, and target_elf_prpsinfo + * may well have higher alignment requirements, fill locally and + * memcpy to the destination afterward. + */ + struct target_elf_prpsinfo psinfo; char *base_filename; - unsigned int i, len; - - (void) memset(psinfo, 0, sizeof (*psinfo)); + size_t len; len = ts->info->env_strings - ts->info->arg_strings; - if (len >= ELF_PRARGSZ) - len = ELF_PRARGSZ - 1; - if (copy_from_user(&psinfo->pr_psargs, ts->info->arg_strings, len)) { - return -EFAULT; + len = MIN(len, ELF_PRARGSZ); + memcpy(&psinfo.pr_psargs, g2h_untagged(ts->info->arg_strings), len); + for (size_t i = 0; i < len; i++) { + if (psinfo.pr_psargs[i] == 0) { + psinfo.pr_psargs[i] = ' '; + } } - for (i = 0; i < len; i++) - if (psinfo->pr_psargs[i] == 0) - psinfo->pr_psargs[i] = ' '; - psinfo->pr_psargs[len] = 0; - psinfo->pr_pid = getpid(); - psinfo->pr_ppid = getppid(); - psinfo->pr_pgrp = getpgrp(); - psinfo->pr_sid = getsid(0); - psinfo->pr_uid = getuid(); - psinfo->pr_gid = getgid(); + psinfo.pr_pid = getpid(); + psinfo.pr_ppid = getppid(); + psinfo.pr_pgrp = getpgrp(); + psinfo.pr_sid = getsid(0); + psinfo.pr_uid = getuid(); + psinfo.pr_gid = getgid(); base_filename = g_path_get_basename(ts->bprm->filename); /* * Using strncpy here is fine: at max-length, * this field is not NUL-terminated. */ - (void) strncpy(psinfo->pr_fname, base_filename, - sizeof(psinfo->pr_fname)); - + strncpy(psinfo.pr_fname, base_filename, sizeof(psinfo.pr_fname)); g_free(base_filename); - bswap_psinfo(psinfo); - return (0); + + bswap_psinfo(&psinfo); + memcpy(data, &psinfo, sizeof(psinfo)); } -static void fill_auxv_note(struct memelfnote *note, const TaskState *ts) +static void fill_auxv_note(void *data, const TaskState *ts) { - elf_addr_t auxv = (elf_addr_t)ts->info->saved_auxv; - elf_addr_t orig_auxv = auxv; - void *ptr; - int len = ts->info->auxv_len; - - /* - * Auxiliary vector is stored in target process stack. It contains - * {type, value} pairs that we need to dump into note. This is not - * strictly necessary but we do it here for sake of completeness. - */ - - /* read in whole auxv vector and copy it to memelfnote */ - ptr = lock_user(VERIFY_READ, orig_auxv, len, 0); - if (ptr != NULL) { - fill_note(note, "CORE", NT_AUXV, len, ptr); - unlock_user(ptr, auxv, len); - } + memcpy(data, g2h_untagged(ts->info->saved_auxv), ts->info->auxv_len); } /* @@ -4462,111 +4381,6 @@ static int dump_write(int fd, const void *ptr, size_t size) return (0); } -static int write_note(struct memelfnote *men, int fd) -{ - struct elf_note en; - - en.n_namesz = men->namesz; - en.n_type = men->type; - en.n_descsz = men->datasz; - - bswap_note(&en); - - if (dump_write(fd, &en, sizeof(en)) != 0) - return (-1); - if (dump_write(fd, men->name, men->namesz_rounded) != 0) - return (-1); - if (dump_write(fd, men->data, men->datasz_rounded) != 0) - return (-1); - - return (0); -} - -static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env) -{ - CPUState *cpu = env_cpu((CPUArchState *)env); - TaskState *ts = (TaskState *)cpu->opaque; - struct elf_thread_status *ets; - - ets = g_malloc0(sizeof (*ets)); - ets->num_notes = 1; /* only prstatus is dumped */ - fill_prstatus(&ets->prstatus, ts, 0); - elf_core_copy_regs(&ets->prstatus.pr_reg, env); - fill_note(&ets->notes[0], "CORE", NT_PRSTATUS, sizeof (ets->prstatus), - &ets->prstatus); - - QTAILQ_INSERT_TAIL(&info->thread_list, ets, ets_link); - - info->notes_size += note_size(&ets->notes[0]); -} - -static void fill_note_info(struct elf_note_info *info, - int signr, const CPUArchState *env) -{ - CPUState *cpu = env_cpu((CPUArchState *)env); - TaskState *ts = (TaskState *)cpu->opaque; - - memset(info, 0, sizeof (*info)); - QTAILQ_INIT(&info->thread_list); - - /* - * First fill in status (and registers) of current thread - * including process info & aux vector. - */ - fill_prstatus(&info->prstatus, ts, signr); - elf_core_copy_regs(&info->prstatus.pr_reg, env); - fill_note(&info->notes[0], "CORE", NT_PRSTATUS, - sizeof(info->prstatus), &info->prstatus); - fill_psinfo(&info->psinfo, ts); - fill_note(&info->notes[1], "CORE", NT_PRPSINFO, - sizeof(info->psinfo), &info->psinfo); - fill_auxv_note(&info->notes[2], ts); - info->numnote = 3; - - info->notes_size = 0; - for (int i = 0; i < info->numnote; i++) { - info->notes_size += note_size(&info->notes[i]); - } - - /* read and fill status of all threads */ - CPU_FOREACH(cpu) { - if (cpu == thread_cpu) { - continue; - } - fill_thread_info(info, cpu_env(cpu)); - } -} - -static void free_note_info(struct elf_note_info *info) -{ - struct elf_thread_status *ets; - - while (!QTAILQ_EMPTY(&info->thread_list)) { - ets = QTAILQ_FIRST(&info->thread_list); - QTAILQ_REMOVE(&info->thread_list, ets, ets_link); - g_free(ets); - } -} - -static int write_note_info(struct elf_note_info *info, int fd) -{ - struct elf_thread_status *ets; - int i, error = 0; - - /* write prstatus, psinfo and auxv for current thread */ - for (i = 0; i < info->numnote; i++) - if ((error = write_note(&info->notes[i], fd)) != 0) - return (error); - - /* write prstatus for each thread */ - QTAILQ_FOREACH(ets, &info->thread_list, ets_link) { - if ((error = write_note(&ets->notes[0], fd)) != 0) - return (error); - } - - return (0); -} - /* * Write out ELF coredump. * @@ -4615,14 +4429,13 @@ static int elf_core_dump(int signr, const CPUArchState *env) const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; struct vm_area_struct *vma; - struct elf_note_info info; - struct elfhdr elf; - struct elf_phdr phdr; struct rlimit dumpsize; struct mm_struct mm; off_t offset, note_offset, data_offset; + size_t note_size; int segs, cpus, ret; int fd = -1; + CPUState *cpu_iter; if (prctl(PR_GET_DUMPABLE) == 0) { return 0; @@ -4644,7 +4457,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) segs = vma_get_mapping_count(&mm); cpus = 0; - CPU_FOREACH(cpu) { + CPU_FOREACH(cpu_iter) { cpus++; } @@ -4655,6 +4468,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) offset += size_note("CORE", ts->info->auxv_len); offset += size_note("CORE", sizeof(struct target_elf_prpsinfo)); offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus; + note_size = offset - note_offset; offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE); data_offset = offset; @@ -4678,61 +4492,64 @@ static int elf_core_dump(int signr, const CPUArchState *env) } /* - * Construct valid coredump ELF header. We also - * add one more segment for notes. + * There is a fair amount of alignment padding within the notes + * as well as preceeding the process memory. Allocate a zeroed + * block to hold it all. Write all of the headers directly into + * this buffer and then write it out as a block. */ - fill_elf_header(&elf, segs + 1, ELF_MACHINE, 0); - if (dump_write(fd, &elf, sizeof (elf)) != 0) - goto out; + { + g_autofree void *header = g_malloc0(data_offset); + void *hptr, *dptr; - /* fill in the in-memory version of notes */ - fill_note_info(&info, signr, env); + /* Create elf file header. */ + hptr = header; + fill_elf_header(hptr, segs + 1, ELF_MACHINE, 0); + hptr += sizeof(struct elfhdr); - /* write out notes program header */ - fill_elf_note_phdr(&phdr, info.notes_size, note_offset); + /* Create elf program headers. */ + fill_elf_note_phdr(hptr, note_size, note_offset); + hptr += sizeof(struct elf_phdr); - if (dump_write(fd, &phdr, sizeof (phdr)) != 0) - goto out; + offset = data_offset; + for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { + struct elf_phdr *phdr = hptr; - /* - * Write program headers for memory regions mapped in - * the target process. - */ - offset = data_offset; - for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { - (void) memset(&phdr, 0, sizeof (phdr)); + phdr->p_type = PT_LOAD; + phdr->p_offset = offset; + phdr->p_vaddr = vma->vma_start; + phdr->p_paddr = 0; + phdr->p_filesz = vma_dump_size(vma); + offset += phdr->p_filesz; + phdr->p_memsz = vma->vma_end - vma->vma_start; + phdr->p_flags = (vma->vma_flags & PROT_READ ? PF_R : 0) + | (vma->vma_flags & PROT_WRITE ? PF_W : 0) + | (vma->vma_flags & PROT_EXEC ? PF_X : 0); + phdr->p_align = ELF_EXEC_PAGESIZE; - phdr.p_type = PT_LOAD; - phdr.p_offset = offset; - phdr.p_vaddr = vma->vma_start; - phdr.p_paddr = 0; - phdr.p_filesz = vma_dump_size(vma); - offset += phdr.p_filesz; - phdr.p_memsz = vma->vma_end - vma->vma_start; - phdr.p_flags = vma->vma_flags & PROT_READ ? PF_R : 0; - if (vma->vma_flags & PROT_WRITE) - phdr.p_flags |= PF_W; - if (vma->vma_flags & PROT_EXEC) - phdr.p_flags |= PF_X; - phdr.p_align = ELF_EXEC_PAGESIZE; + bswap_phdr(phdr, 1); + hptr += sizeof(struct elf_phdr); + } - bswap_phdr(&phdr, 1); - if (dump_write(fd, &phdr, sizeof(phdr)) != 0) { + /* Create the notes. */ + dptr = fill_note(&hptr, NT_AUXV, "CORE", ts->info->auxv_len); + fill_auxv_note(dptr, ts); + + dptr = fill_note(&hptr, NT_PRPSINFO, "CORE", + sizeof(struct target_elf_prpsinfo)); + fill_prpsinfo_note(dptr, ts); + + CPU_FOREACH(cpu_iter) { + dptr = fill_note(&hptr, NT_PRSTATUS, "CORE", + sizeof(struct target_elf_prstatus)); + fill_prstatus_note(dptr, ts, cpu_iter, + cpu_iter == cpu ? signr : 0); + } + + if (dump_write(fd, header, data_offset) < 0) { goto out; } } - /* - * Next we write notes just after program headers. No - * alignment needed here. - */ - if (write_note_info(&info, fd) < 0) - goto out; - - /* align data to page boundary */ - if (lseek(fd, data_offset, SEEK_SET) != data_offset) - goto out; - /* * Finally we can dump process memory into corefile as well. */ @@ -4768,7 +4585,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) ret = -errno; mmap_unlock(); cpu_list_unlock(); - free_note_info(&info); vma_delete(&mm); close(fd); return ret; From patchwork Fri Mar 1 23:05:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777125 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604785wrn; Fri, 1 Mar 2024 15:20:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVr2YFY2NbbpvVBWDqvqacaFmrHcqWLZfXQPXAHcEAL4n+B35CZed2g2Vh7kKFIrnPibCqhLcr8F/E15ZHGgaXJ X-Google-Smtp-Source: AGHT+IEYoO443I5xET/aPSL23Nuydr5x2eFwydBjigyA0Zshn1Z0Byi36DrAwzYhZ/QZi/LUb3Cf X-Received: by 2002:a05:6102:c8b:b0:472:9433:2f8a with SMTP id f11-20020a0561020c8b00b0047294332f8amr3682927vst.4.1709335212748; Fri, 01 Mar 2024 15:20:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335212; cv=none; d=google.com; s=arc-20160816; b=IMN1Q4lphzgkJ6pmkY5kFfIPuOaLOLDlmPAANkGphOqLsKPQaQmzFs0k6gW2j/OueS MlKnqG+D5bwJWewsl3KYNBE9Chn3Ru8t5IcW5HDozt2fS6ZXLmQWebwgjjDFInWjRD0L u+LXBGUiPoibVs/nl9cnXDbCE/WdsO9SKxpRQTnAlLNFn0DHxRIRmwAdTUJOGEAeVSw9 5ATnkioCE8Ik/gSbEy3naWHzmRfA5BkEHWH7OBLBdYVS8SQQe4UOcvHaBYI5DiJO2wkb AORXQ6MIL+JWY7l/5j5kuJpqRLs0upYHFFAjmdN5K9IBL7x0Q1k9SkAq3ZTeQ0mW/UmK d6vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=a539O89HDnQm6bRrG3U6UEZ8BaBKZ6Sb8uXpIM9cbgIfBQu40RUgowpJDFhe64OTDH emPrrXZJQ8prAl3hDTFgJaYugnJ4k9ijuEuJngVkgr9LosalBVvpTTrQh/xDK8sKB17m oh10TwRnWSJvOymAz6IWyQimSzooGSP3lapjMA1b++yDugYad7ROOzkJS6p/q4q+CJrZ jJECNkXSCWrwy0POJJrm92KvJpJah70W6GgrzlXCP8Q7LKpl++hvgQeTfwA2CDvEtPBo WK0u+hl31zMscj0KuBwzo4E7i12nhhjQwInmWOiz5dy6ckzKtOvAt7H9a2wdGDWEMZfF Jh0A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P6m8rL7I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s16-20020ac87590000000b0042e6f32da95si4270287qtq.711.2024.03.01.15.20.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:20:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P6m8rL7I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxl-0004tt-CY; Fri, 01 Mar 2024 18:06:45 -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 1rgBxg-0004s2-7V for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxd-0004EA-Mq for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:38 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d94b222a3aso28315965ad.2 for ; Fri, 01 Mar 2024 15:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334396; x=1709939196; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; b=P6m8rL7I1LpNvpheAK8Iy1EoejxP3ojjKmen4VLCaz/iARpx7kZrXva2xSf7JgoAhh ncNpn8GOZhF2kW4t40moKPGQqZdxAn7Eqmkund5Twu6otaKpNsHrPfHsXhaEcb2yFnRx JXOTdahiZCZUZuAB+VwXQD5OYLEwRU/y/yk97DCYu9ZCp6D5DlIiGNC3R0oFmv310gul 3Lj/is+rruP3zLSh5bRid/nZ2/m3tUo14r89DQRN1J/L52sEUmon54PVYNWq0GWl4oIx Nw5h4Q1X5hWBQOZsH/2d6ulT3R846Co3CgiLhL1tu65Bo+imDO9tA9/ivJBkRB2texmy 0EtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334396; x=1709939196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tzO2W+WajMGPZKg0sOd9kLpT7E3B/88XAmc0t2vBAHU=; b=H5KGra6BxYE02HgPXgMT1Px+VCgy8W2iMtuJfCKSe5ow/kTrymTHuZdZrlf3PgJOz6 6mGNs4KpgzaWr2mk3vMtAgV3w6sRJHf5d49vdMyMwAq+iQ+usexQmY2VQya1xVzjAJN8 WRYU8PQc2kbMzUS5b9xh//T2mptg7vQpw6pTy+Z+dWwMxwIpkaOLfN1C2ect6CR2138Q wM8M7D89vi+tsvJGAwCWkkdS3qBbsf/XWwcmIic/sZjlM4wy1Bl29murm0l/Q7BGxK38 l0uV3ZYn/1613IU76FcoimUox5hyzg2LHFsez/3GkdpxkPYrAeJSXSHj7D0ZVuWfLF/i 8C9g== X-Gm-Message-State: AOJu0YzdXZKBIQ45NPeltLPgTWw9d1D1y3LLEpZATgb7JWPFVGYCC3Q1 yJsE9Yvg9W1+F+1syhFACoPAgiTvb40QD+Hf1/jv+eK2PLy6J4bSwDkJwkvooJk8qdhoSYe4sae i X-Received: by 2002:a17:902:82c7:b0:1dc:affb:1f50 with SMTP id u7-20020a17090282c700b001dcaffb1f50mr2927967plz.47.1709334396419; Fri, 01 Mar 2024 15:06:36 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/60] linux-user/elfload: Write process memory to core file in larger chunks Date: Fri, 1 Mar 2024 13:05:30 -1000 Message-Id: <20240301230619.661008-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We do not need to copy pages from guest memory before writing them out. Because vmas are contiguous in host memory, we can write them in one go. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b8d07d8054..491e754f72 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4551,32 +4551,13 @@ static int elf_core_dump(int signr, const CPUArchState *env) } /* - * Finally we can dump process memory into corefile as well. + * Finally write process memory into the corefile as well. */ for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { - abi_ulong addr; - abi_ulong end; + size_t size = vma_dump_size(vma); - end = vma->vma_start + vma_dump_size(vma); - - for (addr = vma->vma_start; addr < end; - addr += TARGET_PAGE_SIZE) { - char page[TARGET_PAGE_SIZE]; - int error; - - /* - * Read in page from target process memory and - * write it to coredump file. - */ - error = copy_from_user(page, addr, sizeof (page)); - if (error != 0) { - (void) fprintf(stderr, "unable to dump " TARGET_ABI_FMT_lx "\n", - addr); - errno = -error; - goto out; - } - if (dump_write(fd, page, TARGET_PAGE_SIZE) < 0) - goto out; + if (size && dump_write(fd, g2h_untagged(vma->vma_start), size) < 0) { + goto out; } } errno = 0; From patchwork Fri Mar 1 23:05:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777080 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601274wrn; Fri, 1 Mar 2024 15:08:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVSTTIrOg2D2V2DitWpW4vnnKVlPfOCFDUC9dNG1iITlBcLKcSAtAEQIDHWXWQ4SeZPDwiW6jCCfKVbNjLF1iLE X-Google-Smtp-Source: AGHT+IEKY69bIEM6F87h/2ypi6dqcpTRWX7iUD2ske3/5P/I5lMN88AR6idteSqJegknYWV4XCl1 X-Received: by 2002:a05:6358:7e0d:b0:17a:e17f:7f07 with SMTP id o13-20020a0563587e0d00b0017ae17f7f07mr3371665rwm.15.1709334511459; Fri, 01 Mar 2024 15:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334511; cv=none; d=google.com; s=arc-20160816; b=Rqpgb0isCDkZ0DiWe8vM0tsU5usIj0rCykSxkhju0u+XsdwT01QhGsmnIi+X6U+QQL B691QfiROCFB4Dvd/vUIxttBuzKFtgTjzX3gmBV6EhFmdKvvkoW7qyq6PDK1VpwlR9ne 3IGRpqpjxeAbFOtg004PsjS80dwNp6crLT5BN1AiHk77ivnrBtlDwH9q0klEm3HK0dwY WdSE1q8itGJgdU36b9w68Mj0yw5FSHMSTiSpd4WZnPo6eCjHm9+OtSYD16RaMEkROpDO DLTZQHtYV8UXS+bQg20knu3aeg3tfEt4c86gFeVfRd07YUf15in8EuDgHwNystVJ/343 kA7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=lWPOt3X2/SkK7TCeC80rFG4hfv1SleFi0d7pJdfgnlI/x/tehHADTMcXstBCvahyTA gMFfSWxpv72P35mJpG7t27h4uMq39IBgw/tRhBj9MWlbnSQSCHkwn4WpG6ZFIF66KqNZ MRC06ptG2a4BPQLOVOVg9FOhu5uf3n+RcOGWe43WO9Iq6vsR78AuHyY2XXZxXl3KaiNo urMXhVpmIVLCaA7jiIU/aSZTGokiO4dWgw2V+JbsN3yP9i6NDFT3E67GZfikUQoo960E hCs3lS1MZkEhBis0Kb+KdWFGWAooxX6Vkc+WQUrmY0Ly22yhfJTN0dCh3sVE3OFKBF7D eEfQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pmFLZGTX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ld12-20020a056214418c00b0068cf8ab1139si4363585qvb.374.2024.03.01.15.08.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:08:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pmFLZGTX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy8-0005RB-TU; Fri, 01 Mar 2024 18:07: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 1rgBxh-0004s4-FX for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:42 -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 1rgBxf-0004ES-VQ for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:41 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d93edfa76dso24887475ad.1 for ; Fri, 01 Mar 2024 15:06:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334397; x=1709939197; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; b=pmFLZGTXXZXzdF5qfX0OU4tBoQ8yXXaL4zaJKuPkSw2ygntThzwFtiqu6BSQh0Jm1Y Nc8VZmaFnsEPZv8gdfqYFofoPQZkRlgyJ5Er9i1j6g1zn28zeXj9vsDPwpYJnBSzCuo1 bBTSWlNUqaAQSuuZaMOis9pONSeVpsV9UF5YBh4Xo5AOJm7zDDlFknQxcU7flzyVFWu+ 58hEEbiqZnswvMOaXpxiiPdqL3OdHBjefGDcuwRT1v/tUTkcZ4LXJ0uTQko+F9Almowm FxNWZ33FPAfF1d8e/jFkBUxVNukf0QzbUcsEm7Yb7lUc8ASlzg70+lUld1XbB6Ws9F92 aV0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334397; x=1709939197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HEYpUbYOjLF3aHdvtZVlKWz9YeEEY+0zYSzPOHYy/W8=; b=ICHSrWGyipgiYsnLxr8MnJQcAr9zKmT5nlUv5BPSegczwX0EME9fDOYq+Q5LTolXKv CsWXxd1RlXOCKiKmHgxvl0d9WyxRJcQA++5JpdpFTsZ6B2nzd1AspMiy3wTKlGbj2T7B kDPMiJX8slUVrTEA6sPBHSbZv0EvtQhvP+vjaMjqN0FioPqRnpVwOli1+faRYJqd+YKz qfSWf5ydL5+tlo5iPuEPK9ESnLe+ED1V+I76TKn4a1qJ0uaJhmhWG6rFnvrOaQw+8e7s pTJ+cKI1RnTP8k6eS2LmmirrOnD32C6rJOdJ0EJP8E7SJm5ZEBeP3wFgUL8YvoKHKNKl vBwQ== X-Gm-Message-State: AOJu0YxBGuMfvFWCXrdG7/HKxFH/MyF5HiurYcS6vZICWvBwuHCg9s1t vNQ0yXiPiflQYeH5GduUFOd7DssY6J5aDlxOgcYt8LKM5XMLh2YvcUd1P375v9h6ryLNUYs2tdP z X-Received: by 2002:a17:902:e744:b0:1dc:d722:4c08 with SMTP id p4-20020a170902e74400b001dcd7224c08mr3969526plf.5.1709334397658; Fri, 01 Mar 2024 15:06:37 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 12/60] linux-user/elfload: Simplify vma_dump_size Date: Fri, 1 Mar 2024 13:05:31 -1000 Message-Id: <20240301230619.661008-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use the flags that we've already saved in order to test accessibility. Use g2h_untagged and compare guest memory directly instead of copy_from_user. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 491e754f72..47b5ce3005 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4166,37 +4166,23 @@ static int vma_get_mapping_count(const struct mm_struct *mm) */ static abi_ulong vma_dump_size(const struct vm_area_struct *vma) { - /* if we cannot even read the first page, skip it */ - if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) - return (0); + /* The area must be readable. */ + if (!(vma->vma_flags & PROT_READ)) { + return 0; + } /* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from - * target library etc. However, thread stacks are marked - * also executable so we read in first page of given region - * and check whether it contains elf header. If there is - * no elf header, we dump it. + * target library etc. If there is no elf header, we dump it. */ - if (vma->vma_flags & PROT_EXEC) { - char page[TARGET_PAGE_SIZE]; - - if (copy_from_user(page, vma->vma_start, sizeof (page))) { - return 0; - } - if ((page[EI_MAG0] == ELFMAG0) && - (page[EI_MAG1] == ELFMAG1) && - (page[EI_MAG2] == ELFMAG2) && - (page[EI_MAG3] == ELFMAG3)) { - /* - * Mappings are possibly from ELF binary. Don't dump - * them. - */ - return (0); - } + if (!(vma->vma_flags & PROT_WRITE) && + (vma->vma_flags & PROT_EXEC) && + memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) == 0) { + return 0; } - return (vma->vma_end - vma->vma_start); + return vma->vma_end - vma->vma_start; } static int vma_walker(void *priv, target_ulong start, target_ulong end, From patchwork Fri Mar 1 23:05:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777086 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602143wrn; Fri, 1 Mar 2024 15:11:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV27KoLGgLrbI8SdapcJlQt5QS3IUgaJvI1rUedvYp2bhejxdwGmgPkDimQpTyIRtedqExZv9lHAd7XaHyXVXgS X-Google-Smtp-Source: AGHT+IHFBghant3s6+zQzFsgvR2Z2izj+mRErPa5MuOag1fR3u7hGZV/hgexXj1Xrb3j/8WVhdhH X-Received: by 2002:a25:d808:0:b0:dc7:46b7:b7f6 with SMTP id p8-20020a25d808000000b00dc746b7b7f6mr2762414ybg.28.1709334665511; Fri, 01 Mar 2024 15:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334665; cv=none; d=google.com; s=arc-20160816; b=m5CZ0CJcHgiAAmkl6kQ7VSPEh//R3ffdxPlNcBO+ZhhiyHFv4ZWvBSl32cWPC/w4Hn 132B/AFi/TWHMVdXCLZh7MwDAnfnGYbU8veMM8qwA+YBpIwBG+93ehVm33h4TwzgOTTa +6crfOiWyPFCmWWgww5JIAmYkOiEls2uf2oUj+wmc3UDUsTnbRVcQaAcjI1eTFYSNNJk 4FU/bFel5CLx8C8//UhkBiNXMCLxU57+a9myCAw//SHllRPrB+po5ufoSG/e+YiYeFjW jzqChaxRGlHokeLamzdbyymGPW8wHwRM3nFYqzFnt6iw0qsGoG+UAokroc7rdK15TQCO B0rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=giZ24saxiwxROBhWiBg8FdHbh3+0AOej/Ina22iSzlfhkFr4LZj3PsNCqRE6S2Kckt PnqQW9TpZ43Rn72UoMp1wP5gXMCLzd59yTLZeLsqAvyklZXfxwKWaplku6wXCmOcjA4v xuPdGCpGpcB75VCwid7Ww8TK2ORQ5QfG8q9bdo1OuS3PJi9i/bzuDti5G0TQcTKXLHwh rIinN5jT2lxB9D2eqkONeB5Fwt+wWts4Jjs6FE6ClSfpHGANZl5ajj6Rvk5rdMixkRna z1XlX+wCrjQYjR93PScYa8AR9XQ53/PoXRSzjuqcI9+fZBBEvohAtWFhiCfnimYkvglz lARA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vL705bUx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w4-20020a05622a134400b0042ec2608014si3896001qtk.25.2024.03.01.15.11.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:11:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vL705bUx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy0-0004zk-7o; Fri, 01 Mar 2024 18:07: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 1rgBxj-0004tG-F0 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:45 -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 1rgBxg-0004Eb-GS for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:43 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dc5d0162bcso25435425ad.0 for ; Fri, 01 Mar 2024 15:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334399; x=1709939199; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; b=vL705bUx8CEmy+GV8iREqCQJB8KkojXRjpoT1cGyjlP1T7Q/5s+oIWjcD3MUI+cqap 4E3ZBPPn4hivlO0+djJBbI+t1Pi4IwHnNhb9pNYr9x12eUDfEoBhKG5JGAXnZ5xy2Gxs LjoPdk5Owx5aQ4eVXHHREze4+YUFj2Loe6j3xNUqowVzTAEy+STWbUtwvY8lJUvZvZFI Z23KZcz6z+fO25JYz5Bs4cyVN0mUUSf6/rm/jEeQVHAHqCD1Wz6+vZT84UkkBT21iP+b ZWfCtkiongNys0H5waDpY6ABlaDMBx/gHk4QtolLemHTcPYQYo/GUDzZlEdPcY6YdP1V M/bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334399; x=1709939199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mVP5ZXMph2vIaMrgjNZyRxPQx2YhCwiWw0i2ONELss0=; b=LPuSnFPoQME5BQktg7++nYUCj1Yk8q9zaAGeu8lsvArBsU+AMp+ILoplUuGpU5PDyk FoetYx7mcQu4cK2bH/OtfZCoXFAS3a6mBHcwjbCFht7Je4HxFIDbx8dBLRiL6ibaRAr4 MVNPVnNgHfJJV4PEOaNPerRSJC21dT413THIF/XNtrTQ1rzH/ySUDNPWUyT1Thzoh+ii kJ7Yeb+ITMvebek5drf3zhMY//7aUIrwHOACE8o1VBWol6YekfNDsB0Q3h7/9HFBjMh2 XFVo5roXe3rvbaZ+BPG5LNOUjxZuBVX0C7Ss+Msq0BkCuRj6sJ/2+kW4TASIKXWwH+1J yEHg== X-Gm-Message-State: AOJu0YzYTexTDtu5w1kpdav1anbORAhfa3tcJH4oeuRrdqTy4XvXh1OQ LHd85lAcOZo6cXakaaubufxvZ/jXMPq4wQP3/WXvXG1ZZ5/lOaQATGUCQfv8Z7QLrOrz9PXGd7V y X-Received: by 2002:a17:902:b688:b0:1d9:7095:7e3c with SMTP id c8-20020a170902b68800b001d970957e3cmr2699747pls.57.1709334399094; Fri, 01 Mar 2024 15:06:39 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 13/60] linux-user/elfload: Rely on walk_memory_regions for vmas Date: Fri, 1 Mar 2024 13:05:32 -1000 Message-Id: <20240301230619.661008-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Rather than creating new data structures for vma, rely on the IntervalTree used by walk_memory_regions. Use PAGE_* constants, per the page table api, rather than PROT_* constants, per the mmap api. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 213 ++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 135 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 47b5ce3005..ae0abc4931 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4041,29 +4041,6 @@ struct target_elf_prpsinfo { char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ }; -struct vm_area_struct { - target_ulong vma_start; /* start vaddr of memory region */ - target_ulong vma_end; /* end vaddr of memory region */ - abi_ulong vma_flags; /* protection etc. flags for the region */ - QTAILQ_ENTRY(vm_area_struct) vma_link; -}; - -struct mm_struct { - QTAILQ_HEAD(, vm_area_struct) mm_mmap; - int mm_count; /* number of mappings */ -}; - -static void vma_init(struct mm_struct *); -static void vma_delete(struct mm_struct *); -static int vma_add_mapping(struct mm_struct *, target_ulong, - target_ulong, abi_ulong); -static int vma_get_mapping_count(const struct mm_struct *); -static struct vm_area_struct *vma_first(const struct mm_struct *); -static struct vm_area_struct *vma_next(struct vm_area_struct *); -static abi_ulong vma_dump_size(const struct vm_area_struct *); -static int vma_walker(void *priv, target_ulong start, target_ulong end, - unsigned long flags); - #ifdef BSWAP_NEEDED static void bswap_prstatus(struct target_elf_prstatus *prstatus) { @@ -4105,69 +4082,14 @@ static inline void bswap_psinfo(struct target_elf_prpsinfo *p) {} static inline void bswap_note(struct elf_note *en) { } #endif /* BSWAP_NEEDED */ -/* - * Minimal support for linux memory regions. These are needed - * when we are finding out what memory exactly belongs to - * emulated process. No locks needed here, as long as - * thread that received the signal is stopped. - */ - -static void vma_init(struct mm_struct *mm) -{ - mm->mm_count = 0; - QTAILQ_INIT(&mm->mm_mmap); -} - -static void vma_delete(struct mm_struct *mm) -{ - struct vm_area_struct *vma; - - while ((vma = vma_first(mm)) != NULL) { - QTAILQ_REMOVE(&mm->mm_mmap, vma, vma_link); - g_free(vma); - } -} - -static int vma_add_mapping(struct mm_struct *mm, target_ulong start, - target_ulong end, abi_ulong flags) -{ - struct vm_area_struct *vma; - - if ((vma = g_malloc0(sizeof (*vma))) == NULL) - return (-1); - - vma->vma_start = start; - vma->vma_end = end; - vma->vma_flags = flags; - - QTAILQ_INSERT_TAIL(&mm->mm_mmap, vma, vma_link); - mm->mm_count++; - - return (0); -} - -static struct vm_area_struct *vma_first(const struct mm_struct *mm) -{ - return (QTAILQ_FIRST(&mm->mm_mmap)); -} - -static struct vm_area_struct *vma_next(struct vm_area_struct *vma) -{ - return (QTAILQ_NEXT(vma, vma_link)); -} - -static int vma_get_mapping_count(const struct mm_struct *mm) -{ - return (mm->mm_count); -} - /* * Calculate file (dump) size of given memory region. */ -static abi_ulong vma_dump_size(const struct vm_area_struct *vma) +static size_t vma_dump_size(target_ulong start, target_ulong end, + unsigned long flags) { /* The area must be readable. */ - if (!(vma->vma_flags & PROT_READ)) { + if (!(flags & PAGE_READ)) { return 0; } @@ -4176,22 +4098,13 @@ static abi_ulong vma_dump_size(const struct vm_area_struct *vma) * non-writable code that debugger can read directly from * target library etc. If there is no elf header, we dump it. */ - if (!(vma->vma_flags & PROT_WRITE) && - (vma->vma_flags & PROT_EXEC) && - memcmp(g2h_untagged(vma->vma_start), ELFMAG, SELFMAG) == 0) { + if (!(flags & PAGE_WRITE_ORG) && + (flags & PAGE_EXEC) && + memcmp(g2h_untagged(start), ELFMAG, SELFMAG) == 0) { return 0; } - return vma->vma_end - vma->vma_start; -} - -static int vma_walker(void *priv, target_ulong start, target_ulong end, - unsigned long flags) -{ - struct mm_struct *mm = (struct mm_struct *)priv; - - vma_add_mapping(mm, start, end, flags); - return (0); + return end - start; } static size_t size_note(const char *name, size_t datasz) @@ -4367,6 +4280,61 @@ static int dump_write(int fd, const void *ptr, size_t size) return (0); } +typedef struct { + unsigned count; + size_t size; +} CountAndSizeRegions; + +static int wmr_count_and_size_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + CountAndSizeRegions *css = opaque; + + css->count++; + css->size += vma_dump_size(start, end, flags); + return 0; +} + +typedef struct { + struct elf_phdr *phdr; + off_t offset; +} FillRegionPhdr; + +static int wmr_fill_region_phdr(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + FillRegionPhdr *d = opaque; + struct elf_phdr *phdr = d->phdr; + + phdr->p_type = PT_LOAD; + phdr->p_vaddr = start; + phdr->p_paddr = 0; + phdr->p_filesz = vma_dump_size(start, end, flags); + phdr->p_offset = d->offset; + d->offset += phdr->p_filesz; + phdr->p_memsz = end - start; + phdr->p_flags = (flags & PAGE_READ ? PF_R : 0) + | (flags & PAGE_WRITE_ORG ? PF_W : 0) + | (flags & PAGE_EXEC ? PF_X : 0); + phdr->p_align = ELF_EXEC_PAGESIZE; + + bswap_phdr(phdr, 1); + d->phdr = phdr + 1; + return 0; +} + +static int wmr_write_region(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + int fd = *(int *)opaque; + size_t size = vma_dump_size(start, end, flags); + + if (!size) { + return 0; + } + return dump_write(fd, g2h_untagged(start), size); +} + /* * Write out ELF coredump. * @@ -4414,12 +4382,11 @@ static int elf_core_dump(int signr, const CPUArchState *env) { const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; - struct vm_area_struct *vma; struct rlimit dumpsize; - struct mm_struct mm; + CountAndSizeRegions css; off_t offset, note_offset, data_offset; size_t note_size; - int segs, cpus, ret; + int cpus, ret; int fd = -1; CPUState *cpu_iter; @@ -4438,9 +4405,8 @@ static int elf_core_dump(int signr, const CPUArchState *env) * Walk through target process memory mappings and * set up structure containing this information. */ - vma_init(&mm); - walk_memory_regions(&mm, vma_walker); - segs = vma_get_mapping_count(&mm); + memset(&css, 0, sizeof(css)); + walk_memory_regions(&css, wmr_count_and_size_regions); cpus = 0; CPU_FOREACH(cpu_iter) { @@ -4448,22 +4414,18 @@ static int elf_core_dump(int signr, const CPUArchState *env) } offset = sizeof(struct elfhdr); - offset += (segs + 1) * sizeof(struct elf_phdr); + offset += (css.count + 1) * sizeof(struct elf_phdr); note_offset = offset; offset += size_note("CORE", ts->info->auxv_len); offset += size_note("CORE", sizeof(struct target_elf_prpsinfo)); offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus; note_size = offset - note_offset; - offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE); - data_offset = offset; - - for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { - offset += vma_dump_size(vma); - } + data_offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE); /* Do not dump if the corefile size exceeds the limit. */ - if (dumpsize.rlim_cur != RLIM_INFINITY && dumpsize.rlim_cur < offset) { + if (dumpsize.rlim_cur != RLIM_INFINITY + && dumpsize.rlim_cur < data_offset + css.size) { errno = 0; goto out; } @@ -4485,36 +4447,22 @@ static int elf_core_dump(int signr, const CPUArchState *env) */ { g_autofree void *header = g_malloc0(data_offset); + FillRegionPhdr frp; void *hptr, *dptr; /* Create elf file header. */ hptr = header; - fill_elf_header(hptr, segs + 1, ELF_MACHINE, 0); + fill_elf_header(hptr, css.count + 1, ELF_MACHINE, 0); hptr += sizeof(struct elfhdr); /* Create elf program headers. */ fill_elf_note_phdr(hptr, note_size, note_offset); hptr += sizeof(struct elf_phdr); - offset = data_offset; - for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { - struct elf_phdr *phdr = hptr; - - phdr->p_type = PT_LOAD; - phdr->p_offset = offset; - phdr->p_vaddr = vma->vma_start; - phdr->p_paddr = 0; - phdr->p_filesz = vma_dump_size(vma); - offset += phdr->p_filesz; - phdr->p_memsz = vma->vma_end - vma->vma_start; - phdr->p_flags = (vma->vma_flags & PROT_READ ? PF_R : 0) - | (vma->vma_flags & PROT_WRITE ? PF_W : 0) - | (vma->vma_flags & PROT_EXEC ? PF_X : 0); - phdr->p_align = ELF_EXEC_PAGESIZE; - - bswap_phdr(phdr, 1); - hptr += sizeof(struct elf_phdr); - } + frp.phdr = hptr; + frp.offset = data_offset; + walk_memory_regions(&frp, wmr_fill_region_phdr); + hptr = frp.phdr; /* Create the notes. */ dptr = fill_note(&hptr, NT_AUXV, "CORE", ts->info->auxv_len); @@ -4539,12 +4487,8 @@ static int elf_core_dump(int signr, const CPUArchState *env) /* * Finally write process memory into the corefile as well. */ - for (vma = vma_first(&mm); vma != NULL; vma = vma_next(vma)) { - size_t size = vma_dump_size(vma); - - if (size && dump_write(fd, g2h_untagged(vma->vma_start), size) < 0) { - goto out; - } + if (walk_memory_regions(&fd, wmr_write_region) < 0) { + goto out; } errno = 0; @@ -4552,7 +4496,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) ret = -errno; mmap_unlock(); cpu_list_unlock(); - vma_delete(&mm); close(fd); return ret; } From patchwork Fri Mar 1 23:05:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777089 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602388wrn; Fri, 1 Mar 2024 15:11:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUn1GlP8asn0XeZTIoq0gEJVs/s3pCVwmkESChSPXJkY+nGaPRXDUamLrJqxZNml1vfBm3nATx4wbOxxKNaXw1O X-Google-Smtp-Source: AGHT+IHtQmBftTPGkjJ7xR+z8kZX+1Ss6eR0z7dG95ueyEBlbbNLriJqbRsQG7gfgTl22n9NQSj0 X-Received: by 2002:ad4:40c5:0:b0:68f:52b3:6d12 with SMTP id x5-20020ad440c5000000b0068f52b36d12mr3342043qvp.29.1709334713503; Fri, 01 Mar 2024 15:11:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334713; cv=none; d=google.com; s=arc-20160816; b=l4u2V1f9PVNp0j/BQblWaI1EeM89KVDkmEhkQE3iibmtrFaAJ1ZC7Div38eNnFCXZK hnUnOcxX5tq7XU9hoVaD/KCbNjhTpNM7SnnuyJiTpRwM5dJXUF+u0ilKbuMworSzM7mY Q920e8pBD0KtkskC0+Ah/NtNKzaqNbHVbnfJOfX4BKcTEAzno3+FShCfgizks+3eogNZ ToaB/tvauDWYcPAaghuRejJVSfsbyDo2D/v0S/hwX4cnvcxZzX6HOAh542v8dQxmqvqZ H9bv21ZogYBQjLqgrMQzQqdWOjnogWRu2pzaVIcUYwLO8iLPMTehgPBWTtwBLuiV3yRu m87w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=qnBKcE1upHs3W0wU8PYAnZ586opwrt4EWVvCXlBsAi1b75TfECHQqR0PaMfybVG7Qh Zv4XzX4Vsvj1wRxsY0SFfPcY1WGfLptLI3QudYy5g9+VHahiRqVUeGE6Uiqcqy9dJ1K1 kHCIdsd2vAgR6gDruN1yAjo99M6ChjTk20x6xzjjGQ1LsNsozJmiRIW4N9nKyTvg1oh1 VXMhvnfMADGBDhC/xsvqGxhz+m300nrfkZ63ZjRKEYpstzp+/8FPVhqJr2yZpd7kOLGf 8adVAM8P2NMi3P1OvZCwC/idQPu2nGRLVnKwUr3635zNvicSup/GLOvlCUBmcboe26gE zfQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTT4bmeE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u1-20020ad45aa1000000b00690068798fbsi4494217qvg.578.2024.03.01.15.11.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:11:53 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTT4bmeE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBxu-0004wR-Uv; Fri, 01 Mar 2024 18:06: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 1rgBxk-0004tQ-Bl for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:45 -0500 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgBxh-0004Et-M5 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:43 -0500 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6e5eaf5bb3eso42129b3a.3 for ; Fri, 01 Mar 2024 15:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334400; x=1709939200; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=QTT4bmeE7P/lrVIF0X06t1YN6uyGHWaVG2wQfeTXzhpbapEFKuZVmMxBSMNvpYeXH4 8tspBwkln3Mrw5p3New126xroPB2t70UjJa/2Ar054egJy5tH4jMMLnyWxneePPVCcQR 4fWHDTIPno9QHuiEDfn1F7vGX5+lRETtuUgey3hXQaOJtRQOLCEMKnt3JE6uNhYwvAyu WYuivQNtelccOQj3OA0Q5nG1uWGn7VkfznDXj08SCk+M4bTklJAMApQiwNsD7l/m8AEd aU0Vdcj83T3TP1t1qFKwnzzm2B/+oV0WJqd8+x2/kuLlPGdEc9cg4e8cxzlSzqxs/Wko 0yIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334400; x=1709939200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2XrEdDvQ88jaxWmSDzzj/y67fD3f8yoeJckZhxITx78=; b=HAYfkdjP6ZhrpqJ9Np9ccw32GDOruRuPZeDNNqO1jXtNUzlDjGrb3EEBd7ncTLYgEJ QXWS2iE6Uy9BskZCrvhvYg3j/7OItQ8PdiCwrtUG/a8YOfQU8hqQkwbhFhxV8l9a0Dzu EJc0hUoAVcvmsAACTQuBsWMEGr4zxkT2L5Y7JS8ooTvp3bUJlRO0UHn1PzcDzdkqycnP 6dKFMQoJVHORzgsu50dtc9qdi7Azr4RdTxHBTDcIvCP4r2YA77qYEN/48UwnNgnx+y56 QrOoeT0eF+OYtnYNOyAxXyLuebCo7jiAkT5zL5Q1pgQoqP4Gs9pVZWJHIHzVlbW/3idG mIAw== X-Gm-Message-State: AOJu0Yz6qw1ZQDwg4ddkJzAjVzf49ZIjGp0Vgr02/7ffRZxPrPLGBPO3 w/4B3PBuVodj8RL0h+oCoJot+a7/ch1KHhN/U8pBRLu1TbTOxjRa+w9OOy7rf+TUqlAvHpCGxV2 P X-Received: by 2002:a17:902:d3c4:b0:1dc:5d9d:6eb3 with SMTP id w4-20020a170902d3c400b001dc5d9d6eb3mr2833150plb.21.1709334400245; Fri, 01 Mar 2024 15:06:40 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 14/60] linux-user/elfload: Unprotect regions before core dump Date: Fri, 1 Mar 2024 13:05:33 -1000 Message-Id: <20240301230619.661008-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org By unprotecting regions, we re-instate writability and unify regions that have been split, which may reduce the total number of regions. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ae0abc4931..38bfc9ac67 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3963,6 +3963,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) } #ifdef USE_ELF_CORE_DUMP +#include "exec/translate-all.h" + /* * Definitions to generate Intel SVR4-like core files. * These mostly have the same names as the SVR4 types with "target_elf_" @@ -4280,6 +4282,23 @@ static int dump_write(int fd, const void *ptr, size_t size) return (0); } +static int wmr_page_unprotect_regions(void *opaque, target_ulong start, + target_ulong end, unsigned long flags) +{ + if ((flags & (PAGE_WRITE | PAGE_WRITE_ORG)) == PAGE_WRITE_ORG) { + size_t step = MAX(TARGET_PAGE_SIZE, qemu_host_page_size); + + while (1) { + page_unprotect(start, 0); + if (end - start <= step) { + break; + } + start += step; + } + } + return 0; +} + typedef struct { unsigned count; size_t size; @@ -4401,6 +4420,9 @@ static int elf_core_dump(int signr, const CPUArchState *env) cpu_list_lock(); mmap_lock(); + /* By unprotecting, we merge vmas that might be split. */ + walk_memory_regions(NULL, wmr_page_unprotect_regions); + /* * Walk through target process memory mappings and * set up structure containing this information. From patchwork Fri Mar 1 23:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777102 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603308wrn; Fri, 1 Mar 2024 15:15:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXuBNqJj+QX5B2JXSbVdrPo924p3tNGxdO5iQ6anJ7YEuP8enSpKH+uBIlZwGr3Ue5SFKj07LW09u2okzXgdF6U X-Google-Smtp-Source: AGHT+IHxMk9NQIj8Ou6Ql0l2XJycewjqvz1z0XS9guVHUrMxSBV2hJACaZ6u2PBzYTlypcAsvhDh X-Received: by 2002:a37:f518:0:b0:787:caee:4309 with SMTP id l24-20020a37f518000000b00787caee4309mr3337549qkk.31.1709334910464; Fri, 01 Mar 2024 15:15:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334910; cv=none; d=google.com; s=arc-20160816; b=yzL04Dj9Nz2OEbA3HwE9Y48lTL06jh0ZcYx6mhw2HemxTr6TVWHSHpKZTFmK/caWjA 5E8F6hHu7BbYClLVdOnq600+pnOMoMj+PMuyIjrZv9y/AFfoKKLCT6tQxCG9RSwOXZFT V2tULttKFejR2yEBzKsreuiN0/Piby5wU4E4e4g6hg8Rsaume4cNH2rKFeWLtIhoJNQl rdzelVP68GCDJjGAEN3kSRZy2n1DhFYTjfYQ7o0tw1CfEwDJ/s9YoJ3LdieiXIUCxq4x sTN5XDGV3a5pjizBktkyyVjJY78y0pm7QMlDmbdcT87+MI2WH0gMFt4uv4Jvs6Cs1f2a hpTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6bGhiDlU0H1FunNKKdUnN7eps2A5T8/N/TZO0RrbQvI=; fh=aYwv1qvAWDHKcZLZyhvLuIoAkBRd6ysYy/Itgr1WhFg=; b=a0rJdBP4dxSPooVWAB9cZ4QReo3j/uWmT3Ou2UEl/e9/zdnBDOHy44HlcHgxoDrBDi f4TaduT57QS+IqkJEiO2FP++pcVgxmGInJERj84Ko5ZynvKJxWsQC1Mvyk1K8UN0o0rr hNvgeK00w+Q6bAShdULQM1QBE2WV4TLNokgc31nN/mLvVzGfml4H4LUq3R0EVV8rfvt2 xOYbNf2rmK73pGQlgNp/K4NdJE9aukxN4XLjQkK0tB7PTHBRhSBw9nvwX8aiSXM4s3Jr bmQHELFuchkB4nUQF/bFNGbhAOisf8aBFjYL1xo7zk+IiAXO56C/EsQHrBPieaF2dZGd i40Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NY+IJdWx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h29-20020a05620a21dd00b00787b70a0317si4483484qka.299.2024.03.01.15.15.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NY+IJdWx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy0-00050G-F1; Fri, 01 Mar 2024 18:07: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 1rgBxl-0004u0-Di for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:45 -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 1rgBxj-0004F5-0Q for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:44 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dc75972f25so24446135ad.1 for ; Fri, 01 Mar 2024 15:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334402; x=1709939202; 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=NY+IJdWxkIpZk00NtGYSj7nMW/jeCcb9k/FtIhh0zp3+DicMWEW5wgXSRBUovkHM7e UtubRaEELxdHSx+y1pSpDNJoP9EVA1GJsG+WVE1SvlCkAmIDT+VhaNF6EiIUtjjSBcw8 7dOsXWkK4U13DXwBjSojNOfx01oyuIoci8rGBw/MpzM4y4nxz6KTrMtgralv8qccvkGD 3bKRhmPdSa7CzGNEc5gsmkBc6vvcftJKy3QfsTouLCODsGyZ51oJtYWtf9Rjq5H4SFcC O42SRxUkqCXzdFNkOk+ZcR8kP9FVsXGz1wvRQU++PS/NtYWwYuW7n32f6Rz+ltqugTzR xNPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334402; x=1709939202; 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=Tvz9fDSmTeWDBwsYPt4EsV18JxxUJgV9S8SeUZuFLCaFtx65ZPLBT5V6wgDnA5LihF tcGSF86hZLcwY22pStbfeip4ZCfDh+rKfA0dn/v81Mqh0YxlIv36xSo/3Nv6BDLOy0YB kLo+hzex+B9/mCkULgqlXPhSYsJqwK5JNwq7ANAu470V02iW309O4Umm1TZq6yPRH+sY 0xJSJL67iVOAlw0RLyg6aKonf0TBMK20e/i4mwbAajYC8V7uM7PQ7oJuxo2bvSL9C3JK dXxYIg2Gh2wLsDfvYU84O4N9vcHc90Nw87o9ib1B+n9CY/s75Vw5WHnlZYHlo+VahpA7 7gLQ== X-Gm-Message-State: AOJu0YwMRDkX5QaRGbi9yr9BDayyiT+bXwY+vt2IS7UAYilZ3a7l0AX2 5ILMcIwnD7DOa5UgEFid1l7kT88rTpDXogi7al8sRuCNtITmH6zJmHWvinCQL5X31BOverYHgbr 2 X-Received: by 2002:a17:902:a508:b0:1dc:5ae8:174c with SMTP id s8-20020a170902a50800b001dc5ae8174cmr2517460plq.17.1709334401791; Fri, 01 Mar 2024 15:06:41 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 15/60] tcg/aarch64: Apple does not align __int128_t in even registers Date: Fri, 1 Mar 2024 13:05:34 -1000 Message-Id: <20240301230619.661008-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777108 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603717wrn; Fri, 1 Mar 2024 15:16:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWjD6VJRjE59R9SFLblbJMoX7atSNYzHanUcXCL5TdxARj22PvTOJwymEaQpwd4p3wjojHl7+Qz0i9kpJCd+5vV X-Google-Smtp-Source: AGHT+IEYr9AnQ5XDgqbs9rv3Jri1GcFq4a0EFYTEbm9P7///ZX9rh3YespMc4WDuFaJRXQOJ4a9Z X-Received: by 2002:a05:6358:290b:b0:17b:f093:9156 with SMTP id y11-20020a056358290b00b0017bf0939156mr3434451rwb.26.1709334986252; Fri, 01 Mar 2024 15:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334986; cv=none; d=google.com; s=arc-20160816; b=ITLgNvKVtSZcUKfuJSvasze1BcO1xJVfBphanEFGb/kBzGtW6d0PYpxNhK+UxTxD+V wFu32vFif4AuBQ5Sr2a9qQB1L/sT4zu+TaGQiG+uw1zFlzWoLsDeeHquoXEoXcp7mlpP TKZOvSwf+6NVAAUckMwHi5x6r7YNNB9z6JThDIXjqm1vy96U45UlLvAjHh67pX/Zwmev 5Uu1jiPQZbzYrfRBxNpCcQPfPAk/uuG17jyLfy12lRYf7b1F5CD3DBu8+L/4fubJ/Q3R wtQ+ExwY1ic+b6CLGZZk+bR17rWmyFzdjry0YoLLDiYyZIWK1RcfT2Q5+nA6Hvon7ULo l0qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=riDxx/Iexj1qjgzxqR/EG3iYXorkzbFxBXBzbTLKvNo=; fh=b0BCSzBBCb15Qz0w2SaDYFXCQsyBHWooe1k9DSXIzPA=; b=kePy+0qv4S6TMCFiOnOt6mcuOwCrfby8ZIRuZEYcgEI4p/bNyaPoFiC51I4T8MjZ8Q /3pNHkzlKmq3C5j8ShLlO2Aumbku+ZOBJ0MgJtyldBjR3+EAYzb6ldcYnvZHsuQd2dMX z5rbmTha1cvYV4q71xQ0bmPRRyeGSsI6SSUQoNq1/vkNmc3EGRAL26+peWck6T53D+NT AuFXpkHpZBlMLQOODLqSMJnf9PF0M6W/CZZksslxOJ1hdyxGtrqLCRGkgGiDb3445CL7 JKXRDafgI3RR8kk+uvYWmrK+bHyGqrtWxzvh7OoQkS8P6M0jz/W1llnhhqnSLtC+39Hu 07Hw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BdO5C0ha; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 7-20020a0562140dc700b0068c3ca90f97si4852797qvt.564.2024.03.01.15.16.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BdO5C0ha; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy0-00052d-TI; Fri, 01 Mar 2024 18:07: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 1rgBxm-0004uF-Mx for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06: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 1rgBxl-0004FT-5m for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:46 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dca160163dso26426515ad.3 for ; Fri, 01 Mar 2024 15:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334403; x=1709939203; 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=BdO5C0haalHKNv/F7gqAVDaA6VZeSDZh76aRZwYlqJadY1cZ6IVUsxXKZPhe+Nd+sy xdUDcDEdGv1JVqGuLjBlnxxzJtXQfa7NColVor0vVIFMxVXaADMl+2FMZWOu8C86yaJ0 zRXPzk6JOIbIlFtghb13U4lOp6/p47Uaw+VBCSEKrhVQGC3py5kroWDumkrs2SdRcV5E CUCXZda7v8zrQzZ6bGkOHwXmnNNAE5CXNSpMX4iXWm65Xot6o8BCx6s1yrXBXyUhozv1 bnsp59ELatjX3gHrsVqx2ThdYjPofgtqi/Tn0Vye4TJbmPqDBydM+Z2mv0HORuaa1Arq QtEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334403; x=1709939203; 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=ciVnJpwkwwvXQI1+Y5SF2FaNcDTDBPi0mcHrT9FBDjPITfBlN56Ztw8cssDr9Ftfff y5KNhFS6oUBYiqXsX6YHioCC7i3RUCkr+0l1tq7VICd6K2zD2cYFCt/TJ3NOltEXEqNE bp1ClOEtckWHoipRAW/YhyiHrHFQ26h16eDNTinfg69f90dBumCgEduYWaElKd3KNUG2 MtIg8XDjBJiLdZap/y57D/1lAiND0Gv34znFCQS1qIpgMyiaZi8SloSxFZRnBOwUnFZb ue6rvbZx6cbnxXAD0BuycUcOOGPX3CmyBdCMKzr0LANj5eMqxEaFjWClBRWDTSIbyyUY jKYw== X-Gm-Message-State: AOJu0YwDZ3W07SCTfYBf9v61SmD2aEByHQp6PSQ59Vvq4HQ6+sGICFem lftb9BPrwFPL33lOaFdQLHb8hZH/DD13bCoyeaMn2v46F99eQaAj2mfEEtgc66hCjj6ORmHEtYA E X-Received: by 2002:a17:903:2985:b0:1db:d586:b2d with SMTP id lm5-20020a170903298500b001dbd5860b2dmr3783082plb.18.1709334403273; Fri, 01 Mar 2024 15:06:43 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron Subject: [PATCH 16/60] accel/tcg: Set can_do_io at at start of lookup_tb_ptr helper Date: Fri, 1 Mar 2024 13:05:35 -1000 Message-Id: <20240301230619.661008-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777100 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603284wrn; Fri, 1 Mar 2024 15:15:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVi2O1fpjb29+kC7XnG0H9JqHg6YmBy3VYs4kbV5gcLkGyf7VwXSy67ropXCmPAZCIMtK4BrvWjLCKkjJjenMLb X-Google-Smtp-Source: AGHT+IGj7Gs6oXWWR+Zk8v/fdhidY3r+3Geq2/i2Ad7teq+9zG8nMo1cUX1rUV63eEBWNO3Rp7o1 X-Received: by 2002:a25:e807:0:b0:dcd:5f08:3666 with SMTP id k7-20020a25e807000000b00dcd5f083666mr3188729ybd.29.1709334907696; Fri, 01 Mar 2024 15:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334907; cv=none; d=google.com; s=arc-20160816; b=xsAwtOaQTbQnSAEDe75QHFcDwIR6yz6gQDwMcS7c5i5nF9HSpkWJgkZg2O0hldIvst AUtfJEaZHSp0z9t3epk0e4aFgQ2NIHS/zyIapV5kvPOsJJhuDC/JXWinT2MLIrltQ5nL Lr0cp58F0aH0GVYKH8kXZpqXtpaibhRanesrsJVAkfp98TKRrzytExbAYr3VJ7jBfrTD dg2taGzvNC3ccOdz9XQ/paG21wIH4PKDmQ1QlJsFyAWo9v6/0WfKrbIM5ZCxJsbbI4l4 HNV2XfZleoOKsKD3Z4OIUzc7wUTRYn7U59eA2wb64OnOyTbnUE1HIuy9ac/cafsFm44r c0zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GXv7UEq6yLB4cFzFbGG2vFz3ZhmdoWnqKW8J54cTadc=; fh=80eEN0COGyU45v+jVsiTl0bcKzjzjdq/x85AT0ofgoo=; b=BXOgD4urE9UKe/52b2W1q3eZ+uGHbcPQRuRHmMpGJr3cKb6UjyLlRA7ichJWizBGOn wmyegL84wp6gIpbgC8dKFtPJ3uWfdwb0/31CZ/LksTI4PaipQokOPDlNsAlamnuJvBYO GtdPa/dAWZU3oVGEhFNRnRDd9MIY6flAxUKAP1J2g0sDluYy95Upiy/B6fF1M81K6kcV j1DFkkVnzLRAURed9U3DPxhN+OWjlj8tFZxRzIXKDW+GBpbqSkXG6wiiedB8UQADMQXk lPrenTGEwkZNTGVBbU/RjYSfxBJ4aS+5svFJ2Dw/KjDF2YuqKI+v+2TMnfuY36RcH1hL BVDA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ATPboLxD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t2-20020a05622a148200b0042ec6e1bf7esi2950320qtx.652.2024.03.01.15.15.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ATPboLxD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByE-0005ca-B2; Fri, 01 Mar 2024 18:07:14 -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 1rgBxo-0004v6-6h for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:48 -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 1rgBxm-0004Fe-74 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:47 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1dbae7b8ff2so10146535ad.3 for ; Fri, 01 Mar 2024 15:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334405; x=1709939205; 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=ATPboLxDfsaTLNgvFXnLgCdE452zxfkw14RBbC8zb8rVbkYGYR+1UnkR7AeIrcLVm0 i7Ff7/Ae8bD0mCGaNCN8jWtdkWgPZpXdRsGd6/j1Px12dv3GkIvpmL2JZwY1tvdtwWES qFo6/7aCzrCIkAonWI3zvyO3rsGd02G19LBUrkGpOyzni0SqYgDlkrlseB7h8l51Qaj8 l8EA87o/U8lo+Vecw3ymJSQ40Ft/mlV/AQPPSAactowc4eLKN7gBTMg4ZMyMT55PgB7i anIg13ULUl8zwZh7wAUOgJfFFwpB4HwxeKR3bVO5G3D3EHu6NB2yvD9qRYAS86f6SeI7 +oyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334405; x=1709939205; 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=kffqTdkYOBN8IpIAPtyqOjZMaqeAs3IEfQGTOFLsciQhILbw3xxjubQz2j0vJkmdCj 01aqIRn1TJZizOubyVOxzi1ULpsMRYFvMykah9ySVI4vBAK/xMuFMiYo8a6k1cqj8I3J TLMpnUyXRDpXo/irR10G3ZaFH5sCOzUxMBshT4hVEaFU/LgLtBz5SiOskxnWCOSeSt3+ An0Iq5Pd12ZWQ8lHHs8RqxbWDrdIIIeFjVrQpnyVaO5dOzViDljL8zDa++wiHKjK1Lij 9IosIdY7c0Z50/ZAWHxrxrmER3Itgn/oeWCaF7u7ILxnzgsHD189jCE6JLxa0Gh1t29b VIrQ== X-Gm-Message-State: AOJu0YzIZReSn6SkuTsV8TpmY1g2635ifvUFYfQU7giUUwsQXBYbeR7T EOMMkAXtlKAjB7CmBp27KYRkYY+05hX0fneCpb0iBtxcTC4vjKiwpFCdCbCzIEpxplBblaSVI3R T X-Received: by 2002:a17:902:9f90:b0:1dc:c28c:fb92 with SMTP id g16-20020a1709029f9000b001dcc28cfb92mr2782861plq.33.1709334404665; Fri, 01 Mar 2024 15:06:44 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:44 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Jonathan Cameron , Peter Maydell Subject: [PATCH 17/60] tcg: Avoid double lock if page tables happen to be in mmio memory. Date: Fri, 1 Mar 2024 13:05:36 -1000 Message-Id: <20240301230619.661008-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777082 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601441wrn; Fri, 1 Mar 2024 15:08:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUm6kpftHANLPHYaOCqAPzuYjrbLZtk8C1BMeBfvmaqQoJG1+3ofThIxWKhrS173v7sQ4tkuUB4Vy9WjIwsfJzj X-Google-Smtp-Source: AGHT+IEnUJbb6HAS4ASp+YNVR3Xza/ax4mU2KdylXY9U8s/PBRSiOepMWACcyVdZiIQZaLesyieu X-Received: by 2002:a05:620a:13e8:b0:787:2acd:c37b with SMTP id h8-20020a05620a13e800b007872acdc37bmr2854160qkl.21.1709334537579; Fri, 01 Mar 2024 15:08:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334537; cv=none; d=google.com; s=arc-20160816; b=Vpk8iOow0OvCz2ROnogB5yIGkzeGPiqVuex4FpHIdXGUYwTkqMFZpdDvGxKDYlFOUs 230tMWEopuUuP/KH+SjjAmS2NpxnJIfjr8cw05CYydb3w4ixuK2iF02uNRUTz6RoW+DP jllmpcIQxKGcYq3LjW5idh21rAGsHntQX+oQeyboE+JCAFSW1wgbMfYN4rLfZFIadLoB 89UEeiez2nRb3/6KiVfbV8wfaqEykAMNr60uuIFGLtMFeN5yWtpHjwk0Y3erKlTA19Kh R7brbmL/QuWFHuXQU+rpDCJspT/hvFRyu7+Kwjjts9H04p7kS8JMlCFN1dRz7E+zZcU4 cffQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G2VXMZpzicQ4Dm28fmEM7ZpGthYgfI6UDANYII3bJPA=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=QdEpOSkHPgQiFdpBqQ1snxFuaId1bGCL5JkcDhk2A/YRsA+zrIadCOSYMiBEvwdRlC 89jintIS394pE6eU/znluCHqWvKtqLxH1D7+ET97gGzdvIv6FpweVMF78FxhQW0GPM0j GUieSb4B46ZFn3NUxqeswQZIRmySTuiY0MZ4UrsdxGhMw0XgXJKkGhXd5M/J3tp2kcvx EmbEXEO9WAalLVdVQWKNc8zUHwJ09SD5UK1g+RLn/MOh+B0pvwFl1aDN5z1R6SURuGcH 3d+SGecOjUi65EyaFsZsiAtoHhyuJSDtoBbRbRe65nJc74xDoZAR+izWGu6wCnGcqsMk NsBA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WC6R8Cy1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay42-20020a05620a17aa00b007879b1a3f98si5075617qkb.484.2024.03.01.15.08.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:08:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WC6R8Cy1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByL-0005k9-9w; Fri, 01 Mar 2024 18:07: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 1rgBxp-0004vN-Bu for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:51 -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 1rgBxn-0004G4-HR for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:48 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dc0d11d1b7so24577165ad.2 for ; Fri, 01 Mar 2024 15:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334406; x=1709939206; 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=WC6R8Cy1R42yVSuTO2NwOSCU4z2YOpjV4Ec8i8ymmWDq4Dbh5jljrSJlGYyuTqu90a ng5tSnU9hPLGXMyyP4Fbh+hn8Vf8W+tS997UQ23/sgS/6cr7JVFWay7r6uQJorUjNDid 3o7PlAMSYI9GD6i7Ov9Lh9CsytulkNEoNkHDJ/RJpQyHIeUP81TKiCwqQKrn1I2idd1n UUT6Cs496oa8wn0/55segL9Mj+akD9DDptJseOYpe0d6o2cUlo5nIQPMiZ+BTMmKBnGC 1NtLcCrOKNjc7leD79cbrbSJuTPedAOiyzXG8bGMZGdOF2GfoX7sEX9n6Ckz2BhN8c48 3Q/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334406; x=1709939206; 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=qKO9FIKqQ4hyxxJiKrUaJdCGIJckRIihzbYe9Whny87Ul28JR1JEHsZ0W7w7UoD4Ld NaDRmbS4wjlWPulMleT8OK4T/sICSESMP7/OPVxIDNkYYBv5zXjTqjhbaV4miWp1HD66 zuT2h8KxwH1NnYc/dQmvajN7RSXOBlArxx76EKdspvnN35LoV9AuaYQ1pU0xQyqmPE0L zYVnim0qXhWZ45H9LKW/tj4Q4agGXBISybrDcFPfZrdwDOR/N8qaOoOFa88xxJBEZHsC BlbioILkq/NnUiBGTJWiAvWuCk7eF4rg5GdKNnpO5czG1ZtBY0Ng6BrUiZndZh0BFOU1 VoOg== X-Gm-Message-State: AOJu0YzjzhiMR2gZqag4gjF9Riiyy1AtrKGTPYfDvheHLer/e1RA9NcL +zvS5iC7S0vSf/k+VvslIe6198+hX9KBZXsQ2GX9QEnvLugZZwIvZVR3Xr3R3j6hrdaZJKB2O+9 + X-Received: by 2002:a17:902:7790:b0:1d9:a4bb:29f2 with SMTP id o16-20020a170902779000b001d9a4bb29f2mr2518601pll.46.1709334406292; Fri, 01 Mar 2024 15:06:46 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 18/60] accel/tcg: Remove qemu_host_page_size from page_protect/page_unprotect Date: Fri, 1 Mar 2024 13:05:37 -1000 Message-Id: <20240301230619.661008-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777085 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601797wrn; Fri, 1 Mar 2024 15:10:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW76zauWKdAFVPT6pIFTlUvkCXWffZTg61zIQ/YkKCNkS5BH64pbr5zeouEoOG8eaSv51FTmcjO9gIcymMOwZFB X-Google-Smtp-Source: AGHT+IHk+CRz5At66ORAkTAE/9h7P/31YUByDpDqo4Fik62KZSbIcCzOlrJiLnK6+SXKro8BRR3c X-Received: by 2002:a0c:f9d1:0:b0:690:197d:e235 with SMTP id j17-20020a0cf9d1000000b00690197de235mr3415780qvo.37.1709334604808; Fri, 01 Mar 2024 15:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334604; cv=none; d=google.com; s=arc-20160816; b=OPLKeJ19Eux3+H56ddN8UJvH9++xjIzqhIQQI3hXIPMvOOrHzl+duSF9X/ZCQ4qB42 tmu0FUD0We462I3HYKB9eobGe6tTjQMJ5qTLp52mFuI+wcizrZN59uwGiavJBgmAqO9V I1XHZKbSHOPeGkFvpOCZL8tEuFLCIuQRiTi6P2bjxsSXDeRWUUg/Dv+w82FoeuCpyiaT Qe1QVcREo9P0uAqOq61u1IlNUJQcYnMRS1EHBtnUtqLScFZNDbkIUUzYY02zVDMKIpKN 9340SgbFBBXMfS37fhl0p+I784yvnEduQSXuk4tkRxAHXaU2nYX35MGNTeKza39Rs1fk Nglg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fLzyN00Ww9I7UVC17/1x1fEMCCUgdxWcszCn7cBZ/1g=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=X/4zT2DXkKad6drqAFNPtetJhjzX6rlA7TE9yGfXRbWIZKIxu6s4Isyum7E+tqd4r6 tnc9jp5FBwUbOCjav6ZQayynh3qjs+l5z7oDXoFeVUIzYWJIthMZYyfd0/8YFmIXE2ln 7cYnasvLeTe3qV5TYAF82KsvltX87tKTOtUj9kePsmzaJntcL6IyES7TbtxXWk3Fjqgo odCyjnT2g9zP9jsqZUr3ljXQnWb0KGDGDzzA6/nV4oqhkXrLnSI8+hwxnhVIrZDUF0qj HT2DjbyCFHXWkdz2gtBtBh/xUA+bplocuH0BEVy/8P3BHa+ECFqfP0GNDS/dJ7lfRkaZ rU0A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQFkxJp7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kd23-20020a056214401700b0068d0503a3a8si4584368qvb.439.2024.03.01.15.10.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:10:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQFkxJp7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy6-0005Gx-Nd; Fri, 01 Mar 2024 18:07: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 1rgBxq-0004vj-Mw for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:52 -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 1rgBxp-0004GG-57 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:50 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dcd6a3da83so20220675ad.3 for ; Fri, 01 Mar 2024 15:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334408; x=1709939208; 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=fLzyN00Ww9I7UVC17/1x1fEMCCUgdxWcszCn7cBZ/1g=; b=GQFkxJp7FdjlEqaKG6Y6wINtyrrAyPg3+oQfUicYG5PXGgZ+fHqCRDKwQv1bKti7V6 hzRjQd89+jYqKgqmpAXbnKP3JV1thn4U2CAfOhg78MFMcExaAYybTuIFmQ3cRxkrXvOd 5+bBtr6rwwNTvWSJk5Ivw4NmRGcOX09UHe0PvJh2s0XcrfAVthveB5/ykjXbTNMEC6eN IR07x3PIPIn2IsQXgRxYGMVoDpmB3VXS6H4Zmi920bQh3UgiX9//5J88umdUS50eyXmC LxeAZcSWy7fGWDThgEaK/3WFRgGm0XByeE7pMyuZh8XcqRv19TInTeIPNori5YAa3VZk juAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334408; x=1709939208; 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=fLzyN00Ww9I7UVC17/1x1fEMCCUgdxWcszCn7cBZ/1g=; b=w1Ma/jbKBc4RC2mE9YqN224ovCtf+wUa0i1oh/vcLy0Ia8UXQ6FBwBGPZpOcNU20vo 22aNkre6v9deBBmGsjttNkZqgyiFkffwTOO9QY3CrJsl+pvQ8WmtNzIo5vUslI6T5mBp f/m7pHoH5bpMSDqRkMSCrWwuJO0IeMN1oIkKKxNw9g8Nx+JN/KozOAQlOPukWMRWiKvU A4TDLRbQJjmqc6YL5CYZDo/fxMpLYqYOaZFFZVuoGiBhJxHF/iIWiLWepf8/4QWK7ReR WfF6QbHsNp1ZzKoMwAUUrtFhCVv/hxNBiJLF+6wrsPOqJ/1vGQgbW9irW8ET2YEp5SZd 5o7A== X-Gm-Message-State: AOJu0YxYJ7sUJQKehqiwyoUPQNGsX80M6xLDQTi2y0DRQC0is+1sgqSv XVDtYViuZgC9iFjj0geE81STnZKhyZ0Y7pM5RWzaS1hkxS3xJwHKc6Iiu7yfZEC4ExVXXzzKl8x L X-Received: by 2002:a17:902:dacc:b0:1dc:b2ee:c7 with SMTP id q12-20020a170902dacc00b001dcb2ee00c7mr4090566plx.14.1709334407974; Fri, 01 Mar 2024 15:06:47 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 19/60] linux-user: Adjust SVr4 NULL page mapping Date: Fri, 1 Mar 2024 13:05:38 -1000 Message-Id: <20240301230619.661008-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 38bfc9ac67..a51518f817 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 Fri Mar 1 23:05:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777077 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1600838wrn; Fri, 1 Mar 2024 15:07:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWOUj7CbvwUEvoU2OjIB/SgBvEe06wz9hO9X5Z8gV0s/aEtbm0hutWfdDaT56mrJZiVfRIXILMWx7CZDWc4vjoM X-Google-Smtp-Source: AGHT+IHqFHqPCeT2mnjg0oxwgC6clzk7BR7H5Dca+MuPuRfSBJw0HGb9cmbGrD8aJFcZOsUXd9If X-Received: by 2002:ad4:4ae9:0:b0:68f:6260:f71f with SMTP id cp9-20020ad44ae9000000b0068f6260f71fmr2749939qvb.49.1709334435181; Fri, 01 Mar 2024 15:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334435; cv=none; d=google.com; s=arc-20160816; b=ivvugQ9R0J4dNII1j67K4SsdfkSITT2Vrh/QVVwkRwUIhyrSYIK29pDwzo1P9gIpep jUuapUTZC/GPcG3nR4taxImeHUJz/UbjTfUFVdTZSWa3123Fkn/4Dl11BXAAWJGCjHtT XRRS8gGi2NWIxoZDdhPUqu7s0P+8rQHRmDo9UfEkIxQpJHKM4cspxuREoQW4z0lyQRw4 aYSIQiFeulr9pmAScyMEYaxrGwkOugr/ePSe98/oQ42PzUn2kzCPJ/GIU6BcgaaWvcPl 2JhN0fnKxcV4kIW4nEC2zMXQBu8a8naFn3JnlpZeXFGHqaH3gMBJwBVM8mdO0tp7Xwqj Sfsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vVQmqpHBlbE8lrIqY5LVT+yiAGVzo/DdsXrDpEqGU+A=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=cYnoTaK5ed2V/bmDNlGALAOEH6TGDe0YLPd+APmUDosWijflmnkG5L9C7UVBwvDxeJ Vq9V4kd9TMNBqpysO6YlhMgyBf/mhjuyDJkioc63EcNkfAxbePlx/y1O6PZlr2fVMlaV IZ+uPgTDKlBSYykqfCrkf5SXfWlREvUXRlhisAN7nUkJxVysXlh0oLT117z7tLte+dDO 6ZW/2SEKGR8UaLrYyyzgaAfa6MX6AD5OpLAWcX/fTHKRuoU9UbtQ80itm2LkQQ3sDsah VqYeQyUy9iJgY1jde2nYDcxnOFAzJ5fE03leoTr3txyKLZnJAawelQnj0z6czM652oVU PXug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QC8u9SM7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fq5-20020a056214258500b0068f57292ab9si4471466qvb.123.2024.03.01.15.07.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QC8u9SM7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBy9-0005Tr-Ql; Fri, 01 Mar 2024 18:07: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 1rgBxs-0004vx-IN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:52 -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 1rgBxq-0004GQ-W0 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:52 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc49afb495so26079125ad.2 for ; Fri, 01 Mar 2024 15:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334409; x=1709939209; 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=vVQmqpHBlbE8lrIqY5LVT+yiAGVzo/DdsXrDpEqGU+A=; b=QC8u9SM7bNDosgwI+clfqLFG6VJp3t5zHlkUDPyhLdXIWBxmgmfFx6HcfW9Y5uWObJ ZidDUeBK/AxZhJb94PL4A9q/8QBRT3x0uHlcujHQl17T42U3cs8NRCmH2ezj7+YMFpSb POJdWKmP1W5LatBayGVIxeQjbMGoQafcKy9Yvd2nDMpRnnddrf55RCWM6Zr/0e15I8rM bKlofvtMUWm2s2+dZUHwrW4I7ZmI+lmpqqbV/ctgJfy4Ov8ZVVesQOr8oefmaZTdXwq0 k2tcWh9qUNETx7ipgm5pp9musgOeL7wX4Xccc8jK9H3E7rlQpmPI2Hio6iSbeperP1Uc 5/zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334409; x=1709939209; 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=vVQmqpHBlbE8lrIqY5LVT+yiAGVzo/DdsXrDpEqGU+A=; b=cSTQ1ui4uprUD518uIkktQhgZfKmX+vEiac1ZjvVLQCogxSZl95K1CJ3QnSnNOOPjY 6DOPL7rz07N/9q2gdKd3eQ/DCdoCMz2fnJQzOcL2jwQ1ofblTSPn1ZBz7jKJMt48Dnnh jhxzih48euZhQ+OtmeeFbNIujX7Wu5wQgjgGqzFG8rIePisipzd7Mtde4UN+RNQNZ8GG QTkyaz7rfPgn6GqXRaZv2Xr8HYAsxxoA38vaQL6gAEn5jViZO36iP80Nll/Reg4L8xB5 TbJAunoSSCJfU1LLcovEhIeLmzvn+tVtuenFrOqbxYoVnOhNXYTfUhvfiVyLNe6cddUj b+lg== X-Gm-Message-State: AOJu0YwJxhJkKdcMBeXnkuOMU4Tmf/lV2oq+ifv+Ay6+jwFzHDBR5sAl JD1x849Pgr3xDX6zVcYeqhd3Cf6syT7iQofxNfCqD3PM4rPbljRUSlrmOeRHFA91dbDuJdvCell L X-Received: by 2002:a17:902:ee42:b0:1dc:b16c:63fd with SMTP id 2-20020a170902ee4200b001dcb16c63fdmr2947113plo.65.1709334409531; Fri, 01 Mar 2024 15:06:49 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:49 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 20/60] linux-user: Remove qemu_host_page_{size, mask} in probe_guest_base Date: Fri, 1 Mar 2024 13:05:39 -1000 Message-Id: <20240301230619.661008-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 a51518f817..561c11ff37 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 Fri Mar 1 23:05:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777092 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602766wrn; Fri, 1 Mar 2024 15:13:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWLRl+WCNEFWTFrAKuBmXwhL/hcA/ap96O5ZN1uIyteDqF1IpkNtTZDOeC1TFK1n1J+++I8MoB1s1P9WEMkYum/ X-Google-Smtp-Source: AGHT+IEcHBjm51QpOL5IMEYEr2/KA9M+L5l0uCI9g7kW9pxLPXWI2nIr61zyaYdjVJ0jqIdezNvl X-Received: by 2002:a05:6830:18fa:b0:6e4:8eb6:dcef with SMTP id d26-20020a05683018fa00b006e48eb6dcefmr3292436otf.24.1709334802597; Fri, 01 Mar 2024 15:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334802; cv=none; d=google.com; s=arc-20160816; b=nAGY0eFC01b6UMI4HdHVOQ8fSUMeLN0t+SyI8+gvBj/nsIJWpizTzL2g0yIPxcFvqt vY06jHoMF2bE0Q+PHBYmKKL+UCMfFGspaX1UgTLMtUTqNQBcltD0t+lq2e9Nl5iJuQ6E PBaHu8OrZIOiONyad3sQRszlaPLqLdS/aenCZPjcCAfawx0uOUfimHUmTaSDgsmRKUQX 5scBkFHoyRMlergejHjjEMj+/5MYHaZPw+Xe99p+/2EDk0/cC3CsqvCpD2/roGl6q5sd R5BXCo/hwVtxXl6n4xxJi1DAJf0gLeeiPOiCY9Tr4a/cOwXbPBmNAfoXCW3EuTXT7+AW 4i/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2CLMQSQQhuvxkYJMehybPxufQXltsEjsiCdZyGsMtXw=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=FhFDLnvgm1pQrvfBCAViXGI8j7umec47No8pSdsOlBd3S94A8ifuk37f5GgnbYCvYx DXs8dum/GD+qzxhehmvj0fMb2LdOUmgMjRNioX/dwi1/x5cR5k72cf4ChJqDesb/j7J0 ++0IWkEhuYpLnYVoCYPRirO/+fJi5mosVFg4UrH27pBGsQWPZ7qnKvyiy+hmsXtNtjDm iU0qFMAc5RvL7mGDQTbofCNTR8hQStCKmeW99CiQ4jK2atrRmH13nV51WM9a1k+hjivl kiC0MKSNf8wXwxP6EALqYu8gyOPcEq0wLbhY9FPdvEBHa8xQF/1riFl8qKpcil4AxqHW WGWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WUGWO6bO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l7-20020a05620a0c0700b00787a2d9be81si4469809qki.156.2024.03.01.15.13.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WUGWO6bO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByU-00067B-89; Fri, 01 Mar 2024 18:07: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 1rgBxv-0004xN-7A for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:56 -0500 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgBxs-0004Gn-GF for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:06:54 -0500 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5cedfc32250so2310666a12.0 for ; Fri, 01 Mar 2024 15:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334411; x=1709939211; 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=2CLMQSQQhuvxkYJMehybPxufQXltsEjsiCdZyGsMtXw=; b=WUGWO6bOH9q4Yr8A9dKtGy777iWoWKXjoGV/5add2D96Ey0DVLJNzWYHKH2lVUvyNK eCyRQ2SVEW1pz/E65v4a37NxiSBOETnF5Lxh4Uw2ACp393L7Sn6yzqO7bLgNnPyqbedX 0VO7DmeJ3kQ8516xOmb49HtKM8XTf9NLeOJ3ExROjD1eH1k1jKOgDIMEZP3Popif50f2 Lk7Q49LmRhMHGZVfDpesbuDk3PZGbQ4eAZufqBDJpUjePUfipSmVmC7BJ3nCm24aG2UW ceT0ECWJvOPug+MyZ5N7kpIRi6N+pbYxTDE3ZR/Cicu8zEknt2WWyu7sEjlFGUpNDtyU NYnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334411; x=1709939211; 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=2CLMQSQQhuvxkYJMehybPxufQXltsEjsiCdZyGsMtXw=; b=eLfwYXjO/qV780pS1mG026unQji5RidHRTMOoriO80ibey+RU9o/tBcu/gkR4tTgVR Q5JwASSARSk8Og9XdHOOI6GzWHZK5scuQDeLdk7NLMKKdavLPUuW5Weei/C9FyHyNVmN K9I3XApatFuxm1TzMXGvUTaEY7OsDTnv2UndAuKX+jqe5dxwB0WU9s5oi8fcXAj5C3On vCB6l/vxP5h2N3IlA4u01biFkhffnanyOqnsqrEZ6eA6GY1qd68p2murHEogGd7CoSkb urvpe5vyaaNdA3aTr6seFKCCTJrjFfa8g2hsR+bAynF8w0Ta64sICl9PLFcmpyENSJP3 4f6A== X-Gm-Message-State: AOJu0YzB7GMfBzYlPVDBAkc1D6ygqMuBxwsjua7ugB+4HimW1oOwwgGa 83O2RpzCIi1DvH+VIp0ei3CRh3ZkgptU/TTO6i+aB2IOmaVshmyviwNLdXv7P5HgWJzqMmSRwFn I X-Received: by 2002:a17:902:e741:b0:1dc:30f1:b8d3 with SMTP id p1-20020a170902e74100b001dc30f1b8d3mr3825027plf.18.1709334411111; Fri, 01 Mar 2024 15:06:51 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 21/60] linux-user: Remove qemu_host_page_size from create_elf_tables Date: Fri, 1 Mar 2024 13:05:40 -1000 Message-Id: <20240301230619.661008-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 561c11ff37..0f135f6b6d 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 Fri Mar 1 23:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777103 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603341wrn; Fri, 1 Mar 2024 15:15:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUci+2S7gZK6MTf9lAQNNIWXa8dC2ctJjGrTQNooVuOi6yXfYkk5j8PETyQw2pC8ZuVFji3VBSkQZUR2U+3ztEl X-Google-Smtp-Source: AGHT+IF62a7rpas+jZlGnjJcT64H873pQFzGyDJReZjse70DEbWrgfyj7KNPX2Q/CqYNnu/bgPDh X-Received: by 2002:a81:7b84:0:b0:609:856b:9fde with SMTP id w126-20020a817b84000000b00609856b9fdemr2574969ywc.33.1709334912891; Fri, 01 Mar 2024 15:15:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334912; cv=none; d=google.com; s=arc-20160816; b=RP6w4adTNqSldE8jaT9AU65kSV23bC2pPOJ6+DyvVQ2v1umP3m/15d2f/9Y0gSnPj5 ZnIhJDXxcI1MpulDQC4orqxGbariWPT738CzBy80m7kvtLgiRb4Wct+mGmbgh+k99qK3 0SxqAw4Ac6Rup+HBoRYSr+gngGX1+Qb2BTda8FxGUT8UVFoC+HZKH9bonuGaryBNsRJx szGJprglkrKCQ26DmeR78YcTVoJIIhpBLWRHG579niTZY64MZHQZY0mZY0kZ8hidgE5V 6GeBjFVHrZd8DjmGNcpvgzsPrPbuLPM9SkDyIqpKwB6IdJRemFsMx5BAPplt8zXqfH6f HcCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oqsehmdSBpDx4+BqjLPOYj++iC85Ag1++NqdrWinVEc=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=CqpYkW2V5H1NkVozLiDkPnp0JpqkBg3rFDUawsqPOslecUxvbYGBDQnXtTcyn9X2NG Zba4ept1VPnGekvwdqUwb1kMV3FahPs3Fv6IyNZq3FZgwr0s0rMqIGu2G1cCEJvkOBh8 312FjTu57q0hspGKsY8djHtobUmZG743yL0PA2NCxMOSHS3Ta9o91FCm1e/1UE/ViuCW GUvhYinvEK+b1uWmxjZNgXyY0Cn3gGZEN8LcFB12RhBeUkffTuBAIPNbj7lzHYUm8sGK SQh7ZJaFb8K86PLbi1eVYo3tq+S9KtHMoR2OTMl7GP5mhnFXSS/X5D1zsXo+yYv/Ohqh lNSg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kjN7bXhd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n21-20020ac85a15000000b0042e6b9d6b65si4830984qta.230.2024.03.01.15.15.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kjN7bXhd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByS-0005vo-47; Fri, 01 Mar 2024 18:07:28 -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 1rgBy1-00055O-9l for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:02 -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 1rgBxu-0004Gw-Sb for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:01 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1dbd32cff0bso25498775ad.0 for ; Fri, 01 Mar 2024 15:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334412; x=1709939212; 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=oqsehmdSBpDx4+BqjLPOYj++iC85Ag1++NqdrWinVEc=; b=kjN7bXhdBvCQHfZD1myvv61PZ5P3Mms30wp0M3oOLD7oeVrQ+AWo7Pek0FubCM25jN QIwydxdHK87RDDJBqsqmNB0rnNllj/PTdnoiGb35FOOL0nG5lPFGguh1QV2uFbGzxAQp SoHXH9QoQHtr7kL+1PJoZSGKX+do2FFWu/deeZ6CO/599b1elcWDLM1rgxvDRhJe1iPk e+q9mSJY/UnbYhcI2r8l9RzZ6olJ7RKLQovtgtg1H8c9qNlgcH/IkcpGZjGvsDlwuSHD eTSJdy9tLd2X4z1O7U9dec6zEuK+wNdcG/7EfYBhKtuFa7t/aByvtw7Gu+mfOw3PfPuF FYxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334412; x=1709939212; 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=oqsehmdSBpDx4+BqjLPOYj++iC85Ag1++NqdrWinVEc=; b=rytmZGn5ZiFnjlb7K1YVpJo8jgb0O8h3EfFiNIn2qvMhizyCrpJy3e61/GMfKTdj0i 7OtlinWEtXp7nEElgSRuuqe5PfDf3y54vB+oXA6roUM1RzyRD6dWLTcnkw0g82RLUQpN EilrTKmo4lT87vwIkARDdGKGP1HpMLCL7ENkdsVkMUqUYszJj4oF4oPFBfx5tCv8/Hon yOm8pfePLu+E2RUTKizfXwozO03drF2qxXOqQEip2LY+MlJgkodHUtsWttocTwR3+g7S BH1JHFh2ablxivMOJjiYc5LXL26HVSkq3m8Jx8IIlWVpY5HXypogahTpXqeqaQ/NeGPB gsBA== X-Gm-Message-State: AOJu0YyFY86z86py4wHQb5yBxAGliqWBuhufPXzhIjLkISt9SHmnGP2t ZGYR557X9x6TPN/3pfLYsKJft9NFCv88AzfzTNEfpY5YzhbYEVCqMxRGIiF1rmx7FRE4uTPhvCe 7 X-Received: by 2002:a17:902:6544:b0:1dc:7890:72d6 with SMTP id d4-20020a170902654400b001dc789072d6mr2765881pln.22.1709334412565; Fri, 01 Mar 2024 15:06:52 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 22/60] linux-user/hppa: Simplify init_guest_commpage Date: Fri, 1 Mar 2024 13:05:41 -1000 Message-Id: <20240301230619.661008-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 0f135f6b6d..53b61aac77 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 Fri Mar 1 23:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777101 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603297wrn; Fri, 1 Mar 2024 15:15:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWRjKsxowtFW+xideNZBKmG0J9hQZwRULlGKYCbyBh5V0MU0BNqfdFo/7VPFfQd0JhNr4eRSZU5n4+fTibluYav X-Google-Smtp-Source: AGHT+IFxPbFyqVj15EkX9utZHs0L2UmXsMVnOrnZNcr6RQG+RJ3o9XcxE+iSi0rM3lmidjSL2D/D X-Received: by 2002:a05:6808:1524:b0:3c1:ab06:7c5b with SMTP id u36-20020a056808152400b003c1ab067c5bmr3861768oiw.47.1709334909503; Fri, 01 Mar 2024 15:15:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334909; cv=none; d=google.com; s=arc-20160816; b=SoLRbbqWRplRyF08TSJ9/jDTa+naxm8KEB+dw8oh0xOzdZmiY4TRHCtxcnp+tAJB+v W/uMpYXe5Ueqjmj/5+Rwf3ZopEajHj8NjoGHnRzzho6aZ87pCqX+whr3TF8G62/zgASQ sYdB9sHZwJbSjW1uRHnO7+O22jENspdpv5hn22mVbfzKdI/WU+9g8jvtBPi+Is49z8jf xzRU5OAkmzpAdFHp0Ojq9wYkZ/Z7mW5lKGLDp7kTje3TN61hlzWBwEeAe28VaEz7yKd5 TlgQXoabcWBSiaFXgfvvmHy6yFB3GTJf1bcIk2OAXUfOjMngys6Pa3IdKoqgZbUECfvc vJpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nQmGR5cKuPmbKwlAdgNxFbsG53EvNXJRjqMWG5g8T5M=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=lx4IiImFETwLvhG+XL5KxWc75F5POmZpiETf9/wIsd3kuyPmnHes0qhmPqSJZnGYXP 5aDaWmo8FHBkyzYt5i/7H8DuJ4nO42rhzfOsPB5jDSwvmMROPDr5VroqpPniPR2jZmBX ajzMUHbPJ/EImge4ykhEheRoOp/A4f63g8VsJWmqNwaZL23frqrV3bY5okpJCQ1XJHql JUyRxOOUSyQ5hXJNzKfNBOfF6z/QMI8OXosNuGqAF96nYB/aN25ftn6DgnUvH4p9EXu6 A0p3aHvJMZnSnaN81tIaMdC0PJOZ4x3ZF84zKWvW0qZPspzQ9d5Y12TxNTKowyNOYZMD bYAg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jhZfhj8V; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fo9-20020ad45f09000000b0068f2dbe3675si4485605qvb.347.2024.03.01.15.15.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jhZfhj8V; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByS-0005ww-8Q; Fri, 01 Mar 2024 18:07:28 -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 1rgBy2-00056U-Ks for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:03 -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 1rgBxw-0004H3-JZ for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:02 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dcafff3c50so23001815ad.0 for ; Fri, 01 Mar 2024 15:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334414; x=1709939214; 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=nQmGR5cKuPmbKwlAdgNxFbsG53EvNXJRjqMWG5g8T5M=; b=jhZfhj8Vl7XpCYWRyQN+Vyj8HNJBO+FmjWM2rVYUXLFmVreSjxgGCe4J9Pg2l2BD0a 1JibQPHgl2BR64s4OcnwHXsu+A5AgiW6Us6e9ijibDXHYjGieq3jjnLtQ7bMJ8g96lNl 9w5zGdrt1XBRMjoj9qy0e2Ab7kQrlQ5yzl1XFYqsD3EgRBQv0lGokFM+Ao47JN1l0zya Wq66Xe3KPIR3a5CcIBjebtp7JeI7N/RNH+ET19MZb5UFErEIdnvxWipWOwDACOK6v3hq 1u5ovDrED7XRvu0IG9F3gf0cWpaa6QwWuMbK5A6rfaC88Xd5rs/h31Vh6XNt2zX7R8+d lZcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334414; x=1709939214; 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=nQmGR5cKuPmbKwlAdgNxFbsG53EvNXJRjqMWG5g8T5M=; b=Bw/qTezrTn9YiauzE3/nEV5jTlui1xV+O8FavgMBrC1mdyLBi6KSevjSS/i/c2bPKv u5pLoYIYH5iLolChQoCgMfvklOPC01muBiVuDBPB8IedYUCGo5SCf88buGCxP4UHswzn vwgg1iNvkNiEPanH12IYHG7gQ5w0f+WIWAoNErwJ8oSX5xj7sX0xa+SeIWvRF00Abozf 4GoJpMI8664vYMa5VqGJRMihQvyhueAeIkUqSdi1JTBB3YCIk5VjdIuvxs5JQHZR4qOz JIRP9lLBnX63IYzsOJtU8FCpFSEHvpWHm02/NEBQnd4hSTKNDqGl3eOkXqO4LSwS3VjH kQCA== X-Gm-Message-State: AOJu0Yywqa1eqUfVNPZbNLDUySexzZcTq2TsBTa8z35pC7gbOvKy46Uf h3GIENc36EYyp9LRO7iS7Lvixn6tTX4GPhyTF+eQED9+LydZdrvyy0eQuhocHf6W97zjMk7Stw1 a X-Received: by 2002:a17:903:98b:b0:1db:fa84:9be3 with SMTP id mb11-20020a170903098b00b001dbfa849be3mr3697635plb.8.1709334413896; Fri, 01 Mar 2024 15:06:53 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:53 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 23/60] linux-user/nios2: Remove qemu_host_page_size from init_guest_commpage Date: Fri, 1 Mar 2024 13:05:42 -1000 Message-Id: <20240301230619.661008-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 53b61aac77..479acb4e7b 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 Fri Mar 1 23:05:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777111 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603766wrn; Fri, 1 Mar 2024 15:16:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVjY+bht4Kjbd80MxZFvDsA5C6eaZdwOnBJLLWYXeF5lyuDVRXeMzZVE7Hl8GzB7xhSi4x3qMBCgSq/fqjp1IsR X-Google-Smtp-Source: AGHT+IE4NCP923F+sgaHsFPV2kgi9Bu7ntqjke8PYtYIaWQd77R6uVTWR9FYlUAWgnujpvj9XePf X-Received: by 2002:a0c:e2d2:0:b0:68f:a7ff:1106 with SMTP id t18-20020a0ce2d2000000b0068fa7ff1106mr4900969qvl.13.1709334997289; Fri, 01 Mar 2024 15:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334997; cv=none; d=google.com; s=arc-20160816; b=CYIha1FwOyoVN1vvc6l3IZT1B2IC5vvXdm4PSEaSCIOI+i3Eeq38LjU5XAu9HGXiBU eiWj4eWEqTryifw0maT0+UVVjXloFG+EIMjtoXTTvzqKe2FZkVB1OuAviI6Xt8zYUbeo n4Lhmu6TyRuz2bHbbQ/LRFY60j9TrBXD8TxzQr7XDt6mEzMJql9nwjYDkw16rLPCn1Co sTeVNmb9S9OMK0OHH+8lEbji3PB3yPFB7TLlyCfbVHbMoawnU4rBNNJTe4TL91UXdXDw BhATISeNCVyqhVLwwBVhxsLlNvtNwWC/+aSQsv7trOii0u8C2mFI7tbseuEeG39iJ5QJ P2pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8JJAXHXhKfB2vZUAaBWoHwbme18boXrxvRH2oQhMjWA=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=HpSlJT+xcVBae33W5srLDGbIkhcPKC1BYHsSj9lE87j6PKrnSVQa0UjDo5HBY9PQKW NNJZ3FT6EPxYb8YKCcIjRyljgqcsSERJy4jTeaHKVSRhaJtmm6aUbdtdBjU8N+T6MDLl QPTrpHZGel9LyBvR1M0aXmp3HSEs/GrBUyxVbUk8N4M7xDGuI6ab1dC0GNAmG2U6Z9kt jWD/KHSoWfijOedC83xgN1gMew9vrJT4XQyE3TGPpAtFxxdgkCfTR7MTv+ECHAglesJO SZUdBODI1LSujiZLEpobrT69VmMP/A6x0ysOiGzv83eAhb9FI/J8R8Eg0d+hrD+KMzuN ZayQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W8aLEF0F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a8-20020a0562140c2800b0068f5c3cb247si4631032qvd.191.2024.03.01.15.16.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:37 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W8aLEF0F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByB-0005YT-VH; Fri, 01 Mar 2024 18:07: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 1rgBy1-00053m-1f for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:02 -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 1rgBxw-0004HJ-Fe for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:00 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1dba177c596so18018285ad.0 for ; Fri, 01 Mar 2024 15:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334415; x=1709939215; 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=8JJAXHXhKfB2vZUAaBWoHwbme18boXrxvRH2oQhMjWA=; b=W8aLEF0FFZRIRnm8H5B7/zzT5KV3eIwplNo5gI5C93sRZ9f0Ty7DM/3rG0t1Us2Rnm s+nIH7DYq/SIFenxSJPVy/oYM53SBVdLCp6np8unhhVzavaCy1EYenw0jEpM6rmQHZE+ LIbUJPeywbk60NMg1kZnGCHAmlESa46vVzk8ipMH/XuQuRC6eh6x45nqc82rQ1arSKVV EQvobc6Y5tOY0vvMrHtu58LpXMKN70jqHVv8crxi2jelHHMjbmrmx7BdzpuBQMqCQloB OG7IiySpgX4CvqdM/LIeMDsixF0Z7XB3534RwaJrpWQd6ilY2iwLrnJsxa5j0gk5U6e+ NQBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334415; x=1709939215; 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=8JJAXHXhKfB2vZUAaBWoHwbme18boXrxvRH2oQhMjWA=; b=IYzAqjM8cX4CCUd7L6mRuv6yNrmHZqT8vNPDhThiF+cmGyklKY4yAjdDE3oUaRE6wt vJB5zdcarpoO0mqCIBRrlmHGG5mdLu+hIHMRSASi+06Aato3qjbc5ZSQCP5rDDXv7pB5 k9K+MHprJKDTAYs7MoVyHmWCFdfAtl4hbLW575iBcairUBeFDFeXhngfHaOS2/qEtuIH EkdbNmG+7vtTqRU2uA5GVE34enJfrsDwW/mfkp6zv8uYGv8y6BEvaRBGALbjCu6iV362 Zm+Jj3TiyldKW7EfEi4kaF0uRgyPuhfEcIstgg1idPVYLGmCD+Bf8aROTh6zM6uU/zGW YgqQ== X-Gm-Message-State: AOJu0YyDzrjv/jSUTxLV6BiZ8UmkfRKx3D19av2X1h0h6BNJ/mI5QhqU VvPUSzIEwuH3WAQ/xhdYxewgktn8/fdZL7n3t2kKWJM9cp/vxm0bvTX8TSf9vXPmzHPxrNhTHjG r X-Received: by 2002:a17:902:a384:b0:1dc:8b82:7f72 with SMTP id x4-20020a170902a38400b001dc8b827f72mr3257294pla.16.1709334415290; Fri, 01 Mar 2024 15:06:55 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 24/60] linux-user/arm: Remove qemu_host_page_size from init_guest_commpage Date: Fri, 1 Mar 2024 13:05:43 -1000 Message-Id: <20240301230619.661008-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 479acb4e7b..d2919a411d 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 Fri Mar 1 23:05:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777114 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603798wrn; Fri, 1 Mar 2024 15:16:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXOc2IiXt64DBxZAhEMju0yDNNNGuq3KxzjCtDsrrJQ/P+PYkKVtWvcJiRns67lRWG/qpbb0iE22tKPD9bSz7MJ X-Google-Smtp-Source: AGHT+IHMG55gvqwNTIJBCkGAu0BNEsSkDoqEZ5ubXHIAcYkfzb2JxdKOq9xlC3657NkjBvXm9vqy X-Received: by 2002:a05:620a:5792:b0:788:1a1c:dcb6 with SMTP id wk18-20020a05620a579200b007881a1cdcb6mr98088qkn.5.1709335003533; Fri, 01 Mar 2024 15:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335003; cv=none; d=google.com; s=arc-20160816; b=VaH/oGgsElL+0t9SA+P8ifnJvvN5N5amykVXA9Meouf1OY9AWXGZi606nE3JxrP+TO s+JyNaQKX4V5blLLDcZpE2oQvvBAtctxkXkPuYDYjjEE7MOB5c32htdOtlbV9CM8Ebpz SIZSszSrZYxojqI0XpCCEMWAZWz47Z6DU0mKdYn5LHS+xGEkA531U/PAOMLkrnwuZ/3m tqhvqFqY8+8vbigehpTqMozcT9VkOsmi2Il/DJSg0pJszDzR0gf62OoJGhyUBpe9qPnh LY8GWWrOiGX1CUo1hX5VDedCBQuP83xuQe0Rq9JTM78EnEZWPXeUZ7ZE47UpJsXvnZ4f Vcpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hEWtqWwf0Qk6NbmeI5cYzjl67d1WwUtptl/3wcrK9qU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=wEeOfTMz4/8vRrD+BN3vgqCg4fUfM2DxCIDSIO8XGPHW3NjAv1rdBkRH0NySRuBDcs nSGMcawG6sGWhQ3Gl4M+dF5euPb4Et8BXRKOLTf3Any9gEvfuArPJ86ZOlCW+R7Av8bm GcDo4YwrNGx/q/uvMGDuBYlmsA3RttXKpoi3dsrt0UyI5IIHC8GKC9mYZzawkdeMI7cy BD+NHXsSMKlFUUskPByJlFyE15wobtVAl+JlOIMhs/kj8N3/rMRuVP6XIsun+HuaFQBD a4kYjX4NOAi6ahjugdlWBeEnkBFenhiVkoTf5OT6PKETxvscxgpDGbtWuO0pQq5R3PeL x88g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G2NsW8sy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v18-20020a05620a441200b00787f53f52a1si5047698qkp.62.2024.03.01.15.16.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G2NsW8sy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByA-0005W0-8Q; Fri, 01 Mar 2024 18:07: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 1rgBy2-00056R-Jn for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:03 -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 1rgBxy-0004HO-Mq for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:02 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dc96f64c10so26797605ad.1 for ; Fri, 01 Mar 2024 15:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334416; x=1709939216; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hEWtqWwf0Qk6NbmeI5cYzjl67d1WwUtptl/3wcrK9qU=; b=G2NsW8syPlqq2PlNEJRWj3Xg/sq9HQ6MyonVP/KTG85/C0osB28OiMSNziEH7eSVua FvQ/Z1a7Fh5l9gijQBGrMSmVJWS23LnW5wZuel5K3Eavdq7jIbJG5jpo3G9FPYVlT3U2 mBSabzA4kxw+XC288fhA9zd1bRQ4vqAgu6mbshPVIoVZ5Lm4Y2wH1xGsViD8LZBoCt9q lSFWB48AzRsn85BNXAmKn+Eu1aKmHyOigaIQx6WgFy3mDjqMqhYjmcC+XaGz3I9hKWq/ XQyI8fut6C6/JKbKek+VqGlGRdet7lNuanEHbqvntXKeXqKcuLH9V57Ob2fgqy1uIS2y qb6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334416; x=1709939216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hEWtqWwf0Qk6NbmeI5cYzjl67d1WwUtptl/3wcrK9qU=; b=gl6MqpnIK4HeS5KqvIflZL5x9jjL3CtGn3tWXsBXZRw+ZDEinLgPBzRs9amoKE2f3a xGc723bCumlj/5SQ258eac3ph6R1WAeU1j7SO8EJ5NXIuNmRFqQY3X6YiWbrQdhk0zPM +Xw6LMN/v7aYfcV8P8rasjEYMbDpVwLfS6dwfmcAvcFYqjShMcs/IMk2ispiW1nTbbXb 1/9KtIe5aX5R0jvk3VMg1zDvnQ2ccJ/Z/mqqj4qMNWwzHpN1rd1R8G4tRBWwk5iEDFGJ FFQ2CMD81Bz4BhvXWxHUgRSLg0dU5oT3uvbSnDnqumNlKRjwORDYRUVdeaSix0nV2GhY 2NsQ== X-Gm-Message-State: AOJu0YyH4Ubsedi7FlEaNPkOSfGp0tQiYl14r55N5WcZU+PFGQ9LTcDO YSmz6heIN8IonSfFeSIsbaE4VJL7gs+a+VPSuU9U6Yv0EdLb80dCy23eOBElV1qfslS2eOZVcHq p X-Received: by 2002:a17:903:2449:b0:1dc:b320:9475 with SMTP id l9-20020a170903244900b001dcb3209475mr3632998pls.13.1709334416593; Fri, 01 Mar 2024 15:06:56 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 25/60] linux-user: Remove qemu_host_page_size from elf_core_dump Date: Fri, 1 Mar 2024 13:05:44 -1000 Message-Id: <20240301230619.661008-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Used only once in wmr_page_unprotect_regions. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d2919a411d..cc2013c7b4 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4292,7 +4292,7 @@ static int wmr_page_unprotect_regions(void *opaque, target_ulong start, target_ulong end, unsigned long flags) { if ((flags & (PAGE_WRITE | PAGE_WRITE_ORG)) == PAGE_WRITE_ORG) { - size_t step = MAX(TARGET_PAGE_SIZE, qemu_host_page_size); + size_t step = MAX(TARGET_PAGE_SIZE, qemu_real_host_page_size()); while (1) { page_unprotect(start, 0); From patchwork Fri Mar 1 23:05:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777094 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602776wrn; Fri, 1 Mar 2024 15:13:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV0e35ZPw5Ap1rQgZk0UlDU1lueWgNvuSZY1rRpMwDd3E+9OyhVBfUzJslf9ZdMh+YDqjdWlfMuUDgc5Z/JS2Mj X-Google-Smtp-Source: AGHT+IFPsL7ae0hYuamLr4xYDoHrMkgq7BSeDXgq7YkTaGqpM8Qw+38GLRNuRecGl5nE2PgAmqWY X-Received: by 2002:ac8:5cca:0:b0:42e:b8d9:4269 with SMTP id s10-20020ac85cca000000b0042eb8d94269mr3648573qta.52.1709334803901; Fri, 01 Mar 2024 15:13:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334803; cv=none; d=google.com; s=arc-20160816; b=V/r6IQR3fiqlsvGBJafENjTwqM7EvySY+RJ4tEssqxaBxkb72Ct+lBLFsAvPQSd5hE mBvM/WyIAKBiicAKi5h1rVC4LImx+VQGSeL36UdRhNyjCkAmOPQX6WjuXIQDa6eWLbb3 EieL+3v+/UvzqZH0MfgU34bC3xkr5fYxOHcAJA/JWjglhk9zU/nWR0mrWTxc8qApR7XF 24r9emFs2gKThU29Xk4PldDXTczfXUuAvfGIvu3hmYLQyLKlBrAMGvxrc5QiCRqWVrSc Llb6pi0vvcizHem22LsRE4UfNGb7+hB9N6Dnt+7OuqUoLZiZ1p3223GmWxTJzXyRTi3t GZwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7FHxKdfDsfaKmMG5O+L7r4x4DJpI3IWY2MOpcFadlFM=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=JFN5WLQtpvouOqPDoAk4oIQhbHOexw/Fk1yKloC6S31wM2WtDfc1NMeKxJc0+6UCeH TuUWgdNyJ5qt9SbAMlp+nc9U1u4+mVQTvc3B6idTiFvXxYfBBf8fsdTkxMN5CyPie3ap RUbP8KpnVvHkvKqpSYx4GEW2ElL8eR16ctqboWCntwlORfa+S1Lc066LsUoSbDKPYcXY +8Uwi65fmoAqvkKSM9XhCDZuz8tNmmS72yGfIviNhqGs1uukUGGv07WrOXK898B03knI kZG+5ypKHjFkUtElfT3po7BYPMxGbRbRdWnJX+O/FVEM0BxmOysSOa7q3RtfHOa7xUiQ 5M9w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u3uEyxyq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w17-20020ac87e91000000b0042ec7f2e385si339396qtj.732.2024.03.01.15.13.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u3uEyxyq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByC-0005Zw-JH; Fri, 01 Mar 2024 18:07: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 1rgBy3-00056g-0k for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:03 -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 1rgBxz-0004Ip-W5 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:02 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dca8b86ee7so25633625ad.2 for ; Fri, 01 Mar 2024 15:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334419; x=1709939219; 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=u3uEyxyqvTWtkqKogANqRJHyx/OVSJ7I6+MTp6qIkHY2vI/+oqfouq2f9gssprhdxP 3z9KZr2DKpvAa/9dSExJqWVi2mAfsvogg8RaMNq4EquVFo6C/hI0/emrka2JSJgFzbUw lmNam3kBclBVVqlsBWRlIA33YwKqKzesRppnxhj+rpFdBij7pxlzsIxcEts5gsF4FzU4 6NSrb9TBjg39Ag5RJ5rgMrfbddzaDqZN13bBP+JApKrgNQV+6CoS/H2Tud5VIfmShVRU J/32wyLyS28KEu5bVuGRagkjDaVivQC268a0CWDix4mWEaOPnvgPVhhRkuO3WNm82Dan h7zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334419; x=1709939219; 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=FSaVCbY4chbU81tpz+Xa2u/4O39g47lt0djiwevmYILMlsjlYnzX9nXxf0Lr0GR7rj i3lEU0GDZECQyZxVJ1mFJUnTmSoxHHHVTGY0yu6zZzrqBCj0HM+rcmSlgjp5oWLU7ti+ 4eP5rB2ewLW1vmBawCSTdDYU/E0mCcYJHqn986sgys2hzhtNZNY79m/MmH7tqVb3WlXi +0dEJMz5oTS5fEn4ajdtHwy0DnTA1wlMZPS3/y5xI80hRSNcq4sxxFdmy3uY+vJK2EmG Zx4Jx/UrhRo1xwOQtujUEBEpBRcTLX9jnUOkHBRmx/3MQRZA45CaVtAXiPehRvXuaMeu x3Fw== X-Gm-Message-State: AOJu0YzTzqXZSmdNRFi77YMH54OdPe8LqwEopUJdGo/OnDHL81x9YkWG qoTQn6PzhKD789f3KaC/jixnqBxgEv5e6ybkRdJ6Q4tHkQGqGZIx4HHwjvB+1d/OK5h7RNLVIPB p X-Received: by 2002:a17:903:110c:b0:1db:f15e:671c with SMTP id n12-20020a170903110c00b001dbf15e671cmr3899921plh.40.1709334418760; Fri, 01 Mar 2024 15:06:58 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 26/60] linux-user: Remove qemu_host_page_{size, mask} from mmap.c Date: Fri, 1 Mar 2024 13:05:45 -1000 Message-Id: <20240301230619.661008-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777093 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602767wrn; Fri, 1 Mar 2024 15:13:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWrmH/41oBt94AXyD5gKgm9z+d2ouPANpv0w2HXomT8u8NH7FlVY6GO+dahJwO1WkJykWC1zO4mzOJubIvh0t6m X-Google-Smtp-Source: AGHT+IG6MtQHGmPZ9DK2y0e6zINRJ7Rs3y9FbZ33jtdjQvRIcmBqtTtF1uDlYgkUQueJ2rIBvW9g X-Received: by 2002:a05:6358:e4a2:b0:17b:af7b:febb with SMTP id by34-20020a056358e4a200b0017baf7bfebbmr2983040rwb.1.1709334802598; Fri, 01 Mar 2024 15:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334802; cv=none; d=google.com; s=arc-20160816; b=fysj5mlC5eI0l0cLOy6L0Cz19qblPb/LNAMnjCI4R3cUC8C3qW1hZg5UqIvNqhP5Th 5qYBFL28gV5njDNJFVar8konfcpsQLl7bjYYlpP+osE+zwemlo/AdfokcP4VHzxAQ6c4 bJxXw/9vBC/NiyoY+LV6Zi/VIj7Ta/y+PRDyJZa5bVjXz2Dqc9omghQayfh5DXVtfI2P q8BT/uXMP+nTigRbcObafMHFCxa3D0HPSHf4/Q7E2utnz6wN1zLxET5UpPJ8O3rZG1pk g+XtzO5kihFiWmeTTJ+3OGFnp4s8HJv83GA2doykO++83v8LMvy9MQUtdzHQ6OPMQmhG 0dgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QqsG1I779d9YjbXcffYW5wImE5mXquA1bGyFgIG+R5A=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=mTW68MAVsCyquQ7jyIk4uTULwgPukMQWfTLDWsNZwcaOaeYrm3WOFu+/qqxcS0gB/i ycKvRCwh7DJeUBz6PIE7khnipVwGUka1/DLZbHWNeyJTEO9k23rw/1DHTMDKQlbtu8HU kfGC9SNP+Xb+BrjSdkGLflClb+KF70XUJqVj5nu0TMph+wkyc/x6UALjpJ6IV9dscWkt tz/CNCwBch06rxA1RkMhXrWsIVpRCT+3pzIe83RqrBW06jIngFEn0oid7qKyH+NI3tSM q+7gZfEbj4e0rxVjpc7g6e0QDBRsnJddU9BCCTvvreEUketCW39Se6xuw0oZJGfivZbg p/sA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ikvwTk5y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t1-20020a05621421a100b0068c6cb82b51si4647200qvc.192.2024.03.01.15.13.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ikvwTk5y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByT-00063y-9r; Fri, 01 Mar 2024 18:07: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 1rgBy4-000584-9a for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:04 -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 1rgBy2-0004J7-Cv for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:03 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dcafff3c50so23002275ad.0 for ; Fri, 01 Mar 2024 15:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334420; x=1709939220; 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=ikvwTk5y0KRuD4wIwHa1ztsD8rcdsNzvoErFQECKfbaIbr2ev/oFgMfIcK/KKJjDck QmiH/Ke085/ObIJPytUowPI6vZgGPTARI0wGY7jyBgFwZq234ttCq9RvFdc4bYdxHKDg Ne8UtE3DjIq0wrVPaE8FjyIWhm288yoiEAUDk8BRgwhNDx2BDqSJ4+MiWLRMAOpX6ndk o1ObqvwDRpnZmVk9gGYC2/DvY0p2Ca242qx6oWatVs5LSsrRJ2Drg2wkihuU9fDuS/0j ceB72HFqHUMH53zlRHZuHsmegK/S3UcvYhyVZSRM0d/khyM/rZHp2RUG6EXyVcsuGD0x 7T5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334420; x=1709939220; 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=oJZXM+IqFcEAtSdKLYMJbP+jUktGjFyZdXXuXPxTzbrvGbPvIe51pooN4IXWOMof1q MGXQywUhbwHJEC5dmkoMqba8RDQlCIJbqBjxFojrLUZb2IT77EcalRGDnwDYqZqR1Vmq 2iLoYvf6LIay0qvy4UxsgchBv0ZuQ+r2o7Q1MNU6j1C88T0eJiU38L7x/eip51YKNShE KVDh6sCyizfHSsNtrED8eTijzAKaCJKh5KKd3JgcEBBMAZ+yLfjWoouEanzUipvorBYT ms6H+WuX9sm2vNLvtBTpoHaEDa/GZmOmVefZch7qblhyA9buystc59guIN8o/ezDhtnF VqJw== X-Gm-Message-State: AOJu0Yz2H0Ze4qVm1oiUOkfEO1p4zYNxig/NzP03L/p2cm4lZs9Q03Vy uMIn+kIvaGUUWzLWkSqeUyY7EAAz9OxOm8ysrJ4C6K7A1zY0jXH2QNa2eWmFZAkgivudFwHUDdv c X-Received: by 2002:a17:902:6b02:b0:1db:7181:c5ba with SMTP id o2-20020a1709026b0200b001db7181c5bamr2773290plk.62.1709334420287; Fri, 01 Mar 2024 15:07:00 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:06: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: [PATCH 27/60] linux-user: Remove REAL_HOST_PAGE_ALIGN from mmap.c Date: Fri, 1 Mar 2024 13:05:46 -1000 Message-Id: <20240301230619.661008-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777098 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603270wrn; Fri, 1 Mar 2024 15:15:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWJkxkd71HCpIk5ruNnfZgtyZlS7paMQDPEIuSS2RUZJ3h7LqwkFXlD0Mh5OZdrjCF4BQhW7pD3UQM1Sx9D2M/9 X-Google-Smtp-Source: AGHT+IF1iDTbMEKhaqYrqbrbRE2fHCg0aU5SRfIywobsmcCxyc+Ue6YPNhR/P/2xd5ZAKBE0auiH X-Received: by 2002:ad4:4dc9:0:b0:690:44df:b33 with SMTP id cw9-20020ad44dc9000000b0069044df0b33mr3454160qvb.42.1709334905318; Fri, 01 Mar 2024 15:15:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334905; cv=none; d=google.com; s=arc-20160816; b=OlMsfyuYfyRYOqYEUbxS+Q9wLsLIvgydIc/9Zo/b3wWxm9Q2iD6ISO8BlVeyZCTNsY xY1VDtQg53HRFdpMDgU8Yz519D18D84garh1bs/Iz8TefpEWcIcVHLMvasVuiXfvdFAA 6NZjY/MFpp+8u4m10h4WXQogmNNFYpDUf7ZaKD6s5m1wxgmFM66JF3sdUE5lQ42O6rkn YGHpsriUJZoTmZf6yU98HNuuVputp5+D7RJBwrIl+6gamCEFmixTMXHDeskRR1EfI+SS 3tVGLYDnX3S6YuH07YKf0YO2myUEr1Ii4epvg8xe7J28Ni4ANesR/myZ3WWiGqDy5yPl 8Ujw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K5KQN5vcI0KBxXe8ErUYFGLj7ZU4KIuwkr3avJe+C4E=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=TkIExtZSu43ldY2W3Z0fCNf6o+7195I6hUVxGp90S/wORlgfRhruJhuOR04Umy2X2u z3AybQUeemqSNViXUCG9UJKK2mMiJRF2ILF6ncl0tSprHscmTTnDFa9/WYn4LPTvOSgd tIZakyGJJC1vHYDUabXmDQDjhcOhCvfjvrnS6PuL6DeOx6XEBUhTQ8/xL16ZZb7/alLj VrCf0K0A4DulNPHqnVoQ54l9H/En3qQE+cPjYVaoRevIoIYdXFzdo+DwbybyAUos2avV MDmiKXnFYzk6O+fI7tlt0TDBzRj8X+Y6yOl3kCz6SpDO5f91b/9El13AhI+3WkPEMDPY wL2w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MkwIIK/h"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 4-20020ad45b84000000b0068fc839406csi4631690qvp.378.2024.03.01.15.15.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MkwIIK/h"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByB-0005Xe-4n; Fri, 01 Mar 2024 18:07:11 -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 1rgBy5-0005GP-JN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:06 -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 1rgBy4-0004JU-2c for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:05 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dca8b86ee7so25633895ad.2 for ; Fri, 01 Mar 2024 15:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334422; x=1709939222; 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=MkwIIK/hIwNe3EivDUniCDfh/yvahtYbkCUjNJM3FMw71NbcP2T6BVUHaP6JjCG4r6 SqmCYQALDc+sSo4sd6v/oh8aJA19DGMHAOTKgd8GeHHa/mSvZnzcwDJ+CfVNTSwsTyjp Zq+BAn3aSgKsrRl7/gfyj6x71NPUa8BQgTXrcMwbJP1X5CPI4IPLdxVSgFDhzzcvGPCO ZpWwACjpU4y59LSDMorz0WSazWIyn3QgwVU5Pg6mHHZq4Vo2FltEz5cvBnDTnLlEQW9S u+/RldH1FcWYJINLaQ3Z7g5e5701udbk8xZ9q6OiJiadAslGQeFcYOf+Mp5tMzalzSMt 2G5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334422; x=1709939222; 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=ISMjJ7XhXSxwUAiKGmuE/HWE7Ok2fDYFQGfRHCMuxCTZ8vHx1/nHU9AIdJ80+9IfuW b3t9EdIZ43p0YYSOYK27q+LbkwEft+R3QBII4pXNYaVyR7r8eIPsAM7Tk9SBo+49uQYW A4SfLTMfEfrwBeVin6selK4mVM4IBM9VAYXyxm9yaLDwU5iRjbyowwbH9+6kSM39s2uP xQ2AO60w21XLlblLUQ2tA7zXdMPL5dCjb3GgHPY6+QrV8/EXIkFk/1AMXH8tbGw32W52 rJ1i8lmNh9i+q5vzy+M9D7lMc4hXtOCmMne1BzSDQ7et7WJsYppABoEunACFO2avRNto ga1g== X-Gm-Message-State: AOJu0YxDZ0/PxSylqD235vSpBbyn6rT/+afm9N1a8GkU4tw9/d86/KMl S6YcXJ4f9vGFmpLqNpERfo1mPGnifC5CPk7xPwfvbljEAjYrsCBYdE8iFhfeYlo50ycz/BVA1LX i X-Received: by 2002:a17:902:868f:b0:1dc:a82f:c6cb with SMTP id g15-20020a170902868f00b001dca82fc6cbmr2864710plo.16.1709334421828; Fri, 01 Mar 2024 15:07:01 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 28/60] linux-user: Remove HOST_PAGE_ALIGN from mmap.c Date: Fri, 1 Mar 2024 13:05:47 -1000 Message-Id: <20240301230619.661008-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777095 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602814wrn; Fri, 1 Mar 2024 15:13:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWN/PIBWIS4Uy84C+3AcFmMfzeFbWzBKw11XFkZb0uT+P6gJkSEQOBkttz+pzjJ+qJiOqBnQ//oXKe7+7xfTTtK X-Google-Smtp-Source: AGHT+IHaWEAan8ny2yvYjkfyj4dFh8dvqBPt161GF7lnC8BeBEMnd8wypra0+DRcrKyv3GOso1Lo X-Received: by 2002:a05:620a:811:b0:787:c664:a929 with SMTP id s17-20020a05620a081100b00787c664a929mr3035434qks.67.1709334812489; Fri, 01 Mar 2024 15:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334812; cv=none; d=google.com; s=arc-20160816; b=Z6++HHopH9wv13a+uPtjq0rL/PClgnJFDwSM4tWnLr3ApWMioYTVFPMxovcTfRglxM C0OyKAW+xpLGga7VPYDCYekHqcRXMA/1HNysTJ7HW9xqkMxxbbSkGDhaAMPvidPZaEht 60ifkLQPhGavUpvNoXmIlgnIExOR8TjpWEz+l80AoylgZLgQkyCcgheSBwxeRGKocTRC kYzZ70JQAXipUhrj17VgbwGkA7CqoA9Nryc1UumUnFIi3pXod1PXrWsgE9W5t42Mpzn6 1FUJcxpHFGsa8QahWdbXW95Mt2DA+dz1eei5M0r8vsdk+dvi4alD3qA4Pgi/BOVU8p40 bpBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lZemmFhkZWzz9AvC4hLSQ8D3Jh4HUes/r/6Q/zZwIww=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=lL8KMqKD2hBz49TqgQOSNsyAqjXS2U181JPQPb2eR5rrEI4gvhXGp/dGHD4g3J3TzN v7GRCkFf1fYJuA0veQNTvGRpysiItbdBzPfMf8N7G9VJT6rp3B9M9/n3Zr6O8UoVyY+M YXuQEeqUAJuN/TNAJWcdDZEdtjfqWmjQIqXXnjoK6v5JusVfRNVINChD48PGv9S8R/PT 3FCwbBAkmC5v7T2w1fkpJkMkgBfZQQtvSAe1ObVcMIf6UcdtJp8celkigGo6tTD07zWA f4GwNtTi4hqnyQAma+L9USVHnl5+1oGaAIcKYF1JWvvGSLkkajoWlN+ugfDx3ddaPJUd d+Aw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p88Hc/70"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u26-20020a05620a023a00b00787f5ac62a3si4394377qkm.249.2024.03.01.15.13.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p88Hc/70"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByS-00060R-Ll; Fri, 01 Mar 2024 18:07:28 -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 1rgBy6-0005GU-CL for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:06 -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 1rgBy4-0004Jl-OY for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:06 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1d911c2103aso10235095ad.0 for ; Fri, 01 Mar 2024 15:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334423; x=1709939223; 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=lZemmFhkZWzz9AvC4hLSQ8D3Jh4HUes/r/6Q/zZwIww=; b=p88Hc/70b6Xdgd//kfMffeuFe9PLReul6ROGQQe5282pkSnhb34RowJ1/8F+axa3or TmmQ5L/EFv+Kw2loXe+MtVjQjY6XLX1yz5qCo/DT8BsCKCLJpvulzn6T8JeVfDxYi0ly f3PaBNE4eFfevza9HElHHZWBoNWTwWdNTh8uUBylSOtQhATXOap1bcbL1upEvlYYBHuc 3A+6J4YYvcv9tOqQm+tvdUP0vR75DlykDI0n/XHcKM1d6YF4J10zLkOF36Qi5vIJZ7KI t/SD4O4diGSom8jXWZV2Vvq4jYqtcJ4z0fMm1ptjoUpbDLYwGLRqWtP/ZuV7Sb5dZ74B jpTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334423; x=1709939223; 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=lZemmFhkZWzz9AvC4hLSQ8D3Jh4HUes/r/6Q/zZwIww=; b=uDCCKzvJSy7WeGR15ABY6rbaNpS/aSZsuLyzIxYm9PfAye+OtJL68wbuN8Kd087oo0 l7ZKgUvbExWVR6m6HHHAr/T5+qjTTp/hv/uRBDC/fBkL130UpAw7EbPHwJAr+Ry3yzFp OywdtiyAdvace46ud6mK7supvdUCGuuM0zqYsBkq6WVYOhr//qqr1zo+g438tJpD7Lo6 CCSAey4xOsVFbcIWNmNO46I1ltXAS5Sf69i+Hf0IuQ2AURLCRoA1M8hmgI9apjphMs8I dTYV4MSw9hlHKZ3J2ljeg9jUH7TdEn+gz+nB86W63C6Qb896kcgY35bK9ipg145uLlz7 HBLQ== X-Gm-Message-State: AOJu0YyhDHO3XoAiH2RxToZ3fJaYsQ0Zj45RMJL1RZcEvRmClw7uUQVT W6a9qvTrzjuqRb0WOKO5xHsHk8DC1dxZkLtT8hX3d77zt83vBCFhHVD+tNgqZAMRmC4CTFb0ReG m X-Received: by 2002:a17:902:ce91:b0:1dc:15f5:fddf with SMTP id f17-20020a170902ce9100b001dc15f5fddfmr3905967plg.7.1709334423361; Fri, 01 Mar 2024 15:07:03 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:03 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 29/60] migration: Remove qemu_host_page_size Date: Fri, 1 Mar 2024 13:05:48 -1000 Message-Id: <20240301230619.661008-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 45a00b45ed..83fd780fc2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2934,7 +2934,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; @@ -2949,6 +2949,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); @@ -2957,8 +2963,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()) { @@ -3791,6 +3797,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); @@ -3808,9 +3815,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 Fri Mar 1 23:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777105 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603692wrn; Fri, 1 Mar 2024 15:16:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV8uctYeEi8AL68IGC3N5py/XJedAwAOAPLMfnbORXOuTHd6f0Q91KudAYiBP7gCo6xzR59Ll+0Ag4plUBbD7HW X-Google-Smtp-Source: AGHT+IELZ7NYq6gGQTYMjOROJGgs+UsSvz8mFX25q8G3vToQNNYwkdAkk5GE75AnYZXQiWspIqaG X-Received: by 2002:a05:620a:120f:b0:788:10e2:1290 with SMTP id u15-20020a05620a120f00b0078810e21290mr1878431qkj.39.1709334982315; Fri, 01 Mar 2024 15:16:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334982; cv=none; d=google.com; s=arc-20160816; b=ib8Awxif0I4m1I1pM4vcqgcuQlR7V6T7wN77Xl998qzk6rTxH62Vf6ru+/tfmqAY8z sOtrAjsiPh5aHOV3eHcCj4WztRCpRymCKFCQTwjlDwE5VV2B2EZcwW8Q2ttNqcLZuv0o zfiYMhkOEWiIsLq4NgxLpoXT0BLssStyUR2QvtevB5MD6HFMZHmMnqU7Iepthx313O6+ B9NFYj+QvPZROzZtI29xK0eeyHa+nDqpd6I7woFnbPlvn5e6ap7Z19518ihqtm/5TB2b 2m0LYkDCuzHPSgHeCImv9bVOfoZdMXs6lsOnUOO0WQBmVjaftNZ9yk0zaCIt5xwil6An /FIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9UuugcteI3wsnFXZ+gvu7oCS1Hb/WPFzjY9R5VsQ974=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=VESGrhk+D0xrGxeTODUvmdHUWa04bY/SOJRovRUW8XU8XHDZ3L6ns9bG3q2CVr3WMQ xOgoWCGnvo9BqEX+X9iVzVkQnyQbKKwjorBKgbDBxN976xCW/93SXWSGw9AmERPGlZ9t T/2zvKIkY1Rds9LfHrErcJy9GgTZbhfv7O1Wk+ASbBW6nJhf/IzoasnrF6vLzaEebWFh 1hOXCiOa4wVwUyzdNC5cYjiYAMf40+NWuNq9QKW5ZURFC9Gf5jLUtog8vf0O2BIFQLqS clvblKgzCh+9pff04pYo1MpVhUe0nO0by65jxuRBFBzyZFB40+MkduIGBILiko+bJa1l uUUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CiU8qvJb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id qr7-20020a05620a390700b0078802681feasi4205007qkn.5.2024.03.01.15.16.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CiU8qvJb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByE-0005cP-8d; Fri, 01 Mar 2024 18:07:14 -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 1rgBy7-0005M1-EZ for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:07 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgBy6-0004Jz-0Q for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:07 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so1882158a12.3 for ; Fri, 01 Mar 2024 15:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334425; x=1709939225; 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=CiU8qvJbFF+CGuGEAAlV5cAr1aXwRDF1pFKlM2HmJTsfaz8FULHY9n69PycVwjM2RE Hr2aYQXqr1cOdIseZMXnNYuwFY7Qb/MrPHnYYAdJAVX/u+PvxyMBq31bqoPvgDjj5W77 wEEMHFvrON9bGoSX3Uj1Sp+vzkWD38sDLvwVputAKmuX7MmZ0kIDe58LliZHeSwpVgSk c1vkAJqrcgELpghkAbYarxk17sUQzAw6eT8watYQIdlXnxNDVZ98zH9eQw/ZW967OvXh tXV70t5XobiGlVdoBDGGnKo5vhkJcKGxrQTsQjEq8oKQvJJ8tHnrx4JucvwAlRLoT6wl QYvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334425; x=1709939225; 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=ONWXxyYu0zo33oTkp91lYrP4CK+et+N7Ev+1zr5F3WSFx1Jh8saJmhDx7ZVVas7KVo CtMP3NwzmAmRKfGpk3smItAF5cnmuK1VroLd5MYhjOW0Hh+0Elrwpi4/z+PUQuCAiqSJ x/hwaVn0DW6kOk6hPVYKeowOxMOn1dYBinrkHVha+l+trtsFJpJ/x0AH5qlPP8//v6QA bjQnnMoU2LShcYc5dcyf1NZ/T1UYkOKCJgYUMpIsQMOnkJbh5+IRNkzH0Cn8GV8W67XY 0RKg+zzyuOHKe3G/IcjHi6YzyrvejFsucvfpVA7UVHXifvKsVg/voVhOZjpQHdO0FoJS cL5w== X-Gm-Message-State: AOJu0YwIketahH40SQiKW0xdmxUMl+lnLJjxRIWR1RYAJtqoXyMApX0K YL0nu3E4gjfMHemPYcKy0VK/Y23x14mVYOnoIbQYlBC/idgFwVXGW9V1kDd/GMMm/NUFwXRdLwI 9 X-Received: by 2002:a17:903:986:b0:1dc:b01e:f75d with SMTP id mb6-20020a170903098600b001dcb01ef75dmr3755834plb.10.1709334424775; Fri, 01 Mar 2024 15:07:04 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:04 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 30/60] hw/tpm: Remove HOST_PAGE_ALIGN from tpm_ppi_init Date: Fri, 1 Mar 2024 13:05:49 -1000 Message-Id: <20240301230619.661008-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777104 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603344wrn; Fri, 1 Mar 2024 15:15:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVpd8OoVWieyh2BInk6MqhRAvRIAWwbH3EiPeSm3mSXJiJKBsxPcrhhL2iQ4BbzPaWfV+p9V85I+MVW3rCQ7Qnh X-Google-Smtp-Source: AGHT+IHQ3A723hGXDoGQWvhKHTTX3BhddZ7oOE1LdMmSPyge35LWOSjBfSeAm30DeOxGJfAr/NI/ X-Received: by 2002:ac8:5a52:0:b0:42e:c28e:ccba with SMTP id o18-20020ac85a52000000b0042ec28eccbamr3411247qta.47.1709334913219; Fri, 01 Mar 2024 15:15:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334913; cv=none; d=google.com; s=arc-20160816; b=DqyIzFkAKhZlJ8rKiqpJEHqi1wSyzIRMLy9JZwX5JkKZ+B6fgSMgIaUJhup3z2L3Gk qnJWWV2gzpcXkJMglATBpDSRAKkrujXZ6uw/vd0SHAeiXCegSdbjg/2XFWLuCo863mQY kZ0hHKUKhnCxmgi2znKYRO6Kwq+keT6X6BzDj0iKzN61n13RRbVQWlEGX09OsiOlYa3y 4WUI/EKjaWbsVyGOlloaKlzYCxsKBG4JUkyYxCrUIZXjnUVNyfv9OwNpemanhBwfxYLA 09EhFSoUNSXJ7PaRgZbDJQB1Y1Y/1A11AzmN2LehLdzrQlyDo/VKo1dC2pJNUnG9xFBh 4S5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Utr6CY7GZcNfj8e7YUB3Ing2Y6m3UnMyzHBBd5nSQRo=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=C3owfoZiPE2A/kZCt1PzGR1Tal69XAQ7K93baM2oZef4WLsSVylCDkcI0G0Y1IE9ey ZDqCd6DQ3OaBCRQ8pSdGpK4Cn/dsRaGfwUB46uwcq+WwAmSlkuDMHY0CCqqmEWP+yKty v9rPmsldqCeW+UjY8kOn6j/Bhh3qxLsTAe7rnFo4kvtiGtlGGr0fhmNpiPJZ/bTynuYN lmNSKKg9arMXu3pU3t9MraNO4UYE168GeiQ7EFX/0DHnnWRU2ZsQwkym/0WaZLx/lkE8 8GxGlad2tmwaZy99MyH/VUJE0RYdlaUmeoG3hnAwqEzqA0axOLtObN8Q0MXAkdUoUGEc Zz0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lWQYCvev; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h7-20020ac846c7000000b0042e50c47cafsi4277268qto.47.2024.03.01.15.15.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lWQYCvev; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByU-00068P-GF; Fri, 01 Mar 2024 18:07: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 1rgByE-0005cz-E2 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:14 -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 1rgBy7-0004KT-K7 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:14 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc49b00bdbso27275035ad.3 for ; Fri, 01 Mar 2024 15:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334426; x=1709939226; 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=lWQYCvevQOkfEFQjadXLdX9jIO4yXAwVkrHtd1OaNxQV4Z68AtEUcxNqJWN+1i+d27 vx6swDWuUOdVuf9UapdTPzBEYdQ+M8AC3GLihcwpwibJeIdyhkcJZZwSAZ0KXHZKnkpf s3ji/LNRUaERcV4FYA5NZAJFIYlpA5BqGNicdcidzYiQrDAKLUwfrb62Ln3Vc5TMhVrQ RFV+saBk3r+TjInxQjit+s5WQWijoj6vB0PIbBEJyvV85oIc6/iHiH21mqVV8oQYEMSD 82izZh22Dx7yF00fYWhkbcZkm6r0kEhrcs3+aDdO9RXhndc0YyRDoaSuRZwkGkfRncHn STpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334426; x=1709939226; 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=ri6h0uEHqKDRXimBFxfHTBSkiFIsQ5+olcQTfS9uai6zmdca2OsxSGA5bdCMgRM9O7 I6Yxln+7eU/Us8XvpPHWCD/ozgNDfdm8yKtVuhv2m0MHmGjpO47gvLXN31kHhyVjQI2a gx7Gs9hT0aheVk1AOoApoVWCkZ5mMffd9+i2xrVwMD42Ha7CBfiAokBIgVJOAI+y8Kq4 npIZp8zbTVmWHSNrc6DwKeSeE0T0PD5slCBZitPmirEov4x1rt70ocCMGEyI02KyjlXb RAu6q60DrGphkpnOKeYNVUIsytDOt1yxGKKNrxErizjdIekHY/5pbUlIIiLI3S8KQkVG FiGw== X-Gm-Message-State: AOJu0Yz7SaCIOqdZF825GS14hZrlLoRxYgFqdp8FeiEtteCpVjIl4vCX fCTqnqhpDliaITbWlrqSp4La34A1UEf44WAKzPf6Z3fId+iVYbnQFs3VeWBm7gz2M7rn4FHNFS+ k X-Received: by 2002:a17:902:c952:b0:1dc:a84b:e93b with SMTP id i18-20020a170902c95200b001dca84be93bmr3746021pla.4.1709334426438; Fri, 01 Mar 2024 15:07:06 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 31/60] softmmu/physmem: Remove qemu_host_page_size Date: Fri, 1 Mar 2024 13:05:50 -1000 Message-Id: <20240301230619.661008-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777119 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604227wrn; Fri, 1 Mar 2024 15:18:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVo+6pYyvT/k6NYpIdXGP8VGqWHeELCkBFL6YdGhh6w2EvgTafi7mA/Cez8jO3unjfYAsBN23nT17/bYxXN/5Qj X-Google-Smtp-Source: AGHT+IEFxvotdoGgpyyaZmwu+BZbP5JdDbAeB1cpPhTEH2hwb0I7Ageg78K7bOIfA64P/2tSybua X-Received: by 2002:a05:6808:4092:b0:3c1:83fb:ee34 with SMTP id db18-20020a056808409200b003c183fbee34mr2952164oib.29.1709335080394; Fri, 01 Mar 2024 15:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335080; cv=none; d=google.com; s=arc-20160816; b=ujwyHVS6BoCRKHK88jztD9Uw6BIId9dNjmpCDlp6NahpVy1LXcGUMLT5LFRNhQcr0D INSJngd/eY+Xb6hTlst0J4d9GnkMlRNzW8yr6XB3byVEonoGSw0E8zUAm/E/Wbrj8vfO zGw7VhFAhEd3aBY/2ZnGucS9avzMY9gDnkdh2tB0fIgKgfc8rgEU9NCFJ6b0wRBhLOfW ULHmdp9790wLaJhkOFva4YY7OVfpH3vgG/TiDi0+M31QEYuZ1i433M3bW1zjvyNZyxT7 dAYjtPbWfypaZgu36Oyctya9lwGqksJdhbiBwlS0jMeqarD0iCFx5Oib/Z/3wENHZNRV 2zgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dE6xy9+D6Je1Etl+ajN+bavVnxpk9B7ygAyJhkrFQtk=; fh=v7v6q89OJlq+NxHejbJ/ziw7VE+fSww09twjGPM2dQM=; b=loQ1KKDidIMlIxQ+wMXSaVpkYK1sFm33li5JbvbEFcH1yXt1GFnfthhpXYJb3gL5w1 ZlyPttd7/Kkx1e+qpkp/Q/f9FiCI/obD2u++yUX1t/oT+yTR0gCcoUeEb18U1AAsDuY8 RCzEBZ4gi1xQ6f9h5RyWIfNFXdBs6LtOHB/eRsZ/RJB2c/07kU5y0h4iPkEmgXi+aDz3 +nIp0kvX8QFDgy3EtWmlCU514/04l9Fm3QN1iHOWGY5jel5Oj8TSVQmYlJ1ldrjVuVfc bEQhA+f2j5PNX0fRBrCUf2yqgM6mU9uG7q0PojfQU1YVdk/WhAm5NC5CdWv6yBYA4+qW kaKA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jKNIjDiA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a21-20020a05620a439500b007880480ec8bsi3493158qkp.730.2024.03.01.15.18.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:18:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jKNIjDiA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByP-0005pW-VJ; Fri, 01 Mar 2024 18:07:27 -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 1rgByD-0005bq-AB for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:13 -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 1rgByA-0004Kj-RM for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:13 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dc0d11d1b7so24579105ad.2 for ; Fri, 01 Mar 2024 15:07:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334428; x=1709939228; 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=jKNIjDiAMSZSHITBlHFWCnByQx0mVTEYaZV7mUdikYm9dIdsfGWkSzYdfHQrLopoS6 UGH7WtJtfV1Y7Zy2V/mTMjgk9huD8oA5a7UWOw+nNQpEQF+kRX1wyRz3Kse/Uh6uRIqV w2yJeXWzXT2jbkYmnHykXExGsNh0sesvEX+c21dxS0ExX+Jvlmk7Gk5QeoLWaoBdqD0Y JlXz2/cwWk4fmnvT6NSyOc9s5uH+O5GIEtIAAdTy+rCru7iCGETlrYkADrK3plJH0Odd XiAmGCkK0Edtkos7z3QuvwZzO/qrmthLUK1AeW6gxNf5Y6M70d2pbxZ27C26/XN1EAsl YnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334428; x=1709939228; 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=asWkaAyiWaNXRq2Uiml9EbbvCsYWeJO6aimXRAlAn1OyUs3zoxY7ieJ4BV7Hm71IB4 1V9Yn7c3CeK1sW912blEgJl7g88SUFO+wQTR3A8kIZif581YsDT0oFKKyQ1cQcG+TQkF MYccGK0PBUXg5a3zNYxy8Ffq9WDpzcCtU0ITh/PXai4zsrC/QpDGj6ciJHPDH0G8y8tp PsJhJQfLcQ2rtGG//n5nyn7s9UfmPrn7HfzMyrqs+8d+bJQHv7iQiuHnel3cISZUfU8e MliMNOIybZN8EV1ahhUYDfXhdR/Ej4wF6JWiefkJZeLASP+ndfoJ3VY/zrKE5v0/Gtzf iZxg== X-Gm-Message-State: AOJu0Yz7LGosYR3bICi+B8ounHi9XTNq17HbUJdGeEnXLuhps2Ds6apN zHmR+ZcyR5sNybyLVDVreXiJ1OtH9FdW8mgAabjBJGnLT5Alq1xrv0y9L3WWl4hWCcjVReudsc3 b X-Received: by 2002:a17:902:e5cb:b0:1dc:26a1:da26 with SMTP id u11-20020a170902e5cb00b001dc26a1da26mr3323977plf.30.1709334428012; Fri, 01 Mar 2024 15:07:08 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Pierrick Bouvier , Helge Deller Subject: [PATCH 32/60] softmmu/physmem: Remove HOST_PAGE_ALIGN Date: Fri, 1 Mar 2024 13:05:51 -1000 Message-Id: <20240301230619.661008-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777113 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603787wrn; Fri, 1 Mar 2024 15:16:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUvSixzCnzFs+fNE4UEOfm/8dMR4pokVWCUZ+IoqgTnFWed59b7nm7ZKyTsgQR0OGWmseahhQvaodRWuLQjlqWW X-Google-Smtp-Source: AGHT+IGDscf6vgHWOuD+Fu8L1NtvBj41thvNRM2XLsg9nmhtK0b3AqTRrfWCH7kL5BQdeBG+5Nta X-Received: by 2002:a05:6870:f6a2:b0:21f:236:a316 with SMTP id el34-20020a056870f6a200b0021f0236a316mr3571899oab.50.1709335000969; Fri, 01 Mar 2024 15:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335000; cv=none; d=google.com; s=arc-20160816; b=eaAjQvk8zU2Wu6lWhc5c2Pd7VUQqJbJ6FYjGEx451geaXyxh00TKUVqC9OSemVhOCl /RPptVEjf/28tMh9DQW71GRywXo63g6MZ3JZUtcsS9FfyuJymhC0wkQ+BJbL6sB+jK6f cM/sXM9CS6QYZcLoGeLQJdLKGF/wr9QadAJ9W/xInXkjzn2eCtLZMY0Hxt4UkmeE9RWA z0i1YkPYZOMCqCHnNBZFt+k6Sp3e0nIw2rjRpbhN4l5ySZlZCX7sEOkeI2PM6DtWRkqr AOs5gDlNn0AgSc2GDS+J97NNINjf+/5nu5deR+jOqzY0Caza5p8YIp1FQgP1Ol0kR89F 4g7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MJwI7j8qAfDRGrC+KBy3NdL40EXjR4qHacqKh2GDQwg=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=fbd4Ecfy8JMl3KBDsfREKw/XoTdmL6bXM1y/Mphtiy0PEUa3uY0LIl5Y43Io6IURco Z19I7IKZyUDCP+GeK1QPHEWEXkcKbBCGyEqvGA2cmFImZ5X1JDZilevoBpTNsVPW2lWy uJ3iGGudWjtOKp9vOmL/l+d24xtL69M1ZJNnYSOxNAUsfmt8WjIIYS4yyfkU3Ph/IqQP OZ1E8SHo8D4MQOiDn/c2VS04lbOsuINaPuxz6vFZDYLstL2nD8LOh4LHrDXyy/ewFqNn bhICD5GjtkJ7KiqBxt0hmsrzwGU2XhXmVc20da9HwvMbhf4cgIkmPNgqc8BE1YjJlK21 wcyQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ya5qaDan; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ee1-20020a05620a800100b0078802532997si4022392qkb.717.2024.03.01.15.16.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ya5qaDan; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByV-0006Aa-7m; Fri, 01 Mar 2024 18:07:31 -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 1rgByC-0005ZP-2L for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:12 -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 1rgByA-0004L5-Ke for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:11 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d944e8f367so20482885ad.0 for ; Fri, 01 Mar 2024 15:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334429; x=1709939229; 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=ya5qaDan/hzcEgpsytylYs8ciE4to310wI8aeCp65LDnbsv0vdSJBSA/e21XZxVRNO R4B35v6x/m6YlWfqSWVOgUORewCM2MLH9sMH0FbiZ+6khp41Cazbg9JlHYSIvC60qc1r y6ug2xy9U2Heoljesuo/VTGuhEqSzHFSgFgRaEoR+CrRNwz2HFZfb7dx4lqygCuWHmgh GlYPHOOZXpE/y2Igsk/nBEpfSDShWYB5R8NNCsmnRa8Lm/smgXlsgUnF+wJRapp/Cfsh uFZk1RhVDtSz0d1ghZVWPCFBeI3jlvbZvtbNXHcO9zWf/o/KrxRuaCmaiUDqEIauzfde bHSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334429; x=1709939229; 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=Yh+veHN60ciofydIRp/3veAjJdQ8htkN/4YiAiQbMlN3RYOxYfgQ/ItBV3/kWhR5gs diwDID5Tj442p2yzQ2cXNCFMROmf8QL5DQM2SAapQ3TZeyV7UaOWCMVNH/qU/49U1Zdf lQGJQOCPrS3PYBJVuDrchG43TxHzthK3+PGs/wTq4xz0rEIxtvDOhJ8dSvMdSyPojeS7 iQ3JsKLvcPGlAfn92w353BEZATnWEd/yKW/i9XWp1vStLPpCfw0R2VDaLreoT5AjM6QQ lXjW6EmfFzYzfrB76qx4MvC36d+MQezFlqtz1JrvjoXM2n8g/VRqEu2cNYvDcXz+2qMS g0dQ== X-Gm-Message-State: AOJu0Yyn7a/g+Nx820Le60qBBKDDoXfKQaKoPlcP6P2jEsaBf4PAbIAS tejksMiJHwlOLJT6HYazHP6u4VPwdEULQrdDutDcZNyNrY2DNRSfjkijY9Ca8MqLUx4PRHEnXUW A X-Received: by 2002:a17:902:9a07:b0:1dc:7890:cb27 with SMTP id v7-20020a1709029a0700b001dc7890cb27mr3006831plp.48.1709334429464; Fri, 01 Mar 2024 15:07:09 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 33/60] linux-user: Remove qemu_host_page_size from main Date: Fri, 1 Mar 2024 13:05:52 -1000 Message-Id: <20240301230619.661008-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777079 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601253wrn; Fri, 1 Mar 2024 15:08:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUTBmCAqS5OogAz6OBr1BFkPbAEfoDceZedUL71fd/Gu7LpORLoyS1XRDKX7+vJtYy4Vun8tiltWOpNuJX4baOz X-Google-Smtp-Source: AGHT+IHjGA2JPsZyuMeYzehxVHsjJcJppqIF+G48VStHTIMkajq+571xSONglgDOEtjhGJmD+D54 X-Received: by 2002:a05:6870:1596:b0:21e:d8e6:cd95 with SMTP id j22-20020a056870159600b0021ed8e6cd95mr3401647oab.37.1709334507892; Fri, 01 Mar 2024 15:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334507; cv=none; d=google.com; s=arc-20160816; b=yhWXWQz6giy6RoU/tyiZJ5Ba9t1q0B5awWuzKarWsYqhnmump/0zG+FMQo5FUrVcKw R2XgO5skDikfyAbEWEKQGXzayJfyUsqy4Xzb/hAcET0o2HkiMXUytfgeuSBV0KDbZla7 NVdnJW+pkG1bzvSmPj9yBEb6mPvycNStwHjHsAKhsbYr3Qo3+W37m/gzR1NDUqm64pgC N8hcDd8jyjXVB2tJBrnVs5uAOmpEREw++WvV5wmQx02l92TAIOP3Htm0XK5MPvjU/xtV ta4qp7Q8nispOuYf+zzd1e2+UfswzF7SmXVDZgJdtFDFPzrIQLavhhXRmhdUDYVwU46O NG5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qzBaOBmrgtVcZmBT0VJjVQXI2NhHPFgQ+IyeqJADkZ4=; fh=3DhLlFzAZ2wDtINCbhCKz6cI2CK+co2YCXCK+aMgx2I=; b=A8h3LzNKqa35NVmWRZI158O6Ka9pF0JjFy56HXkpKdGTe2lcG2/C6yYu3mRSy1DfPj n6qe4Q26Ede0qVMh02mzioCqA06ZGrOJi6sRJ2q2gv6hXjogpwEBbDhEonmaj3pgLW6P ySpkrc/4XNiYWR6kJKSHMheI447iszlXtrA/vFo8GRU8cXOR1GvXIgyleXiBjEzS9GAG Xu6yEWxEbRtmUGPl1hIy6puf7/gqzyxzthrhYFNiMF1uKqg3Bs5e9JR168Dy+6nY39z+ mC/govCl3SDMiZsHGYO5cjKBGBKXnkbw3K6U93O2jb/6+s8J8DJnk7IvcpMthGA5n5Me KD9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nqRwtprs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t15-20020a05620a034f00b00787af54b088si4556260qkm.238.2024.03.01.15.08.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:08:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nqRwtprs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgBz9-00072i-0m; Fri, 01 Mar 2024 18:08: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 1rgByF-0005en-5X for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:15 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgByC-0004Lu-Ei for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:14 -0500 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e46dcd8feaso1658993b3a.2 for ; Fri, 01 Mar 2024 15:07:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334431; x=1709939231; 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=nqRwtprsU6ucKX1BY/ZiFCW4V2tp2Rhm808w3vuMmFPX6yqAxWV3hpW6jAr60HT98q kIkDVLC9uByNUBigi1ayAU3mshD7pMnqEHrdmzyd5r87cIpnsW2DuT+1wMZuQSJvFkwD vy1uxRXiiLGgveKfZAW5/8PGwFdO8xc7BJX4OEzXBcq9E5+PqsYzL1AmC7jNIhqZYtpo kfVpV7yfVda7yr+YuEFwkGH0bQCLnHOZPQnuSdahkU7zTzEXUwejVlU2ClmMiSBfQrPC d+PHHrOyshDayLe+1UTL4BMUlD9F5FTJHgB5ZPIvEFZDrMiIpCm1gVm/MEXdAHgiHvrE 6zfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334431; x=1709939231; 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=WNA1YqM7UzeUtkR8z8T0K5ay8+F6jMFzjz02pgQiAMqzRSlydidp1QAnzcAJ1UgV6r fJf8CpZe1jclXg5HwtKB4HmGcMlZEZC8+p6FxiuWCd7xbidSFVtgEq/iV/18hW8CqYoL jcW2fplhXDwwLwDzWpFO8z8JVNrhPW48DeU3VdUUbaEhPORl6RBO1WcmItkTnfXorrfA 3z6K3LjU2gwhlsqTe7uDyMrkCveTyJ1Jb5ZQgps1iE2f8SXLA0QLoVg9BMidUSVrCeNi +3OnxkT+3n8Nz4Ao3km66wzcdxiGDrwRrnhOCljceUSaxDWGn8gf9e0DeQG+lQwOlbfQ OvqA== X-Gm-Message-State: AOJu0YyzkYpt6JisLKXaWXySYGMlKWTqBmYzVYfQlaXscipHXiTc91Cq EOsNFftII4ZfALOeHapBtYyNvM4pg8PigWt1DNKgBKlscRYKhFT4NrX9Pn+LAnwwrkAikIw1hzr F X-Received: by 2002:a17:902:a3ce:b0:1dc:6775:a350 with SMTP id q14-20020a170902a3ce00b001dc6775a350mr2496498plb.58.1709334431012; Fri, 01 Mar 2024 15:07:11 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:10 -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: [PATCH 34/60] linux-user: Split out target_mmap__locked Date: Fri, 1 Mar 2024 13:05:53 -1000 Message-Id: <20240301230619.661008-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777091 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602761wrn; Fri, 1 Mar 2024 15:13:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU/GKRGZOaG+Na7uaUt9XH/xXx0oGf0SMJOxFpy6df9v4bsPhfmj21CA9UeVp23yTZQc6TPQxcY5QLwWnHMlK/j X-Google-Smtp-Source: AGHT+IE+aW31zPor2NagfOPKp/B1Kp9Vd1Syo3Nu7hKmoP6/3mNSnwonwV6h7x8278V54IzXzX+0 X-Received: by 2002:a67:e2ca:0:b0:472:4fd5:1dc1 with SMTP id i10-20020a67e2ca000000b004724fd51dc1mr3008366vsm.14.1709334802011; Fri, 01 Mar 2024 15:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334801; cv=none; d=google.com; s=arc-20160816; b=P6xECIYpUD+q6luzX8cCqiD7DY0LDDvGrDpQB1cY8ucRfxOFak88fjT5en4BneUE6K A98LoafNPFCzTrQBJ+ENaPBoX+q+l2I/0WgdmGCDQ2XTC3fi1wgcyeduf9L1+/Ic8Q36 3OE6S+LN79mZG/Kbe9fJaowBG11rlYAh/R16wa8pGV2MuhnES1n7vYplz6MXDcREH0BV dxTC99xHVQAae5dbpWViV0d1qwMDbIh/MV2WeCHBjFi3m61mDZI+3MZi3FY/oEGK+HFn Dp1oSC8uO91jeDcrvXuak8RrZQIub4iz8BNAz9vBpGMXiKF+TsG+wruSaRDO7q6I0yQd OjqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=48MAJNKY8itF/Uvxdy9leMjwL6Lq94BoHatvMOlA6tE=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=rEzEfArH8x7PuqtSoiwScyXajYJyPTx+Rju+PjhSfUun3CO2PVNTGQ6BpUFcHrkET+ LfxU0FZLlZBEvdsuGiaRtVKbqcs4I9tzHJRM/fDFfat9MvxfChCVI7kSLXIrw++qu+Hj dLDtoVfUxIoRCryUJMimY2EGQZq0AaGY2kGLB6nvRJZQVEDY4coL2Lw/t7lmbLD008wp j96sY2AeX/GGFh1WZXJe2XEAJUDEUwjSBoHYoP94VCDJBptNoMnVcoqD41D6+sT4C0m+ BiWPlzDJl2ro+PPMFsceElJJMrB0cQWCx5laj8nuNWSojEMC6uzxf58ZVaGyiGuAIp0n SC1w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iuf2pmTX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k9-20020a05622a03c900b0042e724f7f88si4814394qtx.274.2024.03.01.15.13.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:21 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iuf2pmTX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByX-0006La-5x; Fri, 01 Mar 2024 18:07: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 1rgByF-0005fJ-LY for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:16 -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 1rgByD-0004N1-RH for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:15 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1dc0e5b223eso26021765ad.1 for ; Fri, 01 Mar 2024 15:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334432; x=1709939232; 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=Iuf2pmTXfNbaEDQ3d60gi7CqM53oX//yskS3tzvQm3W0qH6fIq2I4Dd8Gi5tF9lX5Z bh6ThCvDAGDzKRubzYvhPBid8+dwka9JDJPKvNDD5Fv677F65fvzdcpfx/W+COepGV4r cNjl9URJ2QJMikTScA4Phmq4B4ZnZk7PGkZSlybrZh5/yvtsPk7HdW857x8AgKnugbx6 Cm/ahIhfkfy73qIk/JLYHl9AW5cSXS0JA4r0Sb5srI0JL30bp417236AJlZdiVeWA/5+ 0JtV7u0a30aWdes+o6HkirZoXk93+1//EjR7dOskJ+hTxneygtY+/TVki8kC65tSYg1Q j9iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334432; x=1709939232; 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=fvFgiGO3etv6ztIJ67nReTVYsIoZO93uP/ZnzEkiA1s9zgSS22PQncTncv9GEWlE8k hNDgB5FY19sLwPesmw1B6BxnnJ2QU0uR5FlLO1dbGfnak7A1ZH56RJR7o3fj2s50IQj5 hJvJF+/3NI7AbSB+Vv1PJoDvjWjh8voAIaQKG0IgJ5bt9goMhyk6192WoGeip7Eqlni6 CJUxwhoNmdbLTFzRmtbNZRIpkg7OcicVLKPu92IoTj4yM6K3jatZBfWhGn934ok0pQsd 4BHICILQX9pAE3Xsi7iAAm2+gzaNE3NWw7jSc2V273fGdM69FzfgrUsFsVQhfT1Zxle3 kQtA== X-Gm-Message-State: AOJu0YzXu1e1cqwJp1/IlJ0vkYA9HxVq5lBzTK1Hn66QvqVWqUG/Tdmh OCd/Ui2wEIJiPBODv1QtZfpW8823BLkKysCaX/yjFAH1GsLYRWn493H1X31U1xRFLJub08MbVgS h X-Received: by 2002:a17:902:c20c:b0:1db:f389:2deb with SMTP id 12-20020a170902c20c00b001dbf3892debmr2647282pll.17.1709334432587; Fri, 01 Mar 2024 15:07:12 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:12 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 35/60] linux-user: Move some mmap checks outside the lock Date: Fri, 1 Mar 2024 13:05:54 -1000 Message-Id: <20240301230619.661008-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777121 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604468wrn; Fri, 1 Mar 2024 15:18:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWi/FXlA1Sok3+jMnLv4DkOb2cNeLoRilX42hWoBrwXKh9dCAVqGzEwNEMbuS05Bv579qAoM+XsqRgIvzq9aaYM X-Google-Smtp-Source: AGHT+IEfFqW4z3nbvLPp2r1fc7OWjdZJ/1cD1cHlbO3Rfe4syN/5D6osau99jRtu9QT0Mj4DkVSa X-Received: by 2002:a05:6808:3006:b0:3c1:bbe0:4eb with SMTP id ay6-20020a056808300600b003c1bbe004ebmr3276041oib.21.1709335137592; Fri, 01 Mar 2024 15:18:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335137; cv=none; d=google.com; s=arc-20160816; b=A8BSY9fZJMnwBDl8kOkhy9Tp63K7bOwJ4bg6Mi6BHY3P3YTG/wDHqBK8rT3nAaJxmt qxkpmded0+ix3BB3HvEtBo3pdMkpIYLcZ7SXK69Rm6b8KRKwdiKcSXcHIBO16hnxieVF DeNEcG9QEeFi+7RedEQBz19iBDXFIQb/ObPEMtbd8D9qP1m5BaslZ544gfL3zz+0ANwY iczT1g82ZJNn6RVeI2uQ1xgqsyogBoXO5d8/zBDAw/yYfPUYYzyGRZK4vrmpq+Crcs/Y zLTVKJ9mVZ/yrzyZH9SEtOwqO7UqCrAeXWFWI/AN7oJ7ngcYY4T5p426KKn7U0HSUTgt b9uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aJy5WaQ99ApNqzP+t8EteVWeLJYZZHFF49xziucGjOo=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=W1JktSawEBMc4oacv2G+NCfnYMAer5TIXBm6vAsTK1sGOurb4ZObvy4UWQqRFkT7AU EEzdhvV+Q//nCnPZVsRe2fv/z2it76ec1TZNDar5SKkSRJzSz1tf02bxXtL9TOJfp9m5 nMecPCDSooMAtUN56p4QE9DrVPwkJYiS0u5BU+L+Ehn8kA5UnyYrEZHcbGQoyMp/4u8U xRyr0nrlis8lMKkAlm/yD6j9QdXfio5ZzPIQ68q1URS95Cwvs9C4yIMZBQLHh+uRLpAV gsT/0ZjnWbT3Bzl7MQmxudkOrswaNtO8d0eVmS4XbQQHR6KbZLzMVmobhhprjUJ9hIx5 vewQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lyCLax+g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p10-20020ad45f4a000000b006901a3b7869si4483830qvg.297.2024.03.01.15.18.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:18:57 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lyCLax+g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByV-0006Ae-88; Fri, 01 Mar 2024 18:07:31 -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 1rgByH-0005j0-Tc for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:18 -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 1rgByF-0004OF-AN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:16 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc5d0162bcso25439775ad.0 for ; Fri, 01 Mar 2024 15:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334434; x=1709939234; 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=lyCLax+gDlGPVfi3jiwndKhyvqSEaQNDyT6MpvMaf6R5A9EQ79GY1vWRXmz7tA9Bzv itvC19UUjduovvpof7FfQX0gzJLIlwauZVJSDmR5vvlt3ya2j4d5tQL4zls4xID6gSsQ d3kDeuJW8LEHNsODtnbg6XRGmkY/Q8AQPWLVnG5q5bVCtqBucNpUCsNnC8dnWQ4OrUZi ynBiWUXPOjOyoqCBpS5uN+Jg0OOIt2J08FIEiucR7G+EhpiErPmAYq2pb40uUv2BVAr1 A6edzkZm0zJNImJnTLos9BXn7EwQxC5QbGvLhfPcR56RNq2e2zdKibJmLHT806qLoQqD 6MMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334434; x=1709939234; 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=dPiAxLkXfZiF1OZZQ/FNqU1Z/gRaT16+VkAiHzg0q0hBXFPr5ISfFinFFnQT/uJ88Q baa0YwkvW+v+SUREinLzuuYS2dhSFf+0GXGWpCUtCf0suM4k0SMN/a4fxhXlj5Qb+7k3 JwHVsEf6MuXTvmsHNkwq1XLwZnY6FXP21VLwTpvIaQ87ugTj+yM5rETVfu97oE6GeRRv i8JeoQgWJD+aXEgXLAHzhNd/m9JIpBxo5Q0UpGHSVZl5Vmx/Ng5tP+vm33oiZ9M/bNHr srgZrpyNVpYZygL8JS/hiQksDSmAhBPXioo1spsV4YfG5hmJAU9hJkWdbkAJT/+4FuHH 0qfw== X-Gm-Message-State: AOJu0YwNHyR4rUdNABcSGXrKLyfEsmgP3L+DwwC7Dr0gNWgwoeVZF6RO CL3GRdPfdqYnQNFdQJCeBs0ERos4Ur40iRjzkMg3U/4wi41FnxwJE6BdmU3S0C3Uo6180lEy3BG i X-Received: by 2002:a17:903:1251:b0:1dc:f157:51ba with SMTP id u17-20020a170903125100b001dcf15751bamr2405471plh.35.1709334434131; Fri, 01 Mar 2024 15:07:14 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 36/60] linux-user: Fix sub-host-page mmap Date: Fri, 1 Mar 2024 13:05:55 -1000 Message-Id: <20240301230619.661008-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777083 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1601730wrn; Fri, 1 Mar 2024 15:09:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWCmPXNu6mKKvOaYBHuiPgLG1Ze/9VGeehGViSIWFZS+7jMT8hGwgwDdqJc8iKXKFcP3fZRaY5dl6l8Yz54vi0u X-Google-Smtp-Source: AGHT+IFNIpAn0G1Tcqm04uCK/c8WA3ML6o9K2/+zo2scSCoyV0x8Rvx08+gCwaqX200jeFcjuCoP X-Received: by 2002:a05:620a:4081:b0:787:f8bb:9684 with SMTP id f1-20020a05620a408100b00787f8bb9684mr9154012qko.15.1709334592231; Fri, 01 Mar 2024 15:09:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334592; cv=none; d=google.com; s=arc-20160816; b=BV3I9h5Muv3IJLcUBMVQuAqwF8RldfqTSlCcObrNYj6lx2zT5ptLQhSc1eZaQ77puV KzI7TFT9ugUI1PmqnhzsCQ6akABt9M26wjjZ6jOHCcYcf28t8OHoHO/kowg1Q4whwTo3 dz6AcWra7aN1OOdpq/nkRK6yR+R6wENjPnbyl+FiWj5JW6OPhu6cexVzjOt6OnuX+8Y1 8Xyn3j7kW2M8XshV7KpZHOUQxzNhlVfNQWFVCsGdScl0jMA4RrqtVe3IL0BnJxOwOhh3 ryIp4S+ri+RVyoL5pMbIRBkII7RAeV0Gl61cppE+n4uJrMY+Zvh/FP8C0DnFo31YqEXF pcvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t1OILcn76v2zPwlGFZzc7UG2ju3QgEVusg1rS5CPk58=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=lJWeD4oFAjwWuG+9v5sfY1mwUaQM2C1n+xiiMkGDpyn08KK7tikAoGAAlFqQ4O/piG FowFArfGPcXAGfXOQwlXrabs87+zqcilyyU+b6Z3Ldiz83YYle9B7r9LYHFfWI0MwRpj jksvUkT+JcFX+UT8KRqc754XcsSoQyzvz5cLxzgVu+Hi3lKgcwCqPZOFb6J32lXBGDNm quqvshIvCunoPj/3eR9ys+wRGCp0QmPNPle3Ei7zJxImZATa1qVLKDBJzkMimGD887Ne Y1eFeF2sodm6mDhnwa+6mDsWl+YdDw+15Lct3Tq+iYRxE1kte+irUjr67QgLKqyIb9U4 C5Vw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1eiqbP6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g17-20020ac84dd1000000b0042e5cc2f064si4238641qtw.616.2024.03.01.15.09.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:09:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1eiqbP6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByc-0006Xh-PM; Fri, 01 Mar 2024 18:07: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 1rgByJ-0005kc-F4 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:21 -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 1rgByH-0004P4-FL for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:19 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1dba177c596so18019145ad.0 for ; Fri, 01 Mar 2024 15:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334435; x=1709939235; 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=B1eiqbP6pDd9G29r5L8rr75Dl/dpLhfHlvQblYbHHgLqMa46UrkL5/1012J5DmHG7B Ei6bzb3QTwcyNxBTVSHDtuREMjsRc0V0KJf6l+l235P4zOwdJxaSMX+TMRuDd4GR4lH1 FV/5q2jksOLvB/Qt30Oz4foEfD/HgW81CcUElMN6fRznuH32Q5OCvP4Lt5igA+Y71zhA IRim9lDR7p6/FWsA+32kPWx7TFstl4SV30JLc+KCeA9Zxc52RqeM6MMx01jtcpxFDQR6 Ruyo+IU2SaikYVXneqRrIdlpvIsI5zvj1eCNtgT8lvVRyJDB3f6WQGlHfmFmSHujezNy N++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334435; x=1709939235; 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=a6FIeUPtN/Usl0irXwW8+CMYK5jBGTERVlj25N+RXIWmXQZtvx1jwLpaEpBvcOnDH7 SoMOMrVVPI1SPg2NgtEnvH7zZX8GQYPubpnSg7sahOKGDuGkQJkNR11+KoWlnVhOOhbu 8W0DX9G5ucCAlb5bwQXr2fCFLxr2RqR+ZGE2Xsi0eXCpmwLtB35perM0fm21+aEMJ0ZK gabQQfdfxyKid+ECG09X2cU4PQBD6F1zG2UlDLJrB1UIdnNzPK8goa1rLXEYVGwhN3Q3 DD5ahFGVJGaVWO85O/ngQ6H4TlSEMH0y5fZMKQqiz5/gGeEykBK9OWPgx5HfgMEGJ854 0rSg== X-Gm-Message-State: AOJu0Yzsn8aKmiAH7dNYJLNtcGNHYJXfsl7NsBAh70+PmKJUmEQ1A7mj 53kWx2QxHXqYySuiDvihnvqHc1Zt9x1IwbzYV4p6Unnw1nrhsq9T7WuaPXmCoym2c3//xaQeH+5 F X-Received: by 2002:a17:902:da81:b0:1dc:cdd7:a056 with SMTP id j1-20020a170902da8100b001dccdd7a056mr4755978plx.0.1709334435733; Fri, 01 Mar 2024 15:07:15 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:15 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 37/60] linux-user: Split out mmap_end Date: Fri, 1 Mar 2024 13:05:56 -1000 Message-Id: <20240301230619.661008-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777110 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603745wrn; Fri, 1 Mar 2024 15:16:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVEAeg1CSW6orlgEKISQow0yBQ0NjlyGTybrfXWVeOiS+yz+MwN8gUTk1xa3STzYZuVB/1D0T/FZ/HBPCOVsAJh X-Google-Smtp-Source: AGHT+IF7t4BWylHZZ/MTKLz7kxPBhzmhWVZaZiuqDofKMR1HvR6NeNqpMYG/PltkBouta/rmTlsH X-Received: by 2002:ac8:59cc:0:b0:42e:bd4b:7099 with SMTP id f12-20020ac859cc000000b0042ebd4b7099mr2427303qtf.4.1709334992696; Fri, 01 Mar 2024 15:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334992; cv=none; d=google.com; s=arc-20160816; b=I2dh6BOAA5wXT90UGMxOvK/rKmQh5xsj29QZsYhSZFuUsz2QtLco3uoyHOGPQbOixi XZ9jwBR1C8oTMuVIGDyy/DQ8WvEnmlvcyVJQ6cTLIUdIQg4buXXT0R+XQn3ei9KGK6tJ Km93hAtRBLRjoaamB+v/aq+ui1GRWPCb5FuviYg5hpl+gxzff//vOMmgypd5uajhw55i 7MtDqvHvor9blB6u2+OA5WrxsuAQ0Fl3ZC8Kds03+PVpUB66yXT45e8SoJmQmucEZfd3 4zyD9gYjmIamR9wwTEl4gIuAO86pGJcizDbLyDJhzguADEyWx0ynNfyCIcZd8WhTYIva z6iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZykOOhGWRLaDSZ6ojBtzy1ZtPjktUdeyK8bHHdP5Cx0=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=tvhhAtZemZP67Ot9A0vYqGDgKA2GpzkTEGhMrxK3c/ofPA6WiyAWIkYrN1uDi2oBvI jgdL6s5Mhn0NDpExXM8qcaecbphTs1idDO3XbBI1U7hF3ZFkECwwIH+OzFpKgQCWZzyh dBvTkaxeVI7o4HXPKvDI7Pq+a1e7J755lIFKDa/gU/Y9lwZ6c3FKVMuXS7RD5uLv5yt3 Q+Kel5OPeDVeoUCrQZFvGbqQukt+FXyhpwPBoG47cvvFMUSpYMlyj/EXY4iB/IexUswT 6iCSQ7m6aGQjVw53bTZD5CajdaY7zdQxG9Nr5mGleCNVS/Jh2+tYxoXOePHBMJxWpB/0 1kRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DWkDLAOe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6-20020ac85946000000b0042e04621f7bsi4994515qtz.3.2024.03.01.15.16.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DWkDLAOe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByV-0006BL-H2; Fri, 01 Mar 2024 18:07:31 -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 1rgByK-0005kj-QH for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:22 -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 1rgByI-0004PQ-Nf for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:19 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1dc75972f25so24448785ad.1 for ; Fri, 01 Mar 2024 15:07:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334437; x=1709939237; 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=DWkDLAOe9yvqiTfCM4cnIu5qF8tD80IlrKfbJSo8tY8BQAYQjojg+2w9g7YQJ8vzW/ 4NTVEnaC6r2ypZbVHppgYr+OWZS5nGePxl9j6WHExQFg0u2SX+jlCpy0WUZTGggt0C8S M8VjBcJj3pYdlZDmJkua2Q45uoD24UmkkpkfpeRFlBiT2PmWLGuykxnlIZSOgLSDV2ZX z+1KctoGqBpdvvbUjnkaXH4OfsoSiQYGSIeQ2vPAg99laYs7DNG1FI3NPGAvpm5AWrWA wAAQiOTURA9gqmc0OF4lCOa1Amkl1CByUiOklbWmCi0Wp05wktA+Ejhxuhk9FSYbH/pb cBTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334437; x=1709939237; 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=r7QFK4r5lDC0u1lfK8PzSMiXXNcxrbKhlALNAyb5+N+XflzdivhT4adAubfPjGlqvZ 027QTFbmt+i6BqWcvt5OvHGb2K7Y17rkU1UTSTo7RZCV+dU6q2JeqLTEkS0g7ousOVAz JPA7sPj88ZF7/H1fq5RyIpM1srcxlZxpcL9ah0FBtoZ9gDLgAcW0FGohviwA9J8euvBi 9VwwyYQK2XvO9Z/Gm4n35lAnt/7VAvqElEfHnhCChll+MgQ7EWi+Qih0aPtP23LkUTeD f6TRTp3qanIFZtTzkvHuQdyDYUvhI/RCSF5gkd2pqF+PjhpmrSr5ZPs2/lc//VQlrZ8O xNnQ== X-Gm-Message-State: AOJu0YyPm/D8zytqy90iEZ9tojogDSyaWUEX2LDETqOReMd95JJ0x2kA reCMPO9xDoHHYGjrc8GKQbXfsph6qM6456c1bJHyyrZjtNaL+EndHBXE8E3G0QzTBUU3xGfrnQt i X-Received: by 2002:a17:902:ea8d:b0:1d9:7ebe:431f with SMTP id x13-20020a170902ea8d00b001d97ebe431fmr2723459plb.25.1709334437481; Fri, 01 Mar 2024 15:07:17 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 38/60] linux-user: Do early mmap placement only for reserved_va Date: Fri, 1 Mar 2024 13:05:57 -1000 Message-Id: <20240301230619.661008-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777099 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603280wrn; Fri, 1 Mar 2024 15:15:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUDlLNfebPqj2p71djIO3I8e7Ko40nxPtB8dYcBmZxV3PaXC4Q46OCCTohQoMR+GlUN0fV820TVUBl+rK+GwA4l X-Google-Smtp-Source: AGHT+IGZpe6+S5Ue9v/IfyxW3hSRZbqxlr9Tl+oS9CObepsoMVs6GiEVsd4Tgeipf/Kz33eGanyd X-Received: by 2002:a05:620a:57b:b0:787:83b3:2283 with SMTP id p27-20020a05620a057b00b0078783b32283mr3069073qkp.23.1709334907188; Fri, 01 Mar 2024 15:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334907; cv=none; d=google.com; s=arc-20160816; b=PJ65bg8n2M9cxhb2NOnYuDqQ4F1DcQIUolCVrpSmVQ2mY5elxXOwD82nOm5HZVgGm5 r5y214nZ56bkOEZAf+yL1LanF8Xw7hIAva6ntVi7B5+IlMT76DtbRHjQu0OACRUSGfUp +ALEPXamUG8KNGOa5MPHA0dMVD79nfOdw5UEL0aOij3ReeZUtuENEYNmzb/rcqMTcIn5 da2zTli8Yr9Lu3DdEJG55LtpSTqhJxTWefWXXeen/mhoUJ2NI30CtMtVpkYCjwXykiN3 bdgXbye+hOSXnnz3TYU6t0xvwjf2l13MBFOm9v3KAeWhJjIYg7AFBYrjOJmTJr9ym4o5 1fqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=C6o/8jmcsxwG7sGAGCScnKsOGYQCDAJfkRq1XHi4roN+5Asg5RHDXIASJGO9g75h2f PAlEK3UdO+igfpCLsvYVt0Eg2XJ5Dl1dnYI5X5L9+UjSd22E+kuSddSudHz5EmhFDPqS C9EB2g36GmqpDzokajMnCVf5qtOquZECrbcS9DAhGKj7m3Wt61mQZeh4FY1Dpxn57n1M njDw5Ew7if5uYNXsoT/5qee5/m27JfWd1LlcY4FMW2d3ympO/CQp21Hm2JAMEz62dpd5 J8mMbBrlBVF+PkyBdDNjjuqQjW9T7Jlt0waN4mmTuLuUEhTI4MbrNtT33fa7iVwWMiMd 4cBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CK234zOU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k20-20020a05620a0b9400b00788138b4f76si782650qkh.345.2024.03.01.15.15.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CK234zOU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgByd-0006ZF-MB; Fri, 01 Mar 2024 18:07: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 1rgByW-0006Jg-Rt for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:32 -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 1rgByK-0004RP-Cy for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:32 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc29f1956cso23797255ad.0 for ; Fri, 01 Mar 2024 15:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334439; x=1709939239; 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=CK234zOUflO5hGuofTmOE4SXh0GZ0yenbjYm3JgX2WgnmINR5gqIDVeLytPXr1wf2P lwyBw9lwRoHAsdA1mwAJCk9WTktTt4fWvA1CP6Ew3zluZePdQHGE6Ik7wH277nJQrVZW v5Bl1UVLHwnZRbhvSRQgv5UjH3QQ8cemmpmFfLz2xILdGBO/CU+rspc4BRbn3esc48QS 3VI6Ta6aq93jVcM2na3QK2SmpyPZJ9kn6A68NqnVxKuAi4hicuPkHL8plqjnDHRIfNIK RYZJEpmlNDTICmRRRunhhGLMi4z4ZOADpWdwqXKcAKfxISXxipeZGjIL38O6n/9RaSbP gANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334439; x=1709939239; 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=R6P6PKUfrl3f/1ec0oEqe87TmCD0AWHY7nRIstgRz1sZGpyBdII9al/B8xl5cI27sT +Y5PRZkdiNW3l7Kl2hHzeNYgnrLe6tzy5x3qB5ObsToL5dFvs/j4BmoUkEZQBgLv5/0T MxgDhym6NpM866nxHEmt+Qm0XIzLuou4SCOdLBiYoK+EHmXvTNWeIw+yX4cXk4F143Ao rtaxBSTLqvtMFf3PhzG3DNI4OukmFUgXZHhxKiw5pF6TeDDiXssiSAr3OIM18IHwGiGR 5y0BBZK6zAl/YGEEdU2gA5Vy8AqSkqDAQehDKzAT93rQseC8BVGty4EQ9FPbCWoe6KxF dH9g== X-Gm-Message-State: AOJu0YwX5e4si6FclzvWss/G4kZWQ5XzF6h21dn2t+cCMr/6/LHpBdcc snNiG1a3gHQ8MthrzcMzo3xpNWEVkJ+mYk9TQao0jNPDIlqWVb6OxRtDzDS18g05ds11TDkbt2c i X-Received: by 2002:a17:902:d4c8:b0:1db:edb8:35d8 with SMTP id o8-20020a170902d4c800b001dbedb835d8mr3636482plg.34.1709334438803; Fri, 01 Mar 2024 15:07:18 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 39/60] linux-user: Split out do_munmap Date: Fri, 1 Mar 2024 13:05:58 -1000 Message-Id: <20240301230619.661008-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:05: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: 777122 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604550wrn; Fri, 1 Mar 2024 15:19:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVtA6h/u1IcpZyY1q6OILeXfHcWUO7kus9t4V0UzpSB4CwXEr2ybwn+aYQeBcuPIyScmHOa4De6GTTvoJ8RsxnX X-Google-Smtp-Source: AGHT+IHZ51/UOzXoWr06nAxjCaw/2pQzJ5oL5Q36FrClKc6+C56rL8svNxqVLoWzvJDg79rp+2Bo X-Received: by 2002:a0c:f882:0:b0:690:b11:36c2 with SMTP id u2-20020a0cf882000000b006900b1136c2mr3069267qvn.63.1709335155810; Fri, 01 Mar 2024 15:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335155; cv=none; d=google.com; s=arc-20160816; b=GxHv390WoKWymds8dHxKU+qb8StN3a5Ev+CN5fY9bdCoSZxrXsOyjd2rmQDD07dXxU 9oXS9TzFMjuY+93o07yzbaRN2EOFvaISIQ9Gio9flWV6WgG3GgRihLPhhxCItZqpruTR 1toqlq9LZTjBNj/q8hIJ6zWnpHLp3wc2VYrKG3p0gB9WFA5diEtgRYfZUbi/yNfeZpy5 wjh0yxg6B+it2nSc5LKQOFEg0KtSpWgf6q+/tWUKU6uqW26bKxs1Yg9PmR85y4ivDLeH E+RonXYjKFCKiUHgiLO6MRTxHO9sG11yIsSdbgqtYZdqT5njiKMr1qlQo+0m8Fg8WzYD QTOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qMAzWUeeNJh47c4bkyOP/O/3UzvTHZWrc2G+MJg3FB0=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=ddzBgUyJAVe+F/Q3l/i3Fk4fYKIJYLhSkbTZkAgRZw5Oikf0WgfdkQiONaPq1rT9i1 3R51dhxSAliii3MXjnbfP2KsQOyO3CjOG73awcvGRglgN0GPCYuEbVkGbwkqtR37XXQS r2n6PldKqfrxdcl0yCbGQ5nZrErwHQCoJxco1FkWMelb6lEP2jjWwzXrT2NsUMFe7JN2 5VEEY9dSatJkQyOtQoF3Dvr9PAYF6IF2Mqmvm+qyHaDGOGbTiSmoSkxBgi8sPgvpjFaj m5YKDXgdV6TV2CJ+zKAkzWPho0zienIQCi6F3aS7deoT0zF6W2kD1id/kSCbT1s0k3EI lvXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R29xo807; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 7-20020ad45ba7000000b00690193b676fsi4550188qvq.350.2024.03.01.15.19.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:19:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R29xo807; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2b-0005Ia-2s; Fri, 01 Mar 2024 18:11:45 -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 1rgC1M-0003eU-SH for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:31 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1H-0005c5-8H for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:28 -0500 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3bb9b28acb4so1913228b6e.2 for ; Fri, 01 Mar 2024 15:10:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334622; x=1709939422; 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=R29xo8072fvODYHj6CO3zejN6mxhmTEJ0HQshz1Lf8k/VLxRtv5g45pI8ai+KVX7Rn +NRgpwSq9CUhLSpgYQCpZjvgumr+D/snm9+1UOEGGEd4S42ijuqsHCOdsKRIRAZwGG3E GnvuRkT+8D5O3OmfsfyxYkywCh+uGpJfm4gxYdkYgbhLReRseBHfaaaZFd5BjSQ0Uo4Q Chcfr7Hu9KPvSyoxr9ej4CcC5OmT2q4Cyf1AeE8sE+tcaHgA4eonHUMzrfHndiVqM37p AksAe78DIn1v0D5W5KEx3PwCdD505sdDHFmtpeopby3wFK6z4eld4pdWulur69iH6QhI 8yYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334622; x=1709939422; 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=uuq9ucBd0ssyoUOGYErc7H+vGdl2R8t0QqAO9hB0KCV0UGHQPo+s1TLNdJM2rYPY0L ibVDpxaDLMI4Awhc/aFlXAW+mrFk17qy1Hagt/CF/srdnSzHx5RF5ztiND+hHVV1HH5B DgQpW0e263So9qtAlf0Pw2ZF2iBtB5x1LvqUOPiRiah0C1zvRYhVSiSNNVe75X9a3U6S entMt2bYPndE1hdaxYCHhRFg91wz0rAH48Rlu0arV8htDSUO8Z+f3RsvMf6oZOwjupg8 Ss5VYd1JzJ/lcvkeCjUFDDb/OmBA4dH+HFb4C2m6tDu0vkazEMGZYOwSXd2S7IQBVzcB l8RQ== X-Gm-Message-State: AOJu0YwA4pEM0/2w7cxvdME/ojmeIhy7HyhGNYKql9Ezk5/kjSVcyIp5 X/iXky02imUCuo4rO3bcdjtRscd4A41swjiouBD5KqHbBFTChvVV7fpBMNwkHK8GNZOXc3DvI8E o X-Received: by 2002:a05:6808:3c8d:b0:3c1:8066:7531 with SMTP id gs13-20020a0568083c8d00b003c180667531mr4725912oib.26.1709334621827; Fri, 01 Mar 2024 15:10:21 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 40/60] linux-user: Use do_munmap for target_mmap failure Date: Fri, 1 Mar 2024 13:05:59 -1000 Message-Id: <20240301230619.661008-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x235.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777088 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602383wrn; Fri, 1 Mar 2024 15:11:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXGzXqiTDFnZKBR0Q4zDAI7sOGzuFfj/Y8dHk6dPhvuwN82x0X5+/zcWkt+v2GSJX77wz4NKsfvxO+3eQ3e7qEZ X-Google-Smtp-Source: AGHT+IH5rQ3aSeuI0qznoqVBLs5gYQn2xieX04CCoaZ3kqOTkiXTB7zfMf4J4upk0uWGhaRoheqM X-Received: by 2002:a05:620a:1a1b:b0:787:f097:45f1 with SMTP id bk27-20020a05620a1a1b00b00787f09745f1mr3830151qkb.33.1709334712208; Fri, 01 Mar 2024 15:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334712; cv=none; d=google.com; s=arc-20160816; b=RwnZkSz3Gn10Fs9yDSxlTRng5bDoDP0MvVvO7FSPM+pgXGaIJTgCq+L+m2RMQV3mSY BGqCmj68KDrXnyxBk6GRZitkxTz+jAC8guMmOEEh4uG5IBtGcSHBPtmTlq6bukxXXKf0 QDZMKxMeh4k52Ae3VaqUhGr9Fr/a9jvJosJmHwIbczHMgpeG5nbWEodyuYZUJeqck/cw EfSTNUt8c4ZaPR+H3QSEUFuXYHS5wmx634yYTFsPh9UXI+GqZrf8eTyYamZ32FMob5WO f0NL/DVhpPc4oUCfI01vbCrLYLUYnXD9yiGVuV12oOwV4Xp+3yEtZX4JZKInEjtbLFZT d6rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F+mIi8OQkXxgV79040kdu3+FCdCNzpLRNnazUCypFlE=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=n1lADdQ1Ez+1h1v62RfNbhy2vxcHgYwcwwP0AC75HIgC4s9jTVypI57FFMWb8Z0Zax +e02G/Pa1FfY4m0BFe4scPatEKuaGYwKPGApR33N7U8mfWS9AxHvYMgZwo48vX8o/Qxt HZHxS0laf1JPCXJBrkXjXINUnqlhGyBWYmdPLAVVGxGz04N9uYG0jOb8b1pt+GVXFzKo M+ueMUGjgI8h07Ca3TJXRmastSW3Xs02OyYlovMB/fznjgZQtwtAtM4juvQAtJzKSr3L F2+OL2mCobO9pK0nI+RXpWFWWQ9yMexZ8Lt+fUrdrXlSabSR/oalBWLArVpMHXizNzRZ PKmQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PDTC2ggX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o15-20020a05620a110f00b00787a4eaae7fsi4485931qkk.744.2024.03.01.15.11.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:11:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PDTC2ggX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC1t-0003wt-H7; Fri, 01 Mar 2024 18:11: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 1rgC1L-0003eI-IN for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:30 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1I-0005d9-OI for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:26 -0500 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c1adc90830so1495734b6e.0 for ; Fri, 01 Mar 2024 15:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334623; x=1709939423; 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=PDTC2ggXOanzDApgWK2jQ7vdPzjc0gUcmYuIhX8DaWp5cMdtUpxCWhh3vTTJzkucfl V4bucQBZK4KZkBohJ96xMx9ZV6wReU43+TNXWi9+/tiaDVeMcs4FhiiZEcH9zHYZYZp3 yOxMJxjmzydkKaypMQf0wiLZmZHbTms1QyzKjf6DpIpV4Su7KaUXMTI0tIIB8ewgsy3z 4lardH06oA13d3uFvNWki0YenyVSayR8wgaI/+h1bzV2tlmDv1IZd3D1jgONmpG/cqpS 5uLRFGu0pSRZFMAJZNO8SB1vRI6qV/m9JuRMGN8TwZQJFovmID/nAgcx1on6Xp8bqdbA s+Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334623; x=1709939423; 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=cumZt3UGCOL7VzGIEzrylS1x7SvpABwzF1HUvKBwBdBH/x4x3hjVa4VA7+yg085vbh SswoNsydaCXB7Lg2kSOe6fwUSjAEjbxALs9pMdKDaBXYAxiSS55hpfxMd8GOWinlKIxn 8SXXlfXtSUIfAcvB1PHdYmxUOoOuZSGcSFAjFKzuoT3wunwdl85v5H2zqfQd68LY6NtC LRMr1EDwbp9WHYCIDQpwjh+QaqFD1ab+Gpg6oW9e8yNObaFxicWy2KRIZCq54hX7KDYb JiMxY91EPXFiWGV7m/Vs2Vgzn3J1EA9dsN1DXikdoMG3kpz0CcYfRlhA/iw2En6tSEg1 cM8Q== X-Gm-Message-State: AOJu0YyGevb1oge+jwapi8vZgcfjW5gn4w5tJFcjhZJdvCFkAiElM+WL BquYuYkJjEEqwJRfNWorQzQSEvuVqVNYI3dQc/UXtdAhfwCDmcojAJX8LzKLSWz+0mStbMhSm/8 p X-Received: by 2002:a05:6808:e88:b0:3c1:a01f:8df5 with SMTP id k8-20020a0568080e8800b003c1a01f8df5mr3803925oil.33.1709334623165; Fri, 01 Mar 2024 15:10:23 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 41/60] linux-user: Split out mmap_h_eq_g Date: Fri, 1 Mar 2024 13:06:00 -1000 Message-Id: <20240301230619.661008-42-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::231; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x231.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06: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: 777116 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603832wrn; Fri, 1 Mar 2024 15:16:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXHv2qpq7lqMi2I8Q5fnhDX3tZ2F9qqDIQ7f02JkmDdTolEjFD1qq6+wEjPG6Iqsta6XGTRzS2w6MCQOACMtisM X-Google-Smtp-Source: AGHT+IEhhC7VcJ/Ztn148+hpho2DPPtDg/PUHtX/8e1xRxECo8CckyvYPIqaCQC3Y4ww6IoSqIZd X-Received: by 2002:a05:6830:1258:b0:6e4:7ead:db99 with SMTP id s24-20020a056830125800b006e47eaddb99mr2956788otp.33.1709335009060; Fri, 01 Mar 2024 15:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335009; cv=none; d=google.com; s=arc-20160816; b=Ag2d16jN5c9p7w3ud9SkcnebNlQ8bgpl0wXHMSFgbZ0QXtbfceYpATezFpx4b8DHy1 mdjosfhRcTjyBTBRpleMEQri4kWdvou0x3tVFVHzxtjORW4LDdeyuL3feUX+uiClbaiM fpWs+WCbCUtBBckTio35a+2Shmgc85G/wHMHeuw2rNw0/wbptEIND0YofNNU6WIYY69o ag498JqvXotMsMIGmmdg0oZENOdpDJZE9hrTsnXYAIPkiXpuLgoJI7fHvQC6GQ9v6agG NKlrqr1UNB0SmOm1n+QJ0vdUki54I0CbWHDeM25RBvU5oGrrYYONynU5yPNX5Jd7Xoyc XkYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I4UwZkIS26PhKHP+iY1jWw6KRSEUK2Dc0FNGbwDM3y4=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=ffTYE3aCMJDT9wpWT0YTH8LW4NIhjUgfQiifAIZ2FbEadq8/EK+cIyilgKAjk0yu3l Nh68R8Wt1vgxZSrxA7NXt2e+2MZTVhUwXIYDEij0JXf4TpuWKOkwZtmun9m7QUXG0tSk PY3zt/ca7icjrHgZD1M9ZGrLVAXLAqPpZqWpjgcTlBhmobvlB6ou7ilhfC3FGdO9WMZF zsLJuL8tKI1n/p4/l6udiKUXmo5NrVpXWgLS5vNeeqQBpcoYDzAjBe7YjuupFgpE5gdu +OJUOmRCd0sN7/HOsM9uXAldAnaYSLYzzddKzoRqPnsOTub/wklsQaP3jH+5RXSAH7o7 bEZA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y7inVYTm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z15-20020a05622a028f00b0042ed04c966asi1548436qtw.157.2024.03.01.15.16.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y7inVYTm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2P-0004fb-HL; Fri, 01 Mar 2024 18:11:35 -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 1rgC1O-0003f8-CW for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:31 -0500 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1K-0005dn-AF for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:29 -0500 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-365c96e2605so10492445ab.0 for ; Fri, 01 Mar 2024 15:10:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334624; x=1709939424; 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=y7inVYTmmCQwt+c1mcimvuVifIwBmPOKWglqaYA8yELg87KB/utF5iWOPYmvoF4rZe eXWNedSUqB2mBJr1aeeAfNUgdca2tXs+R7u+3glSvxrUwHso0s4tWiABNgwZNYd7GyZl NL4zdV7hDUVh4XQ3iCkJsj7ry3OiTHv5nMIlqbvgR2/bkgfQzdMyggIOqiJMNL9OId+5 uKdCbDiEokGI/9MsrLz4DUe6tfWYhL8sC1WPrWLJP4fmeWrekWC3EyQpC21cTK1GxISg L4+UEE0+OORKQhDo0SkAjsETNVe++vKlcd64BLGVmPDMbuMguT/jHQN5wfmKWKg8ohwJ bh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334624; x=1709939424; 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=bMUfAb3YGvii1U1ol2zwskoGYeHKinT6jxZYiWcCTL52PFlX+A1zXPRFAG46sA4WHs JcPHHi2FK0tXUaPP2swmF7hdxk+gQLj0kR9M+uITVuZQ5x9A98LsbTFRBvji0kZ3IaYh SBzMSLiJepji/8QPb+cp7BVy5F1MdnOFGGTw02DLFEgZD13TE/i13Ygm6devRMxedZfW +m011jgfjOY/aR1MjROW9NaHSSGWAIESHz5Y2MWY7Y3IqzSBtVuNLM7HagDLOr4amUkZ ElsQMmu97PgV38CseSxpjSjB942DnY39gy7afRRTOs+jWrwjFcFQMnj+fvanaZVI5bB+ FLcw== X-Gm-Message-State: AOJu0YzqG/1qYbQ20NPXCvIJJxIZtHShVzNQ1uNN9rtdpqFRrhcYF3qt 9iwkca7tD00SWGpVPYMSKrlTWfCN+Ykwjl69STDmZbWf9I3KQXE2gMNgBpD8x1kj9VxnsewnC8k c X-Received: by 2002:a05:6e02:490:b0:365:d2bc:a535 with SMTP id b16-20020a056e02049000b00365d2bca535mr2671246ils.14.1709334624422; Fri, 01 Mar 2024 15:10:24 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 42/60] linux-user: Split out mmap_h_lt_g Date: Fri, 1 Mar 2024 13:06:01 -1000 Message-Id: <20240301230619.661008-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12e; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777460 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680302wrn; Fri, 1 Mar 2024 20:13:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX5dQ7J7XJBdCM2nk/ewCc4+6XLNfsoEXIxEVFnWc5sLElmxv/pc8SzH1bKz1B8WzOoQeMtHh8k9Ns/08ReAdrI X-Google-Smtp-Source: AGHT+IGPP5PozcH9QAslt0YF+jH7jlHticWjkAonqZfiBifp2hdh373bunqZEsQxc8YJrkyX8qAR X-Received: by 2002:a05:622a:1817:b0:42e:bd48:c77d with SMTP id t23-20020a05622a181700b0042ebd48c77dmr4133218qtc.35.1709352800231; Fri, 01 Mar 2024 20:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352800; cv=none; d=google.com; s=arc-20160816; b=nwGQZsCAAKpIbBGcWOybaxWvaTjtuwiRmgTCpydgHRJ0rXwDc+iEY+XV4XlCqGl4jX aa8Dxc6KLBEwqLeSVLgp/crdKaV8M3pi+7vNIGregyC6kkPn2f5ZaNG3zQoNtDhDaLNz 8wlWBQ8afYc/uU+HhTEvEGDPZp0N7fc6p3+ENlMvY4vay20cY7r7GGCx4qs/54CLYCeP UXuzniIKzg0T3Ye7Y6MJy0ORzjoKuRU70g9w1GttYcUNPM/ZMhJH8tQ2JIPql3DAGJsA LQU2N6BdmKTU+Uc6kF8aH6RTkV15F6CxiYIxYJjrnv5E2lnCcYx92BYS17GJcgs9Pi1o SE9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MfmBcNvAQcjDLvj9qNkCIuvVr8sl09md9gL9eOBPbro=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=tUxNQWmPA0QXEILNbwweshmirwALlcTSyGYE3sM82ZZo6ac+omcz2PCZ5ILFt9LPCs GFtW2NoVuSq7veSOtqC1ZPvRNqxJXT8M7JMSJKEjVA/GOaDqpBTSdqvFq3i1+Jp6H6Sv pt+yZ1OgahUx7SKi62+hdQ/DeBftu0KNTKim8VMFPtlDRb26DG1MqDsQNyI1ofCtiL+F l6gL/5KbYvh5+SDDMAhdR4b+N3ANrzh32mslN1YqYbV/FU6eFsJaREVCXS0nCZMcWVcT nzE5+vaquxmiNut6Id65A8gDh79qdIrblTJ2j10tKjdHWPYWMR8px9Fls4wxK11hexsx fbQw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJdEvd3D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gu7-20020a056214260700b0068f6c00f147si5629324qvb.489.2024.03.01.20.13.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJdEvd3D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjG-0005KY-LY; Fri, 01 Mar 2024 23:12: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 1rgC1O-0003fA-SM for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:34 -0500 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1M-0005eA-3P for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:30 -0500 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6e432514155so1306496a34.1 for ; Fri, 01 Mar 2024 15:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334626; x=1709939426; 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=GJdEvd3DRdAGObIHrYabwTLNvnZC6HmstotDodyiE9S1+GFR+o0YUl8QPp1Xa1b9Xk FZtqlR9sLCgPSib0hJYBZS3UHZ7zlye3tsxaxJC1av0AJbld7rBONoR6VWxh9ECsUG+1 nMA+2SAUUos7FN1XPA0rdxUJSuCDTGpU0YTeDZFZGe0Lai0f3XTKWavFBur6zXiC6WSV 9UFH16xms2NiIEsDSEi47AZh06+8uPESdBT8Xgrzshk5669+W8Qwf+U8QZOTM7g5PfPe D+SU3Xn4iSU4LppR8RdDW+8pgVYeV3BCbuTguPboF+gtr8/DMT8yWVlmgzG3TMzVoXTu ACQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334626; x=1709939426; 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=I128fUc9inhXYuF2maLUOiMCkf/gYanJ8zJWV9AWCOO04XAp9ditpQoGnirEYW7F+L y+pjg/NDKI5lxCBpqLtrn7OBX8a2GE6x6QVDc6D1iHBReUxITFkYK/wUhKVMdiPUcFGd 95+sJWfsVPS3JwaUy8KpiOWhQG0ZiyfXSbTn666PiqxtDLhC/5szp4hkT4c2sNDLpwzU 6cMXQu1fRK7lRM4xrSHRtQlJL+zh9I6L7jODmdxgbf5weQ7918oUvnNihFInQW03nPhX YOY1g9/tSOqAI6jpGKXBMybWqeWgVFzEZGqG4Y9eTRvKEEbwSvqXhNrpzYZwG7A2gmm5 Cjng== X-Gm-Message-State: AOJu0YxkEeBLKLRkejdvH+Sh2dlTYEW5caEc8B1cClbnAPt5fEBMB4/Q MFFDwSvxOBHbXzKcGN0PkBNXKJCan8Ci0by1rxv+g6g4AL66OHVQeVXbA6s0OyzenVTHl8Sa2G+ v X-Received: by 2002:a05:6830:c7:b0:6e4:a6bd:d911 with SMTP id x7-20020a05683000c700b006e4a6bdd911mr3052460oto.15.1709334625953; Fri, 01 Mar 2024 15:10:25 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 43/60] linux-user: Split out mmap_h_gt_g Date: Fri, 1 Mar 2024 13:06:02 -1000 Message-Id: <20240301230619.661008-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777459 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680301wrn; Fri, 1 Mar 2024 20:13:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUAEl8eTMQyKMOKWFfsUhqNuICMcoPh+C/o4AJANB1cB3z0bwnXcTAICu0F1UEWXlSp7/xTl0XB68b3LvLoo2AC X-Google-Smtp-Source: AGHT+IELU0JetY+BLmRHzrkXmIyTtxFULIsfhMMXbmq8r/q4sqRf3IkiiYtyvJPD1ADJVE/k6r4T X-Received: by 2002:a0c:c3cb:0:b0:690:5874:af7 with SMTP id p11-20020a0cc3cb000000b0069058740af7mr3436570qvi.38.1709352800055; Fri, 01 Mar 2024 20:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352800; cv=none; d=google.com; s=arc-20160816; b=RWowJ4b97Tx8htvIRd6lnZnNlDj9r7gBp9st8RPkv07MhnmTA7Sni71GYXI/ilrYbA L22ZwiaAGgWcfTas2LMxXa19VCdPpQlNleiCsEC4hPrHIiitgNBPrm/a5FHhhQFTmfIK ahrqoGHrbtT+8HmLWNgdiTeuQHJ8JkIigDEgEdkXsCR+kxeD552BJB/2+A8bmN/c4vp9 dREK3Q9ZGYuWmv5gzv1NKU5Ro89q12Sc4JAhNWMUZnDp3xT6GzDaPdahjU/39leXvR+7 /DaiFJgZsPElO0gjP3Faqb4MsO5BaPMwwZ8XCkiJESv4m/IABik0JG17cNBqSumO0HXa zl3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2NxBdbDmPXvqTBcYichP7qzlXUZvSD7xiNQMCyXrUoI=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=GpgV90i2I5PfYQdlwNA7dFrZkieV6t4MZgQk1+7ykI1DWQlquNv1PuoU2PsutanmQB ngi5Pt1uInGYXYqJG7Hak906aPZ3Q0dGmtUDSUpgEyGs+aBfP7Z0JFwCGtWtOf/Rq5/B BNqD7jLJx5hT3P5tBLya/FKcFxunBLmbFM1gOBoqEi6Pg2oymA7dMhkVl6Hn/xhN5dgV /EBPgL/05OTIfMqYmCg4NYmLl+2lkiDrDS81rGCw2vu2EqJqZHlWmxyE+eLA9vUM8r9z XwyGkBaZvIp3tbvqXBiblZ8KPn06GeqKWVuoSxPAq8mcqyBTM1qk/BslWtn0mxjflgHP gT+Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qs2Y+WFI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p11-20020a05621421eb00b0068f6c41982csi4873078qvj.494.2024.03.01.20.13.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qs2Y+WFI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjF-0005KG-Qe; Fri, 01 Mar 2024 23:12:05 -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 1rgC1R-0003kp-3f for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:35 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1O-0005ee-4Y for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:32 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e4d48a5823so2408735b3a.1 for ; Fri, 01 Mar 2024 15:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334627; x=1709939427; 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=qs2Y+WFIzwetA+h6Yrssb791wKEbmV4a8K2QmdMcX+tsF0MnByiW3H0a3NkFijhrPj 6LF3IlM3VzQRvAtnpwrdMnmALXHIBl57oV3rfsEpxNCqOH+dGX5QGfmjZ1boUWwBJkeK aAGws+PGWtyBkk3x70XLoTUnXSlsISD9YmpSr27peGYK0KaTE1tfU75D7+jfzs3RFIEc BQmf11UKmuFFYdM5JiJPnJuNm1D2YGRccBNoGRF3MRgb7czIAnWP0XSnGmORbBOUhqEv FBVeRU89t7t5Iz1JvltDPfXIFzHnVB6cYpNweRM38v0C0eVE7c8fzKeg8oq8FBI03q9I mw6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334627; x=1709939427; 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=sAAW5Sqewz/CcpPqM/LVu0iMVzjQ3hd2rkS7/+0MLk14xYg2Lntr4PqfDMTJjBKzdI 8Wjyusg/onm77SdlJSqwNiOwCGdNALe+ljQd+SqGixwflMMjpYttbyc0NS2UAjlZ/gXb dmEcdnfsbDv8LlaXfYc/+ROgKGkZSePRCOGs+pIFJGacrVE5GqSJnimGyrejOwq0pP0k r9t6iWoo8pajtii+UukZEByLwMpJdmXTDj/I1lvH11xQPQvgu2pH2f88KyZ0j+t0xbgQ jWWc02oXE4chSpKVP+B4EVkOo33lLaeDTDkLuT0VtQHuwnwILWMtYEPqz/HSHDbTITKu DFkQ== X-Gm-Message-State: AOJu0YzOhKwbsfC7f7uhCPkipwEGg8i6P1rkaywo0/QsbJKr3kkknz0U biwxcu6aXX3ESuZOreBvZNQBOiJc05SPjnhKELa1pY6g4Y10Hq/eCm9MKy7gZR0e3FMzvtdsc/6 N X-Received: by 2002:a05:6a20:3404:b0:1a0:ed31:d5a6 with SMTP id i4-20020a056a20340400b001a0ed31d5a6mr2365281pzd.56.1709334627407; Fri, 01 Mar 2024 15:10:27 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 44/60] tests/tcg: Remove run-test-mmap-* Date: Fri, 1 Mar 2024 13:06:03 -1000 Message-Id: <20240301230619.661008-45-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06: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: 777106 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603712wrn; Fri, 1 Mar 2024 15:16:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW0Xob/HW+AWooSzG4u05k0uhsblV8fRP+Y6UqevTSIZlZOCY7UtJEkwF6VBvQQHPNS1n7FiGu8XEQSYNdKHB+j X-Google-Smtp-Source: AGHT+IHQ2cAro1tpsAycgBkbAL4gJFxg8VdrIoh0ZCTuZhV8LW3svHj7/ZalcpFYgZCnLXPf4uyu X-Received: by 2002:a0c:fa42:0:b0:68f:cbfa:6876 with SMTP id k2-20020a0cfa42000000b0068fcbfa6876mr3259193qvo.38.1709334985856; Fri, 01 Mar 2024 15:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334985; cv=none; d=google.com; s=arc-20160816; b=K4AlATlgeA5Ley3lUGbIZilVOzlAjLxQ/0kghNHCBSuoo6xhn4HIsYVLGHQNa5bpMw 7PLG5K1qRx5m9W/UctKkVQ12TeGl3DyL1EdCRJG2p5sYlxGM2wpxdQgdQdE+hqMDA+Bx GaxmJVLgswpKxtqWB9MWfEPWoV3/cG+wRhalq9XCOOW2HZ4+365OQEKicwfI3Wb5nSac waEmRILLwyzpr6Sq8c/xbZdqTkCBs9TtiNlg39wsQoONEIpanMkezlx8gXSM5VFNM0d/ PIShK9VC3Iey1WbDMrqqHeuEeKcIyc4SAF22n6pseJbMMlNYuWhfl0HuQCsWFoEzPvZD sn5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e2NESTxnz6150SuLytNvY5Gmn2U5RKg4GfRtueQZH4I=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=CKGDvjbBzufY+6txGhRu043TrVjvCT754436MJDnXh5lGuk34pjoLRvxwUOPzAgP0o hjZ9oH7KFm/qnw+IfcjeOc0PQf6fmVWt1FnXpzd8Cz5Wfcfpo6F7+WR0oQ6ZsbCuQU/5 SmT2VGgvMJMqaJ5H6uq0diCWWMnmTrklPdilMSdKzTCEuyWKV4QFPVMGJ1yqqb7M09gp BqLp0bJ8SDlqOEK9qjIHuHlXfiZKN0W2xZaJtiM9xeCE/yJWfjuB+y0zIbkwfbyezUY3 MkEHgU9SK9w8dYOllach1yl/wnDdVQTzaV+fCYd9y76/YRd5lkroUai5rwHVqTrj9B4n aazg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zvbezarZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id iu4-20020ad45cc4000000b0068f7071cd09si4474367qvb.100.2024.03.01.15.16.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zvbezarZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2C-0004Gb-2q; Fri, 01 Mar 2024 18:11:21 -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 1rgC1R-0003kN-0J for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:35 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1O-0005gI-LY for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:32 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e4560664b5so2238581b3a.1 for ; Fri, 01 Mar 2024 15:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334629; x=1709939429; 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=zvbezarZ2naOe+xWDLmcprnW0NF10+bLiTDva0y7/3hnWQdqGHRSbtcBbOWLUJJWJe OVYor7mvwc92cGcWa9YJ643pcajYQBrkvzStgB7TezWbc6S4P3CSIluf2j9AA+ylHUSC Hyko3Ga/eCAuSGxkqD0MHyAqJK6wkU69AhTq5lGIu1cDbrycaIbPlqA7YTX11g985Gi2 B6sZaAVcZh0fqCcfIzNFhX31lzxGc5IgQNcG8NggSac8ZtqkqgETzCkvOUEp2UkB+C4l HS0jEXbmAKzSDXjttdT3M1+S8hqkioSdrGYGlgC5oHUxqHdyt2rpXM63OwsVTOzVLelv 0ACw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334629; x=1709939429; 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=rev3FRgQNve7/ecc7vmqtfoDnPCtBAQzKkX68Lqv2x0T1YIaXfTXgcg15iXkBYM29g DTMIDoIqHEFFB342P0qh/NU1wM+QhyEzq0+15lhlQ7EkDe+VCaBHRk5PNXm4nn/pzzMx bIEbgWb97GM++RqvwMvUnsOqo0/hCWUgFsbcIlw+9FaEBY37Ewdbd0Xz0LsAetqQfk+g YOlwzwn+fEZ/gpp8ll0GOuHNbgjDtflERFb3audYl67L5T+qNKoJpQ1L9EQjqGkZ2Y09 aaMzkqSu/a52LBDO2B7rZLliEcZC39S1zVK3UVzZZDPCcV+cAzG/QpTLWdv0frnfg+nI QVtQ== X-Gm-Message-State: AOJu0Yw6TQMwTZ+0aBUuQ7deXPGtzBOQnJGFg4RhEbIhPxl8DcOuPtun q2WzSQgoZnpSwBbP3hTgJd56IGaNtDSzWyhZJtexHvwZuyRA1ZhjxaG0+b5426sQgHJoyK6mhG1 X X-Received: by 2002:a05:6a00:2352:b0:6e5:adb9:b955 with SMTP id j18-20020a056a00235200b006e5adb9b955mr3834774pfj.23.1709334628978; Fri, 01 Mar 2024 15:10:28 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 45/60] tests/tcg: Extend file in linux-madvise.c Date: Fri, 1 Mar 2024 13:06:04 -1000 Message-Id: <20240301230619.661008-46-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777466 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680669wrn; Fri, 1 Mar 2024 20:14:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVs5Uf6nvQkraUuiKS3DzzjxNcOcYY1XJbsVWpaEbl0WL18dCZ/ra46lfYbgOlVaNJbgan1HRtfp+QQl4Gs6j+b X-Google-Smtp-Source: AGHT+IEaOthUp+ZCH4FuOxdXnHK/gNj75TMDLBrm+LUTDzs17+7bwyzLM0zePYoj7qod605465Aj X-Received: by 2002:a05:620a:190c:b0:787:a444:12c7 with SMTP id bj12-20020a05620a190c00b00787a44412c7mr4349405qkb.54.1709352888256; Fri, 01 Mar 2024 20:14:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352888; cv=none; d=google.com; s=arc-20160816; b=FByQW+hHJnHnmwPVu8h5Nwj26p1IgH5Pjv2CKMb1/uZOTxbsGlEw98BZ4AyNjDUgC0 AgOy7Pit+BAmRxLTKCPeHw4u4crwhx2NhaK25giWxxPGe2kYWZz0z52pSpj/FgEfMqGv qbHmocVqkqshSW/Vbi3N9zuoTbMxW7dYGpW9aTa9h1asUksKgHZNV+ZmEFA4VCcD7xNu X2TRru319fCdzgcRr7HXhSxBWR8a/tkUSfmeNk3ZnNlscEytVrupBEFnU7s3f/J92VyU eYoBIyIm2ABWhZvfegL4qEFhx8D0rMgxWScJPryPw2UBs2oMXFDNzHgo/ElNi40nx4uH virw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yOzziF9HLP7qTKwq+TAQQdn75nn/2tGow/nkk/g/qYA=; fh=s58Awvj7EeyV94muHEDuIYugSku1j/jQQ3a3hOlVvqQ=; b=raob+wRpPCgs7wbi1c1HxNOnpZdtjk+gRZvRrXZkYvING1Ol7N2j9bhSfhMLTrF0i1 lh9j9qEwNvZq/daC6LWt98l0ijSu5R2SvBcEujFdNNaS8geKTEiE3e6MMJsbpX1dgOxx hK3ciO2Vb70CwuRFlGdLS+lWrwSwyLOnv/DILyruSU82XX9P1wwVrq4O1b2Dp1NG5D+g PmvXoJLmf+cEsBJwLJ132OKOvXb5fC1B/UDLkEZIxv59cfiWq2n3wYhE12prVLCLikti qcmgtxNrBgxdHbIGfBPrGoGf1f+jbGBuM9l7SBvBQmvalbQvoQyvWFkd4POg3yVYxcPr AZWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n8qW/Vdj"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id op34-20020a05620a536200b0078812fe97cfsi1300539qkn.409.2024.03.01.20.14.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:14:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="n8qW/Vdj"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjH-0005LN-DS; Fri, 01 Mar 2024 23:12: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 1rgC1S-0003ld-Fx for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:35 -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 1rgC1Q-0005gV-MV for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:34 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dc1ff3ba1aso22794705ad.3 for ; Fri, 01 Mar 2024 15:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334630; x=1709939430; 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=yOzziF9HLP7qTKwq+TAQQdn75nn/2tGow/nkk/g/qYA=; b=n8qW/Vdj1XfxhQLXgkEuAxio9cY8kSswbik18Y10rA+9XKz9B1vWAA0dPCqRTkBQ/J p/gGl6hUEKTpy0iEkdx804Kjq+csG1xXNLYaFHEjzwOltU66/Kfay3/eEsCqrQAvQoKJ tTNYGeYkc00uKhxmuju9/MgUNX619ofhwZS6FuNCf6iv8S1B/uYB7Ee+IA25om/A8bdl s6NLhMgTSb2khGnvOBrP+RgxPD0KQ3FU3zYEhxxfErzfZV5M/3sRqqVA0skXDavGBSwv irS0I4LH1FR62AtjIQu6QeIVZncA1iZMlEoLkUD4dQc3SMs8KkLwvM1Xg/PIZfWf8p4Q /0uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334630; x=1709939430; 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=yOzziF9HLP7qTKwq+TAQQdn75nn/2tGow/nkk/g/qYA=; b=TcCNQOHIGGi15Upc4mfSjOmMhNbTaL6u3QzFSxiT6hPVHE2gOZPz+b7jDVQ3y/aCLp Hu7uWhMkoIuHUFtkuy9iU5IvtfGgxt0y+CRb9UkQ2YBOv9Qa4UFRqnMsYgZJtuWyv/dG OsvR+HusdLJUdZ558iohWzTV4Q5LkxpqBl86Rvk4UOc1n53m/2s+LL7zGeR+AwFHH2Cp 4OgBr9cqZwsZxegEbH+ElmwyhgBFQqV8f2hRg1JKsssW2Eks8sniyFHVbzINOuAZBN+Q XrCgSAuoiOZaAvRdH+FKYQRlaoS6X8bPYHiA3ZmuSgo2vfIqBCHtH93zvWZEA4PbCg+0 mdZA== X-Gm-Message-State: AOJu0YyHQcHDgZqQAtmzhpj0ZxXwTB081jg+SFjrJ0W9VxXYCSNA2qah 80IBS9TND95RFS6rTxOZ8vgjKn8ulbcGi5fSN63GjTyKTxQSrJpQdXlxSpJRv0EZttUMWWIrdBy J X-Received: by 2002:a17:90a:a606:b0:299:51db:33aa with SMTP id c6-20020a17090aa60600b0029951db33aamr3226010pjq.6.1709334630536; Fri, 01 Mar 2024 15:10:30 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Warner Losh , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Helge Deller Subject: [PATCH 46/60] *-user: Deprecate and disable -p pagesize Date: Fri, 1 Mar 2024 13:06:05 -1000 Message-Id: <20240301230619.661008-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 | 11 ++++++----- linux-user/main.c | 12 ++++++------ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 36bd3e15ef..8565644da6 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..6ab3efd6c0 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -364,11 +364,12 @@ 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(); + + r = argv[optind++]; + if (qemu_strtoui(r, 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 Fri Mar 1 23:06: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: 777112 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603781wrn; Fri, 1 Mar 2024 15:16:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUbpEOVl9TMgx2Affllj2Td1jz1AupSN1xbMwEFAsHrmxoHynffuLvSh+5AvPYR7kxlvaGmCBxUum5eyXZ6UQD0 X-Google-Smtp-Source: AGHT+IFjSEJmuXiel+Lox9biwcaXO8x9oqhlWr5Q/mPBaaX9DEIR4SsToKsqLEek+z5nvrX6Ao4G X-Received: by 2002:a05:620a:40d0:b0:787:f83e:3194 with SMTP id g16-20020a05620a40d000b00787f83e3194mr5635366qko.16.1709335000113; Fri, 01 Mar 2024 15:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335000; cv=none; d=google.com; s=arc-20160816; b=o3MLG39Dfr90o6pbCLiVqRkdkCYgNLLJamDHOdH0HW9NiQl+Qab/GJ3BTA7rKhVuFe NaqWLwHOKtlRMFRiShSU0cfLq0HcdkmqdldgzJNuG52IfW4GJicAGRNJF7nCnipPZ2Dk Uk92dJ2ufJa8J3WCJivmZOb6OhzxeUieijiyV6wF9YHP8zsLMxPt+4KhgXmdIwqgtDeZ qy3vKFnPYXhkuKiXpMtnfQ0J90NfZ0pzSfRKxoLw/dUfgaWWtSFXt1hkI03gms2cADPi fHE53lrywuxUm3GgsfFP624vxUI2Uu7al31uhyQGFm68hOnzt3dQKOZWT6F9Roh+PWKw ZJgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vaUyQsnvahk8PvCDA8gukGjHfbLFzwV+mi5B0BNbUsQ=; fh=/b6muhdHFTPGDEv1d8xYfSbM3v1A3Ow/UiHlQW4DIq0=; b=W6sNlhHvIhXYlU3bwYdEL+cZEAmUvlLUAqDHC3fy78KUlvvyqbfsyX172bwCkfOVhj Oa2Fds7pTo/Nt4JiRwiE2E0PJHjJ7lxhcZzAJsarfxCggRvaBODxx1lCXzWpO4DTR619 KDEOrzYMdjLjr6fmT89/rcdWbBkl1Tf1rHp7CJraluFVAN4DQUBNHmEBKEcTGzSiRwbr qMYhhs6TmH8aGIeZKSvExi1yw/kbyMFbAxIwPfYqu9krzviCbFl2Oow+t5YTeGrcBk0p A9RpEFCxENVcZKw/95I8ba1sKDQGd4/egsEXMXYHyKXm3Lqv1rMD53YLjzo7TWFn7eMR Bvzw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pYE8/6ZN"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id vu18-20020a05620a561200b00787c0e79d2dsi4473584qkn.572.2024.03.01.15.16.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pYE8/6ZN"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2a-0005BU-G4; Fri, 01 Mar 2024 18:11: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 1rgC1U-0003rJ-39 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:43 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1R-0005gb-Dm for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:35 -0500 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e5e4b1d1f1so206791b3a.1 for ; Fri, 01 Mar 2024 15:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334632; x=1709939432; 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=vaUyQsnvahk8PvCDA8gukGjHfbLFzwV+mi5B0BNbUsQ=; b=pYE8/6ZNEihwLPHTBDrDs8dAqsHYmYUS59UB1CcMkgjoaFwV1Hsp7uVlsebhiKVK98 H91s0QfB5SylMhSzrjCE/yOsiVX6Ml6OTRoxBVRoTrtm2u1atEOzjnfDM9hkjI9LHm8M /qUkwCTDe5EpjrzgD7kHoQNxqIhlpMxYh4Rd5oQRRzzr8kSk7rxB/urPeWwXkeB7zSBL 8zc0mFLkaJ34BRDW4Sh6NL9lVwqtIhLXFQZSRQ6//nNjKSjdtoYEwF0Cqwi5qxkZArHh tTF2+UfG4+9pNB5+uflEEZjTNUuDEm5tW8tOovPSNBmPmqSquC1UHZkyy2NrMrmkJjgC PJSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334632; x=1709939432; 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=vaUyQsnvahk8PvCDA8gukGjHfbLFzwV+mi5B0BNbUsQ=; b=Rx6YyDpT8U/oLhQScTZ2/9EzBr5C92oXk6DMlT8+xr3X0h5lYpzwhRZp0sBBhSpth+ it+voT0N03dg8E+DHMJSzZTihNJkD0Qg5q8Lj3FoEZCR90VB/lqYwnBoqIGBT4rIR6Ez T61XgX29zglx8WL8SpVYF+1Tftd2dV+X4SntXS+OqbTD+ODhOLR5cPSm5dsn/4DeWUuM WkoCWEHNAo/EELeH5mhINBbfzhRhkPOaFB+yYkX+DBz2GLpisVLMB2Uh07RX978ep+MN MDTforgbPi26RAx9g2nA2TpDOFYbiOMn7bCuLJKLjFzC/iBDZAQZJdvQjphOij6w8NQQ 1wag== X-Gm-Message-State: AOJu0YxL0iWrBbW1TGYppPSN/BqZgHG7iWupsaGMzzlT2zhb39Oq9xzQ iMFz6C/EhRCL38H/ACh42uiL6gwxa8Ej5LxZQXXvUCLgFrgGJguq5XeTuuriVCvjz0/MAYO/Y8B m X-Received: by 2002:a05:6a20:3d22:b0:19e:ba42:4ed9 with SMTP id y34-20020a056a203d2200b0019eba424ed9mr4598452pzi.1.1709334632155; Fri, 01 Mar 2024 15:10:32 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:31 -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: [PATCH 47/60] cpu: Remove page_size_init Date: Fri, 1 Mar 2024 13:06:06 -1000 Message-Id: <20240301230619.661008-48-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 | 16 ---------------- system/vl.c | 1 - 7 files changed, 19 insertions(+), 27 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 af1a29526d..d0e345419f 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 6ab3efd6c0..512d4ab69f 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); @@ -404,6 +414,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..4c0621bf33 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -45,9 +45,6 @@ #include "trace/trace-root.h" #include "qemu/accel.h" -uintptr_t qemu_host_page_size; -intptr_t qemu_host_page_mask; - #ifndef CONFIG_USER_ONLY static int cpu_common_post_load(void *opaque, int version_id) { @@ -474,16 +471,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 e480afd7a0..48aae6e053 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 Fri Mar 1 23:06:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777097 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603268wrn; Fri, 1 Mar 2024 15:15:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWqQ84QPPXFhPq9DvKrOlb9HXkJA3ktTRxnt3jqHmuzqDJD6NPDgYhdfz9gZROhM16lfhkkEElhP5y1nIUKBA0L X-Google-Smtp-Source: AGHT+IHsyVRmpoZFhwZa4uINlq1+FQza3kTalU2dOQMHz7qk5rxq6FMqEE4y9yseH6JTJNyGmJoW X-Received: by 2002:a05:6808:280a:b0:3c1:a93c:1255 with SMTP id et10-20020a056808280a00b003c1a93c1255mr2253310oib.26.1709334904861; Fri, 01 Mar 2024 15:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334904; cv=none; d=google.com; s=arc-20160816; b=xqK7COZVeMd4/+cWh4NbczsPJ1mPohhT7r3NPr5nUaHQr5rE3gjiR7T/WfKDJQgnst FYzC1v/uFH+ZpVTfe2bSCOEcaEFNwO8UOIoSs4K2D9wHEi655eLWOFC/u5KbaxMwvUi1 pABRLztrksVOkY2AHkhFyG7ScibOnzDXX/8N7BJ0g96ATnBweEpFWqg9sCiWW1ZaeugM bWXNW2IrBz9Els6otxBPhN3EdwhNK7UTx8FW54B2A2JCIJCcj7IjV+9jO+KLJBL8r4Tq avuTq+T2CA02r326gzBZQEJIBXQoy+2GHuMKH04hQQT9GQss9a5uyr6+5T8ePt1ad18M Wlig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nFLr/Nh9lR5RHGOKXL0ktJAFT8XYevI/jB1Fp1QCuj0=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=NUrXlezCEkAEURwOGsqLvMaU1Pd4IoHRluzQyOPz8XOR9x5oKdoPJ70m6p+2HbsuZk FnSGpXVH14moVRROXp5tUgRCjvoa96/lII218xgUVIby87A6ltgvzwyay5URjKaBK0mO WgDXQK0jWQjTEulAvVYvCtWjZvox3oIyw3IjrbIpddU9/KLBGD7TvdrESTtjbuXsK6Xr rWLrq1+0jqAoSdbOdJXDcHBhzxF2XU50cpejb5EviGvH1sRnGlv3XQLcCNQkUHFhuvll doQJNu8R+v+tBrcHjw73J5/LqmNgKBcOmZahEyRJOqo1Sd5v2JczA0et3c2QkbmyKXdd 80Qg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WDyjvaQJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q14-20020a05622a030e00b0042eda70fe20si187688qtw.789.2024.03.01.15.15.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WDyjvaQJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC3E-0006k7-Dc; Fri, 01 Mar 2024 18:12: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 1rgC1V-0003rl-5d for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:43 -0500 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1T-0005h5-9C for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:36 -0500 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5ce2aada130so2373290a12.1 for ; Fri, 01 Mar 2024 15:10:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334633; x=1709939433; 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=WDyjvaQJN1OEqMugqeP4kryL6Wr58LNN0fFaHQj/alOQV/mB5YS8S3/uQVskHvrVE9 9lv4BifWyHGYVT4Dg2TJGfzPwCFyfmtIH0VgDy5PhvnIEWwe3vjnhMyv5aN5uL+3JhvP PH4+k1ds0602/f7v+z6B6kobAwL/VEM6S5JQVWRpvxMqw0RI2sq2tMawVc9BucNbRF7a JQw5db9ZKx33Cth616zVOEVhy8LrgT47AtSem1coYrWMTkxojC8MYNtpYlQVEyXI2jZQ 5GHSXwg42vu80VCGXDD6r4h3BFpIq20kt2l0B8D4HbE9gHeuZSsgPmkaJdbZDWMGXZ9X /4Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334633; x=1709939433; 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=jK+pFXxJd/wVOIOfXl3xMyglJF2PxBvf7FHvb7uGwVNtqfNCqCnsC4pjBb6XH51SbX TzjOXOR2ZnFFAW/CdqNfdpx85mUszZyrQdvehU1J+KyRWnGOEHv6PTD3eATPRdPvV8GR Ze8G7f/P1gAO9wNr+ypcRtFmoneOPEB2PGtXXlV+DgZhJ9EPGFFtrzEv2L1eGdppOUiA 5MiIXde6CYZ1F1ltzvNXnF+2fqH6zTl8J2IlQaxa736hUoYPhJ0Q4ptmpRdoKXL+brmn YLGfuIbFjuOtQBlq4JYJ8CaEmgjdiun3jBlik/ExOptdsexKNBD6Nv9/fEDPZkggL+Nl LZgw== X-Gm-Message-State: AOJu0Yz1gO13YlCngNtBfbdjKQLZohQvppYmBQqRa0xNPcKZif/yJTI6 wSCImBE5X1qE+dHYLhE7c2NO36beSpX/UHvI0kMkScFmFVT/tdhsCF4sYUEYxWw4M/zEQPJqpLf e X-Received: by 2002:a05:6a20:8418:b0:1a1:15ff:43b with SMTP id c24-20020a056a20841800b001a115ff043bmr3434798pzd.23.1709334633691; Fri, 01 Mar 2024 15:10:33 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 48/60] accel/tcg: Disconnect TargetPageDataNode from page size Date: Fri, 1 Mar 2024 13:06:07 -1000 Message-Id: <20240301230619.661008-49-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06: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: 777455 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680284wrn; Fri, 1 Mar 2024 20:13:17 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWk26TyLoLhgI6daJ/NZ7cWJViykDWEViUs5m2/Pc+n6hXKde15OjjMk+yiDKK2VAz4Vyu5reYQMlHtjdYY/HwB X-Google-Smtp-Source: AGHT+IHcaWtYBFdDfTYkBeUfH3ZvcSxnDIZWHHQ9FqSCPIElCQizsqGgXmw74ILkF709hQ1vOya4 X-Received: by 2002:ad4:5491:0:b0:68f:cf6f:6782 with SMTP id pv17-20020ad45491000000b0068fcf6f6782mr3437755qvb.14.1709352797213; Fri, 01 Mar 2024 20:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352797; cv=none; d=google.com; s=arc-20160816; b=DhDZl6Y5ZPOJu7yIRfUBQd0ylWLjVXtGyD/hzxiIQAkjMEel+ovBOIlu6kD5BqkJlQ fqzVDc2jEgEwv75a9dyAwFS9hijvRa+YHh4fmpjD3cGRsWd4xtUodHQ2CD3Fke5GUDUh NvIYLqbA3KlNcznp/BDRfU82tiM3RA22TR+Bg+nLtQZNgA0By5jvDy88tFxi6B5vDrqs 8gf/nn++3EW5Qvq+6fI3NeshkE7ZbFsXnM8YvbWqxpgtxiwPTLtkRNKIPhckzL+6M4Uo qAi3RwprllNNfccyKd2WZ5KW3Kwhsv+4RvUcm3QW/ANsAokaucqo/c2U+G+nJ6q1vfYR b2qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iM2DWBTbIODm0qN2yhX9D3hAXXDtYwow0kqtsMcFoQE=; fh=G0NodtoLUMhKR6pPncKXd0kw6+54AeSvXTR8kR6ypiY=; b=OHExtCQl9axYW8s+AA+wWjywgrXlJ+ny17fY/SMcsEYQD6/oQ8ivtZuMzHRXsZ0Thp 20XQuJuZUxpXeGxT+reb6kqVtRaPRxk0HkonZ/nkTXCImhRvjg6TDyDHXdOZVPKULLsC SBSCBpJ/D2qBdKd7sGzuz2xGAYVnaPm6mAhXqbUeMwGQVAYlF/CsEa/3vz+0HvGyfIIR PHWxr5XOIWxv92+ZRt0PZmvnpG6IrJSuveJIZpEzs8TBUO6Fbac5iQahsibJWDFfLtbw JnwZKF03VkTjU6Tmn92yj4kavRqv2qYWXxRzXews5PxUGKB1zrnzgeIuulvxJbTebo/l +oIw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q2VDXy6E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d14-20020a05621421ce00b0068f13129a6csi4917746qvh.260.2024.03.01.20.13.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:17 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q2VDXy6E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjF-0005KI-RK; Fri, 01 Mar 2024 23:12:05 -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 1rgC1W-0003rn-E0 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:43 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1U-0005hH-UV for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:38 -0500 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-299dba8fd24so2014952a91.2 for ; Fri, 01 Mar 2024 15:10:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334635; x=1709939435; 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=q2VDXy6EXcCz4B0fluG1oG09P/pGUBrBh3mVizp/k16h5/BayaqN/BkCu9yONkG9f8 qqkAyepHULzVJE6OD4F7bPY6FqyDAv+VQxBdyQw9UhFNQ4akFOpOpVPJT/9XUazDq/pu LgstV1MYqnX/id5/bogeOZh+rCzg322vZQAL5Hml3x8EWJe98sxazm4tbt34uMV8a4Ds LbOpgg1Z0LnluMI9B0qynu7rHpfwMsW3YAbZnWkFzMHkbbLhFM/8NWRevKkP2Pv4yL7Z WQ9O8rwHU++kUqJ/EV/AAskf2P7uJGALjcA0VTGXSnHeObgQ8tlRO6wfYD/sAEbtWgYB 5/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334635; x=1709939435; 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=tXA5tsIV2I3jHwxD9Rw57sPnfY4vSNqXgzP+PWq5DpsmqYZcJ6kViyCSxEETycJvRT 1SU9nAOUchM78FfkJ3hr3zn7vSH7LNAC2HTgEy+yGlfd1fIWGqhavbIqONVSkTTeeWw7 1d5yy1Q2NgWyw+YohLbcjOL1qZIwAMSCNojQrjPgGtdx9zSJRX4ZI9qJajNsoOlJg3+7 D98XvrdvEL8d5qbsoPivajVhZYpyMYa6/tYuCEuGJHvzmYJrfC7pOst6j2vdiSBv+56c TEobqx3xXOYgqlvnlo/2jQ4RnRuy/3tcOkXfREbtmN+a2QCX+Zm+LgWypVWcMy7o9cx8 neBg== X-Gm-Message-State: AOJu0YzN1f0P38PtO8pnKy/znEMRH+uLeKzVg8ujCU2l1ZJ5LiaDSbyj VpOOxAj/Csu/83KS2JkqTy8dQd2/Rb9oQi4jRGB1lQY/mrvhaX+KsS4yXLsGtB5/kmJWbscBVVQ j X-Received: by 2002:a17:90b:4e83:b0:29b:2628:6a18 with SMTP id sr3-20020a17090b4e8300b0029b26286a18mr2680942pjb.15.1709334634998; Fri, 01 Mar 2024 15:10:34 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Helge Deller Subject: [PATCH 49/60] linux-user: Allow TARGET_PAGE_BITS_VARY Date: Fri, 1 Mar 2024 13:06:08 -1000 Message-Id: <20240301230619.661008-50-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777126 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604794wrn; Fri, 1 Mar 2024 15:20:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWw6OwxTDbDiyYlEoDgjYv1Rb3cvXhIHDHMPywWfPbSuGaPmGiPpKD0zWiBfoJOvLEryrFqvx1Ieg2/+ylfJNBv X-Google-Smtp-Source: AGHT+IGUknXGEGs5RN0V6VWYS2JlafX959C4GI/LTRR0Alnk+9txdzrEYfaX22FL9CO14POL29J6 X-Received: by 2002:a05:6214:4252:b0:68f:e80f:a285 with SMTP id ne18-20020a056214425200b0068fe80fa285mr3234120qvb.59.1709335214244; Fri, 01 Mar 2024 15:20:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335214; cv=none; d=google.com; s=arc-20160816; b=WSqaiTTTt6UYWadfNgvIauSOwLmEbQ4apvXZFpB89tTa+vYZxzeD/UZgliT5JvyMcS VsMN7ZhHcmDyHJ6H/nHXt7zVLnSLWakrdG1ODzD15C5w8yR99+t0EzJ5J9aWw1sxs9uX xnffs0PohaegcSzpg+q9jAaYqEGJwBgRr3LkwxRizSDJXc0YGa8hQxYhIVt3snJVfz/f quPvZ7NNhqQR+E7lhERtyUuLgkfgI9G5EXnjVydnpW9sfH7Rnp7XGbsjs7JgGnl0K9/6 GUOPnBbPNBDJsQKeTM20tW8Yxa7up21ajnHwDjKUktJ2m7gOB2g4CM/FA7DIOm8BVcEo 6ySQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b5H5GE1LAqBUPd7mQOHglWKh/GcV0V+kwE9pYm3ahFA=; fh=akUSvRccVt8SjEp97fUPeSLjFmLWLgFk16EYqCeIvf8=; b=IqQROYrSUbwBsUT6YjD1Pudg4LwvEqtE+xL5XxNKYKTAB9q3wQtZAKwqZEpXieAFWJ 2YtKKxasDDUUQUKQSHwa5qiSW2Pu32z5elzFdQt/ODBo/4vV0OV8hTcGZp79YNXuIOnu Lv9nwqM2yYpkkTQu3+ggerTf2bBc1Q4mbWCzeVUg+7w/1OIWPhNHziE600Ea5E2s+RV+ j8IvULIl2Fed5ptjZwGQ2UK/kEUo0wqXuvuVuRuwR1/XK3Zl+1mwMvXgbyi+G1LT51U1 Y7sYDm6zyNnoAJENrV1AdBMb2scvhNSMKHnSuM/jRYOUoIqUpbYVjUknYAz2yWZxUqL1 XFfg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lJYAe32X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kc7-20020a056214410700b0068fe50183f4si4581578qvb.76.2024.03.01.15.20.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:20:14 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lJYAe32X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2Z-0004tn-8a; Fri, 01 Mar 2024 18:11: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 1rgC1X-0003rp-Gv for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:44 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1V-0005ig-RL for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:39 -0500 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e5d7f1f15bso658681b3a.2 for ; Fri, 01 Mar 2024 15:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334636; x=1709939436; 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=b5H5GE1LAqBUPd7mQOHglWKh/GcV0V+kwE9pYm3ahFA=; b=lJYAe32X81XPDf+gXyZgIsourEj2xnRFoqlWjxG8mNoZbq2djjMCDm+JjZY6cJkNL4 NndUDSADBbMEILefks0Ezfa4Md2/hG4IA2ILhKWm3rvclj4OTu4Or56sH+mYANCGhn9v msGoRxLf462rbgJYpmaI8B+7b7xXPCSdHvGTi9qSrYoGxOL6kqMxBLQrjPkenRWtOdHq YBKj4xv1ec70ZWz7ZZLn5os0Zrr5v87bYZlWUf/KEGe2h9KjAXuWiGavP+0p5H1ghvsd TZlWD/hdSf1s2IvoYyYxFkvCTPgKIuuMyyqNXQp0ubIxg9jE5k+OLlhfGW/cvlDPPEbn cigQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334636; x=1709939436; 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=b5H5GE1LAqBUPd7mQOHglWKh/GcV0V+kwE9pYm3ahFA=; b=eaBRBLcnC/bGv73b6IpWqbNoWucdNCVhls7D+PfVCZtZMuKuiWnnfHag7U9xJBe28k pqXB1yj4GiwCu7JFpEUupwH/ZQhGxUKorpgKyJdYbjiUSh1P1dZ6IC04t/z7y7QPmGEF OpR1NUT3sFIAPOeMFJgtooOhlYPIDJG8Y7QTPFsMjIRbkD+trXdpYh7xU9e8nkryi85v j5EQdS4tCY+xf5jfwV8apG+4iXZ9VIZTpxPuMgJOPncv/rhAZyAAzXVosTu0XqAwVrju C4mcxLn3U4MXjvspnkneoEm9BOv2irWGqvtWaYAi8HtH0kR634ulW+QKGASvNm9YjK5D IFeA== X-Gm-Message-State: AOJu0YzWaJRKeHebYlt9NPZz8eHzQrcun2NoSKi+cf6367lqKnVhYH3r Gqrot1Rn7TGRI7HglOYjJtqxn6RI1osuz6WvoCSuruz3DZ0Hn3oizbx+9ptDmcKwwY1F7tOF/YE W X-Received: by 2002:a05:6a20:429f:b0:1a1:461a:3a04 with SMTP id o31-20020a056a20429f00b001a1461a3a04mr397633pzj.8.1709334636656; Fri, 01 Mar 2024 15:10:36 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Helge Deller Subject: [PATCH 50/60] target/arm: Enable TARGET_PAGE_BITS_VARY for AArch64 user-only Date: Fri, 1 Mar 2024 13:06:09 -1000 Message-Id: <20240301230619.661008-51-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 b2ea5d6513..f3ed79cef2 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 Fri Mar 1 23:06:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777118 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604226wrn; Fri, 1 Mar 2024 15:18:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUYfZ4BGTa1YPMzony2cfUSt5mkjTFuIqcULULzCEUA0j5nUCG7qw7uDS/xfE1Q8+dviQhzf4zX2AksvfbiwoZ4 X-Google-Smtp-Source: AGHT+IFrsOo7M5XVk58+qqMVu2Be+2KIGa/aQNyOyMbVKCzKup6G2zERq2VLIeX9yNug62jxZjBd X-Received: by 2002:a05:6830:2643:b0:6e4:8d2d:64e5 with SMTP id f3-20020a056830264300b006e48d2d64e5mr3470950otu.13.1709335080289; Fri, 01 Mar 2024 15:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335080; cv=none; d=google.com; s=arc-20160816; b=hnllHdnmVQLEElFdbS6Rjc8SFph100TUzgpxHROeFai3zuP4SCwAbY+cqvk/5Sd4kL M3k9rvdCUEpZjIAELZsWX1Ms3tI1bKRiHKU93cnJvclaQCOt2kSHbX/DM16WqYJg1/kY kfdX1v6tjl+HvBXuGs14mNt4BiD5bl7vE99mdWZjH+TqS19tH2V/uAgqbHSbo/hDmtQ9 rXmtE6BnMKmRql2uTY2st/Z2DxAFRI5oWsW1ITBcBhtQgrtxO9dzO7GtbwJ/hyLHPaIt JNYNkOIfkoG05MzoM+iV5J/TO5P8V9ynLzjgTlgnfX4ZN0UjvT8uJXCWZcSXqNA+uXm5 ++Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e+A2qkcrgjaI9rrkh97Ktn6PEwqN2bQkXlFCXE4NZ3E=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=mAi3TTX/tjZpOWxL8SvQdVyvb7dMEPlTiGVDjGK2KOfmIM4GtYYhSnsMlFlIL9lNvP MTeEaTsqPFl8Bz8WZow2N0kTEUC/Lj71V+QBP2KQXnwNDwIuSctOeMSbN2LSxLpaGBmS 0fCTsc77wwDpS+dVu4RwD3b5gr15gPaq+7JfQNu3Y9jKpRdB1PsieefZzGRr4lTTY7/7 dDywWPlAZNJsnPzwOcbVgaWAWI+gynfBepCqH0zG1GHBuaiG/hbSHSsuRu7mQGpBDBMk gur6+o6iF/dFbWZFY/1EN7f09rJc71SfD6t8HAMaNQ2EaDSc3EZezS3rQZPYcXJnuBuE 3AXw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oeJcwtgT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id de17-20020a05620a371100b00787c5bfbf05si5074184qkb.784.2024.03.01.15.18.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:18:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oeJcwtgT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2c-0005Vp-6V; Fri, 01 Mar 2024 18:11: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 1rgC1Z-0003uH-4D for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:44 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1X-0005jU-JM for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:40 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e09143c7bdso2082525b3a.3 for ; Fri, 01 Mar 2024 15:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334638; x=1709939438; 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=oeJcwtgTJX/V7lI6hZT0mCyUq2eAwP1+2UqSQvIyRvdxYHQjqliIBmWcFvtsN4s+qE CZ38ZAQ00r4dOFdlQbGIEhLu+lCjf8e3Cf6FJgL+j6IIyvIak4m/I/kzMR0tCISI2WjL AuwcG7wxFTt8AWLERUFZI7BXoyO1HuVK1nx3bZZ/rfE2x6eZajCl1GrI3qO6SIBN6TRe F0N87W6Hxln0vWQzESLC+gizBVAUXefAIN02EVHH3FKAkBmldXKDCnDPUP5tR5quMIbv Gnq6n8eRUkPPgp1JjvE88WpqyvuR9V8SqxzU//5a2n6zokBAIjNIUmVv6Dh+6Lo0K64E f7Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334638; x=1709939438; 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=EQKBJ1NysGWbDyryifs+Yvcsgq54VJLmpqHNh7hYEjmFw+KHY3qtiat6W58Xp2326f Zwhq4GQ9yoBg6nVILyZJAlFqpOBdwJgI7D80b5cHh491zf8bwlvOro+GfzwXjiPJlVXW jy73tcKGF4/I2fbMnyVKJ1GQzfzAGhS8wDSNxIPCLyUC67hgf7ze+fFcFosmLddviyNj cdawZPycjTCOFnlhKcqILMrE88LLMW8xae2DLs+EuV1LhqjBIAASIdHWNVarZ+NVR7Y9 gt3tZiccUQ/CHuwsIQrQ1gYbFfAyxLG6kC3xQd3+k7+Ci+6OCJbsUToNhYB+QvaysavM aKnw== X-Gm-Message-State: AOJu0YxKYmL6XpS93/qMpSW6lQJdgCLJWbDELHOdOqOf70EVm3dZNJkt rBvTS8AqzuE0Q3tEiQWs8q5qtmm16wonH7ec0JT1vGZHWFX9SSZz+KdukPkmIGR2axxmFyLfVzY O X-Received: by 2002:a05:6a00:2188:b0:6e5:5c83:c459 with SMTP id h8-20020a056a00218800b006e55c83c459mr3027504pfi.29.1709334638207; Fri, 01 Mar 2024 15:10:38 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 51/60] linux-user: Bound mmap_min_addr by host page size Date: Fri, 1 Mar 2024 13:06:10 -1000 Message-Id: <20240301230619.661008-52-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777462 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680378wrn; Fri, 1 Mar 2024 20:13:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWk1bmQBfmx+FWC77dpCNkjzLq3jgSNBxydOwaAQuhfqZOvS1bM4tYlfYqeHdG3u5i4HqCYDlD+7WAwkzs9t+NW X-Google-Smtp-Source: AGHT+IH1JVpmPs5ZG/Obr/Uvvmfee2+w4iipBFxqjGtYqPeAA7hKiggJlcczFHSfl+HyEjmMkAVw X-Received: by 2002:a05:620a:21c6:b0:787:c5ed:16c with SMTP id h6-20020a05620a21c600b00787c5ed016cmr3496741qka.22.1709352817511; Fri, 01 Mar 2024 20:13:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352817; cv=none; d=google.com; s=arc-20160816; b=X36GX58uBAoF/QhV4llaWRyI0PGFL1CdYZ2gpdKxZOtX13k2p9knKdLYdn+wnTS/i8 bYvaiDmZknmr15NIk3sSindcAW91hDQtW/xfKDfuLWUjlWi1OIJTfsAWYhrH6FlOGlLO JyyeW8HdaUfhlVjT6XKc/mDevuYVRCtbj1RkOwZb01CnAwi31fJKQPibiAkJfh6zdexh 9voxQ8EkM6E6WY+orw3+p+QxthlkneBkRV8y+9lLkn4a0urENV81LBZxh8mrvQod5uCP cf8WrV9j+kp/O4SarDcG6r41jI9G31F/tjQoz5pspAjF/0/0XB3PM2OskSzVxMa3bvi+ xwPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KYeT1V/wjgovpdrb0SONHx5NJHYkyLqzQDA/KKTsreA=; fh=H/IsS+LNYM6dBDHt5BZPsM5V9tnyjdUlJ92VVuTs62g=; b=E+kHaHHY9zxbY2R76wwVtK8T2dkiui4EphydlR8Siji8GoxmnXYuVJZ3DTrWUsaOJ2 S2ez38sJ+amUMu5q7JXFrS4+G6oenUndQeftQ35MtzEbQDYbAoAlcoJB54+ZJhb6XCcA LnUr21W4HGr8icIEfO1fL0ia3Vyzx9rYT92+2IUlYsAyVMP39w7qfG9yMrh7HADtS3qL kJZkPb1buW/dfITaUGBYjVxV/dHvS1OxTeTUFwIXJ1acIHZTSdWB+TdGSDeLf0McXqPm /L3roCrJMXfWfU5UN23HuD0CR7Y1fPR7FGUS3NrFt2iMuISRrOykulQ/JOxPHOZRWF+E Jiaw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bfqqnoQX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c25-20020a05620a201900b00787ad5a987asi4868027qka.185.2024.03.01.20.13.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:37 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bfqqnoQX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjG-0005KR-I7; Fri, 01 Mar 2024 23:12: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 1rgC1a-0003uI-BO for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:45 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1Y-0005kF-Ub for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:42 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6da202aa138so1999747b3a.2 for ; Fri, 01 Mar 2024 15:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334640; x=1709939440; 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=bfqqnoQXRtRu9rKmqZdnmlMhk0tdTgJzXJIUT59zAG1arQWm6Hpj1QAIg6CIpJBW1a 0yZRluUF2/griNTzM85SXrU5j4IbQIRJ0GIEPDC4tCQAsHdzEVuDHmQbABCqFcQvU+kX fMVL4SaFktGze/Dcv9nJoPSLzs1kteE9rlKFqmuvY1Rpc+Qo634bzt37woi8/72X4tZt w2l0lNoVI+usYtiWIdNRm9THgSTMmuWuF4CRC8EuY9eZdTg05jE600AvyopV5i8nzFvq wer8nx6+suO0fOPtG+/q8PCEU6uQxEgrvuOqs2Y8QQpmvvKqTWzKrVCbeWK7OmW+bkg3 5HxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334640; x=1709939440; 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=Co/4c+kigvCJYmHFz8RabJXgzvPuHdwLqrAf6xbKP14TDkSCjmN+F5SgcmLWy2gpoc Mkw+ffA4CSnYaYQb0AiiBeKVSVGECX+mRQ/jzX+9pGyL2VnChY4fiYc2fHusVGTG8D0F OicgOS1If6J5+L0xhiCKatnl50gZxbkQtxxJByW0A+45B5F0QhUluGLTs+YKGHViOgNs 412DIwv7qzm4AHQKcEvFnyyMc0l4GX+16WyABcwECptqXhAuO+HENg43AzxTxkMcqAxr wLBB9dPCXi6fhqSGFNCOUc5VwwZEs1qE8tAxHjxnIhyC82mdSMXX6vwO2Nxn85+WON7x 9otw== X-Gm-Message-State: AOJu0YwnS/IZWrEa5eAxuA1fwevHCntG/TsM/5Wj2hIkQ8eftrs/Rw33 fuw2RMFsS4fydA2/hsuEDDITXnX386m1nhUHmYskY8U2kva042L3WBZWpUQlt1ZBbELv1d6Ntq1 / X-Received: by 2002:a05:6a00:27a0:b0:6e5:5f6a:4966 with SMTP id bd32-20020a056a0027a000b006e55f6a4966mr3790759pfb.6.1709334639677; Fri, 01 Mar 2024 15:10:39 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich , Helge Deller Subject: [PATCH 52/60] target/ppc: Enable TARGET_PAGE_BITS_VARY for user-only Date: Fri, 1 Mar 2024 13:06:11 -1000 Message-Id: <20240301230619.661008-53-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06: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: 777123 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604610wrn; Fri, 1 Mar 2024 15:19:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXBAlmtxecJbe3yqhGEWQhGvu4gyRBFdX8n5DtLIiEuT0aZq9Gu7fRu2EnaLQAwblfqX8Zd4Oh90+n61Ds7iMQC X-Google-Smtp-Source: AGHT+IGJ7ueqDa8UdJI0qXygRhn1VMyrxDskWsPOBKmKMYr7tfu7SV+D6gXbQ9MCojaL76Jc7wNy X-Received: by 2002:a05:622a:1448:b0:42e:b87b:cb65 with SMTP id v8-20020a05622a144800b0042eb87bcb65mr4352966qtx.24.1709335173514; Fri, 01 Mar 2024 15:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335173; cv=none; d=google.com; s=arc-20160816; b=ZuOktHy/0GaKKlqAaaArhv+D6mPidSFKZ4UxPn3ieowmm6oDa0jDzZ/eXcwXf0uFkI 1pERNsDHCX+G8egMgBSZgflqYF1qXXT2DQ1RfVVMOnMdDLehqHDAHrgNWC1E+seZ/8xW G8kUt4MzLM9lz+Hnps3EFpL0em6tNYS+9vU62wDwMnX13KsIJsIyUbKawnUXnp1QF2Uj 3ja3XFtd1wNfLXbP05MobFCu3/fSHmT/W4mcCqrtBNUCL2ZKzkcloiV0qZnO9LZLkRRZ OczD+qJIFUVg6DBU9lbY9R1nvS9YIbAf8OtpYLIo+SwNo+yfjxYiSbouan1gN3t4vK7I lttw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nZgxz9sv+Wfw3NEh+PaVP4+cTZIcAB3l+Ojbwy+/FqY=; fh=TypceWkQqZAd58MbMvFzjbJhJVwYT3Z2Jon575mPbgg=; b=jhYUzN/IlR6AtPoBqCWltU/DVsvA6HNLU90Ks9AkKAmC9citjdA+b4dvzk8aJBBXb+ rpxgfPSCP63W8lTavJr91QtMXYldKJLGPj/E0D/lAtLa/wp+SfsKjKeEETIaOsu/g+tp 2g+VvrVxsDi48zeIqVMbyx0aUbzXsHQj6vmfDkW0awx8JTg3u4iU3Ncgpy4SHQ8DXueu 4+iV0fPh4HotBoqUv5oUIjiCeuFKKtRLj2Ttyk1tkLiS7/F5Qi3Vw6Ligqnh5t6kDOOj wvDTpCOggQ7S3PuTJ5H2SfDhQvwUOzdkUdMqhVksLVsT+PK3vusj0ArJYpKzoxipSz/q pT4g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JoQqJsuk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i1-20020ac87641000000b0042ebbd4d8aasi4117342qtr.260.2024.03.01.15.19.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:19:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JoQqJsuk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2b-0005J1-6b; Fri, 01 Mar 2024 18:11:45 -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 1rgC1g-0003x2-7u for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:52 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1a-0005oY-GI for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:46 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e5dddd3b95so361791b3a.1 for ; Fri, 01 Mar 2024 15:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334641; x=1709939441; 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=JoQqJsukC/sdCxYeC04RI8lTFwT9Q/Vvt8iqAEY0Q5kIANSMH4MBIAfVoQJbl7l36n UseZ6Uoi8+2UH2Z56ltL0or42vOAZxeUBYiyBPJQ4n8+I1jpDchF7bgjSDjrdZK4lg1i xrikDcw4M/S7xOxE+PJOiPh73Ib18lkCnSzXqWn131Xx1J8xC+C08r2UuIzPMziq/CDb PYh272ZPZMvfTm4yjCNI4CFeqLCCgI/jzvAbQlRG5WpS0su4GSYNTAtdvvjOQkI4unrb xQZan7bcYGmC/SNNaQFv3HRmUMmfW73wVf1eHuYtM+unqU/jrwy7qmvq4Pt4eEJ43g7u /ymQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334641; x=1709939441; 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=FcJ7ehP3o66QutpPxtR9ZrZ8qDXIE70ZKObZktevcfy6yD8lU95S7lvqjCt9n4QJMH iZu3PL2DClbXayfkmKmNrHtedsGnfp2w7MDA1TXrCYsqKtEgpkV58BnOJ1+4BP78/zUO idB6RovnKIgSOsRSLnAYHR9KtALMyHxHyBZgR1CoB9Eo4eIQRhMbrnSPuJKz9Wtvw9qz TcHjFrC0fXF8yyP5hS5tgbuzKMdX477RysCJr41ccBeFp3CUbC3hPwgwPZeKBiahG2Fz 9UcDvuIHmFKPFQa3zJmCdk67CFeD15RmWgGdyFC/Dj0JW8QIrWfusuv3KKqJc+VYSFhs OcHg== X-Gm-Message-State: AOJu0YwO1bBYjTJE/piM/3NgKB4lt8wI+oW4lRFqnBl4VBUI7ABYMRLm 2JWYfFEnIFmNkshm5i/H1jca5T+q1Cmx6Ca6KBgr4RO++QrcEpNYy2ryhM+T+i9J70jbNqmPRBj T X-Received: by 2002:a05:6a21:2d09:b0:19e:3391:343b with SMTP id tw9-20020a056a212d0900b0019e3391343bmr8982155pzb.27.1709334641195; Fri, 01 Mar 2024 15:10:41 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Ilya Leoshkevich , Helge Deller Subject: [PATCH 53/60] target/alpha: Enable TARGET_PAGE_BITS_VARY for user-only Date: Fri, 1 Mar 2024 13:06:12 -1000 Message-Id: <20240301230619.661008-54-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 Fri Mar 1 23:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777457 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680293wrn; Fri, 1 Mar 2024 20:13:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVvGp9VSAvraljyP9Itflvp9UNUHjRd2FE7j7bVhlIWL3BVJphxt5n9vHGaiOWovKLo7y2DI7LGtSNDUf/eXT9d X-Google-Smtp-Source: AGHT+IH+eg6HfQE54gkoZHiVDpBtunG7VCgP2VvWYeFgZS0jp3x2MDU1sxid/8oGy7UgW2aP+TTg X-Received: by 2002:a05:620a:4153:b0:785:d64e:7165 with SMTP id k19-20020a05620a415300b00785d64e7165mr4159041qko.27.1709352798673; Fri, 01 Mar 2024 20:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352798; cv=none; d=google.com; s=arc-20160816; b=k6EWWs2pkW9m49UORg4FGedbMX8gNW9YjpdrXrnYg1QaPQZas6ijd0jSfew+SxJFvB zJgC3pfuItHUwQ2Vqo4+ip4zL4cEkNMQ+rpPty/8UGGfj0h4+xD62krJoCdY3oaCziMs f4P8nWG3Kuy8Acv4eWsTpmsdvL75b7wKaauOk4wPgsDc0BEc2wcorXnI7E4DeOZGdaOC hIV7L2Q0TC/ggAvqWmj6HFEvUPHzjkMuI0qbt0YwDtY6vmRRbBzuEoF7UawkT39wSTGW U2LVvtzhjRVLdhbIbkPFVinvwmHkXFOfIExHsoZTDu2+m9io5mM0PtZtFGtS9VZsjH/w GOdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oX3KBb2f91IJNoXnuOHaXnVXtCOeG00rM8fZbeZEXms=; fh=n9yYlS3e5p1jbxxEgLLpo/4j4A1mt1f9EOusxpOjlc0=; b=Y84nlSYV8q2HyK8fSiWzlc08rB6pZ9Rif+hsSEIs93cDK/2HtvE7ABlMm9FJ52beeL OEiHr48yk78/1JiYyKqW2OxZ3z1B0m9jI/YZol4zWh8kGxOpg2TAd9asBARThsfyS6h8 +WwFda2LQU7HU5oQACemEZd3IJCtLu83InETApwT44m4iy855il6E96I073oPUGmDScg s0BCdpq30nYOzo+8IN0TsHyhNuJ67fg57RIOmO9RCTgccnbyahHkI5wCmhXJPGRUZErH SLhz4hFVcaPUvDJ1Gmt3xPjfRSnkGcLVuZmbF1re0VueRK42e3tjPY4x+Ux9REpYVIbH 6OjA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y2kzzu14; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id de17-20020a05620a371100b00787c5bfbf05si5539648qkb.784.2024.03.01.20.13.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y2kzzu14; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjL-0005Og-9E; Fri, 01 Mar 2024 23:12:11 -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 1rgC1h-0003xE-I7 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:54 -0500 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1e-0005oh-Bo for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:49 -0500 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6e4d1448d31so422776a34.0 for ; Fri, 01 Mar 2024 15:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334643; x=1709939443; 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=oX3KBb2f91IJNoXnuOHaXnVXtCOeG00rM8fZbeZEXms=; b=Y2kzzu143heSNZAnx63b8aw5dRDxKrc/OcgUUwdoPxIsZzYPtCJeUEInAam2leFT/7 OJWBmXrWxCpqrmMAHv9/zM7y42ANO2QqCk4ZQcqaPGvGDCaVakniGB1GnD7cTMCwFny0 Hfck20eFgXAfXMVL3/7Tp9RBbWcTCmz4GH1jEDsXjlagfUtBt8ButtRfO6IjPMz6Wgce 8gHpcCCZPRUxcvN40DtUu5sg12yHb07Hu4G8sAHDCXwb8pGBTnvcBXY+f7U6aNr7phx4 LDi0e3j22cNKJ+ZmESOPoirHs2ZfxRsjJJmU4F7i7ephhij55y5vkmuQIUukJVP0thFP z6Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334643; x=1709939443; 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=oX3KBb2f91IJNoXnuOHaXnVXtCOeG00rM8fZbeZEXms=; b=FJip0sxO86oMVF9KjHLV3hQERMQ4x5jmmwggcn3qnf2lsUtRn7sPB4EOdj8qhv6TqX 8BnNF7rSirCcDtSldWMY3H4A9pBbZj9iAHyXY9QwuHFDF2htXHhaHrd6J4W4lV5p0gX+ KmaU2exSJrciybCOrboWxYTiyYC+A/qOZuNH/LRreBUDoDLOmS9ULSZ8C27CzRQaVi5+ 9J7Cud5ulFxbh1VIUos0hbVh5NRiJfTmRICKLKHlpKXT7B9g7Rv6RfCZauLXOTLgyoKb o4m4JWUROv3ywWjYb12xsK7ht8jNBzsSMdXqo5IBOB4S8AkmXFzR+5Pc070NUd6k3YSE ecIQ== X-Gm-Message-State: AOJu0YzrJa1ujp3K0oAojLRZqIxlst4BwHobXVaroUIGl5OsP9rlWdZX XxYrkK5617b3hVye4xotRhFlAOOlN0OrEnHLXN5Lv5P3IHkN5Q4vZvxx/m2c7MFaFtLwpabtnQD O X-Received: by 2002:a9d:63d3:0:b0:6e2:e2d7:55fa with SMTP id e19-20020a9d63d3000000b006e2e2d755famr3233569otl.14.1709334642949; Fri, 01 Mar 2024 15:10:42 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:42 -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: [PATCH 54/60] linux-user: Remove pgb_dynamic alignment assertion Date: Fri, 1 Mar 2024 13:06:13 -1000 Message-Id: <20240301230619.661008-55-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::335; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 cc2013c7b4..0c299a7c15 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); From patchwork Fri Mar 1 23:06: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: 777124 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604744wrn; Fri, 1 Mar 2024 15:20:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXTX9BUzh5lOo3x5ZiXEYS5T7epqVHxBCVJqmCGOSkrcZ/NIyay5ik/25LnVb8LE1qiLMtsy3eEm1hm0oR2JjRG X-Google-Smtp-Source: AGHT+IEr1TUc5N5YMXmN4W7XDx2EZcjmykPsKOB/YMXb6VQCDgYLS7QGEV+69VVLVItvCHWFdo3A X-Received: by 2002:a05:6870:698a:b0:21f:dfd8:e962 with SMTP id my10-20020a056870698a00b0021fdfd8e962mr3599577oab.0.1709335205441; Fri, 01 Mar 2024 15:20:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335205; cv=none; d=google.com; s=arc-20160816; b=A68Axv3yvc3wTJ8ahyPdIR613WULLd7NkryhU6NnwQuANHWnwVcDwnDnS38xfSPsJF fDYna4cZz3sANRwo9MG1IZmHyBNbV1TtDo1+PkvzQDCBAdRtFq4dVRPRW293WQj38d98 LfXsMId/nNhmlZ+a3PnaZ4cmhAbg8khEdYuiiZWoYB5peqiMslQlSvNKnfjvwzaMyGwP D3mnCLyGtyy4pPRlBzFKP178PctfCG7pixU6Qk16P+ka7IHSKF3BoeZfYcfW/bKKE/qx gYSeuUCHG0jYL/do8t50WRQ1gsAw5HEauGdvEUsh7z1gnDJvJ3finnBfHKwgmyeV8U66 5v2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mnZ6WGfrFw+xqlID/o+DhOWiMwOEcHx/bjX2Yi5iHU4=; fh=Qh1fDyeKF6RN1RJuySFfPJyY198jyWlhb0GvHOCyqAQ=; b=ZmevUbj/7FaGiYQYSKxoq5DIcq48o7O6AHZO33bmu/rYmfcuy4Z3EsIi+rL18v0EBy IUG5M4a/TpCthN9x5ctZFF8b09mkYsq8JcJ4QZqpA+GyRekiT+bpA6jTUgwnfdWDwp4M zNEZIUzwtdcq2uG1t27zwTjWaasFFS94kDX6+7qNYLZeqV7BzWGsPb+GHCsLIY96HZC3 6c2raBGrWM5uJhRFBQGQjN/RMSIyI+M6q8//e6zOFwcItJ9dczqC/TTxTvVEBXyhaaxz Ne3t8k/u7Dh9qtOBFuYWs8q87caTJAbc0U7e1OTUzPAlh2VRI+BXbc/CAsw+0XYW5VRv /3eA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fcp1o/8e"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b10-20020a05620a0f8a00b00787d6989706si4503651qkn.98.2024.03.01.15.20.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:20:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fcp1o/8e"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2d-0005fq-7V; Fri, 01 Mar 2024 18:11: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 1rgC1h-0003xC-Dd for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:54 -0500 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1f-0005tx-Pp for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:49 -0500 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-365c9d37995so8900715ab.0 for ; Fri, 01 Mar 2024 15:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334644; x=1709939444; 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=mnZ6WGfrFw+xqlID/o+DhOWiMwOEcHx/bjX2Yi5iHU4=; b=Fcp1o/8eEYU+rAHbsGUFfNVqvaSxMiVYRpVqnpudw/WTgNzqt4niI7u4bxZRaDqMab kKsdjabPM2PK5vWHCMeTj/3z/tkPWipIKfPEJHT2qMx3E5S3HPqlo3ciRnmgqoZj4LPB LSz+UB5vINbNq3/VEh2xn428nlWmWOm5Wc8xYmWXGhULsovBhjHEeUnq8j6c50BfV8if U5HHzkG0s/kaxz9XFlDcasdIs4jiNvLDyMGRbFyUKeo19JIBAPF5lXGVrCKbVNhU9foB 9GQq55k4ArmR9BTzD0qBgss+Y7VxLt2U7kcqPCCF5JXFopzr9q+nBHTkBTPY7M0VOqzp j2yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334644; x=1709939444; 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=mnZ6WGfrFw+xqlID/o+DhOWiMwOEcHx/bjX2Yi5iHU4=; b=bBbkX+sepe6tajrrhCi6Vew7PUfPoZL7pO+9Dt/+hEbfoU+XzQCtOJyFduGiFdR1zd epe3YMdKSfhPaDld9DZr2mUYZfLVxZZAWRkzyofLiADmYIQQK3epwkkgzQBXATOwozW/ vh3Etd+yH6RBQdgnvlR9FrhQLVY0QdnsiuDII0q1J6pNBp/Ssc1zNmE2Z+bvvnYqTnmQ 4eZiSzd54UFziUAjQXi7So+WoTI/hSjwSxk591knvQpZK1Igenxp2Ea9pzmJ666aW3Do CXgi1hkKAOB+e901wF5oxSGG2P03+allQeaugx0pYGcIY5w3/wtwUTqTQcbsUJrB1RiM xegg== X-Gm-Message-State: AOJu0Yyzlfvl3iHoqhBYj/FUxFz2l0+Y7xQMZFAxGl3Vf9aqCyXxv1Yf 8fxYDar70mcxxzfjvhxlSu43Xo9a5x1Q2n8iLYf+I6YxsuEJjIOqwAy5pWjKCdX1zdmensZRqnS D X-Received: by 2002:a05:6e02:2196:b0:363:c576:d6d5 with SMTP id j22-20020a056e02219600b00363c576d6d5mr3651397ila.4.1709334644356; Fri, 01 Mar 2024 15:10:44 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH 55/60] tcg/optimize: fix uninitialized variable Date: Fri, 1 Mar 2024 13:06:14 -1000 Message-Id: <20240301230619.661008-56-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::129; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x129.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Paolo Bonzini The variables uext_opc and sext_opc are used without initialization if TCG_TARGET_extract_i{32,64}_valid returns false. The result, depending on the compiler, might be the generation of extract and sextract opcodes with invalid offset and count, or just random data in the TCG opcode stream. Fixes: ceb9ee06b71 ("tcg/optimize: Handle TCG_COND_TST{EQ,NE}", 2024-02-03) Cc: Richard Henderson Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240228110641.287205-1-pbonzini@redhat.com> Signed-off-by: Richard Henderson --- tcg/optimize.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 79e701652b..752cc5c56b 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2102,7 +2102,8 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) static void fold_setcond_tst_pow2(OptContext *ctx, TCGOp *op, bool neg) { - TCGOpcode and_opc, sub_opc, xor_opc, neg_opc, shr_opc, uext_opc, sext_opc; + TCGOpcode and_opc, sub_opc, xor_opc, neg_opc, shr_opc; + TCGOpcode uext_opc = 0, sext_opc = 0; TCGCond cond = op->args[3]; TCGArg ret, src1, src2; TCGOp *op2; From patchwork Fri Mar 1 23:06: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: 777465 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680642wrn; Fri, 1 Mar 2024 20:14:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWt0+yqGoxmfCEsuBLoI7eMt/smhI1EFd2ntGF3/3TYS/rB9QQ3Cnr94jLjBZtAqg+ElYmoUY+eaSRK5iqr66+x X-Google-Smtp-Source: AGHT+IGN4nhzkuK3G8gYQc/A3x25ZrTygto5DkZU66iDWqf031b1SAYoJ+NqDnTIo+/IpoPX2tLx X-Received: by 2002:a05:620a:22eb:b0:787:f4ad:8268 with SMTP id p11-20020a05620a22eb00b00787f4ad8268mr3442965qki.29.1709352883794; Fri, 01 Mar 2024 20:14:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352883; cv=none; d=google.com; s=arc-20160816; b=YfIHB3YNFkbj2Lf2p350hrwOSe8YYzgZmeCoiIpUsCRiIzu7JEagqTIYQfGwTyp4JZ saqxxkuuuZ8OEn3TQXBgMEaQ+UlxyrcRdpUTjMJ09qm1msU3pJUHmUTQ0q2GXxXPOP4G L+xgvDJ4zrkcJkbWkg3/OelpMJ70tTFeAWYrVHwIOcpt++YJtSqKz4tjGm97iI8ZUVaa rkfUVaCMmPbC8y+NtUXzKMgm4y0KF45o5CovUT9IaN2bE+xq3Ao8YVtt/8KOd3sHqp4G VN0UnE8r0dZnvEgEPatraRxsGEwO0CyLmV1g121D4XVFGjxncfCC4qPsASTYoaA8DXvk JTAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yTWT+RMoE1i/VU7YNW7VXZJeWBnC/6JB7arqg8VoVPY=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=jQ5ADkT5xEEkBHUg7b4EmFAuv4anirDa13WArd6kj7amdjEcyCFjoZkwbpFyXxCt5k ZIXu+aQ72SD65ingax/VW+NhEixuuQModhe65eEzxyz9B7Jw68nqqVVg4x/qU7y4VfxT 7AsNwSaLY3QAx/oKUCjBvUL495ghrglLIOWtFUtolFXhDQdg9oIjResE690+yw2x+6rg 8voGbzjwNjI/pQVnMcgnl04dZrrhP/YUot8tJ7IKH2drWah9+h+IQAkXcG7AY+1udSft 0a6A2DKLjaE9q2ciHJGiFG6TyXK6LZkYXVXdUKQHVyAXpjIXa+6z1XsqtWtgzEKwXZby Jjkg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wPPgO3Az; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b8-20020a05620a088800b0078770fb0835si4833994qka.542.2024.03.01.20.14.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:14:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wPPgO3Az; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjI-0005MB-0d; Fri, 01 Mar 2024 23:12: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 1rgC1j-0003z4-65 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:57 -0500 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1g-0005uF-04 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:50 -0500 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6e48153c13aso1388239a34.3 for ; Fri, 01 Mar 2024 15:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334646; x=1709939446; 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=yTWT+RMoE1i/VU7YNW7VXZJeWBnC/6JB7arqg8VoVPY=; b=wPPgO3Azw4RZNrbdtjDazpIblGSuGm+sz0IzwuS0O8fW9MoBwtkqB3w81bNDlmfZIq T0LL8c6N5a2yBwanLH6OUQ9EO9ZN2ytZb3lBxO4or+6X1UxK3FIeRS6JgiAj8TZpHCzZ L80gvYehonUdo3F/eqlnbsSjTSpq5t+SX8aGV7CgDIT/jUMzzkWBDVz6HaRA+j93e5B4 8jANdlMGCPpt8UzEw12nRYTDoe8nMvUkArMj8QyTaElgAFIq4GT8bJ4fa6t+ZwUfVuZF uNwFES1C+aVNMn+BlHAjE7SkDqyPVrMIvw+Sg97iXPlcFp6fqWjHD24wDu0qHyZiJjHi EUSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334646; x=1709939446; 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=yTWT+RMoE1i/VU7YNW7VXZJeWBnC/6JB7arqg8VoVPY=; b=sI8yS/SzQwZfu3V6MkSA9tjNEaj7hFAHl0kTVpOP7sIAt6BaLBZkhNr303MlMSKDri HXgd4VfEcJ8L7RvYgJRv6SGUaXo25lEOplJ4EDG4h4V9PiQgiiyeUNLQvgQ9SPxPCq/n BUpbeOSE1nf5fAIrE999WQOxQa4d0PLrAHwJWL/NXlvnolrGra8DOoLD0XXap1XTp6ve D14x7URIfqHgqADbevSltXsdx4vduDgdwTgn7FJp0j2j3tA/7LjoU1a++dE1/y/XwROU LsRzBWu6QsLP/xVE2WGjFlRRV2Ophi+yBS0B5+FDtMU6uOPJshhOWO8U1Ns4o7r5vsL2 zVfA== X-Gm-Message-State: AOJu0Yw2u7Ha+diFY8vTVMWP7OdfZXQuIq3hqFyrDJDUNwWqYB/jqxM4 tUPemdLmJjDhdBWMou9Kd/bPVY4DCT51vgXaZ8+CLnR1HTcUly88OXPX1Z1L0iE0W8FbmHvrb9K G X-Received: by 2002:a9d:6d85:0:b0:6e4:7e89:1205 with SMTP id x5-20020a9d6d85000000b006e47e891205mr3873115otp.9.1709334646004; Fri, 01 Mar 2024 15:10:46 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 56/60] linux-user/x86_64: Handle the vsyscall page in open_self_maps_{2, 4} Date: Fri, 1 Mar 2024 13:06:15 -1000 Message-Id: <20240301230619.661008-57-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32a.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This is the only case in which we expect to have no host memory backing for a guest memory page, because in general linux user processes cannot map any pages in the top half of the 64-bit address space. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2170 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/syscall.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e384e14248..bc8c06522f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7994,6 +7994,10 @@ static void open_self_maps_4(const struct open_self_maps_data *d, path = "[heap]"; } else if (start == info->vdso) { path = "[vdso]"; +#ifdef TARGET_X86_64 + } else if (start == TARGET_VSYSCALL_PAGE) { + path = "[vsyscall]"; +#endif } /* Except null device (MAP_ANON), adjust offset for this fragment. */ @@ -8082,6 +8086,18 @@ static int open_self_maps_2(void *opaque, target_ulong guest_start, uintptr_t host_start = (uintptr_t)g2h_untagged(guest_start); uintptr_t host_last = (uintptr_t)g2h_untagged(guest_end - 1); +#ifdef TARGET_X86_64 + /* + * Because of the extremely high position of the page within the guest + * virtual address space, this is not backed by host memory at all. + * Therefore the loop below would fail. This is the only instance + * of not having host backing memory. + */ + if (guest_start == TARGET_VSYSCALL_PAGE) { + return open_self_maps_3(opaque, guest_start, guest_end, flags); + } +#endif + while (1) { IntervalTreeNode *n = interval_tree_iter_first(d->host_maps, host_start, host_start); From patchwork Fri Mar 1 23:06:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777120 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1604465wrn; Fri, 1 Mar 2024 15:18:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUFHd4JZPEJ4VTAeOOnWDlfdru3CS5JDlPNyqb5O1oLb7TvlXtrL9PJVOLIIbgUOwI4Lq2NyxEMlQo1gcSkq7Nv X-Google-Smtp-Source: AGHT+IEa0IDhcVIpFXb2qcO+HZuy2hNtlZv0FieNJfkwGskw1AwoEcyE+124eah0G9poBhNyuZT3 X-Received: by 2002:a05:6871:e499:b0:21e:fc35:73ef with SMTP id pz25-20020a056871e49900b0021efc3573efmr3340909oac.38.1709335136932; Fri, 01 Mar 2024 15:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335136; cv=none; d=google.com; s=arc-20160816; b=v99Bl0UwPNnm+96m8PhhCW9f3ZpIw2wRr2gzgiLCf7pgR8coAoWKt6Ct9dERigsyan QW+z6yL9hPRiGDKx0T6pltU7oJtaRjDqr3hVly7ggEMxg1MX4pF9Kg4G3EQX5xKDoi4U pmaDuheYj/1ACCNQmqv9tHr7sgE14frkHspbEVfJeW91JRpItwmWHRu8xHPYivb7j/Gw xwiIBYiTY9uKJ6HWGc/jdP/7FSh2tL2CKRfyBvWGbHcru12Bmo+5T6U4NbAk8eQVEEN6 s4qWPMfZtxxnnDa03nVK8UgZmkUs7V/nXaBWVS2zd7hmHiLfEKM3EdwFccdW9/FdBjA0 a1Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; fh=KXT8skN7RFTc7N6YjUNlSMSjM9WXZW43UAg6bOEDSoc=; b=B5HV+LjXmXodnvgJlOyeZ0E8P38UjBy/7s2ME4kUa/MbMJDWrwsnxyqA6XRQ6bwteE m2HR9o4aqJ001gCqQk9CrFB4RtsqjMZieqyjjP+n360/XGhGbTgIOKSuiH7sdILj8PWI V43QGkuodAlIk7ExKoRZhHp0vAqv0GaFdLbrq7xiA/2kjX0uKQo4PxwwxX4VbdwmzpFT gTMY6IQrD7fHYI6st0HZ6Bv5G/FWFcavFFbPEIqam6vffrNBmhpVijgK0oz0U+Lcv06N 6J6OE6zOHiUeevXWRdxSK5l2WaIoNMqFORxWsabpvB/mVuy8e1C/vGRksq086h954e/s 8zuQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rz0l0CRP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x18-20020a05620a449200b007873ca4eaaesi5067911qkp.660.2024.03.01.15.18.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:18:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rz0l0CRP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2e-0005tM-Fb; Fri, 01 Mar 2024 18:11: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 1rgC1j-0003z0-5z for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:57 -0500 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1g-0005zZ-G5 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:50 -0500 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7bf7e37dc60so153737639f.3 for ; Fri, 01 Mar 2024 15:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334647; x=1709939447; 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=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; b=rz0l0CRPD52P1/IiZ2iwz4hGlImpScXr9Tb4XpejrLboRmqleCCLcLPRynWoL+gP4P HEw6CqhqlxRivCm3xzmnZ73DzQzicuLGDrmCNLVkwXSYhw1nIBUrLiqrQQWOoZr+k+5G V1jz5FUmimXUqvc7Ohnhx4woSKqzQv4mx8qr5767gMKTcGv05qkB2b+pV0jXd3f7Hu54 oBKQ+tIJWk6/zOs7dXP9/62zhU8PzAJTHX+I805H1FFJHJiD9TrHJdyJWFrSil4u6U3b r89c3Y1Br9pfJJbbgE1jGO9kwfvcYzv49D57LNOmWCInyEdXXFqgxUvHyoySQb/ne10b 0sOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334647; x=1709939447; 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=uYpmvWcDo9XJ8PEub2Zz6TVzblWCi4U6QK1BUlbCzJU=; b=SkmxainzSjWl5tGPtNW9yPjF3gXS5/QjWRLVGpjmGyTG5ox3c8zWk1axgUdY51Q/QK G1j7n+cv6+Q80MAOIVHfN684Nah8SYwY2ZsKFLc7iOtYuKkQnRlujzF0+QGL5r2e4LJR uKzmhrEnLgd/MrrDlOCeRgHXrZI8JaUuxcjznsV7uFJF9wOd2MKMBpHKcZApjPfTduL8 4XDTRVAEO3SD0+o1jDzPtLI0C0W7thaJ6DLfQ7Tnjf+UXgUn0HY0htiTBcfHxjWJolF4 eQTePNDDdkBe5uhlQT5byFiojUiVyhRpSPh6KoDwA06rg/YQu7WbJtmiOg3necp7+Mwf 9g6w== X-Gm-Message-State: AOJu0Yx8mbT1ONniHlmBecUDpPGK92lu4Uosb6JPAcNcUxWPmmt4J9yr b1eLbPQzJHu/38pU42+DRwkM4Ku13LFYYQMrnYbLIWP+HI2tLil6auXbg38y5ernsv7d+wvxjmV p X-Received: by 2002:a6b:c988:0:b0:7c7:fd10:ddf3 with SMTP id z130-20020a6bc988000000b007c7fd10ddf3mr3060461iof.18.1709334647317; Fri, 01 Mar 2024 15:10:47 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Song Gao Subject: [PATCH 57/60] linux-user/loongarch64: Remove TARGET_FORCE_SHMLBA Date: Fri, 1 Mar 2024 13:06:16 -1000 Message-Id: <20240301230619.661008-58-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::d31; envelope-from=richard.henderson@linaro.org; helo=mail-io1-xd31.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The kernel abi was changed with commit d23b77953f5a4fbf94c05157b186aac2a247ae32 Author: Huacai Chen Date: Wed Jan 17 12:43:08 2024 +0800 LoongArch: Change SHMLBA from SZ_64K to PAGE_SIZE during the v6.8 cycle. Reviewed-by: Song Gao Signed-off-by: Richard Henderson --- linux-user/loongarch64/target_syscall.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/linux-user/loongarch64/target_syscall.h b/linux-user/loongarch64/target_syscall.h index 8b5de52124..39f229bb9c 100644 --- a/linux-user/loongarch64/target_syscall.h +++ b/linux-user/loongarch64/target_syscall.h @@ -38,11 +38,4 @@ struct target_pt_regs { #define TARGET_MCL_FUTURE 2 #define TARGET_MCL_ONFAULT 4 -#define TARGET_FORCE_SHMLBA - -static inline abi_ulong target_shmlba(CPULoongArchState *env) -{ - return 64 * KiB; -} - #endif From patchwork Fri Mar 1 23:06: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: 777454 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1680277wrn; Fri, 1 Mar 2024 20:13:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXlgq97WO2MPDDrcpeU1R9QQA3gVShavRH4PBDmisXPrUBOO0uI1RLNYP2ZH1PESuQ1rPGZe5a4L2/MBSyc1uX6 X-Google-Smtp-Source: AGHT+IE2MWsg4XXU5Tru9eOcYBgOr/PU3t27oJdYsqgj4CqzDZK1oQlIZPqiU0uqxZqRiJKFS+vq X-Received: by 2002:ae9:e30a:0:b0:787:dd42:4807 with SMTP id v10-20020ae9e30a000000b00787dd424807mr4839299qkf.3.1709352796420; Fri, 01 Mar 2024 20:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709352796; cv=none; d=google.com; s=arc-20160816; b=KjRELi2DCYKe6K4Nq6CeTPvzRuDLcYAp3674YVV1FOoEANQa59w1z1SdU7kiawzDRt /CV2ENlrSywlWsQSOPmaPxkdu6yJjKAMr7/C3p28VwG3UMn55GG62c65zF0+CwNbYzgo 6cBcJptX/KMupTR8X/f/MRk7UK3Zp+Wm6tqzHc1pBwuiNBM5G+UNQOS/nedAhAz2sTht TmWnqBWQYdPXyTS3jNol4YdF0vKDRc2KX6bBA9QH5mIwvfp/3ODGn7jsZ0Ub4OmqZME5 gq6Dt05rtZF0jhrWIawi7IM5GCuVktChGpLC/07yUxxcu43BGouEOnGqzdM/4rAw8Otb aA7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7rYYyH2nCsC3OszbxYg3gYtAKvyiLKNjInne/wklRig=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=HNURSnJ1h5T04xGVUmGwE1KQVDn4O3nxaimfqiYpEIdcXiiHbGRUo7FmEeExWV0pFM JIGciNowvavkXNLQBng1jPWeP1v+SkwCkDjXkrhF+zLqlRjOmVvQjXeVAv9pNxQTH2eI 2W9av8x+7G0DclZTqzdvZszkW5Vr6DyFZ1aEg/aHDFFygXIPCFtRTTQkozZ++/2lYvA5 0xRyYQ4XI49dIAlWF7BZHTFksndf4qRPYxaMXwf5/ioOUYKIREre5mc4n+BHTCc5HFT4 iPvZ7vOY64HcPwnewTxeO36nv7tZcQOhPO7bH1oPHdCloewuu3PGP1mZIJ9xglAx7ZAR R4Hw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXdVjMPZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bs44-20020a05620a472c00b007881c8c2be8si53799qkb.547.2024.03.01.20.13.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 20:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXdVjMPZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgGjL-0005PU-Ut; Fri, 01 Mar 2024 23:12:11 -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 1rgC1k-0003ze-Ig for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:59 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1h-0005zr-T7 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:52 -0500 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e5dddd3b95so361841b3a.1 for ; Fri, 01 Mar 2024 15:10:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334648; x=1709939448; 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=7rYYyH2nCsC3OszbxYg3gYtAKvyiLKNjInne/wklRig=; b=PXdVjMPZ82/pp1kdK4kP72tSGkH1KBZJb4jb2e83ZY3ltJSxAjzXfXKErrTxFGioZT s58ro0dOrYANbVYwXHMnASFPOPoTpsu61k/ZV9nX+GEQQ60/A+KfRG3AhDiYZdBdFXrb VK29ofkRdnvJPivFQ5zhAefGojZlTg6yLQFr+bEBNg5f4raUXoic8N2t1xzldjMc66RD EWglPsDnxiA2kvbP8GD4nIIdAjbjSgJY+VNhETVnFPZMRa5ZtQYjsKCbDvcyipxI6SOA S/wl3pJcwNawQMsUrLawE5ZOJ33GsK17eo3TF87R8RJhm4Pp/QCqzCZBFmcPzQ95QNpk mRBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334648; x=1709939448; 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=7rYYyH2nCsC3OszbxYg3gYtAKvyiLKNjInne/wklRig=; b=NgvImdX8goKmeBJtdz553LEurVD9zXoAN7owdP4Qjj8pC14B06230r/m02IbQf5NpY M6hBkTvxwqPJXkx/WOGcstaiR7kXUssS7omC/FlwAidg1555VDWw6kRZKFcBhi+R1kUn tLksPBTWzaLRdMNKJhNmjue57MNTns8X/31l5YXaxo13MA9MMAh4yVyamKGD9c6SqUI5 OTYyH8EVgOGT11n5XfLLkiYaxgAAq0m6u+HZ7uv9g20g3WVIg2bc59TBkF1b3ze7OBVD mjdYn1sTn0bZ90Q8hLtrHbxWepR4cosyoq4HmdcmElkRexPnHpIxmQdIQFojY47LkI5J bTvg== X-Gm-Message-State: AOJu0YwUYobvkA9OUEHiTFXwBqFb/YPef9hCg8237FfFsVaRZOE4+YfM l791qIFucvw+N7rNhG0SjyARYKk0LUOaw0FFUKxK6F5k/TucWvMaShvHZo/LwVlAnejA1rVtzIX 4 X-Received: by 2002:a05:6a20:9e49:b0:1a0:eb42:a708 with SMTP id mt9-20020a056a209e4900b001a0eb42a708mr8354340pzb.18.1709334648603; Fri, 01 Mar 2024 15:10:48 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 58/60] linux-user: Add strace for shmat Date: Fri, 1 Mar 2024 13:06:17 -1000 Message-Id: <20240301230619.661008-59-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/strace.c | 24 ++++++++++++++++++++++++ linux-user/strace.list | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index cf26e55264..8d13e55a5b 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -670,6 +670,26 @@ print_semctl(CPUArchState *cpu_env, const struct syscallname *name, } #endif +static void +print_shmat(CPUArchState *cpu_env, const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + static const struct flags shmat_flags[] = { + FLAG_GENERIC(SHM_RND), + FLAG_GENERIC(SHM_REMAP), + FLAG_GENERIC(SHM_RDONLY), + FLAG_GENERIC(SHM_EXEC), + FLAG_END + }; + + print_syscall_prologue(name); + print_raw_param(TARGET_ABI_FMT_ld, arg0, 0); + print_pointer(arg1, 0); + print_flags(shmat_flags, arg2, 1); + print_syscall_epilogue(name); +} + #ifdef TARGET_NR_ipc static void print_ipc(CPUArchState *cpu_env, const struct syscallname *name, @@ -683,6 +703,10 @@ print_ipc(CPUArchState *cpu_env, const struct syscallname *name, print_ipc_cmd(arg3); qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4); break; + case IPCOP_shmat: + print_shmat(cpu_env, &(const struct syscallname){ .name = "shmat" }, + arg1, arg4, arg2, 0, 0, 0); + break; default: qemu_log(("%s(" TARGET_ABI_FMT_ld "," diff --git a/linux-user/strace.list b/linux-user/strace.list index 6655d4f26d..dfd4237d14 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1398,7 +1398,7 @@ { TARGET_NR_sgetmask, "sgetmask" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_shmat -{ TARGET_NR_shmat, "shmat" , NULL, NULL, print_syscall_ret_addr }, +{ TARGET_NR_shmat, "shmat" , NULL, print_shmat, print_syscall_ret_addr }, #endif #ifdef TARGET_NR_shmctl { TARGET_NR_shmctl, "shmctl" , NULL, NULL, NULL }, From patchwork Fri Mar 1 23:06:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777090 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1602693wrn; Fri, 1 Mar 2024 15:13:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW7WzbfyTCneMRoQxYz1trFxGP8IJyLHPv4fUY7jSqKNf2iEezpS+ydKXJ6drLfmkDUyvt862IYZHzVxr8HHmYI X-Google-Smtp-Source: AGHT+IGuifx20bk6XI9oqYaDdRrs2fpUhMwJIGxHygGQ88oI3ctdB90v4Phtw1PofnpPyxNjzYih X-Received: by 2002:a05:6358:e48d:b0:17b:8830:628c with SMTP id by13-20020a056358e48d00b0017b8830628cmr3641781rwb.2.1709334784060; Fri, 01 Mar 2024 15:13:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334784; cv=none; d=google.com; s=arc-20160816; b=siAI7cvq496NeC//TxtSsS0JFR6CX9z3FA2FxAvmLjidUeRW6xR5xrH10EeeAK+G8q yuD+7yNck+K/3T08MxGelDvzsbk23ZA61wmjqT8v8e184qmEFuq35lbGq7ZmilBEOFjQ 4hpj/nmRH7zD2/9qPy+6VEIpzwwegwY5Ct9bmk5aLD7NUg7ix8Z41J5Ttmh1J81lQL3b z2pLnQkeDbHU7TEk6NE6YgFNE4K+t4BSFPMapqi1wqKvykElcaECSyekgFIMH76/Kerl mhHl2YUKzzNEmcdR+Eg9sTISNu+y++zSjB1Pmf6QV4B0CvC6EMZTn6PiKEVvB3nQNwwM g1GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4BedJyRvGRjcK6ipu0C7X+tD3tsp2DJnWnzl/pxkro0=; fh=QogS7UeF8MbIna4eqT0aQWK4TjPdIZWQ9qqC2MYLXeI=; b=iAGQW2v1d5PZgu20Pyo22aAr1uV4+OpCrMrn2sbIwLtbNbMU5/aM7YgmNB3ess3YIN NOLFHDs/9/yYcSoyvrXzVlEjP4RIXvfLWck8wfAIfdvA2sxvcx3Q1A15sdnDipZjOlxl nlHm+1gbJfSkZ0drvxuEzIi10xFTBu7bQco6zOEzvijcmbPxB/4/IukJrnfy2FCVOZl2 Y+whYY4iFxwpDZuRGzZaiIp7awvxG8TaS4Ctrk8izMRgdHqh6kCnrkMnBdn38MBtDHwW VBMRmouhUX+JeOe7iDodTFTkyH16ohDUVDMHm6+M/hPUT0MBM5+p7gUNNf7F2U37HPlb UmJg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="mi/ntgh1"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r12-20020ad4576c000000b0068ef74704a1si4607399qvx.453.2024.03.01.15.13.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:13:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="mi/ntgh1"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC3K-0006mH-BP; Fri, 01 Mar 2024 18:12: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 1rgC1l-0003zg-2o for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:59 -0500 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1j-000608-4f for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:52 -0500 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6e125818649so1418531a34.1 for ; Fri, 01 Mar 2024 15:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334650; x=1709939450; 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=4BedJyRvGRjcK6ipu0C7X+tD3tsp2DJnWnzl/pxkro0=; b=mi/ntgh18DhG8dhG9nnmaikT+mQMIyszrexS4Re54hlKOf6W5G0OD2m0fkThFP+Qsg Q8lP+Rc7KPopkjunaKJ5uQzvZF20yc3JVPKu5uUcLxLHs9eOE+i6xtl8w3UrQV2o2B4D Oyqenz+Vy45XeD8lvxHmCE82Qx7uu8QgoBcs75Uvrcv8l4vpGh12CrBfYY502GkJxgtf qY3lIEmdadekh+7BVUrbpfETr1m5uhFk6rUto0oR1QchAf28AX0dXT59RgbpfXIXe467 qddPSUXHvoo6TtqBCfkA8BE62mHa6OgP+nX8sGPzuYWrNRJZsOmKWoxKmB0FQr4jdX6A OYYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334650; x=1709939450; 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=4BedJyRvGRjcK6ipu0C7X+tD3tsp2DJnWnzl/pxkro0=; b=movLj2CR4N1rjARYoBUkVzyzKO488umyIqDW9/qhfezbh1M91Pnn3SDwWF6OWyXU8m BFU+KK6i8r9Z9f2IqdKF2YzUCBj7u0jC9HmfhXR0pLHxOsmenhrr/kbkAzFrz15qFczd Y5QubOGhmWkseDyaG/vLxMnouT5qvvIzFpulCWb9Yl9IRGVAS4rk5t2mfRPjf/jw2cyp 4cKbxgTpFEwtXqma9c6IkKDxOMaV2iPxFY7SJLRPfM/Zjp2gbAVCYwnMXu3ix3cBdwzY 889BWukI4mAcMuZuz+RtV+aH2g8XOmIamE5M0wJO0PEW/A8WBgVKfm8j6ovhWydynv+r Iz9A== X-Gm-Message-State: AOJu0YwXJ55tLWxfxTiDZZWOndW1K8AzMA6a91oE9/d/gdq6GVrNi+yE Hm/7YTymviZ/ozh5VPAOkfOikaJDyxZfnXS9C4ARdih8/WD6wyWJphPk1ffj/LJU/5+j/0WtwX+ t X-Received: by 2002:a05:6830:6dc7:b0:6e4:8776:36a1 with SMTP id eb7-20020a0568306dc700b006e4877636a1mr5262963otb.25.1709334650010; Fri, 01 Mar 2024 15:10:50 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:49 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Richard Purdie Subject: [PATCH 59/60] linux-user: Rewrite target_shmat Date: Fri, 1 Mar 2024 13:06:18 -1000 Message-Id: <20240301230619.661008-60-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x332.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Handle combined host and guest alignment requirements. Handle host and guest page size differences. Handle SHM_EXEC. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/115 Tested-by: Richard Purdie Signed-off-by: Richard Henderson --- linux-user/mmap.c | 172 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 36 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 82f4026283..4505fd7376 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1236,69 +1236,161 @@ static inline abi_ulong target_shmlba(CPUArchState *cpu_env) } #endif +#if defined(__arm__) || defined(__mips__) || defined(__sparc__) +#define HOST_FORCE_SHMLBA 1 +#else +#define HOST_FORCE_SHMLBA 0 +#endif + abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, abi_ulong shmaddr, int shmflg) { CPUState *cpu = env_cpu(cpu_env); - abi_ulong raddr; struct shmid_ds shm_info; int ret; - abi_ulong shmlba; + int h_pagesize; + int t_shmlba, h_shmlba, m_shmlba; + size_t t_len, h_len, m_len; /* shmat pointers are always untagged */ - /* find out the length of the shared memory segment */ + /* + * Because we can't use host shmat() unless the address is sufficiently + * aligned for the host, we'll need to check both. + * TODO: Could be fixed with softmmu. + */ + t_shmlba = target_shmlba(cpu_env); + h_pagesize = qemu_real_host_page_size(); + h_shmlba = (HOST_FORCE_SHMLBA ? SHMLBA : h_pagesize); + m_shmlba = MAX(t_shmlba, h_shmlba); + + if (shmaddr) { + if (shmaddr & (m_shmlba - 1)) { + if (shmflg & SHM_RND) { + /* + * The guest is allowing the kernel to round the address. + * Assume that the guest is ok with us rounding to the + * host required alignment too. Anyway if we don't, we'll + * get an error from the kernel. + */ + shmaddr &= ~(m_shmlba - 1); + if (shmaddr == 0 && (shmflg & SHM_REMAP)) { + return -TARGET_EINVAL; + } + } else { + int require = TARGET_PAGE_SIZE; +#ifdef TARGET_FORCE_SHMLBA + require = t_shmlba; +#endif + /* + * Include host required alignment, as otherwise we cannot + * use host shmat at all. + */ + require = MAX(require, h_shmlba); + if (shmaddr & (require - 1)) { + return -TARGET_EINVAL; + } + } + } + } else { + if (shmflg & SHM_REMAP) { + return -TARGET_EINVAL; + } + } + /* All rounding now manually concluded. */ + shmflg &= ~SHM_RND; + + /* Find out the length of the shared memory segment. */ ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); if (is_error(ret)) { /* can't get length, bail out */ return ret; } + t_len = TARGET_PAGE_ALIGN(shm_info.shm_segsz); + h_len = ROUND_UP(shm_info.shm_segsz, h_pagesize); + m_len = MAX(t_len, h_len); - shmlba = target_shmlba(cpu_env); - - if (shmaddr & (shmlba - 1)) { - if (shmflg & SHM_RND) { - shmaddr &= ~(shmlba - 1); - } else { - return -TARGET_EINVAL; - } - } - if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { + if (!guest_range_valid_untagged(shmaddr, m_len)) { return -TARGET_EINVAL; } WITH_MMAP_LOCK_GUARD() { - void *host_raddr; + bool mapped = false; + void *want, *test; abi_ulong last; - if (shmaddr) { - host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); - } else { - abi_ulong mmap_start; - - /* In order to use the host shmat, we need to honor host SHMLBA. */ - mmap_start = mmap_find_vma(0, shm_info.shm_segsz, - MAX(SHMLBA, shmlba)); - - if (mmap_start == -1) { + if (!shmaddr) { + shmaddr = mmap_find_vma(0, m_len, m_shmlba); + if (shmaddr == -1) { return -TARGET_ENOMEM; } - host_raddr = shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); + mapped = !reserved_va; + } else if (shmflg & SHM_REMAP) { + /* + * If host page size > target page size, the host shmat may map + * more memory than the guest expects. Reject a mapping that + * would replace memory in the unexpected gap. + * TODO: Could be fixed with softmmu. + */ + if (t_len < h_len && + !page_check_range_empty(shmaddr + t_len, + shmaddr + h_len - 1)) { + return -TARGET_EINVAL; + } + } else { + if (!page_check_range_empty(shmaddr, shmaddr + m_len - 1)) { + return -TARGET_EINVAL; + } } - if (host_raddr == (void *)-1) { - return get_errno(-1); - } - raddr = h2g(host_raddr); - last = raddr + shm_info.shm_segsz - 1; + /* All placement is now complete. */ + want = (void *)g2h_untagged(shmaddr); - page_set_flags(raddr, last, + /* + * Map anonymous pages across the entire range, then remap with + * the shared memory. This is required for a number of corner + * cases for which host and guest page sizes differ. + */ + if (h_len != t_len) { + int mmap_p = PROT_READ | (shmflg & SHM_RDONLY ? 0 : PROT_WRITE); + int mmap_f = MAP_PRIVATE | MAP_ANONYMOUS + | (reserved_va || (shmflg & SHM_REMAP) + ? MAP_FIXED : MAP_FIXED_NOREPLACE); + + test = mmap(want, m_len, mmap_p, mmap_f, -1, 0); + if (unlikely(test != want)) { + /* shmat returns EINVAL not EEXIST like mmap. */ + ret = (test == MAP_FAILED && errno != EEXIST + ? get_errno(-1) : -TARGET_EINVAL); + if (mapped) { + do_munmap(want, m_len); + } + return ret; + } + mapped = true; + } + + if (reserved_va || mapped) { + shmflg |= SHM_REMAP; + } + test = shmat(shmid, want, shmflg); + if (test == MAP_FAILED) { + ret = get_errno(-1); + if (mapped) { + do_munmap(want, m_len); + } + return ret; + } + assert(test == want); + + last = shmaddr + m_len - 1; + page_set_flags(shmaddr, last, PAGE_VALID | PAGE_RESET | PAGE_READ | - (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE) | + (shmflg & SHM_EXEC ? PAGE_EXEC : 0)); - shm_region_rm_complete(raddr, last); - shm_region_add(raddr, last); + shm_region_rm_complete(shmaddr, last); + shm_region_add(shmaddr, last); } /* @@ -1312,7 +1404,15 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, tb_flush(cpu); } - return raddr; + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + FILE *f = qemu_log_trylock(); + if (f) { + fprintf(f, "page layout changed following shmat\n"); + page_dump(f); + qemu_log_unlock(f); + } + } + return shmaddr; } abi_long target_shmdt(abi_ulong shmaddr) From patchwork Fri Mar 1 23:06: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: 777117 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603836wrn; Fri, 1 Mar 2024 15:16:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVzMCJYXEW4IAk6phZw3MPktMI7iNEOgnMtoYdSx7GPv4ys6Bm6Td1mjP9UO10oeGqT2xsdDwC6MM4Es8MyeoVN X-Google-Smtp-Source: AGHT+IGA3xvjdBYhtLeDh2hqWSMW3mIyBjvQKoUrfq4qoko1vi5tp27moyeRUiZkY7kI0RscYxyW X-Received: by 2002:a0c:9781:0:b0:690:5b92:2b61 with SMTP id l1-20020a0c9781000000b006905b922b61mr2360101qvd.14.1709335009348; Fri, 01 Mar 2024 15:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709335009; cv=none; d=google.com; s=arc-20160816; b=GFaijXBGOPTdSYeDrlY/bMQ47/pNsssunqpwgEucO01kLyeG34IP99omZsvmCXmhua t2JIG9X+aD1W7wHtDnx65KkNMDBRn27kDd4HsrDm6GzxxeA/wb1vBVUqm4xhh1RIimgn X8aUVqFhSIIghAa7EgjrI0z1iQe9m8UkDZbfozUWZiXBhh4ZPegMU6KK+vKgT4Z3JSeF cZFIEQnjtXEyMkipzcvoDPJ+VmwbYr1HXzCm7EFd3vc75PmkWI8aoJBtssJ59jnbOrej Rj4ZYUuzO1VXb8N2AgDiVLZvI8KYIeIbWZuN6ZZHRUtq9dDWPgt+cvfqMn9oLRL2FhPy C/uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; fh=o2XzhdKG+B45MJCghEfnYoypmHvLX2hd4SL6yXeiyXI=; b=RSeu3OCQSvNylmAK135wGV56HLbyxEYe+0PS8q8LbfzshcA4QE+k9AN8ClQ6xtPh5m 1n3QMLo1aBZCAq2iEdHJk/7TAZuKBMSAlLjMpULs/c3PLB4fHOpL5skYibA1BcX7QojD o5oK0R45+EjHLkJOnodTivZbnKQxsiBwREM2yVmxZwDn487qs14vO2y446albalWVERm Mg85/b10Z1+yy/PemTnPJuWrpykcrbPTiurcApV3JuBbv1xnWGYlw8Fv0/lvrIrDxupr 1w6FYo+7GHdljUyxmbmj+NtJavUmi/K9jvbeVnHOMN4ThFhKP7+9o5XJoMp0FAPPdlaF V/Dg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GILe9hoH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m5-20020ad45dc5000000b0068f4bab9521si4502790qvh.416.2024.03.01.15.16.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GILe9hoH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgC2g-0005zR-8m; Fri, 01 Mar 2024 18:11: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 1rgC1m-0003zh-8A for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:59 -0500 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgC1k-00062O-GF for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:10:54 -0500 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6e49518f375so1109680a34.1 for ; Fri, 01 Mar 2024 15:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334651; x=1709939451; 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=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=GILe9hoH0YjVaq9230ldul13mDDZzl1m3HvvDq6dDYBob8JmoqtOr6b5m4EcbryE07 NSaxC+qJPFFvpsx6JjrCppyLfpnNJJOKyTTGAwoso/MMKyPZ8Tfa3bcYQXXp+LV0HMXQ F0fwiXHW53vKDx65yiLqR9kOoR4PCGqcZTZhowIRJ/QmR0w0wXdz3C5yVyEQT1HFPooO lzogJJjfjFD1TECqDeFdcGwwZM1qdDTUh72JQT1UNbfCxSYIs3At8Q/TSXwwbQOayo1R cPuU0gnARBRLAvpBY28ihPJ3ZCVLJ9lm9lZBtHLEZlzhfU7yMF/fdjp8l7zbc8V/ZSCW IWHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334651; x=1709939451; 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=p6tPGvcWUCgEHkg4WhhgoNhXXsmKMPZyhGixNdkwuIE=; b=E36gfb/17a9o1V8T3kyKjOtRnRKz2iIoIJ3fVC8Gb6fyLkiLtU+iqhaFUpJHqnWfUB N5Dw5ycgKKp2P1PMldjOulZpbLUKhWDxyURFxUqPHycZGM/f4PmEERAgOmRHnqHlU4iD WHxA3TmswLRSW+bTipG8OVO8bf42376UYqGHlzVtMbAZXFPcQcZyyXeMpJCXfB5xm3+O LUHpqEu/AV/YqPbS9M8Ir+GeCy2fy1fYL05Gq08rUkHAGQWlfTMssH2i7WT4GuCQW94H 15xf89DWL1ioLgzIVK6/yx1pR6DvEmD9WwQjwqWkzsN+Yz0yhlWPCs+0dsKKD53xTpV4 OsTQ== X-Gm-Message-State: AOJu0Yykq/ZG8px1/6Ag/OHQmLAp8EwDHT6fw5L/fb7TttMMLX9CoJYH SxLpzx2ZcOLcv9AvmBntsmzuddEgukAPfH36oPTUgZRlpKJgkqBZv9T+gElaG4izPpJaIOQjO2Y A X-Received: by 2002:a05:6830:1108:b0:6e2:de7a:8f6e with SMTP id w8-20020a056830110800b006e2de7a8f6emr3493299otq.31.1709334651431; Fri, 01 Mar 2024 15:10:51 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id c2-20020a634e02000000b005e438fe702dsm3449407pgb.65.2024.03.01.15.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:10:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PATCH 60/60] tests/tcg: Check that shmat() does not break /proc/self/maps Date: Fri, 1 Mar 2024 13:06:19 -1000 Message-Id: <20240301230619.661008-61-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x332.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Add a regression test for a recently fixed issue, where shmat() desynced the guest and the host view of the address space and caused open("/proc/self/maps") to SEGV. Signed-off-by: Ilya Leoshkevich Message-Id: Signed-off-by: Richard Henderson --- tests/tcg/multiarch/linux/linux-shmat-maps.c | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/tcg/multiarch/linux/linux-shmat-maps.c diff --git a/tests/tcg/multiarch/linux/linux-shmat-maps.c b/tests/tcg/multiarch/linux/linux-shmat-maps.c new file mode 100644 index 0000000000..0ccf7a973a --- /dev/null +++ b/tests/tcg/multiarch/linux/linux-shmat-maps.c @@ -0,0 +1,55 @@ +/* + * Test that shmat() does not break /proc/self/maps. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + char buf[128]; + int err, fd; + int shmid; + ssize_t n; + void *p; + + shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT | 0600); + assert(shmid != -1); + + /* + * The original bug required a non-NULL address, which skipped the + * mmap_find_vma step, which could result in a host mapping smaller + * than the target mapping. Choose an address at random. + */ + p = shmat(shmid, (void *)0x800000, SHM_RND); + if (p == (void *)-1) { + /* + * Because we are now running the testcase for all guests for which + * we have a cross-compiler, the above random address might conflict + * with the guest executable in some way. Rather than stopping, + * continue with a system supplied address, which should never fail. + */ + p = shmat(shmid, NULL, 0); + assert(p != (void *)-1); + } + + fd = open("/proc/self/maps", O_RDONLY); + assert(fd != -1); + do { + n = read(fd, buf, sizeof(buf)); + assert(n >= 0); + } while (n != 0); + close(fd); + + err = shmdt(p); + assert(err == 0); + err = shmctl(shmid, IPC_RMID, NULL); + assert(err == 0); + + return EXIT_SUCCESS; +}