Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2462925yba; Mon, 15 Apr 2019 12:10:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD+Yacx7HiidbuUo+NPcdSaGd+MsbBUVdNY+cPJlaYtXM7/SniUoYFtyjlSjNq9g1ObK+x X-Received: by 2002:a65:62c3:: with SMTP id m3mr71194179pgv.159.1555355402217; Mon, 15 Apr 2019 12:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355402; cv=none; d=google.com; s=arc-20160816; b=jycMX4g5yKAsMFgyJVWxCdWDGd+MxYgGJ2NIqGkBOT9XDQYEfmSdQdl9Y/baerfA6s L1oUl1+leNETBrOEqf11L/IVpJkODckpC+kiBFXakuS5IiDcwP7d9CXrE32bu1o1yzmg dtci+BTL590HhbEvzHdWgrggvB3TVqTnVhQXWfdRuDyfJvUkPMm9/wuUfVf4dzxpDbk8 6dnsxPXB6Oui//ADgIcmqg58eO4ykB1gOs6lyD1hpUNJd0zT0Mz9+nEca+132j7bBI5a gHK1KlhXcynmWBOM7SaPapSnMRv7CN8qdV/zFEBj99/kYYWZVcTEijM6KzjHCAgFb0mk 8IHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nSXoSqDyjtNaAQ1C3UH/We6Hr0jG4cqwfA18da9wsTQ=; b=FxD+saY4ULD1b4aoSOSr4bCalv10ptKBiYfgMtCrx24yq6iZKfx0IQ7EejlUr6fR9B QxuIQGYkibRTUf57y7+eJVYLgi3eay5uAUG01BdyPsD+RFUiR58jBySIAJpTEm3qrdTb 2OOxC2cZZtE8ZEkcSw2PD9PlTwy0FTmpnuKYKmQko9UwjHoPSl9KQdweH4CGrIxPm9tu BN5Gy4KH2s3R1moEOB7KAGNzRik+VBn15JSx0X6/y8Ve0zbRqkYum7gc0kEYUmuWudU5 PWWDH4EkFk2+8Fnq5aSx9tGRAK3sF2zMc5kHCSS0PeV25eLcV5xw7bPjRYjmHe1rD71X vmNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yDBwHn9Z; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si24419283pgq.350.2019.04.15.12.09.44; Mon, 15 Apr 2019 12:10:02 -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=pass header.i=@kernel.org header.s=default header.b=yDBwHn9Z; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730160AbfDOTHW (ORCPT + 99 others); Mon, 15 Apr 2019 15:07:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:42118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730120AbfDOTHR (ORCPT ); Mon, 15 Apr 2019 15:07:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ABD0D218FF; Mon, 15 Apr 2019 19:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355237; bh=RTssTxgPQRGedkSR8HxC3pFnGGFA9F1OIfxTQgxgMvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yDBwHn9ZFj2P6cfKX3OaNnJC4BRRlcP881HtxGq8Dg5Y1u4ZkJMqHxL4on1nVTsNH +bKCzN44MX9jRQK4oE0alvEcrXjq5pWGqQshNMVeDhNoIKtAGiiCbmC1RiLtWl7pjw C8UEd1uyT2HRiWiGIk7F8nCukfv0uFJHCKlgvb80= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Aneesh Kumar K.V" , Chandan Rajendra , Jan Kara , Dan Williams , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 054/101] mm/huge_memory.c: fix modifying of page protection by insert_pfn_pmd() Date: Mon, 15 Apr 2019 20:58:52 +0200 Message-Id: <20190415183743.399884137@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aneesh Kumar K.V commit c6f3c5ee40c10bb65725047a220570f718507001 upstream. With some architectures like ppc64, set_pmd_at() cannot cope with a situation where there is already some (different) valid entry present. Use pmdp_set_access_flags() instead to modify the pfn which is built to deal with modifying existing PMD entries. This is similar to commit cae85cb8add3 ("mm/memory.c: fix modifying of page protection by insert_pfn()") We also do similar update w.r.t insert_pfn_pud eventhough ppc64 don't support pud pfn entries now. Without this patch we also see the below message in kernel log "BUG: non-zero pgtables_bytes on freeing mm:" Link: http://lkml.kernel.org/r/20190402115125.18803-1-aneesh.kumar@linux.ibm.com Signed-off-by: Aneesh Kumar K.V Reported-by: Chandan Rajendra Reviewed-by: Jan Kara Cc: Dan Williams Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/huge_memory.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -734,6 +734,21 @@ static void insert_pfn_pmd(struct vm_are spinlock_t *ptl; ptl = pmd_lock(mm, pmd); + if (!pmd_none(*pmd)) { + if (write) { + if (pmd_pfn(*pmd) != pfn_t_to_pfn(pfn)) { + WARN_ON_ONCE(!is_huge_zero_pmd(*pmd)); + goto out_unlock; + } + entry = pmd_mkyoung(*pmd); + entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); + if (pmdp_set_access_flags(vma, addr, pmd, entry, 1)) + update_mmu_cache_pmd(vma, addr, pmd); + } + + goto out_unlock; + } + entry = pmd_mkhuge(pfn_t_pmd(pfn, prot)); if (pfn_t_devmap(pfn)) entry = pmd_mkdevmap(entry); @@ -745,11 +760,16 @@ static void insert_pfn_pmd(struct vm_are if (pgtable) { pgtable_trans_huge_deposit(mm, pmd, pgtable); mm_inc_nr_ptes(mm); + pgtable = NULL; } set_pmd_at(mm, addr, pmd, entry); update_mmu_cache_pmd(vma, addr, pmd); + +out_unlock: spin_unlock(ptl); + if (pgtable) + pte_free(mm, pgtable); } vm_fault_t vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, @@ -800,6 +820,20 @@ static void insert_pfn_pud(struct vm_are spinlock_t *ptl; ptl = pud_lock(mm, pud); + if (!pud_none(*pud)) { + if (write) { + if (pud_pfn(*pud) != pfn_t_to_pfn(pfn)) { + WARN_ON_ONCE(!is_huge_zero_pud(*pud)); + goto out_unlock; + } + entry = pud_mkyoung(*pud); + entry = maybe_pud_mkwrite(pud_mkdirty(entry), vma); + if (pudp_set_access_flags(vma, addr, pud, entry, 1)) + update_mmu_cache_pud(vma, addr, pud); + } + goto out_unlock; + } + entry = pud_mkhuge(pfn_t_pud(pfn, prot)); if (pfn_t_devmap(pfn)) entry = pud_mkdevmap(entry); @@ -809,6 +843,8 @@ static void insert_pfn_pud(struct vm_are } set_pud_at(mm, addr, pud, entry); update_mmu_cache_pud(vma, addr, pud); + +out_unlock: spin_unlock(ptl); }