From patchwork Fri Jan 24 03:59:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948888 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 161AC1D88D0 for ; Fri, 24 Jan 2025 04:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691279; cv=none; b=Tn36ZkW0bFVj5N/hf7GccBIHeUz8eArhAEn2FQyHtdnwMS0yvbwjC1qwUAjg+D0PWOkfYF5HqMTVNGxYsVp8iAuGfPYFhJH2HKce7qKrAvrQE4D2wfp1vbrXwjZx2SZn1r7sq05klqL4yM0K4mNSy0teOk50b2NowSzKTmlTl6M= 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.170 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-f170.google.com with SMTP id d9443c01a7336-2167141dfa1so30967095ad.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=F3qJxPUi49mK/ScUphGQ+sr6Fo9TRMnLhuHfyZrfspJtf/hq3dO5uee5JzUgCA3zpo Qb9Z6zTCBxcqeHNfHMoeJd9djZBPfxlZsGj6eU5gawma93vtlWqSNEBHEi2oLBNpPPfU tp1JSvB2cok+Pu/m0qki/1cbmIXglNbynMQiodUbgonr2v85swJJ32OGBmPGgGGFaEIV fl4pn2Lb+Sb/giCbUJQ7dhrYVFYu5+4+n3d8CHbzdFwKlQ06FxLmvO8xJ9ZMJl/dYgsZ 9Z8Kajj4IVu/pMPGi7O4tlbt+2c3d0jOe+SZ8TrDDHACB+J5Zkzdd5rWrwe1GiS6/9Rz M2vg== X-Forwarded-Encrypted: i=1; AJvYcCVGrgMMVurcwhCY4PE9Gq5iayL3n30/cT8An6uk2JwvfITvUuEclqRde1t9N8dFtWke0m6J0yG3xNy7FeSF7cY=@vger.kernel.org X-Gm-Message-State: AOJu0YwGjMpreOnlAOO94p8g0oRfI30zs80qapAI2Z8f8RIIqqNbtobV 4khr83a6ccbbZ1tBTOta38QZ5+8O4L3IZ2HvTZEb6tf6w+pTh527qVOLRXistpA= X-Gm-Gg: ASbGncu72KtyiUoxQxWCLbzqG1/6tII+4mCpwwfukDIZYUHltTQ/1Q7zmkDnW8j+wrn GZIrVC8kc6nH2yXMLbh5fq4TwaT97BUTQC1//7DDPy49qGZS2oWsKh2LxnDoMWeF6qBl2Sn4xbM Ugbr0LjRXKMa+83S9WKRgE+9GfA+oSbjrXqyLz4HdctCQ8rHG2B72AL5k/Jg9zKmTisRLFM4iId BlXQ87XSaSlEdrXBgaMffX2xiLeTp7M8AYi1IH1rsPytURxBxtVOhLtH32xhFU0vSDRXgc9RO6i D56oMpglNjt9JzudOrpVSYh8OQkVI4YiJGLVK9UFV3aVNlT1jw== 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/selftests/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); } +static void test_no_cbo_inval(void *arg) +{ + ksft_print_msg("Testing cbo.inval instruction remain privileged\n"); + illegal_insn = 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 = false; cbo_flush(&mem[0]); ksft_test_result(illegal_insn, "No cbo.flush\n"); - - illegal_insn = false; - cbo_inval(&mem[0]); - ksft_test_result(illegal_insn, "No cbo.inval\n"); } static void test_no_zicboz(void *arg) @@ -81,6 +85,30 @@ static bool is_power_of_2(__u64 n) return n != 0 && (n & (n - 1)) == 0; } +static void test_zicbom(void *arg) +{ + struct riscv_hwprobe pair = { + .key = RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, + }; + cpu_set_t *cpus = (cpu_set_t *)arg; + __u64 block_size; + long rc; + + rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, 0); + block_size = pair.value; + ksft_test_result(rc == 0 && pair.key == 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 = false; + cbo_clean(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.clean\n"); + + illegal_insn = false; + cbo_flush(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.flush\n"); +} + static void test_zicboz(void *arg) { struct riscv_hwprobe pair = { @@ -129,7 +157,7 @@ static void test_zicboz(void *arg) ksft_test_result_pass("cbo.zero check\n"); } -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 = { .key = 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 = 0, c = 0; long rc; + char *cbostr; 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 = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&one_cpu, 0); assert(rc == 0 && pair.key == RISCV_HWPROBE_KEY_IMA_EXT_0); - 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 = cbo == 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, }; static struct test_info { @@ -169,7 +203,9 @@ static struct test_info { } tests[] = { [TEST_ZICBOZ] = { .nr_tests = 3, test_zicboz }, [TEST_NO_ZICBOZ] = { .nr_tests = 1, test_no_zicboz }, - [TEST_NO_ZICBOM] = { .nr_tests = 3, test_no_zicbom }, + [TEST_ZICBOM] = { .nr_tests = 3, test_zicbom }, + [TEST_NO_ZICBOM] = { .nr_tests = 2, test_no_zicbom }, + [TEST_NO_CBO_INVAL] = { .nr_tests = 1, test_no_cbo_inval }, }; int main(int argc, char **argv) @@ -189,6 +225,7 @@ int main(int argc, char **argv) assert(rc == 0); tests[TEST_NO_ZICBOZ].enabled = true; tests[TEST_NO_ZICBOM].enabled = true; + tests[TEST_NO_CBO_INVAL].enabled = true; } rc = sched_getaffinity(0, sizeof(cpu_set_t), &cpus); @@ -206,7 +243,14 @@ int main(int argc, char **argv) tests[TEST_ZICBOZ].enabled = true; tests[TEST_NO_ZICBOZ].enabled = 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 = true; + tests[TEST_NO_ZICBOM].enabled = false; + } else { + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOM); } for (i = 0; i < ARRAY_SIZE(tests); ++i)