From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BDF7C4363A for ; Thu, 22 Oct 2020 10:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3FF5222E9 for ; Thu, 22 Oct 2020 10:51:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NDGSsM0H"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MhRdHG7M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2896749AbgJVKvX (ORCPT ); Thu, 22 Oct 2020 06:51:23 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:46738 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2896729AbgJVKuT (ORCPT ); Thu, 22 Oct 2020 06:50:19 -0400 Date: Thu, 22 Oct 2020 10:49:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1603363798; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EKE4tkuVx1iI+TMuSjokY4LRT13L/xCo/XlvF52HAFc=; b=NDGSsM0HrAgfwGgrZbeXJPqXGP5Wg8U341eSxX/xi7KE++8oSijZfNQsqfYM8YAaedKcvw 1zA7NnwBH55wnXIHcMiSLytqG/g6ZH17ajSssCIfLWkatlzyqGqnwFn+08mb7Fb0vijmgV /VW7N4gwvuOpkUV0gxO+t8g1YtrgM+QPgoRp2Wu6iCJB9qHjPchpzi8VvW9Yr/jE1ZHPUe qrkWBidmx6QZr1qsYg4/54yVe22pCazaLeHfajBUvavAo3AGe+3u7gsFtXZsrLSCt5WO7L TJI8sR6/xn+c+nFtWL1aVkFIaY95Msd6WaomAxClWxtlqPrDylie9FvYAmostQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1603363798; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EKE4tkuVx1iI+TMuSjokY4LRT13L/xCo/XlvF52HAFc=; b=MhRdHG7MYuGCgtHEfoQG1xwR6ThiVZmkax2QP5iVLaSgXtO1iexDSr49IaZKUfaP5bcNYu o2PxjEUw8Euka1Aw== From: "tip-bot2 for Juergen Gross" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/alternative: Don't call text_poke() in lazy TLB mode Cc: Juergen Gross , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20201009144225.12019-1-jgross@suse.com> References: <20201009144225.12019-1-jgross@suse.com> MIME-Version: 1.0 Message-ID: <160336379724.7002.17024152211307266195.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: abee7c494d8c41bb388839bccc47e06247f0d7de Gitweb: https://git.kernel.org/tip/abee7c494d8c41bb388839bccc47e06247f0d7de Author: Juergen Gross AuthorDate: Fri, 09 Oct 2020 16:42:25 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 22 Oct 2020 12:37:23 +02:00 x86/alternative: Don't call text_poke() in lazy TLB mode When running in lazy TLB mode the currently active page tables might be the ones of a previous process, e.g. when running a kernel thread. This can be problematic in case kernel code is being modified via text_poke() in a kernel thread, and on another processor exit_mmap() is active for the process which was running on the first cpu before the kernel thread. As text_poke() is using a temporary address space and the former address space (obtained via cpu_tlbstate.loaded_mm) is restored afterwards, there is a race possible in case the cpu on which exit_mmap() is running wants to make sure there are no stale references to that address space on any cpu active (this e.g. is required when running as a Xen PV guest, where this problem has been observed and analyzed). In order to avoid that, drop off TLB lazy mode before switching to the temporary address space. Fixes: cefa929c034eb5d ("x86/mm: Introduce temporary mm structs") Signed-off-by: Juergen Gross Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20201009144225.12019-1-jgross@suse.com --- arch/x86/kernel/alternative.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cdaab30..cd6be6f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -807,6 +807,15 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) temp_mm_state_t temp_state; lockdep_assert_irqs_disabled(); + + /* + * Make sure not to be in TLB lazy mode, as otherwise we'll end up + * with a stale address space WITHOUT being in lazy mode after + * restoring the previous mm. + */ + if (this_cpu_read(cpu_tlbstate.is_lazy)) + leave_mm(smp_processor_id()); + temp_state.mm = this_cpu_read(cpu_tlbstate.loaded_mm); switch_mm_irqs_off(NULL, mm, current);