From patchwork Wed Jan 8 15:20:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 11323907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2CAB17EF for ; Wed, 8 Jan 2020 15:22:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F5F520673 for ; Wed, 8 Jan 2020 15:22:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="C6H2lFMh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F5F520673 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipD96-0003mh-Oq; Wed, 08 Jan 2020 15:21:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipD95-0003mH-8Q for xen-devel@lists.xen.org; Wed, 08 Jan 2020 15:21:19 +0000 X-Inumbo-ID: 8227be68-322a-11ea-b82c-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8227be68-322a-11ea-b82c-12813bfff9fa; Wed, 08 Jan 2020 15:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1578496874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=u+HZe/IB7NWuju/ekZtvFNhhexGEz06n0VVXB1U9a4M=; b=C6H2lFMhAltHiGO5Ns6L0Jfb+OUEYk3l3AbmMs0UQd3YFzpyAISs2sak UpRGCvDqwzXaldjchpA8o0UCVaiMt+aqXYQehge+cnBtSxMgr7F/Kuvw7 LGl+ufZZmx80O0hDny9keWaNgo1Wa6njgtj3VlxqTcX/kXh/OutfiMs5Y s=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=sergey.dyasli@citrix.com; spf=Pass smtp.mailfrom=sergey.dyasli@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of sergey.dyasli@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of sergey.dyasli@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: NbrdZNDy/8773XZvZO8zNVSrjuBIlAMLf4M6CL+ejqbSJOqIN86OXwZR2Ps3f9MnAat1eXt5rL I5/hb4LebArVQjJXBOXfAtGECD78VXz6jBVCYi8lUug0bg+ZZEhfDnvYsb8fP9uyUSmZDg0AFT jKOSB2BDBcfGoWQV7vQbwBSL5PachzEw22NTcMg9xW7eIs2jH1J+/mNaxrn7xe2G3nVPLqdX7z xjzRnNNqF5pxf+YhbmBJeCEuBX4Hv89CfiDNTkbDZc3hXN5yEmJGTM/EOf8PjvYbiT2GYU9wZ6 6Qo= X-SBRS: 2.7 X-MesageID: 11004135 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,410,1571716800"; d="scan'208";a="11004135" From: Sergey Dyasli To: , , , Date: Wed, 8 Jan 2020 15:20:57 +0000 Message-ID: <20200108152100.7630-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200108152100.7630-1-sergey.dyasli@citrix.com> References: <20200108152100.7630-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Sergey Dyasli , Stefano Stabellini , George Dunlap , Ross Lagerwall , Alexander Potapenko , Andrey Ryabinin , Boris Ostrovsky , Andrew Morton , Dmitry Vyukov Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It is incorrect to call pmd_populate_kernel() multiple times for the same page table. Xen notices it during kasan_populate_early_shadow(): (XEN) mm.c:3222:d155v0 mfn 3704b already pinned This happens for kasan_early_shadow_pte when USE_SPLIT_PTE_PTLOCKS is enabled. Fix this by introducing set_pmd_early_shadow() which calls pmd_populate_kernel() only once and uses set_pmd() afterwards. Signed-off-by: Sergey Dyasli Reported-by: kbuild test robot Reported-by: kbuild test robot --- RFC --> v1: - New patch --- mm/kasan/init.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mm/kasan/init.c b/mm/kasan/init.c index ce45c491ebcd..a4077320777f 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -81,6 +81,19 @@ static inline bool kasan_early_shadow_page_entry(pte_t pte) return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page)); } +static inline void set_pmd_early_shadow(pmd_t *pmd) +{ + static bool pmd_populated = false; + pte_t *early_shadow = lm_alias(kasan_early_shadow_pte); + + if (likely(pmd_populated)) { + set_pmd(pmd, __pmd(__pa(early_shadow) | _PAGE_TABLE)); + } else { + pmd_populate_kernel(&init_mm, pmd, early_shadow); + pmd_populated = true; + } +} + static __init void *early_alloc(size_t size, int node) { void *ptr = memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS), @@ -120,8 +133,7 @@ static int __ref zero_pmd_populate(pud_t *pud, unsigned long addr, next = pmd_addr_end(addr, end); if (IS_ALIGNED(addr, PMD_SIZE) && end - addr >= PMD_SIZE) { - pmd_populate_kernel(&init_mm, pmd, - lm_alias(kasan_early_shadow_pte)); + set_pmd_early_shadow(pmd); continue; } @@ -157,8 +169,7 @@ static int __ref zero_pud_populate(p4d_t *p4d, unsigned long addr, pud_populate(&init_mm, pud, lm_alias(kasan_early_shadow_pmd)); pmd = pmd_offset(pud, addr); - pmd_populate_kernel(&init_mm, pmd, - lm_alias(kasan_early_shadow_pte)); + set_pmd_early_shadow(pmd); continue; } @@ -198,8 +209,7 @@ static int __ref zero_p4d_populate(pgd_t *pgd, unsigned long addr, pud_populate(&init_mm, pud, lm_alias(kasan_early_shadow_pmd)); pmd = pmd_offset(pud, addr); - pmd_populate_kernel(&init_mm, pmd, - lm_alias(kasan_early_shadow_pte)); + set_pmd_early_shadow(pmd); continue; } @@ -271,8 +281,7 @@ int __ref kasan_populate_early_shadow(const void *shadow_start, pud_populate(&init_mm, pud, lm_alias(kasan_early_shadow_pmd)); pmd = pmd_offset(pud, addr); - pmd_populate_kernel(&init_mm, pmd, - lm_alias(kasan_early_shadow_pte)); + set_pmd_early_shadow(pmd); continue; }