Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1836012pxb; Thu, 7 Oct 2021 16:36:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBdSdc8yZ5Br7eqOAS2Rct+nLZnSueQCkrWeHpyZxRqaCSaUXKE35TJ6os4i4mTIztChBm X-Received: by 2002:a05:6a00:809:b0:44c:c170:b455 with SMTP id m9-20020a056a00080900b0044cc170b455mr5495059pfk.69.1633649781050; Thu, 07 Oct 2021 16:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633649781; cv=none; d=google.com; s=arc-20160816; b=Fux7LLoGG4j7vt+oEuGHIXJtYQxXocBbgqlJ/FuWpf2Pz2Qk194nQSMWqgwa0a+jXY 9kLUUFZaRWB3L1GGF12hkjW19Sp5hFuwR3PxOsImPO5g5rXJv8gZTz7AONERYBmhucZt e5RO194Bp0zgQ00dPWh0eF78p2R62jWIYH0n7Ou5i4H9uKLfvxBjo7fVzv7p3P6fHLGd LfFxRx91oXn+Qi5EnJca2Bpc27MyA5vLarbuPZLZ3GIifMRxwVX5fSvXWKUJNEOoszoT gIlMmDirYrkUJBsY5taYH1lHpkupzfIgHH7P4OoQ13mBJaiqtSjugmKica+qd6Dg1pEC RiEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=F/zs/L5o3RVm3Py5wUOA95eG+q7sFQsiBYx3cR6Byyc=; b=f0XBjejpk285OY7lSQeCNP03N8cweImXzd3qy/2MsG4CYVu3vtp1lbtLd+9zoqgZEb Z3ZmlRBBCECRSxlblvlZ1Xt14cLnZ4YOzURKG2f0srMsxluozNp2Ceyk2N04ypv1t3mN 3fx2RqmeuBMJjWYqNLxj90v+NRIyQOPzsqSXgsPRcyapSk9Cc8c0USsC3jvM70SvTTMB TfJPoJRl7dwKRbyudFAzPVOcf2qvXNehtcbSrJtEuCtnLeZku8836z1BCU4emFik+X1m VeQhFLdsSjbkUHtod/R9WRbCgArm6mWEZJ9iZ+8RpcAv6lndpPjMHNljJ+jYhOizUFXq RRiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GRWGNWrX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h193si960176pgc.395.2021.10.07.16.36.08; Thu, 07 Oct 2021 16:36:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GRWGNWrX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241899AbhJGXhB (ORCPT + 99 others); Thu, 7 Oct 2021 19:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241245AbhJGXgv (ORCPT ); Thu, 7 Oct 2021 19:36:51 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBED9C061755 for ; Thu, 7 Oct 2021 16:34:56 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id p2-20020a170902bd0200b0013da15f4ab0so3955035pls.7 for ; Thu, 07 Oct 2021 16:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=F/zs/L5o3RVm3Py5wUOA95eG+q7sFQsiBYx3cR6Byyc=; b=GRWGNWrXatSszSYAm5id6fn5vLAzMUADRwMuFO1wfmfuRDodoik8vqN+6qZkkoc8SF IFlvC1lPStzeFZ+RtFERpOQKSBCzL9ziFiLn8UrwxQMrnMK7mdJT8vgkPz6mEOYroCsn 3yCPUBzDCXUBgsCFNO4cR8bHQfVC56stUrv2K9L4mGhVoigrihvoFI0fdYeYRHDzveid 1IWxH0Ur1RmSeXSJ5Fxaf2p8Cp6rmT6S4TqLQYMY1DWz0ZE+PfJvX2rIs74cQD+BoGxk ll0unDBBM29h0O+zYaS84HBfJqk3FzfsHvn1ehS7QDpfqzTvjsf7AFR7lUOPxYZmNHpg TzLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=F/zs/L5o3RVm3Py5wUOA95eG+q7sFQsiBYx3cR6Byyc=; b=Xmh0aMcuGRYm4EBNOGAULNLYpdKRKYjKEkYZCLqqvX3WAl7XFdCbis1SQlDX8gzv4M D06zolxsU7FqDKGs4sRsX5WSm5x8P7iFZTuDiE7RtyjyOmc5bDcOhTS8kv+Z53U640rJ O03QHLDkHKy5kBX1Cv21u13vwqk7aOoTRrjQIEJL8ycZ/axSw6obrqxDXTv9pwrc4vMs hFIn9AnIlvSfusnnb/ADJq1KovvwEmTdSH1+/X0l6n2WQsvtCWvmxiJWxXPj0Q23SrRG TjeyHoFPl/ktZSl/EGHu9O5kc6N1yE+LY2JvHfPxDWA9xbh8Wg1q31zOqBt6N5xYk0U6 BIRA== X-Gm-Message-State: AOAM531kNLU0iMYhm19GoGh3gj23hsVfdX1w6kXhKLt4EfHVGrVdCkEG aoV4qtqgowmHMz4uj6VOlT0SioLsa72b X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:d88d:b0:13e:807b:d52b with SMTP id b13-20020a170902d88d00b0013e807bd52bmr6448083plz.69.1633649696487; Thu, 07 Oct 2021 16:34:56 -0700 (PDT) Date: Thu, 7 Oct 2021 23:34:28 +0000 In-Reply-To: <20211007233439.1826892-1-rananta@google.com> Message-Id: <20211007233439.1826892-5-rananta@google.com> Mime-Version: 1.0 References: <20211007233439.1826892-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v8 04/15] KVM: arm64: selftests: Introduce ARM64_SYS_KVM_REG From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the inclusion of sysreg.h, that brings in system register encodings, it would be redundant to re-define register encodings again in processor.h to use it with ARM64_SYS_REG for the KVM functions such as set_reg() or get_reg(). Hence, add helper macro, ARM64_SYS_KVM_REG, that converts SYS_* definitions in sysreg.h into ARM64_SYS_REG definitions. Also replace all the users of ARM64_SYS_REG, relying on the encodings created in processor.h, with ARM64_SYS_KVM_REG and remove the definitions. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Ricardo Koller Reviewed-by: Andrew Jones --- .../selftests/kvm/aarch64/debug-exceptions.c | 2 +- .../selftests/kvm/aarch64/psci_cpu_on_test.c | 2 +- .../selftests/kvm/include/aarch64/processor.h | 20 ++++++++++--------- .../selftests/kvm/lib/aarch64/processor.c | 16 +++++++-------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 11fd23e21cb4..ea189d83abf7 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -190,7 +190,7 @@ static int debug_version(struct kvm_vm *vm) { uint64_t id_aa64dfr0; - get_reg(vm, VCPU_ID, ARM64_SYS_REG(ID_AA64DFR0_EL1), &id_aa64dfr0); + get_reg(vm, VCPU_ID, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &id_aa64dfr0); return id_aa64dfr0 & 0xf; } diff --git a/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c b/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c index 018c269990e1..4c5f6814030f 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c @@ -91,7 +91,7 @@ int main(void) init.features[0] |= (1 << KVM_ARM_VCPU_POWER_OFF); aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main); - get_reg(vm, VCPU_ID_TARGET, ARM64_SYS_REG(MPIDR_EL1), &target_mpidr); + get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr); vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK); vcpu_run(vm, VCPU_ID_SOURCE); diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index 7989e832cafb..93797783abad 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -16,15 +16,17 @@ #define ARM64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x)) -#define CPACR_EL1 3, 0, 1, 0, 2 -#define TCR_EL1 3, 0, 2, 0, 2 -#define MAIR_EL1 3, 0, 10, 2, 0 -#define MPIDR_EL1 3, 0, 0, 0, 5 -#define TTBR0_EL1 3, 0, 2, 0, 0 -#define SCTLR_EL1 3, 0, 1, 0, 0 -#define VBAR_EL1 3, 0, 12, 0, 0 - -#define ID_AA64DFR0_EL1 3, 0, 0, 5, 0 +/* + * KVM_ARM64_SYS_REG(sys_reg_id): Helper macro to convert + * SYS_* register definitions in asm/sysreg.h to use in KVM + * calls such as get_reg() and set_reg(). + */ +#define KVM_ARM64_SYS_REG(sys_reg_id) \ + ARM64_SYS_REG(sys_reg_Op0(sys_reg_id), \ + sys_reg_Op1(sys_reg_id), \ + sys_reg_CRn(sys_reg_id), \ + sys_reg_CRm(sys_reg_id), \ + sys_reg_Op2(sys_reg_id)) /* * Default MAIR diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 632b74d6b3ca..db64ee206064 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -232,10 +232,10 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini * Enable FP/ASIMD to avoid trapping when accessing Q0-Q15 * registers, which the variable argument list macros do. */ - set_reg(vm, vcpuid, ARM64_SYS_REG(CPACR_EL1), 3 << 20); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_CPACR_EL1), 3 << 20); - get_reg(vm, vcpuid, ARM64_SYS_REG(SCTLR_EL1), &sctlr_el1); - get_reg(vm, vcpuid, ARM64_SYS_REG(TCR_EL1), &tcr_el1); + get_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1), &sctlr_el1); + get_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TCR_EL1), &tcr_el1); switch (vm->mode) { case VM_MODE_P52V48_4K: @@ -273,10 +273,10 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini tcr_el1 |= (1 << 8) | (1 << 10) | (3 << 12); tcr_el1 |= (64 - vm->va_bits) /* T0SZ */; - set_reg(vm, vcpuid, ARM64_SYS_REG(SCTLR_EL1), sctlr_el1); - set_reg(vm, vcpuid, ARM64_SYS_REG(TCR_EL1), tcr_el1); - set_reg(vm, vcpuid, ARM64_SYS_REG(MAIR_EL1), DEFAULT_MAIR_EL1); - set_reg(vm, vcpuid, ARM64_SYS_REG(TTBR0_EL1), vm->pgd); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1), sctlr_el1); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TCR_EL1), tcr_el1); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_MAIR_EL1), DEFAULT_MAIR_EL1); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TTBR0_EL1), vm->pgd); } void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) @@ -362,7 +362,7 @@ void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid) { extern char vectors; - set_reg(vm, vcpuid, ARM64_SYS_REG(VBAR_EL1), (uint64_t)&vectors); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_VBAR_EL1), (uint64_t)&vectors); } void route_exception(struct ex_regs *regs, int vector) -- 2.33.0.882.g93a45727a2-goog