devmem, x86: PAT Change /dev/mem mmap with O_SYNC to use UC_MINUS

All kernel mappings like ioremap(), etc uses UC_MINUS as the type. /dev/mem
mappings with /dev/mem being opened with O_SYNC however was using UC,
resulting in a conflict with /dev/mem mmap failing. This seems to be
affecting some apps (one being flashrom) which are using O_SYNC and which were
working before.

Switch /dev/mem with O_SYNC also to UC_MINUS.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by venkatesh.pallipadi@intel.com and committed by Ingo Molnar 28df82eb c15238df

+5 -12
+5 -12
arch/x86/mm/pat.c
··· 390 } 391 392 393 - /* 394 - * /dev/mem mmap interface. The memtype used for mapping varies: 395 - * - Use UC for mappings with O_SYNC flag 396 - * - Without O_SYNC flag, if there is any conflict in reserve_memtype, 397 - * inherit the memtype from existing mapping. 398 - * - Else use UC_MINUS memtype (for backward compatibility with existing 399 - * X drivers. 400 - */ 401 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 402 unsigned long size, pgprot_t vma_prot) 403 { ··· 427 unsigned long size, pgprot_t *vma_prot) 428 { 429 u64 offset = ((u64) pfn) << PAGE_SHIFT; 430 - unsigned long flags = _PAGE_CACHE_UC_MINUS; 431 int retval; 432 433 if (!range_is_allowed(pfn, size)) 434 return 0; 435 436 if (file->f_flags & O_SYNC) { 437 - flags = _PAGE_CACHE_UC; 438 } 439 440 #ifdef CONFIG_X86_32 ··· 457 #endif 458 459 /* 460 - * With O_SYNC, we can only take UC mapping. Fail if we cannot. 461 * Without O_SYNC, we want to get 462 * - WB for WB-able memory and no other conflicting mappings 463 * - UC_MINUS for non-WB-able memory with no other conflicting mappings 464 * - Inherit from confliting mappings otherwise 465 */ 466 - if (flags != _PAGE_CACHE_UC_MINUS) { 467 retval = reserve_memtype(offset, offset + size, flags, NULL); 468 } else { 469 retval = reserve_memtype(offset, offset + size, -1, &flags);
··· 390 } 391 392 393 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 394 unsigned long size, pgprot_t vma_prot) 395 { ··· 435 unsigned long size, pgprot_t *vma_prot) 436 { 437 u64 offset = ((u64) pfn) << PAGE_SHIFT; 438 + unsigned long flags = -1; 439 int retval; 440 441 if (!range_is_allowed(pfn, size)) 442 return 0; 443 444 if (file->f_flags & O_SYNC) { 445 + flags = _PAGE_CACHE_UC_MINUS; 446 } 447 448 #ifdef CONFIG_X86_32 ··· 465 #endif 466 467 /* 468 + * With O_SYNC, we can only take UC_MINUS mapping. Fail if we cannot. 469 + * 470 * Without O_SYNC, we want to get 471 * - WB for WB-able memory and no other conflicting mappings 472 * - UC_MINUS for non-WB-able memory with no other conflicting mappings 473 * - Inherit from confliting mappings otherwise 474 */ 475 + if (flags != -1) { 476 retval = reserve_memtype(offset, offset + size, flags, NULL); 477 } else { 478 retval = reserve_memtype(offset, offset + size, -1, &flags);