From patchwork Fri Aug 27 10:16:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12461861 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 BF0C4C432BE for ; Fri, 27 Aug 2021 10:19:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 889F260FE7 for ; Fri, 27 Aug 2021 10:19:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 889F260FE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=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: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=/inqjQgXKNVoDM57pzVFrULNoTma7pMgYL1v7CWnEeg=; b=QcI mkllVUGXeskxAPGJy9XPgWWneEkhn/jlZOOhHwQTcKbU1ALd1TvtWjE+OXg+EFuZZZuDkePRjfGLd 8Yy03/R9VZ4krvfWyByf/zcAehVI2yPUg1YeSshKs8TxpfBwftQf0KO35BiJ8OmonfzH7HyIKajHZ jJY+d8VD92DtsLJkKweHLSXd/AAEK6UQdF6lNrKiXRcENa/cJUScsTlCGhZfEh27IsdnisYlTxlab KROXKklPWwrhrWI0eVLmF8BZBRiC6n7cY2GHILqSbm1QCIe1BJJTn6Or8KRK9Nlj7QCtoobpPDCeR P290DFHeFkcory/V1NCMXMUv9j5E9qA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJYuJ-00CDyC-E6; Fri, 27 Aug 2021 10:16:19 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJYuD-00CDx1-3Y for linux-arm-kernel@lists.infradead.org; Fri, 27 Aug 2021 10:16:17 +0000 Received: by mail-qt1-x84a.google.com with SMTP id m6-20020ac807c6000000b0029994381c5fso888226qth.5 for ; Fri, 27 Aug 2021 03:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=jsA6xT98EeA80UGER1WEqhvGsAPxq/3pPd3JQ9gufNk=; b=VhFaBqIfTeTaY8WOw3nAg0JlzJztciYu4suzC598Ebz2q37OUD13vfp9lIwq5DIwyw t2wAB2K4+11hk+25HeExvkyRPequRrvFhjWJRyh1JdbiFa0vwD4hj3hd/PqOLHgui/P9 YfWX7zFGKKu2ymeJI7D+6uyVNjR9Q1ctx4ZkLAHHHNITVKevtV5R9VMkYD6L5A/Z+L4C ZGMuUGyptLkmSaYfLQsfqiQCk7FI2cDGRWLqlN4QQEGyvdUX+LtphSsnwi/HOo9KEcel DYxqxTmSRwZnKtnJoQRVYbLs194cX3pj7jdEqAGWK+Rc5akusnV62oo28FJMS5/UkyRd r7Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=jsA6xT98EeA80UGER1WEqhvGsAPxq/3pPd3JQ9gufNk=; b=B7Wo68BxYoU6sJY1jeqYiVp8dOOccG0ycWcG6lXG7MPQJj8wjjADnQmFo22sDGDuRK L//zv4ei6w3UdZPMLa04tvwm+xiMHJhfh6Dlp/cOgoXAVXK9UxQOQgd9ZO/6lFint1D0 xOLPu3Pq2/oagoYEgRKszoB4NtQWcpkA4Vs0p7z3pYPCAt8qT7ynfq6BrUfxJeMlea+l msrn8CSuKU7/FucN0XB4moKJ+R3azLj2Nm3Jeb+vSnNqcblRKpKZSVC3dDQVWt8VTEDj zqr6uVWOTyxS1zmMrTOCuYiRvryK/HablWOOqRVv85YaYzbGAWkwDK39k0em5oFIMgJi 5tkg== X-Gm-Message-State: AOAM530z20hko9VThL2+Dq/JzsYzlQccX+yXlMt4TXIgEaMU70JgbxfL ANBYioZFlfXKTyta9zGlifaWAf2m3Q== X-Google-Smtp-Source: ABdhPJzvFP8+CJjGjT4Q/qSS+1OA0tDxp3n9hoCOklGx1Uk6TnaXfxtcDrpuAdqzcwZSqvV+uAeQtEL0Zg== X-Received: from tabba.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:482]) (user=tabba job=sendgmr) by 2002:a0c:fbcf:: with SMTP id n15mr9011967qvp.49.1630059370831; Fri, 27 Aug 2021 03:16:10 -0700 (PDT) Date: Fri, 27 Aug 2021 11:16:01 +0100 Message-Id: <20210827101609.2808181-1-tabba@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH v5 0/8] KVM: arm64: Fixed features for protected VMs 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, oupton@google.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-20210827_031613_217351_E4C2837C X-CRM114-Status: GOOD ( 22.52 ) 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 Hi, Changes since v4 [1]: - Calculating feature id register values takes into account features supported/enabled in KVM. - Handle all AArch64 feature ID registers, with sanitized copies at EL2 if necessary, rather than trusting the host, even if the value is the same. - Trap registers are set based on the exposed value of the feature id registers, rather than the masks to allow/restrict. - Move code for settings trap registers for protected guests to EL2. - Refactoring and fixes. - Dropped Will's ack for "KVM: arm64: Trap access to pVM restricted features" - Rebase on Marc's pkvm-fixed-features branch [2]. Changes since v3 [3]: - Redid calculating restricted values of feature register fields, ensuring that the code distinguishes between unsigned and (potentially in the future) signed fields (Will) - Refactoring and fixes (Drew, Will) - More documentation and comments (Oliver, Will) - Dropped patch "Restrict protected VM capabilities", since it should come with or after the user ABI series for pKVM (Will) - Carried Will's acks Changes since v2 [4]: - Both trapping and setting of feature id registers are toggled by an allowed features bitmap of the feature id registers (Will) - Documentation explaining the rationale behind allowed/blocked features (Drew) - Restrict protected VM features by checking and restricting VM capabilities - Misc small fixes and tidying up (mostly Will) - Remove dependency on Will's protected VM user ABI series [5] - Rebase on 5.14-rc2 - Carried Will's acks Changes since v1 [6]: - Restrict protected VM features based on an allowed features rather than rejected ones (Drew) - Add more background describing protected KVM to the cover letter (Alex) This patch series adds support for restricting CPU features for protected VMs in KVM (pKVM) [7]. Various VM feature configurations are allowed in KVM/arm64, each requiring specific handling logic to deal with traps, context-switching and potentially emulation. Achieving feature parity in pKVM therefore requires either elevating this logic to EL2 (and substantially increasing the TCB) or continuing to trust the host handlers at EL1. Since neither of these options are especially appealing, pKVM instead limits the CPU features exposed to a guest to a fixed configuration based on the underlying hardware and which can mostly be provided straightforwardly by EL2. This series approaches that by restricting CPU features exposed to protected guests. Features advertised through feature registers are limited, which pKVM enforces by trapping register accesses and instructions associated with these features. This series is based on 5.14-rc2. You can find the applied series here [8]. Cheers, /fuad [1] https://lore.kernel.org/kvmarm/20210817081134.2918285-1-tabba@google.com/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/pkvm-fixed-features [3] https://lore.kernel.org/kvmarm/20210719160346.609914-1-tabba@google.com/ [4] https://lore.kernel.org/kvmarm/20210615133950.693489-1-tabba@google.com/ [5] https://lore.kernel.org/kvmarm/20210603183347.1695-1-will@kernel.org/ [6] https://lore.kernel.org/kvmarm/20210608141141.997398-1-tabba@google.com/ [7] Once complete, protected KVM adds the ability to create protected VMs. These protected VMs are protected from the host Linux kernel (and from other VMs), where the host does not have access to guest memory,even if compromised. Normal (nVHE) guests can still be created and run in parallel with protected VMs. Their functionality should not be affected. For protected VMs, the host should not even have access to a protected guest's state or anything that would enable it to manipulate it (e.g., vcpu register context and el2 system registers); only hyp would have that access. If the host could access that state, then it might be able to get around the protection provided. Therefore, anything that is sensitive and that would require such access needs to happen at hyp, hence the code in nvhe running only at hyp. For more details about pKVM, please refer to Will's talk at KVM Forum 2020: https://mirrors.edge.kernel.org/pub/linux/kernel/people/will/slides/kvmforum-2020-edited.pdf https://www.youtube.com/watch?v=edqJSzsDRxk [8] https://android-kvm.googlesource.com/linux/+/refs/heads/tabba/el2_fixed_feature_v5 Fuad Tabba (8): KVM: arm64: Pass struct kvm to per-EC handlers KVM: arm64: Add missing field descriptor for MDCR_EL2 KVM: arm64: Simplify masking out MTE in feature id reg KVM: arm64: Add trap handlers for protected VMs KVM: arm64: Initialize trap registers for protected VMs KVM: arm64: Move sanitized copies of CPU features KVM: arm64: Trap access to pVM restricted features KVM: arm64: Handle protected guests at 32 bits arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_fixed_config.h | 164 +++++++ arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/include/asm/kvm_hyp.h | 5 + arch/arm64/kvm/arm.c | 13 + arch/arm64/kvm/hyp/include/hyp/switch.h | 16 +- arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 14 + arch/arm64/kvm/hyp/include/nvhe/sys_regs.h | 29 ++ arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 10 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 - arch/arm64/kvm/hyp/nvhe/pkvm.c | 186 ++++++++ arch/arm64/kvm/hyp/nvhe/switch.c | 59 ++- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 525 +++++++++++++++++++++ arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/sys_regs.c | 10 +- 17 files changed, 1020 insertions(+), 25 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_fixed_config.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/pkvm.h create mode 100644 arch/arm64/kvm/hyp/include/nvhe/sys_regs.h create mode 100644 arch/arm64/kvm/hyp/nvhe/pkvm.c create mode 100644 arch/arm64/kvm/hyp/nvhe/sys_regs.c base-commit: cc3ef75c796e58acec8f64a9acf47fc18645f194