Received: by 10.213.65.68 with SMTP id h4csp662811imn; Fri, 6 Apr 2018 06:59:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx498UrveUrpgCTC1kzGMP7kmkZ9xRZZYuyH9hHQq8LNZ2fZHVwneSu1LLD7CSaU0MNTL1Ucx X-Received: by 10.98.66.203 with SMTP id h72mr20523147pfd.156.1523023163174; Fri, 06 Apr 2018 06:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523023163; cv=none; d=google.com; s=arc-20160816; b=kKKumctZ4dQUKkC5y6uI/5CzIQYxNj8FSDF/mD5V8w4dmzPzyLh6Z1pePgNyerUq80 Vh2ZSUNoG1knPnkM9DS8GghiSs4gYCjND1aA6DpU+e45TTcfZ+ZSHl1urnYEgNCEv2I1 rh8Oe/z57TtY6Mf+rxtvxFIVNqhaAIDCxdeUO5aHWpG12oDQu6CG/xF7GEg2l13pu5ij Jnpd7rLX6u+YY4HVoElBDRyQHdMCbIqS+Uc8tcjPKas7+V5BofDHthr+rKvj6R1xCprU kKkq9YIFBoMI0k0T9ggUP0nBH5uNhek1cwIhbFVnJKdf2m6FqztU4HnN0Vl78ZWrP4Lm xj1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jYLBp0sA7Iouy2fFfg312c2YV9KKSSOWAPdKk71iJhY=; b=at1kno2eL314jzLjG/08Wul+8pmE8izOF2BIIF5wMGuV4hRVPxj0Vizhlv4KK8iPcd QEPNhZP+cTps01u2VlB8jku7BnaFpF06IfuqVMh6aBdJ1nFZ1ivDNlfPKgNNvXZg5juo at4zXeHkU7C/5kpRAN9Qbfqc4B8Z9w9fx28VHJy9RM5bM64mpvS3+wimbRsoTLwN1Ldy CP+UmcGamQV1NgHiFWjxWqN6ACYq3Toa5B7G2go2m/Ccuy7AoOO9PJO1P0mncC3ZQYnQ BJqIPJFLjr431vSVPVwEfik5TmyWT6c2G6unv2S7Y4lrjLcYNjVdcqPtseygTw36MKIg 5kew== 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 q7-v6si6420375plk.129.2018.04.06.06.59.09; Fri, 06 Apr 2018 06:59:23 -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 S1756689AbeDFNnL (ORCPT + 99 others); Fri, 6 Apr 2018 09:43:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37220 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756672AbeDFNnJ (ORCPT ); Fri, 6 Apr 2018 09:43:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6139EDCF; Fri, 6 Apr 2018 13:43:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Herrenschmidt , Balbir Singh , Michael Ellerman Subject: [PATCH 4.15 15/72] powerpc/mm: Add tracking of the number of coprocessors using a context Date: Fri, 6 Apr 2018 15:23:50 +0200 Message-Id: <20180406084350.742056111@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084349.367583460@linuxfoundation.org> References: <20180406084349.367583460@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Herrenschmidt commit aff6f8cb3e2170b9e58b0932bce7bfb492775e23 upstream. Currently, when using coprocessors (which use the Nest MMU), we simply increment the active_cpu count to force all TLB invalidations to be come broadcast. Unfortunately, due to an errata in POWER9, we will need to know more specifically that coprocessors are in use. This maintains a separate copros counter in the MMU context for that purpose. NB. The commit mentioned in the fixes tag below is not at fault for the bug we're fixing in this commit and the next, but this fix applies on top the infrastructure it introduced. Fixes: 03b8abedf4f4 ("cxl: Enable global TLBIs for cxl contexts") Cc: stable@vger.kernel.org # v4.15+ Signed-off-by: Benjamin Herrenschmidt Tested-by: Balbir Singh Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/book3s/64/mmu.h | 3 +++ arch/powerpc/include/asm/mmu_context.h | 18 +++++++++++++----- arch/powerpc/mm/mmu_context_book3s64.c | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) --- a/arch/powerpc/include/asm/book3s/64/mmu.h +++ b/arch/powerpc/include/asm/book3s/64/mmu.h @@ -87,6 +87,9 @@ typedef struct { /* Number of bits in the mm_cpumask */ atomic_t active_cpus; + /* Number of users of the external (Nest) MMU */ + atomic_t copros; + /* NPU NMMU context */ struct npu_context *npu_context; --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -92,15 +92,23 @@ static inline void dec_mm_active_cpus(st static inline void mm_context_add_copro(struct mm_struct *mm) { /* - * On hash, should only be called once over the lifetime of - * the context, as we can't decrement the active cpus count - * and flush properly for the time being. + * If any copro is in use, increment the active CPU count + * in order to force TLB invalidations to be global as to + * propagate to the Nest MMU. */ - inc_mm_active_cpus(mm); + if (atomic_inc_return(&mm->context.copros) == 1) + inc_mm_active_cpus(mm); } static inline void mm_context_remove_copro(struct mm_struct *mm) { + int c; + + c = atomic_dec_if_positive(&mm->context.copros); + + /* Detect imbalance between add and remove */ + WARN_ON(c < 0); + /* * Need to broadcast a global flush of the full mm before * decrementing active_cpus count, as the next TLBI may be @@ -111,7 +119,7 @@ static inline void mm_context_remove_cop * for the time being. Invalidations will remain global if * used on hash. */ - if (radix_enabled()) { + if (c == 0 && radix_enabled()) { flush_all_mm(mm); dec_mm_active_cpus(mm); } --- a/arch/powerpc/mm/mmu_context_book3s64.c +++ b/arch/powerpc/mm/mmu_context_book3s64.c @@ -171,6 +171,7 @@ int init_new_context(struct task_struct mm_iommu_init(mm); #endif atomic_set(&mm->context.active_cpus, 0); + atomic_set(&mm->context.copros, 0); return 0; }