From patchwork Tue Apr 19 06:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12817493 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 4F003C433FE for ; Tue, 19 Apr 2022 06:58:53 +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=IoRxG6K33LmDPSvaiOb+ArvCXzV5ajXhp+FWbG9odt8=; b=qjRyb0WhQOr67mJoJnQXEt8rLE Px/v/0qspiR9k0i/+M03hscj/itKlBnuyJ51D94t+OQhLjzEC6QCWOk2vhuZBj/Lu5vcr6pUI2gdy kwjgZmT/hJb3G4knBnC0C+vBmMV2Peu8DwzQzvYgy+E00djADLuJO1LKmR1R0L3aHGkU7YWJ2BpPk VEg3cb8R/yGPFnKEwxtwAgPQcAadQUKeOvzqVHPdbMayzy/knVtzBboyQYlayIImRff6bBtFgZT0Z R7CPa2TxfaIrAHTOSFZxPtGF02JJ39xbiPY30oAXQJfAlmtG/0SXINwk8aTQFVCrmWZSz2wW9ZVit Zq7QY97w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghny-001nbS-5V; Tue, 19 Apr 2022 06:57:42 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nghnV-001nM9-ME for linux-arm-kernel@lists.infradead.org; Tue, 19 Apr 2022 06:57:15 +0000 Received: by mail-pl1-x649.google.com with SMTP id y12-20020a17090322cc00b001590b19fb1fso2166165plg.16 for ; Mon, 18 Apr 2022 23:57:12 -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=VJImZSIZ+gG1OFTvYyrxAjCUBTqUqO7tRcl+ZvmmrQU=; b=fY034672N11uX9UN7COg34VjlKUqAo7dFya/wOHPBEs1jzO5xKlaqEmIenpptQfc3Z UO7slba7gfWUWNvpAFkm02q8WMmVD74ZeN9mCnYt2u2qXBaNDY4yoKJ/OuV+Z3lqdmmz W278iSjt45hIPJ+VKUtTyZeNHoo6fojiDaHX4KiwL8XTeN7iX5Gc8A/VbEX/dtjLYPWh ToYtzkMaDBmaPztTc/CagS+36DIDmgQw3Pry0pzFNvmBUmLwIjP/b6OljEat0qNHn/Qe uQMzg7jaZcRaQlvLVne9u6lapGzQYrEkbFM1BUCEeNf2SItPlzY0vnkCiPTUt9nqpRf2 xpig== 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=VJImZSIZ+gG1OFTvYyrxAjCUBTqUqO7tRcl+ZvmmrQU=; b=BOTkyZs1EMC5iIHeO5SAWy3ZysUbQQPwyeVbfzlnLFxlnl8gQEJrD7FDUwH1OJiPYQ Qgj+DkgTOiGFefXwANkdIi8Qhjf2Amul2rTkEqPzkUA5yaXoHzQgYWoVkqIzzf/tZIqZ bqwH71LLVvFSYJs4dMgkphQiajFvHJklovEW+tkoOuCkdvqhHFqEvmubynma5n07MY/S 08nUra3TY8pCVGB+/xdIWzBPQg8cBPP0xjudFaWCN2l9wdIl0EsfjpVn4Afoua70OzfQ Nh1YfM5q2NigYyfxjzO4IS7k1c/wV160i2RsxHttlK+vnod40pDH9hRDeTRCWNROHL+C 24Wg== X-Gm-Message-State: AOAM5339WAzjE6Ggo7ceTpnnOFEH6L8C4ouKdKZVfK6sD1CX5Lixnp63 lAjS82wLYnyn3FQWzUJ0+UBTILRUmCs= X-Google-Smtp-Source: ABdhPJwcF9IGP+oXjWqN513CFHPTbOhEPIcFqBvtuNUAEogsKCaN3cLS4dsvrgirt3TnfNpD+Muf6CEieGo= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a05:6a00:10d0:b0:4f7:5af4:47b6 with SMTP id d16-20020a056a0010d000b004f75af447b6mr16187254pfu.6.1650351431964; Mon, 18 Apr 2022 23:57:11 -0700 (PDT) Date: Mon, 18 Apr 2022 23:55:10 -0700 In-Reply-To: <20220419065544.3616948-1-reijiw@google.com> Message-Id: <20220419065544.3616948-5-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 04/38] KVM: arm64: Generate id_reg_desc's ftr_bits at KVM init when needed 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_235713_793116_C445E2C6 X-CRM114-Status: GOOD ( 18.93 ) 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 Most of entries in ftr_bits[] of id_reg_desc will be UNSIGNED+LOWER_SAFE. Use that as the default arm64_ftr_bits for any entries that are not statically defined in ftr_bits[] so that we don't have to statically define every single UNSIGNED+LOWER_SAFE entry. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/sys_regs.c | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 30adc19e4619..b19e14a1206a 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -35,6 +35,7 @@ static u64 read_id_reg_with_encoding(const struct kvm_vcpu *vcpu, u32 id); static inline struct id_reg_desc *get_id_reg_desc(u32 id); +static void id_reg_desc_init_ftr(struct id_reg_desc *idr); /* * All of this file is extremely similar to the ARM coproc.c, but the @@ -325,6 +326,8 @@ struct id_reg_desc { * Used to validate the ID register values with arm64_check_features(). * The last item in the array must be terminated by an item whose * width field is zero as that is expected by arm64_check_features(). + * Entries that are not statically defined will be generated as + * UNSIGNED+LOWER_SAFE entries during KVM's initialization. */ struct arm64_ftr_bits ftr_bits[FTR_FIELDS_NUM]; }; @@ -335,6 +338,9 @@ static void id_reg_desc_init(struct id_reg_desc *id_reg) u64 val = read_sanitised_ftr_reg(id); id_reg->vcpu_limit_val = val; + + id_reg_desc_init_ftr(id_reg); + if (id_reg->init) id_reg->init(id_reg); @@ -3173,6 +3179,54 @@ static inline struct id_reg_desc *get_id_reg_desc(u32 id) return id_reg_desc_table[IDREG_IDX(id)]; } +void kvm_ftr_bits_set_default(u8 shift, struct arm64_ftr_bits *ftrp) +{ + ftrp->sign = FTR_UNSIGNED; + ftrp->type = FTR_LOWER_SAFE; + ftrp->shift = shift; + ftrp->width = ARM64_FEATURE_FIELD_BITS; + ftrp->safe_val = 0; +} + +/* + * Check to see if the id_reg's ftr_bits have statically defined entries + * for all fields of the ID register, and generate the default ones + * (FTR_UNSIGNED+FTR_LOWER_SAFE) for any missing fields. + */ +static void id_reg_desc_init_ftr(struct id_reg_desc *idr) +{ + struct arm64_ftr_bits *ftrp = idr->ftr_bits; + int index = 0; + int shift; + u64 ftr_mask; + u64 mask = 0; + + /* Create a mask for fields that are statically defined */ + for (index = 0; ftrp->width != 0; index++, ftrp++) { + ftr_mask = arm64_ftr_mask(ftrp); + WARN_ON_ONCE(mask & ftr_mask); + mask |= ftr_mask; + } + + if (mask == -1UL) + /* All fields are statically defined */ + return; + + /* The 'index' indicates the first unused index of ftr_bits */ + for (shift = 0; shift < 64; shift += ARM64_FEATURE_FIELD_BITS) { + /* Check if there is an existing ftrp for the field */ + ftr_mask = ARM64_FEATURE_FIELD_MASK << shift; + if (mask & ftr_mask) + continue; + + /* Generate the default arm64_ftr_bits for the field */ + kvm_ftr_bits_set_default(shift, &idr->ftr_bits[index++]); + mask |= ftr_mask; + } + + WARN_ON((mask != -1UL) || (index != (FTR_FIELDS_NUM - 1))); +} + static void id_reg_desc_init_all(void) { int i;