53
[1] Moaning(* ´ Д`) on NVMe hiyohiyo Twitter: @openlibsys http://crystalmark.info/ Sapporo.cpp / Sapporo C++ Study #10 Crypton Future Media

Moaning(*´Д`) on NVMe

Embed Size (px)

Citation preview

Page 1: Moaning(*´Д`) on NVMe

[1]

Moaning(*´Д`) on NVMe

hiyohiyoTwitter: @openlibsys

http://crystalmark.info/

Sapporo.cpp / Sapporo C++ Study #10@ Crypton Future Media

Page 2: Moaning(*´Д`) on NVMe

[2]

OutlineSelf-Introduction

What is NVMe?

BenchmarkSecret of NVMe

Summary

Page 3: Moaning(*´Д`) on NVMe

[3]

Self-Introduction

Page 4: Moaning(*´Д`) on NVMe

[4]

Self-Introduction

Nickname:hiyohiyo

Age:37

Family members:Wife, Loving daughter, Loving son

Hobby:Software Development (About 17yrs)

Living in:Hokkaido Sapporo

Major works: CrystalDiskInfo, CrystalDiskMark, etc.(a.k.a. Crystal Series)

Consistently developing software that more preferred by computer.

Microsoft MVP・Visual C++ (Jan. 2014 – Sep. 2015) ・Visual Studio and Development Technologies (Oct. 2015 -)

Page 5: Moaning(*´Д`) on NVMe

[5]

CrystalMark 2004

Benchmark app with ranking system

Page 6: Moaning(*´Д`) on NVMe

[6]

CrystalCPUID

CPU information viewer

Page 7: Moaning(*´Д`) on NVMe

[7]

CrystalDiskMark 5 Shizuku Edition

Next generation disk benchmark

Put the results aside lol

Standard

Page 8: Moaning(*´Д`) on NVMe

[8]

CrystalDiskInfo 6 Shizuku Edition

Notifies health information of HDD and SSD with VOICE!!

Next generation disk information viewer

Standard

Page 9: Moaning(*´Д`) on NVMe

[9]

Page 10: Moaning(*´Д`) on NVMe

[10]

[AD] 2nd Generation Moe Driven Development

http://www.slideshare.net/hiyohiyo/mddwin32

Introduces the most important thing of software development!!

Programming Win32with MDD(Moe Driven Development)

CLR/H 89th Study~Community Camp Day!~

Page 11: Moaning(*´Д`) on NVMe

[11]

What is NVMe?

Page 12: Moaning(*´Д`) on NVMe

[12]

NVMe is

NVM Express (NVMe) is an interface between Host software and Non-volatile memory.

NVMe is optimized for PCI Express connected Enterprise/Client SSDs.

Next Generation SSD interface

Page 13: Moaning(*´Д`) on NVMe

[13]0 500 1000 1500 2000 2500 3000 3500 4000

NVMe @PCIe 3.0x4

SATA/600

SATA/300

SATA/150

UDMA/100

UDMA/66

UDMA/33

Transfer speed(MB/s)

Page 14: Moaning(*´Д`) on NVMe

[14]

AHCI vs NVMe

The most important thing to benchmark apps AHCI NVMe

Queue 1 65536Commands/Queue 32 65536

1x1 32x1 32x8

Random read benchmark result ofSAMSUNG SSD 950 PRO 512GB (MB/s)

Page 15: Moaning(*´Д`) on NVMe

[15]

Intel SSD 750 1.2TB

Page 16: Moaning(*´Д`) on NVMe

[16]

SAMSUNG SSD 950 PRO 512GB

Bought ONLY for analyzing NVMe

Page 17: Moaning(*´Д`) on NVMe

[17]

SAMSUNG SSD 950 PRO vs Intel SSD 750

SAMSUNG SSD950 PRO

Intel SSD750

※Microsoft Standard Driver

Page 18: Moaning(*´Д`) on NVMe

[18]

Comparing drivers on Intel SSD 750

Intel NVMeDriver

MicrosoftStandard

Driver

Page 19: Moaning(*´Д`) on NVMe

[19]

Secret of NVMe 1

Page 20: Moaning(*´Д`) on NVMe

[20]

Pop quiz!

???

NVMe SSD is not only a storage device,but also a ○○○ device.

Page 21: Moaning(*´Д`) on NVMe

[21]

Part 1

Vendor ID of Intel is

8086h

Page 22: Moaning(*´Д`) on NVMe

[22]

Part 2

○○○Express

Page 23: Moaning(*´Д`) on NVMe

[23]

In fact・・・

But also a PCI Express device!!

Root Complex

Controller

Standard NVM Express Controller

Page 24: Moaning(*´Д`) on NVMe

[24]

So・・・

There maybe some information in PCI Configuration Space.

Page 25: Moaning(*´Д`) on NVMe

[25]

