From patchwork Mon Aug 12 20:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Ramanouski X-Patchwork-Id: 13761017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9249DC52D7C for ; Mon, 12 Aug 2024 20:41:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28D146B00AE; Mon, 12 Aug 2024 16:41:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23D666B00B0; Mon, 12 Aug 2024 16:41:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DE396B00B1; Mon, 12 Aug 2024 16:41:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E394D6B00AE for ; Mon, 12 Aug 2024 16:41:11 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 69D24803C8 for ; Mon, 12 Aug 2024 20:41:11 +0000 (UTC) X-FDA: 82444763142.01.3F90F90 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 9949A80025 for ; Mon, 12 Aug 2024 20:41:09 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YqsuFC8B; spf=pass (imf02.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=max8rr8@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723495176; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=s9BCvy8coHdl2CucoLZ3iDhHSVmt1fz4/dGA+lhm9/c=; b=o0g0OO1VhxIWT5r7U5svoA95jVY+x8Yhry8sMVgJo5+4Dx4Mfyt0szh91IDimid/9I8b5e AaZHXYXaEy7Qrpfi1+9YqPhINdImoDX2XAad+l7qVdNxNK4xOylT7ttjE4RoeugcC2yiPp BlsyWnSbm/i11Y7XgXOGFXiKTUKMZyY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YqsuFC8B; spf=pass (imf02.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=max8rr8@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723495176; a=rsa-sha256; cv=none; b=AC98/uarGLKVfcR4cqhGCAtwvqP+kmUtDTHjXwmlsOL8P9nFDncoH5CA+hgb0T1w2u5zDg GnVKrPHB+wXG+PtFPI51oE1GdmAu3gw+Uqxc71xesWBbFfI7LZqeyx1+GyP5f3yCF3y5Ln TXuic1fGpnCtPjYe4FvKn3tOl5dHIX8= Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2f1a7faa4d5so38696191fa.3 for ; Mon, 12 Aug 2024 13:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723495268; x=1724100068; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=s9BCvy8coHdl2CucoLZ3iDhHSVmt1fz4/dGA+lhm9/c=; b=YqsuFC8B1JrASDhmNCAhKFAgSgSW3Dss8FkNtjbxoLdGabQqvAri2juGmV7VA469Mc SQYQp4zJC2lNqvsneY5q1gfRLaib9P/k4atfwWbo/L37NwWiNXMI7rSWed4QfGsbHNE4 9hpJHs35o74xQVezzs3EQKGC4qyhA7ipaWlXVp7LVU8lzryR7Oqn+XB68mhrHOVgZY68 rwvicbNAHxsIxzOI8zf1rgCJEWkMOs8tQiOkGxobZe5aeaS+nSs2+AEB3kb3clfKdmHV 2l9MpPDNUf5RaPIZ00hvmDe6XXKMChyiiCWF/5o3L9rQHjawKBUEmH9yOddWCgFQCW47 ERkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723495268; x=1724100068; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=s9BCvy8coHdl2CucoLZ3iDhHSVmt1fz4/dGA+lhm9/c=; b=u+YsmLY8j2ylKzwkVcoJMG4LqzjdgRD3NwQ66e4urX4W2QBZhNquEp4bmosd+sdRoy dqJ0r2JcPk5kOdZN5oE5J9CVMqKTXBi3BFki0mlWAaR56/g/Jb4Aa8+KlDaGoMtNikLl LnyONOrbiPTcykfYxcOT/nQxKpvsDodeNeofJ1P6s5DQGkfa17Q5OcaxksZrTlHOmzbi LHO+etyX53G3qpxt30GrySZS7no5OXnRohbsROCCRe9VoQ+7Ol6Xz9+bjPypJqgCjmW1 dZU1BX0H3e9LF9g4KcJRSkvgTqEHyvpUFDKdXLgL9Xndhj8eoU+0g07Tr9b+xeDjKJUs 8acA== X-Forwarded-Encrypted: i=1; AJvYcCVcX/gOCRirufbir0f3fnd6z4a2yrzhC+O8eiukJy6uhlvUs3DXzqoC5YE5MFts9m2xc+2RoobNE7xjFPpiU8+wg+g= X-Gm-Message-State: AOJu0Yx0N8rfX2WhI/5uXn9wQdU8KwMUJrjCr8FSxHrRsKaVpAU4fcIr G0K9GBcfYjl/uCyXsi59TiHwM1aQG3aCIRzj6UwWw4VL9MtFfWWJ X-Google-Smtp-Source: AGHT+IFMbNCdiOKmGRBle4jaHfW9+scmP4Pt32W41n7UrzXfvEIl6Z2fg4uSFyP3sNrOPK/hbNzrhQ== X-Received: by 2002:a05:651c:199e:b0:2ef:2016:2637 with SMTP id 38308e7fff4ca-2f2b70c9e22mr12025721fa.0.1723495267491; Mon, 12 Aug 2024 13:41:07 -0700 (PDT) Received: from localhost.localdomain ([46.53.242.139]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429c750379asm113821565e9.10.2024.08.12.13.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 13:41:07 -0700 (PDT) From: Max Ramanouski To: x86@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, jniethe@nvidia.com, jhubbard@nvidia.com, linux-mm@kvack.org, tglx@linutronix.de Cc: Max Ramanouski Subject: [PATCH v2] x86/ioremap: Use is_ioremap_addr() in iounmap() Date: Mon, 12 Aug 2024 23:35:38 +0300 Message-ID: <20240812203538.82548-1-max8rr8@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9949A80025 X-Stat-Signature: qs88jeris916ideniimu8cuy8uoa9t9r X-Rspam-User: X-HE-Tag: 1723495269-406551 X-HE-Meta: U2FsdGVkX19/8JEVpKJ/htFtpuDa3lB2W+gLr/KeE1PoT/udb7KLVR1eMvvYBnybSAG7eHCprbnA6d120jdA4SmqGLxIyrwNzhcO2U8v+Hh6mvYRfcEuz3yw4+Tp/PdAN3LVuLDSOb5el399Kz7isk0dfNfWaj0GAcNTnjpbEn+6jwCpzwsKKDWG4zzrnGmefvevHRo/PaLb+23+m6GFBb+q/Beo8CTK9L61xQLWZmWzeJL94O/91Jj4uJODXWdgwZVsvd2pFjRYtEL59wFBMTVSa//qB/jj8VuFGMvr5I0xoyMHqA4vu28XcKtO6ehHVEchCt3xruoOfrN85CZfnS6q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.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On systems that use HMM (most notably amdgpu driver) high_memory can jump over VMALLOC_START due to pages at the end of physical space being added with add_pages(), while gap for new pages left by KASLR is as small as 10TB. This results in early exit from iounmap() leading to leaking, and additional problems with rebinding devices to vfio_pci from other drivers with error of conflicting memtypes, as memtypes aren't freed in iounmap(). Replace comparison against high_memory with is_ioremap_addr() to fix the issue and make x86 iounmap() implementation more similar to generic one, it also uses is_ioremap_addr() to validate pointer. Fixes: 41e94a851304 ("add devm_memremap_pages") Signed-off-by: Max Ramanouski Reviewed-by: Christoph Hellwig --- arch/x86/mm/ioremap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index aa7d27932..464344da4 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -457,7 +458,7 @@ void iounmap(volatile void __iomem *addr) { struct vm_struct *p, *o; - if ((void __force *)addr <= high_memory) + if (!is_ioremap_addr(addr)) return; /*