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=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 DD03CC2D0D2 for ; Fri, 20 Dec 2019 15:38:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A5C4121655 for ; Fri, 20 Dec 2019 15:38:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5C4121655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 359828E019F; Fri, 20 Dec 2019 10:38:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 309D58E019D; Fri, 20 Dec 2019 10:38:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 220058E019F; Fri, 20 Dec 2019 10:38:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 0C3FA8E019D for ; Fri, 20 Dec 2019 10:38:37 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 7FE2A181AEF09 for ; Fri, 20 Dec 2019 15:38:36 +0000 (UTC) X-FDA: 76285927032.09.hand22_2dfac9ad68404 X-HE-Tag: hand22_2dfac9ad68404 X-Filterd-Recvd-Size: 3504 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Dec 2019 15:38:35 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E063D30E; Fri, 20 Dec 2019 07:38:34 -0800 (PST) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 069513F6CF; Fri, 20 Dec 2019 07:38:33 -0800 (PST) From: Steven Price To: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Steven Price , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= Subject: [PATCH] mm/hmm: Cleanup hmm_vma_walk_pud()/walk_pud_range() Date: Fri, 20 Dec 2019 15:38:26 +0000 Message-Id: <20191220153826.24229-1-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: There are a number of minor misuses of the page table APIs in hmm_vma_walk_pud(): If the pud_trans_huge_lock() hasn't been obtained it might be because the PUD is unstable, so we should retry. If it has been obtained then there's no need for a READ_ONCE, and the PUD cannot be pud_none() or !pud_present() so these paths are dead code. Finally in walk_pud_range(), after a call to split_huge_pud() the code should check pud_trans_unstable() rather than pud_none() to decide whether the PUD should be retried. Suggested-by: Thomas Hellstr=C3=B6m (VMware) Signed-off-by: Steven Price --- This is based on top of my "Generic page walk and ptdump" series and fixes some pre-existing bugs spotted by Thomas. mm/hmm.c | 16 +++++----------- mm/pagewalk.c | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index a71295e99968..d4aae4dcc6e8 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -480,28 +480,22 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned l= ong start, unsigned long end, int ret =3D 0; spinlock_t *ptl =3D pud_trans_huge_lock(pudp, walk->vma); =20 - if (!ptl) + if (!ptl) { + if (pud_trans_unstable(pudp)) + walk->action =3D ACTION_AGAIN; return 0; + } =20 /* Normally we don't want to split the huge page */ walk->action =3D ACTION_CONTINUE; =20 - pud =3D READ_ONCE(*pudp); - if (pud_none(pud)) { - ret =3D hmm_vma_walk_hole(start, end, -1, walk); - goto out_unlock; - } + pud =3D *pudp; =20 if (pud_huge(pud) && pud_devmap(pud)) { unsigned long i, npages, pfn; uint64_t *pfns, cpu_flags; bool fault, write_fault; =20 - if (!pud_present(pud)) { - ret =3D hmm_vma_walk_hole(start, end, -1, walk); - goto out_unlock; - } - i =3D (addr - range->start) >> PAGE_SHIFT; npages =3D (end - addr) >> PAGE_SHIFT; pfns =3D &range->pfns[i]; diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 5895ce4f1a85..4598f545b869 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -154,7 +154,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long a= ddr, unsigned long end, =20 if (walk->vma) split_huge_pud(walk->vma, pud, addr); - if (pud_none(*pud)) + if (pud_trans_unstable(pud)) goto again; =20 err =3D walk_pmd_range(pud, addr, next, walk); --=20 2.20.1