From patchwork Fri Oct 1 13:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12530663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB15AC4321E for ; Fri, 1 Oct 2021 13:43:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC11461A07 for ; Fri, 1 Oct 2021 13:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353902AbhJANov (ORCPT ); Fri, 1 Oct 2021 09:44:51 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:42632 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352761AbhJANou (ORCPT ); Fri, 1 Oct 2021 09:44:50 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 5ADD22266F; Fri, 1 Oct 2021 13:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633095785; 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=89I/GqU4jKbZ8oW6eMaU78Wbp+BG4tQO08Wgw9elk0E=; b=Pu14E9j1K9nZDi1Zw/I2GYYGxHLyZxDpEyxwMk3d+DOAyVYVlRiOwFI3dmZJH4cpetW72R dhEmEFjoYxIanAOEVxnldM5r0OkIrF6FZGbHih6C3evnRZzeUeR0zjFBLsMJFk38U/XlsR S+drfsttD/jMNjLkgis1l+Q6xtDVuBo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633095785; 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=89I/GqU4jKbZ8oW6eMaU78Wbp+BG4tQO08Wgw9elk0E=; b=3prTXzLIrTE8hjxomuUiS155QjxAPBa7kOKJ4PZIN7VfEeKThFb5W0yO2HRJKYZqqoiSCD 0UQ58GK2J3mgjrAg== Received: from echidna.suse.de (unknown [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 3018BA3B88; Fri, 1 Oct 2021 13:43:05 +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 v3 1/5] initramfs: refactor do_header() cpio magic checks Date: Fri, 1 Oct 2021 15:42:52 +0200 Message-Id: <20211001134256.5581-2-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211001134256.5581-1-ddiss@suse.de> References: <20211001134256.5581-1-ddiss@suse.de> 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 fails if the first six bytes don't match "newc" magic. 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 can be nested under the "newc" mismatch code path to avoid calling memcmp() twice in a non-error case. 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 a842c0544745..6897994c60fb 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -257,12 +257,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 Fri Oct 1 13:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12530667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF95AC4167E for ; Fri, 1 Oct 2021 13:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBFBC61262 for ; Fri, 1 Oct 2021 13:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353959AbhJANow (ORCPT ); Fri, 1 Oct 2021 09:44:52 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47888 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353532AbhJANou (ORCPT ); Fri, 1 Oct 2021 09:44:50 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8BF8E1FEDB; Fri, 1 Oct 2021 13:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633095785; 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=El2HKttjCWtLvnp+cn/O47fN/Ug0Z6IqYK1/bdRAPQ4=; b=wF0OZULxMEtHcGRnDyBj7E9PKMVRVuxoKibJldGDSEjYXu7lKYn5pPbIn5dhLLaNMurldq tY5ikXndTTSRsb5BNU2QvN6v5QMiGUdskvg7jdMoDz9F55S1qlNL5akiUN7A1pORs2/IZn IXJ/jZbRYNNVW9qBeZOuIqEnwDl9to4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633095785; 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=El2HKttjCWtLvnp+cn/O47fN/Ug0Z6IqYK1/bdRAPQ4=; b=URFcIEaRzEJdq6NrvGX2/ifVKNVliyQPJIv4t7YLigt6EKlhCvBoAc+XY7jckX+Ft4wwN9 JOiyIrpEpXaXqrBg== Received: from echidna.suse.de (unknown [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 61C8FA3B89; Fri, 1 Oct 2021 13:43:05 +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 v3 2/5] initramfs: print helpful cpio error on "crc" magic Date: Fri, 1 Oct 2021 15:42:53 +0200 Message-Id: <20211001134256.5581-3-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211001134256.5581-1-ddiss@suse.de> References: <20211001134256.5581-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 6897994c60fb..3bc90ab4e443 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -258,7 +258,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 Fri Oct 1 13:42:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12530665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C0F2C4167B for ; Fri, 1 Oct 2021 13:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DBF661A03 for ; Fri, 1 Oct 2021 13:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353949AbhJANow (ORCPT ); Fri, 1 Oct 2021 09:44:52 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47898 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353770AbhJANou (ORCPT ); Fri, 1 Oct 2021 09:44:50 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id BDAF520453; Fri, 1 Oct 2021 13:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633095785; 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=gJTwOm15pp9tuyNsmQ7zGjoMUZGVeD389Wa9XYXN7bU=; b=f3GNXEudLeHjZsM+sXxllWTu3+7wYwzmrLegQx2UmRSmje+ilJ1W6ZBUWUCD9LJFm/GOx5 6aJ7OfLx/3UZDLp9IKa+xPfEnCGoEO0wTUToQrke/m5dH+9YPwCyqoPPusdmbAFhUGZDwq fE9k6xbuy+NHYmC7shhmkcZ4ajNE2yI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633095785; 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=gJTwOm15pp9tuyNsmQ7zGjoMUZGVeD389Wa9XYXN7bU=; b=ZuP8nm9uNZ6Ug3nI+vGoZipOwiahA68dk2/OoNknn1yYOgFKsP4MI4lWuhBK6Y+QT9BQf3 lq+9+QKYujR8+SAw== Received: from echidna.suse.de (unknown [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 93ACBA3B8A; Fri, 1 Oct 2021 13:43:05 +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 v3 3/5] docs: remove mention of "crc" cpio format support Date: Fri, 1 Oct 2021 15:42:54 +0200 Message-Id: <20211001134256.5581-4-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211001134256.5581-1-ddiss@suse.de> References: <20211001134256.5581-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(-) 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 Fri Oct 1 13:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12530669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF88FC433FE for ; Fri, 1 Oct 2021 13:43:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9D5461262 for ; Fri, 1 Oct 2021 13:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354074AbhJANoy (ORCPT ); Fri, 1 Oct 2021 09:44:54 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47910 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbhJANov (ORCPT ); Fri, 1 Oct 2021 09:44:51 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id ED1EA20455; Fri, 1 Oct 2021 13:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633095785; 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=qYp6TwJjdmzsZNB4jWXeXSfWsLGtToNBVd9s4mjV1PU=; b=pBchRnciQ1ut93uRH15/VxSPV1WZTDKAVDSUBIPO7W5BnXfpuB+HOE+4FK5ksKE4c5Yl0U xOhQglp55fqJOmmR6npdJ273eHjS0qfedvwkxYm5HIcAmBblaqL+NCzZexgrodOtEpx2ks 4rBg3IIYCLlBzbGiveMW3ImgvAgisk0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633095785; 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=qYp6TwJjdmzsZNB4jWXeXSfWsLGtToNBVd9s4mjV1PU=; b=mdRvbzjef+U3ZZQH2og+ac06Kuqmhv2lncOX8AKCnzTANCaYztl4iDjP1VvPIvnIHzt404 UxDbHv8c9VjUNWBg== Received: from echidna.suse.de (unknown [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 C3DBBA3B8B; Fri, 1 Oct 2021 13:43:05 +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 v3 4/5] initramfs: use do_utime() wrapper consistently Date: Fri, 1 Oct 2021 15:42:55 +0200 Message-Id: <20211001134256.5581-5-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211001134256.5581-1-ddiss@suse.de> References: <20211001134256.5581-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 3bc90ab4e443..c64f819ed120 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -379,13 +379,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 Fri Oct 1 13:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12530671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D34CC07CB1 for ; Fri, 1 Oct 2021 13:43:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4758C61A02 for ; Fri, 1 Oct 2021 13:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353939AbhJANox (ORCPT ); Fri, 1 Oct 2021 09:44:53 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:47920 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353834AbhJANov (ORCPT ); Fri, 1 Oct 2021 09:44:51 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 29AFC20459; Fri, 1 Oct 2021 13:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633095786; 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=wBSel4M0Z2Kwh7Vv/gxroZDfsM3cs68ntlBYsm1A2cQ=; b=EQQpHGMbiWYw6UUB9Q9k1ekidSlQzJVBR295sxF9W5sj0XsCEQIllJknx2d4bRBAsk7C0D kD1yCgPxYhJKjNKbfs+62YwSVb7j96yaxYY8EZNhrws4nOkRu9ZhHzW+12BkxsyhTsdZzG cSOPKp0teAyJq6VFdEKXHRsLTjg2dbQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633095786; 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=wBSel4M0Z2Kwh7Vv/gxroZDfsM3cs68ntlBYsm1A2cQ=; b=PJ1pCuzEZBLO9WQlZTO4uC7j07L4RUMR8g3VfTPWUO1CMjCiKxlZIEZkmoGd91iwzPL7F3 3gRkIFpWaJG3MoAg== Received: from echidna.suse.de (unknown [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 0000CA3B81; Fri, 1 Oct 2021 13:43:05 +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 v3 5/5] initramfs: add INITRAMFS_PRESERVE_MTIME Kconfig option Date: Fri, 1 Oct 2021 15:42:56 +0200 Message-Id: <20211001134256.5581-6-ddiss@suse.de> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211001134256.5581-1-ddiss@suse.de> References: <20211001134256.5581-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 11f8a845f259..dc734d72a3c6 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1352,6 +1352,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 c64f819ed120..aa0f63d9f570 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -17,6 +17,8 @@ #include #include +#include "initramfs_mtime.h" + static ssize_t __init xwrite(struct file *file, const char *p, size_t count, loff_t *pos) { @@ -116,46 +118,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