From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-f197.google.com (mail-ua0-f197.google.com [209.85.217.197]) by kanga.kvack.org (Postfix) with ESMTP id 01CF76B0005 for ; Wed, 2 May 2018 09:41:09 -0400 (EDT) Received: by mail-ua0-f197.google.com with SMTP id t46so3757998uad.3 for ; Wed, 02 May 2018 06:41:08 -0700 (PDT) Received: from mail.stoffel.org (mail.stoffel.org. [104.236.43.127]) by mx.google.com with ESMTPS id x35si459346uab.72.2018.05.02.06.41.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 May 2018 06:41:08 -0700 (PDT) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <23273.49098.982175.973732@quad.stoffel.home> Date: Wed, 2 May 2018 09:40:26 -0400 From: "John Stoffel" Subject: Re: [dm-devel] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM In-Reply-To: <20180502133224.GA22123@redhat.com> References: <20180421144757.GC14610@bombadil.infradead.org> <20180423151545.GU17484@dhcp22.suse.cz> <20180424133146.GG17484@dhcp22.suse.cz> <20180424161242.GK17484@dhcp22.suse.cz> <20180501173626.4593a87d0d64f6cc9d219d20@linux-foundation.org> <20180502133224.GA22123@redhat.com> Sender: owner-linux-mm@kvack.org List-ID: To: Mike Snitzer Cc: Andrew Morton , eric.dumazet@gmail.com, mst@redhat.com, netdev@vger.kernel.org, jasowang@redhat.com, linux-kernel@vger.kernel.org, Matthew Wilcox , Michal Hocko , linux-mm@kvack.org, dm-devel@redhat.com, Mikulas Patocka , Babka , virtualization@lists.linux-foundation.org, David Miller , edumazet@google.com >>>>> "Mike" == Mike Snitzer writes: Mike> On Tue, May 01 2018 at 8:36pm -0400, Mike> Andrew Morton wrote: >> On Tue, 24 Apr 2018 12:33:01 -0400 (EDT) Mikulas Patocka wrote: >> >> > >> > >> > On Tue, 24 Apr 2018, Michal Hocko wrote: >> > >> > > On Tue 24-04-18 11:30:40, Mikulas Patocka wrote: >> > > > >> > > > >> > > > On Tue, 24 Apr 2018, Michal Hocko wrote: >> > > > >> > > > > On Mon 23-04-18 20:25:15, Mikulas Patocka wrote: >> > > > > >> > > > > > Fixing __vmalloc code >> > > > > > is easy and it doesn't require cooperation with maintainers. >> > > > > >> > > > > But it is a hack against the intention of the scope api. >> > > > >> > > > It is not! >> > > >> > > This discussion simply doesn't make much sense it seems. The scope API >> > > is to document the scope of the reclaim recursion critical section. That >> > > certainly is not a utility function like vmalloc. >> > >> > That 15-line __vmalloc bugfix doesn't prevent you (or any other kernel >> > developer) from converting the code to the scope API. You make nonsensical >> > excuses. >> > >> >> Fun thread! >> >> Winding back to the original problem, I'd state it as >> >> - Caller uses kvmalloc() but passes the address into vmalloc-naive >> DMA API and >> >> - Caller uses kvmalloc() but passes the address into kfree() >> >> Yes? Mike> I think so. >> If so, then... >> >> Is there a way in which, in the kvmalloc-called-kmalloc path, we can >> tag the slab-allocated memory with a "this memory was allocated with >> kvmalloc()" flag? I *think* there's extra per-object storage available >> with suitable slab/slub debugging options? Perhaps we could steal one >> bit from the redzone, dunno. >> >> If so then we can >> >> a) set that flag in kvmalloc() if the kmalloc() call succeeded >> >> b) check for that flag in the DMA code, WARN if it is set. >> >> c) in kvfree(), clear that flag before calling kfree() >> >> d) in kfree(), check for that flag and go WARN() if set. >> >> So both potential bugs are detected all the time, dependent upon >> CONFIG_SLUB_DEBUG (and perhaps other slub config options). Mike> Thanks Andrew, definitely the most sane proposal I've seen to resolve Mike> this. Cuts to the heart of the issue I think, and seems pretty sane. Should the WARN be rate limited as well? John