Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpuid dies on overflow on AMD 7713P #133

Closed
bcantrill opened this issue Feb 3, 2023 · 1 comment
Closed

cpuid dies on overflow on AMD 7713P #133

bcantrill opened this issue Feb 3, 2023 · 1 comment

Comments

@bcantrill
Copy link

Thanks for this useful crate! Running the cpuid binary on an AMD 7713P with overflow detection enabled (either via the debug profile or explicitly enabled) results in a panic:

...
Processor Brand String = "AMD EPYC 7713P 64-Core Processor"
L1 TLB 2/4 MiB entries (0x8000_0005/eax):
┌──────────────────┬─────────────────┐
│     iTLB #entries│               64│
│iTLB associativity│Fully associative│
│     dTLB #entries│               64│
│dTLB associativity│Fully associative│
└──────────────────┴─────────────────┘
L1 TLB 4 KiB entries (0x8000_0005/ebx):
┌──────────────────┬─────────────────┐
│     iTLB #entries│               64│
│iTLB associativity│Fully associative│
│     dTLB #entries│               64│
│dTLB associativity│Fully associative│
└──────────────────┴─────────────────┘
L1 dCache (0x8000_0005/ecx):
┌─────────────────┬───────┐
│line size [Bytes]│     64│
│    lines per tag│      1│
│    associativity│NWay(8)│
│       size [KiB]│     32│
└─────────────────┴───────┘
L1 iCache (0x8000_0005/edx):
┌─────────────────┬───────┐
│line size [Bytes]│     64│
│    lines per tag│      1│
│    associativity│NWay(8)│
│       size [KiB]│     32│
└─────────────────┴───────┘
L2 TLB 2/4 MiB entries (0x8000_0006/eax):
┌──────────────────┬───────┐
│     iTLB #entries│    512│
│iTLB associativity│NWay(2)│
│     dTLB #entries│   2048│
│dTLB associativity│NWay(4)│
└──────────────────┴───────┘
L2 TLB 4 KiB entries (0x8000_0006/ebx):
┌──────────────────┬───────┐
│     iTLB #entries│    512│
│iTLB associativity│NWay(4)│
│     dTLB #entries│   2048│
│dTLB associativity│NWay(8)│
└──────────────────┴───────┘
L2 Cache (0x8000_0006/ecx):
┌─────────────────┬───────┐
│line size [Bytes]│     64│
│    lines per tag│      1│
│    associativity│NWay(8)│
│       size [KiB]│    512│
└─────────────────┴───────┘
L3 Cache (0x8000_0006/edx):
thread 'main' panicked at 'attempt to multiply with overflow', src/bin/cpuid.rs:1300:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The problem is that l3cache_size() returns a u16 -- and the cache size here (512) times 512 exceeds a 16-bit quantity; it should be promoted to a u32 before being multiplied:

diff --git a/src/bin/cpuid.rs b/src/bin/cpuid.rs
index e58ce16..f27d11f 100644
--- a/src/bin/cpuid.rs
+++ b/src/bin/cpuid.rs
@@ -1297,7 +1297,7 @@ fn markdown(_opts: Opts) {
                 RowGen::tuple("line size [Bytes]", info.l3cache_line_size()),
                 RowGen::tuple("lines per tag", info.l3cache_lines_per_tag()),
                 RowGen::tuple("associativity", info.l3cache_associativity()),
-                RowGen::tuple("size [KiB]", info.l3cache_size() * 512),
+                RowGen::tuple("size [KiB]", info.l3cache_size() as u32 * 512),
             ],
         );
     }

Thanks again for the crate!

@gz
Copy link
Owner

gz commented Feb 3, 2023

fixed in 10.6.1 thanks a lot for reporting this!

@gz gz closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants