Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-15 Thread Jürgen Groß

On 15.01.20 17:32, Sergey Dyasli wrote:

On 15/01/2020 11:09, Jürgen Groß wrote:

On 15.01.20 11:54, Sergey Dyasli wrote:

Hi Juergen,

On 08/01/2020 15:20, Sergey Dyasli wrote:

It is incorrect to call pmd_populate_kernel() multiple times for the
same page table. Xen notices it during kasan_populate_early_shadow():

  (XEN) mm.c:3222:d155v0 mfn 3704b already pinned

This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is
enabled. Fix this by introducing set_pmd_early_shadow() which calls
pmd_populate_kernel() only once and uses set_pmd() afterwards.

Signed-off-by: Sergey Dyasli 


Looks like the plan to use set_pmd() directly has failed: it's an
arch-specific function and can't be used in arch-independent code
(as kbuild test robot has proven).

Do you see any way out of this other than disabling SPLIT_PTE_PTLOCKS
for PV KASAN?


Change set_pmd_early_shadow() like the following:

#ifdef CONFIG_XEN_PV
static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
{
 static bool pmd_populated = false;

 if (likely(pmd_populated)) {
 set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
 } else {
 pmd_populate_kernel(_mm, pmd, early_shadow);
 pmd_populated = true;
 }
}
#else
static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
{
 pmd_populate_kernel(_mm, pmd, early_shadow);
}
#endif

... and move it to include/xen/xen-ops.h and call it with
lm_alias(kasan_early_shadow_pte) as the second parameter.


Your suggestion to use ifdef is really good, especially now when I
figured out that CONFIG_XEN_PV implies X86. But I don't like the idea
of kasan code calling a non-empty function from xen-ops.h when
CONFIG_XEN_PV is not defined. I'd prefer to keep set_pmd_early_shadow()
in mm/kasan/init.c with the suggested ifdef.


Fine with me.


Juergen

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-15 Thread Sergey Dyasli
On 15/01/2020 11:09, Jürgen Groß wrote:
> On 15.01.20 11:54, Sergey Dyasli wrote:
>> Hi Juergen,
>>
>> On 08/01/2020 15:20, Sergey Dyasli wrote:
>>> It is incorrect to call pmd_populate_kernel() multiple times for the
>>> same page table. Xen notices it during kasan_populate_early_shadow():
>>>
>>>  (XEN) mm.c:3222:d155v0 mfn 3704b already pinned
>>>
>>> This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is
>>> enabled. Fix this by introducing set_pmd_early_shadow() which calls
>>> pmd_populate_kernel() only once and uses set_pmd() afterwards.
>>>
>>> Signed-off-by: Sergey Dyasli 
>>
>> Looks like the plan to use set_pmd() directly has failed: it's an
>> arch-specific function and can't be used in arch-independent code
>> (as kbuild test robot has proven).
>>
>> Do you see any way out of this other than disabling SPLIT_PTE_PTLOCKS
>> for PV KASAN?
>
> Change set_pmd_early_shadow() like the following:
>
> #ifdef CONFIG_XEN_PV
> static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
> {
> static bool pmd_populated = false;
>
> if (likely(pmd_populated)) {
> set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
> } else {
> pmd_populate_kernel(_mm, pmd, early_shadow);
> pmd_populated = true;
> }
> }
> #else
> static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
> {
> pmd_populate_kernel(_mm, pmd, early_shadow);
> }
> #endif
>
> ... and move it to include/xen/xen-ops.h and call it with
> lm_alias(kasan_early_shadow_pte) as the second parameter.

Your suggestion to use ifdef is really good, especially now when I
figured out that CONFIG_XEN_PV implies X86. But I don't like the idea
of kasan code calling a non-empty function from xen-ops.h when
CONFIG_XEN_PV is not defined. I'd prefer to keep set_pmd_early_shadow()
in mm/kasan/init.c with the suggested ifdef.

--
Thanks,
Sergey

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-15 Thread Jürgen Groß

On 15.01.20 11:54, Sergey Dyasli wrote:

Hi Juergen,

On 08/01/2020 15:20, Sergey Dyasli wrote:

It is incorrect to call pmd_populate_kernel() multiple times for the
same page table. Xen notices it during kasan_populate_early_shadow():

 (XEN) mm.c:3222:d155v0 mfn 3704b already pinned

This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is
enabled. Fix this by introducing set_pmd_early_shadow() which calls
pmd_populate_kernel() only once and uses set_pmd() afterwards.

Signed-off-by: Sergey Dyasli 


Looks like the plan to use set_pmd() directly has failed: it's an
arch-specific function and can't be used in arch-independent code
(as kbuild test robot has proven).

Do you see any way out of this other than disabling SPLIT_PTE_PTLOCKS
for PV KASAN?


Change set_pmd_early_shadow() like the following:

