From patchwork Mon Feb 5 18:18:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Machhiwal X-Patchwork-Id: 196975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1056529dyb; Mon, 5 Feb 2024 10:19:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRgHQOhegHquCFTsB0eeLxgDg43h2VJbIA3DZ8rE4AJEw+kYMJTbjMxtSzF3Gue4A54Ro+ X-Received: by 2002:a17:902:e545:b0:1d8:fcac:eff0 with SMTP id n5-20020a170902e54500b001d8fcaceff0mr433144plf.9.1707157175967; Mon, 05 Feb 2024 10:19:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707157175; cv=pass; d=google.com; s=arc-20160816; b=DIAzr8HAiflhmuymL8VZTT3nR0fN73D2s8NyLQ2tF9GcXnHnKn2s6YO0FO0AHqHT29 cyeow39nzrU8462cHNKrRldK99oQ5imHlr0N8T3DM97s/RILpFVwL4WP7SEfM5wSyPI5 kgL4sKvwn+G/E91lxXxdtTd1vRYYM/TaJ3YyLCanrOQEGKELusE3yFUHqoWZhC4HhReH jlanV5Ms3XE3NBKR+e/sgRX/nf8Gv5lHivgj94uJ7Eb0WlGhq7ZLEdfG6fM5wmkl+H0z Q7o9sZAzff4v6PVsQKbu8+/k+kv7cOsFSF3PFn0HL084oqCkbUQwURsOm2Dts2MmIe2N LoCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:message-id:date:subject:cc:to:from :dkim-signature; bh=7FZq3UKocrSdIKqb/HIHHIxnBLE3eJesaiVq6qENOmQ=; fh=xJupZl/ozwgKCwoNF/LNfTvUeSf8HkfgzyLd410EgEM=; b=CPnVadjk7/2SwcXvlWrRJBFPpObqC95l2X5gU6cej+R1xfxMhzYk5PjpPgRZx5x0ym /Hav6sD2kEOGbtGzHNqv47/LdWHjD7RWwMqRhun7jwB136oPHCLfSiCrlyew/oK06lNl qL2VHgVmwTWdeMzeI4EgsHZUp93Gu+h/0jwE7y6GB7j5sLmFkUnJxkAK2oSy/gDSMKXF rbNv6Nxl+EgfQ7tsGqt/aGveLMHvm1VeowuHCbFw72fH7VXC/ojAEkuJ+owbmtzJU09g 92VlZdcETEfCeXlPwFRKgelxPtbUN2cbsdMcsej159j1NbkU6++HVWD7TSeBw+UchCN8 ANzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=aK9AHZlL; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-53197-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53197-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com X-Forwarded-Encrypted: i=1; AJvYcCVHcmFAq5EC1E/56gMyiFKmVqwa071zpGY7HX8RCxYjuQP2LOb4JY1HVw81I3LB0wBz+GZLI9ElIua4cp1rZHs2rCArQg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h17-20020a170902f2d100b001d9481c14a9si185517plc.567.2024.02.05.10.19.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:19:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53197-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=aK9AHZlL; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-53197-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53197-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2225C2859F9 for ; Mon, 5 Feb 2024 18:19:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A833B482C9; Mon, 5 Feb 2024 18:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="aK9AHZlL" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17E1A45974; Mon, 5 Feb 2024 18:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707157141; cv=none; b=peh+cBX0hqc3G53C+JgRhZhElxXV0Ix5RYNNc7g/osQw6VmaT6ZlOsDKH2DX0Vg9pwwdaDvrYbpKs8WkOTgwfPFiDytZT/ru55WyWK06np+hiYGehlSlNj97/QMPizOaFS1CB0A0s3NOEddoHl2i0vpFUTWHqHxoBmTfk6MSoJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707157141; c=relaxed/simple; bh=hBYrC30RdNRdKCfKA9EFp1rJ5kkeCllFZfWAQ3T5zvw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dxMMUo1ooqCO9JbGLy2lODQV9POfF3QmuVLCXA/jLQ8/UvOH3ysfeGyrxU4Va2hzf1f/jNJG9wc92jIv3U/vKvty8w2UOz2TAQobCtTe9DSdlSjboOdy4yjETs/bFXlnkDQSU4ZXxYsY5R2v6l0ORHFHtbl/24xWNXrV+8xrVBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=aK9AHZlL; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 415IITo4006991; Mon, 5 Feb 2024 18:18:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=7FZq3UKocrSdIKqb/HIHHIxnBLE3eJesaiVq6qENOmQ=; b=aK9AHZlL3h7U9VYkkszgSpiR6I8EO3Gge0GeM77H5VE0xLd2IEqo6+2l67HeKFodGiMJ oFWfZ943782f+zc9xvzITQyTunw+P5XZZ2ak+U7ME6K7eTNL8Sz6vXGZ6ONWh2id7Yag ZF8Zp4IuuNkcBUGsIaKsD11vXppcKM7t3iN9pj2a0jPplD5TemFOz3jR15BnMb34Ht0C N14D/WQ32ecMdQZc2ASdGWoeqaqKAO6W7diWMGc3l60UjsFimaLZLCxmccbaJJIe94O5 YU0HSTmWjru68A6N4XAiWuqERAgKxzQIAA0CKtvvzbcMJwvAg2bLRNCy7jaSWrmbiMuD Ww== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w34u50075-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Feb 2024 18:18:46 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 415IIZwB007304; Mon, 5 Feb 2024 18:18:46 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w34u5006u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Feb 2024 18:18:46 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 415GekxN014865; Mon, 5 Feb 2024 18:18:45 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w20tnj4vf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Feb 2024 18:18:45 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 415IIgo140239522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Feb 2024 18:18:42 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 557B220040; Mon, 5 Feb 2024 18:18:42 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 436BE20043; Mon, 5 Feb 2024 18:18:39 +0000 (GMT) Received: from li-a83676cc-350e-11b2-a85c-e11f86bb8d73.ibm.com.com (unknown [9.43.55.162]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 5 Feb 2024 18:18:39 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: Vaibhav Jain , Nicholas Piggin , Michael Ellerman , Jordan Niethe , Vaidyanathan Srinivasan , "Aneesh Kumar K . V" , "Naveen N . Rao" , Christophe Leroy , Amit Machhiwal , linux-kernel@vger.kernel.org Subject: [PATCH v3] KVM: PPC: Book3S HV: Fix L2 guest reboot failure due to empty 'arch_compat' Date: Mon, 5 Feb 2024 23:48:33 +0530 Message-ID: <20240205181833.212955-1-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.43.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CYr3oYuRF9ndfHDrfIlv9Y5hzJStxe98 X-Proofpoint-ORIG-GUID: 6VBeCFRo2XRuVcwoMmETR36z-NQiZAa7 X-Proofpoint-UnRewURL: 0 URL was un-rewritten Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-05_12,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxlogscore=894 priorityscore=1501 spamscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402050138 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790065663359609702 X-GMAIL-MSGID: 1790084042787729284 Currently, rebooting a pseries nested qemu-kvm guest (L2) results in below error as L1 qemu sends PVR value 'arch_compat' == 0 via ppc_set_compat ioctl. This triggers a condition failure in kvmppc_set_arch_compat() resulting in an EINVAL. qemu-system-ppc64: Unable to set CPU compatibility mode in KVM: Invalid argument Also, a value of 0 for arch_compat generally refers the default compatibility of the host. But, arch_compat, being a Guest Wide Element in nested API v2, cannot be set to 0 in GSB as PowerVM (L0) expects a non-zero value. A value of 0 triggers a kernel trap during a reboot and consequently causes it to fail: [ 22.106360] reboot: Restarting system KVM: unknown exit, hardware reason ffffffffffffffea NIP 0000000000000100 LR 000000000000fe44 CTR 0000000000000000 XER 0000000020040092 CPU#0 MSR 0000000000001000 HID0 0000000000000000 HF 6c000000 iidx 3 didx 3 TB 00000000 00000000 DECR 0 GPR00 0000000000000000 0000000000000000 c000000002a8c300 000000007fe00000 GPR04 0000000000000000 0000000000000000 0000000000001002 8000000002803033 GPR08 000000000a000000 0000000000000000 0000000000000004 000000002fff0000 GPR12 0000000000000000 c000000002e10000 0000000105639200 0000000000000004 GPR16 0000000000000000 000000010563a090 0000000000000000 0000000000000000 GPR20 0000000105639e20 00000001056399c8 00007fffe54abab0 0000000105639288 GPR24 0000000000000000 0000000000000001 0000000000000001 0000000000000000 GPR28 0000000000000000 0000000000000000 c000000002b30840 0000000000000000 CR 00000000 [ - - - - - - - - ] RES 000@ffffffffffffffff SRR0 0000000000000000 SRR1 0000000000000000 PVR 0000000000800200 VRSAVE 0000000000000000 SPRG0 0000000000000000 SPRG1 0000000000000000 SPRG2 0000000000000000 SPRG3 0000000000000000 SPRG4 0000000000000000 SPRG5 0000000000000000 SPRG6 0000000000000000 SPRG7 0000000000000000 HSRR0 0000000000000000 HSRR1 0000000000000000 CFAR 0000000000000000 LPCR 0000000000020400 PTCR 0000000000000000 DAR 0000000000000000 DSISR 0000000000000000 kernel:trap=0xffffffea | pc=0x100 | msr=0x1000 This patch updates kvmppc_set_arch_compat() to use the host PVR value if 'compat_pvr' == 0 indicating that qemu doesn't want to enforce any specific PVR compat mode. Fixes: 19d31c5f1157 ("KVM: PPC: Add support for nestedv2 guests") Reviewed-by: Aneesh Kumar K.V (IBM) Reviewed-by: Vaibhav Jain Signed-off-by: Amit Machhiwal --- Changes v2 -> v3: - Vaibhav: Use a 'break' instead of switch-case fallthrough - v2: https://lore.kernel.org/all/20240205132607.2776637-1-amachhiw@linux.ibm.com/ Changes v1 -> v2: - Added descriptive error log in the patch description when `arch_compat == 0` passed in GSB - Added a helper function for PCR to capabilities mapping - Added relevant comments around the changes being made - v1: https://lore.kernel.org/lkml/20240118095653.2588129-1-amachhiw@linux.ibm.com/ arch/powerpc/kvm/book3s_hv.c | 26 ++++++++++++++++++++++++-- arch/powerpc/kvm/book3s_hv_nestedv2.c | 23 +++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) base-commit: 6764c317b6bb91bd806ef79adf6d9c0e428b191e diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 52427fc2a33f..0b921704da45 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -391,6 +391,24 @@ static void kvmppc_set_pvr_hv(struct kvm_vcpu *vcpu, u32 pvr) /* Dummy value used in computing PCR value below */ #define PCR_ARCH_31 (PCR_ARCH_300 << 1) +static inline unsigned long map_pcr_to_cap(unsigned long pcr) +{ + unsigned long cap = 0; + + switch (pcr) { + case PCR_ARCH_300: + cap = H_GUEST_CAP_POWER9; + break; + case PCR_ARCH_31: + cap = H_GUEST_CAP_POWER10; + break; + default: + break; + } + + return cap; +} + static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) { unsigned long host_pcr_bit = 0, guest_pcr_bit = 0, cap = 0; @@ -424,11 +442,9 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) break; case PVR_ARCH_300: guest_pcr_bit = PCR_ARCH_300; - cap = H_GUEST_CAP_POWER9; break; case PVR_ARCH_31: guest_pcr_bit = PCR_ARCH_31; - cap = H_GUEST_CAP_POWER10; break; default: return -EINVAL; @@ -440,6 +456,12 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) return -EINVAL; if (kvmhv_on_pseries() && kvmhv_is_nestedv2()) { + /* + * 'arch_compat == 0' would mean the guest should default to + * L1's compatibility. In this case, the guest would pick + * host's PCR and evaluate the corresponding capabilities. + */ + cap = map_pcr_to_cap(guest_pcr_bit); if (!(cap & nested_capabilities)) return -EINVAL; } diff --git a/arch/powerpc/kvm/book3s_hv_nestedv2.c b/arch/powerpc/kvm/book3s_hv_nestedv2.c index 5378eb40b162..6042bdc70230 100644 --- a/arch/powerpc/kvm/book3s_hv_nestedv2.c +++ b/arch/powerpc/kvm/book3s_hv_nestedv2.c @@ -138,6 +138,7 @@ static int gs_msg_ops_vcpu_fill_info(struct kvmppc_gs_buff *gsb, vector128 v; int rc, i; u16 iden; + u32 arch_compat = 0; vcpu = gsm->data; @@ -347,8 +348,26 @@ static int gs_msg_ops_vcpu_fill_info(struct kvmppc_gs_buff *gsb, break; } case KVMPPC_GSID_LOGICAL_PVR: - rc = kvmppc_gse_put_u32(gsb, iden, - vcpu->arch.vcore->arch_compat); + /* + * Though 'arch_compat == 0' would mean the default + * compatibility, arch_compat, being a Guest Wide + * Element, cannot be filled with a value of 0 in GSB + * as this would result into a kernel trap. + * Hence, when `arch_compat == 0`, arch_compat should + * default to L1's PVR. + * + * Rework this when PowerVM supports a value of 0 + * for arch_compat for KVM API v2. + */ + if (!vcpu->arch.vcore->arch_compat) { + if (cpu_has_feature(CPU_FTR_ARCH_31)) + arch_compat = PVR_ARCH_31; + else if (cpu_has_feature(CPU_FTR_ARCH_300)) + arch_compat = PVR_ARCH_300; + } else { + arch_compat = vcpu->arch.vcore->arch_compat; + } + rc = kvmppc_gse_put_u32(gsb, iden, arch_compat); break; }