From nobody Mon Nov 23 04:26:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1795294030; cv=none; d=zohomail.com; s=zohoarc; b=dCxwqgNLDNNqOxV+UMyhhjusghQZMzgrbjlnVZWRA8UtDkcnlXb7+cufXhObQ1yE8jo3SIV1RAvv0HkEz/eh8fakU8PzS++nrOQ3zE/rymueCkjE3RNFr8uikIzdqLCJAPwZ7oN1FwUJI4G6x2qsG8JyCdKLOm+fUW7lMkYDg8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795294030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6cw4bVM/elmiYBT/hpISiGamNAca35rw9WaolQpyJgc=; b=WghUBoHvwNW0peBbSMZxZHslgOBXvAmojpD/7Cu6hLCwzQ4LcnEYLSHjaCOQ/6xzmE+QrWUaK3PgcX4/hTcCR4pKlz7otkd20KlXosGmfXGyDnM6yuRpHJkS7haruxAEXbWVYrsHnZYvi/3t+K+KWtf0RMe5FNRbHjXFbRIj0NI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795294030386809.7091940900418; Sat, 21 Nov 2026 12:47:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xUryS-0004SS-W1; Sat, 21 Nov 2026 15:46:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xUryQ-0004Rb-Tz for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:14 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xUryP-0005z8-3F for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:14 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4a210470b49so18092225e9.2 for ; Sat, 21 Nov 2026 12:46:12 -0800 (PST) Received: from PKL-HASEEBA-LT.. ([39.36.59.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b39b6sm180652385e9.12.2026.11.21.12.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2026 12:46:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795293971; x=1795898771; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6cw4bVM/elmiYBT/hpISiGamNAca35rw9WaolQpyJgc=; b=FW6zivGtYENpgMm2Irynn4BM+ylPkCGxwSwUb3nx7bXpH8R3QEEqE1gxDeVNMRZZ5h 2yJWLpP175XBm8vcRXeiZEEC85HfmkC681dJZnWlQGxtWWG+5/cBU/NxG5GZt+1YNWe8 1YP/FALcaIP0oSqe+5OU2SkABNMiSORHEUSZPsRfcSZcWaIPEN1BlWsJxF8TgPG1pxW9 Fpn5ebG1/9GPe0e+GIbnW58EVNQGzQEcqpF0psEgEL/phmu6YMf1vm+c/lae3iywpf7G AGf29Ve8nfNYXILy5spBjAPeCMd86s7s85nFF+E9huqnMnOy7cin8bwV91/KX/KnaPH5 VBpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795293971; x=1795898771; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6cw4bVM/elmiYBT/hpISiGamNAca35rw9WaolQpyJgc=; b=b3th0bEvoMhrSIQPP0Sjt+nED7MJZcKZXQykmvVAJ7Xzwmz8gQcc4LwWTr8NuJR9/E CqtqPB2dLzDtm6vrkkOKLVeS0dYTamIFFxz5mZ0toEN9ZmtL60V3hBte4vkcZLi86h/F ArDLMmcigFvBPPkVLsE8D8pP7+W73sE+Z/Frb8b6JNdio33zT9FyGA9R4M9hBKFpEbRX qGFDJ7r5Y/gPKLs0RRrjmdLC7Pfxl8/QUBz88E7olCn8jCSOZoilhHHmu8taLYksDTuf LLlxqNMX3dvNvRudpaY4bIkEkI+5dwqqoa4Odh67vQoG08prS+5FHKDykP+gm1DBiRWf IaKg== X-Forwarded-Encrypted: i=1; AL+hErHrcy5WONm08/eE8NZnGsTvZ8O8IealNQr4Sx1QB6QZ7AF53/QeCLvDIfaZCI2cphXEkPsvcJ0AE+lI@nongnu.org X-Gm-Message-State: APuU4Z8fhIhmejM1DrvcPQRHjUxl4VaFatMU7/X5XFlA274VkipRWb3z jyw0YCpvdREm9iqA8LmNRkyu3OuWvnI16sf3/6IrTUalgkd/6ja3WHNT X-Gm-Gg: AZFdTZdm3t8iZlXtry8rzNzoFlwJHFDhrlEEcX9rr1r6JLsfdwwaaSTS8vKBtpKSLKb VmCkAz1wsL3sJQYCAWo6tyE7h3aW145ZSmQZbw60kbkoy28E28qk8klZWXGtrBRYQ7a2qVH3ela 6E4sLsYHaGYcxN7C8psRwRMRudjFmDoCi6g8+Q2lKe3Iqgy7rr/hEjqvRW477denymvEsLeeECJ qEb2eOQsQSAs2oHL1FPYgA2aPSvlf5ZjgUl+aois5Ldy869p1wimlgWjZd82k77NqSb+xGjN4eQ LR9skGaYkCCg28SY5+93lkQ4DYjb9IFiWn6heddr/q0S/n0bblPGTyjuEwG4lV2Jmm6m0UpYh76 NCmRctEn38kEdTI1BtYvmWyKZa7ZuN2lreDmdqvaDV7KjyqBodvYfOyX7z0YNWjDy6jCyttzkuP vdrV2JHYuo+N0jrveFEETi28C3XFuMKR6xLkZ5C7ZEBhNUIIJ2HUDtiPMZDmBnn5VxhabmLmjMF lKdPQ/O39XTs7lsMOwa5zCR/L67/CV7LZ1urxOdenl3BZtDSn1alNWTXinljmNSjsA8rLCMoLmF m+v41aByHmXgXFf1s5tSRTLda/Hhn4rY0UBtLV2rJ6PzQobnbBzhhka+H1o8m0i8UFByownsKdc 2JsTKF6a/Iod6ZcdRbmMY3ms= X-Received: by 2002:a05:600c:190d:b0:4ba:2bfc:c8b5 with SMTP id 5b1f17b1804b1-4bb888267aemr149715085e9.10.1795293971472; Sat, 21 Nov 2026 12:46:11 -0800 (PST) From: Haseeb Ashraf To: Peter Maydell , qemu-arm@nongnu.org Cc: Haseeb Ashraf , Eric Auger , Marc Zyngier , Mohamed Mediouni , Pierrick Bouvier , Paolo Bonzini , Volodymyr Babchuk , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [RFC PATCH v2 1/3] target/arm/kvm: Add kvm_arm_el2_e2h0_supported() Date: Sun, 22 Nov 2026 01:45:59 +0500 Message-ID: <20261121204601.741616-2-haseebashraf091@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261121204601.741616-1-haseebashraf091@gmail.com> References: <20261121095636.289814-1-haseebashraf091@gmail.com> <20261121204601.741616-1-haseebashraf091@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=haseebashraf091@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1795294033559154100 Content-Type: text/plain; charset="utf-8" From: Haseeb Ashraf Add a helper reporting whether KVM can limit a nested guest to an nVHE-only EL2 (HCR_EL2.E2H RES0) through the KVM_ARM_VCPU_HAS_EL2_E2H0 vCPU feature. KVM advertises this with KVM_CAP_ARM_EL2_E2H0. The next patch uses it to let the user select an nVHE-only EL2. Signed-off-by: Haseeb Ashraf --- target/arm/kvm-stub.c | 5 +++++ target/arm/kvm.c | 5 +++++ target/arm/kvm_arm.h | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c index c9387f5c8c..88e35909c4 100644 --- a/target/arm/kvm-stub.c +++ b/target/arm/kvm-stub.c @@ -42,6 +42,11 @@ bool kvm_arm_el2_supported(void) return false; } =20 +bool kvm_arm_el2_e2h0_supported(void) +{ + return false; +} + /* * These functions should never actually be called without KVM support. */ diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 36a5faf537..8ef5597c68 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -2178,6 +2178,11 @@ bool kvm_arm_el2_supported(void) return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2); } =20 +bool kvm_arm_el2_e2h0_supported(void) +{ + return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2_E2H0); +} + bool kvm_arm_mte_supported(void) { return kvm_check_extension(kvm_state, KVM_CAP_ARM_MTE); diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index 2e7e02e4a4..0916a5fdb4 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -200,6 +200,14 @@ bool kvm_arm_mte_supported(void); * Returns true if KVM can enable EL2 and false otherwise. */ bool kvm_arm_el2_supported(void); + +/** + * kvm_arm_el2_e2h0_supported: + * + * Returns true if KVM can limit EL2 to nVHE (HCR_EL2.E2H RES0) through + * KVM_ARM_VCPU_HAS_EL2_E2H0, and false otherwise. + */ +bool kvm_arm_el2_e2h0_supported(void); #else =20 static inline bool kvm_arm_aarch32_supported(void) @@ -216,6 +224,11 @@ static inline bool kvm_arm_el2_supported(void) { return false; } + +static inline bool kvm_arm_el2_e2h0_supported(void) +{ + return false; +} #endif =20 /** --=20 2.34.1 From nobody Mon Nov 23 04:26:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1795294030; cv=none; d=zohomail.com; s=zohoarc; b=eeZd+SH/PlNOtdj+9LJNi3Y2GaTCNbqc4jpuj5fEDeXYrrSEhnXVhnrK6RSg214Gbp/1g6FCHtQXr+uB2go77qIwC2OJKK1OEiSDs7uhDgTyiiE6yg0MOmshb7E1j+xdCY9U4P6dC7JJVLfYFaf6/1sFXNBXIbqQbyUEJHBX4is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795294030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dR4oPwMzXZwkzKBHINmHc4eivvVzlJdhh6T4Ur7acMs=; b=RY7lTubcc0kiCQGYUPFg66abOV5l6aY4I7+6KqW0N1c/CmSXcLEIyLgSDn6TM90zbEaz8NB1bBwCb2TE4cfrs0P8eGX8UWP5NMr/ohmYTxYbrcBabcnFKob36IcpDAUxPg1iQI/8SC51nbRuL6xbQHx0c2QnLVXOEtsAg+eRUCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179529403026881.60658187241052; Sat, 21 Nov 2026 12:47:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xUryW-0004Sq-D1; Sat, 21 Nov 2026 15:46:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xUryU-0004SX-Nw for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:18 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xUryS-0005zm-E6 for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:18 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so16592265e9.0 for ; Sat, 21 Nov 2026 12:46:15 -0800 (PST) Received: from PKL-HASEEBA-LT.. ([39.36.59.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b39b6sm180652385e9.12.2026.11.21.12.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2026 12:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795293975; x=1795898775; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dR4oPwMzXZwkzKBHINmHc4eivvVzlJdhh6T4Ur7acMs=; b=0S6CLhSuHf5LkgYUFHyGqWOCsFsDytGC0F0MwcGTjcBeUNbsTCjftSuuL3MuQ3kqQL WkHrdHBCqzCzZXAn7wGIfeAPv0dDH3Owm9P1eWQ2VGRPJi2/nyUWBkEJY88X0FRkOH+R IaMSm6a5GKh2+rXVB9mjHnl48d3fWodF/+Q4m0VmsjHDw1x8AFYg+YRzanAUfVZWdQEH PbWXJeTbCPbmdSJ9FqJYhDJQ65q3ur8c/R7O2990/kw/rKTwt9Cudwf9m7n4pTYdaxU6 /4HTLWDykqMMSAZOwxnwlqYG2OTby/sblgAZ8B3bXcMUw5jlx5ZUjOGsej6SqtkMPWNs Rs3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795293975; x=1795898775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dR4oPwMzXZwkzKBHINmHc4eivvVzlJdhh6T4Ur7acMs=; b=xiJQd1ZY4lPkLoUXeD1wQRJaD+KBfwZg17jO412bL0F0GKg2IfwwyEXVjRjgdency2 uVLa625+dza6aSRyAWskASFN7HgnYe85nMeg0fRbO+ZcJmVHs695I+vZeb2p4TiTmMPo eGqlDCeIjtyLrGmaoACBnqPRShp2GfeFySA8wL1UdeQu4tdh9v/GZRsTTSkBBKVrXQCy 9+RCHDHDeOtbXuA6Fk2KkzHmJhKqoZfIs5O5F1uB0o/7CP9XR41i8NvFr6/W+zQA8Lm8 A3i5UxXh9GdhcRcl3H7JmJs1KAqOsgHqPymylK5hjbep2FtcqK/N1bsqMtBp7oAy1lJ/ QYIQ== X-Forwarded-Encrypted: i=1; AL+hErEU+mTJ1Y2JYTxXcTbfXIg+uNTK170uKfS6H18NV6BjLaNojTeNP1rgWp/FrvyX3U916sNXkvz2ui0k@nongnu.org X-Gm-Message-State: APuU4Z/ZoodCRZ6qNylCfbLfpZQLCBD3yy95yRidBdQRUkumLbXIhxbP G6ll5xDu6q3//R289AoapxHbV3djv8+R/I0FkKRAXE3CORwgziIjK/4l X-Gm-Gg: AZFdTZejEGvr36qKvbT8RgM4phdlunhYhs/VKzCsZKvsmA8OdklgAME6V6yFJS0EhSQ dos93FIEEZATDYYFkenLL5/h5dk+JjunXT+uv6cjlOBnVn2lpJZnQSqMLavnjha8uxG33NY5lWY zjbGJ9KqoVBfPa1Mt8UvdfR+6+/5zI9ZtAPcYdJMUngzcdXOJntiOTOGXGkPmqropNi/ZsKNjOj 3U3L2R8ikkIaAbIkqCjodQmpgbU+5dJ3djwrj3O/ZfJYOoETo1yjT54fqxgNjJipyBRFoUtLgd+ TPTECG1RkiLIGbMGbCxQ7hh0hXuwTP/jv0WTPdWlhGWZ0a/fVSh8JDmZYmM/n7OAiFyfv5ayMbP bZLyEzNgpF8b1dlW5aqkwnVS2qsXIcrTzS4SzPkAKZ7boTTDVp/HuekZUUOhmHCyZ/M+s3es3Jz LUEaEp4C/PAJWiI84RzXmxpdEp+Tqa06XS0FmDfaE/ZD7vbZVuaIjbfX/7lG3dHkVK40eYKfR9v VvC9zrhKxV7mI3EEf87riHAK8BHEYcxLndHZCxaC3DP5ZNlOQk0kWpqPDziAcPrwuRO1YkLi2vG H8w5oq8RO7Zs05ftTRYiKve0qpUPKmff5y28V9DxyLf+h/wfN292DdHKX6ZpeWI8hjwU1bEiu9G D7AdnLewJNlegLn0UQtP+ulE= X-Received: by 2002:a05:600c:4515:b0:4bb:6f67:ca0b with SMTP id 5b1f17b1804b1-4bb888267f4mr158170395e9.29.1795293974532; Sat, 21 Nov 2026 12:46:14 -0800 (PST) From: Haseeb Ashraf To: Peter Maydell , qemu-arm@nongnu.org Cc: Haseeb Ashraf , Eric Auger , Marc Zyngier , Mohamed Mediouni , Pierrick Bouvier , Paolo Bonzini , Volodymyr Babchuk , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [RFC PATCH v2 2/3] target/arm/kvm: Let SYSREG_ID_AA64MMFR1_EL1_VH select an nVHE EL2 Date: Sun, 22 Nov 2026 01:46:00 +0500 Message-ID: <20261121204601.741616-3-haseebashraf091@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261121204601.741616-1-haseebashraf091@gmail.com> References: <20261121095636.289814-1-haseebashraf091@gmail.com> <20261121204601.741616-1-haseebashraf091@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=haseebashraf091@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1795294033647154100 Content-Type: text/plain; charset="utf-8" From: Haseeb Ashraf KVM runs a nested guest with a VHE-only EL2 (HCR_EL2.E2H RES1) unless KVM_ARM_VCPU_HAS_EL2_E2H0 is requested at KVM_ARM_VCPU_INIT time. With that feature FEAT_VHE is hidden: ID_AA64MMFR1_EL1.VH reads 0 and HCR_EL2.E2H is RES0. Guest hypervisors which only support nVHE, such as Xen, can only run in the latter mode. Do not add a dedicated machine or CPU option for it. Derive the vCPU init feature from the ID register field selected by the user instead: SYSREG_ID_AA64MMFR1_EL1_VH=3D0 requests KVM_ARM_VCPU_HAS_EL2_E2H0. KVM does not let userspace write ID_AA64MMFR1_EL1.VH, so the generic "writable fields only" rule would not create the property. Expose it explicitly when the host supports KVM_CAP_ARM_EL2_E2H0. As KVM already reports the requested value after vCPU init, applying the property does not need a KVM_SET_ONE_REG for this field, and the query-cpu-model-expansion dry run on the scratch vCPU skips it. Setting VH=3D0 without virtualization=3Don is rejected. Only ID_AA64MMFR1_EL1.VH is updated in QEMU's copy of the ID registers. Other fields which KVM derives from E2H0 (e.g. ID_AA64MMFR4_EL1) are not refreshed. Suggested-by: Marc Zyngier Suggested-by: Volodymyr Babchuk Signed-off-by: Haseeb Ashraf --- v2: - Use Eric Auger's SYSREG framework instead of a dedicated vhe machine/CPU property. - Expose the init-driven VH field only when KVM supports E2H0. - Add the virtualization=3Don consistency check and document VH=3D0. docs/system/arm/cpu-features.rst | 22 ++++++++++++++ target/arm/cpu-idregs.h | 31 +++++++++++++++++++ target/arm/cpu64.c | 51 +++++++++++++++++++++++++------- target/arm/kvm.c | 24 +++++++++++++-- 4 files changed, 114 insertions(+), 14 deletions(-) diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-feature= s.rst index 13454783cf..cde26c04b9 100644 --- a/docs/system/arm/cpu-features.rst +++ b/docs/system/arm/cpu-features.rst @@ -579,6 +579,28 @@ either not writable with the specific host kernel, unk= nown to this QEMU build, or intentionally not exposed because it overlaps a legacy composite option. =20 +Selecting an nVHE-only EL2 +-------------------------- + +With ``-machine virt,virtualization=3Don``, KVM presents a VHE-only EL2 to +the guest (``HCR_EL2.E2H`` is RES1) by default. A guest hypervisor which +only supports nVHE, such as a type-1 hypervisor like Xen, needs VHE to be +hidden. This is done by setting ``ID_AA64MMFR1_EL1.VH`` to 0:: + + $ qemu-system-aarch64 -M virt,virtualization=3Don -accel kvm \ + -cpu host,SYSREG_ID_AA64MMFR1_EL1_VH=3D0 + +QEMU then requests ``KVM_ARM_VCPU_HAS_EL2_E2H0`` when initializing the +vCPUs, so that ``HCR_EL2.E2H`` is RES0 for the guest. Leaving the +property unset, or setting it to 1, keeps the default VHE-only EL2. +Setting it to 0 requires ``virtualization=3Don``. + +KVM does not allow userspace to write ``ID_AA64MMFR1_EL1.VH`` directly, so +this is an exception to the rule that only writable fields get a +property: the ``SYSREG_ID_AA64MMFR1_EL1_VH`` property is exposed when the +host kernel supports ``KVM_CAP_ARM_EL2_E2H0``. Without this support the +property does not exist. + A note on compatibility ----------------------- =20 diff --git a/target/arm/cpu-idregs.h b/target/arm/cpu-idregs.h index 465ec83c97..76d7b94858 100644 --- a/target/arm/cpu-idregs.h +++ b/target/arm/cpu-idregs.h @@ -73,4 +73,35 @@ int arm_cpu_apply_sysreg_props(ARMCPU *cpu, ARMSysregPro= pApplyFn accel_apply_fn, bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field, uint64_t value, Error **errp); =20 +/** + * arm_cpu_sysreg_prop_get: + * + * Look up the value the user set through a SYSREG__ + * property, before it is applied to the vcpu. Accelerators use it to + * derive vcpu init settings from the requested ID register values. + * + * @cpu: vcpu the property belongs to + * @reg_idx: ID register index (_EL1_IDX) + * @shift: lowest bit of the field + * @value: set to the requested field value when the property was set + * + * returns true if the property was set by the user + */ +bool arm_cpu_sysreg_prop_get(ARMCPU *cpu, int reg_idx, int shift, + uint64_t *value); + +/** + * arm_cpu_sysreg_field_init_driven: + * + * Some fields cannot be written with the accelerator once the vcpu exists + * but are selected through a vcpu init feature instead (for instance + * ID_AA64MMFR1_EL1.VH with KVM_ARM_VCPU_HAS_EL2_E2H0). Their SYSREG + * property is exposed even if the field is not writable. + * + * @field: ID register field + * + * returns true if @field is selected at vcpu init time on this host + */ +bool arm_cpu_sysreg_field_init_driven(ARM64SysRegField *field); + #endif diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index c08eba7010..1fc3a4bb7c 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -835,6 +835,21 @@ static ARM64SysRegField *arm_sysreg_get_field(ARM64Sys= Reg *reg, int bit) return NULL; } =20 +bool arm_cpu_sysreg_prop_get(ARMCPU *cpu, int reg_idx, int shift, + uint64_t *value) +{ + gpointer value_ptr; + uint64_t key =3D IDREG_FIELD_KEY(reg_idx, shift); + + if (!g_hash_table_lookup_extended(cpu->sysreg_props, + GUINT_TO_POINTER(key), NULL, + &value_ptr)) { + return false; + } + *value =3D GPOINTER_TO_UINT(value_ptr); + return true; +} + /** * arm_cpu_validate_sysreg_prop: * @@ -879,6 +894,13 @@ bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64Sy= sRegField *field, error_setg(errp, "%s is non null whereas pmu is unset", propna= me); return false; } + /* nVHE-only EL2, selected at vcpu init time */ + } else if (!strcmp(propname, "SYSREG_ID_AA64MMFR1_EL1_VH")) { + if (value =3D=3D 0 && !cpu->has_el2) { + error_setg(errp, "%s=3D0 requires -machine virtualization=3Don= ", + propname); + return false; + } /* aarch64=3Doff */ } else if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { if ((!strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL0") || @@ -988,17 +1010,9 @@ static void get_sysreg_prop(Object *obj, Visitor *v, int index =3D field->index; int lower =3D field->shift; int length =3D field->length; - gpointer value_ptr; uint64_t value; - uint64_t key =3D IDREG_FIELD_KEY(index, lower); - gboolean exists; - - exists =3D g_hash_table_lookup_extended(cpu->sysreg_props, - GUINT_TO_POINTER(key), NULL, - &value_ptr); - if (exists) { - value =3D GPOINTER_TO_UINT(value_ptr); - } else { + + if (!arm_cpu_sysreg_prop_get(cpu, index, lower, &value)) { uint64_t mask =3D MAKE_64BIT_MASK(lower, length); uint64_t *idregs =3D cpu->isar.idregs; =20 @@ -1028,6 +1042,20 @@ static const char * const aarch64_sysreg_prop_skip_l= ist[] =3D { "SYSREG_ID_AA64ISAR2_EL1_GPA3", }; =20 +/* + * Fields which KVM does not let userspace write with KVM_SET_ONE_REG, + * but which QEMU can still select through a vcpu init feature, see + * kvm_arm_vcpu_prepare_init_features(). ID_AA64MMFR1_EL1.VH is hidden + * by KVM_ARM_VCPU_HAS_EL2_E2H0, which requests an nVHE-only EL2. + */ +bool arm_cpu_sysreg_field_init_driven(ARM64SysRegField *field) +{ + /* Compare the field first: this runs for every ID register field */ + return field->index =3D=3D ID_AA64MMFR1_EL1_IDX && + field->shift =3D=3D R_ID_AA64MMFR1_VH_SHIFT && + kvm_enabled() && kvm_arm_el2_e2h0_supported(); +} + static bool aarch64_sysreg_prop_skipped(const char *prop_name) { for (int i =3D 0; i < ARRAY_SIZE(aarch64_sysreg_prop_skip_list); i++) { @@ -1084,7 +1112,8 @@ aarch64_add_one_idreg_properties(Object *obj, ARM64Sy= sReg *reg, } map =3D map & ~field_mask; =20 - if (writable_only && !field_writable_mask) { + if (writable_only && !field_writable_mask && + !arm_cpu_sysreg_field_init_driven(field)) { continue; } =20 diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 8ef5597c68..bb4ca7e8d1 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1324,9 +1324,15 @@ bool kvm_idreg_write_scratch_vcpu(ARMCPU *cpu, int c= pufd, return false; } =20 - ret =3D kvm_arm_override_idreg_field(cpufd, field, newfv, errp); - if (ret) { - return false; + /* + * Init-driven fields (e.g. VH) are selected through a vcpu init + * feature, which the scratch vcpu may not have: do not write them. + */ + if (!arm_cpu_sysreg_field_init_driven(field)) { + ret =3D kvm_arm_override_idreg_field(cpufd, field, newfv, errp); + if (ret) { + return false; + } } =20 cpu->isar.idregs[field->index] =3D @@ -2239,7 +2245,19 @@ static void kvm_arm_vcpu_prepare_init_features(ARMCP= U *cpu) 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC); } if (cpu->has_el2 && kvm_arm_el2_supported()) { + uint64_t vh; + cpu->kvm_init_features[0] |=3D 1 << KVM_ARM_VCPU_HAS_EL2; + /* + * KVM exposes a VHE-only EL2 by default. An nVHE-only EL2 can + * only be selected at vcpu init time, so derive it from the + * requested ID_AA64MMFR1_EL1.VH value. + */ + if (arm_cpu_sysreg_prop_get(cpu, ID_AA64MMFR1_EL1_IDX, + R_ID_AA64MMFR1_VH_SHIFT, &vh) && + vh =3D=3D 0) { + cpu->kvm_init_features[0] |=3D 1 << KVM_ARM_VCPU_HAS_EL2_E2H0; + } } } =20 --=20 2.34.1 From nobody Mon Nov 23 04:26:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1795294046; cv=none; d=zohomail.com; s=zohoarc; b=mK+dJhUu32Ulii3QJwOzCX1QSur5Snav3VZO2oOPEylt9WkIUrRE7hL+wUI2rvE6tci69W04TWAW6+1CLRyFphQtlOSQNEWuBbl9c9og2nRoxursh377e6S9O1fXhJsPsGxh/QZuxBnMlM8ltVEgroXRj4g/thnnYypnqOL+yAE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795294046; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AaHxvjxuFM0ZGMpfN7ZubYdgVJfxHgv6fA2HEiSYIX0=; b=eudaunR3adpLALSB8UfbCB6g9DMCe2rtR6c4Zyp9DBh2ved2NNuuN4y3mefvvF6j1hR32BrC1FVaM8m4TXztS11DnhdANcDdCVYZAdZzPAR/aIZ5EwbnD8jdqnJTR8C1vTBIVQEevt6xivOVzTWfzcofDW0kL7XzYQ9LnGrrR20= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795294046696703.53118509334; Sat, 21 Nov 2026 12:47:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xUryZ-0004UP-Fe; Sat, 21 Nov 2026 15:46:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xUryX-0004TR-LI for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:21 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xUryV-000647-Uu for qemu-devel@nongnu.org; Sat, 21 Nov 2026 15:46:21 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4b467581b98so18774065e9.0 for ; Sat, 21 Nov 2026 12:46:19 -0800 (PST) Received: from PKL-HASEEBA-LT.. ([39.36.59.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b39b6sm180652385e9.12.2026.11.21.12.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2026 12:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795293978; x=1795898778; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AaHxvjxuFM0ZGMpfN7ZubYdgVJfxHgv6fA2HEiSYIX0=; b=iXWFe4tW3Q8x0UpVHDTxmp72AqFepQPVLBgozGCB6U3G4wqffMM1kyK/8wXhdZwWe9 U0U7aWGeltl2kgshqVtODII7/uzokkMgfs6lEwv3PXZIO8FD4qJOcRSappDNHwLS76j8 M6/LKLVWeiPRMqt9UHkRzRBF1J4NoHPAkQ0YSH4q3BQXKuot5G9elOqy2VrtpJusc88I CiklkbkWQC/V2KYiy5KphlgUFH2r3AwmLqZyTXb4fNIM6/XsavowmVMrSzURlCdwAoVY R4q5s2gnYGnVaaq/3MQA8wMKUu4cHgsbb/txxmXojRYIPP+snOSLRqppxOy7s5TVYIFP xzcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795293978; x=1795898778; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AaHxvjxuFM0ZGMpfN7ZubYdgVJfxHgv6fA2HEiSYIX0=; b=PvVuk5ENsguN10WZSwyVijYCYF7qKHmizmajB3S4n6eOgbMrd01W2HEk0M2x/hB7o5 0HqSTXn+qZnvJ95Mldv1kd7QvIyTuXPeOWN39QSX6UINEWMF67kG2YI5aGs9embpSeS8 4vQrKS+brpFXnQkHwLsWD2O0fojmyYs3uxPxM0IAycVSz+Wzg1Rn5XfLOyay7UCaid6r u7MKyOs+9NCp5K5X9rviMV/mWEKzrg+VKbscLz4niiRC3OS7vgeiosZ2yj4rHaJWjng9 YJTc3RcqgVUxOI7W5WGn/ZSy4EWoY92JxDkZC73EWmSr9+BM13UmS51tPlPSctLf7fZQ OKdQ== X-Forwarded-Encrypted: i=1; AL+hErH92Pc3OwYztIXbWELB59Wy35YbCSn/1KfyljsL11ZqTdajmExmdimxw8xms4ntrzuo/kFw9m/hSAa1@nongnu.org X-Gm-Message-State: APuU4Z9RXdfC0Y8dWyZ9+Hsw0dK8lcTdf244yRi+VgzLPewB/KU46IZ2 vZKcjG0efaovbxfvt3faWzTBORsoKLvd1HqChzHwSPmFqFQ7/vSz8Fes X-Gm-Gg: AZFdTZf5Wp8XatkRR25VOklCivHkBbRw9ZX76uWoB8bBy9N7sYU642753nsIiSXgOmo QgJI/luXE7g3NHNDL8cX+B5NKUx8LFKs2Xn+7PHysOZRop75vvuPoh4wZv1OvTaehhY0ruOmp/T rRrQL52T1HC2qEDigIa2ipqFRu7f0L7mxco716QjNUVltKj5KtQltH14OyQnthEARmxpNxeNMBi 3I16/su9NYFbeiI/Yi7zZsH2nb6rm9PEk4gYLueUxvNYNMi6mGkAvgn/HfDAWoE39GytDLSaj/+ yIuzZx9R6UqDK8cqPegk7JY/UGqu6GrQxo7625gftz2uNVqQNEhMMf2C4pJjHs3Mg5R2GqSvrDv xsp3nhIvUWz2wJIqW7fs64N5TzlkCucoK/81LGTCSOiZK0VR0FrLLT3ogcNWANgkSdFZq5nTxsr 9UExk8AmilyY5gQWk9EY/CYR9etcACkfcE8DyGLkZc47DeWStvi60BNb18QhhO3AFc08nEbsCHj Pz1K7mo6PxF5sxDAg8qXt9xT2wEnyyKuS3ycwlnv/mFvhYWh1P1BKTLv6KA1/RYjnC0O0V4Iz36 Peg2SmtK2XEY9FzhSLysy0qHMamyfojiz2AeflpzAmIMyUOroZUNZQjjS5h+6FwoAAv0BbcvV68 ipEALN4EeZ9c7qK2TKh7rjYw= X-Received: by 2002:a05:600c:848d:b0:4bb:52d8:73ef with SMTP id 5b1f17b1804b1-4bb88940f1bmr154944795e9.34.1795293978122; Sat, 21 Nov 2026 12:46:18 -0800 (PST) From: Haseeb Ashraf To: Peter Maydell , qemu-arm@nongnu.org Cc: Haseeb Ashraf , Eric Auger , Marc Zyngier , Mohamed Mediouni , Pierrick Bouvier , Paolo Bonzini , Volodymyr Babchuk , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [RFC PATCH v2 3/3] tests/functional: Add a KVM selftest for an nVHE-only EL2 Date: Sun, 22 Nov 2026 01:46:01 +0500 Message-ID: <20261121204601.741616-4-haseebashraf091@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261121204601.741616-1-haseebashraf091@gmail.com> References: <20261121095636.289814-1-haseebashraf091@gmail.com> <20261121204601.741616-1-haseebashraf091@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=haseebashraf091@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1795294049587154100 Content-Type: text/plain; charset="utf-8" From: Haseeb Ashraf Run the existing kvm-unit-tests smoke test with VHE hidden from the guest hypervisor through SYSREG_ID_AA64MMFR1_EL1_VH=3D0. The SYSREG_* properties are available only for the host CPU model with KVM, so select the accelerator and CPU model explicitly, and check that the guest kernel initialized its hypervisor in nVHE mode. The test is skipped when the host kernel cannot limit EL2 to nVHE. Signed-off-by: Haseeb Ashraf --- v2: - Select KVM and the host CPU model explicitly. - Verify the guest kernel reports nVHE mode. tests/functional/aarch64/test_kvm.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch6= 4/test_kvm.py index c977e8c6d2..b7a4aceb66 100755 --- a/tests/functional/aarch64/test_kvm.py +++ b/tests/functional/aarch64/test_kvm.py @@ -30,7 +30,7 @@ class Aarch64VirtKVMTests(LinuxKernelTest): # base of tests KUT_BASE =3D "/usr/share/kvm-unit-tests/" =20 - def _launch_guest(self, kvm_mode=3D"nvhe"): + def _launch_guest(self, kvm_mode=3D"nvhe", cpu=3D"max", accel=3DNone): =20 self.set_machine('virt') kernel_path =3D self.ASSET_KVM_TEST_KERNEL.fetch() @@ -39,7 +39,9 @@ def _launch_guest(self, kvm_mode=3D"nvhe"): kernel_command_line =3D (self.KERNEL_COMMON_COMMAND_LINE + f"console=3DttyAMA0 kvm-arm.mode=3D{kvm_mod= e}") =20 - self.vm.add_args("-cpu", "max") + if accel: + self.vm.add_args("-accel", accel) + self.vm.add_args("-cpu", cpu) self.vm.add_args("-machine", "virt,gic-version=3D3,virtualization= =3Don", '-kernel', kernel_path, '-append', kernel_command_line) @@ -50,6 +52,9 @@ def _launch_guest(self, kvm_mode=3D"nvhe"): except VMLaunchFailure as excp: if "does not support providing Virtualization" in excp.output: self.skipTest("accelerator has no virtualization support") + elif ("SYSREG_ID_AA64MMFR1_EL1_VH" in excp.output and + "not found" in excp.output): + self.skipTest("host KVM cannot limit EL2 to nVHE") else: self.log.info("unhandled launch failure: %s", excp.output) raise excp @@ -73,5 +78,18 @@ def test_aarch64_vhe_selftest(self): self._launch_guest("vhe") self._smoketest_kvm() =20 + def test_aarch64_nvhe_only_selftest(self): + # Hiding VHE from the guest hypervisor is a KVM feature: the + # SYSREG_* properties only exist for the host CPU model with KVM. + self.require_accelerator("kvm") + self._launch_guest("nvhe", "host,SYSREG_ID_AA64MMFR1_EL1_VH=3D0", + accel=3D"kvm") + # The guest kernel must run its hypervisor in nVHE mode + ec_and_wait(self, "dmesg | grep -Eq " + "'Hyp (nVHE )?mode initialized successfully' && " + "! dmesg | grep -q ' VHE mode initialized'", + self.OK_CMD) + self._smoketest_kvm() + if __name__ =3D=3D '__main__': LinuxKernelTest.main() --=20 2.34.1