From patchwork Wed Sep 22 11:52:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12510373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22335C433F5 for ; Wed, 22 Sep 2021 11:52:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F270C60F41 for ; Wed, 22 Sep 2021 11:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235811AbhIVLyB (ORCPT ); Wed, 22 Sep 2021 07:54:01 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50776 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbhIVLyA (ORCPT ); Wed, 22 Sep 2021 07:54:00 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 358BD201E9; Wed, 22 Sep 2021 11:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632311550; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=axIV2Aaeicqox/fHORSsUBSw8MCPPCxxCoZiD3aru9k=; b=H3khMMnawKOYn6w1uZ7Hy4rkW/nhSWGb1a1UJ9G3Ht/IO/fOBZiv8fqVhLclJU33umoEVR j26/g7AUwLQAYq6RP+NykD6znlfh2Cm6bQswfah3N0SJHLNM12AC0AvQ3kuDiFYnE/s6bv TqjtuS6j/bjg0SGyHWKpKR8irEraXUw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632311550; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=axIV2Aaeicqox/fHORSsUBSw8MCPPCxxCoZiD3aru9k=; b=0fg7YVVjE3ZvJbQCkw2OdN8rXirE5QqjdqgfEywtc0G9wJzjyrnP1CE4aVFRBSXEPKdLMw qqfjSyosf+SEjgBg== Received: from echidna.suse.de (ddiss.udp.ovpn2.nue.suse.de [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EC46CA3BA0; Wed, 22 Sep 2021 11:52:29 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH 1/5] initramfs: move unnecessary memcmp from hot path Date: Wed, 22 Sep 2021 13:52:18 +0200 Message-Id: <20210922115222.8987-1-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org do_header() is called for each cpio entry and first checks for "newc" magic before parsing further. The magic check includes a special case error message if POSIX.1 ASCII (cpio -H odc) magic is detected. This special case POSIX.1 check needn't be done in the hot path, so move it under the non-newc-magic error path. Signed-off-by: David Disseldorp --- init/initramfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index af27abc59643..f01590cefa2d 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -256,12 +256,11 @@ static int __init do_collect(void) static int __init do_header(void) { - if (memcmp(collected, "070707", 6)==0) { - error("incorrect cpio method used: use -H newc option"); - return 1; - } if (memcmp(collected, "070701", 6)) { - error("no cpio magic"); + if (memcmp(collected, "070707", 6) == 0) + error("incorrect cpio method used: use -H newc option"); + else + error("no cpio magic"); return 1; } parse_header(collected); From patchwork Wed Sep 22 11:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12510375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F979C4332F for ; Wed, 22 Sep 2021 11:52:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04A6161181 for ; Wed, 22 Sep 2021 11:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235815AbhIVLyD (ORCPT ); Wed, 22 Sep 2021 07:54:03 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50794 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235802AbhIVLyC (ORCPT ); Wed, 22 Sep 2021 07:54:02 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B83C7201F1; Wed, 22 Sep 2021 11:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632311551; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DP5zK5YwcP7TB/exrav4rcNsozXcCy88E5d7YWBggkk=; b=HXVYLWPGxdsirynRjkiCZO16VCPID+XKB911GL+wfU4b06jxWUqsdJVJ10ih/aE8keFBeG ZUNX9SaAawD3pCF8tQZn6EQCbFosAB66oOZ3kQIGOinICIUau01l/2AImJM+FfYa93pDAU wMUFMP5BKOAQExEaeVY6y5ZSYATpdvc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632311551; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DP5zK5YwcP7TB/exrav4rcNsozXcCy88E5d7YWBggkk=; b=XEue/039zqGRlROwsiwXnSf2f/EDfBzTz+IFo0mcGIXhmNf3MjX/Ep625/AXcPsRCKHspk IKiJByrZNfxShaCw== Received: from echidna.suse.de (ddiss.udp.ovpn2.nue.suse.de [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8D2B8A3B8E; Wed, 22 Sep 2021 11:52:31 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH 2/5] initramfs: print helpful cpio error on "crc" magic Date: Wed, 22 Sep 2021 13:52:19 +0200 Message-Id: <20210922115222.8987-2-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922115222.8987-1-ddiss@suse.de> References: <20210922115222.8987-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Contrary to the buffer-format.rst documentation, initramfs cpio extraction does not support "crc" archives, which carry "070702" header magic. Make it a little clearer that "newc" (magic="070701") is the only supported cpio format, by extending the POSIX.1 ASCII (magic="070707") specific error message to also cover "crc" magic. Signed-off-by: David Disseldorp --- init/initramfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/initramfs.c b/init/initramfs.c index f01590cefa2d..19b1c70446fc 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -257,7 +257,7 @@ static int __init do_collect(void) static int __init do_header(void) { if (memcmp(collected, "070701", 6)) { - if (memcmp(collected, "070707", 6) == 0) + if (memcmp(collected, "0707", 4) == 0) error("incorrect cpio method used: use -H newc option"); else error("no cpio magic"); From patchwork Wed Sep 22 11:52:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12510377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99F36C433FE for ; Wed, 22 Sep 2021 11:52:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C67F6113E for ; Wed, 22 Sep 2021 11:52:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235833AbhIVLyG (ORCPT ); Wed, 22 Sep 2021 07:54:06 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50806 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235802AbhIVLyF (ORCPT ); Wed, 22 Sep 2021 07:54:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 16BE4201F0; Wed, 22 Sep 2021 11:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632311555; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lKYO+Tpc8e3f34No4zgqOS6u8nCy/Ay6+o3tevL0n78=; b=ktKvNvwDsM5ECFgPdsFxp49D78fW9ZPLENfrY+04gVtbFHFRtdEq6UHpLkQXBSZuS1Bofw bQr5k5dMgevjBqnPAnFe+G6J6PleWrrQ1YHJLX1J+Jz6QGQ6LxzOGoc9DZXf6y7E3N+WBp 4PC/wPF5D9ChSCqmGWVYenDgumqySeM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632311555; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lKYO+Tpc8e3f34No4zgqOS6u8nCy/Ay6+o3tevL0n78=; b=RPzt5dLGLXhUFMZAzp1esSCE3B5Strt4tPRv/jAq/IocLvd2VrFTlWCcFBQbsJI2sgZohE RcgAcQ6vIFXH0VBA== Received: from echidna.suse.de (ddiss.udp.ovpn2.nue.suse.de [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E00CDA3BA9; Wed, 22 Sep 2021 11:52:34 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH v2 3/5] docs: remove mention of "crc" cpio format support Date: Wed, 22 Sep 2021 13:52:20 +0200 Message-Id: <20210922115222.8987-3-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922115222.8987-1-ddiss@suse.de> References: <20210922115222.8987-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org init/initramfs.c only supports extraction of cpio archives carrying the "newc" header magic ("070701"). Remove statements indicating support for the "crc" cpio format. Signed-off-by: David Disseldorp --- .../early-userspace/buffer-format.rst | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) Version 2: - reword initramfs padding description, as suggested by Matthew Wilcox diff --git a/Documentation/driver-api/early-userspace/buffer-format.rst b/Documentation/driver-api/early-userspace/buffer-format.rst index 7f74e301fdf3..0df76bca444c 100644 --- a/Documentation/driver-api/early-userspace/buffer-format.rst +++ b/Documentation/driver-api/early-userspace/buffer-format.rst @@ -14,10 +14,10 @@ is different. The initramfs buffer contains an archive which is expanded into a ramfs filesystem; this document details the format of the initramfs buffer format. -The initramfs buffer format is based around the "newc" or "crc" CPIO -formats, and can be created with the cpio(1) utility. The cpio -archive can be compressed using gzip(1). One valid version of an -initramfs buffer is thus a single .cpio.gz file. +The initramfs buffer format is based around the "newc" CPIO format, and +can be created with the cpio(1) utility. The cpio archive can be +compressed using gzip(1). One valid version of an initramfs buffer is +thus a single .cpio.gz file. The full format of the initramfs buffer is defined by the following grammar, where:: @@ -40,9 +40,8 @@ grammar, where:: In human terms, the initramfs buffer contains a collection of -compressed and/or uncompressed cpio archives (in the "newc" or "crc" -formats); arbitrary amounts zero bytes (for padding) can be added -between members. +compressed and/or uncompressed cpio archives (in the "newc" format), +with arbitrary amount of zero-byte padding between members. The cpio "TRAILER!!!" entry (cpio end-of-archive) is optional, but is not ignored; see "handling of hard links" below. @@ -55,7 +54,7 @@ by the ASCII string "000012ac"): ============= ================== ============================================== Field name Field size Meaning ============= ================== ============================================== -c_magic 6 bytes The string "070701" or "070702" +c_magic 6 bytes The string "070701" c_ino 8 bytes File inode number c_mode 8 bytes File mode and permissions c_uid 8 bytes File uid @@ -68,8 +67,7 @@ c_min 8 bytes Minor part of file device number c_rmaj 8 bytes Major part of device node reference c_rmin 8 bytes Minor part of device node reference c_namesize 8 bytes Length of filename, including final \0 -c_chksum 8 bytes Checksum of data field if c_magic is 070702; - otherwise zero +c_chksum 8 bytes Ignored; reserved for unsupported "crc" format ============= ================== ============================================== The c_mode field matches the contents of st_mode returned by stat(2) @@ -78,12 +76,6 @@ on Linux, and encodes the file type and file permissions. The c_filesize should be zero for any file which is not a regular file or symlink. -The c_chksum field contains a simple 32-bit unsigned sum of all the -bytes in the data field. cpio(1) refers to this as "crc", which is -clearly incorrect (a cyclic redundancy check is a different and -significantly stronger integrity check), however, this is the -algorithm used. - If the filename is "TRAILER!!!" this is actually an end-of-archive marker; the c_filesize for an end-of-archive marker must be zero. From patchwork Wed Sep 22 11:52:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12510379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20A95C433EF for ; Wed, 22 Sep 2021 11:52:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B9C66113E for ; Wed, 22 Sep 2021 11:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235841AbhIVLyI (ORCPT ); Wed, 22 Sep 2021 07:54:08 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:50814 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235828AbhIVLyH (ORCPT ); Wed, 22 Sep 2021 07:54:07 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4703E201F2; Wed, 22 Sep 2021 11:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632311556; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3AbMJNGRU6lSznxVHegfwMKE7kiJfg2oVBk/ZzsA5Gs=; b=f23nWM+hudFLaiPRqpUnpnZrEzfes5dszcyej5czSQtN3C35wm2+YxoMO/EaTj5w+IaJj2 k6eyydwHd+rVUKS9ZNIPRCe78KUqRq6JDmEevQu8dl+ygjO5whcmLJ/72H/OOs7JJBi3bS FHFPnHO8VkIt97VU07plnyR1KIkni6o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632311556; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3AbMJNGRU6lSznxVHegfwMKE7kiJfg2oVBk/ZzsA5Gs=; b=EiLio+LJZxglf/aul8uuj/w8HxGqVdjcvJ6agwNse6sQtDUOLMdWKAY9AoNldX0IKf/Olc MuUX6Zw9mdm2jzBw== Received: from echidna.suse.de (ddiss.udp.ovpn2.nue.suse.de [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1B236A3BAC; Wed, 22 Sep 2021 11:52:36 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH 4/5] initramfs: use do_utime() wrapper consistently Date: Wed, 22 Sep 2021 13:52:21 +0200 Message-Id: <20210922115222.8987-4-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922115222.8987-1-ddiss@suse.de> References: <20210922115222.8987-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org vfs_utimes() is called via the do_utime() wrapper everywhere except in do_copy(). Make it consistent. Signed-off-by: David Disseldorp --- init/initramfs.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 19b1c70446fc..7f809a1c8e89 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -378,13 +378,9 @@ static int __init do_name(void) static int __init do_copy(void) { if (byte_count >= body_len) { - struct timespec64 t[2] = { }; if (xwrite(wfile, victim, body_len, &wfile_pos) != body_len) error("write error"); - - t[0].tv_sec = mtime; - t[1].tv_sec = mtime; - vfs_utimes(&wfile->f_path, t); + do_utime(collected, mtime); fput(wfile); eat(body_len); From patchwork Wed Sep 22 11:52:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12510381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96BCAC4332F for ; Wed, 22 Sep 2021 11:52:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80781611B0 for ; Wed, 22 Sep 2021 11:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235839AbhIVLyK (ORCPT ); Wed, 22 Sep 2021 07:54:10 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:55080 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235802AbhIVLyH (ORCPT ); Wed, 22 Sep 2021 07:54:07 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 37CDD2221F; Wed, 22 Sep 2021 11:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1632311557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zpk/uaLL1JETo1I6rhDsb+6geCHM6hrjO4lnTz+Lo1Y=; b=BZ9Sid15cyrUE+mxZnJ0K57i0mNcqLnfYad81QAhMVuasHMzj/8fZmqxPB62D1TrVKchJA FA1TFsStwogydoBBV6oA9BmHjkEN4CZ+x9LIv4mYj66GlrfvfYamfHsF0lsVp6PKnJRVSZ Y1ozoRouTxR7OvQOBfVahKHVjCGdh/M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1632311557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zpk/uaLL1JETo1I6rhDsb+6geCHM6hrjO4lnTz+Lo1Y=; b=tG09QfNmpkzmiBCXncWo+vnEWYsrnWfYmGSfZkc3p6V+RG4SVsFSX4wJvaJLT2bCbP2qCm ANhN9Os1ny9JN0AA== Received: from echidna.suse.de (ddiss.udp.ovpn2.nue.suse.de [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0C3CEA3BAE; Wed, 22 Sep 2021 11:52:37 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp Subject: [PATCH 5/5] initramfs: add INITRAMFS_PRESERVE_MTIME Kconfig option Date: Wed, 22 Sep 2021 13:52:22 +0200 Message-Id: <20210922115222.8987-5-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922115222.8987-1-ddiss@suse.de> References: <20210922115222.8987-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org initramfs cpio mtime preservation, as implemented via 889d51a10712b6fd6175196626de2116858394f4, uses a linked list to defer directory mtime processing until after all other items in the cpio archive have been processed. This is done to ensure that parent directory mtimes aren't overwritten via subsequent child creation. This change adds a new INITRAMFS_PRESERVE_MTIME Kconfig option, which can be used to disable on-by-default mtime retention and in turn speed up initramfs extraction, particularly for cpio archives with large directory counts. For a cpio archive with ~1M directories, rough 20-run local benchmarks demonstrated: mean extraction time (s) std dev INITRAMFS_PRESERVE_MTIME=y 3.789035 0.005474 INITRAMFS_PRESERVE_MTIME unset 3.111508 0.004132 Signed-off-by: David Disseldorp --- init/Kconfig | 10 +++++++++ init/Makefile | 3 +++ init/initramfs.c | 42 ++---------------------------------- init/initramfs_mtime.c | 49 ++++++++++++++++++++++++++++++++++++++++++ init/initramfs_mtime.h | 11 ++++++++++ 5 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 init/initramfs_mtime.c create mode 100644 init/initramfs_mtime.h diff --git a/init/Kconfig b/init/Kconfig index 55f9f7738ebb..a79b6ba4d76c 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1324,6 +1324,16 @@ config BOOT_CONFIG If unsure, say Y. +config INITRAMFS_PRESERVE_MTIME + bool "Preserve cpio archive mtimes in initramfs" + default y + help + Each entry in an initramfs cpio archive carries an mtime value. When + enabled, extracted cpio items take this mtime, with directory mtime + setting deferred until after creation of any child entries. + + If unsure, say Y. + choice prompt "Compiler optimization level" default CC_OPTIMIZE_FOR_PERFORMANCE diff --git a/init/Makefile b/init/Makefile index 2846113677ee..d72bf80170ce 100644 --- a/init/Makefile +++ b/init/Makefile @@ -11,6 +11,9 @@ obj-y += noinitramfs.o else obj-$(CONFIG_BLK_DEV_INITRD) += initramfs.o endif +ifeq ($(CONFIG_INITRAMFS_PRESERVE_MTIME),y) +obj-$(CONFIG_BLK_DEV_INITRD) += initramfs_mtime.o +endif obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o obj-y += init_task.o diff --git a/init/initramfs.c b/init/initramfs.c index 7f809a1c8e89..205fd62be616 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -16,6 +16,8 @@ #include #include +#include "initramfs_mtime.h" + static ssize_t __init xwrite(struct file *file, const char *p, size_t count, loff_t *pos) { @@ -115,46 +117,6 @@ static void __init free_hash(void) } } -static long __init do_utime(char *filename, time64_t mtime) -{ - struct timespec64 t[2]; - - t[0].tv_sec = mtime; - t[0].tv_nsec = 0; - t[1].tv_sec = mtime; - t[1].tv_nsec = 0; - return init_utimes(filename, t); -} - -static __initdata LIST_HEAD(dir_list); -struct dir_entry { - struct list_head list; - char *name; - time64_t mtime; -}; - -static void __init dir_add(const char *name, time64_t mtime) -{ - struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL); - if (!de) - panic_show_mem("can't allocate dir_entry buffer"); - INIT_LIST_HEAD(&de->list); - de->name = kstrdup(name, GFP_KERNEL); - de->mtime = mtime; - list_add(&de->list, &dir_list); -} - -static void __init dir_utime(void) -{ - struct dir_entry *de, *tmp; - list_for_each_entry_safe(de, tmp, &dir_list, list) { - list_del(&de->list); - do_utime(de->name, de->mtime); - kfree(de->name); - kfree(de); - } -} - static __initdata time64_t mtime; /* cpio header parsing */ diff --git a/init/initramfs_mtime.c b/init/initramfs_mtime.c new file mode 100644 index 000000000000..0020deb21f76 --- /dev/null +++ b/init/initramfs_mtime.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include +#include + +#include "initramfs_mtime.h" + +long __init do_utime(char *filename, time64_t mtime) +{ + struct timespec64 t[2]; + + t[0].tv_sec = mtime; + t[0].tv_nsec = 0; + t[1].tv_sec = mtime; + t[1].tv_nsec = 0; + return init_utimes(filename, t); +} + +static __initdata LIST_HEAD(dir_list); +struct dir_entry { + struct list_head list; + char *name; + time64_t mtime; +}; + +void __init dir_add(const char *name, time64_t mtime) +{ + struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL); + if (!de) + panic("can't allocate dir_entry buffer"); + INIT_LIST_HEAD(&de->list); + de->name = kstrdup(name, GFP_KERNEL); + de->mtime = mtime; + list_add(&de->list, &dir_list); +} + +void __init dir_utime(void) +{ + struct dir_entry *de, *tmp; + list_for_each_entry_safe(de, tmp, &dir_list, list) { + list_del(&de->list); + do_utime(de->name, de->mtime); + kfree(de->name); + kfree(de); + } +} diff --git a/init/initramfs_mtime.h b/init/initramfs_mtime.h new file mode 100644 index 000000000000..6d15c8b1171f --- /dev/null +++ b/init/initramfs_mtime.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CONFIG_INITRAMFS_PRESERVE_MTIME +long do_utime(char *filename, time64_t mtime) __init; +void dir_add(const char *name, time64_t mtime) __init; +void dir_utime(void) __init; +#else +static long __init do_utime(char *filename, time64_t mtime) { return 0; } +static void __init dir_add(const char *name, time64_t mtime) {} +static void __init dir_utime(void) {} +#endif