From patchwork Thu Dec 14 10:01:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13492684 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 9CE2AC4332F for ; Thu, 14 Dec 2023 10:02:41 +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:Message-ID: Mime-Version: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=RfexuppoqK5Sqv4/Jx+jiQzYn63I1Ii6H7cIZ2WoM48=; b=juo UAugWn9b1qG04YHtZLSvBo3alUYF8DrjsCd64HwQJn1DWvLbrsVYKoY5JKg4Alii/6r2EmVa/cBUW EOcIBpzhvYeLCmsVVEB8tTv7wwv2MgMt0PjkkrOjV+VKOXEvPXIOrm8zar5Apih7GZaiykQ0YN/TD zMNXg+MHoYNJ+G1WzcyhrdTtVpn5aM+nDvRtLzVgB25L1gU4WqCg88CMvsrVL+CXAEZlLVBu3rqsX QitQfF2V/gdD25r2dSDZun2gw7veaG9yoyzluYa/f501AwspO/G8QYdOGnZiPwYw/kKPD2Nnc9819 gqX0aXcpyrr3n3idnc8piXfc5enPOuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDiXf-00HOpx-0G; Thu, 14 Dec 2023 10:02:07 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rDiXc-00HOol-0m for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 10:02:06 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db410931c23so8388096276.2 for ; Thu, 14 Dec 2023 02:02:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702548120; x=1703152920; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jcmoOfTfuAZe0H48BAZSQKy3c0OXKN12bT3q7fYzvao=; b=a0S3VpqOWiW9ysNDn4Rj823uFxysiSc0XUkpfRaxM3KWBIQgd4fJOsgL02Ze7BC3JQ 9gJiyQYqaXWMTYDqiNyN1HlmqmxFME+7YtV/Ydys+Gsn/8qwvZXh8l7I2knWbJzj0iDP tpIwixVAJEMgf7bIgjv24GskOjXexpygxT2m248uM/NLWzKTKWd/5aHR50TIjskQvQMI P8w8COyWvr+GZWc4V0icl/zFsD8eW+Bdg9vJP2zbNPQaBoqvYs/1lhmPcGqU7OGMA9Qz PHuWxVS4a2fOkMXQiVzP1aUWGBUF1THa7As7iPKEyl77qds97PIIICC9hhK2ncpL+sHy p1nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702548120; x=1703152920; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jcmoOfTfuAZe0H48BAZSQKy3c0OXKN12bT3q7fYzvao=; b=O/3fiB6kIWHrZzjTA9Wq0gu7bfWTMjtzvcEEzVHLBSTa/nFGsoPDGHLaSMOtS2yAG/ q13Jqn2c6kWrxkj5EIb1DslrWgkBsc8FNZWb60ck4Tn4Z7L9W7kMCQnlaNC91zC0e1Ba J7DTT6EJbTubRd5Q4V1pcjPjDe9sNsehE5im+esXFhx2Ow7y7nttxRfG3VpWDH4Qg0ll fgaG70YsYafeEJ9g1XErkV2xh9C1sBXI46aw1+XsKkztvWhkZ+NcGWLyfncBnFZSFvje wqe/6uBhRlTTlstWjsUUOnLTWWIjhVSh/SQDjZYfOHIF124dT48RvPK5mNtkW1sc+85a 47wQ== X-Gm-Message-State: AOJu0YxqwXRp415N14Jweqg9XC8wOZdNjhJefOyIryUWhBtH4EWwmAoT 3cw1kUzXj/vyKXfFuizLV4Bo6vY5PA== X-Google-Smtp-Source: AGHT+IHa7ZGIfNRAiqR5mQm9iMrynhdS+L689UnGmzl+oKTX6+S84bpG0jYLqqqsBtLwgJhUvmIEHp0/bQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:534:b0:db5:41e9:aa1c with SMTP id y20-20020a056902053400b00db541e9aa1cmr74689ybs.11.1702548120127; Thu, 14 Dec 2023 02:02:00 -0800 (PST) Date: Thu, 14 Dec 2023 10:01:40 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231214100158.2305400-1-tabba@google.com> Subject: [PATCH v3 00/17] KVM: arm64: Fixes to fine grain traps and pKVM traps From: Fuad Tabba To: kvmarm@lists.linux.dev Cc: maz@kernel.org, oliver.upton@linux.dev, broonie@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, eric.auger@redhat.com, jingzhangos@google.com, joey.gouly@arm.com, tabba@google.com, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231214_020204_320672_2B7312B0 X-CRM114-Status: GOOD ( 13.37 ) 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 Changes from v2: - Rebased on arm64/for-next/sysregs, which includes new system register definitions (Mark, Joey) - Explicitly trap unsupported HFGxTR_EL2 features rather than relying on its nMASK (Joey) - Add new system registers to the auto-generated sysreg rather than hardcoding them (Mark) - Drop patch that was meant as RFC - Added missing system registers, fields, and system instructions - Split patches that make system register changes - Fixes to patches defining allowed features for protected VMs - Other minor fixes and tidying up Changes from v1: - Handle HAFGRTR_EL2 in nested virt - Update the nested virt FGT tables with the added trap bits (Marc) - Use the generated value for RES0 (Marc) - Calculate the value of NMASK based on RES0 and MASK This patch series has fixes, updates, and code for validating fine grain trap register masks, as well as some fixes to feature trapping in pKVM. New fine grain trap (FGT) bits have been defined in the latest Arm Architecture System Registers xml specification (DDI0601 and DDI0602 2023-09) [1], so the code is updated to reflect them. Moreover, some of the already-defined masks overlap with RES0, which this series fixes. It also adds FGT register masks that weren't defined earlier, handling of HAFGRTR_EL2 in nested virt, as well as build time validation that the bits of the various masks are all accounted for and without overlap. Based on arm64/for-next/sysregs (e94e06d8a796), which is composed of system register updates [2] and is based on Linux 6.7-rc3. Cheers, /fuad [1] https://developer.arm.com/downloads/-/exploration-tools [2] https://lore.kernel.org/all/20231209-b4-arm64-sysreg-additions-v1-0-45284e538474@kernel.org/ Fuad Tabba (17): arm64/sysreg: Add missing Pauth_LR field definitions to ID_AA64ISAR1_EL1 arm64/sysreg: Add missing ExtTrcBuff field definition to ID_AA64DFR0_EL1 arm64/sysreg: Add missing system register definitions for FGT arm64/sysreg: Add missing system instruction definitions for FGT KVM: arm64: Explicitly trap unsupported HFGxTR_EL2 features KVM: arm64: Add missing HFGxTR_EL2 FGT entries to nested virt KVM: arm64: Add missing HFGITR_EL2 FGT entries to nested virt KVM: arm64: Add bit masks for HAFGRTR_EL2 KVM: arm64: Handle HAFGRTR_EL2 trapping in nested virt KVM: arm64: Update and fix FGT register masks KVM: arm64: Add build validation for FGT trap mask values KVM: arm64: Use generated FGT RES0 bits instead of specifying them KVM: arm64: Define FGT nMASK bits relative to other fields KVM: arm64: Macros for setting/clearing FGT bits KVM: arm64: Fix which features are marked as allowed for protected VMs KVM: arm64: Mark PAuth as a restricted feature for protected VMs KVM: arm64: Trap external trace for protected VMs arch/arm64/include/asm/kvm_arm.h | 61 +++++++++------ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/sysreg.h | 7 ++ arch/arm64/kvm/emulate-nested.c | 63 +++++++++++++++ arch/arm64/kvm/hyp/include/hyp/switch.h | 77 +++++++++++-------- .../arm64/kvm/hyp/include/nvhe/fixed_config.h | 22 +++++- arch/arm64/kvm/hyp/nvhe/pkvm.c | 4 + arch/arm64/kvm/sys_regs.c | 1 + arch/arm64/tools/sysreg | 50 +++++++++++- 9 files changed, 225 insertions(+), 61 deletions(-) base-commit: e94e06d8a7960fd840ea92021ca1bf1362ea67f8