Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2349572rdg; Sun, 13 Aug 2023 22:18:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjjZrSnJYFFinc8LQEXTvNwLRcwAPPZwk3HqzW6+/53n/JjlZp/CLQmsdyhD7XxBj4aol/ X-Received: by 2002:a05:6830:1bc3:b0:6bc:8b5f:b616 with SMTP id v3-20020a0568301bc300b006bc8b5fb616mr6938433ota.38.1691990288105; Sun, 13 Aug 2023 22:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691990288; cv=none; d=google.com; s=arc-20160816; b=b4gEJOkjptIZkKsVMuUzJcCTnMw/r3/zXPrMG94FOu3n6h1A2cTCLXt1Tztpu0Q+i4 iRsE7jamN9CjH5ciHdM5bXwWiMsnqt7D8tUtmVbNO5WtJWB1CPouVW8ATbdHLifcO5hJ Ir4Ot1PyatdbQpAAq13OI8LdACYoKU8gQiizJVPdwFW0PDOKO+Xju2u0wFcUPFo7C+dp 6n8WhDlgKbcUVcl4mxW0nVv4rCPiPgR+2NLiaHzgDjXwuz58JYRquLUXk3RFWUr8WBQ7 pvxkFpbc9vnFlGZVqOmj9e7UT9uprOyDmGYpb6L0MeSATVb3JjvbN+2sd11Z22YkMV6Q HWxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=ZC4+OuF9IGlC0dOxilLV3EyrOMOvnSrDuqGVCtZyD8k=; fh=BdCzH6WbfzfY9aXaZ4Ih1+AdO0/YedjAiqR0W/BMCq4=; b=gegv5t0F+MHLcCP0XUknGumWC4rOz6YhwNabO2pc6gFUF6kkagml/ZOb6e3qFi+Y9h psOoAT3r68l79OQRzZNI2Z8gQPkVxqSbBLbLYODzwrCcyTzh2lB1FxrUcO4UFlFdAI/z 6AUxEYG5uzLiRd/HGR+9Kw2nRV9qUVnCUOQyLNofsR+UnDri2/Whsp8AgdXEm2RUBJn0 muEcW/KM6qWYh3tobM/fTM6WapePjnvlvX6qMNodstwuXvEXbgw8PLadqLSGA0SEnYZ5 L8KlsAZL9KLIQemdcyJlihzLdoCTkNrHETHW2e5nHm79V/GX3XCVSpA6JGesuISkUAek 3SFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a17090a7bc500b0024e37ccb3fesi7558160pjl.68.2023.08.13.22.17.55; Sun, 13 Aug 2023 22:18:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbjHNC6c (ORCPT + 99 others); Sun, 13 Aug 2023 22:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232683AbjHNC6Z (ORCPT ); Sun, 13 Aug 2023 22:58:25 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C20E9109 for ; Sun, 13 Aug 2023 19:58:23 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.170]) by gateway (Coremail) with SMTP id _____8DxBfFKmNlkmdoXAA--.49463S3; Mon, 14 Aug 2023 10:58:18 +0800 (CST) Received: from [10.20.42.170] (unknown [10.20.42.170]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxfSNImNlkHEJZAA--.41237S3; Mon, 14 Aug 2023 10:58:17 +0800 (CST) Message-ID: <06cf8750-901d-2f65-fb9e-81980688e017@loongson.cn> Date: Mon, 14 Aug 2023 10:58:16 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 04/10] loongson: Fix idle VS timer enqueue To: Frederic Weisbecker Cc: Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen , WANG Xuerui , LKML , Huacai Chen References: <20230811170049.308866-1-frederic@kernel.org> <20230811170049.308866-5-frederic@kernel.org> Content-Language: en-US From: bibo mao In-Reply-To: <20230811170049.308866-5-frederic@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxfSNImNlkHEJZAA--.41237S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW3WF1rXF4DXF17uFyDZw4fWFX_yoW7XFWfpF WUCwn8Krs5Wrn3Xa47Jw18ur98u34DG3ya9an0yrW8AF4UZr1UXw1vv3s2ga4Yg3y8Gw1S vFn5Xa4293WUA3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y 6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr4 1lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWU JVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4 vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IY x2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8hiSPUUUUU== X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 +Add huacai asm instruction move should be replaced with li.w, the other looks good to me. diff --git a/arch/loongarch/kernel/genex.S b/arch/loongarch/kernel/genex.S index 359d693f112e..8a98023ecafd 100644 --- a/arch/loongarch/kernel/genex.S +++ b/arch/loongarch/kernel/genex.S @@ -19,7 +19,7 @@ .align 5 SYM_FUNC_START(__arch_cpu_idle) /* start of idle interrupt region */ - move t0, CSR_CRMD_IE + li.w t0, CSR_CRMD_IE csrxchg t0, t0, LOONGARCH_CSR_CRMD /* * If an interrupt lands here; between enabling interrupts above and By the way __arch_cpu_idle is called by machine_halt/machine_power_off etc, irq will be enabled with new patch. Need we add something like this? diff --git a/arch/loongarch/kernel/reset.c b/arch/loongarch/kernel/reset.c index 1ef8c6383535..9ecd42c0c804 100644 --- a/arch/loongarch/kernel/reset.c +++ b/arch/loongarch/kernel/reset.c @@ -20,6 +20,11 @@ void (*pm_power_off)(void); EXPORT_SYMBOL(pm_power_off); +static __always_inline void native_halt(void) +{ + asm volatile("idle 0": : :"memory"); +} + void machine_halt(void) { #ifdef CONFIG_SMP @@ -32,9 +37,9 @@ void machine_halt(void) pr_notice("\n\n** You can safely turn off the power now **\n\n"); console_flush_on_panic(CONSOLE_FLUSH_PENDING); - while (true) { - __arch_cpu_idle(); - } + while (1) { + native_halt(); + }; } void machine_power_off(void) @@ -52,9 +57,9 @@ void machine_power_off(void) efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); #endif - while (true) { - __arch_cpu_idle(); - } + while (1) { + native_halt(); + }; } void machine_restart(char *command) @@ -73,7 +78,7 @@ void machine_restart(char *command) if (!acpi_disabled) acpi_reboot(); - while (true) { - __arch_cpu_idle(); - } + while (1) { + native_halt(); + }; } Regards Bibo Mao 在 2023/8/12 01:00, Frederic Weisbecker 写道: > From: Peter Zijlstra > > Loongson re-enables interrupts on its idle routine and performs a > TIF_NEED_RESCHED check afterwards before putting the CPU to sleep. > > The IRQs firing between the check and the idling instruction may set the > TIF_NEED_RESCHED flag. In order to deal with the such a race, IRQs > interrupting __arch_cpu_idle() rollback their return address to the > beginning of __arch_cpu_idle() so that TIF_NEED_RESCHED is checked > again before going back to sleep. > > However idle IRQs can also queue timers that may require a tick > reprogramming through a new generic idle loop iteration but those timers > would go unnoticed here because __arch_cpu_idle() only checks > TIF_NEED_RESCHED. It doesn't check for pending timers. > > Fix this with fast-forwarding idle IRQs return value to the end of the > idle routine instead of the beginning, so that the generic idle loop > handles both TIF_NEED_RESCHED and pending timers. > > Fixes: 0603839b18f4 (LoongArch: Add exception/interrupt handling) > Tested-by: Bibo, Mao > Not-yet-signed-off-by: Peter Zijlstra > Cc: WANG Xuerui > Signed-off-by: Frederic Weisbecker > --- > arch/loongarch/kernel/genex.S | 32 ++++++++++++++++++-------------- > arch/loongarch/kernel/idle.c | 1 - > 2 files changed, 18 insertions(+), 15 deletions(-) > > diff --git a/arch/loongarch/kernel/genex.S b/arch/loongarch/kernel/genex.S > index 78f066384657..359d693f112e 100644 > --- a/arch/loongarch/kernel/genex.S > +++ b/arch/loongarch/kernel/genex.S > @@ -18,27 +18,31 @@ > > .align 5 > SYM_FUNC_START(__arch_cpu_idle) > - /* start of rollback region */ > - LONG_L t0, tp, TI_FLAGS > - nop > - andi t0, t0, _TIF_NEED_RESCHED > - bnez t0, 1f > - nop > - nop > - nop > + /* start of idle interrupt region */ > + move t0, CSR_CRMD_IE > + csrxchg t0, t0, LOONGARCH_CSR_CRMD > + /* > + * If an interrupt lands here; between enabling interrupts above and > + * going idle on the next instruction, we must *NOT* go idle since the > + * interrupt could have set TIF_NEED_RESCHED or caused an timer to need > + * reprogramming. Fall through -- see handle_vint() below -- and have > + * the idle loop take care of things. > + */ > idle 0 > - /* end of rollback region */ > -1: jr ra > + nop > + /* end of idle interrupt region */ > +SYM_INNER_LABEL(__arch_cpu_idle_exit, SYM_L_LOCAL) > + jr ra > SYM_FUNC_END(__arch_cpu_idle) > > SYM_FUNC_START(handle_vint) > BACKUP_T0T1 > SAVE_ALL > - la_abs t1, __arch_cpu_idle > + la_abs t1, __arch_cpu_idle_exit > LONG_L t0, sp, PT_ERA > - /* 32 byte rollback region */ > - ori t0, t0, 0x1f > - xori t0, t0, 0x1f > + /* 16 byte idle interrupt region */ > + ori t0, t0, 0x0f > + addi.d t0, t0, 1 > bne t0, t1, 1f > LONG_S t0, sp, PT_ERA > 1: move a0, sp > diff --git a/arch/loongarch/kernel/idle.c b/arch/loongarch/kernel/idle.c > index 0b5dd2faeb90..5ba72d229920 100644 > --- a/arch/loongarch/kernel/idle.c > +++ b/arch/loongarch/kernel/idle.c > @@ -11,7 +11,6 @@ > > void __cpuidle arch_cpu_idle(void) > { > - raw_local_irq_enable(); > __arch_cpu_idle(); /* idle instruction needs irq enabled */ > raw_local_irq_disable(); > }