Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2427857pxa; Fri, 7 Aug 2020 10:52:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH5KJb44obErdsjPcWjT4dxuhmYo7GZm8vOyyNSAW5M1AB3+HAqB69ZFC3TUmm6h9H2JLe X-Received: by 2002:aa7:d654:: with SMTP id v20mr10005639edr.314.1596822725962; Fri, 07 Aug 2020 10:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596822725; cv=none; d=google.com; s=arc-20160816; b=nhdGv1I94yns9wn5xipJfQ4tVxW5ktBVEs0DcBfyGz6j+BO5JX5WOUFlVzf6eUCzX3 Y1x/de1haVjSARqBZDL0H3nTbTZTy4bNY0MZsv6KNAgHuEEQITt+ifissF024ktOVD6B ykhoFCvmODIYRX3Pr1OUbCgD//30YPU6hJ3j6h8UdpGZ88DmRIdDgQX343p9IZI4jPNj DuHCT87beHW4fqftCGYKhC2yUWulhKH8w5FUrJ21MwrkNYzT+aXCbViq3lGg8apGVO0a LsEMYE+aH1y7IeZLG06Pk0ffbCqNlKRtLXEMd8r7TgQl+Y1nrcjvJLl1ogNqN4g6HIbA KpvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nV60Lqd/s6jkR9RwVRlKW7Xy32P0lIA2VNvjGGWHCBg=; b=U1bWxwMAEJEaEPBzF58WieRjObuvrSrZZSTiVzAqTMG2k1vFY4OjIzRQddNU7L8Pxc gA1O81zGmfJ8uhOffIQVARfWo+0xu20+SkXY0lJr2ratsJvU3k8oFqr1wJRTvj//eh4F 6Da+Sh7PZ/jarnNs2K9wY+sRicSDdPmIXBXS/uRZH3ltHfvpdNkS2m3jmTsuQy5gzTmW fdCuYt83KD15CIskB997ruzF8wS9JWF7pLCY3Lu3gFxuBwFqKK4gJHr4MW5zSG0WhHAc 9wHDNHl5/AGeIpFH3euq19aTuBF8OAjgF3vlcNVcKTgQx9lpgE6r10l+AU7fR3b9ByZz Ttew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=IwhGZX7L; 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 y17si5651299eju.316.2020.08.07.10.51.43; Fri, 07 Aug 2020 10:52:05 -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=pass header.i=@posk.io header.s=google header.b=IwhGZX7L; 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 S1728337AbgHGRuz (ORCPT + 99 others); Fri, 7 Aug 2020 13:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728329AbgHGRuy (ORCPT ); Fri, 7 Aug 2020 13:50:54 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B97EBC061756 for ; Fri, 7 Aug 2020 10:50:54 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id a14so1856124edx.7 for ; Fri, 07 Aug 2020 10:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nV60Lqd/s6jkR9RwVRlKW7Xy32P0lIA2VNvjGGWHCBg=; b=IwhGZX7LdBz9Um8mRp/QS0j6Q+GbQl8v73j0V8V2WITC6uJ2ifcAkkiIIfaxA9/9ig T96guVNcY8tg1p4oKZrQ2H3KYKPVrusWb1ZomNrEMd/NlUlmHSE159rPjcfA4sE2nZSr T5WwdJSNJSbR4VYAsuED8Dkk1kfgLjFwLOLGFp680oA4u+TxQvdy4rq5qu/ybULVFECY IavpPCYKYmZ13sepQ/4Ka/LOrhSAu+6DtzXg5Hb3KwPWSeY3wH6n1v7KMEHFifcTgCfX +AmcTfZFtuy+HMD1eoTuWivbfPh7+xH0mZyMQjwBYYnpZnsbBM6Z5dCuISeyFXGT6YwY S8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nV60Lqd/s6jkR9RwVRlKW7Xy32P0lIA2VNvjGGWHCBg=; b=T98Alh9wGig5UQtAb90ySsIsKmCHqwOjFzcoWe3saNbNnWFGHHvlE5qy/bq6aCrvuq OJuT7XmNMykYOPcogbjjYXUsM3T4wL4vdxpKTrQH7Gna1gKTBXj61syyL+tQG0LjnssV 6Fya6D5bCM/ERLe/9GZFIKYOZcx2ejUSSyOVsQg9e07rET/ZB2Td221XbpEVesWdQ26I f9LjdBuNFxDj4CwpBrswDG+rOUCj9mluIb6+ItSk+Y4/5Y/XmsBUK+2TWQeatP2M1bAs gcXDdN57Q2mb1AErijnlORC18SSfFUpIBGHql2dha8jrir3Kc1Uu14NLnkfolDidrHU7 a4JQ== X-Gm-Message-State: AOAM532xofh6oVAsPfrkUs29IENmKEZkclUbp+KbBfPwo+vUNTXyi5rB 3HryHJik/gFURjvfX2zJns+UOi9AUh2ZmoPpWER2hg== X-Received: by 2002:a05:6402:16d0:: with SMTP id r16mr10237222edx.124.1596822653289; Fri, 07 Aug 2020 10:50:53 -0700 (PDT) MIME-Version: 1.0 References: <20200806170544.382140-1-posk@google.com> <20200807133755.GJ2674@hirez.programming.kicks-ass.net> In-Reply-To: <20200807133755.GJ2674@hirez.programming.kicks-ass.net> From: Peter Oskolkov Date: Fri, 7 Aug 2020 10:50:42 -0700 Message-ID: Subject: Re: [PATCH 1/2 v2] rseq/membarrier: add MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU To: Peter Zijlstra Cc: Peter Oskolkov , Mathieu Desnoyers , "Paul E . McKenney" , Boqun Feng , Linux Kernel Mailing List , Paul Turner , Chris Kennelly Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 7, 2020 at 6:38 AM wrote: > [...] > 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. Thanks for the suggestion - I'll prepare a v3 based on your and Mathieu's feedback. > > 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: