Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10784336imu; Thu, 6 Dec 2018 06:46:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/UzfnHRUf9Q8uHwK8YZVaj5t9vqcUAwZXL8NKOORRLfZ7vxC7pvtFDPrw+Hn1156QL6x5ym X-Received: by 2002:a62:99dd:: with SMTP id t90mr23915190pfk.179.1544107616060; Thu, 06 Dec 2018 06:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107616; cv=none; d=google.com; s=arc-20160816; b=vxbrOQpZ52g/CU4OmAWG95wiMt9i1MveSUotehgGUhJJxgiXNg9W1DLnrUozPq+2BU 8TRZgdeWoVyBcSqz78RchezaNcvcnxd4+PBkRC8Sf6e3droWjNxJKVijr2ZpvfHXc5Hf caWET1DaAGccYnhq/RCXcZozp4YYbtjkVL4MjsEw+xAyLsjoOcB8SmQHR4o1Qbt4fA9f k96Ooh9AJy4ulKFNlAz/p6M1S0jCP7laWCCso36jA+yKAEoWN67uA2hZBQDY1ui57Mm4 f2tFbRpjtSAW17xN9R04DlYcDpHIZqrgXfqq8k6Kt9K17z7dmMGq5EUQd42SCfwAVD5b L3gw== 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:dkim-signature; bh=jZNhvgYn3U5r7Cjb6abbglYEEC030rHfu2b9DEfi1uU=; b=tuy+YBfDY8jJqi3I2RhSRg1EVk5s72g9LANSDptXSrGU85waz1opmimfhXz0ZKZqkJ NklIIDVGwp/wMda7syiLbUVylV5J93CNL8Td3f4C94j7mDPDNydzYah/0MdpKXLWqXSk nDGeh3q0/YgtII6SHc0ebmLmazWo05q5XgLjKDrDrQOVBXHCl8WSGhw5H5R8PplAL3cy 013teZ/nJpbtost609mdSE4vSbl+5UGFKRJNNF78lLVpgfomEAFVIrm7S+TcE6jYbABO qpHTzoeN0jY/dZA26+D+ivRUAyEelrnQxOQCkQDCL+mrERLRR/tRlQWm60siO/1MruLT PHeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iLoKTRk6; 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 j39si403236plb.272.2018.12.06.06.46.39; Thu, 06 Dec 2018 06:46:56 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=iLoKTRk6; 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 S1730963AbeLFOo4 (ORCPT + 99 others); Thu, 6 Dec 2018 09:44:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:49584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730949AbeLFOox (ORCPT ); Thu, 6 Dec 2018 09:44:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CFC2320661; Thu, 6 Dec 2018 14:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107492; bh=wFIyoeo1yQjY9hwlQVawILnGx4pvORLLHasgQ+/zi8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iLoKTRk6gfTr4P2e9BJnwQkD4JzgSJysYLXZn/49Qwi5P2kY669aN4+wj3eVZOuDI dyIayu3DZ02O2aa/qJLn3XiuMXrBeNVW0n5jiKr6Q3rXsj8tQqF8Da0gtAC7X2+0HY czRo+ZBGm2f4EoF/5Td6PojvFZZ7qKUI9hhWyWp4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Wang , Amadeusz Juskowiak , Julian Stecklina , Suravee Suthikulpanit , Joerg Roedel , Paolo Bonzini Subject: [PATCH 4.9 026/101] svm: Add mutex_lock to protect apic_access_page_done on AMD systems Date: Thu, 6 Dec 2018 15:38:25 +0100 Message-Id: <20181206143013.086132381@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Wang commit 30510387a5e45bfcf8190e03ec7aa15b295828e2 upstream. There is a race condition when accessing kvm->arch.apic_access_page_done. Due to it, x86_set_memory_region will fail when creating the second vcpu for a svm guest. Add a mutex_lock to serialize the accesses to apic_access_page_done. This lock is also used by vmx for the same purpose. Signed-off-by: Wei Wang Signed-off-by: Amadeusz Juskowiak Signed-off-by: Julian Stecklina Signed-off-by: Suravee Suthikulpanit Reviewed-by: Joerg Roedel Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1333,20 +1333,23 @@ static u64 *avic_get_physical_id_entry(s static int avic_init_access_page(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; - int ret; + int ret = 0; + mutex_lock(&kvm->slots_lock); if (kvm->arch.apic_access_page_done) - return 0; + goto out; - ret = x86_set_memory_region(kvm, - APIC_ACCESS_PAGE_PRIVATE_MEMSLOT, - APIC_DEFAULT_PHYS_BASE, - PAGE_SIZE); + ret = __x86_set_memory_region(kvm, + APIC_ACCESS_PAGE_PRIVATE_MEMSLOT, + APIC_DEFAULT_PHYS_BASE, + PAGE_SIZE); if (ret) - return ret; + goto out; kvm->arch.apic_access_page_done = true; - return 0; +out: + mutex_unlock(&kvm->slots_lock); + return ret; } static int avic_init_backing_page(struct kvm_vcpu *vcpu)