#ifdef CONFIG_XEN_PV
static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
{
static bool pmd_populated = false;

if (likely(pmd_populated)) {
set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
} else {
pmd_populate_kernel(_mm, pmd, early_shadow);
pmd_populated = true;
}
}
#else
static inline void set_pmd_early_shadow(pmd_t *pmd, pte_t *early_shadow)
{
pmd_populate_kernel(_mm, pmd, early_shadow);
}
#endif

... and move it to include/xen/xen-ops.h and call it with
lm_alias(kasan_early_shadow_pte) as the second parameter.


Juergen

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-15 Thread Sergey Dyasli
Hi Juergen,

On 08/01/2020 15:20, Sergey Dyasli wrote:
> It is incorrect to call pmd_populate_kernel() multiple times for the
> same page table. Xen notices it during kasan_populate_early_shadow():
>
> (XEN) mm.c:3222:d155v0 mfn 3704b already pinned
>
> This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is
> enabled. Fix this by introducing set_pmd_early_shadow() which calls
> pmd_populate_kernel() only once and uses set_pmd() afterwards.
>
> Signed-off-by: Sergey Dyasli 

Looks like the plan to use set_pmd() directly has failed: it's an
arch-specific function and can't be used in arch-independent code
(as kbuild test robot has proven).

Do you see any way out of this other than disabling SPLIT_PTE_PTLOCKS
for PV KASAN?

--
Thanks,
Sergey

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-10 Thread kbuild test robot
Hi Sergey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v5.5-rc5 next-20200109]
[cannot apply to xen-tip/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Sergey-Dyasli/basic-KASAN-support-for-Xen-PV-domains/20200110-042623
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 
4a4a52d49d11f5c4a0df8b9806c8c5563801f753
config: s390-allmodconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 7.5.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=s390 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All errors (new ones prefixed by >>):

   mm//kasan/init.c: In function 'set_pmd_early_shadow':
>> mm//kasan/init.c:90:3: error: implicit declaration of function 'set_pmd'; 
>> did you mean 'get_pid'? [-Werror=implicit-function-declaration]
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^~~
  get_pid
   In file included from arch/s390/include/asm/thread_info.h:26:0,
from include/linux/thread_info.h:38,
from arch/s390/include/asm/preempt.h:6,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:10,
from include/linux/memblock.h:13,
from mm//kasan/init.c:14:
   mm//kasan/init.c:90:43: error: '_PAGE_TABLE' undeclared (first use in this 
function); did you mean 'NR_PAGETABLE'?
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/s390/include/asm/page.h:96:37: note: in definition of macro '__pmd'
#define __pmd(x)((pmd_t) { (x) } )
^
   mm//kasan/init.c:90:43: note: each undeclared identifier is reported only 
once for each function it appears in
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/s390/include/asm/page.h:96:37: note: in definition of macro '__pmd'
#define __pmd(x)((pmd_t) { (x) } )
^
   cc1: some warnings being treated as errors

vim +90 mm//kasan/init.c

83  
84  static inline void set_pmd_early_shadow(pmd_t *pmd)
85  {
86  static bool pmd_populated = false;
87  pte_t *early_shadow = lm_alias(kasan_early_shadow_pte);
88  
89  if (likely(pmd_populated)) {
  > 90  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
91  } else {
92  pmd_populate_kernel(_mm, pmd, early_shadow);
93  pmd_populated = true;
94  }
95  }
96  

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org Intel Corporation


.config.gz
Description: application/gzip
___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-10 Thread kbuild test robot
Hi Sergey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v5.5-rc5 next-20200109]
[cannot apply to xen-tip/linux-next]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Sergey-Dyasli/basic-KASAN-support-for-Xen-PV-domains/20200110-042623
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 
4a4a52d49d11f5c4a0df8b9806c8c5563801f753
config: arm64-randconfig-a001-20200109 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 7.5.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=arm64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All error/warnings (new ones prefixed by >>):

   In file included from arch/arm64/include/asm/kasan.h:9:0,
from arch/arm64/include/asm/processor.h:34,
from include/asm-generic/qrwlock.h:14,
from ./arch/arm64/include/generated/asm/qrwlock.h:1,
from arch/arm64/include/asm/spinlock.h:8,
from include/linux/spinlock.h:89,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:10,
from include/linux/memblock.h:13,
from mm/kasan/init.c:14:
   mm/kasan/init.c: In function 'set_pmd_early_shadow':
>> mm/kasan/init.c:90:43: error: '_PAGE_TABLE' undeclared (first use in this 
>> function); did you mean 'NR_PAGETABLE'?
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/arm64/include/asm/pgtable-types.h:40:30: note: in definition of macro 
'__pgd'
#define __pgd(x) ((pgd_t) { (x) } )
 ^
>> include/asm-generic/pgtable-nopmd.h:50:32: note: in expansion of macro 
>> '__pud'
#define __pmd(x)((pmd_t) { __pud(x) } )
   ^
>> mm/kasan/init.c:90:16: note: in expansion of macro '__pmd'
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
   ^
   mm/kasan/init.c:90:43: note: each undeclared identifier is reported only 
