Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp352262pxb; Mon, 25 Oct 2021 09:30:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgWSoy5/aDeO2H1SG7y5x0wXVeDOf2lm5lwiVToyR14NAz9iKjt/kLuSLxa8O1mKoWyvb8 X-Received: by 2002:a17:902:b94b:b0:13d:b1af:f9d4 with SMTP id h11-20020a170902b94b00b0013db1aff9d4mr17668892pls.0.1635179455972; Mon, 25 Oct 2021 09:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635179455; cv=none; d=google.com; s=arc-20160816; b=GrnlLnYHXf+TTXaH244QQSi7cUThNabKYL2O0dEgZBBMlaJ9XEwCFFyXzUvwlGCVLs 7pRZf477V63W0NJept1FDG5MFqokNYy9fYdolUKLgapHpCFxPFL0a31tCFMm1qz83A0b BPu3XRzhoHamNlglsD2/BXJGL7l6BEz7AkiuTuhoIji/mqpZmKH2Kjpb2HPdTmHGZ8yV TnVgwJex/MWwT1dTCjXKw0t1Epkula2Wo6luCRkEorzYMrn0Ikhx1yykkt5iEJ6zqR5I 09/lITUqQA3/AAgevmup5CTA/IyvQ7lenEJCEmxu7gJ9UaoywTVFYYNVCZGIzaCcAYPA kkPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=g/bHWNbEVTUu1p1pY3zhFaw/B4nH/Dtxkz7BbwLJ14U=; b=sIX4WPEw6qeAbhF4oVWsO4czJIZUyJ4TvvOFKUn1uF/0wHVB1TyJ9jaDRG/sn7M5JQ ls298XOHCFv02HgaGfVFaFK42DB/nDFhogdiGrlCfCaEThV2BAh94VrySJcOPtMVcP5N PXrcc4sGFrua8468g6L9AmlyYj7C1PvPy1km2BS5sYfkpVm6SFn05X7Zxb2DpKnTSg80 YiDqBO2ElRbGVG8OqSTfSp2yx7fi5SZ6mwt8h3LN62hTu0PAYlUBCE7LeG4wMAIzY4ha /JWgyuJUZB21EcmLs75rTcjW5ZqDGT0+UmtCv/37b3vPAARkrJg3mdUujiMRECt986UT w7CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=aaaJn8Ce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si16171998pgh.201.2021.10.25.09.30.41; Mon, 25 Oct 2021 09:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=aaaJn8Ce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233913AbhJYQbg (ORCPT + 99 others); Mon, 25 Oct 2021 12:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbhJYQbf (ORCPT ); Mon, 25 Oct 2021 12:31:35 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA552C061745 for ; Mon, 25 Oct 2021 09:29:12 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id t7so11455063pgl.9 for ; Mon, 25 Oct 2021 09:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=g/bHWNbEVTUu1p1pY3zhFaw/B4nH/Dtxkz7BbwLJ14U=; b=aaaJn8CeCvh2LyKQmHk811Z9LqBaCi8WSPoU+cUqJghexKlravjNGfOOPb8ssVCCAX LwjqULdEu/3SYG7DlaswU9DD8m4LPHy9SCRh28KbqUFkVu/Xhxd1ISDw4Qb6uo9VoI7D jc5CSwlbCKJLhLKdVddBFpskz5Sa08QlKNyiiiGL6E7F/cWxTZa3ist4cLyR129HIZ6u cE+VolALQkWNdzM7Y6zfWLEwLPGmeqPSi0fhgZNSU69618ZdCutkVPjod/CHdqBIXmPr XDjAG9MPPCO4jGAQTSCkaD67ke8TpkR0gnKS0GSNER6NoKI82P+z+RFBTcc8eio8qykI Y84w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=g/bHWNbEVTUu1p1pY3zhFaw/B4nH/Dtxkz7BbwLJ14U=; b=7uDnAAqb4INTGka3nwMObP8k4nS+6sEo/UExMSwByYKSNmdqDO94ox5zmnycUK3kzb P1k4vsBZdvzUUKj50SMnCPSoQCNa5qOZ6APChdeTRZ6/+/u/e9FS48f+M+gMk6/Pz6M7 RlQO82x5s4y2e9tVCcFZdyXInL7kxbsHrxY8uJFH4LIBuELpwocymaxRuxYQb2nrsH+V EClk0Gjxr7eQCkz6WGjWT7BAsuiP9M6PYIVdDfx4wuWRo56KDsJcUT6nPuwfVy2eg3zm rrR+LwV1iH+v/+VQJEGMFN/4VFTYnKsRtl4wZJjDwoSg5kF8FyJ3+TpY4oM0iXcg8Rt2 heWQ== X-Gm-Message-State: AOAM5306yLEkNMj/CIyl2FxU4P1160/OtsSwbPDma1I2Q32NvOCZ5sGx dPUz08i2cKdHqFDcP80XqL8= X-Received: by 2002:a05:6a00:b85:b0:47b:ff97:841e with SMTP id g5-20020a056a000b8500b0047bff97841emr3612045pfj.48.1635179352143; Mon, 25 Oct 2021 09:29:12 -0700 (PDT) Received: from smtpclient.apple (c-24-6-216-183.hsd1.ca.comcast.net. [24.6.216.183]) by smtp.gmail.com with ESMTPSA id s3sm22337446pfu.84.2021.10.25.09.29.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Oct 2021 09:29:11 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: [PATCH v2 2/5] mm: avoid unnecessary flush on change_huge_pmd() From: Nadav Amit In-Reply-To: Date: Mon, 25 Oct 2021 09:29:09 -0700 Cc: Linux-MM , LKML , Andrea Arcangeli , Andrew Cooper , Andrew Morton , Andy Lutomirski , Dave Hansen , Peter Xu , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20211021122112.592634-1-namit@vmware.com> <20211021122112.592634-3-namit@vmware.com> To: Peter Zijlstra X-Mailer: Apple Mail (2.3654.120.0.1.13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Oct 25, 2021, at 3:52 AM, Peter Zijlstra = wrote: >=20 > On Thu, Oct 21, 2021 at 05:21:09AM -0700, Nadav Amit wrote: >> diff --git a/arch/x86/include/asm/pgtable.h = b/arch/x86/include/asm/pgtable.h >> index 448cd01eb3ec..18c3366f8f4d 100644 >> --- a/arch/x86/include/asm/pgtable.h >> +++ b/arch/x86/include/asm/pgtable.h >> @@ -1146,6 +1146,14 @@ static inline pmd_t pmdp_establish(struct = vm_area_struct *vma, >> } >> } >> #endif >> + >> +#define __HAVE_ARCH_PMDP_INVALIDATE_AD >> +static inline pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma, >> + unsigned long address, pmd_t = *pmdp) >> +{ >> + return pmdp_establish(vma, address, pmdp, pmd_mkinvalid(*pmdp)); >=20 > Did this want to be something like: >=20 > pmd_t old =3D pmdp_establish(vma, address, pmdp, = pmd_mkinvalid(*pmdp)); > if (cpu_feature_enabled(X86_BUG_PTE_LEAK)) > flush_pmd_tlb_range(vma, address, address + = HPAGE_PMD_SIZE); > return old; >=20 > instead? Yes. Of course. Where did my code go to? :( >=20 >> +} >> + >> /* >> * Page table pages are page-aligned. The lower half of the top >> * level is used for userspace and the top half for the kernel. >=20 >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >> index e5ea5f775d5c..435da011b1a2 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -1795,10 +1795,11 @@ int change_huge_pmd(struct vm_area_struct = *vma, pmd_t *pmd, >> * The race makes MADV_DONTNEED miss the huge pmd and don't = clear it >> * which may break userspace. >> * >> - * pmdp_invalidate() is required to make sure we don't miss >> - * dirty/young flags set by hardware. >> + * pmdp_invalidate_ad() is required to make sure we don't miss >> + * dirty/young flags (which are also known as access/dirty) = cannot be >> + * further modifeid by the hardware. >=20 > "modified", I think is the more common spelling. I tried to start a new trend. I will fix it. >=20 >> */ >> - entry =3D pmdp_invalidate(vma, addr, pmd); >> + entry =3D pmdp_invalidate_ad(vma, addr, pmd); >>=20 >> entry =3D pmd_modify(entry, newprot); >> if (preserve_write) >> diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c >> index 4e640baf9794..b0ce6c7391bf 100644 >> --- a/mm/pgtable-generic.c >> +++ b/mm/pgtable-generic.c >> @@ -200,6 +200,14 @@ pmd_t pmdp_invalidate(struct vm_area_struct = *vma, unsigned long address, >> } >> #endif >>=20 >> +#ifndef __HAVE_ARCH_PMDP_INVALIDATE_AD >=20 > /* > * Does this deserve a comment to explain the intended difference vs > * pmdp_invalidate() ? > */ I will add a comment.