From patchwork Tue Jan 17 11:14:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Vutla X-Patchwork-Id: 9520537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5C4786020A for ; Tue, 17 Jan 2017 11:17:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4756727F9E for ; Tue, 17 Jan 2017 11:17:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BEF528528; Tue, 17 Jan 2017 11:17:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 03A5D27F9E for ; Tue, 17 Jan 2017 11:17:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cTRl5-0006tb-Ue; Tue, 17 Jan 2017 11:16:59 +0000 Received: from lelnx193.ext.ti.com ([198.47.27.77]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cTRkz-0006rn-3N for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2017 11:16:58 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id v0HBGUoU010370; Tue, 17 Jan 2017 05:16:30 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v0HBGU2l004576; Tue, 17 Jan 2017 05:16:30 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Tue, 17 Jan 2017 05:16:29 -0600 Received: from a0131933.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v0HBGMs9015580; Tue, 17 Jan 2017 05:16:24 -0600 From: Lokesh Vutla To: Subject: [RFC PATCH] initramfs: finish fput() before accessing any binary from initramfs Date: Tue, 17 Jan 2017 16:44:56 +0530 Message-ID: <20170117111456.2269-1-lokeshvutla@ti.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170117_031653_255842_6FF66FDF X-CRM114-Status: GOOD ( 10.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nishanth Menon , Lokesh Vutla , Sekhar Nori , linux-kernel@vger.kernel.org, Tero Kristo , Linux ARM Mailing List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP commit 4a9d4b024a31 ("switch fput to task_work_add") implements a schedule_work() for completing fput(), but did not guarantee calling __fput() after unpacking initramfs. Because of this, there is a possibility that during boot a driver can see ETXTBSY when it tries to load a binary from initramfs as fput() is still pending on that binary. This patch makes sure that fput() is completed after unpacking initramfs. Signed-off-by: Lokesh Vutla --- - Reproduced on TI K2HK EVM. K2HK Queue Manager subsystem driver[1] tries to load a firmware from initramfs during boot. Sometimes loading of this firmware fails with error ETXTBSY. Digging a bit more observed that deny_write_access() is returning ETXTBSY as inode->i_writecount is > 0 for that file. This is because Unpacking initramfs does a get_write_access(from open) but hasn't done put_write_access(from fput) as it hasn't been scheduled yet. [1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/ti/knav_qmss_queue.c init/initramfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/init/initramfs.c b/init/initramfs.c index b32ad7d97ac9..c42c69b48a4b 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -18,6 +18,7 @@ #include #include #include +#include static ssize_t __init xwrite(int fd, const char *p, size_t count) { @@ -652,6 +653,7 @@ static int __init populate_rootfs(void) * us a chance to load before device_initcalls. */ load_default_modules(); + flush_delayed_fput(); } return 0; }