Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp145197pxb; Thu, 21 Jan 2021 03:40:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz31/yzXh6r18CIMSKfXnhfJiG3eIIdn7rM3/Ov/zRdpju97wne9aoR68zIkg6Np7c4i7Sc X-Received: by 2002:a17:906:7e42:: with SMTP id z2mr961952ejr.177.1611229215911; Thu, 21 Jan 2021 03:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611229215; cv=none; d=google.com; s=arc-20160816; b=CASx9Og6EPTMKYKMn/W5rNYXTqBaa1/NHX0G2Zd2vl6mN2AQIrWgjSqnhFFWe/uGrs msXarIAHdHV4KwXkPc/Xfsqc2Q54ALneaeqIaIWd6ghsaAORP65nX7TEHnkWtUK+nEWP fvJ3DecGeMwXzIBJxigOEgQitFUHIuStPZH3l9s3FtM361tlfcNn7YPPoArkGCWe/Ezi TrvaFZVQO4BfqvbKj4lgb0YJpf746xKw4y4TBDSZDNJm+NhxRNSIMn9qByeZ6j4pUkt8 vu7z944yu3SdUyl+bTETlmnuIAXiWa7JII/9vxljL41np7pm/HDSNc/udefD16gaTCTd zwZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5gFog2eM9Ua5IL8/pTF/l/bFu+eJ3+MWtZ4C7vgEv9A=; b=0gMpCWEix2kZyizHSj9bAXip9YSq4doHBkr3dvij5IsV57VBBxSaiL1iw7QYspq3fm H9d9bWm+05V4FQxRGQOAn7uVfjERUUXRBUVGuNVCAD9WSrK+cBk0IgwDZ1PYO4y5HlpN UkMNStaKtUxeIztZugwaTfvzITnTpJ7zwWmC7d6UCUJ6+nPM/U/jiCtvzytEDBayMNxQ BWgtQfPv7ulnjIRT7AEPP7U7bzlwaGOkJCAOK9S6MZDdtceYgbtI6kwJo7OS99tCihJK Af6nJXdlLKWbUt2EnGdDB424zB4uWHtjxBvBbiG77GthTzVxasmov4clDJ3tFMTEjMDM MlXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mEvdBxSG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id go43si1460418ejc.565.2021.01.21.03.39.50; Thu, 21 Jan 2021 03:40:15 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mEvdBxSG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730382AbhAULim (ORCPT + 99 others); Thu, 21 Jan 2021 06:38:42 -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-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