From patchwork Mon Jun 10 06:32:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= X-Patchwork-Id: 13691557 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 BD328C27C5F for ; Mon, 10 Jun 2024 06:33:24 +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=SqS5LMQpz7m+cAOPtE9Vin7FBbY8/pjQeqrGxwazCrk=; b=tcU P4xY59ssDiWUF291Uf+HMZYPF2xRgTmwnYGYDJDzH1PdqT8wmDnt5nKLtT3GUTiWhLAZgDNW5GrO9 SR4SvJ9CHeuPJJXqbi3Y8HkI/ULLsZTudBqsHVenVuh1sGYpEniNxR5OWpI4R7RcfhF2u+M4OkPLA oP/noOek1llkGa8l8XAnz3TONQcdvecy1txGqDkW3XCSNmwn401hiBqTWwE5VIogPAWx+BLPpwYM9 0cUbpKLafZuotBUyChuw2PBjYc471CpVTgPu+Tz8aoxYfTw3ag2QB1Ec/tnkHxahEL7XcJpNp3tO8 nMIOW6g7TTMG4hqvggXRBaFr2kb9oVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGYab-00000003zBh-3oV0; Mon, 10 Jun 2024 06:33:09 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGYaY-00000003zAa-2qAf for linux-arm-kernel@lists.infradead.org; Mon, 10 Jun 2024 06:33:08 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-629f8a92145so67282127b3.0 for ; Sun, 09 Jun 2024 23:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718001181; x=1718605981; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=SV3VpUvUuZUDCnIEJtnyIJokYqwm61smGNoJPs2Ev1g=; b=iEvK8NPo4s9XoxxVcmrXYF5GLa7cav1/CUBXbAvSz1NrojYbsP5rWFAZL9SqizHf1I QiZUmjjldW/01FfPTCrr18x1LLD0+u1zzPKeVmV0yYxisbDDZLXpfhgUW5LlDbD9U/xY RDPZDWUfFVBFKs4rVNKaAq8rKVchSOYYJa42sUeNkEphI1b8Cxz0z9RDLDPNmpwkN09t CQ6dPD0BZtYBR+elXRWWCL/XvY+rseb1cbocg+E54Vvkk4WZWn9MDAtgygvY07qQYWbc f4Z6jj+q4CiAdzSKeFab2OI/XKqy7uY2wLjEuDHTjQlvOTPy+otF9NXg3M11nrcUbu4y 0Y/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718001181; x=1718605981; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SV3VpUvUuZUDCnIEJtnyIJokYqwm61smGNoJPs2Ev1g=; b=FHlqHuRtlc96RPXDvluqPDQ7UmzxgSDdB2xXNDmkCw9emXvIOiEVRoWcNSSWhqztpF sF5SM724jmdt1xFkKo/kAnwPv1BH+Jx4WPYi/HvqxKKPUmUMcJXpDCHKUBZ/FjXZlWcO PZbN9bBTATKninmAyuQQL5I3HTcBndeaCdBthUt372ZuUV2hK03wJyerhekZhp8a/VJU gV54/S/vUxdFGx0Qc8gp5DrulaA4h4YD87SkspUzlnExfsCbhSGJiyyD9EqCWC//2amE 8X3n/4eIRG1BV8Nav+vrluERVidCZpaONM5w5s5zKpzq8AO8zBR5gsJNN9PpsmnxZwsZ fBcA== X-Forwarded-Encrypted: i=1; AJvYcCUFkmhHGLgo6OR2J7701mCYnaaE7yChqEbvdxCGTIPhHyWJulus3rNR541Ws4ghxubgU4EdLAOwBhOzWEbVjMiI94Lei552Mn6Aqf0ZqtPzHDdwQk4= X-Gm-Message-State: AOJu0YzK6NqJSuPL/zY295ilSBqvMlu4ka4qo9c7pSvJdh5OekTJw3ph QSPrtIw9K1kMeGKagmjSGcWqrSqSspINlW81cfjR6aFVnrE8WFXBwp+Oyu+iy3NtYd/FxMNrNA= = X-Google-Smtp-Source: AGHT+IE7ukTgtkKT05jf5+K94IJiuvYTmDsAiB90Z4RAIq7icQqVtEUXErqkuzjcjiRo2zRoJ8jUu5/EZw== X-Received: from ptosi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:11ec]) (user=ptosi job=sendgmr) by 2002:a05:6902:10c3:b0:dfb:1c1c:ac11 with SMTP id 3f1490d57ef6-dfb1c1cb10emr174664276.13.1718001181056; Sun, 09 Jun 2024 23:33:01 -0700 (PDT) Date: Mon, 10 Jun 2024 07:32:29 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240610063244.2828978-1-ptosi@google.com> Subject: [PATCH v5 0/8] KVM: arm64: Add support for hypervisor kCFI From: " =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= " To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: " =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= " , Will Deacon , Marc Zyngier , Oliver Upton , Suzuki K Poulose , Vincent Donnefort X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240609_233306_779102_02AD206A X-CRM114-Status: GOOD ( 14.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 CONFIG_CFI_CLANG ("kernel Control Flow Integrity") makes the compiler inject runtime type checks before any indirect function call. On AArch64, it generates a BRK instruction to be executed on type mismatch and encodes the indices of the registers holding the branch target and expected type in the immediate of the instruction. As a result, a synchronous exception gets triggered on kCFI failure and the fault handler can retrieve the immediate (and indices) from ESR_ELx. This feature has been supported at EL1 ("host") since it was introduced by b26e484b8bb3 ("arm64: Add CFI error handling"), where cfi_handler() decodes ESR_EL1, giving informative panic messages such as [ 21.885179] CFI failure at lkdtm_indirect_call+0x2c/0x44 [lkdtm] (target: lkdtm_increment_int+0x0/0x1c [lkdtm]; expected type: 0x7e0c52a) [ 21.886593] Internal error: Oops - CFI: 0 [#1] PREEMPT SMP However, it is not supported at EL2 in nVHE (or pKVM), as CONFIG_CFI_CLANG gets filtered out at build time, preventing the compiler from injecting the checks. To address this, - [1/8] fixes an existing bug where the ELR_EL2 was getting clobbered on synchronous exceptions, causing the wrong "PC" to be reported by nvhe_hyp_panic_handler() or __hyp_call_panic(). This is particularly limiting for kCFI, as it would mask the location of the failed type check. - [2/8] fixes a minor C/asm ABI mismatch which would trigger a kCFI failure - [3/8]-[7/8] prepare nVHE for CONFIG_CFI_CLANG and [8/8] enables it Note that kCFI errors remain fatal at EL2, even when CONFIG_CFI_PERMISSIVE=y. Changes in v5 (addressed Will's comments on v4): - Dropped the patch making the handlers report the kCFI target & expected type - Dropped the hypervisor kCFI test module - Dropped the patch introducing handler for EL2h sync exceptions - Dropped the patch renaming __guest_exit_panic - Made invalid_host_el2_vect branch unconditionally to hyp_panic - Changed SP type in __pkvm_init_switch_pgd signature to unsigned long - Changed which registers __pkvm_init_switch_pgd used for intermediates - Fixed typo in commit message about esr_brk_comment() - Fixed mistake in commit message about context of invalid_host_el2_vect Pierre-Clément Tosi (8): KVM: arm64: Fix clobbered ELR in sync abort/SError KVM: arm64: Fix __pkvm_init_switch_pgd call ABI KVM: arm64: nVHE: Simplify invalid_host_el2_vect KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32 KVM: arm64: VHE: Mark __hyp_call_panic __noreturn arm64: Introduce esr_brk_comment, esr_is_cfi_brk KVM: arm64: Introduce print_nvhe_hyp_panic helper KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2 arch/arm64/include/asm/esr.h | 11 +++++++++ arch/arm64/include/asm/kvm_hyp.h | 4 ++-- arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kernel/debug-monitors.c | 4 +--- arch/arm64/kernel/traps.c | 8 +++---- arch/arm64/kvm/handle_exit.c | 24 +++++++++++++++----- arch/arm64/kvm/hyp/entry.S | 8 +++++++ arch/arm64/kvm/hyp/include/hyp/switch.h | 5 +++-- arch/arm64/kvm/hyp/nvhe/Makefile | 6 ++--- arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 6 +++++ arch/arm64/kvm/hyp/nvhe/host.S | 6 ----- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 30 +++++++++++++++---------- arch/arm64/kvm/hyp/nvhe/setup.c | 4 ++-- arch/arm64/kvm/hyp/vhe/switch.c | 3 +-- 14 files changed, 78 insertions(+), 42 deletions(-)