Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp354434rdh; Tue, 19 Dec 2023 00:26:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLUUioYTJEq9YDsd4Ffxr6qU7bowlyxrYqx5X+RUOPrx+bQaxKNjVLZs2IsbISh0yhlqXo X-Received: by 2002:a05:6214:1c4a:b0:67f:696:2037 with SMTP id if10-20020a0562141c4a00b0067f06962037mr12462569qvb.60.1702974410007; Tue, 19 Dec 2023 00:26:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702974409; cv=none; d=google.com; s=arc-20160816; b=ikRlcfxrbiKAlJ/BhKdxi+/64nmxvQ/o8p++wUuolgg5rO7atl/yBjUD+Y52mKRhBQ AcP+9ZsnV7ZXNQMpy6xRMejXn1LmxiHBOiVpqfVewnjpjeoc38hDcshR3J6pV4RIc+Yp HmuUBUGpqvgfyk5qDEhq64KTdd9su06drIIrtPqgQgm1R2zufaoRqtseHhNASaUH3zua GzQswWEknVTeW0/EUEl6rd9CtYjRpn2raz8m4OPEaWJ5ihWjHjA2JIDG2j1VMwdspIgl HAxHK3FN9yGNHK8MVtnoUth8K+0qTVuI67hUcHNFuNe+8HSm3W8urffXY4iNWESZemHr HBfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=td3C4F14eqefor6PZNRVtU0ftiPg4SDbdyzMDoGzJzM=; fh=9ij+VcRv7xF9/sllVKdRFOlR8usQEBBlqxlxF3PBxS0=; b=iwkEaAzybQi5Gu4pvUGChtF19MjVMApUB0f4jGkr2E26023CnMH6GGpiYbR9hhJ/3o Yf/j5gtQzznSgEcGWr+GpBKrwtgWTJ2j5qCUmX9xpNeEjuDomf49F0zOtnkOg3AmjmLI 0FlXIonuiN+xsQHTaKocRrogGZEin4P6ltZ763XlcCist35PQ5Yy6Vip/FhGM96hJhjF 9eFWxSTThBTYUcH+5LPdDJtPTq9EduWbQVVMSOj+i+fjh6u7OAeOif7EHNUqiLNTQjtl bXLyMabWD84+0TbqK6FI2zxGeNYf9vHOffSkSgPO5XVTycQnd9Pi8G5T8l57QKE58VZV RkUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DYaQ6wNM; spf=pass (google.com: domain of linux-kernel+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y9-20020a0c8ec9000000b0067abffdfd66si5792751qvb.277.2023.12.19.00.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 00:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DYaQ6wNM; spf=pass (google.com: domain of linux-kernel+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BD5BB1C23807 for ; Tue, 19 Dec 2023 08:26:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E5F512B8C; Tue, 19 Dec 2023 08:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DYaQ6wNM" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE23012B71 for ; Tue, 19 Dec 2023 08:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702974402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=td3C4F14eqefor6PZNRVtU0ftiPg4SDbdyzMDoGzJzM=; b=DYaQ6wNMHcbJ+MoD8n2CQ3AGK1oWCXW9CbUR2GgT0TXferx74enmGr0+IxUqHSbqMQP0bM 5hgZesj8IRh58fAGXuTFsduX4U5rDtROV/VkZ1kASw2EhBCMd8c3NsQCSPWK/yyJvcfpyU Zvr2goWUjJ+fo822rUq64HoQFOZKPmY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-3xfZhagFNXmOmrFsiCoxtA-1; Tue, 19 Dec 2023 03:26:35 -0500 X-MC-Unique: 3xfZhagFNXmOmrFsiCoxtA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8EDC185A78A; Tue, 19 Dec 2023 08:26:34 +0000 (UTC) Received: from localhost (unknown [10.72.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFAB73C27; Tue, 19 Dec 2023 08:26:33 +0000 (UTC) Date: Tue, 19 Dec 2023 16:26:30 +0800 From: "bhe@redhat.com" To: "Gowans, James" Cc: "akpm@linux-foundation.org" , "kexec@lists.infradead.org" , "maz@kernel.org" , "tony.luck@intel.com" , "sre@kernel.org" , "linux-kernel@vger.kernel.org" , "seanjc@google.com" , "mingo@redhat.com" , "pbonzini@redhat.com" , "tglx@linutronix.de" , "arnd@arndb.de" , "wens@csie.org" , "ebiederm@xmission.com" , =?iso-8859-1?Q?Sch=F6nherr=2C_Jan_H=2E?= , "Graf (AWS), Alexander" , "orsonzhai@gmail.com" , "bp@alien8.de" , "samuel@sholland.org" , "pavel@ucw.cz" , "jernej.skrabec@gmail.com" Subject: Re: [PATCH] kexec: do syscore_shutdown() in kernel_kexec Message-ID: References: <20231213064004.2419447-1-jgowans@amazon.com> <9ffa2c4d3e808feb2afa6f02f4afabf1cd674516.camel@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9ffa2c4d3e808feb2afa6f02f4afabf1cd674516.camel@amazon.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 On 12/19/23 at 07:41am, Gowans, James wrote: > On Tue, 2023-12-19 at 12:22 +0800, Baoquan He wrote: > > Add Andrew to CC as Andrew helps to pick kexec/kdump patches. > > Ah, thanks, I didn't realise that Andrew pulls in the kexec patches. > > > > On 12/13/23 at 08:40am, James Gowans wrote: > > ...... > > > This has been tested by doing a kexec on x86_64 and aarch64. > > > > Hi James, > > > > Thanks for this great patch. My colleagues have opened bug in rhel to > > track this and try to veryfy this patch. However, they can't reproduce > > the issue this patch is fixing. Could you tell more about where and how > > to reproduce so that we can be aware of it better? Thanks in advance. > > Sure! The TL;DR is: run a VMX (Intel x86) KVM VM on Linux v6.4+ and do a > kexec while the KVM VM is still running. Before this patch the system > will triple fault. Thanks a lot for these details, I will forward this to our QE to try. > > In more detail: > Run a bare metal host on a modern Intel CPU with VMX support. The kernel > I was using was 6.7.0-rc5+. > You can totally do this with a QEMU "host" as well, btw, that's how I > did the debugging and attached GDB to it to figure out what was up. > > If you want a virtual "host" launch with: > > -cpu host -M q35,kernel-irqchip=split,accel=kvm -enable-kvm > > Launch a KVM guest VM, eg: > > qemu-system-x86_64 \ > -enable-kvm \ > -cdrom alpine-virt-3.19.0-x86_64.iso \ > -nodefaults -nographic -M q35 \ > -serial mon:stdio > > While the guest VM is *still running* do a kexec on the host, eg: > > kexec -l --reuse-cmdline --initrd=config-6.7.0-rc5+ vmlinuz-6.7.0-rc5+ && \ > kexec -e > > The kexec can be to anything, but I generally just kexec to the same > kernel/ramdisk as is currently running. Ie: same-version kexec. > > Before this patch the kexec will get stuck, after this the kexec will go > smoothly and the system will end up in the new kernel in a few seconds. > > I hope those steps are clear and you can repro this? > > BTW, the reason that it's important for the KVM VM to still be running > when the host does the kexec is because KVM internally maintains a usage > counter and will disable virtualisation once all VMs have been > terminated, via: > > __fput(kvm_fd) > kvm_vm_release > kvm_destroy_vm > hardware_disable_all > hardware_disable_all_nolock > kvm_usage_count--; > if (!kvm_usage_count) > on_each_cpu(hardware_disable_nolock, NULL, 1); > > So if all KVM fds are closed then kexec will work because VMXE is > cleared on all CPUs when the last VM is destroyed. If the KVM fds are > still open (ie: QEMU process still exists) then the issue manifests. It > sounds nasty to do a kexec while QEMU processes are still around but > this is a perfectly normal flow for live update: > 1. Pause and Serialise VM state > 2. kexec > 3. deserialise and resume VMs. > In that flow there's no need to actually kill the QEMU process, as long > as the VM is *paused* and has been serialised we can happily kexec. > > JG >