From patchwork Mon Aug 5 09:32:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13753332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83050C3DA4A for ; Mon, 5 Aug 2024 09:35:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22DDB6B0099; Mon, 5 Aug 2024 05:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 202A16B009A; Mon, 5 Aug 2024 05:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C9966B009B; Mon, 5 Aug 2024 05:35:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E38946B0099 for ; Mon, 5 Aug 2024 05:35:24 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5CFA7141C90 for ; Mon, 5 Aug 2024 09:35:24 +0000 (UTC) X-FDA: 82417683768.30.F3BFF64 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by imf15.hostedemail.com (Postfix) with ESMTP id 4F2D4A0009 for ; Mon, 5 Aug 2024 09:35:22 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=BZaZ630C; spf=pass (imf15.hostedemail.com: domain of "prvs=940e15008=jgowans@amazon.com" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=940e15008=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722850460; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wges4MT0n6I9CyO780W2I1CcNRjpe5PQ75LHC+blwyY=; b=qTFYje2JvMFp/JZG708aeApuAGfoaGJilWIpwhuXYZK4KhgGhJYuFcTjRHxIVRNe9TMXwv Yj/L1wCCAjWMprX4Hw5XSP9gvmpSfCecLRH6fiTS47uKKgeOqVEqNzmpr+P4Y5PepvSnCW bpRXEbUasbf0KQbxAws3TYyehARrpG4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722850460; a=rsa-sha256; cv=none; b=Y5/ymXE5SoJ+/LJXLEs1cF4ntlU9JmXa2B1w+wGXcHL6R3p3xGbnIUcLyIlZXwpM6hmmYA IJ5ZaxA+4l4eoLLpvg7p2xzHU0Ioxf0EFT3Ksycwn5vXODXVnE86xcI0dPld5kNu5CAtnD s43CvUFOh6LvsMuYIHGJAmz6t1TErh0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=BZaZ630C; spf=pass (imf15.hostedemail.com: domain of "prvs=940e15008=jgowans@amazon.com" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=940e15008=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722850522; x=1754386522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wges4MT0n6I9CyO780W2I1CcNRjpe5PQ75LHC+blwyY=; b=BZaZ630Czllo7tAoiVOI93WyGbuSy0ixVXym56SPOhUnTDUtsCCWRwaL KBFL1+H3FhMKGYhSOaIpQt+VKzy/5T8LDu9lrkawq2NJQt+M49ghByb7o BLVImtlqykFutxqfqo4hb832aAsumYILUioDCfrZlDkl/E83Ub+XURFGe M=; X-IronPort-AV: E=Sophos;i="6.09,264,1716249600"; d="scan'208";a="318022324" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2024 09:35:09 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.43.254:19549] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.14.223:2525] with esmtp (Farcaster) id 73411eaf-fd8d-4133-a679-10dbf0f4e67a; Mon, 5 Aug 2024 09:35:08 +0000 (UTC) X-Farcaster-Flow-ID: 73411eaf-fd8d-4133-a679-10dbf0f4e67a Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 5 Aug 2024 09:35:08 +0000 Received: from u5d18b891348c5b.ant.amazon.com (10.146.13.113) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 5 Aug 2024 09:34:58 +0000 From: James Gowans To: CC: James Gowans , Sean Christopherson , Paolo Bonzini , Alexander Viro , Steve Sistare , Christian Brauner , Jan Kara , "Anthony Yznaga" , Mike Rapoport , "Andrew Morton" , , Jason Gunthorpe , , Usama Arif , , Alexander Graf , David Woodhouse , Paul Durrant , Nicolas Saenz Julienne Subject: [PATCH 06/10] kexec/kho: Add addr flag to not initialise memory Date: Mon, 5 Aug 2024 11:32:41 +0200 Message-ID: <20240805093245.889357-7-jgowans@amazon.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240805093245.889357-1-jgowans@amazon.com> References: <20240805093245.889357-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.146.13.113] X-ClientProxiedBy: EX19D046UWB002.ant.amazon.com (10.13.139.181) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Stat-Signature: qffrcttsciqj4afmzygpd1xy5uctanh5 X-Rspamd-Queue-Id: 4F2D4A0009 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722850522-913054 X-HE-Meta: U2FsdGVkX1/DAQ0mLEBwUD1Y4jL5ZA8Foju5PvupsrfFxd/HRirPXduSqTVefiloYqd94KhQywo88WOAIsXEvfn0AdyhoVGaSbx4eeTKAj/0EJUcmqPJm/KqYRzOXi+Ql/7wjY0NbYowkCM512RhPFfdgX5bnCXxaUopkzX+jrhNIUzDRazn3rb6MtG8hg0mgaE3PSXd+bGc5QSUjwRAvbVtatvNNFQJ5b6aqhmgiB2GMQ2YkXMkP4EMiJC6uNwtF1DHkUOGOIiGl2Dp89w3+yOwzEymtvPKXFYjWfRvLbpsxN9Hc02VBll9H05pp33SRXC50D6B4CKkUtijNRe8ngOfGtz2viexWVAxOdZ7XLwUM1nehLTtAn9GUV9m+x1c6VLs1F+PBX6grRRw8QjNr3eVdla/GSEc5IAsdPAHx+WPAYBh+WWMAFqe+dKL7C7kmcgZXxJ+ORqq4uDZ6I/ZJPGacQAIh4/8ooOBl9E5yIees6/4wYZC4/gFizJIYIUnY50BD8OQr3/co9veD+OZhor5445yDy2OPtddmlrOB8rvm35uUpfYvwGfH2HwMu+jhEp6MLyEGQh3TsV/NxcTvxToHrGIkY3Ky4kxfzhCrIjl8272AmFh5MB6d7tt6GwAh7FCGCoAlFLKREoMlN577GGeRWxC8/qqPTt7qA+PL6Tt59PzLldev9YLR1pNKNyYYF9upf5IyLB96EbBs+PxCFlEWXb81NH0475paks260qtGXZ6YjbPOLShCegwySlQA7hKnwl27Jn1+XveZLuzEVrKDESEzdF/R/GJvDtPdVRpKC2es2mpttN4vIGqD12SKYwosur3KdL16V+Pbl6LVNL4M7Jhd48ucrWdB42Vv5g2r43yzALw4t+xAPr2y0JuOlBMoTHl6g4cCSILf604DkXvFXa7R9uyDFGPqEX0WBdnZl9B5p44fuyn/YicmNsVr7Z5RnNg+0Morsiu/xw 1QpC0RLU KsZusMyzAIzjkGTqb86SdBxtrT0uJbyABTCngzJyNf5s7DNRlNDnaaFRPJ+XqB0Qv7yh+xUtSlh93F4Xs9BkM0bq+lxE0bWMBsMrxKCxOZMEaMxhjnySxUQIr+WDEhQXtF2Sf0nNRyWzWVHxw/WKlB6IYxbBItyMe6Uba9Sy9wi2tAAjEKjDA/8828KbDcMmbBBE1pmTi2C5dUTpqrMzzmheYirDsel4x7wVOOcWYIbbBY7mK0IzGi+L4nWRYCnZMfwOQOHnyf0uLSopdOejIqebrJa9+U2DJktwccBktqim4JfnqHgzifdspLEXsJrCNuRrKyLipeLsNXkk1quZFyaqM+5veWXab4USq0MHzBcZziDvJdVJI9O0WGUBIXuZtHunlm0czgS5pBgpQMdpB3bpoR7Kn/8eS43Ya69cZSP6z1k/iGaB/MfhDc7XS56Z3ObgjwSCdftKaTLHdb+P3ErLiBSLzgp1X7TEPyjPw+INGevoa2tLaXVuJEJM7l8XRgj3lR2gu5Rw0FK8g9mI0XsYoEPVgRwXwIDiTvqypS7bLYf8bky2gneUvt69t/yqysN+PVBoYANMiwUY9c/S8S0EIKVo3ig+zS2TKBGQ386qvYGg= 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: List-Subscribe: List-Unsubscribe: Smuggle a flag on the address field. If set the memory region being reserved via KHO will be marked as no init in memblocks so it will not get struct pages, will not get given to the buddy allocator and will not be part of the direct map. This allows drivers to pass memory ranges which the driver has allocated itself from memblocks, independent of the kernel's mm and struct page based memory management. Signed-off-by: James Gowans --- include/uapi/linux/kexec.h | 6 ++++++ kernel/kexec_kho_in.c | 12 +++++++++++- kernel/kexec_kho_out.c | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h index ad9e95b88b34..1c031a261c2c 100644 --- a/include/uapi/linux/kexec.h +++ b/include/uapi/linux/kexec.h @@ -52,6 +52,12 @@ /* KHO passes an array of kho_mem as "mem cache" to the new kernel */ struct kho_mem { + /* + * Use the last bits for flags; addrs should be at least word + * aligned. + */ +#define KHO_MEM_ADDR_FLAG_NOINIT BIT(0) +#define KHO_MEM_ADDR_FLAG_MASK (BIT(1) - 1) __u64 addr; __u64 len; }; diff --git a/kernel/kexec_kho_in.c b/kernel/kexec_kho_in.c index 5f8e0d9f9e12..943d9483b009 100644 --- a/kernel/kexec_kho_in.c +++ b/kernel/kexec_kho_in.c @@ -75,6 +75,11 @@ __init void kho_populate_refcount(void) */ for (offset = 0; offset < mem_len; offset += sizeof(struct kho_mem)) { struct kho_mem *mem = mem_virt + offset; + + /* No struct pages for this region; nothing to claim. */ + if (mem->addr & KHO_MEM_ADDR_FLAG_NOINIT) + continue; + u64 start_pfn = PFN_DOWN(mem->addr); u64 end_pfn = PFN_UP(mem->addr + mem->len); u64 pfn; @@ -183,8 +188,13 @@ void __init kho_reserve_previous_mem(void) /* Then populate all preserved memory areas as reserved */ for (off = 0; off < mem_len; off += sizeof(struct kho_mem)) { struct kho_mem *mem = mem_virt + off; + __u64 addr = mem->addr & ~KHO_MEM_ADDR_FLAG_MASK; - memblock_reserve(mem->addr, mem->len); + memblock_reserve(addr, mem->len); + if (mem->addr & KHO_MEM_ADDR_FLAG_NOINIT) { + memblock_reserved_mark_noinit(addr, mem->len); + memblock_mark_nomap(addr, mem->len); + } } /* Unreserve the mem cache - we don't need it from here on */ diff --git a/kernel/kexec_kho_out.c b/kernel/kexec_kho_out.c index 2cf5755f5e4a..4d9da501c5dc 100644 --- a/kernel/kexec_kho_out.c +++ b/kernel/kexec_kho_out.c @@ -175,6 +175,10 @@ static int kho_alloc_mem_cache(struct kimage *image, void *fdt) const struct kho_mem *mem = &mems[i]; ulong mstart = PAGE_ALIGN_DOWN(mem->addr); ulong mend = PAGE_ALIGN(mem->addr + mem->len); + + /* Re-apply flags lost during round down. */ + mstart |= mem->addr & KHO_MEM_ADDR_FLAG_MASK; + struct kho_mem cmem = { .addr = mstart, .len = (mend - mstart),