Skip to content

Commit c1b0020

Browse files
configs: adds new configs to simulate rowhammer
This change adds sample configs to simulate rowhammer using hammersim. Change-Id: I8840c55498ad379e953550f765b4880901a120ca Signed-off-by: Kaustav Goswami <kggoswami@ucdavis.edu>
1 parent e2ecd26 commit c1b0020

10 files changed

+1726
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Copyright (c) 2021 The Regents of the University of California
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are
6+
# met: redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer;
8+
# redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution;
11+
# neither the name of the copyright holders nor the names of its
12+
# contributors may be used to endorse or promote products derived from
13+
# this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
"""
28+
29+
This script shows an example of running a full system Ubuntu boot simulation
30+
using the gem5 library. This simulation boots Ubuntu 18.04 using 2 KVM CPU
31+
cores. The simulation then switches to 2 Timing CPU cores before running an
32+
echo statement.
33+
34+
Usage
35+
-----
36+
37+
```
38+
scons build/X86/gem5.opt
39+
./build/X86/gem5.opt configs/example/gem5_library/x86-ubuntu-run-with-kvm.py
40+
```
41+
"""
42+
import os
43+
44+
from numpy import partition
45+
from gem5.utils.requires import requires
46+
from gem5.components.boards.x86_board import X86Board
47+
from gem5.components.memory.single_channel import SingleChannelDDR3_1600
48+
from gem5.components.processors.simple_switchable_processor import (
49+
SimpleSwitchableProcessor,
50+
)
51+
from gem5.components.processors.cpu_types import CPUTypes
52+
from gem5.isas import ISA
53+
from gem5.coherence_protocol import CoherenceProtocol
54+
from gem5.resources.resource import *
55+
from gem5.simulate.simulator import Simulator
56+
from gem5.simulate.exit_event import ExitEvent
57+
58+
# This runs a check to ensure the gem5 binary is compiled to X86 and to the
59+
# MESI Two Level coherence protocol.
60+
requires(
61+
isa_required=ISA.X86,
62+
coherence_protocol_required=CoherenceProtocol.MESI_TWO_LEVEL,
63+
kvm_required=True,
64+
)
65+
66+
from gem5.components.cachehierarchies.classic.private_l1_private_l2_cache_hierarchy import (
67+
PrivateL1PrivateL2CacheHierarchy,
68+
)
69+
70+
# Here we setup a MESI Two Level Cache Hierarchy.
71+
cache_hierarchy = PrivateL1PrivateL2CacheHierarchy(
72+
l1d_size="16kB",
73+
l1i_size="16kB",
74+
l2_size="256kB",
75+
)
76+
77+
# Setup the system memory.
78+
memory = SingleChannelDDR3_1600(size="3GB")
79+
80+
# Here we setup the processor. This is a special switchable processor in which
81+
# a starting core type and a switch core type must be specified. Once a
82+
# configuration is instantiated a user may call `processor.switch()` to switch
83+
# from the starting core types to the switch core types. In this simulation
84+
# we start with KVM cores to simulate the OS boot, then switch to the Timing
85+
# cores for the command we wish to run after boot.
86+
processor = SimpleSwitchableProcessor(
87+
starting_core_type=CPUTypes.KVM,
88+
switch_core_type=CPUTypes.TIMING,
89+
num_cores=2,
90+
)
91+
92+
# Here we setup the board. The X86Board allows for Full-System X86 simulations.
93+
board = X86Board(
94+
clk_freq="3GHz",
95+
processor=processor,
96+
memory=memory,
97+
cache_hierarchy=cache_hierarchy,
98+
)
99+
100+
# Here we set the Full System workload.
101+
# The `set_kernel_disk_workload` function for the X86Board takes a kernel, a
102+
# disk image, and, optionally, a command to run.
103+
104+
# This is the command to run after the system has booted. The first `m5 exit`
105+
# will stop the simulation so we can switch the CPU cores from KVM to timing
106+
# and continue the simulation to run the echo command, sleep for a second,
107+
# then, again, call `m5 exit` to terminate the simulation. After simulation
108+
# has ended you may inspect `m5out/system.pc.com_1.device` to see the echo
109+
# output.
110+
command = (
111+
"m5 exit;" + "echo 'This is running on Timing CPU cores.';" + "sleep 1;"
112+
)
113+
114+
board.set_kernel_disk_workload(
115+
# The x86 linux kernel will be automatically downloaded to the if not
116+
# already present.
117+
kernel=CustomResource(
118+
os.path.join(
119+
os.path.expanduser("~"), ".cache/gem5/x86-linux-kernel-5.4.49"
120+
)
121+
),
122+
# The x86 ubuntu image will be automatically downloaded to the if not
123+
# already present.
124+
disk_image=CustomDiskImageResource(
125+
os.path.join(
126+
os.path.expanduser("~"), ".cache/gem5/x86-ubuntu-18.04-img"
127+
),
128+
disk_root_partition="1",
129+
),
130+
readfile_contents=command,
131+
)
132+
133+
simulator = Simulator(
134+
board=board,
135+
on_exit_event={
136+
# Here we want override the default behavior for the first m5 exit
137+
# exit event. Instead of exiting the simulator, we just want to
138+
# switch the processor. The 2nd m5 exit after will revert to using
139+
# default behavior where the simulator run will exit.
140+
ExitEvent.EXIT: (func() for func in [processor.switch]),
141+
},
142+
)
143+
simulator.run()
144+
simulator.run()
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright (c) 2021 The Regents of the University of California
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are
6+
# met: redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer;
8+
# redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution;
11+
# neither the name of the copyright holders nor the names of its
12+
# contributors may be used to endorse or promote products derived from
13+
# this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
"""
28+
This gem5 configuation script runs `rowhammer-test` on the rowhammer model of
29+
gem5.
30+
31+
This is setup is the close to the simplest setup possible using the gem5
32+
library. It does not contain any kind of caching, IO, or any non-essential
33+
components.
34+
35+
Usage
36+
-----
37+
38+
```
39+
scons build/ARM/gem5.opt
40+
./build/ARM/gem5.opt configs/gem5_library/arm-hello.py
41+
```
42+
"""
43+
44+
import os
45+
from gem5.isas import ISA
46+
from gem5.utils.requires import requires
47+
from gem5.resources.resource import CustomResource
48+
from gem5.components.memory import SingleChannelDDR3_1600
49+
from gem5.components.processors.cpu_types import CPUTypes
50+
from gem5.components.boards.simple_board import SimpleBoard
51+
from gem5.components.cachehierarchies.classic.no_cache import NoCache
52+
from gem5.components.processors.simple_processor import SimpleProcessor
53+
from gem5.simulate.simulator import Simulator
54+
55+
# This check ensures the gem5 binary is compiled to the ARM ISA target. If not,
56+
# an exception will be thrown.
57+
requires(isa_required=ISA.X86)
58+
59+
# In this setup we don't have a cache. `NoCache` can be used for such setups.
60+
cache_hierarchy = NoCache()
61+
62+
# We use a single channel DDR3_1600 memory system
63+
memory = SingleChannelDDR3_1600(size="1GB")
64+
65+
# We use a simple Timing processor with one core.
66+
processor = SimpleProcessor(cpu_type=CPUTypes.TIMING, num_cores=1)
67+
68+
# The gem5 library simble board which can be used to run simple SE-mode
69+
# simulations.
70+
board = SimpleBoard(
71+
clk_freq="3GHz",
72+
processor=processor,
73+
memory=memory,
74+
cache_hierarchy=cache_hierarchy,
75+
)
76+
77+
# Here we set the workload. In this case we want to run a simple "Hello World!"
78+
# program compiled to the ARM ISA. The `Resource` class will automatically
79+
# download the binary from the gem5 Resources cloud bucket if it's not already
80+
# present.
81+
board.set_se_binary_workload(
82+
# The `Resource` class reads the `resources.json` file from the gem5
83+
# resources repository:
84+
# https://gem5.googlesource.com/public/gem5-resource.
85+
# Any resource specified in this file will be automatically retrieved.
86+
# At the time of writing, this file is a WIP and does not contain all
87+
# resources. Jira ticket: https://gem5.atlassian.net/browse/GEM5-1096
88+
CustomResource(
89+
os.path.join(
90+
os.getcwd(), "tests/test-progs/rowhammer/sequential_v2"
91+
) # rowhammer_test")
92+
)
93+
)
94+
95+
# Lastly we run the simulation.
96+
simulator = Simulator(board=board, full_system=False)
97+
simulator.run() # max_ticks = 7000000000)
98+
99+
print(
100+
"Exiting @ tick {} because {}.".format(
101+
simulator.get_current_tick(),
102+
simulator.get_last_exit_event_cause(),
103+
)
104+
)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Copyright (c) 2021 The Regents of the University of California
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are
6+
# met: redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer;
8+
# redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution;
11+
# neither the name of the copyright holders nor the names of its
12+
# contributors may be used to endorse or promote products derived from
13+
# this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
"""
28+
29+
This script shows an example of running a full system Ubuntu boot simulation
30+
using the gem5 library. This simulation boots Ubuntu 18.04 using 2 KVM CPU
31+
cores. The simulation then switches to 2 Timing CPU cores before running an
32+
echo statement.
33+
34+
Usage
35+
-----
36+
37+
```
38+
scons build/X86/gem5.opt
39+
./build/X86/gem5.opt configs/example/gem5_library/x86-ubuntu-run-with-kvm.py
40+
```
41+
"""
42+
43+
import os
44+
from gem5.resources.resource import CustomResource, CustomDiskImageResource
45+
from gem5.utils.requires import requires
46+
from gem5.components.boards.x86_board import X86Board
47+
from gem5.components.memory.single_channel import SingleChannelDDR3_1600
48+
from gem5.components.processors.simple_switchable_processor import (
49+
SimpleSwitchableProcessor,
50+
)
51+
from gem5.components.processors.cpu_types import CPUTypes
52+
from gem5.isas import ISA
53+
from gem5.coherence_protocol import CoherenceProtocol
54+
from gem5.resources.resource import Resource
55+
from gem5.simulate.simulator import Simulator
56+
from gem5.simulate.exit_event import ExitEvent
57+
58+
# This runs a check to ensure the gem5 binary is compiled to X86 and to the
59+
# MESI Two Level coherence protocol.
60+
requires(isa_required=ISA.X86, kvm_required=True)
61+
62+
from gem5.components.cachehierarchies.classic.private_l1_private_l2_cache_hierarchy import (
63+
PrivateL1PrivateL2CacheHierarchy,
64+
)
65+
66+
# Here we setup a MESI Two Level Cache Hierarchy.
67+
cache_hierarchy = PrivateL1PrivateL2CacheHierarchy(
68+
l1d_size="16kB", l1i_size="16kB", l2_size="256kB"
69+
)
70+
71+
# Setup the system memory.
72+
memory = SingleChannelDDR3_1600(size="3GB")
73+
74+
# Here we setup the processor. This is a special switchable processor in which
75+
# a starting core type and a switch core type must be specified. Once a
76+
# configuration is instantiated a user may call `processor.switch()` to switch
77+
# from the starting core types to the switch core types. In this simulation
78+
# we start with KVM cores to simulate the OS boot, then switch to the Timing
79+
# cores for the command we wish to run after boot.
80+
processor = SimpleSwitchableProcessor(
81+
starting_core_type=CPUTypes.KVM,
82+
switch_core_type=CPUTypes.TIMING,
83+
num_cores=2,
84+
)
85+
86+
# Here we setup the board. The X86Board allows for Full-System X86 simulations.
87+
board = X86Board(
88+
clk_freq="3GHz",
89+
processor=processor,
90+
memory=memory,
91+
cache_hierarchy=cache_hierarchy,
92+
)
93+
94+
# Here we set the Full System workload.
95+
# The `set_kernel_disk_workload` function for the X86Board takes a kernel, a
96+
# disk image, and, optionally, a command to run.
97+
98+
# This is the command to run after the system has booted. The first `m5 exit`
99+
# will stop the simulation so we can switch the CPU cores from KVM to timing
100+
# and continue the simulation to run the echo command, sleep for a second,
101+
# then, again, call `m5 exit` to terminate the simulation. After simulation
102+
# has ended you may inspect `m5out/system.pc.com_1.device` to see the echo
103+
# output.
104+
command = "rowhammer_test"
105+
# + "echo 'This is running on Timing CPU cores.';" \
106+
# + "sleep 1;"
107+
# + "m5 exit;"
108+
109+
board.set_kernel_disk_workload(
110+
# The x86 linux kernel will be automatically downloaded to the if not
111+
# already present.
112+
kernel=CustomResource(
113+
os.path.join(
114+
os.path.expanduser("~"), ".cache/gem5/x86-linux-kernel-5.4.49"
115+
)
116+
),
117+
# The x86 ubuntu image will be automatically downloaded to the if not
118+
# already present.
119+
disk_image=CustomDiskImageResource(
120+
os.path.join(os.getcwd(), "rh.img"), disk_root_partition="1"
121+
),
122+
readfile_contents=command,
123+
)
124+
125+
simulator = Simulator(
126+
board=board,
127+
on_exit_event={
128+
# Here we want override the default behavior for the first m5 exit
129+
# exit event. Instead of exiting the simulator, we just want to
130+
# switch the processor. The 2nd m5 exit after will revert to using
131+
# default behavior where the simulator run will exit.
132+
ExitEvent.EXIT: (func() for func in [processor.switch]),
133+
},
134+
)
135+
simulator.run()
136+
simulator.run()

0 commit comments

Comments
 (0)