Received: by 10.192.165.148 with SMTP id m20csp66824imm; Tue, 1 May 2018 17:37:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpm7msiOHzrvof/jWKist/hAItrk0QhwNjJXTy69P48OioWdQEwZTKfv7zity+QpVMULPBX X-Received: by 10.98.139.146 with SMTP id e18mr17357306pfl.60.1525221433280; Tue, 01 May 2018 17:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525221433; cv=none; d=google.com; s=arc-20160816; b=cEYpK6zveISW8QN+bitHQqhPAGAeKvzeISw4li9ABqqM+CT6F0Z2pT+R0eLOvv9WGz jgZ92Q3pacI0UUnZjfCSD3CcIWDTR4PJOvD42Buvxb2OLpEQ2dvb9EgtDwbMk//+1LOr 6WyfwICv90TPsPV5oOH0WkevANSHHL6OogVa4nW1rNHuBMcCHDXtGlUz+vA/8VTuSyCg hoXoWt+Kv3vV6KhjNTrTaKot3jQjRz44Ke+HoDY1JbnUoXBGG30fauWYDTDVsRP5jxWC dsrskTtKHKpUpoUKS7Qd3JKaST+h7WEJmbH+g3ovZcadZldQrYZMsqgzKum8gdLqSepy 6npw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Rglfp6D4l28L24i8eIOsWAp4QTSMna2N8/5O9xvS/2A=; b=x9duItOLz2sbxnHEPAHsfyzRxdfcF5eDzIsSTpoVPz/Q2hMDxsFn2GR51eGp5OmpN2 iF2eoa2LxHAc+EVxwdjrA2GXDQNiYGG2Hd6OiZpjtSt9Vz3zAAyniyvZdHrykwpG4QiA PFOXGHO7ZQodBy60jst6qKCYETM//Mj7WLQxf8EOTvcFdOZN0NZ86yLE+2TXSkTaIedA EMP6MK6lJOdJNjd9A9oznA6kZUJkjuAmQkT5srAg4Z8y3RWbXfWYCd8F33pyymSlU7vB lPNFcaRnCEx/MLP0E+6g4pAl5vILb5GxhRo1v2QkcIWsz1P+zNfiqVa6BL9vA21IrT+Y c41A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si10244955pll.15.2018.05.01.17.36.43; Tue, 01 May 2018 17:37:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbeEBAga (ORCPT + 99 others); Tue, 1 May 2018 20:36:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45406 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750969AbeEBAg2 (ORCPT ); Tue, 1 May 2018 20:36:28 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D4A47707; Wed, 2 May 2018 00:36:27 +0000 (UTC) Date: Tue, 1 May 2018 17:36:26 -0700 From: Andrew Morton To: Mikulas Patocka Cc: Michal Hocko , Matthew Wilcox , David Miller , 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] kvmalloc: always use vmalloc if CONFIG_DEBUG_VM Message-Id: <20180501173626.4593a87d0d64f6cc9d219d20@linux-foundation.org> In-Reply-To: References: <20180420130852.GC16083@dhcp22.suse.cz> <20180420210200.GH10788@bombadil.infradead.org> <20180421144757.GC14610@bombadil.infradead.org> <20180423151545.GU17484@dhcp22.suse.cz> <20180424133146.GG17484@dhcp22.suse.cz> <20180424161242.GK17484@dhcp22.suse.cz> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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).