From patchwork Mon Mar 14 06:19:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12779553 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 C3915C433EF for ; Mon, 14 Mar 2022 06:23:44 +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=gZfJj6bU3eNTLzxMEoefXBdHkZJcmoYrvTp56v9GOz4=; b=UaE 5hrgMFVOunH4m1g0zL8lID/GOxoarzq7Cmq/B3AIr5MDeNM+Hz75lKkM2/51jWq0JwolcVkGbQvd5 inspE8qsgNFnKJ0clwNdzJ2yd2zJlO2YTEBUNF6R9DgbKV2tahgu7SDpShPzfYpjH0aooqTQMsh0C aiNPuLEmkrc9GaVsqAlAqkufnQbuRRd6A8HJngGRbWdgsfo7dDP4f1fhxeGJOx2dDjhyqnxACZKKR 2QK+0sxfHFc2BJcTkmez75rlmqoRbx4VbrhIjwWMsxSuLi8VQ6e3Ovw/9jLNnp+arLyF8qzGhKbix GfIxXR4Lr5ryJa5Cbq6/24nFiG0SP0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTe64-003vnu-Qj; Mon, 14 Mar 2022 06:22:24 +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 1nTe60-003vmZ-UY for linux-arm-kernel@lists.infradead.org; Mon, 14 Mar 2022 06:22:22 +0000 Received: by mail-pl1-x649.google.com with SMTP id q8-20020a170902f78800b00151cc484688so5900166pln.20 for ; Sun, 13 Mar 2022 23:22:17 -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=6PVulGo8PUqZzVS4FQCQESr0wP4UDOtzRfsUiSpPSzU=; b=NMTHcfQ//XkUn0hFLjVC8DV6m2SeAkUsxvrHVx1PDOK7/ZDB4u/CaWkMUe1eUX1KUu oeWxc0jrL5ItjthiRDO8371DRjwU6H4tDrgeZRHvcnJ9TQaUJ5dYy73EDcbbJ+OJamsp u/gnzwiwxo27r86aAstrIVXL2wUXwb4D2Q7P3FwPRgBjiatwul1mp8Zp8Q+CKD2TbQNp J44/0PEURgqLrP49oTQJ9ozS6cl6V9/u1udMFKsqYilq+o+qVUQcozRCnco1kamSOAn0 jDpWAaZEsrJ3rZQ/lXmprnstFDU7dRHMa1id9zxWeOfUTNaE38HJoTarnCJWj6itYWDX tcyw== 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=6PVulGo8PUqZzVS4FQCQESr0wP4UDOtzRfsUiSpPSzU=; b=De0vM51nMZpPJf72JtehlJsXbb3Jl53x9aeKRNNtxKscKOVh1f3cgomP+lVYdLI4gh peMH4eABWS4+ABDW2b3vSstvJWreEOcyVLvHZBwDqZKJF9kifqIfW6CvqWdPVOaHAhVD OX9/HLMEWQ6GgBYzqD9ze6na3SueWDTMKQGB+x+0a6rUzlOBNsHSbYY9aV3mwPGRMidu 2QIyqbUTPGrkYGAWT2HdQwTRPPi+RgEiEFbsCxy0wkTVgGuwpGq/N/sqa6t5WnhJFUhW LpNx8dbWf1C2A6kvVjVngJLsyldyC+ZbDZUcAzOpwMPqNG2O2Wc6BGC5NsX9d7av97r8 nALw== X-Gm-Message-State: AOAM530/s2yvNFRHeSuimoXHG0TPQMODretKvIXe0m0f5Mh8B/ryPYrJ jDT5Tq0rTfeTNzIScjc2qE56g3ep7YM= X-Google-Smtp-Source: ABdhPJxsAV1KsLam10OQrLQ3Mk1lzfy04OADsgT2PIWmgxVOee5D2EHoQAqFiUQHfbSsA2dOXD3LguvkztI= 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:b8e:b0:4f7:c63c:f2fd with SMTP id g14-20020a056a000b8e00b004f7c63cf2fdmr4623111pfj.8.1647238936995; Sun, 13 Mar 2022 23:22:16 -0700 (PDT) Date: Sun, 13 Mar 2022 23:19:56 -0700 Message-Id: <20220314061959.3349716-1-reijiw@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v4 0/3] 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 , 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-20220313_232220_994668_908C9BDE X-CRM114-Status: GOOD ( 16.00 ) 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 a new field 'flags' for kvm_arch (authored by Marc [1]). The flags will replace a set of booleans for VM features. Patch-2 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-3 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 v5.17-rc7. v4: - 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/ Marc Zyngier (1): KVM: arm64: Generalise VM features into a set of flags 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 | 21 ++- arch/arm64/kvm/arm.c | 5 +- arch/arm64/kvm/mmio.c | 3 +- arch/arm64/kvm/reset.c | 64 ++++++--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/vcpu_width_config.c | 125 ++++++++++++++++++ 8 files changed, 209 insertions(+), 38 deletions(-) create mode 100644 tools/testing/selftests/kvm/aarch64/vcpu_width_config.c