[PATCH v2 01/12] MIPS: Fix definition of KSEGX() for 64-bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The KSEGX() macro is defined to 32-bit sign extend the address argument
and logically AND the result with 0xe0000000, with the final result
usually compared against one of the CKSEG macros. However the literal
0xe0000000 is unsigned as the high bit is set, and is therefore
zero-extended on 64-bit kernels, resulting in the sign extension bits of
the argument being masked to zero. This results in the odd situation
where:

  KSEGX(CKSEG0) != CKSEG0
  (0xffffffff80000000 & 0x00000000e0000000) != 0xffffffff80000000)

Fix this by 32-bit sign extending the 0xe0000000 literal using
_ACAST32_.

This will help some MIPS KVM code handling 32-bit guest addresses to
work on 64-bit host kernels, but will also affect a couple of other
users:

- KSEGX in dec_kn01_be_backend() on a 64-bit DECstation kernel. Maciej
  has confirmed this is not a valid combination.

- The SiByte DMA page ops KSEGX check in clear_page() and copy_page() on
  64-bit SB1 kernels, which appears not to be designed with 64-bit
  segments in mind anyway. This would (perhaps unintentionally) have
  always fallen back to the CPU copy on 64-bit kernels anyway, so we
  make this explicit by making CONFIG_SIBYTE_DMA_PAGEOPS depend on
  32BIT, so the change of KSEGX behaviour can't break anything.

Signed-off-by: James Hogan <james.hogan@xxxxxxxxxx>
Cc: Ralf Baechle <ralf@xxxxxxxxxxxxxx>
Cc: Maciej W. Rozycki <macro@xxxxxxxxxxxxxx>
Cc: linux-mips@xxxxxxxxxxxxxx
---
Changes in v2:
- Clarify that the DEC code in question shouldn't get used with 64-bit
  kernels (thanks Maciej).
- Make SIBYTE_DMA_PAGEOPS depend on 32BIT so the dependence is explicit
  and so we don't break anything.
- Correct CKSEG -> CKSEG0 in patch description.
---
 arch/mips/Kconfig                 | 2 +-
 arch/mips/include/asm/addrspace.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index ac91939b9b75..86a9abd398f5 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2195,7 +2195,7 @@ config RM7000_CPU_SCACHE
 
 config SIBYTE_DMA_PAGEOPS
 	bool "Use DMA to clear/copy pages"
-	depends on CPU_SB1
+	depends on CPU_SB1 && 32BIT
 	help
 	  Instead of using the CPU to zero and copy pages, use a Data Mover
 	  channel.  These DMA channels are otherwise unused by the standard
diff --git a/arch/mips/include/asm/addrspace.h b/arch/mips/include/asm/addrspace.h
index 3b0e51d5a613..c5b04e752e97 100644
--- a/arch/mips/include/asm/addrspace.h
+++ b/arch/mips/include/asm/addrspace.h
@@ -45,7 +45,7 @@
 /*
  * Returns the kernel segment base of a given address
  */
-#define KSEGX(a)		((_ACAST32_ (a)) & 0xe0000000)
+#define KSEGX(a)		((_ACAST32_(a)) & _ACAST32_(0xe0000000))
 
 /*
  * Returns the physical address of a CKSEGx / XKPHYS address
-- 
2.4.10





[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux