From mboxrd@z Thu Jan 1 00:00:00 1970 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 C8EA2C5AD49 for ; Thu, 29 May 2025 12:47:21 +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:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y377nm41gjZ6X8wTeBzPC5Jnb0NA1qZ7QeTgNqoh0+8=; b=kfRX+mvX8UwHb7D8pOOdcsv28m YweKKr6ou+oExxDjNjoKkkLRUtOaxN9V/FfbTlcXg1Vu81FUVmwbsHVZM49k8Bog0wKIUyUSwL5kO rG6S+yhXvjyRW/nt5rU3AJ+bFOYrWx8NI6bIjl4srQ8RQWKpeOwqC1OS6l9GywxEQm7+r20wJ2ypS k8JCbGsxz+AZojiRLlRS2wdC+7y4RBiQwf2rZBOg4hoyI1xrFnvwAaLCWiD0UKjcQ8BMpEDpsROwk 3UayY3UI7ZpZ6kcbRzodK83Wr4KtYXHBdEoEgQJjcDZat4aq7UNGnNcCgHp34+ENaKs+dSNPE7T6t erdrndyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uKcfD-0000000Flzr-2OIy; Thu, 29 May 2025 12:47:15 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uKbmp-0000000FgC7-3ZX3 for linux-arm-kernel@lists.infradead.org; Thu, 29 May 2025 11:51:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2EA5B5C12F1; Thu, 29 May 2025 11:48:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAAE7C4CEED; Thu, 29 May 2025 11:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748519462; bh=d4MsMe4pb18cEZ2F/ko49Z5Bbu2Yfh5WWdKzReuzb88=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JYh+GNkp7sNYp8+SPQ+ZD2Kjjm3AHGxBypUc+oPOT+GBw5Sjsy/K5IadsbrjAHAk7 GDUC86ShhVHXYU1yFmUjdnPg9kCTqcZ4T/eelBy68/DUtehdcEy/R8OSAXojZqN4W2 We1STqEbzcDrbfC0438q3ZZDbrD+o6xDH2GDM4zUe5JUykXxEynoeDSYhomy+i6oqQ fucuMUb4TjhKIJAeJmddWh/P6dqoo7TvodkDRvAUvQ8MsaPoUfTGvx/H8RaWbPQQoC +sChcy3KwaP+wUqRSHlKec/0iZqzj8xzDJwgeKu1KuNhFvTIJzqclPl0f6mErzzFgb AOOVQZu+uul4w== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uKbmm-001YOC-Jq; Thu, 29 May 2025 12:51:00 +0100 Date: Thu, 29 May 2025 12:50:59 +0100 Message-ID: <868qmfeiu4.wl-maz@kernel.org> From: Marc Zyngier To: Ganapatrao Kulkarni Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, seanjc@google.com, darren@os.amperecomputing.com Subject: Re: [RFC PATCH v2 1/9] KVM: arm64: nv: selftests: Add support to run guest code in vEL2. In-Reply-To: <20250512105251.577874-2-gankulkarni@os.amperecomputing.com> References: <20250512105251.577874-1-gankulkarni@os.amperecomputing.com> <20250512105251.577874-2-gankulkarni@os.amperecomputing.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: gankulkarni@os.amperecomputing.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, seanjc@google.com, darren@os.amperecomputing.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250529_045103_986232_E12390A9 X-CRM114-Status: GOOD ( 22.49 ) 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 On Mon, 12 May 2025 11:52:43 +0100, Ganapatrao Kulkarni wrote: > > This patch adds required changes to vcpu init to run a guest code > in vEL2 context and also adds NV specific helper functions. > > Signed-off-by: Ganapatrao Kulkarni > --- > tools/testing/selftests/kvm/Makefile.kvm | 2 + > .../kvm/include/arm64/kvm_util_arch.h | 3 + > .../selftests/kvm/include/arm64/nv_util.h | 45 ++++++++++++++ > .../selftests/kvm/include/arm64/vgic.h | 1 + > .../testing/selftests/kvm/include/kvm_util.h | 3 + > tools/testing/selftests/kvm/lib/arm64/nv.c | 46 ++++++++++++++ > .../selftests/kvm/lib/arm64/processor.c | 61 ++++++++++++++----- > tools/testing/selftests/kvm/lib/arm64/vgic.c | 8 +++ > 8 files changed, 155 insertions(+), 14 deletions(-) > create mode 100644 tools/testing/selftests/kvm/include/arm64/nv_util.h > create mode 100644 tools/testing/selftests/kvm/lib/arm64/nv.c > > diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm > index f773f8f99249..3348f729d3b2 100644 > --- a/tools/testing/selftests/kvm/Makefile.kvm > +++ b/tools/testing/selftests/kvm/Makefile.kvm > @@ -37,6 +37,7 @@ LIBKVM_arm64 += lib/arm64/processor.c > LIBKVM_arm64 += lib/arm64/spinlock.c > LIBKVM_arm64 += lib/arm64/ucall.c > LIBKVM_arm64 += lib/arm64/vgic.c > +LIBKVM_arm64 += lib/arm64/nv.c > > LIBKVM_s390 += lib/s390/diag318_test_handler.c > LIBKVM_s390 += lib/s390/processor.c > @@ -155,6 +156,7 @@ TEST_GEN_PROGS_arm64 += arm64/vgic_irq > TEST_GEN_PROGS_arm64 += arm64/vgic_lpi_stress > TEST_GEN_PROGS_arm64 += arm64/vpmu_counter_access > TEST_GEN_PROGS_arm64 += arm64/no-vgic-v3 > +TEST_GEN_PROGS_arm64 += arm64/nv_guest_hypervisor > TEST_GEN_PROGS_arm64 += access_tracking_perf_test > TEST_GEN_PROGS_arm64 += arch_timer > TEST_GEN_PROGS_arm64 += coalesced_io_test > diff --git a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h > index e43a57d99b56..ab5279c24413 100644 > --- a/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h > +++ b/tools/testing/selftests/kvm/include/arm64/kvm_util_arch.h > @@ -2,6 +2,9 @@ > #ifndef SELFTEST_KVM_UTIL_ARCH_H > #define SELFTEST_KVM_UTIL_ARCH_H > > +#define CurrentEL_EL1 (1 << 2) > +#define CurrentEL_EL2 (2 << 2) > + > struct kvm_vm_arch {}; > > #endif // SELFTEST_KVM_UTIL_ARCH_H > diff --git a/tools/testing/selftests/kvm/include/arm64/nv_util.h b/tools/testing/selftests/kvm/include/arm64/nv_util.h > new file mode 100644 > index 000000000000..622a17c9d142 > --- /dev/null > +++ b/tools/testing/selftests/kvm/include/arm64/nv_util.h > @@ -0,0 +1,45 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2025 Ampere Computing > + */ > +#ifndef SELFTEST_NV_UTIL_H > +#define SELFTEST_NV_UTIL_H > + > +#include > +#include > + > +#define HCR_NV2 (UL(1) << 45) > +#define HCR_AT (UL(1) << 44) > +#define HCR_NV (UL(1) << 42) > +#define HCR_E2H (UL(1) << 34) > +#define HCR_TTLB (UL(1) << 25) > + > +/* Enable NV2 and guest in VHE mode */ > +#define HCR_EL2_NV_EANBLE (HCR_E2H | HCR_NV | HCR_NV2 | HCR_AT | HCR_TTLB) > + What is the point of enabling NV and trapping all sort of things, given that you're not even enabling a guest? How do you expect to deal with EL0 without TGE being set? M. -- Without deviation from the norm, progress is not possible.