From patchwork Tue Mar 29 03:19:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12794420 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 08AA5C433F5 for ; Tue, 29 Mar 2022 03:22:03 +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:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=jGX9jt2NMHzimlhDPe4fxL/yLhX4kG8DFLEXRuGHTgg=; b=KKI 9cVzsSPnU7b9pYEvahJVgbJ4JPnvvH3b46jhhK11Zk2UDrKt7HLJLCwH5R5dVMqgJK53MspnB0qug ndMj1yrdtLRuKIbEAOQt1m3mRVooZYhAwkg75XZDbSYNDIoPBEtwpPIsTqOu7/p84rkr2rPQwOJWi 0X2mh1aG0x8jfATeMoUY18NFYwXS6wrLWPM+099+sCeaqmbb5AFrw3FI9Wk07TvxdIXOElyq5n7yD HwKkylqw+sWHPtaIPIN5O7JaC6yV3F6Vo9741HjhXD8Ajl3eVVQEW1N/dGncTMxp2iAZLOtCRAOBl Vrc4DRPQueiFL+i9ELpjEA2hP79hP0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nZ2PM-00ApTQ-Qs; Tue, 29 Mar 2022 03:20:37 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nZ2P1-00ApA8-D0 for linux-arm-kernel@lists.infradead.org; Tue, 29 Mar 2022 03:20:17 +0000 Received: by mail-pl1-x64a.google.com with SMTP id q11-20020a170902c9cb00b001546680ee18so6954489pld.7 for ; Mon, 28 Mar 2022 20:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=sAGNmdLtBshVUh/KYJEFMIapacr3RW4pw1K+CiinPIg=; b=V/TJBz/iUJlEmkrMTjYoIS6WDNFPx87ejo/7vs1jet6SMwswMc4CzXzDjCkjps9egi 127Cak4S3T6A/M28y5M1f1Hq86/nSXOBXnoz72c23voqPqxWYFWZnI6jzEb9ALYSAl/O eGM1GpOhJqrK/YSjdMpQwtvKFgIf31Cug8pGvOqxfsVfzfQU8QfaPEZNq4phzhj41nvT k5hPTFeGQsTKOd4ZJxaWR3C6ZwgDnjG1fyOQNb32py8ITkbMR7b6t6M/rg30q+JVozO0 4vUgt86FSv6oIZvyLwC5YYTggVgcEthH8FWTKJcsX4HBs8fSrk0+4D3QqCPcYjRtH2bR AGQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=sAGNmdLtBshVUh/KYJEFMIapacr3RW4pw1K+CiinPIg=; b=YfMzjVTAnQcn4VZpJSUginDUZaCy+ap24RCtGcRVsh7vhadpjk9Q5dMxOlcuyQxQnx Pqj1fOKoahBGa18JrD50DLzTSbU6wfb/Ih97UgR+ftQIYWKQdQyBRkLh/EjdO3QM7rTP iv6DUSmL4hydgHX1920jgFtcbMfRzYXsvjRZnT+ls607UnNbTiNRet9lPE4XXloo3/xk ZSLP8NlhLc9I8qGr0ED7Ihkhf7Ubiq5gl4+NDaCCv1FIW6EDOEzL9Z9bdlhskmK7dYgG DSko0i8o7dXWlSPnXMkOUPrrB6IN/3wugHHHPpa9PnEepnlozsOfjalpkNoxKweUmugn QsWQ== X-Gm-Message-State: AOAM532flaFijil15S+l3vDv+ASZwp8IfaMx2O25qRuepDUsa4TtfgXo GniF21jYZrY4gzuPbpoWR+ZeaJiBMLY= X-Google-Smtp-Source: ABdhPJzL7MMvXVrrnBv7niD9JFw1J92Bl4gjNXuXN74eGBsYjblpq85cVrz7O16dqYjfIYwFFLWZVajk8pI= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a05:6a00:2310:b0:4fa:7eb1:e855 with SMTP id h16-20020a056a00231000b004fa7eb1e855mr26199966pfh.14.1648524013695; Mon, 28 Mar 2022 20:20:13 -0700 (PDT) Date: Mon, 28 Mar 2022 20:19:22 -0700 Message-Id: <20220329031924.619453-1-reijiw@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v6 0/2] KVM: arm64: mixed-width check should be skipped for uninitialized vCPUs 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 , 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-20220328_202015_503799_DD03A1D2 X-CRM114-Status: GOOD ( 16.42 ) 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 KVM allows userspace to configure either all EL1 32bit or 64bit vCPUs for a guest. At vCPU reset, vcpu_allowed_register_width() checks if the vcpu's register width is consistent with all other vCPUs'. Since the checking is done even against vCPUs that are not initialized (KVM_ARM_VCPU_INIT has not been done) yet, the uninitialized vCPUs are erroneously treated as 64bit vCPU, which causes the function to incorrectly detect a mixed-width VM. This series will fix this problem by introducing a new VM flag that indicates the guest needs to be configured with all 32bit or 64bit vCPUs and checking vcpu's register width against the new flag at the vcpu's KVM_ARM_VCPU_INIT (instead of against other vCPUs' register width). Patch-1 introduces KVM_ARCH_FLAG_EL1_32BIT and KVM_ARCH_FLAG_REG_WIDTH_CONFIGURED bits for kvm->arch.flags and uses them to check vcpu's register width to fix the problem. Patch-2 introduces a selftest that can test non-mixed-width vCPUs (all 64bit vCPUs or all 32bit vcPUs) can be configured, and mixed-width vCPUs cannot be configured. The series is based on kvmarm/fixes at: commit 8872d9b3e35a ("KVM: arm64: Drop unneeded minor version check from PSCI v1.x handler") v6: - Fix typo and minor nits in the selftests [Oliver] v5: https://lore.kernel.org/all/20220321050804.2701035-1-reijiw@google.com/ - Rebase to kvmarm/next (and drop the patch-1 "KVM: arm64: Generalise VM features into a set of flags") - Use kernel-doc style comments for kvm_set_vm_width() [Oliver] - Change kvm_set_vm_width() to use if/else instead of a ternary operator for KVM_ARCH_FLAG_EL1_32BIT check [Oliver] v4: https://lore.kernel.org/all/20220314061959.3349716-1-reijiw@google.com/ - Use different implementation of vcpu_el1_is_32bit() depending on the context. [Marc] - Rename kvm_register_width_check_or_init() to kvm_set_vm_width(), and call it from kvm_rest_vcpu() instead of from kvm_vcpu_set_target() - Remove vcpu_allowed_register_width(), and does the same checking in kvm_set_vm_width() instead. v3: https://lore.kernel.org/all/20220303035408.3708241-1-reijiw@google.com/ - Introduced 'flags' to kvm_arch, and use bits of the flags for a set of booleans for VM feature. - Changed 'el1_reg_width' to two bits of 'flags' of kvm_arch. v2: https://lore.kernel.org/all/20220118041923.3384602-1-reijiw@google.com/ - Introduced 'el1_reg_width' for kvm_arch and use it to check vcpu's register width against the flag at the vcpu's KVM_ARM_VCPU_INIT. v1: https://lore.kernel.org/all/20220110054042.1079932-1-reijiw@google.com/ [1] https://lore.kernel.org/all/20210715163159.1480168-2-maz@kernel.org/ Reiji Watanabe (2): KVM: arm64: mixed-width check should be skipped for uninitialized vCPUs KVM: arm64: selftests: Introduce vcpu_width_config arch/arm64/include/asm/kvm_emulate.h | 27 ++-- arch/arm64/include/asm/kvm_host.h | 10 ++ arch/arm64/kvm/reset.c | 65 ++++++---- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/vcpu_width_config.c | 122 ++++++++++++++++++ 6 files changed, 196 insertions(+), 30 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/vcpu_width_config.c