lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon,  9 Dec 2019 19:42:47 +0200
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
        linux-kernel@...r.kernel.org
Cc:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h

Use predefined macros from mm.h instead of open coded PAGE_ALIGNED()
and PFN_DOWN(). This will show explicitly the meaning of the operations.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
 arch/x86/kernel/cpu/mtrr/if.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index 4d36dcc1cf87..a51eb8e4c079 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -2,6 +2,7 @@
 #include <linux/capability.h>
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
+#include <linux/mm.h>
 #include <linux/proc_fs.h>
 #include <linux/ctype.h>
 #include <linux/string.h>
@@ -49,10 +50,10 @@ mtrr_file_add(unsigned long base, unsigned long size,
 		FILE_FCOUNT(file) = fcount;
 	}
 	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
+		if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
 			return -EINVAL;
-		base >>= PAGE_SHIFT;
-		size >>= PAGE_SHIFT;
+		base = PFN_DOWN(base);
+		size = PFN_DOWN(size);
 	}
 	reg = mtrr_add_page(base, size, type, true);
 	if (reg >= 0)
@@ -68,10 +69,10 @@ mtrr_file_del(unsigned long base, unsigned long size,
 	int reg;
 
 	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
+		if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
 			return -EINVAL;
-		base >>= PAGE_SHIFT;
-		size >>= PAGE_SHIFT;
+		base = PFN_DOWN(base);
+		size = PFN_DOWN(size);
 	}
 	reg = mtrr_del_page(-1, base, size);
 	if (reg < 0)
@@ -134,7 +135,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
 		return -EINVAL;
 
 	size = simple_strtoull(ptr + 5, &ptr, 0);
-	if ((base & 0xfff) || (size & 0xfff))
+	if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
 		return -EINVAL;
 	ptr = skip_spaces(ptr);
 
@@ -146,8 +147,8 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
 	if (i < 0)
 		return i;
 
-	base >>= PAGE_SHIFT;
-	size >>= PAGE_SHIFT;
+	base = PFN_DOWN(base);
+	size = PFN_DOWN(size);
 	err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
 	if (err < 0)
 		return err;
-- 
2.24.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