Received: by 10.192.165.148 with SMTP id m20csp407928imm; Fri, 27 Apr 2018 00:38:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrButnAmAwF450AfFhZ+0+sCuUfHpRJliJH/GvhJuJg4k/7r4J/rRQ1xBuZNcEis7VDQNZZ X-Received: by 10.98.103.86 with SMTP id b83mr1257989pfc.76.1524814735628; Fri, 27 Apr 2018 00:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524814735; cv=none; d=google.com; s=arc-20160816; b=cjTt1gPid+wjz+QLbWvPuUg9IEcsFsN1stFADOqoON9oKxlf0vy39WRYaJ+mBMQsLg WO2OXDEMwwgzybrfKwNGdlmZlkUzbCESrOpxCGB0Kvq0rJnpbJ6DLYL2SCNWE11W/8Tk qrKTElCXKcsDIdP/BcZ86WR5lgGauCQFJf1Ky6Yat9D91CojtDwppWNyyxJnrdl1FCyv ttj+bRs8BbIc1ofoQOiXgTR8JOR5MdxVVcoJCibGERFfDlk88mBWj2jStMdF5yVjk6qt YK7+RwxdKpCXbWfP8VPv5M9QHVviV9sXuHR2cDFxU3aCRlRD/Px7e4Ldue8TrrMtjqAt wdCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=v24zbuhNacBOL1ckcgXNEVNpXwUT6OPieElkokLJd3E=; b=iOwQmxPMgXKPA0ZA/wMCCkYhWh36ABangGQm0HRapLsFZm5uSwyINQzLi6ZWWMdEnz uA0PfcFrepIyfdIkcQJyCSXm/80EWfqvR3TMwtHCIfYb30ROmF+a8KoGx21JW1/dgPDM GI4sP0C9ByZsSE6VP8foCi/6kp30NcxAV8CtJN481TtrOZyjJ2vB1mIJUW1jMU/WUt7i k3eUSVAGLL24CuK1PUUFGBQXjtKfAqDOcOrCpN0om9T+w8mWm0LFa8KskBcqEOjFXyvy emGKFtiqNlOnEs7vIHZDYNiMKK0j7Dt5Zx/8alWvghDC9sVCdChUJw88s1Owg3RNz37e myhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=YH2gdzp6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si732982pgs.508.2018.04.27.00.38.41; Fri, 27 Apr 2018 00:38:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=YH2gdzp6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757588AbeD0Hh1 (ORCPT + 99 others); Fri, 27 Apr 2018 03:37:27 -0400 Received: from 8bytes.org ([81.169.241.247]:35940 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757171AbeD0HhV (ORCPT ); Fri, 27 Apr 2018 03:37:21 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 53AE12DC; Fri, 27 Apr 2018 09:37:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1524814640; bh=MyTF3TL6b+s4qS8puHvB2JqP1PrljXUeu3jsYk3V1Og=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YH2gdzp6GnZn9yYk49btaRQxCubThH5X03JSGEOONJBj42uTgIhmP9Hf9KBnQmTJG K+TKQ9GKUCLf2QYHvXClnfP/UgBMq/YQ83tJqpAdX06IT8q+lPfGtRr5IcrlPBdIlV 1N0xsKSmzZwLitTlKBcRR/RbrQX0Q9DI2sz6GI5lHxeHMexmqSrP1EZFxEuKf3OmIC 6xYSAo8Ghx+JBhh9Dmr0Ytm0DGVBEUS9t1YZOQeGKODrVp2ME5VGQQ6RwccG1ibwyP PmeD/zHe6ef5MPwPGvMPE91j5Egd0+puXWHh6EZj8wcAMWZ1BR/WNT0XO4f8ZS/Ah7 jJ+cYPmHhs13A== Date: Fri, 27 Apr 2018 09:37:20 +0200 From: "joro@8bytes.org" To: "Kani, Toshi" Cc: "linux-kernel@vger.kernel.org" , "bp@suse.de" , "tglx@linutronix.de" , "linux-mm@kvack.org" , "guohanjun@huawei.com" , "wxf.wang@hisilicon.com" , "stable@vger.kernel.org" , "x86@kernel.org" , "akpm@linux-foundation.org" , "willy@infradead.org" , "hpa@zytor.com" , "catalin.marinas@arm.com" , "mingo@redhat.com" , "will.deacon@arm.com" , "Hocko, Michal" , "cpandya@codeaurora.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v2 2/2] x86/mm: implement free pmd/pte page interfaces Message-ID: <20180427073719.GT15462@8bytes.org> References: <20180314180155.19492-1-toshi.kani@hpe.com> <20180314180155.19492-3-toshi.kani@hpe.com> <20180426141926.GN15462@8bytes.org> <1524759629.2693.465.camel@hpe.com> <20180426172327.GQ15462@8bytes.org> <1524764948.2693.478.camel@hpe.com> <20180426200737.GS15462@8bytes.org> <1524781764.2693.503.camel@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1524781764.2693.503.camel@hpe.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 26, 2018 at 10:30:14PM +0000, Kani, Toshi wrote: > Thanks for the clarification. After reading through SDM one more time, I > agree that we need a TLB purge here. Here is my current understanding. > > - INVLPG purges both TLB and paging-structure caches. So, PMD cache was > purged once. > - However, processor may cache this PMD entry later in speculation > since it has p-bit set. (This is where my misunderstanding was. > Speculation is not allowed to access a target address, but it may still > cache this PMD entry.) > - A single INVLPG on each processor purges this PMD cache. It does not > need a range purge (which was already done). > > Does it sound right to you? The right fix is to first synchronize the changes when the PMD/PUD is cleared and then flush the TLB system-wide. After that is done you can free the page. But doing all that in the pud/pmd_free_pmd/pte_page() functions is too expensive, as the TLB flush requires to send IPIs to all cores in the system, and that every time the function is called. So what needs to be done is to fix this from high-level ioremap code to first unmap all required PTE/PMD pages and collect them in a list. When that is done you can synchronize the changes with the other page-tables in the system and do one system-wide TLB flush. When that is complete you can free the pages on the list that were collected while unmapping. Then the new mappings can be established and again synchronized with the other page-tables in the system. > As for the BUG_ON issue, are you able to reproduce this issue? If so, > would you be able to test the fix? Yes, I can reproduce the BUG_ON with my PTI patches and a fedora-i386 VM. I already ran into the issue before your patches were merged upstream, but my "fix" is different because it just prevents huge-mappings when there were smaller mappings before. See e3e288121408 x86/pgtable: Don't set huge PUD/PMD on non-leaf entries for details. This patch does not fix the base-problem, but hides it again, as the real fix needs some more work across architectures. Your patch actually makes the problem worse, without it the PTE/PMD pages were just leaked, so that they could not be reused. But with your patch the pages can be used again and the page-walker might establish TLB entries based on random content the new owner writes to it. This can lead to all kinds of random and very hard to debug data corruption issues. So until we make the generic ioremap code in lib/ioremap.c smarter about unmapping/remapping ranges the best solution is making my fix work again by reverting your patch. Thanks, Joerg