From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41BC338A73F for ; Mon, 4 May 2026 22:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777934563; cv=none; b=tImCg7PWPEWMIaFy+wbV5ZwcsT6n1wtlyF7RkkofqqClUYSUV5IFF1Iug5UaKsXp0ZveeyBaqjOdVSMtIFsN7AnRKZR4VCqyYbe3CXq4i+g4Eyzy2NIwJvYbbgOtpawxMO2zxwIaC9ivbGijbvXNWzjjShFaCXNl3rMLPnA93mI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777934563; c=relaxed/simple; bh=CUOCTJmVRKCTLlMSZJdBYm2KCJJFvArAmComUQyKG2A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OTueegEX0u5IWWVTHNEEHUXNenwK2r01u2B2d5eIkFQ+oaGltIkht+mTldrztZPC+bY0DcwgotRwKp59uPqe18ulOVle7IPktEuNQjYiYwC3HVtrI8+12mlfDVzMwEXhqO2hwmUOJ0peWFpQhG4Yjy8CASLjDzt7rfJQXN8GLZU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pNCJCJOs; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pNCJCJOs" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c7948640854so1949534a12.1 for ; Mon, 04 May 2026 15:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777934562; x=1778539362; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WPDlks8S40wU9ZB94GBJYrEHqJjoYpfybndF76KRr9U=; b=pNCJCJOswO7K0JMYh1I3F/+isDgwdbxdEw4UIMAmGDvBvyz28YtVXt7eyd5EW5JvUm Puju2oC7k7acSosIAEADK+iQq6aw+vpi/dgjtIxltMHLajPeIR29ZlWyumfp2UVn/i+N ECet1OB++24jQSDQKV23E0KetxYMuBaAq/JnjJXpB+js6l7t/tIF+HUJIf0OKNtmwN0H CMlTJOQjil+3a+wUNSVwpXjvDbXriag2MjW2CRj2989wJJxxL8GsXK4fcYMIQ141goSB QxMoONNha3nCdZBy9QtC2HumKJtyEdhNAnESZ2ipqoqgMljGQHDGiKPn0bBt0zNcMRke jRxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777934562; x=1778539362; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WPDlks8S40wU9ZB94GBJYrEHqJjoYpfybndF76KRr9U=; b=kQQ1PJv3f8cemH+brT1R48ZMkZVOhFy1I0Z4onYJ3x2Dd+9E+0qu7LvsiOyWo42mdL z+Zou777a2LCCEfgyvipNEYY+2LhIOGF36/LHrN+lieXQ8iYUI7CkxQndQ3N5ONPIgNn MqVBFW6n3NNMeoct7jAwfWLcD53IbT/sl+ZaCv2wWYnC6VK3FKaT8kclGO6Fsywv6Jx8 3XcqweGgZLf2LfT7g1/e9nRAMFJIrTq2No/LbEbVkBDVG1+t/+RUmwfMnsfNPNK3hGl8 tvzbN5F0QoJ7Xfc+bUILtXYKv37sxsiN3w0pEtRi5R1L82JXtX/qEHeasBN21SsWUo5B 5QvQ== X-Forwarded-Encrypted: i=1; AFNElJ+0pIIjhmHT91KBwFv0bpuZ6Z7trMUZ1Y9T4U891GEwwAYfHzL5Jqd1kR1MKbv1kfPJ1pBHI2tITbHlqC4=@vger.kernel.org X-Gm-Message-State: AOJu0YxRrZmVzLh9rpKCkmMfyOt9eZjF1BjZv23UktSZwFqf7CuKjLfL FREByPg4l5mMe7il+18DZ6rLS5Myw3wXmvUjrv5em/1mep+bTKEmOzxM2aPRGDV4M953wCQyfEp LSbRZ+RcdqFMXauHwIMHgwQ== X-Received: from pgbcp9.prod.google.com ([2002:a05:6a02:4009:b0:c79:8315:4734]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:918a:b0:3a2:e0d3:37d1 with SMTP id adf61e73a8af0-3a7f1eb20dbmr12044574637.41.1777934561428; Mon, 04 May 2026 15:42:41 -0700 (PDT) Date: Mon, 4 May 2026 22:42:10 +0000 In-Reply-To: <20260504224213.1049426-1-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260504224213.1049426-1-jthoughton@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260504224213.1049426-4-jthoughton@google.com> Subject: [PATCH 3/5] KVM: mips: Grab MMU lock in kvm_arch_flush_shadow_all() From: James Houghton To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Sean Christopherson , Gavin Shan , Shaoqin Huang , Ricardo Koller , Tianrui Zhao , Bibo Mao , Huacai Chen , James Hogan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, James Houghton , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" kvm_mips_flush_gpa_pt() expects the MMU lock to be held; it is not in this path. This can lead to a double-free of page table entries if kvm_arch_flush_shadow_all() is called twice on the same `kvm` concurrently; such a scenario is possible. Cc: stable@vger.kernel.org Fixes: b62091108633 ("KVM: MIPS: Implement kvm_arch_flush_shadow_all/memslot") Signed-off-by: James Houghton --- Note: This is compile-tested only! arch/mips/kvm/mips.c | 2 ++ arch/mips/kvm/mmu.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index a53abbba43ea..463b6c4aa62c 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -180,6 +180,8 @@ long kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, void kvm_arch_flush_shadow_all(struct kvm *kvm) { + guard(spinlock)(&kvm->mmu_lock); + /* Flush whole GPA */ kvm_mips_flush_gpa_pt(kvm, 0, ~0); kvm_flush_remote_tlbs(kvm); diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index d2c3b6b41f18..5045833f8116 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -269,6 +269,8 @@ static bool kvm_mips_flush_gpa_pgd(pgd_t *pgd, unsigned long start_gpa, */ bool kvm_mips_flush_gpa_pt(struct kvm *kvm, gfn_t start_gfn, gfn_t end_gfn) { + lockdep_assert_held(&kvm->mmu_lock); + return kvm_mips_flush_gpa_pgd(kvm->arch.gpa_mm.pgd, start_gfn << PAGE_SHIFT, end_gfn << PAGE_SHIFT); -- 2.54.0.545.g6539524ca2-goog