Skip to content

Commit 32d240d

Browse files
committed
x86_64: Reflect new direct mapping region extents in Linux 4.2
Linux commit d52888aa2753 ("x86/mm: Move LDT remap out of KASLR region on 5-level paging") moved direct mapping by one PGD slot to make room for the LDT remap area. This change has gone mostly unnoticed, because the actual location of the direct mapping may be randomized with kASLR, so libaddrxlat was able to find the new address, but there are three caveats: 1. The upper limit should be extended by 0.5 GiB. 2. The 4.2 start address should be added to the list of addresses probed when establishing a reverse direct map. 3. The xlat-linux-x86_64-4.13-nover test case specified an impossible direct mapping location for that kernel version. Signed-off-by: Petr Tesarik <[email protected]>
1 parent 0c8eef8 commit 32d240d

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/addrxlat/x86_64.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,30 @@
108108
/** End of direct physical mapping in Linux between 2.6.11 and 2.6.27 */
109109
#define LINUX_DIRECTMAP_END_2_6_11 0xffffc0ffffffffff
110110

111-
/** Start of direct physical mapping in Linux 2.6.27+ */
111+
/** Start of direct physical mapping in Linux between 2.6.27 and 2.6.31 */
112112
#define LINUX_DIRECTMAP_START_2_6_27 0xffff880000000000
113113
/** End of direct physical mapping in Linux between 2.6.27 and 2.6.31 */
114114
#define LINUX_DIRECTMAP_END_2_6_27 0xffffc0ffffffffff
115115

116-
/** Start of direct physical mapping in Linux 2.6.31+ */
116+
/** Start of direct physical mapping in Linux between 2.6.31 and 4.2 */
117117
#define LINUX_DIRECTMAP_START_2_6_31 LINUX_DIRECTMAP_START_2_6_27
118-
/** End of direct physical mapping in Linux 2.6.31+ */
118+
/** End of direct physical mapping in Linux between 2.6.31 and 4.2 */
119119
#define LINUX_DIRECTMAP_END_2_6_31 0xffffc7ffffffffff
120120

121-
/** Start of direct physical mapping with 5-level paging */
122-
#define LINUX_DIRECTMAP_START_5LEVEL 0xff11000000000000
121+
/** Start of direct physical mapping in Linux 4.2+ */
122+
#define LINUX_DIRECTMAP_START_4_2 0xffff888000000000
123+
/** End of direct physical mapping in Linux 4.2+ */
124+
#define LINUX_DIRECTMAP_END_4_2 0xffffc8ffffffffff
123125

124-
/** End of direct physical mapping with 5-level paging */
125-
#define LINUX_DIRECTMAP_END_5LEVEL 0xff90ffffffffffff
126+
/** Start of direct physical mapping with 5-level paging before 4.2 */
127+
#define LINUX_DIRECTMAP_START_5L 0xff10000000000000
128+
/** End of direct physical mapping with 5-level paging before 4.2 */
129+
#define LINUX_DIRECTMAP_END_5L 0xff8fffffffffffff
130+
131+
/** Start of direct physical mapping with 5-level paging in 4.2+ */
132+
#define LINUX_DIRECTMAP_START_5L_4_2 0xff11000000000000
133+
/** End of direct physical mapping with 5-level paging in 4.2+ */
134+
#define LINUX_DIRECTMAP_END_5L_4_2 0xff90ffffffffffff
126135

127136
/** AMD64 (Intel 64) page table step function.
128137
* @param step Current step state.
@@ -306,11 +315,11 @@ linux_directmap_by_pgt(struct sys_region *rgn,
306315
}
307316

308317
if (step.meth->param.pgt.pf.nfields == 6) {
309-
rgn->first = LINUX_DIRECTMAP_START_5LEVEL;
310-
end = LINUX_DIRECTMAP_END_5LEVEL;
318+
rgn->first = LINUX_DIRECTMAP_START_5L;
319+
end = LINUX_DIRECTMAP_END_5L_4_2;
311320
} else {
312321
rgn->first = LINUX_DIRECTMAP_START_2_6_31;
313-
end = LINUX_DIRECTMAP_END_2_6_31;
322+
end = LINUX_DIRECTMAP_END_4_2;
314323
}
315324
status = lowest_mapped(&step, &rgn->first, end);
316325
if (status == ADDRXLAT_OK) {
@@ -408,6 +417,7 @@ linux_rdirect_map(struct os_init_data *ctl)
408417
* Try more recent kernels first.
409418
*/
410419
static const addrxlat_addr_t fixed_loc[] = {
420+
LINUX_DIRECTMAP_START_4_2,
411421
LINUX_DIRECTMAP_START_2_6_31,
412422
LINUX_DIRECTMAP_START_2_6_11,
413423
LINUX_DIRECTMAP_START_2_6_0,

tests/xlat-linux-x86_64-4.13-nover.data

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
00000000250001e1
88
# direct mapping (64T)
99
@0x25c09880
10+
0000000000000000
1011
00000000263cb067*128+1000
11-
0000000000000000*68
12+
0000000000000000*67
1213
@0x263cb000
1314
80000000000001e3*65536+40000000
1415
# 2.6.31+ VMEMMAP

tests/xlat-linux-x86_64-4.13-nover.expect

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
@direct: LINEAR
99
target_as=KPHYSADDR
10-
off=0x780000000000
10+
off=0x778000000000
1111

1212
@ktext: LINEAR
1313
target_as=KPHYSADDR
1414
off=0xa4000000
1515

1616
@rdirect: LINEAR
1717
target_as=KVADDR
18-
off=0xffff880000000000
18+
off=0xffff888000000000
1919

2020
@machphys_kphys: LINEAR
2121
target_as=KPHYSADDR
@@ -33,9 +33,9 @@ ffff800000000000-ffffffffffffffff: @rootpgt
3333
KV -> PHYS:
3434
0-7fffffffffff: @rootpgt
3535
800000000000-ffff7fffffffffff: NONE
36-
ffff800000000000-ffff87ffffffffff: @rootpgt
37-
ffff880000000000-ffffc7ffffffffff: @direct
38-
ffffc80000000000-ffffffff81c08fff: @rootpgt
36+
ffff800000000000-ffff887fffffffff: @rootpgt
37+
ffff888000000000-ffffc87fffffffff: @direct
38+
ffffc88000000000-ffffffff81c08fff: @rootpgt
3939
ffffffff81c09000-ffffffff81c09fff: @ktext
4040
ffffffff81c0a000-ffffffffffffffff: @rootpgt
4141

0 commit comments

Comments
 (0)