Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1438544rwd; Thu, 8 Jun 2023 18:45:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WJuSL9mCSArJbzfhafBVLXZ1tp0nVK8QfJ3/iiXhCy6iJ+CRGZpzG+1frzUMb9vLiMHsT X-Received: by 2002:a92:cacd:0:b0:338:b798:75b2 with SMTP id m13-20020a92cacd000000b00338b79875b2mr280230ilq.26.1686275127934; Thu, 08 Jun 2023 18:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686275127; cv=none; d=google.com; s=arc-20160816; b=tfCmj1Q9YkwqBA+ULkUYrUwiju2HoYfphKrqaXDspVDVmZnBEkts3bU8zc2BlOhpaF 081QCtYWQfaAB8d/AJCHSfkZcddzKm1B5+oDyzVrQoZzb0K+wCVLxSChlSAnAs62e7oz MKzYsHwsBd6GS6/00ulJAf/3mz1mwAyNIP5cXrDzz9PAMYZ1B2RqzGUWtBk2J71IsrPz Wt+88yae19SPVf7ttwi1mCdmOmnBtlDaMuSJo3rJ3Oo59vUsS8pD5Do3JWEIEtuh0Ol0 GDKRHRhd8jjV1G4SPrNyLvHFg2vYsKNGZmWUr/cO8VFok8bT+rI5r1/osTqDHurET35V +X1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=s/wneZk+WXTrjMA3fZuua9PXiv3fUuHnEiWoD80tgK8=; b=u8l/hCQztTiQVhd25OzspXWo1Ofr+6V2vxqdepO5v4JNhSda/yuAHQG0u/iJO0oeZI CPh0qFLfEtpFEs2kT7lYcNijiAZuyqiwJRlRJg6F/nShKdMJK4FlDqgcvs8GJ/fu77s9 b4XNs0E43Z6dc/YIf42wnhdYPld5lrbSrX/I+CmYn5iwvDU311TKqLvjBcnYKdgK8viu ZhGoWNEGSw4CcZQuXq+c6Dw9zb5QoBLFdv3C1ALxZrx/Xbutw00TP2bIlhAfaI1RhUaB mWBipBvgN5r+EpcjhRMtZ1X3zoa2N5W9TlAU5yE+qgst8m+5/DfMj6eIi9ed/M/3e8PH h6lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ngXLVdTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k16-20020a628410000000b00653a95c829asi1660423pfd.256.2023.06.08.18.45.15; Thu, 08 Jun 2023 18:45:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ngXLVdTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237480AbjFIBS6 (ORCPT + 99 others); Thu, 8 Jun 2023 21:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjFIBS4 (ORCPT ); Thu, 8 Jun 2023 21:18:56 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1816319AC for ; Thu, 8 Jun 2023 18:18:55 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-ba86ea269e0so1277519276.1 for ; Thu, 08 Jun 2023 18:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686273534; x=1688865534; 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=ngXLVdTpVyrnOmcx9sqd11fDN/DpMfDjRFc20sS67KuKXUBPfJVN7b54WivfwCCqcm 2w8p0+WuKxMdG7YLSaNER90dnOHjPSlvPspYoe5kIeMhFky06+Enxr+OKG3u1lmvAOqa C+PVbym1M2SnYvLxMqSZg33YxKhOPm3FgR9jzQ+MnLfZGFUC2OJbbjuScpkVkepg/TEp 276YbysaG6RpeWzjjsraxwjBqi8YR2LoYFLfcozNIrD2bqcAOk2V+q1v/295yDeTTnP9 TfyYNMuGFwQjegWuOVfz1GKj11hEcBHgzfIvjlO8LY2ikBAtYqRoDenRCee7HmvBFb1A njIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686273534; x=1688865534; 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=YMauREB2g/iRaGULaR5xRwXHQNiURkiWyM9zw8gV41v7LapBeB1Q4asogV3syiepZY IIeeM1puuqXlhTpwsm4ZSfOLIPm2J0JoUwww824VOkPl+X2QX4sRVIdvDoXfWUFSSM/j dJbFrZTyFifDHtmPBf24L9GyncP3pLXw8IGuGhTZeuv0J5hfYYggiYM7YdJugrhWhE7+ fMRsCVV+MZqIf/9ZCx23M0KPmq2ORQ83jyB8SP6Wf7fZaoJdHYSUr2ySrU4SH24IvYuz 4hDO8G4+s5w4xlphA/0RA6KZVoTPqtDtDboipD9n480up6Q8YVnylbeCJ8gZFwkH7wK2 WBOw== X-Gm-Message-State: AC+VfDwwuaul5n0n5OVStHTBr9NNgrTa7Ai/T59vbwC///rjjcF5XE+a Fk7rOH5W1c0jI3/y11iMfeTwag== X-Received: by 2002:a25:d757:0:b0:ba7:ff37:4603 with SMTP id o84-20020a25d757000000b00ba7ff374603mr1178588ybg.45.1686273534119; Thu, 08 Jun 2023 18:18:54 -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 v38-20020a25aba9000000b00b923b2935d9sm603286ybi.20.2023.06.08.18.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:18:53 -0700 (PDT) Date: Thu, 8 Jun 2023 18:18:49 -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 , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 10/32] mm/pagewalk: walk_pte_range() allow for pte_offset_map() In-Reply-To: Message-ID: <3eba6f0-2b-fb66-6bb6-2ee8533e221@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.35.3