Re: [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location()

2018-01-04 Thread Alexander Kuleshov
On 01-04-18, Baoquan He wrote:
> On 01/04/18 at 03:54pm, Alexander Kuleshov wrote:
> > we align minimal possible address during randomization to 
> > CONFIG_PHYSICAL_ALIGN
> > two times: during getting of random physical address and virtual
> > address (only for x86_64).
> > 
> > Let's move this to choose_random_location() to not duplicate code in
> > find_random_virt_addr() and find_random_phys_addr().
> > 
> > Signed-off-by: Alexander Kuleshov 
> > ---
> >  arch/x86/boot/compressed/kaslr.c | 8 +++-
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/x86/boot/compressed/kaslr.c 
> > b/arch/x86/boot/compressed/kaslr.c
> > index 8199a6187251..8c93e399fdfd 100644
> > --- a/arch/x86/boot/compressed/kaslr.c
> > +++ b/arch/x86/boot/compressed/kaslr.c
> > @@ -673,9 +673,6 @@ static unsigned long find_random_phys_addr(unsigned 
> > long minimum,
> > return 0;
> > }
> >  
> > -   /* Make sure minimum is aligned. */
> > -   minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> > -
> > if (process_efi_entries(minimum, image_size))
> > return slots_fetch_random();
> >  
> > @@ -688,8 +685,6 @@ static unsigned long find_random_virt_addr(unsigned 
> > long minimum,
> >  {
> > unsigned long slots, random_addr;
> >  
> > -   /* Make sure minimum is aligned. */
> > -   minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> > /* Align image_size for easy slot calculations. */
> > image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
> >  
> > @@ -738,6 +733,9 @@ void choose_random_location(unsigned long input,
> >  */
> > min_addr = min(*output, 512UL << 20);
> >  
> > +   /* Make sure minimum is aligned. */
> > +   min_addr = ALIGN(min_addr, CONFIG_PHYSICAL_ALIGN);
> 
> Hmm, the min_addr is passed to find_random_phys_addr(), but not to
> find_random_virt_addr().

ah, yes, sorry for noise then


[PATCH] x86/KASLR: move aligning of minimal address to choose_random_location()

2018-01-04 Thread Alexander Kuleshov
we align minimal possible address during randomization to CONFIG_PHYSICAL_ALIGN
two times: during getting of random physical address and virtual
address (only for x86_64).

Let's move this to choose_random_location() to not duplicate code in
find_random_virt_addr() and find_random_phys_addr().

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/boot/compressed/kaslr.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8199a6187251..8c93e399fdfd 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -673,9 +673,6 @@ static unsigned long find_random_phys_addr(unsigned long 
minimum,
return 0;
}
 
-   /* Make sure minimum is aligned. */
-   minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
-
if (process_efi_entries(minimum, image_size))
return slots_fetch_random();
 
@@ -688,8 +685,6 @@ static unsigned long find_random_virt_addr(unsigned long 
minimum,
 {
unsigned long slots, random_addr;
 
-   /* Make sure minimum is aligned. */
-   minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
/* Align image_size for easy slot calculations. */
image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
 
@@ -738,6 +733,9 @@ void choose_random_location(unsigned long input,
 */
min_addr = min(*output, 512UL << 20);
 
+   /* Make sure minimum is aligned. */
+   min_addr = ALIGN(min_addr, CONFIG_PHYSICAL_ALIGN);
+
/* Walk available memory entries to find a random address. */
random_addr = find_random_phys_addr(min_addr, output_size);
if (!random_addr) {
-- 
2.14.3



[PATCH] assoc_array: fix path to assoc_array documentation

2017-08-22 Thread Alexander Kuleshov
Signed-off-by: Alexander Kuleshov 
---
 lib/assoc_array.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index 59fd7c0b119c..155c55d8db5f 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -1,6 +1,6 @@
 /* Generic associative array implementation.
  *
- * See Documentation/assoc_array.txt for information.
+ * See Documentation/core-api/assoc_array.rst for information.
  *
  * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowe...@redhat.com)
-- 
2.13.5



[tip:x86/cleanups] x86/traps: Get rid of unnecessary preempt_disable/preempt_enable_no_resched

2017-02-04 Thread tip-bot for Alexander Kuleshov
Commit-ID:  07d495dae20717b00881798ef812f7aa53ca0eb3
Gitweb: http://git.kernel.org/tip/07d495dae20717b00881798ef812f7aa53ca0eb3
Author: Alexander Kuleshov 
AuthorDate: Mon, 28 Nov 2016 13:50:57 +0600
Committer:  Thomas Gleixner 
CommitDate: Sat, 4 Feb 2017 09:36:59 +0100

x86/traps: Get rid of unnecessary preempt_disable/preempt_enable_no_resched

Exception handlers which may run on IST stack call ist_enter() at the start
of execution and ist_exit() in the end. ist_enter() disables preemption
unconditionally and ist_exit() enables it.

So the extra preempt_disable/enable() pairs nested inside the
ist_enter/exit() regions are pointless and can be removed.

Signed-off-by: Alexander Kuleshov 
Cc: Tony Luck 
Cc: Jianyu Zhan 
Cc: Paul Gortmaker 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Link: http://lkml.kernel.org/r/20161128075057.7724-1-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/kernel/traps.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index bf0c6d0..1dc86ee 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -563,11 +563,9 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, 
long error_code)
 * as we may switch to the interrupt stack.
 */
debug_stack_usage_inc();
-   preempt_disable();
cond_local_irq_enable(regs);
do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
 exit:
ist_exit(regs);
@@ -742,14 +740,12 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_inc();
 
/* It's safe to allow irq's after DR6 has been saved */
-   preempt_disable();
cond_local_irq_enable(regs);
 
if (v8086_mode(regs)) {
handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
X86_TRAP_DB);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
goto exit;
}
@@ -769,7 +765,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
send_sigtrap(tsk, regs, error_code, si_code);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
 
 exit:


[PATCH] x86/traps: get rid of unnecessary preempt_disable/preempt_enable_no_resched

2016-11-27 Thread Alexander Kuleshov
Exception handlers which may run on IST stack calls ist_enter() at the
start of execution and ist_exit() in the end. The ist_enter() disables
preemption unconditionally and ist_exit() enables it.

Besides this, such exception handlers do additional unnecessary calls
of preempt_disable() and preempt_enable_no_resched() after/before
ist_enter()/ist_exit(). Let's get rid from them.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/traps.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index bd4e3d4..5fbff64 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -563,11 +563,9 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, 
long error_code)
 * as we may switch to the interrupt stack.
 */
debug_stack_usage_inc();
-   preempt_disable();
cond_local_irq_enable(regs);
do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
 exit:
ist_exit(regs);
@@ -742,14 +740,12 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_inc();
 
/* It's safe to allow irq's after DR6 has been saved */
-   preempt_disable();
cond_local_irq_enable(regs);
 
if (v8086_mode(regs)) {
handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
X86_TRAP_DB);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
goto exit;
}
@@ -769,7 +765,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
send_sigtrap(tsk, regs, error_code, si_code);
cond_local_irq_disable(regs);
-   preempt_enable_no_resched();
debug_stack_usage_dec();
 
 exit:
-- 
2.8.0.rc3.1353.gea9bdc0



[tip:x86/asm] x86/entry64: Remove unused audit related macros

2016-10-25 Thread tip-bot for Alexander Kuleshov
Commit-ID:  5e25d5bdf6d407224ad185a3fb8b870ad7d6c627
Gitweb: http://git.kernel.org/tip/5e25d5bdf6d407224ad185a3fb8b870ad7d6c627
Author: Alexander Kuleshov 
AuthorDate: Sun, 23 Oct 2016 19:56:46 +0600
Committer:  Ingo Molnar 
CommitDate: Tue, 25 Oct 2016 11:43:31 +0200

x86/entry64: Remove unused audit related macros

These macros were added in the following commit:

  86a1c34a929f ("x86_64 syscall audit fast-path")

They were used in two-phase sycalls entry tracing, but this functionality
was then moved to the arch/x86/entry/common.c:syscall_trace_enter() function,
in the following commit:

  1f484aa69046 ("x86/entry: Move C entry and exit code to 
arch/x86/entry/common.c")

syscall_trace_enter() now uses the defines from ,
so these defines entry_64.S are no longer used anywhere.

Signed-off-by: Alexander Kuleshov 
Reviewed-by: Borislav Petkov 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Paolo Bonzini 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: http://lkml.kernel.org/r/20161023135646.4453-1-kuleshovm...@gmail.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64.S | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 65fad8a..5b21970 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -38,12 +38,6 @@
 #include 
 #include 
 
-/* Avoid __ASSEMBLER__'ifying  just for this.  */
-#include 
-#define AUDIT_ARCH_X86_64  
(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
-#define __AUDIT_ARCH_64BIT 0x8000
-#define __AUDIT_ARCH_LE0x4000
-
 .code64
 .section .entry.text, "ax"
 


[PATCH] x86/entry64: move comment about informing of context tracking in right place

2016-10-24 Thread Alexander Kuleshov
We are switching to kernel gsbase if an IRQ come from usermode with swpags.
Now there is comment which describes this:

  IRQ from user mode. Switch to kernel gsbase and inform context tracking that
  we're in kernel mode.

But now we execute swapgs, next TRACE_IRQS_OFF and only then the
CALL_enter_from_user_mode macro expands to the informing of
context tracking about this event. Let's move part of comment to
the right place where actual call to context tracing occured.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/entry/entry_64.S | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ef766a3..5e97642 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -474,8 +474,7 @@ END(irq_entries_start)
jz  1f
 
/*
-* IRQ from user mode.  Switch to kernel gsbase and inform context
-* tracking that we're in kernel mode.
+* IRQ from user mode.  Switch to kernel gsbase.
 */
SWAPGS
 
@@ -489,6 +488,9 @@ END(irq_entries_start)
 */
TRACE_IRQS_OFF
 
+   /*
+* Inform context tracking that we're in kernel mode.
+*/
CALL_enter_from_user_mode
 
 1:
-- 
2.8.0.rc3.1353.gea9bdc0



[PATCH v3] x86/entry64: remove unused audit related macros

2016-10-23 Thread Alexander Kuleshov
These macros were added in:

  86a1c34 ("x86_64 syscall audit fast-path")

commit. They were used in two-phase sycalls entry tracing,
but this functionality was moved to the
arch/x86/entry/common.c:syscall_trace_enter() in:

  1f484aa ("x86/entry: Move C entry and exit code to arch/x86/entry/common.c")

commit.

syscall_trace_enter() now uses same defines from ,
so these defines are no longer used anywhere in entry_64.S outside
of it and we may remove them.

Signed-off-by: Alexander Kuleshov 
Reviewed-by: Borislav Petkov 
---
ChangeLog:

v1 -> v2:

- Added more details in the commit message.

v2 -> v2:

- Make commit message more readable  

 arch/x86/entry/entry_64.S | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ef766a3..4362f1c 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -38,12 +38,6 @@
 #include 
 #include 
 
-/* Avoid __ASSEMBLER__'ifying  just for this.  */
-#include 
-#define AUDIT_ARCH_X86_64  
(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
-#define __AUDIT_ARCH_64BIT 0x8000
-#define __AUDIT_ARCH_LE0x4000
-
 .code64
 .section .entry.text, "ax"
 
-- 
2.8.0.rc3.1353.gea9bdc0



Re: [PATCH v2] x86/entry64: remove unused audit related macros

2016-10-23 Thread Alexander Kuleshov
On 10-23-16, Borislav Petkov wrote:
> Now, I went and made it a bit more readable and put the commit IDs and
> their names on separate lines, like we do in tip:
> 
> "These macros were added in commit
> 
>   86a1c34a929f ("x86_64 syscall audit fast-path").
> 
> They were used for sycalls auditing, but this functionality was moved to
> the arch/x86/entry/common.c:syscall_trace_enter() in
> 
>   1f484aa69046 ("x86/entry: Move C entry and exit code to 
> arch/x86/entry/common.c")
> 
> syscall_trace_enter() now uses the same defines from ,
> so these defines are no longer used anywhere in entry_64.S and we may
> remove them."
>

Agree, this looks more readable. I will take into account this formatting.

> Also, we abbreviate git commits to 12 chars. What you could do is add
> this to your .gitconfig:
> 
> [alias]
> one = show -s --pretty='format:%h (\"%s\")'
> 
> and then simply do
> 
> $ git one 1f484aa69
> 
> and it'll format it properly for ya.
> 
> Anyway, just a couple of things to pay attention to in the future.

Yes, thanks for this.

> With this, you can add
> 
> Reviewed-by: Borislav Petkov 
> 
> to your v3.

Thank you.


[PATCH v2] x86/entry64: remove unused audit related macros

2016-10-23 Thread Alexander Kuleshov
These macro ocured in the 86a1c34a929f commit (x86_64 syscall audit
fast-path by Roland McGrath ).

These defines were used in two-phase sycalls entry tracing, but
this functionality was moved to the syscall_trace_enter() from
arch/x86/entry/common.c in the 1f484aa69 commit (x86/entry: Move
C entry and exit code to arch/x86/entry/common.c by Andy Lutomirski
).

The syscall_trace_enter() now uses same defines from ,
so these defines are no longer used anywhere in entry_64.S and we may
remove them.

Signed-off-by: Alexander Kuleshov 
---
ChangeLog:

v1 -> v2:
- Added more details in the commit message.

 arch/x86/entry/entry_64.S | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ef766a3..4362f1c 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -38,12 +38,6 @@
 #include 
 #include 
 
-/* Avoid __ASSEMBLER__'ifying  just for this.  */
-#include 
-#define AUDIT_ARCH_X86_64  
(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
-#define __AUDIT_ARCH_64BIT 0x8000
-#define __AUDIT_ARCH_LE0x4000
-
 .code64
 .section .entry.text, "ax"
 
-- 
2.8.0.rc3.1353.gea9bdc0



Re: [PATCH] x86/entry64: remove unused audit related macros

2016-10-23 Thread Alexander Kuleshov
Hello Borislav,

On 10-23-16, Borislav Petkov wrote:
> I'd prefer it if you said which patch *removed* them and made those
> defines unused again.
> 
> What would be even better is if your commit message explained *why* they
> were removed in that patch and that because of  we
> don't need them here anymore.
> 
> This should give people looking at your patch the warm and fuzzy feeling
> they need in order to apply it. :-)

I will describe this in V2.

Thanks.



[PATCH] x86/entry64: remove unused audit related macros

2016-10-22 Thread Alexander Kuleshov
which are ocured in the 86a1c34a929f commit (x86_64 syscall audit
fast-path by Roland McGrath ) and now they are
not used anymore.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/entry/entry_64.S | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ef766a3..4362f1c 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -38,12 +38,6 @@
 #include 
 #include 
 
-/* Avoid __ASSEMBLER__'ifying  just for this.  */
-#include 
-#define AUDIT_ARCH_X86_64  
(EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
-#define __AUDIT_ARCH_64BIT 0x8000
-#define __AUDIT_ARCH_LE0x4000
-
 .code64
 .section .entry.text, "ax"
 
-- 
2.8.0.rc3.1353.gea9bdc0



[tip:x86/asm] entry/64: Remove unused ZERO_EXTRA_REGS macro

2016-10-20 Thread tip-bot for Alexander Kuleshov
Commit-ID:  29a6d7964d6853f5bcd84dfb92c074fb41d00563
Gitweb: http://git.kernel.org/tip/29a6d7964d6853f5bcd84dfb92c074fb41d00563
Author: Alexander Kuleshov 
AuthorDate: Thu, 20 Oct 2016 18:07:04 +0600
Committer:  Ingo Molnar 
CommitDate: Fri, 21 Oct 2016 07:47:36 +0200

entry/64: Remove unused ZERO_EXTRA_REGS macro

Signed-off-by: Alexander Kuleshov 
Cc: Paolo Bonzini 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Link: http://lkml.kernel.org/r/20161020120704.24042-1-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/calling.h | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index b493c6a..38dcdfa 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -147,15 +147,6 @@ For 32-bit we have the following conventions - kernel is 
built with
movq 5*8+\offset(%rsp), %rbx
.endm
 
-   .macro ZERO_EXTRA_REGS
-   xorl%r15d, %r15d
-   xorl%r14d, %r14d
-   xorl%r13d, %r13d
-   xorl%r12d, %r12d
-   xorl%ebp, %ebp
-   xorl%ebx, %ebx
-   .endm
-
.macro RESTORE_C_REGS_HELPER rstor_rax=1, rstor_rcx=1, rstor_r11=1, 
rstor_r8910=1, rstor_rdx=1
.if \rstor_r11
movq 6*8(%rsp), %r11


[tip:x86/urgent] entry/64: Remove unused ZERO_EXTRA_REGS macro

2016-10-20 Thread tip-bot for Alexander Kuleshov
Commit-ID:  b05d20f9a12fb7795b2bd220e7dd56e29e196ba8
Gitweb: http://git.kernel.org/tip/b05d20f9a12fb7795b2bd220e7dd56e29e196ba8
Author: Alexander Kuleshov 
AuthorDate: Thu, 20 Oct 2016 18:07:04 +0600
Committer:  Thomas Gleixner 
CommitDate: Thu, 20 Oct 2016 23:41:15 +0200

entry/64: Remove unused ZERO_EXTRA_REGS macro

Signed-off-by: Alexander Kuleshov 
Cc: Paolo Bonzini 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Link: http://lkml.kernel.org/r/20161020120704.24042-1-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/entry/calling.h | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index b493c6a..38dcdfa 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -147,15 +147,6 @@ For 32-bit we have the following conventions - kernel is 
built with
movq 5*8+\offset(%rsp), %rbx
.endm
 
-   .macro ZERO_EXTRA_REGS
-   xorl%r15d, %r15d
-   xorl%r14d, %r14d
-   xorl%r13d, %r13d
-   xorl%r12d, %r12d
-   xorl%ebp, %ebp
-   xorl%ebx, %ebx
-   .endm
-
.macro RESTORE_C_REGS_HELPER rstor_rax=1, rstor_rcx=1, rstor_r11=1, 
rstor_r8910=1, rstor_rdx=1
.if \rstor_r11
movq 6*8(%rsp), %r11


[PATCH] entry/64: remove unused ZERO_EXTRA_REGS macro

2016-10-20 Thread Alexander Kuleshov
Signed-off-by: Alexander Kuleshov 
---
 arch/x86/entry/calling.h | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 9a9e588..e32353a 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -147,15 +147,6 @@ For 32-bit we have the following conventions - kernel is 
built with
movq 5*8+\offset(%rsp), %rbx
.endm
 
-   .macro ZERO_EXTRA_REGS
-   xorl%r15d, %r15d
-   xorl%r14d, %r14d
-   xorl%r13d, %r13d
-   xorl%r12d, %r12d
-   xorl%ebp, %ebp
-   xorl%ebx, %ebx
-   .endm
-
.macro RESTORE_C_REGS_HELPER rstor_rax=1, rstor_rcx=1, rstor_r11=1, 
rstor_r8910=1, rstor_rdx=1
.if \rstor_r11
movq 6*8(%rsp), %r11
-- 
2.8.0.rc3.1353.gea9bdc0



[tip:x86/asm] x86/entry/64: Remove unused 'addskip' parameter of the ALLOC_PT_GPREGS_ON_STACK macro

2016-10-20 Thread tip-bot for Alexander Kuleshov
Commit-ID:  59df2268311795ee7161776248d5288ee0841d41
Gitweb: http://git.kernel.org/tip/59df2268311795ee7161776248d5288ee0841d41
Author: Alexander Kuleshov 
AuthorDate: Thu, 20 Oct 2016 01:11:08 +0600
Committer:  Ingo Molnar 
CommitDate: Thu, 20 Oct 2016 08:42:36 +0200

x86/entry/64: Remove unused 'addskip' parameter of the ALLOC_PT_GPREGS_ON_STACK 
macro

Signed-off-by: Alexander Kuleshov 
Reviewed-by: Borislav Petkov 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Paolo Bonzini 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: http://lkml.kernel.org/r/20161019191108.2230-1-kuleshovm...@gmail.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/calling.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 9a9e588..b493c6a 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -90,8 +90,8 @@ For 32-bit we have the following conventions - kernel is 
built with
 
 #define SIZEOF_PTREGS  21*8
 
-   .macro ALLOC_PT_GPREGS_ON_STACK addskip=0
-   addq$-(15*8+\addskip), %rsp
+   .macro ALLOC_PT_GPREGS_ON_STACK
+   addq$-(15*8), %rsp
.endm
 
.macro SAVE_C_REGS_HELPER offset=0 rax=1 rcx=1 r8910=1 r11=1


[tip:x86/urgent] x86/entry: Remove addskip parameter from ALLOC_PT_GPREGS_ON_STACK

2016-10-20 Thread tip-bot for Alexander Kuleshov
Commit-ID:  ac679bf247cf044a5be6ca7d380307540284dd45
Gitweb: http://git.kernel.org/tip/ac679bf247cf044a5be6ca7d380307540284dd45
Author: Alexander Kuleshov 
AuthorDate: Thu, 20 Oct 2016 01:11:08 +0600
Committer:  Thomas Gleixner 
CommitDate: Thu, 20 Oct 2016 10:57:37 +0200

x86/entry: Remove addskip parameter from ALLOC_PT_GPREGS_ON_STACK

The ALLOC_PT_GPREGS_ON_STACK macro has an optional addskip parameter, which
is not used by any usage site. Remove it.

Signed-off-by: Alexander Kuleshov 
Reviewed-by: Borislav Petkov 
Cc: Paolo Bonzini 
Cc: Andy Lutomirski 
Link: http://lkml.kernel.org/r/20161019191108.2230-1-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/entry/calling.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 9a9e588..b493c6a 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -90,8 +90,8 @@ For 32-bit we have the following conventions - kernel is 
built with
 
 #define SIZEOF_PTREGS  21*8
 
-   .macro ALLOC_PT_GPREGS_ON_STACK addskip=0
-   addq$-(15*8+\addskip), %rsp
+   .macro ALLOC_PT_GPREGS_ON_STACK
+   addq$-(15*8), %rsp
.endm
 
.macro SAVE_C_REGS_HELPER offset=0 rax=1 rcx=1 r8910=1 r11=1


[PATCH] x86/calling.h: remove unused addskip parameter of ALLOC_PT_GPREGS_ON_STACK

2016-10-19 Thread Alexander Kuleshov
as no-one user of ALLOC_PT_GPREGS_ON_STACK macro doesn't pass it.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/entry/calling.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 9a9e588..b493c6a 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -90,8 +90,8 @@ For 32-bit we have the following conventions - kernel is 
built with
 
 #define SIZEOF_PTREGS  21*8
 
-   .macro ALLOC_PT_GPREGS_ON_STACK addskip=0
-   addq$-(15*8+\addskip), %rsp
+   .macro ALLOC_PT_GPREGS_ON_STACK
+   addq$-(15*8), %rsp
.endm
 
.macro SAVE_C_REGS_HELPER offset=0 rax=1 rcx=1 r8910=1 r11=1
-- 
2.8.0.rc3.1353.gea9bdc0



[tip:irq/core] genirq: No need to mask non trigger mode flags before __irq_set_trigger()

2016-09-06 Thread tip-bot for Alexander Kuleshov
Commit-ID:  00b992deaa08495ab958da5950c9ebbba27d0ddc
Gitweb: http://git.kernel.org/tip/00b992deaa08495ab958da5950c9ebbba27d0ddc
Author: Alexander Kuleshov 
AuthorDate: Tue, 19 Jul 2016 15:54:08 +0600
Committer:  Thomas Gleixner 
CommitDate: Tue, 6 Sep 2016 12:14:12 +0200

genirq: No need to mask non trigger mode flags before __irq_set_trigger()

Some callers of __irq_set_trigger() masks all flags except trigger mode
flags. This is unnecessary, ase __irq_set_trigger() already does this
before usage of flags.

[ tglx: Moved the flag mask and adjusted comment. Removed the hunk in
enable_percpu_irq() as it is required there ]

Signed-off-by: Alexander Kuleshov 
Link: http://lkml.kernel.org/r/20160719095408.13778-1-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 

---
 kernel/irq/chip.c   | 1 -
 kernel/irq/manage.c | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index 93c373a..e11e8af 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -76,7 +76,6 @@ int irq_set_irq_type(unsigned int irq, unsigned int type)
if (!desc)
return -EINVAL;
 
-   type &= IRQ_TYPE_SENSE_MASK;
ret = __irq_set_trigger(desc, type);
irq_put_desc_busunlock(desc, flags);
return ret;
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 73a2b78..4908617 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -669,8 +669,6 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned long 
flags)
return 0;
}
 
-   flags &= IRQ_TYPE_SENSE_MASK;
-
if (chip->flags & IRQCHIP_SET_TYPE_MASKED) {
if (!irqd_irq_masked(&desc->irq_data))
mask_irq(desc);
@@ -678,7 +676,8 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned long 
flags)
unmask = 1;
}
 
-   /* caller masked out all except trigger mode flags */
+   /* Mask all flags except trigger mode */
+   flags &= IRQ_TYPE_SENSE_MASK;
ret = chip->irq_set_type(&desc->irq_data, flags);
 
switch (ret) {


[PATCH] Documentation/x86_64: Fix a thread stack size

2016-08-15 Thread Alexander Kuleshov
current information about THREAD_SIZE value is obsoleted. This patch
fixes this.

Signed-off-by: Alexander Kuleshov 
---
 Documentation/x86/kernel-stacks | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/x86/kernel-stacks b/Documentation/x86/kernel-stacks
index 9a0aa4d..f4b4197 100644
--- a/Documentation/x86/kernel-stacks
+++ b/Documentation/x86/kernel-stacks
@@ -6,7 +6,8 @@ Most of the text from Keith Owens, hacked by AK
 x86_64 page size (PAGE_SIZE) is 4K.
 
 Like all other architectures, x86_64 has a kernel stack for every
-active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
+active thread.  These thread stacks are THREAD_SIZE (PAGE_SIZE << 2)
+or (PAGE_SIZE << 3) if the CONFIG_KASAN is enabled.
 These stacks contain useful data as long as a thread is alive or a
 zombie. While the thread is in user space the kernel stack is empty
 except for the thread_info structure at the bottom.
-- 
2.8.0.rc3.1353.gea9bdc0



[PATCH] ACPICA: Remove unnecessary '\n' in the end of ACPI_INFO output

2016-08-06 Thread Alexander Kuleshov
as the ACPI_INFO already prints `\n` in the end itself.

Signed-off-by: Alexander Kuleshov 
---
 drivers/acpi/acpica/tbxfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index ac71abc..e7119b7 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -240,7 +240,7 @@ acpi_status acpi_tb_load_namespace(void)
}
 
if (!tables_failed) {
-   ACPI_INFO(("%u ACPI AML tables successfully acquired and 
loaded\n", tables_loaded));
+   ACPI_INFO(("%u ACPI AML tables successfully acquired and 
loaded", tables_loaded));
} else {
ACPI_ERROR((AE_INFO,
"%u table load failures, %u successful",
-- 
2.8.0.rc3.1353.gea9bdc0



[PATCH] mm/memblock: fix a typo in a comment

2016-08-04 Thread Alexander Kuleshov
s/accomodate/accommodate

Signed-off-by: Alexander Kuleshov 
---
 mm/memblock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index ff5ff3b..1f065da 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -482,7 +482,7 @@ static void __init_memblock memblock_merge_regions(struct 
memblock_type *type)
  * @flags: flags of the new region
  *
  * Insert new memblock region [@base,@base+@size) into @type at @idx.
- * @type must already have extra room to accomodate the new region.
+ * @type must already have extra room to accommodate the new region.
  */
 static void __init_memblock memblock_insert_region(struct memblock_type *type,
   int idx, phys_addr_t base,
@@ -544,7 +544,7 @@ repeat:
/*
 * The following is executed twice.  Once with %false @insert and
 * then with %true.  The first counts the number of regions needed
-* to accomodate the new area.  The second actually inserts them.
+* to accommodate the new area.  The second actually inserts them.
 */
base = obase;
nr_new = 0;
-- 
2.8.0.rc3.1353.gea9bdc0



[PATCH] genirq: no need to mask non trigger mode flags before __irq_set_trigger()

2016-07-19 Thread Alexander Kuleshov
Some callers of __irq_set_trigger() masks all flags besides trigger mode
flags. Actually it is unnecessary operation now, because the
__irq_set_trigger() already does this before usage of flags.

Signed-off-by: Alexander Kuleshov 
---
 kernel/irq/chip.c   | 1 -
 kernel/irq/manage.c | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index 2f9f2b0..38f2fa4 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -76,7 +76,6 @@ int irq_set_irq_type(unsigned int irq, unsigned int type)
if (!desc)
return -EINVAL;
 
-   type &= IRQ_TYPE_SENSE_MASK;
ret = __irq_set_trigger(desc, type);
irq_put_desc_busunlock(desc, flags);
return ret;
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index ef0bc02..f33c719 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -662,7 +662,7 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned long 
flags)
unmask = 1;
}
 
-   /* caller masked out all except trigger mode flags */
+   /* all flags except trigger mode flags are masked */
ret = chip->irq_set_type(&desc->irq_data, flags);
 
switch (ret) {
@@ -1730,8 +1730,7 @@ void enable_percpu_irq(unsigned int irq, unsigned int 
type)
if (!desc)
return;
 
-   type &= IRQ_TYPE_SENSE_MASK;
-   if (type != IRQ_TYPE_NONE) {
+   if (type & IRQ_TYPE_SENSE_MASK) {
int ret;
 
ret = __irq_set_trigger(desc, type);
-- 
2.8.0.rc3.922.g2bcc146



[PATCH] mm/memblock: move memblock_{add,reserve}_region into memblock_{add,reserve}

2016-04-17 Thread Alexander Kuleshov
From: 0xAX 

The memblock_add_region() and memblock_reserve_region do not nothing specific
before the call of the memblock_add_range(), only print debug output.

We can do the same in the memblock_add() and memblock_reserve() since both
memblock_add_region() and memblock_reserve_region are not used by anybody
outside of memblock.c and the memblock_{add,reserve}() have the same set of
flags and nids.

Since the memblock_add_region() and memblock_reserve_region() anyway will be
inlined, there will not be functional changes, but will improve code readability
a little.

Signed-off-by: Alexander Kuleshov 
---
 mm/memblock.c | 28 ++--
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index b570ddd..3b93daa 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -606,22 +606,14 @@ int __init_memblock memblock_add_node(phys_addr_t base, 
phys_addr_t size,
return memblock_add_range(&memblock.memory, base, size, nid, 0);
 }
 
-static int __init_memblock memblock_add_region(phys_addr_t base,
-   phys_addr_t size,
-   int nid,
-   unsigned long flags)
+int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
 {
memblock_dbg("memblock_add: [%#016llx-%#016llx] flags %#02lx %pF\n",
 (unsigned long long)base,
 (unsigned long long)base + size - 1,
-flags, (void *)_RET_IP_);
-
-   return memblock_add_range(&memblock.memory, base, size, nid, flags);
-}
+0UL, (void *)_RET_IP_);
 
-int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
-{
-   return memblock_add_region(base, size, MAX_NUMNODES, 0);
+   return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 
0);
 }
 
 /**
@@ -732,22 +724,14 @@ int __init_memblock memblock_free(phys_addr_t base, 
phys_addr_t size)
return memblock_remove_range(&memblock.reserved, base, size);
 }
 
-static int __init_memblock memblock_reserve_region(phys_addr_t base,
-  phys_addr_t size,
-  int nid,
-  unsigned long flags)
+int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
 {
memblock_dbg("memblock_reserve: [%#016llx-%#016llx] flags %#02lx %pF\n",
 (unsigned long long)base,
 (unsigned long long)base + size - 1,
-flags, (void *)_RET_IP_);
-
-   return memblock_add_range(&memblock.reserved, base, size, nid, flags);
-}
+0UL, (void *)_RET_IP_);
 
-int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
-{
-   return memblock_reserve_region(base, size, MAX_NUMNODES, 0);
+   return memblock_add_range(&memblock.reserved, base, size, MAX_NUMNODES, 
0);
 }
 
 /**
-- 
2.8.0.rc3.212.g1f992f2.dirty



[PATCH] clocksource: use clocksource_freq2mult() helper

2016-03-16 Thread Alexander Kuleshov
which is introduced in the 7aca0c072 commit to simplify calculation of
the mult and shift in the clocks_calc_mult_shift().

Signed-off-by: Alexander Kuleshov 
---
 kernel/time/clocksource.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 56ece14..de57923 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -80,9 +80,7 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 
to, u32 maxsec)
 * accuracy and fits the maxsec conversion range:
 */
for (sft = 32; sft > 0; sft--) {
-   tmp = (u64) to << sft;
-   tmp += from / 2;
-   do_div(tmp, from);
+   tmp = clocksource_freq2mult(from, sft, to);
if ((tmp >> sftacc) == 0)
break;
}
-- 
2.8.0.rc2.216.g1477fb2.dirty



[tip:x86/boot] x86/setup: Calculate ramdisk parameters only once

2016-02-29 Thread tip-bot for Alexander Kuleshov
Commit-ID:  6fc77525f509e16b1e909e5ffd6f9ad9dccc0f82
Gitweb: http://git.kernel.org/tip/6fc77525f509e16b1e909e5ffd6f9ad9dccc0f82
Author: Alexander Kuleshov 
AuthorDate: Fri, 26 Feb 2016 15:04:36 +0600
Committer:  Ingo Molnar 
CommitDate: Sat, 27 Feb 2016 12:52:27 +0100

x86/setup: Calculate ramdisk parameters only once

The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces 'struct ramdisk' which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Signed-off-by: Alexander Kuleshov 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Baoquan He 
Cc: Dave Young 
Cc: Joerg Roedel 
Cc: Linus Torvalds 
Cc: Mark Salter 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1456477476-16415-1-git-send-email-kuleshovm...@gmail.com
[ Small readability changes. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/setup.c | 111 ++--
 1 file changed, 61 insertions(+), 50 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..5cf832c 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,12 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -309,6 +315,7 @@ static u64 __init get_ramdisk_image(void)
 
return ramdisk_image;
 }
+
 static u64 __init get_ramdisk_size(void)
 {
u64 ramdisk_size = boot_params.hdr.ramdisk_size;
@@ -318,90 +325,87 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
 
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
+   /* No initrd provided by bootloader */
if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
-   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+   !ramdisk->start_addr ||
+   

[tip:timers/core] jiffies: Use CLOCKSOURCE_MASK instead of constant

2016-02-27 Thread tip-bot for Alexander Kuleshov
Commit-ID:  232d26373d310a941ef2ab46e53ea62fe076ed13
Gitweb: http://git.kernel.org/tip/232d26373d310a941ef2ab46e53ea62fe076ed13
Author: Alexander Kuleshov 
AuthorDate: Fri, 26 Feb 2016 19:14:14 -0800
Committer:  Thomas Gleixner 
CommitDate: Sat, 27 Feb 2016 08:55:31 +0100

jiffies: Use CLOCKSOURCE_MASK instead of constant

The CLOCKSOURCE_MASK(32) macro expands to the same value, but
makes code more readable.

Signed-off-by: Alexander Kuleshov 
Signed-off-by: John Stultz 
Cc: Prarit Bhargava 
Cc: Richard Cochran 
Link: 
http://lkml.kernel.org/r/1456542854-22104-3-git-send-email-john.stu...@linaro.org
Signed-off-by: Thomas Gleixner 
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 347fecf..555e21f 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -68,7 +68,7 @@ static struct clocksource clocksource_jiffies = {
.name   = "jiffies",
.rating = 1, /* lowest valid rating*/
.read   = jiffies_read,
-   .mask   = 0x, /*32bits*/
+   .mask   = CLOCKSOURCE_MASK(32),
.mult   = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
.shift  = JIFFIES_SHIFT,
.max_cycles = 10,


[tip:timers/core] clocksource: Introduce clocksource_freq2mult()

2016-02-27 Thread tip-bot for Alexander Kuleshov
Commit-ID:  7aca0c07207385cca76025cc85231519935722b9
Gitweb: http://git.kernel.org/tip/7aca0c07207385cca76025cc85231519935722b9
Author: Alexander Kuleshov 
AuthorDate: Fri, 26 Feb 2016 19:14:13 -0800
Committer:  Thomas Gleixner 
CommitDate: Sat, 27 Feb 2016 08:55:30 +0100

clocksource: Introduce clocksource_freq2mult()

The clocksource_khz2mult() and clocksource_hz2mult() share similar
code wihch calculates a mult from the given frequency. Both implementations
in differ only in value of a frequency. This patch introduces the
clocksource_freq2mult() helper with generic implementation of
mult calculation to prevent code duplication.

Signed-off-by: Alexander Kuleshov 
Signed-off-by: John Stultz 
Cc: Prarit Bhargava 
Cc: Richard Cochran 
Link: 
http://lkml.kernel.org/r/1456542854-22104-2-git-send-email-john.stu...@linaro.org
Signed-off-by: Thomas Gleixner 
---
 include/linux/clocksource.h | 45 +++--
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 6013021..a307bf6 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -118,6 +118,23 @@ struct clocksource {
 /* simplify initialization of mask field */
 #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
 
+static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
+{
+   /*  freq = cyc/from
+*  mult/2^shift  = ns/cyc
+*  mult = ns/cyc * 2^shift
+*  mult = from/freq * 2^shift
+*  mult = from * 2^shift / freq
+*  mult = (from<

[PATCH] x86/bitops.h: use IS_IMMEDIATE instead of dirrect call of __builtin_constant_p

2016-02-26 Thread Alexander Kuleshov
The arch/x86/include/asm/bitops.h provides IS_IMMEDIATE macro which expands to
the call of the __builtin_constant_p(). Let's use this macro in the test_bit()
to be more clear.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/include/asm/bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index cfe3b95..8cfbd2b 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -333,7 +333,7 @@ static int test_bit(int nr, const volatile unsigned long 
*addr);
 #endif
 
 #define test_bit(nr, addr) \
-   (__builtin_constant_p((nr)) \
+   (IS_IMMEDIATE((nr)) \
 ? constant_test_bit((nr), (addr))  \
 : variable_test_bit((nr), (addr)))
 
-- 
2.7.2.335.g3476f70



[PATCH v8] x86/setup: get ramdisk parameters only once

2016-02-26 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces struct ramdisk which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v8:

  * style fixes.

v7:

  * ramdisk_image renamed to ramdisk in the setup_arch().

v6:

  * ramdisk_image renamed to ramdisk
  * early check of initrd and memory reservation for it is
  moved to the early_reserve_initrd() again.

v5:

  * move check of the reserve_ramdisk to the reserve_initrd()
  * align ramdisk size in setup_arch() as it maybe not page
  aligned and start_addr + size() will be different with end_addr
  in this case
  * style fixes

v4:

  * bool reserve_ramdisk moved to the struct ramdisk;
  * fields of struct ramdisk are renamed to more understandable
  names
  * early_reserve_initrd() removed as it contains only one call
  of memblock_resere. It was moved to the setup_arch
  * stubs added for get_ramdisk_image() and get_ramdisk_size()
  to prevent compilation error if CONFIG_BLK_DEV_INITRD=n
  * initialization of ramdisk->end_addr is moved from in-place
  initialization to prevent ‘ramdisk_image.size’ is used uninitialized
  in this function warning.

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 107 ++--
 1 file changed, 59 insertions(+), 48 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..f18bbe2 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,12 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,90 +324,87 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
 
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
- 

[PATCH v7] x86/setup: get ramdisk parameters only once

2016-02-25 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces struct ramdisk which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v7:

  * ramdisk_image renamed to ramdisk in the setup_arch().

v6:

  * ramdisk_image renamed to ramdisk
  * early check of initrd and memory reservation for it is
  moved to the early_reserve_initrd() again.

v5:

  * move check of the reserve_ramdisk to the reserve_initrd()
  * align ramdisk size in setup_arch() as it maybe not page
  aligned and start_addr + size() will be different with end_addr
  in this case
  * style fixes

v4:

  * bool reserve_ramdisk moved to the struct ramdisk;
  * fields of struct ramdisk are renamed to more understandable
  names
  * early_reserve_initrd() removed as it contains only one call
  of memblock_resere. It was moved to the setup_arch
  * stubs added for get_ramdisk_image() and get_ramdisk_size()
  to prevent compilation error if CONFIG_BLK_DEV_INITRD=n
  * initialization of ramdisk->end_addr is moved from in-place
  initialization to prevent ‘ramdisk_image.size’ is used uninitialized
  in this function warning.

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 109 ++--
 1 file changed, 60 insertions(+), 49 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..449b4da 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,15 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+/*
+ * ramdisk setup
+ */
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,90 +327,84 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
-
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-  

[PATCH v2] x86/head64: no need to define early_idt_ripmsg only if CONFIG_KALLSYMS=n

2016-02-18 Thread Alexander Kuleshov
We have definition of the early_idt_ripmsg which represents string header
for the output of the kernel symbols during early exception. But the
header with kernel symbols will be printed in a case if the CONFIG_KALLSYMS=y.

Signed-off-by: Alexander Kuleshov 
---
Changelog:

v2: commit message fixed and comment added.

 arch/x86/kernel/head_64.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..f93997f 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -433,8 +433,10 @@ early_recursion_flag:
 #ifdef CONFIG_EARLY_PRINTK
 early_idt_msg:
.asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
+#ifdef CONFIG_KALLSYMS
 early_idt_ripmsg:
.asciz "RIP %s\n"
+#endif /* CONFIG_KALLSYMS */
 #endif /* CONFIG_EARLY_PRINTK */
 
 #define NEXT_PAGE(name) \
-- 
2.7.0.364.g4943984



[PATCH v6] x86/setup: get ramdisk parameters only once

2016-02-17 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces struct ramdisk which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v6:

  * ramdisk_image renamed to ramdisk
  * early check of initrd and memory reservation for it is
  moved to the early_reserve_initrd() again.

v5:

  * move check of the reserve_ramdisk to the reserve_initrd()
  * align ramdisk size in setup_arch() as it maybe not page
  aligned and start_addr + size() will be different with end_addr
  in this case
  * style fixes

v4:

  * bool reserve_ramdisk moved to the struct ramdisk;
  * fields of struct ramdisk are renamed to more understandable
  names
  * early_reserve_initrd() removed as it contains only one call
  of memblock_resere. It was moved to the setup_arch
  * stubs added for get_ramdisk_image() and get_ramdisk_size()
  to prevent compilation error if CONFIG_BLK_DEV_INITRD=n
  * initialization of ramdisk->end_addr is moved from in-place
  initialization to prevent ‘ramdisk_image.size’ is used uninitialized
  in this function warning.

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 109 ++--
 1 file changed, 60 insertions(+), 49 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..3a139b3 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,15 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+/*
+ * ramdisk setup
+ */
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,90 +327,84 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
-
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_siz

[PATCH v5] x86/setup: get ramdisk parameters only once

2016-02-17 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces struct ramdisk which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Additionally we save 85 bytes:

 text data  bss  dec hex filename
  9292517  5011696 15675392 29979605 1c973d5 vmlinux

 text data  bss  dec hex filename
  9292602  5011696 15675392 29979690 1c9742a vmlinux

Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v5:

  * move check of the reserve_ramdisk to the reserve_initrd()
  * align ramdisk size in setup_arch() as it maybe not page
  aligned and start_addr + size() will be different with end_addr
  in this case
  * style fixes

v4:

  * bool reserve_ramdisk moved to the struct ramdisk;
  * fields of struct ramdisk are renamed to more understandable
  names
  * early_reserve_initrd() removed as it contains only one call
  of memblock_resere. It was moved to the setup_arch
  * stubs added for get_ramdisk_image() and get_ramdisk_size()
  to prevent compilation error if CONFIG_BLK_DEV_INITRD=n
  * initialization of ramdisk->end_addr is moved from in-place
  initialization to prevent ‘ramdisk_image.size’ is used uninitialized
  in this function warning.

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 103 +---
 1 file changed, 53 insertions(+), 50 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..d89d9ea 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,15 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+/*
+ * ramdisk setup
+ */
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,90 +327,73 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
 
-static void __init early_reserve_initrd(void)
-{
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-  

[PATCH v4] x86/setup: get ramdisk parameters only once

2016-02-11 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces struct ramdisk which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Additionally we save 85 bytes:

 text data  bss   dec  hex filename
  9292602  5011696 15675392  29979690  1c9742a vmlinux.orig

 text data  bss   dec hex filename
  9292517  5011696 15675392  29979605 1c973d5 vmlinux


Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v4:

  * bool reserve_ramdisk moved to the struct ramdisk;
  * fields of struct ramdisk are renamed to more understandable
  names
  * early_reserve_initrd() removed as it contains only one call
  of memblock_resere. It was moved to the setup_arch
  * stubs added for get_ramdisk_image() and get_ramdisk_size()
  to prevent compilation error if CONFIG_BLK_DEV_INITRD=n
  * initialization of ramdisk->end_addr is moved from in-place
  initialization to prevent ‘ramdisk_image.size’ is used uninitialized
  in this function warning.

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 105 +---
 1 file changed, 54 insertions(+), 51 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..0f0ba51 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,15 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+/*
+ * ramdisk setup
+ */
+struct ramdisk {
+   u64 start_addr; /* ramdisk load address */
+   u64 end_addr;   /* ramdisk end address */
+   u64 size;   /* ramdisk size */
+   bool reserve_ramdisk;   /* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,90 +327,70 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
-
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-  area_size, PAGE_SIZE);
+  ramdisk->size, PAGE_SIZE);
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk->size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
-   memblock_reserve(relocated_ramdisk, area_size);
+   memblock_reserve(relocated_ramdisk, ramdisk->size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk->size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, 
ramdisk->size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
 
-static void __init early_reserve_initrd(void)
-{
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
-   if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
- 

[tip:x86/boot] x86/boot: Use proper array element type in memset( ) size calculation

2016-02-09 Thread tip-bot for Alexander Kuleshov
Commit-ID:  a91bbe017552b80e12d712c85549b933a62c6ed4
Gitweb: http://git.kernel.org/tip/a91bbe017552b80e12d712c85549b933a62c6ed4
Author: Alexander Kuleshov 
AuthorDate: Tue, 9 Feb 2016 19:44:54 +0600
Committer:  Ingo Molnar 
CommitDate: Tue, 9 Feb 2016 14:55:48 +0100

x86/boot: Use proper array element type in memset() size calculation

I changed open coded zeroing loops to explicit memset()s in the
following commit:

  5e9ebbd87a99 ("x86/boot: Micro-optimize reset_early_page_tables()")

The base for the size argument of memset was sizeof(pud_p/pmd_p), which
are pointers - but the initialized array has pud_t/pmd_t elements.

Luckily the two types had the same size, so this did not result in any
runtime misbehavior.

Signed-off-by: Alexander Kuleshov 
Cc: Alexander Popov 
Cc: Andrey Ryabinin 
Cc: Andy Lutomirski 
Cc: Andy Shevchenko 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1455025494-4063-1-git-send-email-kuleshovm...@gmail.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/head64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 35843ca..7793a17 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -75,7 +75,7 @@ again:
}
 
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
-   memset(pud_p, 0, sizeof(pud_p) * PTRS_PER_PUD);
+   memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD);
*pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pud_p += pud_index(address);
@@ -90,7 +90,7 @@ again:
}
 
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
-   memset(pmd_p, 0, sizeof(pmd_p) * PTRS_PER_PMD);
+   memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD);
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pmd = (physaddr & PMD_MASK) + early_pmd_flags;


[PATCH] x86/head64: use pointer type in sizeof

2016-02-09 Thread Alexander Kuleshov
We changed loops with memset in the 5e9ebbd87a99 commit (x86/boot:
Micro-optimize reset_early_page_tables()). The base for size of
memset was size of pud_p/pmd_p, but the they are actually
represented as pointers, although they have the same sizes.

Signed-off-by: Alexander Kuleshov 
---
based on x86/tip/boot

 arch/x86/kernel/head64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 35843ca..7793a17 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -75,7 +75,7 @@ again:
}
 
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
-   memset(pud_p, 0, sizeof(pud_p) * PTRS_PER_PUD);
+   memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD);
*pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pud_p += pud_index(address);
@@ -90,7 +90,7 @@ again:
}
 
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
-   memset(pmd_p, 0, sizeof(pmd_p) * PTRS_PER_PMD);
+   memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD);
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pmd = (physaddr & PMD_MASK) + early_pmd_flags;
-- 
2.7.0.25.gfc10eb5



[PATCH v2] x86/head64: micro optimization: use memset instead of for loop

2016-02-09 Thread Alexander Kuleshov
This patch simplifies clearing of page table directories, by
the using of the fast memset() from the arch/x86/lib/memset_64.S.
Besides this, we 25 bytes is 25 bytes less than original.

text   data bss  dechex filename

9735144 4970776 15474688301806081cc8500 vmlinux.old
9735119 4970776 15474688301805831cc84e7 vmlinux

Signed-off-by: Alexander Kuleshov 
---
Changelog:

v2: We got sizeof pud_p/pmd_p in the v1, but actually we need
to take sizeof of pud_p/pmd_p pointer, although their sizes are
the same.

 arch/x86/kernel/head64.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 2c0f340..1f4422d 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -40,13 +40,8 @@ pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & 
~(_PAGE_GLOBAL | _PAGE_NX);
 /* Wipe all early page tables except for the kernel symbol map */
 static void __init reset_early_page_tables(void)
 {
-   unsigned long i;
-
-   for (i = 0; i < PTRS_PER_PGD-1; i++)
-   early_level4_pgt[i].pgd = 0;
-
+   memset(early_level4_pgt, 0, sizeof(pgd_t)*(PTRS_PER_PGD-1));
next_early_pgt = 0;
-
write_cr3(__pa_nodebug(early_level4_pgt));
 }
 
@@ -54,7 +49,6 @@ static void __init reset_early_page_tables(void)
 int __init early_make_pgtable(unsigned long address)
 {
unsigned long physaddr = address - __PAGE_OFFSET;
-   unsigned long i;
pgdval_t pgd, *pgd_p;
pudval_t pud, *pud_p;
pmdval_t pmd, *pmd_p;
@@ -81,8 +75,7 @@ again:
}
 
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PUD; i++)
-   pud_p[i] = 0;
+   memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD);
*pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pud_p += pud_index(address);
@@ -97,8 +90,7 @@ again:
}
 
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PMD; i++)
-   pmd_p[i] = 0;
+   memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD);
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pmd = (physaddr & PMD_MASK) + early_pmd_flags;
-- 
2.7.0.25.gfc10eb5



[PATCH v3] x86/setup: get ramdisk parameters only once

2016-02-09 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions. We can
get size and address of ramdisk in the setup_arch() and than
pass ramdisk structure with filled ramdisk related parameters
to early_reserve_initrd(), reserve_initrd() and relocate_initrd()
functions.

This allows us to not get ramdisk parameters from the bootparams
every time and save 59 bytes:

 text data  bss dechex filename
  9281618  5010736 15474688297670421c63582 vmlinux.orig

 text data  bss dechex filename
  9281559  5010736 15474688297669831c63547 vmlinux

Signed-off-by: Alexander Kuleshov 
---
Tested as with virtual machine as with real hardware.

Changelog:

v3: introduced ramdisk setup which is filled in th
setup_arch() and passed to the early_reserve_initrd()
and reserve_initrd().

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 92 +
 1 file changed, 47 insertions(+), 45 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..c9d8a86 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,14 @@ static struct resource bss_resource = {
.flags  = IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+/*
+ * ramdisk setup
+ */
+struct ramdisk {
+   u64 image;
+   u64 size;
+   u64 end;
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -318,12 +326,10 @@ static u64 __init get_ramdisk_size(void)
return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk ramdisk)
 {
/* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 area_size = PAGE_ALIGN(ramdisk_size);
+   u64 area_size = PAGE_ALIGN(ramdisk.size);
 
/* We need to move the initrd down into directly mapped mem */
relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
@@ -331,77 +337,60 @@ static void __init relocate_initrd(void)
 
if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
- ramdisk_size);
+ ramdisk.size);
 
/* Note: this includes all the mem currently occupied by
   the initrd, we rely on that fact to keep the data intact. */
memblock_reserve(relocated_ramdisk, area_size);
initrd_start = relocated_ramdisk + PAGE_OFFSET;
-   initrd_end   = initrd_start + ramdisk_size;
+   initrd_end   = initrd_start + ramdisk.size;
printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-  relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+  relocated_ramdisk, relocated_ramdisk + ramdisk.size - 1);
 
-   copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+   copy_from_early_mem((void *)initrd_start, ramdisk.image, ramdisk.size);
 
printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
" [mem %#010llx-%#010llx]\n",
-   ramdisk_image, ramdisk_image + ramdisk_size - 1,
-   relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+   ramdisk.image, ramdisk.image + ramdisk.size - 1,
+   relocated_ramdisk, relocated_ramdisk + ramdisk.size - 1);
 }
 
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
-   if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
-   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+   memblock_reserve(ramdisk.image, ramdisk.end - ramdisk.image);
 }
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(struct ramdisk ramdisk)
 {
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
u64 mapped_size;
 
-   if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
initrd_start = 0;
 
mapped_size = memblock_mem_size(max_pfn_mapped);
-   if (ramdisk_size >= (mapped_size>>1))
+   if (ramdisk.size >= (mapp

Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function

2016-02-09 Thread Alexander Kuleshov
Hello Ingo,

On Tue, Feb 9, 2016 at 3:16 PM, Ingo Molnar  wrote:
>
> So I don't think the code got easier to understand - in particular the
> memblock_reserve()/free() pattern, depending on a flag value, is confusing.
>
> The duplication is there - but please factor it out into a helper structure
> ('struct ramdisk') and a helper function that sets up the structure.

What if instead of `struct ramdisk`, we will move all definitions/check from
the early_reserve_initrd to the setup_arch() and than will pass these values
to the reserve_initrd()?


[PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function

2016-02-08 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd(). So we can get rid of
early_reserve_initrd() and and use late or early algorithm for
initrd reservation depends on reserve_initrd() parameter value.

Save 396 bytes of code:

   textdata  bss  dec hex filename
   9281618  5010736 15474688 29767042 1c63582 vmlinux.orig

   textdata  bss  dec hex filename
   9281222  5010672 15474688 29766582 1c633b6 vmlinux.new

Signed-off-by: Alexander Kuleshov 
---
Changelog:

v2: parameter of reserve_initrd() - int -> bool.
commit message updated.

 arch/x86/kernel/setup.c | 29 +
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..0a2fa55 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -349,20 +349,7 @@ static void __init relocate_initrd(void)
relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
 }
 
-static void __init early_reserve_initrd(void)
-{
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
-   if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
-   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(bool early)
 {
/* Assume only end is not page aligned */
u64 ramdisk_image = get_ramdisk_image();
@@ -374,6 +361,11 @@ static void __init reserve_initrd(void)
!ramdisk_image || !ramdisk_size)
return; /* No initrd provided by bootloader */
 
+   if (early) {
+   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+   return;
+   }
+
initrd_start = 0;
 
mapped_size = memblock_mem_size(max_pfn_mapped);
@@ -398,10 +390,7 @@ static void __init reserve_initrd(void)
memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
 }
 #else
-static void __init early_reserve_initrd(void)
-{
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(bool early)
 {
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
@@ -850,7 +839,7 @@ void __init setup_arch(char **cmdline_p)
memblock_reserve(__pa_symbol(_text),
 (unsigned long)__bss_stop - (unsigned long)_text);
 
-   early_reserve_initrd();
+   reserve_initrd(true);
 
/*
 * At this point everything still needed from the boot loader
@@ -1135,7 +1124,7 @@ void __init setup_arch(char **cmdline_p)
/* Allocate bigger log buffer */
setup_log_buf(1);
 
-   reserve_initrd();
+   reserve_initrd(false);
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
-- 
2.7.0.25.gfc10eb5



Re: [PATCH] x86/setup: refactor initrd reservation

2016-02-08 Thread Alexander Kuleshov
On Mon, Feb 8, 2016 at 9:56 PM, Andy Shevchenko
 wrote:
> On Fri, Feb 5, 2016 at 7:38 PM, Alexander Kuleshov
>  wrote:
>> The check and definitions related to ramdisk are similar in the
>> early_reserve_initrd() and reserve_initrd(). So we can get rid of
>> early_reserve_initrd() and and use late or early algorithm for
>> initrd reservation depends on reserve_initrd() parameter value.
>
> Perhaps: "Squash {early_,}reserve_initrd() to one function" would be
> better for Subject line since it describes what you are doing here
> (Answering question "What kind of refactor?").
>
> Also if you have more argument (like .text size before and after) I
> suppose it would have been passed faster.
>

Hello Andy, thanks for your suggestions. Will update it in second revision.


[PATCH v2] jiffies: use CLOCKSOURCE_MASK instead of constant

2016-02-06 Thread Alexander Kuleshov
The CLOCKSOURCE_MASK(32) macro expands to the same value, but
makes code more readable.

Signed-off-by: Alexander Kuleshov 
---

v2: typo fixed in commit message

 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 347fecf..555e21f 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -68,7 +68,7 @@ static struct clocksource clocksource_jiffies = {
.name   = "jiffies",
.rating = 1, /* lowest valid rating*/
.read   = jiffies_read,
-   .mask   = 0x, /*32bits*/
+   .mask   = CLOCKSOURCE_MASK(32),
.mult   = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
.shift  = JIFFIES_SHIFT,
.max_cycles = 10,
-- 
2.7.0.25.gfc10eb5



[PATCH] jiffies: use CLOSKOURCE_MASK instead of constant

2016-02-05 Thread Alexander Kuleshov
The CLOCKSOURCE_MASK(32) macro expands to the same value, but
makes code more readable.

Signed-off-by: Alexander Kuleshov 
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 347fecf..555e21f 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -68,7 +68,7 @@ static struct clocksource clocksource_jiffies = {
.name   = "jiffies",
.rating = 1, /* lowest valid rating*/
.read   = jiffies_read,
-   .mask   = 0x, /*32bits*/
+   .mask   = CLOCKSOURCE_MASK(32),
.mult   = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
.shift  = JIFFIES_SHIFT,
.max_cycles = 10,
-- 
2.7.0.25.gfc10eb5



[PATCH] clocksource: introduce clocksource_freq2mult()

2016-02-05 Thread Alexander Kuleshov
The clocksource_khz2mult() and clocksource_hz2mult() share similar
code wihch calculates a mult from the given frequency. Both implementations
in differ only in value of a frequency. This patch introduces the
clocksource_freq2mult() helper with generic implementation of
mult calculation to prevent code duplication.

Signed-off-by: Alexander Kuleshov 
---
 include/linux/clocksource.h | 45 +++--
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 6013021..a307bf6 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -118,6 +118,23 @@ struct clocksource {
 /* simplify initialization of mask field */
 #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
 
+static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
+{
+   /*  freq = cyc/from
+*  mult/2^shift  = ns/cyc
+*  mult = ns/cyc * 2^shift
+*  mult = from/freq * 2^shift
+*  mult = from * 2^shift / freq
+*  mult = (from<

[PATCH] x86/setup: refactor initrd reservation

2016-02-05 Thread Alexander Kuleshov
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd(). So we can get rid of
early_reserve_initrd() and and use late or early algorithm for
initrd reservation depends on reserve_initrd() parameter value.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/setup.c | 29 +
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..f6f38b0 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -349,20 +349,7 @@ static void __init relocate_initrd(void)
relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
 }
 
-static void __init early_reserve_initrd(void)
-{
-   /* Assume only end is not page aligned */
-   u64 ramdisk_image = get_ramdisk_image();
-   u64 ramdisk_size  = get_ramdisk_size();
-   u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
-   if (!boot_params.hdr.type_of_loader ||
-   !ramdisk_image || !ramdisk_size)
-   return; /* No initrd provided by bootloader */
-
-   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(int early)
 {
/* Assume only end is not page aligned */
u64 ramdisk_image = get_ramdisk_image();
@@ -374,6 +361,11 @@ static void __init reserve_initrd(void)
!ramdisk_image || !ramdisk_size)
return; /* No initrd provided by bootloader */
 
+   if (early) {
+   memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+   return;
+   }
+
initrd_start = 0;
 
mapped_size = memblock_mem_size(max_pfn_mapped);
@@ -398,10 +390,7 @@ static void __init reserve_initrd(void)
memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
 }
 #else
-static void __init early_reserve_initrd(void)
-{
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(int early)
 {
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
@@ -850,7 +839,7 @@ void __init setup_arch(char **cmdline_p)
memblock_reserve(__pa_symbol(_text),
 (unsigned long)__bss_stop - (unsigned long)_text);
 
-   early_reserve_initrd();
+   reserve_initrd(1);
 
/*
 * At this point everything still needed from the boot loader
@@ -1135,7 +1124,7 @@ void __init setup_arch(char **cmdline_p)
/* Allocate bigger log buffer */
setup_log_buf(1);
 
-   reserve_initrd();
+   reserve_initrd(0);
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
-- 
2.7.0.25.gfc10eb5



[PATCH] mm/memblock: remove unnecessary memblock_type variable

2016-02-04 Thread Alexander Kuleshov
We define struct memblock_type *type in the memblock_add_region()
and memblock_reserve_region() functions only for passing it to the
memlock_add_range() and memblock_reserve_range() functions. Let's
remove these variables and will pass a type directly.

Signed-off-by: Alexander Kuleshov 
---
 mm/memblock.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index d2ed81e..edfae98 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -612,14 +612,12 @@ static int __init_memblock 
memblock_add_region(phys_addr_t base,
int nid,
unsigned long flags)
 {
-   struct memblock_type *type = &memblock.memory;
-
memblock_dbg("memblock_add: [%#016llx-%#016llx] flags %#02lx %pF\n",
 (unsigned long long)base,
 (unsigned long long)base + size - 1,
 flags, (void *)_RET_IP_);
 
-   return memblock_add_range(type, base, size, nid, flags);
+   return memblock_add_range(&memblock.memory, base, size, nid, flags);
 }
 
 int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
@@ -740,14 +738,12 @@ static int __init_memblock 
memblock_reserve_region(phys_addr_t base,
   int nid,
   unsigned long flags)
 {
-   struct memblock_type *type = &memblock.reserved;
-
memblock_dbg("memblock_reserve: [%#016llx-%#016llx] flags %#02lx %pF\n",
 (unsigned long long)base,
 (unsigned long long)base + size - 1,
 flags, (void *)_RET_IP_);
 
-   return memblock_add_range(type, base, size, nid, flags);
+   return memblock_add_range(&memblock.reserved, base, size, nid, flags);
 }
 
 int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
-- 
2.7.0.25.gfc10eb5



[PATCH] init: print warning message if /dev/console failed to open

2016-02-03 Thread Alexander Kuleshov
Signed-off-by: Alexander Kuleshov 
---
 init/do_mounts.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index dea5de9..ca5da05 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -505,7 +505,9 @@ void __init change_floppy(char *fmt, ...)
termios.c_lflag |= ICANON;
sys_ioctl(fd, TCSETSF, (long)&termios);
sys_close(fd);
-   }
+   } else
+   pr_err("Warning: unable to open /dev/console.\n");
+
 }
 #endif
 
-- 
2.7.0.25.gfc10eb5



[tip:x86/asm] x86/entry/traps: Refactor preemption and interrupt flag handling

2016-02-01 Thread tip-bot for Alexander Kuleshov
Commit-ID:  d99e1bd175f4291ddb6e62b22bb5bdbe3976389a
Gitweb: http://git.kernel.org/tip/d99e1bd175f4291ddb6e62b22bb5bdbe3976389a
Author: Alexander Kuleshov 
AuthorDate: Mon, 25 Jan 2016 20:41:46 +0100
Committer:  Ingo Molnar 
CommitDate: Mon, 1 Feb 2016 10:45:14 +0100

x86/entry/traps: Refactor preemption and interrupt flag handling

Make the preemption and interrupt flag handling more readable by
removing preempt_conditional_sti() and preempt_conditional_cli()
helpers and using preempt_disable() and
preempt_enable_no_resched() instead.

Rename contitional_sti() and conditional_cli() to the more
understandable cond_local_irq_enable() and
cond_local_irq_disable() respectively, while at it.

Suggested-by: Borislav Petkov 
Signed-off-by: Alexander Kuleshov 
[ Boris: massage text. ]
Signed-off-by: Borislav Petkov 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: H Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Tony Luck 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/1453750913-4781-2-git-send-email...@alien8.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/traps.c | 47 +++
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index ade185a..410e8e2 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -83,30 +83,16 @@ gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
 
-static inline void conditional_sti(struct pt_regs *regs)
+static inline void cond_local_irq_enable(struct pt_regs *regs)
 {
if (regs->flags & X86_EFLAGS_IF)
local_irq_enable();
 }
 
-static inline void preempt_conditional_sti(struct pt_regs *regs)
-{
-   preempt_count_inc();
-   if (regs->flags & X86_EFLAGS_IF)
-   local_irq_enable();
-}
-
-static inline void conditional_cli(struct pt_regs *regs)
-{
-   if (regs->flags & X86_EFLAGS_IF)
-   local_irq_disable();
-}
-
-static inline void preempt_conditional_cli(struct pt_regs *regs)
+static inline void cond_local_irq_disable(struct pt_regs *regs)
 {
if (regs->flags & X86_EFLAGS_IF)
local_irq_disable();
-   preempt_count_dec();
 }
 
 void ist_enter(struct pt_regs *regs)
@@ -286,7 +272,7 @@ static void do_error_trap(struct pt_regs *regs, long 
error_code, char *str,
 
if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) !=
NOTIFY_STOP) {
-   conditional_sti(regs);
+   cond_local_irq_enable(regs);
do_trap(trapnr, signr, str, regs, error_code,
fill_trap_info(regs, signr, trapnr, &info));
}
@@ -368,7 +354,7 @@ dotraplinkage void do_bounds(struct pt_regs *regs, long 
error_code)
if (notify_die(DIE_TRAP, "bounds", regs, error_code,
X86_TRAP_BR, SIGSEGV) == NOTIFY_STOP)
return;
-   conditional_sti(regs);
+   cond_local_irq_enable(regs);
 
if (!user_mode(regs))
die("bounds", regs, error_code);
@@ -443,7 +429,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
struct task_struct *tsk;
 
RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
-   conditional_sti(regs);
+   cond_local_irq_enable(regs);
 
if (v8086_mode(regs)) {
local_irq_enable();
@@ -517,9 +503,11 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, 
long error_code)
 * as we may switch to the interrupt stack.
 */
debug_stack_usage_inc();
-   preempt_conditional_sti(regs);
+   preempt_disable();
+   cond_local_irq_enable(regs);
do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
-   preempt_conditional_cli(regs);
+   cond_local_irq_disable(regs);
+   preempt_enable_no_resched();
debug_stack_usage_dec();
 exit:
ist_exit(regs);
@@ -648,12 +636,14 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
debug_stack_usage_inc();
 
/* It's safe to allow irq's after DR6 has been saved */
-   preempt_conditional_sti(regs);
+   preempt_disable();
+   cond_local_irq_enable(regs);
 
if (v8086_mode(regs)) {
handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
X86_TRAP_DB);
-   preempt_conditional_cli(regs);
+   cond_local_irq_disable(regs);
+   preempt_enable_no_resched();
debug_stack_usage_dec();
goto exit;
}
@@ -673,7 +663,8 @@ dotraplinkage void do_debug(struct pt_regs *regs, long 
error_code)
si_code = get_si_code(tsk->thread.debugreg6);
if (tsk->thre

[PATCH] x86_64/setup: handle builtin command line early

2016-02-01 Thread Alexander Kuleshov
We handle builtin command line during setup_arch() work of the
setup_arch(). But it may be useful to handle it earlier for
x86_64.

For example: x86_64 supports early update ucode from the
feddc9de (x86/head64.c: Early update ucode in 64-bit) commit by
the calling of load_ucode_bsp() which in turn checks 'dis_ucode_ldr'
option which may be passed through builtin command line.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/include/asm/setup.h |  2 +-
 arch/x86/kernel/head64.c |  5 +
 arch/x86/kernel/setup.c  | 31 +++
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index 11af24e..7c6ca38 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -124,7 +124,7 @@ asmlinkage void __init i386_start_kernel(void);
 #else
 asmlinkage void __init x86_64_start_kernel(char *real_mode);
 asmlinkage void __init x86_64_start_reservations(char *real_mode_data);
-
+void __init setup_builtin_cmdline(void);
 #endif /* __i386__ */
 #endif /* _SETUP */
 #else
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index f129a9a..3a3f3b0 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -173,6 +173,8 @@ asmlinkage __visible void __init x86_64_start_kernel(char * 
real_mode_data)
 
copy_bootdata(__va(real_mode_data));
 
+   setup_builtin_cmdline();
+
/*
 * Load microcode early on BSP.
 */
@@ -188,7 +190,10 @@ void __init x86_64_start_reservations(char *real_mode_data)
 {
/* version is always not zero if it is copied */
if (!boot_params.hdr.version)
+   {
copy_bootdata(__va(real_mode_data));
+   setup_builtin_cmdline();
+   }
 
reserve_ebda_region();
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..0a19059 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -832,6 +832,23 @@ dump_kernel_offset(struct notifier_block *self, unsigned 
long v, void *p)
return 0;
 }
 
+
+void __init setup_builtin_cmdline(void)
+{
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_OVERRIDE
+   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+#else
+   if (builtin_cmdline[0]) {
+   /* append boot loader cmdline to builtin */
+   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
+   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+   }
+#endif
+#endif
+}
+
 /*
  * Determine if we were loaded by an EFI loader.  If so, then we have also been
  * passed the efi memmap, systab, etc., so we should use these data structures
@@ -955,19 +972,9 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
+#ifdef CONFIG_X86_32
+   setup_builtin_cmdline();
 #endif
-
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
-- 
2.7.0.25.gfc10eb5



[PATCH] x86/head64: define early_idt_ripmsg only if CONFIG_KALLSYMS is enabled

2016-01-30 Thread Alexander Kuleshov
We have definition of the early_idt_ripmsg which represents string header
for the output of the kernel symbols during early exception. But it will
be used only if CONFIG_KALLSYMS is enabled.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/head_64.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..c713d94 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -433,8 +433,10 @@ early_recursion_flag:
 #ifdef CONFIG_EARLY_PRINTK
 early_idt_msg:
.asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
+#ifdef CONFIG_KALLSYMS
 early_idt_ripmsg:
.asciz "RIP %s\n"
+#endif
 #endif /* CONFIG_EARLY_PRINTK */
 
 #define NEXT_PAGE(name) \
-- 
2.7.0.25.gfc10eb5



[tip:x86/boot] x86/boot: Simplify kernel load address alignment check

2016-01-30 Thread tip-bot for Alexander Kuleshov
Commit-ID:  a4733143085d6c782ac1e6c85778655b6bac1d4e
Gitweb: http://git.kernel.org/tip/a4733143085d6c782ac1e6c85778655b6bac1d4e
Author: Alexander Kuleshov 
AuthorDate: Tue, 26 Jan 2016 22:12:10 +0100
Committer:  Ingo Molnar 
CommitDate: Sat, 30 Jan 2016 11:22:48 +0100

x86/boot: Simplify kernel load address alignment check

We are using %rax as temporary register to check the kernel
address alignment. We don't really have to since the TEST
instruction does not clobber the destination operand.

Suggested-by: Brian Gerst 
Signed-off-by: Alexander Kuleshov 
Signed-off-by: Borislav Petkov 
Cc: Alexander Popov 
Cc: Andrey Ryabinin 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1453531828-19291-1-git-send-email-kuleshovm...@gmail.com
Link: http://lkml.kernel.org/r/1453842730-28463-11-git-send-email...@alien8.de
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/head_64.S | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..7c21029 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -76,9 +76,7 @@ startup_64:
subq$_text - __START_KERNEL_map, %rbp
 
/* Is the address not 2M aligned? */
-   movq%rbp, %rax
-   andl$~PMD_PAGE_MASK, %eax
-   testl   %eax, %eax
+   testl   $~PMD_PAGE_MASK, %ebp
jnz bad_address
 
/*


[tip:x86/boot] x86/boot: Micro-optimize reset_early_page_tables()

2016-01-30 Thread tip-bot for Alexander Kuleshov
Commit-ID:  5e9ebbd87a99ecc6abb74325b0ac63c46891f6f3
Gitweb: http://git.kernel.org/tip/5e9ebbd87a99ecc6abb74325b0ac63c46891f6f3
Author: Alexander Kuleshov 
AuthorDate: Sat, 30 Jan 2016 14:01:12 +0600
Committer:  Ingo Molnar 
CommitDate: Sat, 30 Jan 2016 09:20:55 +0100

x86/boot: Micro-optimize reset_early_page_tables()

Save 25 bytes of code and make the bootup a tiny bit faster:

 textdata bss dec filename
  9735144 4970776 1547468830180608vmlinux.old
  9735119 4970776 1547468830180583vmlinux

Signed-off-by: Alexander Kuleshov 
Cc: Alexander Popov 
Cc: Andrey Ryabinin 
Cc: Andy Lutomirski 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1454140872-16926-1-git-send-email-kuleshovm...@gmail.com
[ Fixed various small details. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/head64.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index f129a9a..35843ca 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -40,13 +40,8 @@ pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & 
~(_PAGE_GLOBAL | _PAGE_NX);
 /* Wipe all early page tables except for the kernel symbol map */
 static void __init reset_early_page_tables(void)
 {
-   unsigned long i;
-
-   for (i = 0; i < PTRS_PER_PGD-1; i++)
-   early_level4_pgt[i].pgd = 0;
-
+   memset(early_level4_pgt, 0, sizeof(pgd_t)*(PTRS_PER_PGD-1));
next_early_pgt = 0;
-
write_cr3(__pa_nodebug(early_level4_pgt));
 }
 
@@ -54,7 +49,6 @@ static void __init reset_early_page_tables(void)
 int __init early_make_pgtable(unsigned long address)
 {
unsigned long physaddr = address - __PAGE_OFFSET;
-   unsigned long i;
pgdval_t pgd, *pgd_p;
pudval_t pud, *pud_p;
pmdval_t pmd, *pmd_p;
@@ -81,8 +75,7 @@ again:
}
 
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PUD; i++)
-   pud_p[i] = 0;
+   memset(pud_p, 0, sizeof(pud_p) * PTRS_PER_PUD);
*pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pud_p += pud_index(address);
@@ -97,8 +90,7 @@ again:
}
 
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PMD; i++)
-   pmd_p[i] = 0;
+   memset(pmd_p, 0, sizeof(pmd_p) * PTRS_PER_PMD);
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pmd = (physaddr & PMD_MASK) + early_pmd_flags;


[PATCH] x86/head64: micro optimization: use memset instead of for loop

2016-01-30 Thread Alexander Kuleshov
This patch simplifies clearing of page table directories, by
the using of the fast memset() from the arch/x86/lib/memset_64.S.
Besides this, we 25 bytes is 25 bytes less than original.

text   data bss  dechex filename

9735144 4970776 15474688301806081cc8500 vmlinux.old
9735119 4970776 15474688301805831cc84e7 vmlinux

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/head64.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index f129a9a..4260ac4 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -40,13 +40,8 @@ pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & 
~(_PAGE_GLOBAL | _PAGE_NX);
 /* Wipe all early page tables except for the kernel symbol map */
 static void __init reset_early_page_tables(void)
 {
-   unsigned long i;
-
-   for (i = 0; i < PTRS_PER_PGD-1; i++)
-   early_level4_pgt[i].pgd = 0;
-
+   memset(early_level4_pgt, 0, sizeof(pgd_t) * (PTRS_PER_PGD-1));
next_early_pgt = 0;
-
write_cr3(__pa_nodebug(early_level4_pgt));
 }
 
@@ -54,7 +49,6 @@ static void __init reset_early_page_tables(void)
 int __init early_make_pgtable(unsigned long address)
 {
unsigned long physaddr = address - __PAGE_OFFSET;
-   unsigned long i;
pgdval_t pgd, *pgd_p;
pudval_t pud, *pud_p;
pmdval_t pmd, *pmd_p;
@@ -81,8 +75,7 @@ again:
}
 
pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PUD; i++)
-   pud_p[i] = 0;
+   memset(pud_p, 0, sizeof(pud_p) * PTRS_PER_PUD);
*pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pud_p += pud_index(address);
@@ -97,8 +90,7 @@ again:
}
 
pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
-   for (i = 0; i < PTRS_PER_PMD; i++)
-   pmd_p[i] = 0;
+   memset(pmd_p, 0, sizeof(pmd_p) * PTRS_PER_PMD);
*pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + 
_KERNPG_TABLE;
}
pmd = (physaddr & PMD_MASK) + early_pmd_flags;
-- 
2.7.0.25.gfc10eb5



[tip:timers/core] clockevents: Rename last parameter of clocks_calc_mult_shift() to maxsec

2016-01-27 Thread tip-bot for Alexander Kuleshov
Commit-ID:  dd42ac8f02aea32661756554aace2095f7181d34
Gitweb: http://git.kernel.org/tip/dd42ac8f02aea32661756554aace2095f7181d34
Author: Alexander Kuleshov 
AuthorDate: Fri, 16 Oct 2015 15:20:53 +0600
Committer:  Thomas Gleixner 
CommitDate: Wed, 27 Jan 2016 12:38:03 +0100

clockevents: Rename last parameter of clocks_calc_mult_shift() to maxsec

Last parameter of the clocks_calc_mult_shift() was renamed from minsec to
maxsec in the 5fdade95 (time: Rename misnamed minsec argument of
clocks_calc_mult_shift()).

Signed-off-by: Alexander Kuleshov 
Link: 
http://lkml.kernel.org/r/1444987253-11018-1-git-send-email-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 
---
 include/linux/clockchips.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h
index bdcf358..0d442e3 100644
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -190,9 +190,9 @@ extern void clockevents_config_and_register(struct 
clock_event_device *dev,
 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
 
 static inline void
-clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 
minsec)
+clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 
maxsec)
 {
-   return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, 
freq, minsec);
+   return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, 
freq, maxsec);
 }
 
 extern void clockevents_suspend(void);


[tip:x86/asm] x86/asm: Remove unused L3_PAGE_OFFSET

2016-01-27 Thread tip-bot for Alexander Kuleshov
Commit-ID:  14365449b6ce34cf6a3040ff8ebbb39d89d67159
Gitweb: http://git.kernel.org/tip/14365449b6ce34cf6a3040ff8ebbb39d89d67159
Author: Alexander Kuleshov 
AuthorDate: Tue, 26 Jan 2016 18:21:21 +0600
Committer:  Thomas Gleixner 
CommitDate: Wed, 27 Jan 2016 11:37:49 +0100

x86/asm: Remove unused L3_PAGE_OFFSET

L3_PAGE_OFFSET was introduced in commit a6523748bd (paravirt/x86, 64-bit: move
__PAGE_OFFSET to leave a space for hypervisor), but has no users.

Signed-off-by: Alexander Kuleshov 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Denys Vlasenko 
Cc: Andrey Ryabinin 
Link: 
http://lkml.kernel.org/r/1453810881-30622-1-git-send-email-kuleshovm...@gmail.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/head_64.S | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..2e97468 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -38,7 +38,6 @@
 #define pud_index(x)   (((x) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
 
 L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
-L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
 L3_START_KERNEL = pud_index(__START_KERNEL_map)
 


[PATCH] x86/head_64.S: remove unused L3_PAGE_OFFSET

2016-01-26 Thread Alexander Kuleshov
The kernel/head_64.S has L3_PAGE_OFFSET definition which is not
used anywhere. It was introduced in the a6523748bd commit
(paravirt/x86, 64-bit: move __PAGE_OFFSET to leave a space for hypervisor
by Eduardo Habkost ), but still not used
anywhere.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/head_64.S | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..2e97468 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -38,7 +38,6 @@
 #define pud_index(x)   (((x) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
 
 L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
-L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
 L3_START_KERNEL = pud_index(__START_KERNEL_map)
 
-- 
2.7.0.25.gfc10eb5



[PATCH] x86/head_64.S: do not use temporary register to check alignment

2016-01-22 Thread Alexander Kuleshov
We are using temporary %rax register during checking of kernel address
alignment. We can ged rid of it since testl instruction is safe and does
not change value of the rbp register.

Signed-off-by: Alexander Kuleshov 
Suggested-by: Brian Gerst 
---
 arch/x86/kernel/head_64.S | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..7c21029 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -76,9 +76,7 @@ startup_64:
subq$_text - __START_KERNEL_map, %rbp
 
/* Is the address not 2M aligned? */
-   movq%rbp, %rax
-   andl$~PMD_PAGE_MASK, %eax
-   testl   %eax, %eax
+   testl   $~PMD_PAGE_MASK, %ebp
jnz bad_address
 
/*
-- 
2.7.0.25.gfc10eb5



Re: [RFC PATCH] x86/head_64.S: remove redundant check that kernel address is 2M aligned

2016-01-22 Thread Alexander Kuleshov
Hello Brian,

On 01-22-16, Brian Gerst wrote:
> >
> > -   /* Is the address not 2M aligned? */
> > -   movq%rbp, %rax
> > -   andl$~PMD_PAGE_MASK, %eax
> > -   testl   %eax, %eax
> > -   jnz bad_address
> > -
> > /*
> >  * Is the address too large?
> >  */
> 
> I think we still need to do the check, in case we came from a 64-bit
> bootloader that directly jumped to startup_64.  However, this check
> can be simplified to:
> 
> testl $~PMD_PAGE_MASK, %ebp
> jnz bad_address

Ah, ok, in this way we can't trust a bootloader. I just thought that
64-bit entry point is startup_64 from arch/x86/boot/compressed/head_64.S

Thank you.


[RFC PATCH] x86/head_64.S: remove redundant check that kernel address is 2M aligned

2016-01-22 Thread Alexander Kuleshov
We check that the base address of the kernel is 2M aligned in
the arch/x86/kernel/head_65.S right after jump to the decompressed
kernel. But we already have a check in the decompress_kernel()
which validates that kernel location is MIN_KERNEL_ALIGN aligned
which is 2M too for x86_64.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/head_64.S | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ffdc0e8..4967cba 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -75,12 +75,6 @@ startup_64:
leaq_text(%rip), %rbp
subq$_text - __START_KERNEL_map, %rbp
 
-   /* Is the address not 2M aligned? */
-   movq%rbp, %rax
-   andl$~PMD_PAGE_MASK, %eax
-   testl   %eax, %eax
-   jnz bad_address
-
/*
 * Is the address too large?
 */
-- 
2.7.0.25.gfc10eb5



[PATCH] x86/aslr: use get_cmd_line_ptr() to get command line address

2016-01-21 Thread Alexander Kuleshov
The cmdline.c provides the get_cmd_line_ptr() accessor for the command line
address. In the same time, we get command line address in the
mem_avoid_init() in same way. Let's make the get_cmd_line_ptr() non-static
and use it in the mem_avoid_init() to get command line address to prevent
code duplication.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/boot/compressed/aslr.c| 3 +--
 arch/x86/boot/compressed/cmdline.c | 2 +-
 arch/x86/boot/compressed/misc.h| 1 +
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/aslr.c b/arch/x86/boot/compressed/aslr.c
index 6a9b96b..495a617 100644
--- a/arch/x86/boot/compressed/aslr.c
+++ b/arch/x86/boot/compressed/aslr.c
@@ -160,8 +160,7 @@ static void mem_avoid_init(unsigned long input, unsigned 
long input_size,
mem_avoid[1].size = initrd_size;
 
/* Avoid kernel command line. */
-   cmd_line  = (u64)real_mode->ext_cmd_line_ptr << 32;
-   cmd_line |= real_mode->hdr.cmd_line_ptr;
+   cmd_line = get_cmd_line_ptr();
/* Calculate size of cmd_line. */
ptr = (char *)(unsigned long)cmd_line;
for (cmd_line_size = 0; ptr[cmd_line_size++]; )
diff --git a/arch/x86/boot/compressed/cmdline.c 
b/arch/x86/boot/compressed/cmdline.c
index b68e303..6b913e6 100644
--- a/arch/x86/boot/compressed/cmdline.c
+++ b/arch/x86/boot/compressed/cmdline.c
@@ -13,7 +13,7 @@ static inline char rdfs8(addr_t addr)
return *((char *)(fs + addr));
 }
 #include "../cmdline.c"
-static unsigned long get_cmd_line_ptr(void)
+unsigned long get_cmd_line_ptr(void)
 {
unsigned long cmd_line_ptr = real_mode->hdr.cmd_line_ptr;
 
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 3783dc3..7956392 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -60,6 +60,7 @@ static inline void debug_puthex(const char *s)
 
 #if CONFIG_EARLY_PRINTK || CONFIG_RANDOMIZE_BASE
 /* cmdline.c */
+unsigned long get_cmd_line_ptr(void);
 int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 #endif
-- 
2.7.0.25.gfc10eb5



[PATCH] mm/memblock: use memblock_insert_region() for the empty array

2015-12-04 Thread Alexander Kuleshov
We have the special case for an empty array in the memblock_add_range()
function. In the same time we have almost the same functional in the
memblock_insert_region() function. Let's use the memblock_insert_region()
instead of direct initialization.

Signed-off-by: Alexander Kuleshov 
---
 mm/memblock.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index d300f13..e8a897d 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -496,12 +496,16 @@ static void __init_memblock memblock_insert_region(struct 
memblock_type *type,
struct memblock_region *rgn = &type->regions[idx];

BUG_ON(type->cnt >= type->max);
-   memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn));
+   /* special case for empty array */
+   if (idx)
+   {
+   memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn));
+   type->cnt++;
+   }
rgn->base = base;
rgn->size = size;
rgn->flags = flags;
memblock_set_region_node(rgn, nid);
-   type->cnt++;
type->total_size += size;
 }

@@ -536,11 +540,7 @@ int __init_memblock memblock_add_range(struct 
memblock_type *type,
/* special case for empty array */
if (type->regions[0].size == 0) {
WARN_ON(type->cnt != 1 || type->total_size);
-   type->regions[0].base = base;
-   type->regions[0].size = size;
-   type->regions[0].flags = flags;
-   memblock_set_region_node(&type->regions[0], nid);
-   type->total_size = size;
+   memblock_insert_region(type, 0, base, size, nid, flags);
return 0;
}
 repeat:
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mm/memblock: remove rgnbase and rgnsize variables

2015-12-04 Thread Alexander Kuleshov
This patch removes rgnbase and rgnsize variables from the
memblock_overlaps_region() function. We use these variables
only for passing to the memblock_addrs_overlap() function and
that's all. Let's remove them.

Signed-off-by: Alexander Kuleshov 
---
 mm/memblock.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index d300f13..9a45e21 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -96,13 +96,10 @@ bool __init_memblock memblock_overlaps_region(struct 
memblock_type *type,
 {
unsigned long i;
 
-   for (i = 0; i < type->cnt; i++) {
-   phys_addr_t rgnbase = type->regions[i].base;
-   phys_addr_t rgnsize = type->regions[i].size;
-   if (memblock_addrs_overlap(base, size, rgnbase, rgnsize))
+   for (i = 0; i < type->cnt; i++)
+   if (memblock_addrs_overlap(base, size, type->regions[i].base,
+  type->regions[i].size))
break;
-   }
-
return i < type->cnt;
 }
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mm/memblock: introduce for_each_memblock_type()

2015-12-04 Thread Alexander Kuleshov
We already have the for_each_memblock() macrom in the 
which provides ability to iterate over memblock regions of a known type.
The for_each_memblock() macro does allow us to pass the pointer to the
struct memblock_type, instead we need to pass name of the type.

This patch introduces new macro - for_each_memblock_type() which allows
us iterate over memblock regions with the given type when the type is
unknown.

Signed-off-by: Alexander Kuleshov 
---
 include/linux/memblock.h |  5 +
 mm/memblock.c| 32 
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 24daf8f..b7bb796 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -391,6 +391,11 @@ static inline unsigned long 
memblock_region_reserved_end_pfn(const struct memblo
 region < (memblock.memblock_type.regions + 
memblock.memblock_type.cnt);\
 region++)
 
+#define for_each_memblock_type(memblock_type, rgn) \
+   idx = 0;\
+   rgn = &memblock_type->regions[idx]; \
+   for (idx = 0; idx < memblock_type->cnt; \
+idx++,rgn = &memblock_type->regions[idx])
 
 #ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
 #define __init_memblock __meminit
diff --git a/mm/memblock.c b/mm/memblock.c
index d300f13..bf8b8ac 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -528,7 +528,8 @@ int __init_memblock memblock_add_range(struct memblock_type 
*type,
bool insert = false;
phys_addr_t obase = base;
phys_addr_t end = base + memblock_cap_size(base, &size);
-   int i, nr_new;
+   int idx, nr_new;
+   struct memblock_region *rgn;
 
if (!size)
return 0;
@@ -552,8 +553,7 @@ repeat:
base = obase;
nr_new = 0;
 
-   for (i = 0; i < type->cnt; i++) {
-   struct memblock_region *rgn = &type->regions[i];
+   for_each_memblock_type(type, rgn) {
phys_addr_t rbase = rgn->base;
phys_addr_t rend = rbase + rgn->size;
 
@@ -572,7 +572,7 @@ repeat:
WARN_ON(flags != rgn->flags);
nr_new++;
if (insert)
-   memblock_insert_region(type, i++, base,
+   memblock_insert_region(type, idx++, base,
   rbase - base, nid,
   flags);
}
@@ -584,7 +584,7 @@ repeat:
if (base < end) {
nr_new++;
if (insert)
-   memblock_insert_region(type, i, base, end - base,
+   memblock_insert_region(type, idx, base, end - base,
   nid, flags);
}
 
@@ -651,7 +651,8 @@ static int __init_memblock memblock_isolate_range(struct 
memblock_type *type,
int *start_rgn, int *end_rgn)
 {
phys_addr_t end = base + memblock_cap_size(base, &size);
-   int i;
+   int idx;
+   struct memblock_region *rgn;
 
*start_rgn = *end_rgn = 0;
 
@@ -663,8 +664,7 @@ static int __init_memblock memblock_isolate_range(struct 
memblock_type *type,
if (memblock_double_array(type, base, size) < 0)
return -ENOMEM;
 
-   for (i = 0; i < type->cnt; i++) {
-   struct memblock_region *rgn = &type->regions[i];
+   for_each_memblock_type(type, rgn) {
phys_addr_t rbase = rgn->base;
phys_addr_t rend = rbase + rgn->size;
 
@@ -681,7 +681,7 @@ static int __init_memblock memblock_isolate_range(struct 
memblock_type *type,
rgn->base = base;
rgn->size -= base - rbase;
type->total_size -= base - rbase;
-   memblock_insert_region(type, i, rbase, base - rbase,
+   memblock_insert_region(type, idx, rbase, base - rbase,
   memblock_get_region_node(rgn),
   rgn->flags);
} else if (rend > end) {
@@ -692,14 +692,14 @@ static int __init_memblock memblock_isolate_range(struct 
memblock_type *type,
rgn->base = end;
rgn->size -= end - rbase;
type->total_size -= end - rbase;
-   memblock_insert_region(type, i--, rbase, end - rbase,
+   memblock_insert_region(type, idx--, rbase, end - rbase,
   memblock_get_region_node(rgn),
 

[PATCH] xfs/xfs_buf: make xfs_buf_ioend_async() static

2015-11-27 Thread Alexander Kuleshov
There are no callers of the xfs_buf_ioend_async() function outside
of the fs/xfs/xfs_buf.c. So, let's make it static.

Signed-off-by: Alexander Kuleshov 
---
 fs/xfs/xfs_buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 3243cdf..45a8ea7 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1045,7 +1045,7 @@ xfs_buf_ioend_work(
xfs_buf_ioend(bp);
 }
 
-void
+static void
 xfs_buf_ioend_async(
struct xfs_buf  *bp)
 {
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mn10300: use asb2346_fpga_{mask,irq}() instead of direct calculation

2015-11-27 Thread Alexander Kuleshov
Signed-off-by: Alexander Kuleshov 
---
 arch/mn10300/unit-asb2364/irq-fpga.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/mn10300/unit-asb2364/irq-fpga.c 
b/arch/mn10300/unit-asb2364/irq-fpga.c
index 073e2cc..9772598 100644
--- a/arch/mn10300/unit-asb2364/irq-fpga.c
+++ b/arch/mn10300/unit-asb2364/irq-fpga.c
@@ -31,10 +31,8 @@ static void asb2364_fpga_ack(struct irq_data *d)
 
 static void asb2364_fpga_mask_ack(struct irq_data *d)
 {
-   ASB2364_FPGA_REG_MASK(d->irq - NR_CPU_IRQS) = 0x0001;
-   SyncExBus();
-   ASB2364_FPGA_REG_IRQ(d->irq - NR_CPU_IRQS) = 0x0001;
-   SyncExBus();
+   asb2364_fpga_mask(d);
+   asb2364_fpga_irq(d);
 }
 
 static void asb2364_fpga_unmask(struct irq_data *d)
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions

2015-11-26 Thread Alexander Kuleshov
On Thu, Nov 26, 2015 at 12:26 PM, Sudip Mukherjee
 wrote:
> Signed-off-by ?

Hello Sudip,

I've put it in the v2 (https://lkml.org/lkml/2015/11/25/650)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] drivers/tty/serial: make tegra_serial_handle_break() static

2015-11-25 Thread Alexander Kuleshov
There are no callers of the tegra_serial_handle_break() function
outside of drivers/tty/serial/of_serial.c. So let's make it static.

Signed-off-by: Alexander Kuleshov 
---
Forgot Signed-off-by line

 drivers/tty/serial/of_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index de50296..a35f694 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -34,7 +34,7 @@ struct of_serial_info {
 };

 #ifdef CONFIG_ARCH_TEGRA
-void tegra_serial_handle_break(struct uart_port *p)
+static void tegra_serial_handle_break(struct uart_port *p)
 {
unsigned int status, tmout = 1;

--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] crypto/cryptod: use crypto_skcipher_type() for getting skcipher type

2015-11-25 Thread Alexander Kuleshov
The  provides inline function - crypto_skcipher_type().
Let's use it in the cryptd_alloc_ablkcipher() instead of direct calculation.

Signed-off-by: Alexander Kuleshov 
---
 crypto/cryptd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index c81861b..c4af8aa 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -887,8 +887,7 @@ struct cryptd_ablkcipher *cryptd_alloc_ablkcipher(const 
char *alg_name,
if (snprintf(cryptd_alg_name, CRYPTO_MAX_ALG_NAME,
 "cryptd(%s)", alg_name) >= CRYPTO_MAX_ALG_NAME)
return ERR_PTR(-EINVAL);
-   type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
-   type |= CRYPTO_ALG_TYPE_BLKCIPHER;
+   type = crypto_skcipher_type(type);
mask &= ~CRYPTO_ALG_TYPE_MASK;
mask |= (CRYPTO_ALG_GENIV | CRYPTO_ALG_TYPE_BLKCIPHER_MASK);
tfm = crypto_alloc_base(cryptd_alg_name, type, mask);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] staging/dgap: move duplicated code from the dgap_cm.* functions

2015-11-25 Thread Alexander Kuleshov
The dgap driver contains three functions: dgap_cmdb(), dgap_cmdw()
and dgap_cmdw_exit which are contain duplicated code which waits
if necessary before updating the pointer to limit outstanding
commands. This patch introduces the wait_for_fep_cmds_limit()
function which is will be called from these functions to prevent
code duplication.

Signed-off-by: Alexander Kuleshov 
---
Forgot Signed-off-by line

 drivers/staging/dgap/dgap.c | 103 
 1 file changed, 37 insertions(+), 66 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index bad3551..0a20253 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -2328,6 +2328,37 @@ schedule_poller:
add_timer(&dgap_poll_timer);
 }

+
+/*
+ * Wait if necessary before updating the head
+ * pointer to limit the number of outstanding
+ * commands to the FEP.   If the time spent waiting
+ * is outlandish, declare the FEP dead.
+ */
+static void wait_for_fep_cmds_limit(struct channel_t *ch,
+   struct __iomem cm_t *cm_addr,
+   u16 head, u16 tail, uint ncmds)
+{
+   int n;
+   int count;
+
+   for (count = dgap_count ;;) {
+   head = readw(&cm_addr->cm_head);
+   tail = readw(&cm_addr->cm_tail);
+
+   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+
+   if (n <= ncmds * sizeof(struct cm_t))
+   break;
+
+   if (--count == 0) {
+   ch->ch_bd->state = BOARD_FAILED;
+   return;
+   }
+   udelay(10);
+   }
+}
+
 /*===
  *
  *  dgap_cmdb - Sends a 2 byte command to the FEP.
@@ -2345,8 +2376,6 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 
byte1,
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;

@@ -2391,27 +2420,9 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 
byte1,

writew(head, &cm_addr->cm_head);

-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* is outlandish, declare the FEP dead.
-*/
-   for (count = dgap_count ;;) {
-   head = readw(&cm_addr->cm_head);
-   tail = readw(&cm_addr->cm_tail);
-
-   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+   wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds);

-   if (n <= ncmds * sizeof(struct cm_t))
-   break;
-
-   if (--count == 0) {
-   ch->ch_bd->state = BOARD_FAILED;
-   return;
-   }
-   udelay(10);
-   }
+   return;
 }

 /*===
@@ -2429,8 +2440,6 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 
word, uint ncmds)
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;

@@ -2473,27 +2482,9 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 
word, uint ncmds)

writew(head, &cm_addr->cm_head);

-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* is outlandish, declare the FEP dead.
-*/
-   for (count = dgap_count ;;) {
-   head = readw(&cm_addr->cm_head);
-   tail = readw(&cm_addr->cm_tail);
-
-   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+   wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds);

-   if (n <= ncmds * sizeof(struct cm_t))
-   break;
-
-   if (--count == 0) {
-   ch->ch_bd->state = BOARD_FAILED;
-   return;
-   }
-   udelay(10);
-   }
+   return;
 }

 /*===
@@ -2511,8 +2502,6 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, 
u16 word, uint ncmds)
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;

@@ -2567,27 +2556,9 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, 
u16 word, uint ncmds)

writew(head, &cm_addr->cm_head);

-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* i

[PATCH] staging/dgap: move duplicated code from the dgap_cm.* functions

2015-11-25 Thread Alexander Kuleshov
The dgap driver contains three functions: dgap_cmdb(), dgap_cmdw()
and dgap_cmdw_exit which are contain duplicated code which waits
if necessary before updating the pointer to limit outstanding
commands. This patch introduces the wait_for_fep_cmds_limit()
function which is will be called from these functions to prevent
code duplication.
---
 drivers/staging/dgap/dgap.c | 103 
 1 file changed, 37 insertions(+), 66 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index bad3551..0a20253 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -2328,6 +2328,37 @@ schedule_poller:
add_timer(&dgap_poll_timer);
 }
 
+
+/*
+ * Wait if necessary before updating the head
+ * pointer to limit the number of outstanding
+ * commands to the FEP.   If the time spent waiting
+ * is outlandish, declare the FEP dead.
+ */
+static void wait_for_fep_cmds_limit(struct channel_t *ch,
+   struct __iomem cm_t *cm_addr,
+   u16 head, u16 tail, uint ncmds)
+{
+   int n;
+   int count;
+
+   for (count = dgap_count ;;) {
+   head = readw(&cm_addr->cm_head);
+   tail = readw(&cm_addr->cm_tail);
+
+   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+
+   if (n <= ncmds * sizeof(struct cm_t))
+   break;
+
+   if (--count == 0) {
+   ch->ch_bd->state = BOARD_FAILED;
+   return;
+   }
+   udelay(10);
+   }
+}
+
 /*===
  *
  *  dgap_cmdb - Sends a 2 byte command to the FEP.
@@ -2345,8 +2376,6 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 
byte1,
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;
 
@@ -2391,27 +2420,9 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 
byte1,
 
writew(head, &cm_addr->cm_head);
 
-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* is outlandish, declare the FEP dead.
-*/
-   for (count = dgap_count ;;) {
-   head = readw(&cm_addr->cm_head);
-   tail = readw(&cm_addr->cm_tail);
-
-   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+   wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds);
 
-   if (n <= ncmds * sizeof(struct cm_t))
-   break;
-
-   if (--count == 0) {
-   ch->ch_bd->state = BOARD_FAILED;
-   return;
-   }
-   udelay(10);
-   }
+   return;
 }
 
 /*===
@@ -2429,8 +2440,6 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 
word, uint ncmds)
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;
 
@@ -2473,27 +2482,9 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 
word, uint ncmds)
 
writew(head, &cm_addr->cm_head);
 
-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* is outlandish, declare the FEP dead.
-*/
-   for (count = dgap_count ;;) {
-   head = readw(&cm_addr->cm_head);
-   tail = readw(&cm_addr->cm_tail);
-
-   n = (head - tail) & (CMDMAX - CMDSTART - 4);
+   wait_for_fep_cmds_limit(ch, cm_addr, head, tail, ncmds);
 
-   if (n <= ncmds * sizeof(struct cm_t))
-   break;
-
-   if (--count == 0) {
-   ch->ch_bd->state = BOARD_FAILED;
-   return;
-   }
-   udelay(10);
-   }
+   return;
 }
 
 /*===
@@ -2511,8 +2502,6 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, 
u16 word, uint ncmds)
 {
char __iomem *vaddr;
struct __iomem cm_t *cm_addr;
-   uint count;
-   uint n;
u16 head;
u16 tail;
 
@@ -2567,27 +2556,9 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, 
u16 word, uint ncmds)
 
writew(head, &cm_addr->cm_head);
 
-   /*
-* Wait if necessary before updating the head
-* pointer to limit the number of outstanding
-* commands to the FEP.   If the time spent waiting
-* is outlandish, declare the FEP dead.
-*/
-   for (count = dgap_count ;;) {
-   head = readw(&cm_addr->cm_head);
-   tail = 

[PATCH] drivers/tty/serial: make tegra_serial_handle_break() static

2015-11-25 Thread Alexander Kuleshov
There are no callers of the tegra_serial_handle_break() function
outside of drivers/tty/serial/of_serial.c. So let's make it static.
---
 drivers/tty/serial/of_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index de50296..a35f694 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -34,7 +34,7 @@ struct of_serial_info {
 };
 
 #ifdef CONFIG_ARCH_TEGRA
-void tegra_serial_handle_break(struct uart_port *p)
+static void tegra_serial_handle_break(struct uart_port *p)
 {
unsigned int status, tmout = 1;
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] arm64/mm: use PAGE_ALIGNED instead of IS_ALIGNED

2015-10-26 Thread Alexander Kuleshov
The  already provides the PAGE_ALIGNED macro. Let's
use this macro instead of IS_ALIGNED and passing PAGE_SIZE directly.

Signed-off-by: Alexander Kuleshov 
---
 arch/arm64/mm/pageattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index e47ed1c..3571c73 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -45,7 +45,7 @@ static int change_memory_common(unsigned long addr, int 
numpages,
int ret;
struct page_change_data data;
 
-   if (!IS_ALIGNED(addr, PAGE_SIZE)) {
+   if (!PAGE_ALIGNED(addr)) {
start &= PAGE_MASK;
end = start + size;
WARN_ON_ONCE(1);
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mm/hugetlb: make node_hstates array static

2015-10-17 Thread Alexander Kuleshov
There are no users of the node_hstates array outside of the
mm/hugetlb.c. So let's make it static.

Signed-off-by: Alexander Kuleshov 
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 9cc7734..3afd92f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2376,7 +2376,7 @@ struct node_hstate {
struct kobject  *hugepages_kobj;
struct kobject  *hstate_kobjs[HUGE_MAX_HSTATE];
 };
-struct node_hstate node_hstates[MAX_NUMNODES];
+static struct node_hstate node_hstates[MAX_NUMNODES];
 
 /*
  * A subset of global hstate attributes for node devices
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] clockchips.h: rename last parameter of clocks_calc_mult_shift() to maxsec

2015-10-16 Thread Alexander Kuleshov
Last parameter of the clocks_calc_mult_shift() was renamed from minsec to
maxsec in the 5fdade95 (time: Rename misnamed minsec argument of
clocks_calc_mult_shift()).

Signed-off-by: Alexander Kuleshov 
---
 include/linux/clockchips.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h
index bdcf358..0d442e3 100644
--- a/include/linux/clockchips.h
+++ b/include/linux/clockchips.h
@@ -190,9 +190,9 @@ extern void clockevents_config_and_register(struct 
clock_event_device *dev,
 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
 
 static inline void
-clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 
minsec)
+clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 
maxsec)
 {
-   return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, 
freq, minsec);
+   return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, 
freq, maxsec);
 }
 
 extern void clockevents_suspend(void);
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] powerpc/mm: use memblock_is_memory

2015-10-09 Thread Alexander Kuleshov
The  provides memblock_is_memory() function that
tries to find a given physical address in the memblock.memory.regions.
Let's use this function instead of direct coding of the same functionality.

Signed-off-by: Alexander Kuleshov 
---
 arch/powerpc/mm/mem.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 22d94c3..85b462b 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -82,11 +82,9 @@ int page_is_ram(unsigned long pfn)
return pfn < max_pfn;
 #else
unsigned long paddr = (pfn << PAGE_SHIFT);
-   struct memblock_region *reg;

-   for_each_memblock(memory, reg)
-   if (paddr >= reg->base && paddr < (reg->base + reg->size))
-   return 1;
+   if (memblock_is_memory(paddr))
+   return 1;
return 0;
 #endif
 }
--
2.6.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] x86/pci/legacy: make pci_subsys_init static

2015-10-08 Thread Alexander Kuleshov
The pci_subsys_init() is a subsys_initcall that can be declared
static.

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/pci/legacy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/pci/legacy.c b/arch/x86/pci/legacy.c
index 5b662c0..ea6f380 100644
--- a/arch/x86/pci/legacy.c
+++ b/arch/x86/pci/legacy.c
@@ -54,7 +54,7 @@ void pcibios_scan_specific_bus(int busn)
 }
 EXPORT_SYMBOL_GPL(pcibios_scan_specific_bus);
 
-int __init pci_subsys_init(void)
+static int __init pci_subsys_init(void)
 {
/*
 * The init function returns an non zero value when
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] crypto/jitterentropy-kcapi: remove unnecessary information from a comment

2015-10-08 Thread Alexander Kuleshov
The clocksource does not provide clocksource_register() function since
f893598 commit (clocksource: Mostly kill clocksource_register()), so
let's remove unnecessary information about this function from a comment.

Signed-off-by: Alexander Kuleshov 
Suggested-by: Herbert Xu 
---
 crypto/jitterentropy-kcapi.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index ceea83d..597cedd 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -98,10 +98,6 @@ void jent_get_nstime(__u64 *out)
 * If random_get_entropy does not return a value (which is possible on,
 * for example, MIPS), invoke __getnstimeofday
 * hoping that there are timers we can work with.
-*
-* The list of available timers can be obtained from
-* /sys/devices/system/clocksource/clocksource0/available_clocksource
-* and are registered with clocksource_register()
 */
if ((0 == tmp) &&
   (0 == __getnstimeofday(&ts))) {
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] crypto/jitterentropy-kcapi: fix a comment reflecting function name changed

2015-10-07 Thread Alexander Kuleshov
The clocksource does not provide clocksource_register() function since
f893598 commit (clocksource: Mostly kill clocksource_register()), but
__clocksource_register() instead.

Signed-off-by: Alexander Kuleshov 
---
 crypto/jitterentropy-kcapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index ceea83d..4b030df 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -101,7 +101,7 @@ void jent_get_nstime(__u64 *out)
 *
 * The list of available timers can be obtained from
 * /sys/devices/system/clocksource/clocksource0/available_clocksource
-* and are registered with clocksource_register()
+* and are registered with __clocksource_register()
 */
if ((0 == tmp) &&
   (0 == __getnstimeofday(&ts))) {
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] m68k/sun3: Fix virtual addresses of clock and interrupt register

2015-09-25 Thread Alexander Kuleshov
Hello Geert

On Fri, Sep 25, 2015 at 1:21 PM, Geert Uytterhoeven
 wrote:
> Have you tested this?
>
> This means enabling/disabling interrupts never worked on Sun 3, which
> I find a bit difficult to believe.
> There are other 0x0f?? addresses in arch/m68k/sun3/mmu_emu.c.
>

Nope, just trying to do it in virtual machine, I'm learning sun3
architecture now
and have some cleanups patches for it. I'll send these patches and provide more
feedback when I'm able to test it.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [char-misc 1/2] mei: Fix debugfs filename in error output

2015-09-21 Thread Alexander Kuleshov
Hello Greg,

On Mon, Sep 21, 2015 at 8:25 AM, Greg Kroah-Hartman
 wrote:
> On Mon, Aug 24, 2015 at 03:27:36PM +0300, Tomas Winkler wrote:
>> From: "Signed-off-by: Alexander Kuleshov" 
>
> I kind of doubt that's the real author name :(
>

Why? I've definitely sent this patch sometime ago
(https://lkml.org/lkml/2015/8/14/560)

Thank you.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] s390/crash_dump: Use PFN_PHYS and PFN_DOWN macros

2015-09-15 Thread Alexander Kuleshov
The  provides PFN_PHYS and PFN_DOWN macros for the
getting page frame number and physical address of a page frame number.
This patch replaces (pfn << PAGE_SHIFT) and (addr >> PAGE_SHIFT)
expressions with the PFN_PHYS and PFN_DOWN macros.

Signed-off-by: Alexander Kuleshov 
---
 arch/s390/kernel/crash_dump.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index 1e4fcfa..f8da32c 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -136,7 +136,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, 
size_t csize,
 
if (!csize)
return 0;
-   src = (pfn << PAGE_SHIFT) + offset;
+   src = (PFN_PHYS(pfn)) + offset;
if (OLDMEM_BASE)
return copy_oldmem_page_kdump(buf, csize, src, userbuf);
else
@@ -156,16 +156,17 @@ static int remap_oldmem_pfn_range_kdump(struct 
vm_area_struct *vma,
unsigned long size_old;
int rc;
 
-   if (pfn < OLDMEM_SIZE >> PAGE_SHIFT) {
-   size_old = min(size, OLDMEM_SIZE - (pfn << PAGE_SHIFT));
+   if (pfn < PFN_DOWN(OLDMEM_SIZE)) {
+   size_old = min(size,
+   OLDMEM_SIZE - (unsigned long)(PFN_PHYS(pfn)));
rc = remap_pfn_range(vma, from,
-pfn + (OLDMEM_BASE >> PAGE_SHIFT),
+pfn + (PFN_DOWN(OLDMEM_BASE)),
 size_old, prot);
if (rc || size == size_old)
return rc;
size -= size_old;
from += size_old;
-   pfn += size_old >> PAGE_SHIFT;
+   pfn += PFN_DOWN(size_old);
}
return remap_pfn_range(vma, from, pfn, size, prot);
 }
@@ -184,13 +185,14 @@ static int remap_oldmem_pfn_range_zfcpdump(struct 
vm_area_struct *vma,
unsigned long hsa_end = sclp.hsa_size;
unsigned long size_hsa;
 
-   if (pfn < hsa_end >> PAGE_SHIFT) {
-   size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
+   if (pfn < PFN_DOWN(hsa_end)) {
+   size_hsa = min(size,
+   hsa_end - (unsigned long)(PFN_PHYS(pfn)));
if (size == size_hsa)
return 0;
size -= size_hsa;
from += size_hsa;
-   pfn += size_hsa >> PAGE_SHIFT;
+   pfn += PFN_DOWN(size_hsa);
}
return remap_pfn_range(vma, from, pfn, size, prot);
 }
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] s390/crash_dump: Use for_each_mem_range

2015-09-15 Thread Alexander Kuleshov
The  already provides for_each_mem_range() macro that
iterates through memblock areas from type_a and not included in type_b.
We can remove custom for_each_dump_mem_range() macro and use the
for_each_mem_range() instead.

Signed-off-by: Alexander Kuleshov 
---
 arch/s390/kernel/crash_dump.c | 16 
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index 0c6c01e..1e4fcfa 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -32,16 +32,6 @@ static struct memblock_type oldmem_type = {
.regions = &oldmem_region,
 };
 
-#define for_each_dump_mem_range(i, nid, p_start, p_end, p_nid) \
-   for (i = 0, __next_mem_range(&i, nid, MEMBLOCK_NONE,\
-&memblock.physmem, \
-&oldmem_type, p_start, \
-p_end, p_nid); \
-i != (u64)ULLONG_MAX;  \
-__next_mem_range(&i, nid, MEMBLOCK_NONE, &memblock.physmem,\
- &oldmem_type, \
- p_start, p_end, p_nid))
-
 struct dump_save_areas dump_save_areas;
 
 /*
@@ -515,7 +505,8 @@ static int get_mem_chunk_cnt(void)
int cnt = 0;
u64 idx;
 
-   for_each_dump_mem_range(idx, NUMA_NO_NODE, NULL, NULL, NULL)
+   for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
+   MEMBLOCK_NONE, NULL, NULL, NULL)
cnt++;
return cnt;
 }
@@ -528,7 +519,8 @@ static void loads_init(Elf64_Phdr *phdr, u64 loads_offset)
phys_addr_t start, end;
u64 idx;
 
-   for_each_dump_mem_range(idx, NUMA_NO_NODE, &start, &end, NULL) {
+   for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
+   MEMBLOCK_NONE, &start, &end, NULL) {
phdr->p_filesz = end - start;
phdr->p_type = PT_LOAD;
phdr->p_offset = start;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] mm/memblock: Make memblock_remove_range() static

2015-09-15 Thread Alexander Kuleshov
The memblock_remove_range() function is only used in the
mm/memblock.c, so we can do it static.

Signed-off-by: Alexander Kuleshov 
---
 include/linux/memblock.h | 4 
 mm/memblock.c| 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index c518eb5..24daf8f 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -89,10 +89,6 @@ int memblock_add_range(struct memblock_type *type,
   phys_addr_t base, phys_addr_t size,
   int nid, unsigned long flags);
 
-int memblock_remove_range(struct memblock_type *type,
- phys_addr_t base,
- phys_addr_t size);
-
 void __next_mem_range(u64 *idx, int nid, ulong flags,
  struct memblock_type *type_a,
  struct memblock_type *type_b, phys_addr_t *out_start,
diff --git a/mm/memblock.c b/mm/memblock.c
index 1c7b647..d300f13 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -706,7 +706,7 @@ static int __init_memblock memblock_isolate_range(struct 
memblock_type *type,
return 0;
 }
 
-int __init_memblock memblock_remove_range(struct memblock_type *type,
+static int __init_memblock memblock_remove_range(struct memblock_type *type,
  phys_addr_t base, phys_addr_t size)
 {
int start_rgn, end_rgn;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/10] mm/mincore: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/mincore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mincore.c b/mm/mincore.c
index be25efd..a011355 100644
--- a/mm/mincore.c
+++ b/mm/mincore.c
@@ -234,8 +234,7 @@ SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len,
 
/* This also avoids any overflows on PAGE_CACHE_ALIGN */
pages = len >> PAGE_SHIFT;
-   pages += (len & ~PAGE_MASK) != 0;
+   pages += (offset_in_page(len)) != 0;
 
if (!access_ok(VERIFY_WRITE, vec, pages))
return -EFAULT;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 00/10] Use offset_in_page() macro

2015-09-15 Thread Alexander Kuleshov
This patchset does not provide functional changes, but just replaces
(addr & ~PAGE_MASK) expression with already defined offset_in_page()
macro from the .

Alexander Kuleshov (10):
  mm/msync: Use offset_in_page macro
  mm/nommu: Use offset_in_page macro
  mm/mincore: Use offset_in_page macro
  mm/early_ioremap: Use offset_in_page macro
  mm/percpu: Use offset_in_page macro
  mm/util: Use offset_in_page macro
  mm/mlock: Use offset_in_page macro
  mm/vmalloc: Use offset_in_page macro
  mm/mmap: Use offset_in_page macro
  mm/mremap: Use offset_in_page macro

 mm/early_ioremap.c |  6 +++---
 mm/mincore.c   |  2 +-
 mm/mlock.c |  6 +++---
 mm/mmap.c  | 12 ++--
 mm/mremap.c| 12 ++--
 mm/msync.c |  2 +-
 mm/nommu.c |  8 
 mm/percpu.c| 10 +-
 mm/util.c  |  2 +-
 mm/vmalloc.c   | 12 ++--
 10 files changed, 36 insertions(+), 36 deletions(-)

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/10] mm/mmap: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/mmap.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 971dd2c..a313a9c 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1304,7 +1304,7 @@ unsigned long do_mmap(struct file *file, unsigned long 
addr,
 * that it represents a valid section of the address space.
 */
addr = get_unmapped_area(file, addr, len, pgoff, flags);
-   if (addr & ~PAGE_MASK)
+   if (offset_in_page(addr))
return addr;
 
/* Do simple checking here so the lower-level routines won't have
@@ -1475,7 +1475,7 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user 
*, arg)
 
if (copy_from_user(&a, arg, sizeof(a)))
return -EFAULT;
-   if (a.offset & ~PAGE_MASK)
+   if (offset_in_page(a.offset))
return -EINVAL;
 
return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
@@ -1996,7 +1996,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const 
unsigned long addr0,
 * can happen with large stack limits and large mmap()
 * allocations.
 */
-   if (addr & ~PAGE_MASK) {
+   if (offset_in_page(addr)) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
info.low_limit = TASK_UNMAPPED_BASE;
@@ -2032,7 +2032,7 @@ get_unmapped_area(struct file *file, unsigned long addr, 
unsigned long len,
 
if (addr > TASK_SIZE - len)
return -ENOMEM;
-   if (addr & ~PAGE_MASK)
+   if (offset_in_page(addr))
return -EINVAL;
 
addr = arch_rebalance_pgtables(addr, len);
@@ -2543,7 +2543,7 @@ int do_munmap(struct mm_struct *mm, unsigned long start, 
size_t len)
unsigned long end;
struct vm_area_struct *vma, *prev, *last;
 
-   if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
+   if ((offset_in_page(start)) || start > TASK_SIZE || len > 
TASK_SIZE-start)
return -EINVAL;
 
len = PAGE_ALIGN(len);
@@ -2741,7 +2741,7 @@ static unsigned long do_brk(unsigned long addr, unsigned 
long len)
flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
 
error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
-   if (error & ~PAGE_MASK)
+   if (offset_in_page(error))
return error;
 
error = mlock_future_check(mm, mm->def_flags, len);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/10] mm/percpu: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/percpu.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index a63b4d8..8a943b9 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1554,12 +1554,12 @@ int __init pcpu_setup_first_chunk(const struct 
pcpu_alloc_info *ai,
PCPU_SETUP_BUG_ON(ai->nr_groups <= 0);
 #ifdef CONFIG_SMP
PCPU_SETUP_BUG_ON(!ai->static_size);
-   PCPU_SETUP_BUG_ON((unsigned long)__per_cpu_start & ~PAGE_MASK);
+   PCPU_SETUP_BUG_ON(offset_in_page(__per_cpu_start));
 #endif
PCPU_SETUP_BUG_ON(!base_addr);
-   PCPU_SETUP_BUG_ON((unsigned long)base_addr & ~PAGE_MASK);
+   PCPU_SETUP_BUG_ON(offset_in_page(base_addr));
PCPU_SETUP_BUG_ON(ai->unit_size < size_sum);
-   PCPU_SETUP_BUG_ON(ai->unit_size & ~PAGE_MASK);
+   PCPU_SETUP_BUG_ON(offset_in_page(ai->unit_size));
PCPU_SETUP_BUG_ON(ai->unit_size < PCPU_MIN_UNIT_SIZE);
PCPU_SETUP_BUG_ON(ai->dyn_size < PERCPU_DYNAMIC_EARLY_SIZE);
PCPU_SETUP_BUG_ON(pcpu_verify_alloc_info(ai) < 0);
@@ -1806,7 +1806,7 @@ static struct pcpu_alloc_info * __init 
pcpu_build_alloc_info(
 
alloc_size = roundup(min_unit_size, atom_size);
upa = alloc_size / min_unit_size;
-   while (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
+   while (alloc_size % upa || (offset_in_page(alloc_size / upa)))
upa--;
max_upa = upa;
 
@@ -1838,7 +1838,7 @@ static struct pcpu_alloc_info * __init 
pcpu_build_alloc_info(
for (upa = max_upa; upa; upa--) {
int allocs = 0, wasted = 0;
 
-   if (alloc_size % upa || ((alloc_size / upa) & ~PAGE_MASK))
+   if (alloc_size % upa || (offset_in_page(alloc_size / upa)))
continue;
 
for (group = 0; group < nr_groups; group++) {
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/10] mm/nommu: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/nommu.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/nommu.c b/mm/nommu.c
index ab14a20..1e0f168 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1497,7 +1497,7 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user 
*, arg)
 
if (copy_from_user(&a, arg, sizeof(a)))
return -EFAULT;
-   if (a.offset & ~PAGE_MASK)
+   if (offset_in_page(a.offset))
return -EINVAL;
 
return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
@@ -1653,9 +1653,9 @@ int do_munmap(struct mm_struct *mm, unsigned long start, 
size_t len)
goto erase_whole_vma;
if (start < vma->vm_start || end > vma->vm_end)
return -EINVAL;
-   if (start & ~PAGE_MASK)
+   if (offset_in_page(start))
return -EINVAL;
-   if (end != vma->vm_end && end & ~PAGE_MASK)
+   if (end != vma->vm_end && offset_in_page(end))
return -EINVAL;
if (start != vma->vm_start && end != vma->vm_end) {
ret = split_vma(mm, vma, start, 1);
@@ -1736,7 +1736,7 @@ static unsigned long do_mremap(unsigned long addr,
if (old_len == 0 || new_len == 0)
return (unsigned long) -EINVAL;
 
-   if (addr & ~PAGE_MASK)
+   if (offset_in_page(addr))
return -EINVAL;
 
if (flags & MREMAP_FIXED && new_addr != addr)
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/10] mm/util: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index 68ff8a5..9af1c12 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -309,7 +309,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 {
if (unlikely(offset + PAGE_ALIGN(len) < offset))
return -EINVAL;
-   if (unlikely(offset & ~PAGE_MASK))
+   if (unlikely(offset_in_page(offset)))
return -EINVAL;
 
return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/10] mm/mremap: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/mremap.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/mremap.c b/mm/mremap.c
index 5a71cce..3fea83c 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -401,7 +401,7 @@ static unsigned long mremap_to(unsigned long addr, unsigned 
long old_len,
unsigned long charged = 0;
unsigned long map_flags;
 
-   if (new_addr & ~PAGE_MASK)
+   if (offset_in_page(new_addr))
goto out;
 
if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
@@ -435,11 +435,11 @@ static unsigned long mremap_to(unsigned long addr, 
unsigned long old_len,
ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff +
((addr - vma->vm_start) >> PAGE_SHIFT),
map_flags);
-   if (ret & ~PAGE_MASK)
+   if (offset_in_page(ret))
goto out1;
 
ret = move_vma(vma, addr, old_len, new_len, new_addr, locked);
-   if (!(ret & ~PAGE_MASK))
+   if (!(offset_in_page(ret)))
goto out;
 out1:
vm_unacct_memory(charged);
@@ -484,7 +484,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, 
old_len,
if (flags & MREMAP_FIXED && !(flags & MREMAP_MAYMOVE))
return ret;
 
-   if (addr & ~PAGE_MASK)
+   if (offset_in_page(addr))
return ret;
 
old_len = PAGE_ALIGN(old_len);
@@ -566,7 +566,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, 
old_len,
vma->vm_pgoff +
((addr - vma->vm_start) >> PAGE_SHIFT),
map_flags);
-   if (new_addr & ~PAGE_MASK) {
+   if (offset_in_page(new_addr)) {
ret = new_addr;
goto out;
}
@@ -574,7 +574,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, 
old_len,
ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
}
 out:
-   if (ret & ~PAGE_MASK) {
+   if (offset_in_page(ret)) {
vm_unacct_memory(charged);
locked = 0;
}
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/10] mm/vmalloc: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/vmalloc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 2faaa29..b51b733 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -358,7 +358,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
struct vmap_area *first;
 
BUG_ON(!size);
-   BUG_ON(size & ~PAGE_MASK);
+   BUG_ON(offset_in_page(size));
BUG_ON(!is_power_of_2(align));
 
va = kmalloc_node(sizeof(struct vmap_area),
@@ -936,7 +936,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
void *vaddr = NULL;
unsigned int order;
 
-   BUG_ON(size & ~PAGE_MASK);
+   BUG_ON(offset_in_page(size));
BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
if (WARN_ON(size == 0)) {
/*
@@ -989,7 +989,7 @@ static void vb_free(const void *addr, unsigned long size)
unsigned int order;
struct vmap_block *vb;
 
-   BUG_ON(size & ~PAGE_MASK);
+   BUG_ON(offset_in_page(size));
BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
 
flush_cache_vunmap((unsigned long)addr, (unsigned long)addr + size);
@@ -1902,7 +1902,7 @@ static int aligned_vread(char *buf, char *addr, unsigned 
long count)
while (count) {
unsigned long offset, length;
 
-   offset = (unsigned long)addr & ~PAGE_MASK;
+   offset = offset_in_page(addr);
length = PAGE_SIZE - offset;
if (length > count)
length = count;
@@ -1941,7 +1941,7 @@ static int aligned_vwrite(char *buf, char *addr, unsigned 
long count)
while (count) {
unsigned long offset, length;
 
-   offset = (unsigned long)addr & ~PAGE_MASK;
+   offset = offset_in_page(addr);
length = PAGE_SIZE - offset;
if (length > count)
length = count;
@@ -2392,7 +2392,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long 
*offsets,
bool purged = false;
 
/* verify parameters and allocate data structures */
-   BUG_ON(align & ~PAGE_MASK || !is_power_of_2(align));
+   BUG_ON(offset_in_page(align) || !is_power_of_2(align));
for (last_area = 0, area = 0; area < nr_vms; area++) {
start = offsets[area];
end = start + sizes[area];
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/10] mm/msync: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/msync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/msync.c b/mm/msync.c
index bb04d53..24e612f 100644
--- a/mm/msync.c
+++ b/mm/msync.c
@@ -38,7 +38,7 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, 
int, flags)
 
if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC))
goto out;
-   if (start & ~PAGE_MASK)
+   if (offset_in_page(start))
goto out;
if ((flags & MS_ASYNC) && (flags & MS_SYNC))
goto out;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/10] mm/mlock: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/mlock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/mlock.c b/mm/mlock.c
index 25936680..e86206b 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -560,7 +560,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
struct vm_area_struct * vma, * prev;
int error;
 
-   VM_BUG_ON(start & ~PAGE_MASK);
+   VM_BUG_ON(offset_in_page(start));
VM_BUG_ON(len != PAGE_ALIGN(len));
end = start + len;
if (end < start)
@@ -616,7 +616,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
 
lru_add_drain_all();/* flush pagevec */
 
-   len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
+   len = PAGE_ALIGN(len + (offset_in_page(start)));
start &= PAGE_MASK;
 
lock_limit = rlimit(RLIMIT_MEMLOCK);
@@ -645,7 +645,7 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 {
int ret;
 
-   len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
+   len = PAGE_ALIGN(len + (offset_in_page(start)));
start &= PAGE_MASK;
 
down_write(¤t->mm->mmap_sem);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/10] mm/early_ioremap: Use offset_in_page macro

2015-09-15 Thread Alexander Kuleshov
The  provides offset_in_page() macro. Let's use already
predefined macro instead of (addr & ~PAGE_MASK).

Signed-off-by: Alexander Kuleshov 
---
 mm/early_ioremap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/early_ioremap.c b/mm/early_ioremap.c
index 17ae14b..6d5717b 100644
--- a/mm/early_ioremap.c
+++ b/mm/early_ioremap.c
@@ -126,7 +126,7 @@ __early_ioremap(resource_size_t phys_addr, unsigned long 
size, pgprot_t prot)
/*
 * Mappings have to be page-aligned
 */
-   offset = phys_addr & ~PAGE_MASK;
+   offset = offset_in_page(phys_addr);
phys_addr &= PAGE_MASK;
size = PAGE_ALIGN(last_addr + 1) - phys_addr;
 
@@ -189,7 +189,7 @@ void __init early_iounmap(void __iomem *addr, unsigned long 
size)
if (WARN_ON(virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)))
return;
 
-   offset = virt_addr & ~PAGE_MASK;
+   offset = offset_in_page(virt_addr);
nrpages = PAGE_ALIGN(offset + size) >> PAGE_SHIFT;
 
idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*slot;
@@ -234,7 +234,7 @@ void __init copy_from_early_mem(void *dest, phys_addr_t 
src, unsigned long size)
char *p;
 
while (size) {
-   slop = src & ~PAGE_MASK;
+   slop = offset_in_page(src);
clen = size;
if (clen > MAX_MAP_CHUNK - slop)
clen = MAX_MAP_CHUNK - slop;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] m68k/sun3: Fix virtual addresses of clock and interrupt register

2015-09-14 Thread Alexander Kuleshov
The MMU base is 32 bits size - 0xfe00, seems that we missed
one zero in the definition of the clock and interrupt register
addresses.

Signed-off-by: Alexander Kuleshov 
---
 arch/m68k/sun3/config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
index a8b942b..c9c388f 100644
--- a/arch/m68k/sun3/config.c
+++ b/arch/m68k/sun3/config.c
@@ -61,8 +61,8 @@ void __init sun3_init(void)
m68k_cputype = CPU_68020;
m68k_fputype = FPU_68881; /* mc68881 actually */
m68k_mmutype = MMU_SUN3;
-   clock_va=  (char *) 0xfe06000;  /* dark  */
-   sun3_intreg = (unsigned char *) 0xfe0a000;  /* magic */
+   clock_va=  (char *) 0xfe006000; /* dark  */
+   sun3_intreg = (unsigned char *) 0xfe00a000; /* magic */
sun3_disable_interrupts();
 
prom_init((void *)LINUX_OPPROM_BEGVM);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] lib/halfmd4: Use rol32 inline function in the ROUND macro

2015-09-13 Thread Alexander Kuleshov
The  provides rol32() inline function, let's use already
predefined function instead of direct expression.

Signed-off-by: Alexander Kuleshov 
---
 lib/halfmd4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/halfmd4.c b/lib/halfmd4.c
index a8fe627..137e861 100644
--- a/lib/halfmd4.c
+++ b/lib/halfmd4.c
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* F, G and H are basic MD4 functions: selection, majority, parity */
 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z
@@ -14,7 +15,7 @@
  * Rotation is separate from addition to prevent recomputation
  */
 #define ROUND(f, a, b, c, d, x, s) \
-   (a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s)))
+   (a += f(b, c, d) + x, a = rol32(a, s))
 #define K1 0
 #define K2 013240474631UL
 #define K3 015666365641UL
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging/dgap: Use strpbrk() instead of dgap_sindex()

2015-09-11 Thread Alexander Kuleshov
The  provides strpbrk() function that does
the same that the dgap_sindex(). Let's use already defined
function instead of writing custom.

Signed-off-by: Alexander Kuleshov 
---
 drivers/staging/dgap/dgap.c | 24 +---
 1 file changed, 1 insertion(+), 23 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 9112dd2..ee0f022 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -287,28 +287,6 @@ static struct toklist dgap_tlist[] = {
{ 0,NULL }
 };
 
-
-/*
- * dgap_sindex: much like index(), but it looks for a match of any character in
- * the group, and returns that position.
- */
-static char *dgap_sindex(char *string, char *group)
-{
-   char *ptr;
-
-   if (!string || !group)
-   return NULL;
-
-   for (; *string; string++) {
-   for (ptr = group; *ptr; ptr++) {
-   if (*ptr == *string)
-   return string;
-   }
-   }
-
-   return NULL;
-}
-
 /*
  * get a word from the input stream, also keep track of current line number.
  * words are separated by whitespace.
@@ -317,7 +295,7 @@ static char *dgap_getword(char **in)
 {
char *ret_ptr = *in;
 
-   char *ptr = dgap_sindex(*in, " \t\n");
+   char *ptr = strpbrk(*in, " \t\n");
 
/* If no word found, return null */
if (!ptr)
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] kvm: compile process_smi_save_seg_64() only for x86_64

2015-09-06 Thread Alexander Kuleshov
The process_smi_save_seg_64() function called only in the
process_smi_save_state_64() if the CONFIG_X86_64 is set. This
patch adds #ifdef CONFIG_X86_64 around process_smi_save_seg_64()
to prevent following warning message:

arch/x86/kvm/x86.c:5946:13: warning: ‘process_smi_save_seg_64’ defined but not 
used [-Wunused-function]
 static void process_smi_save_seg_64(struct kvm_vcpu *vcpu, char *buf, int n)
 ^

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kvm/x86.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1e7e76e..a60bdbc 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5943,6 +5943,7 @@ static void process_smi_save_seg_32(struct kvm_vcpu 
*vcpu, char *buf, int n)
put_smstate(u32, buf, offset, process_smi_get_segment_flags(&seg));
 }
 
+#ifdef CONFIG_X86_64
 static void process_smi_save_seg_64(struct kvm_vcpu *vcpu, char *buf, int n)
 {
struct kvm_segment seg;
@@ -5958,6 +5959,7 @@ static void process_smi_save_seg_64(struct kvm_vcpu 
*vcpu, char *buf, int n)
put_smstate(u32, buf, offset + 4, seg.limit);
put_smstate(u64, buf, offset + 8, seg.base);
 }
+#endif
 
 static void process_smi_save_state_32(struct kvm_vcpu *vcpu, char *buf)
 {
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] x86/head_32.S: Remove unused macros

2015-09-06 Thread Alexander Kuleshov
This patch removes two unused macros: X86_VENDOR and X86_HARD_MATH
from the arch/x86/kernel/head_32.S. Also as CPUINFO_x86_vendor not
used anywhere, we can safely remove it from asm-offsets_32.c

Signed-off-by: Alexander Kuleshov 
---
 arch/x86/kernel/asm-offsets_32.c | 1 -
 arch/x86/kernel/head_32.S| 2 --
 2 files changed, 3 deletions(-)

diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
index 6ce3902..fbd293c 100644
--- a/arch/x86/kernel/asm-offsets_32.c
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -18,7 +18,6 @@ void foo(void);
 void foo(void)
 {
OFFSET(CPUINFO_x86, cpuinfo_x86, x86);
-   OFFSET(CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor);
OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model);
OFFSET(CPUINFO_x86_mask, cpuinfo_x86, x86_mask);
OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 0e2d96f..89818b4 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -32,10 +32,8 @@
  */
 
 #define X86new_cpu_data+CPUINFO_x86
-#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor
 #define X86_MODEL  new_cpu_data+CPUINFO_x86_model
 #define X86_MASK   new_cpu_data+CPUINFO_x86_mask
-#define X86_HARD_MATH  new_cpu_data+CPUINFO_hard_math
 #define X86_CPUID  new_cpu_data+CPUINFO_cpuid_level
 #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
 #define X86_VENDOR_ID  new_cpu_data+CPUINFO_x86_vendor_id
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   4   >