From patchwork Mon Jan 15 22:02:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13520224 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 C19E5C3DA79 for ; Mon, 15 Jan 2024 22:03:01 +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: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=lEiy/Jnl+7OQlO2pp1z/JFIWTpzrvyt7HzBHGfP2paQ=; b=mbn DY5OZsLpMaoyCOhpo+lGR3nWEHi4Bjdet5bq0vj8RedIBYsLl7pRCwpmnQG9bjrMTG5V4CM1L9SYK +tgwt74mEcvpDhZM94x56kQgWBLHIscfUezxTp9/k5m9VmdH+Zf8Y3mn/jeSvE2iCu5+Ttz+8Rzhg BzIU+ry0/0RIq/FeRfD2ix3OGhZt7oy2Pa0abITc6F5lnhG1ZQJEr/RICjq7VJmR42bA/gs6oz2Zp jazjfRoftKCnqyWCBf9w6IUG/v7ershebj7GYyJQMvWQ1GiwdhXF/PuLGlm/9eW/gcnqRPjx+xXmJ 4vp7Gzq+9qiFEXL4Ndm8UbtIxGmUdNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rPV2F-00AGWo-2X; Mon, 15 Jan 2024 22:02:23 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rPV2C-00AGWP-1r for linux-arm-kernel@lists.infradead.org; Mon, 15 Jan 2024 22:02:21 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db402e6f61dso12335116276.3 for ; Mon, 15 Jan 2024 14:02:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705356138; x=1705960938; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ynJWgyIQTp0mxF1GFOGb+73JwIM0WneWjD70p63cQEA=; b=HLiZMsyEFOjW++pI4D1QKwz1OXKRQg0ZRsqehhnyZrHQmAZnHMVpyd6zQ1xU71fv+1 dPcPlQuBEMOxDqX8rmSa+5lYvzpgx4Pp3aSBoUvNbdqLTOU5Z5zJFA1h3CPd3En/L68D IN3ZhJSXQ6ahnGwRd0wH0hX1XnrUiZC51UIraV/9lje5xgOehs3dIAbcO54rdcIpWUIb +UW8W9CSbTCzq/BjG0bDiHIisxU3XHVy1y7KsgigH8/3mUVkjCi83gUAhgMG8fQp+Zcl r5T9U4SklTE1PkEG8L9xehHuIRJZedPRkDmdsDdY8voXuNsdGXbJaEf5mngj4w6co9c6 usag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705356138; x=1705960938; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ynJWgyIQTp0mxF1GFOGb+73JwIM0WneWjD70p63cQEA=; b=CTsz+oSjiIFk8Ymj/ZZWhjKL23HjRnRu8nbLF7R3NcNQhhYGfji1GtVYsDzfqT79Wp lNpPzk4rAuzg0Pmz268dK0nU2eYem1sEwJOvrp6f9XvvGv1JeKBUkpyb6siz9LzuhIsC XWmlTnQDc09ncBSm2QIlNPezRK+4Kx5immMZQDV4ulB2B0h8SY8Z5xhcROC+vbfh2BTq gajnDVZVC/QuJ/a93WVWrfdwJJr9LQ3/mrmnHboBcrJJ5mPkJ2bshnZxnc+OgumtJxzT r6q7X7kyPUyqeDnka3blVDdivvn4QMXdj+hSq6SAAuCWmw26En/ALKk5tBCfcobrnTut A0+A== X-Gm-Message-State: AOJu0YwghlgtPU3uNcnyHo4YCrnkwES/84i+Xp8v30rZvvacy2BHuSmv O7u/sWDUyJZmlSElwZqXot68XKEX0KlHwCDQocm3Yhls X-Google-Smtp-Source: AGHT+IG/Iz6XwIuapV7X0ZZ3a5fIRKR0t1lv2wuRi/0Zp4hZu5zvYSaE2O3U898S6kuTsnCQsTVHzwgeQxaXgAgzGg== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6902:8c:b0:dc1:f6f0:16cf with SMTP id h12-20020a056902008c00b00dc1f6f016cfmr1218961ybs.11.1705356137876; Mon, 15 Jan 2024 14:02:17 -0800 (PST) Date: Mon, 15 Jan 2024 14:02:08 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.381.gb435a96ce8-goog Message-ID: <20240115220210.3966064-1-jingzhangos@google.com> Subject: [PATCH v1] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240115_140220_638599_30160186 X-CRM114-Status: GOOD ( 11.79 ) 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 Signed-off-by: Jing Zhang --- .../selftests/kvm/aarch64/set_id_regs.c | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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..f17454dc6d9e 100644 --- a/tools/testing/selftests/kvm/aarch64/set_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/set_id_regs.c @@ -224,13 +224,20 @@ 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) + uint64_t min_safe = 0; + + if (!strcmp(ftr_bits->name, "ID_AA64DFR0_EL1_DebugVer")) + min_safe = ID_AA64DFR0_EL1_DebugVer_IMP; + else if (!strcmp(ftr_bits->name, "ID_DFR0_EL1_CopDbg")) + min_safe = ID_DFR0_EL1_CopDbg_Armv8; + + if (ftr > min_safe) ftr--; break; case FTR_HIGHER_SAFE: @@ -252,7 +259,12 @@ 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) + uint64_t min_safe = 0; + + if (!strcmp(ftr_bits->name, "ID_DFR0_EL1_PerfMon")) + min_safe = ID_DFR0_EL1_PerfMon_PMUv3; + + if (ftr > min_safe) ftr--; break; case FTR_HIGHER_SAFE: @@ -276,7 +288,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);