once for each function it appears in
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/arm64/include/asm/pgtable-types.h:40:30: note: in definition of macro 
'__pgd'
#define __pgd(x) ((pgd_t) { (x) } )
 ^
>> include/asm-generic/pgtable-nopmd.h:50:32: note: in expansion of macro 
>> '__pud'
#define __pmd(x)((pmd_t) { __pud(x) } )
   ^
>> mm/kasan/init.c:90:16: note: in expansion of macro '__pmd'
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
   ^
--
   In file included from arch/arm64/include/asm/kasan.h:9:0,
from arch/arm64/include/asm/processor.h:34,
from include/asm-generic/qrwlock.h:14,
from ./arch/arm64/include/generated/asm/qrwlock.h:1,
from arch/arm64/include/asm/spinlock.h:8,
from include/linux/spinlock.h:89,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:10,
from include/linux/memblock.h:13,
from mm//kasan/init.c:14:
   mm//kasan/init.c: In function 'set_pmd_early_shadow':
   mm//kasan/init.c:90:43: error: '_PAGE_TABLE' undeclared (first use in this 
function); did you mean 'NR_PAGETABLE'?
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/arm64/include/asm/pgtable-types.h:40:30: note: in definition of macro 
'__pgd'
#define __pgd(x) ((pgd_t) { (x) } )
 ^
>> include/asm-generic/pgtable-nopmd.h:50:32: note: in expansion of macro 
>> '__pud'
#define __pmd(x)((pmd_t) { __pud(x) } )
   ^
   mm//kasan/init.c:90:16: note: in expansion of macro '__pmd'
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
   ^
   mm//kasan/init.c:90:43: note: each undeclared identifier is reported only 
once for each function it appears in
  set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
  ^
   arch/arm64/include/asm/pgtable-types.h:40:30: note: in definition of macro 
'__pgd'
#define 

[Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow()

2020-01-08 Thread Sergey Dyasli
It is incorrect to call pmd_populate_kernel() multiple times for the
same page table. Xen notices it during kasan_populate_early_shadow():

(XEN) mm.c:3222:d155v0 mfn 3704b already pinned

This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is
enabled. Fix this by introducing set_pmd_early_shadow() which calls
pmd_populate_kernel() only once and uses set_pmd() afterwards.

Signed-off-by: Sergey Dyasli 
---
RFC --> v1:
- New patch
---
 mm/kasan/init.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/mm/kasan/init.c b/mm/kasan/init.c
index ce45c491ebcd..a4077320777f 100644
--- a/mm/kasan/init.c
+++ b/mm/kasan/init.c
@@ -81,6 +81,19 @@ static inline bool kasan_early_shadow_page_entry(pte_t pte)
return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page));
 }
 
+static inline void set_pmd_early_shadow(pmd_t *pmd)
+{
+   static bool pmd_populated = false;
+   pte_t *early_shadow = lm_alias(kasan_early_shadow_pte);
+
+   if (likely(pmd_populated)) {
+   set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE));
+   } else {
+   pmd_populate_kernel(_mm, pmd, early_shadow);
+   pmd_populated = true;
+   }
+}
+
 static __init void *early_alloc(size_t size, int node)
 {
void *ptr = memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),
@@ -120,8 +133,7 @@ static int __ref zero_pmd_populate(pud_t *pud, unsigned 
long addr,
next = pmd_addr_end(addr, end);
 
if (IS_ALIGNED(addr, PMD_SIZE) && end - addr >= PMD_SIZE) {
-   pmd_populate_kernel(_mm, pmd,
-   lm_alias(kasan_early_shadow_pte));
+   set_pmd_early_shadow(pmd);
continue;
}
 
@@ -157,8 +169,7 @@ static int __ref zero_pud_populate(p4d_t *p4d, unsigned 
long addr,
pud_populate(_mm, pud,
lm_alias(kasan_early_shadow_pmd));
pmd = pmd_offset(pud, addr);
-   pmd_populate_kernel(_mm, pmd,
-   lm_alias(kasan_early_shadow_pte));
+   set_pmd_early_shadow(pmd);
continue;
}
 
@@ -198,8 +209,7 @@ static int __ref zero_p4d_populate(pgd_t *pgd, unsigned 
long addr,
pud_populate(_mm, pud,
lm_alias(kasan_early_shadow_pmd));
pmd = pmd_offset(pud, addr);
-   pmd_populate_kernel(_mm, pmd,
-   lm_alias(kasan_early_shadow_pte));
+   set_pmd_early_shadow(pmd);
continue;
}
 
@@ -271,8 +281,7 @@ int __ref kasan_populate_early_shadow(const void 
*shadow_start,
pud_populate(_mm, pud,
lm_alias(kasan_early_shadow_pmd));
pmd = pmd_offset(pud, addr);
-   pmd_populate_kernel(_mm, pmd,
-   lm_alias(kasan_early_shadow_pte));
+   set_pmd_early_shadow(pmd);
continue;
}
 
-- 
2.17.1


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel