From patchwork Thu Aug 3 20:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 070A0C001DF for ; Thu, 3 Aug 2023 20:48:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRfF1-0007Wg-6v; Thu, 03 Aug 2023 16:48:15 -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 1qRfEz-0007V4-OV; Thu, 03 Aug 2023 16:48:13 -0400 Received: from mout.gmx.net ([212.227.17.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRfEw-0002SS-Ty; Thu, 03 Aug 2023 16:48:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691095684; x=1691700484; i=deller@gmx.de; bh=xwz6aMde3YBdcmDS3z738t66mXpAPMuyqhPYVzFaalo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bapFYpASH8ihOXy/fchYrTEtlGYnFQP6jI9rb0Hb4bIFd/BQmkzGN7eZdejZWEdWZX4s804 SyEz7asbwcgtJaTVYkyDcwnPxwy5fnimh0Soc7dvKpvSfko+stubN+jNQ1yIdeIYsRXOb5UQT o7rvC1MVV4ihtYL6I2kDH4SYVnkfYoYeMVoSfk/El3IiKQJ7unrPBpjt6l73UGgvvYTT8lxLI Dmgyp62rQLu1SmfNrbaLBper1J9pfUwqmnWvbxlRBH8aqvmyNulbuDVVeWhyplN8DNK3PIiL5 dL6gxPaQdB80zsntzGnEr7qRUxDAPjLgKi8F0D9labWrMxvWF4FA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.147.53]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MRCOK-1qDQB61xh6-00NDW1; Thu, 03 Aug 2023 22:48:04 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?q?=C3=A9?= , qemu-arm@nongnu.org, Richard Henderson , Laurent Vivier , Helge Deller Subject: [PATCH v3 1/3] linux-user: Fix openat() emulation to correctly detect accesses to /proc Date: Thu, 3 Aug 2023 22:48:01 +0200 Message-ID: <20230803204803.639733-2-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803204803.639733-1-deller@gmx.de> References: <20230803204803.639733-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FWY0+UEU+U6Ysrxr9GvdMR9C0hGXfG7CzpCGA3MsfxX9XVIBQ4B Yk2LkXdZXd/NUNJEw/XMZ+3V7AFITZB0+/Zfe+KaasTZbeOuqCQBrylzGlY/U1IqnRB5Yrh FQfz5m9gVBjxHPmkZvagu++ZGlH4hgnyzz3dpgOCO+JxYpPvMqvUd3GiFHWZHJtWd7/E11R dh768SfjRZMYNVMK6kNaQ== UI-OutboundReport: notjunk:1;M01:P0:UU1Tlh3NTCg=;X5hFlEhISiimliao1YqqmdYEM3J +cSrVgXc6jAl/6gU0ofMT6zSNRzQo22mRCJIXTA+C2VlSMEyoKqEFUONrsi3KR6B/tUpcguPl 1DNjGSuT8ssLy6SGAAymW80Roy8oEKK5OA5Hq7hyz7fBYnNEoUsWhIE2qjr+Q0l3hh6QQc9uQ AjFzWhjRZj+79p/lfT7AuB+Lq4Dqs6oeeHEREzb1cI+o4GzEdIN5H1KfLhMdSygoeB+31Nxh0 KDaHOvugHxYdEIThrECjkIJheSKdsGEODLur4P5iChYHQKkElVCaVhmvBMR53PiWqSAO55aJ6 /OW+BOJAKApyzWPQNh+OPV3IuqL3mWRXxXuIP/oRtrJsLwWxY9WoXSACTMWDziStGLkxmBJRy lxnfmKICIIqZa/2jC28E/TS6vaSbioF/e3+5k0LQ3lG2gmLzZBP4n8muGawGdLyoieX2H20yh OErwWWr2QrgUSerAM8K8E0wOHEWIbTswyqGZ3G3tMFnI7ft2Tg8qJbkZDYhGNLUbkZ9V51SKu Ny2+/1yBTcLIk2tFZbxMEfoqTRGLxBnU8ot0RcBd/cEPGLZgIEnFThoclhhZgnusMSVknAqoj 73xMTkMPt8UADs8F+Zakg9oljOeG83xaECnvg+vf4sxc6A4PE/R1Xm0V6RWPqmjhw8BkypwXH 0Yx5d+30uwLI3JOx6QJZwEsL+9VrBSIn5fyAGfSmE1qpRHhMXBbSRmwo9/BvRE8309dgEY8kR LXkvQXk0ZLIjgBefhT9joa601SVMkV2rCFC7vM8rNwsWGwOH/bvQwNC5wpgmv0bOgtBptGBcv uD7XOZ+8m+U9TT1kfO9ROJ35ABRGk/2LFwA+wwh+L7ZA1kIkyVZXpWuEusu/+p1sa1KMPZhUg LQvFxU8omKsdm8T19QlZb9HSDiiEUSWnYwLZ6HytOKIZqCInYcfmU9XkBG10zqOrgBxLIX6/9 D4mJHg== Received-SPF: pass client-ip=212.227.17.21; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In qemu we catch accesses to files like /proc/cpuinfo or /proc/net/route and return to the guest contents which would be visible on a real system (instead what the host would show). This patch fixes a bug, where for example the accesses cat /proc////cpuinfo or cd /proc && cat cpuinfo will not be recognized by qemu and where qemu will wrongly show the contents of the host's /proc/cpuinfo file. Signed-off-by: Helge Deller --- v3: - use g_autofree on returned value from realpath v2: - use g_autofree instead of pathname on stack Daniel P. Berrangé requested to not put buffers on stack. Using g_autofree keeps code much cleaner than using extended semantics of realpath(), unless I can use g_autofree on malloced area from realpath(). --- linux-user/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.41.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..1ec7d27e37 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8539,9 +8539,12 @@ static int open_hardware(CPUArchState *cpu_env, int fd) } #endif -int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, int flags, mode_t mode, bool safe) { + g_autofree char *proc_name = NULL; + const char *pathname; struct fake_open { const char *filename; int (*fill)(CPUArchState *cpu_env, int fd); @@ -8567,6 +8570,14 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, { NULL, NULL, NULL } }; + /* if this is a file from /proc/ filesystem, expand full name */ + proc_name = realpath(fname, NULL); + if (proc_name && strncmp(proc_name, "/proc/", 6) == 0) { + pathname = proc_name; + } else { + pathname = fname; + } + if (is_proc_myself(pathname, "exe")) { if (safe) { return safe_openat(dirfd, exec_path, flags, mode); From patchwork Thu Aug 3 20:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7D95C001DF for ; Thu, 3 Aug 2023 20:49:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRfF1-0007Wi-H6; Thu, 03 Aug 2023 16:48:15 -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 1qRfEz-0007Ux-EU; Thu, 03 Aug 2023 16:48:13 -0400 Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRfEw-0002Se-UO; Thu, 03 Aug 2023 16:48:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691095684; x=1691700484; i=deller@gmx.de; bh=XWSnm7MlhEIJTAyNaAmmAZHyaAMI6Jg/4buWfucSipI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=dD/GnG1CNaptYwT0ykzsgFXCPZKkdbfgNiB32qX1EhQ2dEIpwqss3iaZs5RiIsA5/aTlXM2 DSDvLfVXwj1Fyw/7SvwNBpC88oICG8U501QMzSCEneaJFmL/7yKxEzKed8z6+MNFdzFwLUYga WWr/xD/g0z894Fqc4k40dGGkudT96fwDzyyB6k6pY3rzjt0E/AqiTpaaR8+c74fGOmGITpZEg j6Bpnptvg4pr978/UMVJ/WyzbYEZ5m9LAXyJobT8OGZ2TMS+aH75Dt+Z4Qu10QjblBEauGVZa TAWMlbBct5KgHl0VklUFk7vUSjoxP40qknYVSIRhXfD/Uz1MkO2g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.147.53]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N0XD2-1peMPQ2u8K-00wYKj; Thu, 03 Aug 2023 22:48:04 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?q?=C3=A9?= , qemu-arm@nongnu.org, Richard Henderson , Laurent Vivier , Helge Deller Subject: [PATCH v3 2/3] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Date: Thu, 3 Aug 2023 22:48:02 +0200 Message-ID: <20230803204803.639733-3-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803204803.639733-1-deller@gmx.de> References: <20230803204803.639733-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:pAfX9IZIztBv37IaGITGUblZYck+LXI/nA0BsHmCfikc6wuJ+2u 4VBvtFfQI6E5NeyYeWk0F0qIwo52Au+R0bxR1jGCM05WNlXi4HReVGchIGmpKKoVgI//DYU e7MTWZ0z7QvSpCI4WGgoGwfeTaO6eqo4KrsP1r+cX5YHlH9VWzSGBRk86ZhL7f9eFaK0kUI tNF7dXNoGCevAUk61fevQ== UI-OutboundReport: notjunk:1;M01:P0:pbYVW42pKZo=;BUdApvVkquhEO1ldVIXEmK567le aCqn47kd8iiMfvB0LcZqmv6K5uWG62Jc+IZwUMEByhnqPqCxPp24TIGrkfdDeP/n4ArAObFd1 NZ5RiZwbCCpG9Hx+J+s7WN992iyb0Nam8DwwDSG7p4BT489ni/MhiHNZOd3kpAydrnCvLft4g gI5hUMDSQMLc2gY1VjhD0jsuAu8wvvrs8mEjWPXlmlZxRB9Jvoj8wOcrf136bqwt3xwJI35wK DX2GudOa26ZtsFqQ+MlL5n3pgODuyED+ptu2f+URzUUhW4aYI0kN/IDNdE9gIQGWKo7AoHYGb vtt8Vy+X5/jILiNl9ZRzLCjMQj/x29lZj22JA15PleFbHXWFR/cygg01F1pwrVumR/SbFmigC M+Ysd2u85JFCB8pwbDqwxfasqRH9I4ytZ7jonYiSo40EhzWY6ew83mOpPQiKE6HXySd+mvgPV UZOHEEoXTAY/slO7llmFXUcdaTRN/VLRpE2wkqH2Fn6EoRw25DEvQbjsO62aZc5vXfiUWEak7 1/rRIKVkdEMdOYthuzcYcsUqfHEIBL/vMtZWFPQe3OPDSh1FvmfFZAWNV3xbjLxJ8Ea+jyJ6r 658VV3r5kiNFaPxUVVAjDYIfRrswCelJd8ckXs+QGY809/I/9EhHiOZf0vqgDkxkeRO1+gXGG nwcm22knrDmfVYxvYC9/YIJrGmhRmYxUohYyzOVeoaNrSCmEFcLbbBhGxo8bNI1pFY39Exxqy WhRlNZ5xW+Ob/6mIwAYTeYXdlgbwx98zEr4T0Z71Kr2ppMgL+Ah0OlXEnMm7Gz5aFRZ4VG2JY S91JCckEm4XkF9MpzDD81B6Wl35swMA/tRn6sNlgg3zILe6PFwCrwHK8gtTorLsgf2eU7qW3j 5p1Ij5FRtKOClMZpQdqVIn40359AZuarD6lJtH9guVQXUSB9XASi78jHQTFRRgBn7Kpg2R5Gr /S109H6dLkkIxnzwD1HVshsTFgY= Received-SPF: pass client-ip=212.227.17.22; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 Hardware : QEMU v8.0.92 arm,cortex-a57 arm 32-bit output example: processor : 0 model name : ARMv5 Processor rev 6 (armv5l) BogoMIPS : 50.00 Features : swp half thumb fast_mult edsp CPU implementer : 0x69 CPU architecture: 5 CPU variant : 0 CPU part : 0x2d0 CPU revision : 6 Hardware : QEMU v8.0.92 marvell,xscale Revision : 0000 Serial : 0000000000000000 Signed-off-by: Helge Deller v4: - more refinements based on Richards feedback v3: - show variant, part, revision and implementor based on midr value (suggested by Richard Henderson) v2: - show features of CPU which is actually being emulated by qemu (suggested by Peter Maydell) --- linux-user/elfload.c | 130 +++++++++++++++++++++++++++++++++++++++++-- linux-user/loader.h | 6 +- linux-user/syscall.c | 76 ++++++++++++++++++++++++- 3 files changed, 205 insertions(+), 7 deletions(-) -- 2.41.0 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 861ec07abc..99804e477d 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 */ 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/syscall.c b/linux-user/syscall.c index 1ec7d27e37..bac764f502 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8323,7 +8323,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) + defined(TARGET_RISCV) || defined(TARGET_S390X) || defined(TARGET_ARM) || \ + defined(TARGET_AARCH64) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8539,6 +8540,76 @@ static int open_hardware(CPUArchState *cpu_env, int fd) } #endif +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + const int rev = FIELD_EX64(cpu->midr, MIDR_EL1, REVISION); + int arch, is64; + uint32_t elf_hwcap = get_elf_hwcap(); + uint32_t elf_hwcap2 = get_elf_hwcap2(); + const char *hwcap_str; + int i, j, num_cpus; + + if (arm_feature(&cpu->env, ARM_FEATURE_V8)) { + arch = 8; + } else if (arm_feature(&cpu->env, ARM_FEATURE_V7)) { + arch = 7; + } else if (arm_feature(&cpu->env, ARM_FEATURE_V6)) { + arch = 6; + } else if (arm_feature(&cpu->env, ARM_FEATURE_V5)) { + arch = 5; + } else { + arch = 4; + } + is64 = (arch >= 8) ? 1 : 0; + + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + dprintf(fd, "model name\t: ARMv%d Processor rev %d (%sv%d%c)\n", + arch, rev, is64 ? "" : "arm", arch, TARGET_BIG_ENDIAN ? 'b' : 'l'); + dprintf(fd, "BogoMIPS\t: %d.00\n", is64 ? 100 : 50); + dprintf(fd, "Features\t:"); + for (j = 0; j < sizeof(elf_hwcap) * 8; j++) { + if (!(elf_hwcap & (1 << j))) { + continue; + } + hwcap_str = elf_hwcap_str(j); + if (hwcap_str) { + dprintf(fd, " %s", hwcap_str); + } + } + for (j = 0; j < sizeof(elf_hwcap2) * 8; j++) { + if (!(elf_hwcap2 & (1 << j))) { + continue; + } + hwcap_str = elf_hwcap2_str(j); + if (hwcap_str) { + dprintf(fd, " %s", hwcap_str); + } + } + dprintf(fd, "\n"); + dprintf(fd, "CPU implementer\t: %#02x\n", + (unsigned int) FIELD_EX64(cpu->midr, MIDR_EL1, IMPLEMENTER)); + dprintf(fd, "CPU architecture: %d\n", arch); + dprintf(fd, "CPU variant\t: %#x\n", + (unsigned int) FIELD_EX64(cpu->midr, MIDR_EL1, VARIANT)); + dprintf(fd, "CPU part\t: %#03x\n", + (unsigned int) FIELD_EX64(cpu->midr, MIDR_EL1, PARTNUM)); + dprintf(fd, "CPU revision\t: %d\n\n", rev); + } + + dprintf(fd, "Hardware\t: QEMU v%s %s\n", QEMU_VERSION, + cpu->dtb_compatible ? : ""); + if (!is64) { + dprintf(fd, "Revision\t: 0000\n"); + dprintf(fd, "Serial\t\t: 0000000000000000\n"); + } + + return 0; +} +#endif int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, int flags, mode_t mode, bool safe) @@ -8561,7 +8632,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, { "/proc/net/route", open_net_route, is_proc }, #endif #if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) + defined(TARGET_RISCV) || defined(TARGET_S390X) || \ + defined(TARGET_ARM) || defined(TARGET_AARCH64) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K) From patchwork Thu Aug 3 20:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07AE3C04A6A for ; Thu, 3 Aug 2023 20:48:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRfF5-0007em-Rx; Thu, 03 Aug 2023 16:48:19 -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 1qRfF4-0007YX-5m; Thu, 03 Aug 2023 16:48:18 -0400 Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRfF2-0002UP-F1; Thu, 03 Aug 2023 16:48:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691095685; x=1691700485; i=deller@gmx.de; bh=lhYljpfvW3kbrbZFdXLNDwXWVsR5BLVObZ2qG3ggGF4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=McgcxK26LWYz0iO6ABI3xRtvcShZAPTMuxNkxCuuAspiHUAhZI7yeeV2SFm7RGn+TJUgyuZ BId+DBGH3iB2UctiHDlErgbk0jhF0VguOsjL18HcD41L9Q9zWak5kuLiULE2faVs7j6/j5l0n IaDkc32KfHr0DmaTUCfA2nhoze7PD/O1GDSm44hs/QRYfvRFw93yH0jFUSve80SDQNt11SgTb YIbExHPBCDyvoZC5TE7+CFaUCJtAV71Ujlpp5X1tbJc0u9IY+muL6MNY53awK29y0nj0QIXKq AQDCVUtBjNkyHMZSpFFdqWhOuEMRwsUppL1ra7LpojkxeUK83x4g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.147.53]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N9Mtg-1pnC7641jg-015Jl7; Thu, 03 Aug 2023 22:48:05 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Daniel_P_=2E_Berrang?= =?utf-8?q?=C3=A9?= , qemu-arm@nongnu.org, Richard Henderson , Laurent Vivier , Helge Deller , Michael Cree Subject: [PATCH v3 3/3] linux-user: Emulate /proc/cpuinfo for Alpha Date: Thu, 3 Aug 2023 22:48:03 +0200 Message-ID: <20230803204803.639733-4-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803204803.639733-1-deller@gmx.de> References: <20230803204803.639733-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:obfIfNRsORslnLIr1qrPWGHFWRiPb/NcfzczxGgi/EetgjPsNiy XnCunUwRQ0gjeOZ4PT0q/7gNC5hPoEvhfY67Jj+UIKUQI38xB6k0jGA+p4YnSFiR+1+ri0C YyxloKeCVUyEcc6Dk5w5zVj8Ij3WNE6XN5aKurGz1VG5hrUShJJTqnG8RWnW9xqsSE6A9vF lIhSmtw8nDeTOpFi8Fj2g== UI-OutboundReport: notjunk:1;M01:P0:f5sXkuxRrFc=;o/4H8SO2nFBBcTJlH9z+hiVv78P Uz51bgPqDhAYliMStQvQ7WzLzBJbv/AJywD9gjniWIzDH6eAPBpE2Y7+XFYho6pE5SJT4qaQR +ZKFfVE2v6BSaK+2R51aXeWDKLoZrDOF58Tvtg+2iWb4t+uDjplYA0ZfG6elxF9LD/jzmrccL 7obr9pC0BuyCIKcAZYMlI5EXi7Yjw93kOY3dsaI0TFCr3OPeLAKPLNN2/AeC9apFncirt6Bvo BkwvnS/b88mfEf56E4uzXFo0Rn96/3IgxQTfth0JDPB++FEqHVoJzR9S9MkfDu1qAJXg75xSA 4K+YIXKEcpEXVfnGdZcGQU240kMyUgZiwYVvUlUlSJuUaVX2H/2wgywNo4ix0xzi/YF7XQcfb TKW94HkqZZtxgKm93M7JPDveeDwRd+Qs2Ulc4FPb7H1q84xYwJSScYtBbp8yGVBG41o84ofgZ CKKQFfmwLjExeo1/djnwgJX6gg2soXh9P1iyF7wnIKGSDvd0dIAKLBcQ2EEuowShOiAW3PgEC NIW5cYvQJJEKGEwC47JumaIkWW6vTKfQ8P34JmJHOHuysNWd2C1SOIDT46UgLW65NQ8MNbJaN fqcedhifKYJbAhWEkXsgFrOEtDnYAq2StFmeCNJbekn59EHcuUPiChLXpFeozKBOt45VworQr riWKG+P4IjFq87C4nz3MfGlyOQlIBj2fa3BLjj0ax4XplJ7EHPAGQKvT3pUAxS8Ozr3Le4cxI bxRt62NBlHhayhGnFL/qb6oyTsxiGLsiv7KCgxUp+E03oAU8y+i8N12wkxwhaGB4UgeN+IC5a 1FfYzl6VFx7o8ofqSk56wFzQhq8z62iVGrfKCtSii0QDfUBfQMtztRkLAF6fZEMuJpHXUwWqi MeePyHZRmF9hjOz16IpOREvYvgyqLHCahDNsq1m+ArxzrrKTbZOt4BnecjTfaM7f1z+LN0orK 7vfGrxgccZOr4B+yJf+4gs+5bTw= Received-SPF: pass client-ip=212.227.17.20; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 : 7 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 Cc: Michael Cree v2: - revised platform string and system variation output - show cpus detected/active/active mask based on current physical machine configuration --- linux-user/syscall.c | 56 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) -- 2.41.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bac764f502..a4d597ac05 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8324,7 +8324,7 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \ defined(TARGET_RISCV) || defined(TARGET_S390X) || defined(TARGET_ARM) || \ - defined(TARGET_AARCH64) + defined(TARGET_AARCH64) || defined(TARGET_ALPHA) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8376,6 +8376,57 @@ static int open_net_route(CPUArchState *cpu_env, int fd) } #endif +#if defined(TARGET_ALPHA) +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int max_cpus = sysconf(_SC_NPROCESSORS_CONF); + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + uint64_t cpu_mask; + char model[32]; + char *p; + AlphaCPU *cpu = env_archcpu(cpu_env); + CPUAlphaState *env = &cpu->env; + + g_strlcpy(model, object_class_get_name( + OBJECT_CLASS(CPU_GET_CLASS(env_cpu(cpu_env)))), + sizeof(model)); + p = strchr(model, '-'); + if (p) { + *p = '\0'; + } + if (sched_getaffinity(getpid(), sizeof(cpu_mask), + (cpu_set_t *) &cpu_mask) < 0) { + cpu_mask = (1ULL << num_cpus) - 1; + } + + dprintf(fd, "cpu\t\t\t: Alpha\n"); + dprintf(fd, "cpu model\t\t: %s\n", model); + dprintf(fd, "cpu variation\t\t: %d\n", env->implver + 5); + dprintf(fd, "cpu revision\t\t: 0\n"); + dprintf(fd, "cpu serial number\t: JA00000000\n"); + dprintf(fd, "system type\t\t: QEMU\n"); + dprintf(fd, "system variation\t: QEMU_v%s\n", QEMU_VERSION); + dprintf(fd, "system revision\t\t: 0\n"); + dprintf(fd, "system serial number\t: AY00000000\n"); + dprintf(fd, "cycle frequency [Hz]\t: 250000000\n"); + dprintf(fd, "timer frequency [Hz]\t: 250.00\n"); + dprintf(fd, "page size [bytes]\t: %d\n", TARGET_PAGE_SIZE); + dprintf(fd, "phys. address bits\t: %d\n", TARGET_PHYS_ADDR_SPACE_BITS); + dprintf(fd, "max. addr. space #\t: 255\n"); + dprintf(fd, "BogoMIPS\t\t: 2500.00\n"); + dprintf(fd, "platform string\t\t: AlphaServer QEMU user-mode VM\n"); + dprintf(fd, "cpus detected\t\t: %d\n", max_cpus); + dprintf(fd, "cpus active\t\t: %d\n", num_cpus); + dprintf(fd, "cpu active mask\t\t: %016llx\n", (unsigned long long) cpu_mask); + dprintf(fd, "L1 Icache\t\t: n/a\n"); + dprintf(fd, "L1 Dcache\t\t: n/a\n"); + dprintf(fd, "L2 cache\t\t: n/a\n"); + dprintf(fd, "L3 cache\t\t: n/a\n"); + return 0; +} +#endif + + #if defined(TARGET_SPARC) static int open_cpuinfo(CPUArchState *cpu_env, int fd) { @@ -8633,7 +8684,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, #endif #if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \ defined(TARGET_RISCV) || defined(TARGET_S390X) || \ - defined(TARGET_ARM) || defined(TARGET_AARCH64) + defined(TARGET_ARM) || defined(TARGET_AARCH64) || \ + defined(TARGET_ALPHA) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K)