Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp38559ybp; Thu, 3 Oct 2019 14:26:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhxi6kLmFw05mU1GMVZe6S/xmSd71oF6Dkf2WYQzgNoiGii6jXK0KWj+e0faoGRGrBJn8j X-Received: by 2002:a50:8933:: with SMTP id e48mr11721376ede.51.1570137996419; Thu, 03 Oct 2019 14:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570137996; cv=none; d=google.com; s=arc-20160816; b=WjBbE+wk94igDJqOIfS7BZbH6YpuqGptxrTgSfI1yoMHlz3tX+hotdZH8+oXJJyf6h l+bj2VPLu99rk8lCKA4iFm0f7swde8+0pJV3LSjiEH+JWXNlZbNgGwYksXBbi6iF+6jZ yYA/A5bNc5QisjFdv4rsJmkNCnJ8uwkKFDXGhcsLlhByLU8iTgTUDZZ3rp+RiUsMHdZJ gQwjY+sKg8RPotlKyHaGLBJUL/yMwxmlhLxnROBYmfbEXHkN2mvzL9CD31+F7AOjj8ZX XH4aS6goJYpf2z80TDsnTTvqRmN+5oi9W+TXuMMGF8YaHyt8xPl9Bv/SknW08oOrYdTD +t2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=8+q7Pq/zQanM8hs/2D35RBNm2L3TyvWz6xbM82pdzhU=; b=nTZDb6wqAjhtw7Egs578BySOqIzZEy3vJKmZRPEOV+OZn6x9AQdD3LAOqoPJaBKLO3 kojSBcImPQiCKQdW0dAeDrw8s6H7thrTcJ+v+8yBckbDjwWk78qCoIcAG7Cg4g746WWK U9daip0ayuZrUzpscB9vL58cYVVoo7PLdIAPRxzVzo6TA/ksSE9d/rDBg1lQia5/7nSd RHgqk6833hdLWy/q9FQgYrssM1acOj+UCyJGdP52EoztdmoTT7WmQ4b3m+xrYDaHnZGC 0d0Wl0ofB2iCxNybnlDTI8JsIAft+WmY7NSgINq/8wlJZP7wMoeOSN9zHOnMHqqS+48U 5UmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si1903873ejx.295.2019.10.03.14.25.57; Thu, 03 Oct 2019 14:26:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731032AbfJCVZO (ORCPT + 99 others); Thu, 3 Oct 2019 17:25:14 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:20934 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732520AbfJCVZO (ORCPT ); Thu, 3 Oct 2019 17:25:14 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x93LCdfx082613; Thu, 3 Oct 2019 17:24:23 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vdpu7432j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Oct 2019 17:24:23 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x93LOMJM110138; Thu, 3 Oct 2019 17:24:22 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vdpu74323-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Oct 2019 17:24:22 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x93LA0iK002172; Thu, 3 Oct 2019 21:24:21 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma01dal.us.ibm.com with ESMTP id 2v9y5a39je-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Oct 2019 21:24:21 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x93LOJjE45547824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Oct 2019 21:24:19 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3BF9FC605A; Thu, 3 Oct 2019 21:24:19 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3ABC0C6055; Thu, 3 Oct 2019 21:24:11 +0000 (GMT) Received: from leobras.br.ibm.com (unknown [9.18.235.190]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 3 Oct 2019 21:24:10 +0000 (GMT) Message-ID: Subject: Re: [PATCH v5 01/11] asm-generic/pgtable: Adds generic functions to monitor lockless pgtable walks From: Leonardo Bras To: Peter Zijlstra Cc: Song Liu , Michal Hocko , "Dmitry V. Levin" , Keith Busch , linux-mm@kvack.org, Paul Mackerras , Christoph Lameter , Ira Weiny , Dan Williams , Elena Reshetova , linux-arch@vger.kernel.org, Santosh Sivaraj , Davidlohr Bueso , "Aneesh Kumar K.V" , Bartlomiej Zolnierkiewicz , Mike Rapoport , Jason Gunthorpe , Vlastimil Babka , Mahesh Salgaonkar , Andrey Ryabinin , Alexey Dobriyan , Ingo Molnar , Andrea Arcangeli , Ralph Campbell , Arnd Bergmann , Jann Horn , John Hubbard , Jesper Dangaard Brouer , Nicholas Piggin , =?ISO-8859-1?Q?J=E9r=F4me?= Glisse , Mathieu Desnoyers , kvm-ppc@vger.kernel.org, Thomas Gleixner , Reza Arbab , Allison Randal , Christian Brauner , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Logan Gunthorpe , Souptick Joarder , Andrew Morton , linuxppc-dev@lists.ozlabs.org, Roman Gushchin , "Kirill A. Shutemov" , Al Viro Date: Thu, 03 Oct 2019 18:24:07 -0300 In-Reply-To: <20191003115141.GJ4581@hirez.programming.kicks-ass.net> References: <20191003013325.2614-1-leonardo@linux.ibm.com> <20191003013325.2614-2-leonardo@linux.ibm.com> <20191003071145.GM4536@hirez.programming.kicks-ass.net> <20191003115141.GJ4581@hirez.programming.kicks-ass.net> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-AbFimQGKzzzvtIH76Jj2" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-03_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910030171 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-AbFimQGKzzzvtIH76Jj2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Peter, thanks for the feedback! On Thu, 2019-10-03 at 13:51 +0200, Peter Zijlstra wrote: > On Thu, Oct 03, 2019 at 09:11:45AM +0200, Peter Zijlstra wrote: > > On Wed, Oct 02, 2019 at 10:33:15PM -0300, Leonardo Bras wrote: > > > diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgta= ble.h > > > index 818691846c90..3043ea9812d5 100644 > > > --- a/include/asm-generic/pgtable.h > > > +++ b/include/asm-generic/pgtable.h > > > @@ -1171,6 +1171,64 @@ static inline bool arch_has_pfn_modify_check(v= oid) > > > #endif > > > #endif > > > =20 > > > +#ifndef __HAVE_ARCH_LOCKLESS_PGTBL_WALK_CONTROL > > > +static inline unsigned long begin_lockless_pgtbl_walk(struct mm_stru= ct *mm) > > > +{ > > > + unsigned long irq_mask; > > > + > > > + if (IS_ENABLED(CONFIG_LOCKLESS_PAGE_TABLE_WALK_TRACKING)) > > > + atomic_inc(&mm->lockless_pgtbl_walkers); > >=20 > > This will not work for file backed THP. Also, this is a fairly serious > > contention point all on its own. >=20 > Kiryl says we have tmpfs-thp, this would be broken vs that, as would > your (PowerPC) use of mm_cpumask() for that IPI. Could you please explain it? I mean, why this breaks tmpfs-thp? Also, why mm_cpumask() is also broken? >=20 > > > + /* > > > + * Interrupts must be disabled during the lockless page table walk. > > > + * That's because the deleting or splitting involves flushing TLBs, > > > + * which in turn issues interrupts, that will block when disabled. > > > + */ > > > + local_irq_save(irq_mask); > > > + > > > + /* > > > + * This memory barrier pairs with any code that is either trying to > > > + * delete page tables, or split huge pages. Without this barrier, > > > + * the page tables could be read speculatively outside of interrupt > > > + * disabling. > > > + */ > > > + smp_mb(); > >=20 > > I don't think this is something smp_mb() can guarantee. smp_mb() is > > defined to order memory accesses, in this case the store of the old > > flags vs whatever comes after this. > >=20 > > It cannot (in generic) order against completion of prior instructions, > > like clearing the interrupt enabled flags. > >=20 > > Possibly you want barrier_nospec(). >=20 > I'm still really confused about this barrier. It just doesn't make > sense. >=20 > If an interrupt happens before the local_irq_disable()/save(), then it > will discard any and all speculation that would be in progress to handle > the exception. >=20 > If there isn't an interrupt (or it happens after disable) it is > irrelevant. >=20 > Specifically, that serialize-IPI thing wants to ensure in-progress > lookups are complete, and I can't find a scenario where > local_irq_disable/enable() needs additional help vs IPIs. The moment an > interrupt lands it kills speculation and forces things into > program-order. >=20 > Did you perhaps want something like: >=20 > if (IS_ENABLED(CONFIG_LOCKLESS_PAGE_TABLE_WALK_TRACKING)) { > atomic_inc(&foo); > smp_mb__after_atomic(); > } >=20 > ... >=20 > if (IS_ENABLED(CONFIG_LOCKLESS_PAGE_TABLE_WALK_TRACKING)) { > smp_mb__before_atomic(); > atomic_dec(&foo); > } >=20 > To ensure everything happens inside of the increment? >=20 I need to rethink this barrier, but yes. I think that's it.=20 It's how it was on v4. I have changed it because I thought it would be better this way. Well, it was probably a mistake of my part. > And I still think all that wrong, you really shouldn't need to wait on > munmap(). That is something I need to better understand. I mean, before coming with this patch, I thought exactly this: not serialize when on munmap.=20 But on the way I was convinced it would not work on munmap. I need to recall why, and if it was false to assume this, re-think the whole solution. Best regards, Leonardo Br=C3=A1s --=-AbFimQGKzzzvtIH76Jj2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEMdeUgIzgjf6YmUyOlQYWtz9SttQFAl2WZvcACgkQlQYWtz9S ttTX8hAAxN3+8qz101R3PnfPxCPJuz+SZo22mLmwJKcJWwwEejFEZR0+2bLUMzIH ryWzy33/IPNdLR4le/j2oXMWbxsaj/mIFCPSv2kZECYKBexqmdwL5bu89xzdbahC keS0+sD/WZzYa9F2IaipvTQROGGjgLJkdCTEk3NnR/eXsWwXGATQ1k40G3kOVGg0 b8/27SCbuDKVHXEXtoIMXHV5b62a6ShT4qg2hqBbzsWGel/jYMwg7FFgImogu0YP L5jlEXZLKOWEaklSCyzA1XYPVpyIFct/ZBV5YpKKelZsOcu7GiCHB4fLyJCLc18K vQc3d8n/mjsE1ikyKTprhJZEY46MNtKMjWLnnhwxVAcDU5qCijt0WlRqeeI14NuP 3IN/+SysNt7Hzl70QRWeR2siGKYPPWMQDqEHcLJtYtau0r/qtKjixZkath62KVrJ MlziT40b3hLEtZsQj0VdwqQ+w3H+vu04RjvUt0dRXHEmQXz0tbCyHcCZ3ztUHx8O kisfErvVQT4xl+esHJWumKJGS5udezi/FRLLeABwWKbbv8UncwCb7OneOAmdtYA/ AsGmCP8YBPrsTF5gGymTP0mg/yvvjyDqXYTAmqY0KyDjKC4UM7hpnP5iIBobPTA4 ZEa8jx6zzJvipJ4/C/bR0XtE4ql6pMPddC5HBNMHrYyPO5myIyY= =AO5j -----END PGP SIGNATURE----- --=-AbFimQGKzzzvtIH76Jj2--