Received: by 10.213.65.68 with SMTP id h4csp646746imn; Fri, 6 Apr 2018 06:42:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4++NcdIfCNP9XQTAXZRyRBR5wvFyTdElfsB1apWxjZRCwE00kKyKLsHj8cwNXEQHlMwEP/g X-Received: by 2002:a17:902:bb87:: with SMTP id m7-v6mr27779392pls.103.1523022177436; Fri, 06 Apr 2018 06:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022177; cv=none; d=google.com; s=arc-20160816; b=BevCDMIo1ELLciBVWCv89OcZJkgg3pD99u5IGhtp6J1UwajcT49DifNkqOuAtYtHrC uutWVwcYtUGEXqXn59Cx7pZmJzgeYMJwIetHMxKocQauqLVvPFxHujO8aqOC3t2cHFfh gfcs09zoGJui1EIsau59hguS9g787jUD0bHkmX0QfcFRaaMVvhn6v+KamGZULf2Zw/TE t23TzFbqYS80s7cFdXxl2fpHG3k5kGEIu9x/2YxxYl4sFmLLKOdrTkEEUnH2nGV3hfqW Pr+NvLesR1silLDn4TYtekQ+zHu3er05IWo9VX2jMgCg7IVTDXFEWqhJyOP11UxCS/Va sYZA== 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=ki5hG4jSZc/xUhF00IgL28+l3isLRZdMtAx6w1eHw64=; b=wgC4jT9w8TdOfxVvQ4aLcVlB7o/cA5XrZiMHsk4X9S1C+9FCF0TmD75SPnkOLXry3t 74IpOhfsmqStIIeIpPzOxFDgVZRc/UQRuFvkNU5/RvOpadM7DfoNeM5D9utTNmMfnSgv /ZpjBtVFe91k4QmmoMZHbyQL/6SbtlvEo5I0It0FdTjKowI6Ep22uWxC3kfnkFHUj210 t72HiWfufBIlA/bMP6jCKbdqpqTNgW7ZqPqv/riv3WYXeMGNypmZm5ytHPNlSjbRPLX+ c0H8n5VAONN4lw9CjtSekR0Gejd7YT1DZXe6oXJ1kaLWbsNOV/IUII2p55H0+qPuh+ge 0jjA== 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 9-v6si6648491plf.283.2018.04.06.06.42.43; Fri, 06 Apr 2018 06:42:57 -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 S932899AbeDFNlc (ORCPT + 99 others); Fri, 6 Apr 2018 09:41:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36282 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932881AbeDFNl3 (ORCPT ); Fri, 6 Apr 2018 09:41:29 -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 D50D5DFC; Fri, 6 Apr 2018 13:41:28 +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 16/72] powerpc/mm: Workaround Nest MMU bug with TLB invalidations Date: Fri, 6 Apr 2018 15:23:51 +0200 Message-Id: <20180406084350.809452852@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 80a4ae202f2d319eced8bbf612a4e8b0f11c21f5 upstream. On POWER9 the Nest MMU may fail to invalidate some translations when doing a tlbie "by PID" or "by LPID" that is targeted at the TLB only and not the page walk cache. This works around it by forcing such invalidations to escalate to RIC=2 (full invalidation of TLB *and* PWC) when a coprocessor is in use for the context. Fixes: 03b8abedf4f4 ("cxl: Enable global TLBIs for cxl contexts") Cc: stable@vger.kernel.org # v4.15+ Signed-off-by: Benjamin Herrenschmidt Signed-off-by: Balbir Singh [balbirs: fixed spelling and coding style to quiesce checkpatch.pl] Tested-by: Balbir Singh Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/mm/tlb-radix.c | 50 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) --- a/arch/powerpc/mm/tlb-radix.c +++ b/arch/powerpc/mm/tlb-radix.c @@ -85,7 +85,23 @@ static inline void _tlbiel_pid(unsigned static inline void _tlbie_pid(unsigned long pid, unsigned long ric) { asm volatile("ptesync": : :"memory"); - __tlbie_pid(pid, ric); + + /* + * Workaround the fact that the "ric" argument to __tlbie_pid + * must be a compile-time contraint to match the "i" constraint + * in the asm statement. + */ + switch (ric) { + case RIC_FLUSH_TLB: + __tlbie_pid(pid, RIC_FLUSH_TLB); + break; + case RIC_FLUSH_PWC: + __tlbie_pid(pid, RIC_FLUSH_PWC); + break; + case RIC_FLUSH_ALL: + default: + __tlbie_pid(pid, RIC_FLUSH_ALL); + } asm volatile("eieio; tlbsync; ptesync": : :"memory"); } @@ -245,6 +261,16 @@ void radix__local_flush_tlb_page(struct } EXPORT_SYMBOL(radix__local_flush_tlb_page); +static bool mm_needs_flush_escalation(struct mm_struct *mm) +{ + /* + * P9 nest MMU has issues with the page walk cache + * caching PTEs and not flushing them properly when + * RIC = 0 for a PID/LPID invalidate + */ + return atomic_read(&mm->context.copros) != 0; +} + #ifdef CONFIG_SMP void radix__flush_tlb_mm(struct mm_struct *mm) { @@ -255,9 +281,12 @@ void radix__flush_tlb_mm(struct mm_struc return; preempt_disable(); - if (!mm_is_thread_local(mm)) - _tlbie_pid(pid, RIC_FLUSH_TLB); - else + if (!mm_is_thread_local(mm)) { + if (mm_needs_flush_escalation(mm)) + _tlbie_pid(pid, RIC_FLUSH_ALL); + else + _tlbie_pid(pid, RIC_FLUSH_TLB); + } else _tlbiel_pid(pid, RIC_FLUSH_TLB); preempt_enable(); } @@ -369,10 +398,14 @@ void radix__flush_tlb_range(struct vm_ar } if (full) { - if (local) + if (local) { _tlbiel_pid(pid, RIC_FLUSH_TLB); - else - _tlbie_pid(pid, RIC_FLUSH_TLB); + } else { + if (mm_needs_flush_escalation(mm)) + _tlbie_pid(pid, RIC_FLUSH_ALL); + else + _tlbie_pid(pid, RIC_FLUSH_TLB); + } } else { bool hflush = false; unsigned long hstart, hend; @@ -482,6 +515,9 @@ static inline void __radix__flush_tlb_ra } if (full) { + if (!local && mm_needs_flush_escalation(mm)) + also_pwc = true; + if (local) _tlbiel_pid(pid, also_pwc ? RIC_FLUSH_ALL : RIC_FLUSH_TLB); else