[PATCH 7/7] rcu: splite tasks_rcu to tasks.c

2019-10-15 Thread Lai Jiangshan
bootup_oddness() whose declaration and call-site are also (forced) changed. Nothing else is changed. ./scripts/checkpatch.pl gives four warnings, but they don't need to be fixed. Signed-off-by: Lai Jiangshan Signed-off-by: Lai Jiangshan --- kernel/rcu/Makefile | 1 + kernel/rcu/

[PATCH 6/7] rcu: rename some CONFIG_PREEMPTION to CONFIG_PREEMPT_RCU

2019-10-15 Thread Lai Jiangshan
CONFIG_PREEMPTION and CONFIG_PREEMPT_RCU are always identical, but some code depends on CONFIG_PREEMPTION to access to rcu_preempt functionalitis. This patch changes CONFIG_PREEMPTION to CONFIG_PREEMPT_RCU in these cases. Signed-off-by: Lai Jiangshan Signed-off-by: Lai Jiangshan --- kernel/rcu

[PATCH 5/7] rcu: move gp_state_names[] and gp_state_getname() to tree_stall.h

2019-10-15 Thread Lai Jiangshan
Only tree_stall.h needs to get name from GP state. Signed-off-by: Lai Jiangshan Signed-off-by: Lai Jiangshan --- kernel/rcu/tree.c | 10 -- kernel/rcu/tree.h | 12 kernel/rcu/tree_stall.h | 22 ++ 3 files changed, 22 insertions(+), 22

[PATCH 4/7] rcu: remove the declaration of call_rcu() in tree.h

2019-10-15 Thread Lai Jiangshan
call_rcu() is external RCU API declared in include/linux/, and doesn't need to be (re-)declared in internal files again. Signed-off-by: Lai Jiangshan Signed-off-by: Lai Jiangshan --- kernel/rcu/tree.h | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/rcu/tree.h b/kernel/rcu/t

Re: [PATCH 2/7] rcu: fix tracepoint string when RCU CPU kthread runs

2019-10-15 Thread Lai Jiangshan
On 2019/10/16 11:38 上午, Paul E. McKenney wrote: On Tue, Oct 15, 2019 at 10:23:57AM +, Lai Jiangshan wrote: "rcu_wait" is incorrct here, use "rcu_run" instead. Signed-off-by: Lai Jiangshan Signed-off-by: Lai Jiangshan --- kernel/rcu/tree.c | 4 ++-- 1 file c

Re: [PATCH 6/7] rcu: rename some CONFIG_PREEMPTION to CONFIG_PREEMPT_RCU

2019-10-16 Thread Lai Jiangshan
On 2019/10/16 11:54 上午, Paul E. McKenney wrote: On Tue, Oct 15, 2019 at 10:28:48AM +, Lai Jiangshan wrote: CONFIG_PREEMPTION and CONFIG_PREEMPT_RCU are always identical, but some code depends on CONFIG_PREEMPTION to access to rcu_preempt functionalitis. This patch changes

Re: [PATCH] workqueue: combine judgments in the loop ofmaybe_create_worker

2018-09-12 Thread Lai Jiangshan
On Thu, Sep 13, 2018 at 9:51 AM wrote: > > >> From: Liu Song > >> > >> Although the 'need_to_create_worker' has been determined to be > >> true before entering the function. However, adjusting the order > >> of judgment can combine two judgments in the loop. Also improve > >> the matching between

Re: [PATCH 3/6] workqueue: Make worker_attach/detach_pool() update worker->pool

2018-05-18 Thread Lai Jiangshan
On Thu, May 17, 2018 at 12:34 PM, Tejun Heo wrote: > For historical reasons, the worker attach/detach functions don't > currently manage worker->pool and the callers are manually and > inconsistently updating it. > > This patch moves worker->pool updates into the worker attach/detach > functions.

[PATCH] workqueue: make manage_workers() and pool destruction exclusive

2018-03-19 Thread Lai Jiangshan
refcount of the pool in manage_workers(). "indirect" means it gets a refcount of the first involved pwq which holds a refcount of the pool. This refcount can prevent the pool from being destroyed. The original synchronization mechanism (wq_manager_wait) is also removed. Signed-off-by: Lai

Re: [PATCH 6/8] RCU, workqueue: Implement rcu_work

