From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bl2nam02on0107.outbound.protection.outlook.com ([104.47.38.107]:21664 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754436AbeDIAVS (ORCPT ); Sun, 8 Apr 2018 20:21:18 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Paul Mackerras , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 174/189] KVM: PPC: Book3S HV: Fix handling of secondary HPTEG in HPT resizing code Date: Mon, 9 Apr 2018 00:19:06 +0000 Message-ID: <20180409001637.162453-174-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Paul Mackerras [ Upstream commit 05f2bb0313a2855e491dadfc8319b7da261d7074 ] This fixes the computation of the HPTE index to use when the HPT resizing code encounters a bolted HPTE which is stored in its secondary HPTE group. The code inverts the HPTE group number, which is correct, but doesn't then mask it with new_hash_mask. As a result, new_pteg will be effectively negative, resulting in new_hptep pointing before the new HPT, which will corrupt memory. In addition, this removes two BUG_ON statements. The condition that the BUG_ONs were testing -- that we have computed the hash value incorrectly -- has never been observed in testing, and if it did occur, would only affect the guest, not the host. Given that BUG_ON should only be used in conditions where the kernel (i.e. the host kernel, in this case) can't possibly continue execution, it is not appropriate here. Reviewed-by: David Gibson Signed-off-by: Paul Mackerras Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_= 64_mmu_hv.c index b73dbc9e797d..dc0f2ade589e 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -1337,12 +1337,8 @@ static unsigned long resize_hpt_rehash_hpte(struct k= vm_resize_hpt *resize, } =20 new_pteg =3D hash & new_hash_mask; - if (vpte & HPTE_V_SECONDARY) { - BUG_ON(~pteg !=3D (hash & old_hash_mask)); - new_pteg =3D ~new_pteg; - } else { - BUG_ON(pteg !=3D (hash & old_hash_mask)); - } + if (vpte & HPTE_V_SECONDARY) + new_pteg =3D ~hash & new_hash_mask; =20 new_idx =3D new_pteg * HPTES_PER_GROUP + (idx % HPTES_PER_GROUP); new_hptep =3D (__be64 *)(new->virt + (new_idx << 4)); --=20 2.15.1