From patchwork Mon Feb 14 06:57:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12745069 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 7CB17C433EF for ; Mon, 14 Feb 2022 07:21:11 +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=IgZwOzFA0eD1dG0BDbCzhs+wlCa1bSyl+dTv0Ti0H20=; b=TejFLw52AWOuzPtpsnQePUHzVs Z4UoTN0JwK8Hitp4I3YIrBxxut/5aXHl2EPaiURGXocxfFt0USWA21tXhATxA1x4xcBBNBVP3ATiK /dmAeJhdU8yccZielPiq9UkVaW2CmTr+SyiRHtmDW25O3qwZFdsqjxYbumrywTedYPe01JqD23BX7 6v8BKyNalRW1/4QNSUq83zihIvEWF8XD8Ji7uVWYLg6Ymp9Mruwl5kSZIzHdTkKrRIIfI7QYbEd5a L6yJ/Zn3IiGDVqVj7mkpHkByPDIT/JIB8HjRZ5U5vVRGw+bqFKZrl/dmqNNfbIs+1ysiXXmd8gXdt UXTBwqpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVe6-00Dekq-Dd; Mon, 14 Feb 2022 07:19:39 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJVMq-00DXi4-Ih for linux-arm-kernel@lists.infradead.org; Mon, 14 Feb 2022 07:01:50 +0000 Received: by mail-pl1-x64a.google.com with SMTP id u4-20020a170902a60400b0014dca32c59eso5756810plq.9 for ; Sun, 13 Feb 2022 23:01:47 -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=l5XORbNWq/eRBF/KP+e0aDCNzGukLV10hjBR4KXniUs=; b=MJufiVJHKSyIus/sFhnoRwe2+keKwVB9kk5MzqrsJ7id6EZNMC30IKykXiNLgdTTsU VEMC26J4nsTGlzC1/XFzD+0AENUijjmcQSoMhoylRxg1CvenHLuPuZlRr7OLrHqWJzRa fvVE6sPk2yZWUhkJNd4jo5SZdek+ZjFGE8Lezs/exgfghLy7DZ1lKrblwCawnKK1oyoI RW3JtZZ9/0HQy9zbN4q1n5dcbiV0g1q9cKMrVesvzox6k0BUfqXyK/8U+zMu2pCEr/Bl pEQtrdCftz8Tl1R2z1vD79cXtgZk6KA2BcyV4qkFNaaOwqu97A8KasmUHI1X4QULMsbd 7Jog== 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=l5XORbNWq/eRBF/KP+e0aDCNzGukLV10hjBR4KXniUs=; b=j8GjG10ig12hfRdWuf7CncgecdgDx0uNryj+PRqRfWWkvn8Bp4kLPOpvYSdWJkQUbn yWSHeKh9oN8oAFRTrLnfkw6MiISX9N4BSJUfix7A5v9SUf2Glfrh4GKnNnHXvMyD41e3 KmkjW0inbqv0tySWUzXyNTJpUXXFG0MA1rJ9Mv9CueqRqNb98vUUOa0rLC1Ku3GCYE0k vbbjOvUhrzMKRVqebTXho59vmiWrUpYMU/K/yMmGjhVvV+ndCises/ayPAQfZOUmItgB 72tRf400MZ+NaIL8AyTUOAon0bGuGSi4UUTFDgDgUEtF6IDwKqNYozHMDaoO8SyF7AGl MfVg== X-Gm-Message-State: AOAM532TGrwq3rfi50JfFWUCE8sYTnIHCHyrEBvgPN8c3KDQivqDUXG2 SLl/MJuym8UbIYR6TrjjY6uHdvfjzQ8= X-Google-Smtp-Source: ABdhPJwJkw68YJr5to3yBrgNhXZsf8uxRX0mR+fW+ct2ISB7LByn8kkySbfysY2JTpFORc7JKGvY52yitHY= 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:4c8e:: with SMTP id my14mr1640945pjb.0.1644822106646; Sun, 13 Feb 2022 23:01:46 -0800 (PST) Date: Sun, 13 Feb 2022 22:57:44 -0800 In-Reply-To: <20220214065746.1230608-1-reijiw@google.com> Message-Id: <20220214065746.1230608-26-reijiw@google.com> Mime-Version: 1.0 References: <20220214065746.1230608-1-reijiw@google.com> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH v5 25/27] 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-20220213_230148_660988_20701F25 X-CRM114-Status: GOOD ( 14.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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 205670a7d7c5..562f9b28767a 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. @@ -378,6 +402,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, @@ -446,6 +475,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 { /* Register ID */ u32 sys_reg; @@ -986,6 +1021,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 = {