2018-03-15 Thread Lai Jiangshan
;work); > + local_irq_enable(); > +} > + > +/** > + * queue_rcu_work - queue work after a RCU grace period > + * @wq: workqueue to use > + * @rwork: work to queue > + * > + * Return: %false if @rwork was already pending, %true otherwise. Note > +

Re: [PATCH v4 07/15] lockdep: Implement crossrelease feature

2017-01-12 Thread Lai Jiangshan
> + > +/* > + * No contention. Irq disable is only required. > + */ > +static int same_context_plock(struct pend_lock *plock) > +{ > + struct task_struct *curr = current; > + int cpu = smp_processor_id(); > + > + /* In the case of hardirq context */ > + if (curr->hardirq_con

Re: [PATCH] Fix: disable sys_membarrier when nohz_full is enabled

2016-11-16 Thread Lai Jiangshan
, flags) > { > + /* MEMBARRIER_CMD_SHARED is not compatible with nohz_full. */ > + if (tick_nohz_full_enabled()) > + return -ENOSYS; I guess this code needs to be moved down into the branch of "case MEMBARRIER_CMD_SHARED" to match its comment. Acked-by: Lai Jia

Re: [PATCH RFC tip/core/rcu] SRCU rewrite

2016-11-17 Thread Lai Jiangshan
On Thu, Nov 17, 2016 at 10:31 PM, Boqun Feng wrote: > On Thu, Nov 17, 2016 at 08:18:51PM +0800, Lai Jiangshan wrote: >> On Tue, Nov 15, 2016 at 10:37 PM, Paul E. McKenney >> wrote: >> > On Tue, Nov 15, 2016 at 09:44:45AM +0800, Boqun Feng wrote: >> >> &g

Re: [PATCH RFC tip/core/rcu] SRCU rewrite

2016-11-17 Thread Lai Jiangshan
p->per_cpu_ref->lock_count[idx]); > smp_mb(); /* B */ /* Avoid leaking the critical section. */ > - __this_cpu_inc(sp->per_cpu_ref->seq[idx]); > return idx; > } > EXPORT_SYMBOL_GPL(__srcu_read_lock); > @@ -314,7 +285,7 @@ EXPORT_SYMBOL_GPL(__srcu_read_lock); > void __srcu_read_unlock(struct srcu_struct *sp, int idx) > { > smp_mb(); /* C */ /* Avoid leaking the critical section. */ > - this_cpu_dec(sp->per_cpu_ref->c[idx]); > + this_cpu_inc(sp->per_cpu_ref->unlock_count[idx]); > } > EXPORT_SYMBOL_GPL(__srcu_read_unlock); > > @@ -349,7 +320,7 @@ static bool try_check_zero(struct srcu_struct *sp, int > idx, int trycount) > > /* > * Increment the ->completed counter so that future SRCU readers will > - * use the other rank of the ->c[] and ->seq[] arrays. This allows > + * use the other rank of the ->(un)lock_count[] arrays. This allows > * us to wait for pre-existing readers in a starvation-free manner. > */ > static void srcu_flip(struct srcu_struct *sp) > Acked-by: Lai Jiangshan

Re: [PATCH RFC tip/core/rcu] SRCU rewrite

2016-11-17 Thread Lai Jiangshan
On Thu, Nov 17, 2016 at 10:45 PM, Boqun Feng wrote: > On Thu, Nov 17, 2016 at 06:38:29AM -0800, Paul E. McKenney wrote: >> On Thu, Nov 17, 2016 at 05:49:57AM -0800, Paul E. McKenney wrote: >> > On Thu, Nov 17, 2016 at 08:18:51PM +0800, Lai Jiangshan wrote: >> > > On

Re: [PATCH RFC tip/core/rcu] SRCU rewrite

2016-11-17 Thread Lai Jiangshan
On Tue, Nov 15, 2016 at 10:37 PM, Paul E. McKenney wrote: > On Tue, Nov 15, 2016 at 09:44:45AM +0800, Boqun Feng wrote: >> >> __srcu_read_lock() used to be called with preemption disabled. I guess >> the reason was because we have two percpu variables to increase. So with >> only one percpu right

Re: [RFC] kthread_create_on_node is failing to honor the node choice

2015-06-25 Thread Lai Jiangshan
On 06/26/2015 05:44 AM, Nathan Zimmer wrote: > In kthread_create_on_node we set_cpus_allowed to cpu_all_mask > regardless of what the node is requested. > This seems incorrect. > > Signed-off-by: Nathan Zimmer > Cc: Andrew Morton > Cc: Nishanth Aravamudan > Cc: Tejun

Re: [Ksummit-discuss] [BELATED CORE TOPIC] context tracking / nohz / RCU state

2015-08-11 Thread Lai Jiangshan
On Wed, Aug 12, 2015 at 1:49 AM, Andy Lutomirski wrote: > This is a bit late, but here goes anyway. > > Having played with the x86 context tracking hooks for awhile, I think > it would be nice if core code that needs to be aware of CPU context > (kernel, user, idle, guest, etc) could come up with

[PATCH 3/5] x86/entry: directly switch to kernel stack when .Lerror_bad_iret

2020-05-27 Thread Lai Jiangshan
(), switch to kernel stack with pt_regs copied So we can do the all things together in fixup_bad_iret(). After this patch, fixup_bad_iret() is restored to the behavior before 7f2590a110b8("x86/entry/64: Use a per-CPU trampoline stack for IDT entries") Signed-off-by: Lai Jiangshan ---

[PATCH 1/5] x86/entry: introduce macro idtentry_swapgs_and_switch_to_kernel_stack

2020-05-27 Thread Lai Jiangshan
Move a portion of code to be a macro, and it will also be used in next patch. Just move around the code, no functionality changed. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 60 ++- 1 file changed, 41 insertions(+), 19 deletions(-) diff

[PATCH 2/5] x86/entry: avoid calling into sync_regs() when entering from userspace

2020-05-27 Thread Lai Jiangshan
his is hot path, such overhead should be avoided. This patch borrows the way how interrupt_entry handles it. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 18 +++--- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/

[PATCH 5/5] x86/entry: don't copy to tmp in fixup_bad_iret

2020-05-27 Thread Lai Jiangshan
It is safe to do memcpy() in fixup_bad_iret() now. Signed-off-by: Lai Jiangshan --- arch/x86/kernel/traps.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 8291f84933ff..6fe72c771745 100644 --- a

