Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2354119pxb; Mon, 20 Sep 2021 19:53:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEEnMmE8scgyhatIDUnZ16G47INMOyKLJdWE3CEbgCrpRukCwWUSM65mNHuXzen7ha1Wbb X-Received: by 2002:a17:906:c18d:: with SMTP id g13mr20832443ejz.518.1632192792801; Mon, 20 Sep 2021 19:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192792; cv=none; d=google.com; s=arc-20160816; b=p2GubMcJ7Qcz8kXylA7SHFuGGmdiNNoJELcFHLY6g1mo8Asjn9kO+s9r7e864+Iz/2 Cs4l1rMxYNchQscxbDNtaE0cFK4DyVzuEZXUEfitVcitldEFRLB9E+I4/id7TPcqmaac c02WXtE+womiBmbpshxnkPbO3s+d2qouOZrlsY/vPV2W0DWQKNetSnm2909RAc2L52se L/DYZjjosv399n8LMQrJTRH8IKjOIYmbdS9h5VB3/7PXf2cVhy4yvP5T+A8szfBqN4HB 5tKLyKNILG4PgCWhtXu3EFzfCt7SIegWOze4xcSc0r5tWoZAGWVknqx/VIue1i7miwvu aCAA== 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=3sFlZJpBDJkJUP7jsp2TST2MndF1ii9oUUBTIaASxO8=; b=kuHG+pBYtL3VvFYE9ugJH0f5r1mBK8LHtoNtwCBXQ29GM8b6ooUOg8HC6tUvZtVoCf I0YrIAo2oy4Hmi8tN/LOweueoI/TLQppzbRCKrwsIhJi+2gCIbjw/4D6Bg5AAZ8NVAQ9 j/7uCiL2hs1X3xl1WcFFui6JYl3hYJKUzTThuBLEvYxC5anwfqoX5x4ZqjnOiGU4uywP n2A3belNvz9CONLg6jfCFn6tDixiS/UbgyRMdS9ednaHuZWUeLCY7eT8i9V15ZJ8rzRW fMm1I8dSOEVEzifh5Y4qksRRsIc2iGzCbOVGmgjtdPFhg0sNn+wXFdAr73NfF/RDujfV nz3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q4AMaL8E; 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 di3si19302583ejc.728.2021.09.20.19.52.49; Mon, 20 Sep 2021 19:53:12 -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=q4AMaL8E; 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 S1386215AbhITSxy (ORCPT + 99 others); Mon, 20 Sep 2021 14:53:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:33540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385512AbhITSue (ORCPT ); Mon, 20 Sep 2021 14:50:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B98BB61B1B; Mon, 20 Sep 2021 17:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159296; bh=S9GpUT2zPaFCVHTn4TLRuJ0//T5Z664GS/xBdhStYvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q4AMaL8EVKnq5kLzxlryKtWzMt9E4MkUGsyrjfwJTp5D/3k6HoHPsx/VNc15ELcGh 5N/lOv6MUQvZNiqb6+4WD9+92R28QxxU0+UeTjF3PWeg8E/4O0IVr13r6dJjh3MsyA BZ0rxf1lAVUMDfiB8l4sFs96APkD49ZB0DBIERbc= 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.14 134/168] KVM: arm64: Handle PSCI resets before userspace touches vCPU state Date: Mon, 20 Sep 2021 18:44:32 +0200 Message-Id: <20210920163926.070528257@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 --- arch/arm64/kvm/arm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5d1fc9c4bca5..45ee8abcf202 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1220,6 +1220,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