From patchwork Fri Jan 24 03:59:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948886 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 4B2BC1D63C9 for ; Fri, 24 Jan 2025 04:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737691265; cv=none; b=jJlgrgkMEPhoabJgFCbVIyuHdYmw34a493jUQo84zcLBogc0dWIC+92kgCgjZspNRTLhXyu7fXqFgemHDue/7FBc2gVXzjqCJektIFXg77/4frIpSQlsW+rsOGAL88dmpqBo+3G9anWn8qWj2TOzMNPBX7UeNO+SzriPB60BHMg= 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.179 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-f179.google.com with SMTP id d9443c01a7336-216426b0865so26952155ad.0 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=Iz2JogIBwIcsEdBDEz5q6+DVy/bm0GwjPVj0PH8OYnusd/rXYDogAtxDhdVz1/JK7s BHUZ+bnAi/ZbNNPAEKQZOS/iLaWIxHg+kOaIB3XJTNatrFTU+AitBV4kDLvSn8VWp1F/ V33PYH9qMVoYnTGoFotItnq0TAaBvjh3gcLIsZF/WHPbnbpGpwmM2kTbGd9hfWscoOPA GQ2ZqZucnQmxg6gHLgMp0Stw/Oobl0mFCDp0ML0pesLWbVwwOv4dCF1hAyEabpJiCIHz 6p4nG2WhiqySAe4T0l6PFNyN09dSUpUEdFx2e6MIJzPa7il1zogdm5R/9JMuhuRIOtt2 uvFQ== X-Forwarded-Encrypted: i=1; AJvYcCVI9yCbm86+Nb3kwgGKMsqv9S8xZXWJ3NXqUMiD6TZ63VpUEAtGsSCBxeHudQayKaBcI+MKWs2rtOpUadvMZmE=@vger.kernel.org X-Gm-Message-State: AOJu0YzAnObNdA+Cvz9+J+ig854q8e84fghU1b71RxkZuwLjeF3IetcQ uAPFZNWlTtC18J2ru0m7LRDjEwqmsaZZhehpgX2YOvVGOJrnodctTBsLBfLfutI= X-Gm-Gg: ASbGnct8cogLNN5kCoZrsIZ4k7qrOG1i4C5Rs192T18H935ujDhkuJIEOE0rXqRFqwy J85lBvTTAaIAl4Qp10Ns8JFEb+aMkWXL59whjJJlFESli55b7IwBOHcJ4bNjlsGuaZmYkde/bhv C6vXE18a/RahIwG/gg1F/AMImkgaFXhMXvPVIY2h880kZMOMnBgZ4oydlO5I0FHs4ixD/OauV1l FQqum6/V4eSitvOdfCt5PJ4eF1ol/NMA7WEJWbBT0mbC3pNWlVfInVorlB/pac/XmGvYmTT9MK7 hgRo4mD8B9jUPgKYN0yKt9Eenp2RZv2e918bUxLxudz2a5L67w== 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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) static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicbom; unsigned long elf_hwcap __read_mostly; @@ -87,6 +88,8 @@ static int riscv_ext_zicbom_validate(const struct riscv_isa_ext_data *data, pr_err("Zicbom disabled as cbom-block-size present, but is not a power-of-2\n"); return -EINVAL; } + + any_cpu_has_zicbom = true; return 0; } @@ -944,6 +947,11 @@ void __init riscv_user_isa_enable(void) current->thread.envcfg |= 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 |= ENVCFG_CBCFE; + else if (any_cpu_has_zicbom) + pr_warn("Zicbom disabled as it is unavailable on some harts\n"); } #ifdef CONFIG_RISCV_ALTERNATIVE From patchwork Fri Jan 24 03:59:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948887 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 039581D86ED for ; Fri, 24 Jan 2025 04:01:10 +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=1737691272; cv=none; b=NXhhaHo/NMJDMH1bz/8LiTHhOsy3Hjfnxq8r0M+iF2TF2iwCxR/cVT1hj/LeC3/pysIofhtt86ejMXd8eLRlb8DTLl0Icg1636uu7R1YSR7sI6r6vDiVgUMlIkpL3W/Yew+VfUeiL/yv7avxfkYatrTFwNXslnzYFlVm80kvOkk= 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.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="V4a7qL/C" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21634338cfdso37017875ad.2 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=FSiSsaO11ZrY3/B7+6wFaKpNPIo95/hTY582W+GWBNvGoADtSIW4Nzvn5gBNdJGZPB fghDGUkJqEp6CiPSfnuRaOvJAZIkwQZPU3+wbIPsifLgJ5b1m/usfw+Lxj/IU2k2ahNC ua3S6TONdjoO5tn9OOQH5wb/FJAImPb/HEl6iZN4xp7gmq6hsrc24tciCjni7K3CQvGp CKTPdUER9NRhQ5YCEnGGSP1l40JXX1tRhQgMlsYwu5g2JABHAvDMyXK4LcYc18S0+tdM GMJQa7PCbb8YveGD1ON2t00zIWgTVA4JD5tKkxWzharn7bZ4zoy15TR25InO/Du/iH4p VtTg== X-Forwarded-Encrypted: i=1; AJvYcCV0KqXFFN3GqvEfgELXcW4a8/XTp1XU2P5VACSRnCMLMQkcf2Mip0SuYat8ngA34qDcVPhJX+zJwJLDFV1gmwY=@vger.kernel.org X-Gm-Message-State: AOJu0YydocACx61crxmvdbMCSNVZZP/u1pZymXVUE5NiC7vBLCJjcoeB f5ient9lesGCkK5g0WAMqljn8cxtRdV2k2qOgO8VFsIJ7ThIWjEMjNoHZH0D1bw= X-Gm-Gg: ASbGncvOx5zd3g0mm0qCX5veajRU1FAQZMz8i0+70mdLBudMhLkHBlrIiUJcGLOsP5p u5ZTLA9eeNsvyEqCisRQqgz4HQZDOW06lMD7KvgUFWYSZKaBVysWVHTLGARjO4iOK8BjDAF36DE +/0xs+z+NmYGRQ2LhqXRNuzz6lfFISPhpJQwtbgR6MnzfpWnLoU+uLTtg+/Hoa6qDR2R20OD3Pl ABJkRiQRmhhIXpox2TqH+tHT8ArDVHwBAoTkvu+pHqZbFIO3s9YrMenX9ArpdnWRTMn+odFpCgk FJ/xlnA8HaabZfIrW6Uq5/IflINp8fk2u+L/WIdtbxQVjtddQw== 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/riscv/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. + * :c:macro:`RISCV_HWPROBE_EXT_ZICBOM`: The Zicbom extension is supported, as + ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values 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: * :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vector 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/hwprobe.h index 1ce1df6d0ff3..89379f9a2e6e 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ #include -#define RISCV_HWPROBE_MAX_KEY 10 +#define RISCV_HWPROBE_MAX_KEY 11 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/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. */ /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.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 &= ~missing; } -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; @@ -278,6 +279,11 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) pair->value = riscv_cboz_block_size; break; + case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE: + pair->value = 0; + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM)) + pair->value = riscv_cbom_block_size; + break; case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: pair->value = user_max_virt_addr(); break; 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)