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 390 } 391 391 392 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 393 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 402 394 unsigned long size, pgprot_t vma_prot) 403 395 { ··· 427 435 unsigned long size, pgprot_t *vma_prot) 428 436 { 429 437 u64 offset = ((u64) pfn) << PAGE_SHIFT; 430 - unsigned long flags = _PAGE_CACHE_UC_MINUS; 438 + unsigned long flags = -1; 431 439 int retval; 432 440 433 441 if (!range_is_allowed(pfn, size)) 434 442 return 0; 435 443 436 444 if (file->f_flags & O_SYNC) { 437 - flags = _PAGE_CACHE_UC; 445 + flags = _PAGE_CACHE_UC_MINUS; 438 446 } 439 447 440 448 #ifdef CONFIG_X86_32 ··· 457 465 #endif 458 466 459 467 /* 460 - * With O_SYNC, we can only take UC mapping. Fail if we cannot. 468 + * With O_SYNC, we can only take UC_MINUS mapping. Fail if we cannot. 469 + * 461 470 * Without O_SYNC, we want to get 462 471 * - WB for WB-able memory and no other conflicting mappings 463 472 * - UC_MINUS for non-WB-able memory with no other conflicting mappings 464 473 * - Inherit from confliting mappings otherwise 465 474 */ 466 - if (flags != _PAGE_CACHE_UC_MINUS) { 475 + if (flags != -1) { 467 476 retval = reserve_memtype(offset, offset + size, flags, NULL); 468 477 } else { 469 478 retval = reserve_memtype(offset, offset + size, -1, &flags);