Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5129960imm; Tue, 26 Jun 2018 06:26:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJb+qRtwu6x4YqCAzzCGtI7eN43atcJqlgdcaX8QKuVp5TfUWXdWHOQVgfMLG7toa8UBe8r X-Received: by 2002:a17:902:c85:: with SMTP id 5-v6mr1672958plt.126.1530019578379; Tue, 26 Jun 2018 06:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530019578; cv=none; d=google.com; s=arc-20160816; b=fdpgFaWTFj+AJzgRGjQrB/Bqvhxp/o5mMqKAbsMoSt/sCx9D5VTSFrLt7MEtv2faO8 eP8aYZGLO/lHqOxUvFodKJCFK1u73WSswidP7rVoulxBuhnH5u230M714YwGTTGDg7Oo VOpYPzgQc0+sEnZ5gzRQdwe8CJNuvckHdFYo9G04w2PKs3H8TKo+58UZZ6gg1qRXlZVY X3n7X4KY1UW/dLdeYx/abj2fLFJpjvzm+dX8ythrlnGdPKyOwT5nXnOhScoII2my0WFS dDlCq4B3lTp7QO5Nmhc8DYmL3GSCKGYwzRZfgIDp9K+i4h2cbTBBz2/UFD/i0HmrGBNx JLpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=uo/khf0+KRYebF0KaXlbo3aP3NW1iEd/jRsBMhD/PN8=; b=CCr/p87XefkM6FHj7SqGVZ8P/GU2a+2jeJeqyQsYeczI4NzeEkRi/x9wdZqZCGtNH3 XFxVuDb8a0kCscO47O2rlX9YekFHHB1jxasT/WXHmvA+Y8dagRDmJpGpCi/5V6BviY5L 6Lpcb1U9QyXvELNynmXLszxQkxgYWap/EGJ/oaEJShkNnSEghbfPdiGs6pWZ3h6Gwxv3 VH4ybypCMC5Xms/81SDVONen23oU0RMxPCxrcVYxLPryV9AYaUKWz4At8fJzNjgOZM9W eTxK2hu3POCPMVdu0awEEZ3oeJxcGElz8UkptKP+LCWMRswmuwQzYU4WGg3cJZSw2SXu NgjA== 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 h3-v6si1630113pld.114.2018.06.26.06.26.04; Tue, 26 Jun 2018 06:26:18 -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 S935791AbeFZNYm (ORCPT + 99 others); Tue, 26 Jun 2018 09:24:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50748 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935005AbeFZNYl (ORCPT ); Tue, 26 Jun 2018 09:24:41 -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 w5QDIjCM032000 for ; Tue, 26 Jun 2018 09:24:40 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jup1g10v0-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 26 Jun 2018 09:24:40 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Jun 2018 14:24:38 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 26 Jun 2018 14:24:36 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5QDOZ4p31654142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 26 Jun 2018 13:24:35 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B7B7AAE045; Tue, 26 Jun 2018 14:24:29 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 84027AE056; Tue, 26 Jun 2018 14:24:29 +0100 (BST) Received: from s38lp21.boeblingen.de.ibm.com (unknown [9.152.224.155]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 26 Jun 2018 14:24:29 +0100 (BST) From: Janosch Frank To: mike.kravetz@oracle.com, aarcange@redhat.com Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH] userfaultfd: hugetlbfs: Fix userfaultfd_huge_must_wait pte access Date: Tue, 26 Jun 2018 14:24:21 +0100 X-Mailer: git-send-email 2.14.3 X-TM-AS-GCONF: 00 x-cbid: 18062613-0020-0000-0000-0000029F1DF3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18062613-0021-0000-0000-000020EB9731 Message-Id: <20180626132421.78084-1-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-26_07:,, 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=837 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806260150 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_wait for hugepmd ranges") --- 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(struct userfaultfd_ctx *ctx, unsigned long reason) { struct mm_struct *mm = ctx->mm; - pte_t *pte; + pte_t *ptep, pte; bool ret = true; VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem)); - pte = huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); - if (!pte) + ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); + + if (!ptep) goto out; ret = false; + pte = huge_ptep_get(ptep); /* * 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 = true; - if (!huge_pte_write(*pte) && (reason & VM_UFFD_WP)) + if (!huge_pte_write(pte) && (reason & VM_UFFD_WP)) ret = true; out: return ret; -- 2.14.3