Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2346708pxb; Mon, 20 Sep 2021 19:37:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpZMyNhW/9N6lw8z87HRL7QmcpfLMTSulolm+H1wDBmWkcn+2+xsEHnXmh6nwoyw7gewlC X-Received: by 2002:a92:cb11:: with SMTP id s17mr20250226ilo.90.1632191830321; Mon, 20 Sep 2021 19:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632191830; cv=none; d=google.com; s=arc-20160816; b=Sr/CO4/LRkQ1NsqzKChThfEL77yLzkeqUfRvt7HMhyhrD07wefFqeDQ+PSd+0ff3PP O7GQmuvbQKiIXVaChsil5kWQau7UvlLrLGy+rti70HlvPqxswtBMlHHrS/un2+Lrr/yK ZsXbhe/k+K9N/WKECqYI5focuGeJgjfFdbTnpX788L/wfzs7azb9Jw4OmKb+36RXXWLo RPnq4OCxOPhM2a2YgUTjHutbpld+LfAZDJcbaiI1a74VYWRajDh8iyKBaRlBaEJrp785 PxEykFL/ouCoaKj/Cjrg1EwcVsl1l45FVHYnPuEkuCrcemtD7slaxY9kQ6tKYUf5AATy +m3A== 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=KqTbyZkB6nqCJRrw43fgzxK+xCIcL/TqxgvScxWijfY=; b=pkhy44KiaCURy987Oh6nUOei0jweUNLbRRikLXWWqurrhyRBMqZMmZfs6Ph7n01OUv ygS1JAhtzzDVGXSCXJQVrUCMKyOnmQIV8UF8NyPsKzIiN0Zu3s6Xw1L0iDtW+MSOqayF qkkS4GHcalWj5mRfHs/4Epzi27XScByGFq1srOEdZZwMpv+JcioIoeynFXOP7PaWucb8 T01FnVdIEmDjyBSQkHm3CZO+wHX68fjSirR26fpM0Mo9fGq9lPvcMtvZ6NoIMQfGUCij JwlmWsPlGK0CPmDaFvA4FyrA6lu4rQdPt1541GjnDmfzHYvXGXuCPviEUrSgVjArx9D6 6MZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RkRR9fbW; 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 g1si14023041jab.92.2021.09.20.19.36.58; Mon, 20 Sep 2021 19:37:10 -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=RkRR9fbW; 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 S1357671AbhITSEm (ORCPT + 99 others); Mon, 20 Sep 2021 14:04:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:56862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356126AbhITR6n (ORCPT ); Mon, 20 Sep 2021 13:58:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 53B2A613A8; Mon, 20 Sep 2021 17:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158110; bh=8VccMSGAKrpiOrRmvxOgbr6P40fQhoiDZOYGcWLJ8q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RkRR9fbWCmlALfP382F4s8VUAjX/5n4NH8lJQNPgoKRANPYJkMar2DN0Rd+0PxZKB BJxk4/rAh8GoDNWKPS4NaRe5iac2S4gSEyuuJ04zdsLqoTVeL/URBkYOR6cjgI2F4k jjPwLoUQcnCxNrrYRK1coqhfuQxKznEhwUIfTYhg= 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 4.19 284/293] KVM: arm64: Handle PSCI resets before userspace touches vCPU state Date: Mon, 20 Sep 2021 18:44:06 +0200 Message-Id: <20210920163943.145411627@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 39706799ecdf..b943ec5345cb 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1137,6 +1137,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