From patchwork Tue Sep 19 17:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13391747 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 96F92CE79A8 for ; Tue, 19 Sep 2023 17:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=30bb0Wsu8vIcOpWEeok7p9VGNLD3mhaze16PeU/GlxI=; b=YwjO8cOSqK4W9yJ98wwmue4nUW llUhYS3Pgpsvh1mEznsDUPRiY9ZeVjcL0CTxrA7rkZM5613mJ6zzHP4Q7IVd3RIPySdfKyYN2zVQQ KFVZ4aQySQMR/Ckxr+xp3fZwgmysi5KO6XrYAGcbtBiJneOY2LDUmbPfDTIdNPlaTblrwIdIVh0Nx UArz1+gvG7WORSIAXmWott3jebDcpITEFoom8INb/C+wc6so5IHMJlT/77h8iX4BfbkKsADVwQ5ec lLiqr+OBYP3FLh8c1hNbW5YNFUS8mW+sy7hZnNE5wT6trj170lZLeYnlADEk/w4mG7DtMdIgzH3oy TaYHNgpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiesg-000ztf-14; Tue, 19 Sep 2023 17:51:26 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qierk-000zGF-01 for linux-arm-kernel@lists.infradead.org; Tue, 19 Sep 2023 17:50:31 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-68fe3d77ed8so6410154b3a.2 for ; Tue, 19 Sep 2023 10:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695145825; x=1695750625; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Nc9IhLzKfLsRQeYUmIOlUXC0AFKZ1OL0TidKJ4UxU6g=; b=RKhxDBYf0JyOilhL7pDU6jIjgkD6l27+XfPlxYMx/BvcLKYdwUmFwme0Rha8nfXlRl 6xtjc6L46KqjoPsgw+HP18z3T2KscOaQ0MCA7tmyHaZjsDDHKWQVUmFTXBfrkuM76vCQ 85xLHk49jkNODEkDJlcBLsw/piW7s85J8JXoh5lumpG5rnfAzv19t7IRThl3L0djj7qA gPzR2oU4yZS4o7n+dRel8MbZ6AbexXIegw6jfRj5hfDY6h3PkahBfYuAtLU7SDd+hH9h wVrGn1Dny8vbY823k2+T6MuBT7XtUgqEMHEoJhJPNFrD3dj+OAXqMKZXxMy/hI1XPWZV gz6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695145825; x=1695750625; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Nc9IhLzKfLsRQeYUmIOlUXC0AFKZ1OL0TidKJ4UxU6g=; b=HYxdYlSqtExpxVJ8dTNNW5dHdbeZ+xTEvLvOYi54ZVm3D4STgmO4E9MCoN5lMukFOi BguRg0uvEgJnw3ju3qL+FfZkGaYI4zEmB6jMHDoqfUapcMQ7nNeMoaK8vDWsasWB1wsB XtTag8vCSeYtpOLzt5ERfED5+uwKZOyNmiv0qrR8IUuOcJoihkCgpLd7mJVdl2du29qJ Al5+zQ2bRYrhglSXkpjcOWBNYK9jCOi9LN4tEZEjJ7I2XvwIx5XG4DTW4hPQI8ZHzqNL QP6PRl6WfWlndPbDn0oZgE874Ahd55Ag1Hw9HFPgaWDA2HBj/6Qg6pCQfTCdVFAKJR4a eFvQ== X-Gm-Message-State: AOJu0YyO8UP+7UQ+UKuG9C+qtzxMz2tt4v+y97I8Ztd2LQzsvUGoh7Ew J0SaylMcAXbL7x/sVsYkGm6OJT14hnbTojNmQQ== X-Google-Smtp-Source: AGHT+IEzgFYHWoI5Y3ME7mliKGcMaRUOApa6TvADiOKyCMaHRzNyZfIVjUxH+iPvlizVJNpMNCc2HZAFY/N/OxlUeQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6a00:2289:b0:68f:fa41:4e94 with SMTP id f9-20020a056a00228900b0068ffa414e94mr9025pfe.0.1695145825464; Tue, 19 Sep 2023 10:50:25 -0700 (PDT) Date: Tue, 19 Sep 2023 10:50:13 -0700 In-Reply-To: <20230919175017.538312-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230919175017.538312-1-jingzhangos@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919175017.538312-2-jingzhangos@google.com> Subject: [PATCH v1 1/4] KVM: arm64: Allow userspace to get the writable masks for feature ID registers From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Suraj Jitindar Singh , Cornelia Huck , Shaoqin Huang , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230919_105028_361836_B81485B0 X-CRM114-Status: GOOD ( 27.21 ) 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 While the Feature ID range is well defined and pretty large, it isn't inconceivable that the architecture will eventually grow some other ranges that will need to similarly be described to userspace. Add a VM ioctl to allow userspace to get writable masks for feature ID registers in below system register space: op0 = 3, op1 = {0, 1, 3}, CRn = 0, CRm = {0 - 7}, op2 = {0 - 7} This is used to support mix-and-match userspace and kernels for writable ID registers, where userspace may want to know upfront whether it can actually tweak the contents of an idreg or not. Add a new capability (KVM_CAP_ARM_SUPPORTED_FEATURE_ID_RANGES) that returns a bitmap of the valid ranges, which can subsequently be retrieved, one at a time by setting the index of the set bit as the range identifier. Suggested-by: Marc Zyngier Suggested-by: Cornelia Huck Signed-off-by: Jing Zhang --- arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/include/uapi/asm/kvm.h | 32 +++++++++++++++ arch/arm64/kvm/arm.c | 10 +++++ arch/arm64/kvm/sys_regs.c | 66 +++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 + 5 files changed, 112 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index af06ccb7ee34..5e3f778f81db 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1078,6 +1078,8 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, struct kvm_arm_copy_mte_tags *copy_tags); int kvm_vm_ioctl_set_counter_offset(struct kvm *kvm, struct kvm_arm_counter_offset *offset); +int kvm_vm_ioctl_get_reg_writable_masks(struct kvm *kvm, + struct reg_mask_range *range); /* Guest/host FPSIMD coordination helpers */ int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index f7ddd73a8c0f..01242274db87 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -505,6 +505,38 @@ struct kvm_smccc_filter { #define KVM_HYPERCALL_EXIT_SMC (1U << 0) #define KVM_HYPERCALL_EXIT_16BIT (1U << 1) +/* + * Get feature ID registers userspace writable mask. + * + * From DDI0487J.a, D19.2.66 ("ID_AA64MMFR2_EL1, AArch64 Memory Model + * Feature Register 2"): + * + * "The Feature ID space is defined as the System register space in + * AArch64 with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, + * op2=={0-7}." + * + * This covers all currently known R/O registers that indicate + * anything useful feature wise, including the ID registers. + * + * If we ever need to introduce a new range, it will be described as + * such in the range field. + */ +#define ARM64_FEATURE_ID_SPACE_IDX(op0, op1, crn, crm, op2) \ + ({ \ + __u64 __op1 = (op1) & 3; \ + __op1 -= (__op1 == 3); \ + (__op1 << 6 | ((crm) & 7) << 3 | (op2)); \ + }) + +#define ARM64_FEATURE_ID_SPACE_SIZE (3 * 8 * 8) +#define ARM64_FEATURE_ID_RANGE_IDREGS BIT(0) + +struct reg_mask_range { + __u64 addr; /* Pointer to mask array */ + __u32 range; /* Requested range */ + __u32 reserved[13]; +}; + #endif #endif /* __ARM_KVM_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4866b3f7b4ea..1c4017a253fd 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -317,6 +317,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES: r = kvm_supported_block_sizes(); break; + case KVM_CAP_ARM_SUPPORTED_FEATURE_ID_RANGES: + r = ARM64_FEATURE_ID_RANGE_IDREGS; + break; default: r = 0; } @@ -1629,6 +1632,13 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) return kvm_vm_set_attr(kvm, &attr); } + case KVM_ARM_GET_REG_WRITABLE_MASKS: { + struct reg_mask_range range; + + if (copy_from_user(&range, argp, sizeof(range))) + return -EFAULT; + return kvm_vm_ioctl_get_reg_writable_masks(kvm, &range); + } default: return -EINVAL; } diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index e92ec810d449..cdb9976d8091 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1373,6 +1373,13 @@ static inline bool is_id_reg(u32 id) sys_reg_CRm(id) < 8); } +static inline bool is_aa32_id_reg(u32 id) +{ + return (sys_reg_Op0(id) == 3 && sys_reg_Op1(id) == 0 && + sys_reg_CRn(id) == 0 && sys_reg_CRm(id) >= 1 && + sys_reg_CRm(id) <= 3); +} + static unsigned int id_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { @@ -3572,6 +3579,65 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +#define ARM64_FEATURE_ID_SPACE_INDEX(r) \ + ARM64_FEATURE_ID_SPACE_IDX(sys_reg_Op0(r), \ + sys_reg_Op1(r), \ + sys_reg_CRn(r), \ + sys_reg_CRm(r), \ + sys_reg_Op2(r)) + +static bool is_feature_id_reg(u32 encoding) +{ + return (sys_reg_Op0(encoding) == 3 && + (sys_reg_Op1(encoding) < 2 || sys_reg_Op1(encoding) == 3) && + sys_reg_CRn(encoding) == 0 && + sys_reg_CRm(encoding) <= 7); +} + +int kvm_vm_ioctl_get_reg_writable_masks(struct kvm *kvm, struct reg_mask_range *range) +{ + const void *zero_page = page_to_virt(ZERO_PAGE(0)); + u64 __user *masks = (u64 __user *)range->addr; + + /* Only feature id range is supported, reserved[13] must be zero. */ + if (range->range != ARM64_FEATURE_ID_RANGE_IDREGS || + memcmp(range->reserved, zero_page, sizeof(range->reserved))) + return -EINVAL; + + /* Wipe the whole thing first */ + if (clear_user(masks, ARM64_FEATURE_ID_SPACE_SIZE * sizeof(__u64))) + return -EFAULT; + + for (int i = 0; i < ARRAY_SIZE(sys_reg_descs); i++) { + const struct sys_reg_desc *reg = &sys_reg_descs[i]; + u32 encoding = reg_to_encoding(reg); + u64 val; + + if (!is_feature_id_reg(encoding) || !reg->set_user) + continue; + + /* + * For ID registers, we return the writable mask. Other feature + * registers return a full 64bit mask. That's not necessary + * compliant with a given revision of the architecture, but the + * RES0/RES1 definitions allow us to do that. + */ + if (is_id_reg(encoding)) { + if (!reg->val || + (is_aa32_id_reg(encoding) && !kvm_supports_32bit_el0())) + continue; + val = reg->val; + } else { + val = ~0UL; + } + + if (put_user(val, (masks + ARM64_FEATURE_ID_SPACE_INDEX(encoding)))) + return -EFAULT; + } + + return 0; +} + int __init kvm_sys_reg_table_init(void) { struct sys_reg_params params; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 13065dd96132..2102df261f1b 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1192,6 +1192,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_COUNTER_OFFSET 227 #define KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 228 #define KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES 229 +#define KVM_CAP_ARM_SUPPORTED_FEATURE_ID_RANGES 230 #ifdef KVM_CAP_IRQ_ROUTING @@ -1562,6 +1563,7 @@ struct kvm_s390_ucas_mapping { #define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags) /* Available with KVM_CAP_COUNTER_OFFSET */ #define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_counter_offset) +#define KVM_ARM_GET_REG_WRITABLE_MASKS _IOR(KVMIO, 0xb6, struct reg_mask_range) /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) From patchwork Tue Sep 19 17:50:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13391743 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 7B13FCE79AA for ; Tue, 19 Sep 2023 17:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=YSWlf+TkuoV45BAsJ+R5wFwDP1fsuy/HIYlDoBZXeRk=; b=Hx/vMldgto7c/kIMGfwYx+1Adj jI7z2GiIEHwUQ4s5zC4zbR8MJTYuJ0yakby/qxHhApoyGC6YlxsbUWCSpMZ8Y0Wgao5WsaGyu2EcT fCSR7iJR3ewCIE60G+xiv2B/kdjqW4c9qN5Rh+DebWzMImJjI9S++GSxs8GGoicidLXS/lssVIn9S 9FJJ2Tc3FxcYs3EPxwfndJ2JbprBjV2p5p++Ut3pRJb7Ryg+3btAo3pGv7ptHZVOxzE42mKl9FkU4 AlBU7IImswlxM5KHJwcn6KIpjC8M8j/ER0dB0ANmEYKDdC58iCuQ2iLaxzhnAbwtza2vY8yCwFB+0 CW9GrqVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiesi-000zv5-04; Tue, 19 Sep 2023 17:51:28 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qierl-000zHz-2i for linux-arm-kernel@lists.infradead.org; Tue, 19 Sep 2023 17:50:33 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59c0327b75dso56246467b3.2 for ; Tue, 19 Sep 2023 10:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695145827; x=1695750627; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NNgnTGU4YpsPoVFc3PtBmlT7XDV3ZwiZBqdVlE5z4mo=; b=tj2pkU+NBWc3Kffat3JoHxNElqZWwLX5x3ANDe/wxTOXgrwhxi6fu59kUo4Jg1fQ9o RWV+kY/ollGCq+lHSrwzdaPNIqbF8794TD8AoLYu0+Eg7pQpgfY7dXN0B58NImaubNzn tJaHG8dhnt2Z2syJpwVYokYrCzILogH42B39MtVI56P60rJPoZmio7W8TeH3u33riheK Dt/LtBjWbLgsZ1l+Nb2PLwafHGo++rPvhvAZ0yzTMYC4j1AMl+O5zCWnlfyF9DX2C79Y wxxPMKiP0c4SXPRnFoODZq/fT1EpUfebiAsngC09zlAew3Vm20yX3CX2quymNsfoTbzf u0Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695145827; x=1695750627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NNgnTGU4YpsPoVFc3PtBmlT7XDV3ZwiZBqdVlE5z4mo=; b=FBBxknlEnN2TVQP83cuYcUxg4WFhO7gmy19I4/rNeaSbrB7wS+HmnD0UxktXZ0TgeZ GU7yf721CrGJRKKzOTNInL5Yx9bEMCQ+6IqpbDQu0O86Y0SsfdUVhocodvB52DU0jSkn LJ4zPNzZ55ziTPgtDT2A9rYutoE5yUh0QVYXqE5WVS+2x+MEzMRSo5v0hKveW9QTmERV Txa4hNrnQeJjs55f7pBOCB9PBZmBbRA9uDKqK/h64BDYDcd+1Hk8Ggz4VbFUdj3ym5+V oWmDMeWkBZBiwyPiGWisaggWVfA7R+m87RlXseRZSqy2Zn9ox5QaY5QOFBJPOp+Sj4+j 07sA== X-Gm-Message-State: AOJu0YwOO/nr3cQNLftH/pj0E22zghKwTAcACKjI4ZGqf0GAurzYJ255 nI7Z8MZDrp01kvhJGais4mSX4xDgaH2A4KsyDw== X-Google-Smtp-Source: AGHT+IEu56riQdG7TAOdvAS2CxA7zpebYty6rvbyBf23leV5Zz1VX6/KIxfw4Os8Nq3PKH1WkglynetaSy09CpEecQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a25:8d0d:0:b0:d84:c154:9b7d with SMTP id n13-20020a258d0d000000b00d84c1549b7dmr6424ybl.12.1695145827325; Tue, 19 Sep 2023 10:50:27 -0700 (PDT) Date: Tue, 19 Sep 2023 10:50:14 -0700 In-Reply-To: <20230919175017.538312-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230919175017.538312-1-jingzhangos@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919175017.538312-3-jingzhangos@google.com> Subject: [PATCH v1 2/4] KVM: arm64: Document KVM_ARM_GET_REG_WRITABLE_MASKS From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Suraj Jitindar Singh , Cornelia Huck , Shaoqin Huang , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230919_105029_899847_F8530D11 X-CRM114-Status: GOOD ( 15.74 ) 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 Add some basic documentation on how to get feature ID register writable masks from userspace. Signed-off-by: Jing Zhang --- Documentation/virt/kvm/api.rst | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 21a7578142a1..2defb5e198ce 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6070,6 +6070,48 @@ writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG interface. No error will be returned, but the resulting offset will not be applied. +4.139 KVM_ARM_GET_REG_WRITABLE_MASKS +------------------------------------------- + +:Capability: KVM_CAP_ARM_SUPPORTED_FEATURE_ID_RANGES +:Architectures: arm64 +:Type: vm ioctl +:Parameters: struct reg_mask_range (in/out) +:Returns: 0 on success, < 0 on error + + +:: + + #define ARM64_FEATURE_ID_SPACE_SIZE (3 * 8 * 8) + #define ARM64_FEATURE_ID_RANGE_IDREGS BIT(0) + + struct reg_mask_range { + __u64 addr; /* Pointer to mask array */ + __u32 range; /* Requested range */ + __u32 reserved[13]; + }; + +This ioctl copies the writable masks for Feature ID registers to userspace. +The Feature ID space is defined as the AArch64 System register space with +op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}. + +The mask array pointed to by ``addr`` is indexed by the macro +``ARM64_FEATURE_ID_SPACE_IDX(op0, op1, crn, crm, op2)``, allowing userspace +to know what bits can be changed for the system register described by ``op0, +op1, crn, crm, op2``. + +The ``range`` field describes the requested range of registers. The valid +ranges can be retrieved by checking the return value of +KVM_CAP_CHECK_EXTENSION_VM for the KVM_CAP_ARM_SUPPORTED_FEATURE_ID_RANGES +capability, which will return a bitmask of the supported ranges. Each bit +set in the return value represents a possible value for the ``range`` +field. At the time of writing, only bit 0 is returned set by the +capability, meaning that only the value ``ARM64_FEATURE_ID_RANGE_IDREGS`` +is valid for ``range``. + +The ``reserved[13]`` array is reserved for future use and should be 0, or +KVM may return an error. + 5. The kvm_run structure ======================== From patchwork Tue Sep 19 17:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13391746 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 BCAD8CE79AB for ; Tue, 19 Sep 2023 17:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ktohVVrUsPNYlM+vzeCspFs7JY7FD3gyWySxFzg8XRE=; b=uGrObXiGHmzxktTgTB3Lr8sqyy H2EoZtNHw3ZsX6z39DT1g0a8IP7BEAyqfTM6dOmJEjT+8ZcjQA6qaB00EshXsFK6cwS48nDpivfBQ 7ry/tpF4Prt1y8JUl/e9DmQG6Q7wtccZTpMVvXEq5zlsp34IEdxssv5pIOA84PHB0x0GE0p1oFANy E1i+gimr8CSFQrx3P06FobVIXHv3yyC+v7D9DlatrxDNQF48S5auzwiir6w1amO9nVppTJsDmFKWi guWgkRxeIMT3tvOn790tD9CWdf8Q5irQuIJHnMMnjlL5MzznVYkgDlL1cSEhEyozfVATNcT6WtpAJ sTCuRytg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiesg-000zuE-32; Tue, 19 Sep 2023 17:51:26 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qierp-000zKR-02 for linux-arm-kernel@lists.infradead.org; Tue, 19 Sep 2023 17:50:35 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59e758d6236so36179337b3.1 for ; Tue, 19 Sep 2023 10:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695145829; x=1695750629; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+FfNGTxjW46m0vYg5JQZcFmeN0Q+crU/shufIChYdkI=; b=ZmwaNK27VuVKXzs5OakRfHE5lMHWd+yDQncqWWEWBSM84FknBxNWW89bxNvEmjl22N n1P1DztqbE/ZQZ2cMG+hzoMvumZBWIAkV67cTe74GhKqDYMMkaETvxAM/5uJXjEkZxtu lZ+XD3GZZ0DSV60YTN1O4hfHKqCldlk1UxrQ6/Nfrlj4JM7MreZz5pSdgkPxAGOeRb97 2GADi1yXM6L4yhSE9sQaTBNEkZRB9cGNG8STQhA65ChradM0ErNus5oR3+ouSg2ZaHz/ +S/Fq10WeUyhXUAnAik8m3xNiXar6HOPe//6Bw5Dm5JBs4CfGb9/+tIwyJH8gU/8ds2h d6+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695145829; x=1695750629; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+FfNGTxjW46m0vYg5JQZcFmeN0Q+crU/shufIChYdkI=; b=Wx+ikWzSaK3K+LBSeSSa6/3EslzeeZhYDz9rly1VWyDhHa6e9amsHRhByVohfB09wa UfVDV6AAKdQQVJGsmQbmN/6jqehNSYLGexSWBlvtz8Myqf8F2ydIed+AjtNwfTVMNzpC 6cePU0kOXjazVNppn8J9wlvyubUPVi92WnP+aCPAe0Y21+mHpgOWny6gEc7oigtlztpB FE8hDe6W+yV0oGdN6RtGYeT5EUgDmV+tnL536NGoIOYxVB2z0V03BWL6zHM1SXb8exCd V2YojHbZn0T8RpbFgQM8xnhU4mPz0f2T9tIhjJzlGYYQaPv21FcPs2ElggniJZVinYkc O5Eg== X-Gm-Message-State: AOJu0YwXos6t2Cep/d5o2HKg5Yj9slHEVS615DwlavlfogYYd07C72Vy Pom7rMq6l0WaeQX3aVLuxURCqi/Z3aVdtZVfcQ== X-Google-Smtp-Source: AGHT+IHzfDyzqT0qS3LWIHvfZz7RLjnCjuKsmPhD/Jh5rsxGnZ1+liEskGzE0UZSm4JarDPcCE5W4ld3r7CjK2ykmA== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a25:db07:0:b0:d81:78ec:c403 with SMTP id g7-20020a25db07000000b00d8178ecc403mr5069ybf.12.1695145829452; Tue, 19 Sep 2023 10:50:29 -0700 (PDT) Date: Tue, 19 Sep 2023 10:50:15 -0700 In-Reply-To: <20230919175017.538312-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230919175017.538312-1-jingzhangos@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919175017.538312-4-jingzhangos@google.com> Subject: [PATCH v1 3/4] KVM: arm64: Use guest ID register values for the sake of emulation From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Suraj Jitindar Singh , Cornelia Huck , Shaoqin Huang , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230919_105033_091763_DB7BF411 X-CRM114-Status: GOOD ( 11.50 ) 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 Since KVM now supports per-VM ID registers, use per-VM ID register values for the sake of emulation for DBGDIDR and LORegion. Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index cdb9976d8091..4dcc9272fbb8 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -379,7 +379,7 @@ static bool trap_loregion(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - u64 val = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); + u64 val = IDREG(vcpu->kvm, SYS_ID_AA64MMFR1_EL1); u32 sr = reg_to_encoding(r); if (!(val & (0xfUL << ID_AA64MMFR1_EL1_LO_SHIFT))) { @@ -2445,8 +2445,8 @@ static bool trap_dbgdidr(struct kvm_vcpu *vcpu, if (p->is_write) { return ignore_write(vcpu, p); } else { - u64 dfr = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); - u64 pfr = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); + u64 dfr = IDREG(vcpu->kvm, SYS_ID_AA64DFR0_EL1); + u64 pfr = IDREG(vcpu->kvm, SYS_ID_AA64PFR0_EL1); u32 el3 = !!cpuid_feature_extract_unsigned_field(pfr, ID_AA64PFR0_EL1_EL3_SHIFT); p->regval = ((((dfr >> ID_AA64DFR0_EL1_WRPs_SHIFT) & 0xf) << 28) | From patchwork Tue Sep 19 17:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13391748 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 4EFA9CE79AA for ; Tue, 19 Sep 2023 17:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KmlSJBvTpssh7W61NBgUtURCGKhPmp3bVQyCys79nWs=; b=dZkUAwDxkOl9esJeN+89QaAo2j ky12uq2qZuVs1uckMfU11GYObVrllFRjZyBvgvT+tpX3W0k+fgc8XgfMgSH7k1ZgGe7I/zbYT5mvX 6/W/q2NvcFkiCJ3vcrplQPKz0y/QdWMkOHuJrhHXUUH553lxpuE4gmuWDzN+XcqytgzKNJJz1eRw9 JREjtM7QYq7PngrJlx5uU4x5jHxK3ekrNtIHKpHnxy/Bfn50mNc8AJEgfV2L6epohWRgC6CYFUrTD lwDUb32UaOT57RHCYYSZYL9Ksbagdin/uhwIRZ2ynO/tidRaYbp0AazaQt2eAwKm+JS0rHxU35ADb Do5I8WSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiesi-000zvk-21; Tue, 19 Sep 2023 17:51:28 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qierr-000zMo-1c for linux-arm-kernel@lists.infradead.org; Tue, 19 Sep 2023 17:50:37 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-274b736caf3so2660687a91.2 for ; Tue, 19 Sep 2023 10:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695145832; x=1695750632; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WDqS9gCK2hWJbMjalAxBpmnQXFt//tHeeybGxVMKHYk=; b=W50nmnNuP+zh5JGpB1xuupTFxpE3UCkuX3XLUE0PCClRqJ5LNX0awjYMYuK1Fts/iA LOJpKBPD/QFJawCVNnYrUbPH7ERMcEDjIiymElit13U/FnX6DT+pvMKfCjjBHhIcZEVy j/vBJ2tmGEMDx+NtBJO2SRpnxv1Xwp5yIkaCe0hFwg9QQYKUagGoXtxeRONRVZjUH6o0 yQOWdnzVV/FgFkJuYDfdzhJzJlrWq4F5r8AndtyjfOgq/bI+DN8KcbbKL8lxcMa2pTjp 1YjtkZNNqZbQ4JpagcgmFbvNQ5OHNSNWeajuFxaOXZirnfYQ0eb0qzShcqw3jiXhbKa/ E9Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695145832; x=1695750632; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WDqS9gCK2hWJbMjalAxBpmnQXFt//tHeeybGxVMKHYk=; b=F4cziUSTKECk7QBbuvq1PNw89evR2fkUyYlhKUli1rLfbvTUG+ww6aYZgcyfFfJ7tJ e5y++my9/dDN2T0l2NJ98KYH52fRNQYCIk4copC0PwfHkmgbtIATUI23R40EQ9VVLPCG iLM6aJhYM5kM4WONtxDO3d9TTD2jwm9OsGH+R93/AQYvC5s19KB9RM2jOJYRpoDWEJPB Lc7bxxmk2NUmu08cfrEWE8UU1hLgxHtrqfRbmzGOkJSrwFd5O2M7ze6UwnM2rVkXoaXi XJ9hfWoBjnmI1LECGndHXaC8GLCMbeonqtig/yXSa98axY8RFJU1aKHI+gaxaBMbkeQN P1vA== X-Gm-Message-State: AOJu0YzJW0BVlTEWX3xsAfCuPSTqxwxYKwrV2Y5FZ7UvPjm7ep5yumrW cMhflMeYMJ+2MjO/wGOgWP+Iu7Nq29sIzYn4Tw== X-Google-Smtp-Source: AGHT+IFN34HCsWwHcm0VPaYd7vZlKFFWGc9Vo3Vmh+MXi2TsekzYPzoQupklZxM0iu6EWzoGRPjs/bXawpslssLVYQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a17:90a:fa12:b0:268:1d63:b9ae with SMTP id cm18-20020a17090afa1200b002681d63b9aemr8189pjb.3.1695145831933; Tue, 19 Sep 2023 10:50:31 -0700 (PDT) Date: Tue, 19 Sep 2023 10:50:16 -0700 In-Reply-To: <20230919175017.538312-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20230919175017.538312-1-jingzhangos@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919175017.538312-5-jingzhangos@google.com> Subject: [PATCH v1 4/4] KVM: arm64: Reject attempts to set invalid debug arch version From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Suraj Jitindar Singh , Cornelia Huck , Shaoqin Huang , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230919_105035_576065_EA172509 X-CRM114-Status: GOOD ( 16.55 ) 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 From: Oliver Upton The debug architecture is mandatory in ARMv8, so KVM should not allow userspace to configure a vCPU with less than that. Of course, this isn't handled elegantly by the generic ID register plumbing, as the respective ID register fields have a nonzero starting value. Add an explicit check for debug versions less than v8 of the architecture. Signed-off-by: Oliver Upton Signed-off-by: Jing Zhang --- arch/arm64/kvm/sys_regs.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 4dcc9272fbb8..fdebd9d042c3 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1216,8 +1216,14 @@ static s64 kvm_arm64_ftr_safe_value(u32 id, const struct arm64_ftr_bits *ftrp, /* Some features have different safe value type in KVM than host features */ switch (id) { case SYS_ID_AA64DFR0_EL1: - if (kvm_ftr.shift == ID_AA64DFR0_EL1_PMUVer_SHIFT) + switch (kvm_ftr.shift) { + case ID_AA64DFR0_EL1_PMUVer_SHIFT: kvm_ftr.type = FTR_LOWER_SAFE; + break; + case ID_AA64DFR0_EL1_DebugVer_SHIFT: + kvm_ftr.type = FTR_LOWER_SAFE; + break; + } break; case SYS_ID_DFR0_EL1: if (kvm_ftr.shift == ID_DFR0_EL1_PerfMon_SHIFT) @@ -1476,14 +1482,22 @@ static u64 read_sanitised_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, return val; } +#define ID_REG_LIMIT_FIELD_ENUM(val, reg, field, limit) \ +({ \ + u64 __f_val = FIELD_GET(reg##_##field##_MASK, val); \ + (val) &= ~reg##_##field##_MASK; \ + (val) |= FIELD_PREP(reg##_##field##_MASK, \ + min(__f_val, (u64)reg##_##field##_##limit)); \ + (val); \ +}) + static u64 read_sanitised_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) { u64 val = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); /* Limit debug to ARMv8.0 */ - val &= ~ID_AA64DFR0_EL1_DebugVer_MASK; - val |= SYS_FIELD_PREP_ENUM(ID_AA64DFR0_EL1, DebugVer, IMP); + val = ID_REG_LIMIT_FIELD_ENUM(val, ID_AA64DFR0_EL1, DebugVer, IMP); /* * Only initialize the PMU version if the vCPU was configured with one. @@ -1503,6 +1517,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val) { + u8 debugver = SYS_FIELD_GET(ID_AA64DFR0_EL1, DebugVer, val); u8 pmuver = SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer, val); /* @@ -1522,6 +1537,13 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF) val &= ~ID_AA64DFR0_EL1_PMUVer_MASK; + /* + * ID_AA64DFR0_EL1.DebugVer is one of those awkward fields with a + * nonzero minimum safe value. + */ + if (debugver < ID_AA64DFR0_EL1_DebugVer_IMP) + return -EINVAL; + return set_id_reg(vcpu, rd, val); } @@ -1543,6 +1565,7 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, u64 val) { u8 perfmon = SYS_FIELD_GET(ID_DFR0_EL1, PerfMon, val); + u8 copdbg = SYS_FIELD_GET(ID_DFR0_EL1, CopDbg, val); if (perfmon == ID_DFR0_EL1_PerfMon_IMPDEF) { val &= ~ID_DFR0_EL1_PerfMon_MASK; @@ -1558,6 +1581,9 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, if (perfmon != 0 && perfmon < ID_DFR0_EL1_PerfMon_PMUv3) return -EINVAL; + if (copdbg < ID_DFR0_EL1_CopDbg_Armv8) + return -EINVAL; + return set_id_reg(vcpu, rd, val); }