Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp40016pxj; Tue, 1 Jun 2021 14:36:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDTbmQELQnoh9j//9qtS+HyaVfXV1ByS4MyN/GnogQ7ocL+Nd3cTH5wvjh5QU0TnBKKFMP X-Received: by 2002:aa7:db94:: with SMTP id u20mr34808608edt.381.1622583360016; Tue, 01 Jun 2021 14:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622583360; cv=none; d=google.com; s=arc-20160816; b=AHulgxaJTSt8zaUIqzfI9Ln24ASz8D+6fTIOPgFD7RDlVMDROzq39JiHBHJpEOzhS3 unCLfOIQbugdXIOQCEQhaNfD+BFAY8x5VmkdhghPzT6ehIHJ3bmj8j6iBGsz/SbxNhmf RzAtv4M/OoAl1yHFDMseoG0agC/O/x5ACCO9T6Ggz2W0i1lBFawX++nuDjJoiGOgxHIJ GCrcI5oPTp0Zx4onfPtmmI6rcUKP5A1SvaOZnhHPANPwC1nru/DW+cvXryeby19yjyxr ZA3TkU6T9IZFY0gKcsiU57s3y1xlCkduwdd4MKbBKEnTjKF0i6I4eeh0n7yI31wu0HbI qTrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=N/AlK42fZ61t/CqPDnX2Zk4uh79h6uINaIjBrlZprnY=; b=mQVDLDeAmJR6M51EFBHJ921vW24y1CMEbiQOZHZWkRWYAif/DsNjiWLbtVQN8R2ugS KiKfD6fQeuKrZRouwCiQGB0X0hwBlO+jgMXHIaGFCeFvKUPeRkNV3JdJukWd5v/OzTcf EIdF62bDgwaiUX2ss9un3B0dShDEKXNJh5Jt/4kzNRnXJxElPmf9YaVBPDZ1i2h6YqpA BK7qNnhV90k2tICtcIo1eWGEi5c04bml8g22AI3+12dhEmu4n5ADtM1Ng9V0q4IQnFR+ QfQjJBGZ9fHBOV0ng9PcE53k550dn/kKJAz97qh47wEo6vB49O4oZ4bVA1DFK6VUgQtF aHYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Gw9cnklp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si210435edd.561.2021.06.01.14.35.30; Tue, 01 Jun 2021 14:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Gw9cnklp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234782AbhFAVdi (ORCPT + 99 others); Tue, 1 Jun 2021 17:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234761AbhFAVdh (ORCPT ); Tue, 1 Jun 2021 17:33:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99902C061574 for ; Tue, 1 Jun 2021 14:31:55 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);