From patchwork Tue Sep 12 04:04:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 9948351 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 A221F60360 for ; Tue, 12 Sep 2017 04:07:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8182E212DB for ; Tue, 12 Sep 2017 04:07:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 760AA281C3; Tue, 12 Sep 2017 04:07:19 +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 E98F4212DB for ; Tue, 12 Sep 2017 04:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751217AbdILEHR (ORCPT ); Tue, 12 Sep 2017 00:07:17 -0400 Received: from ozlabs.org ([103.22.144.67]:53279 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750724AbdILEHQ (ORCPT ); Tue, 12 Sep 2017 00:07:16 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 3xrrpp50Xqz9sBZ; Tue, 12 Sep 2017 14:07:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1505189234; bh=yf46WpowEMLzUqLx4qye5/cJI3lEmMBGCM4BE7u10OQ=; h=Date:From:To:Subject:From; b=Aj9OAi2Sa0myqckLO7tSD/j+BhEnLOfkjVta852tgZo1MssoZANWfUM1nvN/SLCNC MY54urIZjfjt1tQ32LkC3xWPbDkWGqtPGo+2RJcDItQySUmtSPJjbfjtd2tmykxPeZ INCZNEC80a9z188EYI9JGppT7Ji6Q7tGMZXlzINso6mRHTHMiP0nRjnuikeEVlWury HRnNT8m43crd4SlgiLTiLcn4Cb8NDsSC5JT1Z/66xV0LyEYYkM1ohrkhXfWN4mAl3H U4wkdoIKIQTGZ1F1CzhPRzhbFKlkQ5oIfyrMmj5GLBwiik8FT1cTd/L1U0LMY+y2gB NBuMxRBonnpOw== Date: Tue, 12 Sep 2017 14:04:28 +1000 From: Paul Mackerras To: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: PPC: Book3S HV: Hold kvm->lock around call to kvmppc_update_lpcr Message-ID: <20170912040428.up7nzodqmqbfuke4@oak.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 468808bd35c4 ("KVM: PPC: Book3S HV: Set process table for HPT guests on POWER9", 2017-01-30) added a call to kvmppc_update_lpcr() which doesn't hold the kvm->lock mutex around the call, as required. This adds the lock/unlock pair, and for good measure, includes the kvmppc_setup_partition_table() call in the locked region, since it is altering global state of the VM. This error appears not to have any fatal consequences for the host; the consequences would be that the VCPUs could end up running with different LPCR values, or an update to the LPCR value by userspace using the one_reg interface could get overwritten, or the update done by kvmhv_configure_mmu() could get overwritten. Cc: stable@vger.kernel.org # v4.10+ Fixes: 468808bd35c4 ("KVM: PPC: Book3S HV: Set process table for HPT guests on POWER9") Signed-off-by: Paul Mackerras --- I intend to get this one included in 4.14. arch/powerpc/kvm/book3s_hv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 18e974a34fce..a7177c284f9b 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4212,11 +4212,13 @@ static int kvmhv_configure_mmu(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg) if ((cfg->process_table & PRTS_MASK) > 24) return -EINVAL; + mutex_lock(&kvm->lock); kvm->arch.process_table = cfg->process_table; kvmppc_setup_partition_table(kvm); lpcr = (cfg->flags & KVM_PPC_MMUV3_GTSE) ? LPCR_GTSE : 0; kvmppc_update_lpcr(kvm, lpcr, LPCR_GTSE); + mutex_unlock(&kvm->lock); return 0; }