From patchwork Mon Jan 15 22:02:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13520226 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 81FFFC3DA79 for ; Mon, 15 Jan 2024 22:03:32 +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:Message-ID: References:Mime-Version: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=cGdVvui1bT15rJ2lA5k7TXfr9Ym3EiDs63RY8NXVD6k=; b=BlhbMQC8udTEH93TjOPXCvaq8o XA2/RFzcnFdXiFpmLoOyfbSvG7XgeGI6x/9p2mz/2OhtBoYmwrEyd+mBJtvQQFzLtBkVI5tAjs7l3 rahiDvgPSPBDm9fPkxd86qB91eoZ0g2yLe66J/g/4JOFNPxGNS8FwjYpzEAiCUpiqd1DGo1AdV4Qo lTpBYiF2DEjGIxFWo1SpFRE3T9vJCUPmZ1XDZILRTkcy5uwHjQbwXdVUcwkNtkEVtnLuUkWiD6lEV QWyk7JARklv82DYLHjuAACmC4ZJU9d2ItrY5r3roSTguSljl3ZRdyR3Olg2YKrGvFGlHtmyU709FJ 8FlUhMRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPV2o-00AGbo-10; Mon, 15 Jan 2024 22:02:58 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPV2l-00AGb1-0H for linux-arm-kernel@lists.infradead.org; Mon, 15 Jan 2024 22:02:56 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5fc8ff9ffb5so27329657b3.1 for ; Mon, 15 Jan 2024 14:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705356173; x=1705960973; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fs5plhdODh5O3jwOa02ZCAJ9LDrZDHKVjydsmrZKIRI=; b=iiA5gPqf1pFy/FdkfTppuLTXptAMH0s8FASlCU4ZJzJReNNBKBS9DAaKFYoFmUiAS1 D4qrdDBkHb+HoJJGTpswfqmZ7XH/r9kw7dXeZ5cErlWPrlq1SQUiCpgAiHFZhLPvN1WY FsxAyNL8Flx5hYrFgg9DChLfkpkeT1UIHDTfHh8rCq5h7xE6CKvRTOYJtcRb2/kNb423 a4dhLyvHm5IRofr9+Nvkm1FC0WrYSskqdAEw7mRvu1D4mWo1gxzHSTqmoj1uf2CJmDxd xyih+OWZg5QQIphgLtiKdOFL5KEgJWL9gvA0B6Bjnq/Ytt2aeWMQKUeAdSYKxkwdOA82 tVMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705356173; x=1705960973; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fs5plhdODh5O3jwOa02ZCAJ9LDrZDHKVjydsmrZKIRI=; b=sGcXNXuHVOMYwFWCh3291WxixChZBvx5aQzCSgh9iIWt1JDDIXu9AdSFueTqUHTLsH e9S3yQD86sAgUI/h7y5ROmBF4YE1xxVvxhDYt6Kc5GSNFg9XzU5ej12fI5W9UbMqMUEe FpfJy02QV92OkRbsyNI5IjLuxcMBQ7x0WYdUQiz5vw8zr/PsgBc2VpCNojXajfRLKi+g EDPEyDg62tqXBKm1ElKvQd4C/bHCQibYL8961zOGXIGUwL2PwRmboHIZ6uTpI018SeWX iVLXVRGZ7sAOVbG7SU7lQfLPG/zgEH9IsG9bUbKpgnaXI7l/dnoY8zK7Ogdbu9rhEogi VB7A== X-Gm-Message-State: AOJu0YxzQQKMPhkLxG90t6FKZNj7HBgeWhBmNCyUvGx6P+iuqE1mvstC IauGDpMX/CUlDr3EoQFguoV7zwu59uXuCQMhrZRSlf78 X-Google-Smtp-Source: AGHT+IF+fzRJLAXxL6I3qdWZEbC2fAkyfSI5O2l3h7Gnd5rTDrziaodY8En22xaBj29yb4KDWgcqegBtA+/+HIEKgQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a25:aac7:0:b0:dc2:232b:5cf1 with SMTP id t65-20020a25aac7000000b00dc2232b5cf1mr57299ybi.1.1705356173573; Mon, 15 Jan 2024 14:02:53 -0800 (PST) Date: Mon, 15 Jan 2024 14:02:09 -0800 In-Reply-To: <20240115220210.3966064-1-jingzhangos@google.com> Mime-Version: 1.0 References: <20240115220210.3966064-1-jingzhangos@google.com> X-Mailer: git-send-email 2.43.0.381.gb435a96ce8-goog Message-ID: <20240115220210.3966064-2-jingzhangos@google.com> Subject: [PATCH v2] KVM: arm64: selftests: Handle feature fields with nonzero minimum value correctly From: Jing Zhang To: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton Cc: Paolo Bonzini , James Morse , Suzuki K Poulose , Zenghui Yu , Itaru Kitayama , Jing Zhang , Itaru Kitayama X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240115_140255_123754_49ADE22F X-CRM114-Status: GOOD ( 13.50 ) 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 There are some feature fields with nonzero minimum valid value. Make sure get_safe_value() won't return invalid field values for them. Also fix a bug that wrongly uses the feature bits type as the feature bits sign causing all fields as signed in the get_safe_value() and get_invalid_value(). Fixes: 54a9ea73527d ("KVM: arm64: selftests: Test for setting ID register from usersapce") Reported-by: Zenghui Yu Reported-by: Itaru Kitayama Tested-by: Itaru Kitayama Signed-off-by: Jing Zhang Tested-by: Itaru Kitayama --- * v1 -> v2: - Use ftr_bits->safe_val for minimal safe value for type FTR_LOWER_SAFE. - Fix build error reported by Zenghui with gcc-10.3.1. --- .../selftests/kvm/aarch64/set_id_regs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a diff --git a/tools/testing/selftests/kvm/aarch64/set_id_regs.c b/tools/testing/selftests/kvm/aarch64/set_id_regs.c index bac05210b539..16e2338686c1 100644 --- a/tools/testing/selftests/kvm/aarch64/set_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/set_id_regs.c @@ -32,6 +32,10 @@ struct reg_ftr_bits { enum ftr_type type; uint8_t shift; uint64_t mask; + /* + * For FTR_EXACT, safe_val is used as the exact safe value. + * For FTR_LOWER_SAFE, safe_val is used as the minimal safe value. + */ int64_t safe_val; }; @@ -65,13 +69,13 @@ struct test_feature_reg { static const struct reg_ftr_bits ftr_id_aa64dfr0_el1[] = { S_REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64DFR0_EL1, PMUVer, 0), - REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64DFR0_EL1, DebugVer, 0), + REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64DFR0_EL1, DebugVer, ID_AA64DFR0_EL1_DebugVer_IMP), REG_FTR_END, }; static const struct reg_ftr_bits ftr_id_dfr0_el1[] = { - S_REG_FTR_BITS(FTR_LOWER_SAFE, ID_DFR0_EL1, PerfMon, 0), - REG_FTR_BITS(FTR_LOWER_SAFE, ID_DFR0_EL1, CopDbg, 0), + S_REG_FTR_BITS(FTR_LOWER_SAFE, ID_DFR0_EL1, PerfMon, ID_DFR0_EL1_PerfMon_PMUv3), + REG_FTR_BITS(FTR_LOWER_SAFE, ID_DFR0_EL1, CopDbg, ID_DFR0_EL1_CopDbg_Armv8), REG_FTR_END, }; @@ -224,13 +228,13 @@ uint64_t get_safe_value(const struct reg_ftr_bits *ftr_bits, uint64_t ftr) { uint64_t ftr_max = GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0); - if (ftr_bits->type == FTR_UNSIGNED) { + if (ftr_bits->sign == FTR_UNSIGNED) { switch (ftr_bits->type) { case FTR_EXACT: ftr = ftr_bits->safe_val; break; case FTR_LOWER_SAFE: - if (ftr > 0) + if (ftr > ftr_bits->safe_val) ftr--; break; case FTR_HIGHER_SAFE: @@ -252,7 +256,7 @@ uint64_t get_safe_value(const struct reg_ftr_bits *ftr_bits, uint64_t ftr) ftr = ftr_bits->safe_val; break; case FTR_LOWER_SAFE: - if (ftr > 0) + if (ftr > ftr_bits->safe_val) ftr--; break; case FTR_HIGHER_SAFE: @@ -276,7 +280,7 @@ uint64_t get_invalid_value(const struct reg_ftr_bits *ftr_bits, uint64_t ftr) { uint64_t ftr_max = GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0); - if (ftr_bits->type == FTR_UNSIGNED) { + if (ftr_bits->sign == FTR_UNSIGNED) { switch (ftr_bits->type) { case FTR_EXACT: ftr = max((uint64_t)ftr_bits->safe_val + 1, ftr + 1);