Received: by 10.213.65.68 with SMTP id h4csp463350imn; Fri, 6 Apr 2018 03:29:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+99rx/TUQOWCOzdkNH/5Icd68nKx0/bYXDdsPqzVqRCnOa4AkYwQnqz0HrkKHMxizUgobX X-Received: by 2002:a17:902:6e01:: with SMTP id u1-v6mr26331239plk.96.1523010557155; Fri, 06 Apr 2018 03:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523010557; cv=none; d=google.com; s=arc-20160816; b=Yyk8COp03agj8Mnhr1pYHcfWiHE1F+LwQU7chifWldYkpSGzT6N3YrMb6obdcelNpz mY7U8oKiERD3QWqYyqunbABfGMSeFRoZLHdBI0wCNRPFZI7xr/d7K6ysFD1Hi5kBZ8TT oxbXMXjJfnuEJxBnvbkl/Uy8AVYIVJnrT/+QE7QkO3Oesr+kqoVh6m21DuNgMj0SZLPk /04NHJhlU6uY9ugDdaiyEUzYyJfT1xj5K4mZFQydV+qos+l3Y9Nj4fN7TfdrRiq4nwBm pma+RrBzxToeAYaTRZeifCecSn1Qw00R7i/2+IeDUz9XYmGphJ/ClSuoUBPJVdAH3jz9 7rhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=M+SqgI5wEI7GIOlJiJ1iTJ4X4MJuwkF2O3iAOtM0KCw=; b=dcIwlH1QyZS9zyx/bAp8SZ253xp17HEw2epKdR57YB4PdeaQNrUW8rA4F82LuLStNK 8ylR4ci6qPZiDulH5XkIRyRVxr6hqlKh3E+rAgrtJlKD7P/xdp/LQDHNSDZjAy6NiaUU e1Fhf7tyneX/Z6R3rI2fHakVet3T9DFXH4Hnl77dpFiEDo+fJHYJFyjX4+Nw3VNtDKMA WwHubkhjOKUxhZjQKdP+DtXC04EIApcKfpIXysief7Ty4wKi+DhonII0aZKqvmktrEZw V10rVoyQfVjVxS75Jk6NwjzzwsW+ZDwzVdZ+m/u+7zBcZro/HLAfGdOIZtVyR7VnahYm YlkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c143si6222604pfc.197.2018.04.06.03.29.03; Fri, 06 Apr 2018 03:29:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752246AbeDFK1q (ORCPT + 99 others); Fri, 6 Apr 2018 06:27:46 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:41059 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751874AbeDFK1p (ORCPT ); Fri, 6 Apr 2018 06:27:45 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f4Oaq-0008Hc-12; Fri, 06 Apr 2018 12:27:40 +0200 Date: Fri, 6 Apr 2018 12:27:39 +0200 (CEST) From: Thomas Gleixner To: Jia-Ju Bai cc: akpm@linux-foundation.org, mingo@kernel.org, keescook@chromium.org, lauraa@codeaurora.org, viresh.kumar@linaro.org, nicolas.pitre@linaro.org, thomas.lendacky@amd.com, Linux Kernel Mailing List Subject: Re: A question of sleeping with interrupts are disabled in start_kernel() In-Reply-To: <1eb16c24-ef3b-2962-d216-57f66321035e@gmail.com> Message-ID: References: <1eb16c24-ef3b-2962-d216-57f66321035e@gmail.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 6 Apr 2018, Jia-Ju Bai wrote: > Hello, > > I have a question of the call path init/main.c: > init/main.c: start_kernel() -> > kernel/events/core.c: perf_pmu_register() -> > kernel/events/core.c: perf_event_init() -> > kernel/events/core.c: pmu_dev_alloc() > > In this call path, start_kernel() calls local_irq_disable() to disable the > interrupt; > perf_pmu_register() calls mutex_lock() and idr_alloc(GFP_KERNEL), and they can > sleep; > pmu_dev_alloc() calls kzalloc(GFP_KERNEL), and it can sleep. > > In my opinion, this code may sleep with interrupts are disabled. > I wonder why this code is okay? Because this is the very early boot up stage where contention of the mutex cannot happen and the allocations are all implicitely converted to atomic allocations. If the mutex would be contended then the system would fail to boot anyway. If the allocations fail at that stage, it's unlikely that the machine will come up at all. So yes, it looks odd, but we don't want to have duplicated code pathes just for the early boot up and the debugging mechanisms are aware of that situation and don't emit warnings. Once the scheduler is functional and the early boot stage is done, these 'magic' violations are not longer allowed. Hope that helps. Thanks, tglx