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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED 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 A0948C5ACC6 for ; Tue, 16 Oct 2018 19:21:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5330D21470 for ; Tue, 16 Oct 2018 19:21:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="TRru2n0U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5330D21470 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727180AbeJQDN1 (ORCPT ); Tue, 16 Oct 2018 23:13:27 -0400 Received: from mail.efficios.com ([167.114.142.138]:49424 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbeJQDN1 (ORCPT ); Tue, 16 Oct 2018 23:13:27 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 7EE8B1C1436; Tue, 16 Oct 2018 15:21:32 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 4bpQKrKkwDmh; Tue, 16 Oct 2018 15:21:32 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 084FD1C1433; Tue, 16 Oct 2018 15:21:32 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 084FD1C1433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1539717692; bh=fEfleuhAi5SOPsml1IkkTXbb3NbR3igmWeKbfGT90fk=; h=Date:From:To:Message-ID:MIME-Version; b=TRru2n0UGTToyr1mIMo+wJTz76VQV9mMCxX32Wbp2c2ckYWpP6FbD+8a0RyjJcKeo MzkvIkhVa+CjuiwU2PIYusJ3tXWPMNvoQjPjW6BXB63Sz2rXqUScAMKzCjvoanf8yJ xyG2KMGip6gvR0zQxrV5CoaDJFhN9jeZFfisTp7mf2rAm91WDsgzTsLxBgWhwzp8tS MWMD85Erxla9/99gXjxRh1Ow6u0AaxmnHmNhnw2aU01Kg/l+Y1Lq+4Au1Vopqo7PkK sunOGvS+mMe5e8Zi7XYQGfNgwf6tJ5bQWjuNzs8NijZ1rmyNO7zJoVX0ebd9g9fq/e lJ8hIUkJDp1Ng== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id oU5wX8hk8BJQ; Tue, 16 Oct 2018 15:21:31 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id D77A51C1428; Tue, 16 Oct 2018 15:21:31 -0400 (EDT) Date: Tue, 16 Oct 2018 15:21:31 -0400 (EDT) From: Mathieu Desnoyers To: rostedt Cc: Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , linux-kernel , linux-api , Thomas Gleixner , Andy Lutomirski , Dave Watson , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H. Peter Anvin" , Andi Kleen , Chris Lameter , Ben Maurer , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes , Sergey Senozhatsky Message-ID: <1635827931.274.1539717691833.JavaMail.zimbra@efficios.com> In-Reply-To: <20181016143016.10da89bd@gandalf.local.home> References: <20181010191936.7495-1-mathieu.desnoyers@efficios.com> <20181010191936.7495-5-mathieu.desnoyers@efficios.com> <20181016143016.10da89bd@gandalf.local.home> Subject: Re: [RFC PATCH for 4.21 04/16] mm: Introduce vm_map_user_ram, vm_unmap_user_ram MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.10_GA_3039 (ZimbraWebClient - FF52 (Linux)/8.8.10_GA_3041) Thread-Topic: Introduce vm_map_user_ram, vm_unmap_user_ram Thread-Index: J9PjQ3wWUWJncBLA8CDA+ZxmePYh0w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Oct 16, 2018, at 2:30 PM, rostedt rostedt@goodmis.org wrote: > On Wed, 10 Oct 2018 15:19:24 -0400 > Mathieu Desnoyers wrote: > >> + * vm_unmap_user_ram - unmap linear kernel address space set up by >> vm_map_user_ram >> + * @mem: the pointer returned by vm_map_user_ram >> + * @count: the count passed to that vm_map_user_ram call (cannot unmap partial) >> + */ >> +void vm_unmap_user_ram(const void *mem, unsigned int count) >> +{ >> + unsigned long size = (unsigned long)count << PAGE_SHIFT; >> + unsigned long addr = (unsigned long)mem; >> + struct vmap_area *va; >> + >> + might_sleep(); >> + BUG_ON(!addr); >> + BUG_ON(addr < VMALLOC_START); >> + BUG_ON(addr > VMALLOC_END); >> + BUG_ON(!PAGE_ALIGNED(addr)); >> + >> + debug_check_no_locks_freed(mem, size); >> + va = find_vmap_area(addr); >> + BUG_ON(!va); >> + free_unmap_vmap_area(va); >> +} >> +EXPORT_SYMBOL(vm_unmap_user_ram); >> + > > Noticing this from Sergey's question in another patch, why are you > using BUG_ON()? That's rather extreme and something we are trying to > avoid adding more of (I still need to remove the BUG_ON()s I've added > over ten years ago). I don't see why all these BUG_ON's can't be turned > into: > > if (WARN_ON(x)) > return; I borrowed the code from vm_unmap_ram(), which has the following checks: BUG_ON(!addr); BUG_ON(addr < VMALLOC_START); BUG_ON(addr > VMALLOC_END); BUG_ON(!PAGE_ALIGNED(addr)); [...] va = find_vmap_area(addr); BUG_ON(!va); The expectation here is that inputs to vm_unmap_ram() should always come from vm_map_ram(), so an erroneous input is an internal kernel bug. I applied the same logic to vm_unmap_user_ram() and vm_map_user_ram(). Should we turn all those BUG_ON() into if (WARN_ON(x)) return; in vm_{map,unmap}_ram as well ? Thanks, Mathieu > > -- Steve -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com