SlideShare una empresa de Scribd logo
1 de 16
© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Low-level Accesses
2© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
After this session, you would know
Various Address Spaces in Linux
Role of Memory Manager in Linux
Accessing the Memory in Kernel Space
Accessing the Device or Hardware
Memory
Registers
Low-level Access in Drivers
3© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Address Spaces in Linux
An Example assuming 32-bit architecture
4GB Process
VA Space 1
User Space
4GB Process
VA Space N
.
.
.
Logical Address
(Non-swappable)
Virtual Address
(Swappable)
3GB
Virtual
Address
for User
1GB VA
for Kernel
Kernel Space
(fixed by kernel)
0x00000000
0xBFFFFFFF
0xFFFFFFFF
0xC0000000
Upto 3GB
Memory
(RAM)
Addressing
Upto 1GB Dev
Addressing
Physical Address Space
(fixed by architecture)
0x00000000
0xBFFFFFFF
0xC0000000
0xFFFFFFFF
Bus Address (incl.
both h/w memory &
registers)
Physical Address
(incl. only memory)
4© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Memory Manager
Provides Access Control to h/w & memory resources
Provides Dynamic Memory to kernel sub-system
Drivers
File Systems
Stacks
Provides Virtual Memory to Kernel & User space
Kernel & User Processes run in their own virtual address spaces
Providing the various features of a Linux system
System reliability, Security
Communication
Program Execution Support
5© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Space Memory Access
Virtual Address for Physical Address
Header: <linux/gfp.h>
unsigned long __get_free_pages(flags, order); etc
void free_pages(addr, order); etc
Header: <linux/slab.h>
void *kmalloc(size_t size, gfp_t flags);
GFP_USER, GFP_KERNEL, GFP_DMA
void kfree(void *obj);
Header: <linux/vmalloc.h>
void *vmalloc(unsigned long size);
void vfree(void *addr);
6© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Space Device Access
Virtual Address for Bus/IO Address
Header: <asm/io.h>
void *ioremap(phys_addr_t bus_addr, unsigned long size);
void iounmap(void *addr);
I/O Memory Access
Header: <asm/io.h>
u[8|16|32] ioread[8|16|32](void *addr);
void iowrite[8|16|32](u[8|16|32] value, void *addr);
Kernel Window: /proc/iomem
Access Permissions
Header: <linux/ioport.h>
struct resource *request_mem_region(resource_size_t start, resource_size_t size, label);
void release_mem_region(resource_size_t start, resource_size_t size);
7© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
x86 Memory & Device Access
x86
CPU
Memory
Controller
Bus
Controller
RAM
Device
Address Space
Address BusData Bus
32
32
32
32
8© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
x86 Hardware Architecture
complete
x86
CPU
North
Bridge
South
Bridge
RAM
(PCI) Device
Address Space
I/O Ports /
Address
Space
I/O Line
Address BusData Bus
32
32
32
32
32
16
9© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
I/O Access (x86* specific)
I/O Port Access
u8 inb(unsigned long port);
u16 inw(unsigned long port);
u32 inl(unsigned long port);
void outb(u8 value, unsigned long port);
void outw(u16 value, unsigned long port);
void outl(u32 value, unsigned long port);
Header: <asm/io.h>
Kernel Window: /proc/ioports
Access Permissions
Header: <linux/ioport.h>
struct resource *request_region(resource_size_t start, resource_size_t size, label);
void release_region(resource_size_t start, resource_size_t size);
© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
DMA Mapping
To Device
PM VM
PA VA
From Device
APIs
dma_addr_t dma_map_single(struct device *, void *, size_t, enum dma_data_direction);
void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction);
Directions
DMA_BIDIRECTIONAL
DMA_TO_DEVICE
DMA_FROM_DEVICE
DMA_NONE
Header: <linux/dma-mapping.h>
© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
DMA Allocation
PM VM
APIs
void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t);
void dma_free_coherent(struct device *, size_t, void *, dma_addr_t);
int dma_set_mask(struct device *, u64 mask);
Header: <linux/dma-mapping.h>
PA VA
12© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Barriers
Heard about Processor Optimization?
void barrier(void);
For surrounding instructions
Header: <linux/kernel.h>
void [r|w|]mb(void);
For surrounding read/write instructions
Header: <asm/system.h>
13© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory & Character Driver
Dynamic Memory Experiments
Preserve latest write in /dev/memory
Control the preserve size using ioctl
Implement seek
14© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Hardware & Character Driver
Digital/Analog I/O Control on the Board
Figure out
Operation Relevant Registers
Hardware Access Addresses
Relevant low-level access APIs to be used
Driver for I/O access over /dev/io
15© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
Various Address Spaces in Linux
Role of Memory Manager in Linux
Accessing the Memory in Kernel Space
Accessing the Device or Hardware
Memory
Registers
Barriers
Low-level Access in Drivers
16© 2010-15 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

