From patchwork Thu Jan 6 04:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12705127 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 32A30C433EF for ; Thu, 6 Jan 2022 04:46:34 +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=31ccJTWwXv3rjK/wse1W1XAAv8bbJvtyaZSMe5+5Fj0=; b=Nmm65PaSLsto60MEcBM4I3snjq Rkt4gB3B1SL0zjH9ruvNcL6w6ZArvCu32Cwj7ZnUY3yoxXUrH4H8+fXclzUkucDJEUYIl+yU64zGt 5WiTuYqBs0uJyIlOrqgpw3T9YHNbhUSkYZcXJHLvj4FCQS8Hm4c2s24x4qtl+W2hPoM1Kf4cusjat psLPBJfqAVUM+OYBTSDR49SqQaKURrLmMTu7QZ+IWJyR66+7RCk/25H8xyZpM86UXePdNz4BYYko2 u3kVJcEO7NuLEEsmLm/p+hhXVsm0MJgzkkcikZLlhTU7rJkAjQI7+2w0v1tC5QeWHP2NLZvJfpTt1 T8YUbNgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5Kds-00GY9P-T6; Thu, 06 Jan 2022 04:44:50 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5KOh-00GS6S-Ja for linux-arm-kernel@lists.infradead.org; Thu, 06 Jan 2022 04:29:09 +0000 Received: by mail-pg1-x549.google.com with SMTP id t18-20020a63dd12000000b00342725203b5so864984pgg.16 for ; Wed, 05 Jan 2022 20:29:06 -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=b5C+ulXk8DtiFV4JWD7KK9B/636Yn3BYdNq9V7se8IQ=; b=PjwCpBHP/IlWcYBXpvIsuDywh36YeiZC/7CnqpU98fCKw1F5N2wvJRLtoHAP9QkS5C n5/eEfsy3Xv8rOxDpQY6S4WGbteBxe4aB36WpHnCQKWmg3S88vB1pOgk2k3ur57OwRAE P0jHYQrmrp5PVY775P9xRzw6t2r4MXLM0WrV5YWHbOC6Y/BLxqnwTdVQ0Qs18SH6r18G frBoODBE/xAJ0M6PMSR64DM+nyddamS3h03/mO/72kIxeL0cCF5h/qMHitTkz5H6Sddp KifN4e1+JOQ0O0sDfHdrhYHUOTJFMmvO3Z6vPUMnGHwARDDCwzll55HGvBS1KhtAu4y9 18Dg== 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=b5C+ulXk8DtiFV4JWD7KK9B/636Yn3BYdNq9V7se8IQ=; b=Jot/9jmkQWD3IiaacuVaNIS0k4/MO9VasonhAu0Hwj1toEzYZKi4unYIoE7f5GCUmK bQMOHhERoc0HA50hW2cNKOSDH9B3G7zktGkXQc3tXFEPDXd3t2QsUz1zqaoovRBpb8PM ozBcP14hVhiGHPt8I7yQrscL5lxHZ7YwafJm0xUlv7AMObnoiXbQFe37IiZTYh2iszYo DEsAlENUqElNUptxfoUvaiFvP8Gpg8egYMSXzoxXZHkDzYFjDV40QOSSiALTbrP1AODZ 3elSLoFk1yAIayDeB1cM9gGXQ81yKofx2yOE4vwb6qYxgzCAr3SKaCR5K7RjKLB6lbcL mfhQ== X-Gm-Message-State: AOAM532Y+lSU7THD25pCq0tMAY/2dg5ajQBiG8Co2TnrDXLuFUcRgoQB fuXRxWH7L8VRA+cwNXJA04sbbjNTA/Y= X-Google-Smtp-Source: ABdhPJywQHVMdwWzXRNzQnbUj7l0gau6d2J6BL/vkouVUlOhhdSI1dpQp4sJkOWx/rCODBxotVyGj6bV4c4= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:902:ced2:b0:148:a3e6:b48d with SMTP id d18-20020a170902ced200b00148a3e6b48dmr56863089plg.103.1641443346010; Wed, 05 Jan 2022 20:29:06 -0800 (PST) Date: Wed, 5 Jan 2022 20:27:05 -0800 In-Reply-To: <20220106042708.2869332-1-reijiw@google.com> Message-Id: <20220106042708.2869332-24-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 23/26] KVM: arm64: Trap disabled features of ID_AA64MMFR1_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_202907_689752_B4A3E6B8 X-CRM114-Status: GOOD ( 14.77 ) 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 LORegions, which is indicated in ID_AA64MMFR1_EL1, to program configuration register to trap guest's using the feature when it is not exposed to the guest. Change trap_loregion() to use vcpu_feature_is_available() to simplify checking of the feature's availability. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 229671ec3abd..f8a5ee927ecf 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -365,6 +365,11 @@ static void feature_tracefilt_trap_activate(struct kvm_vcpu *vcpu) feature_trap_activate(vcpu, VCPU_MDCR_EL2, MDCR_EL2_TTRF, 0); } +static void feature_lor_trap_activate(struct kvm_vcpu *vcpu) +{ + feature_trap_activate(vcpu, VCPU_HCR_EL2, HCR_TLOR, 0); +} + /* For ID_AA64PFR0_EL1 */ static struct feature_config_ctrl ftr_ctrl_ras = { .ftr_reg = SYS_ID_AA64PFR0_EL1, @@ -416,6 +421,15 @@ static struct feature_config_ctrl ftr_ctrl_tracefilt = { .trap_activate = feature_tracefilt_trap_activate, }; +/* For ID_AA64MMFR1_EL1 */ +static struct feature_config_ctrl ftr_ctrl_lor = { + .ftr_reg = SYS_ID_AA64MMFR1_EL1, + .ftr_shift = ID_AA64MMFR1_LOR_SHIFT, + .ftr_min = 1, + .ftr_signed = FTR_UNSIGNED, + .trap_activate = feature_lor_trap_activate, +}; + struct id_reg_info { u32 sys_reg; /* Register ID */ u64 sys_val; /* Sanitized system value */ @@ -947,6 +961,14 @@ static struct id_reg_info id_aa64dfr0_el1_info = { }, }; +static struct id_reg_info id_aa64mmfr1_el1_info = { + .sys_reg = SYS_ID_AA64MMFR1_EL1, + .trap_features = &(const struct feature_config_ctrl *[]) { + &ftr_ctrl_lor, + NULL, + }, +}; + static struct id_reg_info id_dfr0_el1_info = { .sys_reg = SYS_ID_DFR0_EL1, .init = init_id_dfr0_el1_info, @@ -976,6 +998,7 @@ static struct id_reg_info *id_reg_info_table[KVM_ARM_ID_REG_MAX_NUM] = { [IDREG_IDX(SYS_ID_AA64ISAR0_EL1)] = &id_aa64isar0_el1_info, [IDREG_IDX(SYS_ID_AA64ISAR1_EL1)] = &id_aa64isar1_el1_info, [IDREG_IDX(SYS_ID_AA64MMFR0_EL1)] = &id_aa64mmfr0_el1_info, + [IDREG_IDX(SYS_ID_AA64MMFR1_EL1)] = &id_aa64mmfr1_el1_info, }; static int validate_id_reg(struct kvm_vcpu *vcpu, u32 id, u64 val) @@ -1050,10 +1073,9 @@ static bool trap_loregion(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - u64 val = __read_id_reg(vcpu, SYS_ID_AA64MMFR1_EL1); u32 sr = reg_to_encoding(r); - if (!(val & (0xfUL << ID_AA64MMFR1_LOR_SHIFT))) { + if (!vcpu_feature_is_available(vcpu, &ftr_ctrl_lor)) { kvm_inject_undefined(vcpu); return false; }