Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp58155rdh; Wed, 22 Nov 2023 18:13:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGskLtFyCQzU8pI4XwjsCwVQUKAg9R3kDqY39G7MCR/oqXEHPTle4MspoLE3Ub/MP7GMBIf X-Received: by 2002:a05:6808:1a03:b0:3b5:c587:d9ed with SMTP id bk3-20020a0568081a0300b003b5c587d9edmr5705029oib.26.1700705624995; Wed, 22 Nov 2023 18:13:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700705624; cv=none; d=google.com; s=arc-20160816; b=FzAE8OApaCpS6rIxRx4l134Pj5+n0Hln4NUmHH5tV/gSeCYgoTBhSt8CxRx2U+XQYh 0KfY6jAJaG49EU60AyCEupnI1R5t6DRoJpEn8a5mHSCeg+7UpOPhPNZ8t+9nIyaZQwrl YTfBtoJ3jInxarH39NCINbTRMb0zdbzJuEGbmgBDRvbFIHWrnDpqyF/Lv8FpYnvw/dR+ 8Ay3KKGLGWq9wmzipHTU9gTJQEtXKv/8ejGdC0P+EsCEqcrkinWC//OJmj5XZXKCaI/8 e+cGt8L5ol3otLb2RB9pT1dfQdc1Al+LhVyWpKrharbsbUxfdGdA/wIjwoJgDSqXMavY WK5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=sZ3euqI0ej6uNdRGolfcFbx3Ri9SGnf8O0EV3LkiNII=; fh=fyRPcFrG3tT66QZcDodxCcEOrTi5uc7UkwGdqMSvMfM=; b=EmhiKIgW5Tvj0/kOFPNX52NyT4ZNT6daEfHHNTyHtzE+6SL3dEniiF2kmm2WqtCuQM I7rDEiJtVeV4V6hTMStd67L6/pI2aUnYc6WOEgssdi9450miW0WyKhHwY3b/IoFg/EsH 2OfKWn9FkQHGRV3/Ak1/V0mUubs2B/duiWYo2/oVqrl9JC8AAPXNjwd4vkxpJYXRapI8 qIklzxGJIxjtaxK6d05aT7qhzUPOSdaidVsT5kHz8y3Mlkrfgt5x40fdjK5Pv2vj97rr KFgKv0lF8H6VyeRqtdgtPSWjlHLhMJ9Bc3ip/e+5SUgqUYLv4FMUKMJbPW2CFc8dKL+x BH3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=JUxXpa2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id u21-20020a632355000000b005bd66bfc235si345811pgm.413.2023.11.22.18.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 18:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=JUxXpa2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CB36F807C5CA; Wed, 22 Nov 2023 18:13:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbjKWCNU (ORCPT + 99 others); Wed, 22 Nov 2023 21:13:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232839AbjKWCNP (ORCPT ); Wed, 22 Nov 2023 21:13:15 -0500 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3E5D43 for ; Wed, 22 Nov 2023 18:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1700705597; bh=/iv6gHY+vJGMSPrVKbAaM5xdtaRFsSNH4rODAL5Qm/w=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=JUxXpa2kpeCMpLtm+AkR3IqmWuVsA+w1oQ5TgjRdq6z/uW/Tu+n+n7z5CISQm3T+l y8i7ltnVNv7hzsy+n+ql7+sJyRDXXLfM2Knpq33vQEcej3wRJr+ERuAOnrZoMfLBGG ZSjrxQrgYSOGvQgwUpjULsga43Sev4hTZ57xMDlvD7fa1YE0/s8hFYgPxMTnAoqb+x lizz/2lYu5g/E8ahvsIYmAgGQo6OkP21vMbcPvEvbmQPcE6ESNDm2VAKKOHswDjCmr 2QzNCBlAyUZl/9cAUmLJT+Dig7Vs3TeJx0At3oHMphI2pf9IlsRIIMWuIX05NmnMpN aIHHdxK0npN0A== Received: from [IPV6:2606:6d00:100:4000:cacb:9855:de1f:ded2] (unknown [IPv6:2606:6d00:100:4000:cacb:9855:de1f:ded2]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4SbM8s2tjLz1dHp; Wed, 22 Nov 2023 21:13:17 -0500 (EST) Message-ID: <790b8b57-43ac-447a-96b9-150e5b3a4237@efficios.com> Date: Wed, 22 Nov 2023 21:13:43 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] membarrier: riscv: Provide core serializing command Content-Language: en-US To: Charlie Jenkins , Andrea Parri Cc: Palmer Dabbelt , rehn@rivosinc.com, paulmck@kernel.org, Paul Walmsley , aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, mmaas@google.com, hboehm@google.com, striker@us.ibm.com References: <65e98129-0617-49ca-9802-8e3a46d58d29@efficios.com> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 22 Nov 2023 18:13:41 -0800 (PST) On 2023-11-22 20:07, Charlie Jenkins wrote: > On Thu, Nov 09, 2023 at 08:24:58PM +0100, Andrea Parri wrote: >> Mathieu, all, >> >> Sorry for the delay, >> >>> AFAIR this patch implements sync_core_before_usermode which gets used by >>> membarrier_mm_sync_core_before_usermode() to handle the uthread->kthread->uthread >>> case. It relies on switch_mm issuing a core serializing instruction as well. >>> >>> Looking at RISC-V switch_mm(), I see that switch_mm() calls: >>> >>> flush_icache_deferred(next, cpu); >>> >>> which only issues a fence.i if a deferred icache flush was required. We're >>> missing the part that sets the icache_stale_mask cpumask bits when a >>> MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE is invoked. >> >> [...] >> >>> The only part where I think you may want to keep some level of deferred >>> icache flushing as you do now is as follows: >>> >>> - when membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE is invoked, >>> call a new architecture hook which sets cpumask bits in the mm context >>> that tells the next switch_mm on each cpu to issue fence.i for that mm. >>> - keep something like flush_icache_deferred as you have now. >>> >>> Otherwise, I fear the overhead of a very expensive fence.i would be too >>> much when processes registering with MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE >>> and start doing fence.i on each and every switch_mm(). >>> >>> So you'd basically rely on membarrier to only issue IPIs to the CPUs which are >>> currently running threads belonging to the mm, and handle the switch_mm with >>> the sync_core_before_usermode() for uthread->kthread->uthread case, and implement >>> a deferred icache flush for the typical switch_mm() case. >> >> I've (tried to) put this together and obtained the two patches reported below. >> Please let me know if this aligns with your intentions and/or there's interest >> in a proper submission. > > This looks good to me, can you send out a non-RFC? I just sent out > patches to support userspace fence.i: > https://lore.kernel.org/linux-riscv/20231122-fencei-v1-0-bec0811cb212@rivosinc.com/T/#t. > > - Charlie > Hi Andrea, Yes, please send those as non-RFC patches. They align well with my intentions. Thanks! Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com