From nobody Fri Feb 16 13:17:08 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tbssc2R9Qz5Bs3p; Fri, 16 Feb 2024 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tbssc1jn7z4YZw; Fri, 16 Feb 2024 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708089428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=64va3I4ZmRjSy2WpAhooJs+muIcPaOh0FARL4daaAmM=; b=QaGDvYgC8ifxNunLmlFbyfol/SYrfVczszag7YmhvyBdm8TNjEqR6tQB49PdJ0Jz9w33N6 2oJCKu27WlJRzUBzkP5TigoaPMme1XkKnSdMIBabFJniQbIVvcEaSFp3Puwan6O2i8LL0k g8z6rUdbcxQ59jPefdIXzq5S6Fsihk05lToiv75lrJ6mGGEplOtrzZIPDAypfqLFrXBDSR aQmfDOuDb3jldjepD1LfXC9ZhvfEmjYGsTaN3DoQnsmBvDUY6Iunp6icb3dUTsYtkoOugB 62ZmF9PUPmeugUh5Ghf7EFm9ep8pZhRA8GMYrrx0zirVHZhAQ+TLuM57sNtX3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708089428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=64va3I4ZmRjSy2WpAhooJs+muIcPaOh0FARL4daaAmM=; b=HLuev/ccSi8NLERGzZLUoXi6kJdE0Bcoh7xuzxnEJupnUTUYGzn6dx0DsGROAOOSzfAnVv gjsS+euV01WaTpRIBqb8WeAFbu1ujICrHy0AX3my0ntJuoKTI5+CJ+wPI1X93XVdUx0tp6 KQe1EBzJeZjPVhaCMGZKAMuuhr6whoILwH99R8cvvwG+Dw6Z6Qc5wjsZQpMpITpKsSsVIe biwdUZD3u6k+Bim0q3+lHX0IeUNGGFIPNgjeS3MRjjzKslnz+wfqeH6SWvBlrDSaMXfMHp qz2FJ94YY4NL3P1XPOKdlciACxWyWJ/FnxB3GU2xBi3dCPSkFxSeW2mXijHf1g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708089428; a=rsa-sha256; cv=none; b=yQHDSt943ToAA+lxRvbpOIpSpLiHSmRxVDnoz+nZ3CKtLZyOEMbWJ1VPjyb4dKTWJRerEv arlMd3AhgUwpLh3HuHLUmJ+UrMCjrRZeiMlImB8SvMBYnb9f8hlcWdKpJy7VsftUh6WOw1 gFifrw/ts9lGB1caFdrQz86aepkjv2VYXoZW7K4fPHPktwdwGiArQMz13hu3bWieJOMsxX P6CQqnUI1RWWC+/xj4Odkku4kgnC+90cUGIU9/nzknnscZDQYQ8YMvhdPBmHQljxbd5PRz PVP8yxDCClE4DemvCX6WLB01JCiK6UkHoeCC6/v7C9pfhWKIy731ggKTcvMbug== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tbssc0nyBzPwL; Fri, 16 Feb 2024 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41GDH8Lo053088; Fri, 16 Feb 2024 13:17:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41GDH86q053085; Fri, 16 Feb 2024 13:17:08 GMT (envelope-from git) Date: Fri, 16 Feb 2024 13:17:08 GMT Message-Id: <202402161317.41GDH86q053085@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: e7e2431586a4 - main - x86/xen: fix migration when ACPI suspend is not available List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e7e2431586a4f1d81fc37410f1ca1a9ae794857b Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=e7e2431586a4f1d81fc37410f1ca1a9ae794857b commit e7e2431586a4f1d81fc37410f1ca1a9ae794857b Author: Roger Pau Monné AuthorDate: 2024-02-06 08:16:44 +0000 Commit: Roger Pau Monné CommitDate: 2024-02-16 13:16:18 +0000 x86/xen: fix migration when ACPI suspend is not available Xen PVH guests expose a very minimal set of ACPI tables, and due to the lack of SCI interrupt FreeBSD doesn't allocate the suspend stacks for saving CPU and FPU contexts. Lack of allocated stacks would lead to a page-fault in cpususpend_handler() when CPUs attempted to use the save context area as a result of a Xen suspend request. However there's no need to save the CPU or the FPU registers in the Xen case, as that's all handled by the hypervisor. Hence avoid saving all this state if the suspend stacks are not allocated. Note that this will currently only apply to PVH guests, HVM ones will still get the stack allocated and the context saved even when not strictly required. I find it easier rather that having to provide cpususpend_handler() with extra information whether the context needs to be saved or not. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43765 --- sys/x86/x86/mp_x86.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 11b11471d736..1027c2c8972b 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -1594,6 +1594,24 @@ cpususpend_handler(void) mtx_assert(&smp_ipi_mtx, MA_NOTOWNED); cpu = PCPU_GET(cpuid); + +#ifdef XENHVM + /* + * Some Xen guest types (PVH) expose a very minimal set of ACPI tables, + * and for example have no support for SCI. That leads to the suspend + * stacks not being allocated, and hence when attempting to perform a + * Xen triggered suspension FreeBSD will hit a #PF. Avoid saving the + * CPU and FPU contexts if the stacks are not allocated, as the + * hypervisor will already take care of this. Note that we could even + * do this for Xen triggered suspensions on guests that have full ACPI + * support, but doing so would introduce extra complexity. + */ + if (susppcbs == NULL) { + KASSERT(vm_guest == VM_GUEST_XEN, ("Missing suspend stack")); + CPU_SET_ATOMIC(cpu, &suspended_cpus); + CPU_SET_ATOMIC(cpu, &resuming_cpus); + } else +#endif if (savectx(&susppcbs[cpu]->sp_pcb)) { #ifdef __amd64__ fpususpend(susppcbs[cpu]->sp_fpususpend);