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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 6E544C433C1 for ; Tue, 23 Mar 2021 12:15:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B9654619B1 for ; Tue, 23 Mar 2021 12:15:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9654619B1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2EE216B0187; Tue, 23 Mar 2021 08:15:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29DD36B0189; Tue, 23 Mar 2021 08:15:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 124D36B018A; Tue, 23 Mar 2021 08:15:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id E7F366B0187 for ; Tue, 23 Mar 2021 08:15:49 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A67251E14 for ; Tue, 23 Mar 2021 12:15:49 +0000 (UTC) X-FDA: 77951035218.12.D6CA52E Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf24.hostedemail.com (Postfix) with ESMTP id 4E1ABA000847 for ; Tue, 23 Mar 2021 12:15:47 +0000 (UTC) Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F4Vf466rNzkcKd; Tue, 23 Mar 2021 20:14:04 +0800 (CST) Received: from [10.174.178.163] (10.174.178.163) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Mar 2021 20:15:39 +0800 Subject: Re: [PATCH 3/5] mm/migrate.c: fix potential indeterminate pte entry in migrate_vma_insert_page() From: Miaohe Lin To: Alistair Popple CC: David Hildenbrand , , , , , linux-kernel References: <20210320093701.12829-1-linmiaohe@huawei.com> <20210320093701.12829-4-linmiaohe@huawei.com> <0bee2243-5771-4969-7b92-aaca67abc90c@redhat.com> <5999334.9xz1uWCbsP@nvdebian> Message-ID: Date: Tue, 23 Mar 2021 20:15:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.163] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4E1ABA000847 X-Stat-Signature: cyds8n6nfgwzkkjy5wmapaajwbx14jsw Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=szxga06-in.huawei.com; client-ip=45.249.212.32 X-HE-DKIM-Result: none/none X-HE-Tag: 1616501747-349491 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 2021/3/23 19:28, Miaohe Lin wrote: > On 2021/3/23 19:07, Alistair Popple wrote: >> On Tuesday, 23 March 2021 9:26:43 PM AEDT David Hildenbrand wrote: >>> On 20.03.21 10:36, Miaohe Lin wrote: >>>> If the zone device page does not belong to un-addressable device memory, >>>> the variable entry will be uninitialized and lead to indeterminate pte >>>> entry ultimately. Fix this unexpectant case and warn about it. >>> >>> s/unexpectant/unexpected/ >>> >>>> >>>> Fixes: df6ad69838fc ("mm/device-public-memory: device memory cache >> coherent with CPU") >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/migrate.c | 7 +++++++ >>>> 1 file changed, 7 insertions(+) >>>> >>>> diff --git a/mm/migrate.c b/mm/migrate.c >>>> index 20a3bf75270a..271081b014cb 100644 >>>> --- a/mm/migrate.c >>>> +++ b/mm/migrate.c >>>> @@ -2972,6 +2972,13 @@ static void migrate_vma_insert_page(struct >> migrate_vma *migrate, >>>> >>>> swp_entry = make_device_private_entry(page, vma->vm_flags & >> VM_WRITE); >>>> entry = swp_entry_to_pte(swp_entry); >>>> + } else { >>>> + /* >>>> + * For now we only support migrating to un-addressable >>>> + * device memory. >>>> + */ >>>> + WARN_ON(1); >>>> + goto abort; >>> >>> Fix it by crashing the kernel with panic_on_warn? :) >>> >>> If this case can actual happen, than no WARN_ON() - rather a >>> pr_warn_once(). If this case cannot happen, why do we even care (it's >>> not a fix then)? >> >> There is also already a check for this case in migrate_vma_pages(). The >> problem is it happens after the call to migrate_vma_insert_page(). I wonder if >> instead it would be better just to move the existing check to before that >> call? >> > While look at this more closely, move the existing check to before migrate_vma_insert_page() could potentially change the current mmu_notifier semantics against anonymous zero page. :( So check zone device page inside migrate_vma_insert_page() would be more acceptable. Many thanks. > Yes, sounds good! Many thanks for your advice! :) > >>> >> . >> >