Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1044962ybl; Wed, 8 Jan 2020 10:03:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyRGNkW3VbAZGFpOuBxRyEE3IXNzpYzKamMmzSpIz14vOI98CJs9/lC/Hk3RVxDfo73SlIx X-Received: by 2002:a9d:664a:: with SMTP id q10mr4741064otm.99.1578506624116; Wed, 08 Jan 2020 10:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578506624; cv=none; d=google.com; s=arc-20160816; b=vZlzaH21rTQf040UmBeR8QdnhbWF6uc4PJWsRwLU9x3zktx2udkhEjfB7L4hTUOAFO xsyWdIxX4vHT9w0SsgcBVEei9KYTlLF/tKXc9ZKokTulaqdDY8Zz/+gRSIfGURpZewf4 7UO5jcmRqZXfiUJBIsP6jWbzQ7lbQ8gRbxeYZR7n/57GbfafejLQF1oTf0V5onxDndxo eCY9TQQFUpNPq4BeULG2/SKAhDB92lEMYx52Uw2XiOkFvCeBDICodnphxsgCxyQW/ICG JKIlO9ic4BnlmdO2yPCtHIWgHWzyS1tPXeL07fA4MdagtJs5pU2AkDbW3WMaiYGOBbqg MEgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=LtdPnrcsTw6Dr/fClAbuyIX4XALzyf8f7Vy6o/q2R3U=; b=aGcmbCn5KirZ8g2z1pw4yFWLquF8ZNXuOd6BbWP/HEnNTqSV0PLTx0hEbVGA4G8rKd DMcf7+iYWVQj/Pl0QUokAmyia/UjYZ/qtCmwWe5WGsf22DKCjlHEXSdozlPXCTqdalbJ X5XFrIYkb07bPbOm/Dqfh1AxvNc1irJbaOinFWxLR9u7d59HudKiwtxDCjU/1Ty92YLH dpNdg6YNVREVMY+8tP8VZ0+0Ge2ETcDjyMieFG3Qx9gF4/5DhWxEjhvu7+kKiP2+By1N ig0XZu17EntCxjTeej9j/VEF/m4RCBcKegO2SorOyA90Feu+ZLhAunWHsq2t/BjTKf3V LmQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=AgXhiwF2; 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=citrix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y140si2192082oia.49.2020.01.08.10.03.26; Wed, 08 Jan 2020 10:03:44 -0800 (PST) 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 header.i=@citrix.com header.s=securemail header.b=AgXhiwF2; 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=citrix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728686AbgAHP2T (ORCPT + 99 others); Wed, 8 Jan 2020 10:28:19 -0500 Received: from esa5.hc3370-68.iphmx.com ([216.71.155.168]:3495 "EHLO esa5.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728218AbgAHP2T (ORCPT ); Wed, 8 Jan 2020 10:28:19 -0500 X-Greylist: delayed 426 seconds by postgrey-1.27 at vger.kernel.org; Wed, 08 Jan 2020 10:28:18 EST DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1578497299; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=u+HZe/IB7NWuju/ekZtvFNhhexGEz06n0VVXB1U9a4M=; b=AgXhiwF2PTwG93UagGXq27V0GBqDlamh/teZvCTcjbNuZU6ZWTWMlrdq koFUa400l4sjjHr/iqIdFEdLvxRfNIZbvq5tdyasMLwLKFCUZubGR5WZy T/fWdayMkfZuYqVs98q5oN1XmVRBVnUH+ANPxAxcXpdUELc2a8GSU6etp 8=; 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: , , , CC: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Boris Ostrovsky , Juergen Gross , "Stefano Stabellini" , George Dunlap , Ross Lagerwall , Andrew Morton , Sergey Dyasli Subject: [PATCH v1 1/4] kasan: introduce set_pmd_early_shadow() 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 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.17.1