From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56F0918DB03; Thu, 29 May 2025 11:51:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748519463; cv=none; b=rndVBOdpwJWSqUgdwy/mqRm4e7AubkaynIDE3Xdt+UuMI2jZwTc5rMkvEs9h1Lms9nzkVzEWuUeWkKAvA/18Q3Jqew/T+H/ME5+31OxHwlR7ympzZq/s+FJP6yqtKBtVQ+iYpqpx2dy/gPOz35W99YuIl2jEz4UQcR2Qlo8QHzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748519463; c=relaxed/simple; bh=d4MsMe4pb18cEZ2F/ko49Z5Bbu2Yfh5WWdKzReuzb88=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=B1a4Rew2Afwth+TN1NMH6X0M2CN1qPK1ZXu8ygI72ZMV5TUEYSyb9ZouyqXzP1LrbX27C/FqD25/vjq8ZiyzCsVYz6k/vSH0j2Ok1cEvJ/Jb97BlBq+nPl6DfqG0IvjxFVm6qYEp9EDzZpmlnTYAmlaV8uQHYBKYVoFG5D9LLEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JYh+GNkp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JYh+GNkp" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.