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.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 BC717C4360C for ; Thu, 26 Sep 2019 17:22:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C0F2222C7 for ; Thu, 26 Sep 2019 17:22:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="aaCbtB0T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C0F2222C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 00ACE8E001C; Thu, 26 Sep 2019 13:22:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F24928E0015; Thu, 26 Sep 2019 13:22:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E139C8E001C; Thu, 26 Sep 2019 13:22:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id C30758E0015 for ; Thu, 26 Sep 2019 13:22:54 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 7764F45A8 for ; Thu, 26 Sep 2019 17:22:54 +0000 (UTC) X-FDA: 75977741868.04.lunch96_538318ca79922 X-HE-Tag: lunch96_538318ca79922 X-Filterd-Recvd-Size: 6841 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 17:22:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8QHECL8190820; Thu, 26 Sep 2019 17:22:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=a19DNMduxRdLSm/GXurzRRNZHL4nEwEsoxdGUsCbSjM=; b=aaCbtB0TdM1Uyrk3sNvrUgLjjGueNMDj8CyvFov/gBGXVD3skJnwWjD6NSa0HdU9+lSa rSGeLf2JQ71VJajybVk95YvBIX82leN/IYvIdUKStZZpgOFyfS0fRdhZk7iBFtpXlxDI v3hToBD9muE/9+GkddJ3PgiBcx5XGPDvjaWOEfW1vQ5bv4mAikZr0fZS/30QGqrpR/cO wXB9lZcNlCUFpc+/RoG3wrMAbkz9fwriSVv+6P7kWkMcVruv2JVHzuy4O7qhoUeEC3vS Vz9CE4Os/s4ekglwvIbLbmph62Nme6yP2tncz1av55H/98+GaDeI9MPZ3PwzwhERCigu tg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2v5btqd9ea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 17:22:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8QHEIsJ061489; Thu, 26 Sep 2019 17:20:51 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2v91btgwpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Sep 2019 17:20:51 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x8QHKnEV018777; Thu, 26 Sep 2019 17:20:49 GMT Received: from [192.168.1.222] (/71.63.128.209) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 26 Sep 2019 10:20:49 -0700 Subject: Re: [PATCH 1/2] userfaultfd: remove one unnecessary warn_on in __mcopy_atomic_hugetlb To: Wei Yang Cc: akpm@linux-foundation.org, aarcange@redhat.com, hughd@google.com, linux-mm@kvack.org 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> <20190926025638.GA7636@richard> From: Mike Kravetz Message-ID: <28901b0b-b565-94c7-1d45-b2afb8b561bb@oracle.com> Date: Thu, 26 Sep 2019 10:20:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190926025638.GA7636@richard> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9392 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909260146 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9392 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default 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-1909260146 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 9/25/19 7:56 PM, Wei Yang wrote: > 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? Yes, that looks good. Thanks for cleaning up this code. -- Mike Kravetz