Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2437789ioo; Sat, 28 May 2022 13:41:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywynh2JSBgX3UqQRJ+aAS56Vc6hrH6WIuEQVnHj78gMYlVkFW/WPJQzbRfG6v+V3N8FGaj X-Received: by 2002:a17:90a:5b0b:b0:1e2:8e28:1a61 with SMTP id o11-20020a17090a5b0b00b001e28e281a61mr7449751pji.187.1653770471463; Sat, 28 May 2022 13:41:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770471; cv=none; d=google.com; s=arc-20160816; b=PPjuYxsH1YDtdWHj92RM5Il+XY/aVchkpkldUgBaj0NFb+toV/p4wj5lnBbvTSAfA2 ZIEOTO+ZXvxGBQjVQ/a/Bqm4zZD2+9jU111euw7ri/QkcpBj+CeC63s9zfDzMxxMRSVu UyRTS3swlud+/kZJ59l5DNf7Opv6ECek1jZbjklGFjNlBUXwT6/vGOJNdmk2DrUldjHw EMSl8duOZwJBg2E1ExHfghdGKhc8R2Jq0x/U2LoqtpdJsmur0BdvlvMBRF4X9RNxRQwh iV2ebbfFSAL8mrVY10+OPbgtJkk1aWsLzhq/e+4yQdWKVT8x88TDVlosKrLyXFD4VgPB r2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Nt+n2haklMuWStLRmgRtCfZgoN7afB/xjurnhlibBtA=; b=ybdIzjw8G0y7jpz8A5c4HiM5CKLQ8vysnG16YPfpK0tLFY8JhhBIjygVYsVu4rleb/ pIKAAu6yTXM2FJA3by6FyHXK9QawuyvEhV7LV37QdNnNCMFpTf+04am7E0V8ZCr/yvCB xhSiViVW0a2x029hoANoae5iFX1Xqdr0j813zw2eOqqCm05l5/wYiXy9Yzy5ehW7xCNi mzgSKGsJ8kBAT+SLZmJ06LDs2uGoZ+9f4FYzSdN0USiHa65sS8BbGOU+Zsg+dxafDfPD OkwhQeko9rsKvLdGs3aeuBUQUlCs+jCCDHaP03Qm8xJfoFSVE3AAnrV9emiT1QI+Rdrn 0haw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=mdh4hUAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b0015e9ff43b64si5923971plg.585.2022.05.28.13.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:41:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=mdh4hUAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 290FC1C4B0C; Sat, 28 May 2022 12:46:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344907AbiEZNLu (ORCPT + 99 others); Thu, 26 May 2022 09:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244857AbiEZNLs (ORCPT ); Thu, 26 May 2022 09:11:48 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E29D6817 for ; Thu, 26 May 2022 06:11:46 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id gi33so2974287ejc.3 for ; Thu, 26 May 2022 06:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Nt+n2haklMuWStLRmgRtCfZgoN7afB/xjurnhlibBtA=; b=mdh4hUALSiiYooecz2d11OWfKfPev1AO99H5MjRa6BV8gFhSR5KjdOV7L8lCUi701X 3oE6KQ+1Pz6HNtSdOhN1ac/v1j7/wpJtJXG1c7Dh3jy9720CFNKoHEiAKmaYWREiK0ud YPTCe4Pc+4v24AnQM0uCl3U+MMV2GfyF3FlVlTaUgBDtnVSPu1My2a5HuiHpmoSOG1mv h2D8npJzXAq8jGEnX4q+C/5kLLFJGhzC4EXV/j+51zADBGxTb5cAvm9GkoMGrWR/n9dW F/fQMJIw96OTAOdjrFD8j/ghyoWQhiLQbiCcljv/HWdzPJ0F3RK7VneNeFgQnQq4WV71 GF3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Nt+n2haklMuWStLRmgRtCfZgoN7afB/xjurnhlibBtA=; b=VwSYozbtARaNQPQvWsqlhmbaPf6i5lLb6uSPKQ8ggCaq8H2J/GAnWvjBPvlLd6EORR gAQSFMb1LjeYw29gkkVc58IbG1DhbVOEMMMFkhzbaWRCIETyzMG+kf7v/Gfuf/9sW4TF 5GewGkje4X3MRZGuRgTqB4BlS2zfi/8Axp5Ba2N/JoUkC7RVt+o1uX4MsBUbUQ7VVkQ3 A64O1+YoV3/2mS3UlfGLj8q8x0vvrp/ad9GyvJOyS5cZVTzOn6Xee9llZVcAb6c1gktH /1U3i42qUTRBss8irFF/57WixUY/H2Z53rJtZsXQX8hik0IY+yNz0g9BSmnssguAxBUR kETQ== X-Gm-Message-State: AOAM5303TUtQ81Rv7pk7dldZaFzEERnzk+lleCFWxbOFFFtB8uIwLdIB pMHpnU9cljIdduFNsDaC/xyFYvQ40ZaMAyiJZSF7cw== X-Received: by 2002:a17:907:86a9:b0:6ff:45d:c05b with SMTP id qa41-20020a17090786a900b006ff045dc05bmr11989570ejc.492.1653570704863; Thu, 26 May 2022 06:11:44 -0700 (PDT) MIME-Version: 1.0 References: <20220526113350.30806-1-linmiaohe@huawei.com> <09f38cf3-282a-61fa-9916-057b01b57d30@bytedance.com> In-Reply-To: <09f38cf3-282a-61fa-9916-057b01b57d30@bytedance.com> From: Pasha Tatashin Date: Thu, 26 May 2022 09:11:07 -0400 Message-ID: Subject: Re: [PATCH] mm/page_table_check: fix accessing unmapped ptep To: Qi Zheng Cc: Miaohe Lin , Andrew Morton , David Rientjes , linux-mm , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Thu, May 26, 2022 at 9:04 AM Qi Zheng wrote: > > > > On 2022/5/26 7:33 PM, Miaohe Lin wrote: > > ptep is unmapped too early, so ptep will be accessed while it's unmapped. > > Fix it by deferring pte_unmap() until page table checking is done. > > In the beginning, page_table_check only supported x86_64, so there > is no problem. But then the commit 3fee229a8eb9 ("riscv/mm: enable > ARCH_SUPPORTS_PAGE_TABLE_CHECK") added support for riscv-32, it is > indeed a problem in this case. pte_unmap() is needed only with CONFIG_HIGHPTE. I do not see this config for riskv-32? Pasha > > So: > > Reviewed-by: Qi Zheng > > > > > Fixes: 80110bbfbba6 ("mm/page_table_check: check entries at pmd levels") > > Signed-off-by: Miaohe Lin > > --- > > mm/page_table_check.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/page_table_check.c b/mm/page_table_check.c > > index 3692bea2ea2c..971c3129b0e3 100644 > > --- a/mm/page_table_check.c > > +++ b/mm/page_table_check.c > > @@ -234,11 +234,11 @@ void __page_table_check_pte_clear_range(struct mm_struct *mm, > > pte_t *ptep = pte_offset_map(&pmd, addr); > > unsigned long i; > > > > - pte_unmap(ptep); > > for (i = 0; i < PTRS_PER_PTE; i++) { > > __page_table_check_pte_clear(mm, addr, *ptep); > > addr += PAGE_SIZE; > > ptep++; > > } > > + pte_unmap(ptep); > > } > > } > > -- > Thanks, > Qi