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 3EFF9C433F5 for ; Sun, 8 May 2022 00:19:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B8FB6B0071; Sat, 7 May 2022 20:19:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 466EB6B0073; Sat, 7 May 2022 20:19:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E1EF6B0074; Sat, 7 May 2022 20:19:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1BA226B0071 for ; Sat, 7 May 2022 20:19:28 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id DF51680875 for ; Sun, 8 May 2022 00:19:27 +0000 (UTC) X-FDA: 79440666774.21.FB720C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 93D2B14008B for ; Sun, 8 May 2022 00:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651969166; 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=D8RQ/NBXUo1sDphRtbdglnAAjd1UBg3u9Ic5xtzocgM=; b=EPm33lFY618ZffmLGOrM/nb+R7+Rg9LfHvhGs2kOs8j3NMWzml0uWRfzgWkd/fenUGJYse l2REW0FbA72zHxnkKAavngu2fiCDwgciJjBS3vEaNzcrnXd6tEi3BmEss8nwRw5cCt4Rlg EtcmIvIm2RMs9batdEZFP+W6Jrqlyxg= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-kVeTpQBwMDSs9x8uY0vHCg-1; Sat, 07 May 2022 20:19:24 -0400 X-MC-Unique: kVeTpQBwMDSs9x8uY0vHCg-1 Received: by mail-qk1-f200.google.com with SMTP id y140-20020a376492000000b0069f7e985c95so7392417qkb.15 for ; Sat, 07 May 2022 17:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=D8RQ/NBXUo1sDphRtbdglnAAjd1UBg3u9Ic5xtzocgM=; b=clQyADwlsiTLfiD7wRTwjzoKixAannrmxmI86VGCajTVBF+lo65LHQ9QNwYQBcK8S2 5IGonIEJW0ajoX9REhJ8q93QKm3+4zkRaWG2VTX7st4h+Na86ajeyaahusM12d4UzMSJ B+69xXaXHxSK11QUaHPMznC5efb8EulVHMhvItlTkCYh+lsxtMZOQUvYrjLncIjU79pB X6nuutbvICl3/0qVEf+T3VTQzYFyHE4HIRDcLS6suOHK6JqSN4IXKz+OtYreI89Q6/QX gPheLEFh8IEnTocHsKnc+FVvXq8bzEq+oT5D3sT1A8xwEzu/i5FNI7xgGfa7z67TxXF1 WwLg== X-Gm-Message-State: AOAM533AeayNWrcFgtTrolPtO5nQyrQfB/irD28gOUv3lWTsJWixFgbh j15yEQ3ZRy20Jww+KzAwWFVjRfw1j0hw//kQl5QDX6xGmXUEu/xLREg4hT69T8tr7uhWm958nTT MF04YdvkhQas= X-Received: by 2002:a05:620a:2847:b0:67d:2bad:422f with SMTP id h7-20020a05620a284700b0067d2bad422fmr7502671qkp.559.1651969163930; Sat, 07 May 2022 17:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhYz6BDmqA0tlTwXwMx+7nJK9CIoatYh8eI+7kQRPiNqOGNPgaez+SXAKYyc0zKb3Qz8wdng== X-Received: by 2002:a05:620a:2847:b0:67d:2bad:422f with SMTP id h7-20020a05620a284700b0067d2bad422fmr7502659qkp.559.1651969163670; Sat, 07 May 2022 17:19:23 -0700 (PDT) Received: from [10.23.153.165] ([46.248.132.196]) by smtp.gmail.com with ESMTPSA id c138-20020ae9ed90000000b0069fc13ce211sm4544498qkg.66.2022.05.07.17.19.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 May 2022 17:19:22 -0700 (PDT) Message-ID: <5871724a-3a9c-75c8-15d9-d3f9fe31a3f0@redhat.com> Date: Sun, 8 May 2022 02:19:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v2] mm: fix is_pinnable_page against on cma page To: Andrew Morton , Minchan Kim Cc: linux-mm , LKML , "Paul E . McKenney" , John Hubbard , John Dias References: <20220505064429.2818496-1-minchan@kernel.org> <20220507122301.3b50eb030f9cd6f047f14352@linux-foundation.org> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220507122301.3b50eb030f9cd6f047f14352@linux-foundation.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 93D2B14008B X-Stat-Signature: zgkpforpsgntq6mbkejyizdytnqhwmzh Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EPm33lFY; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf26.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1651969164-740269 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 07.05.22 21:23, Andrew Morton wrote: > On Wed, 4 May 2022 23:44:29 -0700 Minchan Kim wrote: > >> Pages on CMA area could have MIGRATE_ISOLATE as well as MIGRATE_CMA >> so current is_pinnable_page could miss CMA pages which has MIGRATE_ >> ISOLATE. It ends up putting CMA pages longterm pinning possible on >> pin_user_pages APIs so CMA allocation fails. >> >> The CMA allocation path protects the migration type change race >> using zone->lock but what GUP path need to know is just whether the >> page is on CMA area or not rather than exact type. Thus, we don't >> need zone->lock but just checks the migratype in either of >> (MIGRATE_ISOLATE and MIGRATE_CMA). >> >> Adding the MIGRATE_ISOLATE check in is_pinnable_page could cause >> rejecting of pinning the page on MIGRATE_ISOLATE pageblock even >> thouth it's neither CMA nor movable zone if the page is temporarily > > "though" > >> unmovable. However, the migration failure is general issue, not >> only come from MIGRATE_ISOLATE and the MIGRATE_ISOLATE is also >> transient state like other temporal refcount holding of pages. >> >> ... >> >> --- a/include/linux/mm.h >> +++ b/include/linux/mm.h >> @@ -1625,8 +1625,18 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, >> #ifdef CONFIG_MIGRATION >> static inline bool is_pinnable_page(struct page *page) >> { >> - return !(is_zone_movable_page(page) || is_migrate_cma_page(page)) || >> - is_zero_pfn(page_to_pfn(page)); >> +#ifdef CONFIG_CMA >> + /* >> + * use volatile to use local variable mt instead of >> + * refetching mt value. >> + */ >> + volatile int mt = get_pageblock_migratetype(page); >> + >> + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) >> + return false; >> +#endif > > Open-coded use of `volatile' draws unwelcome attention. > > What are we trying to do here? Prevent the compiler from rerunning all > of get_pageblock_migratetype() (really __get_pfnblock_flags_mask()) > twice? That would be pretty dumb of it? > > Would a suitably-commented something like > > int __mt = get_pageblock_migratetype(page); > int mt = __READ_ONCE(__mt); > > express this better? Yes, we want READ_ONCE I think. Apart from that LGTM. -- Thanks, David / dhildenb