Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6278900iob; Tue, 10 May 2022 14:44:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvyC1ndBEikiXeTsSs6j7pGf9U2iiC7CK8p75hrZpLUQpgM/SBOKM3GZ0kU3pJySHp34C+ X-Received: by 2002:a17:90b:4b81:b0:1dc:4dfe:9b01 with SMTP id lr1-20020a17090b4b8100b001dc4dfe9b01mr1894952pjb.110.1652219088015; Tue, 10 May 2022 14:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652219088; cv=none; d=google.com; s=arc-20160816; b=qI6Wtz35qJQMzYY2/iBt6LrzsEtoNNF+tyFD7NnTgaERtTQZkt3jg9g7w6AGX+ynJw scKGMmN1mii5bGN4KF0/pigjBosBmNUSVcD0scWXhix3zJjzq8T/fdwoGPZbH5Aril79 fouv8R7Oi2kM7oeLsgUr5aenwfDbsGbWrCLeS/rZrmvryS3TRVsrcia3zW91wECmfk5W gqiUDod9CccmB3c/MPZh6iwx95S/4p3T+duilQiQNwoNUBUfmKx/rbOU+1iKlKoxkx/v gRLSdPWO5JZekyYkZHhSFb2gbT1xYZkKsON+icRX2P2c2DvJsmde+AVn0Jy86XCbIrdI ZSBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5s3z6+GfLlqgAatexvViqHzNwtTgEjjsFa+9u0mWhM8=; b=Hp9y1KZ1hGwBgo2jr/rZtnBnC/VGGRXVZmlAa9jy9zl0wxqWNQWPQkzRybg/3nRAzE fkHmv4RSrdmkJxFIDZtvoQ2xxn1qz8FeKspQCIg6TQok41COa51NbJWqbFw5zRG4+lJc vd25j2O6Jd7RWHVxnwoj31sr7L2/vfLsXIYC+1EnLq6SMWFB+ghPXBXDLCCvjrfWq9iG 28z05q+KaRgWxkhbCR6GFFT2od9JifQG+5mF6D66aOCcCAenIY4xqiqE98yjhw8/65g8 vmu4eF8etPJm4vYbGv78Ft4/JuohapIYdCKw382bvc5oIdUD7pwP8mfz4VymBHKkw2Ti zl2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SeTYsq9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a170902ef4600b0015e7d5502a8si156178plx.612.2022.05.10.14.44.32; Tue, 10 May 2022 14:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SeTYsq9o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343492AbiEJOSn (ORCPT + 99 others); Tue, 10 May 2022 10:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243896AbiEJNtS (ORCPT ); Tue, 10 May 2022 09:49:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82CBB6FD3D; Tue, 10 May 2022 06:37:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E0F1CB81DAB; Tue, 10 May 2022 13:37:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D5BC385C2; Tue, 10 May 2022 13:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189827; bh=RIK5MElVo47bD1tsF8v3qbeY9yUwA6PQltPBj+Q7u+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SeTYsq9ooa/QinIXIJbC/MhXaLprlqzrzVnNZ6hYtBm2lb6OZ6wp0ZDATySAhdqWV vi0KM2p4jHaWrsPY1RLi1fbFOrJj0jBqlEiH8nPqAqgvx7ALPyCs1SL6GHiQ0DFdsf /VybVptkkbOu39YRNZNcuQn0tnKmgoa6TMwB9e6s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Maciej W. Rozycki" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Bogendoerfer Subject: [PATCH 5.17 004/140] MIPS: Fix CP0 counter erratum detection for R4k CPUs Date: Tue, 10 May 2022 15:06:34 +0200 Message-Id: <20220510130741.729581715@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130741.600270947@linuxfoundation.org> References: <20220510130741.600270947@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maciej W. Rozycki commit f0a6c68f69981214cb7858738dd2bc81475111f7 upstream. Fix the discrepancy between the two places we check for the CP0 counter erratum in along with the incorrect comparison of the R4400 revision number against 0x30 which matches none and consistently consider all R4000 and R4400 processors affected, as documented in processor errata publications[1][2][3], following the mapping between CP0 PRId register values and processor models: PRId | Processor Model ---------+-------------------- 00000422 | R4000 Revision 2.2 00000430 | R4000 Revision 3.0 00000440 | R4400 Revision 1.0 00000450 | R4400 Revision 2.0 00000460 | R4400 Revision 3.0 No other revision of either processor has ever been spotted. Contrary to what has been stated in commit ce202cbb9e0b ("[MIPS] Assume R4000/R4400 newer than 3.0 don't have the mfc0 count bug") marking the CP0 counter as buggy does not preclude it from being used as either a clock event or a clock source device. It just cannot be used as both at a time, because in that case clock event interrupts will be occasionally lost, and the use as a clock event device takes precedence. Compare against 0x4ff in `can_use_mips_counter' so that a single machine instruction is produced. [1] "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0", MIPS Technologies Inc., May 10, 1994, Erratum 53, p.13 [2] "MIPS R4400PC/SC Errata, Processor Revision 1.0", MIPS Technologies Inc., February 9, 1994, Erratum 21, p.4 [3] "MIPS R4400PC/SC Errata, Processor Revision 2.0 & 3.0", MIPS Technologies Inc., January 24, 1995, Erratum 14, p.3 Signed-off-by: Maciej W. Rozycki Fixes: ce202cbb9e0b ("[MIPS] Assume R4000/R4400 newer than 3.0 don't have the mfc0 count bug") Cc: stable@vger.kernel.org # v2.6.24+ Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Thomas Bogendoerfer Signed-off-by: Greg Kroah-Hartman --- arch/mips/include/asm/timex.h | 8 ++++---- arch/mips/kernel/time.c | 11 +++-------- 2 files changed, 7 insertions(+), 12 deletions(-) --- a/arch/mips/include/asm/timex.h +++ b/arch/mips/include/asm/timex.h @@ -40,9 +40,9 @@ typedef unsigned int cycles_t; /* - * On R4000/R4400 before version 5.0 an erratum exists such that if the - * cycle counter is read in the exact moment that it is matching the - * compare register, no interrupt will be generated. + * On R4000/R4400 an erratum exists such that if the cycle counter is + * read in the exact moment that it is matching the compare register, + * no interrupt will be generated. * * There is a suggested workaround and also the erratum can't strike if * the compare interrupt isn't being used as the clock source device. @@ -63,7 +63,7 @@ static inline int can_use_mips_counter(u if (!__builtin_constant_p(cpu_has_counter)) asm volatile("" : "=m" (cpu_data[0].options)); if (likely(cpu_has_counter && - prid >= (PRID_IMP_R4000 | PRID_REV_ENCODE_44(5, 0)))) + prid > (PRID_IMP_R4000 | PRID_REV_ENCODE_44(15, 15)))) return 1; else return 0; --- a/arch/mips/kernel/time.c +++ b/arch/mips/kernel/time.c @@ -141,15 +141,10 @@ static __init int cpu_has_mfc0_count_bug case CPU_R4400MC: /* * The published errata for the R4400 up to 3.0 say the CPU - * has the mfc0 from count bug. + * has the mfc0 from count bug. This seems the last version + * produced. */ - if ((current_cpu_data.processor_id & 0xff) <= 0x30) - return 1; - - /* - * we assume newer revisions are ok - */ - return 0; + return 1; } return 0;