Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2351360pxb; Mon, 20 Sep 2021 19:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuvzBndWKFmXc46T3VDmYzoKymac9U1elVLbX9VWtkjU8B6NBG/4msqL7pPAh+JFoa4rCH X-Received: by 2002:a17:906:7217:: with SMTP id m23mr31822480ejk.466.1632192440683; Mon, 20 Sep 2021 19:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192440; cv=none; d=google.com; s=arc-20160816; b=rs5Jl7mLcyIHjGLoj2Yk6wyvaMhoBmyeLiKY8hjvwbMk8W4Ldb7Pw064eAelhKUvDx t9+L52YzWCKpXItC3MtQIwIizpNFvnIuzdTnwgAcL+SISqr+dwImiTeCMDoDHy3aEoEy t0NPb6VziqfvOvSU1DAPckMNpv7iyotzCiK3iXiEQ6RByYk+9I/o2uN16RMVxrRWbEZ6 SIGfTuA2kiaxkC0Q6Hkkwm8HluExfQDG1JxpSXAM2s6xdI8jZ9Y4PGpDH+fYorWef/Iq YYsd9f5thc5IDOL9eQbw9sjlWDkoaFy+zQHRly7ByKKpilIo2sKgWoMhpoVXGWovWQvo vvrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BnufWTFloF3K8dYcj/XiwOxLuxgfrOBQ/PekP4qQw7Q=; b=twdsgUJuJlROlKegeQ8J+I3XWLdI2ZJZ1xChgtA6nE9R8P4jREBm6cKzcVt3EkQ2bK jt5E+zPXrY0usHPx79/3RkGQxZ0TK9ebdwg5ebJ6Ro4HWuRgis7Y35NrAJsUaNW2akai goRu//FzeHP1+KXr/t4kf8pUiF3XLOU59fsr243v6xZ5EpTa9cYTYs/KDrVbJe0LmE4s Sc7leWFCpsZb92Gz0yikzst/IaicFJq37EfEjduOmx0UP2So1V4lod12xdam24L3dVAx cK7Ua1uKYl+sxrlSFAOS+DZAV4PuRghpXNa8rEFoPGx8DoJ6TYmPujP1OgFaKPEEtL8z HavA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ym6chfVT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si25876037edj.282.2021.09.20.19.46.56; Mon, 20 Sep 2021 19:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ym6chfVT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348548AbhITS23 (ORCPT + 99 others); Mon, 20 Sep 2021 14:28:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:44380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377967AbhITSWR (ORCPT ); Mon, 20 Sep 2021 14:22:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED402613D3; Mon, 20 Sep 2021 17:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158643; bh=66r49HTNwkwE+JMJG+EQWMjUJv8oQQa5yygb5WMrK88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ym6chfVT1Ssk1n4Z7he4PlGnAvXL894JSxXFS6hYkrZ4qP/ivwnmVJm88frfGxfiL P4MOlG7Hq5V0qBPYK9QsXuBjx8vEAYVoqqTsn8PNXztF7Ec/EHCIhhUaN+wmsG3Ykz Pzyx6wj7XXJj12tEW3kaBYeaQXnd8uAUY9s32KlA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Upton , Marc Zyngier , Sasha Levin Subject: [PATCH 5.4 250/260] KVM: arm64: Handle PSCI resets before userspace touches vCPU state Date: Mon, 20 Sep 2021 18:44:28 +0200 Message-Id: <20210920163939.606845863@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Upton [ Upstream commit 6826c6849b46aaa91300201213701eb861af4ba0 ] The CPU_ON PSCI call takes a payload that KVM uses to configure a destination vCPU to run. This payload is non-architectural state and not exposed through any existing UAPI. Effectively, we have a race between CPU_ON and userspace saving/restoring a guest: if the target vCPU isn't ran again before the VMM saves its state, the requested PC and context ID are lost. When restored, the target vCPU will be runnable and start executing at its old PC. We can avoid this race by making sure the reset payload is serviced before userspace can access a vCPU's state. Fixes: 358b28f09f0a ("arm/arm64: KVM: Allow a VCPU to fully reset itself") Signed-off-by: Oliver Upton Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20210818202133.1106786-3-oupton@google.com Signed-off-by: Sasha Levin --- virt/kvm/arm/arm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 4af85605730e..f7150fbeeb55 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1141,6 +1141,14 @@ long kvm_arch_vcpu_ioctl(struct file *filp, if (copy_from_user(®, argp, sizeof(reg))) break; + /* + * We could owe a reset due to PSCI. Handle the pending reset + * here to ensure userspace register accesses are ordered after + * the reset. + */ + if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu)) + kvm_reset_vcpu(vcpu); + if (ioctl == KVM_SET_ONE_REG) r = kvm_arm_set_reg(vcpu, ®); else -- 2.30.2