From patchwork Tue Jul 30 13:29:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13747402 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AAD75C3DA7E for ; Tue, 30 Jul 2024 13:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To: Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=lde9Xp8zGKsL+fxaDR6yexHsJdBQDXsONmpwA4d0E/I=; b=Oais4p3mdxuL93 CYDTeLTgnZU4o6yp2UgoZUppJkmz9nwcUKA+URWrFSSlGJS8Q4ohJcIotg5lHyc2TFRG65OYIeBZY 6dlRrLFJMqTtvM781LZTSKN3L6Iyk9VGIiuLLTN2QqLyBT14PwhWlkkw1ael1WWstWBAxHP79rJPX lXVVnOGvu1RwZdRH1afnULq08NUOotvBLwXbTDkLwyz3NYnYqH6V8SjopGoGOcUFXWeevtS8usEAC 5PdHoAwilJ9easLZQXCw1jIzSDeb9Owl3iiXsNw+//gx1Hckt/VXbAyhMHQ6UCNaAm6RdjkXlvc5b YVy1Nn7MrnCuI04HoIQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYmwu-0000000FHOF-1D3W; Tue, 30 Jul 2024 13:31:32 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYmwQ-0000000FHEh-32Q3 for linux-arm-kernel@lists.infradead.org; Tue, 30 Jul 2024 13:31:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C8CFCCE0E70; Tue, 30 Jul 2024 13:31:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C0DFC32782; Tue, 30 Jul 2024 13:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722346260; bh=yy7+5mJanhSnLny9/z+l3tsyVx0RSv5rtYylirglrzA=; h=From:Subject:Date:To:Cc:From; b=brxI5y5+ueGJkOCI3yHtZTXCSXMZnPdO4pOcQxjAzZY3MTMHq1ARACPHMXzKcaVxm snAP/VyJVG0NFBLMnvZRQUXfsNvTWl4GxVcyiJJ3Pve+qH4wyxQtsc9M7zmvcx4OJP wuE1ZlhmIb9GH4S+A8OxR384km5s+ZusCcNI915Pof2JnyeMRINijWyA3PviY4Qfyx st2sIrjrtAlvG8JIsc1/H5DO4+TO6AAKqHz7GUpmEn+qf/Ovv0p9Xrl2/3FRkJg9SB g+AihyWv1gOpwZ9oiJVM1wlALxc954F7Hh+W/V6mzj0qAuA06UHXfxHi2UjDXNV+7E fVAMCTgq2YYKA== From: Mark Brown Subject: [PATCH v6 0/4] KVM: arm64: Fix underallocation of storage for SVE state Date: Tue, 30 Jul 2024 14:29:12 +0100 Message-Id: <20240730-kvm-arm64-fix-pkvm-sve-vl-v6-0-cae8a2e0bd66@kernel.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKjqqGYC/33QTWrDMBAF4KsErauin9FIyar3CF1Y1jgRSewgF ZESfPfKgVIXg5ZvmPkG3pNlSpEyO+yeLFGJOU5jDfi2Y/25G0/EY6iZKaFAoAB+KTfepRsCH+K D35eYC/Fy5VL3wcoh2OAFq/f3RHXlZR8/az7H/DWl79eropbpr4oNtSgueO/cAOTBS/AfF0ojX d+ndGILW+SaMi1KVgqdCOhBe+jlhtJryrYoXSmzJ+ukFRjQbCj4o2yztgKV8uj2rvNKhx42lFl TrkWZSgUlrbHagcH/Xc3z/AOeMHbx7wEAAA== To: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Fuad Tabba Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, Mark Brown X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2551; i=broonie@kernel.org; h=from:subject:message-id; bh=yy7+5mJanhSnLny9/z+l3tsyVx0RSv5rtYylirglrzA=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmqOsNqaeRRdie8SdDAQ1lneq5D6pOxAZk+JOkgK1T u5d7SHSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZqjrDQAKCRAk1otyXVSH0KxZB/ 49KowH0dC5AqjvGa56kImJwH54qJ+8xxn8+/i4xsXTkGObox6ZvOgGSo0TraoMKT9Qll/hDZ03IWmP SFD94uuj5FauK0rAoGn6Vj62Zd86banU5TfpapC7jWyMQ99+Kvdihv/dm951YlTwNk6AolPrqCwNgx QnPb7tuHeWkWfmFT5fvJAz40N3XZ+VtLuB+BypWWGc2e6gVzM/IfP5cZHazTCB1DALVHB3ruJVXLpA qWuiFwlt8HNOyo+UY172RIFVg9Xad1pSknK3F8eBIrH/C23FngcxSgXSG+sFCwjdPRekw4vv8CveD9 Nwpt3j9rwcWmVm0LxFM4BcZXmE0mMU X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240730_063103_148629_A8C1A484 X-CRM114-Status: GOOD ( 10.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As observed during review the pKVM support for saving host SVE state is broken if an asymmetric system has VLs larger than the maximum shared VL, fix this by discovering then using the maximum VL for allocations and using RDVL during the save/restore process. Fuad posted[1] another attempt to address this issues but as indicated in review I have maintanability concerns since the VL configuration does not follow best practices and the enumeration is not well integrated with the rest of the enumeration code. [1] https://lore.kernel.org/r/20240606092623.2236172-1-tabba@google.com Signed-off-by: Mark Brown --- Changes in v6: - Rebase onto v6.11-rc1. - Link to v5: https://lore.kernel.org/r/20240708-kvm-arm64-fix-pkvm-sve-vl-v5-0-d2175738456b@kernel.org Changes in v5: - Clarify commit message on patch 3. - Link to v4: https://lore.kernel.org/r/20240704-kvm-arm64-fix-pkvm-sve-vl-v4-0-b6898ab23dc4@kernel.org Changes in v4: - Roll in Catalin's acks. - Link to v3: https://lore.kernel.org/r/20240607-kvm-arm64-fix-pkvm-sve-vl-v3-0-59e781706d65@kernel.org Changes in v3: - Replace %u with %lu in late CPU error message. Changes in v2: - Downgrade check for a late CPU increasing maximum VL to a warning only but do it unconditionally since pKVM prevents late CPUs anyway. - Commit log tweaks. - Link to v1: https://lore.kernel.org/r/20240605-kvm-arm64-fix-pkvm-sve-vl-v1-0-680d6b43b4c1@kernel.org --- Mark Brown (4): arm64/fpsimd: Introduce __bit_to_vl() helper arm64/fpsimd: Discover maximum vector length implemented by any CPU KVM: arm64: Fix FFR offset calculation for pKVM host state save and restore KVM: arm64: Avoid underallocating storage for host SVE state arch/arm64/include/asm/fpsimd.h | 17 +++++++++++++++ arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/asm/kvm_hyp.h | 3 ++- arch/arm64/include/asm/kvm_pkvm.h | 2 +- arch/arm64/kernel/fpsimd.c | 38 +++++++++++++++++++++++++++------ arch/arm64/kvm/hyp/fpsimd.S | 5 +++++ arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 6 +++--- arch/arm64/kvm/hyp/nvhe/pkvm.c | 2 +- arch/arm64/kvm/reset.c | 6 +++--- 10 files changed, 65 insertions(+), 18 deletions(-) --- base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b change-id: 20240604-kvm-arm64-fix-pkvm-sve-vl-13cd71fd7db0 Best regards,