Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp350192imm; Tue, 3 Jul 2018 21:00:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcdDvg6PjldsPdZRW5oQzURJDEkTVdkB31KiHxiM2wRurHbDJDiIKU61oqKrujlyTcc4eP5 X-Received: by 2002:a17:902:26:: with SMTP id 35-v6mr443022pla.276.1530676817959; Tue, 03 Jul 2018 21:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530676817; cv=none; d=google.com; s=arc-20160816; b=Zvwy7GEPJ/IjcKEGD/2TMPQe8pA3kjp8qb6L26fPYAccU3CzUAAImqnLalkOgK+cyZ g3SJZuuPkRbAsJpWI1l3oS02vYkWP23yprPrguiBwufJhQQCXEbvbf30nAH9bn0yIvlU 48y6UkfBSu6D746KBJIVwe5HZxRpMcrgykbg4INx2rn72CEA8os3s63AfNI4AejImM9b 2y2/QDIuNVszjf6mJJtJqdKunXF79jvYSgoaLVA+vKII16/xnj5ReE3jVYrz4pRGtveT a238O+fhVGtgJFqN5Pwo5d1wfYlj2xx7uINMEDGjgPpSMYMpu4chns9T9zh2JoTsB57z T7eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=QzkxE2DPaL3rGliJvbTJgY0A0/exacWy/BK4MUnj+s4=; b=BavFMF89IHEeE+alFDUuQKsJG4aPePuLymAXvcqlJzbtUFhhp9hPhTVPly45Rcb7qy lJ2+4i4bMGYkhdJ3doRLsGKHmAbjj1tCZbeATP9Rpaftx6XUmPEznzeZs6+U1iOIPko9 vCGqLNfql8OKEFhX0NpqwQ3IDGm78VFf79/mUnPl5t9zOsuyOKSK4VGXY+qlfed+EbCa MHGs1egYB9B3udEZMsOmYBuR0HGo/ZBQm3fhB/fTXFk7ovYasYUeFAcqEXpyrxOTlySw qfj7UEtDeiHjoALf/BXmq1X7J9YDXd7rDcpG1ywIIE4rA0nnXgQ6ftiDMzRgx7lYZX1N h2mA== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13-v6si2540428plo.287.2018.07.03.21.00.03; Tue, 03 Jul 2018 21:00:17 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933197AbeGDD6H (ORCPT + 99 others); Tue, 3 Jul 2018 23:58:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59794 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932434AbeGDD6G (ORCPT ); Tue, 3 Jul 2018 23:58:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 532FD40676C0; Wed, 4 Jul 2018 03:58:06 +0000 (UTC) Received: from sky.random (ovpn-120-117.rdu2.redhat.com [10.10.120.117]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E24621C59C; Wed, 4 Jul 2018 03:58:05 +0000 (UTC) Date: Tue, 3 Jul 2018 23:58:05 -0400 From: Andrea Arcangeli To: Janosch Frank Cc: Mike Kravetz , linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, "linux-mm@kvack.org" , Andrew Morton Subject: Re: [PATCH] userfaultfd: hugetlbfs: Fix userfaultfd_huge_must_wait pte access Message-ID: <20180704035805.GA9833@redhat.com> References: <20180626132421.78084-1-frankja@linux.ibm.com> <961dc253-b071-8a72-c046-c23cae377e2c@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <961dc253-b071-8a72-c046-c23cae377e2c@linux.ibm.com> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 04 Jul 2018 03:58:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 04 Jul 2018 03:58:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'aarcange@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Jun 27, 2018 at 10:47:44AM +0200, Janosch Frank wrote: > 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_wait for hugepmd ranges") > > Adding linux-mm and Andrew on Cc: > > > > 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. :) What I thought when I read the fix is it would be more robust and we could catch any further error like this at build time by having huge_pte_offset return a new type "hugepte_t *" instead of the current "pte_t *". Of course then huge_ptep_get() would take a "hugepte_t *" as parameter. The x86 implementation would then become: static inline pte_t huge_ptep_get(hugepte_t *ptep) { return *(pte_t *)ptep; } I haven't tried it, perhaps it's not feasible for other reasons because there's a significant fallout from such a change (i.e. a lot of hugetlbfs methods needs to change input type), but you said you're actively looking to get less of these problems this could be a way if it can be done, so I should mention it. The need of huge_ptep_get() of course is very apparent when reading the fix, but it was all but apparent when reading the previous code and the previous code was correct for x86 because of course huge_ptep_get is implemented as *ptep on x86. For now the current fix is certainly good, any robustness cleanup is cleaner if done orthogonal anyway. Thanks! Andrea