Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp191557pxb; Wed, 22 Sep 2021 19:53:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo8gMqt5HrS/LmsXXosS4jgZ7TNgB4U5vypN8HjCkW8Pa0C0Xsy/vZjNpWJgGd5n5wApu1 X-Received: by 2002:a5d:88d7:: with SMTP id i23mr1866099iol.38.1632365611061; Wed, 22 Sep 2021 19:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632365611; cv=none; d=google.com; s=arc-20160816; b=tMfPQs8lhAi2oUHylF2yA/ZW76xb02EjNBW9N+Mi9sSMyTKrm3c7YP5Mp8GvAI2xsM HKBRzNHpToafTmOUifpRq1XLiL7kxMVYQjerg/wUJCn8Rj5s01SOrjMGB9cE7Hs+PJBJ dKp8eAZ7EVVQmf9S3Fimhn5mA68P4QuNLjay8mIISd8ANzZWWxleWW377nI75G+Vj9M9 gnyIfExAbg/yG/jL86ORwfjB45iCtO8E6mxuB9OJztNNRgGzfky8xFSjFqoLt6giaAkj pX6SJISeUWF0koCMgb1iqbPedX1+gjHpBmS/MYi7rD36FtLP1B/gAYJdgsvr163bImGu KciQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6ArNH4FOPgEo2+wAsh5ihX60RWek2hwhkq64oZnUrfM=; b=fYwGRbbJdRNXwcQkk5dF5NozR4vFTMVCkEjh1szagaGdPDkdkFOUq/mZGHnHfkxyRG BE1BB4sGLgHWcIA4aS7EzH0747D5kBpO6J2ZrqYbSxr6q+t6av926JA5HUJnpl468jeW nDEgC21fbzLqsXPOykePb9oKmtfQ+FZ7BopJpjVOMW+X3yAw/gZ4T6vGeWobtk9FTAGK HqWoKEoXTs95SkErwDdt/K4POWUTFS+mJ2RYzp90Ckq4PV9tfiGnSLxJCFTCfGs/T5ZG pSL3pTf/l3fDSGuWpO0FNXCG8coC4R3e5+iMOu0pPn2T59eUms5G3j+lCxd5BGvPmknF pE8Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o3si5447584ilk.81.2021.09.22.19.53.16; Wed, 22 Sep 2021 19:53:31 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239003AbhIWCxT (ORCPT + 99 others); Wed, 22 Sep 2021 22:53:19 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:16284 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238953AbhIWCxS (ORCPT ); Wed, 22 Sep 2021 22:53:18 -0400 Received: from dggeme751-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HFKRS5ljlz8tJl; Thu, 23 Sep 2021 10:51:00 +0800 (CST) Received: from huawei.com (10.67.174.96) by dggeme751-chm.china.huawei.com (10.3.19.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Thu, 23 Sep 2021 10:51:45 +0800 From: Zhang Jianhua To: CC: , Subject: [PATCH -next] efi: Change down_interruptible() in virt_efi_reset_system() to down_trylock() Date: Thu, 23 Sep 2021 10:53:40 +0800 Message-ID: <20210923025340.1469836-1-chris.zjh@huawei.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.96] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme751-chm.china.huawei.com (10.3.19.97) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While reboot the system by sysrq, the following bug will be occur. BUG: sleeping function called from invalid context at kernel/locking/semaphore.c:90 in_atomic(): 0, irqs_disabled(): 128, non_block: 0, pid: 10052, name: rc.shutdown CPU: 3 PID: 10052 Comm: rc.shutdown Tainted: G W O 5.10.0 #1 Call trace: dump_backtrace+0x0/0x1c8 show_stack+0x18/0x28 dump_stack+0xd0/0x110 ___might_sleep+0x14c/0x160 __might_sleep+0x74/0x88 down_interruptible+0x40/0x118 virt_efi_reset_system+0x3c/0xd0 efi_reboot+0xd4/0x11c machine_restart+0x60/0x9c emergency_restart+0x1c/0x2c sysrq_handle_reboot+0x1c/0x2c __handle_sysrq+0xd0/0x194 write_sysrq_trigger+0xbc/0xe4 proc_reg_write+0xd4/0xf0 vfs_write+0xa8/0x148 ksys_write+0x6c/0xd8 __arm64_sys_write+0x18/0x28 el0_svc_common.constprop.3+0xe4/0x16c do_el0_svc+0x1c/0x2c el0_svc+0x20/0x30 el0_sync_handler+0x80/0x17c el0_sync+0x158/0x180 The reason for this problem is that irq has been disabled in machine_restart() and then it calls down_interruptible() in virt_efi_reset_system(), which would occur sleep in irq context, it is dangerous! Commit 99409b935c9a("locking/semaphore: Add might_sleep() to down_*() family") add might_sleep() in down_interruptible(), so the bug info is here. down_trylock() can solve this problem, cause there is no might_sleep. -------- Signed-off-by: Zhang Jianhua --- drivers/firmware/efi/runtime-wrappers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/runtime-wrappers.c b/drivers/firmware/efi/runtime-wrappers.c index 1410beaef5c3..f3e54f6616f0 100644 --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -414,7 +414,7 @@ static void virt_efi_reset_system(int reset_type, unsigned long data_size, efi_char16_t *data) { - if (down_interruptible(&efi_runtime_lock)) { + if (down_trylock(&efi_runtime_lock)) { pr_warn("failed to invoke the reset_system() runtime service:\n" "could not get exclusive access to the firmware\n"); return; -- 2.31.0