Analyze as a PCI Express device

Source: http://www.nvmexpress.org/wp-content/uploads/NVM-Express-1_2a.pdf

Intel※Little Endian

Capabilities Pointer

Page 26: Moaning(*´Д`) on NVMe

[26]

Analyze as a PCI Express device

Address Capability ID Next Address

40h 01h 50h

50h 11h 60h

60h 10h ----

CLS Link Speed

1h 250MB/s, 2.5GT/s (8B10)

2h 500MB/s, 5.0GT/s (8B10)

3h 1000MB/s, 8.0GT/s (128B130B)

NLW Link Width

1h x1

2h x2

4h x4

Source: http://www.nvmexpress.org/wp-content/uploads/NVM-Express-1_2a.pdf

Page 27: Moaning(*´Д`) on NVMe

[27]

Little question

How to access to PCI?

Page 28: Moaning(*´Д`) on NVMe

[28]

Introduction of WinRing0 (Deprecated)

Closed due to personal reasons.

With full user guide

Generic Hardware Access Library

Modified BSD

Read and Write I/O ports.Read and Write PCI Configuration Space.Use RDMSR/WRMSR privileged command.Use RDTSC and CPUID.

With you can

Page 29: Moaning(*´Д`) on NVMe

[29]

User modeRing3

Kernel modeRing0

Composition of WinRing0

Page 30: Moaning(*´Д`) on NVMe

[30]

1. Add OpenLibSys.cs to project.2. Add using OpenLibSys; to source code.3. Create instance of Ols like ols = new Ols();.4. Call features through the object.

Procedure

using OpenLibSys;public partial class WinRing0Sample : Form{

private void Form1_Load(object sender, EventArgs e){

uint freq = 1193180000 / 440000; // 440HzOls ols = new Ols();// Make beep sound.ols.WriteIoPortByte(0x43, 0xB6);ols.WriteIoPortByte(0x42, (byte)(freq & 0xFF));ols.WriteIoPortByte(0x42, (byte)(freq >> 9));// Omitted below

}}

hogehoge.cs

How to use WinRing0

Page 31: Moaning(*´Д`) on NVMe

[31]

// Host Bridgeaddress = ols.FindPciDeviceByClass(0x06, 0x00, 0x00, 0);if (address != 0xFFFFFFFF){

str += "[PCI Confguration Space Dump] HostBridge\r\n"; str += " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n";str += "---------------------------------------------------\r\n";for (int i = 0; i < 256; i+= 16){

str += i.ToString("X2") + "|";for (int j = 0; j < 16; j++){

str += “ ” + (ols.ReadPciConfigByte(address, (byte)(i + j))).ToString("X2");

}str += "\r\n";

}}

Dump PCI Configuration Space

Page 32: Moaning(*´Д`) on NVMe

[32]

Secret of NVMe 2

Page 33: Moaning(*´Д`) on NVMe

[33]

NVMe command set

NVM Commands3 Mandatory commands

Admin Commands10 Mandatory commands

Page 34: Moaning(*´Д`) on NVMe

[34]

Get S.M.A.R.T. information (NVMe)

Microsoft NVMe Driver

NVMe SSDs

Get Log Page

Admin command cannot be used!!

Command to accessS.M.A.R.T.

NVM Command

Admin Command

ReadFile() ※Win32API

Read ※NVM command

Page 35: Moaning(*´Д`) on NVMe

[35]

Get S.M.A.R.T. information (ATA)

Microsoft ATA Driver

ATA HDD/SSD

Command to accessS.M.A.R.T.ReadFile()

※Win32API

READ **** ※ATA Command

SMART READ DATASend ATA Command directly with struct named ATA PASS THROUGH

Page 36: Moaning(*´Д`) on NVMe

[36]

Get S.M.A.R.T. information (USB)

Get S.M.A.R.T. information (External) Look through the external HDD

Support USB/IEEE 1394 Get S.M.A.R.T. information (External)

S.M.A.R.T. information retrieval command

SATA/PATA

Command

translator chip

USB packet or IEEE 1394 packet

SCSI Command (Like Read/Write)

Unfortunately, It’s not possible to use 100% of ATA commands with device that uses USB-ATA translator chip.

But, there are some USB-ATA translator chips that has ATA command pass-through interface.

BackdoorUSB packet or IEEE 1394 packet

SCSI Command (Like Read/Write)

General ATA Command

USB packet or IEEE 1394 packet

SCSI Command (Like Read/Write)

General ATA Command

SATA/PATA

a.k.a.

Command

translator chip

Page 37: Moaning(*´Д`) on NVMe

[37]

What should I do・・・

Can’t get NVMe SSD S.M.A.R.T. information on Windows!!!!!!!!!!

NVMe \(^o^)/Screwed up

