Skip to content

Commit 158f238

Browse files
committed
Merge tag 'for-linus-6.13-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen updates from Juergen Gross: - a series for booting as a PVH guest, doing some cleanups after the previous work to make PVH boot code position independent - a fix of the xenbus driver avoiding a leak in an error case * tag 'for-linus-6.13-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xen: Fix the issue of resource not being properly released in xenbus_dev_probe() x86/pvh: Avoid absolute symbol references in .head.text x86/xen: Avoid relocatable quantities in Xen ELF notes x86/pvh: Omit needless clearing of phys_base x86/pvh: Use correct size value in GDT descriptor x86/pvh: Call C code via the kernel virtual mapping
2 parents ba1f9c8 + afc545d commit 158f238

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

arch/x86/kernel/vmlinux.lds.S

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,22 @@ INIT_PER_CPU(irq_stack_backing_store);
531531
#endif
532532

533533
#endif /* CONFIG_X86_64 */
534+
535+
/*
536+
* The symbols below are referenced using relative relocations in the
537+
* respective ELF notes. This produces build time constants that the
538+
* linker will never mark as relocatable. (Using just ABSOLUTE() is not
539+
* sufficient for that).
540+
*/
541+
#ifdef CONFIG_XEN
542+
#ifdef CONFIG_XEN_PV
543+
xen_elfnote_entry_value =
544+
ABSOLUTE(xen_elfnote_entry) + ABSOLUTE(startup_xen);
545+
#endif
546+
xen_elfnote_hypercall_page_value =
547+
ABSOLUTE(xen_elfnote_hypercall_page) + ABSOLUTE(hypercall_page);
548+
#endif
549+
#ifdef CONFIG_PVH
550+
xen_elfnote_phys32_entry_value =
551+
ABSOLUTE(xen_elfnote_phys32_entry) + ABSOLUTE(pvh_start_xen - LOAD_OFFSET);
552+
#endif

arch/x86/platform/pvh/head.S

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
.code32
88
.text
9+
#ifdef CONFIG_X86_32
910
#define _pa(x) ((x) - __START_KERNEL_map)
11+
#endif
1012
#define rva(x) ((x) - pvh_start_xen)
1113

1214
#include <linux/elfnote.h>
@@ -52,7 +54,7 @@
5254
#define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
5355
#define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
5456

55-
SYM_CODE_START_LOCAL(pvh_start_xen)
57+
SYM_CODE_START(pvh_start_xen)
5658
UNWIND_HINT_END_OF_STACK
5759
cld
5860

@@ -72,8 +74,7 @@ SYM_CODE_START_LOCAL(pvh_start_xen)
7274
movl $0, %esp
7375

7476
leal rva(gdt)(%ebp), %eax
75-
leal rva(gdt_start)(%ebp), %ecx
76-
movl %ecx, 2(%eax)
77+
addl %eax, 2(%eax)
7778
lgdt (%eax)
7879

7980
mov $PVH_DS_SEL,%eax
@@ -103,10 +104,23 @@ SYM_CODE_START_LOCAL(pvh_start_xen)
103104
btsl $_EFER_LME, %eax
104105
wrmsr
105106

107+
/*
108+
* Reuse the non-relocatable symbol emitted for the ELF note to
109+
* subtract the build time physical address of pvh_start_xen() from
110+
* its actual runtime address, without relying on absolute 32-bit ELF
111+
* relocations, as these are not supported by the linker when running
112+
* in -pie mode, and should be avoided in .head.text in general.
113+
*/
106114
mov %ebp, %ebx
107-
subl $_pa(pvh_start_xen), %ebx /* offset */
115+
subl rva(xen_elfnote_phys32_entry)(%ebp), %ebx
108116
jz .Lpagetable_done
109117

118+
/*
119+
* Store the resulting load offset in phys_base. __pa() needs
120+
* phys_base set to calculate the hypercall page in xen_pvh_init().
121+
*/
122+
movl %ebx, rva(phys_base)(%ebp)
123+
110124
/* Fixup page-tables for relocation. */
111125
leal rva(pvh_init_top_pgt)(%ebp), %edi
112126
movl $PTRS_PER_PGD, %ecx
@@ -165,20 +179,12 @@ SYM_CODE_START_LOCAL(pvh_start_xen)
165179
xor %edx, %edx
166180
wrmsr
167181

