Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp670983ybv; Fri, 7 Feb 2020 06:28:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxFuExuQWTEEzVWhL++k0hgUduuMEBnlpeOnsekXvYXsOnnUAFMSpOlAZ4uLbJB2OCxZVwV X-Received: by 2002:aca:5094:: with SMTP id e142mr2166352oib.101.1581085721301; Fri, 07 Feb 2020 06:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581085721; cv=none; d=google.com; s=arc-20160816; b=lxwoFReKGkrB1IO6eMqI7QfEeDz7hNxQ5fvLYlruABVA3k8LkTrbbM+DFE5sCj8tqj 6dSHhBBsKQZNi4frz+jiL/5ZcHPJMp/QGQnGfX4g9pre3oFqLXHnYH05abrU/aOmSk2D lC4bygsNzvxUinfi6mKj+X5Th2VFnye4lqJH4Cx/SXVAHb7WN4bsy0Af+ayCVceRypXp aQrA4IDK1z1/gIChqRsKMDRiVtHMk/IEdjub4RsU7Wag9j5L4fiXAr45SMwGsph9pc45 8+oc7H/FpJQZDpsyceYTn7DwKPZ1coc8IkCTskmVNaXB9vlQaWf9jLV0uFir9DUxpyYa A70A== 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=thYUobt6pp4eEud8l8vCKfukm0gTsC+SY9nMHyqvvms=; b=Wl8Pv0bSXIS/0EOhf9Q2v5y7ObsZSWELmnmvTjd9g0zjLt1Kf8wHlXWve5Geii3Ov/ 5Dmk3LF9daPXGkNKX4iVzuCaldKuziVHAhDHqmOf7UMkeHAdcUXe5hOv9HlQmEtEXvRQ rlKfcnYb5FE4weR1WhXzY3S+7Vv/Y/rzlgl03lvhciSjUztv2dp24tbwHDXt/PkcBlCo WL+hohZaqCiem7POdBTKhfQARA+2kcl2Q3VG7oGUcntdAZz956xSKkYtnv2oJVA5rZZo hE8pistR60JIExX+haw+c34NN8FsmF4huRUpvxY4TP5+xvvL0fK6a0p2An1dpxqsJ1Os xA5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=IiyWRiiv; 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 s17si1593537otr.320.2020.02.07.06.28.29; Fri, 07 Feb 2020 06:28:41 -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=IiyWRiiv; 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 S1727422AbgBGO06 (ORCPT + 99 others); Fri, 7 Feb 2020 09:26:58 -0500 Received: from esa5.hc3370-68.iphmx.com ([216.71.155.168]:51046 "EHLO esa5.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727011AbgBGO06 (ORCPT ); Fri, 7 Feb 2020 09:26:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1581085617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=AQw9NSimR4U12ghjgIVRKEpnFYF65RqKgaPuBmOw1Ec=; b=IiyWRiivxo/Os5Np2BhmQxB253d1oRsR6EYf7RebTC0iWN7iOtvFDS5v HKwbzQb/R4kpTWWcUYUkFlg5L5DzGJwufryb977wwUh6vwdl62hQvgPN1 TkE8LSHdgt5KxY77TXv1jYrgCD/6nDlon/4ehRuBKMTswsjvI8aMxRy2W 0=; 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: NbCBsYaY7tmZHavhqZHrbPJ2IHI7GEcD1su+OtjP6Feuh7t+T6eFm5iKhfT122oG8TD/O3R8jw C5g0kaQf1sgi6i8GcO+rDSWiFdeM6ww+sxchmgZSpu1Ngha9qM0EQzQdNSAaRt8Bu7M5x2Bkbn kDUjOTCdTHUFqKjA6qLuOGaJDttPGeQ9ydKYf6zzUacaY7RFxrX6j7R3mqaLyNlRpVq1pDJScF Bg8JDVmtoM4n0+LyzPPxNHsH0+1tlVZxNMup64noARhGcmZ/Hao+6WQaKQ8zkTwvKLNKggLICd weI= X-SBRS: 2.7 X-MesageID: 12479583 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.70,413,1574139600"; d="scan'208";a="12479583" 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 v3 1/4] kasan: introduce set_pmd_early_shadow() Date: Fri, 7 Feb 2020 14:26:49 +0000 Message-ID: <20200207142652.670-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200207142652.670-1-sergey.dyasli@citrix.com> References: <20200207142652.670-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 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 --- v2 --> v3: no changes 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; } -- 2.17.1