x86: address drivers that do not work with PAT
Subsystems (7)
PATCH v4 6/8 ivtv: use arch_phys_wc_add() and require PAT disabled
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We are burrying direct access to MTRR code support on x86 in order to take advantage of PAT. In the future we also want to make the default behaviour of ioremap_nocache() to use strong UC, use of mtrr_add() on those systems would make write-combining void.
In order to help both enable us to later make strong UC default and in order to phase out direct MTRR access code port the driver over to arch_phys_wc_add() and annotate that the device driver requires systems to boot with PAT disabled, with the nopat kernel parameter.
This is a worthy comprmise given that the hardware is really rare these days, and perhaps only some lost souls in some third world country are expected to be using this feature of the device driver.
--- drivers/media/pci/ivtv/Kconfig | 3 +++ drivers/media/pci/ivtv/ivtvfb.c | 58 ++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 35 deletions(-)
drivers/media/pci/ivtv/Kconfig +3 -0
@@ -57,5 +57,8 @@ config VIDEO_FB_IVTV This is used in the Hauppauge PVR-350 card. There is a driver homepage at <http://www.ivtvdriver.org>. + If you have this hardware you will need to boot with PAT disabled + on your x86 systems, use the nopat kernel parameter. + To compile this driver as a module, choose M here: the module will be called ivtvfb.
drivers/media/pci/ivtv/ivtvfb.c +23 -35
98 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 7/8 IB/ipath: add counting for MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There is no good reason not to, we eventually delete it as well.
--- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c +1 -1
@@ -127,7 +127,7 @@ int ipath_enable_wc(struct ipath_devdata *dd)"(addr %llx, len=0x%llx)\n" , (unsigned long long ) pioaddr, (unsigned long long) piolen); - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,0 ); + cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 );if (cookie <0 ) { { dev_info(&dd->pcidev->dev,
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 8/8 IB/ipath: use arch_phys_wc_add() and require PAT disabled
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We are burrying direct access to MTRR code support on x86 in order to take advantage of PAT. In the future we also want to make the default behaviour of ioremap_nocache() to use strong UC, use of mtrr_add() on those systems would make write-combining void.
In order to help both enable us to later make strong UC default and in order to phase out direct MTRR access code port the driver over to arch_phys_wc_add() and annotate that the device driver requires systems to boot with PAT disabled, with the nopat kernel parameter.
This is a worthy compromise given that the ipath device driver powers the old HTX bus cards that only work in AMD systems, while the newer IB/qib device driver powers all PCI-e cards. The ipath device driver is obsolete, hardware hard to find and because of this this its a reasonable compromise to make to require users of ipath to boot with nopat.
--- drivers/infiniband/hw/ipath/Kconfig | 3 ++ drivers/infiniband/hw/ipath/ipath_driver.c | 18 +++++++---- drivers/infiniband/hw/ipath/ipath_kernel.h | 4 +-- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 43 ++++++--------------------- 4 files changed, 26 insertions(+), 42 deletions(-)
drivers/infiniband/hw/ipath/Kconfig +3 -0
@@ -9,3 +9,6 @@ config INFINIBAND_IPATH as IP-over-InfiniBand as well as with userspace applications (in conjunction with InfiniBand userspace access). For QLogic PCIe QLE based cards, use the QIB driver instead. + + If you have this hardware you will need to boot with PAT disabled + on your x86-64 systems, use the nopat kernel parameter.
drivers/infiniband/hw/ipath/ipath_driver.c +13 -5
@@ -42,6 +42,9 @@#include <linux/bitmap.h> #include <linux/slab.h> #include <linux/module.h> +#ifdef CONFIG_X86_64 +#include <asm/pat.h> +#endif #include "ipath_kernel.h" #include "ipath_verbs.h"
@@ -395,6 +398,14 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)unsigned long long addr;u32 bar0 =0 , bar1 =0 ; +#ifdef CONFIG_X86_64 +if (WARN (pat_enabled (), +"ipath needs PAT disabled, boot with nopat kernel parameter\n" )) { + ret =EINVAL ; + goto bail; + } +#endif + dd =ipath_alloc_devdata (pdev);if (IS_ERR (dd)) { ret =PTR_ERR (dd);
@@ -542,6 +553,7 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dd->ipath_kregbase =__ioremap (addr, len, (_PAGE_NO_CACHE|_PAGE_WRITETHRU));#else +/* XXX: split this properly to enable on PAT */ dd->ipath_kregbase =ioremap_nocache (addr, len);#endif
@@ -587,12 +599,8 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ret =ipath_enable_wc (dd); -if (ret) { -ipath_dev_err (dd,"Write combining not enabled " -"(err %d): performance may be poor\n" , - -ret); +if (ret) ret =0 ; - }ipath_verify_pioperf (dd);
drivers/infiniband/hw/ipath/ipath_kernel.h +1 -3
@@ -463,9 +463,7 @@ struct ipath_devdata {/* offset in HT config space of slave/primary interface block */ u8 ipath_ht_slave_off;/* for write combining settings */ -unsigned long ipath_wc_cookie; -unsigned long ipath_wc_base; -unsigned long ipath_wc_len; +int wc_cookie;/* ref count for each pkey */ atomic_t ipath_pkeyrefs[4 ];/* shadow copy of struct page *'s for exp tid pages */
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c +9 -34
59 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
v4 cover x86: address drivers that do not work with PAT
From: "Luis R. Rodriguez" <[email protected]>
This provides a bit of clean up on PAT and then adds addresses the agreed upon compromise of how we will address drivers with broken PAT support by using pat_enabled() and recommending to boot with "nopat" kernel parameter.
With this and the rest of the easier changes submitted we should soon see a patch trickle down which buries MTRR from direct driver access. That will only be done once *all* the series addressing the conversion have been merged.
The two driver changes that are implicated here have been reviewed by the respective maintainers, this goes with their respective ACKs.
Luis R. Rodriguez (8):
x86/mm/pat: use pr_info() and friends
init.h: add __read_mostly to early_param_on_off() init.h: add early_param_on() and early_param_off() x86/mm/pat: use early_param_off() and redefine pat_enabled() arch/x86/mm/pat: export pat_enabled()
ivtv: use arch_phys_wc_add() and require PAT disabled IB/ipath: add counting for MTRR
IB/ipath: use arch_phys_wc_add() and require PAT disabled
arch/x86/include/asm/pat.h | 7 +-- arch/x86/kernel/cpu/mtrr/main.c | 2 +- arch/x86/mm/iomap_32.c | 2 +- arch/x86/mm/ioremap.c | 4 +- arch/x86/mm/pageattr.c | 2 +- arch/x86/mm/pat.c | 86 ++++++++++++--------------- arch/x86/pci/i386.c | 6 +- drivers/infiniband/hw/ipath/Kconfig | 3 + drivers/infiniband/hw/ipath/ipath_driver.c | 18 ++++-- drivers/infiniband/hw/ipath/ipath_kernel.h | 4 +- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 43 +++----------- drivers/media/pci/ivtv/Kconfig | 3 + drivers/media/pci/ivtv/ivtvfb.c | 58 +++++++----------- include/linux/init.h | 25 +++++++- 14 files changed, 123 insertions(+), 140 deletions(-)
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 1/8 x86/mm/pat: use pr_info() and friends
From: "Luis R. Rodriguez" <[email protected]>
--- arch/x86/mm/pat.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)
arch/x86/mm/pat.c +23 -24
@@ -39,7 +39,7 @@ int __read_mostly pat_enabled = 1;static inline void pat_disable (const char *reason) { pat_enabled =0 ; -printk (KERN_INFO "%s\n" , reason); +pr_info ("%s\n" , reason); }static int __init nopat (char *str)
@@ -211,8 +211,7 @@ void pat_init(void)* switched to PAT on the boot CPU. We have no way to * undo PAT. */ -printk (KERN_ERR "PAT enabled, " -"but not supported by secondary CPU\n" ); +pr_err ("PAT enabled, but not supported by secondary CPU\n" );BUG (); } }
@@ -451,9 +450,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, err =rbt_memtype_check_insert (new, new_type);if (err) { -printk (KERN_INFO "reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , - start, end -1 , -cattr_name (new->type),cattr_name (req_type)); +pr_info ("reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , + start, end -1 , +cattr_name (new->type),cattr_name (req_type));kfree (new);spin_unlock (&memtype_lock);
@@ -462,9 +461,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,spin_unlock (&memtype_lock); -dprintk ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , - start, end -1 ,cattr_name (new->type),cattr_name (req_type), - new_type ?cattr_name (*new_type) :"-" ); +pr_debug ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , + start, end -1 ,cattr_name (new->type),cattr_name (req_type), + new_type ?cattr_name (*new_type) :"-" );return err; }
@@ -497,14 +496,15 @@ int free_memtype(u64 start, u64 end)spin_unlock (&memtype_lock);if (!entry) { -printk (KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , - current->comm, current->pid, start, end -1 ); +pr_info ("%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , + current->comm, current->pid, start, end -1 );return -EINVAL ; }kfree (entry); -dprintk ("free_memtype request [mem %#010Lx-%#010Lx]\n" , start, end -1 ); +pr_debug ("free_memtype request [mem %#010Lx-%#010Lx]\n" , + start, end -1 );return 0 ; }
@@ -628,8 +628,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)while (cursor < to) {if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , - current->comm, from, to -1 ); +pr_info ("Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , + current->comm, from, to -1 );return 0 ; } cursor +=PAGE_SIZE ;
@@ -698,8 +698,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, size;if (ioremap_change_attr ((unsigned long )__va (base), id_sz, pcm) <0 ) { -printk (KERN_INFO "%s:%d ioremap_change_attr failed %s " -"for [mem %#010Lx-%#010Lx]\n" , +pr_info ("%s:%d ioremap_change_attr failed %s for [mem %#010Lx-%#010Lx]\n" , current->comm, current->pid,cattr_name (pcm), base, (unsigned long long )(base + size-1 ));
@@ -734,7 +733,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, pcm =lookup_memtype (paddr);if (want_pcm != pcm) { - printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", + pr_warn("%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", current->comm, current->pid, cattr_name(want_pcm), (unsigned long long)paddr,
@@ -755,13 +754,13 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,if (strict_prot || !is_new_memtype_allowed (paddr, size, want_pcm, pcm)) {free_memtype (paddr, paddr + size); -printk (KERN_ERR "%s:%d map pfn expected mapping type %s" -" for [mem %#010Lx-%#010Lx], got %s\n" , - current->comm, current->pid, -cattr_name (want_pcm), - (unsigned long long )paddr, - (unsigned long long )(paddr + size -1 ), -cattr_name (pcm)); +pr_err (KERN_ERR "%s:%d map pfn expected mapping type %s" +" for [mem %#010Lx-%#010Lx], got %s\n" , + current->comm, current->pid, +cattr_name (want_pcm), + (unsigned long long )paddr, + (unsigned long long )(paddr + size -1 ), +cattr_name (pcm));return -EINVAL ; }/*
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 2/8 init.h: add __read_mostly to early_param_on_off()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
--- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/init.h +1 -1
@@ -272,7 +272,7 @@ struct obs_kernel_param {#define early_param_on_off (str_on, str_off, var, config) \ \ - int var = IS_ENABLED(config); \ + int __read_mostly var = IS_ENABLED(config); \ \ static int __init parse_##var##_on(char *arg) \ { \
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 3/8 init.h: add early_param_on() and early_param_off()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
At times all we need is an enabler / disabler.
--- include/linux/init.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/linux/init.h +23 -0
@@ -270,6 +270,29 @@ struct obs_kernel_param {#define early_param (str, fn) \ __setup_param(str, fn, fn, 1) +#define early_param_on (str_on, var, config) \ + \ + int __read_mostly var = IS_ENABLED(config); \ + \ + static int __init parse_##var##_on(char *arg) \ + { \ + var = 1; \ + return 0; \ + } \ + __setup_param(str_on, parse_##var##_on, parse_##var##_on, 1); \ + \ + +#define early_param_off (str_off, var, config) \ + \ + int __read_mostly var = IS_ENABLED(config); \ + \ + static int __init parse_##var##_off(char *arg) \ + { \ + var = 0; \ + return 0; \ + } \ + __setup_param(str_off, parse_##var##_off, parse_##var##_off, 1) +#define early_param_on_off (str_on, str_off, var, config) \ \ int __read_mostly var = IS_ENABLED(config); \
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 4/8 x86/mm/pat: use early_param_off() and redefine pat_enabled()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We use pat_enabled on x86 specific code to see if PAT is enabled or not, we however are granting full access to the variable even though readers do not need to set it.
This uses the early_param_off() to simplify the definition of the old pat_enabled under a new static variable __pat_enabled, for access to see if its enabled / disabled folks can just use pat_enabled() now. Code that set this is purely internal to pat.c. Apart from the early parameter to disable it we also have a few cases that disable it later, these were wrapped under and ifdef but since that code cannot run unless PAT was enabled its not required to wrap it with ifdefs.
--- arch/x86/include/asm/pat.h | 7 +------ arch/x86/kernel/cpu/mtrr/main.c | 2 +- arch/x86/mm/iomap_32.c | 2 +- arch/x86/mm/ioremap.c | 4 ++-- arch/x86/mm/pageattr.c | 2 +- arch/x86/mm/pat.c | 38 ++++++++++++++------------------------ arch/x86/pci/i386.c | 6 +++--- 7 files changed, 23 insertions(+), 38 deletions(-)
arch/x86/include/asm/pat.h +1 -6
@@ -4,12 +4,7 @@#include <linux/types.h> #include <asm/pgtable_types.h> -#ifdef CONFIG_X86_PAT -extern int pat_enabled; -#else -static const int pat_enabled; -#endif - +bool pat_enabled (void );extern void pat_init (void );void pat_init_cache_modes (void );
arch/x86/kernel/cpu/mtrr/main.c +1 -1
@@ -556,7 +556,7 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) {int ret; -if (pat_enabled || !mtrr_enabled) +if (pat_enabled () || !mtrr_enabled)return 0 ;/* Success! (We don't need to do anything.) */ ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);
arch/x86/mm/iomap_32.c +1 -1
@@ -82,7 +82,7 @@ iomap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)* MTRR is UC or WC. UC_MINUS gets the real intention, of the * user, which is "WC if the MTRR is WC, UC if you can't do that." */ -if (!pat_enabled &&pgprot_val (prot) == +if (!pat_enabled () &&pgprot_val (prot) == (__PAGE_KERNEL |cachemode2protval (_PAGE_CACHE_MODE_WC))) prot =__pgprot (__PAGE_KERNEL |cachemode2protval (_PAGE_CACHE_MODE_UC_MINUS));
arch/x86/mm/ioremap.c +2 -2
@@ -234,7 +234,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size) {/* * Ideally, this should be: -* pat_enabled ? _PAGE_CACHE_MODE_UC : _PAGE_CACHE_MODE_UC_MINUS; +* pat_enabled() ? _PAGE_CACHE_MODE_UC : _PAGE_CACHE_MODE_UC_MINUS; * * Till we fix all X drivers to use ioremap_wc(), we will use * UC MINUS. Drivers that are certain they need or can already
@@ -292,7 +292,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);*/ void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) { -if (pat_enabled) +if (pat_enabled ())return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC,__builtin_return_address (0 ));else
arch/x86/mm/pageattr.c +1 -1
@@ -1574,7 +1574,7 @@ int set_memory_wc(unsigned long addr, int numpages) {int ret; -if (!pat_enabled) +if (!pat_enabled ())return set_memory_uc (addr, numpages); ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
arch/x86/mm/pat.c +14 -24
@@ -33,28 +33,18 @@#include "pat_internal.h" #include "mm_internal.h" -#ifdef CONFIG_X86_PAT -int __read_mostly pat_enabled =1 ; +static early_param_off("nopat", __pat_enabled, CONFIG_X86_PAT);static inline void pat_disable (const char *reason) { - pat_enabled =0 ; + __pat_enabled =0 ;pr_info ("%s\n" , reason); } -static int __init nopat (char *str) -{ -pat_disable ("PAT support disabled." ); -return 0 ; -} -early_param ("nopat" , nopat); -#else -static inline void pat_disable (const char *reason) +bool pat_enabled (void ) { - (void )reason; +return !!__pat_enabled; } -#endif -int pat_debug_enable;
@@ -198,7 +188,7 @@ void pat_init(void)u64 pat;bool boot_cpu = !boot_pat_state; -if (!pat_enabled) +if (!pat_enabled ())return ;if (!cpu_has_pat) {
@@ -399,7 +389,7 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,BUG_ON (start >= end);/* end is exclusive */ -if (!pat_enabled) { +if (!pat_enabled ()) {/* This is identical to page table setting without PAT */ if (new_type) {if (req_type == _PAGE_CACHE_MODE_WC)
@@ -474,7 +464,7 @@ int free_memtype(u64 start, u64 end)int is_range_ram;struct memtype *entry; -if (!pat_enabled) +if (!pat_enabled ())return 0 ;/* Low ISA region is always mapped WB. No need to track */
@@ -623,7 +613,7 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)u64 to = from + size;u64 cursor = from; -if (!pat_enabled) +if (!pat_enabled ())return 1 ;while (cursor < to) {
@@ -659,7 +649,7 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,* caching for the high addresses through the KEN pin, but * we maintain the tradition of paranoia in this code. */ - if (!pat_enabled && + if (!pat_enabled() && !(boot_cpu_has(X86_FEATURE_MTRR) || boot_cpu_has(X86_FEATURE_K6_MTRR) || boot_cpu_has(X86_FEATURE_CYRIX_ARR) ||
@@ -728,7 +718,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,* the type requested matches the type of first page in the range. */ if (is_ram) { -if (!pat_enabled) +if (!pat_enabled ())return 0 ; pcm =lookup_memtype (paddr);
@@ -843,7 +833,7 @@ int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,return ret; } -if (!pat_enabled) +if (!pat_enabled ())return 0 ;/*
@@ -871,7 +861,7 @@ int track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot, {enum page_cache_mode pcm; -if (!pat_enabled) +if (!pat_enabled ())return 0 ;/* Set prot based on lookup */
@@ -912,7 +902,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,pgprot_t pgprot_writecombine (pgprot_t prot) { -if (pat_enabled) +if (pat_enabled ())return __pgprot (pgprot_val (prot) |cachemode2protval (_PAGE_CACHE_MODE_WC));else
@@ -995,7 +985,7 @@ static const struct file_operations memtype_fops = {static int __init pat_memtype_list_init (void ) { -if (pat_enabled) { +if (pat_enabled ()) {debugfs_create_file ("pat_memtype_list" ,S_IRUSR , arch_debugfs_dir,NULL , &memtype_fops); }
arch/x86/pci/i386.c +3 -3
@@ -429,12 +429,12 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,* Caller can followup with UC MINUS request and add a WC mtrr if there * is a free mtrr slot. */ -if (!pat_enabled && write_combine) +if (!pat_enabled () && write_combine)return -EINVAL ; -if (pat_enabled && write_combine) +if (pat_enabled () && write_combine) prot |=cachemode2protval (_PAGE_CACHE_MODE_WC); -else if (pat_enabled || boot_cpu_data.x86 >3 ) +else if (pat_enabled () || boot_cpu_data.x86 >3 )/* * ioremap() and ioremap_nocache() defaults to UC MINUS for now. * To avoid attribute conflicts, request UC MINUS here
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 5/8 arch/x86/mm/pat: export pat_enabled()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Two Linux device drivers cannot work with PAT and the work required to make them work is significant. There is not enough motivation to convert these drivers over to use PAT properly, the compromise reached is to let drivers that cannot be ported to PAT check if PAT was enabled and if so fail on probe with a recommendation to boot with the "nopat" kernel parameter.
--- arch/x86/mm/pat.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/mm/pat.c +1 -0
@@ -45,6 +45,7 @@ bool pat_enabled(void) {return !!__pat_enabled; } +EXPORT_SYMBOL_GPL (pat_enabled);int pat_debug_enable;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v4 1/8] x86/mm/pat: use pr_info() and friends
In reply to Luis R. RodriguezQuoted 2 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Please add a commit message, albeit a single trivial sentence.
arch/x86/mm/pat.c
Quoted 21 lines
Cc Andy Walls <[email protected]>Cc Doug Ledford <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Borislav Petkov <[email protected]>Cc Michael S. Tsirkin <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- arch/x86/mm/pat.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)arch/x86/mm/pat.c +0
-0
#define pr_fmt(fmt) "PAT: " fmt
or so, so that it has a prefix and lookers can know where the message comes from.
Quoted 33 lines
arch/x86/mm/pat.c +5
-6@@ -39,7 +39,7 @@ int __read_mostly pat_enabled = 1;static inline void pat_disable (const char *reason) { pat_enabled =0 ; -printk (KERN_INFO "%s\n" , reason); +pr_info ("%s\n" , reason); }static int __init nopat (char *str)@@ -211,8 +211,7 @@ void pat_init(void)* switched to PAT on the boot CPU. We have no way to * undo PAT. */ -printk (KERN_ERR "PAT enabled, " -"but not supported by secondary CPU\n" ); +pr_err ("PAT enabled, but not supported by secondary CPU\n" );BUG (); } }@@ -451,9 +450,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, err =rbt_memtype_check_insert (new, new_type);if (err) { -printk (KERN_INFO "reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , - start, end -1 , -cattr_name (new->type),cattr_name (req_type)); +pr_info ("reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , + start, end -1 , +cattr_name (new->type),cattr_name (req_type));kfree (new);spin_unlock (&memtype_lock);
arch/x86/mm/pat.c int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, · line 467
Quoted 6 lines
arch/x86/mm/pat.c +0
-3@@ -462,9 +461,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,spin_unlock (&memtype_lock); -dprintk ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , - start, end -1 ,cattr_name (new->type),cattr_name (req_type), - new_type ?cattr_name (*new_type) :"-" );
This was using "debugpat"...
arch/x86/mm/pat.c int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, · line 466
Quoted 3 lines
arch/x86/mm/pat.c +3
-0+pr_debug ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , + start, end -1 ,cattr_name (new->type),cattr_name (req_type), + new_type ?cattr_name (*new_type) :"-" );
... and now that pr_debug() ugliness which I can't enable at boot time.
Quoted 1 line
From looking at
Documentation/dynamic-debug-howto.txtapparently I can
using dyndbg= but let's not change that.
Quoted 8 lines
arch/x86/mm/pat.c +0
-2return err; }@@ -497,14 +496,15 @@ int free_memtype(u64 start, u64 end)spin_unlock (&memtype_lock);if (!entry) { -printk (KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , - current->comm, current->pid, start, end -1 );
arch/x86/mm/pat.c int free_memtype(u64 start, u64 end) · line 507
Quoted 10 lines
arch/x86/mm/pat.c +4
-1+pr_info ("%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , + current->comm, current->pid, start, end -1 );return -EINVAL ; }kfree (entry); -dprintk ("free_memtype request [mem %#010Lx-%#010Lx]\n" , start, end -1 ); +pr_debug ("free_memtype request [mem %#010Lx-%#010Lx]\n" , + start, end -1 );
Ditto.
Quoted 35 lines
arch/x86/mm/pat.c +4
-5return 0 ; }@@ -628,8 +628,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)while (cursor < to) {if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , - current->comm, from, to -1 ); +pr_info ("Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , + current->comm, from, to -1 );return 0 ; } cursor +=PAGE_SIZE ;@@ -698,8 +698,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, size;if (ioremap_change_attr ((unsigned long )__va (base), id_sz, pcm) <0 ) { -printk (KERN_INFO "%s:%d ioremap_change_attr failed %s " -"for [mem %#010Lx-%#010Lx]\n" , +pr_info ("%s:%d ioremap_change_attr failed %s for [mem %#010Lx-%#010Lx]\n" , current->comm, current->pid,cattr_name (pcm), base, (unsigned long long )(base + size-1 ));@@ -734,7 +733,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, pcm =lookup_memtype (paddr);if (want_pcm != pcm) { - printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", + pr_warn("%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", current->comm, current->pid, cattr_name(want_pcm), (unsigned long long)paddr,@@ -755,13 +754,13 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, if (strict_prot ||
arch/x86/mm/pat.c static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, · line 757
Quoted 10 lines
arch/x86/mm/pat.c +1
-7!is_new_memtype_allowed(paddr, size, want_pcm, pcm)) {free_memtype (paddr, paddr + size); -printk (KERN_ERR "%s:%d map pfn expected mapping type %s" -" for [mem %#010Lx-%#010Lx], got %s\n" , - current->comm, current->pid, -cattr_name (want_pcm), - (unsigned long long )paddr, - (unsigned long long )(paddr + size -1 ), -cattr_name (pcm)); + pr_err(KERN_ERR "%s:%d map pfn expected mapping type %s"
KERN_ERR forgotten.
Use checkpatch but don't take it too seriously :-)
Quoted 12 lines
arch/x86/mm/pat.c +6
-0+" for [mem %#010Lx-%#010Lx], got %s\n" , + current->comm, current->pid, +cattr_name (want_pcm), + (unsigned long long )paddr, + (unsigned long long )(paddr + size -1 ), + cattr_name(pcm));return -EINVAL ; }/* Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH v4 2/8] init.h: add __read_mostly to early_param_on_off()
In reply to Luis R. RodriguezQuoted 1 line · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
So this one is missing a commit message too but we need to talk about this. Why are we adding __read_mostly in the macro? This would put every param declared this way into __section__(".data..read_mostly") and I'm not really convinced that is needed.
Those setup params get accessed a couple of times only during boot, in non-critical paths so we don't really care.
If you care about pat_enabled being read a lot, you could do:
int __read_mostly pat_enabled;
only for it.
But for every param declared this way? I'm not sure we want that...
Quoted 31 lines
Cc Andy Walls <[email protected]>Cc Doug Ledford <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Borislav Petkov <[email protected]>Cc Michael S. Tsirkin <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/init.h +1
-1@@ -272,7 +272,7 @@ struct obs_kernel_param {#define early_param_on_off (str_on, str_off, var, config) \ \ - int var = IS_ENABLED(config); \ + int __read_mostly var = IS_ENABLED(config); \ \ static int __init parse_##var##_on(char *arg) \ { \
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH v4 1/8] x86/mm/pat: use pr_info() and friends
In reply to Borislav PetkovQuoted 30 lines · Borislav Petkov
Quoted 2 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Please add a commit message, albeit a single trivial sentence.
arch/x86/mm/pat.c
Quoted 21 lines
Cc Andy Walls <[email protected]>Cc Doug Ledford <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Borislav Petkov <[email protected]>Cc Michael S. Tsirkin <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- arch/x86/mm/pat.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-)arch/x86/mm/pat.c +0
-0#define
pr_fmt(fmt)"PAT: " fmt
Quoted 2 lines
or so, so that it has a prefix and lookers can know where the message comes from.
Sure, I didn't as I thought this was already automatically going to be added for is, after I added the build complained about it being defined. I checked an we udef it and redefine it for some other x86 code so will do the same. I'll use "x86-PAT".
Quoted 42 lines
Quoted 33 lines
arch/x86/mm/pat.c +5
-6@@ -39,7 +39,7 @@ int __read_mostly pat_enabled = 1;static inline void pat_disable (const char *reason) { pat_enabled =0 ; -printk (KERN_INFO "%s\n" , reason); +pr_info ("%s\n" , reason); }static int __init nopat (char *str)@@ -211,8 +211,7 @@ void pat_init(void)* switched to PAT on the boot CPU. We have no way to * undo PAT. */ -printk (KERN_ERR "PAT enabled, " -"but not supported by secondary CPU\n" ); +pr_err ("PAT enabled, but not supported by secondary CPU\n" );BUG (); } }@@ -451,9 +450,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, err =rbt_memtype_check_insert (new, new_type);if (err) { -printk (KERN_INFO "reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , - start, end -1 , -cattr_name (new->type),cattr_name (req_type)); +pr_info ("reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n" , + start, end -1 , +cattr_name (new->type),cattr_name (req_type));kfree (new);spin_unlock (&memtype_lock);arch/x86/mm/pat.c int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, · line 467
Quoted 6 lines
arch/x86/mm/pat.c +0
-3@@ -462,9 +461,9 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,spin_unlock (&memtype_lock); -dprintk ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , - start, end -1 ,cattr_name (new->type),cattr_name (req_type), - new_type ?cattr_name (*new_type) :"-" );This was using "debugpat"...
Quoted 7 lines
arch/x86/mm/pat.c int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, · line 466
Quoted 3 lines
arch/x86/mm/pat.c +3
-0+pr_debug ("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n" , + start, end -1 ,cattr_name (new->type),cattr_name (req_type), + new_type ?cattr_name (*new_type) :"-" );... and now that
pr_debug()ugliness which I can't enable at boot time. From looking atDocumentation/dynamic-debug-howto.txtapparently I can using dyndbg= but let's not change that.
OK sure, I'll leave this and mention the few remaining non-converted stragglers on the commit log, I'll also add a "x86-PAT-debug" prefix to dprintk().
Quoted 13 lines
Quoted 13 lines
arch/x86/mm/pat.c +2
-2return err; }@@ -497,14 +496,15 @@ int free_memtype(u64 start, u64 end)spin_unlock (&memtype_lock);if (!entry) { -printk (KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , - current->comm, current->pid, start, end -1 ); +pr_info ("%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n" , + current->comm, current->pid, start, end -1 );return -EINVAL ; }
Quoted 7 lines
arch/x86/mm/pat.c int free_memtype(u64 start, u64 end) · line 507
Quoted 5 lines
arch/x86/mm/pat.c +2
-1kfree (entry); -dprintk ("free_memtype request [mem %#010Lx-%#010Lx]\n" , start, end -1 ); +pr_debug ("free_memtype request [mem %#010Lx-%#010Lx]\n" , + start, end -1 );Ditto.
OK, fixed.
Quoted 48 lines
Quoted 35 lines
arch/x86/mm/pat.c +4
-5return 0 ; }@@ -628,8 +628,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)while (cursor < to) {if (!devmem_is_allowed (pfn)) { -printk (KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , - current->comm, from, to -1 ); +pr_info ("Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx], PAT prevents it\n" , + current->comm, from, to -1 );return 0 ; } cursor +=PAGE_SIZE ;@@ -698,8 +698,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, size;if (ioremap_change_attr ((unsigned long )__va (base), id_sz, pcm) <0 ) { -printk (KERN_INFO "%s:%d ioremap_change_attr failed %s " -"for [mem %#010Lx-%#010Lx]\n" , +pr_info ("%s:%d ioremap_change_attr failed %s for [mem %#010Lx-%#010Lx]\n" , current->comm, current->pid,cattr_name (pcm), base, (unsigned long long )(base + size-1 ));@@ -734,7 +733,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, pcm =lookup_memtype (paddr);if (want_pcm != pcm) { - printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", + pr_warn("%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n", current->comm, current->pid, cattr_name(want_pcm), (unsigned long long)paddr,@@ -755,13 +754,13 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, if (strict_prot ||arch/x86/mm/pat.c static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot, · line 757
Quoted 10 lines
arch/x86/mm/pat.c +1
-7!is_new_memtype_allowed(paddr, size, want_pcm, pcm)) {free_memtype (paddr, paddr + size); -printk (KERN_ERR "%s:%d map pfn expected mapping type %s" -" for [mem %#010Lx-%#010Lx], got %s\n" , - current->comm, current->pid, -cattr_name (want_pcm), - (unsigned long long )paddr, - (unsigned long long )(paddr + size -1 ), -cattr_name (pcm)); + pr_err(KERN_ERR "%s:%d map pfn expected mapping type %s"
KERN_ERRforgotten.
Quoted 1 line
Use checkpatch but don't take it too seriously :-)
That was a fat finger rather. Fixed, thanks.
Luis
Re: [PATCH v4 2/8] init.h: add __read_mostly to early_param_on_off()
In reply to Borislav PetkovQuoted 11 lines · Borislav Petkov
Quoted 1 line · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
So this one is missing a commit message too but we need to talk about this. Why are we adding
__read_mostlyin the macro? This would put every param declared this way into__section__(".data..read_mostly")and I'm not really convinced that is needed.Those setup params get accessed a couple of times only during boot, in non-critical paths so we don't really care.
Quoted 7 lines
If you care about
pat_enabledbeing read a lot, you could do:int
__read_mostlypat_enabled;only for it.
But for every param declared this way? I'm not sure we want that...
I'm glad you bring this up, Christoph can you or anyone else can you provide advise since you added __read_mostly ?
I added this to early_param_on_off() given I saw a prevalence of __read_mostly in similar taste elsewhere in the kernel on kernel parameters, and since this patch tried to convert one kernel parameter which used __read_mostly over to early_param_on_off() I decided to add it and now we need to really decide if its ideal for kernel parameters or not.
In this particular case early_param_on_off() will be used for boot time kernel parameters which we do not intend on dynamically change a lot at run time, we at run time in early boot have to disable a feature but this will typically happen only once.
Luis
Quoted 13 lines
Quoted 13 lines
include/linux/init.h +1
-1@@ -272,7 +272,7 @@ struct obs_kernel_param {#define early_param_on_off (str_on, str_off, var, config) \ \ - int var = IS_ENABLED(config); \ + int __read_mostly var = IS_ENABLED(config); \ \ static int __init parse_##var##_on(char *arg) \ { \
Re: [PATCH v4 2/8] init.h: add __read_mostly to early_param_on_off()
Quoted 3 lines · Luis R. Rodriguez
, we
at run time in early boot have to disable a feature but this will typically happen only once.
Sorry I meant that we may need to disable a feature early at boot time, but this typically happens only once with the variable.
Luis
Re: [PATCH v4 2/8] init.h: add __read_mostly to early_param_on_off()
In reply to Luis R. RodriguezQuoted 3 lines · Luis R. Rodriguez
In this particular case
early_param_on_off()will be used for boot time kernel parameters which we do not intend on dynamically change a lot at run time, we
It is not about whether you're going to dynamically change it but more about how often it is accessed. If it is accessed only a couple of times tops during boot and then never again during the system lifetime - which is generally the case for most boot params - then you certainly don't want to pollute the read.mostly section with dead weight. You can just as well use a stinking normal variable.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Re: [PATCH v4 2/8] init.h: add __read_mostly to early_param_on_off()
In reply to Luis R. RodriguezQuoted 4 lines · Luis R. Rodriguez
Quoted 1 line
But for every param declared this way? I'm not sure we want that...
I'm glad you bring this up, Christoph can you or anyone else can you provide advise since you added
__read_mostly?
Well it should be reseved for data that is actually used frequently in hot paths. Initially we only moved variables into __read_mostly after we saw in performance traces that there was contention on an item because a neighboring variable was frequently written to.
You want the __read_mostly data to be tighly packed. In the best case multiple frequently read variables for a hot path will be next to each other in order to reduce the number of cachelines needed to execute a critical path. That means being selective and aware of which variables actually benefit.