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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 4197BC4708F for ; Tue, 1 Jun 2021 21:31:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B640460FE3 for ; Tue, 1 Jun 2021 21:31:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B640460FE3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 45C386B0072; Tue, 1 Jun 2021 17:31:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 433076B0073; Tue, 1 Jun 2021 17:31:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AE136B0074; Tue, 1 Jun 2021 17:31:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id EC6486B0072 for ; Tue, 1 Jun 2021 17:31:52 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7FB5BA8F6 for ; Tue, 1 Jun 2021 21:31:52 +0000 (UTC) X-FDA: 78206452464.36.A759A4F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 9C9AB544 for ; Tue, 1 Jun 2021 21:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=N/AlK42fZ61t/CqPDnX2Zk4uh79h6uINaIjBrlZprnY=; b=Gw9cnklpUPhmKaibH4IJtO0ebo QpeSUNiWsYGczv1YkXUGfnL0J6XVv+z0qOG08Dk5zqrUnLxtMfuark1gTnuwXFcFuA4z+GGoyphOf PZqlipSHtr44vXbHEACZSiDwN+pPJyJ6GB1s4+veyBHMAEOCCghM3bKBEqADLBfQUbW2HU0h/u6wA tjgA7Df15JraUBvpn054S+hI4K5MvtpRPxJj0wUVYf2SbdtjjTKN11nDaro+35Wl1exZ3Z8bNU7Md auS3XsIiLoqX/YHIET99AIPkC5LeXj+ZO6GQbGt1QoQdMh9czUAcGRZETBhzNOfg82Ppn2ANNWZRu 2cXWrOMA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1loByP-00ASAC-A6; Tue, 01 Jun 2021 21:30:55 +0000 Date: Tue, 1 Jun 2021 22:30:53 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , "Kirill A. Shutemov" , Yang Shi , Wang Yugui , Naoya Horiguchi , Alistair Popple , Ralph Campbell , Zi Yan , Miaohe Lin , Minchan Kim , Jue Wang , Peter Xu , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/7] mm/thp: fix vma_address() if virtual address below file offset Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Gw9cnklp; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9C9AB544 X-Stat-Signature: jfidkptyjnjsmpga6d83tjkwyyxx37gu X-HE-Tag: 1622583094-645248 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 Tue, Jun 01, 2021 at 02:09:31PM -0700, Hugh Dickins wrote: > static inline unsigned long > -__vma_address(struct page *page, struct vm_area_struct *vma) > +vma_address(struct page *page, struct vm_area_struct *vma) > { > - pgoff_t pgoff = page_to_pgoff(page); > - return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > + pgoff_t pgoff; > + unsigned long address; > + > + VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */ > + pgoff = page_to_pgoff(page); > + if (pgoff >= vma->vm_pgoff) { > + address = vma->vm_start + > + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); > + /* Check for address beyond vma (or wrapped through 0?) */ > + if (address < vma->vm_start || address >= vma->vm_end) > + address = -EFAULT; > + } else if (PageHead(page) && > + pgoff + (1UL << compound_order(page)) > vma->vm_pgoff) { } else if (PageHead(page) && pgoff + compound_nr(page) > vma->vm_pgoff) { > +vma_address_end(struct page *page, struct vm_area_struct *vma) > { > + pgoff_t pgoff; > + unsigned long address; > + > + VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */ > + pgoff = page_to_pgoff(page); > + if (PageHead(page)) > + pgoff += 1UL << compound_order(page); > + else > + pgoff++; Again, can use compound_nr here. In fact, the whole thing can be: pgoff += compound_nr(page);