Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp447644imn; Mon, 25 Jul 2022 23:08:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZZsCCjD9rGVIWMDlROUBYIYhfplF2a6lT0sT4RRE8BF1prH/GJyWWMon2GfAihXG5+uZX X-Received: by 2002:a05:6a00:1901:b0:518:916e:4a85 with SMTP id y1-20020a056a00190100b00518916e4a85mr15921994pfi.65.1658815728613; Mon, 25 Jul 2022 23:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658815728; cv=none; d=google.com; s=arc-20160816; b=TZPw8B1heuiqYdj8c4KLlAUObtFFS55N7MvvWMe0TRuSgLhYS3VvH0GpnjuraOikqz 8JFerunItbRGaUKEc++RH+pzR31GET8Kwm5WS1/LEk/bEVB3U7b2YtV4BQ7do5VmRGkD PmVsrjaQ8yjNpAIPpVrEZo9hXFuWVVCKRfHeR7O3YzLC04+3BxqdtsWRf0fyy4lNe2Bv IQ6Zgb6kFDVccPUR1ySnuLjNtp09fCh1TllBo9VoSE9VGc2ZJKsJ6PpbDPBcKuiKr6sw Byo3udmUM/y9yDpipzgGZK0hgSiPcgXDkYK3hWJAWCAm4onmWgvF0K4O4h7dHhvl/Uvg FFnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9NqP8zb13cEgKtZZvdVuc+bb8giuTenSXo8OvwSJLpc=; b=S4gKRsxhO2U4mBXukMgDyuNJQa6mHpVGG9/3prGcCsSQIoGkicRIk3XTac2saMkt+y kc+F7I+y6xgtVRkLXu07HpAap1w+Sa1ef7ZmGeFUpouV6VQ6O9JjSLfK5o0L/p6tCLVE Ue3jqkCl2VEIsH/CPQY/cXYVXa25tzuh9f+6AAXhKNbZ5ieUFycANPN/cL838DQBVakk GWYPHTI88qD4rzZUSzSk79xYYCMAetLHTtyqZBaCxKzVMCC9PmHyzxWpoLQTCzlCSL9+ pk0wgbuxrFgAP860oSz8YqofHMC2OiAYIxek4pTfinOBebW+f+uxDX5WhV/3gWltfUPX My8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TGYN7fdg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020aa79507000000b00528c7f780a4si14818530pfp.42.2022.07.25.23.08.32; Mon, 25 Jul 2022 23:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=TGYN7fdg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237598AbiGZFx2 (ORCPT + 99 others); Tue, 26 Jul 2022 01:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbiGZFx1 (ORCPT ); Tue, 26 Jul 2022 01:53:27 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B98E275FC for ; Mon, 25 Jul 2022 22:53:26 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id c185so4822716iof.7 for ; Mon, 25 Jul 2022 22:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=9NqP8zb13cEgKtZZvdVuc+bb8giuTenSXo8OvwSJLpc=; b=TGYN7fdgHROPKhTokOlKbDXQsF3DrUWRscdFhO4StXlgImpnjc+ST+m5zQ2mDI5JY5 oLc0+lzu61o5iTTW6v6CUQERKYP0HeLhXsCOqSWoGidrFECb+qFvWSMhWgtz5zWOJmKN B1Rx9tkp22OEJEhu5ZXANe4PcZkbHFe6jFoqdVA8RFQbx62sZ/LWZafa29FDud4j7YqZ +WEmM93hNeShSdCI5Z3Gvk4jK9jfSHYQhLJe3uZNgFxH0kBUeOnAuj7hqqOkmLrZtAHf QiOMZwOBh+CSVBUYt+CqEuWcL96yoIRySBl0yzvWgRzhMrFiAokfvP+ic8GVPdkxnLs8 QpaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=9NqP8zb13cEgKtZZvdVuc+bb8giuTenSXo8OvwSJLpc=; b=2ywZ723mSPzVe+wmDARu8079AyaBhqX+qj6zT6C58SYzD6EmBAbUcfMw+kvqLPzdj3 aDImr/lf7LgguD9zN2lT95KDdPD2/gbHa7z+1UN99wOpWpWrI91G2zT+eZ48wgu/LtZj h6LVJhTOXddNruJP425H7oKEWHZI3v5ir3Prno72V9dr120Hzfbm1i57rBzUBqmtA8+H jeE/0JOL748mUwff3paWkc8uE9xui4KAmFj4BYPMm8nucF1fPIni7LH8mDxeRPG+XtIC R1Q0fWCLBNVhV9sL36EUSloq4bsZXJ1UqBWLm0eKyTw9FgNPumIdJqhv2zFLaPmHwyou peWA== X-Gm-Message-State: AJIora8IJ+i87Ad0D8HPySGc0FhrOl3eeOMF0tjODGz0hXWi2oilaj80 E8bR0cZEHfh6pErLpfLNR584pch5s4MP66e/x7OOsg== X-Received: by 2002:a5e:a618:0:b0:67c:27b4:1f93 with SMTP id q24-20020a5ea618000000b0067c27b41f93mr5476177ioi.75.1658814805551; Mon, 25 Jul 2022 22:53:25 -0700 (PDT) MIME-Version: 1.0 References: <20220725083904.56552-1-huangjie.albert@bytedance.com> <8735epf7j5.fsf@email.froward.int.ebiederm.org> In-Reply-To: <8735epf7j5.fsf@email.froward.int.ebiederm.org> From: =?UTF-8?B?6buE5p2w?= Date: Tue, 26 Jul 2022 13:53:13 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 0/4] faster kexec reboot To: "Eric W. Biederman" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Masahiro Yamada , Michal Marek , Nick Desaulniers , "Kirill A. Shutemov" , Michael Roth , Kuppuswamy Sathyanarayanan , Nathan Chancellor , Peter Zijlstra , Sean Christopherson , Joerg Roedel , Mark Rutland , Kees Cook , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-kbuild@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eric W. Biederman Thank you for your advice and opinion, I am very honored Eric W. Biederman =E4=BA=8E2022=E5=B9=B47=E6=9C=882= 6=E6=97=A5=E5=91=A8=E4=BA=8C 01:04=E5=86=99=E9=81=93=EF=BC=9A > > Albert Huang writes: > > > From: "huangjie.albert" > > > > In many time-sensitive scenarios, we need a shorter time to restart > > the kernel. However, in the current kexec fast restart code, there > > are many places in the memory copy operation, verification operation > > and decompression operation, which take more time than 500ms. Through > > the following patch series. machine_kexec-->start_kernel only takes > > 15ms > > Is this a tiny embedded device you are taking the timings of? > > How are you handling driver shutdown and restart? I would expect those > to be a larger piece of the puzzle than memory. There is no way to make the code universal in the time optimization here, and various devices need to be customized, but we have some solutions to achieve the maintenance and recovery of these devices, especially the scanning and initialization of pci devices > > My desktop can do something like 128GiB/s. Which would suggest that > copying 128MiB of kernel+initrd would take perhaps 10ms. The SHA256 > implementation may not be tuned so that could be part of the performance > issue. The SHA256 hash has a reputation for having fast > implementations. I chose SHA256 originally simply because it has more > bits so it makes the odds of detecting an error higher. > Yes, sha256 is a better choice, but if there is no memory copy between kexec load and kexec -e, and this part of the memory is reserved. Don't think this part of memory will be changed. Especially in virtual machine scenarios > > If all you care about is booting a kernel as fast as possible it make > make sense to have a large reserved region of memory like we have for > the kexec on panic kernel. If that really makes sense I recommend > adding a second kernel command line option and a reserving second region > of reserved memory. That makes telling if the are any conflicts simple. > I initially implemented re-adding a parameter and region, but I figured out later that it doesn't really make sense and would waste extra memory. > > I am having a hard time seeing how anyone else would want these options. > Losing megabytes of memory simply because you might reboot using kexec > seems like the wrong side of a trade-off. Reuse the memory reserved by the crash kernel? Why does it increase memory consumption? > > The CONFIG_KEXEC_PURGATORY_SKIP_SIG option is very misnamed. It is not > signature verification that is happening it is a hash verification. > There are not encrypted bits at play. Instead there is a check to > ensure that the kernel has not been corrupted by in-flight DMA that some > driver forgot to shut down. > Thanks for pointing that out. but Even if the data is detected to have been changed, there is currently no way to recover it. I don't have a good understanding of this place yet. maybe for security rea= sons=EF=BC=9F > So you are building a version of kexec that if something goes wrong it > could very easily eat your data, or otherwise do some very bad things > that are absolutely non-trivial to debug. > > That the decision to skip the sha256 hash that prevents corruption is > happening at compile time, instead of at run-time, will guarantee the > option is simply not available on any general purpose kernel > configuration. Given how dangerous it is to skip the hash verification > it is probably not a bad thing overall, but it is most definitely > something that will make maintenance more difficult. > Maybe parameters will be a better choice. What do you think ? > > If done well I don't see why anyone would mind a uncompressed kernel > but I don't see what the advantage of what you are doing is over using > vmlinux is the build directory. It isn't a bzImage but it is the > uncompressed kernel. > > As I proof of concept I think what you are doing goes a way to showing > that things can be improved. My overall sense is that improving things > the way you are proposing does not help the general case and simply adds > to the maintenance burden. I don't think so. The kernel startup time of some lightweight virtual machines maybe 100-200ms (start_kernel->init). But this kexec->start_kernel took more than 500ms. This is still valuable, and the overall code size is also very small. > Eric > > > > > How to measure time: > > > > c code: > > uint64_t current_cycles(void) > > { > > uint32_t low, high; > > asm volatile("rdtsc" : "=3Da"(low), "=3Dd"(high)); > > return ((uint64_t)low) | ((uint64_t)high << 32); > > } > > assembly code: > > pushq %rax > > pushq %rdx > > rdtsc > > mov %eax,%eax > > shl $0x20,%rdx > > or %rax,%rdx > > movq %rdx,0x840(%r14) > > popq %rdx > > popq %rax > > the timestamp may store in boot_params or kexec control page, so we can > > get the all timestamp after kernel boot up. > > > > huangjie.albert (4): > > kexec: reuse crash kernel reserved memory for normal kexec > > kexec: add CONFING_KEXEC_PURGATORY_SKIP_SIG > > x86: Support the uncompressed kernel to speed up booting > > x86: boot: avoid memory copy if kernel is uncompressed > > > > arch/x86/Kconfig | 10 +++++++++ > > arch/x86/boot/compressed/Makefile | 5 ++++- > > arch/x86/boot/compressed/head_64.S | 8 +++++-- > > arch/x86/boot/compressed/misc.c | 35 +++++++++++++++++++++++++----- > > arch/x86/purgatory/purgatory.c | 7 ++++++ > > include/linux/kexec.h | 9 ++++---- > > include/uapi/linux/kexec.h | 2 ++ > > kernel/kexec.c | 19 +++++++++++++++- > > kernel/kexec_core.c | 16 ++++++++------ > > kernel/kexec_file.c | 20 +++++++++++++++-- > > scripts/Makefile.lib | 5 +++++ > > 11 files changed, 114 insertions(+), 22 deletions(-)