Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp386314imm; Thu, 31 May 2018 02:11:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKiZxle6gB7Ke8H2uaF5gemB0lqZHoTKG+t3sKK4r0cgLXEqo4nMIe7znrkVOSE30FNq9wr X-Received: by 2002:a63:93:: with SMTP id 141-v6mr4980196pga.322.1527757887607; Thu, 31 May 2018 02:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527757887; cv=none; d=google.com; s=arc-20160816; b=Ns8IBIhp4oxUdKNmjuOAknk5MLyPaslca0QaWiF+UEhpmTz6Ne/EZCt0cjprdfeXLy c4q1xYrKGlPkzWU9dDTUH8P5XdWepX9V2SXbc/If+xhTthgjobPN9W1Ut7p4vU1JgWN+ ykNNTO3dc9FjhG2D69/CmCO0EibKA6hu/PTwOa0/1SX5TPnAMqO5eAWqyV9GGmES6FIu OgIUHPi7w/ZWr5J0Cp7UoB9Bi6mUMJzLLMeEZ8RPeavbw26yaBZwC5ic3uPLorUd20JC yAgonGdp//zoP9sHsGg5vUswKJfTMFZvUxxyzwaVMnrwXbqwu2uim+3rnFzUpuw6Zb9T RZcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:mime-version:user-agent:date:message-id :cc:subject:from:to:dkim-signature:arc-authentication-results; bh=wI/00Wu2VL+OgsMMmiO2Sgf9TO0J0VAwjFc++koApJM=; b=YcB2Spzx7Cs6pB5y4RgqTEL1WGWcsfUkdiSqEqc1LwPlqVCVhIc8jgzS57dtDcaeAi rxBi9t+LNJoJ73nQPzns4wKfBffyPS9UWI46XZRFwX1JIHRYs/8oTQ4QwhYV5tBDNWSf wnJ8SPqNnwvTT6oCKWWBZcNAQC0oGJc0aAzMl7K8c2gmukPcKEDebD2suILrAdoseQZ+ +g9/PY5a9hotVdOjdn5idaMDuBg6bhGnQWDBMJs+3g9DZgFfWS7dudXOd8u3bhUm/Wfx 1Knal83k0k+cxXGA7FI3O0i6Sq2o8WnaVv1skRL0aAIsJsJPQ94zpIWCRRIb4Ex59fU8 glSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ot3FH2Fp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t84-v6si329786pfj.231.2018.05.31.02.11.13; Thu, 31 May 2018 02:11:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ot3FH2Fp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754192AbeEaJJR (ORCPT + 99 others); Thu, 31 May 2018 05:09:17 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45883 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026AbeEaJJM (ORCPT ); Thu, 31 May 2018 05:09:12 -0400 Received: by mail-pf0-f193.google.com with SMTP id c10-v6so10459687pfi.12 for ; Thu, 31 May 2018 02:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:cc:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=wI/00Wu2VL+OgsMMmiO2Sgf9TO0J0VAwjFc++koApJM=; b=Ot3FH2FpbKCXTHZzfTd3DsCLbMex36m49vv5TXS8CtKCxbTzeOGQ26d6VfUi++oJxD mKy2Eyh+FAcSA5kx2nbGt1PJI6pd0utjWuZwsOQzfBV1WHNAsWdcAsPUGiNvmQbS0dOQ pWZLdugN8urcWNSerFZKUvqdEEIeRyfhzcUYfDmql1V2uOhMkls4RpmD03UJY7ZKyZAH LfEupmehbW9jc1eU/CZ3fSB8m4Jpo87KexWVHoqDI9y5dcm6XDr9wIY9FR+srHHkli/M e2+n4Eel2eQHz+1tMCnVRkuzXJyUsHDHpb6IcTDElS+e+1ebHfQg3LgfRIJ1Gmg9sDgX K4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:cc:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=wI/00Wu2VL+OgsMMmiO2Sgf9TO0J0VAwjFc++koApJM=; b=O/oJmTz0tzRRjT+DtYL8SVKIaBvxWXj2F4CCeaC+r2fk7yHZmJ29yE7Zo8adFSd0P4 jZHH6epWwzaVmE0fpRb3PDhQEHYcmYcVRp2CF1eGm4HXlZxrpfSQodip3BUb4c7+VgQH znU+0hIFU9cteiDosc623REN8m0wKGJ+EdG4tp+/Im3RY0rqdiu786fAQNnmA4ORgO53 3SH6ZiAX//nYvtcMIPXwOjLWAfBWH/0oM5gSX2dVZHTvAXgV20nS7ByN4QM7kFA9XOCk rn2Cw+wV3E4wNX+4Uw/mtggSVJnV7dXk4pXTGerVsDMyWwh2W8m2uBCN7JpVIFWGHlN2 HEjQ== X-Gm-Message-State: ALKqPwf/VS4RcHt/1jLobw8IFlFoyc5ZByYzhbH30O25rH3gTxPvaDWx F9n9d6gV1BnOFVDuZIzLYDz7dTcI X-Received: by 2002:a63:448:: with SMTP id 69-v6mr4676808pge.395.1527757752318; Thu, 31 May 2018 02:09:12 -0700 (PDT) Received: from ?IPv6:2402:f000:1:1501:200:5efe:166.111.70.46? ([2402:f000:1:1501:200:5efe:a66f:462e]) by smtp.gmail.com with ESMTPSA id a23-v6sm18421868pgd.85.2018.05.31.02.09.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 02:09:11 -0700 (PDT) To: bhelgaas@google.com, pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, Al Viro , Greg KH , corbet@lwn.net, Linus Torvalds From: Jia-Ju Bai Subject: Can printk() sleep at runtime? Cc: Linux Kernel Mailing List Message-ID: Date: Thu, 31 May 2018 17:08:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, I write a static analysis tool (DSAC), and it finds that printk can sleep. According to this finding, there is an example bug in drivers/pci/pci.c in Linux-4.16.7. Here is the call path for this bug. Please look at it *from the bottom up*. ========== BUG ========== [FUNC] __might_sleep kernel/locking/mutex.c: 747: __might_sleep in __mutex_lock_common kernel/locking/mutex.c: 893: __mutex_lock_common in __mutex_lock kernel/locking/mutex.c: 908: __mutex_lock in mutex_lock_nested drivers/clk/clk.c, 123: mutex_lock_nested in clk_prepare_lock drivers/clk/clk.c, 1369: clk_prepare_lock in clk_core_get_rate drivers/clk/clk.c, 1393: clk_core_get_rate in clk_get_rate lib/vsprintf.c, 1450: clk_get_rate in clock lib/vsprintf.c, 1944: clock in pointer lib/vsprintf.c, 2286: pointer in vsnprintf lib/vsprintf.c, 2385: vsnprintf in vscnprintf kernel/printk/printk.c, 1853: vscnprintf in vprintk_emit kernel/printk/printk.c, 1947: vprintk_emit in vprintk_default kernel/printk/printk_safe.c, 379: vprintk_default in vprintk_func kernel/printk/printk.c, 1980: vprintk_func in printk drivers/pci/pci.c, 5364: printk in pci_specified_resource_alignment drivers/pci/pci.c, 5313: spin_lock in pci_specified_resource_alignment In fact, I suspect that my report is false, because I always have an impression that printk() cannot sleep. But according to the call path, I cannot find where I make the mistake... So could someone please help me to point the mistake? Best wishes, Jia-Ju Bai