Received: by 10.192.165.148 with SMTP id m20csp2197834imm; Thu, 26 Apr 2018 07:21:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/281oI+UniIjudOcoXfe8QONxmAII+d2QjFbx3wnOVsAPCpNU1K/chAqVpGvxC09NweByu X-Received: by 2002:a17:902:820d:: with SMTP id x13-v6mr33211239pln.225.1524752466629; Thu, 26 Apr 2018 07:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524752466; cv=none; d=google.com; s=arc-20160816; b=UsY7VmUhFGIt9QyzBLHCa2dmYof+qUF8qL0arr6iZR8+pdnLcpxq2+Sv/UCLM87H0l yZ44ACUrztS6rz8VwllwMDNB5AQeLxj7VqFkxtNPtkYH/lBW74dFrhkQwzQP4JYVD/0a ArEzoywrLmwR6J3WFK8OkroMgqXujeHLbv0em5X1+3RtmMN1BlW9X5ORcQno54d0WKzt tK8IRG9xAOG4hZuWhE1Fn6xl2dMEAh34kOW53Uq+IVPXnXevUBBjCuYy6NMK20d9JvKh VYLARtcwJ0LkhDfctANqQFvQfNTCsVFizq8FJ7LuZTqNKyt9Hkr+IlO+B3jSLFf0CKb9 xJqQ== 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=NJKAuRG9ci6Uk8zZrPuI8bBUulOoCqE65ou6Hzqv3Sw=; b=Y9bSZaZCBEnIRrfLgYSMUwHyxrpEWqYONjcEVXbDSxPfjrlG2y0nER5ot8ADNJIUzo 7wlLPigFlB3gGMLMHWkvlRHtYN++5veJmMZrFh8vXpKXaUm6YVP9a1m7f0J+Mnr60kH4 TRHVNp7XBgp2sYdS7V8Gln3DcqKu5989pPxa+k1vCerD4EP06w/VV9Fo4l+5euZPXM2c eZXrokEVSiVVJF+F/V1TsZp6RaQ1Q7yWOBbjnWNLNGbn2T7AQXCzW8Xi19Y8DzAdPDtf J4vwRLPQ+DM+5611oI3uro3cEYzZx85AYfUNPG8X0n+Zrflv9UlGP8m7eCUXevKQeEf6 yYhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=DNOHagHY; 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 a2si18530201pfa.148.2018.04.26.07.20.52; Thu, 26 Apr 2018 07:21:06 -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=DNOHagHY; 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 S1756566AbeDZOTe (ORCPT + 99 others); Thu, 26 Apr 2018 10:19:34 -0400 Received: from 8bytes.org ([81.169.241.247]:51914 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756431AbeDZOT2 (ORCPT ); Thu, 26 Apr 2018 10:19:28 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id D2A7A259; Thu, 26 Apr 2018 16:19:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1524752366; bh=tEJSCAreWdlsx6sgxEK0aifR6dmW3DjNLjy6YxUFlxo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DNOHagHYQyRlFVdKdQ5EP6UVCxNyGPblnushO4PomidD9WEMTc1AIgEMHvawY/+7C pYCrobqpzTn2cU3VFI2iPXPp/am80zU3NFfoa2Vd8gu3VInnywT27QhKoXhhcRFoyL ALtsbRoCdFvXlsHf2Xte1QuwwuXpDHoZ0X+m0Tz6izIv4RMvfR2pV0x5Cji9orsOI0 YRkFPvAFOho6N1BCve1FNfDEDBGY0JrhGPnSaG7jEK+v/xi1/NxdCYaUxMRFbM+PRW u/bvlFIIrNLVqC7PUGPPo2xzBTxlIyGsUG0saEpNahe+SBSV+5Gq+XJMe5B7p7kDS9 QJSOotWfbEikg== Date: Thu, 26 Apr 2018 16:19:26 +0200 From: Joerg Roedel To: Toshi Kani Cc: mhocko@suse.com, akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de, catalin.marinas@arm.com, guohanjun@huawei.com, will.deacon@arm.com, wxf.wang@hisilicon.com, willy@infradead.org, cpandya@codeaurora.org, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 2/2] x86/mm: implement free pmd/pte page interfaces Message-ID: <20180426141926.GN15462@8bytes.org> References: <20180314180155.19492-1-toshi.kani@hpe.com> <20180314180155.19492-3-toshi.kani@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180314180155.19492-3-toshi.kani@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 Hi Toshi, Andrew, this patch(-set) is broken in several ways, please see below. On Wed, Mar 14, 2018 at 12:01:55PM -0600, Toshi Kani wrote: > Implement pud_free_pmd_page() and pmd_free_pte_page() on x86, which > clear a given pud/pmd entry and free up lower level page table(s). > Address range associated with the pud/pmd entry must have been purged > by INVLPG. An INVLPG before actually unmapping the page is useless, as other cores or even speculative instruction execution can bring the TLB entry back before the code actually unmaps the page. > int pud_free_pmd_page(pud_t *pud) > { > - return pud_none(*pud); > + pmd_t *pmd; > + int i; > + > + if (pud_none(*pud)) > + return 1; > + > + pmd = (pmd_t *)pud_page_vaddr(*pud); > + > + for (i = 0; i < PTRS_PER_PMD; i++) > + if (!pmd_free_pte_page(&pmd[i])) > + return 0; > + > + pud_clear(pud); TLB flush needed here, before the page is freed. > + free_page((unsigned long)pmd); > + > + return 1; > } > > /** > @@ -724,6 +739,15 @@ int pud_free_pmd_page(pud_t *pud) > */ > int pmd_free_pte_page(pmd_t *pmd) > { > - return pmd_none(*pmd); > + pte_t *pte; > + > + if (pmd_none(*pmd)) > + return 1; > + > + pte = (pte_t *)pmd_page_vaddr(*pmd); > + pmd_clear(pmd); Same here, TLB flush needed. Further this needs synchronization with other page-tables in the system when the kernel PMDs are not shared between processes. In x86-32 with PAE this causes a BUG_ON() being triggered at arch/x86/mm/fault.c:268 because the page-tables are not correctly synchronized. > + free_page((unsigned long)pte); > + > + return 1; > } > #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */