Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp82448pxb; Mon, 13 Sep 2021 13:32:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSLHjh2CTJf8InV4Cw3yKOkdYKUeIYJqjc8SpkjxAX4ZEgNDS4P3KoNfxGdC1h/C1ELjbM X-Received: by 2002:a92:a30e:: with SMTP id a14mr9229005ili.238.1631565173929; Mon, 13 Sep 2021 13:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631565173; cv=none; d=google.com; s=arc-20160816; b=jkoch6F3BaYnUfLG+Ez+HFNdt8eHn9dtfIttRIYcszREmlETO75wL7DygObZ86LxRI MKrPN7PqQOPAhAWhdDtfil3WIfZUs+Ce2ZesjuTc23E6gUqyQcBsg5jW6fkVm2SRHyZ3 mM40RAv1WMtiCxM8SrUyQVWYS5F/V8ROAcPW1keJ3A94hMGFqg5kFnXRJ6XdghDTYJXO sfUwNK2v+3roKNTxIrmWR50quGwEb1jTKshTer2gebizY71wqNBUnHPIuCQh6MowTqDS EaN5igtxM8HS1U934hfncn7Pr0gTG6YsngK0Jt0lzj4CJ9BLW2QILyc9mRcUBPmuaLrG nxkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Zy1/cQfwZH0UIKCGkdmpVNS4AU2XB2z7iCrUzAOHj4A=; b=ELJSbrA29DxaZOIvgCJj/4/+nzuOmjBbtL7wfiX7h4O2CMAa1e1f1yUZbAl8hElV5A YtyPV8HM+5tKxritrKncJGZkooW1Y91+mBjizIriSI/LQ7hx7yZVyxNFgHS5iYo6gEdn j5VqaI+c7ipp3LcjfosVPWs3dhqpoijnuDlSGHxcJ9rdZeBAjc04Q3bK+dCO3IBVcXww oEcggfO5tRhgh5kR9Tkj7NghpGdEDq7LVR3pnCQVJfIa8nOAzRW6vg6JzXMUGPCKNkIC /fXkH2sAkZCcd3Res/fKmY3hGDBM11yHnIuWfovtVF2XMh+A0IdF1nTuQNrMgaT7Wcq1 u+iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oz1pd9G4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si8385079ioj.39.2021.09.13.13.32.42; Mon, 13 Sep 2021 13:32:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oz1pd9G4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242929AbhIMNhx (ORCPT + 99 others); Mon, 13 Sep 2021 09:37:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:58346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240870AbhIMNch (ORCPT ); Mon, 13 Sep 2021 09:32:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14E0661361; Mon, 13 Sep 2021 13:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539549; bh=pRz0pcGrk0bI5tVenX8gEj6hCVq03V+Zw6XBu62Nmks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oz1pd9G4f64fTeLrH7x0EEaAy8HIb0T5KH90Dn3nLsC+L7g7y5hxB6GxxpmcDUveu MGEpldcOKzJmfB8cGVcGfYMqgVimj5tNWVH5/jY66ROup5eOtRx7ixdV+rTpXzzEIj w4ReEaSSEDAA+Mpu0XiVvVfzW+HW/1ZDdLmILBJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Gordeev , Vasily Gorbik , Heiko Carstens , Sasha Levin Subject: [PATCH 5.10 035/236] s390/kasan: fix large PMD pages address alignment check Date: Mon, 13 Sep 2021 15:12:20 +0200 Message-Id: <20210913131101.539613035@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Gordeev [ Upstream commit ddd63c85ef67ea9ea7282ad35eafb6568047126e ] It is currently possible to initialize a large PMD page when the address is not aligned on page boundary. Signed-off-by: Alexander Gordeev Reviewed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik Signed-off-by: Heiko Carstens Signed-off-by: Sasha Levin --- arch/s390/mm/kasan_init.c | 41 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/arch/s390/mm/kasan_init.c b/arch/s390/mm/kasan_init.c index 5646b39c728a..e9a9b7b616bc 100644 --- a/arch/s390/mm/kasan_init.c +++ b/arch/s390/mm/kasan_init.c @@ -108,6 +108,9 @@ static void __init kasan_early_vmemmap_populate(unsigned long address, sgt_prot &= ~_SEGMENT_ENTRY_NOEXEC; } + /* + * The first 1MB of 1:1 mapping is mapped with 4KB pages + */ while (address < end) { pg_dir = pgd_offset_k(address); if (pgd_none(*pg_dir)) { @@ -165,30 +168,26 @@ static void __init kasan_early_vmemmap_populate(unsigned long address, pm_dir = pmd_offset(pu_dir, address); if (pmd_none(*pm_dir)) { - if (mode == POPULATE_ZERO_SHADOW && - IS_ALIGNED(address, PMD_SIZE) && + if (IS_ALIGNED(address, PMD_SIZE) && end - address >= PMD_SIZE) { - pmd_populate(&init_mm, pm_dir, - kasan_early_shadow_pte); - address = (address + PMD_SIZE) & PMD_MASK; - continue; - } - /* the first megabyte of 1:1 is mapped with 4k pages */ - if (has_edat && address && end - address >= PMD_SIZE && - mode != POPULATE_ZERO_SHADOW) { - void *page; - - if (mode == POPULATE_ONE2ONE) { - page = (void *)address; - } else { - page = kasan_early_alloc_segment(); - memset(page, 0, _SEGMENT_SIZE); + if (mode == POPULATE_ZERO_SHADOW) { + pmd_populate(&init_mm, pm_dir, kasan_early_shadow_pte); + address = (address + PMD_SIZE) & PMD_MASK; + continue; + } else if (has_edat && address) { + void *page; + + if (mode == POPULATE_ONE2ONE) { + page = (void *)address; + } else { + page = kasan_early_alloc_segment(); + memset(page, 0, _SEGMENT_SIZE); + } + pmd_val(*pm_dir) = __pa(page) | sgt_prot; + address = (address + PMD_SIZE) & PMD_MASK; + continue; } - pmd_val(*pm_dir) = __pa(page) | sgt_prot; - address = (address + PMD_SIZE) & PMD_MASK; - continue; } - pt_dir = kasan_early_pte_alloc(); pmd_populate(&init_mm, pm_dir, pt_dir); } else if (pmd_large(*pm_dir)) { -- 2.30.2