From nobody Wed Feb 08 18:05:20 2023 X-Original-To: freebsd-virtualization@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 4PBnwP4htHz3nk40 for ; Wed, 8 Feb 2023 18:05:25 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PBnwN5X5Tz3nrb; Wed, 8 Feb 2023 18:05:24 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=UbukKn7b; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::12e as permitted sender) smtp.mailfrom=markjdb@gmail.com; dmarc=none Received: by mail-il1-x12e.google.com with SMTP id v15so967147ilc.10; Wed, 08 Feb 2023 10:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=zQOHdUDbGP1ViKIYaGVZKyXs9Q4XZmpU3BUfnv2lpRI=; b=UbukKn7bGosd1s9/WRvbCu/m1ltWNigAtk3k2QDnjJDz4+z4SSRBr+v0gjJB2xoLFI 25FJfuNLnQKNOUFjuDt8wQIGpMReujswb4Uo/eJYMdjRoOxRMSumv+oGTuBEwzNb6cks XgS9Fkz4rM1PmY9QUJwY82m733BtJ31/y6DMwxuQ+4xZq4bITMpuQJtJ1pqeogqks2Kg r31kWd8G/yEt/u9ihQa5E8VmGDZN8V+SjncUFNY8lp2iEfNYNNbGzkppiYrsHNn1GnxT 4av6RhlJhqd73EGDo8mRPF44yhPWF4RrwX8Pl/NkXM3dNADFd22iwmuEvzQwgVYyr0RJ Kt2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zQOHdUDbGP1ViKIYaGVZKyXs9Q4XZmpU3BUfnv2lpRI=; b=faSmSwcQtudGjqLcrFKVeJRlk1YbUNSpM+GYV+Ly9HXMrhaQOuWyhDAJ+6AL9dA4rO MqDYVbv0MAY7rJZkO9B49oPl7qIuPTOLDaoH6OgenkST8rwuBrrzuXlbnhsMqCIjnLLV ukXaSthh0I8e7mAXKYrsz86RIc1iUA221YbVDu7FYnduAJedeK+N8pZ6D3n1QSWoakIw xquslK/Odv01jm2PZpOxX7VvAjWrwAcNaRKnfcw+7zINTpTmjZ57XeaznbAKmw1PyST6 UE58Y9iyH+z9Xo3KL2HVZLGbk2RY276oTYCu1rxjq0wHxZE/onP2tn0560BZzUXcYjH9 74vA== X-Gm-Message-State: AO0yUKUk8Ebn/FUl01DEU+jo0t4HbWFGQvCfZtYi+oALHzpQkmpL/KWV omoXWhXjSzz5AiLJDHTH3n7UT/e1urY= X-Google-Smtp-Source: AK7set9X9uaq6iNs/Ae7biFZ5LDhC7FCNWSrN2PAzcgRh0v9j86J6Lz2ZFJIBWuRelPRvdn/rfzUxw== X-Received: by 2002:a05:6e02:8ab:b0:313:e431:10fb with SMTP id a11-20020a056e0208ab00b00313e43110fbmr5752457ilt.2.1675879523276; Wed, 08 Feb 2023 10:05:23 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id y24-20020a02ce98000000b003c488204c6fsm28356jaq.76.2023.02.08.10.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 10:05:22 -0800 (PST) Date: Wed, 8 Feb 2023 13:05:20 -0500 From: Mark Johnston To: Corvin =?iso-8859-1?Q?K=F6hne?= , jhb@freebsd.org Cc: freebsd-virtualization@freebsd.org Subject: bhyve 13.1 compatibility breakage Message-ID: References: <202211230800.2AN80G58068419@gitrepo.freebsd.org> List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spamd-Result: default: False [-2.60 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.90)[-0.902]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; DKIM_TRACE(0.00)[gmail.com:+]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::12e:from]; MLMMJ_DEST(0.00)[freebsd-virtualization@freebsd.org]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCPT_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_TLS_LAST(0.00)[]; TO_DN_SOME(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-Rspamd-Queue-Id: 4PBnwN5X5Tz3nrb X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N On Sun, Jan 15, 2023 at 10:46:21AM -0500, Mark Johnston wrote: > On Wed, Nov 23, 2022 at 08:00:16AM +0000, Corvin Köhne wrote: > > The branch main has been updated by corvink: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=7c326ab5bb9aced8dcbc2465ac1c9ff8df2ba46b > > > > commit 7c326ab5bb9aced8dcbc2465ac1c9ff8df2ba46b > > Author: Corvin Köhne > > AuthorDate: 2022-11-21 14:00:04 +0000 > > Commit: Corvin Köhne > > CommitDate: 2022-11-23 08:00:04 +0000 > > > > vmm: don't lock a mtx in the icr_low write handler > > > > x2apic accesses are handled by a wrmsr exit. This handler is called in a > > critical section. So, we can't lock a mtx in the icr_low handler. > > > > Reported by: kp, pho > > Tested by: kp, pho > > Approved by: manu (mentor) > > Fixes: c0f35dbf19c3c8825bd2b321d8efd582807d1940 vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs. > > MFC after: 1 week > > MFC with: c0f35dbf19c3c8825bd2b321d8efd582807d1940 > > Sponsored by: Beckhoff Automation GmbH & Co. KG > > Differential Revision: https://reviews.freebsd.org/D37452 > > --- > > Hi Corvin, > > This seems to break AP startup when using bhyve/libvmmapi from FreeBSD > 13.1 on a kernel built from main. It looks like the commit somehow > regresses commit 769b884e2e2, but I'm not sure yet exactly how. I debugged this further and am not quite sure how to fix the problem, which isn't specific to this commit after all. I'll try to describe it here. Suppose we're booting a VM with 2 vCPUs. When the BSP raises the INIT IPI to start AP 1, vlapic_icrlo_write_handler() looks up the destination vCPU with vlapic_calcdest(), which only returns active vCPUs. However, old bhyve executables activate APs (i.e., call vm_activate_cpu()) lazily, only upon receiving a VM_EXITCODE_SPINUP_AP message. Thus, vm_handle_ipi() simply doesn't doesn't do anything since "dmask" is empty, so APs don't boot up. To further complicate things, new vmm.ko allocates vCPUs lazily. New bhyve executables call vm_activate_cpu() for all vCPUs before running the BSP, but as I said above, old bhyve executables do not. So merely fixing "dmask" in vlapic_icrlo_write_handler() to include not-yet-activated vCPUs doesn't work, and we can't allocate a new vCPU in that context. In general it seems that we want an INIT IPI to trigger allocation of a vcpu structure to preserve compatibility with old bhyve, but I don't see a good way to implement that. I would quite like to fix this since I make heavy use of 13.1-RELEASE bhyve+jails on a kernel running main. I believe bhyve from stable/13 is unaffected, but 13.2 is not yet released. Any suggestions would be appreciated.