From patchwork Tue Apr 19 06:55:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817525 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 258C6C433EF for ; Tue, 19 Apr 2022 07:12:40 +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:References: Mime-Version:Message-Id: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=gDk+IOaHZFP9jfxqJlcryv+GAjUj8BY32iky+wn8Ql0=; b=Cu7D3U9c4d/q2avsbRMfFNVPds EPIDiHTQXczHX+Wsym4ZhhU4xbLtraDM/yDctjOwRLqohmTrPRwBSu6NRcUJs02qqHbWR2U0RZ1U4 Ii1rzYMb08WwKkJR4KXQ+aSAtqBawiV8Jqey+OhpPsuGNuJevtmZJkR1KmnH9i0lmrqArXJeLns5N bLsQOE/xaURXHc0cKBKHjbuu4ULVrCLaftUbkkGMuqosqmm1p4YtRC2A2/Rl8qtRATAF9mBZHvbV1 8uFYbn3cOgjDbuEqKa5zzJBdth6HDwoI5K4hS1TLJGAyRNpFdCkunDh6JCwtZhy5UIfljmrR7JYf0 bS0Mqwow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngi12-001skw-1g; Tue, 19 Apr 2022 07:11:13 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghnz-001ncS-1V for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:57:44 +0000 Received: by mail-pl1-x649.google.com with SMTP id x23-20020a170902b41700b0015906c1ea31so2612720plr.20 for ; Mon, 18 Apr 2022 23:57:42 -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=U4uOGGGNJJAvE+8qhBWKzG6xiqX6UboPrGG2sNPZOY8=; b=BewbNlPjPqMatcm5XCUJOCpQZV4IoUW4ifHD5JfI6GHGlRBqW2sLCDsPuTDMbF2jUH Wlv1w+R+Edq3e7b8T/1GKHqWp2fKfCDQosSdPRzW1wXYl688u7L0nZNPdsN1cV8hUJlj dA7dU+yyYorRaosHIs3zf7EDl5GaiYDINtqkhAEv928ecEPq4g9QENwKQkaqEVUO+EdU kLtR11yTTd7eAasAJcwfVzE8tSgBo/4cH2y9b/7wc9XFcuKMcMQ188Jx2nOlz6c8Pt6r 4SpvFqlxMnxNrUpursSPLQOzcC+Kc38iLMoD9FEUJ9QWJjCdK6M8OTNlU4b8jYjVazsJ NFYw== 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=U4uOGGGNJJAvE+8qhBWKzG6xiqX6UboPrGG2sNPZOY8=; b=RQMVCrV5gC7ulBw7KJhBWziTJfXEGfToNQD/rBr81AYmv1LWBvEBsCNxq9MK67y9lF o0/ulmZ6VmYEoS1FoF8fy9+wkcs03C8tpKOCTPI7cQ0qUy51vDKCNpfbjun3Og5yqVqA WzDgXRiLPchY2mYNegqEn/Yi3s54VP+PfPlELETVjJYNcDo25ecM6MLzJlkjsxBLbWSo qmNWk9och8Bk+mHBziFUFTWc67m11Y2QO+ozJ2BA7vZqQMo+IWjz8+E21w+MfB/KO8H3 ZMK4WbROIXgNDIY7h9I8I96qbsSO3yZ4GDqjk2nrJRN/NPNHCENM22HUiRjGwoMeF87e 8cDw== X-Gm-Message-State: AOAM532BW3KFE+GVNvlEN0Vz5sItfDa3HkOCOdiIyF6yDNi1eBeVKUH6 YzD1KN7tENVF1/hznmh7oCLbSpnpeAg= X-Google-Smtp-Source: ABdhPJwNvsMFXxj/P4c/uyL22/CuuuumZEIUldC8yuu2qFzsobmd9UhZjjZnKg5gGPfNpCl6SSEUeTinmLA= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90a:cc0b:b0:1cb:8351:a47e with SMTP id b11-20020a17090acc0b00b001cb8351a47emr17191716pju.67.1650351461844; Mon, 18 Apr 2022 23:57:41 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:28 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-23-reijiw@google.com> Mime-Version: 1.0 References: <20220419065544.3616948-1-reijiw@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v7 22/38] KVM: arm64: Introduce KVM_CAP_ARM_ID_REG_CONFIGURABLE capability From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220418_235743_131620_4443FDFD X-CRM114-Status: GOOD ( 12.67 ) 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 Introduce a new capability KVM_CAP_ARM_ID_REG_CONFIGURABLE to indicate that ID registers are writable by userspace. Signed-off-by: Reiji Watanabe --- Documentation/virt/kvm/api.rst | 16 ++++++++++++++++ arch/arm64/kvm/arm.c | 1 + include/uapi/linux/kvm.h | 1 + 3 files changed, 18 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 85c7abc51af5..e2e7b08e64c1 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -2601,6 +2601,14 @@ EINVAL. After the vcpu's SVE configuration is finalized, further attempts to write this register will fail with EPERM. +The arm64 ID registers with encoding Op0=3, Op1=0, CRn=0, 1<=CRm<8, 0<=Op2<8 +are allowed to modified by userspace only for AArch64 EL1 vCPUs if +KVM_CAP_ARM_ID_REG_CONFIGURABLE is available. +They become immutable after calling KVM_RUN on any of the +vcpus in the guest (modifying values of those registers will fail). +Those ID registers are always immutable for AArch32 EL1 vCPUs, which +KVM_ARM_VCPU_EL1_32BIT is configured for, even when +KVM_CAP_ARM_ID_REG_CONFIGURABLE is available. MIPS registers are mapped using the lower 32 bits. The upper 16 of that is the register group type: @@ -7724,6 +7732,14 @@ At this time, KVM_PMU_CAP_DISABLE is the only capability. Setting this capability will disable PMU virtualization for that VM. Usermode should adjust CPUID leaf 0xA to reflect that the PMU is disabled. +8.35 KVM_CAP_ARM_ID_REG_CONFIGURABLE +------------------------------------ + +:Architectures: arm64 + +This capability indicates that userspace can modify the ID registers +via KVM_SET_ONE_REG ioctl. + 9. Known KVM API problems ========================= diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 5c1cee04aa95..b4db368948cc 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -211,6 +211,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_SET_GUEST_DEBUG: case KVM_CAP_VCPU_ATTRIBUTES: case KVM_CAP_PTP_KVM: + case KVM_CAP_ARM_ID_REG_CONFIGURABLE: r = 1; break; case KVM_CAP_SET_GUEST_DEBUG2: diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 91a6fe4e02c0..171f1d0ea1e1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1144,6 +1144,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_MEM_OP_EXTENSION 211 #define KVM_CAP_PMU_CAPABILITY 212 #define KVM_CAP_DISABLE_QUIRKS2 213 +#define KVM_CAP_ARM_ID_REG_CONFIGURABLE 214 #ifdef KVM_CAP_IRQ_ROUTING