Received: by 10.192.165.148 with SMTP id m20csp4542394imm; Tue, 24 Apr 2018 04:40:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4++woYwkOw3KZbb1h9NrSl0/nrK2W1PbOzNNywJeUKPcBpiVYYuRzR+u1tTWd8EKiA6QOZ9 X-Received: by 10.99.60.71 with SMTP id i7mr10731365pgn.254.1524570015673; Tue, 24 Apr 2018 04:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524570015; cv=none; d=google.com; s=arc-20160816; b=qjcKmHE/cmRFclosgDerVFaijTtHNmRjGbN0CF+2jdXs1kYKzYta9X3yk27V7M60oI 6PmYRblWzbWiqEI2Z/E3KWUCcZKoU5ZHUQd0dNqCk9WoKS+Nhzc23J3qcdf/S3RWfiZe 95QJuzH11aPCJQA9UmPkOD/SgLi20KwhuQZKSQ2Dn6It89SfRsQ3wwu9La1x4sQbNho6 k7PFuKQ1311PIh/UeboJ93d8r8YQJK4jizgirU6RDnVSvHubaPqlo+EjbOF7KlTFHGbv 27ZTzgcN1VFaFKcIAwTUk8Vhued12dpzOZBjWDnex36UvudhpF8ftZl7erPVkbBksXWu zB/Q== 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=ea75HPJC2UjHLXip8T47v7IyD7d5LNvXozrPGtAQx1k=; b=vihkPzkZeKxw9P7ctGkwx3ROVFa9+vBzQeSJm1ucqclmLGD29CUXmmgjZI2FQ3tAFx HCROGZmbazBFLJylcOTT4YEG5EvVIIv9nBfXJ1WNzoLSJcPG3ByV/pT7ZbiWgkfcjVq+ DLAd7roUspSyjnh4brd/ql2KqPRISaY7tuLPGFSxZ1BlcDJortKczNti6WVdWKbJ2Pvz xkOBb50wEhItJxGQINzv3I8oT7L6ixKyVxYZMuGdGZF7Xy137BDNg/UF1qBK6P0sWGYP PS5fdI9jY+y/Pgqs8HEoD4++Rv7tZ05GHsUtMKkEzdRP0yeiYm+TkGp1KVHwzk5GN7uY xKMg== 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 k33-v6si13812203pld.100.2018.04.24.04.40.01; Tue, 24 Apr 2018 04:40:15 -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 S1756806AbeDXLEc (ORCPT + 99 others); Tue, 24 Apr 2018 07:04:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35250 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750772AbeDXLE2 (ORCPT ); Tue, 24 Apr 2018 07:04:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27DAE406C794; Tue, 24 Apr 2018 11:04:28 +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 2024D1C722; Tue, 24 Apr 2018 11:04:24 +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 w3OB4OZ7028615; Tue, 24 Apr 2018 07:04:24 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w3OB4Nri028611; Tue, 24 Apr 2018 07:04:23 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Tue, 24 Apr 2018 07:04:23 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: David Rientjes cc: Michal Hocko , Matthew Wilcox , David Miller , Andrew Morton , linux-mm@kvack.org, eric.dumazet@gmail.com, edumazet@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, dm-devel@redhat.com, Vlastimil Babka Subject: Re: [PATCH v3] kvmalloc: always use vmalloc if CONFIG_DEBUG_SG In-Reply-To: Message-ID: References: <20180418.134651.2225112489265654270.davem@davemloft.net> <20180420130852.GC16083@dhcp22.suse.cz> <20180420210200.GH10788@bombadil.infradead.org> <20180421144757.GC14610@bombadil.infradead.org> <20180423151545.GU17484@dhcp22.suse.cz> 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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 24 Apr 2018 11:04:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 24 Apr 2018 11:04:28 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 Mon, 23 Apr 2018, David Rientjes wrote: > On Mon, 23 Apr 2018, Mikulas Patocka wrote: > > > The kvmalloc function tries to use kmalloc and falls back to vmalloc if > > kmalloc fails. > > > > Unfortunatelly, 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. > > > > These bugs are hard to reproduce because kvmalloc falls back to vmalloc > > only if memory is fragmented. > > > > In order to detect these bugs reliably I submit this patch that changes > > kvmalloc to fall back to vmalloc with 1/2 probability if CONFIG_DEBUG_SG > > is turned on. CONFIG_DEBUG_SG is used, because it makes the DMA API layer > > verify the addresses passed to it, and so the user will get a reliable > > stacktrace. > > Why not just do it unconditionally? Sounds better than "50% of the time > this will catch bugs". Because kmalloc (with slub_debug) detects buffer overflows better than vmalloc. vmalloc detects buffer overflows only at a page boundary. This is intended for debugging kernels and debugging kernels should detect as many bugs as possible. Mikulas