From patchwork Thu Aug 24 01:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716491 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091567wrp; Wed, 23 Aug 2023 18:04:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/6/NXLEIfkVeHmHzHkvMQh6IZfMpv7NdO42UHB/kR5nhcJLuqn9dhiPMssgQco9icQIFj X-Received: by 2002:a05:620a:1a16:b0:76c:df5d:13a9 with SMTP id bk22-20020a05620a1a1600b0076cdf5d13a9mr17152352qkb.58.1692839075667; Wed, 23 Aug 2023 18:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839075; cv=none; d=google.com; s=arc-20160816; b=MfRjvEI/sHrwBR0PfghFKUlgnk4cEnkvpQ1bZM/VCF7UcMQhZ0LkIJi0EYmjfM3btU TFfWjOyHSXPA+gXVHNSRfLoZIFfY/UvjGIgrYkH7QkvIEssU2pUh8oKreGodZWWywWIV sX9jSBqf0A6WjjXNL2Rvps0eDO3InBw5hvwhg6bpOA5Vn3Zb/o8e/44ndG94M/kU8NZB smZHH1nxaypNg0OuXC4JRRfrq6oa2zxCKIDkXmqVpVbiRv1o3UevhszntCFAspRIpTxi rJIAUD2QQwIiqfh6sJUeU09DSsN/JcKI03EGm2AyZWgnOeI/SD04av3ptZy+uXecdSDO ajXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wPP+gA6R3N32OGWovg7WhoS2VIkJuzBfzz5kdSKolx0=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=0p8ZB8qSOGWqtQqisNydcGU72t9Hd5aLSUq/a2ka6Nv24QbYuyE5CeMFau2nJbjlJG IgKUo1aWmvEGhnYQIV7OyVGCGv7K5r3Cwk9lmcveTpYOWRmk8XV/6Kkw75NNMyH7Ftqf Fd2I8mOucRyXeYSVuFZG0Ml/tDTQv2c6cd8mEajHmuKAiNaJgYpfXoY/c+xxdF/OvQ/s 63iQXV7o1MOQpVoxNz9o/CgCoe+Z4xoigkfg0hvmVaQkZVLMZzGhWvuvKRlD2yyb8vos atf12L79pDB81TaSdHVEjdvKZUq7Oq71pCVfEU+QeUF8bk7eAMN84ElbhosUb/MEEihK NM4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fYTUWMZK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q4-20020a05620a0d8400b0076d0b35958bsi7945833qkl.568.2023.08.23.18.04.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:04:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fYTUWMZK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é --- 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_proc.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_proc.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 = sysconf(_SC_NPROCESSORS_ONLN); + for (i = 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/target_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_proc.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 = sysconf(_SC_NPROCESSORS_ONLN); + RISCVCPU *cpu = env_archcpu(cpu_env); + const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env); + char *isa_string = riscv_isa_string(cpu); + const char *mmu; + + if (cfg->mmu) { + mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48"; + } else { + mmu = "none"; + } + + for (i = 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=tcg 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 = 0, since SMT / SIGP_SET_MULTI_THREADING is not supported. + * + * Keep the code structure close to arch/s390/kernel/processor.c. + */ + +static void show_facilities(int fd) +{ + size_t sizeof_stfl_bytes = 2048; + g_autofree uint8_t *stfl_bytes = 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 = 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_BITS, + n); +} + +static void show_cpu_summary(CPUArchState *cpu_env, int fd) +{ + S390CPUModel *model = env_archcpu(cpu_env)->model; + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + uint32_t elf_hwcap = 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 = 0; i < sizeof(elf_hwcap) * 8; i++) { + if (!(elf_hwcap & (1 << i))) { + continue; + } + hwcap_str = elf_hwcap_str(i); + if (hwcap_str) { + dprintf(fd, "%s ", hwcap_str); + } + } + dprintf(fd, "\n"); + show_facilities(fd); + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor %d: " + "version = %02X, " + "identification = %06X, " + "machine = %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 = 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 = sysconf(_SC_NPROCESSORS_ONLN); + int i; + + show_cpu_summary(cpu_env, fd); + for (i = 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_proc.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_proc.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) } } +#include "target_proc.h" + #if HOST_BIG_ENDIAN != 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) == 0; @@ -8393,171 +8395,6 @@ static int open_net_route(CPUArchState *cpu_env, int fd) } #endif -#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 = sysconf(_SC_NPROCESSORS_ONLN); - for (i = 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 = sysconf(_SC_NPROCESSORS_ONLN); - RISCVCPU *cpu = env_archcpu(cpu_env); - const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env); - char *isa_string = riscv_isa_string(cpu); - const char *mmu; - - if (cfg->mmu) { - mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48"; - } else { - mmu = "none"; - } - - for (i = 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=tcg 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 = 0, since SMT / SIGP_SET_MULTI_THREADING is not supported. - * - * Keep the code structure close to arch/s390/kernel/processor.c. - */ - -static void show_facilities(int fd) -{ - size_t sizeof_stfl_bytes = 2048; - g_autofree uint8_t *stfl_bytes = 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 = 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_BITS, - n); -} - -static void show_cpu_summary(CPUArchState *cpu_env, int fd) -{ - S390CPUModel *model = env_archcpu(cpu_env)->model; - int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); - uint32_t elf_hwcap = 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 = 0; i < sizeof(elf_hwcap) * 8; i++) { - if (!(elf_hwcap & (1 << i))) { - continue; - } - hwcap_str = elf_hwcap_str(i); - if (hwcap_str) { - dprintf(fd, "%s ", hwcap_str); - } - } - dprintf(fd, "\n"); - show_facilities(fd); - for (i = 0; i < num_cpus; i++) { - dprintf(fd, "processor %d: " - "version = %02X, " - "identification = %06X, " - "machine = %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 = 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 = sysconf(_SC_NPROCESSORS_ONLN); - int i; - - show_cpu_summary(cpu_env, fd); - for (i = 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 dirfd, const char *fname, #if HOST_BIG_ENDIAN != 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 } From patchwork Thu Aug 24 01:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716494 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091901wrp; Wed, 23 Aug 2023 18:05:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE41KqJLx1BCOLGJyAkFR8WiLe73Nv2veIqF1+R5V4nW+WZLyX7lV6Bo/LfewjH0KsE5bUr X-Received: by 2002:ac8:4e4d:0:b0:410:7ba7:3815 with SMTP id e13-20020ac84e4d000000b004107ba73815mr18648242qtw.35.1692839133486; Wed, 23 Aug 2023 18:05:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839133; cv=none; d=google.com; s=arc-20160816; b=ihXUiWzhA8jcoOS1On4NcUgTxg8eZY3zcjXa/yP3NJZZir2YslYnhv57VJPleAxjdw nsOGTLbN6MVaBoScho5xLHnnw72+CsIV96NWPmJtZmLzcMwdkVzDFEKSe2VZ94Gm2Tdf BXdhDDGVxisNGB6Q93ltIZPa7fr0ph40cIgwtEcWQPIZ/RUnOn0yC0wEuzorSUoF3uN1 HwLxoT40Xxu1OHOvl6rn2GpjzNdcCLoHvlstq5ZfQb2ZI7zmr0RyPM5c7ktdOlPkr/gR wjIvCvYu0yiTFw05Qw1gVzN/qqlEys6Jjng4pNJ/CCS090E8tekOGtrTtA6w9kQrVcx2 /A2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wal0ceK+IUSRsFq7bdrVrWMU0yw4HOVJbg4k4NIo3Hk=; fh=nKwyeXx8rt8hF214OSFP+HjBpDto8utNxLoZSNqK/Bc=; b=KzXzThh96OrpPc7rPKer/TpaW26pwNXlZsYyexFfcc2DfKj75AMDGoXJ7sOOR7O41p 3LcjpfVyaxNtlPG3NDyvW178xFSi3oszN1dqK6daZfwOSnXACQWtZRAI/KUbZiBg2YFZ /DJTsWQJm3qTxaj8mSaq5aqHtAQXKwN2KuOACOyr+VygxPVVr5Bsdwh0NVyOF9JjAlSB mG3XGoHVpMdzJ3bYXASuUCKzAbMLIxoAI3ffnCEnudeeSI0u9r+w/uBejIHTFBh4J8+i Ky9FLMfg0dPHHoPi1S1qNdU7lvDMNuc/Pl3kOhZa2d9yZ5nxh7G3v/7uK12DIlqmd1/c UHkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bq38sBa8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d2-20020a0ce442000000b0064d325919a2si5705485qvm.280.2023.08.23.18.05.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:05:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bq38sBa8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 idiva 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 idiva 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 --- 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_proc.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 = env_archcpu(cpu_env); + int arch, midr_rev, midr_part, midr_var, midr_impl; + target_ulong elf_hwcap = get_elf_hwcap(); + target_ulong elf_hwcap2 = 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 = 8; + elf_name = "v8" END_SUFFIX; + midr_rev = FIELD_EX32(cpu->midr, MIDR_EL1, REVISION); + midr_part = FIELD_EX32(cpu->midr, MIDR_EL1, PARTNUM); + midr_var = FIELD_EX32(cpu->midr, MIDR_EL1, VARIANT); + midr_impl = FIELD_EX32(cpu->midr, MIDR_EL1, IMPLEMENTER); + len_part = 3; + len_var = 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 = 7; + midr_var = (cpu->midr >> 16) & 0x7f; + len_var = 2; + if (arm_feature(&cpu->env, ARM_FEATURE_M)) { + elf_name = "armv7m" END_SUFFIX; + } else { + elf_name = "armv7" END_SUFFIX; + } + } else { + midr_part = cpu->midr >> 4; + len_part = 7; + if (arm_feature(&cpu->env, ARM_FEATURE_V6)) { + arch = 6; + elf_name = "armv6" END_SUFFIX; + } else if (arm_feature(&cpu->env, ARM_FEATURE_V5)) { + arch = 5; + elf_name = "armv5t" END_SUFFIX; + } else { + arch = 4; + elf_name = "armv4" END_SUFFIX; + } + } + } +#endif + +#undef END_SUFFIX + + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + for (int i = 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 = elf_hwcap; j ; j &= j - 1) { + dprintf(fd, " %s", elf_hwcap_str(ctz64(j))); + } + for (target_ulong j = elf_hwcap2; j ; j &= 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 >= 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 *src, extern unsigned long guest_stack_size; -#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 #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() -static uint32_t get_elf_hwcap(void) +uint32_t get_elf_hwcap(void) { ARMCPU *cpu = ARM_CPU(thread_cpu); uint32_t hwcaps = 0; @@ -508,7 +508,7 @@ static uint32_t get_elf_hwcap(void) return hwcaps; } -static uint32_t get_elf_hwcap2(void) +uint32_t get_elf_hwcap2(void) { ARMCPU *cpu = ARM_CPU(thread_cpu); uint32_t hwcaps = 0; @@ -521,6 +521,49 @@ static uint32_t get_elf_hwcap2(void) return hwcaps; } +const char *elf_hwcap_str(uint32_t bit) +{ + static const char *hwcap_str[] = { + [__builtin_ctz(ARM_HWCAP_ARM_SWP )] = "swp", + [__builtin_ctz(ARM_HWCAP_ARM_HALF )] = "half", + [__builtin_ctz(ARM_HWCAP_ARM_THUMB )] = "thumb", + [__builtin_ctz(ARM_HWCAP_ARM_26BIT )] = "26bit", + [__builtin_ctz(ARM_HWCAP_ARM_FAST_MULT)] = "fast_mult", + [__builtin_ctz(ARM_HWCAP_ARM_FPA )] = "fpa", + [__builtin_ctz(ARM_HWCAP_ARM_VFP )] = "vfp", + [__builtin_ctz(ARM_HWCAP_ARM_EDSP )] = "edsp", + [__builtin_ctz(ARM_HWCAP_ARM_JAVA )] = "java", + [__builtin_ctz(ARM_HWCAP_ARM_IWMMXT )] = "iwmmxt", + [__builtin_ctz(ARM_HWCAP_ARM_CRUNCH )] = "crunch", + [__builtin_ctz(ARM_HWCAP_ARM_THUMBEE )] = "thumbee", + [__builtin_ctz(ARM_HWCAP_ARM_NEON )] = "neon", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv3 )] = "vfpv3", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv3D16 )] = "vfpv3d16", + [__builtin_ctz(ARM_HWCAP_ARM_TLS )] = "tls", + [__builtin_ctz(ARM_HWCAP_ARM_VFPv4 )] = "vfpv4", + [__builtin_ctz(ARM_HWCAP_ARM_IDIVA )] = "idiva", + [__builtin_ctz(ARM_HWCAP_ARM_IDIVT )] = "idivt", + [__builtin_ctz(ARM_HWCAP_ARM_VFPD32 )] = "vfpd32", + [__builtin_ctz(ARM_HWCAP_ARM_LPAE )] = "lpae", + [__builtin_ctz(ARM_HWCAP_ARM_EVTSTRM )] = "evtstrm", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + +const char *elf_hwcap2_str(uint32_t bit) +{ + static const char *hwcap_str[] = { + [__builtin_ctz(ARM_HWCAP2_ARM_AES )] = "aes", + [__builtin_ctz(ARM_HWCAP2_ARM_PMULL)] = "pmull", + [__builtin_ctz(ARM_HWCAP2_ARM_SHA1 )] = "sha1", + [__builtin_ctz(ARM_HWCAP2_ARM_SHA2 )] = "sha2", + [__builtin_ctz(ARM_HWCAP2_ARM_CRC32)] = "crc32", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + #undef GET_FEATURE #undef GET_FEATURE_ID @@ -668,7 +711,7 @@ enum { #define GET_FEATURE_ID(feat, hwcap) \ do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) -static uint32_t get_elf_hwcap(void) +uint32_t get_elf_hwcap(void) { ARMCPU *cpu = ARM_CPU(thread_cpu); uint32_t hwcaps = 0; @@ -706,7 +749,7 @@ static uint32_t get_elf_hwcap(void) return hwcaps; } -static uint32_t get_elf_hwcap2(void) +uint32_t get_elf_hwcap2(void) { ARMCPU *cpu = ARM_CPU(thread_cpu); uint32_t hwcaps = 0; @@ -741,6 +784,85 @@ static uint32_t get_elf_hwcap2(void) return hwcaps; } +const char *elf_hwcap_str(uint32_t bit) +{ + static const char *hwcap_str[] = { + [__builtin_ctz(ARM_HWCAP_A64_FP )] = "fp", + [__builtin_ctz(ARM_HWCAP_A64_ASIMD )] = "asimd", + [__builtin_ctz(ARM_HWCAP_A64_EVTSTRM )] = "evtstrm", + [__builtin_ctz(ARM_HWCAP_A64_AES )] = "aes", + [__builtin_ctz(ARM_HWCAP_A64_PMULL )] = "pmull", + [__builtin_ctz(ARM_HWCAP_A64_SHA1 )] = "sha1", + [__builtin_ctz(ARM_HWCAP_A64_SHA2 )] = "sha2", + [__builtin_ctz(ARM_HWCAP_A64_CRC32 )] = "crc32", + [__builtin_ctz(ARM_HWCAP_A64_ATOMICS )] = "atomics", + [__builtin_ctz(ARM_HWCAP_A64_FPHP )] = "fphp", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDHP )] = "asimdhp", + [__builtin_ctz(ARM_HWCAP_A64_CPUID )] = "cpuid", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDRDM)] = "asimdrdm", + [__builtin_ctz(ARM_HWCAP_A64_JSCVT )] = "jscvt", + [__builtin_ctz(ARM_HWCAP_A64_FCMA )] = "fcma", + [__builtin_ctz(ARM_HWCAP_A64_LRCPC )] = "lrcpc", + [__builtin_ctz(ARM_HWCAP_A64_DCPOP )] = "dcpop", + [__builtin_ctz(ARM_HWCAP_A64_SHA3 )] = "sha3", + [__builtin_ctz(ARM_HWCAP_A64_SM3 )] = "sm3", + [__builtin_ctz(ARM_HWCAP_A64_SM4 )] = "sm4", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDDP )] = "asimddp", + [__builtin_ctz(ARM_HWCAP_A64_SHA512 )] = "sha512", + [__builtin_ctz(ARM_HWCAP_A64_SVE )] = "sve", + [__builtin_ctz(ARM_HWCAP_A64_ASIMDFHM)] = "asimdfhm", + [__builtin_ctz(ARM_HWCAP_A64_DIT )] = "dit", + [__builtin_ctz(ARM_HWCAP_A64_USCAT )] = "uscat", + [__builtin_ctz(ARM_HWCAP_A64_ILRCPC )] = "ilrcpc", + [__builtin_ctz(ARM_HWCAP_A64_FLAGM )] = "flagm", + [__builtin_ctz(ARM_HWCAP_A64_SSBS )] = "ssbs", + [__builtin_ctz(ARM_HWCAP_A64_SB )] = "sb", + [__builtin_ctz(ARM_HWCAP_A64_PACA )] = "paca", + [__builtin_ctz(ARM_HWCAP_A64_PACG )] = "pacg", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + +const char *elf_hwcap2_str(uint32_t bit) +{ + static const char *hwcap_str[] = { + [__builtin_ctz(ARM_HWCAP2_A64_DCPODP )] = "dcpodp", + [__builtin_ctz(ARM_HWCAP2_A64_SVE2 )] = "sve2", + [__builtin_ctz(ARM_HWCAP2_A64_SVEAES )] = "sveaes", + [__builtin_ctz(ARM_HWCAP2_A64_SVEPMULL )] = "svepmull", + [__builtin_ctz(ARM_HWCAP2_A64_SVEBITPERM )] = "svebitperm", + [__builtin_ctz(ARM_HWCAP2_A64_SVESHA3 )] = "svesha3", + [__builtin_ctz(ARM_HWCAP2_A64_SVESM4 )] = "svesm4", + [__builtin_ctz(ARM_HWCAP2_A64_FLAGM2 )] = "flagm2", + [__builtin_ctz(ARM_HWCAP2_A64_FRINT )] = "frint", + [__builtin_ctz(ARM_HWCAP2_A64_SVEI8MM )] = "svei8mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEF32MM )] = "svef32mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEF64MM )] = "svef64mm", + [__builtin_ctz(ARM_HWCAP2_A64_SVEBF16 )] = "svebf16", + [__builtin_ctz(ARM_HWCAP2_A64_I8MM )] = "i8mm", + [__builtin_ctz(ARM_HWCAP2_A64_BF16 )] = "bf16", + [__builtin_ctz(ARM_HWCAP2_A64_DGH )] = "dgh", + [__builtin_ctz(ARM_HWCAP2_A64_RNG )] = "rng", + [__builtin_ctz(ARM_HWCAP2_A64_BTI )] = "bti", + [__builtin_ctz(ARM_HWCAP2_A64_MTE )] = "mte", + [__builtin_ctz(ARM_HWCAP2_A64_ECV )] = "ecv", + [__builtin_ctz(ARM_HWCAP2_A64_AFP )] = "afp", + [__builtin_ctz(ARM_HWCAP2_A64_RPRES )] = "rpres", + [__builtin_ctz(ARM_HWCAP2_A64_MTE3 )] = "mte3", + [__builtin_ctz(ARM_HWCAP2_A64_SME )] = "sme", + [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64 )] = "sme_i16i64", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64 )] = "sme_f64f64", + [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32 )] = "sme_i8i32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32 )] = "sme_f16f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32 )] = "sme_b16f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32 )] = "sme_f32f32", + [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64 )] = "sme_fa64", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + #undef GET_FEATURE_ID #endif /* not TARGET_AARCH64 */ From patchwork Thu Aug 24 01:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716492 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091573wrp; Wed, 23 Aug 2023 18:04:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKvP03iljmi/h5eM53B2tRIATxbNElqJvdb128MYtZoTs3nplfn8vQ2Ibsn+z+IbRgb87h X-Received: by 2002:a0c:dd8a:0:b0:64f:3cad:a058 with SMTP id v10-20020a0cdd8a000000b0064f3cada058mr10990626qvk.36.1692839076083; Wed, 23 Aug 2023 18:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839076; cv=none; d=google.com; s=arc-20160816; b=gnODGOZQSmaBbocxTRG7GLfdoUJAZA25krDH4XYW0GfUQ3EFJFi7/h4RL0I7wo1TsA VpFXLtnwtpSyGrIvYvcuYmC/Zh25HhnQuMSQM9V8hDsJUa1t8ZCITzvpKGx9AaCOqCyY MeHikPzAldp35aAO+VUeNqHjbLPDFnafYlo6kX6RqdEEH6XCH2lMSytr75JaXgy9Z0/o fQHuAW5mfgMtKA6GvWHmpBizIUA8LZucW+il1C9tKnCSNAJab+2mUnBk7TTiNFRhBdsG m0HpcVz6NuF+exJktGjqpiRN5HtmtGgw/Rsj2/Wt6zR+/s7zAlgYRvjVOjhhyYU9gA4H 2BJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yER8RLCvXGE4QY1NsvgxkMYXrHTMG4W+91MMUIhX/Po=; fh=NoQ0F09ZQKy1Uh3bcgJ5NnLsbIRkWsdI/O0fcc168pY=; b=UsiZ2P2zCkSaNgTp2oBj8ok5R5+y3ojl7wzE4W5Q6Rv9tXzMYeyWB35jXnHOHCd6Qt ftrIKv6eavQfxvQuSqsQ71nMTCm2UpE/3M5hjuU5vrYsy8aKohiSwLu4gswPSLzxNvAK IvFtLpkZgWXN7eYtTaqpWTmE/Qkbs1ayDtVW4ZBKhfRrc34qa/+4jD/4QEOcEk8hFVe3 Nn1rxLyCL3C0s3e6154UDMUjrJMyWrirbJ1qq+1zuBXAMF+0FwhM1zpq7D1sKVciD0DW YopYk4+BcAXes3m+B7UGqxhdByMAQtOggfG6vx0lFA0Zj6S7Yr1PDZ9qdK6SM/TYGg9A Uqlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DMW0px2x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d5-20020a05620a240500b0076ce9812237si668036qkn.550.2023.08.23.18.04.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:04:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DMW0px2x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- 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 = sysconf(_SC_NPROCESSORS_CONF); + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + unsigned long cpu_mask; + char model[32]; + const char *p, *q; + int t; + + p = object_class_get_name(OBJECT_CLASS(CPU_GET_CLASS(env_cpu(cpu_env)))); + q = strchr(p, '-'); + t = q - p; + assert(t < sizeof(model)); + memcpy(model, p, t); + model[t] = 0; + + t = sched_getaffinity(getpid(), sizeof(cpu_mask), (cpu_set_t *)&cpu_mask); + if (t < 0) { + if (num_cpus >= sizeof(cpu_mask) * 8) { + cpu_mask = -1; + } else { + cpu_mask = (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=0,va=0)\n" + "user unaligned acc\t: 0 (pc=0,va=0)\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 */ From patchwork Thu Aug 24 01:02:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716493 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091631wrp; Wed, 23 Aug 2023 18:04:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHbDjIZp9AwAFzQPS2WqqpvOREIeVgtyXIOl8NgNskHNCHon3sa38KMDo1FzTqJt8Zuza1 X-Received: by 2002:a05:620a:280c:b0:76c:ba9d:3ec7 with SMTP id f12-20020a05620a280c00b0076cba9d3ec7mr16897493qkp.6.1692839085956; Wed, 23 Aug 2023 18:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839085; cv=none; d=google.com; s=arc-20160816; b=ZfsDDZ9TrHNyslJn54fK6XO6YJQde7NJP3sVGQg5jb8tdE7gLkX+ORbSgRYuL95T/m bzxVIg96fQ8JdT8NDnS7YbS19Bt288rhdSKD3BoWO1BhDExmNAPEVTrTkUEEVv3+4zWj bRrpHGwbp4/Ql7YrFAec3XmvVBoINYZeQwa+QaQ3HR9oKGcnL7ckYBeSN3Sm6jH6AmHi LlBAat3h/CpMyo/8Zf4t5iV5zZLjACwaEhuPtzxmJyIpThm2wpLK8ioSe2xDwlN2PFq8 WtFCl6P+W5YUhBQ+sKA90JdAzJuY2t3ghItMwGc68woT/ANitJrDbdlhlNHYnKjcBpD2 HagQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4DWAv0bR3QBWPP10gPMl5GXU+szn3XnQPYnLcaRRAHU=; fh=WpTNcOBxl+ViqVJ027hc6uh8MPmhfO3NWsuNb69FM0w=; b=k+iXTdNoVs3xQi+T/+E3hkNy4whw8F3n/nICXV1XPaP1bWhz+cXwRBhuql0kfoq9mK ky9SRmMJT3N/dLX0Gw0MwWfKUxuxxoRFIlZU4M2/QdrpQrvjIYSH4YoHw4vCBt1mjwkJ /XWnQ50EqyadHMkptSs95PM0WIsa4IcgOMS2O80dHx3te5/FAJEVuhEwtEExXomwBLIB ZbgHsK4yKN/zk6Lh2xWxsk1cTFs9s7iIfrax1oBehio7Qqnl/KdG/BdicjEO2yUesC9F dcw/Cn8Ovn3aghfuUcSktsFMZ8r2rObD72W1rSnpNggcl53uKPlBKBDOoDuvmoHcL1s6 vCOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WNsMtT+D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bp7-20020a05620a458700b0076da8e6727dsi783187qkb.677.2023.08.23.18.04.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:04:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WNsMtT+D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é 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; + dev_t dev; + ino_t inode; uint64_t offset; - uint64_t inode; const char *path; - char dev[]; } MapInfo; /** 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) } count = 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) if (nfields > 4) { uint64_t start, end, offset, inode; + unsigned dev_maj, dev_min; int errors = 0; const char *p; errors |= qemu_strtou64(fields[0], &p, 16, &start); errors |= qemu_strtou64(p + 1, NULL, 16, &end); errors |= qemu_strtou64(fields[2], NULL, 16, &offset); + errors |= qemu_strtoui(fields[3], &p, 16, &dev_maj); + errors |= qemu_strtoui(p + 1, NULL, 16, &dev_min); errors |= qemu_strtou64(fields[4], NULL, 10, &inode); if (!errors) { - size_t dev_len, path_len; + size_t path_len; MapInfo *e; - dev_len = strlen(fields[3]) + 1; if (nfields == 6) { p = fields[5]; p += strspn(p, " "); @@ -52,11 +54,12 @@ IntervalTreeRoot *read_self_maps(void) path_len = 0; } - e = g_malloc0(sizeof(*e) + dev_len + path_len); + e = g_malloc0(sizeof(*e) + path_len); e->itree.start = start; e->itree.last = end - 1; e->offset = offset; + e->dev = makedev(dev_maj, dev_min); e->inode = inode; e->is_read = fields[1][0] == 'r'; @@ -64,9 +67,8 @@ IntervalTreeRoot *read_self_maps(void) e->is_exec = fields[1][2] == 'x'; e->is_priv = fields[1][3] == 'p'; - memcpy(e->dev, fields[3], dev_len); if (path_len) { - e->path = memcpy(e->dev + dev_len, p, path_len); + e->path = memcpy(e + 1, p, path_len); } interval_tree_insert(&e->itree, root); From patchwork Thu Aug 24 01:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716495 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091941wrp; Wed, 23 Aug 2023 18:05:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3d1lStDZSEv9yAWkW9mbcdKwZ9b5IedGDot4DgJfIJXulGYuw6Nj1jrhyhf/vxQnIcHiu X-Received: by 2002:ac8:5c46:0:b0:411:5528:64f6 with SMTP id j6-20020ac85c46000000b00411552864f6mr3842687qtj.27.1692839139270; Wed, 23 Aug 2023 18:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839139; cv=none; d=google.com; s=arc-20160816; b=eBrgYSJXOTnX9P5kHbfTQWIySg5B3TxqbcpxB7U5pDDX45Glg+Fkr7yxOaLXrEnwmN AcouD9by75f6Oj7utsw2U72gC7cTEV3sJqka9WV27Pu8NryxHLF0bQkS/kFqSqxjzXAl 6fzPyXUlC9ffPNyJBNJK6rmyXk8Ptt+4RfcJ66oHL8KUV7DmeQfopHodY55eSZp3A8U1 MiuqnT41SyOFWYjGn0Wic4EGq6NA8FmsO/yj8uosXLpo7Zo/qfzG1oQ6UAbpembpZloK NCdy2HO5g5as3pROQgr4kk84NrQHRzyBOp1BQgTbJMWgsczUEeT0ScAKsTjuL20t31uD kQRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bpFeD6GHYH/QT6fcBbDbU7NqohK/EObQjIfv1Nj799s=; fh=HKkwVadJ/uaTI8+zGemceZF/kgFFDZAwzMS4W0iLuHY=; b=alsN3RwxG+JXnReyweeUNY474vuTqZoCMotsr2+kgy3m1DvE+Vq+0SySJB44BBLhC5 3NKO6fvNldCh0I01swUopM592etNVmo6g9MN2UkWD3Mfkh5zo80lqteFb7ZJrH+OtwIb +ZcTuTMWjsj82S4LhzEPqZEm+arC1jW5Rz8CJsxIzjODydDb53NsSoaUrjpsxT9mmoNU nAiQF2PPpAOyS6DLEgBXVWC1212GpGGS+1r998sJ0eioT0eofwb/tWMti1rq9FP1qGX6 /uQEDoVxjykS31XMsYCQwJTbQ4xjymrdoUNHTjaNPRvX86zM9c2i1lHP0vKcedj8BVX2 a9fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PSDaL/Mm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j8-20020ac85f88000000b003f86195769dsi7894436qta.408.2023.08.23.18.05.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:05:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PSDaL/Mm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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; } -static void show_smaps(int fd, unsigned long size) -{ - unsigned long page_size_kb = TARGET_PAGE_SIZE >> 10; - unsigned long size_kb = size >> 10; +struct open_self_maps_data { + TaskState *ts; + IntervalTreeRoot *host_maps; + int fd; + bool smaps; +}; - 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 == L) +#else +# define test_stack(S, E, L) (S == 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 = d->ts->info; + const char *path = mi->path; + uint64_t offset; + int fd = d->fd; + int count; + + if (test_stack(start, end, info->stack_limit)) { + path = "[stack]"; + } + + /* Except null device (MAP_ANON), adjust offset for this fragment. */ + offset = mi->offset; + if (mi->dev) { + uintptr_t hstart = (uintptr_t)g2h_untagged(start); + offset += hstart - mi->itree.start; + } + + count = 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 = end - start; + unsigned long page_size_kb = TARGET_PAGE_SIZE >> 10; + unsigned long size_kb = 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"); + } } -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 = env_cpu(cpu_env); - TaskState *ts = cpu->opaque; - IntervalTreeRoot *map_info = read_self_maps(); - IntervalTreeNode *s; - int count; + static const MapInfo mi = { .is_priv = true }; - for (s = interval_tree_iter_first(map_info, 0, -1); s; - s = interval_tree_iter_next(s, 0, -1)) { - MapInfo *e = container_of(s, MapInfo, itree); + open_self_maps_4(opaque, &mi, guest_start, guest_end, flags); + return 0; +} - if (h2g_valid(e->itree.start)) { - unsigned long min = e->itree.start; - unsigned long max = e->itree.last + 1; - int flags = 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 = opaque; + uintptr_t host_start = (uintptr_t)g2h_untagged(guest_start); + uintptr_t host_last = (uintptr_t)g2h_untagged(guest_end - 1); - max = h2g_valid(max - 1) ? - max : (uintptr_t) g2h_untagged(GUEST_ADDR_MAX) + 1; + while (1) { + IntervalTreeNode *n = + interval_tree_iter_first(d->host_maps, host_start, host_start); + MapInfo *mi = container_of(n, MapInfo, itree); + uintptr_t this_hlast = MIN(host_last, n->last); + target_ulong this_gend = h2g(this_hlast) + 1; - if (!page_check_range(h2g(min), max - min, flags)) { - continue; - } + open_self_maps_4(d, mi, guest_start, this_gend, flags); -#ifdef TARGET_HPPA - if (h2g(max) == ts->info->stack_limit) { -#else - if (h2g(min) == ts->info->stack_limit) { -#endif - path = "[stack]"; - } else { - path = e->path; - } - - count = 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 == host_last) { + return 0; } + host_start = this_hlast + 1; + guest_start = h2g(host_start); } +} - free_self_maps(map_info); +static int open_self_maps_1(CPUArchState *env, int fd, bool smaps) +{ + struct open_self_maps_data d = { + .ts = env_cpu(env)->opaque, + .host_maps = read_self_maps(), + .fd = fd, + .smaps = smaps + }; -#ifdef TARGET_VSYSCALL_PAGE - /* - * We only support execution from the vsyscall page. - * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=y from v5.3. - */ - count = dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx - " --xp 00000000 00:00 0", - TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_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; } From patchwork Thu Aug 24 01:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716485 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091228wrp; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHBey4Ph055/GIHPbMgeS9fXt192ozEmS6PzOtNA175c7EiuW0NPcT2XPLw18v+cpQI3E4 X-Received: by 2002:a05:622a:1049:b0:40f:ba4c:6222 with SMTP id f9-20020a05622a104900b0040fba4c6222mr16149157qte.3.1692839022344; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=google.com; s=arc-20160816; b=pTic8x2XB66CmODrZbuH06Ugs64lvZdIalwKXsCGhSEdJxU5o8nehkZsESzvF12JlH R0d10x615/gIdomDKdp3q0oalkGvUQjYiGn5+lghgOe08CxN4Xb7GHDJScP1k6I+GQ1G hPAUU6sfmoMB9eRfTbDclYPEsO226ST8iWIXtGOy32MtgL6Qs0lrBUwer1y2Mw8SiUlp hteebcetpffHVUvKErEp1uVfYhL124prV0KeWS9MtHiFD94WXeRorZhhVlyqML37fJXd W/BSIZgWQ+qdZA0CKVSQK14zlj3WitiOckkARFAp6uVBthgwKvuow3hN/Ky+igbymjy6 ShnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Nx0E+Cf9iwRX4Njxvb3jlIfoidd9B3bB+8lmV0laZYk=; fh=QGskMdelARGHezMEnGEe9a8PD5qAPMslgdVEeVGZ1W4=; b=geLIBCX1i9EHHCvCSfmlHrADS8b++oCREJKty/wFnRblJ7MBwYteIcoAFpksz92KGU d+d9OzPItap4eWTCJqOT1rCQLlJpe3+RO3r5wh9++6a4Y2GhViMiiAo0FUYYe0CSQDgY Zav2RU/A+ZJvKRtygiFFqeXSQ1/F+GcKn0CGKKT2wMuQREXfG/nLtw7WiZMYrCFdtBa1 rakktOrdDvT8PoEddnMJlpg/y1Zb9Hh2WS56cwLnXWCjRWfCCs3Xgqc4zCk1UB9eWXqI 7r1XDz15UuyXpskR479T4UNy27Xl7WHDys9lrh6al/+Jo8+SlZxgdt3xCJfzQB7y/yPI wbHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fqkb/Air"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h1-20020ac87d41000000b004009e42b674si2945380qtb.317.2023.08.23.18.03.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fqkb/Air"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Helge Deller , Ilya Leoshkevich , =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 close to executable") Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Reviewed-by: Philippe Mathieu-Daudé 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, int image_fd, info->start_data = -1; info->end_data = 0; /* Usual start for brk is after all sections of the main executable. */ - info->brk = TARGET_PAGE_ALIGN(hiaddr); + info->brk = TARGET_PAGE_ALIGN(hiaddr + load_bias); info->elf_flags = ehdr->e_flags; prot_exec = PROT_EXEC; From patchwork Thu Aug 24 01:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716483 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091221wrp; Wed, 23 Aug 2023 18:03:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXImEj7RJ6R4YmrHggYrtXtEwNKblApAo+aqFec4Gi5V91LMi8gu8CB1fwoTAATX+On3NK X-Received: by 2002:a05:6214:27eb:b0:647:30f9:4b79 with SMTP id jt11-20020a05621427eb00b0064730f94b79mr15619147qvb.7.1692839021431; Wed, 23 Aug 2023 18:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839021; cv=none; d=google.com; s=arc-20160816; b=v7zz3f7ilLhoQp8LYb/ZwDxOWIfV05exauHMa1UcG22U7E3lRGAQihiNdaXaRJD+RS BU2a1zGiFJqCzxj17VPEltd1O3SkPj39DldFbbOwDDKOI12CvGduHu8gruKZh0FHb9yo eGHB0Wm0+BM/oCm5+WKOGsc7xrPEtUwQb8qyyu3erArkRm0qTM4R7I4Qjix1KkJ8jIhJ 2lvyVGmZlwEslE3j2mOW89dH5mnF9bmiIdRWy+VV/mZ2HHqusstxH8sN5vLn6Q0AdOhF IJqkwZEHrT/4LJzBIfYufJ2Wr/1Z8MdkPNXTQbCfxLfK87DemNHgyj/2XXNh9UGDnpku V1iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/J3OwiFqVwoYplEY/vkfNER1ejXeddYX7iHD/HQTT+U=; fh=HKkwVadJ/uaTI8+zGemceZF/kgFFDZAwzMS4W0iLuHY=; b=HIjmGLuj2dCIGxp8ekuYHiHk1zHAbj1gfx4ChLHP7rF6HCOwuAbXq5MFRgYEUYi7ah Tm35k7xBcpktqh8zleKGe6RGX+gl/kaCGlrgI/cociVtRcScMT2VOooviXkXk6waVfvn DaNvOqAUVWT6pHkCw2GcIdmiu/Bt80ONX4mjnywtc9LnnRvKWVcR5UGKf4KBxc+tv31+ xgj8bwsMUkluF73kjDLwtR5wncQ+3HTbKPxPJCstERqQ2r+FGUmj7jxYncxeZFvCFGw5 KIGTj3s8FHYGoDlgq1mbjEx03OsR7e8cTY2OvfoSCEcR/OHQgn3BG9t9upSWTLuR4zXZ 3Rig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UM4HUJzD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fi4-20020a0562141a4400b0063d57c2050asi8174583qvb.46.2023.08.23.18.03.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UM4HUJzD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Tested-by: Helge Deller Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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_maps_data *d, if (test_stack(start, end, info->stack_limit)) { path = "[stack]"; + } else if (start == info->brk) { + path = "[heap]"; } /* Except null device (MAP_ANON), adjust offset for this fragment. */ From patchwork Thu Aug 24 01:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716489 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091318wrp; Wed, 23 Aug 2023 18:03:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZAVUrfQzSy3waUxB6R+ktmGvdbw4RHL9g7lXdiPFhqUZdyBBJ/2DgClOw1MX7xFjTIzX7 X-Received: by 2002:a05:6214:1a47:b0:635:eff8:2b4c with SMTP id fi7-20020a0562141a4700b00635eff82b4cmr16581384qvb.31.1692839033732; Wed, 23 Aug 2023 18:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839033; cv=none; d=google.com; s=arc-20160816; b=e2Pw4+uovNpURso4hYaeeNaWmJaziAoD8LOKdfCvnoFtrtI3rFsyG1jImLtdUA85AV Ec6sFu/JtF9Q3w6NmArsT/vmiisOBRAlFIOKYng+mHhbmwN8qjf4HAgF768ByJVbNIcy sDr5kHqZRAzIu88nmjibxc8kAh8yCGKS3kziu3mSM96goel8zxEi4dk0as/o+9b16eZx g2ECooprpYaUOhxsSW9kznd4l/yuwPvI3T1EJCi30OJG7ffxAspf7NIC0MGgg9UvpR8A 6FtZa16Wv52gG0rEaG1kgPtRpTBzbm23HHmDCl7l5g+cydblcCdJ7kwwbW6CKYGnlarV s1Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UxFB11WokbscidLNJIq7jg3sXBkPLDLF7tCCnRzjj4U=; fh=F9+CNiVJwRFefBQuaFQguBFal8jOUM389V8ndcNesT0=; b=wF7R0GuS1hLy3/iOOClArGlpg16sEdaXePXdHsw5SeLn97H4iXxKNseKK/yV1nvZf3 gCYLBwleJPkUqjfOu1QJwYbI7NnFW9m7LPmvyFGLElQjPJKexkgDSFEThbRcEkoh7peD n+195O+IGeyUpmMyRcIBBqVQZMCZyaKFYpnEBQ1Z06HW+4UAnUs2rBxXEKZ3UBsVqYBo GhBQsAZSbX0+kperQ4SjRcLuItr2NM5Uixy/0YMHara8eJ0zRpOpBzNzZ8OzqQIH0OyQ pMZP0J2y1QIc4K7quOx4u8bv7lKQtgVxo9Ez8rt+pwHPSZCjDl6YfDgGrLysrWTraXk8 2Ecg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H9bvMoeL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m3-20020a0cdb83000000b0064c5c85a364si6712128qvk.526.2023.08.23.18.03.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H9bvMoeL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é --- 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_maps_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_maps_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" : "", From patchwork Thu Aug 24 01:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716490 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091531wrp; Wed, 23 Aug 2023 18:04:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvLDU6A1vgON30XY2l+gkCzY5F68K8giX4ZlvYBP8krQOsD8GHs0DVtVcXHzGRoDwRSvEX X-Received: by 2002:a05:620a:2901:b0:76d:307c:5bae with SMTP id m1-20020a05620a290100b0076d307c5baemr19140583qkp.38.1692839068431; Wed, 23 Aug 2023 18:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839068; cv=none; d=google.com; s=arc-20160816; b=urFYSXC4cXSbvpKcbSfLU+8FpPIq8LDfQj6ix5VUdYaOFCn5y6KqmPTfCAafwUeNRn 2xdrMqA4QOB8xhUyeZuU1yJclXUZgWXojJXOTPeFXm4JpJvndaCiit5qeV/KH8PQrqjD B0OCaYR0AZJaRAPuIP4AJT7X0CX0LkUN+7FvwXQSC3vLOMWk43fa8KNXspXsZf6mBJu2 ItXwCkaU2GYXtnkhWyC+lGibQjE1Dd2oWaimOSEenuCiXwEEBmgqkocCLTbpMsoAsGw7 AhlYM+eiA6NUbo5iAKFYskcUa5JIxOPBEeKShcHXQ72RttkT27ELn7CJvYZkGKt6OEp3 O68Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KH0FHPd2e6QV8ZmEsDwRCzlCpTkPvLk9RV9t+BHx8lg=; fh=WpTNcOBxl+ViqVJ027hc6uh8MPmhfO3NWsuNb69FM0w=; b=W/LZnfe3yqi++nI3DGc7R2iTQfqydNMMEPJAesF/rfSuMAGKzu78AkZqYO63XYnxwO L3bao6e//EwXJ5qzB+Le9nqGtHGMgzj4KM7qbzlGTaHlfkrYrBd1QHLRIieq/gO+K3il 3ezrDRWsvJuHLbNHrwCC0qG7fNR4kufZsOBw4pL8m1nTIak8FzyAPn3+Mc3MdRsmPH+d e2DdJNVSh8X/icX3wuyv7l17q9W9E6E38FpLoxhtULgabjQLoMxwX86iaQGUIJ8NyywA a+3wR9BV3RFMrYcP8Ju8qmLlSsZ18HMMjdPvo03t2tn9Bp4wz32mOVXBthi6iPqkf+wD 67hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qrjREae0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l6-20020a05620a28c600b0076cb4706335si8192213qkp.256.2023.08.23.18.04.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:04:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qrjREae0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é 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) } #ifdef TARGET_X86_64 -#define ELF_START_MMAP 0x2aaaaab000ULL - #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_X86_64 @@ -221,8 +219,6 @@ static bool init_guest_commpage(void) #endif #else -#define ELF_START_MMAP 0x80000000 - /* * This is used to ensure we don't load something for the wrong architecture. */ @@ -308,8 +304,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en #ifndef TARGET_AARCH64 /* 32 bit ARM definitions */ -#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) #else /* 64 bit ARM definitions */ -#define ELF_START_MMAP 0x80000000 #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 -#define ELF_START_MMAP 0x80000000 #define ELF_HWCAP (HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR | HWCAP_SPARC_SWAP \ | 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_SWAP \ | HWCAP_SPARC_MULDIV) #define ELF_CLASS ELFCLASS32 @@ -905,7 +896,6 @@ static inline void init_thread(struct target_pt_regs *regs, #ifdef TARGET_PPC #define ELF_MACHINE PPC_ELF_MACHINE -#define ELF_START_MMAP 0x80000000 #if defined(TARGET_PPC64) @@ -1108,8 +1098,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en #ifdef TARGET_LOONGARCH64 -#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) #ifdef TARGET_MIPS -#define ELF_START_MMAP 0x80000000 - #ifdef TARGET_MIPS64 #define ELF_CLASS ELFCLASS64 #else @@ -1359,8 +1345,6 @@ static uint32_t get_elf_hwcap(void) #ifdef TARGET_MICROBLAZE -#define ELF_START_MMAP 0x80000000 - #define elf_check_arch(x) ( (x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD) #define ELF_CLASS ELFCLASS32 @@ -1401,8 +1385,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env #ifdef TARGET_NIOS2 -#define ELF_START_MMAP 0x80000000 - #define elf_check_arch(x) ((x) == EM_ALTERA_NIOS2) #define ELF_CLASS ELFCLASS32 @@ -1498,8 +1480,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, #ifdef TARGET_OPENRISC -#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, #ifdef TARGET_SH4 -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_SH @@ -1618,8 +1596,6 @@ static uint32_t get_elf_hwcap(void) #ifdef TARGET_CRIS -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_CRIS @@ -1635,8 +1611,6 @@ static inline void init_thread(struct target_pt_regs *regs, #ifdef TARGET_M68K -#define ELF_START_MMAP 0x80000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_68K @@ -1686,8 +1660,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e #ifdef TARGET_ALPHA -#define ELF_START_MMAP (0x30000000000ULL) - #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_ALPHA @@ -1705,8 +1677,6 @@ static inline void init_thread(struct target_pt_regs *regs, #ifdef TARGET_S390X -#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, #ifdef TARGET_RISCV -#define ELF_START_MMAP 0x80000000 #define ELF_ARCH EM_RISCV #ifdef TARGET_RISCV32 @@ -1852,7 +1821,6 @@ static inline void init_thread(struct target_pt_regs *regs, #ifdef TARGET_HPPA -#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) #ifdef TARGET_XTENSA -#define ELF_START_MMAP 0x20000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_XTENSA @@ -1971,8 +1937,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, #ifdef TARGET_HEXAGON -#define ELF_START_MMAP 0x20000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_HEXAGON @@ -3689,8 +3653,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) interp_info.fp_abi = MIPS_ABI_FP_UNKNOWN; #endif - info->start_mmap = (abi_ulong)ELF_START_MMAP; - load_elf_image(bprm->filename, bprm->fd, info, &elf_interpreter, bprm->buf); From patchwork Thu Aug 24 01:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716484 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091223wrp; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi9uP1ea8ABZN4XgOyyPso2ucn1bXq274cQuPZX7zBAHrUgTJpgZocni03qvERURxKQVD4 X-Received: by 2002:a0c:8d82:0:b0:64f:3a18:9a4 with SMTP id t2-20020a0c8d82000000b0064f3a1809a4mr11335199qvb.8.1692839021757; Wed, 23 Aug 2023 18:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839021; cv=none; d=google.com; s=arc-20160816; b=uV7MQeAIjjvtzbnSn1lJ1boYO2BCcFryEnnvYg3E94n8g5klIS6MxWERwTm7pXgUZ7 Qro/dXZBtNlZe/A1BAwkpGSOcOLSE9xz/mkSFeX//E0OfraiNamN07Jz97sPD/EEb+2c a3GC+34rCyDElPJquNw7BQpMi4St84zAWfzlGFqFkxcLeLX6X6a5Gzv2neWaPJS0z+pT z1NkxLVqxny5ry+G9SLORXXs24xeWlBAmBYvprtL+0H1UhdGv0yEXRQxAw1VNCTHOxkR +spcIZeSenmLnKScfLSgjUqInjLHGtOCpWKlVOfFltdsJk9cs2w6gZaSSuyA4l1OMoZ1 4QUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mus/3sAGYIp/tZt8gw3OhfynvDJwuLWU//9f2MDJGRM=; fh=nQWK8nVk+1GMC2JeYe9PXR0srRwGH1udkFCEvbYPueo=; b=a1KufZt8wx43mAvlV0AMsuBjeKHtsEACd3Io22YMjXnOx31/j7g/vEBNq4JbGqgghj VVbTaXTZTJyqTIrg71+uKkwsVEkSByabLiTU3MsIQ8Lq/EXC0DyLrbzsPhknTjyujFAu hXENyOD4FkqJKIWf4yG/gdDEoiQWC2ERGdvaBjz0V9guvVVm9XAcMFeE0RxoFxv8aYeT rK6XZAJ0xIt6K50R8A7GXPMLRnehQiIGOgotgvrPtcKNaN4rGM5HVWFnFH3wImgWazLu 7YLNXAb+tEo5CF2NXFo/wPeR3ZOPZNJ46K47eZtMT5I+tQA9QPJxrZPSkB/omctyBEDf rjpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SrOC2Nx/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k6-20020a0cabc6000000b00649a1768b24si7893675qvb.466.2023.08.23.18.03.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SrOC2Nx/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Rename from do_* to target_*. Fix some minor checkpatch errors. Tested-by: Philippe Mathieu-Daudé Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Warner Losh Signed-off-by: Richard Henderson --- 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); +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 = PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; +#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++ == 0) { @@ -981,3 +990,132 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice) 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 = 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 = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); + if (is_error(ret)) { + /* can't get length, bail out */ + return ret; + } + + shmlba = target_shmlba(cpu_env); + + if (shmaddr & (shmlba - 1)) { + if (shmflg & SHM_RND) { + shmaddr &= ~(shmlba - 1); + } else { + return -TARGET_EINVAL; + } + } + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { + 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 level + * 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 |= CF_PARALLEL; + tb_flush(cpu); + } + + if (shmaddr) { + host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); + } else { + abi_ulong mmap_start; + + /* In order to use the host shmat, we need to honor host SHMLBA. */ + mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, shmlba)); + + if (mmap_start == -1) { + errno = ENOMEM; + host_raddr = (void *)-1; + } else { + host_raddr = shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + } + + if (host_raddr == (void *)-1) { + mmap_unlock(); + return get_errno((intptr_t)host_raddr); + } + raddr = 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 = 0; i < N_SHM_REGIONS; i++) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use = true; + shm_regions[i].start = raddr; + shm_regions[i].size = 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 = 0; i < N_SHM_REGIONS; ++i) { + if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { + shm_regions[i].in_use = false; + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); + break; + } + } + rv = 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 vptr) } #endif -#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; } -#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 = 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 = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); - if (is_error(ret)) { - /* can't get length, bail out */ - return ret; - } - - shmlba = target_shmlba(cpu_env); - - if (shmaddr & (shmlba - 1)) { - if (shmflg & SHM_RND) { - shmaddr &= ~(shmlba - 1); - } else { - return -TARGET_EINVAL; - } - } - if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { - 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 level - * 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 |= CF_PARALLEL; - tb_flush(cpu); - } - - if (shmaddr) - host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); - else { - abi_ulong mmap_start; - - /* In order to use the host shmat, we need to honor host SHMLBA. */ - mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, shmlba)); - - if (mmap_start == -1) { - errno = ENOMEM; - host_raddr = (void *)-1; - } else - host_raddr = shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); - } - - if (host_raddr == (void *)-1) { - mmap_unlock(); - return get_errno((intptr_t)host_raddr); - } - raddr = 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 = 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use = true; - shm_regions[i].start = raddr; - shm_regions[i].size = 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 = 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); - break; - } - } - rv = 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 = do_shmat(cpu_env, first, ptr, second); + raddr = 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 = do_shmdt(ptr); + ret = target_shmdt(ptr); break; 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)); From patchwork Thu Aug 24 01:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716496 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091980wrp; Wed, 23 Aug 2023 18:05:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBRZ557qWqO++ZUe77XABbkQfYB02BfTF+/NKGPL4qy8Z6Xt/WDtH8TtOO/nrCfJoANYc1 X-Received: by 2002:a0c:ac01:0:b0:647:42ac:d7f2 with SMTP id l1-20020a0cac01000000b0064742acd7f2mr13985527qvb.63.1692839144924; Wed, 23 Aug 2023 18:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839144; cv=none; d=google.com; s=arc-20160816; b=XHWawPxlCHw2apVJWOiGlMCx4SvZkIibElDf+2hSOkRC1eExUNrYNBFkiJWs4m/Ly2 LfrJgLNz9Rk87Wom/f8G2tNy48mTIrn34e75oyDhRZxDljbhKMtAir8xu34r9JPEsjbZ vRklYRPS8vBLyiX54+KzguBKOyxFFAfa3FD70E5DeQ9rsgzhZKyUVlhXRqBQjlAzTvg4 5q6MzAT1hG+6HW5bRHuPkuM8nX6yv2D0M98X5o6mNGYg6GGdDOKgb9tAY20rv3RRj4FX S1oP7tqU5Lex1r/LfI1lE6ERbDobGxjTulw2G/3ja85BYEoatDASFxnXoIS69N6mxZqk bOSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Y+pbl/I8yc9+qiiBx4oS2dhGsqACGwpE/srodEThD5g=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=upuxIst9Mf3UjgYbZJq5IVegKZFSU1Gz49znqPFXyNYGTpKvojmAi8I/OUYi/P4drX o92XhRYxvV1+RGEQCa14EHCFUvHgwlm++5uuSUgqwzspSHPYykbW/nwabp6exdJ4XWwZ kSa1mzIoFdxePYxbItTK3Ca43YcvbuHUkVobChdmtIzpdwkyR/bIHCPplWZHx8nve6fo 4/4V2vPjU3d2AOFIgqe8gT7lnwVJYrCyvL2rqzg/6rgMdtkFo9LYT4mb/WP/nX7UK6b0 ysNV46Zu9hxheLI+DDZ58RRETIckjJUJePTbyDPI5hHe3O+1mKmrTfroI3fpXqox2U7X aOHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=r9+NLgS5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z8-20020a0cf248000000b0064f572979aasi1609801qvl.60.2023.08.23.18.05.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:05:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=r9+NLgS5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Move the CF_PARALLEL setting outside of the mmap lock. Signed-off-by: Richard Henderson Reviewed-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 shmid, { CPUState *cpu = env_cpu(cpu_env); abi_ulong raddr; - void *host_raddr; struct shmid_ds shm_info; - int i, ret; + int ret; abi_ulong shmlba; /* shmat pointers are always untagged */ @@ -1044,7 +1043,43 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, return -TARGET_EINVAL; } - mmap_lock(); + WITH_MMAP_LOCK_GUARD() { + void *host_raddr; + + if (shmaddr) { + host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); + } else { + abi_ulong mmap_start; + + /* In order to use the host shmat, we need to honor host SHMLBA. */ + mmap_start = mmap_find_vma(0, shm_info.shm_segsz, + MAX(SHMLBA, shmlba)); + + if (mmap_start == -1) { + return -TARGET_ENOMEM; + } + host_raddr = shmat(shmid, g2h_untagged(mmap_start), + shmflg | SHM_REMAP); + } + + if (host_raddr == (void *)-1) { + return get_errno(-1); + } + raddr = 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 = 0; i < N_SHM_REGIONS; i++) { + if (!shm_regions[i].in_use) { + shm_regions[i].in_use = true; + shm_regions[i].start = raddr; + shm_regions[i].size = shm_info.shm_segsz; + break; + } + } + } /* * We're mapping shared memory, so ensure we generate code for parallel @@ -1057,65 +1092,24 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, tb_flush(cpu); } - if (shmaddr) { - host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); - } else { - abi_ulong mmap_start; - - /* In order to use the host shmat, we need to honor host SHMLBA. */ - mmap_start = mmap_find_vma(0, shm_info.shm_segsz, MAX(SHMLBA, shmlba)); - - if (mmap_start == -1) { - errno = ENOMEM; - host_raddr = (void *)-1; - } else { - host_raddr = shmat(shmid, g2h_untagged(mmap_start), - shmflg | SHM_REMAP); - } - } - - if (host_raddr == (void *)-1) { - mmap_unlock(); - return get_errno((intptr_t)host_raddr); - } - raddr = 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 = 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use = true; - shm_regions[i].start = raddr; - shm_regions[i].size = 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 = 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); - break; + WITH_MMAP_LOCK_GUARD() { + for (int i = 0; i < N_SHM_REGIONS; ++i) { + if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { + shm_regions[i].in_use = false; + page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); + break; + } } + rv = get_errno(shmdt(g2h_untagged(shmaddr))); } - rv = get_errno(shmdt(g2h_untagged(shmaddr))); - - mmap_unlock(); - return rv; } From patchwork Thu Aug 24 01:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716487 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091231wrp; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjLLyLDH0EKrmk61SRla0aKW1T6zMqqxeC1mNr9zwPmDdtz1xNJlMdlmmIYBzTJ8F5TNpn X-Received: by 2002:a05:622a:1001:b0:410:af94:6838 with SMTP id d1-20020a05622a100100b00410af946838mr3711565qte.2.1692839022517; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=google.com; s=arc-20160816; b=pV6K97A0yK1SMpIamceQkYlkro2OkeXyjQOd5WuMJ8uDxHuMMcGb6vaUSTHO6/VqRw b40DOPQi5VApXyt9zIs0+hCxoPkGxKJWgXwB6tkzdISYEdbu7qw5w22KXTHgEnhDvvXd pZg7h6gihoi+A0vQEPVjRUH5Cfchvt7c8zKH8BOtIRlm1OPe+s9bcX01A7OxVCK+OetB MOa3ogXKBOAuvoDuwd+XE7VepmlWFv57CYQ2lQWVP2f/NQO1u7ivtpZS3Jd/bfkytfjR TYTnw+3VecmqIwh56EYzK4wKilqN8MX/tuZMshMXzEUa78anB7/GDpfby7xlCRBgs1Jx vPCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=w5ksMQj35m+yCeIWGrGNigy7JAnPo0mf1QEQxYD2q74=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=AUobxoQ/18TbSThukBnHXSZpImpsu5+Ds856S1bXp0QiYIquf9RiLrSTVDWJRkdPgr 5zXmBNL/itwvrVXdjYvHzPkflYfLuz0clcaWw7A/rwdGTWClaonEu7TTNjjGvdctgI9Y 3JinMtq2Zuk/Y8ex3McySQhwjTn0Pshlb3kMeWy6f7AiiVXeEpAUInlCm6G3zeOss7a/ 9pbRCgzJkynC+xWNL38cN55JralJIwL413ZaGkYkO4wIF1fHAmAv+1uwmCFrCfVplx7k maeUX+cTDsdK4GzSpzPaj5/lvBrBXZ/hipr11i5LKxeIzxxFMoTIBGSmRNZpp440x8nE j9Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PmAiyfwT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q2-20020a05622a030200b0040ed0ffaa6dsi7990946qtw.596.2023.08.23.18.03.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PmAiyfwT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é --- 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 */ WITH_MMAP_LOCK_GUARD() { - for (int i = 0; i < N_SHM_REGIONS; ++i) { + int i; + + for (i = 0; i < N_SHM_REGIONS; ++i) { if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - shm_regions[i].in_use = false; - page_set_flags(shmaddr, shmaddr + shm_regions[i].size - 1, 0); break; } } + if (i == N_SHM_REGIONS) { + return -TARGET_EINVAL; + } + rv = get_errno(shmdt(g2h_untagged(shmaddr))); + if (rv == 0) { + abi_ulong size = shm_regions[i].size; + + shm_regions[i].in_use = false; + page_set_flags(shmaddr, shmaddr + size - 1, 0); + mmap_reserve_or_unmap(shmaddr, size); + } } return rv; } From patchwork Thu Aug 24 01:02:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716486 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1091229wrp; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGp5kPADwoqR4jb+fdbeNkmfx4ld+EoYOs3LgXqBubeI8LY6wIzs2txnP8SKpV6F4ojBw8L X-Received: by 2002:ad4:4e52:0:b0:63d:7214:638e with SMTP id eb18-20020ad44e52000000b0063d7214638emr13334189qvb.56.1692839022457; Wed, 23 Aug 2023 18:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692839022; cv=none; d=google.com; s=arc-20160816; b=D9rSgBGkouXtr6tfCXI05zE/xFemiLdumPcxsGszoda1kJJQHjT6GB2BDtx/bHYJ36 n1t3BkCdoEpVBjlYgi9qiYwBhCvjSh2QloWuuYEUY/3XkdhDIYItWa7bTVahCx9PtbN7 lvqQ2huSoVYoopogzvbtYDfk8iXbRp1NYJxNxVQ9c9qJk1LM8Pu9KHQ6Cr0YruRqeEnV k8U2y/s9Z0QB6yMG0i/ltuXUDPVqxmFALfUhJECEDozYtONQirN37oCf8v4+iO2JXs03 BpSeVEWX4OFM3VWvFfTWm6lXX/9sohfSxAcGIAzOWRJ0TC9Q1Rv6pFINMk73NQELSQU4 xHhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UN+H+/GfTniCDQqNqoi86BdHI3S12YJ9y5ScYnnODH0=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=gONe0g0r78yj/JHYxOB7XR7HByCpzmQCUeX6lWeQN3HhaqbEiJRkcJAH7UyyMEXd5V Haw1ugn4gbxnI8o4qkoCzD20kUMtFJLSLJC9se0fDlykQbe2HFbl0dfRE+A276W07wT7 aFXjmN44y08kPDuL5jwVoKzpHmxzK3xWISW+/x0PyJINU/RbbeFCaz/ncAZuiJUSCmgA g9FGPaRuHNN3/7nLTSwvsPKg39/ojzxGxljGx9NiSR3fd+s+ovkc6Imp+FdC8vm5V6DB ltMbu6EUg0B0oGYkbmB3/jDtbzAlTZexVVvsDbHYsn8V0En+jDsAMWlgpn88AhzkZ7Xp 5Q+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OmIoDg8z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k13-20020a0cb24d000000b006418e876d0bsi8014938qve.10.2023.08.23.18.03.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 18:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OmIoDg8z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- 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" static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; -#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++ == 0) { @@ -73,6 +66,44 @@ void mmap_fork_end(int child) } } +/* Protected by mmap_lock. */ +static IntervalTreeRoot shm_regions; + +static void shm_region_add(abi_ptr start, abi_ptr last) +{ + IntervalTreeNode *i = g_new0(IntervalTreeNode, 1); + + i->start = start; + i->last = last; + interval_tree_insert(i, &shm_regions); +} + +static abi_ptr shm_region_find(abi_ptr start) +{ + IntervalTreeNode *i; + + for (i = interval_tree_iter_first(&shm_regions, start, start); i; + i = interval_tree_iter_next(i, start, start)) { + if (i->start == start) { + return i->last; + } + } + return 0; +} + +static void shm_region_rm_complete(abi_ptr start, abi_ptr last) +{ + IntervalTreeNode *i, *n; + + for (i = interval_tree_iter_first(&shm_regions, start, last); i; i = n) { + n = interval_tree_iter_next(i, start, last); + if (i->start >= start && i->last <= 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, int 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(); return 0; @@ -915,8 +948,10 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, new_addr = h2g(host_addr); prot = 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 shmid, WITH_MMAP_LOCK_GUARD() { void *host_raddr; + abi_ulong last; if (shmaddr) { host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); @@ -1066,19 +1102,14 @@ abi_ulong target_shmat(CPUArchState *cpu_env, int shmid, return get_errno(-1); } raddr = h2g(host_raddr); + last = raddr + shm_info.shm_segsz - 1; - 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)); - for (int i = 0; i < N_SHM_REGIONS; i++) { - if (!shm_regions[i].in_use) { - shm_regions[i].in_use = true; - shm_regions[i].start = raddr; - shm_regions[i].size = shm_info.shm_segsz; - break; - } - } + shm_region_rm_complete(raddr, last); + shm_region_add(raddr, last); } /* @@ -1102,23 +1133,17 @@ abi_long target_shmdt(abi_ulong shmaddr) /* shmdt pointers are always untagged */ WITH_MMAP_LOCK_GUARD() { - int i; - - for (i = 0; i < N_SHM_REGIONS; ++i) { - if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { - break; - } - } - if (i == N_SHM_REGIONS) { + abi_ulong last = shm_region_find(shmaddr); + if (last == 0) { return -TARGET_EINVAL; } rv = get_errno(shmdt(g2h_untagged(shmaddr))); if (rv == 0) { - abi_ulong size = shm_regions[i].size; + abi_ulong size = last - shmaddr + 1; - shm_regions[i].in_use = 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); } }