Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7150794ybi; Mon, 8 Jul 2019 15:40:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuDiKCxi1YOuQam1Rkox+iWdeVwFQTbMosQnhyr9CdxDvUvhJAeDh7er3G1EuApqBC+hm5 X-Received: by 2002:a65:4808:: with SMTP id h8mr26256811pgs.22.1562625607183; Mon, 08 Jul 2019 15:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625607; cv=none; d=google.com; s=arc-20160816; b=hXyMXI+b03EYAuORzRLodieV2SbE0WVfpRr/+8kqiH5aoPrB8s3Yh+e9/x8f6KPKla PsV7kORHLRDlDicLE+0fZFV4bV95bKJhquocQ4jqs9S/adt1OwtiAGiRCHNxjCZQ+Ntl zyIVOMxRJss8wZl3CV4Plargtt8GNaGIJ8h0UCmM9dUos56lHOapyPAgs1R3Hbr51eEW 0X3XxZlQ8zRdZFi6NnfkPic77sIEoVJPjpG6kryAD9cXAVrzlyFFj+H+u20p3WvEPTrd kSPv6ZOY4QszGv5C9H3EzPuLTSqkNfNUsi0OfxwAk2jV1pyJfxJwSkYXxpetGqrvAW4/ GadA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OgPtfSMMa8KoKofcyWvPCab741Gj5dTZiqwy8uYA+tY=; b=oG6HpwnHQw/Fgi0CmLm9zDtIlV9XPrl/NJoMFh1WigCZEKyOrbsIQ4V35Q/Rz+BzQy 5QM663wLl+n4qyG32j9k5nklVTlTx38+Mg8OFNMyveJmcm4Q7cdN+Gv+oXN3Dvv77/od Fy6mjHdVefDiXssIS5JXKyEdHE8K6uGIineEl3/xeApFSdQSd1gGCiKVvxqlXbjzEG8y U9qurOWbSiI1auDGmu4DWWyYnQPR2ct/wWlCSrtx7RLGALyLrHXCZ7aeVDvnYqi2G/HE zUAms0TYUjh1B0V+2EqCtOwaRIAKVRmfy8t7J+rPspGdFeZILs7bbEy7giArnPATx/HA FAjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kv1jbgMc; 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 q1si18443256pll.324.2019.07.08.15.39.52; Mon, 08 Jul 2019 15:40:07 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Kv1jbgMc; 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 S2390617AbfGHPfq (ORCPT + 99 others); Mon, 8 Jul 2019 11:35:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:37546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390885AbfGHPfG (ORCPT ); Mon, 8 Jul 2019 11:35:06 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC12F20665; Mon, 8 Jul 2019 15:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600105; bh=aw3R7eOnBAmNqbUhTp0UkZa3L8zcJ/9lggnLn8268MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kv1jbgMcPR2Cwd5EF57X74PX3FEPdoKpIrEKbocXxYEo74zcdO5VDYBi9O12tR9om fKw+yx43066aSh/p7TLs4ZEE36FRYKhYM0edU5sGBEq1eN5R2mRQpevklISU/VMv08 93O0xfkJCsUGZA94NCFsYQD7u53DR1DUUO7wix48= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Korotin , Paul Burton , linux-mips@vger.kernel.org Subject: [PATCH 5.1 90/96] MIPS: Add missing EHB in mtc0 -> mfc0 sequence. Date: Mon, 8 Jul 2019 17:14:02 +0200 Message-Id: <20190708150531.301538782@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Korotin commit 0b24cae4d535045f4c9e177aa228d4e97bad212c upstream. Add a missing EHB (Execution Hazard Barrier) in mtc0 -> mfc0 sequence. Without this execution hazard barrier it's possible for the value read back from the KScratch register to be the value from before the mtc0. Reproducible on P5600 & P6600. The hazard is documented in the MIPS Architecture Reference Manual Vol. III: MIPS32/microMIPS32 Privileged Resource Architecture (MD00088), rev 6.03 table 8.1 which includes: Producer | Consumer | Hazard ----------|----------|---------------------------- mtc0 | mfc0 | any coprocessor 0 register Signed-off-by: Dmitry Korotin [paul.burton@mips.com: - Commit message tweaks. - Add Fixes tags. - Mark for stable back to v3.15 where P5600 support was introduced.] Signed-off-by: Paul Burton Fixes: 3d8bfdd03072 ("MIPS: Use C0_KScratch (if present) to hold PGD pointer.") Fixes: 829dcc0a956a ("MIPS: Add MIPS P5600 probe support") Cc: linux-mips@vger.kernel.org Cc: stable@vger.kernel.org # v3.15+ Signed-off-by: Greg Kroah-Hartman --- arch/mips/mm/tlbex.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) --- a/arch/mips/mm/tlbex.c +++ b/arch/mips/mm/tlbex.c @@ -391,6 +391,7 @@ static struct work_registers build_get_w static void build_restore_work_registers(u32 **p) { if (scratch_reg >= 0) { + uasm_i_ehb(p); UASM_i_MFC0(p, 1, c0_kscratch(), scratch_reg); return; } @@ -668,10 +669,12 @@ static void build_restore_pagemask(u32 * uasm_i_mtc0(p, 0, C0_PAGEMASK); uasm_il_b(p, r, lid); } - if (scratch_reg >= 0) + if (scratch_reg >= 0) { + uasm_i_ehb(p); UASM_i_MFC0(p, 1, c0_kscratch(), scratch_reg); - else + } else { UASM_i_LW(p, 1, scratchpad_offset(0), 0); + } } else { /* Reset default page size */ if (PM_DEFAULT_MASK >> 16) { @@ -938,10 +941,12 @@ build_get_pgd_vmalloc64(u32 **p, struct uasm_i_jr(p, ptr); if (mode == refill_scratch) { - if (scratch_reg >= 0) + if (scratch_reg >= 0) { + uasm_i_ehb(p); UASM_i_MFC0(p, 1, c0_kscratch(), scratch_reg); - else + } else { UASM_i_LW(p, 1, scratchpad_offset(0), 0); + } } else { uasm_i_nop(p); } @@ -1258,6 +1263,7 @@ build_fast_tlb_refill_handler (u32 **p, UASM_i_MTC0(p, odd, C0_ENTRYLO1); /* load it */ if (c0_scratch_reg >= 0) { + uasm_i_ehb(p); UASM_i_MFC0(p, scratch, c0_kscratch(), c0_scratch_reg); build_tlb_write_entry(p, l, r, tlb_random); uasm_l_leave(l, *p); @@ -1603,15 +1609,17 @@ static void build_setup_pgd(void) uasm_i_dinsm(&p, a0, 0, 29, 64 - 29); uasm_l_tlbl_goaround1(&l, p); UASM_i_SLL(&p, a0, a0, 11); - uasm_i_jr(&p, 31); UASM_i_MTC0(&p, a0, C0_CONTEXT); + uasm_i_jr(&p, 31); + uasm_i_ehb(&p); } else { /* PGD in c0_KScratch */ - uasm_i_jr(&p, 31); if (cpu_has_ldpte) UASM_i_MTC0(&p, a0, C0_PWBASE); else UASM_i_MTC0(&p, a0, c0_kscratch(), pgd_reg); + uasm_i_jr(&p, 31); + uasm_i_ehb(&p); } #else #ifdef CONFIG_SMP @@ -1625,13 +1633,16 @@ static void build_setup_pgd(void) UASM_i_LA_mostly(&p, a2, pgdc); UASM_i_SW(&p, a0, uasm_rel_lo(pgdc), a2); #endif /* SMP */ - uasm_i_jr(&p, 31); /* if pgd_reg is allocated, save PGD also to scratch register */ - if (pgd_reg != -1) + if (pgd_reg != -1) { UASM_i_MTC0(&p, a0, c0_kscratch(), pgd_reg); - else + uasm_i_jr(&p, 31); + uasm_i_ehb(&p); + } else { + uasm_i_jr(&p, 31); uasm_i_nop(&p); + } #endif if (p >= (u32 *)tlbmiss_handler_setup_pgd_end) panic("tlbmiss_handler_setup_pgd space exceeded");