Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
1118220e
Commit
1118220e
authored
Sep 09, 2020
by
Antoine Kaufmann
Browse files
libnicbm: catch dma transfers larger than buffer size
parent
4998b831
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
libnicbm/include/nicbm.h
libnicbm/include/nicbm.h
+1
-0
libnicbm/nicbm.cc
libnicbm/nicbm.cc
+17
-4
No files found.
libnicbm/include/nicbm.h
View file @
1118220e
...
...
@@ -65,6 +65,7 @@ class Runner {
Device
&
dev
;
uint64_t
mac_addr
;
struct
nicsim_params
nsparams
;
struct
cosim_pcie_proto_dev_intro
dintro
;
volatile
union
cosim_pcie_proto_d2h
*
d2h_alloc
(
void
);
volatile
union
cosim_eth_proto_d2n
*
d2n_alloc
(
void
);
...
...
libnicbm/nicbm.cc
View file @
1118220e
...
...
@@ -66,6 +66,12 @@ void Runner::issue_dma(DMAOp &op)
if
(
op
.
write
)
{
volatile
struct
cosim_pcie_proto_d2h_write
*
write
=
&
msg
->
write
;
if
(
dintro
.
d2h_elen
<
sizeof
(
*
write
)
+
op
.
len
)
{
fprintf
(
stderr
,
"issue_dma: write too big (%zu), can only fit up "
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
d2h_elen
-
sizeof
(
*
write
));
abort
();
}
write
->
req_id
=
(
uintptr_t
)
&
op
;
write
->
offset
=
op
.
dma_addr
;
write
->
len
=
op
.
len
;
...
...
@@ -75,6 +81,14 @@ void Runner::issue_dma(DMAOp &op)
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
else
{
volatile
struct
cosim_pcie_proto_d2h_read
*
read
=
&
msg
->
read
;
if
(
dintro
.
h2d_elen
<
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
)
+
op
.
len
)
{
fprintf
(
stderr
,
"issue_dma: write too big (%zu), can only fit up "
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
h2d_elen
-
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
));
abort
();
}
read
->
req_id
=
(
uintptr_t
)
&
op
;
read
->
offset
=
op
.
dma_addr
;
read
->
len
=
op
.
len
;
...
...
@@ -296,9 +310,8 @@ int Runner::runMain(int argc, char *argv[])
signal
(
SIGINT
,
sigint_handler
);
signal
(
SIGUSR1
,
sigusr1_handler
);
struct
cosim_pcie_proto_dev_intro
di
;
memset
(
&
di
,
0
,
sizeof
(
di
));
dev
.
setup_intro
(
di
);
memset
(
&
dintro
,
0
,
sizeof
(
dintro
));
dev
.
setup_intro
(
dintro
);
nsparams
.
sync_pci
=
1
;
nsparams
.
sync_eth
=
1
;
...
...
@@ -308,7 +321,7 @@ int Runner::runMain(int argc, char *argv[])
nsparams
.
pci_latency
=
PCI_LATENCY
;
nsparams
.
eth_latency
=
ETH_LATENCY
;
nsparams
.
sync_delay
=
SYNC_PERIOD
;
if
(
nicsim_init
(
&
nsparams
,
&
di
))
{
if
(
nicsim_init
(
&
nsparams
,
&
di
ntro
))
{
return
EXIT_FAILURE
;
}
fprintf
(
stderr
,
"sync_pci=%d sync_eth=%d
\n
"
,
nsparams
.
sync_pci
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment