Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756250AbbEUScs (ORCPT ); Thu, 21 May 2015 14:32:48 -0400 Received: from casper.infradead.org ([85.118.1.10]:43448 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755655AbbEUScq (ORCPT ); Thu, 21 May 2015 14:32:46 -0400 Date: Thu, 21 May 2015 20:32:40 +0200 From: Peter Zijlstra To: Mathieu Desnoyers Cc: Paul Turner , Andrew Hunter , Ben Maurer , linux-kernel@vger.kernel.org, Ingo Molnar , Steven Rostedt , "Paul E. McKenney" , Josh Triplett , Lai Jiangshan , Linus Torvalds , Andrew Morton Subject: Re: [RFC PATCH] percpu system call: fast userspace percpu critical sections Message-ID: <20150521183240.GW3644@twins.programming.kicks-ass.net> References: <1432219487-13364-1-git-send-email-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432219487-13364-1-git-send-email-mathieu.desnoyers@efficios.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2282 Lines: 81 On Thu, May 21, 2015 at 10:44:47AM -0400, Mathieu Desnoyers wrote: > +struct thread_percpu_user { > + int32_t nesting; > + int32_t signal_sent; > + int32_t signo; > + int32_t current_cpu; > +}; I would require this thing be naturally aligned, such that it does not cross cacheline boundaries. > + > +static void percpu_user_sched_in(struct preempt_notifier *notifier, int cpu) > +{ > + struct thread_percpu_user __user *tpu_user; > + struct thread_percpu_user tpu; > + struct task_struct *t = current; > + > + tpu_user = t->percpu_user; > + if (tpu_user == NULL) > + return; > + if (unlikely(t->flags & PF_EXITING)) > + return; > + /* > + * access_ok() of tpu_user has already been checked by sys_percpu(). > + */ > + if (__put_user(smp_processor_id(), &tpu_user->current_cpu)) { > + WARN_ON_ONCE(1); > + return; > + } This seems a waste; you already read the number unconditionally, might as well double check and avoid the store. > + if (__copy_from_user(&tpu, tpu_user, sizeof(tpu))) { > + WARN_ON_ONCE(1); > + return; > + } if (tpu.current_cpu != smp_processor_id()) __put_user(); > + if (!tpu.nesting || tpu.signal_sent) > + return; > + if (do_send_sig_info(tpu.signo, SEND_SIG_PRIV, t, 0)) { > + WARN_ON_ONCE(1); > + return; > + } > + tpu.signal_sent = 1; > + if (__copy_to_user(tpu_user, &tpu, sizeof(tpu))) { > + WARN_ON_ONCE(1); > + return; > + } > +} Please do not use preempt notifiers for this. Second, this all is done with preemption disabled, this means that all that user access can fail. You print useless WARNs and misbehave. If you detect a desire to fault, you could delay until return to userspace and try again there. But it all adds complexity. The big advantage pjt's scheme had is that we have the instruction pointer, we do not need to go read userspace memory that might not be there. And it being limited to a single range, while inconvenient, simplifies the entire kernel side to: if ((unsigned long)(ip - offset) < size) do_magic(); Which is still simpler than the above. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/