Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3208978imm; Sun, 29 Jul 2018 12:56:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwyNZzjrD8wuTBrhuj5v5px/ctGuRGIQytIAephNb2lsS+0O85gIeyAhYwm1ENKYpJ8tT5 X-Received: by 2002:a17:902:8e81:: with SMTP id bg1-v6mr13742636plb.129.1532894174187; Sun, 29 Jul 2018 12:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532894174; cv=none; d=google.com; s=arc-20160816; b=cNQbtzTaZbZ6zIUmylJaQrlm3tTfP9piYwxxG6CudTRav/nWM628XEz7e6RX/9hFX9 3ByOMdJdgKF4k6yDAkkIw/05tdJzb6nv4sXb5cG0NCvBVw4neBrMY9FsTPYs+qodb4Ej 9EmWThkRlXI6xxpyBxG+ZgEOZCFTVlSK73HWSnzmNA/QNCyEE89vDxjk9elum45qDZvA OELTDz0qiqoM3/dZ2IkvqcswNg7wLenSzh4YReM6qHfvXJBk8npleZSuX7es+cCwOD1P jjvBDy5DJmLF/q3jOMwPLYpxXn0prbci7VkzwKB7A+XPdHifKyeiT5UCCfpafWKdhf5Q eIwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=hhchYIgZu3ImEBCGjN6cgIR53S5DEZbrnZwbjEIww5E=; b=Z+V5MN5emZT1DItIZ8RerExW7e71G0LzcTdfL0Ns8jbHrhcgUEC3knJYg41OQcAhlz xFTCPy/fcChY/lSPFAbGp5Z7uKoTnb4JlWIiHofByZcMSATCdsnU3FRG3rqSO0kWdVId eJVWGgRAnZ9LRn/ydAZNi79GwEfz4sGvAIU/DeAlSFDolNNgINJ70I6M2vjIOVjx9EqD TQFxmO07v0WGvKgLa68nsGhCOe0p+FAml/cJz6VpMa8FrhdnKfEYE3NY86LJP4LSRBHF Mq65cDVv7ZOqdFrrczgsru1pEH5IPLn4kcjXCpSnyQ5ISaKvxznedY1ju63UPjTy8hht mkhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11-v6si5608583plq.265.2018.07.29.12.55.59; Sun, 29 Jul 2018 12:56:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728476AbeG2V0s (ORCPT + 99 others); Sun, 29 Jul 2018 17:26:48 -0400 Received: from shelob.surriel.com ([96.67.55.147]:48282 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726644AbeG2V0r (ORCPT ); Sun, 29 Jul 2018 17:26:47 -0400 Received: from [2001:470:1f07:12aa:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fjrmL-0002Lb-CK; Sun, 29 Jul 2018 15:54:57 -0400 Date: Sun, 29 Jul 2018 15:54:51 -0400 From: Rik van Riel To: Andy Lutomirski Cc: LKML , kernel-team , Peter Zijlstra , X86 ML , Vitaly Kuznetsov , Ingo Molnar , Mike Galbraith , Dave Hansen , Catalin Marinas , Benjamin Herrenschmidt Subject: [PATCH v2 10/11] x86,tlb: really leave mm on shootdown Message-ID: <20180729155451.7a1eb1a5@imladris.surriel.com> In-Reply-To: References: <20180728215357.3249-1-riel@surriel.com> <20180728215357.3249-11-riel@surriel.com> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 28 Jul 2018 21:21:17 -0700 Andy Lutomirski wrote: > On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel wrote: > > Conditionally skip lazy TLB mm refcounting. When an architecture has > > CONFIG_ARCH_NO_ACTIVE_MM_REFCOUNTING enabled, an mm that is used in > > lazy TLB mode anywhere will get shot down from exit_mmap, and there > > in no need to incur the cache line bouncing overhead of refcounting > > a lazy TLB mm. > > Unless I've misunderstood something, this patch results in idle tasks > whose active_mm has been freed still having active_mm pointing at > freed memory. Below (plus the next email) should fix the bug you pointed out, in a somewhat non-invasive way. Patches have survived a few simple tests on my test system, I have not thrown a full load at them yet. I would like to save the full rewrite to remove ->active_mm for a later series, because this is already as much churn as I am comfortable with for this code :) ---8<--- Author: Rik van Riel Subject: [PATCH 10/11] x86,tlb: really leave mm on shootdown When getting an mm shot down from under us in lazy TLB mode, don't just switch the TLB over to the init_mm page tables, but really drop our references to the lazy TLB mm. This allows for faster (instant) freeing of a lazy TLB mm, which is a precondition to getting rid of the refcounting of mms in lazy TLB mode. Signed-off-by: Rik van Riel --- arch/x86/mm/tlb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 7b1add904396..425cb9fa2640 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -140,6 +140,8 @@ void leave_mm(void *dummy) WARN_ON(!this_cpu_read(cpu_tlbstate.is_lazy)); switch_mm(NULL, &init_mm, NULL); + current->active_mm = &init_mm; + mmdrop(loaded_mm); } EXPORT_SYMBOL_GPL(leave_mm); @@ -483,6 +485,8 @@ static void flush_tlb_func_common(const struct flush_tlb_info *f, * IPIs to lazy TLB mode CPUs. */ switch_mm_irqs_off(NULL, &init_mm, NULL); + current->active_mm = &init_mm; + mmdrop(loaded_mm); return; } -- 2.14.4