From patchwork Fri Jan 17 12:58:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 11339013 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 4A96614B4 for ; Fri, 17 Jan 2020 13:00:27 +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 25F6F20728 for ; Fri, 17 Jan 2020 13:00:27 +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="DJ2UebC2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25F6F20728 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 1isRDG-0000ZS-OY; Fri, 17 Jan 2020 12:58:58 +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 1isRDF-0000ZN-Nr for xen-devel@lists.xen.org; Fri, 17 Jan 2020 12:58:57 +0000 X-Inumbo-ID: 1c1a9784-3929-11ea-b50e-12813bfff9fa Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1c1a9784-3929-11ea-b50e-12813bfff9fa; Fri, 17 Jan 2020 12:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579265932; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=4o9RJx4StHoB6G/jxqKKoPDaZjJC3Q3+qMbkHErq6tg=; b=DJ2UebC23ulFqCWrWFy7lopLru5unv2smwT3KcCQIsO5XMdm+eOXaKTh 8skgxQ/64qsRXCDx7VlOgP7gzsb9GsL3I/VSAbdRsBRqUyWXg0HOH8lqC OqGnXGDlQvcYROgvmXDcj0WKZetmEXDG714jpy0mvinwIdPLpKQG/4v88 E=; Authentication-Results: esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: zD3guFlkH9JhD+uSChmLcxdihehn1gAY55V0yNOLmfd5xHNkkyjQkaG1rNe8JDLriMbXtqsdj0 81dpZI705lNPF60X/LSI9Zed8Ipu/jX3FdGD0/VCa2xZQHYWL1ajeD5dMTEwtRTi9r2yF6xi9U BWpJr6wpKSm7udaVNwywU2OV5nt7AoxiT6BZueqhYAr6rFhXtL4h856U0/kqypBQmHvOBz7pSc dndcgglECoHTuRJtrokHRkSL/prOB0icVkoTw4UuoGG6SOWAn45h1sm75ZIutyTQgiKCbBK8cc FgM= X-SBRS: 2.7 X-MesageID: 11502055 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,330,1574139600"; d="scan'208";a="11502055" From: Sergey Dyasli To: , , , Date: Fri, 17 Jan 2020 12:58:31 +0000 Message-ID: <20200117125834.14552-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200117125834.14552-1-sergey.dyasli@citrix.com> References: <20200117125834.14552-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 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 from inside Xen PV domains. 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 --- v1 --> v2: - Fix compilation without CONFIG_XEN_PV - Slightly updated description RFC --> v1: - New patch --- mm/kasan/init.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/mm/kasan/init.c b/mm/kasan/init.c index ce45c491ebcd..7791fe0a7704 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -81,6 +81,26 @@ static inline bool kasan_early_shadow_page_entry(pte_t pte) return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page)); } +#ifdef CONFIG_XEN_PV +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; + } +} +#else +static inline void set_pmd_early_shadow(pmd_t *pmd) +{ + pmd_populate_kernel(&init_mm, pmd, lm_alias(kasan_early_shadow_pte)); +} +#endif /* ifdef CONFIG_XEN_PV */ + static __init void *early_alloc(size_t size, int node) { void *ptr = memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS), @@ -120,8 +140,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 +176,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 +216,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 +288,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; }