Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6672067pxb; Wed, 17 Feb 2021 10:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwo0tJbjtZM0fqQarFqXyknEo9SscHJ49lUECu4wGDdD0KdAM5h50+i+utDh5w6rhTnmJE2 X-Received: by 2002:a17:906:4ec5:: with SMTP id i5mr182686ejv.395.1613585677064; Wed, 17 Feb 2021 10:14:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613585677; cv=none; d=google.com; s=arc-20160816; b=HCwp0biDqlVoY4W1GM3ikO9mAKAf1K5RvXAtexlPgGGsstvVFSe9jkFcV+yKG4zJP1 tSHT0cGdF9PtRYJWWbSOP/zN/CovNtlww6hlIlJYUQAd6wgaop/KcdM1YML2/+akXIpL e0Z0i0BuXShz/sSXEO88zxSxYF8ODQvE1p70INdqLBS+UiZrXZjg3KMrWGNIe5wqrzn8 W68vGnXfjrHqd+9fbwCzzOVpbhpBLjUbdqQy1la/2hB07MxyOITRQZrbgGxOY63InStl gHhciidAv6KNsVjNvg2bEu+N4MaRbfOKkbsW80kfZ2JpHV5DzZAOoyiS9khgzKuDJfFJ B3tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=p8rzk+9PWX0J6QS6PkL3eYmf4NkHf+hW8bzcZcs99bk=; b=PZcKbnxEvxIw1vHoaqkMFoQC3shxJ6Zrnzf5fr8X9jYjifwFNUPuh1/zrI+MgKUE9d 5j8CLTFRHCi0y6NtfS55u3E62ZdFB3URn6VsGDC84J9fa6LXaB95fys8dfAnAziy5W7P TBh8TLHoLVY25KGziuINk21P6D/xjuUerUNiQ9ttnlm7EbRzs4/LzbXS75NyiDWzOvpJ JfR8GjBSlUxrsGuT6tIZEe8fYocIL744HG5ct06Rs2/qxTlC6dPtr/pcoFQ30gf8ZiHY g4V89lQNKoIqOe3hQwfd/ePOqJtc15EwOeKFudka87G4jZ4Hk5B03G/FmPyXzxKc62Lf 7mGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Yau5Agp9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si1606760edc.122.2021.02.17.10.14.11; Wed, 17 Feb 2021 10:14:36 -0800 (PST) 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=@efficios.com header.s=default header.b=Yau5Agp9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233505AbhBQOy4 (ORCPT + 99 others); Wed, 17 Feb 2021 09:54:56 -0500 Received: from mail.efficios.com ([167.114.26.124]:60202 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbhBQOy4 (ORCPT ); Wed, 17 Feb 2021 09:54:56 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 71DB8321AD4; Wed, 17 Feb 2021 09:54:15 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id PGxdqeZkWP_m; Wed, 17 Feb 2021 09:54:15 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 1B70E321872; Wed, 17 Feb 2021 09:54:15 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 1B70E321872 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1613573655; bh=p8rzk+9PWX0J6QS6PkL3eYmf4NkHf+hW8bzcZcs99bk=; h=Date:From:To:Message-ID:MIME-Version; b=Yau5Agp9OVisj4/vcVlU3y7L7YOusdltgzM4nrze0XE2MYO+fjZfWV+4kYtxZSaCn P3zvtBLy4o1D/XciP/qlvMvzg9eC90StwRdA030lATLEnmef2g8mzi8ueL35Dg1Ycf HYp8TeUAMZsDpmXaAw1oeIR2+X9SzhADimR765gKXieKY8uZfsQxURlkjp3Kfih3/T 0pQPOFC2i03iDL+1+zyksjSu0d1Tq1puA9sKHFyMRFJjP1oYRHLZ/PmZk5PuwIdr0L VQoSgpJ1FWdqb+S32kn0H1hUE2K+RXnDiS6FT/3jozNCBArIhjKWVckagjVpFhcect Z0QmtPn3Rt+wQ== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id st-EjuNfwK2n; Wed, 17 Feb 2021 09:54:15 -0500 (EST) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id F2849321D87; Wed, 17 Feb 2021 09:54:14 -0500 (EST) Date: Wed, 17 Feb 2021 09:54:14 -0500 (EST) From: Mathieu Desnoyers To: Nadav Amit Cc: linux-kernel , Peter Zijlstra Message-ID: <330895069.24567.1613573654866.JavaMail.zimbra@efficios.com> In-Reply-To: <74F1E842-4A84-47BF-B6C2-5407DFDD4A4A@gmail.com> References: <74F1E842-4A84-47BF-B6C2-5407DFDD4A4A@gmail.com> Subject: Re: Local execution of ipi_sync_rq_state() on sync_runqueues_membarrier_state() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3996 (ZimbraWebClient - FF85 (Linux)/8.8.15_GA_3996) Thread-Topic: Local execution of ipi_sync_rq_state() on sync_runqueues_membarrier_state() Thread-Index: aQ9FvzemhUrCAb4Wf2CU2pP04nc+YQ== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Feb 16, 2021, at 4:35 PM, Nadav Amit nadav.amit@gmail.com wrote: > Hello Mathieu, > > While trying to find some unrelated by, something in > sync_runqueues_membarrier_state() caught my eye: > > > static int sync_runqueues_membarrier_state(struct mm_struct *mm) > { > if (atomic_read(&mm->mm_users) == 1 || num_online_cpus() == 1) { > this_cpu_write(runqueues.membarrier_state, membarrier_state); > > /* > * For single mm user, we can simply issue a memory barrier > * after setting MEMBARRIER_STATE_GLOBAL_EXPEDITED in the > * mm and in the current runqueue to guarantee that no memory > * access following registration is reordered before > * registration. > */ > smp_mb(); > return 0; > } > > [ snip ] > > smp_call_function_many(tmpmask, ipi_sync_rq_state, mm, 1); > > > And ipi_sync_rq_state() does: > > this_cpu_write(runqueues.membarrier_state, > atomic_read(&mm->membarrier_state)); > > > So my question: are you aware smp_call_function_many() would not run > ipi_sync_rq_state() on the local CPU? Generally, yes, I am aware of it, but it appears that when I wrote that code, I missed that important fact. See commit 227a4aadc75b ("sched/membarrier: Fix p->mm->membarrier_state racy load") > Is that the intention of the code? Clearly not! If we look at sync_runqueues_membarrier_state(), there is even a special-case for mm_users==1 || num online cpus == 1 where it writes the membarrier state into the current cpu runqueue. I'll prepare a fix, thanks a bunch for spotting this. Mathieu > > Thanks, > Nadav -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com