Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15799079rwd; Mon, 26 Jun 2023 01:14:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50aIMgo9RnhocfrS4sRV1J/pAkZZkqEU4dm8oHWGExx8ygGI4ukTJjIPnYTr2TMMg69J/M X-Received: by 2002:a05:6402:50cd:b0:516:a1d5:846f with SMTP id h13-20020a05640250cd00b00516a1d5846fmr30732046edb.1.1687767245174; Mon, 26 Jun 2023 01:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687767245; cv=none; d=google.com; s=arc-20160816; b=Xv9uwFdBu3JEZLMUTuApCaSZwGyPSYSfSE2a/Rk/kFD2pALcy/oJNU9ak0wzQAm2Fy NuxYIUtPxI3wBPjtCwgjsGRHk+3I7FqDzDHQfmLMFxUCIw64i2NYD3sTgGcAkJ4JHBAs e4lb7xWLuIuuKCsn61M4Dw70yPcmj2bdeQ31sNsgpD3ifPNRoGjwrTmQJLa4dD4DVU8k 6jWjDwEbKf1VOiwhYlb64nJhoQtoT1q2lpPbsXas4q5313U2Oj+6ZvVx6/dYFrl5kPH3 ksEY2eUkgs/KUiHiiHusXDIzPK8+zwK0/XVPhHFcnIzggvyBJPkKaINqWuFU7Kn08QLF i0BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=bdy6ilB9MCEHjnSXB3UxFLYarjo26SKIUeQi/Jp98Ng=; fh=qwBehi8McT2nubRUemYpqDiqDkppJC7G8i/GgZ5RmZY=; b=MKZR94h2hAWBLal2Xg5kIVtjnrUdakA5xtxiF0gGYl0MweMmUeb/zPtTEg7YW8zhcB iFIajIaqJSDMhsS/85rf3yM+3hWSCHv6QtxONdBitplutzKNJxMcA3mNZgHhFn9zBQPP 6pnzVnRlOGFHG8pQ6hDvYj33WziLUesSbNYsDRHsAk5jwGo+usRDJNchwx1T5rEL62DF p8IFxknsoWgffS2t8EtmsIdsBw0WhFqSEeMDiD1QdGeo2SMMxiUZ8fZNhqn7u9frVHhk SpZsIVuVPe8mkmST1zoKhlCuvsOS/Ia0IewyRgZSOdZA6Myy1avYG7Kp5BtjZW3lqBAS YNUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fseRFZ2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020aa7d946000000b0051a59360fdbsi2446604eds.514.2023.06.26.01.13.40; Mon, 26 Jun 2023 01:14:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fseRFZ2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbjFZIHW (ORCPT + 99 others); Mon, 26 Jun 2023 04:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjFZIHU (ORCPT ); Mon, 26 Jun 2023 04:07:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB12C83 for ; Mon, 26 Jun 2023 01:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687766791; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bdy6ilB9MCEHjnSXB3UxFLYarjo26SKIUeQi/Jp98Ng=; b=fseRFZ2Y1C86eQ4Ycewy0oPh723ulsVvm8pgKTZWC5KH08TabAuhac1yZJB/BUeBuVJZZE S4PHbwBXCD1PiR2pbGOYvngX9sJxsEK76m3A18b3SoHZWITy6poSkI+frJpx0KKPv7cIjA K0591gMt08R7+Uh7r/dGVMCV2FX8VuQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-DwZpn1tsOHC4lmOapfi0fQ-1; Mon, 26 Jun 2023 04:06:27 -0400 X-MC-Unique: DwZpn1tsOHC4lmOapfi0fQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-313f3c115eeso192691f8f.0 for ; Mon, 26 Jun 2023 01:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687766786; x=1690358786; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bdy6ilB9MCEHjnSXB3UxFLYarjo26SKIUeQi/Jp98Ng=; b=P57eFJ32SXLmDHsQG6QImxE0FMdgFMDHT8uiMooTG+QzDvvXjnBcse5kjU3cYAF9/X eBbbPlv281D/vC5DdRQD1IX5KSpBqFbL+ubQGa1JG8ii1ic93jI2ET9C0R8e5/e85MYa efLnix21ta/Cg2Fh3I7NYYtxQnOlP+mdt1tb4C6WihY1Dm81Jfa6Qscc2nY1b25RaOaJ 61depiJUebRu80wDFfzu9Z/njSxJtisxX7UXCg/3P+1aBteHePVwF2zaWEq0cttUUwY1 PueLjHYEPWScR7QGcuyw5EM17SjuCv5c0hRLl7gA+oREsPhnVlxxS6dRJB7/KsGokQUQ bkQw== X-Gm-Message-State: AC+VfDw+u/1UeAegsIWjeqvA/rU5g+9VB9bJPprZL/L+080Rj2j3NYMq AFceT7YbHbx3cukMoVTyUSQpd/l7vZLVcczgHMq7kISeuXGTyQ02ui9QwcuUCv034OojjrxZMf0 iPQF2IM5e7SnX0RpYqHhwaTWz X-Received: by 2002:a5d:5507:0:b0:313:e5ca:7517 with SMTP id b7-20020a5d5507000000b00313e5ca7517mr4774726wrv.9.1687766786181; Mon, 26 Jun 2023 01:06:26 -0700 (PDT) X-Received: by 2002:a5d:5507:0:b0:313:e5ca:7517 with SMTP id b7-20020a5d5507000000b00313e5ca7517mr4774703wrv.9.1687766785754; Mon, 26 Jun 2023 01:06:25 -0700 (PDT) Received: from ?IPV6:2003:cb:c74b:7300:2ef6:6cd6:703c:e498? (p200300cbc74b73002ef66cd6703ce498.dip0.t-ipconnect.de. [2003:cb:c74b:7300:2ef6:6cd6:703c:e498]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm6559048wrp.101.2023.06.26.01.06.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Jun 2023 01:06:25 -0700 (PDT) Message-ID: <89fee4bf-29a1-db19-e0ae-dd827d277504@redhat.com> Date: Mon, 26 Jun 2023 10:06:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: 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 References: <20230623142936.268456-1-peterx@redhat.com> <20230623142936.268456-3-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3 2/8] mm/hugetlb: Prepare hugetlb_follow_page_mask() for FOLL_PIN In-Reply-To: <20230623142936.268456-3-peterx@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)) { With that Reviewed-by: David Hildenbrand -- Cheers, David / dhildenb