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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL 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 11A07C47082 for ; Thu, 3 Jun 2021 21:37:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFC50611C9 for ; Thu, 3 Jun 2021 21:37:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbhFCVjZ (ORCPT ); Thu, 3 Jun 2021 17:39:25 -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-Google-Smtp-Source: ABdhPJxQrzqM3TCx+SozMQdopXsTTrnp+llKpDAJG/mbFkZdwHQNSDq/sHeU1qLGTrDBrMOAmuLtzg== 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 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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL 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 58EE2C47082 for ; Thu, 3 Jun 2021 21:36:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E7534600EF for ; Thu, 3 Jun 2021 21:36:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7534600EF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3CFEC6B0036; Thu, 3 Jun 2021 17:36:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 394416B006C; Thu, 3 Jun 2021 17:36:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2359C6B006E; Thu, 3 Jun 2021 17:36:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id E9CA86B0036 for ; Thu, 3 Jun 2021 17:36:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8AC50180AD802 for ; Thu, 3 Jun 2021 21:36:44 +0000 (UTC) X-FDA: 78213722328.29.67A9B63 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf25.hostedemail.com (Postfix) with ESMTP id AA5F56001703 for ; Thu, 3 Jun 2021 21:36:27 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id pi6-20020a17090b1e46b029015cec51d7cdso4654052pjb.5 for ; Thu, 03 Jun 2021 14:36:41 -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=W+g45Ecbcslo6AXqZZgbydtUrP8PMcdNOrkVz1F/uzRSdy1KPsZq0Hxfp2XWaJMce2 MkKAauVlQvpz3MfUp+dmzoEBeLT9zAepOYEANu2nuMF7apBxrvkTei++jfQZ1Gsx8Qjo WmnO69Tsp+eRxV0Dz8OgyC9zSYS+ONNivmlyeLlrkRJ5lG02pGeY6r1THqnm7drjBeXJ unDAX2MBUn+EAequH5t/Cwt11/TYj5tkQK9YBMxnYSsyL1EA+s8uiDMLPM0RSwFQgy5K bjHz6n93NUYQIZWlQwFKrzTP1WTTUKCQ1MpTDtOKgjdonOjxFhx1/IPM5kk/797xsv8j gmqQ== X-Gm-Message-State: AOAM533WJrdcq/P6xOHVC49+YyjEOjr+eQRI756gBnPGr9yRMvHJb3ex OBU5W5KHwyjqTmu0VHZ+OIEw9Q== X-Google-Smtp-Source: ABdhPJxQrzqM3TCx+SozMQdopXsTTrnp+llKpDAJG/mbFkZdwHQNSDq/sHeU1qLGTrDBrMOAmuLtzg== 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 X-Rspamd-Queue-Id: AA5F56001703 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=fTsaDKhx; spf=pass (imf25.hostedemail.com: domain of hughd@google.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam04 X-Stat-Signature: rqatt84c75yp6fauhb5z1ghd1gcacnyt X-HE-Tag: 1622756187-739789 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, 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