From patchwork Mon Jun 5 11:39:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13267248 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 2ECC3C77B73 for ; Mon, 5 Jun 2023 11:40:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q68ZD-0008NA-MI; Mon, 05 Jun 2023 07:40:07 -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 1q68ZA-0008Mj-Vd; Mon, 05 Jun 2023 07:40:05 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q68Z8-0001Lm-Qm; Mon, 05 Jun 2023 07:40:04 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 355Bd3wo007968; Mon, 5 Jun 2023 11:39:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=8/7Ucu7bP+Bej9q4jKRvVmBuHIM33C7F/YTw5Jmu8Rg=; b=fl+/TA3CZt445pDPF5TWfB0itMufgpLkA6vw9vZaYtk0uWjF9NO6Y+GygIhWwgxmlnJu cLiaAXNQUWgokL4AnqbGGpaTBoJ7DPi/apsGdAl2RQ7MRcsLrH05SAzCbfZfAupHlU/H GinJ/bzaGrYZrkLrbcl1NXNgB/rkWrlB9xwo528KnQunKgplEzEJLobrLbmjCy/NXpu/ VmsLJqzNV6+LdoJlfhDy2fM27F/vyGU3srQg/zpWurtV7u+xnEEC4osjz2DcqtV9GFYV y5l8LpyLneTJ8VWUJwejsHOSSahC7GNZUzZ65qJk2czY2yw3q+CWkI/oMWQKsWUWb/7i eQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1edyrqu8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:39:59 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 355BdIeJ008479; Mon, 5 Jun 2023 11:39:58 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1edyrqtu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:39:58 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3550sWg9010031; Mon, 5 Jun 2023 11:39:57 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3qyxg2ha6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:39:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 355Bdscm55378236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Jun 2023 11:39:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A62FF20043; Mon, 5 Jun 2023 11:39:54 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D76B20040; Mon, 5 Jun 2023 11:39:54 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.209.184]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 5 Jun 2023 11:39:54 +0000 (GMT) From: Ilya Leoshkevich To: Laurent Vivier , David Hildenbrand , Thomas Huth , Richard Henderson Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v2 1/4] s390x/tcg: Fix CPU address returned by STIDP Date: Mon, 5 Jun 2023 13:39:47 +0200 Message-Id: <20230605113950.1169228-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605113950.1169228-1-iii@linux.ibm.com> References: <20230605113950.1169228-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: wZWao3Lx6ldQQJp4YOKyuVf8ww9dRTvt X-Proofpoint-GUID: Q3iH101puMTQC9FZ4Z19UXWvOpzyPyfv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-03_08,2023-06-02_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=923 adultscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306050103 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=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-user-s390x, /proc/cpuinfo contains: processor 0: version = 00, identification = 000000, machine = 8561 processor 1: version = 00, identification = 400000, machine = 8561 The highest nibble is supposed to contain the CPU address, but it's off by 2 bits. Fix the shift value and provide a symbolic constant for it. With the fix we get: processor 0: version = 00, identification = 000000, machine = 8561 processor 1: version = 00, identification = 100000, machine = 8561 Fixes: 076d4d39b65f ("s390x/cpumodel: wire up cpu type + id for TCG") Reviewed-by: David Hildenbrand Signed-off-by: Ilya Leoshkevich --- target/s390x/cpu_models.c | 4 ++-- target/s390x/cpu_models.h | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 457b5cb10c4..ae8880e81dc 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -607,8 +607,8 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) #if !defined(CONFIG_USER_ONLY) cpu->env.cpuid = s390_cpuid_from_cpu_model(cpu->model); if (tcg_enabled()) { - /* basic mode, write the cpu address into the first 4 bit of the ID */ - cpu->env.cpuid = deposit64(cpu->env.cpuid, 54, 4, cpu->env.core_id); + cpu->env.cpuid = deposit64(cpu->env.cpuid, CPU_PHYS_ADDR_SHIFT, + CPU_PHYS_ADDR_BITS, cpu->env.core_id); } #endif } diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h index fb1adc8b210..cc7305ec213 100644 --- a/target/s390x/cpu_models.h +++ b/target/s390x/cpu_models.h @@ -96,10 +96,18 @@ static inline bool s390_known_cpu_type(uint16_t type) { return s390_get_gen_for_cpu_type(type) != 0; } +#define CPU_ID_SHIFT 32 +#define CPU_ID_BITS 24 +/* + * When cpu_id_format is 0 (basic mode), the leftmost 4 bits of cpu_id contain + * the rightmost 4 bits of the physical CPU address. + */ +#define CPU_PHYS_ADDR_BITS 4 +#define CPU_PHYS_ADDR_SHIFT (CPU_ID_SHIFT + CPU_ID_BITS - CPU_PHYS_ADDR_BITS) static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model) { return ((uint64_t)model->cpu_ver << 56) | - ((uint64_t)model->cpu_id << 32) | + ((uint64_t)model->cpu_id << CPU_ID_SHIFT) | ((uint64_t)model->def->type << 16) | (model->def->gen == 7 ? 0 : (uint64_t)model->cpu_id_format << 15); } From patchwork Mon Jun 5 11:39:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13267249 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 7EA96C7EE23 for ; Mon, 5 Jun 2023 11:40:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q68ZX-0008Qx-MH; Mon, 05 Jun 2023 07:40:35 -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 1q68ZD-0008NJ-Oq; Mon, 05 Jun 2023 07:40:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q68ZB-0001MJ-5N; Mon, 05 Jun 2023 07:40:06 -0400 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 355BNXIM004782; Mon, 5 Jun 2023 11:40:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ihcPcXiIidfCiPyRtX/zY5CTCGkeOzuKFNykdBgc8Pg=; b=SbRX+4fgpFUddc0AvYg1Pa7lx/dOPMFrh422LPDnIZlvx2HlFY8boGnAtw0rr0cOHYxi DA4f4tNrbjkMAKvAAEruQ0Bgd8j9eRewpX4AFQBm+lCIqAhcX0Bvp3hmlL9z9hSCPtbs FW+4DnZNHIX0FaWwKBbQ4HbwHSWM5DechvTbY/izaZplVrTEE9IStBIR3mCb1uemFaRU AFF2rupedYI+CjM7XF0aH3UtgbF+ENAYod9evI+pDn7INJQIZ5xvlYYJR8iY5BAYnOta 4L1B1+WPXmi6XkAL+Bb2H5IsptJICTsAuO/EvcKDPxLyqqt5t7pMS00MNG3U6CHAuVkc 6A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1esv8c6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:01 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 355BOZom009666; Mon, 5 Jun 2023 11:40:00 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1esv8c65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:00 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3552gJ42032350; Mon, 5 Jun 2023 11:39:58 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3qyxdf91ht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:39:58 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 355BduMX18809380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Jun 2023 11:39:56 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4161820043; Mon, 5 Jun 2023 11:39:56 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F3B4A20040; Mon, 5 Jun 2023 11:39:55 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.209.184]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 5 Jun 2023 11:39:55 +0000 (GMT) From: Ilya Leoshkevich To: Laurent Vivier , David Hildenbrand , Thomas Huth , Richard Henderson Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v2 2/4] linux-user/elfload: Expose get_elf_hwcap() on s390x Date: Mon, 5 Jun 2023 13:39:48 +0200 Message-Id: <20230605113950.1169228-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605113950.1169228-1-iii@linux.ibm.com> References: <20230605113950.1169228-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: EAZCudBK4vGkbJ4GoldAzOsV_ML_xMwb X-Proofpoint-ORIG-GUID: cza00Rf5lrUiErCFRS23zCXV8VR3cI0- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-03_08,2023-06-02_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 phishscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306050103 Received-SPF: pass client-ip=148.163.158.5; envelope-from=iii@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=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 It is required for implementing /proc/cpuinfo emulation. Reviewed-by: David Hildenbrand Signed-off-by: Ilya Leoshkevich --- linux-user/elfload.c | 2 +- linux-user/loader.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 418ad92598c..49ec9ccc944 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1583,7 +1583,7 @@ static inline void init_thread(struct target_pt_regs *regs, #define GET_FEATURE(_feat, _hwcap) \ do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0) -static uint32_t get_elf_hwcap(void) +uint32_t get_elf_hwcap(void) { /* * Let's assume we always have esan3 and zarch. diff --git a/linux-user/loader.h b/linux-user/loader.h index f375ee0679b..ad6ca9dbe35 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -56,4 +56,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src, extern unsigned long guest_stack_size; +#ifdef TARGET_S390X +uint32_t get_elf_hwcap(void); +#endif + #endif /* LINUX_USER_LOADER_H */ From patchwork Mon Jun 5 11:39:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13267251 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 AB352C77B73 for ; Mon, 5 Jun 2023 11:41:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q68a6-0000Jx-15; Mon, 05 Jun 2023 07:41:04 -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 1q68ZD-0008NK-P5; Mon, 05 Jun 2023 07:40:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q68ZB-0001Xx-Kz; Mon, 05 Jun 2023 07:40:07 -0400 Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 355BHWuM006983; Mon, 5 Jun 2023 11:40:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=FMmC+NDiH4E0OblmqlQKqPFxSKGizYNiaFpTDwa77rQ=; b=UjwIEqjbfxDK06/z52MCXcYV5Sl2pMp8q4id47bCFe5nZ2t2it4h1WVReosml4M+sv1s UxA6m64Ko0elvwJj1wGsYRGWBnuHT/JJJGbV6mUJoOR/wQGGqp6nvF7zjG9dB9eHezAe hE7PBMwNEY9dJA6j2ASzpS+sZ2+a3PyoZYpymjwLymkucTyzJFurcm1KTanNEpYh8jPS TU9OHMcVmOyUDWkHKLFmfqQNkP9JepSKVY6sllioi1twLksdMbQGsJL7s+f+B9rA7zki y+aROjXRkyVXVGsgu7sna+z/9DiIEb8dWDp9plid0jBIdlEexnVuuPA0a1Bw8D6ncLRe Gg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1epugfxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:02 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 355BPU82002158; Mon, 5 Jun 2023 11:40:02 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1epugfw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:02 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3559LIga027166; Mon, 5 Jun 2023 11:39:59 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qyx5q91k3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:39:59 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 355BdvCN20972190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Jun 2023 11:39:57 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E4C820043; Mon, 5 Jun 2023 11:39:57 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 156EE20040; Mon, 5 Jun 2023 11:39:57 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.209.184]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 5 Jun 2023 11:39:57 +0000 (GMT) From: Ilya Leoshkevich To: Laurent Vivier , David Hildenbrand , Thomas Huth , Richard Henderson Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v2 3/4] linux-user/elfload: Introduce elf_hwcap_str() on s390x Date: Mon, 5 Jun 2023 13:39:49 +0200 Message-Id: <20230605113950.1169228-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605113950.1169228-1-iii@linux.ibm.com> References: <20230605113950.1169228-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vTvf-h6uAIruIRfj2N0F6OK5mTM7tJKu X-Proofpoint-GUID: A8KkOynIOxZ5L08mliVF7A3HCOK1Xaah X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-03_08,2023-06-02_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306050103 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=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 It is required for implementing /proc/cpuinfo emulation. Reviewed-by: David Hildenbrand Signed-off-by: Ilya Leoshkevich --- linux-user/elfload.c | 27 +++++++++++++++++++++++++++ linux-user/loader.h | 1 + 2 files changed, 28 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 49ec9ccc944..d80d68484b6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1605,6 +1605,33 @@ uint32_t get_elf_hwcap(void) return hwcap; } +const char *elf_hwcap_str(uint32_t bit) +{ + static const char *hwcap_str[] = { + [HWCAP_S390_ESAN3] = "esan3", + [HWCAP_S390_ZARCH] = "zarch", + [HWCAP_S390_STFLE] = "stfle", + [HWCAP_S390_MSA] = "msa", + [HWCAP_S390_LDISP] = "ldisp", + [HWCAP_S390_EIMM] = "eimm", + [HWCAP_S390_DFP] = "dfp", + [HWCAP_S390_HPAGE] = "edat", + [HWCAP_S390_ETF3EH] = "etf3eh", + [HWCAP_S390_HIGH_GPRS] = "highgprs", + [HWCAP_S390_TE] = "te", + [HWCAP_S390_VXRS] = "vx", + [HWCAP_S390_VXRS_BCD] = "vxd", + [HWCAP_S390_VXRS_EXT] = "vxe", + [HWCAP_S390_GS] = "gs", + [HWCAP_S390_VXRS_EXT2] = "vxe2", + [HWCAP_S390_VXRS_PDE] = "vxp", + [HWCAP_S390_SORT] = "sort", + [HWCAP_S390_DFLT] = "dflt", + }; + + return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL; +} + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { regs->psw.addr = infop->entry; diff --git a/linux-user/loader.h b/linux-user/loader.h index ad6ca9dbe35..59cbeacf24f 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -58,6 +58,7 @@ extern unsigned long guest_stack_size; #ifdef TARGET_S390X uint32_t get_elf_hwcap(void); +const char *elf_hwcap_str(uint32_t bit); #endif #endif /* LINUX_USER_LOADER_H */ From patchwork Mon Jun 5 11:39:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13267250 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 04FC7C7EE2A for ; Mon, 5 Jun 2023 11:41:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q68aJ-0000WZ-Oz; Mon, 05 Jun 2023 07:41:16 -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 1q68ZG-0008OC-5F; Mon, 05 Jun 2023 07:40:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q68ZD-0001bZ-QQ; Mon, 05 Jun 2023 07:40:09 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 355BUZbo006635; Mon, 5 Jun 2023 11:40:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=AAuuJnKEslDmxDQKLZ3cyieSto90/UiEsNBezbigGx8=; b=rUXjd24hBlSOH8q1T41/FesfpKZacLnbHhB0pEoGm8+eymXUJxelG8MNM4ivdfn74CrZ RAMV3UPupTfq8EEaAdhKwosE7JlqlJOwHBecJpAe0fBXjQs++eS//aBKGjKoX27jrAdV 97s2Sx7bGNlMjN/K/6sXbMqgru320dYRnHJceI6EUasK3DkW5fJLCh/TpFq2heM/k8HD yCdny9famoMxELCfrbVjI4yJauWvJ6G9X184zOYDqRRaVKlc0BX4g1IVpv764FLhGiuw A3bvQ6Ihop2maFxOAm47q1p/oKGT2A/91+YzNIsAeZ5vL2HdATk4o1kSWHTHkMx9grR0 TA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1evxr87g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:04 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 355BVBKW007139; Mon, 5 Jun 2023 11:40:04 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r1evxr84v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:04 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3554ReQ9019802; Mon, 5 Jun 2023 11:40:00 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3qyxahh1p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Jun 2023 11:40:00 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 355BdwfX44630448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Jun 2023 11:39:58 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 26C5020043; Mon, 5 Jun 2023 11:39:58 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD0C820040; Mon, 5 Jun 2023 11:39:57 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.155.209.184]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 5 Jun 2023 11:39:57 +0000 (GMT) From: Ilya Leoshkevich To: Laurent Vivier , David Hildenbrand , Thomas Huth , Richard Henderson Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Ilya Leoshkevich , Tulio Magno Quites Machado Filho Subject: [PATCH v2 4/4] linux-user: Emulate /proc/cpuinfo on s390x Date: Mon, 5 Jun 2023 13:39:50 +0200 Message-Id: <20230605113950.1169228-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230605113950.1169228-1-iii@linux.ibm.com> References: <20230605113950.1169228-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6-jaX_WEmRGHYD6ibZsvog5ONWJ7zOUA X-Proofpoint-GUID: 5mtk1-YDN3o4_ugwplUWO02hpysGc-W5 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-03_08,2023-06-02_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2306050103 Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=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 Some s390x userspace programs are confused when seeing a foreign /proc/cpuinfo [1]. Add the emulation for s390x; follow the respective kernel code structure where possible. Output example: vendor_id : IBM/S390 # processors : 12 bogomips per cpu: 13370.00 max thread id : 0 features : esan3 zarch stfle msa facilities : 0 1 2 3 4 7 9 16 17 18 19 21 22 24 25 27 30 31 32 33 34 35 37 40 41 45 49 51 52 53 57 58 61 69 71 72 75 76 77 129 130 131 135 138 146 148 processor 0: version = 00, identification = 000000, machine = 8561 processor 1: version = 00, identification = 100000, machine = 8561 [...] cpu number : 0 version : 00 identification : 000000 machine : 8561 cpu number : 1 version : 00 identification : 100000 machine : 8561 [...] [1] https://bugzilla.redhat.com/show_bug.cgi?id=2211472 Reported-by: Tulio Magno Quites Machado Filho Reviewed-by: David Hildenbrand Signed-off-by: Ilya Leoshkevich --- linux-user/syscall.c | 106 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3e6ed51ce62..2d3070cfd62 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8232,7 +8232,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_RISCV) || defined(TARGET_S390X) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8339,6 +8339,107 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd) } #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) { @@ -8364,7 +8465,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, #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) +#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \ + defined(TARGET_RISCV) || defined(TARGET_S390X) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K)