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=unavailable 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 8B252C433C1 for ; Tue, 23 Mar 2021 12:16:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C1516197F for ; Tue, 23 Mar 2021 12:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhCWMQD (ORCPT ); Tue, 23 Mar 2021 08:16:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:14435 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbhCWMPr (ORCPT ); Tue, 23 Mar 2021 08:15:47 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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! :) > >>> >> . >> >