All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yaohui Wang <yaohuiwang@linux.alibaba.com>
To: dave.hansen@linux.intel.com
Cc: luto@kernel.org, peterz@infradead.org, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, x86@kernel.org,
	linux-kernel@vger.kernel.org, Ben Luo <luoben@linux.alibaba.com>,
	Yahui Wang <yaohuiwang@linux.alibaba.com>
Subject: [PATCH v2 1/2] mm: fix the pfn calculation mistake in __ioremap_check_ram
Date: Fri, 11 Jun 2021 12:21:46 +0800	[thread overview]
Message-ID: <20210611042147.80744-2-yaohuiwang@linux.alibaba.com> (raw)
In-Reply-To: <20210611042147.80744-1-yaohuiwang@linux.alibaba.com>

In arch/x86/mm/ioremap.c:__ioremap_check_ram, the original pfn wrapping
calculation may cause the pfn range to ignore the very start page, if
res->start is not page-aligned, or the very end page, if res->end is not
page aligned.

So start_pfn should wrap down the res->start address, and end_pfn should
wrap up the res->end address. This makes the pfn range completely
contain [res->start, res->end] ram range. This check is more strict and is
more reasonable.

Signed-off-by: Ben Luo <luoben@linux.alibaba.com>
Signed-off-by: Yahui Wang <yaohuiwang@linux.alibaba.com>
---
 arch/x86/mm/ioremap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 9e5ccc56f..79adf0d2d 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -74,8 +74,8 @@ static unsigned int __ioremap_check_ram(struct resource *res)
 	if ((res->flags & IORESOURCE_SYSTEM_RAM) != IORESOURCE_SYSTEM_RAM)
 		return 0;
 
-	start_pfn = (res->start + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	stop_pfn = (res->end + 1) >> PAGE_SHIFT;
+	start_pfn = res->start >> PAGE_SHIFT;
+	stop_pfn = (res->end + PAGE_SIZE) >> PAGE_SHIFT;
 	if (stop_pfn > start_pfn) {
 		for (i = 0; i < (stop_pfn - start_pfn); ++i)
 			if (pfn_valid(start_pfn + i) &&
-- 
2.25.1


  reply	other threads:[~2021-06-11  4:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11  4:21 [PATCH v2 0/2] mm: unexpected behavior of __ioremap_caller Yaohui Wang
2021-06-11  4:21 ` Yaohui Wang [this message]
2021-06-19 21:22   ` [PATCH v2 1/2] mm: fix the pfn calculation mistake in __ioremap_check_ram Thomas Gleixner
2021-06-21  8:06     ` Thomas Gleixner
2021-06-11  4:21 ` [PATCH v2 2/2] mm: fix boundary judgment issues in kernel/resource.c Yaohui Wang
2021-06-19 22:16   ` Thomas Gleixner
2021-06-21  6:12     ` Yaohui Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210611042147.80744-2-yaohuiwang@linux.alibaba.com \
    --to=yaohuiwang@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luoben@linux.alibaba.com \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.