From patchwork Wed Nov 3 06:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12600275 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD2EFC433EF for ; Wed, 3 Nov 2021 06:48:39 +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 87441610E5 for ; Wed, 3 Nov 2021 06:48:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87441610E5 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: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=yRcc3r2nofkwTAm0Y1L2efA3VcWNuDyoMIJjLYMABVs=; b=VFUVt89+BuQ+fIfBim+R6LD68l TBGfHh5L5ya4MxrxDSSzl+Q3VQMuJLVd0sSILBfhIeCXq70YJK/JcwVtzfSMQ/6kbVDHqZnNxZx3t RTlIOvN4bXxH38hqCCEX0M+sQqkP4pgKE+AeCmjpoEGsbGzpk35Rh70Q9WKrQEOGupvXV4hC8haCA +P6acABbJHzwb4HNFXDNEpyl4yd9vuRSPy85kMd7VnZ3S0dFbvcplSL1Qceb8D2XSctBJ/pZok/UW ZgLxL+JHL4/Qg5RV7rJXnVUwZ8hRkoZ5MwvOIV3MEEz4yOK7LWuErBy7MXOOhSSg4TtqoAqOWNm3y ayWI5yIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miA2X-004JYq-53; Wed, 03 Nov 2021 06:46:29 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mi9lH-004Cds-89 for linux-arm-kernel@lists.infradead.org; Wed, 03 Nov 2021 06:28:40 +0000 Received: by mail-pf1-x44a.google.com with SMTP id x25-20020aa79199000000b0044caf0d1ba8so858154pfa.1 for ; Tue, 02 Nov 2021 23:28:38 -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=Ep2NTeFQHRtb1x7tniQeG2pd+DzpIaqpLIGDyxGNaak=; b=fFT02gdqViWYrbCdTEQFZh2dd8gF3sRFDKawTgXYqjLI7nmc2vVWIHc5fQYX9NKzEd OrN0S2OhP0OEbUusgLIOJ24ho/2alYvcos4x7SolFhapIn6YxL0Q/VDzjpdSyamRXq5s RrMyR8gjtsL8vUcd0lgvbJ6rN2iAQkzAgkFYvLsnRwgoEAjFhXUV3qEsGRMH+1yMZEsW 29uITSD/EwfM2NeAOOpPDlb7zlKc6xEPzSf2xyfOc7+pQtJPKZvN+WxtlnnDnD9b2L8D LRn27uaxX+R+rYFbVrWjFF0aBcTVeCPiqJg9ZhuOt107MpCcOF6wgHso+ZYIQoYbVD/j HDkQ== 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=Ep2NTeFQHRtb1x7tniQeG2pd+DzpIaqpLIGDyxGNaak=; b=CeTXXARwit7eOPE4JWMSJpIT2Zxk5uYEoqSWyB1HXoJV+QCorBHDYZhWyOtxYeIImm 6bAMlVcvGvE2T3NfCi8Udets14mm4G88kD/cov2/i7U9ngdXZ+YwDWBugT79/0swaS0E gzSl/ydWryrOdGFUEIPD11w3ZqYtI7141OVpxTQ5XNcUz7jbClmhc+oG0CZAbv0c8c8E AxtWm/soOMyYms4Fo/4ZCfZdEiXeb65VJnEwT/U/XnfhtTsnNr/sNfQEi7dPXIiXiUOg QkqpWMrKchEQ5wXZvX2ZAKgtf7d7ACqVok1RuPjMH8Fzmij+h1QH5HpIpYONQrrDv2eo BDhw== X-Gm-Message-State: AOAM531pQeWnK5eHhV2svM9BSpug7XNs/RPI/Bg11OKzLD9fbeEMKKeN bEYobn0xCyXnwu/honC9lFZ0eYwOnhw= X-Google-Smtp-Source: ABdhPJxq8mVjnPJ20WpU44gAZn9NtxzZ4+sWrLWZuqNplD2biJyP84pZy1BiGUiTUN9ebm+egsfYYdatDyg= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:903:24c:b0:13f:2377:ef3a with SMTP id j12-20020a170903024c00b0013f2377ef3amr36514167plh.59.1635920917622; Tue, 02 Nov 2021 23:28:37 -0700 (PDT) Date: Tue, 2 Nov 2021 23:25:18 -0700 In-Reply-To: <20211103062520.1445832-1-reijiw@google.com> Message-Id: <20211103062520.1445832-27-reijiw@google.com> Mime-Version: 1.0 References: <20211103062520.1445832-1-reijiw@google.com> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [RFC PATCH v2 26/28] 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-20211102_232839_340478_6BBFBE75 X-CRM114-Status: GOOD ( 15.95 ) 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 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 2d2263abac90..fd38b3574864 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -374,6 +374,30 @@ static int arm64_check_features(u64 check_types, u64 val, u64 lim) (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 = __vcpu_sys_reg(vcpu, IDREG_SYS_IDX(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; +} + enum vcpu_config_reg { VCPU_HCR_EL2 = 1, VCPU_MDCR_EL2, @@ -478,6 +502,14 @@ static struct feature_config_ctrl ftr_ctrl_lor = { .cfg_val = HCR_TLOR, }; +/* For SYS_ID_AA64ISAR1_EL1 */ +static struct feature_config_ctrl ftr_ctrl_ptrauth = { + .ftr_need_trap = vcpu_need_trap_ptrauth, + .cfg_reg = VCPU_HCR_EL2, + .cfg_mask = (HCR_API | HCR_APK), + .cfg_val = 0, +}; + struct id_reg_info { u32 sys_reg; /* Register ID */ u64 sys_val; /* Sanitized system value */ @@ -953,6 +985,10 @@ static struct id_reg_info id_aa64isar1_el1_info = { .init = init_id_aa64isar1_el1_info, .validate = validate_id_aa64isar1_el1, .get_reset_val = get_reset_id_aa64isar1_el1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_ptrauth, + NULL, + }, }; static struct id_reg_info id_aa64mmfr0_el1_info = {