Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874399pxk; Thu, 17 Sep 2020 19:58:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUa0PIfD0KSqVcsLqKm8CGbouMuefMalvCoGl+GtjX8Qlmomg/ja8BjKGGPTiVcCLalz1l X-Received: by 2002:a17:906:a4e:: with SMTP id x14mr33369360ejf.112.1600397935214; Thu, 17 Sep 2020 19:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600397935; cv=none; d=google.com; s=arc-20160816; b=zHs6KWnznCI+Z5CYkONGS4ccXhgJXV9U7dTCbTHEAsEfskwHXVUkbu6MDoyPRxhW1r bvW1LqI8hLESVkJwrBVBuUSXwuFjAuT9nKW9j/j+U+PnnXRmzMcDImR4lkPSAsNf4tMl KGvRFlZp5LFGFXPMEs/lfAtrTMQjY/kwo+vZKMcmk9S47AOjgptLL+pOugtSNxKYm73M Qgy1IALmEGvfROWA3CRfXFGFtNr/B018K4eXMcDlIXJO7stsM+wGC6dE0maYtNyElpyz pUdcP5AUFtxjLOT6ekB+xRqV2kfbsU8fntPUyag6F4sOR/1OpUspbxou8+7iGhgvbiQ3 pAPQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ktE/NgjjBZI81FcxuZyq2z7WA9w8D3XIDJ/RZwYvPzs=; b=RhBaha8POdWmr2bzYp3U29s0QP8r6NFckR1A8IW9Nb3D8IH4pOTF4K5byV8tornZhI ijjdP+HCJfOawEs/bTHpb98r9GRN67qBSLsyTD+suc3dPHRHoDS488dW1NFX7ezUUve4 1q9uf0F7cuj0IZ+GmfqhZ1YmEozccYwiTnVYtqBMKFW1sOLRBU9wWRw1gMSMIsVjfOHC sWOQsqY5PB0NDz8mr8AyiTi4iA+ZVPZQGSfyA+lMnthjXN3aYheUFoFUOfjJvaqoa6yT ruc6yWyPds65vRftgENQD17/3/nus1kNmaA+RDWnzyYt0DQKOaz9MjFyeGGTM4suV4Ay iQgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rO7WPuTZ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si1085195edv.344.2020.09.17.19.58.32; Thu, 17 Sep 2020 19:58:55 -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=@kernel.org header.s=default header.b=rO7WPuTZ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728917AbgIRCze (ORCPT + 99 others); Thu, 17 Sep 2020 22:55:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727855AbgIRCHI (ORCPT ); Thu, 17 Sep 2020 22:07:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7380F23A31; Fri, 18 Sep 2020 02:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394825; bh=SPERwlclIXQwTDhY9S9VzGMn42+SabgQHJDdP2nrnVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rO7WPuTZ/yUzvg9shwPlE0akOMvDAHC4/R1DGcEMDLKFfYVc6hvHJ2y7HIv1rFh7l 1n7s+70jVctX0/NoThT8uncUrTZdJ8C5mQ1svngMo4fNhMyY2GDoLeXo1cRpncqm3O LMziZvv18gnNC+a0IyQHYvA1dHhDfycxu4/+3ZDs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paul Mackerras , Sasha Levin , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 5.4 290/330] KVM: PPC: Book3S HV: Close race with page faults around memslot flushes Date: Thu, 17 Sep 2020 22:00:30 -0400 Message-Id: <20200918020110.2063155-290-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Mackerras [ Upstream commit 11362b1befeadaae4d159a8cddcdaf6b8afe08f9 ] There is a potential race condition between hypervisor page faults and flushing a memslot. It is possible for a page fault to read the memslot before a memslot is updated and then write a PTE to the partition-scoped page tables after kvmppc_radix_flush_memslot has completed. (Note that this race has never been explicitly observed.) To close this race, it is sufficient to increment the MMU sequence number while the kvm->mmu_lock is held. That will cause mmu_notifier_retry() to return true, and the page fault will then return to the guest without inserting a PTE. Signed-off-by: Paul Mackerras Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_64_mmu_radix.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c index da8375437d161..9d73448354698 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -1104,6 +1104,11 @@ void kvmppc_radix_flush_memslot(struct kvm *kvm, kvm->arch.lpid); gpa += PAGE_SIZE; } + /* + * Increase the mmu notifier sequence number to prevent any page + * fault that read the memslot earlier from writing a PTE. + */ + kvm->mmu_notifier_seq++; spin_unlock(&kvm->mmu_lock); } -- 2.25.1