From patchwork Tue Jan 9 16:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 13515101 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 64B2CC46CD2 for ; Tue, 9 Jan 2024 16:57:30 +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=2Cp a6juAHM3+g/FpzME8uT12xxjRFtgH05wsuLQ3wnELc91yQ7DTpXh0yNSY/zcApp/C8pqIbtJeOqol b/C6GAMZ3LQyA5ZRn8mPwNorBhXPwXJ/CZp0O47c4/82NqiZ4EQBjZjuJ+T/m0Kww4jlD63P4qQ62 TVaBlRg7N20UjCSmhV/DmHrLOYcAaUDztfbhQYBWQ4BNZmOcImi0/Qjy6yT2BOMPvLVH8n1NwG4VI uNPuphlGjuyxBo73Q6wurZwtTNC1Rtx5zXu6kq/wZZLOPfrUoh/5z1QLej0icrF898MwOo7x3HPN9 B12mAuetFLry00ztzupF+MwaoTp11Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rNFPS-008vGr-21; Tue, 09 Jan 2024 16:57:02 +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 1rNFPP-008vF3-1y for linux-arm-kernel@lists.infradead.org; Tue, 09 Jan 2024 16:57:00 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5efb07ddb0fso42303767b3.0 for ; Tue, 09 Jan 2024 08:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704819411; x=1705424211; 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=wv7EzYGYeAPP2vE0610HFTIV/b5Eyy2e/xoexw2q4KiSHJr5UmQTmoYIc2yO69UK2g hm0WRiFgAfWuHBoZ00qHL8kc5IWZmEuUvg8ALup39yo8rpOepfFU+KDZR7y8rI2HKuuw aU3xZHi8FLf0B9S2PtLOG3lnzoph+luDTt1JMAwNCCv9tEdLx3B6bqiWKJLozu99D/Ln +RPNNt8e4N3VdmkcO3w8pzcNemls3aONfR8szZ67W3BgKqgrLfRZc1poFrq7TcmgEIfh rF+B/kR/v6aPzrBl43ajpQ1Rq+RI0CdFN7rhTTWRmbMjyMQt4Rz3AQzXAerqbzATwWvU Serg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704819411; x=1705424211; 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=daYZ5dngiprAdpD0m+AwSXnIvCZ89c5iLlZ3fP0H5IkXV7KqEhJrZwiW8omvgP/KqY 3gSdPiqAFFb06o6IyeR36hCB5SQD3Rh+ryXPou/w3yLfeh5i8iJHlpUUkcfIU3ajbXms vUw/QsfblCRyG6pC64G2PPA3M0+roNeJJE+cjZhWNqn6zhCDnH86Nj1yjiMPIAROAbCe JxEaUEGIuJZa17ZtOtYgtDa/zIJ4b4RoQo5cAeHn+SqwpKY9kViss188eNgaUv7JgYjT 8Rp402/8wPWqxC8Dmw2Ir3Qz2nALRJvkRmBHE/RX+//LhuDcULUuRrYLgnud9DuhDl0g QOEg== X-Gm-Message-State: AOJu0Yz26yp0HB21uVThGCL42E8V/7Ug6v9Bvm1lkMT8bk3gcsPLqULB 4KvmEUDKwFoOQpAzKmDDrfRYzbIFGEY+BSwzkt9XIk0L X-Google-Smtp-Source: AGHT+IFJYk3i2RC1bH88fwAuau9C4zuiOPot5e3J0BArmIefW2S8KwtUXxKUu+wt+MEHyKZAdOV1+wsmcKU76wbbYQ== X-Received: from jgzg.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1acf]) (user=jingzhangos job=sendgmr) by 2002:a05:6902:1369:b0:dbe:ab5b:c667 with SMTP id bt9-20020a056902136900b00dbeab5bc667mr159057ybb.2.1704819411220; Tue, 09 Jan 2024 08:56:51 -0800 (PST) Date: Tue, 9 Jan 2024 08:56:21 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240109165622.4104387-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-20240109_085659_670007_E8EE4BF0 X-CRM114-Status: GOOD ( 11.68 ) 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 Tested-by: Itaru Kitayama --- .../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);