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=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 AC879C43457 for ; Thu, 15 Oct 2020 12:58:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DF2C22255 for ; Thu, 15 Oct 2020 12:58:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DF2C22255 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D8F8C900002; Thu, 15 Oct 2020 08:58:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D18D46B0062; Thu, 15 Oct 2020 08:58:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C06C5900002; Thu, 15 Oct 2020 08:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 954196B005D for ; Thu, 15 Oct 2020 08:58:56 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1F1361EF1 for ; Thu, 15 Oct 2020 12:58:56 +0000 (UTC) X-FDA: 77374164672.25.side96_1a0e4d827214 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id E15BE1804E3A8 for ; Thu, 15 Oct 2020 12:58:55 +0000 (UTC) X-HE-Tag: side96_1a0e4d827214 X-Filterd-Recvd-Size: 2417 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 12:58:55 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DD768ABD1; Thu, 15 Oct 2020 12:58:53 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 15 Oct 2020 14:58:53 +0200 From: osalvador@suse.de To: Shijie Luo Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linmiaohe@huawei.com, linfeilong@huawei.com Subject: Re: [PATCH] mm: fix potential pte_unmap_unlock pte error In-Reply-To: <20201015121534.50910-1-luoshijie1@huawei.com> References: <20201015121534.50910-1-luoshijie1@huawei.com> User-Agent: Roundcube Webmail Message-ID: X-Sender: osalvador@suse.de 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 2020-10-15 14:15, Shijie Luo wrote: > When flags don't have MPOL_MF_MOVE or MPOL_MF_MOVE_ALL bits, code > breaks > and passing origin pte - 1 to pte_unmap_unlock seems like not a good > idea. > > Signed-off-by: Shijie Luo > Signed-off-by: linmiaohe > --- > mm/mempolicy.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index 3fde772ef5ef..01f088630d1d 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -571,7 +571,11 @@ static int queue_pages_pte_range(pmd_t *pmd, > unsigned long addr, > } else > break; > } > - pte_unmap_unlock(pte - 1, ptl); > + > + if (addr >= end) > + pte = pte - 1; > + > + pte_unmap_unlock(pte, ptl); But this is still wrong, isn't it? Unless I am missing something, this is "only" important under CONFIG_HIGHPTE. We have: pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); which under CONFIG_HIGHPTE does a kmap_atomoc. Now, we either break the loop in the first pass because of !(MPOL_MF_MOVE | MPOL_MF_MOVE_ALL), or we keep incrementing pte by every pass. Either way is wrong, because the pointer kunmap_atomic gets will not be the same (since we incremented pte). Or is the loop meant to be running only once, so pte - 1 will bring us back to the original pte?