Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp599792pxj; Thu, 3 Jun 2021 14:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+o0fJNwNeiaeXIAXBI7Cy+N2NxJerMsECzfMnb45fYGx0o7wtQoYx5rDDHRQkDGRnbCyV X-Received: by 2002:a17:906:39c6:: with SMTP id i6mr1221546eje.334.1622756433897; Thu, 03 Jun 2021 14:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622756433; cv=none; d=google.com; s=arc-20160816; b=BF7Bfr7Q4RtO+dF/yLBfsxzHAxDvho9irtaSrHdBwCT2Fd8a0dqoCztgjfP+BFVGZ8 Vx39B1FL8/fd8RVMPaQ3q2gBWD2SJml8Q03mOJM8n6ep2emk6GF7a/B6Fi59wUk1AoJw yG2UKIwyK2r03WfHEMpjf0L5FVuF/mzT98yvh87+1YL+v4Pt3Zht5/Gz1eFeos7B73kX K7lRd1uOTexlz4dNf882MJuCiIJhfNdQhRIHh6/215G46Pb2jSg4hqX+L8XdpC4lOcCP WoN3KjHQZvD1SBz8G8eCe7M5StaWgpLnj2f2aSbIpTKz+zIAMgHY65ON8sG93eaSLzld a/1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Cj9U35yyPKE7pmK1j+7Q/zTNdC/H5R4M+AV3/2neWss=; b=dKVdwVbPRQhGscs9DuSKiS85I8s8cp4iPCJIgE+YTJoSmVIH+vzKfh/jODhB1zUzf1 9T5yjyQcNmC44aadcO96qsIb0WchzIuiDMEQ9jzqgpRx9G+v3SCWFxN6YAEjDOX6WjUx 0xI8WRraTzptgCaIlkdsB1/Tiz8aEhwLw28GcniLvc7E4otETRMsp8CJ67Cxer/VtgRO AEwF2iaouaG+moWBo+y+SLBS7NkVahPFntEAFjvMNO6AhJbbpefb2tVxnmhDTOOXmLx6 AW3ZlJq69iKM3Sag3jSf2V5ENTho5kc5GFZQPA13Cw0aG9MGVsxGWkVlCrtVofECS8cQ Vgiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fTsaDKhx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m11si2998614ejc.708.2021.06.03.14.40.09; Thu, 03 Jun 2021 14:40:33 -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=@google.com header.s=20161025 header.b=fTsaDKhx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbhFCVjY (ORCPT + 99 others); Thu, 3 Jun 2021 17:39:24 -0400 Received: from mail-pj1-f47.google.com ([209.85.216.47]:45001 "EHLO mail-pj1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbhFCVjY (ORCPT ); Thu, 3 Jun 2021 17:39:24 -0400 Received: by mail-pj1-f47.google.com with SMTP id h12-20020a17090aa88cb029016400fd8ad8so4676353pjq.3 for ; Thu, 03 Jun 2021 14:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=Cj9U35yyPKE7pmK1j+7Q/zTNdC/H5R4M+AV3/2neWss=; b=fTsaDKhxAw8PVvd83BCP/cC6qKJlN6V1o9LrtB/y3O9S4mwmZ7uBGouH9gCJd104kY PZGI/0aZo+mptQPhKHftz5U4u85THlEgNu5bQMPzs6a+YQkqQ57RwoSNgRYalz7ptdhw IGMVfkwHNUiIyZxIffwW4micgcNNdthk2pqKYXrpmRGJF7huGilIH8RIJWIjqsgrWZqR vwWw9rKAR1q1dSmix/yth+LRJLlDHM9LahZcA6C0E1lY0g+D/g67Q8VxV7Frne4HCZ1e KQB0ShNLnsBLe9kyi0y1MjeJjSt/1pALCv0tgcAsRiu024W3Ppj/HdX6xrBumsGr6XWk 91Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Cj9U35yyPKE7pmK1j+7Q/zTNdC/H5R4M+AV3/2neWss=; b=JzJfyrL/ZaC1jJaWUsGqnauCGk3EVd2CANTX3wRrrvBLqtGAL6NxPf2S1B8QIf/VjT oDqo2O0CKWtME2xhXn+UpEqa7tf/jmlT2/tdI0W7RjWpVbCCZecG0KIb80u7c1yfzpvp r/o1kC+AoR6R4uqLy2MduE/9NIQGSXOjelviMmK9WUTO/kWlFitlYsgQg9YZfy4Ls/+d s1hYgDDhJimDmcz/EFbwc8mcXrqKXUkAIJN6nsYOGsO35oj1/XRhRHecBlmsxjjieAmU T3HCpgtlRX0OiaM576rLOXE4xcbPwYfNlQyplyrFIda256EfEw3ohGHTP71dBPe+cgFe aaFg== X-Gm-Message-State: AOAM533v9uH5IabYnW9JxOerQNpgUQ64esUaWIw7kU6aOojR7vugFhrx vpJWPdm87GdsYm5xNufxsHyZvQ== X-Received: by 2002:a17:902:b683:b029:ee:f0e3:7a50 with SMTP id c3-20020a170902b683b02900eef0e37a50mr1103742pls.7.1622756185123; Thu, 03 Jun 2021 14:36:25 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id mr23sm2966147pjb.12.2021.06.03.14.36.23 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 03 Jun 2021 14:36:24 -0700 (PDT) Date: Thu, 3 Jun 2021 14:36:11 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Matthew Wilcox cc: Hugh Dickins , 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 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Jun 2021, Matthew Wilcox wrote: > 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) { Yes, that's better, thanks. I was tempted to leave out the preliminary PageHead() test altogether; but you didn't suggest that, and I've concluded that perhaps it makes for good documentation, even though not strictly needed. > > > +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); Even nicer; and I've taken the liberty of just saying pgoff = page_to_pgoff(page) + compound_nr(page); v2 of this patch coming up now, thanks. Hugh