From patchwork Mon May 22 05:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249760 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 2E4E9C77B73 for ; Mon, 22 May 2023 05:02:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C478690000A; Mon, 22 May 2023 01:02:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCFFE900002; Mon, 22 May 2023 01:02:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A991D90000A; Mon, 22 May 2023 01:02:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 95F87900002 for ; Mon, 22 May 2023 01:02:02 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6D66A1406B1 for ; Mon, 22 May 2023 05:02:02 +0000 (UTC) X-FDA: 80816694084.17.215ECD0 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) by imf02.hostedemail.com (Postfix) with ESMTP id 9C51680013 for ; Mon, 22 May 2023 05:02:00 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Q+WLY7Ro; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.180 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684731720; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=mhV/xeyYWEhdRXiGl/v2X560i4MBHD3gsaxPudVfcHZwkVfVcUO6FMjYFb+PgwiCiOBYQs 5WtF8/0P4aq2gldA2cQPj9DlqJ+ubDOeZVvlh/dyxphL3T+HBOIGtWOPRqHg+3zjTCA5jq jFkzfUmskflY8PRaBoFVOELJ0k99iVU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Q+WLY7Ro; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.180 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684731720; a=rsa-sha256; cv=none; b=iFrEIgcnlZh8RSS2mRawXEapMNSjqNA0KK782I0DO031Kz5DKS5VrWH/mIEnjMeaTQpHOY CQsVb6YcSMT6LX1rNTcQSGDO4lcO2aMw+PA9gK5RdvtP75h63/XwYZN1p11bO2biZ2rA44 O8ZnbnAKf9Sm7hV+mQN8UzYlqBKtE2s= Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-561b7729a12so45689857b3.1 for ; Sun, 21 May 2023 22:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684731720; x=1687323720; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=Q+WLY7Ro5SD5yNUAGTclzTje+VDS5OJwsYctg43k8TXzrg8fckZAOFDLbOpbv+Cz4d vusZX67zn6q4S5qUq6SfyoErvRul9hzMJrB3MRNnhQ6C5pPl/f+0Ug23z4gIrshnXudw uyL2XPYtPcLeaaYEa9djIcbbIiLW16k5noNko0Ixwnf5lma2IwkwvbUb6+ol9PyhD+iA SFpbS9+EhhrldJnU+af1fSiFWnx4LWMy4hftbnHOIsp4fFcbSzoqMd7Z+gmLZKCZGF9K xNYQslTPradcxr1kOt1BAZkUVCQ1AUWpnoyxrlCIdMtfrWBTqYrF1ShOS0ygR98FffYZ BJig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684731720; x=1687323720; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=PkfbMPBxn9AZMAtVTrjNRdYIfdULvS02lkFAIAQoe6t4Sx5H1+vGbl0gK/k0SFV4LR GAbN0NTFwhyUAOJ+YgElw5PsnELvv68HLjw+hshg5r74gOjRnXOF5nJeR2Tno0aZyGxB eFN0/qoyHqCLrQWTZ7pNXq1IvJ/vFIP+4K5Dq9yA8Q8vnkyXIx8ej1ZusCm0YR+YDIEX C3VznxKgsIWio4eWJLXsLMQB0yc1AJGJjqlXfBnc3liENXsjRYWzYM5cnSXdDS1xFyki Mgm7Ke3/X1rfENJbVXZLhHWDUYrWf6gxpb/RTotYQFEQUfVkMuM2PKq06PRTgUMn8aT3 +zEQ== X-Gm-Message-State: AC+VfDxlpX1ZIXbyUqA89utZnh6/vSXn7CPWeyzNHoUVJdQxaFEl14ad rdwQWpGHwfELYAmKKFcvrKE+mg== X-Google-Smtp-Source: ACHHUZ62zTVVW00Kw9P1qNrMirZM+5qrpLkNDTDbJjpW5hqzfUZErYJorH+/umfKDMFCMPWuq8GGOg== X-Received: by 2002:a0d:cc45:0:b0:55a:3502:d2ca with SMTP id o66-20020a0dcc45000000b0055a3502d2camr10051671ywd.13.1684731719564; Sun, 21 May 2023 22:01:59 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x67-20020a81a046000000b0054fcbf35b94sm1819620ywg.87.2023.05.21.22.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 22:01:59 -0700 (PDT) Date: Sun, 21 May 2023 22:01:56 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/31] mm/pagewalk: walk_pte_range() allow for pte_offset_map() In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9C51680013 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 36ef5n6m1cmo58xorbzdb961jt6tw45d X-HE-Tag: 1684731720-16481 X-HE-Meta: U2FsdGVkX1/M2EflRfGVu6FLEBlY4u1h8Az2bTX9xZ7i+4UovpMyKTkqznqJgOnoGCsdc6PJ2krYMHaJ+ZWO8sj31c3z4cNozMt1ybU43lP7YPsqtsbs9BYYsD9zJSrAOJZ3DhKpFuyrGgAhM8E+W1P4bR7Uv+MGHdc4+qJEUyJwaaO3TRz6xVY+i4oJaJSrqlIJk9pTWGNT5pEyVVDDTJDU8x5i77xXvv6hQMpl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CHADw1Xd1gokQlMDWRI/FGpt+UWS8WVhIzbG7N4jGIxpX1K0eqOrqEys0AC9Rsq+pi4MgYEMFTwfqXIGIjYWPVrUqahemVZYOyDJi+frc/nuhyAo1A== 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: walk_pte_range() has a no_vma option to serve walk_page_range_novma(). I don't know of any problem, but it looks safer to check for init_mm, and use pte_offset_kernel() rather than pte_offset_map() in that case: pte_offset_map()'s pmdval validation is intended for userspace. Allow for its pte_offset_map() or pte_offset_map_lock() to fail, and retry with ACTION_AGAIN if so. Add a second check for ACTION_AGAIN in walk_pmd_range(), to catch it after return from walk_pte_range(). Remove the pmd_trans_unstable() check after split_huge_pmd() in walk_pmd_range(): walk_pte_range() now handles those cases safely (and they must fail powerpc's is_hugepd() check). Signed-off-by: Hugh Dickins --- mm/pagewalk.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index cb23f8a15c13..64437105fe0d 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -46,15 +46,27 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, spinlock_t *ptl; if (walk->no_vma) { - pte = pte_offset_map(pmd, addr); - err = walk_pte_range_inner(pte, addr, end, walk); - pte_unmap(pte); + /* + * pte_offset_map() might apply user-specific validation. + */ + if (walk->mm == &init_mm) + pte = pte_offset_kernel(pmd, addr); + else + pte = pte_offset_map(pmd, addr); + if (pte) { + err = walk_pte_range_inner(pte, addr, end, walk); + if (walk->mm != &init_mm) + pte_unmap(pte); + } } else { pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); - err = walk_pte_range_inner(pte, addr, end, walk); - pte_unmap_unlock(pte, ptl); + if (pte) { + err = walk_pte_range_inner(pte, addr, end, walk); + pte_unmap_unlock(pte, ptl); + } } - + if (!pte) + walk->action = ACTION_AGAIN; return err; } @@ -141,11 +153,8 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, !(ops->pte_entry)) continue; - if (walk->vma) { + if (walk->vma) split_huge_pmd(walk->vma, pmd, addr); - if (pmd_trans_unstable(pmd)) - goto again; - } if (is_hugepd(__hugepd(pmd_val(*pmd)))) err = walk_hugepd_range((hugepd_t *)pmd, addr, next, walk, PMD_SHIFT); @@ -153,6 +162,10 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, err = walk_pte_range(pmd, addr, next, walk); if (err) break; + + if (walk->action == ACTION_AGAIN) + goto again; + } while (pmd++, addr = next, addr != end); return err;