From patchwork Fri Sep 1 20:42:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719521 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp466882wrh; Fri, 1 Sep 2023 13:43:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFje4Wq1lmDovfNJ5g5zMQhRtsRRiKZcU4YRvFbidpqfNDBDOh4cTA71aJx6LbIQRUToOxt X-Received: by 2002:a05:620a:2446:b0:76e:fa82:5f02 with SMTP id h6-20020a05620a244600b0076efa825f02mr9464100qkn.18.1693601019992; Fri, 01 Sep 2023 13:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601019; cv=none; d=google.com; s=arc-20160816; b=vY/BwwUTLKH5V2h9bI707/CpImrdELB1nA8BRPXtDgK0W4Kk6hdDRhhDyitSLQxHNX vV4cW/uvwE5xccxymxCPF3pWZnj8om5EeLgWQeiAn/rWWVXTWGmpss15Dc+giUK+xVq7 b9Khw7McrXzDIAatms5bjoQyL2KkgzpQzvet8VJQbe46JB30SfRYFDl+4PIh8PE4XDHh 4PBBz/n+FQ37ryfL2sgmsPS3h+awEhY/AKgr9RcamhQvUMbIYx++NPioqTinJZ84Dyws wdN0g9EW+D72uh5XpFEMbJtgOptotjboSSzr2IxbRnklJ0sR0tA21EkBOwTemTq7Zr9k bOIg== 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=kIdz6fORtYQosHOppAmYyY3l4+SK9t3Ue4xgFTE6WTQ=; fh=3//KcqJEsa04kIBt5Nb/DJuP+2GuH1NwDRxnSl44zdw=; b=Fpu1s5m9u7kiB3EcrYRVppX488tH8n1ff3Ry5Ts74El3VrhH/5xpwod+ON6SMUonm/ OmPCkt7FCc+M+DO94Yj4mSbkQ6GldesNQgRT0AzZHlB7IVeW2nb3cSQxqCACEqXM41EW wBgR2vq65531PdJn0iSj/xolki9kfxOCnwycf8svqw3E9agmq0F03cz4Se3s5oamK+Cg glQhktrh/KaSkQX6gIoJOQvccLYWpKHVLRl+XkJoFA3LsbcuEJOUbw8yX3fXH7U7A55N yL+aIg/gKBxeKFomh13+rdP3dQpnoXXlOjseallUoIhOI8pfayFTJY8Vo9k5433nPYYg jF/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ltZDxIsG; 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 l18-20020a0ce092000000b00651658c204dsi3074945qvk.280.2023.09.01.13.43.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:43: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=ltZDxIsG; 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 1qcAys-0006yR-AA; Fri, 01 Sep 2023 16:43:02 -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 1qcAyq-0006wy-5F for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:00 -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 1qcAyl-0001wU-G3 for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:42:59 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68a3082c771so271648b3a.0 for ; Fri, 01 Sep 2023 13:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600974; x=1694205774; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kIdz6fORtYQosHOppAmYyY3l4+SK9t3Ue4xgFTE6WTQ=; b=ltZDxIsGuDDnUYMvqVF2IEhluAQITbhnFNvU45OmjR2tecJyKGdeSiMoBcpTXkSibe pvIYzq+ONgTU6hYlyKTb8Ne1KOwfl6Vw7tIoUqBHgYTqBQbXa99uW+nRxnQ6iw8XBmlR +D2FGr3hmdcXT0rm6shrz9kpkmLZ9kZyANk1b/CDIlOHt+r8uyM7COg/b34AefD88oie z+JYCEZFQ1LMeFPY5+Nr1hMeInd3ULBx//oMyIbb7QtVpcOwOSebIWJNRHAPdV2x7Da4 UzbLhJ+/7H1wqe+5WlD3INlBPTA78aPAWGTRJ0/YWo+jHkMYBDDbNyXJ3n4Bt3o/jDYB ULPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600974; x=1694205774; 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=kIdz6fORtYQosHOppAmYyY3l4+SK9t3Ue4xgFTE6WTQ=; b=Uq5zIWWpcAECIcUtGkH5RJbXbGeQUQPv0rWVyIfs8nezsrHa7E7U+paAQv4ZCNCal2 o5IW7H3kPQ1JQ9LtAcrSVxGlSPdXJfqRRJ3RStog/8Xmo4fj0aCvDaHMo47iIoGKVZcJ 7hDICstByNL72824Vrp3idxBZQmP0LSkn/B33CBUHHruWJBF+OWbiafbLoM+Ep4ZY063 sUV/Wgy0Api6xXBWxGQjyCyblO4wFGf22v4poY5rCnFeK/bwbnUwH/3jwobDIMlmWjfy v7XFQtdy+hAjqtuZUuj6xTtjgTUHaSfADQNfmxkPd6ve9Hv/C0GVZKcMxdvDx/hk9Ytc tdYQ== X-Gm-Message-State: AOJu0YxcNnx7ryT5kArAVY8cF0BbNwaENW0To5fQnd82veXiPA/ZvPBw C64WZ2Do0STpnolCmcLnHlOWysQkcOQWoJ4f7XM= X-Received: by 2002:a05:6a00:1d1e:b0:68a:3eef:1672 with SMTP id a30-20020a056a001d1e00b0068a3eef1672mr5202227pfx.5.1693600973609; Fri, 01 Sep 2023 13:42:53 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 01/13] linux-user: Split out cpu/target_proc.h Date: Fri, 1 Sep 2023 13:42:39 -0700 Message-Id: <20230901204251.137307-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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 various open_cpuinfo functions into new files. Move the m68k open_hardware function as well. All other guest architectures get a boilerplate empty file. Tested-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 Fri Sep 1 20:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719527 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467235wrh; Fri, 1 Sep 2023 13:44:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvgG0LgAVmc+iqWyNuAcFl2tOORVhZTdyphWOYzblUsILPHNWb7ATThHDrvtPowx7cpAvq X-Received: by 2002:a05:622a:15c1:b0:40d:4c6:bcdb with SMTP id d1-20020a05622a15c100b0040d04c6bcdbmr3632909qty.5.1693601081801; Fri, 01 Sep 2023 13:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601081; cv=none; d=google.com; s=arc-20160816; b=wR1cJY1ECezX+XuRbw/eb2myEkSKjrwpUVaVtcORwtWU6mZE7WZvD788WXTg8XPG2A iOl3MbEcEy8GxoZRPcS/fpE9bfwirnW2OaiwrKzMN/p6qQ9fqx3Atv0Qc+dG2qc8S84b CM8fAR3hiJcrgwhOiXi8g2Z3NxikHwdbc+h3+d7lmRhVNJXU6Rv0RfLrbAfpUwGsv+iV WHVpncoFaapJfQbenv1AGEGWdOElRXf62eHm14wzrs1YKowgt02SJ+RkoS2CiAhzvAvI JzTOcaa+WYRefCh5rhURlhuRbpTvcBAzgcUrDvBYUHJ+Ee6EebZV+bYIifof2dsVW07R UBGA== 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=HN9bdDKpCXsqx9IM4u0+R/+OpGOMVkY0zwFC+KcDdss=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=ZBKwNNfcDEOpXbOjT4cG9sEIBkZD5Yrvs6UwovswMMKzbhZqqxUwKVGJ9fgVGF531t 7W0kV/igrpJFN4l/YYzHBRZoAuMWiaCMR4Q6nIGOaCTqsKoHH1Da+ufoeWbGi5o17BKv vW2BDrviQd5Z4sHAeYgOfS9UQqhJd2LwpGtiYGzWVEbKfK6U4x1I45CA5jvmwU4zEPjf xqDu954BX/EljpninogFGTzvCzyOLYmXSMWceLfWqCZEnQu1p75kmtO3RbAp/eMZeQBp ZCuoTlsnkh04mrqsksj7O0uu9r10L10Drkp+OnjaomEZ+XKf0TmU/PkdN4LbsMjRal/0 lm3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i7b0PwzJ; 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 c21-20020ac87dd5000000b0040ffe0db808si3040126qte.802.2023.09.01.13.44.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44: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=i7b0PwzJ; 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 1qcAyz-00071M-Po; Fri, 01 Sep 2023 16:43:12 -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 1qcAyq-0006wv-1W for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:00 -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 1qcAyl-0001wi-U3 for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:42:59 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68c0d262933so2072876b3a.0 for ; Fri, 01 Sep 2023 13:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600974; x=1694205774; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HN9bdDKpCXsqx9IM4u0+R/+OpGOMVkY0zwFC+KcDdss=; b=i7b0PwzJAd7ZeLiweZG3er6WuQwE5Td7xg9zK3tNFktCUWwVCSMG6IBGcLNS3LyTGP Wn+XkIWCczqOrJo9LoTJ10ugss9ukkZr8d12hqJMZfra8d3dnP3OhEZOvLqKyosbZsFV OFhAuMN00Rs0ZpRAI5VYoy20LZ4T7KNuTwKPYXQ+wjk/rAWsTmgXzTDSzRBzNzm4Gu8U heuYmf6koXdbOasuw9SaxgKxVYOCz6wwAqUU9GVuRGBu6cWOQjXPyJdzkMdOM3rG24yB cNX+xDA7bfomqmpy/SnZJ+iNGzwVBKx/kTbKGW6IlPsmaiBqvBDZKeymnarPnvQWw1F/ de6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600974; x=1694205774; 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=HN9bdDKpCXsqx9IM4u0+R/+OpGOMVkY0zwFC+KcDdss=; b=PVqmgyjrBDWjie9/H73krnOnLbdlp78BNaPZxjBzNG+0mTfcOS0G6HradHcHKJerFi L3fviSOnheCQnRXZDQVCJ6ZLJdcrSCE0BpD0PBmtGt12zPRNWuNbCJLHKl2nWIQTAQqn 4cSlrlBdTUJmnv26cp638YHbvr03sUaNjAnZGZeUMnlfcO8Ej39f7mDM8/K8xJYTz/ES 6fM6AtAiMOJJA6cfS/hc0jRx5GqZOP3e3X6mQ+OZXvjPC+80WEwWL4Ey0ntYa6RSQuyZ eF+//P+tvm3yRn5zoD8/O9NA+YsLVk4YIIL4tEwOXLcXJSnm+P0CR4TRWVWXO50dzp7c KOTw== X-Gm-Message-State: AOJu0YyVAkmk3jY7vo6TYEvGjJ1IKfbuNS5QibEujHavmB2KuQVQCyJH sjeLEiaOr0AwTW4L4RbDAwqDCaFP9VaUNDNZPH8= X-Received: by 2002:a05:6a21:7746:b0:138:60e:9bb with SMTP id bc6-20020a056a21774600b00138060e09bbmr3623655pzc.28.1693600974411; Fri, 01 Sep 2023 13:42:54 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 02/13] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Date: Fri, 1 Sep 2023 13:42:40 -0700 Message-Id: <20230901204251.137307-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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 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 92b981c445..7c95098e3e 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 Fri Sep 1 20:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719530 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467353wrh; Fri, 1 Sep 2023 13:45:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpN6zbcYGLbQVOnmToTqW3FegLf/+DePGlVWUWP55453IO/OXBJnfMCq+r98gtgOm1lnjx X-Received: by 2002:a05:620a:4143:b0:76c:a957:b2f1 with SMTP id k3-20020a05620a414300b0076ca957b2f1mr4803537qko.66.1693601102802; Fri, 01 Sep 2023 13:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601102; cv=none; d=google.com; s=arc-20160816; b=fpPzhpK/y2RvDW8/4oc95ROQ1qeBZxIRNWVZc9P85IKvLhT62U+NYino87F6SdbW8P UtmljfnT8SUVUQqk0E+DJ5lE3zShTGCy3lB72NsNKicMgTloI0qmKqefpb3RTEZ/xRVf QKHfv2ef3exAzdsTH0RSGjAIySM9Gfxmlqs2gCAlruxSJcdK5ys/vSd+ZE87hkJ16jbO xCHlr5rmnlw7FHTBIz5HePllINFqd/7fvYQ/gpJknUscW40lmXCJI9fwmuz+R3I0rIvI NYpI8rvVsG/PglsFWi8Q7HhEXY4MztiH6WojjBTCPdeh7sGi5jW0sp7l+Uz+324tX5G9 /CmA== 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=/B5IqGsoBIAdUJbjfGrMvXvwE70qvqApVXK+BsG31Yc=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=Lfpd3PlreUS170uwJIQ9mvmqC1oFf69pYUycLfIpezVTNF0ggzGI3nKqSvXrKFYAkh jCq09ZIPZrfet5aIQlo32JeQGVDP9BRIMPp4cQROqRssGGtV2HzBDIY/nz9XvD8IqgDh b0WUd2s1t7uGJq2Z2nZKTft9wZRZIiH9wucFwP/2QQigOk85fgP0SoZ+VF7ysN487fAN +l3u90TTMNbCEKtGQGSY7L0i6UuCRoob5xh7IWvMoU0XD/0UBY9c0RzzmKWrAjT2eA6y j+hxLXu/0EsHrBQdslsjK1u75CJLI5X7l9w/jfQHSQbPjgIWyPJX1Ia+u/X+eGP4x7Ps yUGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qJzAVp5V; 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 rh3-20020a05620a8f0300b0076d9d214cfasi2924914qkn.165.2023.09.01.13.45.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:45:02 -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=qJzAVp5V; 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 1qcAyq-0006xC-My; Fri, 01 Sep 2023 16:43:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qcAyp-0006wn-N0 for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:42:59 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAym-0001x0-R0 for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:42:59 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68c3ec0578bso2056781b3a.2 for ; Fri, 01 Sep 2023 13:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600975; x=1694205775; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/B5IqGsoBIAdUJbjfGrMvXvwE70qvqApVXK+BsG31Yc=; b=qJzAVp5V/+63lA9mF7KTemC3xYs098e6fWjl+L8lByr4rCnsSM+uUm/HFd8EeJ27xl 12aisZhbgdhNC0nITzPJWotyp8vbrrKfYyL+/Ks9X/U+viKAZn6dA+zFwr1faTbOcUA2 t00semcSETvjcZoLtdoLwyKrpCPbHPxRO00e9nibHl2PJZCrqF6WxXISMB4HvCk/jFD1 wnQUwWTyUR5wKYroXeVAzKHUaDZYr6yhm3gak/xNefNf7WpnCdiTLBX/kQMgi/GgqCYF S2RDLJ4VfZGev9EuLYFeM+5n8I3QMDmpWx9k01S6Tmh+/kkkpwdb0POsaTkQn8ta/y2O HrAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600975; x=1694205775; 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=/B5IqGsoBIAdUJbjfGrMvXvwE70qvqApVXK+BsG31Yc=; b=YMlDG2Lj+BfVve6EDXTZnl5nrD5cktQiP/BhYccv5xcTItymDDpzUoXJ5MDDt1S2xz ucJGjm5nIdBKnqBYyWcUxBEVt18dtwRncghNEGlruCmHUIwDaBWymz0Ear+s/+ahurvm DF9oS87+W+wzabVWBSz3MB+eNWe6lgJkF7IqtXn3rbQpCTGJuI8i6gwF96PxZNIHaDLB VKrtqfigPSzljsKE935t4aYNAkO8EnVNdaeH1e2r9kjTAqGaeqQg4cq7AaGt7cK1EvH+ ybsQsb8yzli/vkXYKXnOecxFXmmzMwqSqt6onkDN2bLkRD/iysbsbPrELSS8F/ptMbgz J1CA== X-Gm-Message-State: AOJu0YxnyKHUk6CA5uyDarC4PpEbrq3UA/L+zGd9wEoSlKqLu/6TcpRa tGqzC5CkPGH2z3ZCX2n6bcy489/diT1DWpVp6Tc= X-Received: by 2002:a05:6a21:4987:b0:148:6a9e:143f with SMTP id ax7-20020a056a21498700b001486a9e143fmr3601407pzc.21.1693600975360; Fri, 01 Sep 2023 13:42:55 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 03/13] linux-user: Emulate /proc/cpuinfo for Alpha Date: Fri, 1 Sep 2023 13:42:41 -0700 Message-Id: <20230901204251.137307-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 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 Fri Sep 1 20:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719526 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467136wrh; Fri, 1 Sep 2023 13:44:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFATUIA/1AwIWd0x1sfHSXIbn4WIUu+oHjzrLyURczg553lAmVMTh6iLVpzL8L0swSJnPGv X-Received: by 2002:a0c:f3c7:0:b0:653:589b:9cfc with SMTP id f7-20020a0cf3c7000000b00653589b9cfcmr3335595qvm.43.1693601064757; Fri, 01 Sep 2023 13:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601064; cv=none; d=google.com; s=arc-20160816; b=h5SYJ6Jsavyt72BlwNvrT39zI0C3TblBSUCRjmbO5aE/Y8eUC87wvEF8ePcnKiQm0W XOmeIgBIqMG0sXXTUOg/fFdb9CdpAE/GyrXxxi0McLmHBcCsF3aP2gqFRTUcZuknA9LH 036LVRXhWqm2QI46HBDezKgftiLMp0BbICzMjgpL8KJqMqBPi6fNZGur7dhDRx4/mibU JLAmEJmNamR4Hb86WDXM7+VPxaw2qCK/BxBWmfBeY1CuyYOlu1bsdtBSpL8502A2D8y9 AlUBGHnCBaMeI//kg4BZyMNTqinmAMZZsgbdjPjupoDnwO0pBnsvlv3WA9NugQXKOalo R75g== 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=m386hzt8OWKJ4T1viNMaokaOFou30w3zXtdge72DRf8=; b=nNohBlCNI6zZ7kKXbrSR3ilRMKkaeR4pKkSOiHIbZdTA8If+pmjOzFk5J6rY2/q21o t4A1XfzxrRobGUf/2jDxOXBSYD30yMNUpXItbJ38EFtOYj+upOvY9ZCO4LDQL6w8tlFl uX5NW+NaqhV8l4Oz0zm5jV+TCtCb0rBenOrrLCGy6Q4dWoJIzn4yOvLm54WpJnoi5n75 I57lOUvtZWnJ+XDBmyujg6ZZw0ksJLwVc2iZ0BPCgvsuHxdgafsJabnRzjA2PWAW1SCb iqUVdTmONaXSfj2ZqX87kounOFeTO4tJVlygaf4XmdOhzyvH23hG/k5X3kgXd/f/vqiF vFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s8bWWaUU; 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 a26-20020a0cb35a000000b0064a41ce341asi3280203qvf.100.2023.09.01.13.44.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:24 -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=s8bWWaUU; 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 1qcAzC-0007AT-CO; Fri, 01 Sep 2023 16:43:22 -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 1qcAyr-0006xh-Bo for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:01 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAyn-0001x6-VO for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:01 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-68a520dba33so2121471b3a.0 for ; Fri, 01 Sep 2023 13:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600976; x=1694205776; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4DWAv0bR3QBWPP10gPMl5GXU+szn3XnQPYnLcaRRAHU=; b=s8bWWaUUx00gfcYOn0IPaujePZo+lQrnx7nNCUL8FErzjMQds7A4AUfSMGBHR9vF0B UPfClH6UMSQwHy1KhLWRuTDKdCZuUXqQNsdGITx2pLfohwLAPAG1FbOc5uduChN8JP/F w+Pki2iTykHZR8CQrBOxSw5pYJUJXFDqFrisUa5Hnt8Mv8h59UssIg0cu6BvfrOcW5YA DqiHXEbXf4CclZSLP7umy61iqcWjrfK3MVUi0aDUhziAFWVNIyzzHRt8x89E36e4xWbW xWiUOImx/8ITs3A0ef2Dlnni9TrUPNnG2Uuw12bRHnoSCFsj1czqDJ5ov71ZAGiXNn// gBQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600976; x=1694205776; 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=KjtOTMABsLE6rKsPQi9Azfm8r7rLQh3gesu9Qk2d+QY76YfaeWq97ETuWp6fvuRW06 x9WzQdayk9HqaBrvPExEH/r3LuSZlby1NOMm5bOOIcUKW6KUw4Z8Jd4hUUy+CaDv65Ar uRHpEWMTWSY1F05fXQGaFmr40A8WYw5WlxKtSSGRnr1So5NSOZtDbuGZiUUS168sEQ5I 2mOzcH3/52IRBR+tLk0H9sozcUAVvgrNIq0pVHMnw3nuc5ft+BDPqF2TKTqI/1AlR/bd znkIzXymbU9CZEgUWsFGkj9C93c5LaSOjCMSzk2+csNKINhdV8hf23Nw52svHBJZrTVF 1V0A== X-Gm-Message-State: AOJu0YxBq3iEnLt9WC9EwkITQy2guMRAtwZia78D+r6Q4fxsyDBMv1Q/ G9Yn8Cv8XsR9KACZQwiZjGr25uAAbxnbv6J7qPQ= X-Received: by 2002:a05:6a20:8f28:b0:135:7975:f55 with SMTP id b40-20020a056a208f2800b0013579750f55mr4821957pzk.47.1693600976425; Fri, 01 Sep 2023 13:42:56 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 04/13] util/selfmap: Use dev_t and ino_t in MapInfo Date: Fri, 1 Sep 2023 13:42:42 -0700 Message-Id: <20230901204251.137307-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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 Fri Sep 1 20:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719524 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467109wrh; Fri, 1 Sep 2023 13:44:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFc1weyKwF903OnIqgeKCH+nvWH/xhIlksoS9HT+RSJKOtZAah+i6bf8fWDM2/f25f1W6l3 X-Received: by 2002:a05:6830:1193:b0:6b9:5b75:969 with SMTP id u19-20020a056830119300b006b95b750969mr3587178otq.11.1693601060916; Fri, 01 Sep 2023 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601060; cv=none; d=google.com; s=arc-20160816; b=qNAf76zIGM7oReOWC7dX2ZaS8YIbI+03EKP5eTl6qdmI2VE7IC2oUCppAFXNqxRBjB jySOgOsmkPcUXQfosSIxhnaC2oB9m6/1G1qDAjjZoE5lDZfOnuIVOewXqrldqd3kVqhX Xi3SBx/77c4X1CEC7VUvIOYfXOoxwRTDWha5KABA8SJPUieEaBK1YTtkJL9VPuBlBqdD DS32+RJVb+w2g7E+U3VVi7l8V9Co9Bl14aLDAQaTk2f3FOIYurYIBPD80MFSBzV9FUs4 dbg+vZ/30GgH6JqniYAh30qgLscH1VbS/VDjTq2HCR/TQbFFxA7UWXH9Z0AkZpU0DtHg ukoA== 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=34AiJwL3uD6/r8nj7RDXRG8mDmXJQy5R4F6EYwwWnXc=; b=EfvBF2kIsG8M2ETlTy6rL1Q+BMNPKTdpd8SrbOZFvGYNLZoCAN3Fw1UimJ37uhzVQj mfl+hKLg8Bxjnf2PdqaqRdRflO5dn2QnV8xaXOm8KVisW56L5HmkAVl9tRv+qMmCEDCO OMBwVhiP4K/nIxtGb2BwfZXvg+dvHEjwtHf2Tx8CKIoZFfuhKJy6ujM/sibnscTwVc0E a5+kfSyAEk99ppvHoNxTqmiQhKv2KrwhlS6cu+tSqGHGsU+/m/ESUJ0Ww+vhaIw/wgfm acj6t6escR1Zzigu8MBNdj1efhoG0i9CEm39yZJRPRk6DqteDf+Wp+LShSAz0/RtVMKc kJQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pfh6F07f; 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 v7-20020ac85787000000b0040378f30d44si2963732qta.172.2023.09.01.13.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:20 -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=Pfh6F07f; 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 1qcAzA-00075N-TR; Fri, 01 Sep 2023 16:43:22 -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 1qcAys-0006y6-0K for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:02 -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 1qcAyo-0001xH-SU for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:01 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68a3b66f350so2107287b3a.3 for ; Fri, 01 Sep 2023 13:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600977; x=1694205777; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bpFeD6GHYH/QT6fcBbDbU7NqohK/EObQjIfv1Nj799s=; b=Pfh6F07faWFMQCCJnD6+4BOS0HOckjjfghfzPz/9TuxsJH53QAkwtO6kc/UZQvDhlM fbhS+omdgOYG+NYaZJtDdQeWtwOl5STbS35bGJ7vGrjNL86rht6dplkhdhxMflmYmIDC xS2ujRxAoTsP50/D+xjv66hkzULiOJVwIwsmy0el2I8hCZZMv3LUgSNwBUqn9bFtINdw rP80jYJPFgvnn1eFV7I7SO4X588L6oMk39Z9mzEmNKGvtRaiwlPG+R2nvbnP7IjKUvaj bEHxpLRgwLj2tM9qSqX4AlrVGgiA3FW0r8gDqpk+n3M0pd+GZW7q/URncLR2lNJ3CZh4 /bGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600977; x=1694205777; 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=VYYXwoQ19fU255DQi5KsqAgZki+l2UDFXaFSJWQIBddT3saM8o0ooUouCrDx4aKhBX Gjdbs4CtIwY6T5e77qFLnSoYhPOQgBuk1oy0wBUFKHBoN5ZM5JGrsnerobx0s69i+lG2 YDIL4prgG+HjKGtSSIL+CjNTVDWr7ahfSFSMkMyrBrIXR454LS8AgGP9KSktLWnHoonc c9y/Eq4wicqJmnGUxc8uFKB9WiFIPbuXi0zl3225BHPgyr51AEpWljaQXdBeUmz2O8pw F+Hql7XdBM3rCANmsrxi5CwSN8RBOLrjWOYvEIJERC0uVKW9WnQyryvP61Sgy9JY9xEa SyrQ== X-Gm-Message-State: AOJu0YxYm3nj00PkiMxclWgH0Ym4NujH3eUu5eFlMffdzyZbjC7rdSL1 WWQbyvXBvSLJF523QgP1lpp3265WfYBZLFc9ZNw= X-Received: by 2002:a05:6a00:1393:b0:67a:8fc7:1b61 with SMTP id t19-20020a056a00139300b0067a8fc71b61mr4392169pfg.11.1693600977347; Fri, 01 Sep 2023 13:42:57 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich Subject: [PULL 05/13] linux-user: Use walk_memory_regions for open_self_maps Date: Fri, 1 Sep 2023 13:42:43 -0700 Message-Id: <20230901204251.137307-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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=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 Fri Sep 1 20:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719519 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp466881wrh; Fri, 1 Sep 2023 13:43:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/VXSv4VTCpPbsHIssUCQDEqwzeL2bDFkVFVPfYnR4i/2TMCYcADmvebbZDUsmduRBWIdV X-Received: by 2002:a05:620a:1aa4:b0:76d:aa23:f8e1 with SMTP id bl36-20020a05620a1aa400b0076daa23f8e1mr4291508qkb.27.1693601019955; Fri, 01 Sep 2023 13:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601019; cv=none; d=google.com; s=arc-20160816; b=Pwe6tGz6mD6vACltlLG/SXLOt9dGq0Fc6dPsFDqm+lOabI+L1rzvdx3sdGzbp7HaI2 d46UyoF0/pGOK1rl4bdeRB8G8JivXlPl/VdPPF6uc/Na9KjIdgxuf4EoN6a5y7cqmf2j sXu+f9HxNaMyA0FLcu0AMkRikPfYeTHfC5obtmWu0DmJnRN+9Tm9B620r3hsKT5jTh6a fdOI1cHCplCBp0siraxPNVRCB5jb1JnRXx2qYVFDwMBFyhZK1Np9c16ggRneVIWogjmR Q1WV6+Ap/WrDc9BO7lsqPEOO0JWo0xNU1huH40v2xV0IfqqSsGH9rSiOnex2dK2Xnqp2 C75w== 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=Ll7Fcerm+Jswr+2aKJK47stIuMjiaUzk13pA9L+5+w4=; fh=fBRXHUj60rk5luGLPRGw8IH8EbaZu8RlH695BHD58a8=; b=I8bON/vxRcZBKzsY2CSeocIJvl2H/Bjuj+XQ7ggImv+95Ty64t886Il9zTab4qG1FS tzI0Wiz9ymRjBG5TerJx7DQcXHbWeKH4p5dAvDz97be0QXV5AHqcXknhCtVRMJL/mE0Y zqWTmn/mlM1BQh+VIW0fxBKND2I8epUhmqSf/3Ldtmaj5mlIZM83bxz5pAA+7/SECLp4 rHiHzBN3sKwLGbun1QaQc8T0TlBTE71e1qToULoJmedIHD+71d1wMqen0vN2DS4mx1iW c9/IBFPPguTXnll7uWbi16CO+WiGwiw1uw1G2e9GzDJQ/EEoFMnbn/vAZNYMBU5b/bAM 0q4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mTuoqtqH; 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 i17-20020a05620a249100b007671cacee6csi3279076qkn.113.2023.09.01.13.43.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:43: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=mTuoqtqH; 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 1qcAyu-0006yW-MT; Fri, 01 Sep 2023 16:43:06 -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 1qcAyr-0006xv-TH for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:01 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAyp-0001xK-EN for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:01 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-68a42d06d02so2060523b3a.0 for ; Fri, 01 Sep 2023 13:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600978; x=1694205778; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ll7Fcerm+Jswr+2aKJK47stIuMjiaUzk13pA9L+5+w4=; b=mTuoqtqHphL1rODik5Se1W8KUGmaWNZhfI1X3w/A1JXLJrjlnURoVV8JjWX2EoCe9m iE5E5x8pDhm2HJf6400WiRC/tWaJPM22jLDE1mLtV4nLb1fesO9gE5lznoXm1ijAMDAQ C+QiCYHO3KQgyj6u/T24Fd5FYwBLmDxTktuWupQMjPW1aEfmK/Lx0moEkpNoUdC9snQn MaOdUqaXPVzB/xCNdWk8hHvJX7FxUmO04c0H5vT165YKAj9x+uq7OhEijXPnFjDe6l0x qmXZ0rFJn8HOykKt7y/PCIvjT4kSZS/7zQ5tXsPHjrNk5Rp60pR/fhZzOvkkdBoY3If4 xOlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600978; x=1694205778; 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=Ll7Fcerm+Jswr+2aKJK47stIuMjiaUzk13pA9L+5+w4=; b=gsDLDW822ZRfNE6cjDihDujIJREnResSE3O0I2TXV3fxShcYBZiqqaBpi01nd8F+mf 7U29BHdqt4JU2fPG4j5YZas2MlVNEPZj47L0JYbcRQXA6IY6H6i3pM2WSUsGfdOIDpJg IqY6jsUijN3ZWmiNGDFVHR7BBxUSBDmM2VQLqYK/M5QmkiOSFJpGmJdEOoJR4m411o3i x9ifcBS79Ett5wHZQkjR7fExGNyWjrsnNZsAMt00NAxAHK+MnGp1G6KPMRkVZhT7D314 mkKaAxP7iCjKI+L/R7ikIC1vhBKdGAqKxr48G/a0MIz8XezwqVGtR//Uf18MwQy6lWrt rsiw== X-Gm-Message-State: AOJu0Yym0/qvCf0asabgt99o1R5RqesnskLVFhLpx0tx5FarWh9Wsvze WtUjdgxORn/JGvCP1lf6NSHTfSPEQdOmcnFkQrU= X-Received: by 2002:a05:6a00:1587:b0:68c:42:d3d7 with SMTP id u7-20020a056a00158700b0068c0042d3d7mr4219861pfk.25.1693600978168; Fri, 01 Sep 2023 13:42:58 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:57 -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: [PULL 06/13] linux-user: Adjust brk for load_bias Date: Fri, 1 Sep 2023 13:42:44 -0700 Message-Id: <20230901204251.137307-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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 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 7c95098e3e..d52d47c5c3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3327,7 +3327,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 Fri Sep 1 20:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719523 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467113wrh; Fri, 1 Sep 2023 13:44:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMAnRH8qcJnpy22ROQyoi0q0fybsxJ0LaJIZJDnzDq5dNo/YAzj7IJDRdGbL/btxEKYrCl X-Received: by 2002:a05:622a:3d3:b0:407:613a:c383 with SMTP id k19-20020a05622a03d300b00407613ac383mr5656323qtx.67.1693601061359; Fri, 01 Sep 2023 13:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601061; cv=none; d=google.com; s=arc-20160816; b=mTZhuzo/WBDfJukNdH64541ZIQZWk+JyiD1oowdIIroMhQ0o91SxJp07m6QA+Ba0/B YdOiJZLLGxvmRbi9amosHeYIyD8IUHBL2zxcBCwHAH7wv3K/LF8jPbfWPdW3bKIRSaS0 OSzyy7qpO/FiytIXKSS0SQB/bSzTmgAyqjAALzAR7USuMuZ8PvWGmzXbecuAwfatWDaL 5kJP1rmdXyqjRk6hMtYRI28Jc66xGYdnzysaDsZOqcwgXmkzSZx/2rcTxbDNHxtzGPJJ 1eJV1cV++p0OCKrHIDJ8AXoGkB7uSwOQ31ndTGQIzkCy8KPYNQdnQMv+84YY9ni5IgDM S0aQ== 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=0iqggZ/kUA5XzQ6SOnvjK327/KaVNo8nl6UgLS2s/bg=; fh=FC7nc2cUwJgFcj2hBYd16CauO1xSDGC/usFm7Dz4sAo=; b=hNNn3N+clxbXPo5dNZU9nuVzl8xGFcz7SYMf2A7vZNSJs7+5Xad9IgRfhssfGnPakg edcsGzaFS4P8X+DfHotOMay2nl3C6AGbNh111TBsyoEbzf4PWUkAeIsNorIKdpj3zzR+ tOxx8IEzD4NfFsa44WQhJWrLknyQXyWuB+NfMQKP5Z5qIEwasHNZoPyONyNUs/9B/NT1 fX/rW9GeOfXSq2kOryqUXOMOWizkJYCA1esIPjhFwRrksdKigFQlI74xXq4Jk6RRPtSb No+aV8a7jhX4xXzrkUFmTgq/2r5s9dE93B7OUg0IaI9mrEqYEJX8FPImSo+pjYIE5iih 5g/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DlZ9HJrE; 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 s21-20020a05622a1a9500b0040681c1920esi3120484qtc.343.2023.09.01.13.44.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:21 -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=DlZ9HJrE; 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 1qcAzE-0007DK-K7; Fri, 01 Sep 2023 16:43:24 -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 1qcAyt-0006yX-7R for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:03 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAyq-0001xa-9h for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:02 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-68a410316a2so2030461b3a.0 for ; Fri, 01 Sep 2023 13:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600979; x=1694205779; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0iqggZ/kUA5XzQ6SOnvjK327/KaVNo8nl6UgLS2s/bg=; b=DlZ9HJrESRXlyfxOWl61Wi/5iq42dknbSyrqwMWe9baERQaQEhyLttui/+FsWUjzgp MqjMrGRWUbSO6fmA2GNt31iP7r15FgJEsW0EL3z8rJpErYqeR+TdVBV8M4uxP9DSjq3s 4RssjGjFvBBJKPDD6NRh3/SH8y9q9ZmDseuQvFEOsavSDEuI7fa3pf3rSA2yXrQGX++/ wI+QtoK01lIkBMxysPtn07bTXCEMmSlUE5pDLR95QF7HfcE45jDA3yq5VcLXPqzw22h7 G5QLOKOabUqsoPwNyckVL3ZoLbaEpFTcIGt14c2UK8YqrmBJl1qEMBcgGKX8KDUGotoB 3Vng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600979; x=1694205779; 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=0iqggZ/kUA5XzQ6SOnvjK327/KaVNo8nl6UgLS2s/bg=; b=e+VUQX+nr4/8Vd9BJ8V74fkc28zuq0nGLtL2oXOP2YEu9yJ0xzO8yUeAYauqs1OoBH J2jJLFM1X+we21YYZuXNBy7YPJEcPsfBot1hLaDVJKghH24+VyqAYQwZTCneRWJUat+Z RTwKZ/i4kfx/vFag3zNhNN3HTJs+N0xMITlN+CWA7nfN1oHkKkb8Hm4JoWhO384hwZXz GbOOd5OS6ql5YQIsdY+z9sHqWubjkfnBsiwnERPByXtX6XbaFGlSndwfVp+KuLh1ncL5 460PXEao99t16AVd93EscrjTEiE12JNbdZxNcrAbzOMX2N3JcrscBBaN++OnH/ihSRv0 MhQA== X-Gm-Message-State: AOJu0YzjLW5tlLaH5WXQg4ZgJl97hmgMEGOmQ5huUNgU9G/wX1glgZuX ZEfUzO12umn6n4f/nLSxs6cHwPcC50hDX+PCB9U= X-Received: by 2002:a05:6a21:6da0:b0:14e:509:1d7b with SMTP id wl32-20020a056a216da000b0014e05091d7bmr4934665pzb.8.1693600979002; Fri, 01 Sep 2023 13:42:59 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Ilya Leoshkevich Subject: [PULL 07/13] linux-user: Show heap address in /proc/pid/maps Date: Fri, 1 Sep 2023 13:42:45 -0700 Message-Id: <20230901204251.137307-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Philippe Mathieu-Daudé Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- 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 Fri Sep 1 20:42:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719532 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467454wrh; Fri, 1 Sep 2023 13:45:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgoY3QPgRw7d/HleDisng28nVk5VpesGOkJhGCjdWR2/FZ/5qhb0netSXEZfISZZzCBfca X-Received: by 2002:a05:620a:4103:b0:76d:aa66:f7b4 with SMTP id j3-20020a05620a410300b0076daa66f7b4mr4408770qko.11.1693601119850; Fri, 01 Sep 2023 13:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601119; cv=none; d=google.com; s=arc-20160816; b=tz60VqwsJq9cAPhwWavZ8c12/JOpu+ntGSVQzwFp+zVg+/WzAkCdPP7BcCkVQSNP3D kNplMJp69a+X9MEO7/th8taxn+OvFFLH8v0LhFwP2xum9qnRth1q13WRAX9lcjmz+iEf HtatdgbwPr9O/Lc8RRWg3GWgmXlSA5tPKkT4O9sFTNZ/2G8Scx8NGthiJyOUC/HqXqvq Whuduo5aQRsYVTlEKE0nzZ18kM0sEC4eZBPD3DwxawbUbpGyN+7tu0ut+98NmvBESAYs JL6ui+UUeR6jj3AAEHtGd27LSf3aTRq4mgYeNm61CSvmS6bjPKjlNKQjudlX28zifiH/ IUhg== 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=F2haO9XzQj3kdCBvuyOIrGT2u14BthjtvXUbKPu1PcU=; fh=6DUz/WH1FfDiu76BT6C6RJALhc1FSbJldzC6PRDNU4s=; b=mL6kZdyKfu0Jmk0OT7eUmHplY1oc1hU1CZf/tfILZCWQCcOpWGaSKlDVgL6BprqaRf rM45kvdvU+5JT1WoblH7pls0vM6p/5qNsfkY8qxqvnlkkOgtcWL3EdFqaNM0S2fuAE8z aXrxfvi0mZjfO1Pi3QbQmcB4csKn4z5dKGN8o22sz2kM2BaHFcStAWCDGgKeCAY1lOHd kyGipZA96m8rj6cciJ8U2lRQjjS5Vw89YVflm5xuiTwRzEIirHr4QnXVmVXHWzd0+Pfe rlYH2nK0+YWuogk5JzCtkwPpivgJUYh5P5gyL4Jp7qu3D5hfnOeYqPGym5nspWsvfcAc uJRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JkE6tvYP; 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 qh4-20020a05620a668400b0076eef17f215si2822707qkn.119.2023.09.01.13.45.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:45:19 -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=JkE6tvYP; 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 1qcAzG-0007FB-CW; Fri, 01 Sep 2023 16:43:26 -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 1qcAyt-00070O-Sy for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:04 -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 1qcAyr-0001xv-3R for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:03 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68bed2c786eso2062479b3a.0 for ; Fri, 01 Sep 2023 13:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600980; x=1694205780; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F2haO9XzQj3kdCBvuyOIrGT2u14BthjtvXUbKPu1PcU=; b=JkE6tvYPDAZ1/qO70jeZDL5F5OFblU112Y2B5E3pJas2PipsR/Ug7bHL2ZgDrCKwCy piZg8jReixCgs9ktGOH6e8Hg2oqcx919hI56xZ2zl90OJVxKB1HzpaJEivU2LlV8Hy3j 6YuR+H6hoxFA9l/abnbm9KaTx/r0SeRaWFhoXPK+/9qC3qrgK/i43uq2hot+ImyWyd+C 51QfBlw/3l0x6CETG2RdSUPK5mv3Oa3EsKlygAESNkvzBw0BVlKNeOs7mre/jPwpOJ7x u0ym9PtpTJzZpyrIrKQAXT/5WXXxqLQG7TChaAnGsV6o1VqZ8xtef9Wgx2cGgws3HJJV AR1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600980; x=1694205780; 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=F2haO9XzQj3kdCBvuyOIrGT2u14BthjtvXUbKPu1PcU=; b=ch5/Q5xk4WAoegFBTrYUQj4vXCEAsN0Ysx9osgH3Vt/9GeK8GmeO/7lyQ05didP9va TQ4AzcGMXh3/20u3UPmewQMjXtVVDISXr22t6tx3XtLI4Qc9ekLob5yVWG3U3hfdxJ1b 3jiZ0okJ2vAO0W95Q1NOHwmC93OrO4lXsObUh8dFC3yXUUJrVBcsIgv4XtXqj/O+Q1XD xqDnmnEb5pXzXeT5g7cXQ7uyLe5ktwB0wUOzz51ZuFkzjyP/r8GrpYhsbayWgHbtwlS3 7lnu5m2Q0EjQzbgP91V1Wx/eLjH9ULJB6u8xzciB5hI1ozylH7foHHsu6bijypvlHUQW EHCg== X-Gm-Message-State: AOJu0YxXZbNEe7JX+9UFYmeYVJ0qRmLN9Xbnq6DyBja51pUjhMy7tSKx l9mFm9n/TqChJUYB9ddJzLygHbLdgAmnkjbORhM= X-Received: by 2002:a05:6a00:398e:b0:68a:4dc3:dbb9 with SMTP id fi14-20020a056a00398e00b0068a4dc3dbb9mr4254787pfb.28.1693600979804; Fri, 01 Sep 2023 13:42:59 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:42:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 08/13] linux-user: Emulate the Anonymous: keyword in /proc/self/smaps Date: Fri, 1 Sep 2023 13:42:46 -0700 Message-Id: <20230901204251.137307-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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: 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. Tested-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Ilya Leoshkevich [rth: Update for open_self_maps_* rewrite] Signed-off-by: Richard Henderson --- 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 Fri Sep 1 20:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719531 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467452wrh; Fri, 1 Sep 2023 13:45:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWRSpCb5S4TjHJ0ZlTgXPsRnMR3Le6dQCT31N0kuqVJyWz3REhwpA7USF91KH51AGxfRbr X-Received: by 2002:a05:620a:172c:b0:76c:bfeb:97d0 with SMTP id az44-20020a05620a172c00b0076cbfeb97d0mr4614880qkb.58.1693601119589; Fri, 01 Sep 2023 13:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601119; cv=none; d=google.com; s=arc-20160816; b=WFUzsh8OEbKiGHTx8SkHHL5EJ+rRZJJJqLWyLrLr4MXex8gwCgl3e4TsnXq1tNzCKY AK/tr/kjDQJoBFXMLxSBvlmjICMA4K93YmmbzDIFqPaAdxd/e6igIJfLFROXmUu2XnKu mAwe4Y73uAjhwnsMG+ABNEQvd1UgnaWWUuLrLRpDqnwxCdaeJz2IBTNlJROElITcyGIe 9Nw0n4eNxD20mrjLR8TXW6ebA+x3MpTEIPjDrj/iumj1XkGTKoADSqF0P5ZvDrmyuVFO LD1B30n3+nPDjuV1dSYr7Z6p2u6PhY0dcuVwAnYZmSs669JQZ6x5l/OKkQ1RKzQovw1z INSw== 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=210OlXxvczx1b1iEJ/hgZ0SIwPEb13CqLNf5LjSm/Y4=; fh=m386hzt8OWKJ4T1viNMaokaOFou30w3zXtdge72DRf8=; b=sFent/9PAKjQs1U6wCXr1YbyemwNXtUuPNVCeXJENl7NmXTnFjCU9MsZ/jIgcVhxuH 2LofFYKeuoU5DBiBcd0JkQBV1JczmGBeMMuuEhevSsZoj3MgS6cVB6lqpI926uADltap yoThqkxh2XijeiYfqD9kDONtg8K1PnWQirjX6aJFGkb8yQSINIP6FvGgvPBu4uXt+w9+ jVaNoDvz8wINw4etMW7ezBFR5Z+ae77fEDTm4n+Cr52XuDI0uFCDl88dLIxjW9vhQZNN aEtjr08LtzdACwcsLm/WJAA0d5fM2I+S0UMgEEgc51ckDZdV8XtOA9rw8qMA7BxHNmlB phYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C1idA/A2"; 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 s13-20020a05620a0bcd00b0076cbf0f6bd3si3119751qki.647.2023.09.01.13.45.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:45:19 -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="C1idA/A2"; 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 1qcAzD-0007Ai-3B; Fri, 01 Sep 2023 16:43:23 -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 1qcAyw-00071D-Ks for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:06 -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 1qcAyu-0001y0-1o for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:06 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68c3ec0578bso2056850b3a.2 for ; Fri, 01 Sep 2023 13:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600980; x=1694205780; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=210OlXxvczx1b1iEJ/hgZ0SIwPEb13CqLNf5LjSm/Y4=; b=C1idA/A2xT5bGIAYYnodAORH1hVTbdyj0JR7v7cfVdE8KB3OOCXbLEZOPY77EphUYL voacJeElOGJjDG7oyAv8qGRFbH9qEhMBm9E/hh0SEg1NcA/GVL2h2DQU2vDnkePy7ILc eTg6T1S+VRNH5LuTz7ar/L4P5FNjiUHNAOyZOWRMxbASdeswb2dyxJcqyiUkkIgP7td8 TERzUmzGUf0jC/95r1OoLosE6Q7Dq+Sw+pSDyMwgj/j/XwoM+7ykJGZj3loefmNyNP0x 5B/qmAzOV7+EvZ1FwVTrEodDOxAZdzQneu/o1gegFA5vm/KpRxvCGpZypsLn2vCO4h1J 1J0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600980; x=1694205780; 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=210OlXxvczx1b1iEJ/hgZ0SIwPEb13CqLNf5LjSm/Y4=; b=NEr5gAiEZvHj2XsYtKzbeosou9Uewxr98uPMbtWjiPkvy6sqcO4v8HyD6YiiM6NYZN fwBhHi+RgDs54ZGkhP0/S9ELQuaZ+k/xpWaSORFXkY5I3e5Lro6FN59RnRxtMZjptJD7 z+oQn33FWNCxXmFWp36NhTTWhNqmEotGj8jVMn5//0+WTy0IUOoFGk8cDBotYU5tLyQY SgSmlEy2uhvpDhZ6Ed4mZuR1+PUqA04bEpoT5s6WJPWVmWYfTj1m3IHxXW/rOF8EMQdE /RI0vEmeB59RW70puQSoS0bVOHQgyM0HvKXZL4N0bAY7+OUOpcjSb5vXtoD8jDe2MXsb 8STg== X-Gm-Message-State: AOJu0Yygm7hgHp5EYJh9zvM83/X8hFDNsChznzsh+hMT48Pee1Jnj3Ly HEHpdxrjNfW9+5tWknIuORguKOPns7wdC/1lYcU= X-Received: by 2002:aa7:888a:0:b0:68a:5cf8:dad5 with SMTP id z10-20020aa7888a000000b0068a5cf8dad5mr3894952pfe.2.1693600980664; Fri, 01 Sep 2023 13:43:00 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:43:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Ilya Leoshkevich , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 09/13] linux-user: Remove ELF_START_MMAP and image_info.start_mmap Date: Fri, 1 Sep 2023 13:42:47 -0700 Message-Id: <20230901204251.137307-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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 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 d52d47c5c3..a5b28fa3e7 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 @@ -1817,7 +1787,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 @@ -1853,7 +1822,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" @@ -1905,8 +1873,6 @@ static bool init_guest_commpage(void) #ifdef TARGET_XTENSA -#define ELF_START_MMAP 0x20000000 - #define ELF_CLASS ELFCLASS32 #define ELF_ARCH EM_XTENSA @@ -1972,8 +1938,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 @@ -3690,8 +3654,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 Fri Sep 1 20:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719529 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467299wrh; Fri, 1 Sep 2023 13:44:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhz0m7XvofV/2ZakjKJgFRQ4RMEhhXqLbpcG7V5vXs2NoXgXiYl5XtIv46oCv2QKRJYQSm X-Received: by 2002:a05:620a:a90:b0:76f:7f4:7286 with SMTP id v16-20020a05620a0a9000b0076f07f47286mr3826470qkg.44.1693601094491; Fri, 01 Sep 2023 13:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601094; cv=none; d=google.com; s=arc-20160816; b=zpxqCltu04X3zgOc42vUqCRM3WBeyD+Jqya+MqjWFaE7YVLKRElJrGyoQvOB4sCVE2 kMz7u5ZXRu6WLvOF11PXtn9e/T3rk+kdX/vPjMdU5sQAisRq+xjw1cEhDfeO0/77cgkf Rb7E+EaJ5FneU0dVDBzdQYNe0bQw0KkuTJ3mg9/0Xqedwx89WPz6u3zmBYtO62dbyh9g rHTBX3+oVfG3nu1RGWZ8lgGEj+DbYWvsWDgtSTPXUKb/4sG8EmIzAfp2rpdVbQ0PF61/ Xm/IEqHFs+EG4wi4rUMiqGgRTyvJKLlblQs2dIJEK1+fiDe3wlVRdPs8nao22RKAfMBW YHjQ== 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=QFR2l8AVy2AahKPTnSsete6fKREG3JpA0Lq3ZO2hhv4=; fh=LUeVDuBFqp51Z6cOyQ9rKCvWn53AZn+yqAEwm6XZBJ0=; b=diX6qeuYTOxv7ff6HnrS7M5ibUOonSzinNg5KNnOCXcIOJt8pADVo/H1sv9bo1i2Pk QlCTw+uMngO17UakZvj3e1cwW3RE+I0fH7lj7w3ckv+QuEuyeaGFH/pgAYKfly0wGXLz /FIfh7xwS3lHxPUqLmfidKy4Cde6Ij5FgPFDTAYd8UHwLc70DzmqVOjLxiB7EbBnV6Sl JTif/rgTSW+tuwMzyFZHSCy6gr8c6pNBUDHTdjgepUnaTVcMZxbWEN5s6R4AfbCXZpsA Z7HyrthWLeNX4VTRfajxqFk4fv45oEx+Yj39OKHZVo+AZwL3wN9K/n9cDgod3KfZ7ASj zhgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k8FFn9bz; 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 pz3-20020a05620a640300b0076db6edb7a3si3003792qkn.92.2023.09.01.13.44.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:54 -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=k8FFn9bz; 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 1qcAzI-0007Gz-0c; Fri, 01 Sep 2023 16:43:28 -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 1qcAyz-00072d-71 for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:12 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAyv-0001yQ-9W for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:08 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-68bee12e842so2043088b3a.3 for ; Fri, 01 Sep 2023 13:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600981; x=1694205781; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QFR2l8AVy2AahKPTnSsete6fKREG3JpA0Lq3ZO2hhv4=; b=k8FFn9bzO5MBmyGSJkwBsCkwLFpplVju4ZQS5+mUYGqCYqRDYocNYeaEobbRrWA/9M cN4s19Kk61sbDReN4NAeDaXPiCDPEVy3V2O8kc1kHgCEpV7Q4dcKaU+XxrquI+nO/tEr Zfw54ATpl6maGUH5L3SBvqn39lC29a2kCymd4k/bbVQbKRzcxLUQNqeljViehYpoSTMQ dIVeLllRLAfai/sFloPCzCGLdbG+5OMT5F2sdJ/jGaQV3U8E0ThHsvNRh28+ZOQdC1ft GXvFF7ccmccFyrdpB1L3kLnRr/TaVGG+qNz4fhx/rV+otRDY0Ar5G9kq3vIq8f9oYXmk yuxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600981; x=1694205781; 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=QFR2l8AVy2AahKPTnSsete6fKREG3JpA0Lq3ZO2hhv4=; b=JeKAK7ZvFZCof8kbB6lNCqFOzT66XsphYWlVRqSbGkoy6TZ6ZAgU1yBISSi3QDcS17 UGLM7eKw8N90YrJ1RoiaJ38EDRMoHvndCTZdb1+scWZnFO5Oz2oYMNP+MfVcAOyaQGkx DU/AzWgDLbjwwXaFGY/gOnIWM2PLclVkb/BqNBzRqcKePTIsvmZAna0WN/6XJ5RDly4o kMEsUeW5hKX/oO648Jh3t36ZxH1SjX/v+gKIVYtANISurBFojm1uMDUlgZPi5mO7b93x yEsY+6Ad2Qs+CFk/X1p8lpqg5L4nt8jQRUMF5z85AS5zXT/d8KWpJef1JxHIc7OQDFD4 6nAg== X-Gm-Message-State: AOJu0Yw34DI09QihRe5Y7C1j8D1kd1pY+nmMa4wCTcTVhGs7KZctwiuh zc9gDP0ur2SKha4fXnrO1StQGyAUgxTvnquoXco= X-Received: by 2002:a05:6a00:1587:b0:68c:4ff1:3dfb with SMTP id u7-20020a056a00158700b0068c4ff13dfbmr4802385pfk.8.1693600981474; Fri, 01 Sep 2023 13:43:01 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:43:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Warner Losh Subject: [PULL 10/13] linux-user: Move shmat and shmdt implementations to mmap.c Date: Fri, 1 Sep 2023 13:42:48 -0700 Message-Id: <20230901204251.137307-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: Helge Deller 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 Fri Sep 1 20:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719525 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467133wrh; Fri, 1 Sep 2023 13:44:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9GsUroOeetsJOG+1CE5/MLRgJv361/gA8aEbVtzEdTriOZGSgogPu13VNYpwTim/5xfT/ X-Received: by 2002:a05:622a:1315:b0:410:9b3c:e828 with SMTP id v21-20020a05622a131500b004109b3ce828mr4189827qtk.37.1693601064713; Fri, 01 Sep 2023 13:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601064; cv=none; d=google.com; s=arc-20160816; b=XPxZ2iN7myXI0DV7/NgPEGy9bSqAoGev4S5Vw4On63dAN3MZbJZ44R24Z6N7MllpCl DXNH9BPXq5f4UTESd/yk85UupWYX/8W/uHQoF637nCPOrY4wGW+Q23zsOzWCQhTGoxhT MCeEB+BbI4aNaEASZ6TyiVo8Bn8bPHivrqbVurWJ83v4ZbPZ3dNjP+Xy//urbHTQZFfU sYk1wyd2iPxhNrZ99ACGeNZXCo26Xevh6LTx9xJvj9u2RjjvMx5lkgAivVBPPMRSbA2X S3AazgqlxHTPiu+JPTVbJvADyuE9Nwaxlz7BqvZT9idD1wwj1Di+QNHcQ0VdGyNleZGl CwgA== 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=AcFXIYDDmm3o3vQOz6x04+Y31c6savnmQ0Pt4q+vdFI=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=hWVa4UulmQEx5DiTxpXxr8p7QJPYNVA0J5xsUZ1cb+4hcjDqqy2CSktW8sSJJRG+Kz nISZx7gs1ihQHUpj1tn9gMjsN1qP+kA0nJTeQqW2lCOtzSC98cw45ZOXEi9p6O/wqU5B qTspyRuO3FTcC6oGsIDyuqpfxFC5BnKpmtY1g6NmJpV940xpyVRvG51W4fV4390R/lkm fa6L+Hla+OGDjvbgwNaeEmS+SR4HT8L7C8w/jBDp+tlOT/YOHAoN+rm+PY5FvNwrecoP b9ez3HsEHXSmHN21QypVh/IC1KkyYrhVePxoawBG8yGB5nSNXN9qKSNP0lyeE9rA/9U8 ZB0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LQ+Quwj+; 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 s12-20020ac85ccc000000b0040fd9f98527si2864555qta.754.2023.09.01.13.44.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:24 -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=LQ+Quwj+; 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 1qcAzE-0007DD-EC; Fri, 01 Sep 2023 16:43:24 -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 1qcAyx-00071n-9V for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:08 -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 1qcAyu-0001yY-St for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:07 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68c3ec0578bso2056881b3a.2 for ; Fri, 01 Sep 2023 13:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600982; x=1694205782; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AcFXIYDDmm3o3vQOz6x04+Y31c6savnmQ0Pt4q+vdFI=; b=LQ+Quwj+eTG47JAGkz/UcfPvbmtEJV7evBaoVg7wgX33IDjSlFhzQbLNf5RvjqAB/O vY75tXpK8sP7qDPkMCiHgCYVsG3xkcEtImFoxCfbcx9R1W0n7wxUHL1nlqhLg2kuiF2Y ZxP9lazUitF4H4JiNXRsyhya5tmfmaKdgN4PjLxJSamN3gUF2NsltEKKYWo9cd9Xvke/ 7NIzjQq03Uxbj+g20iPTdMDkQSE6JWuNa9A7Av+4Nd6qxENRPAr9VFQDjy7d2bQRa9vL Q7muW7i3PGhcAEZYebFeGeg+Y/I202RkbO9d+uftk4woJ+fi8faWFaoKCKB2vJs9ccpB VZ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600982; x=1694205782; 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=AcFXIYDDmm3o3vQOz6x04+Y31c6savnmQ0Pt4q+vdFI=; b=KY95V9+p/niKKzxpF2nyipHzHtMx0cVuDIJP9Wq3+jVTc2qpnjSQyZaqfQIaAkfiRc 82FhW8FBbPfmKyEwgjHtNIj4UHOy8EDHs23mDtzFuq0kxAUFC2dxvVMuLQpmuDWYnoan 61CB+TMO7JbH44pZ51dO5dxgLQXBtxfybrGEFZYguT/Ai6WwtDhb0L+ljH5SD8CJtP+S ZeEaBT6nKsYJrzELeMwjvP5E71VpqkPOgNUriVSR2ggn5fs3K4uDMINMbGqpzcuNKGuD 27FJeFsqkMrv6CyABHbpGJCo1EuOuJdLer782o5kXWokxpBUUun2hwi96oIXtAN2SOX5 nkDg== X-Gm-Message-State: AOJu0YyrynhncUw87dLyCbiAkhfmCU+AvcIU8TtWGSh90ix5ufl2iX91 7k/X2Z6JYysL8K6wzhrvuWRdyCfpw1Hcha5vosY= X-Received: by 2002:a05:6a00:2e0b:b0:68b:c2c7:a8ce with SMTP id fc11-20020a056a002e0b00b0068bc2c7a8cemr4069095pfb.17.1693600982583; Fri, 01 Sep 2023 13:43:02 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:43:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 11/13] linux-user: Use WITH_MMAP_LOCK_GUARD in target_{shmat, shmdt} Date: Fri, 1 Sep 2023 13:42:49 -0700 Message-Id: <20230901204251.137307-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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 Move the CF_PARALLEL setting outside of the mmap lock. Tested-by: Helge Deller Reviewed-by: Helge Deller Signed-off-by: Richard Henderson --- 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 Fri Sep 1 20:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719528 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp467271wrh; Fri, 1 Sep 2023 13:44:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGdcw/1LwjODRX+mzwo7T/6zkYblIO2aRRHmMTLXgYkwkpxmfJmhwXOxQ8JxzUpin1MbQY X-Received: by 2002:a1f:e043:0:b0:490:393e:9053 with SMTP id x64-20020a1fe043000000b00490393e9053mr3161118vkg.13.1693601088153; Fri, 01 Sep 2023 13:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601088; cv=none; d=google.com; s=arc-20160816; b=We/XgatRXpRGwVdSRQ84eg9ZUgIOpNRFA95UZVwqIp9CpdyeJEuzxh9gKinMxF36mo E/xGucxlTneZryQk6CRnAZJzb/LXFBiwAH4sA+NXDpe9ltB0A7MzX3dEeL3BqI/cqwI3 DnNs8gnNmE099Jl9gKN7q3pKTmZRM4xeywqhqhydNOauqyYClNoGV/n2S0nHoQpN0inv AmX2na2AZQmWkr58L1R6Ap5XaaoS57BFclMxBkIerz9oeOYdSqY+txJA7YhFc8lWUode ujnoqFvfixCsDvVZj/99i/hhO8DO8DFPo9oUEqwE7C0ugJ/L8eU0d11UL8avt4yK6aBu N8XQ== 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=mqs/jfDEIHNofUCfPibQFnYzPmfzQW+loIwUJrctV2Y=; fh=3//KcqJEsa04kIBt5Nb/DJuP+2GuH1NwDRxnSl44zdw=; b=pVNw+EX/PsIKmDgEkiYOfnTRiRlcirJ2Rsk9w2Yh3dYEoItJtkCGL7IPjfiewKdk8/ qfTIArVh6i47pvRsQoNAmc2Ga2mm55N0WY7N1XgiQf5e6m6lyBQj6C87kMMMNQKf8lU+ Y16en9/hkUv4DCk0jUkoDmlyHgqcLia/e62sRYynUZPUI7jv7hDLKF/4z5phSpF1JTPx WFlg1/c62Nh9EIgdS2MnndCchGdq3ZqqZBmck/t1vrM0LJ+IoUXjV2bP+P9Mv8QWmeje T8L1WcOkpG71roVT7ViXKRUC2niGToc+pxYf1kTii18dDV6giFCqJwzMyNf0L2QHzE1s 01qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KHdlZu61; 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 b26-20020a0c9b1a000000b0064c224027acsi2852954qve.616.2023.09.01.13.44.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:44:48 -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=KHdlZu61; 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 1qcAzF-0007EY-CE; Fri, 01 Sep 2023 16:43:25 -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 1qcAyy-00072K-Ex for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:10 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcAyv-0001ys-Cs for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:08 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-68a440a8a20so2058329b3a.3 for ; Fri, 01 Sep 2023 13:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600983; x=1694205783; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mqs/jfDEIHNofUCfPibQFnYzPmfzQW+loIwUJrctV2Y=; b=KHdlZu61YagUHHQbODp5Ew143SF/t5iVYhgtpRrv7R+fBjB8DACeyoU7l2DmDA2sdf b9kjhElYFKyI7MVikgpNV2bt0X/5tm93W8ardtBCD4xHR9G0ZkhpAZOsgxtuK6ASEP08 4g6cTw/WsI2BkunO0dU+vzFAfkRvyA0BXiPxngDvc0P6nFvPvxmJeOEFZsJD9Iwh7ak7 A/F3LOPAck71TTIdYzwLDZ/HrbUu9a7V9lyiOvRHugAivICcCqDmi9yYXlYSHi3D+l2m d0Bt5sDuwyIBUqvnHFlKlhnw6eB9u/cOvlI7J6J0khNOs0QNJceVFaxguILtvQVJ0PdI s5dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600983; x=1694205783; 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=mqs/jfDEIHNofUCfPibQFnYzPmfzQW+loIwUJrctV2Y=; b=F9DIG6oJ0ULFjKj5VydsCEXAJfvCa5mZcygCv9vCi+CJXg1RqwrvIsdSZaPzN3a7E/ iZ23ZzC67FR564ccf6i6G+h6i5L8crurBq3eCsD4ruyEc7QXepnoO7GecK4ZjQyrEVba QKswYncLcH4vpPcEPLcFzdsJm5M9QefA7EGLoGmFtjmlCF3NDVHAV+TWrs6kZHj0+wFt v6xRI84Cvpd2WXvaTVypZBUdHsc6FZ+JBwoMfocYMi8PZF4zwDGhrd3OmCZUvsSRxja5 49O6DRI/QjZqA8W0q7sUwtHOp1qvn4dHA+iCEAjVfGS6EoVHjqjnq5w0v6fzjh9IY+rd nf5w== X-Gm-Message-State: AOJu0Yw3Ab/MBLQTpNUXgSzHXb9JQXlKypn5oFDNtXm7Kts4qYhIdWMx 3Wd+KIKSPqSmuWRb7FK1QNMXqs56hGK5EqRo5AA= X-Received: by 2002:a05:6a20:7f85:b0:134:76f6:e9e2 with SMTP id d5-20020a056a207f8500b0013476f6e9e2mr5320407pzj.58.1693600983481; Fri, 01 Sep 2023 13:43:03 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:43:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 12/13] linux-user: Fix shmdt Date: Fri, 1 Sep 2023 13:42:50 -0700 Message-Id: <20230901204251.137307-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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. Tested-by: Helge Deller Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 Fri Sep 1 20:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 719520 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp466883wrh; Fri, 1 Sep 2023 13:43:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpuJUpRQlGdwf7t5PjMsD5TLFcT0YwFhc9fhwjlQHayRgxc3F9YAEJJQqEi2pzf7/UOlDq X-Received: by 2002:a05:620a:4095:b0:76f:14dd:b165 with SMTP id f21-20020a05620a409500b0076f14ddb165mr4663547qko.17.1693601019972; Fri, 01 Sep 2023 13:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693601019; cv=none; d=google.com; s=arc-20160816; b=zbc+MOKCMirCpH2Mgr6H2rJjKjlpWJv7FTXroS3QERZJFdTbNicwnmXXE2e4gambcq 5+odA3ma5FKTPv7znBne5q4I6GrTNMHBkT5DcWEFHK4T8VcyySV4QHJU+HT/reJYj3eC 4q3H/0eMUinAZc4aVrO5FY9/uS7cKtGf9RZpYysxdSGYlA5s501p5sSDncEfzqsiWYwp P8EYWajCFAQl8fodsGss6iGnHElQBj+XkOh6Ry6PdyYKJgyviV5zEZnTMIwq6vMOwF/U 0bLTQT8khQZgF/rn0eVjsXJdana1HmVDgNszZ5NJ3VcdWo2oqXatb5MtEslNwwe61IQK EPEg== 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=uBIoNdfoCHZlUDPCS1YWUY+gLgz0IIKwqu+6lqO6x2g=; fh=wDljmxUHXfz9MGj2//jPHYRc53BMWF157v8rVKELrf4=; b=nwpHhhWmzFZQ7/KYL40acel0zwUBxwtqg/5hiy3mZdaaLEckI9n0K6yzjM9CWLIHd7 rXVSnYDwc89+Hrign+2lvzVqbIC8rjb6vLGIvlX6cLf8aLWPKibC3rwUU3BH9u6bVoM3 wxaKQDznkR6UzdTvuggHCHQDfs7teJS3tgmS4ch8q+JYDAF9S0Q7NjHh5ZIeYZXDTjxW yRY28swUS7X1bvn+iGcG3dBYRZnxG07TaG+H5V2poXgI66tDkjpR64VIonTxR41d3iw2 s3giqh8Cksubs7iLxTHjljNnpxGll4cfKgWih9y6ZY0MKjboYPWo/P292uybWxsEx0Pt OQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cqmqm+t8; 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 y17-20020a05620a44d100b00767ee53f0absi3180940qkp.340.2023.09.01.13.43.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Sep 2023 13:43: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=cqmqm+t8; 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 1qcAzI-0007HP-Hw; Fri, 01 Sep 2023 16:43:28 -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 1qcAyy-00072T-Rj for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:12 -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 1qcAyw-0001z1-Cw for qemu-devel@nongnu.org; Fri, 01 Sep 2023 16:43:08 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68bee12e842so2043122b3a.3 for ; Fri, 01 Sep 2023 13:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693600984; x=1694205784; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uBIoNdfoCHZlUDPCS1YWUY+gLgz0IIKwqu+6lqO6x2g=; b=cqmqm+t8zxwfMnKFLZywxt32QgcMoIQKMf0GpxzCC6uzMvQmwai9Yz7VKxRJE4jTLP wyTz1Qvmcrz+JYXPZMr7hpE5t4Aa3ZIzMRXdIhyaYlf9na/pcuXavnJBkXZim5ha7F0S lkSMY7N1j5goOF4wbDrDuhF4e89s47kmuXCfWRSmKZcMN7OuluyVZSqjanO1J3gbSD3k WFIUcynexuOT/KzKTT1Pl/BTTHJfD016JMKRHBtGEyBWfoPONiEq2Zv51/vhRckgjU1D WK9RLEkOAEROutbpZz0owkDHL1un+5h/I2yZypNcA71bqD517UvycTYpaSi6UVPFsAkx Nnyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693600984; x=1694205784; 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=uBIoNdfoCHZlUDPCS1YWUY+gLgz0IIKwqu+6lqO6x2g=; b=K0eBu5MBhzWOPQSUJp26TzMQgrmLBwBD9kSbnolj4akrq+/RXe90SMyebCuUYoxJbi f42SyA8wRyDlu1Wph8rEF/glY75m6LqctqGOTj51V4eJSWsthxxcknCfGOK8swfUckmz tilFfJ6bgmYG2lkyKcKliOhq14KF9MFSEuS1OQ+6f0BCuscetpJ2oSRtLLu6fG8wx0s/ 03bJJOgNe19JqPlssw0EHJvnqeBu4ywXi3Y/Ff22lURmcPyM0BAUGJwYhVGSNNasfPJx QulMxne3ko8zXsFBVCUipa6e/jKeWshAJE9HUab1e+gaLsVF3xG4DmZWKVmmRad3+XIh dnaw== X-Gm-Message-State: AOJu0YyZK9WOkx2YjMfv0HL9QdJ3NOw6LU4rV8YW1ZZfZbWCu0Trdjwn G3IzqZKW0tYvOoNMmvIXKV1S7rIAY1u7DrntGDs= X-Received: by 2002:a05:6a00:398e:b0:68a:4dc3:dbb9 with SMTP id fi14-20020a056a00398e00b0068a4dc3dbb9mr4254998pfb.28.1693600984435; Fri, 01 Sep 2023 13:43:04 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b0068c97a4eb0dsm3320666pfe.191.2023.09.01.13.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 13:43:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 13/13] linux-user: Track shm regions with an interval tree Date: Fri, 1 Sep 2023 13:42:51 -0700 Message-Id: <20230901204251.137307-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901204251.137307-1-richard.henderson@linaro.org> References: <20230901204251.137307-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 Remove the fixed size shm_regions[] array. Remove references when other mappings completely remove or replace a region. Tested-by: Helge Deller Reviewed-by: Helge Deller Signed-off-by: Richard Henderson --- 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); } }