From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E968C04AA7 for ; Wed, 15 May 2019 05:38:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 583282166E for ; Wed, 15 May 2019 05:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557898694; bh=VdgeS7LfnGpSS71DN+m5uT3nq2DbFueMnKgesOh1s1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iHfk8LJwpVKNFEjtDrHRKfDvrfJE6eAP8NB7JxW8DDyprPYe983ot2ywmMX1Wl7FP cb3NYtXZflJwDH8LHlObO5oCB6d8ZfJkpcxulb9S40+56lWco4Q4ntby7LpE6fn8ex vCSAMwpGgbf9UgO6Okaa7H5C7KH7MrR//K2OnCrU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726473AbfEOFiN (ORCPT ); Wed, 15 May 2019 01:38:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:52526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbfEOFiN (ORCPT ); Wed, 15 May 2019 01:38:13 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C959E21473; Wed, 15 May 2019 05:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557898692; bh=VdgeS7LfnGpSS71DN+m5uT3nq2DbFueMnKgesOh1s1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uW1MlsIatY9pUomqsOsHJPwKNMxkbMCpjlUk/JHjmQRLQ+bhGcru8KBVpsLc9gIsX zPbVRDG82kBXAjf+/Ja+s0DUPWqzFRnbQhFJy3PnQgfhV4hePYu7flLaHMhAqCysfx N4gg8ovEhU65ZNJgetBQLQMUlE0b/G8uWyVAHRrg= From: Masami Hiramatsu To: Steven Rostedt , Linus Torvalds , Shuah Khan , Arnaldo Carvalho de Melo , Peter Zijlstra Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Ingo Molnar , Andrew Morton , Changbin Du , Jann Horn , Kees Cook , Andy Lutomirski , Alexei Starovoitov , Nadav Amit , Joel Fernandes , yhs@fb.com Subject: [PATCH -tip v9 1/6] x86/uaccess: Allow access_ok() in irq context if pagefault_disabled Date: Wed, 15 May 2019 14:38:06 +0900 Message-Id: <155789868664.26965.7932665824135793317.stgit@devnote2> X-Mailer: git-send-email 2.17.1 In-Reply-To: <155789866428.26965.8344923934342528416.stgit@devnote2> References: <155789866428.26965.8344923934342528416.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org WARN_ON_IN_IRQ() assumes that the access_ok() and following user memory access can sleep. But this assumption is not always correct; when the pagefault is disabled, following memory access will just returns -EFAULT and never sleep. Add pagefault_disabled() check in WARN_ON_ONCE() so that it can ignore the case we call it with disabling pagefault. For this purpose, this modified pagefault_disabled() as an inline function. Signed-off-by: Masami Hiramatsu Acked-by: Steven Rostedt (VMware) --- arch/x86/include/asm/uaccess.h | 4 +++- include/linux/uaccess.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index c82abd6e4ca3..9c4435307ff8 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -66,7 +66,9 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un }) #ifdef CONFIG_DEBUG_ATOMIC_SLEEP -# define WARN_ON_IN_IRQ() WARN_ON_ONCE(!in_task()) +static inline bool pagefault_disabled(void); +# define WARN_ON_IN_IRQ() \ + WARN_ON_ONCE(!in_task() && !pagefault_disabled()) #else # define WARN_ON_IN_IRQ() #endif diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 2b70130af585..5a43ef7db492 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -203,7 +203,10 @@ static inline void pagefault_enable(void) /* * Is the pagefault handler disabled? If so, user access methods will not sleep. */ -#define pagefault_disabled() (current->pagefault_disabled != 0) +static inline bool pagefault_disabled(void) +{ + return current->pagefault_disabled != 0; +} /* * The pagefault handler is in general disabled by pagefault_disable() or