-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkernel_panda.c
614 lines (501 loc) · 21.1 KB
/
kernel_panda.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/***
The below code tests for 60 secs for running a loop continuously
In the code, we can execute it for 60 secs
It initialises the PUF Memory location
Performs Rowhammering
Reads Puf memory location
***/
/***********Header Files************/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h> // for threads
#include <linux/time.h> // for using jiffies
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
/************ Variable Declaration *********/
static unsigned long puf_init_val = 0x0;
module_param(puf_init_val, uint, S_IRUGO);
static unsigned long puf_delaysec =60;
module_param(puf_delaysec , uint, S_IRUGO);
static unsigned long puf_base_address =0xa0000000;
module_param(puf_base_address, uint, S_IRUGO);
static char *mystring = "once";
module_param(mystring, charp, S_IRUGO);
MODULE_PARM_DESC(mystring, "A character string");
static unsigned long hammer_init_value = 0x0;
module_param(hammer_init_value, uint, S_IRUGO);
static unsigned long no_hammer_rows = 32;
module_param(no_hammer_rows, uint, S_IRUGO);
static unsigned long no_PUF_rows = 32;
module_param(no_PUF_rows, uint, S_IRUGO);
char *hammerall = "all";
unsigned int puf_complete_flag=0;
unsigned int PUF_size=1024; //1024*4 byte//
unsigned int OMAP_EMIF2 =0x4d000010;
unsigned int OMAP_EMIF2_SHW =0x4d000014;
unsigned int OMAP_EMIF2_temp_polling =0x4d0000cc;
#define same_bank_row_size 0x8000
#define row_size 0x400
//static struct delayed_work PUF_work; -- Used by earlier method for scheduling the task
// Below are variables for thread creation
len = sizeof(struct task_struct);
struct task_struct *thread1;
/************Functions for Reading and Writing**************************/
/*
* This function writes the value write_vale to the system address system_addr.
*/
void write_OMAP_system_address(unsigned int system_addr,unsigned int write_val){
void *write_virtaddr;
unsigned int written_value;
write_virtaddr = ioremap(system_addr,sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=write_val;
iounmap(write_virtaddr);
}
/*
* This function reads the value from system address system_addr.
*/
void read_OMAP_system_address(unsigned int system_addr){
void *read_virtaddr;
read_virtaddr = ioremap(system_addr, sizeof(unsigned int));
printk(KERN_INFO "PUF Read:0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr),system_addr);
iounmap(read_virtaddr);
}
/*
* This function disables the DRAM refresh of the external memory interface 2 (EMIF2). Note, that
* if DRAM refresh of EMIF1 is disabled, it will not be possible to boot a linux kernel.
*/
void disable_refresh(void){
void *read_virtaddr; //read address for EMIF 2 register
void *write_virtaddr; //write address for EMIF 2 register
write_virtaddr = ioremap(OMAP_EMIF2,sizeof(unsigned int));
read_virtaddr = ioremap(OMAP_EMIF2, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x80000000;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr),OMAP_EMIF2);
iounmap(read_virtaddr);
iounmap(write_virtaddr);
write_virtaddr = ioremap(OMAP_EMIF2_SHW,sizeof(unsigned int));
read_virtaddr = ioremap(OMAP_EMIF2_SHW, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x80000000;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2_SHW);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr),OMAP_EMIF2_SHW);
iounmap(read_virtaddr);
iounmap(write_virtaddr);
write_virtaddr = ioremap( OMAP_EMIF2_temp_polling,sizeof(unsigned int));
read_virtaddr = ioremap( OMAP_EMIF2_temp_polling, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x08016893;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2_temp_polling);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr), OMAP_EMIF2_temp_polling);
printk(KERN_INFO "Temp polling alert disabled");
printk(KERN_INFO "Refresh Disabled at EMIF2");
iounmap(read_virtaddr);
iounmap(write_virtaddr);
}
/*
* This function enables the DRAM refresh of the external memory interface 2 (EMIF2).
*/
void enable_refresh(void){
void *read_virtaddr; //read address for EMIF 2 register
void *write_virtaddr; //write address for EMIF 2 register
write_virtaddr = ioremap(OMAP_EMIF2,sizeof(unsigned int));
read_virtaddr = ioremap(OMAP_EMIF2, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x00000618;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr),OMAP_EMIF2);
iounmap(read_virtaddr);
iounmap(write_virtaddr);
write_virtaddr = ioremap(OMAP_EMIF2_SHW,sizeof(unsigned int));
read_virtaddr = ioremap(OMAP_EMIF2_SHW, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x00000618;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2_SHW);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr),OMAP_EMIF2_SHW);
iounmap(read_virtaddr);
iounmap(write_virtaddr);
write_virtaddr = ioremap( OMAP_EMIF2_temp_polling,sizeof(unsigned int));
read_virtaddr = ioremap( OMAP_EMIF2_temp_polling, sizeof(unsigned int));
*((unsigned int*)write_virtaddr)=0x58016893;
printk(KERN_INFO "EMIF 2 REG Write 0x%08x at 0x%08x\n",*((unsigned int*)write_virtaddr),OMAP_EMIF2_temp_polling);
printk(KERN_INFO "EMIF 2 REG Read 0x%08x at 0x%08x\n",*((unsigned int*)read_virtaddr), OMAP_EMIF2_temp_polling);
printk(KERN_INFO "Temp polling alert enabled");
printk(KERN_INFO "Refresh enabled at EMIF2");
iounmap(read_virtaddr);
iounmap(write_virtaddr);
}
/*
* This function reads the contents of the PUF memory range.
*/
/* The below code is for testing purposes
*static unsigned int PUF_read_query()
*{
unsigned int addr,puf_read_loop,puf_read_vale;
puf_read_vale=0;
addr=0xa0000000;
printk(KERN_INFO "PUF Query START.\n");
for(puf_read_loop=0;puf_read_loop<PUF_size;puf_read_loop++){
read_OMAP_system_address(addr);
addr=addr+4;
}
printk(KERN_INFO "PUF Query END.\n");
enable_refresh();
return puf_read_vale;
}*/
void read_row(unsigned int row_base_address){
unsigned int puf_read_value=0x0;
unsigned int puf_address=row_base_address;
for(puf_address=row_base_address;puf_address<(row_base_address+row_size);puf_address+=4){
read_OMAP_system_address(puf_address);
}
}
void Read_puf(unsigned int puf_base_address,unsigned int no_PUF_rows,unsigned int pair_alternate_flag){
unsigned int current_row=0;
unsigned int puf_address=0;
puf_address=puf_base_address+same_bank_row_size; //Setting base address for PUF section @ ROW 1
printk(KERN_INFO "[i] Starting PUF read-out\n");
switch(pair_alternate_flag){ //Set Hammer rows
case 0:
{
printk(KERN_INFO "[i] Single-Sided Rowhammer (SSRH)\n");
if(no_PUF_rows==1){
//address_decode(puf_address,0); //Decode ROW and COL address form system address
read_row(puf_address);
}
else{
for(current_row=0;current_row<no_PUF_rows/2;current_row++){
//address_decode(puf_address,0); //Decode ROW and COL address form system address
read_row(puf_address);
puf_address=puf_address+same_bank_row_size;
//address_decode(puf_address,0); //Decode ROW and COL address form system address
read_row(puf_address);
puf_address=puf_address+(2*same_bank_row_size);
}
}
break;
}
default:
{
printk(KERN_INFO "PUF Alternate Mode\n");
for(current_row=0;current_row<no_PUF_rows*2;current_row++){
if(current_row%2!=0){
//address_decode(puf_address,0); //Decode ROW and COL address form system address
read_row(puf_address);
puf_address=puf_base_address+((current_row+2)*same_bank_row_size);
}
}
break;
}
}
printk(KERN_INFO "[i] Finished PUF read-out\n");
}
/*
* This function writes the initialization value to the PUF memory range.
*/
/* The below code is for testing purposes
static void PUF_write_query(void){
unsigned int addr;
unsigned int puf_write_loop;
puf_write_loop=0;
addr=0xa0000000;
for(puf_write_loop=0;puf_write_loop<PUF_size;puf_write_loop++){
write_OMAP_system_address(addr,puf_init_val);
addr=addr+4;
}
}
*/
void hammering_rows(unsigned int puf_base_address,unsigned int no_hammer_rows,unsigned int pair_alternate_flag){
unsigned int hammer_address=0;
unsigned int x=0;
void *read_virtaddr;
unsigned int current_row=0;
hammer_address=puf_base_address; //Setting base address for Hammer section @ ROW 0
switch(pair_alternate_flag){
case 0:
{
if(no_hammer_rows==1){
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
read_virtaddr = ioremap(hammer_address, sizeof(unsigned int));
x = *((unsigned int*)read_virtaddr);
iounmap(read_virtaddr);
hammer_address=hammer_address+(1024*same_bank_row_size);
read_virtaddr = ioremap(hammer_address, sizeof(unsigned int));
x = *((unsigned int*)read_virtaddr);
iounmap(read_virtaddr);
}else{
for(current_row=0;current_row<(no_hammer_rows/2)+1;current_row++){
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
read_virtaddr = ioremap(hammer_address, sizeof(unsigned int));
x = *((unsigned int*)read_virtaddr);
iounmap(read_virtaddr);
hammer_address=hammer_address+(3*same_bank_row_size);
}
}
break;
}
default:
{
for(current_row=0;current_row<=no_hammer_rows*2;current_row++){
if(current_row%2==0){
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
read_virtaddr = ioremap(hammer_address, sizeof(unsigned int));
x = *((unsigned int*)read_virtaddr);
iounmap(read_virtaddr);
hammer_address=puf_base_address+((current_row+2)*same_bank_row_size);
}
}
break;
}
}
}
void write_row(unsigned int row_base_address,unsigned int write_value){
unsigned int puf_address=row_base_address;
for(puf_address=row_base_address;puf_address<(row_base_address+row_size);puf_address+=4){
write_OMAP_system_address(puf_address,write_value);
}
}
void Init_puf_and_hammer_rows(unsigned int puf_base_address,unsigned int no_PUF_rows,unsigned int puf_init_value,unsigned int no_hammer_rows,unsigned int hammer_init_value,unsigned int pair_alternate_flag){
unsigned int current_row=0;
unsigned int puf_address=0;
unsigned int hammer_address=0;
//Setting base address for PUF section @ ROW 1
puf_address=puf_base_address+same_bank_row_size;
//Setting base address for Hammer section @ ROW 0
hammer_address=puf_base_address;
printk(KERN_INFO "[i] Initialiting PUF & hammer rows\n");
//Set Hammer rows
switch(pair_alternate_flag){
case 0:
{
printk(KERN_INFO "[i] Single-Sided Rowhammer (SSRH)\n");
//address_decode(puf_address,0); //Decode ROW and COL address form system address
if(no_PUF_rows==1){
write_row(puf_address,puf_init_value);
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
write_row(hammer_address,hammer_init_value);
}else{
for(current_row=0;current_row<no_PUF_rows/2;current_row++){
//address_decode(puf_address,0); //Decode ROW and COL address form system address
write_row(puf_address,puf_init_value);
puf_address=puf_address+same_bank_row_size;
//address_decode(puf_address,0); //Decode ROW and COL address form system address
write_row(puf_address,puf_init_value);
puf_address=puf_address+(2*same_bank_row_size);
}
for(current_row=0;current_row<(no_hammer_rows/2)+1;current_row++){
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
write_row(hammer_address,hammer_init_value);
hammer_address=hammer_address+(3*same_bank_row_size);
}
}
break;
}
default:
{
printk(KERN_INFO "[i] Double-Sided Rowhammer (SSRH)\n");
for(current_row=0;current_row<no_PUF_rows*2;current_row++){
if(current_row%2!=0){
//address_decode(puf_address,0); //Decode ROW and COL address form system address
write_row(puf_address,puf_init_value);
puf_address=puf_base_address+((current_row+2)*same_bank_row_size);
}
}
for(current_row=0;current_row<=no_hammer_rows*2;current_row++){
if(current_row%2==0){
//address_decode(hammer_address,0); //Decode ROW and COL address form system address
write_row(hammer_address,hammer_init_value);
hammer_address=puf_base_address+((current_row+2)*same_bank_row_size);
}
}
break;
}
}
printk(KERN_INFO "[i] Finished initialiting PUF & hammer rows\n");
return;
}
void get_puf(unsigned int base_address_puf){
//PUF code begin
unsigned int puf_init_value=0x0; //PUF Init Value
unsigned int hammer_number=0; //Number of hammers
unsigned int measurment_loop=0; //Loop variable for measurements
unsigned int no_of_measurements_per_sampledecay=20; //number of sample per sample decay
unsigned int hammer_flag=0x1; //Hammer Flag.. Hammer Yes or No
unsigned int no_PUF_rows=32; //No of Rows for PUF > 1Row has 1024 words total size:4KB:::
unsigned int no_hammer_rows=1; //No of Rows for Hammer > 1Row has 1024 words total size:4KB::: e.g No of Hammer rows is 8
unsigned int hammer_init_value=0x0; //Hammer Rows init Value
int puf_row_select=0;
int puf_init_select=0;
int RH_init_select=0;
unsigned long pair_or_alternate_flag=0x0; // 0x1: ALT (DSRH), 0x0: PRH (SSRH)
// The below is code for timing specifications
unsigned int currentdecay=0; //current decay in running loop
unsigned int Sample_delay=60*HZ; //Measurement sample decay(s)
unsigned int total_delay=120*HZ; //Total decay time(s)
unsigned long current_timer_value=0; //current Timer value in msec,Reference to get timer value from this point
unsigned long relative_decay_time=0x0; //Decay time relative to starting of application
unsigned long j0,j1;
int delay = puf_delaysec*HZ;
while(puf_init_select<3){ //begin multiple test with multiple ending loop
//Set rows
switch(puf_row_select){
case 0: no_hammer_rows=1;no_PUF_rows=1; break;
case 1: no_hammer_rows=8;no_PUF_rows=8; break;
case 2: no_hammer_rows=32;no_PUF_rows=32; break;
default:
no_hammer_rows=1;
no_PUF_rows=1;
puf_row_select=0;
RH_init_select++;
break;
}
//Set Hammer row IV
switch(RH_init_select){
case 0: hammer_init_value=0x0; break;
case 1: hammer_init_value=0x55555555; break;
case 2: hammer_init_value=0xaaaaaaaa; break;
case 3: hammer_init_value=0xffffffff; break;
default:
hammer_init_value=0x0;
RH_init_select=0;
puf_init_select++;
break;
}
//Set PUF row IV
switch(puf_init_select){
case 0: puf_init_value=0x0; break;
case 1: puf_init_value=0xaaaaaaaa; break;
case 2: puf_init_value=0xffffffff; break;
default:puf_init_value=0x0; break;
}
printk(KERN_INFO "[i] Starting the Rowhammer PUF for PandaBoard\n");
printk(KERN_INFO "Number of PUF rows: %d PUF init Value :%x Rowhammer rows init Value:%x\n",no_PUF_rows,puf_init_value,hammer_init_value);
// Iterating the individual measurements
for(measurment_loop=0;measurment_loop<no_of_measurements_per_sampledecay;measurment_loop++){
printk(KERN_INFO "[i] Start measurement: %d\n",measurment_loop);
// Iterating the invidivual decay times
for(currentdecay=Sample_delay;currentdecay<=total_delay;currentdecay+=Sample_delay){
printk(KERN_INFO "[i] Start decaytime: %d\n",currentdecay/HZ);
disable_refresh();
Init_puf_and_hammer_rows(base_address_puf,no_PUF_rows,puf_init_value,no_PUF_rows,hammer_init_value,pair_or_alternate_flag);
printk(KERN_INFO "[i]\tTimer elapsed since its reset %lu sec\n",current_timer_value/HZ);
printk(KERN_INFO "[i] Decay: %d sec\n",currentdecay/HZ);
printk(KERN_INFO "[i]\tRelative Decay: %lu msec\n",relative_decay_time);
j0 = jiffies;
j1 = j0 + currentdecay;
while (time_before(jiffies, j1)){
//Rowhammer Code here
if(hammer_flag==1){
hammering_rows(base_address_puf,no_hammer_rows,pair_or_alternate_flag);
hammer_number++;
schedule();
}
}
printk(KERN_INFO "[i] Total hammer attempts per row: %d\n",hammer_number);
enable_refresh();
//printk(KERN_INFO "[i] Starting PUF read-out\n");
Read_puf(base_address_puf,no_PUF_rows,pair_or_alternate_flag);
//printk(KERN_INFO "[i] PUF reading end\n");
printk(KERN_INFO KERN_INFO"[i] Finished PUF query for decaytime: %d\n",currentdecay);
hammer_number=0;
}
printk(KERN_INFO"End measurement:%d\n",measurment_loop);
}
puf_row_select++;
}
return;
}
//End get_puf function
// The below function runs only once
void get_puf_once(unsigned int base_address_puf){
//PUF code begin
unsigned int hammer_number=0; //Number of hammers
unsigned int measurment_loop=0; //Loop variable for measurements
unsigned int no_of_measurements_per_sampledecay=1; //number of sample per sample decay
unsigned int hammer_flag=0x1; //Hammer Flag.. Hammer Yes or No
unsigned long pair_or_alternate_flag=0x0; // 0x1: ALT (DSRH), 0x0: PRH (SSRH)
// The below is code for timing specifications
unsigned int currentdecay=0; //current decay in running loop
unsigned int Sample_delay=puf_delaysec*HZ; //Measurement sample decay(s)
unsigned int total_delay=2*puf_delaysec*HZ; //Total decay time(s)
unsigned long current_timer_value=0; //current Timer value in msec,Reference to get timer value from this point
unsigned long relative_decay_time=0x0; //Decay time relative to starting of application
unsigned long j0,j1;
printk(KERN_INFO "[i] Starting the Rowhammer PUF for PandaBoard\n");
printk(KERN_INFO "Number of PUF rows: %d PUF init Value :%x Rowhammer rows init Value:%x\n",no_PUF_rows,puf_init_val,hammer_init_value);
// Iterating the individual measurements
for(measurment_loop=0;measurment_loop<no_of_measurements_per_sampledecay;measurment_loop++){
printk(KERN_INFO "[i] Start measurement: %d\n",measurment_loop);
// Iterating the invidivual decay times
for(currentdecay=Sample_delay;currentdecay<=total_delay;currentdecay+=Sample_delay){
printk(KERN_INFO "[i] Start decaytime: %d\n",currentdecay/HZ);
disable_refresh();
Init_puf_and_hammer_rows(base_address_puf,no_PUF_rows,puf_init_val,no_PUF_rows,hammer_init_value,pair_or_alternate_flag);
printk(KERN_INFO "[i]\tTimer elapsed since its reset %lu sec\n",current_timer_value/HZ);
printk(KERN_INFO "[i] Decay: %d sec\n",currentdecay/HZ);
printk(KERN_INFO "[i]\tRelative Decay: %lu msec\n",relative_decay_time);
j0 = jiffies;
j1 = j0 + currentdecay;
while (time_before(jiffies, j1)){
//Rowhammer Code here
if(hammer_flag==1){
hammering_rows(base_address_puf,no_hammer_rows,pair_or_alternate_flag);
hammer_number++;
schedule();
}
}
printk(KERN_INFO "[i] Total hammer attempts per row: %d\n",hammer_number);
enable_refresh();
//printk(KERN_INFO "[i] Starting PUF read-out\n");
Read_puf(base_address_puf,no_PUF_rows,pair_or_alternate_flag);
//printk(KERN_INFO "[i] PUF reading end\n");
printk(KERN_INFO KERN_INFO"[i] Finished PUF query for decaytime: %d\n",currentdecay);
hammer_number=0;
}
printk(KERN_INFO"End measurement:%d\n",measurment_loop);
}
return;
}
/*
The below function takes care of timing so as to run the program accordingly
*/
/*In the call to kthread_create we have passed the following arguments
thread_fn : Which is the function that will be run as the thread.
NULL: As we are not passing any data to the function we have kept this NULL.
name: The process will be named "thread1" in the list of processes .
*/
int thread_fn() {
printk(KERN_INFO "Pandaboard PUF Kernel Module\n");
if(!strcmp(mystring, hammerall))
get_puf(puf_base_address);
else
get_puf_once(puf_base_address);
printk(KERN_INFO "Rowhammering Completed");
puf_complete_flag = 1;
return 0;
}
int thread_init (void) {
char our_thread[8]="thread1";
printk(KERN_INFO "in init");
thread1 = kthread_create(thread_fn,puf_delaysec,our_thread);
if((thread1))
{
printk(KERN_INFO "in if");
wake_up_process(thread1);
}
return 0;
}
void thread_cleanup(void) {
int ret=1;
if(!puf_complete_flag){
ret = kthread_stop(thread1);
if(!ret)
printk(KERN_INFO "Thread stopped");
}
printk(KERN_INFO "Module Removed");
return;
}
MODULE_LICENSE("GPL");
module_init(thread_init);
module_exit(thread_cleanup);
MODULE_AUTHOR("PANDABOARD Rowhammer-BASED DRAM PUF");
MODULE_DESCRIPTION("Pandaboard Rowhammer-based DRAM PUF kernel module for changing DRAM refresh rate and reading/writing tp PUF memory locations");