[PATCH 0/5] x86/entry: simply stack switching when exception on userspace

2020-05-27 Thread Lai Jiangshan
jlstra , Cc: Alexandre Chartre , Cc: "Eric W. Biederman" , Cc: Jann Horn , Cc: Dave Hansen Lai Jiangshan (5): x86/entry: introduce macro idtentry_swapgs_and_switch_to_kernel_stack x86/entry: avoid calling into sync_regs() when entering from userspace x86/entry: directly switch to

[PATCH 4/5] x86/entry: remove unused sync_regs()

2020-05-27 Thread Lai Jiangshan
No more users. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/traps.h | 1 - arch/x86/kernel/traps.c | 13 - 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index f5a2e438a878..20b9db7a1d49 100644 --- a/arch/x86

Re: [PATCH v2 2/2] workqueue: Convert the pool::lock and wq_mayday_lock to raw_spinlock_t

2020-05-27 Thread Lai Jiangshan
-off-by: Sebastian Andrzej Siewior > --- > kernel/workqueue.c | 176 ++------- > 1 file changed, 88 insertions(+), 88 deletions(-) > Reviewed-by: Lai Jiangshan

[PATCH 2/2] workqueue: remove useless POOL_MANAGER_ACTIVE

2020-05-27 Thread Lai Jiangshan
It is the same meaning as pool->manager now. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 7 ++- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index fde10a5dba82..8bc11075763b 100644 --- a/kernel/workqueue.c +++ b/ker

[PATCH 1/2] workqueue: pin the pool while it is managing

2020-05-27 Thread Lai Jiangshan
pinlocks. Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Linus Torvalds Cc: Sebastian Andrzej Siewior Link: https://lore.kernel.org/lkml/20200527194633.1660952-2-bige...@linutronix.de Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 23 --- 1 file ch

Re: [PATCH 1/2] workqueue: pin the pool while it is managing

2020-05-28 Thread Lai Jiangshan
On Thu, May 28, 2020 at 4:08 PM Sebastian Andrzej Siewior wrote: > > On 2020-05-28 03:06:55 [+0000], Lai Jiangshan wrote: > > So that put_unbound_pool() can ensure all workers in idle, > > no unfinished manager. And it doens't need to wait any manager > > and can go t

Re: [PATCH V2 0/4] x86/entry: simply stack switching when exception on userspace

