From patchwork Tue Apr 19 06:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817539 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 C94EFC433F5 for ; Tue, 19 Apr 2022 07:21: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: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=lykmPrYpCebfQzHdpjz6HPfnhJrxPhRXzR9FEvgCksA=; b=t1js0jSRv1uL1aHMVEKpBJWwh7 lVmVF4gg+D7qTNrCrkZ9hdXQwkIQr5u4jAHeDfbZGsSjntP+UdVvmfB766GFlCUvFnaCjRwi/9vD0 P3hfAK3FC/gsqBbXF0WO0q9w6V+nLa3HPheG73Ct/ANBAOI2wmWEKGecK58XIJjWdx9L47FTJNT9z kCoVYd1hPGLHeaCqaG+ZOVG5CxoHrVPzvO0qSXXDFxflLjKhv+l1W6gPbt1onIwSKb/KgAtTSut+D HtHN64sdqHlbZu5biFSc/pnRWXaFjwbuXEQNMAXk8ePxEZl61OrGuFBVcNXcGBnf3tzHHnm74DioN Agg2PuHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngi9e-001vwe-1G; Tue, 19 Apr 2022 07:20:07 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghoD-001nkw-9B for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:57:59 +0000 Received: by mail-pj1-x1049.google.com with SMTP id r12-20020a17090a690c00b001cb9bce2284so10128802pjj.8 for ; Mon, 18 Apr 2022 23:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=YLQ/jtBXlP9biEBlw29VzMlxGtkHK85JhXdSg1Dey2k=; b=eAw4dTke4ES4lJseM7OQ6Z/1m7Omzg+78Rf0GXMt1GNKwDyp38SZ6TmEaeL41gIF3V O3W2n9UMmq+6M2Dlqx7kPsxjW9QwgcacCCvhksep5fJ2ps5tbZ4U6zJw0q2UO/Zml3ym 9BCmmDCprmbgGdLCXrZdHzt/XmNLdUXEBH4TBQs6gcdzLkC7ybe3KRk952sC/b6zHZSA iAvYXo/EGdqGvbO71ux5zx0vlb30A3xe8dM0BJSX6BxG1QZD+7b6D7VD8d30WtVdba9j P00CX0knXDaWtBD1id8WQ6fLIy/E99z+vOOTA5nnERYy6RpDQtJR1OgHZ37/lfhfTb+s RrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YLQ/jtBXlP9biEBlw29VzMlxGtkHK85JhXdSg1Dey2k=; b=pMbOZlZB++yECgWH9lPi3fNQuwzMyIuF4+Qh2RmEmOhM22aIOQmSBz+2cZk7CIFIbV 55Mt/PgirsuDYg5PGOSEjXxNH3vSzdtwkrMEsu1Qc4oMJ2fD5on7zjBr1qq0ra1FXbhw Jiw0YdlNbdqMi+u7Q9fVqXBB2E3Th0itXGUQ7EfWlQO++Z6Dqaq6XjpJF/zXK0qXITB6 kS7unwkkGUt/a33Yp7qnNu49ogRLEMjd1OHz6ofUBiiaWTugPdXfzRy7XuEwjJGRyAXx iwV2zV2W2cZF0Ezr9ORzoVZJ9JQspC3dLSQ6B6IqxaBWzjH2JdLpRxsNW5CWxkXVLWSj 2MkQ== X-Gm-Message-State: AOAM530yWKkAv0Zmrh5mbHGUOqioi8fA98XLqJfSuOBorZeAJGC9I1pr +thLhws4VR6yChwqjuJV8GvhEO6i1Y8= X-Google-Smtp-Source: ABdhPJwTql5uKFd/srdQQoG38aaRxnbuF6PS3EHwIAVgiky4Itg3RMnrRk+AFOPWQpN2BRiBLUohcU6eXZw= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90b:4b07:b0:1d1:8a08:5096 with SMTP id lx7-20020a17090b4b0700b001d18a085096mr16807088pjb.91.1650351475734; Mon, 18 Apr 2022 23:57:55 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:37 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-32-reijiw@google.com> Mime-Version: 1.0 References: <20220419065544.3616948-1-reijiw@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v7 31/38] KVM: arm64: Trap disabled features of ID_AA64ISAR1_EL1 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 , Fuad Tabba , 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-20220418_235757_417846_985DD422 X-CRM114-Status: GOOD ( 14.02 ) 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 Add feature_config_ctrl for PTRAUTH, which is indicated in ID_AA64ISAR1_EL1, to program configuration register to trap guest's using the feature when it is not exposed to the guest. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 6a8ed59d8d90..0e3cff91f41d 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -299,6 +299,15 @@ static bool trap_raz_wi(struct kvm_vcpu *vcpu, (cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR2_GPA3_SHIFT) >= \ ID_AA64ISAR2_GPA3_ARCHITECTED) +/* + * Return true if ptrauth needs to be trapped. + * (i.e. if ptrauth is supported on the host but not exposed to the guest) + */ +static bool vcpu_need_trap_ptrauth(struct kvm_vcpu *vcpu) +{ + return (system_has_full_ptr_auth() && !vcpu_has_ptrauth(vcpu)); +} + /* * Feature information to program configuration register to trap or disable * guest's using a feature when the feature is not exposed to the guest. @@ -394,6 +403,11 @@ static void feature_lor_trap_activate(struct kvm_vcpu *vcpu) feature_trap_activate(vcpu, VCPU_HCR_EL2, HCR_TLOR, 0); } +static void feature_ptrauth_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_HCR_EL2, 0, HCR_API | HCR_APK); +} + /* For ID_AA64PFR0_EL1 */ static struct feature_config_ctrl ftr_ctrl_ras = { .ftr_reg = SYS_ID_AA64PFR0_EL1, @@ -462,6 +476,12 @@ static struct feature_config_ctrl ftr_ctrl_lor = { .trap_activate = feature_lor_trap_activate, }; +/* For SYS_ID_AA64ISAR1_EL1 */ +static struct feature_config_ctrl ftr_ctrl_ptrauth = { + .ftr_need_trap = vcpu_need_trap_ptrauth, + .trap_activate = feature_ptrauth_trap_activate, +}; + #define __FTR_BITS(ftr_sign, ftr_type, bit_pos, safe) { \ .sign = ftr_sign, \ .type = ftr_type, \ @@ -4416,6 +4436,10 @@ static struct id_reg_desc id_aa64isar1_el1_desc = { U_FTR_BITS(FTR_EXACT, ID_AA64ISAR1_APA_SHIFT, 0), U_FTR_BITS(FTR_EXACT, ID_AA64ISAR1_API_SHIFT, 0), }, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_ptrauth, + NULL, + }, }; static struct id_reg_desc id_aa64isar2_el1_desc = {