Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1929344imu; Fri, 23 Nov 2018 02:12:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xiufendan/rB57opyEC6Pc0fSHvalUmhX00cZDpjFF2lW37pnqiA1gxgTwn8x2/V5QQTNA X-Received: by 2002:a63:4a4d:: with SMTP id j13mr13680173pgl.127.1542967971923; Fri, 23 Nov 2018 02:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542967971; cv=none; d=google.com; s=arc-20160816; b=PUDyH9ZHB0cw3jMxfg6HoVUD0fVSB2sch8Q2g9L0mFaGOY66/7f8WSiXthkhqqDz08 sZ2AW9FaqNi7ARR9hvBtPTxNagIFgaAf3XV0sN9g69o7ArslGg1YtaAZQSWrOHmqUujL MN9YwhytzvSnj0u/P3zq8/v6SfrnkNGWFlX2EmRa3Q9s1CBrnxZTRvmpVo0BRfuYdV/o qswDVpiH2l5tJTmlZ9M9C1VubvC9hEnhB540eJhB9fb4wcGOYCxunhzof5SfRDOyYWx1 /ZE9aKvDlrbMEAbArbXKN/KdxukzA+Ok8aSzK7Vjo7qrSH8oebwj/hAC0ENpwUqkAoG2 9Bqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=K6f43cJ+F046Ucu9AmcPuR74+tT26zlvfl2p76vQfvY=; b=JIPOROhCYdrK0HK4uSAJLUL84DnXfcw+9cziquJhLKR7dJCUHoYVqMa82qkJV9pjxl 68XtF+aLzsXU3uWaAcVcYuFZXNa8uvhVSGVgiPPizo02PYg+tRpTO4Ju5Rac6VqJ6BrQ VRHZjGbXySj7IiqpNM3P6FZUkwq/ey0Agp4J2Wa9FR+5B9MJNFWLb8s5ntXWElpYM1qT 3ZxQ44OCTIqGFJdNzU2rYOoHNc2uirtO5UbN9Fh5PAc9v459tijbQTlKFGZAtKsglmLm 3D2PAPNs0EVYbNEHgwVOrWPK+lCn3p2qo0ZF/IG4qgqCmPzO1Pl+U3SghezilB/kgTCV Mfzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si52075693pga.297.2018.11.23.02.12.35; Fri, 23 Nov 2018 02:12:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393895AbeKVUtT (ORCPT + 99 others); Thu, 22 Nov 2018 15:49:19 -0500 Received: from terminus.zytor.com ([198.137.202.136]:41211 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390426AbeKVUtT (ORCPT ); Thu, 22 Nov 2018 15:49:19 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wAMA9sWt3743618 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 22 Nov 2018 02:09:54 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wAMA9svG3743615; Thu, 22 Nov 2018 02:09:54 -0800 Date: Thu, 22 Nov 2018 02:09:54 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Andy Lutomirski Message-ID: Cc: hpa@zytor.com, mingo@kernel.org, torvalds@linux-foundation.org, dave.hansen@linux.intel.com, bp@alien8.de, tglx@linutronix.de, linux-kernel@vger.kernel.org, peterz@infradead.org, luto@kernel.org, yu-cheng.yu@intel.com, riel@surriel.com Reply-To: dave.hansen@linux.intel.com, bp@alien8.de, tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, yu-cheng.yu@intel.com, peterz@infradead.org, luto@kernel.org, riel@surriel.com In-Reply-To: <078f5b8ae6e8c79ff8ee7345b5c476c45003e5ac.1542841400.git.luto@kernel.org> References: <078f5b8ae6e8c79ff8ee7345b5c476c45003e5ac.1542841400.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/fault: Remove sw_error_code Git-Commit-ID: 0ed32f1aa66ee758e6c8164f549f7ff9d399a20e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0ed32f1aa66ee758e6c8164f549f7ff9d399a20e Gitweb: https://git.kernel.org/tip/0ed32f1aa66ee758e6c8164f549f7ff9d399a20e Author: Andy Lutomirski AuthorDate: Wed, 21 Nov 2018 15:11:22 -0800 Committer: Ingo Molnar CommitDate: Thu, 22 Nov 2018 09:22:59 +0100 x86/fault: Remove sw_error_code All of the fault handling code now corrently checks user_mode(regs) as needed, and nothing depends on the X86_PF_USER bit being munged. Get rid of the sw_error code and use hw_error_code everywhere. Signed-off-by: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: Thomas Gleixner Cc: Yu-cheng Yu Link: http://lkml.kernel.org/r/078f5b8ae6e8c79ff8ee7345b5c476c45003e5ac.1542841400.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/mm/fault.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index b898a38093a3..82881bc5feef 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1217,7 +1217,6 @@ void do_user_addr_fault(struct pt_regs *regs, unsigned long hw_error_code, unsigned long address) { - unsigned long sw_error_code; struct vm_area_struct *vma; struct task_struct *tsk; struct mm_struct *mm; @@ -1262,13 +1261,6 @@ void do_user_addr_fault(struct pt_regs *regs, return; } - /* - * hw_error_code is literally the "page fault error code" passed to - * the kernel directly from the hardware. But, we will shortly be - * modifying it in software, so give it a new name. - */ - sw_error_code = hw_error_code; - /* * It's safe to allow irq's after cr2 has been saved and the * vmalloc fault has been handled. @@ -1278,26 +1270,6 @@ void do_user_addr_fault(struct pt_regs *regs, */ if (user_mode(regs)) { local_irq_enable(); - /* - * Up to this point, X86_PF_USER set in hw_error_code - * indicated a user-mode access. But, after this, - * X86_PF_USER in sw_error_code will indicate either - * that, *or* an implicit kernel(supervisor)-mode access - * which originated from user mode. - */ - if (!(hw_error_code & X86_PF_USER)) { - /* - * The CPU was in user mode, but the CPU says - * the fault was not a user-mode access. - * Must be an implicit kernel-mode access, - * which we do not expect to happen in the - * user address space. - */ - pr_warn_once("kernel-mode error from user-mode: %lx\n", - hw_error_code); - - sw_error_code |= X86_PF_USER; - } flags |= FAULT_FLAG_USER; } else { if (regs->flags & X86_EFLAGS_IF) @@ -1306,9 +1278,9 @@ void do_user_addr_fault(struct pt_regs *regs, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); - if (sw_error_code & X86_PF_WRITE) + if (hw_error_code & X86_PF_WRITE) flags |= FAULT_FLAG_WRITE; - if (sw_error_code & X86_PF_INSTR) + if (hw_error_code & X86_PF_INSTR) flags |= FAULT_FLAG_INSTRUCTION; #ifdef CONFIG_X86_64 @@ -1321,7 +1293,7 @@ void do_user_addr_fault(struct pt_regs *regs, * The vsyscall page does not have a "real" VMA, so do this * emulation before we go searching for VMAs. */ - if ((sw_error_code & X86_PF_INSTR) && is_vsyscall_vaddr(address)) { + if ((hw_error_code & X86_PF_INSTR) && is_vsyscall_vaddr(address)) { if (emulate_vsyscall(regs, address)) return; } @@ -1345,7 +1317,7 @@ void do_user_addr_fault(struct pt_regs *regs, * Fault from code in kernel from * which we do not expect faults. */ - bad_area_nosemaphore(regs, sw_error_code, address); + bad_area_nosemaphore(regs, hw_error_code, address); return; } retry: @@ -1361,17 +1333,17 @@ retry: vma = find_vma(mm, address); if (unlikely(!vma)) { - bad_area(regs, sw_error_code, address); + bad_area(regs, hw_error_code, address); return; } if (likely(vma->vm_start <= address)) goto good_area; if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) { - bad_area(regs, sw_error_code, address); + bad_area(regs, hw_error_code, address); return; } if (unlikely(expand_stack(vma, address))) { - bad_area(regs, sw_error_code, address); + bad_area(regs, hw_error_code, address); return; } @@ -1380,8 +1352,8 @@ retry: * we can handle it.. */ good_area: - if (unlikely(access_error(sw_error_code, vma))) { - bad_area_access_error(regs, sw_error_code, address, vma); + if (unlikely(access_error(hw_error_code, vma))) { + bad_area_access_error(regs, hw_error_code, address, vma); return; } @@ -1420,13 +1392,13 @@ good_area: return; /* Not returning to user mode? Handle exceptions or die: */ - no_context(regs, sw_error_code, address, SIGBUS, BUS_ADRERR); + no_context(regs, hw_error_code, address, SIGBUS, BUS_ADRERR); return; } up_read(&mm->mmap_sem); if (unlikely(fault & VM_FAULT_ERROR)) { - mm_fault_error(regs, sw_error_code, address, fault); + mm_fault_error(regs, hw_error_code, address, fault); return; }