2020-06-18 Thread Lai Jiangshan
Hello and Ping On Tue, Jun 16, 2020 at 9:56 AM Lai Jiangshan wrote: > > On Sat, May 30, 2020 at 2:33 AM Andy Lutomirski wrote: > > > > On Fri, May 29, 2020 at 1:26 AM Lai Jiangshan > > wrote: > > > > > > 7f2590a110b8("x86/entry/64: Use a

Re: [PATCH 4/7] x86/entry: Increase entry_stack size to a full page

2020-06-18 Thread Lai Jiangshan
I'm glad to have the stack expanded, thanks. Reviewed-by: Lai Jiangshan > > Suggested-by: Andy Lutomirski > Reported-by: Marco Elver > Signed-off-by: Peter Zijlstra (Intel) > --- > arch/x86/include/asm/processor.h |2 +- > 1 file changed, 1 insertion(+), 1 dele

Re: [RFC PATCH 1/2] kvm/x86: intercept guest changes to X86_CR4_LA57

2020-09-29 Thread Lai Jiangshan
On Tue, Sep 29, 2020 at 4:32 PM Sean Christopherson wrote: > > On Tue, Sep 29, 2020 at 01:32:45PM +0800, Lai Jiangshan wrote: > > On Tue, Sep 29, 2020 at 12:24 AM Sean Christopherson > > wrote: > > > > > > On Mon, Sep 28, 2020 at 04:30:46PM +0800, Lai Jiangsha

[RFC PATCH 2/2] kvm/x86: allow guest to toggle X86_CR4_FSGSBASE

2020-09-28 Thread Lai Jiangshan
From: Lai Jiangshan There is no reason to force VM-Exit on toggling X86_CR4_FSGSBASE. Cc: Paolo Bonzini Signed-off-by: Lai Jiangshan --- arch/x86/kvm/kvm_cache_regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm

[RFC PATCH 1/2] kvm/x86: intercept guest changes to X86_CR4_LA57

2020-09-28 Thread Lai Jiangshan
From: Lai Jiangshan When shadowpaping is enabled, guest should not be allowed to toggle X86_CR4_LA57. And X86_CR4_LA57 is a rarely changed bit, so we can just intercept all the attempts to toggle it no matter shadowpaping is in used or not. Fixes: fd8cb433734ee ("KVM: MMU: Expose the

Re: [RFC PATCH 1/2] kvm/x86: intercept guest changes to X86_CR4_LA57

2020-09-28 Thread Lai Jiangshan
On Tue, Sep 29, 2020 at 12:24 AM Sean Christopherson wrote: > > On Mon, Sep 28, 2020 at 04:30:46PM +0800, Lai Jiangshan wrote: > > From: Lai Jiangshan > > > > When shadowpaping is enabled, guest should not be allowed > > to toggle X86_CR4_LA57. And X86_CR4_LA57 is a

Re: 回复: [PATCH v5] workqueue: Remove unnecessary kfree() call in rcu_free_wq()

2020-05-28 Thread Lai Jiangshan
On Thu, May 28, 2020 at 5:57 PM Dan Carpenter wrote: > > Guys, the patch is wrong. The kfree is harmless when this is called > from destroy_workqueue() and required when it's called from > pwq_unbound_release_workfn(). Lai Jiangshan already explained this > already. Why are

Re: 回复: [PATCH v5] workqueue: Remove unnecessary kfree() call in rcu_free_wq()

2020-05-28 Thread Lai Jiangshan
On Thu, May 28, 2020 at 8:27 PM Dan Carpenter wrote: > > On Thu, May 28, 2020 at 08:08:06PM +0800, Lai Jiangshan wrote: > > On Thu, May 28, 2020 at 5:57 PM Dan Carpenter > > wrote: > > > > > > Guys, the patch is wrong. The kfree is harmless when this is

Re: [RFC][PATCH 6/6] x86/entry: Remove DBn stacks

2020-05-28 Thread Lai Jiangshan
On Fri, May 29, 2020 at 4:26 AM Peter Zijlstra wrote: > > Both #DB itself, as all other IST users (NMI, #MC) now clear DR7 on > entry. Combined with not allowing breakpoints on entry/noinstr/NOKPROBE > text and no single step (EFLAGS.TF) inside the #DB handler should > guarantee us no nested #DB.

Re: [PATCH 0/6] x86/entry: disallow #DB more

2020-05-28 Thread Lai Jiangshan
On Fri, May 29, 2020 at 4:25 AM Peter Zijlstra wrote: > > These patches disallow #DB during NMI/#MC and allow removing a lot of fugly > code. > Hello Will #DB be allowed in #DF? Thanks Lai > Patch #6 should probably wait until we've got the KGDB situation sorted > because applying that makes

Re: [PATCH 0/6] x86/entry: disallow #DB more

2020-05-28 Thread Lai Jiangshan
On Fri, May 29, 2020 at 6:48 AM Peter Zijlstra wrote: > > On Fri, May 29, 2020 at 06:42:46AM +0800, Lai Jiangshan wrote: > > On Fri, May 29, 2020 at 4:25 AM Peter Zijlstra wrote: > > > > > > These patches disallow #DB during NMI/#MC and allow remov

Re: [PATCH 1/2] workqueue: pin the pool while it is managing

2020-05-28 Thread Lai Jiangshan
On Thu, May 28, 2020 at 10:35 PM Tejun Heo wrote: > > Hello, > > On Thu, May 28, 2020 at 03:06:55AM +, Lai Jiangshan wrote: > > @@ -2129,10 +2128,21 @@ __acquires(&pool->lock) > > static bool manage_workers(struct worker *worker) > > { > >

[PATCH 1/4] workqueue: void unneeded requeuing the pwq in rescuer thread

2020-05-28 Thread Lai Jiangshan
m rescuers, but it doesn't check whether the pwq has work items in the pool (the real reason that this rescuer can help for the pool). The patch adds the check and void unneeded requeuing. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion

[PATCH 0/4] workqueue: simple cleanups

2020-05-28 Thread Lai Jiangshan
Simple cleanups found when I was reviewing the lkml patches. Lai Jiangshan (4): workqueue: void unneeded requeuing the pwq in rescuer thread workqueue: rescuer doesn't check wq->rescuer workqueue: free wq->unbound_attrs earlier workqueue: remove useless unlock() and lock() in

[PATCH 4/4] workqueue: remove useless unlock() and lock() in series

2020-05-28 Thread Lai Jiangshan
This is no point to unlock() and then lock() the same mutex back to back. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index c0cbe0de95d0..415893cfb074 100644 --- a/kernel/workqueue.c +++ b

[PATCH 2/4] workqueue: don't check wq->rescuer in rescuer

2020-05-29 Thread Lai Jiangshan
Now rescuer checks pwq->nr_active before requeues the pwq, it is a more robust check and the rescuer must be still valid. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 23 +-- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/kernel/workqueue.c b/ker

[PATCH 3/4] workqueue: free wq->unbound_attrs earlier

2020-05-29 Thread Lai Jiangshan
wq->unbound_attrs is never accessed in rcu read site, so that it can be freed earlier and relieves memory pressure earlier, although slightly. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/ker

[PATCH V2 0/4] x86/entry: simply stack switching when exception on userspace

2020-05-29 Thread Lai Jiangshan
x...@kernel.org, Cc: "H. Peter Anvin" , Cc: Peter Zijlstra , Cc: Alexandre Chartre , Cc: "Eric W. Biederman" , Cc: Jann Horn , Cc: Dave Hansen Lai Jiangshan (4): x86/entry: avoid calling into sync_regs() when entering from userspace x86/entry: directly switch to kernel stac

[PATCH V2 4/4] x86/entry: don't copy to tmp in fixup_bad_iret

2020-05-29 Thread Lai Jiangshan
It is safe to do memcpy() in fixup_bad_iret() now. Signed-off-by: Lai Jiangshan --- arch/x86/kernel/traps.c | 20 +--- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 9d16672865f8..1a0253a80a4c 100644 --- a

[PATCH V2 1/4] x86/entry: avoid calling into sync_regs() when entering from userspace

2020-05-29 Thread Lai Jiangshan
ry handles it. It switches to the thread stack directly right away when comes from userspace. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 43 +++ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch

[PATCH V2 2/4] x86/entry: directly switch to kernel stack when .Lerror_bad_iret

2020-05-29 Thread Lai Jiangshan
kernel stack with pt_regs copied So we can do the all things together in fixup_bad_iret(). After this patch, fixup_bad_iret() is restored to the behavior before 7f2590a110b8("x86/entry/64: Use a per-CPU trampoline stack for IDT entries") Signed-off-by: Lai Jiangshan --- arch/x86/entr

[PATCH V2 3/4] x86/entry: remove unused sync_regs()

2020-05-29 Thread Lai Jiangshan
No more users. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/traps.h | 1 - arch/x86/kernel/traps.c | 13 - 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 714b1a30e7b0..52cd29bde1d0 100644 --- a/arch/x86

Re: [PATCH 2/4] workqueue: don't check wq->rescuer in rescuer

2020-05-29 Thread Lai Jiangshan
On Fri, May 29, 2020 at 10:14 PM Tejun Heo wrote: > > On Fri, May 29, 2020 at 06:59:00AM +0000, Lai Jiangshan wrote: > > Now rescuer checks pwq->nr_active before requeues the pwq, > > it is a more robust check and the rescuer must be still valid. > > >

[RFC PATCH 3/5] x86/hw_breakpoint: Prevent data breakpoints on per_cpu cpu_tss_rw

2020-05-25 Thread Lai Jiangshan
-shifting, is done). Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 13 + 1 file changed, 13 insertions(+) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel

[RFC PATCH 0/5] x86/hw_breakpoint: protects more cpu entry data

2020-05-25 Thread Lai Jiangshan
ise it may cause dangerous/recursive/unwanted #DB. Lai Jiangshan (5): x86/hw_breakpoint: add within_area() to check data breakpoints x86/hw_breakpoint: Prevent data breakpoints on direct GDT x86/hw_breakpoint: Prevent data breakpoints on per_cpu cpu_tss_rw x86/hw_breakpoint: Prevent data brea

[RFC PATCH 2/5] x86/hw_breakpoint: Prevent data breakpoints on direct GDT

2020-05-25 Thread Lai Jiangshan
...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 30 ++ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index c149c7b29ac3..f859095c1b6c 100644 --- a/arch/x86/kernel

[RFC PATCH 4/5] x86/hw_breakpoint: Prevent data breakpoints on user_pcid_flush_mask

2020-05-25 Thread Lai Jiangshan
rigger #DB (espfix related). Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/

[RFC PATCH 5/5] x86/hw_breakpoint: Prevent data breakpoints on debug_idt_table

2020-05-25 Thread Lai Jiangshan
...@kernel.org Signed-off-by: Lai Jiangshan --- Please drop this patch when Peter's work to remove debug_idt_table is merged. arch/x86/kernel/hw_breakpoint.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index 9579bd6

[RFC PATCH 1/5] x86/hw_breakpoint: add within_area() to check data breakpoints

2020-05-25 Thread Lai Jiangshan
: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index 9ddf441ccaa8..c149c7b29ac3 100644 --- a/arch/x86/kernel

[RFC PATCH V2 5/7] x86/entry: don't shift stack on #DB

2020-05-25 Thread Lai Jiangshan
debug_enter() will disable #DB, there should be no recursive #DB. Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S| 17 - arch/x86/kernel/asm-offsets_64.c | 1 - 2 files

[RFC PATCH V2 0/7] x86/DB: protects more cpu entry data and

2020-05-25 Thread Lai Jiangshan
ct the full cpu_tlbstate structure to be sure. Suggested by Peter. Drop the last patch of the V1 because debug_idt_table is removed in Peter's patchset[3]. remove IST-shifting Lai Jiangshan (7): x86/hw_breakpoint: add within_area() to check data breakpoints x86/hw_break

[RFC PATCH V2 3/7] x86/hw_breakpoint: Prevent data breakpoints on per_cpu cpu_tss_rw

2020-05-25 Thread Lai Jiangshan
-shifting, is done). Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 13 + 1 file changed, 13 insertions(+) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel

[RFC PATCH V2 1/7] x86/hw_breakpoint: add within_area() to check data breakpoints

2020-05-25 Thread Lai Jiangshan
: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index 9ddf441ccaa8..c149c7b29ac3 100644 --- a/arch/x86/kernel

[RFC PATCH V2 4/7] x86/hw_breakpoint: Prevent data breakpoints on user_pcid_flush_mask

2020-05-25 Thread Lai Jiangshan
(espfix_waddr, espfix_stack). Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86

[RFC PATCH V2 2/7] x86/hw_breakpoint: Prevent data breakpoints on direct GDT

2020-05-25 Thread Lai Jiangshan
...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/hw_breakpoint.c | 30 ++ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index c149c7b29ac3..f859095c1b6c 100644 --- a/arch/x86/kernel

[RFC PATCH V2 7/7] x86/entry: remove DB1 stack and DB2 hole from cpu entry area

2020-05-25 Thread Lai Jiangshan
IST-shift code is removed from entry code, #DB will stick to DB stack only. So we remove the DB1 stack and the DB2 hole. Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/cpu_entry_area.h | 12

[RFC PATCH V2 6/7] x86/entry: is_debug_stack() don't check of DB1 stack

2020-05-25 Thread Lai Jiangshan
IST-shift code is removed from entry code, #DB will not at DB1 stack. So we remove the check of DB1 stack in is_debug_stack(). Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Signed-off-by: Lai Jiangshan --- arch/x86/kernel/nmi.c | 7 +-- 1 file

Re: [RFC PATCH 0/5] x86/hw_breakpoint: protects more cpu entry data

2020-05-25 Thread Lai Jiangshan
On Mon, May 25, 2020 at 11:27 PM Peter Zijlstra wrote: > > On Mon, May 25, 2020 at 02:50:57PM +0000, Lai Jiangshan wrote: > > Hello > > > > The patchset is based on (tag: entry-v9-the-rest, tglx-devel/x86/entry). > > And it is complement of 3ea11ac991d > &g

Re: [RFC PATCH V2 4/7] x86/hw_breakpoint: Prevent data breakpoints on user_pcid_flush_mask

2020-05-25 Thread Lai Jiangshan
On Tue, May 26, 2020 at 12:21 PM Andy Lutomirski wrote: > > On Mon, May 25, 2020 at 6:42 PM Lai Jiangshan wrote: > > > > The percpu user_pcid_flush_mask is used for CPU entry > > If a data breakpoint on it, it will cause an unwanted #DB. > > Protect the full cpu

[PATCH 2/2] x86/entry: always flush user CR3 in RESTORE_CR3

2020-05-25 Thread Lai Jiangshan
RESTORE_CR3 is called when CPL==0 or #DF, it is unlikely CPL==0&cr3==userCR3 and #DF itself is unlikely case. There is no much overhead to always flush userCR3. Signed-off-by: Lai Jiangshan --- arch/x86/entry/calling.h | 27 ++- arch/x86/entry/entry_64.S | 6 +++--

[PATCH 1/2] x86/entry: Don't write to CR3 when restoring to kernel CR3

2020-05-25 Thread Lai Jiangshan
Skip resuming KERNEL pages since it is already KERNEL CR3 Signed-off-by: Lai Jiangshan --- arch/x86/entry/calling.h | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h index 1c7f13bb6728..505246185624 100644 --- a

[PATCH 0/2] x86/entry: simplify RESTORE_CR3

2020-05-25 Thread Lai Jiangshan
STORE_CR3") for User CR3. Cc: Andy Lutomirski Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x...@kernel.org Link: https://lore.kernel.org/lkml/20200525145102.122557-1-la...@linux.alibaba.com Lai Jiangshan (2): x86/entry: Don't write to CR3 when restoring to kernel CR3 x86/ent

Re: [RFC PATCH V2 4/7] x86/hw_breakpoint: Prevent data breakpoints on user_pcid_flush_mask

2020-05-25 Thread Lai Jiangshan
On Tue, May 26, 2020 at 12:39 PM Andy Lutomirski wrote: > > On Mon, May 25, 2020 at 9:31 PM Lai Jiangshan > wrote: > > > > On Tue, May 26, 2020 at 12:21 PM Andy Lutomirski wrote: > > > > > > On Mon, May 25, 2020 at 6:42 PM Lai Jiangshan

Re: [PATCH v3] workqueue: Fix double kfree for rescuer

2020-05-26 Thread Lai Jiangshan
On Mon, May 25, 2020 at 5:22 PM wrote: > > From: Zhang Qiang > > The callback function "rcu_free_wq" could be called after memory > was released for "rescuer" already, Thus delete a misplaced call > of the function "kfree". Hello wq->rescuer is guaranteed to be NULL in rcu_free_wq() since def98

Re: [patch V4 part 1 02/36] x86/hw_breakpoint: Prevent data breakpoints on cpu_entry_area

2020-05-09 Thread Lai Jiangshan
(CPU_ENTRY_AREA_ARRAY_SIZE + PAGE_SIZE) ^ sizeof PER_CPU ^ RO_IDT Reviewed-by: Lai Jiangshan > + > static int arch_build_bp_info(struct perf_event *bp, > const struct perf_event_attr *attr, >

Re: [patch V4 part 1 02/36] x86/hw_breakpoint: Prevent data breakpoints on cpu_entry_area

2020-05-09 Thread Lai Jiangshan
On Tue, May 5, 2020 at 10:15 PM Thomas Gleixner wrote: > > From: Andy Lutomirski > > A data breakpoint near the top of an IST stack will cause unresoverable > recursion. A data breakpoint on the GDT, IDT, or TSS is terrifying. > Prevent either of these from happening. > What happen when a data

Re: [patch V4 part 5 13/31] x86/irq: Convey vector as argument and not in ptregs

2020-05-09 Thread Lai Jiangshan
On Tue, May 5, 2020 at 10:23 PM Thomas Gleixner wrote: > +/* > + * ASM code to emit the common vector entry stubs where each stub is > + * packed into 8 bytes. > + * > + * Note, that the 'pushq imm8' is emitted via '.byte 0x6a, vector' because > + * GCC treats the local vector variable as unsigne

Re: [patch V4 part 5 02/31] x86/entry: Provide helpers for execute on irqstack

2020-05-09 Thread Lai Jiangshan
On Tue, May 5, 2020 at 10:19 PM Thomas Gleixner wrote: > > Device interrupt handlers and system vector handlers are executed on the > interrupt stack. The stack switch happens in the low level assembly entry > code. This conflicts with the efforts to consolidate the exit code in C to > ensure corr

Re: [PATCH v4 tip/core/rcu 05/38] rcu-tasks: Move Tasks RCU to its own file

2020-05-10 Thread Lai Jiangshan
On Thu, Apr 16, 2020 at 2:19 AM wrote: > > From: "Paul E. McKenney" > > This code-movement-only commit is in preparation for adding an additional > flavor of Tasks RCU, which relies on workqueues to detect grace periods. > > Signed-off-by: Paul E. McKenney > --- > kernel/rcu/tasks.h | 370 > +

Re: [PATCH RFC tip/core/rcu 09/16] rcu-tasks: Add an RCU-tasks rude variant

2020-05-10 Thread Lai Jiangshan
On Tue, Mar 17, 2020 at 6:03 AM Steven Rostedt wrote: > > On Mon, 16 Mar 2020 17:45:40 -0400 > Joel Fernandes wrote: > > > > > > > Same for the function side (if not even more so). This would require > > > adding > > > a srcu_read_lock() to all functions that can be traced! That would be a > >

Re: [PATCH] workqueue: Fix an use after free in init_rescuer()

2020-05-10 Thread Lai Jiangshan
Reviewed-by: Lai Jiangshan On Fri, May 8, 2020 at 11:07 PM Dan Carpenter wrote: > > We need to preserve error code before freeing "rescuer". > > Fixes: f187b6974f6df ("workqueue: Use IS_ERR and PTR_ERR instead of > PTR_ERR_OR_ZERO.") > Signed-off-by: Dan C

Re: [PATCH RFC tip/core/rcu 09/16] rcu-tasks: Add an RCU-tasks rude variant

2020-05-10 Thread Lai Jiangshan
On Sun, May 10, 2020 at 11:49 PM Paul E. McKenney wrote: > > On Sun, May 10, 2020 at 05:59:27PM +0800, Lai Jiangshan wrote: > > On Tue, Mar 17, 2020 at 6:03 AM Steven Rostedt wrote: > > > > > > On Mon, 16 Mar 2020 17:45:40 -0400 > > > Joel Fernandes wrote:

Re: [patch V4 part 5 13/31] x86/irq: Convey vector as argument and not in ptregs

2020-05-11 Thread Lai Jiangshan
Hello On Mon, May 11, 2020 at 10:35 PM Thomas Gleixner wrote: > > Lai, > > Lai Jiangshan writes: > > On Tue, May 5, 2020 at 10:23 PM Thomas Gleixner wrote: > >> +SYM_CODE_START(irq_entries_start) > >> +vector=FIRST_EXTERNAL_VECTOR

[PATCH] workqueue: ensure all flush_work() completed when being destoryed

2020-06-02 Thread Lai Jiangshan
he WORK_NO_COLOR. The patch simply adds an atomic counter for in-flight flush_work() and a completion for destroy_workqueue() waiting for them. Signed-off-by: Lai Jiangshan --- Changed from V1: Change from flush_no_color based mechanism to atomic+completion based as TJ suggeste

Re: [PATCH] workqueue: ensure all flush_work() completed when being destoryed

2020-06-02 Thread Lai Jiangshan
On Wed, Jun 3, 2020 at 12:13 AM Tejun Heo wrote: > > Hello, Lai. > > On Tue, Jun 02, 2020 at 01:49:14PM +, Lai Jiangshan wrote: > > +static void dec_nr_in_flight_flush_work(struct workqueue_struct *wq) > > +{ > > + if (atomic_dec_and_test(&wq->nr_fl

Re: [PATCH V2 1/2] rbtree_latch: quit searching when reaching to maximum depth

2020-05-22 Thread Lai Jiangshan
On Sat, May 16, 2020 at 12:01 AM Lai Jiangshan wrote: > > lib/rbtree.c has ensured that there is not possible to > inadvertently cause (temporary) loops in the tree structure > as seen in program order of the modifier. But loop is still > possible to be seen in searcher due to C

Re: [patch V6 00/37] x86/entry: Rework leftovers and merge plan

2020-05-22 Thread Lai Jiangshan
On Tue, May 19, 2020 at 5:04 PM Peter Zijlstra wrote: > +#ifdef CONFIG_DEBUG_ENTRY > /* Begin/end of an instrumentation safe region */ > -#define instrumentation_begin() ({ > \ > +#define instrumentation_begin() ({

[PATCH 1/2] rbtree_latch: quit searching when reaching to maximum depth

2020-05-15 Thread Lai Jiangshan
: Rik van Riel Cc: Mathieu Desnoyers Signed-off-by: Lai Jiangshan --- include/linux/rbtree_latch.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/rbtree_latch.h b/include/linux/rbtree_latch.h index 7d012faa509a..b012bd95eabf 100644 --- a/include/linux/rbtr

[PATCH 2/2] rbtree_latch: don't need to check seq when it found a node

2020-05-15 Thread Lai Jiangshan
Signed-off-by: Lai Jiangshan --- include/linux/rbtree_latch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/rbtree_latch.h b/include/linux/rbtree_latch.h index b012bd95eabf..09a3c05d1c5b 100644 --- a/include/linux/rbtree_latch.h +++ b/include/linux/rbtree_latch.h

Re: [PATCH 1/2] rbtree_latch: quit searching when reaching to maximum depth

2020-05-15 Thread Lai Jiangshan
On Fri, May 15, 2020 at 9:04 PM Peter Zijlstra wrote: > > On Fri, May 15, 2020 at 12:47:06PM +0000, Lai Jiangshan wrote: > > lib/rbtree.c has ensured that there is not possible to > > inadvertently cause (temporary) loops in the tree structure > > as seen in program or

[PATCH V2 2/2] rbtree_latch: don't need to check seq when it found a node

2020-05-15 Thread Lai Jiangshan
Cc: Oleg Nesterov Cc: Michel Lespinasse Cc: Andrea Arcangeli Cc: Rik van Riel Cc: Mathieu Desnoyers Acked-by: Peter Zijlstra (Intel) Signed-off-by: Lai Jiangshan --- include/linux/rbtree_latch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/rbtree_latch.h

[PATCH V2 1/2] rbtree_latch: quit searching when reaching to maximum depth

2020-05-15 Thread Lai Jiangshan
parent->rb_right The long loop won't stop until the modifer's CPU flushes its writes. Too avoid it, we should limit the searching depth. There are no more than (1< Cc: Paul E. McKenney Cc: Oleg Nesterov Cc: Michel Lespinasse Cc: Andrea Arcangeli Cc: Rik van Riel Cc: Ma

Re: [PATCH V2 2/2] rbtree_latch: don't need to check seq when it found a node

2020-05-15 Thread Lai Jiangshan
On Sat, May 16, 2020 at 12:28 PM Michel Lespinasse wrote: > > On Fri, May 15, 2020 at 03:59:09PM +0000, Lai Jiangshan wrote: > > latch_tree_find() should be protected by caller via RCU or so. > > When it find a node in an attempt, the node must be a valid one > > in RCU&#x

Re: [PATCH] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-08-27 Thread Lai Jiangshan
Ping @Sean Christopherson On Mon, Aug 24, 2020 at 5:18 PM Lai Jiangshan wrote: > > From: Lai Jiangshan > > 8c8560b83390("KVM: x86/mmu: Use KVM_REQ_TLB_FLUSH_CURRENT for MMU specific > flushes) > changed it without giving any reason in the changelog. > > In theor

Re: [PATCH] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-08-27 Thread Lai Jiangshan
Ping @Sean Christopherson On Mon, Aug 24, 2020 at 5:18 PM Lai Jiangshan wrote: > > From: Lai Jiangshan > > 8c8560b83390("KVM: x86/mmu: Use KVM_REQ_TLB_FLUSH_CURRENT for MMU specific > flushes) > changed it without giving any reason in the changelog. > > In theor

Re: [RFC][PATCH 6/7] freelist: Lock less freelist

2020-08-27 Thread Lai Jiangshan
On Fri, Aug 28, 2020 at 12:23 AM Peter Zijlstra wrote: > +static inline void __freelist_add(struct freelist_node *node, struct > freelist_head *list) > +{ > + /* > +* Since the refcount is zero, and nobody can increase it once it's > +* zero (except us, and we run only one

[PATCH V3] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-09-03 Thread Lai Jiangshan
From: Lai Jiangshan When kvm_mmu_get_page() gets a page with unsynced children, the spt pagetable is unsynchronized with the guest pagetable. But the guest might not issue a "flush" operation on it when the pagetable entry is changed from zero or other cases. The hypervis

[PATCH] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-08-24 Thread Lai Jiangshan
From: Lai Jiangshan 8c8560b83390("KVM: x86/mmu: Use KVM_REQ_TLB_FLUSH_CURRENT for MMU specific flushes) changed it without giving any reason in the changelog. In theory, the syncing is needed, and need to be fixed by reverting this part of change. Signed-off-by: Lai Jiangshan --- arc

[PATCH V2] kvm x86/mmu: use KVM_REQ_MMU_SYNC to sync when needed

2020-09-02 Thread Lai Jiangshan
From: Lai Jiangshan When kvm_mmu_get_page() gets a page with unsynced children, the spt pagetable is unsynchronized with the guest pagetable. But the guest might not issue a "flush" operation on it when the pagetable entry is changed from zero or other cases. The hypervis

[PATCH V3 2/3] x86/entry: directly switch to kernel stack when .Lerror_bad_iret

2020-08-16 Thread Lai Jiangshan
From: Lai Jiangshan Directly copy pt_regs to kernel stack when .Lerror_bad_iret. Directly switch to kernel stack when .Lerror_bad_iret. We can see that entry_64.S do the following things back to back when .Lerror_bad_iret: call fixup_bad_iret(), switch to sp0 stack with pt_regs copied call

[PATCH V3 1/3] x86/entry: avoid calling into sync_regs() when entering from userspace

2020-08-16 Thread Lai Jiangshan
From: Lai Jiangshan 7f2590a110b8("x86/entry/64: Use a per-CPU trampoline stack for IDT entries") made a change that when any exception happens on userspace, the entry code will save the pt_regs on the sp0 stack, and then copy it to the thread stack via sync_regs() and switch to th

[PATCH V3 3/3] x86/entry: remove unused sync_regs()

2020-08-16 Thread Lai Jiangshan
From: Lai Jiangshan No more users. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/traps.h | 1 - arch/x86/kernel/traps.c | 13 - 2 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 714b1a30e7b0..52cd29bde1d0

<    7   8   9   10   11   12   13   >