Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1824330pxb; Mon, 13 Sep 2021 06:23:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPwLWCuuJ362Cz6ZxkCa8fnYHXMJCbFqBoKe1ZukZ5dZxMG1LKlsHlu1doFFKi9KyCeBoW X-Received: by 2002:a02:a48:: with SMTP id 69mr6116546jaw.42.1631539401506; Mon, 13 Sep 2021 06:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539401; cv=none; d=google.com; s=arc-20160816; b=pK2IpczFAO5iJCVz7aIqzerxI9uOqbaO1nOYJ0LdHhi0gZlgfKQrqJJRpV+D7/vVAm TbjvtrxePZ2n1tAVB3sxM1wuIyKekJ0djSZoGgIbHyLAO5kYNmiQcSrL308hT/lpDGrM rPP+4QSC/rSl1Oi2XIoxbQNN9bZ5lw1C6K7A+D975K8mp+ZYeUs65SI2L/xKPPbjfTqw rkBeAD6VLmc/WU94teZpQJ6zFdDBmkacKkcwT9+Ho5x6VGC67lUBF+2af0T7GlkllH58 psx/xS6+s8zERVZjDel5bCDc8sQmN7lFcOG88UK98/Y53x7K864g/+cK/+2A2zJGfLXr 53SA== 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=JAEa4Lg7jrj4DHAGLY3MFK6muTGUA0pZYgn/g8Yyod8=; b=f+8v4ZHJ5H8ST8+NxSLAgGe3SQC4A+fvEIAJE8KCz4mxTC666TqwDjmKEJLqn8j9R6 Vg3EXySIdvm9i2NHIe9Wsmxw3/XoInloZZN1S3iRYFL2bygEH73KM60S3bwJIQY9QwvY 20PCYr0s8GbSgW65DvkpytZYQucmIPbfHFLqOpP4XxWMGkCvWzWg9DS4RaA+s3XHUG5D rRn30EB+wHXj/aPY3RPSINZ1OtRZeTBKG/l08KFhGO9uJS/m5S6jkRWKHJW5XgQamcpM ECHAXmj8qgnxgx12vhQn7Kp/Sp+6fmEMioAWrC9yJuwqU7aRvw3busKaRB2HyLtgt1Xv alDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZaYAnFw3; 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 x4si6104151ilj.121.2021.09.13.06.23.07; Mon, 13 Sep 2021 06:23:21 -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=ZaYAnFw3; 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 S240456AbhIMNV4 (ORCPT + 99 others); Mon, 13 Sep 2021 09:21:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:35044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240536AbhIMNUz (ORCPT ); Mon, 13 Sep 2021 09:20:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C8276103B; Mon, 13 Sep 2021 13:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539154; bh=wS9B+vqHgc6uCx1PSmE3t5QxXSsEKNRwNNJUmWfPJM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZaYAnFw3nZs43weaxE0KhEOnjrcX00cF9YL9nmn6JJeSrXlE/c6eYZ2BMMjBjMw0Q xnpQcLZce2UlBQLYzjWMzJnrwRDv6lwiX1D3JCGJoNMewoZ9ej6QXUsqD5oyrt82zK HhFEF0BFWLTwhUSvV5HpFbiDMB7v8bWYCn+3zIFw= 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.4 029/144] s390/kasan: fix large PMD pages address alignment check Date: Mon, 13 Sep 2021 15:13:30 +0200 Message-Id: <20210913131048.931253071@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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 460f25572940..5182e0836ca7 100644 --- a/arch/s390/mm/kasan_init.c +++ b/arch/s390/mm/kasan_init.c @@ -101,6 +101,9 @@ static void __init kasan_early_vmemmap_populate(unsigned long address, pgt_prot = pgprot_val(PAGE_KERNEL_EXEC); sgt_prot = pgprot_val(SEGMENT_KERNEL_EXEC); + /* + * 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)) { @@ -146,30 +149,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