Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5758625rwb; Tue, 22 Nov 2022 04:41:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+ITwQ3KzuJ/YsUGNuwATDPrKnz5YAdREnCsYbdVhk0UpWoIK52AJPgoVAQ7uJ3Fx8qtJ0 X-Received: by 2002:a17:902:6b44:b0:188:afa9:ba76 with SMTP id g4-20020a1709026b4400b00188afa9ba76mr8009333plt.58.1669120911298; Tue, 22 Nov 2022 04:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669120911; cv=none; d=google.com; s=arc-20160816; b=S51uzX9qogVeqQhVnByz2T8Q+kPpdtBleLsPPV8Fx8+4mvW2cXgKEWsWSHmFRhvomk ngRSIZ4Lis1HeBNEzBY6JLXipzGhl8fji1med98WNNxdQlk9EK5dgdSEYXMllxMXtoOK iBrs90thNNqXVw/SLf/zCwNUxRhW8Us/0XhLEIVSsPkpVmfchFDUPgU1oS2ce23L+VyU EGA/Z+lhnTnZPrM7K84Z2t23MD2E5P0ITSWLKELn0jj/TheErh4d90WnMvxU6PVQnHcM QecYTQXZ/lyLGHy2fjKEjtA0iVyjT20sDJOatVPR27do35MWY8QMFkxJkRfBXicvCf91 5vew== 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.s=2020e; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170903125200b00187359fc95csi12041620plh.563.2022.11.22.04.41.39; Tue, 22 Nov 2022 04:41:51 -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.s=2020e; 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 + 90 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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) {