From nobody Thu Jan 30 17:39:01 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 093691D5AD9 for ; Fri, 24 Jan 2025 04:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691265; cv=none; b=R9FBd6LSTNue8oIHa1WkZ9osGt31xcv/JBa629mZdt10cnHhYFY2KkTjBjSJGHO85tWqRqLYKE7Y5eoXONxPEuys5XKiWE85IXcOPqsJ8Jr70b1aopbcctfRbMKzz9YlgbZg+oBx0GAy4L8/SGEhawxYhCXsBCLyOP5p1UIAluY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691265; c=relaxed/simple; bh=G+K9MvSpAIpwDwMmunI0YSdJnqQJGTJZcC3ONEVxX60=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Sjuj7YWfJGJV1s7Q+L1BIjhUEkfoYmUyEPaPMzFb0tioGm9ytRCXuLdiHYRIE7HiLDILXh04gfIm601hUYwVXnNBmp0GVFcbDaHVLWcWlyrG6obZthuYCkAsLI7oVAJC+SzFEVSyQowatE8M4vSsqgatD2sbB1MplxTP4KiOf0A= 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=VRwZSVXO; arc=none smtp.client-ip=209.85.214.177 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="VRwZSVXO" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2161eb95317so29386365ad.1 for ; Thu, 23 Jan 2025 20:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691263; x=1738296063; 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=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=VRwZSVXOhTD2P4yJYnfWOX55FTyD+UgYkwpt7B3k1j4K28tpvuxAW2u73V/X8VbzoM +I2v0tnJVVWgvYokh1mzGuPJ+pxtHDONQDaJdDLeLy1pbjvra0u1WxfcVOAZ/SHG5fME DVk+tO8D5KWKJH55uAPk1YeTxEXuI8SrKzxggelsisEhPrSd9qKkUOw/hzT3cHCuw3ZW iOo0/hKtg1hAipzplBu1OdcZ2VxIeS8gPbCUL2zjENcLNoEPdnjJ6QftpP1pRDFm9ZRC HLjhVGlW20atzF9jHdZ6QKijprPSefUtf47WLZlUlr8P37Al/+6M0BAdO0lABD4ToqW7 7Lrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691263; x=1738296063; 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=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=l5k2pMsGJXLbYuvr5zycIfA5k3IXynswAOjjg1fzeESMTr23a5VEHYwX9EZSgugWZ+ 7ilpTdFNYKpNw0rsEdvXaSpfgE0lZbkMcIFyhX7F+bSmn+KIGdBowBaOG2Lv8/e8pks1 XBMcLQ2yJucHmy+bT71IJKNPs2cZoYm2qeB/Ccip5ZLujyDczil6MpfxqTIJlMFhflng suIwkMX/PA3/8v/X0dquzXXQJle5gjmQEfY533G9Tal6k3Lc5kAW3dYUDmItwHd++I/r mFvOBpQrQeymcchcXMg+hIu7qFKiHTNB8/aA4zzYVZ4x7DAzi8pVJHpGPVNLeqUUG4s9 Iy7Q== X-Forwarded-Encrypted: i=1; AJvYcCUHZhRuNK1Mn9QDwtVN/qPvH3Cf+J6G/BgWHOFUjdAK5MGzEloUzRurpBm7ypQfLHofub9T6f+pjxkgxac=@vger.kernel.org X-Gm-Message-State: AOJu0YxsTpmWliKS47UPiKGWb7gVCjTX0KKEYDmxF0WzPXsjoewEWn9c 9oQgM3dZgi8tfrHV/aPSvwkVoWikfjcGfphyXMl2oSpVPIgHcksngD7dLiYYlwQ= X-Gm-Gg: ASbGncsxyRVaSocD0apD35ebWQ1Xc7Rq0vv2rrrcFCK8YECl/wmKoNriOsJjtNWuSEL OEnFTjf9CQv1g042HnNn/72D9crPkt0UtzlTlXSdpkKuxxwbKHu5WraY5k8h3d39R6NpHg/JgOd 0N+j2JWfL9V6u2FKJ0/E36vd6joIkbsXTnP4pfhDT1LFm3CTPVM8GIKUKFTBstFGisq1VXG7qHe OuEDmrlzZJwICm+uu5Hc4j3mI0ekUaaJWTQzA//3Lm7MFysdsvKL08U4YDxbKfP7qUQkSIiJwjt 8Cgq/pGozBX309rc3js/419S0ptXI6G36BkJdbU63OhNCSow8g== X-Google-Smtp-Source: AGHT+IHEVuIwXoOL2BRMckKQdUn6rThK8+gCeYIzAbtbkLa2fGtpENXBcF3NVF3avHHuHE184wgyUA== X-Received: by 2002:a17:903:8cb:b0:21a:874e:8adf with SMTP id d9443c01a7336-21c355dc4eemr425518995ad.45.1737691263230; Thu, 23 Jan 2025 20:01:03 -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.00.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:02 -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 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Fri, 24 Jan 2025 11:59:57 +0800 Message-Id: <20250124035959.45499-2-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" Enabling cbo.clean and cbo.flush in user mode makes it more convenient to manage the cache state and achieve better performance. Reviewed-by: Andrew Jones Signed-off-by: Yunhui Cui --- arch/riscv/kernel/cpufeature.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c0916ed318c2..60d180b98f52 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -30,6 +30,7 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) =20 static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicbom; =20 unsigned long elf_hwcap __read_mostly; =20 @@ -87,6 +88,8 @@ static int riscv_ext_zicbom_validate(const struct riscv_i= sa_ext_data *data, pr_err("Zicbom disabled as cbom-block-size present, but is not a power-o= f-2\n"); return -EINVAL; } + + any_cpu_has_zicbom =3D true; return 0; } =20 @@ -944,6 +947,11 @@ void __init riscv_user_isa_enable(void) current->thread.envcfg |=3D ENVCFG_CBZE; else if (any_cpu_has_zicboz) pr_warn("Zicboz disabled as it is unavailable on some harts\n"); + + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOM)) + current->thread.envcfg |=3D ENVCFG_CBCFE; + else if (any_cpu_has_zicbom) + pr_warn("Zicbom disabled as it is unavailable on some harts\n"); } =20 #ifdef CONFIG_RISCV_ALTERNATIVE --=20 2.39.2 From nobody Thu Jan 30 17:39:01 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 E0A951D86E6 for ; Fri, 24 Jan 2025 04:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691272; cv=none; b=coEzlkCY5UEtaPKPKkHaK/w6/IlUY5ROb/D0B1PMgQBrCohVWmJwjqLxIO4usdaey/U1f6OCmHArFH6H8Ijhi9CGJFzzAtSBcr4ucIpBy3Q6UiTlMa9sFawHqMgbThFTXszRsvzvCGJF/CnSjlkbaALOKzAaqgTawf9Tzzaytm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691272; c=relaxed/simple; bh=c9cRr3mQ6E+Sm3MLQkn4R9H1H/29MlPqeqytx1/YJ6o=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p3jPuzK0m4TS1aiLrfUiMqHvm5TSYbsry0n/lfZE7qEbVbpHEqVmRHZg18YQKWOqApuczduITXFylEepN3WgodZopYa0qSS0XAJcRV+YFK4v0iENS4BKJD0S5NPHn7KEAGKdPLSoLtkplr4F5blqq9ClRIr7iK8185oO4Gp53ls= 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=V4a7qL/C; arc=none smtp.client-ip=209.85.214.173 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="V4a7qL/C" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2166f1e589cso40446335ad.3 for ; Thu, 23 Jan 2025 20:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691270; x=1738296070; 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=uhogcwNy3A24ar7Arj4nwWwwc1NEi0tTGPamBbIerrs=; b=V4a7qL/CZs9+Osc/GlPovuNHPwpgPacFo3vDmMzv0W6ccftR7VLJsWJ2u0gMmB733v A73td9H0BY2g28Abfz2hlNA/iMHGE4S0usnl8NAtDBTA/Xtm8WiCLl2b7eoDiWu+aEJ+ 4UMMjOlDArU1zVZcr/V61rgQ5Dq/Omv4Csd4+GAI0y/PQlA+7+pvRAth4ZIXMCNdwNwi OHCQvIJP29jaPIioe/X3yfo9nUuaW228/ZKTtlyqG20hp3/TQHZTh6vnW5fY0B0VlyOj zPtr6eB1nleVWM/w56MmFg0cgga+WhP4uohGyaerY4wjYbP/fnQYrejouAeNupW0UMb0 6vtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691270; x=1738296070; 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=uhogcwNy3A24ar7Arj4nwWwwc1NEi0tTGPamBbIerrs=; b=H07wrv8+n4RRtFfr6j4Y+pER+UoBUND8D/25o9KnYMERNCzIYSQbfd2RISWgaHjW7S rBBnGPyMIaCwgpzC2Ta1X9g6f10iO6qUIdbvi7sswaIZVWjCE9UiOhnnHlA/YBBJu1pj HwBnQqz3pY8OkrZL5V/NvAA4Imw8Q+V9ANFBlOXr0PjiPJ61aYji3XsMLuL/3MbsJm7E bTUrZiYzUrtWWdYHbmSufhj8HxyM9wnYD/0AqfEzMlCHOGvOBCkEjOhwrgvUKm7Drdv4 IaJy7dkLuFbWENbb2JiLProfE3RNUDkPMjXsD96hkmFNQpf6Jf4x/M/cJvDGUE3bumPI uAMQ== X-Forwarded-Encrypted: i=1; AJvYcCXNpDcejFvFaikRBso0BemPSAU8aQ3eaWdx2RJZCFRsJIxzz1613Qtb8wK8vpCSuKh88Fp7qk47IVVpbPA=@vger.kernel.org X-Gm-Message-State: AOJu0YyxMbGHl88dGCe4kzN68VnxGuBh5eqm7EJvesmyS+Lwmr+MHOoZ Yk4HZvfA2mMTS+tEvQy5D4cODB7GRtV7DzkI8/BS89cHlqOIs3GUYIOQ4h1IHQ0= X-Gm-Gg: ASbGnctpIy/NYZR20eKW3mMh15Mewin7riu5KdzLTsLu3ZXrGp+rvp+DNYP/xlM27Zi yYyBF3lm6sbha2OUpAAhnaC/layJ20qanOla9Nhw58x02rxUy0fY2gUB7zzuzmzMc0SS+ga1XJW rYwGaiAKrmk5MRX9uUeGrzxuUX3zMsjydWigzXhb8tfmj/+Ljpp30Z+N2gcfaQeQUI9f2XVblxv Jy65TB1oh7nikom83+s7Rms0uRkRcffM4Fcdz+akvc9MqnfpZ8lm0jOe6LCpCOE3+0HRKk3dNtZ nKg1bPhygGso2HVy9YMR0oohDPi81p1v+47LItCUp9Vqj4q9QQ== X-Google-Smtp-Source: AGHT+IHypLNaXsQx1FvJy6sHsbSOt7rVRjml9Nk+TXnCiyBsirRqofRzqo0H1bHoO0B4nLDc9UgDlQ== X-Received: by 2002:a17:903:1381:b0:216:361a:783d with SMTP id d9443c01a7336-21c3562097amr473816585ad.28.1737691270197; Thu, 23 Jan 2025 20:01:10 -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.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:09 -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 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Fri, 24 Jan 2025 11:59:58 +0800 Message-Id: <20250124035959.45499-3-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" Expose Zicbom through hwprobe and also provide a key to extract its respective block size. Reviewed-by: Andrew Jones Reviewed-by: Samuel Holland Signed-off-by: Yunhui Cui --- Documentation/arch/riscv/hwprobe.rst | 6 ++++++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/uapi/asm/hwprobe.h | 2 ++ arch/riscv/kernel/sys_hwprobe.c | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/risc= v/hwprobe.rst index 955fbcd19ce9..21323811a206 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -242,6 +242,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as defined in version 1.0 of the RISC-V Pointer Masking extensions. =20 + * :c:macro:`RISCV_HWPROBE_EXT_ZICBOM`: The Zicbom extension is supported= , as + ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMO= s. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar val= ues to :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was mistakenly classified as a bitmask rather than a value. @@ -293,3 +296,6 @@ The following keys are defined: =20 * :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vec= tor accesses are not supported at all and will generate a misaligned address fault. + +* :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which + represents the size of the Zicbom block in bytes. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwpr= obe.h index 1ce1df6d0ff3..89379f9a2e6e 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ =20 #include =20 -#define RISCV_HWPROBE_MAX_KEY 10 +#define RISCV_HWPROBE_MAX_KEY 11 =20 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uap= i/asm/hwprobe.h index 3af142b99f77..b15c0bd83ef2 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -73,6 +73,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_EXT_ZCMOP (1ULL << 47) #define RISCV_HWPROBE_EXT_ZAWRS (1ULL << 48) #define RISCV_HWPROBE_EXT_SUPM (1ULL << 49) +#define RISCV_HWPROBE_EXT_ZICBOM (1ULL << 50) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) @@ -94,6 +95,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW 2 #define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3 #define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4 +#define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 11 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ =20 /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprob= e.c index cb93adfffc48..b47939f5ffee 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -106,6 +106,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, EXT_KEY(ZCA); EXT_KEY(ZCB); EXT_KEY(ZCMOP); + EXT_KEY(ZICBOM); EXT_KEY(ZICBOZ); EXT_KEY(ZICOND); EXT_KEY(ZIHINTNTL); @@ -160,7 +161,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, pair->value &=3D ~missing; } =20 -static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext) +static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) { struct riscv_hwprobe pair; =20 @@ -278,6 +279,11 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pai= r, if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) pair->value =3D riscv_cboz_block_size; break; + case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE: + pair->value =3D 0; + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM)) + pair->value =3D riscv_cbom_block_size; + break; case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: pair->value =3D user_max_virt_addr(); break; --=20 2.39.2 From nobody Thu Jan 30 17:39:01 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