Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2237547pxa; Fri, 7 Aug 2020 06:39:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxarW8pfbxutDbrMg4rBOl2hpDuw6wSeCNsnhrx6GpFqfY1GkAO7oraL+55Z26uVvCCLA6x X-Received: by 2002:a17:906:1396:: with SMTP id f22mr2631747ejc.227.1596807571415; Fri, 07 Aug 2020 06:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596807571; cv=none; d=google.com; s=arc-20160816; b=ZvBE/FYiSkJA6MLsvjuv8ULw/9xI3C1IfF/83cEsIdrRGJaZpLfa04N5XH079K2Mzf CHVaIBsEfuIyiuKFBDwSW1lUBOgTiinnLF9uujM+iFDFyFpXPsWi7Ydsxyj+WzENPTm0 7ObZ3jbZUSZNqOsAacO3dct5N+lAUD1xZcNlYJnAJsxH7tzl1Fo4phoRsfX+JQJ28YlZ vkBUeCKgWpk1VPgFFd5Wq6nn112eX1aFsmc+oCB+Dar9+3tx/u7MVtO1GRlVvgeEiOf5 eq1cVF+70YVQ5HVoYvfkaYJ68msoy4Jb/5srKJU4LFZuawhqnvnnVU67SWYqygBaFK6C TeNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=BNHhg74FH0aIGNuZudrsPwpAtKO2+uyNLCH15s0iV80=; b=xKVt3CG5Kq013w5b2UUe6c+Yat6poq9UrTGMxH7VnWE6mEE0kPQQ0tQXnEiwpllO6y qJiPgsK6G+r1POhTWbyhLlBFpctxuJw3TwW+UzYhXvAXH0g/74mIlBD4agdbwa+mLAyq CMtu1t1MhmB5NzvDQGnjcbNjjDv1POkCO2rnFL0fsIq66/Ewsjd13qVrJ5HBzca6QxiW 10Hx5T2oqIIfloqpwzbEWUhLgUnrvnhCrqY+Z8c1wpai+V3OXH+MKxxKby5Lw0JqsG7N vybCHtDfiHAA/fkNWumMj7BlU2HAfLTi6FatTdEY/qVSkqvS6QopNNJc+gqUvXfvpmPV Ow2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=dAvmNoqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si4997096ejz.724.2020.08.07.06.39.08; Fri, 07 Aug 2020 06:39:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=dAvmNoqW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726155AbgHGNiI (ORCPT + 99 others); Fri, 7 Aug 2020 09:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbgHGNiH (ORCPT ); Fri, 7 Aug 2020 09:38:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAF05C061574 for ; Fri, 7 Aug 2020 06:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BNHhg74FH0aIGNuZudrsPwpAtKO2+uyNLCH15s0iV80=; b=dAvmNoqW0EYerv/ttknI0evnMM 1yVh8ZDVtV7XlmwNUf3V3RXlmmMgRbeqX6jarc4U05eNV2oxNFnmuBgUwVQz17GWiKAyVpQzinEuT zxDJYq1RYy1ZhxHCSZoQpzDH6+kf7dQ6C7KE3fu5emoyyIkHSTcAeXORuoe8ebo3G+ll2+zEHbUwa S9FbmOi66+RnJlnyZ1SSK5iSUOoxlUEuVeHzZ4fMxlYP8TF894gpw+A21fjuE/iyPn+CpUZ6EcdOj B/AXQzzzJt91zdHWDrySKHcYjUin0EgLRGl5m2Jf6klb1ulY+mzO4Mo4MTDkBKHpyJJm990NLt1qL Mm5dOCuQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1k42ZL-0003m1-0x; Fri, 07 Aug 2020 13:37:59 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4BE1B3010D2; Fri, 7 Aug 2020 15:37:55 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A9B9621451922; Fri, 7 Aug 2020 15:37:55 +0200 (CEST) Date: Fri, 7 Aug 2020 15:37:55 +0200 From: peterz@infradead.org To: Peter Oskolkov Cc: Mathieu Desnoyers , "Paul E . McKenney" , Boqun Feng , linux-kernel@vger.kernel.org, Paul Turner , Chris Kennelly , Peter Oskolkov Subject: Re: [PATCH 1/2 v2] rseq/membarrier: add MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU Message-ID: <20200807133755.GJ2674@hirez.programming.kicks-ass.net> References: <20200806170544.382140-1-posk@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200806170544.382140-1-posk@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 06, 2020 at 10:05:43AM -0700, Peter Oskolkov wrote: > +#ifdef CONFIG_RSEQ > +static void membarrier_rseq_ipi(void *arg) > +{ > + if (current->mm != arg) /* Not our process. */ > + return; > + if (!current->rseq) /* RSEQ not set up for the current task/thread. */ > + return; > + > + rseq_preempt(current); > +} > +#endif > + > +static int membarrier_private_restart_rseq_on_cpu(int cpu_id) > +{ > +#ifdef CONFIG_RSEQ > + /* syscalls are not allowed inside rseq critical sections. */ > + if (cpu_id == raw_smp_processor_id()) > + return 0; > + > + return smp_call_function_single(cpu_id, membarrier_rseq_ipi, > + current->mm, true); > +#else > + return 0; > +#endif > +} I'm thinking even this is a problem, we can end up sending IPIs to CPUs outside out partition (they might be NOHZ_FULL) and that's a no-no too. Something like so perhaps... that really limits it to CPUs that match our mm. diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 6be66f52a2ad..bee5e98e6774 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -356,6 +356,7 @@ enum { enum { MEMBARRIER_FLAG_SYNC_CORE = (1U << 0), + MEMBARRIER_FLAG_RSEQ = (1U << 1), }; #ifdef CONFIG_ARCH_HAS_MEMBARRIER_CALLBACKS diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c index 168479a7d61b..4d9b22c2f5e2 100644 --- a/kernel/sched/membarrier.c +++ b/kernel/sched/membarrier.c @@ -27,6 +27,11 @@ static void ipi_mb(void *info) { + int *flags = info; + + if (flags && (*flags & MEMBARRIER_FLAG_RSEQ)) + rseq_preempt(current); + smp_mb(); /* IPIs should be serializing but paranoid. */ } @@ -129,11 +134,11 @@ static int membarrier_global_expedited(void) return 0; } -static int membarrier_private_expedited(int flags) +static int membarrier_private_expedited(int flags, int cpu_id) { - int cpu; - cpumask_var_t tmpmask; struct mm_struct *mm = current->mm; + cpumask_var_t tmpmask; + int cpu; if (flags & MEMBARRIER_FLAG_SYNC_CORE) { if (!IS_ENABLED(CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE)) @@ -174,6 +179,10 @@ static int membarrier_private_expedited(int flags) */ if (cpu == raw_smp_processor_id()) continue; + + if (cpu_id >= 0 && cpu != cpu_id) + continue; + p = rcu_dereference(cpu_rq(cpu)->curr); if (p && p->mm == mm) __cpumask_set_cpu(cpu, tmpmask); @@ -181,7 +190,7 @@ static int membarrier_private_expedited(int flags) rcu_read_unlock(); preempt_disable(); - smp_call_function_many(tmpmask, ipi_mb, NULL, 1); + smp_call_function_many(tmpmask, ipi_mb, &flags, 1); preempt_enable(); free_cpumask_var(tmpmask); @@ -362,11 +371,13 @@ SYSCALL_DEFINE2(membarrier, int, cmd, int, flags) case MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED: return membarrier_register_global_expedited(); case MEMBARRIER_CMD_PRIVATE_EXPEDITED: - return membarrier_private_expedited(0); + return membarrier_private_expedited(0, -1); case MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED: return membarrier_register_private_expedited(0); case MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE: - return membarrier_private_expedited(MEMBARRIER_FLAG_SYNC_CORE); + return membarrier_private_expedited(MEMBARRIER_FLAG_SYNC_CORE, -1); + case MEMBERRIER_CMD_PRIVATE_EXPEDITED_RSEQ: + return membarrier_private_expedited(MEMBARRIER_FLAG_RSEQ, flags); case MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE: return membarrier_register_private_expedited(MEMBARRIER_FLAG_SYNC_CORE); default: