From patchwork Thu Aug 3 21:44:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340853 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 AE7C8C001DF for ; Thu, 3 Aug 2023 21:45:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRg7v-0003qz-O7; Thu, 03 Aug 2023 17:44: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 1qRg7u-0003qA-EH; Thu, 03 Aug 2023 17:44:58 -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 1qRg7s-0001FK-GT; Thu, 03 Aug 2023 17:44:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691099091; x=1691703891; i=deller@gmx.de; bh=xwz6aMde3YBdcmDS3z738t66mXpAPMuyqhPYVzFaalo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=rc5N8fRZrbH1QQXpKMmfnEBKkv7QxxqcfgSvsRzshO7no5q0eWmk7EYwocYSX66UnqaNElf 92XLGOdTduDRxsXTGLRwpr7lSM3wj6/TuPu7pIkvIzIvWjVtmkRayAtPQeF7c0vuYmHyrJMEF xCFI+1Z2V0TmLjAWWHQ5sRp8pSFuHO30rquvpkR8nIuHgEGOl46M6kYJNZHamZlmnN0a1AFBR 2vi4dYjstBmJv6FRMccJ6BTk62ZjZFqZ99I0OYtF5+KR4aQxiJgXpVI5XVr8vKjTjwK7EwXfH Yp+8D3vwyCo/4+Vmw9CcH4mN5idFOqU2y+FMjUXx86+qSKEbNiXQ== 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 1MCbEp-1qbKm93OOB-009eks; Thu, 03 Aug 2023 23:44:50 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Laurent Vivier , Peter Maydell , Richard Henderson , Helge Deller Subject: [PATCH v4 1/3] linux-user: Fix openat() emulation to correctly detect accesses to /proc Date: Thu, 3 Aug 2023 23:44:47 +0200 Message-ID: <20230803214450.647040-2-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803214450.647040-1-deller@gmx.de> References: <20230803214450.647040-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:E6jZmUD8b9E4Kc2BiDPx9ahwQlCwmzsuwv39p5tnJPirMIpqap7 ZGpvUoueICd/At7m2DudLYMbnYG+bm/f3jg88apRy42KYHPHBdP5RqpFkzfg0fzLhpRcVFG DVtLC+Pwzk64iuIXou0vxaDJASZQXY41dzsOfjGSsZtZ8tJUdoNtQxjBZgOqW4xSxWBTbQK OfmC54jWPe1gZpKWpTO5g== UI-OutboundReport: notjunk:1;M01:P0:zqCNsq0Ssgw=;2hUdO9/keL3wmlQfYAMEEthQsol TpJ8255dQIpsmDrOunxqNefMpxM7ee0f+QzF4d7jd7RkjQN9yOdUYLcJFnSllAzVRZF8HuR2a 2ekFIULzXjle6Eylxyc98fCsPluchi0eJcINXDmRvI4Zm2pCw06fkvHoOs5VvL1YoMoogVW6u iezWKnJdeh443oxb5mLMCbP1LDWn83mfHg9WrtxvpiJT9DQhAp5rG7zkT1qXL24RaMLLwELVs 5LXIi6StHMaAhvr9cekhhgKT0Y1FSj5mttoFBJAFLS/ezNTVHs5x6EwR/KZHjK6RvFE7Qq6qI tOA+9VD+RpRK5U2vdTDaVo8SdvFLd3reMtV2c3oRoyKnB+Nr4GxGD8O4sQBie1iXTA75UmLRV K4vAS1xI9UOJi4wpzGBDoE7hyCDv5l3GhAzThV5/99rWhpc+q41uCj8CTtnx1I5knlxUD5dD/ F5ZFFkeAQsDXMmXcGc3Be8o/tKjiqAZN5ByRptaHJiUitUbY4cfRNFvYpf6k612IIJ8fEp6H8 ugbjghnsIg5bhAPnPdT73tzecnbe5tdQoCGo8wHsdgvMxaaFXLrZz1TpBcFwWKmOeLHWBS2MX PJI+KyutEytc47wonRy6N9GekT1I3Z3Ap2AC7KRlUl8ZhejDDhsmEqxKO7yhlSBl9ETxfzDVv uVGG7tdYzFRb31lpRwkJIzziCgZqeJYG0KPzqKIBHv14wfLsdZiQnpziymKsYzVAOGIMt0Syg wcwLplafTp7H9Kz3gIOA5oDMyrcc7aQQA4sLaToSwW0bXrK7W+b0k6xsfevlyaRiTR2rhBfEE 2n1yyzxVidQlHgAzhCfzuscSoNWUcD1A8gZMKe5LGsBpG/teVgqrWG92K4zIRaQruVTOXdMJe d/9YJHbjshgIMXdXqam1pdBR/cmoO1DVag1eAg70CyTAuYr5YGWi6EJx2nEUS4zhXx+3D9D9B dvsuULP2aifYD6WKSMAWN4ru9qw= 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 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 21:44:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340852 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 A2D66C00528 for ; Thu, 3 Aug 2023 21:45:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRg7x-0003ro-G0; Thu, 03 Aug 2023 17:45:01 -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 1qRg7u-0003qT-V8; Thu, 03 Aug 2023 17:44:58 -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 1qRg7s-0001FN-Ep; Thu, 03 Aug 2023 17:44:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691099091; x=1691703891; i=deller@gmx.de; bh=YPgVEknD3rXl2+ZRqGIBdEyd7eyLE0WaMymUUljNnMY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=oHHdqXoKG1Hl9v1+8SW8f3jTYyEiVq9MY/JpKLIetlN4Ij1HccZeyY4iJBPLNiZP6QrIMJi OzI1Y3weIJnr9b0vNI9MV3ymuL082VWAAzMeT1ltfzJP2Zs+q/1a3nBdcZE2B4UuiEEXQr8pU BaeptlslVpboxnGvCUfpdeo3xtOOV9NR4mm+LFpD217R3a/Qe5wn3MLfhYsB9ubv6WFOYMa/B 3Q8JnHdiDtN4bUD8aQPsnUNoDigoeChCtal3ggweACBdGhy1ZlLZYe9cXY+mlPawZOQ6iuhei aU5vh47XAfcycM/aqATXdThVKdhjxQBD0Erxw6KXGjaMCKKp1Lkg== 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 1MuDXp-1pY34Q05e9-00ud24; Thu, 03 Aug 2023 23:44:51 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Laurent Vivier , Peter Maydell , Richard Henderson , Helge Deller Subject: [PATCH v4 2/3] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Date: Thu, 3 Aug 2023 23:44:48 +0200 Message-ID: <20230803214450.647040-3-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803214450.647040-1-deller@gmx.de> References: <20230803214450.647040-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:j9LDkK/dHC/n7JPBYRKSAOgHuFYgTF63y3Vc7CCnRD/o7e5zfp6 Ik+L2266klJUJ6dUnUntZ0+yTdbbe6TxW32hp3Lt3aiqnp94lQqaDkYbE2loM3S1ZU48Yj0 HPq5FM0NM13ZIbGXdrUOwza7OWXyhQCzcHzzoW+M8H7tNRXsPl9dZ3gqbkxlvq91i6td9E6 LAsngB7cJk67GyCCE8ptg== UI-OutboundReport: notjunk:1;M01:P0:PDKBKa03O0c=;9vszGhnDqE/VpWleQiibJfaa3Dl nFk9evbT05ayGKu1eyGDcFBN2VpPrgcMpRZDnfVQ82Dl4UEh6pLaIPsDwyAHAvaowoXyKhXQG cj1ABUII60d4Dw+ILWImTy00wtTdbJFQYFBrpZocWnZ1HpGFvcqmWLMZoH8dvoWcqvGp8w4D4 J4gSvZW3X7TRS2agQGEEtCE7f4zniqQ80KABmQY2ZF8PRFiPO7XWO2MzA0xd7Qmzh1ON4td9u tU43aywmLMcJ0VFaHXWRy+EzdAtyC3qewafs2k/xr9t2+PqoU0onrYFGzqY3TmdwnKtyjDukr xVOdB+4HJAu1KWeAbEnZSuiiQlI3F6UG3YtD+g3EYY6W+j9Ji4D5G6iEYVsL8bplUKYSkNKRD GxAl46dz9F7f+GfSrZ6u94qz5DivrGqiJ33pbURtVz8C7kSIcXB2hiHr4r6ZjzDl2WSskDyV0 PFb+XQ6zLxsCrM6eO/ZdAFcvOfeeUh9FWofOn38XyPc7QGs4fG/KxObVJaWyYONHRL8lkm5UN 41f7NkzrTmAZhhSNHNS0UKK9KpYRcuqblIda/W78A7SyL6SqzR9GZl0Dac5N8OYugF2r2I6up DrBk7CXvHXFwWuvSK6ZcLGCXHZFR5+foaOjmNA31e1C+qN17R4U3PymUVFym2u+Oju8lhIRuR nwfL6MAT2/Wa4MNWAKudIU23tXUUxUCMeU76pZhYKSloJ9m3OR2DEgr9JBlha0a/LHRFpwyY9 u1ca7qteZa40nssfGWvOu9n8XuDo26+nX4QOIjunuIU1OnNqr9AMiOu30Cyj1K57Tx8c4px1r BkDdoC1odlci+gQui6eNxp86A69FZ+XFG6Fvt4J6oywRVdkn+e8Gz2TWmuKhuobTd0QSFz1Jx W2rD2OYi7b/NJCy7C7ayzJaTLWGOo+hkOQdyRfZhlGtalRH84rIZOJ4nShUUFBR/h0mem7j01 IXvF180ltjaMj9JrIofLWRVMXM8= 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 v5: - use is_a64() 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) Reviewed-by: Richard Henderson --- 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..6328d7f434 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 = is_a64(&cpu->env); + + 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 21:44:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13340854 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 45DF1C41513 for ; Thu, 3 Aug 2023 21:46:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRg82-0003t1-HC; Thu, 03 Aug 2023 17:45: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 1qRg81-0003sn-7Z; Thu, 03 Aug 2023 17:45:05 -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 1qRg7y-0001Gs-8O; Thu, 03 Aug 2023 17:45:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691099091; x=1691703891; i=deller@gmx.de; bh=/02ufWd4kJoEc7JJHuyZDWsKtIMBSraIfCOSIvVAJPc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=C9WbPzkx96QAAhRajMhO/EgKwCU5Q1c0TI1f22HU4v6b2kgSbN7oJlBpTnM1iE36A+973+K M2X+UFmR0ATIux0K9K887i4VTY5/472/KwDiJl/HS4TiuIV7XEhrP6gsxEPUKI10LYliN6ynA c8mYNlA3gY6p4z/wdnAkUFb/U5QgTzKdB04e5BLmIgbt+T3bG+NUDEX+3avTNnJC0s6jzdeKK P/JqcPUaN7FpGuUi4GVUsNrJN/hsOu2mUuqdjOUzvZrDfT05BMTQMPP2d2UdRFICr16hQS4aM 4BrHDeKSF/JpxTRQQ9/5mwavxqGyvqe7/WozcHJrvKEhX+XMkzTg== 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 1MnJlc-1q0LbD1Bxs-00jGDt; Thu, 03 Aug 2023 23:44:51 +0200 From: Helge Deller To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Laurent Vivier , Peter Maydell , Richard Henderson , Helge Deller , Michael Cree Subject: [PATCH v4 3/3] linux-user: Emulate /proc/cpuinfo for Alpha Date: Thu, 3 Aug 2023 23:44:49 +0200 Message-ID: <20230803214450.647040-4-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803214450.647040-1-deller@gmx.de> References: <20230803214450.647040-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QS5FUNJmVRwQhUXSAdGoGAtQszlnLdkshwjiRZoAmkagIH3tdrA x2NBwsRtxKWGDIGJGkOVYtvApN4O91lDOl0YKa7NyOpKD2ejHbP0C3ZyjPugrMXPWygPMEl b/Chj/Q/zsGEJxJVrvWH26EJ25lh601ObDB29+T2xtoaa1gouGzoyfEC5wHmlAW2p5fUGCD 8bIXYHvdTME6/AIMFaSsA== UI-OutboundReport: notjunk:1;M01:P0:RPwYYEAgkIY=;UvBbEzdgYu8O+bHQENtIh5q8WCE H6vGHN9z5APgMCprWrORQ0XC8pwqQbLpymRc0pLhqVdZZbzlXj/1xH6YFkS1ULvj/XDp/zgxK LJTSxDWNunUezGKNeGcSYImt/tU0nnWor51PLpb00i+XQPBuPSW1LW3aAg3hGU8js+4fKUFa1 n2dN8V+UQMCoetdaO+mDN9adzQTdUEe+zCwfYzjCN/P31UJWQmTZx2Wk+kbzq8mDEuGdO8E07 veqYLSX6Tm+H+2eQPyp4SFWAPS3VBmUW+sjij/b183KipFE++Rjn4eGnLcFuApH6+q6jK1bPm lIlBb8LxuVYRpN2dP+2e0bQSLqijhRdCr4Yy4aEHtRJMbq4Gi6BioM865gDCeIdoYZ6ubZIjD P+Hu1RFBmF++v/Ko6Bi6jVDRu4AlZwtZHFuVbKBwv3WV9Ts4guVvhg2N1pWKjACYAFyv+vn+K oQpkrQvewyMCTx7UTKB0/XkFv14oIDVhTaBoc91UL8mhL8m9X269cuDFoHrriMH8lfkKKjI9g FoLhI9Mv6myITfwcKakKB9MdK2Ao5PDZ6IRkGce3ZDTtmL6LzSh+D6v9II9JN3XSL2/9oyTap xsGCLGQ0E1adcwBqVo/ZWpsDULDoviQa/+4Uv+61E2GxKBl7F4XqUtEo7VlLArghKeeM0fnvx eSCO9LvcJVtIM/pODhB5Uiw/DBeq2NwZfUl6j0uZeGyvVLKqiRXJNPpuP+4uaN44OPsBy8JVT khLKZHXZLybEU2CVbEvNxrb9JluqhQfY7X9vlUSFUSY3MYhoX+HcDglEANRVA9ncQBYiAyRQR 6lAVkdgCe8lsa9Poit9Ot8uieHnht26HMxerhq5uNJCXN7RQGoiSoPFws6/cINt/ducvoL3JH XTOgXEq9NU9EbH9/caSiVJN0VvR0rnZC9OdP8aUnZvkDwS/d+EWzFUiXuT1Ovo4idW1bVYiuH OU21/Q== 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 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 v3: - use PRIx64 instead of casting to long long v2: - revised platform string and system variation output - show cpus detected/active/active mask based on current physical machine configuration Reviewed-by: Richard Henderson --- 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 6328d7f434..aa470c465d 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: %016"PRIx64"\n", 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)