linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Leesoo Ahn <lsahn@ooseel.net>
To: lsahn@wewakecorp.com
Cc: Leesoo Ahn <lsahn@ooseel.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mmzone: remove redundant exception handler on pfn_valid()
Date: Thu, 26 Sep 2024 00:55:28 +0900	[thread overview]
Message-ID: <20240925155540.4087150-1-lsahn@ooseel.net> (raw)

1). It can ensure the upper PAGE_SHIFT'ed bits of PHYS_PFN(..) are clear
by the C11 standard:

    6.5.7 Bitwise shift operator

    ...

    The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has
    an unsigned type or if E1 has a signed type and a nonnegative value,
    the value of the result is the integral part of the quotient of E1 / 2^E2.

@pfn parameter of pfn_valid(..) is unsigned long and PHYS_PFN(..) makes
the upper bits clear(zero) always with it. Otherwise, the result of E1 / 2^E2
doesn't make sense in the document.

2). x86 instructions

The following x86 instructions are the part of the redundant exception handler:

    ...
    movabs  $0xfffffffffffff,%rax
    and     %rdi,%rax
    cmp     %rax,%rdi
    je      22
    xor     %eax,%eax
    jmp     __x86_return_thunk
22: push    %rbp
    ...

%rdi would be the @pfn parameter of pfn_valid(..) and -1 assigned to %rax.
'je' always takes place by %rdi AND and CMP ops with %rax.

Therefore, the exception handler is unnecessary.

Signed-off-by: Leesoo Ahn <lsahn@ooseel.net>
---
 include/linux/mmzone.h | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 17506e4a2835..164ae80977d6 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -2028,15 +2028,6 @@ static inline int pfn_valid(unsigned long pfn)
 	struct mem_section *ms;
 	int ret;
 
-	/*
-	 * Ensure the upper PAGE_SHIFT bits are clear in the
-	 * pfn. Else it might lead to false positives when
-	 * some of the upper bits are set, but the lower bits
-	 * match a valid pfn.
-	 */
-	if (PHYS_PFN(PFN_PHYS(pfn)) != pfn)
-		return 0;
-
 	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
 		return 0;
 	ms = __pfn_to_section(pfn);
-- 
2.46.0



             reply	other threads:[~2024-09-25 15:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 15:55 Leesoo Ahn [this message]
2024-09-25 17:59 ` Matthew Wilcox

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=20240925155540.4087150-1-lsahn@ooseel.net \
    --to=lsahn@ooseel.net \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lsahn@wewakecorp.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox