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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 2E8CAC3F68F for ; Thu, 23 Jan 2020 08:23:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ECB362468C for ; Thu, 23 Jan 2020 08:23:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECB362468C 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 90D3B6B0005; Thu, 23 Jan 2020 03:23:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BD686B0007; Thu, 23 Jan 2020 03:23:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D3516B0008; Thu, 23 Jan 2020 03:23:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 6877E6B0005 for ; Thu, 23 Jan 2020 03:23:14 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 21CEB2C8B for ; Thu, 23 Jan 2020 08:23:14 +0000 (UTC) X-FDA: 76408209108.09.heart35_7373bfd69364e X-HE-Tag: heart35_7373bfd69364e X-Filterd-Recvd-Size: 3603 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jan 2020 08:23:13 +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 4AADB1FB; Thu, 23 Jan 2020 00:23:12 -0800 (PST) Received: from [10.162.16.32] (p8cg001049571a15.blr.arm.com [10.162.16.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA1773F6C4; Thu, 23 Jan 2020 00:26:43 -0800 (PST) Subject: Re: [PATCH 0/2] mm/thp: rework the pmd protect changing flow To: Xuefeng Wang , catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, arnd@arndb.de, akpm@linux-foundation.org Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chenzhou10@huawei.com References: <20200123075514.15142-1-wxf.wang@hisilicon.com> From: Anshuman Khandual Message-ID: <50493410-c44c-7ef0-81f9-d4ce9a525c1f@arm.com> Date: Thu, 23 Jan 2020 13:54:32 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200123075514.15142-1-wxf.wang@hisilicon.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 01/23/2020 01:25 PM, Xuefeng Wang wrote: > On KunPeng920 board. When changing permission of a large range region, > pmdp_invalidate() takes about 65% in profile (with hugepages) in JIT tool. > Kernel will flush tlb twice: first flush happens in pmdp_invalidate, second > flush happens at the end of change_protect_range(). The first pmdp_invalidate > is not necessary if the hardware support atomic pmdp changing. The atomic > changing pimd to zero can prevent the hardware from update asynchronous. > So reconstruct it and remove the first pmdp_invalidate. And the second tlb > flush can make sure the new tlb entry valid. > > This patch series add a pmdp_modify_prot transaction abstraction firstly. > Then add pmdp_modify_prot_start() in arm64, which uses pmdp_huge_get_and_clear() > to atomically fetch the pmd and zero the entry. There is a comment section in change_huge_pmd() which details how clearing the PMD entry there (in prot_numa case) can potentially race with another concurrent madvise(MADV_DONTNEED, ..) call. Here is the comment block for reference. /* * In case prot_numa, we are under down_read(mmap_sem). It's critical * to not clear pmd intermittently to avoid race with MADV_DONTNEED * which is also under down_read(mmap_sem): * * CPU0: CPU1: * change_huge_pmd(prot_numa=1) * pmdp_huge_get_and_clear_notify() * madvise_dontneed() * zap_pmd_range() * pmd_trans_huge(*pmd) == 0 (without ptl) * // skip the pmd * set_pmd_at(); * // pmd is re-established * * 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. */ By defining the new override with pmdp_huge_get_and_clear(), are not we now exposed to above race condition ? - Anshuman