Page 38: Moaning(*´Д`) on NVMe

[38]

Advent of the god

Reply from Korean God atJapanese (*´Д`)moaning tweet!!!

Does global activities occurred the miracle?

Actively getting a number of information like data sheets from official channel, I’ve overwhelmed by undone homework (Unsupported SSD) these days.I want to put these homework aside and analyze NVMe (* 'Д`)moaning.

Page 39: Moaning(*´Д`) on NVMe

[39]

Advent of the god

http://naraeon.net/

https://github.com/ebangin127/nvmetools

Page 40: Moaning(*´Д`) on NVMe

[40]

Get S.M.A.R.T. information (Samsung)

Microsoft NVMe Driver

SAMSUNG SSD 950 PRO (Only)

Security Command (SCSI)

Get Log Page

ReadFile() ※Win32API

READ ※NVMe Command

Access secret

backdoor

Page 41: Moaning(*´Д`) on NVMe

[41]

::ZeroMemory(&sptwb, sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS24));

sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH);sptwb.Spt.PathId = 0;sptwb.Spt.TargetId = 0;sptwb.Spt.Lun = 0;sptwb.Spt.SenseInfoLength = 24;sptwb.Spt.DataTransferLength = IDENTIFY_BUFFER_SIZE;sptwb.Spt.TimeOutValue = 2;sptwb.Spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS24, DataBuf);sptwb.Spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS24, SenseBuf);

sptwb.Spt.CdbLength = 16;sptwb.Spt.Cdb[0] = 0xB5; // SECURITY PROTOCOL INsptwb.Spt.Cdb[1] = 0xFE; // SAMSUNG PROTOCOLsptwb.Spt.Cdb[3] = 6; // Get Log Pagesptwb.Spt.Cdb[9] = 0x40; // Transfer Lengthsptwb.Spt.DataIn = SCSI_IOCTL_DATA_OUT;sptwb.DataBuf[0] = 2;sptwb.DataBuf[4] = 0xFF;sptwb.DataBuf[5] = 0xFF;sptwb.DataBuf[6] = 0xFF;sptwb.DataBuf[7] = 0xFF;

length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS24, DataBuf) + sptwb.Spt.DataTransferLength;

bRet = ::DeviceIoControl(hIoCtrl, IOCTL_SCSI_PASS_THROUGH,&sptwb, length, &sptwb, length, &dwReturned, NULL);

Access SAMSUNG SSD 950 PROPartial code

Magic Number: Only working with these constants

Page 42: Moaning(*´Д`) on NVMe

[42]

Released development build!!

Page 43: Moaning(*´Д`) on NVMe

[43]

Get S.M.A.R.T. information (Intel)

Intel NVMe Driver

Intel SSD 750(Only)

ReadFile() ※Win32API

READ ※NVMe Command

Get Log Page

Command to accessS.M.A.R.T.

Admin Command

Pass the command with NVMe PASS THROUGH (Intel only)

Page 44: Moaning(*´Д`) on NVMe

[44]

Now supports NVMe SSDs!!

Hell of “Vendor specific pass-through”……

Page 45: Moaning(*´Д`) on NVMe

[45]

Completely different S.M.A.R.T. format!!

SAMSUNG SSD 830 512GB (SATA) SAMSUNG SSD 950 PRO 512GB (NVMe)

Compare S.M.A.R.T. format

Page 46: Moaning(*´Д`) on NVMe

[46]

Completely different S.M.A.R.T. format!!

SAMSUNG SSD 830 512GB (SATA) SAMSUNG SSD 950 PRO 512GB (NVMe)

Compare S.M.A.R.T. format

Page 47: Moaning(*´Д`) on NVMe

[47]

God’s project written in Delphi……Downloaded eval version due to step over feature!!

Digression

Page 48: Moaning(*´Д`) on NVMe

[48]

Summary

Page 49: Moaning(*´Д`) on NVMe

[49]

Summary

Rush to buy a NVMe SSD Right now!!

Page 50: Moaning(*´Д`) on NVMe

[50]

Summary

• Sometimes make apps open source occurs miracles.

• I don’t hesitate to buy test samples.

⇒ It hurts like hell to develop without samples.

• This presentation is a momentum for supporting NVMe.

⇒ Without this opportunity it would be pretty delayed!?

• It’s always an interesting thing to develop apps related to

hardware.

⇒ (*´Д`)moaning

Page 51: Moaning(*´Д`) on NVMe

[51]

Sources

Page 52: Moaning(*´Д`) on NVMe

[52]

• nvmexpress.orghttp://www.nvmexpress.org/

• NVM Express 1.2a Specificationhttp://www.nvmexpress.org/wp-content/uploads/NVM-Express-1_2a.pdf

• Naraeon NVMe Toolshttps://github.com/ebangin127/nvmetools

Sources

Page 53: Moaning(*´Д`) on NVMe

[53]

Thank you for listening