Moaning(*´Д`) on NVMe

Post on 22-Jan-2018

756 views 2 download

Transcript of Moaning(*´Д`) on NVMe

[1]

Moaning(*´Д`) on NVMe

hiyohiyoTwitter: @openlibsys

http://crystalmark.info/

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

[2]

OutlineSelf-Introduction

What is NVMe?

BenchmarkSecret of NVMe

Summary

[3]

Self-Introduction

[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 -)

[5]

CrystalMark 2004

Benchmark app with ranking system

[6]

CrystalCPUID

CPU information viewer

[7]

CrystalDiskMark 5 Shizuku Edition

Next generation disk benchmark

Put the results aside lol

Standard

[8]

CrystalDiskInfo 6 Shizuku Edition

Notifies health information of HDD and SSD with VOICE!!

Next generation disk information viewer

Standard

[9]

[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!~

[11]

What is 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

[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)

[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)

[15]

Intel SSD 750 1.2TB

[16]

SAMSUNG SSD 950 PRO 512GB

Bought ONLY for analyzing NVMe

[17]

SAMSUNG SSD 950 PRO vs Intel SSD 750

SAMSUNG SSD950 PRO

Intel SSD750

※Microsoft Standard Driver

[18]

Comparing drivers on Intel SSD 750

Intel NVMeDriver

MicrosoftStandard

Driver

[19]

Secret of NVMe 1

[20]

Pop quiz!

???

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

[21]

Part 1

Vendor ID of Intel is

8086h

[22]

Part 2

○○○Express

[23]

In fact・・・

But also a PCI Express device!!

Root Complex

Controller

Standard NVM Express Controller

[24]

So・・・

There maybe some information in PCI Configuration Space.

[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

[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

[27]

Little question

How to access to PCI?

[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

[29]

User modeRing3

Kernel modeRing0

Composition of WinRing0

[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

[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

[32]

Secret of NVMe 2

[33]

NVMe command set

NVM Commands3 Mandatory commands

Admin Commands10 Mandatory commands

[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

[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

[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

[37]

What should I do・・・

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

NVMe \(^o^)/Screwed up

[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.

[39]

Advent of the god

http://naraeon.net/

https://github.com/ebangin127/nvmetools

[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

[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

[42]

Released development build!!

[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)

[44]

Now supports NVMe SSDs!!

Hell of “Vendor specific pass-through”……

[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

[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

[47]

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

Digression

[48]

Summary

[49]

Summary

Rush to buy a NVMe SSD Right now!!

[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

[51]

Sources

[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

[53]

Thank you for listening