168-
/*
169-
* Calculate load offset and store in phys_base. __pa() needs
170-
* phys_base set to calculate the hypercall page in xen_pvh_init().
171-
*/
172-
movq %rbp, %rbx
173-
subq $_pa(pvh_start_xen), %rbx
174-
movq %rbx, phys_base(%rip)
175-
call xen_prepare_pvh
176-
/*
177-
* Clear phys_base. __startup_64 will *add* to its value,
178-
* so reset to 0.
179-
*/
180-
xor %rbx, %rbx
181-
movq %rbx, phys_base(%rip)
182+
/* Call xen_prepare_pvh() via the kernel virtual mapping */
183+
leaq xen_prepare_pvh(%rip), %rax
184+
subq phys_base(%rip), %rax
185+
addq $__START_KERNEL_map, %rax
186+
ANNOTATE_RETPOLINE_SAFE
187+
call *%rax
182188

183189
/* startup_64 expects boot_params in %rsi. */
184190
lea pvh_bootparams(%rip), %rsi
@@ -217,8 +223,8 @@ SYM_CODE_END(pvh_start_xen)
217223
.section ".init.data","aw"
218224
.balign 8
219225
SYM_DATA_START_LOCAL(gdt)
220-
.word gdt_end - gdt_start
221-
.long _pa(gdt_start) /* x86-64 will overwrite if relocated. */
226+
.word gdt_end - gdt_start - 1
227+
.long gdt_start - gdt
222228
.word 0
223229
SYM_DATA_END(gdt)
224230
SYM_DATA_START_LOCAL(gdt_start)
@@ -300,5 +306,5 @@ SYM_DATA_END(pvh_level2_kernel_pgt)
300306
.long KERNEL_IMAGE_SIZE - 1)
301307
#endif
302308

303-
ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
304-
_ASM_PTR (pvh_start_xen - __START_KERNEL_map))
309+
ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .global xen_elfnote_phys32_entry;
310+
xen_elfnote_phys32_entry: _ASM_PTR xen_elfnote_phys32_entry_value - .)

arch/x86/tools/relocs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
5656
[S_ABS] =
5757
"^(xen_irq_disable_direct_reloc$|"
5858
"xen_save_fl_direct_reloc$|"
59+
"xen_elfnote_.+_offset$|"
5960
"VDSO|"
6061
"__kcfi_typeid_|"
6162
"__crc_)",

arch/x86/xen/xen-head.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ SYM_CODE_END(xen_cpu_bringup_again)
9494
ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, _ASM_PTR __START_KERNEL_map)
9595
/* Map the p2m table to a 512GB-aligned user address. */
9696
ELFNOTE(Xen, XEN_ELFNOTE_INIT_P2M, .quad (PUD_SIZE * PTRS_PER_PUD))
97-
ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, _ASM_PTR startup_xen)
97+
ELFNOTE(Xen, XEN_ELFNOTE_ENTRY, .globl xen_elfnote_entry;
98+
xen_elfnote_entry: _ASM_PTR xen_elfnote_entry_value - .)
9899
ELFNOTE(Xen, XEN_ELFNOTE_FEATURES, .ascii "!writable_page_tables")
99100
ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "yes")
100101
ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,
@@ -115,7 +116,8 @@ SYM_CODE_END(xen_cpu_bringup_again)
115116
#else
116117
# define FEATURES_DOM0 0
117118
#endif
118-
ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _ASM_PTR hypercall_page)
119+
ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, .globl xen_elfnote_hypercall_page;
120+
xen_elfnote_hypercall_page: _ASM_PTR xen_elfnote_hypercall_page_value - .)
119121
ELFNOTE(Xen, XEN_ELFNOTE_SUPPORTED_FEATURES,
120122
.long FEATURES_PV | FEATURES_PVH | FEATURES_DOM0)
121123
ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic")

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ int xenbus_dev_probe(struct device *_dev)
313313
if (err) {
314314
dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
315315
dev->nodename);
316-
return err;
316+
goto fail_remove;
317317
}
318318

319319
dev->spurious_threshold = 1;
@@ -322,6 +322,12 @@ int xenbus_dev_probe(struct device *_dev)
322322
dev->nodename);
323323

324324
return 0;
325+
fail_remove:
326+
if (drv->remove) {
327+
down(&dev->reclaim_sem);
328+
drv->remove(dev);
329+
up(&dev->reclaim_sem);
330+
}
325331
fail_put:
326332
module_put(drv->driver.owner);
327333
fail:

0 commit comments

Comments
 (0)