From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.114]) (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 1D1B63AB26D for ; Tue, 9 Jun 2026 09:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.114 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780996864; cv=none; b=cFPrf9rLMKDNADx7PVmVuc2KGw+n0X8csX8BRzWqQmRqBoTMNDz/JaM096iJZW3m9pa9u9QkjZR8L/0I9I2OeefNwK3hKrwEu8Z3zJ9Mjo5sNit8NQxf0Rx+NQtNECFE9sO3vObsZtAO/iXlCA9BaDU1TgBYPEOzKzPKljdAkKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780996864; c=relaxed/simple; bh=/ZIk1PhvsGTQl4yIwWXnYIJ4uKwn1gsGeIJS017923o=; h=References:From:In-Reply-To:Content-Type:Cc:Mime-Version:Date: Message-Id:To:Subject; b=H3+A8Q1Va+zDQlw37j33CLV/RkRQWbm+YpcE4t1AWweviNDYYfQr7wRs8SQ7TiC4fuN7IzLvTPIy6s45b9BPkPXUz4wYzZ4srSgaKIjl8SIRPMd1dfzjBDf8X9UUa0DU6Qqil/3NtNBzXIKjvUa4T8FGarh9YJfcuXji0FPgIXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=lN7HupRa; arc=none smtp.client-ip=209.127.230.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="lN7HupRa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780996859; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=fxjFgs3jmgVbxBEjqFS+NGlWNchb9XQmZzLBfuKu/K4=; b=lN7HupRa9fUfGy+u5ItUFz/6n5/44mrWVEkcTJTLLldJGJgAXlLNi6OcUifkYdjGFTCKrM pZlJIsuen1YOATynJWv77JOfnOvdiMaHRsA06Ct1mu6YQj0ugsISzJhGY6ZPZhfZrjbSGq 7dyXctKVDAvtZ0YZ4VpY3khYn10enP0FbrwQbtiDcVnSNCYXuHwYaQuUVKBRR7M3GKCe2k uu9mMnJ1vuMYtHXkOFSwIsO8zB7FHqTxITlpOtFUm3XQSAo4/uFIDEsFJ1JW250Rx8ikXV nsOYBn627EXvjTVXgojU5O20gYfKqBOc0M/lkageCM1ZcY3DoXtssCPZY87Xkw== X-Lms-Return-Path: References: <20260609091710.404083-1-zhouchuyi@bytedance.com> From: "Chuyi Zhou" In-Reply-To: <20260609091710.404083-1-zhouchuyi@bytedance.com> Content-Type: text/plain; charset=UTF-8 Cc: , "Chuyi Zhou" X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Date: Tue, 9 Jun 2026 17:17:09 +0800 Message-Id: <20260609091710.404083-14-zhouchuyi@bytedance.com> Content-Transfer-Encoding: 7bit X-Original-From: Chuyi Zhou To: , , , , , , , , , , , , , Subject: [PATCH v7 13/14] x86/kvm: Disable preemption in kvm_flush_tlb_multi() kvm_flush_tlb_multi() is installed as an x86 PV TLB flush backend, so flush_tlb_multi() can reach it through pv_ops when running as a KVM guest. kvm_flush_tlb_multi() uses the per-CPU scratch cpumask __pv_cpu_mask. That buffer must remain tied to the current CPU until the mask has been copied, filtered, and consumed by native_flush_tlb_multi(). Today the x86/mm callers enter flush_tlb_multi() while pinned to a CPU, but a subsequent x86/mm change will drop that caller-side CPU pinning before issuing the remote TLB flush so the caller can be preempted while waiting for remote CPUs. Make the KVM backend protect its own per-CPU scratch cpumask by disabling preemption locally. This is harmless with the current callers, where the preemption disable is nested, and makes the KVM pv_ops dependency explicit before changing the x86/mm call sites. Signed-off-by: Chuyi Zhou --- arch/x86/kernel/kvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 29226d112029..d540f54f4d16 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -662,8 +662,10 @@ static void kvm_flush_tlb_multi(const struct cpumask *cpumask, u8 state; int cpu; struct kvm_steal_time *src; - struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask); + struct cpumask *flushmask; + guard(preempt)(); + flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask); cpumask_copy(flushmask, cpumask); /* * We have to call flush only on online vCPUs. And -- 2.20.1