From patchwork Sun Apr 23 17:09:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30BAF60245 for ; Sun, 23 Apr 2017 17:13:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B0C726530 for ; Sun, 23 Apr 2017 17:13:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FC7D26538; Sun, 23 Apr 2017 17:13:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F3BA267EC for ; Sun, 23 Apr 2017 17:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757507AbdDWRM5 (ORCPT ); Sun, 23 Apr 2017 13:12:57 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:35972 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163038AbdDWRKx (ORCPT ); Sun, 23 Apr 2017 13:10:53 -0400 Received: by mail-wr0-f169.google.com with SMTP id l50so5314692wrc.3 for ; Sun, 23 Apr 2017 10:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S2O5Mq707Xa0DEHAk9RztKap/pcb0rX5ORH0/7nCX1Q=; b=hRgnowAQETH0tZAWF3JCE6e1FkqDn0Aoadw5X7YUhUWYnwhP80kpEi4VgUeLxjFv6O ISowZvNzhvz286pE0kQN4yjw8pI432RBMSM3Nz06zrIe9BtVez4JBgfRhcxM1HMnpTwv DKu5BIff+dpIdi7k1zad7LK5pG9eF84eHtIQM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S2O5Mq707Xa0DEHAk9RztKap/pcb0rX5ORH0/7nCX1Q=; b=fmr3ebu2R6dVw/jKgEQpVnKQEaKs8sYZFM4P5cbZHDlgNfnf4zXK1l1G+W2DA6oqGQ 1q1KE+Y4q/gUMotP9fiZ/invaBAV0qo0zY44PgihYiRtqb/dMaUfc3fA7ZWwMzS2k/Cd uMv9+S1OiaSdwc+UgPj1UuKdLQEHI4A1FvIAnc52GZn6C2jhqDiFaX/g3xameEBQObY3 BXq7hPqHCNTESuRxioT8nlSqrozC/FLSFlpU8gkfgVfkMakJtLrAfMOeuqCKcOC0gjzO lF5YpL/dT5FWSMJi90EKSgTZqkVjGPd4CUfytyL2nJjoPDrzyEkTgFLnXZob5wo+WtFM 5xHQ== X-Gm-Message-State: AN3rC/4DMG7HgymM9tsIHEnwdzEcCvKiMz/2Sp8Zal9d3U46XUPduGPV bSQ+L8kdHMkX8ftI X-Received: by 10.223.151.6 with SMTP id r6mr2611706wrb.189.1492967452126; Sun, 23 Apr 2017 10:10:52 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id 58sm2803521edz.2.2017.04.23.10.10.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:10:51 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jones , stable@vger.kernel.org, Christoffer Dall Subject: [PULL 75/79] KVM: arm/arm64: fix races in kvm_psci_vcpu_on Date: Sun, 23 Apr 2017 19:09:25 +0200 Message-Id: <20170423170929.27334-76-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170423170929.27334-1-cdall@linaro.org> References: <20170423170929.27334-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Jones Fix potential races in kvm_psci_vcpu_on() by taking the kvm->lock mutex. In general, it's a bad idea to allow more than one PSCI_CPU_ON to process the same target VCPU at the same time. One such problem that may arise is that one PSCI_CPU_ON could be resetting the target vcpu, which fills the entire sys_regs array with a temporary value including the MPIDR register, while another looks up the VCPU based on the MPIDR value, resulting in no target VCPU found. Resolves both races found with the kvm-unit-tests/arm/psci unit test. Reviewed-by: Marc Zyngier Reviewed-by: Christoffer Dall Reported-by: Levente Kurusa Suggested-by: Christoffer Dall Signed-off-by: Andrew Jones Cc: stable@vger.kernel.org Signed-off-by: Christoffer Dall --- arch/arm/kvm/psci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index c2b1315..a08d7a9 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -208,9 +208,10 @@ int kvm_psci_version(struct kvm_vcpu *vcpu) static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) { - int ret = 1; + struct kvm *kvm = vcpu->kvm; unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); unsigned long val; + int ret = 1; switch (psci_fn) { case PSCI_0_2_FN_PSCI_VERSION: @@ -230,7 +231,9 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) break; case PSCI_0_2_FN_CPU_ON: case PSCI_0_2_FN64_CPU_ON: + mutex_lock(&kvm->lock); val = kvm_psci_vcpu_on(vcpu); + mutex_unlock(&kvm->lock); break; case PSCI_0_2_FN_AFFINITY_INFO: case PSCI_0_2_FN64_AFFINITY_INFO: @@ -279,6 +282,7 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) { + struct kvm *kvm = vcpu->kvm; unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); unsigned long val; @@ -288,7 +292,9 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) val = PSCI_RET_SUCCESS; break; case KVM_PSCI_FN_CPU_ON: + mutex_lock(&kvm->lock); val = kvm_psci_vcpu_on(vcpu); + mutex_unlock(&kvm->lock); break; default: val = PSCI_RET_NOT_SUPPORTED;