Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6084418imm; Wed, 27 Jun 2018 01:49:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeurFqv+e/dbZhcZkG81UvHvrXDoO8E5dpaROgWFezLG5leSxvkJK5vd+4N8L+qzsXw3G23 X-Received: by 2002:a62:b24f:: with SMTP id x76-v6mr4937479pfe.147.1530089382758; Wed, 27 Jun 2018 01:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530089382; cv=none; d=google.com; s=arc-20160816; b=z1kPKTITNuhUjNy4TwX9+o5gKp2DsYKVRBF8yEIGwTWKdGysQMiTVZXoq9N+X3TrZW Ce+l1FIKIXbivUeIZs1mDjSQoMwhdY6+Agu+uZsty5eUhqJNiaNgcW8mXt+MIcn2vkmn Pm09xr9eNZa6PMXy7wjy78X6igNlRfmwAGH5aI/sTRK4xHmLDeBrvJtpenWVGV35wCSd 4MKDlXqharseKlSypDOiHImFeNMhPtkpQU6bCP7J7T6ALegEGYDhFAstoZ4haJyrUjHH O+KP/r47J5FcPyXN6OvW9O7bhjPsG7rqwwxH7c+aVjB3T373zLnsu00LvqMenVsvTyRz YI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:in-reply-to:mime-version :user-agent:date:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=vJznM9DCxydfwej6WliYKFCunGeKcE6AGEmDDXQl/lI=; b=jFpAx+HVgw4jtlsqeRuk7PoOi1zTMgU6rMSNEZSXuzp+wwQqBfA42+yPBawal3TLsw Z1Rfbf1NznKpTV2LsQ4gnExrlTxevjrvtHdqya8yRsZ8bi+7/0BGMAx2+PkxL3/4iZSr AsKWUwYsdyR/GCOgtuoZpZRqISpy0dyrNtcx5n3SIt0vAAtdmh5BOXDsqrrJwWQcStYd B2B7KQ7UDX2juJuRsDRmKF3Q4OZZgRFc6ncer0TTxi0KRMhW9HXH8oFNMmUC+YBxioRE Ye2ZipVrwNc4+aqVg5StSzWJSMsV5ZzIK4qmqEiecqCfMWMXBJKFDwi1gV5cCMZs+I3G OoQA== 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 z3-v6si2946410pgp.527.2018.06.27.01.49.25; Wed, 27 Jun 2018 01:49:42 -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 S932587AbeF0IsN (ORCPT + 99 others); Wed, 27 Jun 2018 04:48:13 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33676 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932234AbeF0IsI (ORCPT ); Wed, 27 Jun 2018 04:48:08 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5R8ieIe065530 for ; Wed, 27 Jun 2018 04:48:07 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jv4qn6syh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 27 Jun 2018 04:48:07 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Jun 2018 09:48:05 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 27 Jun 2018 09:48:03 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5R8m2VB13566172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 27 Jun 2018 08:48:02 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3415D4C040; Wed, 27 Jun 2018 09:47:53 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 002DC4C04E; Wed, 27 Jun 2018 09:47:52 +0100 (BST) Received: from [9.152.224.155] (unknown [9.152.224.155]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 27 Jun 2018 09:47:52 +0100 (BST) Subject: Re: [PATCH] userfaultfd: hugetlbfs: Fix userfaultfd_huge_must_wait pte access To: Mike Kravetz , aarcange@redhat.com Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, "linux-mm@kvack.org" , Andrew Morton References: <20180626132421.78084-1-frankja@linux.ibm.com> From: Janosch Frank Openpgp: preference=signencrypt Autocrypt: addr=frankja@linux.ibm.com; prefer-encrypt=mutual; keydata= xsFNBFfqIWIBEAC9u1ku3alDY4YilAfKidqWZ46kCnu7WPXkdcgH3ww/9CcgIDoeSr90SnaU T9gQRO92ESh2OO0ff3RMfmQpPG7hivVK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SzAMAAAoJEBcO/8Q8ZEV5R+oQAJgaEDxy1cpGmGva0s0Oxvia s5b4+otopF5pnlElTZcqWY1bx3vh2c5NZjCCubY1tb8548x6IprwAYtpmx3XlOXb12Jki/HT qHgeSscyleLbneNO+s8LfhJKY15smPqVKG6leCbtIpliZ0TI2Zif+gYvDZRruHYgHwi9bQzH +wEVDrgess/1dDq3Pt+W7NRhFoKKq7ZQOYkyHE1qdck/cGvq4/XCL9np7+3CBEql+QOtuR2o AdES5cnZwKm7peagQBEaFqgni26de11pW294pJRG0U36mSqxEoyqe97vKUYzsdy1hPPbOPfy 7img6Ifh6WL1b4FIIn9TFbooQ1WRSQvbOzxL+E2x+vmEPfNxpzAuuS+ASLJ6Zv9QCOUAvzBn Lfg7BvkfUhALMIZnAoyYmxutcWL4XYYAvMG13l8hFYpoQcF4WEnUoP0UuNwXmR4QZvOuiE8u CyL9U2LEYbrPVTIsEtUVmDlCyD1Kq+6LE3aU+n06soITGp9a3/WNLpXUbUYfzRvYJ3p6jssI Pe50r3yPfdgbWIWzeWuLimNVTlbIZAi1Y0VIdCDbDQpXl2DDTB9zZw2yz0kRKxasMCAEsvlA CT0NLoyQplUjM1ir5e6QTwy9+v3niCCesupe7owsFfrg/YZsE9jCy8vWgdPjSnRJkwQqV2Fw lFM6NIuMAY1Y Date: Wed, 27 Jun 2018 10:47:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EOx6EeNelUcnckrJL4sELenaLgzAW7D4j" X-TM-AS-GCONF: 00 x-cbid: 18062708-0016-0000-0000-000001E0980C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062708-0017-0000-0000-00003234D5C3 Message-Id: <961dc253-b071-8a72-c046-c23cae377e2c@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-27_02:,, 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-1806210000 definitions=main-1806270103 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EOx6EeNelUcnckrJL4sELenaLgzAW7D4j Content-Type: multipart/mixed; boundary="y0PnyKh8xwW8SWzdhueygGCUBDtCbMUus"; protected-headers="v1" From: Janosch Frank To: Mike Kravetz , aarcange@redhat.com Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, "linux-mm@kvack.org" , Andrew Morton Message-ID: <961dc253-b071-8a72-c046-c23cae377e2c@linux.ibm.com> Subject: Re: [PATCH] userfaultfd: hugetlbfs: Fix userfaultfd_huge_must_wait pte access References: <20180626132421.78084-1-frankja@linux.ibm.com> In-Reply-To: --y0PnyKh8xwW8SWzdhueygGCUBDtCbMUus Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 26.06.2018 19:00, Mike Kravetz wrote: > On 06/26/2018 06:24 AM, Janosch Frank wrote: >> Use huge_ptep_get to translate huge ptes to normal ptes so we can >> check them with the huge_pte_* functions. Otherwise some architectures= >> will check the wrong values and will not wait for userspace to bring >> in the memory. >> >> Signed-off-by: Janosch Frank >> Fixes: 369cd2121be4 ("userfaultfd: hugetlbfs: userfaultfd_huge_must_wa= it for hugepmd ranges") > Adding linux-mm and Andrew on Cc: >=20 > Thanks for catching and fixing this. Sure I'd be happy if we get less of these problems with time, this one was rather painful to debug. :) > I think this needs to be fixed in stable as well. Correct? Assuming > userfaultfd is/can be enabled for impacted architectures. Correct, it seems I forgot the CC stable... >=20 > Reviewed-by: Mike Kravetz Thanks > -- Mike Kravetz >> --- >> fs/userfaultfd.c | 12 +++++++----- >> 1 file changed, 7 insertions(+), 5 deletions(-) >> >> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c >> index 123bf7d516fc..594d192b2331 100644 >> --- a/fs/userfaultfd.c >> +++ b/fs/userfaultfd.c >> @@ -222,24 +222,26 @@ static inline bool userfaultfd_huge_must_wait(st= ruct userfaultfd_ctx *ctx, >> unsigned long reason) >> { >> struct mm_struct *mm =3D ctx->mm; >> - pte_t *pte; >> + pte_t *ptep, pte; >> bool ret =3D true; >> =20 >> VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); >> =20 >> - pte =3D huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); >> - if (!pte) >> + ptep =3D huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); >> + >> + if (!ptep) >> goto out; >> =20 >> ret =3D false; >> + pte =3D huge_ptep_get(ptep); >> =20 >> /* >> * Lockless access: we're in a wait_event so it's ok if it >> * changes under us. >> */ >> - if (huge_pte_none(*pte)) >> + if (huge_pte_none(pte)) >> ret =3D true; >> - if (!huge_pte_write(*pte) && (reason & VM_UFFD_WP)) >> + if (!huge_pte_write(pte) && (reason & VM_UFFD_WP)) >> ret =3D true; >> out: >> return ret; >> --y0PnyKh8xwW8SWzdhueygGCUBDtCbMUus-- --EOx6EeNelUcnckrJL4sELenaLgzAW7D4j Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJbM09BAAoJEBcO/8Q8ZEV5i9oQAIqm1ue34kTJFM07C7AD3/H0 FU7fNoU9KCPnqyq9eyS3AWeW/tKu53JtuOn8zEtsExGpv1UkQKxfEmUd5PuOlAam vdnxGv/xjVwggismVKu27LP39RhspCEPoZG4tGcPOMrCdM/xqE/3QSoSGdRVzab5 g9AykXJ9hOGd73VCBAMTAtVLFEBuqjY+kxlptxM0IuMQfBvltCsdGpncOIkF8UWQ MiToGV1hF1r/MnOQn8IlkQZu3Ftgsm4Z8sGc3jfON+oad+P2OtaU1vbjMN3l0qW4 V9fWNN2QL7fMpqpV8AXDMYkLTo3iB6+ryd7BAt0Fo0nLt4NIo6eU+A809Wnx62d2 IhkbRpe0raZzDuK93LuhDeSp9Q4Xp597/u5cuIfL+kz2IugekVVc1E0wySZtvYoG nscene1bQH9OJG7KnfUkEOm8Wpx5b0ys0/oqJgg7uSLaAoH591wgEYBAXZMvtJuD afzap8+hSaLcyPC6QHMS+juh39YD/P0CVT1MvkOi6SaClKM2AUYH0UJep0BkA5Te YCq22Qjy5KB8ruXwlgBtIrPxw3ADY9bOjpOglyd4lCoCge08FGaeWrB7t6aPZpjp oqlcZ15gSMFmg/g7oCe5C7FuCTKwaoYLZU0TmLx2kny78WvrkPOjh6QkchYmpNgw rY5WahobUYtljzX/yFqN =8cRD -----END PGP SIGNATURE----- --EOx6EeNelUcnckrJL4sELenaLgzAW7D4j--