Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp253322pxj; Thu, 17 Jun 2021 01:48:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSWa9tUzXXzItHTjwtUkiykmU2aF0AtobLd3Cfw1lLjQ+yXp6j/0A7ykxgYxyNv9QD19Vt X-Received: by 2002:aa7:db49:: with SMTP id n9mr4940740edt.361.1623919738794; Thu, 17 Jun 2021 01:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623919738; cv=none; d=google.com; s=arc-20160816; b=BxpxsT/JaciN+b1V5FUwYCPyIfYA/2cIC/O225Ta+p1cAB/TXtQ5egYuST5ZNGqkqW GamTO0nS+YEcKS6Zq1UgXCi92nwuweHwGGLbgtY0/H8WM9lL/FHlGaMFKy1OnrWEhtd9 4x44c1Zv4MZUsyZK+Tir+PLXYgpFMRbLqHS7gKwYiuvtKCSDIAe7cdJwzIcVPkkslFlE 490mon3MuWsqwFC+rZY8D8z6BK7ZH9mLi0uMJjIvVa03BQWnMpJNBxaT+H2tqO39pXCs nypbsVfs8WpCF/K/kssspOqcQ+H1C7Z/iepDhHu18abPeCrILLZ/JtsnTgKS9XPzawT/ ci1w== 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=KZl/Wka2k1ddujQH+TFRsFdpimwLd/Gy1bZGIFO9vgw=; b=AH+umDRhE4NSjPi6Q4GVthYOlL+bv6Ca7h26kuKTq3Tq4fXfUQB4UD1XoG/xogs3Vp r3WXJ2x3ngrStohGegIJm6simvvAwpEiie41aKTXzL8YMDRuBk3HtO13Kgm9EMq62Kii B2Ez03//QTPqGl7Uf47KSne3/K79DtEjKydFf98ehgZO2bU+iRNzTRqPMs9vErkbWLB6 sHtSdDOi+kcsQHtAiS8PVWvE+zCbirtnkPTPRD6RJqF8Zv5FkW25qmMXcojxNvB+FVGl BRAvbDwhi1sKvoUHrGoFKQCntM35nTEp4YYAS2Bbnd+ad9/5xXK3n6uX3rKgcDUSIl1Z 8KaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=M9U1xfKe; 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 b10si4874209ejd.716.2021.06.17.01.48.36; Thu, 17 Jun 2021 01:48:58 -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=@infradead.org header.s=casper.20170209 header.b=M9U1xfKe; 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 S231226AbhFQIsg (ORCPT + 99 others); Thu, 17 Jun 2021 04:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbhFQIsd (ORCPT ); Thu, 17 Jun 2021 04:48:33 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BF38C061574 for ; Thu, 17 Jun 2021 01:46:26 -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=KZl/Wka2k1ddujQH+TFRsFdpimwLd/Gy1bZGIFO9vgw=; b=M9U1xfKesPpxfW7j41eixKbnwb 8p2j+GwHJo3jshsKXSpsdAqo1ZaoAugZIna6cjJbMxg8GuscfOm/7P/n4rWxbOaOOQszQU0BVUIZV 4T6SVHvtd2YUwE401qrIFwm8FW6XBzoBVkHtZcMbp1ux1zH6KA/KrZHHJgHHQ0tBFtg2heCDgbNUM R0G/vhzqvSB1mbqa3i2aC96vnMf89kiXNFvVxHggge7YXuX/+B3PbS1lWCVURwBODi3NKTBhhNnml dhrtHa9TJX4nX16RQLszcwbAWH0Cg0caPpiL+kWQOYfSqZTlaEX7DHNm4yLcHFVZmuAHAJiFVIil+ id8SQR3A==; 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.94.2 #2 (Red Hat Linux)) id 1ltnei-008vvm-Hu; Thu, 17 Jun 2021 08:45:51 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B0013300252; Thu, 17 Jun 2021 10:45:42 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 76ACA2BF4234B; Thu, 17 Jun 2021 10:45:42 +0200 (CEST) Date: Thu, 17 Jun 2021 10:45:42 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Nicholas Piggin , x86@kernel.org, Andrew Morton , Dave Hansen , LKML , linux-mm@kvack.org, Mathieu Desnoyers Subject: Re: [PATCH 4/8] membarrier: Make the post-switch-mm barrier explicit Message-ID: References: <1623816595.myt8wbkcar.astroid@bobo.none> <617cb897-58b1-8266-ecec-ef210832e927@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <617cb897-58b1-8266-ecec-ef210832e927@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 16, 2021 at 11:41:19AM -0700, Andy Lutomirski wrote: > mmgrab() and mmdrop() would be better if they were not full barriers. As a > trivial optimization, > mmgrab() could use a relaxed atomic and mmdrop() > could use a release on architectures that have these operations. mmgrab() *is* relaxed, mmdrop() is a full barrier but could trivially be made weaker once membarrier stops caring about it. static inline void mmdrop(struct mm_struct *mm) { unsigned int val = atomic_dec_return_release(&mm->mm_count); if (unlikely(!val)) { /* Provide REL+ACQ ordering for free() */ smp_acquire__after_ctrl_dep(); __mmdrop(mm); } } It's slightly less optimal for not being able to use the flags from the decrement. Or convert the whole thing to refcount_t (if appropriate) which already does something like the above.