From patchwork Thu Jan 6 04:27:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12705128 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 55DF5C433EF for ; Thu, 6 Jan 2022 04:47:15 +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=U46lWHvHLpb/jz8Lz/E6M77E8MZ+z7EalHLwA0RUgF4=; b=izbWcTaDP9C/rFMZsH+seuv/gR LdcR0x6nH11CrGvKTYuOA4hMWj/9vBoAQxo46HPbhPwgfF9qjWZbhuuL54z3k+0Hml7zo4hXdA4VJ aiJOe/q985fNYtY5vxzX5kmHUQzGsuak+43r9hEPT3NrqqMQqNROG1yrsrktLfkg3ESbGa90SngCp sBka1cMkixlqf42LKfS8jSnYgG0KIgMpeONSu9dqm7UcRBSTZGRJGoh0r31SWEXEulEi04cF/YBAA QAImAo6hc7jbCB1H1zIZXLYD22YZ82wIJJM2xQcEIjR9gRCuaXgvILE9kBVALqDlhWYcfoTuDCDlw kOQ7ym9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5Ker-00GYXR-NC; Thu, 06 Jan 2022 04:45:50 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5KOi-00GS7e-Re for linux-arm-kernel@lists.infradead.org; Thu, 06 Jan 2022 04:29:10 +0000 Received: by mail-pf1-x449.google.com with SMTP id i25-20020aa796f9000000b004bcc8372c41so949051pfq.4 for ; Wed, 05 Jan 2022 20:29:08 -0800 (PST) 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=iwXsEGXlRtnuTPyM/ryhBa4F3YbG0RREAYmK8S1ALak=; b=DY7bN9c02WCcBIqylRNzAa/UKrlEqTdIPajSGSeXyRQpP4wggxu1ISZyO1v/ZGCngz 0+SHEjeqZI0uX9Pn9pJNUV/x2ZrbEsfDttbMPqFG8ERSn7RGb5ii2aWKxB3U8XO75UBv tvRqTOb4xqxIsB3EQYD9ljD0jWpW9K06TOuMoRa8oQDAF82bHN99MvgfdsXb0QfvWOYq OPi9gKx+MXSGxbTsuWmqPuzZs4raKY1OXhB+1KA0SIy2U5CtMqK0JDsdDRVzU+30vBl5 /VAuQTw0SVFGp4LMQyKyeupT1SQyNAXo0IK0uLxm6N1mtzWuttt3UQlfmknM8c67y9p3 Ts9w== 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=iwXsEGXlRtnuTPyM/ryhBa4F3YbG0RREAYmK8S1ALak=; b=dO0KHeD5Jwqq4ofBAkMpwvZSMpK6hcEEabxP8ZVdWK6H0HqhL5kfYbvx0ZpV81W4zt 09hTug6FRfGI8kXY2g/PZ3Vy4pbfukeo2GqLnbfKIJ1w0H2twMUTuZMafnHNtLJ1vPEh EVDZCN8dslRZZF8JYIl53zZ3G9jhTLWdr5wolZijKTqTsOlRycpV+A+8QXZp7RY49pX/ Ryp5TMtjcP/r/RPPHIfV2T8pQBOWrzMZD2uuYI7Ec74myqXy5aUv6l5qr0S8jAjZcP7N R9AFLooCQYe1YkRiYatOxcz6kZ8P+7qMbG8EgwYOPSDvEWRMHAgQ7ZUmXcknYG8KsEIU MRog== X-Gm-Message-State: AOAM533L1R7O4OozXGYVs2h+vPweIzzO8RMmh8K9DewHlXWfIu8pq7CN MfrSMV50VGaRtvP/dj/A+xHxtFhFW2s= X-Google-Smtp-Source: ABdhPJz9xkqu05Zv3mJ6ciKxZhfGOKGvAVLc21cuH1LPUGn8hbmqRWcz+0GsoulJ4ERK1227XDG5qggDLy8= 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:2311:: with SMTP id mt17mr4608281pjb.203.1641443347686; Wed, 05 Jan 2022 20:29:07 -0800 (PST) Date: Wed, 5 Jan 2022 20:27:06 -0800 In-Reply-To: <20220106042708.2869332-1-reijiw@google.com> Message-Id: <20220106042708.2869332-25-reijiw@google.com> Mime-Version: 1.0 References: <20220106042708.2869332-1-reijiw@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [RFC PATCH v4 24/26] 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 , 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-20220105_202908_977454_D877EE97 X-CRM114-Status: GOOD ( 16.03 ) 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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index f8a5ee927ecf..e6ef76f9b563 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -283,6 +283,30 @@ static bool trap_raz_wi(struct kvm_vcpu *vcpu, (cpuid_feature_extract_unsigned_field(val, ID_AA64ISAR1_GPI_SHIFT) >= \ ID_AA64ISAR1_GPI_IMP_DEF) +/* + * 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) +{ + u64 val; + bool generic, address; + + if (!system_has_full_ptr_auth()) + /* The feature is not supported. */ + return false; + + val = __read_id_reg(vcpu, SYS_ID_AA64ISAR1_EL1); + generic = aa64isar1_has_gpi(val) || aa64isar1_has_gpa(val); + address = aa64isar1_has_api(val) || aa64isar1_has_apa(val); + if (generic && address) + /* The feature is available. */ + return false; + + /* The feature is supported but hidden. */ + return true; +} + /* * Feature information to program configuration register to trap or disable * guest's using a feature when the feature is not exposed to the guest. @@ -370,6 +394,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, @@ -430,6 +459,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, +}; + struct id_reg_info { u32 sys_reg; /* Register ID */ u64 sys_val; /* Sanitized system value */ @@ -932,6 +967,10 @@ static struct id_reg_info id_aa64isar1_el1_info = { .init = init_id_aa64isar1_el1_info, .validate = validate_id_aa64isar1_el1, .vcpu_mask = vcpu_mask_id_aa64isar1_el1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_ptrauth, + NULL, + }, }; static struct id_reg_info id_aa64mmfr0_el1_info = {