From patchwork Sat Nov 28 16:01:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11937585 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 547AEC63777 for ; Sat, 28 Nov 2020 16:01:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BF70C241A4 for ; Sat, 28 Nov 2020 16:01:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fddofWue" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF70C241A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EADE6B0070; Sat, 28 Nov 2020 11:01:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59ABE8D0001; Sat, 28 Nov 2020 11:01:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48F626B0072; Sat, 28 Nov 2020 11:01:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 2EF4B6B0070 for ; Sat, 28 Nov 2020 11:01:57 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E77511F1A for ; Sat, 28 Nov 2020 16:01:56 +0000 (UTC) X-FDA: 77534293032.08.straw66_51096a827391 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id C3BFA1819E627 for ; Sat, 28 Nov 2020 16:01:56 +0000 (UTC) X-HE-Tag: straw66_51096a827391 X-Filterd-Recvd-Size: 7183 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sat, 28 Nov 2020 16:01:56 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id e23so1868326pgk.12 for ; Sat, 28 Nov 2020 08:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gttnBtFOibE2tP2Qz24NLSDRYoTGub5YJjfSoizC0iA=; b=fddofWue+O7PL7JyLzbrmfEZ1AmPAs4YpBi425i4fGaiDzUtTP1Cjb/kUW5gGhUTUG zroDx2CGFhUo8MVoFIUF+MP8b1p2psaIqXLAsQr05kPX/p4d/S7xxuUvrdD122e3zNTk +yWVb5RpbczP24WMcIBwgAESCFaKaOazX1xmiySUU7Q4UENN4oLJouX6ftvashMBqtNo k9k7ojLvXh7wWrdH5HhDZtS64VIpEQm0fl12lwLV2acHXX+2Z4z3IDRijQ1jKh4kn6f8 te2+ctqgL6SkhFEZCO0U/smJPgELN01XFV1O3fSOhYhR0PJS+cMx8avXrp2TZTREkvoq hJRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gttnBtFOibE2tP2Qz24NLSDRYoTGub5YJjfSoizC0iA=; b=LG2UZic5aEsEGw1tffuL/07A4k2Bb9sIgLqQLa/BOSO5AoY8aBIYPGf4Z60xV2ITsh hB0Sg5SxLrqEIqJPzLcYcYb2Qxyz47zfIhhrCUc4xUj+XWnb9iY5CWgRXPgZVkWNmC5p W00c7XIOD6Ex/bdzEFsEQwJKVgBr7tY7MCm2JEfQEGtwtkdaPwLwbqAFCAWl1LG17x7b GVtdwTAppIa3Dovr5cPsnoBgGG8yOurOagdef5UOQyADx+qYoBMVXJkHuTT6oKtKbObc BcysFK8KpBfTCSJd/aiVtbdxlKVg1CyiB5VqwIfjLRSJmyhM6VdL+lPn8jNAAn2/7J8K 2Rrw== X-Gm-Message-State: AOAM531Ws+Q2sBoCTZm8kAO9kN5WYudjf8/7WWAMo7vgGdjpuaNfJkxJ /9SgrtLOZU+fnki8ZoAv0vk= X-Google-Smtp-Source: ABdhPJzSlEN2fFhGsSm+AZ067hVpNTL/kp5XtHU/fInnX4+IsK4D3+Ht2oCRMtspesP14x3iR4yVHg== X-Received: by 2002:a17:90b:30cb:: with SMTP id hi11mr16522183pjb.94.1606579315315; Sat, 28 Nov 2020 08:01:55 -0800 (PST) Received: from bobo.ibm.com (193-116-103-132.tpgi.com.au. [193.116.103.132]) by smtp.gmail.com with ESMTPSA id d4sm9762607pjz.28.2020.11.28.08.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 08:01:54 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , x86@kernel.org, Mathieu Desnoyers , Arnd Bergmann , Peter Zijlstra , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard Subject: [PATCH 1/8] lazy tlb: introduce exit_lazy_tlb Date: Sun, 29 Nov 2020 02:01:34 +1000 Message-Id: <20201128160141.1003903-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201128160141.1003903-1-npiggin@gmail.com> References: <20201128160141.1003903-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is called at points where a lazy mm is switched away or made not lazy (by its owner switching back). Signed-off-by: Nicholas Piggin --- arch/arm/mach-rpc/ecard.c | 1 + arch/powerpc/mm/book3s64/radix_tlb.c | 1 + fs/exec.c | 6 ++++-- include/asm-generic/mmu_context.h | 21 +++++++++++++++++++++ kernel/kthread.c | 1 + kernel/sched/core.c | 2 ++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-rpc/ecard.c b/arch/arm/mach-rpc/ecard.c index 827b50f1c73e..43eb1bfba466 100644 --- a/arch/arm/mach-rpc/ecard.c +++ b/arch/arm/mach-rpc/ecard.c @@ -253,6 +253,7 @@ static int ecard_init_mm(void) current->mm = mm; current->active_mm = mm; activate_mm(active_mm, mm); + exit_lazy_tlb(active_mm, current); mmdrop(active_mm); ecard_init_pgtables(mm); return 0; diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c b/arch/powerpc/mm/book3s64/radix_tlb.c index b487b489d4b6..ac3fec03926a 100644 --- a/arch/powerpc/mm/book3s64/radix_tlb.c +++ b/arch/powerpc/mm/book3s64/radix_tlb.c @@ -661,6 +661,7 @@ static void do_exit_flush_lazy_tlb(void *arg) mmgrab(&init_mm); current->active_mm = &init_mm; switch_mm_irqs_off(mm, &init_mm, current); + exit_lazy_tlb(mm, current); mmdrop(mm); } diff --git a/fs/exec.c b/fs/exec.c index 547a2390baf5..4b4dea1bb7ba 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1017,6 +1017,8 @@ static int exec_mmap(struct mm_struct *mm) if (!IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM)) local_irq_enable(); activate_mm(active_mm, mm); + if (!old_mm) + exit_lazy_tlb(active_mm, tsk); if (IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM)) local_irq_enable(); tsk->mm->vmacache_seqnum = 0; @@ -1028,9 +1030,9 @@ static int exec_mmap(struct mm_struct *mm) setmax_mm_hiwater_rss(&tsk->signal->maxrss, old_mm); mm_update_next_owner(old_mm); mmput(old_mm); - return 0; + } else { + mmdrop(active_mm); } - mmdrop(active_mm); return 0; } diff --git a/include/asm-generic/mmu_context.h b/include/asm-generic/mmu_context.h index 91727065bacb..4626d0020e65 100644 --- a/include/asm-generic/mmu_context.h +++ b/include/asm-generic/mmu_context.h @@ -24,6 +24,27 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, } #endif +/* + * exit_lazy_tlb - Called after switching away from a lazy TLB mode mm. + * + * mm: the lazy mm context that was switched + * tsk: the task that was switched to (with a non-lazy mm) + * + * mm may equal tsk->mm. + * mm and tsk->mm will not be NULL. + * + * Note this is not symmetrical to enter_lazy_tlb, this is not + * called when tasks switch into the lazy mm, it's called after the + * lazy mm becomes non-lazy (either switched to a different mm or the + * owner of the mm returns). + */ +#ifndef exit_lazy_tlb +static inline void exit_lazy_tlb(struct mm_struct *mm, + struct task_struct *tsk) +{ +} +#endif + /** * init_new_context - Initialize context of a new mm_struct. * @tsk: task struct for the mm diff --git a/kernel/kthread.c b/kernel/kthread.c index 933a625621b8..e380302aac13 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -1250,6 +1250,7 @@ void kthread_use_mm(struct mm_struct *mm) } tsk->mm = mm; switch_mm_irqs_off(active_mm, mm, tsk); + exit_lazy_tlb(active_mm, tsk); local_irq_enable(); task_unlock(tsk); #ifdef finish_arch_post_lock_switch diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e7e453492cff..dcc46039ade5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3765,6 +3765,8 @@ context_switch(struct rq *rq, struct task_struct *prev, switch_mm_irqs_off(prev->active_mm, next->mm, next); if (!prev->mm) { // from kernel + exit_lazy_tlb(prev->active_mm, next); + /* will mmdrop() in finish_task_switch(). */ rq->prev_mm = prev->active_mm; prev->active_mm = NULL;