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=-9.3 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 B5793C433E2 for ; Mon, 14 Sep 2020 07:02:36 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6369208DB for ; Mon, 14 Sep 2020 07:02:35 +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="SPsvJsoO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6369208DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BqckK0syszDqXZ for ; Mon, 14 Sep 2020 17:02:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1043; helo=mail-pj1-x1043.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=SPsvJsoO; dkim-atps=neutral Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Bqch55trhzDqRS for ; Mon, 14 Sep 2020 17:00:37 +1000 (AEST) Received: by mail-pj1-x1043.google.com with SMTP id jw11so4856603pjb.0 for ; Mon, 14 Sep 2020 00:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=Y2wlAqtXNyefQseZpanYLfJq3N5RvjaF5iCZEQXKmek=; b=SPsvJsoOJGWCNz0MqiQxw/0yRCr5888lfA3TYTSv87ufnSkUZYEsSA86+seIOVYE/Y sEsXwdezlw4T7/8lmU7BopeUocyx8Wa6xwC9agje45+MBpLMpwWv97C8P//JYAbRAGs3 RMmdIo20tOL6WZzNu7HBBNTUuknLwntruhux56ilu09Rfw4I8shyVWz/6m63EEJ+2snF +epCklQ4IYAAnNg7MixSMBYM1fXZ+nXjSTYll1bQtE6q+nwWRrZrh+whLeyFq0aW0EYf K1k/F/sraohhvQlS7WMZtC4lA8lFxZZTPqySYZ/mADZFg1s3OkMfGyw5Am2EyNN2yrYJ NFdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=Y2wlAqtXNyefQseZpanYLfJq3N5RvjaF5iCZEQXKmek=; b=ZANkSLj/4K6blrQHFpFUusp2i/f6o3r+E2cJVH61900FxfAqKPR4jE3dtyEb5bH3sQ lV6TstSJ8+VtsHoOEZB7Dxcu8TUicpwjSm4T0zHfAgnInDEfWgc09ipzPe4odyNXI6za lkKFzLxpv3xyQ3+7/0yhrWEpNZYLpgABCw2MEjnc22tm2FUxYFIGRhex9bhjqabHhvfA mOviEYg/+BrTTLJ2tFqwfSdWtDF5nWXHyM3D/PG3w/LMdfXHsCGXPOLgF3f3PJqoGVb7 vDoHIJ4V9NIu2uJxkZXRxxG2/CLwuVXPkE7FmaIGntASzufezzd2C9zNqAZurE2Put/T VsxA== X-Gm-Message-State: AOAM533ftfTuEZMRmyUo+MuV9q/9tjy6gjuhf+WlPzCoE3THyV46oO/2 cCaMETw/pDcBTFy7P+4P5rs= X-Google-Smtp-Source: ABdhPJxSdvNhMAY02DXO75GE5ykb8GoCQd5VlSAXulERBIog4wwB9uSCtbBQFfL7CZp4YQqpVBmMZw== X-Received: by 2002:a17:90a:930e:: with SMTP id p14mr13005911pjo.49.1600066835157; Mon, 14 Sep 2020 00:00:35 -0700 (PDT) Received: from localhost ([203.185.249.227]) by smtp.gmail.com with ESMTPSA id e2sm7536325pgl.38.2020.09.14.00.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 00:00:34 -0700 (PDT) Date: Mon, 14 Sep 2020 17:00:29 +1000 From: Nicholas Piggin Subject: Re: [PATCH v2 3/4] sparc64: remove mm_cpumask clearing to fix kthread_use_mm race To: linux-mm@kvack.org References: <20200914045219.3736466-1-npiggin@gmail.com> <20200914045219.3736466-4-npiggin@gmail.com> In-Reply-To: <20200914045219.3736466-4-npiggin@gmail.com> MIME-Version: 1.0 Message-Id: <1600066040.vnmz9nxhwt.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , linux-arch@vger.kernel.org, Peter Zijlstra , "Aneesh Kumar K . V" , linux-kernel@vger.kernel.org, sparclinux@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S . Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Excerpts from Nicholas Piggin's message of September 14, 2020 2:52 pm: [...] > The basic fix for sparc64 is to remove its mm_cpumask clearing code. The > optimisation could be effectively restored by sending IPIs to mm_cpumask > members and having them remove themselves from mm_cpumask. This is more > tricky so I leave it as an exercise for someone with a sparc64 SMP. > powerpc has a (currently similarly broken) example. So this compiles and boots on qemu, but qemu does not support any sparc64 machines with SMP. Attempting some simple hacks doesn't get me far because openbios isn't populating an SMP device tree, which blows up everywhere. The patch is _relatively_ simple, hopefully it shouldn't explode, so it's probably ready for testing on real SMP hardware, if someone has a few cycles. Thanks, Nick >=20 > Signed-off-by: Nicholas Piggin > --- > arch/sparc/kernel/smp_64.c | 65 ++++++++------------------------------ > 1 file changed, 14 insertions(+), 51 deletions(-) >=20 > diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c > index e286e2badc8a..e38d8bf454e8 100644 > --- a/arch/sparc/kernel/smp_64.c > +++ b/arch/sparc/kernel/smp_64.c > @@ -1039,38 +1039,9 @@ void smp_fetch_global_pmu(void) > * are flush_tlb_*() routines, and these run after flush_cache_*() > * which performs the flushw. > * > - * The SMP TLB coherency scheme we use works as follows: > - * > - * 1) mm->cpu_vm_mask is a bit mask of which cpus an address > - * space has (potentially) executed on, this is the heuristic > - * we use to avoid doing cross calls. > - * > - * Also, for flushing from kswapd and also for clones, we > - * use cpu_vm_mask as the list of cpus to make run the TLB. > - * > - * 2) TLB context numbers are shared globally across all processors > - * in the system, this allows us to play several games to avoid > - * cross calls. > - * > - * One invariant is that when a cpu switches to a process, and > - * that processes tsk->active_mm->cpu_vm_mask does not have the > - * current cpu's bit set, that tlb context is flushed locally. > - * > - * If the address space is non-shared (ie. mm->count =3D=3D 1) we avo= id > - * cross calls when we want to flush the currently running process's > - * tlb state. This is done by clearing all cpu bits except the curre= nt > - * processor's in current->mm->cpu_vm_mask and performing the > - * flush locally only. This will force any subsequent cpus which run > - * this task to flush the context from the local tlb if the process > - * migrates to another cpu (again). > - * > - * 3) For shared address spaces (threads) and swapping we bite the > - * bullet for most cases and perform the cross call (but only to > - * the cpus listed in cpu_vm_mask). > - * > - * The performance gain from "optimizing" away the cross call for thr= eads is > - * questionable (in theory the big win for threads is the massive sha= ring of > - * address space state across processors). > + * mm->cpu_vm_mask is a bit mask of which cpus an address > + * space has (potentially) executed on, this is the heuristic > + * we use to limit cross calls. > */ > =20 > /* This currently is only used by the hugetlb arch pre-fault > @@ -1080,18 +1051,13 @@ void smp_fetch_global_pmu(void) > void smp_flush_tlb_mm(struct mm_struct *mm) > { > u32 ctx =3D CTX_HWBITS(mm->context); > - int cpu =3D get_cpu(); > =20 > - if (atomic_read(&mm->mm_users) =3D=3D 1) { > - cpumask_copy(mm_cpumask(mm), cpumask_of(cpu)); > - goto local_flush_and_out; > - } > + get_cpu(); > =20 > smp_cross_call_masked(&xcall_flush_tlb_mm, > ctx, 0, 0, > mm_cpumask(mm)); > =20 > -local_flush_and_out: > __flush_tlb_mm(ctx, SECONDARY_CONTEXT); > =20 > put_cpu(); > @@ -1114,17 +1080,15 @@ void smp_flush_tlb_pending(struct mm_struct *mm, = unsigned long nr, unsigned long > { > u32 ctx =3D CTX_HWBITS(mm->context); > struct tlb_pending_info info; > - int cpu =3D get_cpu(); > + > + get_cpu(); > =20 > info.ctx =3D ctx; > info.nr =3D nr; > info.vaddrs =3D vaddrs; > =20 > - if (mm =3D=3D current->mm && atomic_read(&mm->mm_users) =3D=3D 1) > - cpumask_copy(mm_cpumask(mm), cpumask_of(cpu)); > - else > - smp_call_function_many(mm_cpumask(mm), tlb_pending_func, > - &info, 1); > + smp_call_function_many(mm_cpumask(mm), tlb_pending_func, > + &info, 1); > =20 > __flush_tlb_pending(ctx, nr, vaddrs); > =20 > @@ -1134,14 +1098,13 @@ void smp_flush_tlb_pending(struct mm_struct *mm, = unsigned long nr, unsigned long > void smp_flush_tlb_page(struct mm_struct *mm, unsigned long vaddr) > { > unsigned long context =3D CTX_HWBITS(mm->context); > - int cpu =3D get_cpu(); > =20 > - if (mm =3D=3D current->mm && atomic_read(&mm->mm_users) =3D=3D 1) > - cpumask_copy(mm_cpumask(mm), cpumask_of(cpu)); > - else > - smp_cross_call_masked(&xcall_flush_tlb_page, > - context, vaddr, 0, > - mm_cpumask(mm)); > + get_cpu(); > + > + smp_cross_call_masked(&xcall_flush_tlb_page, > + context, vaddr, 0, > + mm_cpumask(mm)); > + > __flush_tlb_page(context, vaddr); > =20 > put_cpu(); > --=20 > 2.23.0 >=20 >=20