Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2486933imm; Mon, 24 Sep 2018 05:19:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV63YmzQ+oRz6whHqiogSmHAHVuqu+2fgl8od2tPf4xdU2QsK/uNVeKwiBFEhsB18rxdcX8+I X-Received: by 2002:a65:4242:: with SMTP id d2-v6mr8386672pgq.265.1537791581010; Mon, 24 Sep 2018 05:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537791580; cv=none; d=google.com; s=arc-20160816; b=g7vng0aPruYw8L64916VpZP/yjcYB9FHVqk4CN9zaxCvH675wQtqsiF+IcTblFaN/u zCncFG80QDsn6zLy6zMmH30xHaXpfmwXXu15MV+F/y4JG1hE/aIdMD6XUkO4QXQQwUYM EFN94PdU07QvFV5mSHq6c+jHCfPTRg9DH/D1tCNzhjCb5Z0FTRx6WxduIZuU+IU/dwHg eUPRWafr7q4Ttm5oypJtufold41LRof2pZGtGXqb7dIpjyyXlfk9ziFKDmYSaIfTxmoi Pg7BJ5t4jqYqsD318H3UGZx3vUNXIiAt1gM68Ik3s9xpHJkyxtWICtVZRsxfKBjMIJdg Uw2Q== 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; bh=mLvF7D1LinzMuEgOedZvrnAtlBjw98qLmtl1XWK0ZAg=; b=AlsewuXqssS16IOptbO6TU/RXkvu4WFZulpi/xifToQo2Hfs1ecHVrxN2CUcrrfJPh xIybx/RRt2S8w7nHRh6ks8DP8CJpk8jUSf8Brv6qEtHMt/W7mNUf0q4BdY7fvgvYqwtv 1UbVSGMLjQZbv/yhi0NpxWMY1GsQu5sw8bEpC/r+KXE6DoUJE8cwAte7447dNcwHjETC O5Q4V7xf/BNA64dTyRgr65pntFb0suCJKt/4ZcI4XEuIICFGOY163kjfvvQtSFaLCCgr ZK4diO4R/te2Ez0xS3bTUn7piqSvRZzud/RfclWUmFPh5ABmSehsaEC8Nz/piJyAWwwN 8hqw== ARC-Authentication-Results: i=1; mx.google.com; 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 h6-v6si32473272pls.150.2018.09.24.05.19.25; Mon, 24 Sep 2018 05:19:40 -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; 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 S1732575AbeIXSUP (ORCPT + 99 others); Mon, 24 Sep 2018 14:20:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56102 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730063AbeIXSUP (ORCPT ); Mon, 24 Sep 2018 14:20:15 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BBE011087; Mon, 24 Sep 2018 12:18:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Auger , Christoffer Dall , Marc Zyngier , Sasha Levin Subject: [PATCH 4.14 066/173] KVM: arm/arm64: Fix vgic init race Date: Mon, 24 Sep 2018 13:51:40 +0200 Message-Id: <20180924113120.872436151@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113114.334025954@linuxfoundation.org> References: <20180924113114.334025954@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christoffer Dall [ Upstream commit 1d47191de7e15900f8fbfe7cccd7c6e1c2d7c31a ] The vgic_init function can race with kvm_arch_vcpu_create() which does not hold kvm_lock() and we therefore have no synchronization primitives to ensure we're doing the right thing. As the user is trying to initialize or run the VM while at the same time creating more VCPUs, we just have to refuse to initialize the VGIC in this case rather than silently failing with a broken VCPU. Reviewed-by: Eric Auger Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/vgic/vgic-init.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -277,6 +277,10 @@ int vgic_init(struct kvm *kvm) if (vgic_initialized(kvm)) return 0; + /* Are we also in the middle of creating a VCPU? */ + if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus)) + return -EBUSY; + /* freeze the number of spis */ if (!dist->nr_spis) dist->nr_spis = VGIC_NR_IRQS_LEGACY - VGIC_NR_PRIVATE_IRQS;