From patchwork Tue Aug 1 19:10:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13337182 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 6A41CC41513 for ; Tue, 1 Aug 2023 19:11:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQulj-0002Zp-Ot; Tue, 01 Aug 2023 15:10:57 -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 1qQula-0002UV-81; Tue, 01 Aug 2023 15:10:48 -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 1qQulX-0002DI-O5; Tue, 01 Aug 2023 15:10:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1690917037; x=1691521837; i=deller@gmx.de; bh=x2WCk90r3kqILwUNojPe8GNq/6l5cw5ovlA7R/f2IzU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HLG7KUrUOlX6EiLTny+/V2iKCPTxX6+xBNTs8pReTpdkkWOx9n/0p9tkTGOQN9lvNpXLrtd ZWx7+5cFbtNhpVheG0JPcH2YlX3v6qtwQkgLxG8BBBlALg9CuJoa3b1jLb2RO7DwPbaVLHSzf /kTwlD2x2Xjk6amOxV1gFclJnr9LKXl3lvprLv8SfoJLiZ6mx+yW50DPPnW4mH4eqJyn5bqKZ JqePzIxrWqKEXORcQ6bfZUleMqPmBgcwIpSDTnMpEQT8rik6i9TbMvXNz9vIwTduyiYyBtGiY XXR59nVTGz4Yo/TrLmdjBEyIaMD78gkW92Da/G+SkNw0qyc3Mmww== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.150.247]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MnJhU-1q1n8y432y-00jEov; Tue, 01 Aug 2023 21:10:37 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Laurent Vivier , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , qemu-arm@nongnu.org, Helge Deller Subject: [PATCH 1/2] linux-user: Fix openat() emulation to correctly detect accesses to /proc Date: Tue, 1 Aug 2023 21:10:34 +0200 Message-ID: <20230801191035.374120-2-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801191035.374120-1-deller@gmx.de> References: <20230801191035.374120-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:t2Qxvy/8uIfWsppEqM5abCnaRoULrkykz2ZZeXCLGXfQJOOPBAP J27DaF0PPCWxDac6ygd3ozCHVLG5VyovwcyXD5SOyPxkXT9/KQedMBvsIr3666V1ljzzSP+ UK4plnoZgiQGmOvv6amqPweeqYQBGnHxUpxLFd+/G9P3mu72AAM7Rt31tLwuFj0Ppq/FelH /aFyBLFlbACObr4uJw3/w== UI-OutboundReport: notjunk:1;M01:P0:zBl5iumgsRU=;vRj4BaMYLi2Ah55QRXZv1dNAIYC MeDzHyAVn0i/6xLMETkxIbIPAKMEezsex/L9BnYGl9ALQvn6lxl968TFm0dHu3iyj0ZRsohk/ Gk4VJr2D9+pRfPNAwj5IulZ2OJmm4pxVlr1EweSdF1DtPOdSfWfiK1vDprkt6bwMxFtV8qvel UFqHLU7keLrhW4tTFncKvb8q0DNqIbrzESDyUUM6xbP/xVYRuWZsaIoAkUxb+4V6g0N6bFeeP azonhVqN9oF0HUliOprdxvTGRRtl8D/9qVhmWTzpBwLwo501VYcsKiBvzgAUphsXJE6KMbDhx TMjvbmRUEDPpgt8/p1f2khIVLdZLyxI6HKzlQV3hWqiPQsJRRkuMWdM+Kp3G1sB4emj9JEyZK cUqTVpxuVycwhFv7/6XsnuyCgYjXxXL31ly5fyBTSqzxQX2iP7HQwGvqhBEpelbRyPoOBx+23 eGFmC7M59id9B8TkIH+yLVYvhpk3TUMZGLSyl6r1dVpfBfWLhCjVCc77h+dLpQr6u4bHujCGb anZm6J8uoZjNY9EFg6mmoYdeTjqvBhLqS9dpaNB3nLnNC6rjBdnRdCqG5FBO1HIEe6y5K97U3 2cxptu6zO6HLqrMUEbfeIhzC556AtdcbrPMz5Grj62LBCa/tOzCallnHRFXh1cDAVSr0dc8da if0chTETwORqRN2NB+1zb1Wgn85oxXYgE8E/xQsy6Qc46Ny5iLMeip78xqcDkPazcgfvQKW/q OVsDjozgab5gNbYqFJ9LNaCuGJ4CcQV6bJCEoZzHPaklNlL0GvujeDVikTgGZcbD+szZKQMi0 PpovMEoA8yIJnrNq6YTQMpo78rfrvmzVoM2qJFr8zGwLUfTfKW1vE4DR/lNtr220BbT8nQWSi mi2DW3SNioPDXhGXcvSsM3gBcRnysZSd/VeIISyeEnAcg//bSbAHCJkBrRdO8kPElt/z4rTQF HedYIIlznfIkZqeuAMZeETt6x5k= 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 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 --- 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 2.41.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..a089463969 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 = g_new(char, PATH_MAX); + const char *pathname; struct fake_open { const char *filename; int (*fill)(CPUArchState *cpu_env, int fd); @@ -8567,6 +8570,13 @@ 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 */ + if (realpath(fname, 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 Tue Aug 1 19:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13337183 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 8F254C00528 for ; Tue, 1 Aug 2023 19:11:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQulm-0002iJ-VY; Tue, 01 Aug 2023 15:10:59 -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 1qQuld-0002Xe-TT; Tue, 01 Aug 2023 15:10:49 -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 1qQulX-0002DB-Nr; Tue, 01 Aug 2023 15:10:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1690917037; x=1691521837; i=deller@gmx.de; bh=A9foXwB4xfV1MCiqkjNwcLYxaCPGMINDt6L21YLkWSE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Lai3Nm2hyVorLpb8v5YEJwV/FQuPZQBz+V8ljKQv/qsvyRxHbLmXCDTNZWJLKdmWacbHcoj TGLYC9Hlkaajamw1K9a/p9TE4wRq4pO/k8t05pRo4KLVq397h6t05+VdYvHn1BI8lOfcr4hZl EyUa5IVoGSEhwMDSUuRB0H4SnUlBwP+eCLeZl/YKUF530VacHn/SRTz7TKZX2v0gcKvRq0zhh qO5MCmSr15pGhUn6lQXRsBZ6opTNqhNbe6QZg//raTSQmgUtGcr99zNpQr2cTYCMhE8GLa2xT xmQJAkvgjrFcC9DxSulZzTCDr5DqA0PqlNLCYqm56esLzFzlKS1g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.150.247]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Msq24-1pXyh30y7c-00tFFZ; Tue, 01 Aug 2023 21:10:37 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Laurent Vivier , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , qemu-arm@nongnu.org, Helge Deller Subject: [PATCH 2/2] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Date: Tue, 1 Aug 2023 21:10:35 +0200 Message-ID: <20230801191035.374120-3-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801191035.374120-1-deller@gmx.de> References: <20230801191035.374120-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:IjMVSLXi1tUy2nsWl6SHNHXUABBdUBqv3vGm0L1p9Sf3Vg2jrB6 xDBNBdFcpdIippsC3l4xZTEQOb0JpiUC2AClK+IHyaYB7gtXYUo6mtuTPn2PftLc7fk9GJk hVz56jVS6cMwhoKQYBt+EOGHHmlrI1FOkODxMerzAt0CSyklqXWqrp32XMpPdRc9j9mWWuR 5nNjNk3qJqND9aTIiq4Rw== UI-OutboundReport: notjunk:1;M01:P0:rtFmJehCun8=;hy9qzKqyOVqXnMGyFcJVBulClgI QhcWmk/EtXYr6QCHJxCTZYja+cU+YJZCSSaI2vTsTLCoa0blSAkq1GrGEX/skbqGKe3Y0T4nZ HJV+y71UwGcc9iR1Z1ZbINPQHEd2zOPCnPfh/+Kq6mwPJAwIPmiBd6Dy1rR4xfx1lqhQQ2fP6 MUGn3fVDyZhtw6pC+yNcWkV1RIsyPJQZA+sItEhQSp7OguQGZ5cPgcTQB57TGysJeDVdbn2Cx z6jZmuy/HZFxFrLACWNlxUfalG4GVxxmugJQLXDb31MZr2NLJ2nHw0Fij8hgDFho6hUb+lyFV B3ZOXC2x8NeXXk1Dk1o8VaSb6iuaN3yJSe3a9IMH67ABPg3ji3Zzm9CbZCaxIgqaSeo/pxZke f7M1gHjc0ufcHCdvtt6QlCWUuB9z5t8pCOEvNZt3uiyqRz6WPYlaIFucXbZQSUIhxuWYlHhrg xRl24CwdOLMl/sX8OXsEtyRpjv+NEHnEnTswxZcY0OMQwRrhB9sx9TCTdLAABySRihBp9Xmnc dOgXC3q3LGZGroseFjtK5W6NQJ1uI0QUyTo9GgRPAt/Bh1t0Uf84IrjZW19DjQ9o+pyrV+6hD 9Lt04IFPWkkIQSQUiG02cpHU3wipWI/P7uIL3/ScrWg2KikTZKbDBCQ2pTcSYYia/BDcoh8VH VnhErhUBPmh8hcHIyFgsfadS70zrYVZrwtWJIsYmmZS2CciaUerj/xOGMTWFK/oMRtgyiR/3z Cvuy74Jg2YGckWpBcYkibPjFpl7D9aznubB5dhpSvOQvILULSTfEkn4tWkR07S+5h6McomZXf x+j3Tga4ahvG7VEnBlJ9f01T7oJJMGWUShwQPKgUmJTpFji8NI/YZXqCfZu6l6cEUQIq6qaL2 ToC5bxD5Hq1hakJuRXWzWCVFdZekRjcy3cv2WillnOsy23GMQh7fUJDqFeb/eG5NqsqI8RCNM zt5lu5D6jm19vvci/EJDfKBd6b0= 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 Add emulation for /proc/cpuinfo for arm architecture. The output below mimics output as seen on debian porterboxes. aarch64 output example: processor : 0 BogoMIPS : 100.00 Features : fp asimd aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svef32mm svef64mm svebf16 i8mm bf16 rng bti mte sme sme_i16i64 sme_f64f64 sme_i8i32 sme_f16f32 sme_b16f32 sme_f32f32 sme_fa64 CPU implementer : 0x50 CPU architecture: 8 CPU variant : 0x0 CPU part : 0x0 CPU revision : 1 arm output example: processor : 0 model name : ARMv7 Processor rev 2 (v7l) BogoMIPS : 50.00 Features : swp half thumb fast_mult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae aes pmull sha1 sha2 crc32 CPU implementer : 0x56 CPU architecture: 7 CPU variant : 0x2 CPU part : 0x584 CPU revision : 2 Hardware : Marvell Armada 370/XP (Device Tree) Revision : 0000 Serial : 0000000000000000 Signed-off-by: Helge Deller 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 | 58 ++++++++++++++++++- 3 files changed, 187 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 a089463969..8d11c459cc 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,58 @@ 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) +{ + const int is64 = TARGET_ABI_BITS == 64; + uint32_t elf_hwcap = get_elf_hwcap(); + uint32_t elf_hwcap2 = get_elf_hwcap2(); + const char *hwcap_str; + int i, j, num_cpus; + + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + if (!is64) { + dprintf(fd, "model name\t: ARMv7 Processor rev 2 (v7l)\n"); + } + 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: 0x%d\n", is64 ? 50 : 56); + dprintf(fd, "CPU architecture: %d\n", is64 ? 8 : 7); + dprintf(fd, "CPU variant\t: 0x%d\n", is64 ? 0 : 2); + dprintf(fd, "CPU part\t: 0x%d\n", is64 ? 0 : 584); + dprintf(fd, "CPU revision\t: %d\n\n", is64 ? 1 : 2); + } + + if (!is64) { + dprintf(fd, "Hardware\t: %s\n", is64 ? "??" : "Marvell Armada 370/XP (Device Tree)"); + 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 +8614,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)