Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp762072pxu; Wed, 2 Dec 2020 02:44:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7DhJ57aN1WYl2M7a2l545Tgos/GxNAu4qqAcPHSTdnW5xpDJYJqLXf8EBCEkYcr8L8MF9 X-Received: by 2002:a17:906:1294:: with SMTP id k20mr1669837ejb.404.1606905870047; Wed, 02 Dec 2020 02:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606905870; cv=none; d=google.com; s=arc-20160816; b=YB/IgDvSdqE6hhRgpnBD9pNrAZmsHLgeQUeHeC26gnc3D8TaJFtxV8s9vzwzp5KKfT IplWHivJv93R3CpVRHqXfj5HvOTRJJic0/yXCjAx+/r4PLguHUbCM6BJ6vYaXATpbaw1 xfVWzxVksH50Nr/xvmqwz2/tKNDxZ+eJMvSc7dZYnPXvFnVOYMaLDk0mk8+iI8DYWUa6 Ugzb5nFkl1eNgFpBO/KjpJEjUySr2SOqy/g3eUwMzVwlNWY/yqbX/UEn/ovu7GGL6R8s DbflbHYqvMGJqR8I/djTyEeUZqJmorAku9+e1pYX3DGhHiTdzipIincTxrG+EF37uXZ9 LM3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=XtZ17djJb7T+4KeefDiHCJ6rUrdy9CcbUak5XTHTBSA=; b=LCooCEt/LTYhyoY9OoQXJ7YHIltmiLbyhkdJiUA9InGlX9ZDNnoF9bK98fF0DnGNPd 69phgY7SrAoVvFFE6TZjeNTmArH3k/4kJ+CPEMkrIMtkfefrvMZ4P54osO9JSMQc5iUK R/GKlnurI6GLZ5hjZu1tE4NtfNAR5kU3fiT2EV38kUT5gAQ1IgE4+fDhOy0abLyni7HI MX4Qm5PD43u3K2m8ucIYduInwd3gg5BWhhl4wwm10/1wFTklb2dMTQzWz+K56vEShxsm 1VzIglY0pNt6UqYjmcuY8LZhEtHHNcIpDavxk+goHAP0CcULGQHwqp9irhWTeLqR3D2h 0AoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx19si599163ejb.535.2020.12.02.02.44.05; Wed, 02 Dec 2020 02:44:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388607AbgLBKky (ORCPT + 99 others); Wed, 2 Dec 2020 05:40:54 -0500 Received: from elvis.franken.de ([193.175.24.41]:43109 "EHLO elvis.franken.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729412AbgLBKky (ORCPT ); Wed, 2 Dec 2020 05:40:54 -0500 Received: from uucp (helo=alpha) by elvis.franken.de with local-bsmtp (Exim 3.36 #1) id 1kkPYR-0001YK-00; Wed, 02 Dec 2020 11:40:11 +0100 Received: by alpha.franken.de (Postfix, from userid 1000) id 54174C02B7; Wed, 2 Dec 2020 11:39:43 +0100 (CET) Date: Wed, 2 Dec 2020 11:39:43 +0100 From: Thomas Bogendoerfer To: Jinyang He Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] MIPS: KASLR: Fix sync_icache() trapped in loop when synci_step is zero Message-ID: <20201202103943.GA9065@alpha.franken.de> References: <1606878005-11427-1-git-send-email-hejinyang@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1606878005-11427-1-git-send-email-hejinyang@loongson.cn> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 02, 2020 at 11:00:05AM +0800, Jinyang He wrote: > Reading synci_step by using rdhwr instruction may return zero if no cache > need be synchronized. On the one hand, to make sure all load operation and > store operation finished we do __sync() for every platform. On the other > hand, some platform need operate synci one time although step is zero. Should this be someting like: Avoid endless loop, if no synci is needed ? > diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c > index 57bdd276..47aeb33 100644 > --- a/arch/mips/kernel/relocate.c > +++ b/arch/mips/kernel/relocate.c > @@ -64,7 +64,7 @@ static void __init sync_icache(void *kbase, unsigned long kernel_length) > : "r" (kbase)); > > kbase += step; > - } while (kbase < kend); > + } while (step && kbase < kend); why not do a if (step == 0) return; before entering the loop ? According to MIPS32PRA no synci is needed, if stepi value is zero. Thomas. PS: Does anybody know a reason, why this code doesn't use an old fashioned dache/icache flushing, which might be slower but would work also on legecy cores ? -- Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]