From patchwork Tue Jun 15 13:39:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12322053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B1A1C48BDF for ; Tue, 15 Jun 2021 14:32:58 +0000 (UTC) Received: from bombadil.infradead.org (unknown [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E57D61483 for ; Tue, 15 Jun 2021 14:32:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E57D61483 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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=zWRLliBrUiwpVj18wB/C+jkSl5IsXFwvujZv4V5vEx4=; b=4MEmIMxIHEbmQJWArCr97sYKZn nmXMRVZDHQsm6SKqLHRI1DNYEjozLix5ySABVS/Sxqf9+iirz56P1aUbJTmKp2sDOwsLQ93wEyIxr 50ocN2lca4/q7rPHW8QUTNI37zZO6UdurefW4YrWwJlr18+5EH/pmFmq+T+qhNHDIM7BCvU/4puhn tvaIS9kjGksV+aonSSxYSpxvNgg9bhVFOOfLs8i029aMziP49iiVtuYiiRu33nPHvHAMOzTXFgdBb Z7NtaViqx7jS0reZCXgMW/njXqvRyW0Nz4lH4YpxrbWCzaofG8MElacOO/W4kR0htIHT0oC2B2BPa RJymDF2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltA0B-000ZSm-DJ; Tue, 15 Jun 2021 14:25:16 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lt9Il-000FBP-Jg for linux-arm-kernel@lists.infradead.org; Tue, 15 Jun 2021 13:40:25 +0000 Received: by mail-qk1-x74a.google.com with SMTP id k15-20020a05620a138fb02903aadd467ff1so175086qki.7 for ; Tue, 15 Jun 2021 06:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=MzTuqOfSLXkQXPIBooH4fP63ZLmEi4w/w9F0qFeyLuI=; b=b7HMusMXDb/BxYrxekRaLBxg6+8Di6dNYMsHoZDx91Rw74oEQIqQpEq4tZYgXlM9Bq vBq9n+In91lMzAjJUtBV2Qu2CPHCKbd9illCEiWAlYwAgEaftP0NYm7BNePEToWqmCCn 7pVSLwwRKSPKsT64YEkG5/LzzS+jWXFoy+P6Inh6ochfcO7ZoZuX0kLF/J7TNi9BHi96 5VDUuCwqtxO3gINwdOreBNN5T2Yir3rmT17+JqIg3gxAsrmpqEyfo9AT2MUfC3dBApjL jYoPAG42lxBJXkEvBK8FjZwPr8Bf5LH/9q+VgPrdh0UubiS6CyOU9vemBBgXNldhL5zL mWgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MzTuqOfSLXkQXPIBooH4fP63ZLmEi4w/w9F0qFeyLuI=; b=qw0YNxnHT5y4KVKA4z8ynPgiRxxvLDVnlpsrQdqNNk/WyrN5jAM64iQlMqLgW6WkX6 DNcxY2s4rrPeBQ1jBVZlVKWV+K3KKYVSkdRtHwIbZTl6rBW+1V+kw81G4iBKNsDToB3n TQVMJGb59Fr+nTrb2tsvc9y6m5QeW8sgMr6lEBqeWNlstac9lvafT6kbXKZYUBxSetRi nkS1aeCB6X5FHtSfvR9D3f5s5pPpFNULMKmPRSv+LSo/+ZbVKBpCZdf9YmyEcE9GUMBL cqgJ3Lnt2L3S0W5pKpqb5ijTGtsMYqphAKcwKllChkuQhsMhO9P0i+KRuvf6yVDTKXdi 31yg== X-Gm-Message-State: AOAM531/JVdJeXzMoWYkKYhCfZlTKzBjhslsjsIVFmi/7qIz7me/rXRf owLpvrGLFUIZXPs/jRTnnpKon/pR8w== X-Google-Smtp-Source: ABdhPJwvkJ1Cqi1cwhQ8+25SscFqILXhxSW+c+DE3yisa7Q5WIyh+leztx9V8c334RDLLSz46bw6zNHG1g== X-Received: from tabba.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:482]) (user=tabba job=sendgmr) by 2002:ad4:5309:: with SMTP id y9mr5312176qvr.31.1623764420268; Tue, 15 Jun 2021 06:40:20 -0700 (PDT) Date: Tue, 15 Jun 2021 14:39:50 +0100 In-Reply-To: <20210615133950.693489-1-tabba@google.com> Message-Id: <20210615133950.693489-14-tabba@google.com> Mime-Version: 1.0 References: <20210615133950.693489-1-tabba@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 13/13] KVM: arm64: Check vcpu features at pVM creation From: Fuad Tabba To: kvmarm@lists.cs.columbia.edu Cc: maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, pbonzini@redhat.com, drjones@redhat.com, qperret@google.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, tabba@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210615_064023_753629_0CAAB18A X-CRM114-Status: GOOD ( 12.82 ) 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 Check that a protected VM enabled only supported features when created. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/pkvm.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index cf624350fb27..15a92f3fdd44 100644 --- a/arch/arm64/kvm/pkvm.c +++ b/arch/arm64/kvm/pkvm.c @@ -88,10 +88,53 @@ static void pkvm_teardown_firmware_slot(struct kvm *kvm) kvm->arch.pkvm.firmware_slot = NULL; } +/* + * Check that only supported features are enabled for the protected VM's vcpus. + * + * Return 0 if all features enabled for all vcpus are supported, or -EINVAL if + * one or more vcpus has one or more unsupported features. + */ +static int pkvm_check_features(struct kvm *kvm) +{ + int i; + const struct kvm_vcpu *vcpu; + DECLARE_BITMAP(allowed_features, KVM_VCPU_MAX_FEATURES); + + bitmap_zero(allowed_features, KVM_VCPU_MAX_FEATURES); + + /* + * Support for: + * - CPU starting in poweroff state + * - PSCI v0.2 + * - Pointer authentication: address or generic + * + * No support for remaining features, i.e.,: + * - AArch32 state + * - Performance Monitoring + * - Scalable Vectors + */ + set_bit(KVM_ARM_VCPU_POWER_OFF, allowed_features); + set_bit(KVM_ARM_VCPU_PSCI_0_2, allowed_features); + set_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, allowed_features); + set_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, allowed_features); + + kvm_for_each_vcpu(i, vcpu, kvm) { + if (!bitmap_subset(vcpu->arch.features, allowed_features, + KVM_VCPU_MAX_FEATURES)) + return -EINVAL; + } + + return 0; +} + static int pkvm_enable(struct kvm *kvm, u64 slotid) { int ret; + ret = pkvm_check_features(kvm); + if (ret) + return ret; + ret = pkvm_init_firmware_slot(kvm, slotid); if (ret) return ret;