Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5226892ybl; Tue, 27 Aug 2019 01:07:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqybO2s0VQ2gFtlZ9dnI3XlVwBKtAn9BhWZtFDtSNj7GlLScbA0pBF0E7Wwa7Kfn2AGExBtg X-Received: by 2002:a62:8281:: with SMTP id w123mr24524215pfd.36.1566893275803; Tue, 27 Aug 2019 01:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893275; cv=none; d=google.com; s=arc-20160816; b=CzMc/Kxs30IcEHFESRHXlbz1/3eiSNX6JlfXhKm4ZURxxxd8Kg9pFT4WdTB7NXGgON DEUDbQrF2dachsB04ZCAOnhWosjNwTqU3f1Ku9TqNOzSuLwcxuQaQ9frWIeOd/Gs9iix kb1CA6tA6nVj+uWmFUMMqxWqyoO7VCXfFLiKpqZhA52+AZ0J3b8Hf21fPACBALLGcG2O sOfkNjpH6rlglS58LBqwDCVmDsmC4eIMFD9N31acgFj5UFp/7BpISzr8lF66Ei1Nlalx P7+olXO0vZBwaZdBUwUNo/ufm+er22IiQIqhDkNpYVvGdr59b78tMQXLwfcxxZB3niPl yazQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=siXS7niENrCVM5Y0Es8kdE4XMYio67FiLmbozwaLV1c=; b=f70pDt8lybEWvIH0MyxbT+B5hnexAToRuEknB79PC5q7zuKAT3px0GSZZOgM57IBR7 p23N+tnBImRuGx5KX6Y78mQDLy8Tt/P65zU4Dc8Sh1xlbxotfkei9kDWvZMVHY930VyS 0sdJMsI58ZbG/V8224FF4LgS6WP1I5KR+agp4xIJEGHMvQz62CrXeujXnhsGpFsuSChB pDG1m8pWjpJ5JUuNfqRUib/fG60W+Wxg8PzssKi6SPEQLd1jn+tzzhA/6b00pqIlkj9l ZoK37wWL4lE4oTpcbm4UvkCXJ2X2QkLB9iKB2R/uyTtMlZt93JiD+Fw0wbys+/4FO4DT kmsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ABTJCpOk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si1780066pjr.62.2019.08.27.01.07.40; Tue, 27 Aug 2019 01:07:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ABTJCpOk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732331AbfH0IGa (ORCPT + 99 others); Tue, 27 Aug 2019 04:06:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:36486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731822AbfH0IG1 (ORCPT ); Tue, 27 Aug 2019 04:06:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4DBFF2189D; Tue, 27 Aug 2019 08:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893186; bh=kkWKgMSn2++kQcHs6rrtBwWij9MF5eoi/UPReTyw1to=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ABTJCpOk0mdQTF/1rY+UgDc40bZdM435E1oneynAmfY1OEx6DH3QXL6FCnjsgRu2l tqpWNi3SwyY1ldsv+31YkiSuVO76dBuEeF6tgm3TyJfoZslw6bI39eX8KzhyRR7qQ7 GoDZCGsqIEiLvAOLrwqvBo6XDdscIcN63zPU52rk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Zyngier , Sasha Levin Subject: [PATCH 5.2 108/162] KVM: arm: Dont write junk to CP15 registers on reset Date: Tue, 27 Aug 2019 09:50:36 +0200 Message-Id: <20190827072742.092102786@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit c69509c70aa45a8c4954c88c629a64acf4ee4a36 ] At the moment, the way we reset CP15 registers is mildly insane: We write junk to them, call the reset functions, and then check that we have something else in them. The "fun" thing is that this can happen while the guest is running (PSCI, for example). If anything in KVM has to evaluate the state of a CP15 register while junk is in there, bad thing may happen. Let's stop doing that. Instead, we track that we have called a reset function for that register, and assume that the reset function has done something. In the end, the very need of this reset check is pretty dubious, as it doesn't check everything (a lot of the CP15 reg leave outside of the cp15_regs[] array). It may well be axed in the near future. Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin --- arch/arm/kvm/coproc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index d2806bcff8bbb..07745ee022a12 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -651,13 +651,22 @@ int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) } static void reset_coproc_regs(struct kvm_vcpu *vcpu, - const struct coproc_reg *table, size_t num) + const struct coproc_reg *table, size_t num, + unsigned long *bmap) { unsigned long i; for (i = 0; i < num; i++) - if (table[i].reset) + if (table[i].reset) { + int reg = table[i].reg; + table[i].reset(vcpu, &table[i]); + if (reg > 0 && reg < NR_CP15_REGS) { + set_bit(reg, bmap); + if (table[i].is_64bit) + set_bit(reg + 1, bmap); + } + } } static struct coproc_params decode_32bit_hsr(struct kvm_vcpu *vcpu) @@ -1432,17 +1441,15 @@ void kvm_reset_coprocs(struct kvm_vcpu *vcpu) { size_t num; const struct coproc_reg *table; - - /* Catch someone adding a register without putting in reset entry. */ - memset(vcpu->arch.ctxt.cp15, 0x42, sizeof(vcpu->arch.ctxt.cp15)); + DECLARE_BITMAP(bmap, NR_CP15_REGS) = { 0, }; /* Generic chip reset first (so target could override). */ - reset_coproc_regs(vcpu, cp15_regs, ARRAY_SIZE(cp15_regs)); + reset_coproc_regs(vcpu, cp15_regs, ARRAY_SIZE(cp15_regs), bmap); table = get_target_table(vcpu->arch.target, &num); - reset_coproc_regs(vcpu, table, num); + reset_coproc_regs(vcpu, table, num, bmap); for (num = 1; num < NR_CP15_REGS; num++) - WARN(vcpu_cp15(vcpu, num) == 0x42424242, + WARN(!test_bit(num, bmap), "Didn't reset vcpu_cp15(vcpu, %zi)", num); } -- 2.20.1