From mboxrd@z Thu Jan 1 00:00:00 1970 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 7C88FC77B73 for ; Thu, 25 May 2023 04:17:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q22P5-0006cE-T2; Thu, 25 May 2023 00:16:43 -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 1q22P2-0006bc-0l; Thu, 25 May 2023 00:16:40 -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 1q22Oz-0002JZ-7U; Thu, 25 May 2023 00:16:39 -0400 Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34P4A36J030020; Thu, 25 May 2023 04:15:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=content-type : message-id : date : subject : to : cc : references : from : in-reply-to : mime-version; s=pp1; bh=AZ4WA1ObwPxymNTKsrGVqWteNfJGkwq4grCMf9BZLBU=; b=j+wZ0xk3WcCPQZLisaoQhjII/r2BOlvvjEj/peJj9ERdYMYMrk8Psaa95Fpvz391u19v hFuayBmrAghFpsSGZhzCWxRmUbYb1kMbVvKLbWii9b2pV0DCm7dlEb7RT3zLDN3oMyl2 ACIHIqX4UdKkINXSt2cZNM9OtKX2xVeDsaFm4LLviz6GeZKKZUFr6d4jvPt9yaM6G6yt kR9EITNfU5pxpEjXEJ/ZyjKoTAyrXDpWULT7ZJBYTnKuhoTqAB6nanL62wlgvn+IWpa8 6BrvjpW0mpWdV2ies6XElikRTzAmQtctG8pZ8ttKyZUnYA1Vk3bDSjYh1tAvLDJnCi2w jA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qsyqc8vq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 04:15:22 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34P4C0tC001651; Thu, 25 May 2023 04:15:21 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 3qsyqc8vpm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 04:15:21 +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 34P2eib0014407; Thu, 25 May 2023 04:15:19 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3qppcua8ay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 May 2023 04:15:19 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34P4FFJh19989034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 May 2023 04:15:15 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B38A20043; Thu, 25 May 2023 04:15:15 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 892FB20040; Thu, 25 May 2023 04:15:12 +0000 (GMT) Received: from [9.109.208.57] (unknown [9.109.208.57]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 25 May 2023 04:15:12 +0000 (GMT) Content-Type: multipart/alternative; boundary="------------oJctBMf0DWvu8YY8p0UFXnWx" Message-ID: <460d3d0f-3b4b-330e-87ba-d491d7c55d07@linux.vnet.ibm.com> Date: Thu, 25 May 2023 09:45:11 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v3] target: ppc: Use MSR_HVB bit to get the target endianness for memory dump To: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Narayana Murty N , danielhb413@gmail.com, david@gibson.dropbear.id.au, groug@kaod.org, npiggin@gmail.com Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, farosas@suse.de, npiggin@linux.ibm.com, vaibhav@linux.ibm.com, harshpb@linux.ibm.com, sbhat@linux.ibm.com, Greg Kurz References: <20230522160242.37261-1-nnmlinux@linux.ibm.com> Content-Language: en-US From: Narayana Murty N In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: U65ZLeRx2XlsZLfXjCowxwYRu3edSP2- X-Proofpoint-GUID: xxTrHvdxEenf2NqcyiQ0-3aJFyan2T8H 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-05-25_01,2023-05-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305250031 Received-SPF: none client-ip=148.163.158.5; envelope-from=nnmlinux@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, NICE_REPLY_A=-0.107, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 This is a multi-part message in MIME format. --------------oJctBMf0DWvu8YY8p0UFXnWx Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 5/23/23 15:52, Cédric Le Goater wrote: > On 5/22/23 18:02, Narayana Murty N wrote: >> Currently on PPC64 qemu always dumps the guest memory in >> Big Endian (BE) format even though the guest running in Little Endian > > > > The patch is surely correct. I have problems understanding the config > you are testing. PPC Book3s has multiple hypervisor implementations : > > 1. pHyp (AKA PowerVM) > 2. OPAL/PowerNV (AKA Power KVM-HV) > 3. OPAL/PowerNV/pSeries (AKA Power KVMHV-on-pSeries) > 4. pHyp/pSeries (very recent implementation, I don't know how it is >    referred to in the kernel) > > I am leaving the KVM-PR implementation out of the discussions for > simplicity. > > QEMU also supports emulation of 2. and 3. in two different machines > PowerNV and pseries, although running pseries guests under a PowerNV > machine is slow, so is running pseries guests under pseries. > > Could you please describe your environment ? > > Thanks, > > C. > > It had been tested target machine OPAL/PowerNV with big endian host os. and also target OPAL/PowerNV/pSeries little endian host setup with qemu. > >> (LE) mode. So crash tool fails to load the dump as illustrated below: >> >> Log : >> $ virsh dump DOMAIN --memory-only dump.file >> >> Domain 'DOMAIN' dumped to dump.file >> >> $ crash vmlinux dump.file >> >> >> crash 8.0.2-1.el9 >> >> WARNING: endian mismatch: >>            crash utility: little-endian >>            dump.file: big-endian >> >> WARNING: machine type mismatch: >>            crash utility: PPC64 >>            dump.file: (unknown) >> >> crash: dump.file: not a supported file format >> >> >> This happens because cpu_get_dump_info() passes cpu->env->has_hv_mode >> to function ppc_interrupts_little_endian(), the cpu->env->has_hv_mode >> always set for powerNV even though the guest is not running in hv mode. >> The hv mode should be taken from msr_mask MSR_HVB bit >> (cpu->env.msr_mask & MSR_HVB). This patch fixes the issue by passing >> MSR_HVB value to ppc_interrupts_little_endian() in order to determine >> the guest endianness. >> >> The crash tool also expects guest kernel endianness should match the >> endianness of the dump. >> >> The patch was tested on POWER9 box booted with Linux as host in >> following cases: >> >> Host-Endianess Qemu-Target-Machine Qemu-Guest-Endianess >> Qemu-Generated-Guest >> Memory-Dump-Format >> BE             powernv             LE KVM guest LE >> BE             powernv             BE KVM guest BE >> LE             powernv             LE KVM guest LE >> LE             powernv             BE KVM guest BE >> LE             pseries KVM         LE KVM guest LE >> LE             pseries TCG         LE guest LE >> >> Signed-off-by: Narayana Murty N >> --- >> Changes since V2: >> commit message modified as per feedbak from Nicholas Piggin. >> Changes since V1: >> https://lore.kernel.org/qemu-devel/20230420145055.10196-1-nnmlinux@linux.ibm.com/ >> >> The approach to solve the issue was changed based on feedback from >> Fabiano Rosas on patch V1. >> --- >>   target/ppc/arch_dump.c | 2 +- >>   1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c >> index f58e6359d5..a8315659d9 100644 >> --- a/target/ppc/arch_dump.c >> +++ b/target/ppc/arch_dump.c >> @@ -237,7 +237,7 @@ int cpu_get_dump_info(ArchDumpInfo *info, >>       info->d_machine = PPC_ELF_MACHINE; >>       info->d_class = ELFCLASS; >>   -    if (ppc_interrupts_little_endian(cpu, cpu->env.has_hv_mode)) { >> +    if (ppc_interrupts_little_endian(cpu, !!(cpu->env.msr_mask & >> MSR_HVB))) { >>           info->d_endian = ELFDATA2LSB; >>       } else { >>           info->d_endian = ELFDATA2MSB; > --------------oJctBMf0DWvu8YY8p0UFXnWx Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 5/23/23 15:52, Cédric Le Goater wrote:
On 5/22/23 18:02, Narayana Murty N wrote:
Currently on PPC64 qemu always dumps the guest memory in
Big Endian (BE) format even though the guest running in Little Endian



The patch is surely correct. I have problems understanding the config
you are testing. PPC Book3s has multiple hypervisor implementations :

1. pHyp (AKA PowerVM)
2. OPAL/PowerNV (AKA Power KVM-HV)
3. OPAL/PowerNV/pSeries (AKA Power KVMHV-on-pSeries)
4. pHyp/pSeries (very recent implementation, I don't know how it is
   referred to in the kernel)

I am leaving the KVM-PR implementation out of the discussions for
simplicity.

QEMU also supports emulation of 2. and 3. in two different machines
PowerNV and pseries, although running pseries guests under a PowerNV
machine is slow, so is running pseries guests under pseries.

Could you please describe your environment ?

Thanks,

C.


It had been tested target machine OPAL/PowerNV with big endian host os.
and also target OPAL/PowerNV/pSeries little endian host setup with qemu. 

(LE) mode. So crash tool fails to load the dump as illustrated below:

Log :
$ virsh dump DOMAIN --memory-only dump.file

Domain 'DOMAIN' dumped to dump.file

$ crash vmlinux dump.file

<snip>
crash 8.0.2-1.el9

WARNING: endian mismatch:
           crash utility: little-endian
           dump.file: big-endian

WARNING: machine type mismatch:
           crash utility: PPC64
           dump.file: (unknown)

crash: dump.file: not a supported file format
<snip>

This happens because cpu_get_dump_info() passes cpu->env->has_hv_mode
to function ppc_interrupts_little_endian(), the cpu->env->has_hv_mode
always set for powerNV even though the guest is not running in hv mode.
The hv mode should be taken from msr_mask MSR_HVB bit
(cpu->env.msr_mask & MSR_HVB). This patch fixes the issue by passing
MSR_HVB value to ppc_interrupts_little_endian() in order to determine
the guest endianness.

The crash tool also expects guest kernel endianness should match the
endianness of the dump.

The patch was tested on POWER9 box booted with Linux as host in
following cases:

Host-Endianess Qemu-Target-Machine Qemu-Guest-Endianess  Qemu-Generated-Guest
                                                           Memory-Dump-Format
BE             powernv             LE KVM guest                 LE
BE             powernv             BE KVM guest                 BE
LE             powernv             LE KVM guest                 LE
LE             powernv             BE KVM guest                 BE
LE             pseries KVM         LE KVM guest                 LE
LE             pseries TCG         LE guest                     LE

Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
Changes since V2:
commit message modified as per feedbak from Nicholas Piggin.
Changes since V1:
https://lore.kernel.org/qemu-devel/20230420145055.10196-1-nnmlinux@linux.ibm.com/
The approach to solve the issue was changed based on feedback from
Fabiano Rosas on patch V1.
---
  target/ppc/arch_dump.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c
index f58e6359d5..a8315659d9 100644
--- a/target/ppc/arch_dump.c
+++ b/target/ppc/arch_dump.c
@@ -237,7 +237,7 @@ int cpu_get_dump_info(ArchDumpInfo *info,
      info->d_machine = PPC_ELF_MACHINE;
      info->d_class = ELFCLASS;
  -    if (ppc_interrupts_little_endian(cpu, cpu->env.has_hv_mode)) {
+    if (ppc_interrupts_little_endian(cpu, !!(cpu->env.msr_mask & MSR_HVB))) {
          info->d_endian = ELFDATA2LSB;
      } else {
          info->d_endian = ELFDATA2MSB;

--------------oJctBMf0DWvu8YY8p0UFXnWx--