From patchwork Tue Nov 22 11:38:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 24319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2158349wrr; Tue, 22 Nov 2022 04:04:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6OdS3UgoiIxmW17NNdNRTVfjeBH7TRw1c9JYguckV+XFHHvbUOH5pffkXTLiZvwDNGH/GY X-Received: by 2002:a63:f503:0:b0:470:4acb:1eb with SMTP id w3-20020a63f503000000b004704acb01ebmr2984725pgh.440.1669118643035; Tue, 22 Nov 2022 04:04:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669118643; cv=none; d=google.com; s=arc-20160816; b=noZR4M142CzA9gp135qa2wX40UK7c4JBBdxVuSkG15p5XzWA6iCowEVV/Oh7AczyQz GyE7I3X5ZfxdosvG9quKTgd2pkFbTANqQ6oSrvpKX6UywKOrQmbkrlMAuZ+K8K7l5ney 5sYWMaRtF5XWJq8e7O5qy88jOHEm0oApTddlTdv+f2mGYnYC6DmkmmnYv45KmNvP3jDQ ST62FeImfZdqkjTv+hFLXFm/iJzV2oGpRlh5jemEt/syHP7nrKD4cAhMoP3hTSHPeUcP B5cx1otPAPVipUmEti6ymHN5H28+2qT8rG8/NmL0JRJEFl/u8wWDcYYR+IYed6gx4yK1 iWAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ju8RVrpAmoxu07QrDfR6AfyPN+fjpTPQ6RH2y9sCpj4=; b=ISylXR/KLGOMQEHpVhLeP/LSHk29CADph/zygRvyjk6Ef8lspyoGhu6fCE5fDZW7tg NaetK0kAjPtIgsHYcmCs12HCGO9YmdavjkuOebpsqLwBd2phppfRsxDMm8Y9hL7XJcwy LC0IzqKXdyKydttiT2u0kBOEcJCYlJBgoClfh9g13ig4DOGBeuolhcX7wvlxBuCExreL l7aIqgIdMqIBW6TZe9kNR6yYIq+ipXIima+6tLm9k99xjeCMfBmntzxEhYfPVGeBNkp3 dy3XuyA570UBSIFzdbYF1XCRKk2SkWtcE8HPAZXN43Nr2ClajrQoRBQVwhjpvANeH3XH l2xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Lfuwt/07"; dkim=neutral (no key) header.i=@linutronix.de header.b=XOuUKUqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n185-20020a6327c2000000b0047798cae7ecsi2533279pgn.685.2022.11.22.04.03.47; Tue, 22 Nov 2022 04:04:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Lfuwt/07"; dkim=neutral (no key) header.i=@linutronix.de header.b=XOuUKUqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232988AbiKVLnA (ORCPT + 99 others); Tue, 22 Nov 2022 06:43:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233184AbiKVLlm (ORCPT ); Tue, 22 Nov 2022 06:41:42 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F815B59C; Tue, 22 Nov 2022 03:38:53 -0800 (PST) Date: Tue, 22 Nov 2022 11:38:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669117131; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ju8RVrpAmoxu07QrDfR6AfyPN+fjpTPQ6RH2y9sCpj4=; b=Lfuwt/076us6HYFOP1XIUyOesk4P0bfNOz0u+sFvz5EJPderIlVwHW98nksKcapZ3uUOlC XA3bGeIpPsPUdeurClEbDESYd4jRb1OLWYsRj87WIa28GEK6An4hbMhH7PnHxJQLg44jgF g2GhjlPxQOFinRwIhWZbXmmEsZAV5BVCyC8Lld3mWTqTAshmjmecNqseb5AQSXGdQ67o8J niwWk3F2Ybwc2nesNkjMbSlAQN+PytlDCD29fZApbFPDq3JTWGTJQIam5uBX0ftQkCw6z1 TOSVvOBeZpaU5LwANsvGCXDK629Hw54tKqGaUwLxF1GDFc+NrP100hYPt91n6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669117131; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ju8RVrpAmoxu07QrDfR6AfyPN+fjpTPQ6RH2y9sCpj4=; b=XOuUKUqhW01F6sjByzjjTsTYBbKsadlVQPDxlvsF+s5CfIakI+F7ZtETtSa9EghgeVPw0T XL67fQXUJIDM15CQ== From: "tip-bot2 for Michael Kelley" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/ioremap: Fix page aligned size calculation in __ioremap_caller() Cc: Michael Kelley , Borislav Petkov , Dave Hansen , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1668624097-14884-2-git-send-email-mikelley@microsoft.com> References: <1668624097-14884-2-git-send-email-mikelley@microsoft.com> MIME-Version: 1.0 Message-ID: <166911713030.4906.16935727667401525991.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749679696050211710?= X-GMAIL-MSGID: =?utf-8?q?1750197749905302970?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 4dbd6a3e90e03130973688fd79e19425f720d999 Gitweb: https://git.kernel.org/tip/4dbd6a3e90e03130973688fd79e19425f720d999 Author: Michael Kelley AuthorDate: Wed, 16 Nov 2022 10:41:24 -08:00 Committer: Borislav Petkov CommitterDate: Tue, 22 Nov 2022 12:21:16 +01:00 x86/ioremap: Fix page aligned size calculation in __ioremap_caller() Current code re-calculates the size after aligning the starting and ending physical addresses on a page boundary. But the re-calculation also embeds the masking of high order bits that exceed the size of the physical address space (via PHYSICAL_PAGE_MASK). If the masking removes any high order bits, the size calculation results in a huge value that is likely to immediately fail. Fix this by re-calculating the page-aligned size first. Then mask any high order bits using PHYSICAL_PAGE_MASK. Fixes: ffa71f33a820 ("x86, ioremap: Fix incorrect physical address handling in PAE mode") Signed-off-by: Michael Kelley Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Cc: Link: https://lore.kernel.org/r/1668624097-14884-2-git-send-email-mikelley@microsoft.com --- arch/x86/mm/ioremap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index 78c5bc6..6453fba 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -217,9 +217,15 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size, * Mappings have to be page-aligned */ offset = phys_addr & ~PAGE_MASK; - phys_addr &= PHYSICAL_PAGE_MASK; + phys_addr &= PAGE_MASK; size = PAGE_ALIGN(last_addr+1) - phys_addr; + /* + * Mask out any bits not part of the actual physical + * address, like memory encryption bits. + */ + phys_addr &= PHYSICAL_PAGE_MASK; + retval = memtype_reserve(phys_addr, (u64)phys_addr + size, pcm, &new_pcm); if (retval) {