From patchwork Thu Aug 15 20:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Ramanouski X-Patchwork-Id: 13765153 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 74D0AC3DA7F for ; Thu, 15 Aug 2024 21:00:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 970FE6B01A5; Thu, 15 Aug 2024 17:00:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 920596B01A6; Thu, 15 Aug 2024 17:00:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E8196B01A7; Thu, 15 Aug 2024 17:00:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 673926B01A5 for ; Thu, 15 Aug 2024 17:00:31 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0F96F1613B8 for ; Thu, 15 Aug 2024 21:00:31 +0000 (UTC) X-FDA: 82455698262.05.EE8F923 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf18.hostedemail.com (Postfix) with ESMTP id 3253F1C003A for ; Thu, 15 Aug 2024 21:00:28 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l17OOGAn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=max8rr8@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723755547; 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=nw+i6a5BQdCkk4Mdx+fFTiDbWj87Rjwq5IfRXwZ8bow=; b=NjCHnGhid2+mLyIi+LVBL48irinRv9eQn8ITjnSr4YiFXjBUBjwwXwWT5ycZ4uqlVpMZLL 9KCfzIhWbMUuL52IkKhyCz2lO+VJ3+GwLR/TZYWRI7jQN1fJ40Dn2AbeepQ2Y/4HlWopSE T/GEbHs1Iy1ViF6afQUMkCFde08te0M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723755547; a=rsa-sha256; cv=none; b=tgAtZl470n7XJglPvfK0JjGigtjLlhfUuc+Ihe/5UVivR4ZxL+UyvJrA3EkX2wqb6RJHQw jNdm9mLSMCYz9DoYh8pH7xXi3uzdkdtbcEHqlRBwqJsRhdRJeWQEdOnJAcfdj8623uFErm nf4DmlDEJJQDu/GtFvtcqVLjTn4lDw8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l17OOGAn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of max8rr8@gmail.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=max8rr8@gmail.com Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-52f01613acbso2823900e87.1 for ; Thu, 15 Aug 2024 14:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723755627; x=1724360427; 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=nw+i6a5BQdCkk4Mdx+fFTiDbWj87Rjwq5IfRXwZ8bow=; b=l17OOGAnE+OjdSy4/5yd0eHLUiRLUaCMyj2XcN0hqss/BxDmHxsK8JDi3Xfx2j0kH7 7Qm0uK7UdGB1iB7K2AJ9nPmcd2Kiai36aymbZAmkfoXs7HYbNnHq0tghNX2FL5v6ecRb b3htqEfLGoBmWkOkU1dFPR2tuzp3W2Glrp96MHd+d6xvk/615tAl+HihfdiRJ7BQNioN ZbzXm/QjJKA5npSZI+S+/PqN4rQ9pr6B4sH8Dhvrs1bPk102qK9uvn8+T7mdyKJPjI6p U4bnImn5zsB3a+r7os8uD7BfvdZHuV960B7cXpMs6o7Gfl078RlxaM2SiKdcYmKCB/zh 3BXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723755627; x=1724360427; 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=nw+i6a5BQdCkk4Mdx+fFTiDbWj87Rjwq5IfRXwZ8bow=; b=Hhht2lTKoyWKnbSHq/s3mPea5fM1lFBEWbe+3zMPrYy9np2b9hi3kl7jRW5juQRJh0 X/rn0vAl1hkjw9jJqwdxSLBg4YovH86fkLnq8WUf5D3shYF4AGm7g5S04ECWrX6e9YOD 8NSrbzblcMUabRz8DjZ3rDAvH+MNda36WLBRtguPPlhIkKsJaA2YA9TEx+GuOY+EoBMe r8oAMIFMgDM7twtHbLkEjXb3luncITQ46G0HkmCioStkBSUoobtDidH/nH+jzpyqoyR0 POPfAOyNsMtjZgZjoXBG/QKNf9VVk4OHPbku1ueFQOAAJgbA14jkOIgwMHavEFdQrAPv 84VQ== X-Forwarded-Encrypted: i=1; AJvYcCV4awaaUWG3sG005cW9P+DZEzaHKevylzCBg82I5B6Iou8EUkKpcOfE/sIZdRWpwVelnq+8YdzwxvPJKiGx2YQGkXU= X-Gm-Message-State: AOJu0Yw+u8jbKIznoOhwpyXt9/1rH0MZwuBSnH86SJIUMbkf1kwZCQL+ ZQ+D7PD8OFxvXjapxLv25vPCdNyLG5hk97zaT2Ar9D1lMtn17aXj X-Google-Smtp-Source: AGHT+IFWbSQBpKicv3Y8V2rBGWp+KhKB1btNuBp2B33rekQlBdE3v7MLXbPaGifVd1rmUt5je4u8SA== X-Received: by 2002:a05:6512:b10:b0:52d:ab43:b276 with SMTP id 2adb3069b0e04-53307f740c2mr1076264e87.2.1723755626896; Thu, 15 Aug 2024 14:00:26 -0700 (PDT) Received: from localhost.localdomain (nat2-minsk-pool-46-53-193-144.telecom.by. [46.53.193.144]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5330d42466csm331998e87.257.2024.08.15.14.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2024 14:00:26 -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, hch@infradead.org, apopple@nvidia.com Cc: Max Ramanouski , Christoph Hellwig Subject: [PATCH v3] x86/ioremap: Use is_ioremap_addr() in iounmap() Date: Thu, 15 Aug 2024 23:56:07 +0300 Message-ID: <20240815205606.16051-2-max8rr8@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3253F1C003A X-Stat-Signature: 8cabg9ojxmu4q95xz6537a9arrenyjgp X-Rspam-User: X-HE-Tag: 1723755628-854078 X-HE-Meta: U2FsdGVkX18uAG52jK/1XHIi4mVfNB+6yFd8qSriVsRMd0nAKR+K1Pe5/HpMGgshX69rMzbkqP91ci8io+NbPVcWI0l3q6Xorp21k1EYQY+g3+PfnJmWPwvA6XwGqGGeLjPmN/54dLu3P4wr2eMLvXJfBi4VfzT+AGEeqiZf8AaKb3pdO/m+jF7qM08CUs4J/9g9d4dDd2iIljSsQo9ldFNh51qA43ow29UKabFC20T3S3A+rhiQRUesIiibA37W8DnS+5EDqRJTT3AMo56zz4f2D5kdQR2A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GzOtSJCwMhKvn2t87GYyuqtc9Q== 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(). Reviewed-by: Christoph Hellwig Signed-off-by: Max Ramanouski Reviewed-by: Alistair Popple --- 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 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; /*