Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4784461rdh; Wed, 29 Nov 2023 10:30:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyMOO3YZziRs5pc67z59vLssnSSzsuEz488z2jqcSMSu7Y/2REcX6UQaO71fDl+iUhCsjH X-Received: by 2002:a17:902:8485:b0:1cf:fb96:9692 with SMTP id c5-20020a170902848500b001cffb969692mr7089395plo.12.1701282607485; Wed, 29 Nov 2023 10:30:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701282607; cv=none; d=google.com; s=arc-20160816; b=Qgz0WA16x5tYmeaPDY/7/665lkN1V9fY7DozcHqEixauge+e2eFECO+cX3oiVXfBR4 3j9zl4Vb3zvD6aTdej4cjfZ5vQturEU4Y69JKTiWbLwio+3xY04DAHQH8dhuqeJATUy2 bwvVXgVfYCL1fEDoOXjVs5hL5LsqW+Tm7PGh2P6/RSSBbKMdOlg0wBO0uSQRYqJRrJiz 2DmgNxQibUnrdD6lLms4p74AKQdxm5Qqs5KdN3B1eK5p1W2VQ8Tm8jxQmoYDeY1PvTdj kMQrX73daOsiIhAnkQO+n6okbY8T/LeOZsfc9bkHg+9b9eEza3RoQb09MWza40Lqat3m walw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1PZV2QPewxHMt+nvpSEk026io2gN1RNWhVSG3HcbufI=; fh=lbjvIu5YtU1tNM+H+yNSpOa+wxrXuiW1se1TzMxgn70=; b=MwNqXoaPi3dQ1l0PhSi7Z1qrEruAJivwmCJLUepi1pROwW7G0Rmw8XyX3WuIosQeta QXDSlJliIF8CiapUm5lMajXIz9LEvkT/SW0sCU5xSawEnxZ6vW04kDg449sUnTAJOxBy giYwbPGLTnjlRCcy/jSoWzjbaoi6LUJAxRuF4qEd8PHEOTvW+zpvRk4fpxsZA+gaehP0 kLR2nMbCnijRi0yy8J0/FGUTqFXv5nTiP3BJ4IFfp7flbTBtbwzgZqMxDeLM5sd6xMSW X76vqFcKYs22mpouEOI7UwWnao0bP0UI9KbKFUSu/sPYE+luBFyRcFX2xuyRIt/w9HlM 2qcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZaduLkb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z14-20020a170902ccce00b001ce16902d3dsi15793519ple.430.2023.11.29.10.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 10:30:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZaduLkb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1775780C3A02; Wed, 29 Nov 2023 10:30:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231304AbjK2S3r (ORCPT + 99 others); Wed, 29 Nov 2023 13:29:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjK2S3p (ORCPT ); Wed, 29 Nov 2023 13:29:45 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 143D6112 for ; Wed, 29 Nov 2023 10:29:52 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b4734b975so397245e9.2 for ; Wed, 29 Nov 2023 10:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701282590; x=1701887390; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1PZV2QPewxHMt+nvpSEk026io2gN1RNWhVSG3HcbufI=; b=ZaduLkb+rOLxauZf9q5vfmcAfO7S3qqCezc+/2IQ/mnMFIvmVAZnYE1jpZqi1YfSzH B297LO5Q6VrWHBdTJQ5Ij1F1Hz7igqkG1bPzwE9+yzeLa71e8y1NmBYHuwKZm38rZx+Y k81vsoHeGD0ddBOTxC/PizgzKO453qtPHxZIDdD6SYcvbYNMml6likwRgtmvZQ91gqed 56UM2MfE8eTxtIJIhGP3rQ1v85zXRl05/EawC1Pj3GNJUAKwDpLBC9mbV4ZM0KNbnJd2 mBxCvhc6jM62d0cL17W3arjty8Zbh6VRwPvdxEqtp498H76hJc3/JKsTAr2JFFFdC1uP LqaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701282590; x=1701887390; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1PZV2QPewxHMt+nvpSEk026io2gN1RNWhVSG3HcbufI=; b=ke705UDnqmAPJ3RVIhqTtgY1MdNav8bbM2EhiyM42kpFuJvSgJv7gyhFnl6V232UFQ 7fu3otqKZRWwZxRv/cDSwpJf3jg8lYJzITj7KmziuDcc5VjInhAFxjF9m+RVkkUdh2/F vV7J+hjermWLboUSFcV3oeEI/AWdjXB1KtOfaYhsXggTWIj11TnXg5iRw4I1QeSJorpC Doc2eV4/cI4LdPu8aI04t+jfA+UWp1kGvo/8ScwkJFY+DvgoZC30YeyILmEnkFbAtUEZ HQe8wsxQTg4V2YJTcS9kd1QIjMYXno7DZAurg6rlcaPP8oSZn2/tOWbMNRoS810lgeCQ dIag== X-Gm-Message-State: AOJu0Yx39CW7Kzt8q7yyOHxbWhfN7NCHZX/fkdoXdq6jvYgoLOI52fR7 E5g9T4SHIMisZJIodVZo0+ID3MutxtI= X-Received: by 2002:a5d:48c9:0:b0:333:1c69:dd5 with SMTP id p9-20020a5d48c9000000b003331c690dd5mr971955wrs.6.1701282590188; Wed, 29 Nov 2023 10:29:50 -0800 (PST) Received: from andrea ([31.189.63.178]) by smtp.gmail.com with ESMTPSA id 2-20020a5d47a2000000b00332ff137c29sm10453314wrb.79.2023.11.29.10.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 10:29:49 -0800 (PST) Date: Wed, 29 Nov 2023 19:29:43 +0100 From: Andrea Parri To: Mathieu Desnoyers Cc: paulmck@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mmaas@google.com, hboehm@google.com, striker@us.ibm.com, charlie@rivosinc.com, rehn@rivosinc.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] membarrier: riscv: Provide core serializing command Message-ID: References: <20231127103235.28442-1-parri.andrea@gmail.com> <20231127103235.28442-3-parri.andrea@gmail.com> <91ab0210-07f9-42c4-af7f-a98799250cf7@efficios.com> <0a84c0e0-2571-4c7f-82ae-a429f467a16b@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0a84c0e0-2571-4c7f-82ae-a429f467a16b@efficios.com> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 29 Nov 2023 10:30:04 -0800 (PST) > > diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c > > index 217fd4de61342..f63222513076d 100644 > > --- a/arch/riscv/mm/context.c > > +++ b/arch/riscv/mm/context.c > > @@ -323,6 +323,23 @@ void switch_mm(struct mm_struct *prev, struct mm_struct *next, > > if (unlikely(prev == next)) > > return; > > +#if defined(CONFIG_MEMBARRIER) && defined(CONFIG_SMP) > > + /* > > + * The membarrier system call requires a full memory barrier > > + * after storing to rq->curr, before going back to user-space. > > + * > > + * Only need the full barrier when switching between processes: > > + * barrier when switching from kernel to userspace is not > > + * required here, given that it is implied by mmdrop(); barrier > > + * when switching from userspace to kernel is not needed after > > + * store to rq->curr. > > + */ > > + if (unlikely(atomic_read(&next->membarrier_state) & > > + (MEMBARRIER_STATE_PRIVATE_EXPEDITED | > > + MEMBARRIER_STATE_GLOBAL_EXPEDITED)) && prev) > > + smp_mb(); > > +#endif > > The approach looks good. Please implement it within a separate > membarrier_arch_switch_mm() as done on powerpc. Will do. Thanks. As regards the Fixes: tag, I guess it boils down to what we want or we need to take for commit "riscv: Support membarrier private cmd". :-) FWIW, a quick git-log search confirmed that MEMBARRIER has been around for quite some time in the RISC-V world (though I'm not familiar with any of its mainstream uses): commit 1464d00b27b2 says (at least) since 93917ad50972 ("RISC-V: Add support for restartable sequence"). I am currently inclined to pick the latter commit (and check it w/ Palmer), but other suggestions are welcome. Andrea