Más contenido relacionado

La actualidad más candente (20)

Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Kernel Timing Management
Kernel Timing ManagementKernel Timing Management
Kernel Timing Management
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Architecture Porting
Architecture PortingArchitecture Porting
Architecture Porting
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 

Similar a Low-level Accesses

[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practicalMoabi.com
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIeJin Wu
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationTalal Khaliq
 
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 modeMoabi.com
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits BVBA (freelancer)
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slidesMoabi.com
 
Nios2 and ip core
Nios2 and ip coreNios2 and ip core
Nios2 and ip coreanishgoel
 
my Windows 7 info
my Windows 7 infomy Windows 7 info
my Windows 7 infoisky guard
 
OSDC 2017 | Open POWER for the data center by Werner Fischer
OSDC 2017 | Open POWER for the data center by Werner FischerOSDC 2017 | Open POWER for the data center by Werner Fischer
OSDC 2017 | Open POWER for the data center by Werner FischerNETWAYS
 
OSDC 2017 - Werner Fischer - Open power for the data center
OSDC 2017 - Werner Fischer - Open power for the data centerOSDC 2017 - Werner Fischer - Open power for the data center
OSDC 2017 - Werner Fischer - Open power for the data centerNETWAYS
 
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner Fischer
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner FischerOSDC 2017 | Linux Performance Profiling and Monitoring by Werner Fischer
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner FischerNETWAYS
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfzahixdd
 
Session01_Intro.pdf
Session01_Intro.pdfSession01_Intro.pdf
Session01_Intro.pdfRahnerJames
 
Csw2016 economou nissim-getting_physical
Csw2016 economou nissim-getting_physicalCsw2016 economou nissim-getting_physical
Csw2016 economou nissim-getting_physicalCanSecWest
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 

Similar a Low-level Accesses (20)

RISC-V 30908 patra
RISC-V 30908 patraRISC-V 30908 patra
RISC-V 30908 patra
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIe
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
 
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
 
The Cell Processor
The Cell ProcessorThe Cell Processor
The Cell Processor
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slides
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Nios2 and ip core
Nios2 and ip coreNios2 and ip core
Nios2 and ip core
 
my Windows 7 info
my Windows 7 infomy Windows 7 info
my Windows 7 info
 
OSDC 2017 | Open POWER for the data center by Werner Fischer
OSDC 2017 | Open POWER for the data center by Werner FischerOSDC 2017 | Open POWER for the data center by Werner Fischer
OSDC 2017 | Open POWER for the data center by Werner Fischer
 
OSDC 2017 - Werner Fischer - Open power for the data center
OSDC 2017 - Werner Fischer - Open power for the data centerOSDC 2017 - Werner Fischer - Open power for the data center
OSDC 2017 - Werner Fischer - Open power for the data center
 
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner Fischer
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner FischerOSDC 2017 | Linux Performance Profiling and Monitoring by Werner Fischer
OSDC 2017 | Linux Performance Profiling and Monitoring by Werner Fischer
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdf
 
Session01_Intro.pdf
Session01_Intro.pdfSession01_Intro.pdf
Session01_Intro.pdf
 
Csw2016 economou nissim-getting_physical
Csw2016 economou nissim-getting_physicalCsw2016 economou nissim-getting_physical
Csw2016 economou nissim-getting_physical
 
Cao 2012
Cao 2012Cao 2012
Cao 2012
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 

Más de Anil Kumar Pugalia (20)

Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
References
ReferencesReferences
References
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Power of vi
Power of viPower of vi
Power of vi
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 
Signals
SignalsSignals
Signals
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 

Último

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Último (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Low-level Accesses

  • 1. © 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Low-level Accesses
  • 2. 2© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? After this session, you would know Various Address Spaces in Linux Role of Memory Manager in Linux Accessing the Memory in Kernel Space Accessing the Device or Hardware Memory Registers Low-level Access in Drivers
  • 3. 3© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Address Spaces in Linux An Example assuming 32-bit architecture 4GB Process VA Space 1 User Space 4GB Process VA Space N . . . Logical Address (Non-swappable) Virtual Address (Swappable) 3GB Virtual Address for User 1GB VA for Kernel Kernel Space (fixed by kernel) 0x00000000 0xBFFFFFFF 0xFFFFFFFF 0xC0000000 Upto 3GB Memory (RAM) Addressing Upto 1GB Dev Addressing Physical Address Space (fixed by architecture) 0x00000000 0xBFFFFFFF 0xC0000000 0xFFFFFFFF Bus Address (incl. both h/w memory & registers) Physical Address (incl. only memory)
  • 4. 4© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Memory Manager Provides Access Control to h/w & memory resources Provides Dynamic Memory to kernel sub-system Drivers File Systems Stacks Provides Virtual Memory to Kernel & User space Kernel & User Processes run in their own virtual address spaces Providing the various features of a Linux system System reliability, Security Communication Program Execution Support
  • 5. 5© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Space Memory Access Virtual Address for Physical Address Header: <linux/gfp.h> unsigned long __get_free_pages(flags, order); etc void free_pages(addr, order); etc Header: <linux/slab.h> void *kmalloc(size_t size, gfp_t flags); GFP_USER, GFP_KERNEL, GFP_DMA void kfree(void *obj); Header: <linux/vmalloc.h> void *vmalloc(unsigned long size); void vfree(void *addr);
  • 6. 6© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Space Device Access Virtual Address for Bus/IO Address Header: <asm/io.h> void *ioremap(phys_addr_t bus_addr, unsigned long size); void iounmap(void *addr); I/O Memory Access Header: <asm/io.h> u[8|16|32] ioread[8|16|32](void *addr); void iowrite[8|16|32](u[8|16|32] value, void *addr); Kernel Window: /proc/iomem Access Permissions Header: <linux/ioport.h> struct resource *request_mem_region(resource_size_t start, resource_size_t size, label); void release_mem_region(resource_size_t start, resource_size_t size);
  • 7. 7© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. x86 Memory & Device Access x86 CPU Memory Controller Bus Controller RAM Device Address Space Address BusData Bus 32 32 32 32
  • 8. 8© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. x86 Hardware Architecture complete x86 CPU North Bridge South Bridge RAM (PCI) Device Address Space I/O Ports / Address Space I/O Line Address BusData Bus 32 32 32 32 32 16
  • 9. 9© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. I/O Access (x86* specific) I/O Port Access u8 inb(unsigned long port); u16 inw(unsigned long port); u32 inl(unsigned long port); void outb(u8 value, unsigned long port); void outw(u16 value, unsigned long port); void outl(u32 value, unsigned long port); Header: <asm/io.h> Kernel Window: /proc/ioports Access Permissions Header: <linux/ioport.h> struct resource *request_region(resource_size_t start, resource_size_t size, label); void release_region(resource_size_t start, resource_size_t size);
  • 10. © 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. DMA Mapping To Device PM VM PA VA From Device APIs dma_addr_t dma_map_single(struct device *, void *, size_t, enum dma_data_direction); void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction); Directions DMA_BIDIRECTIONAL DMA_TO_DEVICE DMA_FROM_DEVICE DMA_NONE Header: <linux/dma-mapping.h>
  • 11. © 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. DMA Allocation PM VM APIs void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t); void dma_free_coherent(struct device *, size_t, void *, dma_addr_t); int dma_set_mask(struct device *, u64 mask); Header: <linux/dma-mapping.h> PA VA
  • 12. 12© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Barriers Heard about Processor Optimization? void barrier(void); For surrounding instructions Header: <linux/kernel.h> void [r|w|]mb(void); For surrounding read/write instructions Header: <asm/system.h>
  • 13. 13© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Memory & Character Driver Dynamic Memory Experiments Preserve latest write in /dev/memory Control the preserve size using ioctl Implement seek
  • 14. 14© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Hardware & Character Driver Digital/Analog I/O Control on the Board Figure out Operation Relevant Registers Hardware Access Addresses Relevant low-level access APIs to be used Driver for I/O access over /dev/io
  • 15. 15© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? Various Address Spaces in Linux Role of Memory Manager in Linux Accessing the Memory in Kernel Space Accessing the Device or Hardware Memory Registers Barriers Low-level Access in Drivers
  • 16. 16© 2010-15 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?