engineering and use of large formal specifications alastair reid … · huge value in being able to...

49
© 2017 Arm Limited Engineering and Use of Large Formal Specifications Alastair Reid Arm Research @alastair_d_reid

Upload: others

Post on 13-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited

EngineeringandUseofLargeFormalSpecifications AlastairReid

ArmResearch

@alastair_d_reid

Page 2: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�2

More Less

Data

Performance

MachineLearning

InternetofThings

SmartHomes

SelfDrivingCars

SocialMedia

Bugs

Crashes

Dataloss

Datacorruption

Dataleaks/theft

DDoSattacks

Cyber-Physicalattacks

Page 3: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�3

BetterProgrammingLanguages

BetterSystemDesign

HardwareSecurity

Enforcement

AutomaticTest

Generation

FuzzTesting

ExploitDetection

BetterBug

Finding

FormalVerification

Legal/Regulatory

Page 4: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�4

Page 5: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�5

Specification

Specification Specification

Specification

Specification

Page 6: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�6

What(formal)specificationsdoweneed?

Libraries:stdio.h,OpenGL,…

Languages:C,C++,ML,Javascript,Verilog,…

Network:TCP/IP,OAuth,DNS,TLS,WiFi,…

Filesystems:FAT32,NTFS,ext4,…

OSes:Posix/Linuxsystemcall,Linuxdevicedriver,KVM,UEFI,…

Hardware:CPU,PCIe,AMBA,NIC,…

Page 7: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�7

Criticalpropertiesofspecifications

Scope-Completeness

-Notabstractingoutcriticaldetail

Applicability-Versionagnostic

-Vendoragnostic

Trustworthiness

Page 8: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�8

OvercomingtheSpecificationBottleneck

CreatingformalspecificationsTestingspecificationsGettingbuyinUsingspecificationsFormalvalidationofspecificationsMakingyourspecificationspublic

“TrustworthySpecificationsoftheARMv8-Aandv8-Marchitecture,”FMCAD2016“EndtoEndVerificationofARMprocessorswithISAFormal,”CAV2016“Whoguardstheguards?FormalValidationofARMv8-MSpecifications,”OOPSLA2017“ISASemanticsforARMv8-A,,RISC-V,andCHERI-MIPS,”POPL2019

https://alastairreid.github.io/papers/

Page 9: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�9

Creating formal specificationsTesting specificationsGetting buy in

“Trustworthy Specifications of the ARM v8-A and v8-M architecture,” FMCAD 2016

Page 10: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 11: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 12: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 13: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 14: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 15: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�10

CreatingSpecifications

Page 16: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�11

Pseudocode

Page 17: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�12

ARMPseudocode

~40,000lines

-32-bitand64-bitmodes

-All4encodings:Thumb16,Thumb32,ARM32,ARM64

-Allinstructions(>1300encodings)

-All4privilegelevels(User,Supervisor,Hypervisor,SecureMonitor)

-BothSecuritymodes(Secure/NonSecure)

-MMU,Exceptions,Interrupts,Privilegechecks,Debug,TrustZone,…

Page 18: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�13

Statusatthestart

- Nolanguagespec- Notools(parser,typechecker)- Incomplete(around15%missing)- Unexecuted,untested- Seniorarchitectsbelievedthatanexecutablespecwas

- Impossible- Notuseful- Lessreadable- Lesscorrect

Page 19: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�14

ArchitecturalConformanceSuite

Processorarchitecturalcompliancesign-off

Large• v8-A32,000testprograms,billionsofinstructions• v8-M3,500testprograms,>250millioninstructions

Thorough• Testsdarkcornersofspecification

Hardtorun• Requiresadditionaltestinginfrastructure

Page 20: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�15 ©2017ArmLimited

ProgressintestingArmspecification

- Doesnotparse,doesnottypecheck

- Can’tgetoutofreset

- Can’texecutefirstinstruction

- Can’texecutefirst100instructions

- …

- Passes90%oftests

- Passes99%oftests

- …

0

50

100

Page 21: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�16

Measuringarchitecturecoverageoftests

Untested: op1*op2 == -3.0, FPCR.RND=-Inf

Page 22: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�17

Creating a Virtuous Cycle

ARMSpec

Page 23: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�18

Lessonslearnedaboutengineeringaspecification

Specificationscontainbugs

Hugevalueinbeingabletorunexistingtestsuites

-Needtobalanceagainstbenefitsofnon-executablespecs

Findwaystoprovidedirectbenefittootherusersofspec

-Theywilldosomeofthetesting/debuggingforyou

-Theywillsupportgettingyourchanges/specadoptedasmasterspec

-CreatesVirtuousCycle

Page 24: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�19

Using Specifications

“End to End Verification of ARM processors with ISA Formal,” CAV 2016

Page 25: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�20

VerificationofImplementations- BoundedModelChecking- Testing(GoldenReference)- DeductiveReasoning

VerificationofClients- FormallyverifyingOScode/etc.- VerifyingCompilers/Linkers

Generation- Testsuites(Concolic)- Simulators- PeepholeOptimisations- BinaryTranslators

Documentation- GeneratePDF/HTML- Interactivespecifications

SpecificationExtension- Testing/Exploration

StaticAnalysis- Abstractinterpretationofbinaries- Decompilationofbinaries- Reverseengineeringtools

InstrumentedExecution- MeasureCoverage- DrivingFuzzTesting

Page 26: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�21

FormallyvalidatingARMprocessors-usinganexistingtool

ARM Specification

ARM Processor

TranslatetoVerilog

VerilogModelChecker

Page 27: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�22

Checkinganinstrucpon

ADD

Page 28: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�22

Checkinganinstrucpon

ADDCMP LDR STR BNE

Context

Page 29: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�23

LessonsLearnedfromvalidatingprocessors

Veryeffectivewaytofindbugsinimplementations

Formallyvalidatingimplementationiseffectiveatfindingbugsinspec

-Trytofindmostofthebugsinyourspecbeforeyoustart

Hugevalueinbeingabletousespectovalidateimplementations

-Helpsgetformalspecificationadoptedaspartofofficialspec

Spec

Page 30: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�24

Formal Validation of Specifications

“Who guards the guards? Formal Validation of ARM v8-M Specifications” OOPSLA 2017

Page 31: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�25

OneSpecificationtorulethemall?

ArchitectureSpec

ComplianceTests

Processors

ReferenceSimulator

Page 32: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�26

Rule JRJC Exit from lockup is by any of the following: • A Cold reset. • A Warm reset. • Entry to Debug state. • Preemption by a higher priority processor exception.

Page 33: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�26

Rule JRJC Exit from lockup is by any of the following: • A Cold reset. • A Warm reset. • Entry to Debug state. • Preemption by a higher priority processor exception.

StateChangeXEventAEventB

StateChangeCEventD

R

Page 34: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�26

Rule JRJC Exit from lockup is by any of the following: • A Cold reset. • A Warm reset. • Entry to Debug state. • Preemption by a higher priority processor exception.

StateChangeXEventAEventB

StateChangeCEventD

R

RuleR:X→A∨B∨C∨D

Page 35: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�27

StateChange Exit from lockup Fell(LockedUp)

Event A Cold reset Called(TakeColdReset)

Event A Warm reset Called(TakeReset)

StateChange Entry to Debug state Rose(Halted)

Event Preemption by a higher priority processor exception

Called(ExceptionEntry)

Page 36: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�28

“EyeballCloseness”Rule JRJC

Exit from lockup is by any of the following: • A Cold reset. • A Warm reset. • Entry to Debug state. • Preemption by a higher priority processor exception.

Fell(LockedUp)→Called(TakeColdReset)∨Called(TakeReset)∨Rose(Halted)∨Called(ExceptionEntry)

Page 37: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�29

Rule VGNW Entry to lockup from an exception causes • Any Fault Status Registers associated with the exception

to be updated. • No update to the exception state, pending or active. • The PC to be set to 0xEFFFFFFE. • EPSR.IT to become UNKNOWN.

In addition, HFSR.FORCED is not set to 1.

OutofdateMisleading

AmbiguousUntestable

Page 38: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�30

Counterexample

v8-M Spec

Rules

Convert Z3SMTSolver

+

~10,000lines ~1,000,000lines

Page 39: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�31

LessonsLearnedfromvalidatingspecifications

Redundancyessentialfordetectingerrors

-Detectedsubtlebugsinsecurity,exceptions,debug,…

-FoundbugsinEnglishprose

Needsetof‘orthogonal’properties

-Invariants,Securityproperties,Reachabilityproperties,etc.

Eyeballcloseness

Neededtotranslatespecificationtoanotherlanguagetoletususeothertools

Page 40: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�32

Making your specificationpublic

Page 41: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�33

PublicreleaseofmachinereadableArmspecification

Enableformalverificaponofsotwareandtools

Machinereadable

Releases:

v8.2(4/2017)

v8.3(10/2017)

v8.4(6/2018)

v8.5(9/2018)hups://developer.arm.com/products/architecture/a-profile/explorapon-toolshups://github.com/alastairreid/mra_toolshups://github.com/herd/herdtools7/blob/master/herd/libdir/aarch64.cat

Page 42: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�34

CambridgeUniversitySpecs/Tools

From“ISASemanticsforARMv8-A,,RISC-V,andCHERI-MIPS,”POPL2019UsedwithpermissionofREMSGroup,CambridgeUniversity

Page 43: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�34

CambridgeUniversitySpecs/Tools

From“ISASemanticsforARMv8-A,,RISC-V,andCHERI-MIPS,”POPL2019UsedwithpermissionofREMSGroup,CambridgeUniversity

x86(ACL2)

Missing?

Page 44: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�34

CambridgeUniversitySpecs/Tools

From“ISASemanticsforARMv8-A,,RISC-V,andCHERI-MIPS,”POPL2019UsedwithpermissionofREMSGroup,CambridgeUniversity

x86(ACL2)

Missing?

ACL2

Missing?

Page 45: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�35

Work in Progress:Security of Architecture Specifications

Page 46: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�36

Validatingsecurityofprocessorarchitectures

Scope

-Hardware-basedSecurityEnforcement(HSE)Mechanisms

-Confidentiality,Integrity,Availability

Challenges

-CompositionalAttacks

-CyclicdependenciesbetweenHSEs

-Microarchitecturalstorage/timingchannels

Page 47: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�37

TheSpecificationBottleneck:ModellingRealWorldArtifacts

-Trustworthiness,ScopeandApplicability

-SignificantEngineeringEffort

-Importanceofsharingspecificationsacrossmanyusers

Spec

Page 48: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

©2017ArmLimited�38

Thanks

Alasdair Armstrong (Cambridge U.)Alex Chadwick (ARM)Ali Zaidi (ARM)Anastasios Deligiannis (ARM)Anthony Fox (Cambridge U.)Ashan Pathirane (ARM)Belaji Venu (ARM)Bradley Smith (ARM)Brian Foley (ARM)Curtis Dunham (ARM)David Gilday (ARM)David Hoyes (ARM)David Seal (ARM)Daniel Bailey (ARM)Erin Shepherd (ARM)Francois Botman (ARM)

George Hawes (ARM)Graeme Barnes (ARM)Isobel Hooper (ARM)Jack Andrews (ARM)Jacob Eapen (ARM)Jon French (Cambridge U.)Kathy Gray (Cambridge U.)Krassy Gochev (ARM)Lewis Russell (ARM)Matthew Leach (ARM)Meenu Gupta (ARM)Michele Riga (ARM)Milosch Meriac (ARM)Nigel Stephens (ARM)Niyas Sait (ARM)Peng Wang (ARM)

Peter Sewell (Cambridge U.)Peter Vrabel (ARM)Richard Grisenthwaite (ARM)Rick Chen (ARM)Simon Bellew (ARM)Thomas Grocutt (ARM)Will Deacon (ARM)Will Keen (ARM)Wojciech Meyer (ARM)(and others)

Page 49: Engineering and Use of Large Formal Specifications Alastair Reid … · Huge value in being able to run existing test suites - Need to balance against benefits of non-executable specs

ThankYou!Danke!Merci!谢谢!ありがとう!Gracias!Kiitos!

©2017ArmLimited�39

@alastair_d_reid

“TrustworthySpecificationsoftheARMv8-Aandv8-Marchitecture,”FMCAD2016“EndtoEndVerificationofARMprocessorswithISAFormal,”CAV2016“Whoguardstheguards?FormalValidationofARMv8-MSpecifications,”OOPSLA2017“ISASemanticsforARMv8-A,,RISC-V,andCHERI-MIPS,”POPL2019

https://alastairreid.github.io/papers/