From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839076; cv=none; d=zohomail.com; s=zohoarc; b=QHnhIzGCUulXHe2Kyds9gOk0B7hC5fm28+zTMSuk/4BBqIeThGi5gcz9UQUsDtvmraLk4eeFMBnrBW+Wfi9X0ei73x4ATYzu7xELJuqaQIsV5TVWspsFrGJW5o+avZxkfBWCYE4RU66bUnyaZixTNaePembEogXBbxmnXvYVWvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839076; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wPP+gA6R3N32OGWovg7WhoS2VIkJuzBfzz5kdSKolx0=; b=gEevEx6MmcafXCDpSHp6w3+qWD8pzDtRDB0OQKGUMcjmfU45poJCEsgF3PEra5fLR0MLqkSJVMrXXTXfJEZJPtNMMakdJq17AHqz/twOgtUvbm6KrKUc9OGShEZyLWTZZHk/EqQ9DthPqg4oOOdcaXlGAO4TMRn1RLjOzKzgvn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169283907604678.86239594123958; Wed, 23 Aug 2023 18:04:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykN-0000FQ-VE; Wed, 23 Aug 2023 21:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykH-00005d-W9 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:46 -0400 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 1qYykD-0000QD-To for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:45 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68bed28cb22so299134b3a.2 for ; Wed, 23 Aug 2023 18:02:41 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838960; x=1693443760; 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=wPP+gA6R3N32OGWovg7WhoS2VIkJuzBfzz5kdSKolx0=; b=fYTUWMZKN/pxaOvZVs2qKY+UGP1BsvENVeG48WlWS8/jQ7AhEugD2bq2poaIPcwpGD uQ6C3StayON9NTvks3M83N8zUynzqa17IzTrBB3kf669TVjTFv4A3xCtm5yuhUrBj/75 u6I3E45tMbpLdfvmV84/fNm7Su466CO68gAnT4bsW+V88cl5xpatRBcZ+Qmdw2J1o0oI gZwZQhxXQvIAcxjaxAXJUp/VML85WI36+Jwi3nyVxDmEedkaGrWanaTIVbDkDTKmR/9F omLTj0d2EWXINQMExa2dH8wHRqkbDOZYJE5Zra99jmmbkETXK5639RVtqrPhsgD425Al OfIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838960; x=1693443760; 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=wPP+gA6R3N32OGWovg7WhoS2VIkJuzBfzz5kdSKolx0=; b=YaGwXSCpDRt8VOjSAJF5J/8xhmeyWK62Oe0/TVPaBEVttawOIbrvfjsj53uVvFoEtl I8uE07yS38eXpRKkp9orLSFjgtK+AT5nDI7pUVYD8yH6SZDulhIBE6Xw9n1JSSBr94PQ XTCcEDZrDSBVdTu36EqWYx4gpjcELrOMczMnZYkWkEvkqveQeG8ZRw6RokNMN8G0/ULL 34rALHRYUh4ZAsRkUeQiWwOw4oLw8rf/r9HHddt+x822U1gBroUrGhek0CKz8jtMt9bs lbFVAcHTN2xmef7TKSdI725D6GOAlBSPF8zx6kBscp26bjzyTF6+eyyOO1c5oJSSQ2lv RM1w== X-Gm-Message-State: AOJu0YwLcf1tGPs5JORB5iBiwOe5VAVxI431EvK8JVrLJeoOwvvEAfQT ONr7ygmAyyZ4htkmXIfCf1cWlVAqsPcrobBh53s= X-Google-Smtp-Source: AGHT+IGrcCPIIXBzzfHz417irmj9RbiM5/2ljplj1zeoBobc5aVxbONQlO8rbLVodAiiMfEjNw4xMg== X-Received: by 2002:a05:6a20:1390:b0:149:26d1:f24c with SMTP id hn16-20020a056a20139000b0014926d1f24cmr8014014pzc.29.1692838960033; Wed, 23 Aug 2023 18:02:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/13] linux-user: Split out cpu/target_proc.h Date: Wed, 23 Aug 2023 18:02:25 -0700 Message-Id: <20230824010237.1379735-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839078291100005 Content-Type: text/plain; charset="utf-8" Move the various open_cpuinfo functions into new files. Move the m68k open_hardware function as well. All other guest architectures get a boilerplate empty file. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Helge Deller --- linux-user/aarch64/target_proc.h | 1 + linux-user/alpha/target_proc.h | 1 + linux-user/arm/target_proc.h | 1 + linux-user/cris/target_proc.h | 1 + linux-user/hexagon/target_proc.h | 1 + linux-user/hppa/target_proc.h | 26 ++++ linux-user/i386/target_proc.h | 1 + linux-user/loongarch64/target_proc.h | 1 + linux-user/m68k/target_proc.h | 16 +++ linux-user/microblaze/target_proc.h | 1 + linux-user/mips/target_proc.h | 1 + linux-user/mips64/target_proc.h | 1 + linux-user/nios2/target_proc.h | 1 + linux-user/openrisc/target_proc.h | 1 + linux-user/ppc/target_proc.h | 1 + linux-user/riscv/target_proc.h | 37 ++++++ linux-user/s390x/target_proc.h | 109 +++++++++++++++++ linux-user/sh4/target_proc.h | 1 + linux-user/sparc/target_proc.h | 16 +++ linux-user/x86_64/target_proc.h | 1 + linux-user/xtensa/target_proc.h | 1 + linux-user/syscall.c | 176 +-------------------------- 22 files changed, 226 insertions(+), 170 deletions(-) create mode 100644 linux-user/aarch64/target_proc.h create mode 100644 linux-user/alpha/target_proc.h create mode 100644 linux-user/arm/target_proc.h create mode 100644 linux-user/cris/target_proc.h create mode 100644 linux-user/hexagon/target_proc.h create mode 100644 linux-user/hppa/target_proc.h create mode 100644 linux-user/i386/target_proc.h create mode 100644 linux-user/loongarch64/target_proc.h create mode 100644 linux-user/m68k/target_proc.h create mode 100644 linux-user/microblaze/target_proc.h create mode 100644 linux-user/mips/target_proc.h create mode 100644 linux-user/mips64/target_proc.h create mode 100644 linux-user/nios2/target_proc.h create mode 100644 linux-user/openrisc/target_proc.h create mode 100644 linux-user/ppc/target_proc.h create mode 100644 linux-user/riscv/target_proc.h create mode 100644 linux-user/s390x/target_proc.h create mode 100644 linux-user/sh4/target_proc.h create mode 100644 linux-user/sparc/target_proc.h create mode 100644 linux-user/x86_64/target_proc.h create mode 100644 linux-user/xtensa/target_proc.h diff --git a/linux-user/aarch64/target_proc.h b/linux-user/aarch64/target_p= roc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/aarch64/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/alpha/target_proc.h b/linux-user/alpha/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/alpha/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/arm/target_proc.h b/linux-user/arm/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/arm/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/cris/target_proc.h b/linux-user/cris/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/cris/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/hexagon/target_proc.h b/linux-user/hexagon/target_p= roc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/hexagon/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/hppa/target_proc.h b/linux-user/hppa/target_proc.h new file mode 100644 index 0000000000..9340c3b6af --- /dev/null +++ b/linux-user/hppa/target_proc.h @@ -0,0 +1,26 @@ +/* + * HPPA specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef HPPA_TARGET_PROC_H +#define HPPA_TARGET_PROC_H + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int i, num_cpus; + + num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + for (i =3D 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + dprintf(fd, "cpu family\t: PA-RISC 1.1e\n"); + dprintf(fd, "cpu\t\t: PA7300LC (PCX-L2)\n"); + dprintf(fd, "capabilities\t: os32\n"); + dprintf(fd, "model\t\t: 9000/778/B160L - " + "Merlin L2 160 QEMU (9000/778/B160L)\n\n"); + } + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* HPPA_TARGET_PROC_H */ diff --git a/linux-user/i386/target_proc.h b/linux-user/i386/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/i386/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/loongarch64/target_proc.h b/linux-user/loongarch64/= target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/loongarch64/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/m68k/target_proc.h b/linux-user/m68k/target_proc.h new file mode 100644 index 0000000000..3df8f28e22 --- /dev/null +++ b/linux-user/m68k/target_proc.h @@ -0,0 +1,16 @@ +/* + * M68K specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef M68K_TARGET_PROC_H +#define M68K_TARGET_PROC_H + +static int open_hardware(CPUArchState *cpu_env, int fd) +{ + dprintf(fd, "Model:\t\tqemu-m68k\n"); + return 0; +} +#define HAVE_ARCH_PROC_HARDWARE + +#endif /* M68K_TARGET_PROC_H */ diff --git a/linux-user/microblaze/target_proc.h b/linux-user/microblaze/ta= rget_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/microblaze/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/mips/target_proc.h b/linux-user/mips/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/mips/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/mips64/target_proc.h b/linux-user/mips64/target_pro= c.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/mips64/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/nios2/target_proc.h b/linux-user/nios2/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/nios2/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/openrisc/target_proc.h b/linux-user/openrisc/target= _proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/openrisc/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/ppc/target_proc.h b/linux-user/ppc/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/ppc/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/riscv/target_proc.h b/linux-user/riscv/target_proc.h new file mode 100644 index 0000000000..c77c003d65 --- /dev/null +++ b/linux-user/riscv/target_proc.h @@ -0,0 +1,37 @@ +/* + * RISC-V specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef RISCV_TARGET_PROC_H +#define RISCV_TARGET_PROC_H + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int i; + int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + RISCVCPU *cpu =3D env_archcpu(cpu_env); + const RISCVCPUConfig *cfg =3D riscv_cpu_cfg((CPURISCVState *) cpu_env); + char *isa_string =3D riscv_isa_string(cpu); + const char *mmu; + + if (cfg->mmu) { + mmu =3D (cpu_env->xl =3D=3D MXL_RV32) ? "sv32" : "sv48"; + } else { + mmu =3D "none"; + } + + for (i =3D 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + dprintf(fd, "hart\t\t: %d\n", i); + dprintf(fd, "isa\t\t: %s\n", isa_string); + dprintf(fd, "mmu\t\t: %s\n", mmu); + dprintf(fd, "uarch\t\t: qemu\n\n"); + } + + g_free(isa_string); + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* RISCV_TARGET_PROC_H */ diff --git a/linux-user/s390x/target_proc.h b/linux-user/s390x/target_proc.h new file mode 100644 index 0000000000..a4a4821ea5 --- /dev/null +++ b/linux-user/s390x/target_proc.h @@ -0,0 +1,109 @@ +/* + * S390X specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef S390X_TARGET_PROC_H +#define S390X_TARGET_PROC_H + +/* + * Emulate what a Linux kernel running in qemu-system-s390x -M accel=3Dtcg= would + * show in /proc/cpuinfo. + * + * Skip the following in order to match the missing support in op_ecag(): + * - show_cacheinfo(). + * - show_cpu_topology(). + * - show_cpu_mhz(). + * + * Use fixed values for certain fields: + * - bogomips per cpu - from a qemu-system-s390x run. + * - max thread id =3D 0, since SMT / SIGP_SET_MULTI_THREADING is not supp= orted. + * + * Keep the code structure close to arch/s390/kernel/processor.c. + */ + +static void show_facilities(int fd) +{ + size_t sizeof_stfl_bytes =3D 2048; + g_autofree uint8_t *stfl_bytes =3D g_new0(uint8_t, sizeof_stfl_bytes); + unsigned int bit; + + dprintf(fd, "facilities :"); + s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes); + for (bit =3D 0; bit < sizeof_stfl_bytes * 8; bit++) { + if (test_be_bit(bit, stfl_bytes)) { + dprintf(fd, " %d", bit); + } + } + dprintf(fd, "\n"); +} + +static int cpu_ident(unsigned long n) +{ + return deposit32(0, CPU_ID_BITS - CPU_PHYS_ADDR_BITS, CPU_PHYS_ADDR_BI= TS, + n); +} + +static void show_cpu_summary(CPUArchState *cpu_env, int fd) +{ + S390CPUModel *model =3D env_archcpu(cpu_env)->model; + int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + uint32_t elf_hwcap =3D get_elf_hwcap(); + const char *hwcap_str; + int i; + + dprintf(fd, "vendor_id : IBM/S390\n" + "# processors : %i\n" + "bogomips per cpu: 13370.00\n", + num_cpus); + dprintf(fd, "max thread id : 0\n"); + dprintf(fd, "features\t: "); + for (i =3D 0; i < sizeof(elf_hwcap) * 8; i++) { + if (!(elf_hwcap & (1 << i))) { + continue; + } + hwcap_str =3D elf_hwcap_str(i); + if (hwcap_str) { + dprintf(fd, "%s ", hwcap_str); + } + } + dprintf(fd, "\n"); + show_facilities(fd); + for (i =3D 0; i < num_cpus; i++) { + dprintf(fd, "processor %d: " + "version =3D %02X, " + "identification =3D %06X, " + "machine =3D %04X\n", + i, model->cpu_ver, cpu_ident(i), model->def->type); + } +} + +static void show_cpu_ids(CPUArchState *cpu_env, int fd, unsigned long n) +{ + S390CPUModel *model =3D env_archcpu(cpu_env)->model; + + dprintf(fd, "version : %02X\n", model->cpu_ver); + dprintf(fd, "identification : %06X\n", cpu_ident(n)); + dprintf(fd, "machine : %04X\n", model->def->type); +} + +static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned long n) +{ + dprintf(fd, "\ncpu number : %ld\n", n); + show_cpu_ids(cpu_env, fd, n); +} + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + int i; + + show_cpu_summary(cpu_env, fd); + for (i =3D 0; i < num_cpus; i++) { + show_cpuinfo(cpu_env, fd, i); + } + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* S390X_TARGET_PROC_H */ diff --git a/linux-user/sh4/target_proc.h b/linux-user/sh4/target_proc.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/sh4/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/sparc/target_proc.h b/linux-user/sparc/target_proc.h new file mode 100644 index 0000000000..3bb3134a47 --- /dev/null +++ b/linux-user/sparc/target_proc.h @@ -0,0 +1,16 @@ +/* + * Sparc specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef SPARC_TARGET_PROC_H +#define SPARC_TARGET_PROC_H + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + dprintf(fd, "type\t\t: sun4u\n"); + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* SPARC_TARGET_PROC_H */ diff --git a/linux-user/x86_64/target_proc.h b/linux-user/x86_64/target_pro= c.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/x86_64/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/xtensa/target_proc.h b/linux-user/xtensa/target_pro= c.h new file mode 100644 index 0000000000..43fe29ca72 --- /dev/null +++ b/linux-user/xtensa/target_proc.h @@ -0,0 +1 @@ +/* No target-specific /proc support */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9353268cc1..faad3a56df 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8339,9 +8339,11 @@ void target_exception_dump(CPUArchState *env, const = char *fmt, int code) } } =20 +#include "target_proc.h" + #if HOST_BIG_ENDIAN !=3D TARGET_BIG_ENDIAN || \ - defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) = || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) + defined(HAVE_ARCH_PROC_CPUINFO) || \ + defined(HAVE_ARCH_PROC_HARDWARE) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) =3D=3D 0; @@ -8393,171 +8395,6 @@ static int open_net_route(CPUArchState *cpu_env, in= t fd) } #endif =20 -#if defined(TARGET_SPARC) -static int open_cpuinfo(CPUArchState *cpu_env, int fd) -{ - dprintf(fd, "type\t\t: sun4u\n"); - return 0; -} -#endif - -#if defined(TARGET_HPPA) -static int open_cpuinfo(CPUArchState *cpu_env, int fd) -{ - int i, num_cpus; - - num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); - for (i =3D 0; i < num_cpus; i++) { - dprintf(fd, "processor\t: %d\n", i); - dprintf(fd, "cpu family\t: PA-RISC 1.1e\n"); - dprintf(fd, "cpu\t\t: PA7300LC (PCX-L2)\n"); - dprintf(fd, "capabilities\t: os32\n"); - dprintf(fd, "model\t\t: 9000/778/B160L - " - "Merlin L2 160 QEMU (9000/778/B160L)\n\n"); - } - return 0; -} -#endif - -#if defined(TARGET_RISCV) -static int open_cpuinfo(CPUArchState *cpu_env, int fd) -{ - int i; - int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); - RISCVCPU *cpu =3D env_archcpu(cpu_env); - const RISCVCPUConfig *cfg =3D riscv_cpu_cfg((CPURISCVState *) cpu_env); - char *isa_string =3D riscv_isa_string(cpu); - const char *mmu; - - if (cfg->mmu) { - mmu =3D (cpu_env->xl =3D=3D MXL_RV32) ? "sv32" : "sv48"; - } else { - mmu =3D "none"; - } - - for (i =3D 0; i < num_cpus; i++) { - dprintf(fd, "processor\t: %d\n", i); - dprintf(fd, "hart\t\t: %d\n", i); - dprintf(fd, "isa\t\t: %s\n", isa_string); - dprintf(fd, "mmu\t\t: %s\n", mmu); - dprintf(fd, "uarch\t\t: qemu\n\n"); - } - - g_free(isa_string); - return 0; -} -#endif - -#if defined(TARGET_S390X) -/* - * Emulate what a Linux kernel running in qemu-system-s390x -M accel=3Dtcg= would - * show in /proc/cpuinfo. - * - * Skip the following in order to match the missing support in op_ecag(): - * - show_cacheinfo(). - * - show_cpu_topology(). - * - show_cpu_mhz(). - * - * Use fixed values for certain fields: - * - bogomips per cpu - from a qemu-system-s390x run. - * - max thread id =3D 0, since SMT / SIGP_SET_MULTI_THREADING is not supp= orted. - * - * Keep the code structure close to arch/s390/kernel/processor.c. - */ - -static void show_facilities(int fd) -{ - size_t sizeof_stfl_bytes =3D 2048; - g_autofree uint8_t *stfl_bytes =3D g_new0(uint8_t, sizeof_stfl_bytes); - unsigned int bit; - - dprintf(fd, "facilities :"); - s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes); - for (bit =3D 0; bit < sizeof_stfl_bytes * 8; bit++) { - if (test_be_bit(bit, stfl_bytes)) { - dprintf(fd, " %d", bit); - } - } - dprintf(fd, "\n"); -} - -static int cpu_ident(unsigned long n) -{ - return deposit32(0, CPU_ID_BITS - CPU_PHYS_ADDR_BITS, CPU_PHYS_ADDR_BI= TS, - n); -} - -static void show_cpu_summary(CPUArchState *cpu_env, int fd) -{ - S390CPUModel *model =3D env_archcpu(cpu_env)->model; - int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); - uint32_t elf_hwcap =3D get_elf_hwcap(); - const char *hwcap_str; - int i; - - dprintf(fd, "vendor_id : IBM/S390\n" - "# processors : %i\n" - "bogomips per cpu: 13370.00\n", - num_cpus); - dprintf(fd, "max thread id : 0\n"); - dprintf(fd, "features\t: "); - for (i =3D 0; i < sizeof(elf_hwcap) * 8; i++) { - if (!(elf_hwcap & (1 << i))) { - continue; - } - hwcap_str =3D elf_hwcap_str(i); - if (hwcap_str) { - dprintf(fd, "%s ", hwcap_str); - } - } - dprintf(fd, "\n"); - show_facilities(fd); - for (i =3D 0; i < num_cpus; i++) { - dprintf(fd, "processor %d: " - "version =3D %02X, " - "identification =3D %06X, " - "machine =3D %04X\n", - i, model->cpu_ver, cpu_ident(i), model->def->type); - } -} - -static void show_cpu_ids(CPUArchState *cpu_env, int fd, unsigned long n) -{ - S390CPUModel *model =3D env_archcpu(cpu_env)->model; - - dprintf(fd, "version : %02X\n", model->cpu_ver); - dprintf(fd, "identification : %06X\n", cpu_ident(n)); - dprintf(fd, "machine : %04X\n", model->def->type); -} - -static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned long n) -{ - dprintf(fd, "\ncpu number : %ld\n", n); - show_cpu_ids(cpu_env, fd, n); -} - -static int open_cpuinfo(CPUArchState *cpu_env, int fd) -{ - int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); - int i; - - show_cpu_summary(cpu_env, fd); - for (i =3D 0; i < num_cpus; i++) { - show_cpuinfo(cpu_env, fd, i); - } - return 0; -} -#endif - -#if defined(TARGET_M68K) -static int open_hardware(CPUArchState *cpu_env, int fd) -{ - dprintf(fd, "Model:\t\tqemu-m68k\n"); - return 0; -} -#endif - - int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, int flags, mode_t mode, bool safe) { @@ -8578,11 +8415,10 @@ int do_guest_openat(CPUArchState *cpu_env, int dirf= d, const char *fname, #if HOST_BIG_ENDIAN !=3D TARGET_BIG_ENDIAN { "/proc/net/route", open_net_route, is_proc }, #endif -#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) +#if defined(HAVE_ARCH_PROC_CPUINFO) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif -#if defined(TARGET_M68K) +#if defined(HAVE_ARCH_PROC_HARDWARE) { "/proc/hardware", open_hardware, is_proc }, #endif { NULL, NULL, NULL } --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839134; cv=none; d=zohomail.com; s=zohoarc; b=BbFKgeR26U4Qp3R4o0qvkg7b9PxyPxddHuxDS3h3UhGKn6mEodoERV4oCd+03Ek9LTlMVR7dyDAtKmaf+yU3CTNavEKOxaDVXPzg/3xYTL5VaiYC6DhPIDN3B9a77VN/soPvMo26pVS5hBtAtSfWLW+v0oCqbFczYvKy+KGn6hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839134; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wal0ceK+IUSRsFq7bdrVrWMU0yw4HOVJbg4k4NIo3Hk=; b=AqQFfIulutq7NMjvgqGjtvKVr2SERhCnNiZkW3qoOstUxd7/A2IxG5Yfb2ZkIwXsLg9pYDCsjEnjw8OOsJq7uqd/ViQpP3i8ZB1RZsJwHa8nFWTz8afgLPwhmdQ8Trwldprn+mJlf04g5AVx5ArpTVqo6BEYRe3cMNnTcuDtfAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839134856458.53912163473024; Wed, 23 Aug 2023 18:05:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykK-00007R-9h; Wed, 23 Aug 2023 21:02:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykI-00005g-EE for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:46 -0400 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 1qYykE-0000QM-Pz for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:46 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a4bcf8a97so3014036b3a.1 for ; Wed, 23 Aug 2023 18:02:42 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838961; x=1693443761; 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=wal0ceK+IUSRsFq7bdrVrWMU0yw4HOVJbg4k4NIo3Hk=; b=bq38sBa8OBfR9NZ+vy/rQmelrtNm/XnBAnEi9SvJl0Zb3ju23P2V1cjVZcNA2TkaiO oYIFzrnZbObbNhFdDyGKjmdQ7HMJOxVIsU1wgZMOn4exStVIe5UkPAEZ4ZnNHg2GXPXP QqTgUxO+VJpNNJFEJuKl/FuprWwpkMRDA3jDNP6SZAfi1X3iMZ+oHKITwuDp/jUkX90o m3Tz8ITpu2Jsk/wzt/LlS2Av6SwF4tJc6XaFZhC2g+gZBHXl1rTopWODLOjVLPdfznG3 tLydncDbRF+Pk1dEJgNK9IBoJFkg/wSobJJLnvQu9QULqAzkhxVSR/R2ubdfGF434bV5 ERbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838961; x=1693443761; 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=wal0ceK+IUSRsFq7bdrVrWMU0yw4HOVJbg4k4NIo3Hk=; b=AUV0FfeP1hEAAKHhIb3OtN66yRovoWNQexkq1PI2a87IcjILrLFxLxr90BQBPvv7TZ tZ4SGDcsgoMo98uSARZIwCIXnvZ0crlG13/yzvUNAt9FlZoQ+k+OVcHZykXBJ5JHQpaH I65VliIZWtPl12xMI86N5ucWS/0NCm6hsQQosfxu55CByr9IUPWtmR9ILk7Zh4PQrWR4 F+N0ABVHkIpCbTgxsM6T38oUtTYiBDBtsqkD7sojLundq8nmU6P99bFza11tSDLpR+CA 4avwK0kZJDKVXLOLj7bDR499Axgky5pxATwMXDJHGZC5Ta+yQDU63vwTp9c9FQYYO/dh nd8A== X-Gm-Message-State: AOJu0Yyg07+gBzckFBEuqRtxXIH1cEMoRVplh9j4st6PPQo+PoGmqQrK t/SJWhWk/RYBR02vIUk+GSx1q1UviB/ShoU4gH0= X-Google-Smtp-Source: AGHT+IE0HZJKBinPT+QYpzmYxYWGaVMT/D70EBXHpVB1ga8+jh3oHkRzUj7AIrrpW0yPJXbat0D4fg== X-Received: by 2002:a05:6a20:3c8a:b0:148:9ce9:2f44 with SMTP id b10-20020a056a203c8a00b001489ce92f44mr13406795pzj.13.1692838960769; Wed, 23 Aug 2023 18:02:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 02/13] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Date: Wed, 23 Aug 2023 18:02:26 -0700 Message-Id: <20230824010237.1379735-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839136893100003 Content-Type: text/plain; charset="utf-8" From: Helge Deller Add emulation for /proc/cpuinfo for arm architecture. The output below mimics output as seen on debian porterboxes. aarch64 output example: processor : 0 model name : ARMv8 Processor rev 0 (v8l) BogoMIPS : 100.00 Features : swp half thumb fast_mult vfp edsp neon vfpv3 tls vfpv4 id= iva idivt vfpd32 lpae aes pmull sha1 sha2 crc32 CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x1 CPU part : 0xd07 CPU revision : 0 arm 32-bit output example: processor : 0 model name : ARMv7 Processor rev 5 (armv7l) BogoMIPS : 100.00 Features : swp half thumb fast_mult vfp edsp thumbee neon vfpv3 tls vfpv4 i= diva idivt vfpd32 lpae CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0f CPU part : 0xc07 CPU revision : 5 Signed-off-by: Helge Deller Reviewed-by: Richard Henderson Message-Id: <20230803214450.647040-3-deller@gmx.de> Signed-off-by: Richard Henderson Tested-by: Helge Deller --- linux-user/aarch64/target_proc.h | 2 +- linux-user/arm/target_proc.h | 102 +++++++++++++++++++++++- linux-user/loader.h | 6 +- linux-user/elfload.c | 130 ++++++++++++++++++++++++++++++- 4 files changed, 233 insertions(+), 7 deletions(-) diff --git a/linux-user/aarch64/target_proc.h b/linux-user/aarch64/target_p= roc.h index 43fe29ca72..907df4dcd2 100644 --- a/linux-user/aarch64/target_proc.h +++ b/linux-user/aarch64/target_proc.h @@ -1 +1 @@ -/* No target-specific /proc support */ +#include "../arm/target_proc.h" diff --git a/linux-user/arm/target_proc.h b/linux-user/arm/target_proc.h index 43fe29ca72..ac75af9ca6 100644 --- a/linux-user/arm/target_proc.h +++ b/linux-user/arm/target_proc.h @@ -1 +1,101 @@ -/* No target-specific /proc support */ +/* + * Arm specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef ARM_TARGET_PROC_H +#define ARM_TARGET_PROC_H + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + ARMCPU *cpu =3D env_archcpu(cpu_env); + int arch, midr_rev, midr_part, midr_var, midr_impl; + target_ulong elf_hwcap =3D get_elf_hwcap(); + target_ulong elf_hwcap2 =3D get_elf_hwcap2(); + const char *elf_name; + int num_cpus, len_part, len_var; + +#if TARGET_BIG_ENDIAN +# define END_SUFFIX "b" +#else +# define END_SUFFIX "l" +#endif + + arch =3D 8; + elf_name =3D "v8" END_SUFFIX; + midr_rev =3D FIELD_EX32(cpu->midr, MIDR_EL1, REVISION); + midr_part =3D FIELD_EX32(cpu->midr, MIDR_EL1, PARTNUM); + midr_var =3D FIELD_EX32(cpu->midr, MIDR_EL1, VARIANT); + midr_impl =3D FIELD_EX32(cpu->midr, MIDR_EL1, IMPLEMENTER); + len_part =3D 3; + len_var =3D 1; + +#ifndef TARGET_AARCH64 + /* For simplicity, treat ARMv8 as an arm64 kernel with CONFIG_COMPAT. = */ + if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { + if (arm_feature(&cpu->env, ARM_FEATURE_V7)) { + arch =3D 7; + midr_var =3D (cpu->midr >> 16) & 0x7f; + len_var =3D 2; + if (arm_feature(&cpu->env, ARM_FEATURE_M)) { + elf_name =3D "armv7m" END_SUFFIX; + } else { + elf_name =3D "armv7" END_SUFFIX; + } + } else { + midr_part =3D cpu->midr >> 4; + len_part =3D 7; + if (arm_feature(&cpu->env, ARM_FEATURE_V6)) { + arch =3D 6; + elf_name =3D "armv6" END_SUFFIX; + } else if (arm_feature(&cpu->env, ARM_FEATURE_V5)) { + arch =3D 5; + elf_name =3D "armv5t" END_SUFFIX; + } else { + arch =3D 4; + elf_name =3D "armv4" END_SUFFIX; + } + } + } +#endif + +#undef END_SUFFIX + + num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + for (int i =3D 0; i < num_cpus; i++) { + dprintf(fd, + "processor\t: %d\n" + "model name\t: ARMv%d Processor rev %d (%s)\n" + "BogoMIPS\t: 100.00\n" + "Features\t:", + i, arch, midr_rev, elf_name); + + for (target_ulong j =3D elf_hwcap; j ; j &=3D j - 1) { + dprintf(fd, " %s", elf_hwcap_str(ctz64(j))); + } + for (target_ulong j =3D elf_hwcap2; j ; j &=3D j - 1) { + dprintf(fd, " %s", elf_hwcap2_str(ctz64(j))); + } + + dprintf(fd, "\n" + "CPU implementer\t: 0x%02x\n" + "CPU architecture: %d\n" + "CPU variant\t: 0x%0*x\n", + midr_impl, arch, len_var, midr_var); + if (arch >=3D 7) { + dprintf(fd, "CPU part\t: 0x%0*x\n", len_part, midr_part); + } + dprintf(fd, "CPU revision\t: %d\n\n", midr_rev); + } + + if (arch < 8) { + dprintf(fd, "Hardware\t: QEMU v%s %s\n", QEMU_VERSION, + cpu->dtb_compatible ? : ""); + dprintf(fd, "Revision\t: 0000\n"); + dprintf(fd, "Serial\t\t: 0000000000000000\n"); + } + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* ARM_TARGET_PROC_H */ diff --git a/linux-user/loader.h b/linux-user/loader.h index 59cbeacf24..324e5c872a 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -56,9 +56,13 @@ abi_long memcpy_to_target(abi_ulong dest, const void *sr= c, =20 extern unsigned long guest_stack_size; =20 -#ifdef TARGET_S390X +#if defined(TARGET_S390X) || defined(TARGET_AARCH64) || defined(TARGET_ARM) uint32_t get_elf_hwcap(void); const char *elf_hwcap_str(uint32_t bit); #endif +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) +uint32_t get_elf_hwcap2(void); +const char *elf_hwcap2_str(uint32_t bit); +#endif =20 #endif /* LINUX_USER_LOADER_H */ diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ac03beb01b..d5f67de288 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -466,7 +466,7 @@ static bool init_guest_commpage(void) #define ELF_HWCAP get_elf_hwcap() #define ELF_HWCAP2 get_elf_hwcap2() =20 -static uint32_t get_elf_hwcap(void) +uint32_t get_elf_hwcap(void) { ARMCPU *cpu =3D ARM_CPU(thread_cpu); uint32_t hwcaps =3D 0; @@ -508,7 +508,7 @@ static uint32_t get_elf_hwcap(void) return hwcaps; } =20 -static uint32_t get_elf_hwcap2(void) +uint32_t get_elf_hwcap2(void) { ARMCPU *cpu =3D ARM_CPU(thread_cpu); uint32_t hwcaps =3D 0; @@ -521,6 +521,49 @@ static uint32_t get_elf_hwcap2(void) return hwcaps; } =20 +const char *elf_hwcap_str(uint32_t bit) +{ + static const char *hwcap_str[] =3D { + [__builtin_ctz(ARM_HWCAP_ARM_SWP )] =3D "swp", + [__builtin_ctz(ARM_HWCAP_ARM_HALF )] =3D "half", + [__builtin_ctz(ARM_HWCAP_ARM_THUMB )] =3D "thumb", + [__builtin_ctz(ARM_HWCAP_ARM_26BIT )] =3D "26bit", + [__builtin_ctz(ARM_HWCAP_ARM_FAST_MULT)] =3D "fast_mult", + [__builtin_ctz(ARM_HWCAP_ARM_FPA )] =3D "fpa", + [__builtin_ctz(ARM_HWCAP_ARM_VFP )] =3D "vfp", + [__builtin_ctz(ARM_HWCAP_ARM_EDSP )] =3D "edsp", + [__builtin_ctz(ARM_HWCAP_ARM_JAVA )] =3D "java", + [__builtin_ctz(ARM_HWCAP_ARM_IWMMXT )] =3D "iwmmxt", + [__builtin_ctz(ARM_HWCAP_ARM_CRUNCH )] =3D "crunch", + [__builtin_ctz(ARM_HWCAP_ARM_THUMBEE )] =3D "thumbee", + [__builtin_ctz(ARM_HWCAP_ARM_NEON )] =3D "neon", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv3 )] =3D "vfpv3", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv3D16 )] =3D "vfpv3d16", + [__builtin_ctz(ARM_HWCAP_ARM_TLS )] =3D "tls", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv4 )] =3D "vfpv4", + [__builtin_ctz(ARM_HWCAP_ARM_IDIVA )] =3D "idiva", + [__builtin_ctz(ARM_HWCAP_ARM_IDIVT )] =3D "idivt", + [__builtin_ctz(ARM_HWCAP_ARM_VFPD32 )] =3D "vfpd32", + [__builtin_ctz(ARM_HWCAP_ARM_LPAE )] =3D "lpae", + [__builtin_ctz(ARM_HWCAP_ARM_EVTSTRM )] =3D "evtstrm", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + +const char *elf_hwcap2_str(uint32_t bit) +{ + static const char *hwcap_str[] =3D { + [__builtin_ctz(ARM_HWCAP2_ARM_AES )] =3D "aes", + [__builtin_ctz(ARM_HWCAP2_ARM_PMULL)] =3D "pmull", + [__builtin_ctz(ARM_HWCAP2_ARM_SHA1 )] =3D "sha1", + [__builtin_ctz(ARM_HWCAP2_ARM_SHA2 )] =3D "sha2", + [__builtin_ctz(ARM_HWCAP2_ARM_CRC32)] =3D "crc32", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + #undef GET_FEATURE #undef GET_FEATURE_ID =20 @@ -668,7 +711,7 @@ enum { #define GET_FEATURE_ID(feat, hwcap) \ do { if (cpu_isar_feature(feat, cpu)) { hwcaps |=3D hwcap; } } while (= 0) =20 -static uint32_t get_elf_hwcap(void) +uint32_t get_elf_hwcap(void) { ARMCPU *cpu =3D ARM_CPU(thread_cpu); uint32_t hwcaps =3D 0; @@ -706,7 +749,7 @@ static uint32_t get_elf_hwcap(void) return hwcaps; } =20 -static uint32_t get_elf_hwcap2(void) +uint32_t get_elf_hwcap2(void) { ARMCPU *cpu =3D ARM_CPU(thread_cpu); uint32_t hwcaps =3D 0; @@ -741,6 +784,85 @@ static uint32_t get_elf_hwcap2(void) return hwcaps; } =20 +const char *elf_hwcap_str(uint32_t bit) +{ + static const char *hwcap_str[] =3D { + [__builtin_ctz(ARM_HWCAP_A64_FP )] =3D "fp", + [__builtin_ctz(ARM_HWCAP_A64_ASIMD )] =3D "asimd", + [__builtin_ctz(ARM_HWCAP_A64_EVTSTRM )] =3D "evtstrm", + [__builtin_ctz(ARM_HWCAP_A64_AES )] =3D "aes", + [__builtin_ctz(ARM_HWCAP_A64_PMULL )] =3D "pmull", + [__builtin_ctz(ARM_HWCAP_A64_SHA1 )] =3D "sha1", + [__builtin_ctz(ARM_HWCAP_A64_SHA2 )] =3D "sha2", + [__builtin_ctz(ARM_HWCAP_A64_CRC32 )] =3D "crc32", + [__builtin_ctz(ARM_HWCAP_A64_ATOMICS )] =3D "atomics", + [__builtin_ctz(ARM_HWCAP_A64_FPHP )] =3D "fphp", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDHP )] =3D "asimdhp", + [__builtin_ctz(ARM_HWCAP_A64_CPUID )] =3D "cpuid", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDRDM)] =3D "asimdrdm", + [__builtin_ctz(ARM_HWCAP_A64_JSCVT )] =3D "jscvt", + [__builtin_ctz(ARM_HWCAP_A64_FCMA )] =3D "fcma", + [__builtin_ctz(ARM_HWCAP_A64_LRCPC )] =3D "lrcpc", + [__builtin_ctz(ARM_HWCAP_A64_DCPOP )] =3D "dcpop", + [__builtin_ctz(ARM_HWCAP_A64_SHA3 )] =3D "sha3", + [__builtin_ctz(ARM_HWCAP_A64_SM3 )] =3D "sm3", + [__builtin_ctz(ARM_HWCAP_A64_SM4 )] =3D "sm4", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDDP )] =3D "asimddp", + [__builtin_ctz(ARM_HWCAP_A64_SHA512 )] =3D "sha512", + [__builtin_ctz(ARM_HWCAP_A64_SVE )] =3D "sve", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDFHM)] =3D "asimdfhm", + [__builtin_ctz(ARM_HWCAP_A64_DIT )] =3D "dit", + [__builtin_ctz(ARM_HWCAP_A64_USCAT )] =3D "uscat", + [__builtin_ctz(ARM_HWCAP_A64_ILRCPC )] =3D "ilrcpc", + [__builtin_ctz(ARM_HWCAP_A64_FLAGM )] =3D "flagm", + [__builtin_ctz(ARM_HWCAP_A64_SSBS )] =3D "ssbs", + [__builtin_ctz(ARM_HWCAP_A64_SB )] =3D "sb", + [__builtin_ctz(ARM_HWCAP_A64_PACA )] =3D "paca", + [__builtin_ctz(ARM_HWCAP_A64_PACG )] =3D "pacg", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + +const char *elf_hwcap2_str(uint32_t bit) +{ + static const char *hwcap_str[] =3D { + [__builtin_ctz(ARM_HWCAP2_A64_DCPODP )] =3D "dcpodp", + [__builtin_ctz(ARM_HWCAP2_A64_SVE2 )] =3D "sve2", + [__builtin_ctz(ARM_HWCAP2_A64_SVEAES )] =3D "sveaes", + [__builtin_ctz(ARM_HWCAP2_A64_SVEPMULL )] =3D "svepmull", + [__builtin_ctz(ARM_HWCAP2_A64_SVEBITPERM )] =3D "svebitperm", + [__builtin_ctz(ARM_HWCAP2_A64_SVESHA3 )] =3D "svesha3", + [__builtin_ctz(ARM_HWCAP2_A64_SVESM4 )] =3D "svesm4", + [__builtin_ctz(ARM_HWCAP2_A64_FLAGM2 )] =3D "flagm2", + [__builtin_ctz(ARM_HWCAP2_A64_FRINT )] =3D "frint", + [__builtin_ctz(ARM_HWCAP2_A64_SVEI8MM )] =3D "svei8mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEF32MM )] =3D "svef32mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEF64MM )] =3D "svef64mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEBF16 )] =3D "svebf16", + [__builtin_ctz(ARM_HWCAP2_A64_I8MM )] =3D "i8mm", + [__builtin_ctz(ARM_HWCAP2_A64_BF16 )] =3D "bf16", + [__builtin_ctz(ARM_HWCAP2_A64_DGH )] =3D "dgh", + [__builtin_ctz(ARM_HWCAP2_A64_RNG )] =3D "rng", + [__builtin_ctz(ARM_HWCAP2_A64_BTI )] =3D "bti", + [__builtin_ctz(ARM_HWCAP2_A64_MTE )] =3D "mte", + [__builtin_ctz(ARM_HWCAP2_A64_ECV )] =3D "ecv", + [__builtin_ctz(ARM_HWCAP2_A64_AFP )] =3D "afp", + [__builtin_ctz(ARM_HWCAP2_A64_RPRES )] =3D "rpres", + [__builtin_ctz(ARM_HWCAP2_A64_MTE3 )] =3D "mte3", + [__builtin_ctz(ARM_HWCAP2_A64_SME )] =3D "sme", + [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64 )] =3D "sme_i16i64", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64 )] =3D "sme_f64f64", + [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32 )] =3D "sme_i8i32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32 )] =3D "sme_f16f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32 )] =3D "sme_b16f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32 )] =3D "sme_f32f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64 )] =3D "sme_fa64", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + #undef GET_FEATURE_ID =20 #endif /* not TARGET_AARCH64 */ --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839076; cv=none; d=zohomail.com; s=zohoarc; b=Y1H+81LM4M3VXC2WJ2ZsG7rKy3XTAGNfoGWljjNj370IAXvVDXnORW/Re33bnY8DIiYBXoo1+cHEzaNTds7IiURgkeNhOsYU46E79IcrQ+mtDkEyKeKzTQwmffeLSHPg0WoFDFUCkrNUzMFPvhSQKzU3r45EAzQMR8cmieGqf84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839076; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yER8RLCvXGE4QY1NsvgxkMYXrHTMG4W+91MMUIhX/Po=; b=h1/3GDYYjbIb/fnVZ6Ygu9QE7fo+SuMg+dUgFWcCG8OcuNhABZuYQ3FLM6bUeYAeFpd+6hETGYLCln8vkcw4Q5an2LrZ/ew4C0z2PSUF6fF9dwmR4fiq/ER2o95g1R1N2W8I/sXD5W+L6HbJbYhiEP8Hm54FOvPo2dIYtO+/3LE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839076417209.94527445599397; Wed, 23 Aug 2023 18:04:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykK-00007e-9t; Wed, 23 Aug 2023 21:02:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykI-00005e-1z for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:46 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykE-0000QP-Vx for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:45 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68bec436514so343575b3a.1 for ; Wed, 23 Aug 2023 18:02:42 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838961; x=1693443761; 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=yER8RLCvXGE4QY1NsvgxkMYXrHTMG4W+91MMUIhX/Po=; b=DMW0px2xfF8NLZkQ0gx+QLO5+qybrbI1WOpDIOTMUuuaerdh4r0WKxEHjiKuWgdcJ2 leNrxdNuTR0X3yLQdnbgnXy0vbSircTHy9bqQTJcnpBUPPTfLb/cucIy26W7I+KDI2Px rkaGqEI0vnn9Yp+MFnK24VKQ0J/mkKGy+naSA0c5xatezKuoY6+J29xCkT987tbrWxID 3tSyefhMFJvLAxSllTMMgvPJ8u6o+5PPWemP9bVK3nfLE3RTgVNWtwtnFFjeUmSSzawu bMbt9jYxRUnTCjt0ZBa2f9T0aFZi50k4RuuiqFrFNCaISNJ5YOsQU1Fmf2BfJ2prODDd borQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838961; x=1693443761; 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=yER8RLCvXGE4QY1NsvgxkMYXrHTMG4W+91MMUIhX/Po=; b=I0mDGT5JlB/T62dDgR/cu/jqmySQUgWqI/X6OLuP3rNzksnot3ZBdAa7O/Xvi0dlbV cEBLgL0StUItanZRk63X5vdc5lp1QJSPqOW9Ltrfi0fWlXURFC/nIJn5kYGV3G9wNZoZ kziBU72bi7p9bKAGUoaz+/QtvdpKeLT7PnLp8B4lXiz7V/V7EFpsgLcgdbVL5maVYxOy ozESb4oGff4Fda9kH9D4IxeYn8qkGKI9rco7VqOQtjPQChlsQQqeV5bTCZUoPoejzSJb YBNlJ2j3gjVotcZpiCERy8/7MnnhBokP4nKJ0NO0m89W7v3FEG43538Abm7eisnzscCx aq+Q== X-Gm-Message-State: AOJu0Yx9XhazQS5J/8RnCmBNk9fQ2p9T/+ozQTXz8ikdZP0E9cgBQFLQ LT0zn8FAEEeqOGKmK3BrZwg4p1xw7qmLbH7HA0U= X-Google-Smtp-Source: AGHT+IGV4ec3zOJxYEEWBHhe5+2lYZE4HMOzvkTg5S++dPB1v0HDezsMPlwFsR9JVaA0R3lgAovc2Q== X-Received: by 2002:a05:6a21:81a3:b0:11e:7ced:3391 with SMTP id pd35-20020a056a2181a300b0011e7ced3391mr10662236pzb.43.1692838961681; Wed, 23 Aug 2023 18:02:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Michael Cree Subject: [PATCH 03/13] linux-user: Emulate /proc/cpuinfo for Alpha Date: Wed, 23 Aug 2023 18:02:27 -0700 Message-Id: <20230824010237.1379735-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839077489100003 Content-Type: text/plain; charset="utf-8" From: Helge Deller Add emulation for /proc/cpuinfo for the alpha architecture. alpha output example: (alpha-chroot)root@p100:/# cat /proc/cpuinfo cpu : Alpha cpu model : ev67 cpu variation : 0 cpu revision : 0 cpu serial number : JA00000000 system type : QEMU system variation : QEMU_v8.0.92 system revision : 0 system serial number : AY00000000 cycle frequency [Hz] : 250000000 timer frequency [Hz] : 250.00 page size [bytes] : 8192 phys. address bits : 44 max. addr. space # : 255 BogoMIPS : 2500.00 platform string : AlphaServer QEMU user-mode VM cpus detected : 8 cpus active : 4 cpu active mask : 0000000000000095 L1 Icache : n/a L1 Dcache : n/a L2 cache : n/a L3 cache : n/a Cc: Michael Cree Signed-off-by: Helge Deller Reviewed-by: Richard Henderson Message-Id: <20230803214450.647040-4-deller@gmx.de> Signed-off-by: Richard Henderson Tested-by: Helge Deller --- linux-user/alpha/target_proc.h | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/linux-user/alpha/target_proc.h b/linux-user/alpha/target_proc.h index 43fe29ca72..dac37dffc9 100644 --- a/linux-user/alpha/target_proc.h +++ b/linux-user/alpha/target_proc.h @@ -1 +1,67 @@ -/* No target-specific /proc support */ +/* + * Alpha specific proc functions for linux-user + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef ALPHA_TARGET_PROC_H +#define ALPHA_TARGET_PROC_H + +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int max_cpus =3D sysconf(_SC_NPROCESSORS_CONF); + int num_cpus =3D sysconf(_SC_NPROCESSORS_ONLN); + unsigned long cpu_mask; + char model[32]; + const char *p, *q; + int t; + + p =3D object_class_get_name(OBJECT_CLASS(CPU_GET_CLASS(env_cpu(cpu_env= )))); + q =3D strchr(p, '-'); + t =3D q - p; + assert(t < sizeof(model)); + memcpy(model, p, t); + model[t] =3D 0; + + t =3D sched_getaffinity(getpid(), sizeof(cpu_mask), (cpu_set_t *)&cpu_= mask); + if (t < 0) { + if (num_cpus >=3D sizeof(cpu_mask) * 8) { + cpu_mask =3D -1; + } else { + cpu_mask =3D (1UL << num_cpus) - 1; + } + } + + dprintf(fd, + "cpu\t\t\t: Alpha\n" + "cpu model\t\t: %s\n" + "cpu variation\t\t: 0\n" + "cpu revision\t\t: 0\n" + "cpu serial number\t: JA00000000\n" + "system type\t\t: QEMU\n" + "system variation\t: QEMU_v" QEMU_VERSION "\n" + "system revision\t\t: 0\n" + "system serial number\t: AY00000000\n" + "cycle frequency [Hz]\t: 250000000\n" + "timer frequency [Hz]\t: 250.00\n" + "page size [bytes]\t: %d\n" + "phys. address bits\t: %d\n" + "max. addr. space #\t: 255\n" + "BogoMIPS\t\t: 2500.00\n" + "kernel unaligned acc\t: 0 (pc=3D0,va=3D0)\n" + "user unaligned acc\t: 0 (pc=3D0,va=3D0)\n" + "platform string\t\t: AlphaServer QEMU user-mode VM\n" + "cpus detected\t\t: %d\n" + "cpus active\t\t: %d\n" + "cpu active mask\t\t: %016lx\n" + "L1 Icache\t\t: n/a\n" + "L1 Dcache\t\t: n/a\n" + "L2 cache\t\t: n/a\n" + "L3 cache\t\t: n/a\n", + model, TARGET_PAGE_SIZE, TARGET_PHYS_ADDR_SPACE_BITS, + max_cpus, num_cpus, cpu_mask); + + return 0; +} +#define HAVE_ARCH_PROC_CPUINFO + +#endif /* ALPHA_TARGET_PROC_H */ --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839086; cv=none; d=zohomail.com; s=zohoarc; b=kjtRBjulHv0es7M0BGZQ1HoxOeFYNwClPV/zcqjjZqnau36TSiZ8z9eN6SqqbtGt3987ssXeUFcOVK/J5QwhxNX2p4C7GC/gvzGQL2IXYnnm1Y1Tp8GvoVQKU/JE5hDUnohtFvrfOA2C1dhPCuXgP/gIffgUa52lehvnKmdpp3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839086; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4DWAv0bR3QBWPP10gPMl5GXU+szn3XnQPYnLcaRRAHU=; b=f4D8bglHgO3oF0P6aQfLDc/i3mKyhOUdbU1ZhaUhgy28/rMz+LjmKUVDU3TEAn9Dv5WeOWiey4ABJon4z0ApdyHwruPt6oDAvFVGGc+vwdrLHwGoL1Y97Ztbm83pbW6CFVBFaygSudbsc7/C+u0dr7TIrVscJSe4LVQ+Ff6dVWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839086306714.959514842785; Wed, 23 Aug 2023 18:04:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykN-0000AM-AT; Wed, 23 Aug 2023 21:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykI-00005f-5c for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:46 -0400 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 1qYykF-0000QY-OP for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:45 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a3082c771so308910b3a.0 for ; Wed, 23 Aug 2023 18:02:43 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838962; x=1693443762; 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=4DWAv0bR3QBWPP10gPMl5GXU+szn3XnQPYnLcaRRAHU=; b=WNsMtT+Dl7h1fwXfuMFloPrYZBORVbvIgxnhVdjSjstjonL/yWgOMuFoZGpoHX0NND J7QXzH1OJnrR6/0Ca4fBvXJ0ehvn60ibk42oWNH86slV7r5sHZ3sDkCMTq+/GpfyEyhG KKq/xJqLOek/AHjMDHswg4YFIeHtL+VqvZyRT6xb4NxtPT0geR3b4aFEG4TTqU/YyCTj +7qTJG8WMMYRYxNeKJTGR6HxWpvEwI2cLp9jKsSssfZc6wFOmwc143fZgUlt/edmCWpi SQHEn9qdk4knYyqbPrJOwNCutplOsnqlb44xE9T1GvqboMtgofHRefhFF4qPSoQuidfh 9KPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838962; x=1693443762; 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=4DWAv0bR3QBWPP10gPMl5GXU+szn3XnQPYnLcaRRAHU=; b=UUwA36OJvQcb+GzcRKiVHldIT0HcSBJCE86SgWnkKLjeIh9G5DVRKXeXn7/E3piFDI aW129DbgPZT3JLYH3yUDEDY0G0nX7oodATLY4x6rc+vQKPnJAYhfOYufz8tN67A2XvfO 6gHQ611TvMAPqTdKT2CXAYJQV9wQGFxYytkxZwPdpP709OyAPeW05tdEybkPLryTCuXX s28VJXcwLei3oqTKsuHiCWT2Uc0T83WgNDdK3QS1zK6WYYL48/Dtnaal81obhf3WLhdW oub+CvBc8PhZO5symiMMcl3O3UnH1IRZrL447pQzNkZzw6FLZUt08rCBY51IQ7FbU1eY 28LQ== X-Gm-Message-State: AOJu0YzZDtdVKcg0aF1wq7CA9jewzxdSYJQcn7nYoYxLte2YaO4AghbT EbIhE52JLdOrtkYQGj5uT7V1je34Pscbl3WXLME= X-Google-Smtp-Source: AGHT+IH+BFd6Ik1Qv/vy/RAbvcd6Jd7wKZZc7fypQHkgyl6FPV7yjyG+TB5xPrrZfl4tZPHiIlRn/w== X-Received: by 2002:a05:6a00:2808:b0:68a:6e26:a918 with SMTP id bl8-20020a056a00280800b0068a6e26a918mr7996046pfb.8.1692838962388; Wed, 23 Aug 2023 18:02:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 04/13] util/selfmap: Use dev_t and ino_t in MapInfo Date: Wed, 23 Aug 2023 18:02:28 -0700 Message-Id: <20230824010237.1379735-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839087345100001 Use dev_t instead of a string, and ino_t instead of uint64_t. The latter is likely to be identical on modern systems but is more type-correct for usage. Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- include/qemu/selfmap.h | 4 ++-- linux-user/syscall.c | 6 ++++-- util/selfmap.c | 12 +++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/qemu/selfmap.h b/include/qemu/selfmap.h index 7d938945cb..1690a74f4b 100644 --- a/include/qemu/selfmap.h +++ b/include/qemu/selfmap.h @@ -20,10 +20,10 @@ typedef struct { bool is_exec; bool is_priv; =20 + dev_t dev; + ino_t inode; uint64_t offset; - uint64_t inode; const char *path; - char dev[]; } MapInfo; =20 /** diff --git a/linux-user/syscall.c b/linux-user/syscall.c index faad3a56df..a562920a84 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8160,13 +8160,15 @@ static int open_self_maps_1(CPUArchState *cpu_env, = int fd, bool smaps) } =20 count =3D dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr - " %c%c%c%c %08" PRIx64 " %s %"PRId64, + " %c%c%c%c %08" PRIx64 " %02x:%02x %"PRId64, h2g(min), h2g(max - 1) + 1, (flags & PAGE_READ) ? 'r' : '-', (flags & PAGE_WRITE_ORG) ? 'w' : '-', (flags & PAGE_EXEC) ? 'x' : '-', e->is_priv ? 'p' : 's', - (uint64_t) e->offset, e->dev, e->inode); + (uint64_t)e->offset, + major(e->dev), minor(e->dev), + (uint64_t)e->inode); if (path) { dprintf(fd, "%*s%s\n", 73 - count, "", path); } else { diff --git a/util/selfmap.c b/util/selfmap.c index 4db5b42651..483cb617e2 100644 --- a/util/selfmap.c +++ b/util/selfmap.c @@ -30,19 +30,21 @@ IntervalTreeRoot *read_self_maps(void) =20 if (nfields > 4) { uint64_t start, end, offset, inode; + unsigned dev_maj, dev_min; int errors =3D 0; const char *p; =20 errors |=3D qemu_strtou64(fields[0], &p, 16, &start); errors |=3D qemu_strtou64(p + 1, NULL, 16, &end); errors |=3D qemu_strtou64(fields[2], NULL, 16, &offset); + errors |=3D qemu_strtoui(fields[3], &p, 16, &dev_maj); + errors |=3D qemu_strtoui(p + 1, NULL, 16, &dev_min); errors |=3D qemu_strtou64(fields[4], NULL, 10, &inode); =20 if (!errors) { - size_t dev_len, path_len; + size_t path_len; MapInfo *e; =20 - dev_len =3D strlen(fields[3]) + 1; if (nfields =3D=3D 6) { p =3D fields[5]; p +=3D strspn(p, " "); @@ -52,11 +54,12 @@ IntervalTreeRoot *read_self_maps(void) path_len =3D 0; } =20 - e =3D g_malloc0(sizeof(*e) + dev_len + path_len); + e =3D g_malloc0(sizeof(*e) + path_len); =20 e->itree.start =3D start; e->itree.last =3D end - 1; e->offset =3D offset; + e->dev =3D makedev(dev_maj, dev_min); e->inode =3D inode; =20 e->is_read =3D fields[1][0] =3D=3D 'r'; @@ -64,9 +67,8 @@ IntervalTreeRoot *read_self_maps(void) e->is_exec =3D fields[1][2] =3D=3D 'x'; e->is_priv =3D fields[1][3] =3D=3D 'p'; =20 - memcpy(e->dev, fields[3], dev_len); if (path_len) { - e->path =3D memcpy(e->dev + dev_len, p, path_len); + e->path =3D memcpy(e + 1, p, path_len); } =20 interval_tree_insert(&e->itree, root); --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839139; cv=none; d=zohomail.com; s=zohoarc; b=mEUjVMCSwEgkYMb2FneyHiT4EHeCuSdsRE1cbJFTsJTNt8t3yPXQqWyv+o1qQu30DusYa0qhJBsByHOwlRfzOFHBV4KH2160EiyQba0koYVsavXP5a+v/c9rcPjtlXKdeiwqpo4rl6bcocm8DtslIRb2NgLvubNLADh+xnXJUI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839139; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bpFeD6GHYH/QT6fcBbDbU7NqohK/EObQjIfv1Nj799s=; b=QwRbIVXn31VSrw+HB2xZa5iIWTCCemBPdIS2RApnO4lZd9KjEI69HqNImnJIdzeDJ+bki11jYnonOxt6BDNOUP6eJsX4UJBUT4eX4Edz2aum14TcOGL72QPsLONNaHsTBQmX03OO3WiPMshDHPN2G8c1Ai5XBq9c5guB+agjZGo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839139504515.0731490139062; Wed, 23 Aug 2023 18:05:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykO-0000MX-Si; Wed, 23 Aug 2023 21:02:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykK-00007s-D6 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:49 -0400 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 1qYykH-0000Qk-O0 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:48 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68a42d06d02so2925658b3a.0 for ; Wed, 23 Aug 2023 18:02:44 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838963; x=1693443763; 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=bpFeD6GHYH/QT6fcBbDbU7NqohK/EObQjIfv1Nj799s=; b=PSDaL/MmIN+AY9Hzi8kCMAnwkAevsa6c3KsdPnMoZN3H1PTW4jQhw0QmMViLN7jY/+ UeciVBFeHEZdksbpFDXgD2BcuVXDvCw+QBDC3ye8rvJsJFstNXGPsMW9fU0TrLvq6PtQ FFWcGBu7EKYJD3uRsbf0NNariLZP0dSF5at9ZbQnDfdXdadNdurYMZGF6pveF9Sr2zLQ hwCIazn9LTMnOkidUntbz49iyu94K9C9qa76xsRNZUkO3ysXaRUhnERqE3+HCqxlnc5h dAxttPFU5Xy8BUwhxLG0FvTc5Kt9be05+2wEEG8cCowmya5lnveBoOskfYa2X5dc3502 bM+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838963; x=1693443763; 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=bpFeD6GHYH/QT6fcBbDbU7NqohK/EObQjIfv1Nj799s=; b=GLO6UhTJv8tfBVe/2cBnTBPaqH+sq2q1PBzLJ6Z0/7wAI8pjvo0Z0NqyKMiVEW6AEs vQ/9/2wbKmJCV5BjO1qUVtx+rhHTf2OUZ/MKM88Kbm4fryNV2A/1I0y5w8s3rLzOmdvU uf6/2ZndLOFDEMU7B2DXhLumqMKj7ZvdjtrXMZ0fQN2Ah0mdXNUFiwzNj029rFc9ffgu CQ2VVWNXgPLVyXQG8CL7WXgGad4i7/jS/RnLlSe2anvLWuEh+/MKEKAIyJDlW968S7p8 CqINN8aRoRFGCuwfL0Upq5P0MHWqUWPFkCPixRvaN1m6Y1yeyK3KQOtgONuNKy5voNKI 6lBw== X-Gm-Message-State: AOJu0YywcygEvkjyMRAUtR/1x0SLTIS2aiQ1Tyl/fbKxdwUXhB3wPMYE AGV2w3lyLUz/dR3Re0RaQWTJdAf6Zuc2rspylXw= X-Google-Smtp-Source: AGHT+IGIe6J94Wo7Pa5w1q81LqTCuwqgGg3y0YSIyoZacoSckI8iPAEb8Q4ZmbHmF+p+FqEXR7bvZg== X-Received: by 2002:a05:6a20:3d85:b0:13f:9cee:ff2b with SMTP id s5-20020a056a203d8500b0013f9ceeff2bmr14393425pzi.17.1692838963293; Wed, 23 Aug 2023 18:02:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich Subject: [PATCH 05/13] linux-user: Use walk_memory_regions for open_self_maps Date: Wed, 23 Aug 2023 18:02:29 -0700 Message-Id: <20230824010237.1379735-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839140499100001 Content-Type: text/plain; charset="utf-8" Replace the by-hand method of region identification with the official user-exec interface. Cross-check the region provided to the callback with the interval tree from read_self_maps(). Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- linux-user/syscall.c | 192 ++++++++++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 77 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a562920a84..0b91f996b7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8095,12 +8095,66 @@ static int open_self_cmdline(CPUArchState *cpu_env,= int fd) return 0; } =20 -static void show_smaps(int fd, unsigned long size) -{ - unsigned long page_size_kb =3D TARGET_PAGE_SIZE >> 10; - unsigned long size_kb =3D size >> 10; +struct open_self_maps_data { + TaskState *ts; + IntervalTreeRoot *host_maps; + int fd; + bool smaps; +}; =20 - dprintf(fd, "Size: %lu kB\n" +/* + * Subroutine to output one line of /proc/self/maps, + * or one region of /proc/self/smaps. + */ + +#ifdef TARGET_HPPA +# define test_stack(S, E, L) (E =3D=3D L) +#else +# define test_stack(S, E, L) (S =3D=3D L) +#endif + +static void open_self_maps_4(const struct open_self_maps_data *d, + const MapInfo *mi, abi_ptr start, + abi_ptr end, unsigned flags) +{ + const struct image_info *info =3D d->ts->info; + const char *path =3D mi->path; + uint64_t offset; + int fd =3D d->fd; + int count; + + if (test_stack(start, end, info->stack_limit)) { + path =3D "[stack]"; + } + + /* Except null device (MAP_ANON), adjust offset for this fragment. */ + offset =3D mi->offset; + if (mi->dev) { + uintptr_t hstart =3D (uintptr_t)g2h_untagged(start); + offset +=3D hstart - mi->itree.start; + } + + count =3D dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr + " %c%c%c%c %08" PRIx64 " %02x:%02x %"PRId64, + start, end, + (flags & PAGE_READ) ? 'r' : '-', + (flags & PAGE_WRITE_ORG) ? 'w' : '-', + (flags & PAGE_EXEC) ? 'x' : '-', + mi->is_priv ? 'p' : 's', + offset, major(mi->dev), minor(mi->dev), + (uint64_t)mi->inode); + if (path) { + dprintf(fd, "%*s%s\n", 73 - count, "", path); + } else { + dprintf(fd, "\n"); + } + + if (d->smaps) { + unsigned long size =3D end - start; + unsigned long page_size_kb =3D TARGET_PAGE_SIZE >> 10; + unsigned long size_kb =3D size >> 10; + + dprintf(fd, "Size: %lu kB\n" "KernelPageSize: %lu kB\n" "MMUPageSize: %lu kB\n" "Rss: 0 kB\n" @@ -8121,91 +8175,75 @@ static void show_smaps(int fd, unsigned long size) "Swap: 0 kB\n" "SwapPss: 0 kB\n" "Locked: 0 kB\n" - "THPeligible: 0\n", size_kb, page_size_kb, page_size_kb= ); + "THPeligible: 0\n" + "VmFlags:%s%s%s%s%s%s%s%s\n", + size_kb, page_size_kb, page_size_kb, + (flags & PAGE_READ) ? " rd" : "", + (flags & PAGE_WRITE_ORG) ? " wr" : "", + (flags & PAGE_EXEC) ? " ex" : "", + mi->is_priv ? "" : " sh", + (flags & PAGE_READ) ? " mr" : "", + (flags & PAGE_WRITE_ORG) ? " mw" : "", + (flags & PAGE_EXEC) ? " me" : "", + mi->is_priv ? "" : " ms"); + } } =20 -static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps) +/* + * Callback for walk_memory_regions, when read_self_maps() fails. + * Proceed without the benefit of host /proc/self/maps cross-check. + */ +static int open_self_maps_3(void *opaque, target_ulong guest_start, + target_ulong guest_end, unsigned long flags) { - CPUState *cpu =3D env_cpu(cpu_env); - TaskState *ts =3D cpu->opaque; - IntervalTreeRoot *map_info =3D read_self_maps(); - IntervalTreeNode *s; - int count; + static const MapInfo mi =3D { .is_priv =3D true }; =20 - for (s =3D interval_tree_iter_first(map_info, 0, -1); s; - s =3D interval_tree_iter_next(s, 0, -1)) { - MapInfo *e =3D container_of(s, MapInfo, itree); + open_self_maps_4(opaque, &mi, guest_start, guest_end, flags); + return 0; +} =20 - if (h2g_valid(e->itree.start)) { - unsigned long min =3D e->itree.start; - unsigned long max =3D e->itree.last + 1; - int flags =3D page_get_flags(h2g(min)); - const char *path; +/* + * Callback for walk_memory_regions, when read_self_maps() succeeds. + */ +static int open_self_maps_2(void *opaque, target_ulong guest_start, + target_ulong guest_end, unsigned long flags) +{ + const struct open_self_maps_data *d =3D opaque; + uintptr_t host_start =3D (uintptr_t)g2h_untagged(guest_start); + uintptr_t host_last =3D (uintptr_t)g2h_untagged(guest_end - 1); =20 - max =3D h2g_valid(max - 1) ? - max : (uintptr_t) g2h_untagged(GUEST_ADDR_MAX) + 1; + while (1) { + IntervalTreeNode *n =3D + interval_tree_iter_first(d->host_maps, host_start, host_start); + MapInfo *mi =3D container_of(n, MapInfo, itree); + uintptr_t this_hlast =3D MIN(host_last, n->last); + target_ulong this_gend =3D h2g(this_hlast) + 1; =20 - if (!page_check_range(h2g(min), max - min, flags)) { - continue; - } + open_self_maps_4(d, mi, guest_start, this_gend, flags); =20 -#ifdef TARGET_HPPA - if (h2g(max) =3D=3D ts->info->stack_limit) { -#else - if (h2g(min) =3D=3D ts->info->stack_limit) { -#endif - path =3D "[stack]"; - } else { - path =3D e->path; - } - - count =3D dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr - " %c%c%c%c %08" PRIx64 " %02x:%02x %"PRId64, - h2g(min), h2g(max - 1) + 1, - (flags & PAGE_READ) ? 'r' : '-', - (flags & PAGE_WRITE_ORG) ? 'w' : '-', - (flags & PAGE_EXEC) ? 'x' : '-', - e->is_priv ? 'p' : 's', - (uint64_t)e->offset, - major(e->dev), minor(e->dev), - (uint64_t)e->inode); - if (path) { - dprintf(fd, "%*s%s\n", 73 - count, "", path); - } else { - dprintf(fd, "\n"); - } - if (smaps) { - show_smaps(fd, max - min); - dprintf(fd, "VmFlags:%s%s%s%s%s%s%s%s\n", - (flags & PAGE_READ) ? " rd" : "", - (flags & PAGE_WRITE_ORG) ? " wr" : "", - (flags & PAGE_EXEC) ? " ex" : "", - e->is_priv ? "" : " sh", - (flags & PAGE_READ) ? " mr" : "", - (flags & PAGE_WRITE_ORG) ? " mw" : "", - (flags & PAGE_EXEC) ? " me" : "", - e->is_priv ? "" : " ms"); - } + if (this_hlast =3D=3D host_last) { + return 0; } + host_start =3D this_hlast + 1; + guest_start =3D h2g(host_start); } +} =20 - free_self_maps(map_info); +static int open_self_maps_1(CPUArchState *env, int fd, bool smaps) +{ + struct open_self_maps_data d =3D { + .ts =3D env_cpu(env)->opaque, + .host_maps =3D read_self_maps(), + .fd =3D fd, + .smaps =3D smaps + }; =20 -#ifdef TARGET_VSYSCALL_PAGE - /* - * We only support execution from the vsyscall page. - * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=3Dy from v5.3. - */ - count =3D dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx - " --xp 00000000 00:00 0", - TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PA= GE_SIZE); - dprintf(fd, "%*s%s\n", 73 - count, "", "[vsyscall]"); - if (smaps) { - show_smaps(fd, TARGET_PAGE_SIZE); - dprintf(fd, "VmFlags: ex\n"); + if (d.host_maps) { + walk_memory_regions(&d, open_self_maps_2); + free_self_maps(d.host_maps); + } else { + walk_memory_regions(&d, open_self_maps_3); } -#endif - return 0; } =20 --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=zohomail.com; s=zohoarc; b=bEn/F28/6QLz147yj3znEDZ2GTJf2XqBU1EdDzwReoilCLDQTTfSV36d8TeDcOzKMSbcOlVOVbMcyw8fg0sglOIXBOTo96N4FXSSgHR+2uMbk2td810RIzmKWHlhAl7fAd1v3cHfEgZ8DbCb47eSgITd8DgOxijRRJrUTfvSLOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839022; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Nx0E+Cf9iwRX4Njxvb3jlIfoidd9B3bB+8lmV0laZYk=; b=KnEQ9377hTKVIzXal4QkaibwqS4/W/7N4nBmArsyiAS+DcS6JLeEwCSgT6YQ0AKEJVnDp28ztjhHaLoUFDCyGLYNg5/enLjEGaIp1JePOu2SXbFAzYNAMpPqzqtTIjiQ0sWa0vPsTsgkMerLbuwUL7/Ltb1jL36RbYQ5mJGKBE0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839021997932.6768564545243; Wed, 23 Aug 2023 18:03:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykL-00008T-OY; Wed, 23 Aug 2023 21:02:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykK-00007D-1F for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:48 -0400 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 1qYykH-0000Qu-Og for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:47 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68bed286169so331985b3a.1 for ; Wed, 23 Aug 2023 18:02:45 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838964; x=1693443764; 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=Nx0E+Cf9iwRX4Njxvb3jlIfoidd9B3bB+8lmV0laZYk=; b=Fqkb/Air8yokxmh0Wsk32iilPc3nBNTUqoBNTelkAr606zh/6wvVHISGt9YA8SsP+U HUIwVBGCjK0V+y2F3l7rs7Z7PXZNSFw9tAPmFKR+kRMbDEjklObVHX/MPQ0hojoKVnH5 C8wNOlIGqDsEMB9WaI8EwvTLdipCoBKAyste87mu4qhXlCm15eiCBNsRWIuewcmYZDh+ Y8GdCPkL6BqykJ8MgvLp+v8N8DYi+beJQNPLbWW6NGJZY73ME49havzv+lhh6EEcHxeE b2XTBhtVyYUYV7M4UVX21aaVHWrQ67QtRMYu7CvfIrry6elAVWb/+G4LTgmYCIJ1oeiO t47Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838964; x=1693443764; 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=Nx0E+Cf9iwRX4Njxvb3jlIfoidd9B3bB+8lmV0laZYk=; b=XwM2vFTkMfAK+jjFRZDgDZI6ug23rQHHe7p0WILBbSlb1MK1h2h28DeL/rN9DedHCW pDceWsoCVqYgof62VzM6s8He4TqqUTgWCJHZqU1cesfpZKMTix8gWiSJqBGQoH4ZxSWs fC2YvprrNgZRt9Njtptqv1dh8EqbxaHtZL2Nb/7FHcFIU18NxrN+/brJ9cb4jEMcYcIf M+65JW33FoP6+xg1F6TtgU/fGAx8ftTClq9WxXYx+H6dx7fWehUy6habS9lDeWd5Mmjw XoIyynUobcpSwtiZ7wJwQbGxjCHsRzCjVc55MnWSR+GbYHCcHm2i0XsEY7GD4+uj5zu8 1+Nw== X-Gm-Message-State: AOJu0YzLxuANnpFVw/rtB7QKTNx44uszJAMwQ779y8vuy1KM8wQt5XDY hzgtfVF+punLI0u82NtKnSZfTc3Bt5a51UkLnuM= X-Google-Smtp-Source: AGHT+IF6TFRKnBgga3XrR1gRNo2COqFL/5CJjCuC4s0GpUHd/oIFitFV20kq8namRKQU98u1MddGtg== X-Received: by 2002:a05:6a00:14d0:b0:68a:45a1:c0ee with SMTP id w16-20020a056a0014d000b0068a45a1c0eemr12711358pfu.15.1692838964147; Wed, 23 Aug 2023 18:02:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Helge Deller , Ilya Leoshkevich , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 06/13] linux-user: Adjust brk for load_bias Date: Wed, 23 Aug 2023 18:02:30 -0700 Message-Id: <20230824010237.1379735-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839023738100002 PIE executables are usually linked at offset 0 and are relocated somewhere during load. The hiaddr needs to be adjusted to keep the brk next to the executable. Cc: qemu-stable@nongnu.org Fixes: 1f356e8c013 ("linux-user: Adjust initial brk when interpreter is clo= se to executable") Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 d5f67de288..dbc5d430e8 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3326,7 +3326,7 @@ static void load_elf_image(const char *image_name, in= t image_fd, info->start_data =3D -1; info->end_data =3D 0; /* Usual start for brk is after all sections of the main executable. */ - info->brk =3D TARGET_PAGE_ALIGN(hiaddr); + info->brk =3D TARGET_PAGE_ALIGN(hiaddr + load_bias); info->elf_flags =3D ehdr->e_flags; =20 prot_exec =3D PROT_EXEC; --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=zohomail.com; s=zohoarc; b=ZFc5vtu7Pkf64f6Ki5s5QntjCWxIVAgJMs5QW4vCQ4JNf2i4tfuRKHfJawuzbvDqAMY5hw9DQRSeUb15mZ9SM41kFyh5f1bQo8XZrKwqrLCYGYEfysxu5hGHQEIiGwXoNYGo1TnXtyiZX02eJ7kJdylsGufAozVgq+UtHxl1K7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839022; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/J3OwiFqVwoYplEY/vkfNER1ejXeddYX7iHD/HQTT+U=; b=W62LgqNKMIdTycI+htEWvP6pSd3spgrNnAHNidaBQ/SAk+lDowdUQMGCR0KRxl2g/YjNgSLYQ2tEdFbQXsKHY2468JYFd2+Od4RznhfhVZDknWrYFHQ8kHsEqpuTx0NFnmOr1tPyDZMZWGhMeS5sngCmEIywb/C7/QurbTKESHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839021937255.11712701400916; Wed, 23 Aug 2023 18:03:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykP-0000R6-Ja; Wed, 23 Aug 2023 21:02:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykK-00007l-Bl for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:48 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykI-0000R7-2g for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:48 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68bec3a81c4so300501b3a.1 for ; Wed, 23 Aug 2023 18:02:45 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838965; x=1693443765; 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=/J3OwiFqVwoYplEY/vkfNER1ejXeddYX7iHD/HQTT+U=; b=UM4HUJzDeqK7nHD1k2rsWAc5JcXBllrpi43v/zcPlh7ajB6pfca6tfwpi4OafMUGVc ucpxPCbY8IaMybuNjgRSWlwAf0D560OxmCLNaKMDb7nyz2d2X1Luzpo5LwETSFvJCoZP AHZAlfngqATCQ4OjrMtCiID3STiwHlfKsd1t892xzQ+d7923M4cbjJM/Q2hqWkmxTMMt fH1or/V1Ybwh9vmgvMPBxbAg+02ePM9ILEFR1nEDm4NQiI8yJHKKzeOGAdDcHUJhxDnU JwZC6Sl54ok7F4H+4qLzHk72s5qUf83PqSw4F6x01KzN4f87UYVo5vLyJ27Ov+rhh1h+ 1isQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838965; x=1693443765; 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=/J3OwiFqVwoYplEY/vkfNER1ejXeddYX7iHD/HQTT+U=; b=lip8C66lucWBaoITc7TJ03oz7MRO9zTalq3M16rwGDtOS56d3h0VI7wIogOy2F4Sec YQSUqIeu5g89vP4sZNesEoIFNSXz53ehnH/7hO98RY2anAJVBthm8QFWqKs0PQpwh2hm rMLk+Rt4VqAzQ5NoKNPPPUi36jxrt+gAOzHCZf9tG/V5q2hsN+6ej80UuFo6gMe/EQhf WbyjH3a9XWnmabpQq/pcj/Ff8XsdxddayrGMbnEf/1sic7NNhG5zc6+k1/1CHUIwmF6P cLvUb2nPMFnv2uKpIwEAR3usHtyzc8Kqxsv4GxII+eTPOjecEmg79EDRjbz1pp/4PpHn uXUg== X-Gm-Message-State: AOJu0YywK4w03pB5D248A6cwOxR5kJDwvm4+W61vwdugEUmNd7B8U7Lk AG87cH7o7EaEogErPNZ988b38MuLMoYDESmb1Ug= X-Google-Smtp-Source: AGHT+IE6B5Y13O1hRPMdMQVNpM0IOV9K9bSejO41NpLwWHu6uS0FFBPCuLmbNIYa+PjmmdFKcaZCAA== X-Received: by 2002:a05:6a00:4c07:b0:68b:bedd:c2e9 with SMTP id ea7-20020a056a004c0700b0068bbeddc2e9mr7930697pfb.16.1692838964838; Wed, 23 Aug 2023 18:02:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich Subject: [PATCH 07/13] linux-user: Show heap address in /proc/pid/maps Date: Wed, 23 Aug 2023 18:02:31 -0700 Message-Id: <20230824010237.1379735-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839025067100008 Content-Type: text/plain; charset="utf-8" Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/syscall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0b91f996b7..0641d8f433 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8125,6 +8125,8 @@ static void open_self_maps_4(const struct open_self_m= aps_data *d, =20 if (test_stack(start, end, info->stack_limit)) { path =3D "[stack]"; + } else if (start =3D=3D info->brk) { + path =3D "[heap]"; } =20 /* Except null device (MAP_ANON), adjust offset for this fragment. */ --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839034; cv=none; d=zohomail.com; s=zohoarc; b=dcTZZUkDChf58cLN1+iAp7OuHGeOKI+H4YPdgN4kxMUsENSeI9WAo3dI1j2M/bNxgep+iKWIPZxtIaaTJFbalmPO+jkHRc2N9l2VAaL+dhuPJ8ziwmLrQizi/S0o3P2gkwLgB9Yc2K/AdEe4U/eytpPL7+7u8Sna3JM7EbYThTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839034; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UxFB11WokbscidLNJIq7jg3sXBkPLDLF7tCCnRzjj4U=; b=CeV/TlQaI+rr1n8ygPejCmNqb4JWSeA7or8irLMd8VMTAyHOALYe4pkPhCPFr5R+v/0NrFddaOc4B+/eDTQgDoP21AQjgdB2JEViIfE6oaKAbP5P0JV4GwUcHEZpmsodpNcGX4plbw7AlPMbPcZmekLck5PEL6Qe1YTz+6wmfak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839034217837.9647098518757; Wed, 23 Aug 2023 18:03:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykM-0000AF-RV; Wed, 23 Aug 2023 21:02:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykL-00009k-UO for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:49 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykJ-0000RQ-1B for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:49 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68a56401c12so2779210b3a.2 for ; Wed, 23 Aug 2023 18:02:46 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838965; x=1693443765; 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=UxFB11WokbscidLNJIq7jg3sXBkPLDLF7tCCnRzjj4U=; b=H9bvMoeLhoUHrZtnCvcK2q8sTAW8YFr3Gk8vqZHjcigHMn5j2JB0fCkYjBhoQHsZfN wuRU7jak5o8OIJEDzFpUBfPPEbEbTbM1oNYUFf3MBcto0b50axh6u5v7xCxYxIXgaN7z qydF1HWyoIPbtiWcYT5UtCO+fXuoc6rRcTEi4trD/P6HrBVqCTakzpiVhs3TYml0nme/ pBEWkfXTfPrgJPFk6bpP9k+eH5XKTE7lYTH6QvzSzu/wfiXn5aeI+BpIPkZ1fLclp2tc OCIDE/eiZQYilPjjCA1ARGVvGbbfhiz3Vgj87pc79qtZIqqgAdSjgv0W94mK4Ph5czhB kEjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838965; x=1693443765; 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=UxFB11WokbscidLNJIq7jg3sXBkPLDLF7tCCnRzjj4U=; b=BOs9sh3pR2Z5APbmu4rxPbPRgPaOmD9rHwJlN578f3GVgkgAEPvO/2HUHYQq70z57n mEliIg3fsZ/z09Jog3IF11EQ5H/57EG/y4VuPA8+VbiWrrCL/hUY4AjYl8U96szL5OsT L0nS6sbhFPi5Rxus4FN8lTBfUdhbO71mDtXw5Wp7H8UPjpQElZuquW2Q07JhjJ27aLx6 SmcoojYLnZ1zUUEG7Q8BguNEw+zTW+V+O9NJmIJvJ5o4v32sqj+9TdiFMc/Dz6QUHbe7 PTJcDKTFCH0S0540NNyQa6Ohk72milv4dQM7r5hZSw7la2Di3SwBszGKfCsfHbIvuol0 Ya6A== X-Gm-Message-State: AOJu0Yzxk37bo+2r/IQhlAXS4rF71qH8jcWHgN+7VN+hq5DEDlF4f/Pe lM6U427mxwiImT9PHRYBdVWrKOaRDTsNJ2fLAUw= X-Google-Smtp-Source: AGHT+IE/DtTe3+dRscDRb5X0EuaZdJcBTUPEaJoxFcjs9+hrEhg3xVf7q+NYnxw/SNYvFygajaJIFg== X-Received: by 2002:a05:6a21:7905:b0:14b:8023:33bb with SMTP id bg5-20020a056a21790500b0014b802333bbmr3110411pzc.22.1692838965541; Wed, 23 Aug 2023 18:02:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PATCH 08/13] linux-user: Emulate the Anonymous: keyword in /proc/self/smaps Date: Wed, 23 Aug 2023 18:02:32 -0700 Message-Id: <20230824010237.1379735-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839035255100007 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich Core dumps produced by gdb's gcore when connected to qemu's gdbstub lack stack. The reason is that gdb includes only anonymous memory in core dumps, which is distinguished by a non-0 Anonymous: value. Consider the mappings with PAGE_ANON fully anonymous, and the mappings without it fully non-anonymous. Signed-off-by: Ilya Leoshkevich [rth: Update for open_self_maps_* rewrite] Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Helge Deller --- linux-user/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0641d8f433..8d96acd085 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8167,7 +8167,7 @@ static void open_self_maps_4(const struct open_self_m= aps_data *d, "Private_Clean: 0 kB\n" "Private_Dirty: 0 kB\n" "Referenced: 0 kB\n" - "Anonymous: 0 kB\n" + "Anonymous: %lu kB\n" "LazyFree: 0 kB\n" "AnonHugePages: 0 kB\n" "ShmemPmdMapped: 0 kB\n" @@ -8180,6 +8180,7 @@ static void open_self_maps_4(const struct open_self_m= aps_data *d, "THPeligible: 0\n" "VmFlags:%s%s%s%s%s%s%s%s\n", size_kb, page_size_kb, page_size_kb, + (flags & PAGE_ANON ? size_kb : 0), (flags & PAGE_READ) ? " rd" : "", (flags & PAGE_WRITE_ORG) ? " wr" : "", (flags & PAGE_EXEC) ? " ex" : "", --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839068; cv=none; d=zohomail.com; s=zohoarc; b=kC2jZzCfigSRKeQp8kOOR0WhkQisK361KEe7lL7dcfH5udsY/fMR075jpvyzsgB0aoT/EKAiS0MJ+Jeq26Nq7/JPQ3491x6HAp35kJ3710hFsZh5GtTyGmPCcyZ48T7h3xdQDWehwXg0diTkAhRMT1Mc2E0dtY6qngzDzqTy/ng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839068; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KH0FHPd2e6QV8ZmEsDwRCzlCpTkPvLk9RV9t+BHx8lg=; b=PMwWnxrzQu0UBU3CxdUui2WLvf9IlY+033ifnEOGwXFz6GRFlnC6TSUxGOvfb1x3kGdbonWMyty8f3K48aVRglxqhL3+3keFuJgcIEaLL7W1v2J7m84ERKxjNoU2ii2sb9dhfdwrx0RX0WmlX8aclf/2Xv56stdtZZWgz6VyupA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839068057710.850468653665; Wed, 23 Aug 2023 18:04:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykN-0000EZ-SP; Wed, 23 Aug 2023 21:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykM-0000A6-AG for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:50 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykJ-0000Rm-Ku for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:50 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68a3082c771so308935b3a.0 for ; Wed, 23 Aug 2023 18:02:47 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838966; x=1693443766; 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=KH0FHPd2e6QV8ZmEsDwRCzlCpTkPvLk9RV9t+BHx8lg=; b=qrjREae0vYGgV59nzd5uaUetMBJJfB928NlFtfawd9KRmwtkPl+SJ5cW5lGehCAb/K p9z2dS7ly/LClyQGzSFzovwmDN3JM52z5MJ8c9rRY84ZF0uz5jeUqfBwWL1Dgye2nW9v Aky+wQ/woTQg2nCMM2y8cIaCmxpoyk49tUAU9eZshUQbqo7rXIHg0shW7kvRxZMnzFCw +cKL46HCTdMrSXDuPCXnSiANjSeJ6YHrWnPEypJeEKKWM2Pohln6pM+L8ZNgB58jMydP AU9Y/xcTMI6q4kWLUfQRJLuajNap5doYHHjAnvd1oIQ+vF25SvZFwDy8c/GQ4Pl4Aykp kB5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838966; x=1693443766; 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=KH0FHPd2e6QV8ZmEsDwRCzlCpTkPvLk9RV9t+BHx8lg=; b=IEugWMtt2pRdexlMba4zKzwCQU3odK5Iym5josGlAUaymbFij6ERuhEwv8Vbxopdy/ Ix6XKH+7I93ovAbZiUP/WAiy/8DnZaRw7Fgz7HXytemaOSGlKusjxQJKDg+86zCgfq++ TRi++86y1ZvsWBPcJ6UMJa8oFAu3pxmxCSWyPX2FjKMFhuBlCJbr0Y/k7FKPPtrs+dsl /RZ/x9TbHLSIvL9r/8bRtc336llUzEK7Bc21oU6oFKJNVP0fSyO0Obl4L7vfeN9cp349 /3v5swg/bWe4ox8lSlIYt0RmwOl9pVUewkixX59DvNKP29rl9OduSZHq30Wbt4yypiHC F8WA== X-Gm-Message-State: AOJu0YzR0dRDlDk4JAmZqhg4k9uTJlXjoBkyJONPU+p4dlEexQDmQw/n o7AguDObbjhE8CmfXiOhGRDoRhMQRT7gdtVCRj8= X-Google-Smtp-Source: AGHT+IGe9scQgB+P0dLDzQMqqLVt90YsPYVbkHqq4hiVQxhF5KB4wmTO7wLCfcYcxRS3yY0UQnuDSw== X-Received: by 2002:a05:6a00:801a:b0:68a:4163:66f with SMTP id eg26-20020a056a00801a00b0068a4163066fmr17000226pfb.9.1692838966308; Wed, 23 Aug 2023 18:02:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 09/13] linux-user: Remove ELF_START_MMAP and image_info.start_mmap Date: Wed, 23 Aug 2023 18:02:33 -0700 Message-Id: <20230824010237.1379735-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839070069100003 The start_mmap value is write-only. Remove the field and the defines that populated it. Logically, this has been replaced by task_unmapped_base. Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/elfload.c | 38 -------------------------------------- 2 files changed, 39 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4f8b55e2fb..12f638336a 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -30,7 +30,6 @@ struct image_info { abi_ulong start_data; abi_ulong end_data; abi_ulong brk; - abi_ulong start_mmap; abi_ulong start_stack; abi_ulong stack_limit; abi_ulong entry; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index dbc5d430e8..fdb87d80d3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -143,8 +143,6 @@ static uint32_t get_elf_hwcap(void) } =20 #ifdef TARGET_X86_64 -#define ELF_START_MMAP 0x2aaaaab000ULL - #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_X86_64 =20 @@ -221,8 +219,6 @@ static bool init_guest_commpage(void) #endif #else =20 -#define ELF_START_MMAP 0x80000000 - /* * This is used to ensure we don't load something for the wrong architectu= re. */ @@ -308,8 +304,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *re= gs, const CPUX86State *en #ifndef TARGET_AARCH64 /* 32 bit ARM definitions */ =20 -#define ELF_START_MMAP 0x80000000 - #define ELF_ARCH EM_ARM #define ELF_CLASS ELFCLASS32 #define EXSTACK_DEFAULT true @@ -600,7 +594,6 @@ static const char *get_elf_platform(void) =20 #else /* 64 bit ARM definitions */ -#define ELF_START_MMAP 0x80000000 =20 #define ELF_ARCH EM_AARCH64 #define ELF_CLASS ELFCLASS64 @@ -871,7 +864,6 @@ const char *elf_hwcap2_str(uint32_t bit) #ifdef TARGET_SPARC #ifdef TARGET_SPARC64 =20 -#define ELF_START_MMAP 0x80000000 #define ELF_HWCAP (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | HWCAP_SPARC_SW= AP \ | HWCAP_SPARC_MULDIV | HWCAP_SPARC_V9) #ifndef TARGET_ABI32 @@ -883,7 +875,6 @@ const char *elf_hwcap2_str(uint32_t bit) #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_SPARCV9 #else -#define ELF_START_MMAP 0x80000000 #define ELF_HWCAP (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | HWCAP_SPARC_SW= AP \ | HWCAP_SPARC_MULDIV) #define ELF_CLASS ELFCLASS32 @@ -905,7 +896,6 @@ static inline void init_thread(struct target_pt_regs *r= egs, #ifdef TARGET_PPC =20 #define ELF_MACHINE PPC_ELF_MACHINE -#define ELF_START_MMAP 0x80000000 =20 #if defined(TARGET_PPC64) =20 @@ -1108,8 +1098,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUPPCState *en =20 #ifdef TARGET_LOONGARCH64 =20 -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_LOONGARCH #define EXSTACK_DEFAULT true @@ -1200,8 +1188,6 @@ static uint32_t get_elf_hwcap(void) =20 #ifdef TARGET_MIPS =20 -#define ELF_START_MMAP 0x80000000 - #ifdef TARGET_MIPS64 #define ELF_CLASS ELFCLASS64 #else @@ -1359,8 +1345,6 @@ static uint32_t get_elf_hwcap(void) =20 #ifdef TARGET_MICROBLAZE =20 -#define ELF_START_MMAP 0x80000000 - #define elf_check_arch(x) ( (x) =3D=3D EM_MICROBLAZE || (x) =3D=3D EM_MICR= OBLAZE_OLD) =20 #define ELF_CLASS ELFCLASS32 @@ -1401,8 +1385,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUMBState *env =20 #ifdef TARGET_NIOS2 =20 -#define ELF_START_MMAP 0x80000000 - #define elf_check_arch(x) ((x) =3D=3D EM_ALTERA_NIOS2) =20 #define ELF_CLASS ELFCLASS32 @@ -1498,8 +1480,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, =20 #ifdef TARGET_OPENRISC =20 -#define ELF_START_MMAP 0x08000000 - #define ELF_ARCH EM_OPENRISC #define ELF_CLASS ELFCLASS32 #define ELF_DATA ELFDATA2MSB @@ -1536,8 +1516,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, =20 #ifdef TARGET_SH4 =20 -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_SH =20 @@ -1618,8 +1596,6 @@ static uint32_t get_elf_hwcap(void) =20 #ifdef TARGET_CRIS =20 -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_CRIS =20 @@ -1635,8 +1611,6 @@ static inline void init_thread(struct target_pt_regs = *regs, =20 #ifdef TARGET_M68K =20 -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_68K =20 @@ -1686,8 +1660,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, const CPUM68KState *e =20 #ifdef TARGET_ALPHA =20 -#define ELF_START_MMAP (0x30000000000ULL) - #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_ALPHA =20 @@ -1705,8 +1677,6 @@ static inline void init_thread(struct target_pt_regs = *regs, =20 #ifdef TARGET_S390X =20 -#define ELF_START_MMAP (0x20000000000ULL) - #define ELF_CLASS ELFCLASS64 #define ELF_DATA ELFDATA2MSB #define ELF_ARCH EM_S390 @@ -1816,7 +1786,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, =20 #ifdef TARGET_RISCV =20 -#define ELF_START_MMAP 0x80000000 #define ELF_ARCH EM_RISCV =20 #ifdef TARGET_RISCV32 @@ -1852,7 +1821,6 @@ static inline void init_thread(struct target_pt_regs = *regs, =20 #ifdef TARGET_HPPA =20 -#define ELF_START_MMAP 0x80000000 #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_PARISC #define ELF_PLATFORM "PARISC" @@ -1904,8 +1872,6 @@ static bool init_guest_commpage(void) =20 #ifdef TARGET_XTENSA =20 -#define ELF_START_MMAP 0x20000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_XTENSA =20 @@ -1971,8 +1937,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *= regs, =20 #ifdef TARGET_HEXAGON =20 -#define ELF_START_MMAP 0x20000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_HEXAGON =20 @@ -3689,8 +3653,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct= image_info *info) interp_info.fp_abi =3D MIPS_ABI_FP_UNKNOWN; #endif =20 - info->start_mmap =3D (abi_ulong)ELF_START_MMAP; - load_elf_image(bprm->filename, bprm->fd, info, &elf_interpreter, bprm->buf); =20 --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=zohomail.com; s=zohoarc; b=QdGVgx4HX6qv4DZAzlBNK0yzCyLPSAWTxRE+kI1x3gKjUh9xUgisyRnTTQtStua57DlLaVEEXpeVQd5RufLWx2I0uDx0Ua7Hdrp2W+IvNP3oRCzMlweJR05MwTpehXUG6p0ObmfqMNZIra68NHEcuGeOQKL5gmHb0JTNy/H0qLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839022; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mus/3sAGYIp/tZt8gw3OhfynvDJwuLWU//9f2MDJGRM=; b=M7xi8SLgNIvUN8N0KbebBnde2BylvTXXVm0OYRPbcGaoq2qQ5wIm/LBErXFPPw1leP1YUbsXYxnJrtZV1uCpXlaGM/QCfaQ7Ddry845oemD/563HG4KgnNhG0Ry55+KsXEUSeg2xnTDaITNhkxeJ9LzzYOE7dyNN78L2KGsAObw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839022084153.07959976612813; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykP-0000TY-U5; Wed, 23 Aug 2023 21:02:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykN-0000ET-QD for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:51 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykK-0000S1-M5 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:51 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68becf931bfso332598b3a.0 for ; Wed, 23 Aug 2023 18:02:48 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838967; x=1693443767; 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=Mus/3sAGYIp/tZt8gw3OhfynvDJwuLWU//9f2MDJGRM=; b=SrOC2Nx/cxZaGF/dcSkCbfCmRcnrl3/S1gkX5sM0rmiZYJrzoA7nsLOoTraI+VrN69 Mt6Gfyb/n+LLzOpDnN+TZd+h8e+KtPvYeg6pGDoihk9KoEsFbcL/ffzCbJUPP2LkZYl1 E9cbFfdJDD8W1Mr5WGLouu/6W2RSQ70X4yyvvynDKZgjIYtbIo8FHsJGVdQn9hBTokYv laNifJ/VgkY+1JGOiaVGmuR0MxHiWASdNmG7Fo3/FkH2/BgsVxMslAS0LQgskHEjzbZa 9zDO5lt9PhWJOy5rBN9mFxUJRMGJbUJG87VGjthSZxMx+r4XSsK2YhaHHz3Rd3kLm7dC mNig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838967; x=1693443767; 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=Mus/3sAGYIp/tZt8gw3OhfynvDJwuLWU//9f2MDJGRM=; b=Unu9MFKH+J9sMUsZdsSBANuanZzpNfF3dJOMVL93B3kVA/w8Ee8E5cYu9CR7tq6Gku eZG7CC/0OCmF1MyRvFPJFId9LuiN7tGYZNAOVLxNQeMl3UZ7nH6ggRujZh3Nte8m2y0q viSc0p10WQPZFvHiEw4EOT7k1bF06zmuK3d4iXBUsoY2yWR/zszODbItRuNITp5axtu/ 6UOoHre2nWVOZRjwnh3Rv2pCw2XLKExnKJuvwKQlS+J9J7b+KWAUK1qxbxXHnLPqdl9T jmFc+roUGGcmKlSv5vRdEWLb82BuPcpiA4pMqyeduGybd33BuBYu4kg43bcZvK5NGDAl ZSnw== X-Gm-Message-State: AOJu0YyJvGp4Tihok0meckcR86p6s3IVpDIbP6ijeoU3IDEOK1+MIma4 F713JiE7oDZjqPrsgU4szJ5r4/7khvQaHtfZWvM= X-Google-Smtp-Source: AGHT+IHpeXUChXao5ZQ8y9Cza8clmDkl4Sf6+KHgPf67W5/VgIVQvi3sPkADykdA5nZjjQxTAtzUYw== X-Received: by 2002:a05:6a00:b84:b0:688:7559:4175 with SMTP id g4-20020a056a000b8400b0068875594175mr12634935pfj.20.1692838967210; Wed, 23 Aug 2023 18:02:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Warner Losh Subject: [PATCH 10/13] linux-user: Move shmat and shmdt implementations to mmap.c Date: Wed, 23 Aug 2023 18:02:34 -0700 Message-Id: <20230824010237.1379735-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839025100100012 Rename from do_* to target_*. Fix some minor checkpatch errors. Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Warner Losh Signed-off-by: Richard Henderson Tested-by: Helge Deller --- linux-user/user-mmap.h | 4 ++ linux-user/mmap.c | 138 +++++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 143 ++--------------------------------------- 3 files changed, 146 insertions(+), 139 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 0f4883eb57..b94bcdcf83 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -58,4 +58,8 @@ abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); =20 +abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, + abi_ulong shmaddr, int shmflg); +abi_long target_shmdt(abi_ulong shmaddr); + #endif /* LINUX_USER_USER_MMAP_H */ diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 9aab48d4a3..3aeacd1ecd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -17,6 +17,7 @@ * along with this program; if not, see . */ #include "qemu/osdep.h" +#include #include "trace.h" #include "exec/log.h" #include "qemu.h" @@ -27,6 +28,14 @@ static pthread_mutex_t mmap_mutex =3D PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; =20 +#define N_SHM_REGIONS 32 + +static struct shm_region { + abi_ulong start; + abi_ulong size; + bool in_use; +} shm_regions[N_SHM_REGIONS]; + void mmap_lock(void) { if (mmap_lock_count++ =3D=3D 0) { @@ -981,3 +990,132 @@ abi_long target_madvise(abi_ulong start, abi_ulong le= n_in, int advice) =20 return ret; } + +#ifndef TARGET_FORCE_SHMLBA +/* + * For most architectures, SHMLBA is the same as the page size; + * some architectures have larger values, in which case they should + * define TARGET_FORCE_SHMLBA and provide a target_shmlba() function. + * This corresponds to the kernel arch code defining __ARCH_FORCE_SHMLBA + * and defining its own value for SHMLBA. + * + * The kernel also permits SHMLBA to be set by the architecture to a + * value larger than the page size without setting __ARCH_FORCE_SHMLBA; + * this means that addresses are rounded to the large size if + * SHM_RND is set but addresses not aligned to that size are not rejected + * as long as they are at least page-aligned. Since the only architecture + * which uses this is ia64 this code doesn't provide for that oddity. + */ +static inline abi_ulong target_shmlba(CPUArchState *cpu_env) +{ + return TARGET_PAGE_SIZE; +} +#endif + +abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, + abi_ulong shmaddr, int shmflg) +{ + CPUState *cpu =3D env_cpu(cpu_env); + abi_ulong raddr; + void *host_raddr; + struct shmid_ds shm_info; + int i, ret; + abi_ulong shmlba; + + /* shmat pointers are always untagged */ + + /* find out the length of the shared memory segment */ + ret =3D get_errno(shmctl(shmid, IPC_STAT, &shm_info)); + if (is_error(ret)) { + /* can't get length, bail out */ + return ret; + } + + shmlba =3D target_shmlba(cpu_env); + + if (shmaddr & (shmlba - 1)) { + if (shmflg & SHM_RND) { + shmaddr &=3D ~(shmlba - 1); + } else { + return -TARGET_EINVAL; + } + } + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { + return -TARGET_EINVAL; + } + + mmap_lock(); + + /* + * We're mapping shared memory, so ensure we generate code for parallel + * execution and flush old translations. This will work up to the lev= el + * supported by the host -- anything that requires EXCP_ATOMIC will not + * be atomic with respect to an external process. + */ + if (!(cpu->tcg_cflags & CF_PARALLEL)) { + cpu->tcg_cflags |=3D CF_PARALLEL; + tb_flush(cpu); + } + + if (shmaddr) { + host_raddr =3D 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 =3D mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, sh= mlba)); + + if (mmap_start =3D=3D -1) { + errno =3D ENOMEM; + host_raddr =3D (void *)-1; + } else { + host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + } + + if (host_raddr =3D=3D (void *)-1) { + mmap_unlock(); + return get_errno((intptr_t)host_raddr); + } + raddr =3D h2g((uintptr_t)host_raddr); + + page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, + PAGE_VALID | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + + for (i =3D 0; i < N_SHM_REGIONS; i++) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use =3D true; + shm_regions[i].start =3D raddr; + shm_regions[i].size =3D shm_info.shm_segsz; + break; + } + } + + mmap_unlock(); + return raddr; +} + +abi_long target_shmdt(abi_ulong shmaddr) +{ + int i; + abi_long rv; + + /* shmdt pointers are always untagged */ + + mmap_lock(); + + for (i =3D 0; i < N_SHM_REGIONS; ++i) { + if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmaddr) { + shm_regions[i].in_use =3D false; + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); + break; + } + } + rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); + + mmap_unlock(); + + return rv; +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8d96acd085..ff4eefe7fc 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3725,14 +3725,6 @@ static abi_long do_socketcall(int num, abi_ulong vpt= r) } #endif =20 -#define N_SHM_REGIONS 32 - -static struct shm_region { - abi_ulong start; - abi_ulong size; - bool in_use; -} shm_regions[N_SHM_REGIONS]; - #ifndef TARGET_SEMID64_DS /* asm-generic version of this struct */ struct target_semid64_ds @@ -4482,133 +4474,6 @@ static inline abi_long do_shmctl(int shmid, int cmd= , abi_long buf) return ret; } =20 -#ifndef TARGET_FORCE_SHMLBA -/* For most architectures, SHMLBA is the same as the page size; - * some architectures have larger values, in which case they should - * define TARGET_FORCE_SHMLBA and provide a target_shmlba() function. - * This corresponds to the kernel arch code defining __ARCH_FORCE_SHMLBA - * and defining its own value for SHMLBA. - * - * The kernel also permits SHMLBA to be set by the architecture to a - * value larger than the page size without setting __ARCH_FORCE_SHMLBA; - * this means that addresses are rounded to the large size if - * SHM_RND is set but addresses not aligned to that size are not rejected - * as long as they are at least page-aligned. Since the only architecture - * which uses this is ia64 this code doesn't provide for that oddity. - */ -static inline abi_ulong target_shmlba(CPUArchState *cpu_env) -{ - return TARGET_PAGE_SIZE; -} -#endif - -static abi_ulong do_shmat(CPUArchState *cpu_env, int shmid, - abi_ulong shmaddr, int shmflg) -{ - CPUState *cpu =3D env_cpu(cpu_env); - abi_ulong raddr; - void *host_raddr; - struct shmid_ds shm_info; - int i, ret; - abi_ulong shmlba; - - /* shmat pointers are always untagged */ - - /* find out the length of the shared memory segment */ - ret =3D get_errno(shmctl(shmid, IPC_STAT, &shm_info)); - if (is_error(ret)) { - /* can't get length, bail out */ - return ret; - } - - shmlba =3D target_shmlba(cpu_env); - - if (shmaddr & (shmlba - 1)) { - if (shmflg & SHM_RND) { - shmaddr &=3D ~(shmlba - 1); - } else { - return -TARGET_EINVAL; - } - } - if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { - return -TARGET_EINVAL; - } - - mmap_lock(); - - /* - * We're mapping shared memory, so ensure we generate code for parallel - * execution and flush old translations. This will work up to the lev= el - * supported by the host -- anything that requires EXCP_ATOMIC will not - * be atomic with respect to an external process. - */ - if (!(cpu->tcg_cflags & CF_PARALLEL)) { - cpu->tcg_cflags |=3D CF_PARALLEL; - tb_flush(cpu); - } - - if (shmaddr) - host_raddr =3D 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 =3D mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, sh= mlba)); - - if (mmap_start =3D=3D -1) { - errno =3D ENOMEM; - host_raddr =3D (void *)-1; - } else - host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); - } - - if (host_raddr =3D=3D (void *)-1) { - mmap_unlock(); - return get_errno((intptr_t)host_raddr); - } - raddr =3D h2g((uintptr_t)host_raddr); - - page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, - PAGE_VALID | PAGE_RESET | PAGE_READ | - (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); - - for (i =3D 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use =3D true; - shm_regions[i].start =3D raddr; - shm_regions[i].size =3D shm_info.shm_segsz; - break; - } - } - - mmap_unlock(); - return raddr; -} - -static inline abi_long do_shmdt(abi_ulong shmaddr) -{ - int i; - abi_long rv; - - /* shmdt pointers are always untagged */ - - mmap_lock(); - - for (i =3D 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmaddr) { - shm_regions[i].in_use =3D false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); - break; - } - } - rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); - - mmap_unlock(); - - return rv; -} - #ifdef TARGET_NR_ipc /* ??? This only works with linear mappings. */ /* do_ipc() must return target values and target errnos. */ @@ -4695,7 +4560,7 @@ static abi_long do_ipc(CPUArchState *cpu_env, default: { abi_ulong raddr; - raddr =3D do_shmat(cpu_env, first, ptr, second); + raddr =3D target_shmat(cpu_env, first, ptr, second); if (is_error(raddr)) return get_errno(raddr); if (put_user_ual(raddr, third)) @@ -4708,7 +4573,7 @@ static abi_long do_ipc(CPUArchState *cpu_env, } break; case IPCOP_shmdt: - ret =3D do_shmdt(ptr); + ret =3D target_shmdt(ptr); break; =20 case IPCOP_shmget: @@ -11008,11 +10873,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env= , int num, abi_long arg1, #endif #ifdef TARGET_NR_shmat case TARGET_NR_shmat: - return do_shmat(cpu_env, arg1, arg2, arg3); + return target_shmat(cpu_env, arg1, arg2, arg3); #endif #ifdef TARGET_NR_shmdt case TARGET_NR_shmdt: - return do_shmdt(arg1); + return target_shmdt(arg1); #endif case TARGET_NR_fsync: return get_errno(fsync(arg1)); --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839145292732.754840953506; Wed, 23 Aug 2023 18:05:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykQ-0000VQ-ML; Wed, 23 Aug 2023 21:02:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykN-0000CX-L5 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:51 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykL-0000SO-6T for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:51 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68bec436514so343635b3a.1 for ; Wed, 23 Aug 2023 18:02:48 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838968; x=1693443768; 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=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; b=r9+NLgS5S+LsSI8suNS7NKaI1yjI4AM4dEypvxowmk4J2Hf00Z55sm826uPo7EgaE7 DhQxxuXVpvp6hb5jp3IFn7Ud9AM2VZFrhOAGVhsaBt6RnK5P6f3Mq8bBne12FyrneVKo 4RP11syEagwVy9u8Tnk8bTVW/gevxmgeqLbbGQ687RKJ31ILit6tZTPcW+NSRlhe5YAr OD1A4/MY6j7SDmeVXVK8yUs5r6Zseb+D2CwaNaqcAD5/Mfe9KNe3kS9lgjpjm9Q6faPH w7DjOk+3uJKT+8ZCIYOWLlQBbjcam9OCFL8GbMQLHSW8O4WZzsEPqedpznyp8GQr5Qqb XXEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838968; x=1693443768; 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=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; b=MzTEJpqLO2IwEP1LoR73VldEA3uUyyKuS85moyxvAycQjEQx7+mRw4S4hDyCLHbX7S 98BlmqNniPbGvS+F/VuLly1QsUDxYBLfsfRLo7JmX5b/90eZl36+ajO3Ho6/6f4bHgEw LsQoDiUysoSUbV3VVOXOIv4LVSH18eMrdr1RpQhR69fg/dAQhaLB/dfqP5CDj186Su66 +9KSgVhosZJp/DwWU36CqGFABso84VAHm3JaibJXEPeE8btMwxGiCLWC35tyafIs/rtb nhQOcrQgztfwNZWgCgz3UVhqoC3eGYDWP7ZUtb/wmzT41FWFkMd6YBLg8QQAuCSAikOs nhhA== X-Gm-Message-State: AOJu0Yze3MV9U7gcLH86nfCB6lXlYukR78IBOD2rMDOSR+1wJhapTH6m rG5m4FxUtzD8E5SF/KOwduan74mDgpq4QCx13Iw= X-Google-Smtp-Source: AGHT+IH/qQDTknwDu5Myvas91exk3C6vOG58/duVL5Q8quUx7krY2EM5JdZpiSmGCJCBOhjxfl/YHQ== X-Received: by 2002:a05:6a20:9381:b0:140:48d4:8199 with SMTP id x1-20020a056a20938100b0014048d48199mr15332400pzh.24.1692838968004; Wed, 23 Aug 2023 18:02:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/13] linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat, shmdt} Date: Wed, 23 Aug 2023 18:02:35 -0700 Message-Id: <20230824010237.1379735-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1692839146826100003 Content-Type: text/plain; charset="utf-8" Move the CF_PARALLEL setting outside of the mmap lock. Signed-off-by: Richard Henderson Reviewed-by: Helge Deller Tested-by: Helge Deller --- linux-user/mmap.c | 98 ++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 3aeacd1ecd..f45b2d307c 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1017,9 +1017,8 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shm= id, { CPUState *cpu =3D env_cpu(cpu_env); abi_ulong raddr; - void *host_raddr; struct shmid_ds shm_info; - int i, ret; + int ret; abi_ulong shmlba; =20 /* shmat pointers are always untagged */ @@ -1044,7 +1043,43 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int sh= mid, return -TARGET_EINVAL; } =20 - mmap_lock(); + WITH_MMAP_LOCK_GUARD() { + void *host_raddr; + + if (shmaddr) { + host_raddr =3D shmat(shmid, (void *)g2h_untagged(shmaddr), shm= flg); + } else { + abi_ulong mmap_start; + + /* In order to use the host shmat, we need to honor host SHMLB= A. */ + mmap_start =3D mmap_find_vma(0, shm_info.shm_segsz, + MAX(SHMLBA, shmlba)); + + if (mmap_start =3D=3D -1) { + return -TARGET_ENOMEM; + } + host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + + if (host_raddr =3D=3D (void *)-1) { + return get_errno(-1); + } + raddr =3D h2g(host_raddr); + + page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, + PAGE_VALID | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); + + for (int i =3D 0; i < N_SHM_REGIONS; i++) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use =3D true; + shm_regions[i].start =3D raddr; + shm_regions[i].size =3D shm_info.shm_segsz; + break; + } + } + } =20 /* * We're mapping shared memory, so ensure we generate code for parallel @@ -1057,65 +1092,24 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int s= hmid, tb_flush(cpu); } =20 - if (shmaddr) { - host_raddr =3D 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 =3D mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, sh= mlba)); - - if (mmap_start =3D=3D -1) { - errno =3D ENOMEM; - host_raddr =3D (void *)-1; - } else { - host_raddr =3D shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); - } - } - - if (host_raddr =3D=3D (void *)-1) { - mmap_unlock(); - return get_errno((intptr_t)host_raddr); - } - raddr =3D h2g((uintptr_t)host_raddr); - - page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, - PAGE_VALID | PAGE_RESET | PAGE_READ | - (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); - - for (i =3D 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use =3D true; - shm_regions[i].start =3D raddr; - shm_regions[i].size =3D shm_info.shm_segsz; - break; - } - } - - mmap_unlock(); return raddr; } =20 abi_long target_shmdt(abi_ulong shmaddr) { - int i; abi_long rv; =20 /* shmdt pointers are always untagged */ =20 - mmap_lock(); - - for (i =3D 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmaddr) { - shm_regions[i].in_use =3D false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); - break; + WITH_MMAP_LOCK_GUARD() { + for (int i =3D 0; i < N_SHM_REGIONS; ++i) { + if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmad= dr) { + shm_regions[i].in_use =3D false; + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1,= 0); + break; + } } + rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); } - rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); - - mmap_unlock(); - return rv; } --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=zohomail.com; s=zohoarc; b=cHvH+SQgEoppOev0DaERqlTa0f5DfE4i2kVyPsYed0XaeGfOpK76t4K5wKvdJjpwx08ZpFvzZ49zNJ90/HecC2Bs2N46OCL0jq+ZpRMggLVzcMgttBza2aLJQiUx8/GTQfN8DeeZuBnikuY+qY5wNGGxqMzMy0QNaYvGASrpACw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839022; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; b=SN7BgzWJL7dI0ExRMTJRXWlUb0JpAfPyx7HCSn4/jYVUBS6M+IpSLRrAELH1xwDibO+dfajsHDSRdC+EaxOEcfElWh6Em+DOyJPyZkhSO4PJvJWFBvoMeooq7AkrDR2splug1lhgEDwx6xu2UPx4dNwa8g8D4OML1/UKbnmYUYk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839022519421.94805779601256; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykR-0000Vb-IF; Wed, 23 Aug 2023 21:02:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykO-0000I6-9U for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:52 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykM-0000SW-2C for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:52 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68a3cae6d94so3798192b3a.0 for ; Wed, 23 Aug 2023 18:02:49 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838968; x=1693443768; 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=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; b=PmAiyfwTTuuPEHsHlhJjJr+qiHa326xnhaPXsS3HQTMhUH8lUdR0NyydPQU8te2Qjf oTwA625MsUmE3qgD7XcZmOaOdV2iOs6Aze0zSVKvd9HyryxCRwS92Cqu8BB6m85G6ohl XCR1XwOji6M0621KQ1KYxPGeuiMzMXjpt17ZUbUxlGIQr1IzscCWGlEheLpLUkLchFe4 cb8zTjh8+gtCzOF70XuFcj27ChqIGsk9gCpvb/rxGf/Qsh5RqR9jXtFZs/l62FNCT5PI KwarTSHnNEgfGuTJFQ0m3kQBHjFgg8G0bFoNhEdUgYGEwFdy0u0rMocMz6p6dliQLfUz sb9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838968; x=1693443768; 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=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; b=S5JVVX0h6gNwfXBquXpon2GgPWLaBJWDCrvtJxcE/dGL4t0G1aSSer77rCmcrApNpo dKjgEXQ2QQ1fKh3ATQsWq0cINaarNDTdH+wQeJzw9bfRyb2MJOV/s+Vk12XdZgc3QM/b LcO0j1yUUUkEQhx/cEkjIx4C28jVzV1yCxxER6uq5l+9Iz2IoGE7LIpTPg3Trmjvqv/o biQhcIy/KqcLcCDgWfZMwVIUDnQaUs7O9z/evKeb1mKRSutjSwmL3AMf3iQjdbdALCY+ d1XEwIyFwQHc8+FVvzjET9m2To5mAkwh0XW2n04olgiMrgWPZMUyNJbA4IwZ/GdEbToe hRiA== X-Gm-Message-State: AOJu0Yz8FdpXxQ/G+iF3gn0dec0t9Z+XVyP0oQ9WHy2AGHjzwZmtAm9a DGjDwGu/Q8rS7ifb/viLWrGYDumVTNcNzw4ANUk= X-Google-Smtp-Source: AGHT+IEegzGDh0ESub1IYR6x1hGeYE2UTqJ/X5zKLhr276gcOmoQxJyxhByknB1DLzdKYF17SEE2NQ== X-Received: by 2002:a05:6a20:8e29:b0:144:c131:dbe2 with SMTP id y41-20020a056a208e2900b00144c131dbe2mr17605700pzj.5.1692838968635; Wed, 23 Aug 2023 18:02:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 12/13] linux-user: Fix shmdt Date: Wed, 23 Aug 2023 18:02:36 -0700 Message-Id: <20230824010237.1379735-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839025055100007 Content-Type: text/plain; charset="utf-8" If the shm region is not mapped at shmaddr, EINVAL. Do not unmap the region until the syscall succeeds. Use mmap_reserve_or_unmap to preserve reserved_va semantics. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Helge Deller --- linux-user/mmap.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index f45b2d307c..44116c014b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1102,14 +1102,25 @@ abi_long target_shmdt(abi_ulong shmaddr) /* shmdt pointers are always untagged */ =20 WITH_MMAP_LOCK_GUARD() { - for (int i =3D 0; i < N_SHM_REGIONS; ++i) { + int i; + + for (i =3D 0; i < N_SHM_REGIONS; ++i) { if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmad= dr) { - shm_regions[i].in_use =3D false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1,= 0); break; } } + if (i =3D=3D N_SHM_REGIONS) { + return -TARGET_EINVAL; + } + rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); + if (rv =3D=3D 0) { + abi_ulong size =3D shm_regions[i].size; + + shm_regions[i].in_use =3D false; + page_set_flags(shmaddr, shmaddr + size - 1, 0); + mmap_reserve_or_unmap(shmaddr, size); + } } return rv; } --=20 2.34.1 From nobody Thu Nov 28 08:38:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=zohomail.com; s=zohoarc; b=nw20ry4SUY/5fSLOFPYun8cr72b+OJHC6z1eUgyEwN79KiWg40OarcyTWE+qdfjDmFhK0CoJTPYFIP4LdDC34quce4t/U4tGc5X0D28YHhAyC6U3pb7Jrce1QV+pwlKBWjWT49w9LVmhOOqgWwidU3maHfGf1z0eLc9BFz74XnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692839022; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UN+H+/GfTniCDQqNqoi86BdHI3S12YJ9y5ScYnnODH0=; b=c1sob0WKuFlPsDs1dI+4Rfd8QODZRV2K2TpxTRcYZoEv6RqM1S2QltgUi0RRXL3CxsfKuTTmPgaWelxyeU3GdpWPbSmPnngLIm/xHnmpP5trNQHl90qDS3GiO5G0A6ry7BvE3FW8YjMjibdAzzhUf7GywqXNYO7UeCj8c0LxzF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692839022482895.8434636331882; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYykQ-0000V2-CU; Wed, 23 Aug 2023 21:02:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYykP-0000Qv-H8 for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:53 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYykN-0000Sm-2s for qemu-devel@nongnu.org; Wed, 23 Aug 2023 21:02:53 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-563f8e8a53dso3647145a12.3 for ; Wed, 23 Aug 2023 18:02:50 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id c10-20020aa78c0a000000b006875df4773fsm2050789pfd.163.2023.08.23.18.02.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 18:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692838969; x=1693443769; 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=UN+H+/GfTniCDQqNqoi86BdHI3S12YJ9y5ScYnnODH0=; b=OmIoDg8z1OjtcnAW2jF/7FS2KO+ERxDBZ96xWzyHurHPJQrMrFvSlXvWTOGQOWDd4G qOH94u+TkJ/bwhVkPFsrx8yYmWG7ZWfHc+RU4CUvA69cAnG2l/nCuFTo1dKerpsZ1WRy Yh7LNkEXiCgDrox+wDWGTaNwOEKLb9RX7wUzyWwBVAJZWt902ypLQyk1zJID/XitUyIf 9HuctgRO+eIUkn8YrsJtaE63fuxRbJLBGKXxqJxcSNS3AblkbxtsTACgxlBisoWmZ6Ow AIGUxMJZ4Pqi0ve5/IRJB2NTRw6ZE4SKPJ4CC5fKYXDCGjgCyfLtDgzTCwXlfIt8Jxvm 7k9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692838969; x=1693443769; 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=UN+H+/GfTniCDQqNqoi86BdHI3S12YJ9y5ScYnnODH0=; b=RmnohysdnzkMAaqsiN9QlAh6a5H3Zi1zbKk9lQ3T+/W+dOjcgbnTmWqeq7bhUGWwLk vAkt/J3bDNhPOAkp35HumtXl1z8Yp1XtY6DhA2GiFoS4QQTtj8GSVvH3zDikDgy2FLsz e33gOpOF2tugAho8XVdD9Q5XMr1jY0oo1DBMizH8yHtNMnBxki7rALb7UlZLqPkblobz gBLMIJ9oHJwWwedcagjMEvW/OtkmgMCo9KrNtu2Xz+CsG7SWzUWfk/aIbZC77wOjv0UM ttnqRpI7aV6fTZ3hN0Mz1yD+FFnDaC2j3B+1Q0YXb/F/XBJOyQXRwPE3VT5T9Ea8wQcA 7HDA== X-Gm-Message-State: AOJu0YwhzVPRwSOBzUmE03UfZf4GL0ywMf68RDZoy3k7pjM6ykRQthpz gNc6lnS7VW9MpaJLW2FCi6JgUQ3jXgY6ip0Gv18= X-Google-Smtp-Source: AGHT+IFGOwhPb0tp2gvGCMfGSBEQdXxyU87HV6wtyE9gncPKj+BYT3zv51B5a1ZIhErgM3+Xu6uVHg== X-Received: by 2002:a05:6a21:3b4a:b0:14b:8023:33b3 with SMTP id zy10-20020a056a213b4a00b0014b802333b3mr3451667pzb.19.1692838969324; Wed, 23 Aug 2023 18:02:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 13/13] linux-user: Track shm regions with an interval tree Date: Wed, 23 Aug 2023 18:02:37 -0700 Message-Id: <20230824010237.1379735-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824010237.1379735-1-richard.henderson@linaro.org> References: <20230824010237.1379735-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692839025078100010 Content-Type: text/plain; charset="utf-8" Remove the fixed size shm_regions[] array. Remove references when other mappings completely remove or replace a region. Signed-off-by: Richard Henderson Reviewed-by: Helge Deller Tested-by: Helge Deller --- linux-user/mmap.c | 81 +++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 44116c014b..8eaf57b208 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -24,18 +24,11 @@ #include "user-internals.h" #include "user-mmap.h" #include "target_mman.h" +#include "qemu/interval-tree.h" =20 static pthread_mutex_t mmap_mutex =3D PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; =20 -#define N_SHM_REGIONS 32 - -static struct shm_region { - abi_ulong start; - abi_ulong size; - bool in_use; -} shm_regions[N_SHM_REGIONS]; - void mmap_lock(void) { if (mmap_lock_count++ =3D=3D 0) { @@ -73,6 +66,44 @@ void mmap_fork_end(int child) } } =20 +/* Protected by mmap_lock. */ +static IntervalTreeRoot shm_regions; + +static void shm_region_add(abi_ptr start, abi_ptr last) +{ + IntervalTreeNode *i =3D g_new0(IntervalTreeNode, 1); + + i->start =3D start; + i->last =3D last; + interval_tree_insert(i, &shm_regions); +} + +static abi_ptr shm_region_find(abi_ptr start) +{ + IntervalTreeNode *i; + + for (i =3D interval_tree_iter_first(&shm_regions, start, start); i; + i =3D interval_tree_iter_next(i, start, start)) { + if (i->start =3D=3D start) { + return i->last; + } + } + return 0; +} + +static void shm_region_rm_complete(abi_ptr start, abi_ptr last) +{ + IntervalTreeNode *i, *n; + + for (i =3D interval_tree_iter_first(&shm_regions, start, last); i; i = =3D n) { + n =3D interval_tree_iter_next(i, start, last); + if (i->start >=3D start && i->last <=3D last) { + interval_tree_remove(i, &shm_regions); + g_free(i); + } + } +} + /* * Validate target prot bitmask. * Return the prot bitmask for the host in *HOST_PROT. @@ -729,6 +760,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, page_set_flags(passthrough_last + 1, last, page_flags); } } + shm_region_rm_complete(start, last); the_end: trace_target_mmap_complete(start); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { @@ -826,6 +858,7 @@ int target_munmap(abi_ulong start, abi_ulong len) mmap_lock(); mmap_reserve_or_unmap(start, len); page_set_flags(start, start + len - 1, 0); + shm_region_rm_complete(start, start + len - 1); mmap_unlock(); =20 return 0; @@ -915,8 +948,10 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong o= ld_size, new_addr =3D h2g(host_addr); prot =3D page_get_flags(old_addr); page_set_flags(old_addr, old_addr + old_size - 1, 0); + shm_region_rm_complete(old_addr, old_addr + old_size - 1); page_set_flags(new_addr, new_addr + new_size - 1, prot | PAGE_VALID | PAGE_RESET); + shm_region_rm_complete(new_addr, new_addr + new_size - 1); } mmap_unlock(); return new_addr; @@ -1045,6 +1080,7 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shm= id, =20 WITH_MMAP_LOCK_GUARD() { void *host_raddr; + abi_ulong last; =20 if (shmaddr) { host_raddr =3D shmat(shmid, (void *)g2h_untagged(shmaddr), shm= flg); @@ -1066,19 +1102,14 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int s= hmid, return get_errno(-1); } raddr =3D h2g(host_raddr); + last =3D raddr + shm_info.shm_segsz - 1; =20 - page_set_flags(raddr, raddr + shm_info.shm_segsz - 1, + page_set_flags(raddr, last, PAGE_VALID | PAGE_RESET | PAGE_READ | (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); =20 - for (int i =3D 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use =3D true; - shm_regions[i].start =3D raddr; - shm_regions[i].size =3D shm_info.shm_segsz; - break; - } - } + shm_region_rm_complete(raddr, last); + shm_region_add(raddr, last); } =20 /* @@ -1102,23 +1133,17 @@ abi_long target_shmdt(abi_ulong shmaddr) /* shmdt pointers are always untagged */ =20 WITH_MMAP_LOCK_GUARD() { - int i; - - for (i =3D 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start =3D=3D shmad= dr) { - break; - } - } - if (i =3D=3D N_SHM_REGIONS) { + abi_ulong last =3D shm_region_find(shmaddr); + if (last =3D=3D 0) { return -TARGET_EINVAL; } =20 rv =3D get_errno(shmdt(g2h_untagged(shmaddr))); if (rv =3D=3D 0) { - abi_ulong size =3D shm_regions[i].size; + abi_ulong size =3D last - shmaddr + 1; =20 - shm_regions[i].in_use =3D false; - page_set_flags(shmaddr, shmaddr + size - 1, 0); + page_set_flags(shmaddr, last, 0); + shm_region_rm_complete(shmaddr, last); mmap_reserve_or_unmap(shmaddr, size); } } --=20 2.34.1