Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1219497rdb; Wed, 24 Jan 2024 08:14:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOS46ZWlo1HlzzeGA8ljvAJgedYY9+4EvXNmbqjkIdDtylK5QKxbfKu5Sjm6xnVkGukGEs X-Received: by 2002:a05:6602:182:b0:7bc:3dca:c57d with SMTP id m2-20020a056602018200b007bc3dcac57dmr2065854ioo.43.1706112886898; Wed, 24 Jan 2024 08:14:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706112886; cv=pass; d=google.com; s=arc-20160816; b=RvSgX7XEohoXPCuk4IfgTN1cw6uozB8ha3OYWVDcCn6t9BFwYyZt+lJHHvonYzgWh8 3DjG7GJrb+29IZNXC82WA79Cp/wETwQ1GfbmMeNMqNI4rSTnE3DHMunOKSuaBMeJPAxM 6wxr/mDojukjjPZpjP/6+FG/GwAkNjYHywfcOz62xkIbcs4ijEdP5DwSe3CLt4taGZ3p zQqjK1SSHbrAn0zfC7w2nuxN5qB0fDHC2/9EMU/2i72ofsMTiIvjS/Adbz+/1/tmU9DF KY/Ev5MVrJWlHwQQjHD0wdg325zt7q5BZxig4+kLx9Sa3anMI1F9QNqejEHOP9FISz5h 5EKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=cGQlYAlZEN8fvsYaB19/pysmJM/K1UHlAY9PpGkTl5g=; fh=LD+wB+vdc1Xkqt2ewkuqG3bsdcpXP7tj9SZ0Am/y5Os=; b=xicFPhv0yGSZqv0nkPSoCwFjwcza6cq8R0gFf4kzIXlPUfOb3lfQU4W1NJZEmfXewN YHOmf4ypSPc0m/iZLM4wurSERj5an8OQ5KARcD+7+gv6Qxf/lG4esKJy3Bqbu8UkYU6r IjK1oZGhdO0Pnd4kcTf/naT9EC1ArtYGTFodSNWoiZx0Ojd3Hjms0P2J+3cS51lcIRr9 lugMZZZd41EPPWdy7xmb2NLvs/Su5EMI6dutIRVy2mAyCov0qFoJjZ7lzMo6kV4cMo+A q4xQshyStFCnbNM5+vRmkfc6x4jPr6Z9Z0gkk3VRa9tave8/j4wUW/vbGWVh1g7rjo4j D7uQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=xY69iOjQ; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-37312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h14-20020a63120e000000b005cdba90861fsi11797746pgl.137.2024.01.24.08.14.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 08:14:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=xY69iOjQ; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-37312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7A5B32886A9 for ; Wed, 24 Jan 2024 16:14:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AB737CF3A; Wed, 24 Jan 2024 16:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="xY69iOjQ" Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 757C57E594; Wed, 24 Jan 2024 16:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112807; cv=none; b=o7/fe5gzWsUEq3MXQBAPIV+D/g49LB3g9sInpzMtXXOQPt6kZ2QPW0Nh0+/L36zivlY5nW1qe9UdQHmF5FO/pu5wmcjeuT7Zub3m+hVvSyY609x4rt2oRQl7VHP9eNoTgenVCKxGnph971q2lNPA1MsJlir5BHEX3UyrFxpDPwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112807; c=relaxed/simple; bh=CmL8wTtpgjbpskLlRLiCz6pU6cSsxxWnkQiC+ZyxVGk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Io2nLHXd5bwrvfbkOZeBVGHYypYDYsfy5z3O8p4BcHt/KH/MKBirboVvfhsfkZQMx8Ty0J3HLtUgPHl9uJiJ7h302u2Ag/yKmgg40CQFExtCwr2MUX5LcndlXqrRIqgFWnTvEzqwrJgbe3l7TOhi/gJEe+FUo/OLEsQuqEKg0no= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=xY69iOjQ; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1706112796; bh=CmL8wTtpgjbpskLlRLiCz6pU6cSsxxWnkQiC+ZyxVGk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=xY69iOjQrXnkCBpDwyzUKhwkCE8wToyhDK/3oQtq3mno7+NJ9lS5u7bHrcvBOYXUp W37jFqUB1RFPHkI9qvdTseGgeOoQqsvKNCMi18/sc+3xo3Be4DAeBkCJrD/do3lp5e lkDinivWyTqeIDE+JM7Vesp97qHUE3ZQvzUtkvR5ooQk7auyVcTy2z9jKWbOU+jAP5 XCxnNL+qMU8ODg7V4xk09T3oQ1qxWTaQDWF8BKDZPQDKUP4lf0KzeC0khQ+gJEQmcg mi6Sr6NaEslo+urKskjKEnh+1w0NaA01qiopSpNdRP+Hpg+lz3rpQTaejIHiUoBlZE V6cSnQYLRYQgg== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4TKpsS3JvnzTt5; Wed, 24 Jan 2024 11:13:16 -0500 (EST) Message-ID: Date: Wed, 24 Jan 2024 11:13:16 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/4] membarrier: Create Documentation/scheduler/membarrier.rst Content-Language: en-US To: Andrea Parri , paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, paulmck@kernel.org, corbet@lwn.net Cc: mmaas@google.com, hboehm@google.com, striker@us.ibm.com, charlie@rivosinc.com, rehn@rivosinc.com, linux-riscv@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240110145533.60234-1-parri.andrea@gmail.com> <20240110145533.60234-3-parri.andrea@gmail.com> From: Mathieu Desnoyers In-Reply-To: <20240110145533.60234-3-parri.andrea@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-01-10 09:55, Andrea Parri wrote: > To gather the architecture requirements of the "private/global > expedited" membarrier commands. The file will be expanded to > integrate further information about the membarrier syscall (as > needed/desired in the future). While at it, amend some related > inline comments in the membarrier codebase. Reviewed-by: Mathieu Desnoyers > > Suggested-by: Mathieu Desnoyers > Signed-off-by: Andrea Parri > --- > Documentation/scheduler/index.rst | 1 + > Documentation/scheduler/membarrier.rst | 37 ++++++++++++++++++++++++++ > MAINTAINERS | 1 + > kernel/sched/core.c | 7 ++++- > kernel/sched/membarrier.c | 8 +++--- > 5 files changed, 49 insertions(+), 5 deletions(-) > create mode 100644 Documentation/scheduler/membarrier.rst > > diff --git a/Documentation/scheduler/index.rst b/Documentation/scheduler/index.rst > index 3170747226f6d..43bd8a145b7a9 100644 > --- a/Documentation/scheduler/index.rst > +++ b/Documentation/scheduler/index.rst > @@ -7,6 +7,7 @@ Scheduler > > > completion > + membarrier > sched-arch > sched-bwc > sched-deadline > diff --git a/Documentation/scheduler/membarrier.rst b/Documentation/scheduler/membarrier.rst > new file mode 100644 > index 0000000000000..ab7ee3824b407 > --- /dev/null > +++ b/Documentation/scheduler/membarrier.rst > @@ -0,0 +1,37 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +======================== > +membarrier() System Call > +======================== > + > +MEMBARRIER_CMD_{PRIVATE,GLOBAL}_EXPEDITED - Architecture requirements > +===================================================================== > + > +Memory barriers before updating rq->curr > +---------------------------------------- > + > +The command requires each architecture to have a full memory barrier after > +coming from user-space, before updating rq->curr. This barrier is implied > +by the sequence rq_lock(); smp_mb__after_spinlock() in __schedule(). The > +barrier matches a full barrier in the proximity of the membarrier system > +call exit, cf. membarrier_{private,global}_expedited(). > + > +Memory barriers after updating rq->curr > +--------------------------------------- > + > +The command requires each architecture to have a full memory barrier after > +updating rq->curr, before returning to user-space. The schemes providing > +this barrier on the various architectures are as follows. > + > + - alpha, arc, arm, hexagon, mips rely on the full barrier implied by > + spin_unlock() in finish_lock_switch(). > + > + - arm64 relies on the full barrier implied by switch_to(). > + > + - powerpc, riscv, s390, sparc, x86 rely on the full barrier implied by > + switch_mm(), if mm is not NULL; they rely on the full barrier implied > + by mmdrop(), otherwise. On powerpc and riscv, switch_mm() relies on > + membarrier_arch_switch_mm(). > + > +The barrier matches a full barrier in the proximity of the membarrier system > +call entry, cf. membarrier_{private,global}_expedited(). > diff --git a/MAINTAINERS b/MAINTAINERS > index 0f8cec504b2ba..6bce0aeecb4f2 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -13815,6 +13815,7 @@ M: Mathieu Desnoyers > M: "Paul E. McKenney" > L: linux-kernel@vger.kernel.org > S: Supported > +F: Documentation/scheduler/membarrier.rst > F: arch/*/include/asm/membarrier.h > F: include/uapi/linux/membarrier.h > F: kernel/sched/membarrier.c > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 711dc753f7216..b51bc86f8340c 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6599,7 +6599,9 @@ static void __sched notrace __schedule(unsigned int sched_mode) > * if (signal_pending_state()) if (p->state & @state) > * > * Also, the membarrier system call requires a full memory barrier > - * after coming from user-space, before storing to rq->curr. > + * after coming from user-space, before storing to rq->curr; this > + * barrier matches a full barrier in the proximity of the membarrier > + * system call exit. > */ > rq_lock(rq, &rf); > smp_mb__after_spinlock(); > @@ -6677,6 +6679,9 @@ static void __sched notrace __schedule(unsigned int sched_mode) > * architectures where spin_unlock is a full barrier, > * - switch_to() for arm64 (weakly-ordered, spin_unlock > * is a RELEASE barrier), > + * > + * The barrier matches a full barrier in the proximity of > + * the membarrier system call entry. > */ > ++*switch_count; > > diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c > index 2ad881d07752c..f3d91628d6b8a 100644 > --- a/kernel/sched/membarrier.c > +++ b/kernel/sched/membarrier.c > @@ -251,7 +251,7 @@ static int membarrier_global_expedited(void) > return 0; > > /* > - * Matches memory barriers around rq->curr modification in > + * Matches memory barriers after rq->curr modification in > * scheduler. > */ > smp_mb(); /* system call entry is not a mb. */ > @@ -300,7 +300,7 @@ static int membarrier_global_expedited(void) > > /* > * Memory barrier on the caller thread _after_ we finished > - * waiting for the last IPI. Matches memory barriers around > + * waiting for the last IPI. Matches memory barriers before > * rq->curr modification in scheduler. > */ > smp_mb(); /* exit from system call is not a mb */ > @@ -339,7 +339,7 @@ static int membarrier_private_expedited(int flags, int cpu_id) > return 0; > > /* > - * Matches memory barriers around rq->curr modification in > + * Matches memory barriers after rq->curr modification in > * scheduler. > */ > smp_mb(); /* system call entry is not a mb. */ > @@ -415,7 +415,7 @@ static int membarrier_private_expedited(int flags, int cpu_id) > > /* > * Memory barrier on the caller thread _after_ we finished > - * waiting for the last IPI. Matches memory barriers around > + * waiting for the last IPI. Matches memory barriers before > * rq->curr modification in scheduler. > */ > smp_mb(); /* exit from system call is not a mb */ -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com