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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DCD7EB64D7 for ; Mon, 26 Jun 2023 16:23:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88FE98D0002; Mon, 26 Jun 2023 12:23:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 840338D0001; Mon, 26 Jun 2023 12:23:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 709188D0002; Mon, 26 Jun 2023 12:23:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 600908D0001 for ; Mon, 26 Jun 2023 12:23:17 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 105C11603A7 for ; Mon, 26 Jun 2023 16:23:17 +0000 (UTC) X-FDA: 80945418834.05.6BBD36A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 77C2B1A000C for ; Mon, 26 Jun 2023 16:23:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i+wvgfza; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687796594; a=rsa-sha256; cv=none; b=pFkqmdhboHZMcRDcyWqVSquQG9SeCeiqV8kS4X5ibU+CI+nqXjdiT8RERwrNA5C5u4DntV gl+q3zB3EUnScqtqfnyPxlraEN4YUGxQAiOTz8FVsVdTpqAhcgB87FWz28T4Y/ujv+ZtFZ 0sxXJLfxaMcYq2QDtljco9xnY5biYL8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i+wvgfza; spf=pass (imf19.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687796594; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=igMfXFR5kNoI10TQDurWKUzwN6Z45JekZK2Q72EILNo=; b=0HMgKYU4OyGZ18HVLzY+khdPBejarRqdPyj2MbvO8MBFVZsIcKc+cHeiKmSmYdq20xZshj 8vMYq7tEilcEiErpo/+mfBsw+k75YjSKEYJoO81w8cIA4VCW0XBIBGIHxrQA5u8+tKpqI0 H1oD+B/t0iIzEKRHUTRNBCaWTJdHMWI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687796593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=igMfXFR5kNoI10TQDurWKUzwN6Z45JekZK2Q72EILNo=; b=i+wvgfzaOYF/Cz6IFNh2/CRkm5kV0pnJp13gg0LzWgB98VTvoX6MPf46LfTOnhtseu3wiu LgZG9muytrH87l0l3WRQiFdVrfhLtZ9jm6oSZcvaAPocHVF1NKBnFeSYDJhw2jPYc/OBVQ s3rJ0u3VXUHBYh5ZusqXa0rDfLTnnNo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-r1Is4ga5PNOgiiGlmL5S2Q-1; Mon, 26 Jun 2023 12:23:06 -0400 X-MC-Unique: r1Is4ga5PNOgiiGlmL5S2Q-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6340023ffbbso5376256d6.1 for ; Mon, 26 Jun 2023 09:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687796582; x=1690388582; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=igMfXFR5kNoI10TQDurWKUzwN6Z45JekZK2Q72EILNo=; b=ccxoDvHUjSRljjtlrXPs0EOPrj/0OCKck17Bqf2upVwdACPUJOnz74+jZ2GnLbf1KG n/MgfmwED79U297b8JgIv2pUUXO3qFgtzwiYNOBZl+Op7EjV2EBjVAHoPQJWsBFrcCBO nL80aKzRbEFSFAy7Ek/vhCK7Hqbo6wLJOTQ4dKEN2ypDT1LbRnTVrxU3DbmphC8/mt4e 8ravcCDeQ6dhxs8AVRfKVGObZn2WgQNXsqSjarQGnuN3Si0c3keTwiYD51GCBkvNVc4f L3KkGQNiVxrVTS1SSkq0cOuN8Z8yFlRHsdn4cxvKPyKRleZGVKm5/TZbKmPI5MOHjY06 CVig== X-Gm-Message-State: AC+VfDyEXDdH1qMKLcQryqgWPumlUor1KrkG9Dndx98biLFjKIfv6EFe GF1MtXfxX1Bl8qPfFVMWyKd8IfnZqFTNQYOZfDIdHlg0pU1Crvurotrha0oDhcxsRxqBZJOdCcq MAF0o2ZnACcQ= X-Received: by 2002:a05:6214:27eb:b0:616:870c:96b8 with SMTP id jt11-20020a05621427eb00b00616870c96b8mr36132637qvb.3.1687796582602; Mon, 26 Jun 2023 09:23:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oVBR2URFNF062kj36ByRSo63M2eJzjnhcU1VZ6ZJnCR3z2r+9LNb0CCEiOx2Y22cP34jYBA== X-Received: by 2002:a05:6214:27eb:b0:616:870c:96b8 with SMTP id jt11-20020a05621427eb00b00616870c96b8mr36132612qvb.3.1687796582255; Mon, 26 Jun 2023 09:23:02 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id f19-20020ae9ea13000000b007592174cb08sm2864932qkg.10.2023.06.26.09.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 09:23:01 -0700 (PDT) Date: Mon, 26 Jun 2023 12:23:00 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lorenzo Stoakes , John Hubbard , Andrew Morton , Mike Rapoport , Yang Shi , Andrea Arcangeli , Vlastimil Babka , "Kirill A . Shutemov" , James Houghton , Matthew Wilcox , Mike Kravetz , Hugh Dickins , Jason Gunthorpe Subject: Re: [PATCH v3 2/8] mm/hugetlb: Prepare hugetlb_follow_page_mask() for FOLL_PIN Message-ID: References: <20230623142936.268456-1-peterx@redhat.com> <20230623142936.268456-3-peterx@redhat.com> <89fee4bf-29a1-db19-e0ae-dd827d277504@redhat.com> MIME-Version: 1.0 In-Reply-To: <89fee4bf-29a1-db19-e0ae-dd827d277504@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 77C2B1A000C X-Stat-Signature: bfjt38w3y1854xyiiq3gmkdk1dzzpg9w X-Rspam-User: X-HE-Tag: 1687796594-478770 X-HE-Meta: U2FsdGVkX1/mdT/mca7B1PfJwy6I3WDmfrkzPkCo7y6za0Lo4mNOWdX0ksqimB9SFsnlPXh6epPLL7SyDGcVUStAL/rvk6ADdBB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1m2c3PxsTXdeyzdRa9q8G+Q1e12GzZOJUzAlR7NAaKrpirVNxomgJjcBf5OvgX9Lek4Ng2T5JBclzVPRXawvRfoQM4q34jX/kpsS5hU7bW3rWd7OjJDyl3/f4cCrxakZmyqTIzU3Xr59GH0WFkFqn3cjiShScCt7tXfetmR+z6LiBHJywz7SYdw2JMHSHm30uNvx5R0HxQsqzQ4cNo8QDLzJr469Ze82KS7UPXna/oYpO0d0iiX4Z8j/XdPqJ7eWQy8= 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 Mon, Jun 26, 2023 at 10:06:24AM +0200, David Hildenbrand wrote: > On 23.06.23 16:29, Peter Xu wrote: > > follow_page() doesn't use FOLL_PIN, meanwhile hugetlb seems to not be the > > target of FOLL_WRITE either. However add the checks. > > > > Namely, either the need to CoW due to missing write bit, or proper > > unsharing on !AnonExclusive pages over R/O pins to reject the follow page. > > That brings this function closer to follow_hugetlb_page(). > > > > So we don't care before, and also for now. But we'll care if we switch > > over slow-gup to use hugetlb_follow_page_mask(). We'll also care when to > > return -EMLINK properly, as that's the gup internal api to mean "we should > > unshare". Not really needed for follow page path, though. > > > > When at it, switching the try_grab_page() to use WARN_ON_ONCE(), to be > > clear that it just should never fail. When error happens, instead of > > setting page==NULL, capture the errno instead. > > > > Reviewed-by: Mike Kravetz > > Signed-off-by: Peter Xu > > --- > > mm/hugetlb.c | 31 ++++++++++++++++++++----------- > > 1 file changed, 20 insertions(+), 11 deletions(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index f75f5e78ff0b..27367edf5c72 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -6462,13 +6462,7 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, > > struct page *page = NULL; > > spinlock_t *ptl; > > pte_t *pte, entry; > > - > > - /* > > - * FOLL_PIN is not supported for follow_page(). Ordinary GUP goes via > > - * follow_hugetlb_page(). > > - */ > > - if (WARN_ON_ONCE(flags & FOLL_PIN)) > > - return NULL; > > + int ret; > > hugetlb_vma_lock_read(vma); > > pte = hugetlb_walk(vma, haddr, huge_page_size(h)); > > @@ -6478,8 +6472,21 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, > > ptl = huge_pte_lock(h, mm, pte); > > entry = huge_ptep_get(pte); > > if (pte_present(entry)) { > > - page = pte_page(entry) + > > - ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); > > + page = pte_page(entry); > > + > > + if ((flags & FOLL_WRITE) && !huge_pte_write(entry)) { > > + page = NULL; > > + goto out; > > + } > > + > > + if (gup_must_unshare(vma, flags, page)) { > > + /* Tell the caller to do unsharing */ > > + page = ERR_PTR(-EMLINK); > > + goto out; > > + } > > > No need to check if the page is writable (like all other callers and as > gup_must_unshare() documents -- "for which pages that are write-protected in > the page table") > > if (!huge_pte_write(entry) && gup_must_unshare(vma, flags, page)) { Sure. I was wondering whether we should just allow passing in "write" into gup_must_unshare(), it'll just be a bit weird that it'll return false directly if write, meanwhile hopefully that makes it easier to be consistent. I'll leave that as-is for now, anyway. For this one I'll just merge it into: if (!huge_pte_write(entry)) { if (flags & FOLL_WRITE) { page = NULL; goto out; } if (gup_must_unshare(vma, flags, page)) { /* Tell the caller to do unsharing */ page = ERR_PTR(-EMLINK); goto out; } } > > > With that > > Reviewed-by: David Hildenbrand Thanks, -- Peter Xu