Received: by 10.192.165.148 with SMTP id m20csp1272903imm; Fri, 27 Apr 2018 16:21:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoneRwLRQt2pOmkdTJTZhXf58PauZeG380JEx2zEwonROg+WkRSkt/AvBXE1Oiv3fZeAehM X-Received: by 10.98.5.196 with SMTP id 187mr3785382pff.151.1524871292281; Fri, 27 Apr 2018 16:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524871292; cv=none; d=google.com; s=arc-20160816; b=fJteQ0b5KC4LS5cWrXDgjzmPWODDYweF/YggygfYoWcLWzRjJRKzPVoKJFBEiOY4LB hRyGoPGvAvBDlBv5Y7gS5cLzqNLxNwpHkagsRyRa+d6gV/rUpTnsl99rt6O87BHIemz6 YV43+gxAo+hZvq967tu2hBf+UxXNm7ZGm6q8J4vcjMZ6ca3I+uHVjVYN2x51/+iQPuRK HtTGWZ3FOwh2UNXcula/0jM4Y2kz7SMWpZHihv5ee3LJhJh7zWs/IX+v6UGi6a9sBljo O0t8vzv2F9HvLhIO487JtGaHY1iecGnV5xd4X3nMsbygHkGc1UMYsFa/UxVz7wQXPt7P jUaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=2fcYdzON72/hQtSanGnyuFIRrr9yr+UJbIyOpw0Cfd8=; b=ANO0OKdVSef6paTrvyX13AgcxZR9mHBx12DH2mjZMQe7AjbWVCxPdk2vXr7mKva7oC MLl4EKuizB1EsBHKQtS1u88FjUOXFCx7Ar47ykjr61cDBPtN99mxx8JkI92EzLP5HOgP Tkn6HuDP0ubYJVWURdC/0CoK390IffA/Hpqk7o/gQK0RlDGMtr29PPQNirTA9hW8doZ7 48zKYNKcSeaNpZQ41ceZ47Ae1cV+duKlVrH11iz2+Yd1vRI34Qkm9ldib/bFrn1+nROa 5UkyE6PJVc9UbTq6AYx29Pnn3oHNBsgtQ67dOtQDpbYFUw56E/UI2cdLU2OqZk9ign2v /WaQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x64si2179772pff.196.2018.04.27.16.21.18; Fri, 27 Apr 2018 16:21:32 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933043AbeD0XUL (ORCPT + 99 others); Fri, 27 Apr 2018 19:20:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49784 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932342AbeD0XUK (ORCPT ); Fri, 27 Apr 2018 19:20:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8707E406C768; Fri, 27 Apr 2018 23:20:09 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8B7E215CDCB; Fri, 27 Apr 2018 23:20:08 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id w3RNK8a3005118; Fri, 27 Apr 2018 19:20:08 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w3RNK7Ye005114; Fri, 27 Apr 2018 19:20:07 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 27 Apr 2018 19:20:07 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: "Michael S. Tsirkin" cc: John Stoffel , James Bottomley , Michal@stoffel.org, eric.dumazet@gmail.com, netdev@vger.kernel.org, jasowang@redhat.com, Randy Dunlap , linux-kernel@vger.kernel.org, Matthew Wilcox , Hocko , linux-mm@kvack.org, dm-devel@redhat.com, Vlastimil Babka , Andrew@stoffel.org, David Rientjes , Morton , virtualization@lists.linux-foundation.org, David Miller , edumazet@google.com Subject: Re: [dm-devel] [PATCH v5] fault-injection: introduce kvmalloc fallback options In-Reply-To: <20180427005213-mutt-send-email-mst@kernel.org> Message-ID: References: <1114eda5-9b1f-4db8-2090-556b4a37c532@infradead.org> <1524694663.4100.21.camel@HansenPartnership.com> <1524697697.4100.23.camel@HansenPartnership.com> <23266.8532.619051.784274@quad.stoffel.home> <20180427005213-mutt-send-email-mst@kernel.org> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 27 Apr 2018 23:20:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 27 Apr 2018 23:20:09 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mpatocka@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 27 Apr 2018, Michael S. Tsirkin wrote: > 2. Ability to control this from a separate config > option. > > It's still not that clear to me why is this such a > hard requirement. If a distro wants to force specific > boot time options, why isn't CONFIG_CMDLINE sufficient? So, try this and turn it on with CONFIG_CMDLINE. But I'm not a blogger and I will not write a blog post about it as James Bottomley suggests :-) - so very few users will use it. fault-injection: introduce kvmalloc fallback options This patch introduces a fault-injection option "kvmalloc_fallback". This option makes kvmalloc randomly fall back to vmalloc. Unfortunately, some kernel code has bugs - it uses kvmalloc and then uses DMA-API on the returned memory or frees it with kfree. Such bugs were found in the virtio-net driver, dm-integrity or RHEL7 powerpc-specific code. This options helps to test for these bugs. Signed-off-by: Mikulas Patocka --- Documentation/fault-injection/fault-injection.txt | 7 +++++ mm/util.c | 30 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) Index: linux-2.6/Documentation/fault-injection/fault-injection.txt =================================================================== --- linux-2.6.orig/Documentation/fault-injection/fault-injection.txt 2018-04-28 01:01:25.000000000 +0200 +++ linux-2.6/Documentation/fault-injection/fault-injection.txt 2018-04-28 01:01:25.000000000 +0200 @@ -15,6 +15,12 @@ o fail_page_alloc injects page allocation failures. (alloc_pages(), get_free_pages(), ...) +o kvmalloc_fallback + + makes the function kvmalloc randomly fall back to vmalloc. This could be used + to detects bugs such as using DMA-API on the result of kvmalloc or freeing + the result of kvmalloc with free. + o fail_futex injects futex deadlock and uaddr fault errors. @@ -167,6 +173,7 @@ use the boot option: failslab= fail_page_alloc= + kvmalloc_fallback= fail_make_request= fail_futex= mmc_core.fail_request=,,, Index: linux-2.6/mm/util.c =================================================================== --- linux-2.6.orig/mm/util.c 2018-04-28 01:01:25.000000000 +0200 +++ linux-2.6/mm/util.c 2018-04-28 01:03:25.000000000 +0200 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -377,6 +378,29 @@ unsigned long vm_mmap(struct file *file, } EXPORT_SYMBOL(vm_mmap); +#ifdef CONFIG_FAULT_INJECTION + +static DECLARE_FAULT_ATTR(kvmalloc_fallback); + +static int __init setup_kvmalloc_fallback(char *str) +{ + kvmalloc_fallback.verbose = 0; + return setup_fault_attr(&kvmalloc_fallback, str); +} + +__setup("kvmalloc_fallback=", setup_kvmalloc_fallback); + +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS +static int __init kvmalloc_fallback_debugfs_init(void) +{ + fault_create_debugfs_attr("kvmalloc_fallback", NULL, &kvmalloc_fallback); + return 0; +} +late_initcall(kvmalloc_fallback_debugfs_init); +#endif + +#endif + /** * kvmalloc_node - attempt to allocate physically contiguous memory, but upon * failure, fall back to non-contiguous (vmalloc) allocation. @@ -404,6 +428,11 @@ void *kvmalloc_node(size_t size, gfp_t f */ WARN_ON_ONCE((flags & GFP_KERNEL) != GFP_KERNEL); +#ifdef CONFIG_FAULT_INJECTION + if (should_fail(&kvmalloc_fallback, size)) + goto do_vmalloc; +#endif + /* * We want to attempt a large physically contiguous block first because * it is less likely to fragment multiple larger blocks and therefore @@ -427,6 +456,7 @@ void *kvmalloc_node(size_t size, gfp_t f if (ret || size <= PAGE_SIZE) return ret; +do_vmalloc: __maybe_unused return __vmalloc_node_flags_caller(size, node, flags, __builtin_return_address(0)); }