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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,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 E0902C433EF for ; Fri, 17 Sep 2021 20:10:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6848E61241 for ; Fri, 17 Sep 2021 20:10:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6848E61241 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7BA84900002; Fri, 17 Sep 2021 16:10:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76A9D6B0072; Fri, 17 Sep 2021 16:10:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 658DD900002; Fri, 17 Sep 2021 16:10:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id 53F466B0071 for ; Fri, 17 Sep 2021 16:10:14 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2FB173946D for ; Fri, 17 Sep 2021 20:10:13 +0000 (UTC) X-FDA: 78598157106.11.426F0E1 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP id CD34710000BB for ; Fri, 17 Sep 2021 20:10:12 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id D0E1D60F92; Fri, 17 Sep 2021 20:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631909411; bh=4CV71PX5L1bAnolYAfoAUtbpOQPUt68lFyDFbREQEmA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Issk0ybUjlf7y1iOIPDxsvLfWYtqR9GRdqpBO1JE/xGyy8SnVm+UHn4IiXb4fVvpL y0+jXlqMtE2A9janN+d4cBD+QrOEApyHywDG75/OAW/7BcNXIC77cqaDR7IpqWmdy4 AmgBS6D0HY90knefZJ16ClvIko8NbY3uUgCzDT5OxP7AsmM35nYlWnDAbiYl5YnFU2 /0eLyURolKCAVteNR4+NDurkPWgcLRdkFlOz3ybNV5/Qir9J5O5f+dC9dGZk7tlLNt 0m1+2VOn02yo6HHpz01uwXu9ET2SSYLrJV6bttem1LuhIVM1HwxMQ95Gxg3DIAgg9Q rgi9yyP6EoYMQ== Date: Fri, 17 Sep 2021 23:10:06 +0300 From: Mike Rapoport To: Linus Torvalds Cc: Steven Rostedt , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM Subject: Re: [GIT PULL] tracing: Fixes to bootconfig memory management Message-ID: References: <20210914105620.677b90e5@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CD34710000BB X-Stat-Signature: kidqopfr6fh3eyrirz1tehufudsmiqiu Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Issk0ybU; spf=pass (imf07.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1631909412-392515 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 14, 2021 at 11:01:31AM -0700, Linus Torvalds wrote: > On Tue, Sep 14, 2021 at 7:56 AM Steven Rostedt wrote: > > > > A couple of memory management fixes to the bootconfig code > > These may be fixes, but they are too ugly to merit the tiny > theoretical leak fix. > > All of these are just plain wrong: > > > +static void *init_xbc_data_copy __initdata; > > +static phys_addr_t init_xbc_data_size __initdata; > > + init_xbc_data_copy = copy; > > + init_xbc_data_size = size + 1; > > + memblock_free(__pa(init_xbc_data_copy), init_xbc_data_size); > > because the xbc code already saves these as xbc_data/xbc_data_size and > that final free should just be done in xbc_destroy_all(). > > So this fix is pointlessly ugly to begin with. > > But what I _really_ ended up reacting to was that > > > + memblock_free(__pa(copy), size + 1); > > where that "copy" was allocated with > > copy = memblock_alloc(size + 1, SMP_CACHE_BYTES); > > so it should damn well be free'd without any crazy "__pa()" games. > > This is a memblock interface bug, plain and simple. > > Mike - this craziness needs to just be fixed. If memblock_alloc() > returns a virtual address, then memblock_free() should take one. Yep, it was on my todo list. But since it was like this for years with both memblock and bootmem I didn't prioritise this. > Let's just get these interfaces fixed. It might be as simple as having > a "memblock_free_phys()" interface, and doing a search-and-replace > with coccinelle of > > memblock_free(__pa(xyz), .. -> memblock_free(xyz, ... > memblock_free(other, .. -> memblock_free_phys(other, .. > > and adding the (trivial) internal helper functions to memblock, > instead of making the atcual _users_ of memblock do insanely stupid > and confusing things. I've done the automated search and replace, with several fixups here and there, so there is now memblock_phys_free(phys_addr_t addr) to match memblock_phys_alloc() and memblock_free(void *ptr) to match memblock_alloc(). The initial version is in memblock tree https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock.git/log/?h=memblock_free-cleanup/v0 I'm waiting for robots to run the builds before posting. While doing the replacement I've found one mismatch in Xen code which used memblock_free() to free a virtual pointer, but except that users seem to do the correct thing, even if it is ugly __pa() conversions. -- Sincerely yours, Mike.