From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13ECEC433E0 for ; Thu, 21 Jan 2021 11:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE10D238E3 for ; Thu, 21 Jan 2021 11:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730453AbhAULiw (ORCPT ); Thu, 21 Jan 2021 06:38:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:46498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730494AbhAULhZ (ORCPT ); Thu, 21 Jan 2021 06:37:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2ACDE238E3 for ; Thu, 21 Jan 2021 11:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611229004; bh=c529Zol8CrTx09rGLG9vb4AaNRN7sUXHBfb+tqUL5MY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mEvdBxSG/7amt+sKn2Q1wq1sPflHn926i7nyiiRyAkWRFcHnbimMg8Uk8F/6vL0vo qeOtGo/Zic34NUQMOvA+qmh4foSscCFozVEExkoqTiCBXKdYu7KVSrNLx6J6BlF6T7 Cb83geiXehlxGT9iAageUhbBdb9ZQbW1WON7gTtLglAHgrvYc0FqZ+1ivBhmg+pVmA 3HV0RRpcSSMGieqFXlATlcJZGjJ5R9roAlNJPIAlM6iVZwsuIolH9DyCyFEcESRJMk CTfI/t0GRtY6FlP4fDJzjXLw9vPoiddQMJrm7al+yZ8t0tXpl9jSvPxdqQ/VVY5241 xxQe+ZPt4N4LA== Received: by mail-ot1-f49.google.com with SMTP id d1so1248724otl.13 for ; Thu, 21 Jan 2021 03:36:44 -0800 (PST) X-Gm-Message-State: AOAM531XUadGs1Z+ctQonWxjVnBOuCBPm7j/C/xZUe9+yftJruKrhNS5 Pb4ojV+fG5qIpbci3BugMkek1holk50naYjK1nU= X-Google-Smtp-Source: ABdhPJwdzyxsACQknRLgT5ZX9OB8pFKd5fhZA/phme9eP8yz9udQHOBHLjD6RhXwelSq6oIk0+3jLAW0I9mtZ8jL7c0= X-Received: by 2002:a05:6830:139a:: with SMTP id d26mr10125507otq.305.1611229003319; Thu, 21 Jan 2021 03:36:43 -0800 (PST) MIME-Version: 1.0 References: <20210120132717.395873-1-mohamed.mediouni@caramail.com> <20210120132717.395873-3-mohamed.mediouni@caramail.com> <5403A355-A4FA-442B-8F8B-5629FCECC006@caramail.com> In-Reply-To: <5403A355-A4FA-442B-8F8B-5629FCECC006@caramail.com> From: Arnd Bergmann Date: Thu, 21 Jan 2021 12:36:27 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 2/7] arm64: kernel: Add a WFI hook. To: Mohamed Mediouni Cc: Linux ARM , Mark Rutland , Catalin Marinas , Hector Martin , "linux-kernel@vger.kernel.org" , Marc Zyngier , Will Deacon , Stan Skowronek Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 21, 2021 at 12:01 PM Mohamed Mediouni wrote: > > On 21 Jan 2021, at 11:52, Arnd Bergmann wrote: > > > > On Wed, Jan 20, 2021 at 2:27 PM Mohamed Mediouni > > wrote: > >> --- a/arch/arm64/kernel/cpu_ops.c > >> +++ b/arch/arm64/kernel/cpu_ops.c > > > >> #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK) > >> #include > >> @@ -74,8 +75,14 @@ void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); > >> > >> static void noinstr __cpu_do_idle(void) > >> { > >> - dsb(sy); > >> - wfi(); > >> + const struct cpu_operations *ops = get_cpu_ops(task_cpu(current)); > >> + > >> + if (ops->cpu_wfi) { > >> + ops->cpu_wfi(); > >> + } else { > >> + dsb(sy); > >> + wfi(); > >> + } > >> } > > > > I think the correct place to put this would be a platform specific driver > > in drivers/cpuidle/ instead of an added low-level callback in the > > default idle function and a custom cpu_operations structure. > > Can we make sure that wfi never gets called even on early > boot when using a cpuidle driver? Good question, I don't know what all the possible call sites are for this, but if there is nothing else works (such as what Alex suggested), it may be possible to just patch out the wfi instruction here and do a busy loop until the cpuidle driver has come up. The main issue here is the existence of the custom cpu_operations in the first place: I don't think we want or need the custom start_secondary at the moment (as commented in the other patch), but then there is no obvious place to put the custom wfi. Note that there are a few other uses of the wfi instruction besides the one in __cpu_do_idle(), so whatever you do here may also apply to the others. arch/arm64/include/asm/smp.h: wfi(); arch/arm64/kernel/head.S: wfi arch/arm64/kernel/head.S: wfi arch/arm64/kernel/head.S: wfi arch/arm64/kernel/process.c: wfi(); arch/arm64/kvm/hyp/nvhe/hyp-init.S: wfi Arnd From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F18F5C433DB for ; Thu, 21 Jan 2021 11:38:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8729420637 for ; Thu, 21 Jan 2021 11:38:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8729420637 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=K4iBxqdqDthcYtBAAAYLUryprmw1/pvH2MJ4cftbwns=; b=W4mKBOhZNYPO3LFT/iktPHkMu v9KJwY+DTc0XTAyjR6mCyC4wXoYaKx/2RpGP+Lr6SoSRQJuB7ra8w2ql66f6YLqJKpQPgTiGR0Kut 9JUGohVuepV+6tqPswQqLmhykfu8kVt8StA6eeIoJl9BU73lwOZo7KjFMlJVzaSPVERlZtqpEzjZ+ dCdJrHWi+LCzjI4RnvH+DPLTSzXTjgNohYEAPk+Or45rcvjRTaomL6SiAsGKNe5oqo1iHvZMl9gOJ OsGwYd+weoqO7eUslkMYn5AchdOQq83aJkM7A77pV8W2rRYNuR/E0AEv47kL+fU9qXIEKy7YjgQm9 ZGuMB024w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2YGd-0004E5-9L; Thu, 21 Jan 2021 11:36:47 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2YGb-0004DE-C9 for linux-arm-kernel@lists.infradead.org; Thu, 21 Jan 2021 11:36:46 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1CA4E2222B for ; Thu, 21 Jan 2021 11:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611229004; bh=c529Zol8CrTx09rGLG9vb4AaNRN7sUXHBfb+tqUL5MY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mEvdBxSG/7amt+sKn2Q1wq1sPflHn926i7nyiiRyAkWRFcHnbimMg8Uk8F/6vL0vo qeOtGo/Zic34NUQMOvA+qmh4foSscCFozVEExkoqTiCBXKdYu7KVSrNLx6J6BlF6T7 Cb83geiXehlxGT9iAageUhbBdb9ZQbW1WON7gTtLglAHgrvYc0FqZ+1ivBhmg+pVmA 3HV0RRpcSSMGieqFXlATlcJZGjJ5R9roAlNJPIAlM6iVZwsuIolH9DyCyFEcESRJMk CTfI/t0GRtY6FlP4fDJzjXLw9vPoiddQMJrm7al+yZ8t0tXpl9jSvPxdqQ/VVY5241 xxQe+ZPt4N4LA== Received: by mail-ot1-f41.google.com with SMTP id v1so1263445ott.10 for ; Thu, 21 Jan 2021 03:36:44 -0800 (PST) X-Gm-Message-State: AOAM530/Igx8SKppPjSnahHVMMQQPihejZKzPQSLvqpyNvgMBrUqhrhW BkDRKHsrVWyZZwwe5dotdcQVJAnoHT1FywEmkjY= X-Google-Smtp-Source: ABdhPJwdzyxsACQknRLgT5ZX9OB8pFKd5fhZA/phme9eP8yz9udQHOBHLjD6RhXwelSq6oIk0+3jLAW0I9mtZ8jL7c0= X-Received: by 2002:a05:6830:139a:: with SMTP id d26mr10125507otq.305.1611229003319; Thu, 21 Jan 2021 03:36:43 -0800 (PST) MIME-Version: 1.0 References: <20210120132717.395873-1-mohamed.mediouni@caramail.com> <20210120132717.395873-3-mohamed.mediouni@caramail.com> <5403A355-A4FA-442B-8F8B-5629FCECC006@caramail.com> In-Reply-To: <5403A355-A4FA-442B-8F8B-5629FCECC006@caramail.com> From: Arnd Bergmann Date: Thu, 21 Jan 2021 12:36:27 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 2/7] arm64: kernel: Add a WFI hook. To: Mohamed Mediouni X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210121_063645_588615_8A049A2D X-CRM114-Status: GOOD ( 22.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Catalin Marinas , Hector Martin , "linux-kernel@vger.kernel.org" , Marc Zyngier , Will Deacon , Linux ARM , Stan Skowronek Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jan 21, 2021 at 12:01 PM Mohamed Mediouni wrote: > > On 21 Jan 2021, at 11:52, Arnd Bergmann wrote: > > > > On Wed, Jan 20, 2021 at 2:27 PM Mohamed Mediouni > > wrote: > >> --- a/arch/arm64/kernel/cpu_ops.c > >> +++ b/arch/arm64/kernel/cpu_ops.c > > > >> #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK) > >> #include > >> @@ -74,8 +75,14 @@ void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); > >> > >> static void noinstr __cpu_do_idle(void) > >> { > >> - dsb(sy); > >> - wfi(); > >> + const struct cpu_operations *ops = get_cpu_ops(task_cpu(current)); > >> + > >> + if (ops->cpu_wfi) { > >> + ops->cpu_wfi(); > >> + } else { > >> + dsb(sy); > >> + wfi(); > >> + } > >> } > > > > I think the correct place to put this would be a platform specific driver > > in drivers/cpuidle/ instead of an added low-level callback in the > > default idle function and a custom cpu_operations structure. > > Can we make sure that wfi never gets called even on early > boot when using a cpuidle driver? Good question, I don't know what all the possible call sites are for this, but if there is nothing else works (such as what Alex suggested), it may be possible to just patch out the wfi instruction here and do a busy loop until the cpuidle driver has come up. The main issue here is the existence of the custom cpu_operations in the first place: I don't think we want or need the custom start_secondary at the moment (as commented in the other patch), but then there is no obvious place to put the custom wfi. Note that there are a few other uses of the wfi instruction besides the one in __cpu_do_idle(), so whatever you do here may also apply to the others. arch/arm64/include/asm/smp.h: wfi(); arch/arm64/kernel/head.S: wfi arch/arm64/kernel/head.S: wfi arch/arm64/kernel/head.S: wfi arch/arm64/kernel/process.c: wfi(); arch/arm64/kvm/hyp/nvhe/hyp-init.S: wfi Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel