From nobody Thu Jan 30 23:12:14 2025 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DDEF1D88D3 for ; Fri, 24 Jan 2025 04:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691279; cv=none; b=tro61dVblnI736Lr+M2EW7keS3xFa4kxQvX3MEz0fbxezcKxHlllJEnPPicsD0xHLYZjSBinKfymAMbBnmshTnkzWXcmaZXHIzzfmeK/QAxUb3YI4BqTyceLgog7l+/j9nydoQ3OuKnUEYjxutbh0/rIwnnGLSyQdX3qJTYPmXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691279; c=relaxed/simple; bh=NqOUrka99DSUi18FOpq9XilJAxI+Dx6U6EraUGvZnFk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MXqiBZDas5Z8PIY/JAz2r0FrlxGoXrCFai+oZKFZMI7q5zivIIchJtzYH5Ku0QzeTECY5qwcCE318TVfl8VUhwIAhqzdbi0gGCnfY9u++OSqMj3DD4U+78l4el/eqmrxbNdtR90dr3Z6MXCoQ5g3ls1oHe8cZgbIuDYZue1DNGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=EQK7ihrT; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="EQK7ihrT" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2167141dfa1so30967165ad.1 for ; Thu, 23 Jan 2025 20:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691277; x=1738296077; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Y6H6/Xpe5szI3425MURKDC2kUnYsqHlXT/4n1BN4R7E=; b=EQK7ihrT5C4S7afBkYW74/9Wx8JJO9xu7HzfTop1TG5gnfowDvRqdNKRU41u6NvQ9g MoEpFb5PYYFPVXWLmkwcEUautKqqn3O+1ptt5FSnOdkG+UaCHfTxOvJDyQdga/SJaDCR HeYtxGpTJiTVLUD7RJASnM9xIZIyTsjaXmA3tZZ/pfYL/zR/6jtTegWDmeeCTIxNnvte 0T/M8vCf/TiLELrafXv5hgU2rV2xLWD8FW8fMAF+IeEFdUNSWk0QM7gJLePT/6l9Bx4J 5cU6em6i1QvwcSlKg9Hj513u1M/fVsyUyvzJcalIsPBPNCB4d0kCTEQaVc1tGgy0gKTw 1OZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691277; x=1738296077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y6H6/Xpe5szI3425MURKDC2kUnYsqHlXT/4n1BN4R7E=; b=Av5wZ5Br/A/RtPx+w4onxbcIdDYUAcHyDU4Yxs44BL0Rp7uXe3kESNRYZodp2c1/OP Ojqbm7Nlg3KREtMqhhpUXwie1PEjzxAReAOCtYdfYvBXp3CzdKRHz1n4qDtyzkkzUy5E U5H6iL4uHTK9LT0Jl+baq7wxKaTJHQEB+vRiXCURi3d4qg/pztc1ikWhtZ5YWWrmVGPm yX2pFp1UIFzrA8eJBkMl2xROugaaZOeyo5xQqquYRyZlmiuUW/Rk6CObzasxn8Nx91fb k1EOT4r3DshkFVL4pgmPm7PekebqP4vK/fQf8iuIJurVo+MoCb5Q/IkTAuhwJLHefiIP 8w/Q== X-Forwarded-Encrypted: i=1; AJvYcCWIHaK0ZKmhwWv030xHVXOchJS/0V7cmNS0nF15/AzCAtWl+HVW1xOdUN6Q29i6lW4epf7hTge3pO9LvrQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzwXpmdeemrGqvkO1Eustp0TbxVLDuwW/RwZN3d1IHu6nte+WJO 2+FohEbH7S6YhmJHDk/AwShmLdaajDpT3V29tdJZqBM58MJ5Y+4s81PNXJdwLj8= X-Gm-Gg: ASbGnctjjvBv6uMhUc+OzotfL7KKASTAOC1RXNuTe+5CUhSz946+GgfhHnENAXH07fB wwrvSegF+6JYOZi4tISOZlm3N4ZBipN6i34c54RuxRkczePeX3YQIl46X+TS8mV2oqk6vNR0Mgd yqgSZUrmdVtYh1CbdB9lPmjlZXVSxUiOpyz7De19i3EYuMpuAkGNQ6Q2Lewd6nrT8Id9WrY4EoS bvo8MqeT8dOFmWu9ke6AiHp7+pqvcdkHNY0PgGArZDt7u/k93v11PaDffuylj/hNoO2cekmmD9h 1R2Za4ZxJh89YQMURq+lq5p2GuCsE4NK4kITuOicF4GEPLwR4w== X-Google-Smtp-Source: AGHT+IEmNJ9PTxDO/9xUv7qTG6D6YOowwQFpMMoo6I4xfnFmtGI8+HqdGOFtB4iDinl8gA0atu0SWA== X-Received: by 2002:a17:903:124b:b0:215:98e7:9b1 with SMTP id d9443c01a7336-21d993177a2mr87590995ad.5.1737691277079; Thu, 23 Jan 2025 20:01:17 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([2408:8406:78d1:bf49:24c4:f518:9b3b:36de]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da4141d67sm6758915ad.153.2025.01.23.20.01.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:16 -0800 (PST) From: Yunhui Cui To: ajones@ventanamicro.com, alexghiti@rivosinc.com, andybnac@gmail.com, aou@eecs.berkeley.edu, charlie@rivosinc.com, cleger@rivosinc.com, conor.dooley@microchip.com, conor@kernel.org, corbet@lwn.net, cuiyunhui@bytedance.com, evan@rivosinc.com, jesse@rivosinc.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, samuel.holland@sifive.com, shuah@kernel.org Subject: [PATCH v6 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Fri, 24 Jan 2025 11:59:59 +0800 Message-Id: <20250124035959.45499-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250124035959.45499-1-cuiyunhui@bytedance.com> References: <20250124035959.45499-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add test for Zicbom and its block size into CBO tests, when Zicbom is present, test that cbo.clean/flush may be issued and works. As the software can't verify the clean/flush functions, we just judged that cbo.clean/flush isn't executed illegally. Reviewed-by: Andrew Jones Reviewed-by: Samuel Holland Signed-off-by: Yunhui Cui --- tools/testing/selftests/riscv/hwprobe/cbo.c | 66 +++++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/se= lftests/riscv/hwprobe/cbo.c index a40541bb7c7d..5e96ef785d0d 100644 --- a/tools/testing/selftests/riscv/hwprobe/cbo.c +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c @@ -50,6 +50,14 @@ static void cbo_clean(char *base) { cbo_insn(base, 1); } static void cbo_flush(char *base) { cbo_insn(base, 2); } static void cbo_zero(char *base) { cbo_insn(base, 4); } =20 +static void test_no_cbo_inval(void *arg) +{ + ksft_print_msg("Testing cbo.inval instruction remain privileged\n"); + illegal_insn =3D false; + cbo_inval(&mem[0]); + ksft_test_result(illegal_insn, "No cbo.inval\n"); +} + static void test_no_zicbom(void *arg) { ksft_print_msg("Testing Zicbom instructions remain privileged\n"); @@ -61,10 +69,6 @@ static void test_no_zicbom(void *arg) illegal_insn =3D false; cbo_flush(&mem[0]); ksft_test_result(illegal_insn, "No cbo.flush\n"); - - illegal_insn =3D false; - cbo_inval(&mem[0]); - ksft_test_result(illegal_insn, "No cbo.inval\n"); } =20 static void test_no_zicboz(void *arg) @@ -81,6 +85,30 @@ static bool is_power_of_2(__u64 n) return n !=3D 0 && (n & (n - 1)) =3D=3D 0; } =20 +static void test_zicbom(void *arg) +{ + struct riscv_hwprobe pair =3D { + .key =3D RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, + }; + cpu_set_t *cpus =3D (cpu_set_t *)arg; + __u64 block_size; + long rc; + + rc =3D riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, = 0); + block_size =3D pair.value; + ksft_test_result(rc =3D=3D 0 && pair.key =3D=3D RISCV_HWPROBE_KEY_ZICBOM_= BLOCK_SIZE && + is_power_of_2(block_size), "Zicbom block size\n"); + ksft_print_msg("Zicbom block size: %llu\n", block_size); + + illegal_insn =3D false; + cbo_clean(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.clean\n"); + + illegal_insn =3D false; + cbo_flush(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.flush\n"); +} + static void test_zicboz(void *arg) { struct riscv_hwprobe pair =3D { @@ -129,7 +157,7 @@ static void test_zicboz(void *arg) ksft_test_result_pass("cbo.zero check\n"); } =20 -static void check_no_zicboz_cpus(cpu_set_t *cpus) +static void check_no_zicbo_cpus(cpu_set_t *cpus, __u64 cbo) { struct riscv_hwprobe pair =3D { .key =3D RISCV_HWPROBE_KEY_IMA_EXT_0, @@ -137,6 +165,7 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) cpu_set_t one_cpu; int i =3D 0, c =3D 0; long rc; + char *cbostr; =20 while (i++ < CPU_COUNT(cpus)) { while (!CPU_ISSET(c, cpus)) @@ -148,10 +177,13 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) rc =3D riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&one_= cpu, 0); assert(rc =3D=3D 0 && pair.key =3D=3D RISCV_HWPROBE_KEY_IMA_EXT_0); =20 - if (pair.value & RISCV_HWPROBE_EXT_ZICBOZ) - ksft_exit_fail_msg("Zicboz is only present on a subset of harts.\n" - "Use taskset to select a set of harts where Zicboz\n" - "presence (present or not) is consistent for each hart\n"); + cbostr =3D cbo =3D=3D RISCV_HWPROBE_EXT_ZICBOZ ? "Zicboz" : "Zicbom"; + + if (pair.value & cbo) + ksft_exit_fail_msg("%s is only present on a subset of harts.\n" + "Use taskset to select a set of harts where %s\n" + "presence (present or not) is consistent for each hart\n", + cbostr, cbostr); ++c; } } @@ -159,7 +191,9 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) enum { TEST_ZICBOZ, TEST_NO_ZICBOZ, + TEST_ZICBOM, TEST_NO_ZICBOM, + TEST_NO_CBO_INVAL, }; =20 static struct test_info { @@ -169,7 +203,9 @@ static struct test_info { } tests[] =3D { [TEST_ZICBOZ] =3D { .nr_tests =3D 3, test_zicboz }, [TEST_NO_ZICBOZ] =3D { .nr_tests =3D 1, test_no_zicboz }, - [TEST_NO_ZICBOM] =3D { .nr_tests =3D 3, test_no_zicbom }, + [TEST_ZICBOM] =3D { .nr_tests =3D 3, test_zicbom }, + [TEST_NO_ZICBOM] =3D { .nr_tests =3D 2, test_no_zicbom }, + [TEST_NO_CBO_INVAL] =3D { .nr_tests =3D 1, test_no_cbo_inval }, }; =20 int main(int argc, char **argv) @@ -189,6 +225,7 @@ int main(int argc, char **argv) assert(rc =3D=3D 0); tests[TEST_NO_ZICBOZ].enabled =3D true; tests[TEST_NO_ZICBOM].enabled =3D true; + tests[TEST_NO_CBO_INVAL].enabled =3D true; } =20 rc =3D sched_getaffinity(0, sizeof(cpu_set_t), &cpus); @@ -206,7 +243,14 @@ int main(int argc, char **argv) tests[TEST_ZICBOZ].enabled =3D true; tests[TEST_NO_ZICBOZ].enabled =3D false; } else { - check_no_zicboz_cpus(&cpus); + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOZ); + } + + if (pair.value & RISCV_HWPROBE_EXT_ZICBOM) { + tests[TEST_ZICBOM].enabled =3D true; + tests[TEST_NO_ZICBOM].enabled =3D false; + } else { + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOM); } =20 for (i =3D 0; i < ARRAY_SIZE(tests); ++i) --=20 2.39.2