From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD2BAC432C2 for ; Thu, 26 Sep 2019 02:57:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8993E222BD for ; Thu, 26 Sep 2019 02:57:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8993E222BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 12C7F6B0006; Wed, 25 Sep 2019 22:57:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08F026B0008; Wed, 25 Sep 2019 22:57:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E97CF6B000A; Wed, 25 Sep 2019 22:57:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id C30FB6B0006 for ; Wed, 25 Sep 2019 22:57:01 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 69626181AC9B6 for ; Thu, 26 Sep 2019 02:57:01 +0000 (UTC) X-FDA: 75975559842.21.dock93_5a53b47bbb706 X-HE-Tag: dock93_5a53b47bbb706 X-Filterd-Recvd-Size: 4536 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 02:57:00 +0000 (UTC) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 19:56:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,550,1559545200"; d="scan'208";a="201467984" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga002.jf.intel.com with ESMTP; 25 Sep 2019 19:56:57 -0700 Date: Thu, 26 Sep 2019 10:56:38 +0800 From: Wei Yang To: Mike Kravetz Cc: Wei Yang , akpm@linux-foundation.org, aarcange@redhat.com, hughd@google.com, linux-mm@kvack.org Subject: Re: [PATCH 1/2] userfaultfd: remove one unnecessary warn_on in __mcopy_atomic_hugetlb Message-ID: <20190926025638.GA7636@richard> Reply-To: Wei Yang References: <20190925121833.2766-1-richardw.yang@linux.intel.com> <3f69dc19-eb3b-ed46-62bc-c5e6e89ab6eb@oracle.com> <20190926003528.GA3162@richard> <89ab9534-33c6-523c-bef0-282826af1be5@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89ab9534-33c6-523c-bef0-282826af1be5@oracle.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 25, 2019 at 07:10:46PM -0700, Mike Kravetz wrote: >On 9/25/19 5:35 PM, Wei Yang wrote: >> On Wed, Sep 25, 2019 at 10:44:58AM -0700, Mike Kravetz wrote: >>> On 9/25/19 5:18 AM, Wei Yang wrote: >>>> The warning here is to make sure address(dst_addr) and length(len - >>>> copied) are huge page size aligned. >>>> >>>> While this is ensured by: >>>> >>>> dst_start and len is huge page size aligned >>>> dst_addr equals to dst_start and increase huge page size each time >>>> copied increase huge page size each time >>> >>> Can we also remove the following for the same reasons? >>> >>> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c >>> index 640ff2bd9a69..f82d5ec698d8 100644 >>> --- a/mm/userfaultfd.c >>> +++ b/mm/userfaultfd.c >>> @@ -262,7 +262,6 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, >>> pte_t dst_pteval; >>> >>> BUG_ON(dst_addr >= dst_start + len); >>> - VM_BUG_ON(dst_addr & ~huge_page_mask(h)); >>> >> >> Thanks for your comment. >> >> It looks good, while I lack some knowledge between vma_hpagesize and >> huge_page_mask(). > >vma_hpagesize is just a local variable used so that repeated calls to >vma_kernel_pagesize() or huge_page_size() are not necessary. > Thanks for your confirmation. If this is the case, we can remove this BUG_ON safely. >> If they are the same, why not use the same interface for all those checks in >> this function? > >If we remove the VM_BUG_ON, that is the only use of huge_page_mask() in >the function. > >We can can also eliminate a call to huge_page_size() by making this change. > >@@ -273,7 +272,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, > mutex_lock(&hugetlb_fault_mutex_table[hash]); > > err = -ENOMEM; >- dst_pte = huge_pte_alloc(dst_mm, dst_addr, huge_page_size(h)); >+ dst_pte = huge_pte_alloc(dst_mm, dst_addr, vma_hpagesize); > if (!dst_pte) { > mutex_unlock(&hugetlb_fault_mutex_table[hash]); > goto out_unlock; Agree, and also with this I think diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index c153344774c7..74363f0a0dd0 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -315,7 +315,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, err = copy_huge_page_from_user(page, (const void __user *)src_addr, - pages_per_huge_page(h), true); + vma_hpagesize / PAGE_SIZE, true); if (unlikely(err)) { err = -EFAULT; goto out; After these cleanup, we use vma_pagesize to deal with all page size related calculation in this function, which looks more consistent to me. Does it looks good to you? >-- >Mike Kravetz -- Wei Yang Help you, Help me