From patchwork Sat Aug 24 22:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Ramanouski X-Patchwork-Id: 13776505 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 00AACC52D6F for ; Sat, 24 Aug 2024 22:04:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8555800F6; Sat, 24 Aug 2024 18:04:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E33FC800F0; Sat, 24 Aug 2024 18:04:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD53A800F6; Sat, 24 Aug 2024 18:04:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A9379800F0 for ; Sat, 24 Aug 2024 18:04:32 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0FAEBA80C7 for ; Sat, 24 Aug 2024 22:04:32 +0000 (UTC) X-FDA: 82488518784.29.58D746A Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf28.hostedemail.com (Postfix) with ESMTP id 44BE8C0017 for ; Sat, 24 Aug 2024 22:04:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KNaxzFuh; spf=pass (imf28.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.167.49 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=1724537052; 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=cI9QjfsYevZ0D06wl4+hXDHJRv8/BsCXbfcfhSDGJtY=; b=xmqf+9E0mlvFPX0zUNa/oxh38qD+S7xfJ2K0kAt3VMZmnSCAq+wuQU4MbN7TRcmFGHJrp2 QUixIUzdzue2+VNa7cf8Fh9J6FTlTo8EWQJJuKpnpJhAKx+nOhkbmHtxxSzQ0uUUjaTFeq LFEzAbqpMqV7lDuN2LnYZabct/i9SU8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KNaxzFuh; spf=pass (imf28.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.167.49 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=1724537052; a=rsa-sha256; cv=none; b=1o2eCmO1sIzwlyYVVcx4BFQUJSJtBkUug7Nb5Vl8hqcjGSh+/yQ4XL1c/HZwsx2LHoIHCQ nbgD14qRTW9rWMXXwpNypv2fpvxoYYsS+QpEK7LGNrfpWq1pzO+jvrqvFCbASlKn0DCDsc dz6khZs55q6XFdrLz34o/IjEtne/+18= Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5334b7c9bb2so632579e87.1 for ; Sat, 24 Aug 2024 15:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724537068; x=1725141868; 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=cI9QjfsYevZ0D06wl4+hXDHJRv8/BsCXbfcfhSDGJtY=; b=KNaxzFuhnzkpi3afUiFSjfKGAZsStObskHKLcmIzwxGGIQxwMnjEq31kRTYzv6LsZl brs/Kud0w2+/x+XDGJwB58O8n2dNaTi3WGWV5MjdgWSktO3B/x/iqpok8Lt78Cd2orI3 ofo2QZeVm7wc6ew9zT/3xnawqFsqAY2bzt8qrWT5zLPncJ2s13+zvUrvUsTDOuKS0fGS eFGtpW87ThVh8YHnl1V4qIUpfQDgGGeoQzcpOsyn6mYsLSGnGJPm4TXaVe1DYsOHoJvY IbkZPPmCtt9E3kLJCGwTW0cuGzfnAbD61DNYm2ZyUtM7XZN8mjQaiCDKH9rig5iU9v0K F3QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724537068; x=1725141868; 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=cI9QjfsYevZ0D06wl4+hXDHJRv8/BsCXbfcfhSDGJtY=; b=Gfj6kA1haPKFyY9waBV9yknFQuXCO15xS34siqAtYobOin1sFX6y81u7ZPT/48PAIx ElujddWOJkKDJSOjcFELB4HbLVw9b9RpL+QtPMSEE6OM+rlabtAtMMGw9Jd0mFYZuRnM 7NmHCZC6oBm5hyX2tB8m/iOmgK+oE4YeqtzOdSMyubWGM1xtlwb00jV3YlPAdLpdn6GH nzjcXKwBBrCGet1POMWq6cZebJfiSBgdKKVNgcxr0OtmRrwHmIOlrfG1gHn6q7y/r1Ny b7SlhFdAiOSLOoWVbWYX26Znu2A8KCNwo27QwHUrx1XmLM7Yg63+h77/3PSeqSAwAmV+ YeBw== X-Forwarded-Encrypted: i=1; AJvYcCXbrR/B7nLkzp/V1//0r3a0d0Aek/DbKNiG8+U0N+i/BFn+FZ3FTGre5d5IX9DCUeG/aWeEhXV0eQ==@kvack.org X-Gm-Message-State: AOJu0Yx3S5x+l/U1zjfvWsG0s2CH6W0/9qF8uOpiyJqtC50rhU0F5t+T NQdKA6pWkXdDr1LEngl1mulRPCaDJRL9OkJC8JpUlLRxGk4yg+2K X-Google-Smtp-Source: AGHT+IFCXCtvqXzxiLDv/dnRpCyVxJj80C3PmX+GUzcdKtnS2Rg9NwAHSCvh17A7hJE20kFnPYVTvA== X-Received: by 2002:a05:6512:3b98:b0:52f:cad0:2d4a with SMTP id 2adb3069b0e04-534387cd659mr2374970e87.9.1724537067876; Sat, 24 Aug 2024 15:04:27 -0700 (PDT) Received: from localhost.localdomain ([46.53.242.108]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea36f8dsm965968e87.96.2024.08.24.15.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 15:04:27 -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, linux-mm@kvack.org, tglx@linutronix.de, hch@infradead.org, apopple@nvidia.com Cc: Max Ramanouski , Christoph Hellwig Subject: [PATCH v4] x86/ioremap: Use is_ioremap_addr() in iounmap() Date: Sun, 25 Aug 2024 01:01:11 +0300 Message-ID: <20240824220111.84441-1-max8rr8@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 6oanjurbmnrsow5zzcqhe3x3uiwytoit X-Rspamd-Queue-Id: 44BE8C0017 X-Rspamd-Server: rspam11 X-HE-Tag: 1724537070-415031 X-HE-Meta: U2FsdGVkX1/ny95GASjMEJiap6xfcM9hm90qx2rI4mQxL6Mt7DVOzTgQRYCvohMQ6mepkUzZ8rm+GwY5Gr2bDAzREUvchkk7/a6DWJYQ9rVxHRwdrlb4bbr0lhM/bNoMFFS6p6JS5pDPx3C9YsczRxIpR2GYalOmD8+rSISwyqj8Pt9oQRABbOIRKodp1WBgFyZWHOLV5KLcpZAmCrcWjybC/fAYuz6PfV7YfXcL495RxlFy/mXjDUWMATsegG5uA98iGHjESR0crMN7hdUCBZkqEde+tu6OjLCHCSpyB2/LlUHBbHT88s9U8wvl0y1U3o0yb56+qtN2U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hc+PkfOohfE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.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: Restrict iounmap() to memory allocated in ioremap region, by using is_ioremap_addr(). Similarly to the generic iounmap() implementation. Additionally, add warning in case there is an attempt to iounmap() invalid memory, instead of silently exiting, thus helping to avoid incorrect usage of iounmap(). Due to VMALLOC_START on i386 not being present in asm/pgtable.h, include for asm/vmalloc.h had to be added to include/linux/ioremap.h. Reviewed-by: Christoph Hellwig Reviewed-by: Alistair Popple Signed-off-by: Max Ramanouski --- arch/x86/mm/ioremap.c | 3 ++- include/linux/ioremap.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index aa7d279321ea..70b02fc61d93 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 (WARN_ON_ONCE(!is_ioremap_addr((void __force *)addr))) return; /* diff --git a/include/linux/ioremap.h b/include/linux/ioremap.h index f0e99fc7dd8b..2bd1661fe9ad 100644 --- a/include/linux/ioremap.h +++ b/include/linux/ioremap.h @@ -4,6 +4,7 @@ #include #include +#include #if defined(CONFIG_HAS_IOMEM) || defined(CONFIG_GENERIC_IOREMAP) /*