xen: remove some checks for always present Xen features
Subsystems (3)
Juergen Gross
maintainercover xen: remove some checks for always present Xen features
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assume XENFEAT_mmu_pt_update_preserve_ad being set for pv guests
xen: assume XENFEAT_gnttab_map_avail_bits being set for pv guests
arch/x86/xen/enlighten_pv.c | 12 ++---------- arch/x86/xen/mmu_pv.c | 4 ++-- drivers/xen/features.c | 18 ++++++++++++++++++ drivers/xen/gntdev.c | 36 ++---------------------------------- 4 files changed, 24 insertions(+), 46 deletions(-)
Signature · 1 line
2.26.2
Juergen Gross
maintainerPATCH 1/3 xen: check required Xen features
Linux kernel is not supported to run on Xen versions older than 4.0.
Add tests for required Xen features always being present in Xen 4.0 and newer.
--- drivers/xen/features.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/xen/features.c +18 -0
@@ -9,13 +9,26 @@#include <linux/types.h> #include <linux/cache.h> #include <linux/export.h> +#include <linux/printk.h> #include <asm/xen/hypercall.h> +#include <xen/xen.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/features.h> +/* +* Linux kernel expects at least Xen 4.0. +* +* Assume some features to be available for that reason (depending on guest +* mode, of course). +*/ +#define chk_feature (f) { \ + if (!xen_feature(f)) \ + pr_err("Xen: feature %s not available!\n", #f); \ + } +u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ;EXPORT_SYMBOL_GPL (xen_features);
@@ -31,4 +44,9 @@ void xen_setup_features(void)for (j =0 ; j <32 ; j++) xen_features[i *32 + j] = !!(fi.submap &1 <<j); } + +if (xen_pv_domain ()) { +chk_feature (XENFEAT_mmu_pt_update_preserve_ad); +chk_feature (XENFEAT_gnttab_map_avail_bits); + } }
Signature · 1 line
2.26.2
Stefano Stabellini
maintainerRe: [PATCH 1/3] xen: check required Xen features
Quoted 27 lines · Juergen Gross
Linux kernel is not supported to run on Xen versions older than 4.0.
Add tests for required Xen features always being present in Xen 4.0 and newer.
Signed-off-by Juergen Gross <[email protected]>--- drivers/xen/features.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/xen/features.c +2
-0@@ -9,13 +9,26 @@#include <linux/types.h> #include <linux/cache.h> #include <linux/export.h> +#include <linux/printk.h> #include <asm/xen/hypercall.h> +#include <xen/xen.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/features.h>
drivers/xen/features.c line 30
Quoted 10 lines
drivers/xen/features.c +10
-0+/* +* Linux kernel expects at least Xen 4.0. +* +* Assume some features to be available for that reason (depending on guest +* mode, of course). +*/ +#define chk_feature (f) { \ + if (!xen_feature(f)) \ + pr_err("Xen: feature %s not available!\n", #f); \ + }
I think this could be done as a static inline function in include/xen/features.h. That way it would be available everywhere. Also, static inlines are better than macro when it is possible to use them in terms of code safety.
Quoted 16 lines
drivers/xen/features.c +5
-0u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ;EXPORT_SYMBOL_GPL (xen_features);@@ -31,4 +44,9 @@ void xen_setup_features(void)for (j =0 ; j <32 ; j++) xen_features[i *32 + j] = !!(fi.submap &1 <<j); } + +if (xen_pv_domain ()) { +chk_feature (XENFEAT_mmu_pt_update_preserve_ad); +chk_feature (XENFEAT_gnttab_map_avail_bits); + } }Signature · 1 line
2.26.2
Juergen Gross
maintainerRe: [PATCH 1/3] xen: check required Xen features
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Juergen Gross
Linux kernel is not supported to run on Xen versions older than 4.0.
Add tests for required Xen features always being present in Xen 4.0 and newer.
Signed-off-by Juergen Gross <[email protected]>--- drivers/xen/features.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/xen/features.c +2
-0@@ -9,13 +9,26 @@#include <linux/types.h> #include <linux/cache.h> #include <linux/export.h> +#include <linux/printk.h> #include <asm/xen/hypercall.h> +#include <xen/xen.h> #include <xen/interface/xen.h> #include <xen/interface/version.h> #include <xen/features.h>
Quoted 15 lines
drivers/xen/features.c line 30
Quoted 10 lines
drivers/xen/features.c +10
-0+/* +* Linux kernel expects at least Xen 4.0. +* +* Assume some features to be available for that reason (depending on guest +* mode, of course). +*/ +#define chk_feature (f) { \ + if (!xen_feature(f)) \ + pr_err("Xen: feature %s not available!\n", #f); \ + }I think this could be done as a static inline function in
include/xen/features.h. That way it would be available everywhere. Also, static inlines are better than macro when it is possible to use them in terms of code safety.
It is a macro in order to have only one parameter.
And being a local macro is rendering the code safety reasoning moot.
Additionally I don't want this testing to be scattered all over the code base. It should be done in one place only.
Juergen
Boris Ostrovsky
reviewerRe: [PATCH 1/3] xen: check required Xen features
In reply to Juergen Grossdrivers/xen/features.c line 30
Quoted 11 lines · Juergen Gross
drivers/xen/features.c +10
-0+/* +* Linux kernel expects at least Xen 4.0. +* +* Assume some features to be available for that reason (depending on guest +* mode, of course). +*/ +#define chk_feature (f) { \ + if (!xen_feature(f)) \ + pr_err("Xen: feature %s not available!\n", #f); \ + }
With your changes in the subsequent patches, are we still going to function properly without those features? (i.e. maybe we should just panic)
(Also, chk_required_features() perhaps?)
-boris
Quoted 14 lines
drivers/xen/features.c +6
-0+u8 xen_features[XENFEAT_NR_SUBMAPS *32 ]__read_mostly ;EXPORT_SYMBOL_GPL (xen_features);@@ -31,4 +44,9 @@ void xen_setup_features(void)for (j =0 ; j <32 ; j++) xen_features[i *32 + j] = !!(fi.submap &1 <<j); } + +if (xen_pv_domain ()) { +chk_feature (XENFEAT_mmu_pt_update_preserve_ad); +chk_feature (XENFEAT_gnttab_map_avail_bits); + } }
Juergen Gross
maintainerRe: [PATCH 1/3] xen: check required Xen features
Quoted 16 lines · Boris Ostrovsky
drivers/xen/features.c line 30
Quoted 11 lines · Juergen Gross
drivers/xen/features.c +10
-0+/* +* Linux kernel expects at least Xen 4.0. +* +* Assume some features to be available for that reason (depending on guest +* mode, of course). +*/ +#define chk_feature (f) { \ + if (!xen_feature(f)) \ + pr_err("Xen: feature %s not available!\n", #f); \ + }With your changes in the subsequent patches, are we still going to function properly without those features? (i.e. maybe we should just panic)
Depends on the use case.
XENFEAT_gnttab_map_avail_bits is relevant for driver domains using user space backends only. In case it is not available "interesting" things might happen.
XENFEAT_mmu_pt_update_preserve_ad not being present would result in a subsequent mmu-update function using that feature returning -ENOSYS, so this wouldn't be unrecognized.
So panic() might be a good idea in case the features are not available.
Quoted 1 line
(Also,
chk_required_features()perhaps?)
Fine with me.
Juergen
Juergen Gross
maintainerPATCH 2/3 xen: assume XENFEAT_mmu_pt_update_preserve_ad being set for pv guests
In reply to Juergen GrossXENFEAT_mmu_pt_update_preserve_ad is always set in Xen 4.0 and newer. Remove coding assuming it might be zero.
--- arch/x86/xen/enlighten_pv.c | 12 ++---------- arch/x86/xen/mmu_pv.c | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-)
arch/x86/xen/enlighten_pv.c +2 -10
@@ -116,9 +116,8 @@ static void __init xen_banner(void)HYPERVISOR_xen_version (XENVER_extraversion, &extra);pr_info ("Booting paravirtualized kernel on %s\n" , pv_info.name); -printk (KERN_INFO "Xen version: %d.%d%s%s\n" , - version >>16 , version &0xffff , extra.extraversion, -xen_feature (XENFEAT_mmu_pt_update_preserve_ad) ?" (preserve-AD)" :"" ); +pr_info ("Xen version: %d.%d%s (preserve-AD)\n" , + version >>16 , version &0xffff , extra.extraversion); }static void __init xen_pv_init_platform (void )
@@ -1303,13 +1302,6 @@ asmlinkage __visible void __init xen_start_kernel(void)xen_init_apic ();#endif -if (xen_feature (XENFEAT_mmu_pt_update_preserve_ad)) { - pv_ops.mmu.ptep_modify_prot_start = - xen_ptep_modify_prot_start; - pv_ops.mmu.ptep_modify_prot_commit = - xen_ptep_modify_prot_commit; - } - machine_ops = xen_machine_ops;/*
arch/x86/xen/mmu_pv.c +2 -2
@@ -2100,8 +2100,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = { .set_pte = xen_set_pte_init, .set_pmd = xen_set_pmd_hyper, - .ptep_modify_prot_start = __ptep_modify_prot_start, - .ptep_modify_prot_commit = __ptep_modify_prot_commit, + .ptep_modify_prot_start = xen_ptep_modify_prot_start, + .ptep_modify_prot_commit = xen_ptep_modify_prot_commit, .pte_val = PV_CALLEE_SAVE(xen_pte_val), .pgd_val = PV_CALLEE_SAVE(xen_pgd_val),
Signature · 1 line
2.26.2
Juergen Gross
maintainerPATCH 3/3 xen: assume XENFEAT_gnttab_map_avail_bits being set for pv guests
In reply to Juergen GrossXENFEAT_gnttab_map_avail_bits is always set in Xen 4.0 and newer. Remove coding assuming it might be zero.
--- drivers/xen/gntdev.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-)
drivers/xen/gntdev.c +2 -34
@@ -266,20 +266,13 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) {struct gntdev_grant_map *map = data;unsigned int pgnr = (addr - map->vma->vm_start) >>PAGE_SHIFT ; -int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte; +int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte | + (1 << _GNTMAP_guest_avail0);u64 pte_maddr;BUG_ON (pgnr >= map->count); pte_maddr =arbitrary_virt_to_machine (pte).maddr; -/* -* Set the PTE as special to force get_user_pages_fast() fall -* back to the slow path. If this is not supported as part of -* the grant map, it will be done afterwards. -*/ -if (xen_feature (XENFEAT_gnttab_map_avail_bits)) - flags |= (1 << _GNTMAP_guest_avail0); -gnttab_set_map_op (&map->map_ops[pgnr], pte_maddr, flags, map->grants[pgnr].ref, map->grants[pgnr].domid);
@@ -288,14 +281,6 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data)return 0 ; } -#ifdef CONFIG_X86 -static int set_grant_ptes_as_special (pte_t *pte,unsigned long addr,void *data) -{ -set_pte_at (current->mm, addr, pte,pte_mkspecial (*pte)); -return 0 ; -} -#endif -int gntdev_map_grant_pages (struct gntdev_grant_map *map) {int i, err =0 ;
@@ -1053,23 +1038,6 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) err =vm_map_pages_zero (vma, map->pages, map->count);if (err) goto out_put_map; - }else { -#ifdef CONFIG_X86 -/* -* If the PTEs were not made special by the grant map -* hypercall, do so here. -* -* This is racy since the mapping is already visible -* to userspace but userspace should be well-behaved -* enough to not touch it until the mmap() call -* returns. -*/ -if (!xen_feature (XENFEAT_gnttab_map_avail_bits)) { -apply_to_page_range (vma->vm_mm, vma->vm_start, - vma->vm_end - vma->vm_start, - set_grant_ptes_as_special,NULL ); - } -#endif }return 0 ;
Signature · 1 line
2.26.2
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guests
I wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
Jan
Juergen Gross
maintainerQuoted 9 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guests
Quoted 5 lines
I wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
I'm testing the feature to be really present when booting and issue a message if it is not there.
Juergen
Quoted 10 lines · Juergen Gross
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guests
Quoted 8 lines
Quoted 5 lines
I wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
I'm testing the feature to be really present when booting and issue a message if it is not there.
And how does this help if the feature really isn't there yet other code assumes it is?
Jan
Juergen Gross
maintainerQuoted 17 lines · Jan Beulich
Quoted 16 lines · Juergen Gross
Quoted 14 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guestsI wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
Quoted 5 lines
Quoted 2 lines
I'm testing the feature to be really present when booting and issue a message if it is not there.
And how does this help if the feature really isn't there yet other code assumes it is?
Did you look at the features I'm testing? Those are really just low level additions I can't imagine will ever be removed again.
Juergen
Quoted 18 lines · Juergen Gross
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Juergen Gross
Quoted 14 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guestsI wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I'm testing the feature to be really present when booting and issue a message if it is not there.
And how does this help if the feature really isn't there yet other code assumes it is?
Did you look at the features I'm testing?
I did, yes.
Quoted 2 lines
Those are really just low
level additions I can't imagine will ever be removed again.
I don't expect them to be removed. But I don't think the people having contributed gnttab v2 expected any such for it, either.
Jan
Juergen Gross
maintainerQuoted 27 lines · Jan Beulich
Quoted 18 lines · Juergen Gross
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Juergen Gross
Quoted 14 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guestsI wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I'm testing the feature to be really present when booting and issue a message if it is not there.
And how does this help if the feature really isn't there yet other code assumes it is?
Did you look at the features I'm testing?
Quoted 7 lines
I did, yes.
Quoted 2 lines
Those are really just low
level additions I can't imagine will ever be removed again.I don't expect them to be removed. But I don't think the people having contributed gnttab v2 expected any such for it, either.
There is a major difference here.
gnttab v2 was replacing an existing functionality by a more scalable, but more complex solution.
The features I'm assuming to be present are basically repairing issues which have been present due to omissions in the initial implementation.
Especially the XENFEAT_gnttab_map_avail_bits causes a racy workaround in the kernel when not present. The race is only avoided in case the user code is well-behaved. It is dom0 user code, yes, but nevertheless such issues are never nice.
Juergen
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Juergen Gross
Quoted 19 lines · Jan Beulich
Quoted 9 lines · Juergen Gross
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guestsQuoted 7 lines
Quoted 5 lines
I wonder whether it's a good idea to infer feature presence from version numbers. If (at some point in the past) you had inferred gnttab v2 being available by version, this would have been broken by its availability becoming controllable by a command line option in Xen.
I'm testing the feature to be really present when booting and issue a message if it is not there.
And how does this help if the feature really isn't there yet other code assumes it is?
Quoted 7 lines
Quoted 1 line
Did you look at the features I'm testing?
I did, yes.
Quoted 2 lines
Those are really just low
level additions I can't imagine will ever be removed again.I don't expect them to be removed. But I don't think the people having contributed gnttab v2 expected any such for it, either.
The trainwreck around gnttab v2 is a mistake I hope we're never going to make again. I don't think it's a useful argument here.
The logic is fine. It's checking for the actual features in the ABI upon which Linux depends.
Sure - someone could modify Xen to take the feature out, but they'd get a red wall in CI as they break every Linux kernel released in the past decade.
~Andrew
Juergen Gross
maintainerQuoted 8 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guests
Quoted 6 lines
arch/x86/xen/enlighten_pv.c | 12 ++---------- arch/x86/xen/mmu_pv.c | 4 ++-- drivers/xen/features.c | 18 ++++++++++++++++++ drivers/xen/gntdev.c | 36 ++---------------------------------- 4 files changed, 24 insertions(+), 46 deletions(-)
Could I please get some feedback on this series?
Juergen
Peter Zijlstra
Acked-byQuoted 9 lines · Juergen Gross
Quoted 8 lines · Juergen Gross
Some features of Xen can be assumed to be always present, so add a central check to verify this being true and remove the other checks.
Juergen Gross (3):
xen: check required Xen features
xen: assumeXENFEAT_mmu_pt_update_preserve_adbeing set for pv guests
xen: assumeXENFEAT_gnttab_map_avail_bitsbeing set for pv guests
Quoted 8 lines
Quoted 6 lines
arch/x86/xen/enlighten_pv.c | 12 ++---------- arch/x86/xen/mmu_pv.c | 4 ++-- drivers/xen/features.c | 18 ++++++++++++++++++ drivers/xen/gntdev.c | 36 ++---------------------------------- 4 files changed, 24 insertions(+), 46 deletions(-)Could I please get some feedback on this series?
I'm obviously in favour, but given I'm not an actual Xen user that might not be worth much, still: