Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4606834imw; Tue, 19 Jul 2022 09:40:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uIWRDJe+VsDoODDN3k5nNkKaAMrqpmIBDdHdX9JaT/7c+MP6UoKCts47+qaqK5ZMMj02VO X-Received: by 2002:a05:6870:1709:b0:10c:1e3c:1232 with SMTP id h9-20020a056870170900b0010c1e3c1232mr154797oae.68.1658248852565; Tue, 19 Jul 2022 09:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658248852; cv=none; d=google.com; s=arc-20160816; b=rkhukodolyy637f9hQcVY1ptQjToQHxrz7p30PLjD7lI1ZdSQm/gftMrzW0fPRVesO wGY2678uBwuoHl1WJRL5Ae+xkzqA52uW1zORsv46ZnDej+0+W+le1P4ukErPHAMHmsUh BhcZogKmcBdtlLQ8RkA5/vfUjgZdEx9gsGPyVopW2EM75aDnpb6V26SiDiJ289HqpdTE O8MsHZl3xVMRfNqbivLrOjs1LTN6S3zCQh1Oa1qxNt/7kOq6Q7k6i8P9m1MNfcoCle/o Zwgbl4utDv6k15kuTtaZRtrJqgXIBjOcoJcCoCxoqki1CR0ZQYe17MBOwsurWnvPxx8D iqvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=/rnOinfjefyG7040ci+QjKu8n+QSf1S9hG2ztD7d8UA=; b=eRo1ycOVGNZUg8KRfx+Axt+LcbB8RSgL6QeSLt04VTjlJw8fBiVJbM1f+5GdNmlMNw /jUbRcFpumW5qQ+U7npxofgA7vaMJpwdJpVoOA4yKAnkY/oZnapCn9vaJsawhRLzhIuP UBiAM3hhDIsSGQWZD8RbWM32/T3N6hLs/v4pIr+moXZIEAgmIAot4ze1W01DmXV0Yzy/ JMEBfFTxRIkEKXMf8dkZ9P/ZGQHhCKHos018nX4X6xqVPqqGXaZQL99Iuo0TQQF3b2Jo g8tF+U/bFvJc1BZaiLt6RB4R4nTis+10UanEIsMu72oziDGtFVctLWfKiVJ+Tx/PmiTQ MMzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aAhQSfDw; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o4-20020a4a4404000000b004354f89db2bsi13998481ooa.27.2022.07.19.09.40.37; Tue, 19 Jul 2022 09:40:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aAhQSfDw; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236561AbiGSQRG (ORCPT + 99 others); Tue, 19 Jul 2022 12:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbiGSQRF (ORCPT ); Tue, 19 Jul 2022 12:17:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B8D349B6B; Tue, 19 Jul 2022 09:17:04 -0700 (PDT) Date: Tue, 19 Jul 2022 16:17:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658247422; 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=/rnOinfjefyG7040ci+QjKu8n+QSf1S9hG2ztD7d8UA=; b=aAhQSfDwq5/iaVqf0x0NEqRYIUwYk61StVOoJdfA2c6VOlXgujhmtcshelSkeU3C1AjORv WNMxGxynuHUP2GcCA/t24leelqQVk5RpIpv+UodMdACQQQGaIWxa+sOQ482K823xXnfwD7 9sM1+1D1tdV6FLur8qOA7WfAtT6nHz9tAufD+h1748MTOlib5OlcS5/2jVXXw6yY2+pI9T Os3rlXKv5pyLX2aTn0znmh7qCySmeA+hIDlUOkTaspH3nrLLivL6t0jwBwGqAno1Gl/A2E mp5FVPPuFvw0jD1Fgjx61/+C4KFVRPI/0hE6MqvuWLNy2xZF2m4GJP1n5iGAKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658247422; 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=/rnOinfjefyG7040ci+QjKu8n+QSf1S9hG2ztD7d8UA=; b=oiw3HHu+MYSh4C/4nHtvZNZ1Pd+QPpkpuXOE6js9n1gCl2Z0wSX4qyE5w7VyR0cF6qJKSB I0y4/wWRMGDmlLCw== From: "tip-bot2 for Nadav Amit" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm/tlb: Ignore f->new_tlb_gen when zero Cc: Hugh Dickins , Nadav Amit , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220710232837.3618-1-namit@vmware.com> References: <20220710232837.3618-1-namit@vmware.com> MIME-Version: 1.0 Message-ID: <165824742138.15455.11110929785444044294.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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/mm branch of tip: Commit-ID: 8f1d56f64f8d6b80dea2d1978d10071132a695c5 Gitweb: https://git.kernel.org/tip/8f1d56f64f8d6b80dea2d1978d10071132a695c5 Author: Nadav Amit AuthorDate: Sun, 10 Jul 2022 16:28:37 -07:00 Committer: Dave Hansen CommitterDate: Tue, 19 Jul 2022 09:04:52 -07:00 x86/mm/tlb: Ignore f->new_tlb_gen when zero Commit aa44284960d5 ("x86/mm/tlb: Avoid reading mm_tlb_gen when possible") introduced an optimization to skip superfluous TLB flushes based on the generation provided in flush_tlb_info. However, arch_tlbbatch_flush() does not provide any generation in flush_tlb_info and populates the flush_tlb_info generation with 0. This 0 is causes the flush_tlb_info to be interpreted as a superfluous, old flush. As a result, try_to_unmap_one() would not perform any TLB flushes. Fix it by checking whether f->new_tlb_gen is nonzero. Zero value is anyhow is an invalid generation value. To avoid future confusion, introduce TLB_GENERATION_INVALID constant and use it properly. Add warnings to ensure no partial flushes are done with TLB_GENERATION_INVALID or when f->mm is NULL, since this does not make any sense. In addition, add the missing unlikely(). [ dhansen: change VM_BUG_ON() -> VM_WARN_ON(), clarify changelog ] Fixes: aa44284960d5 ("x86/mm/tlb: Avoid reading mm_tlb_gen when possible") Reported-by: Hugh Dickins Signed-off-by: Nadav Amit Signed-off-by: Dave Hansen Tested-by: Hugh Dickins Link: https://lkml.kernel.org/r/20220710232837.3618-1-namit@vmware.com --- arch/x86/include/asm/tlbflush.h | 1 + arch/x86/mm/tlb.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 98fa0a1..21bf105 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -16,6 +16,7 @@ void __flush_tlb_all(void); #define TLB_FLUSH_ALL -1UL +#define TLB_GENERATION_INVALID 0 void cr4_update_irqsoff(unsigned long set, unsigned long clear); unsigned long cr4_read_shadow(void); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index d9314cc..c1e31e9 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -771,7 +771,8 @@ static void flush_tlb_func(void *info) return; } - if (f->new_tlb_gen <= local_tlb_gen) { + if (unlikely(f->new_tlb_gen != TLB_GENERATION_INVALID && + f->new_tlb_gen <= local_tlb_gen)) { /* * The TLB is already up to date in respect to f->new_tlb_gen. * While the core might be still behind mm_tlb_gen, checking @@ -843,6 +844,12 @@ static void flush_tlb_func(void *info) /* Partial flush */ unsigned long addr = f->start; + /* Partial flush cannot have invalid generations */ + VM_WARN_ON(f->new_tlb_gen == TLB_GENERATION_INVALID); + + /* Partial flush must have valid mm */ + VM_WARN_ON(f->mm == NULL); + nr_invalidate = (f->end - f->start) >> f->stride_shift; while (addr < f->end) { @@ -1045,7 +1052,8 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) struct flush_tlb_info *info; preempt_disable(); - info = get_flush_tlb_info(NULL, start, end, 0, false, 0); + info = get_flush_tlb_info(NULL, start, end, 0, false, + TLB_GENERATION_INVALID); on_each_cpu(do_kernel_range_flush, info, 1); @@ -1214,7 +1222,8 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) int cpu = get_cpu(); - info = get_flush_tlb_info(NULL, 0, TLB_FLUSH_ALL, 0, false, 0); + info = get_flush_tlb_info(NULL, 0, TLB_FLUSH_ALL, 0, false, + TLB_GENERATION_INVALID); /* * flush_tlb_multi() is not optimized for the common case in which only * a local TLB flush is needed. Optimize this use-case by calling