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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3D86C48BEF for ; Fri, 16 Feb 2024 15:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48C026B0096; Fri, 16 Feb 2024 10:57:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 43C3B6B0098; Fri, 16 Feb 2024 10:57:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B5E26B009B; Fri, 16 Feb 2024 10:57:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 150256B0096 for ; Fri, 16 Feb 2024 10:57:39 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C76691C0391 for ; Fri, 16 Feb 2024 15:57:38 +0000 (UTC) X-FDA: 81798122196.19.B4062A5 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by imf06.hostedemail.com (Postfix) with ESMTP id 3680518001D for ; Fri, 16 Feb 2024 15:57:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amazon.de header.s=amazon201209 header.b=esgtJFPO; dmarc=pass (policy=quarantine) header.from=amazon.de; spf=pass (imf06.hostedemail.com: domain of "prvs=769cabf0f=ptyadav@amazon.de" designates 207.171.190.10 as permitted sender) smtp.mailfrom="prvs=769cabf0f=ptyadav@amazon.de" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708099055; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ySlk5EP+5EPRFvPn7fKspQz+Y/lmLyPoeT8Lylq3p9Y=; b=2nEObwaXl4CEwWbV5ISX+fD1kpzbzVirInqpvmtjRD/71RgoB9bsKpRccxkHR33Ihmsi0t dkV48K9+7NY2aKA65O/CYlvDVnUG1JBVZoo2zZY6MGwdwFiHk3jC4puN85Vgh/cS6vIGHG vJ6kzL1R1MoBMXgAxvk93Nw1Aylomus= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=amazon.de header.s=amazon201209 header.b=esgtJFPO; dmarc=pass (policy=quarantine) header.from=amazon.de; spf=pass (imf06.hostedemail.com: domain of "prvs=769cabf0f=ptyadav@amazon.de" designates 207.171.190.10 as permitted sender) smtp.mailfrom="prvs=769cabf0f=ptyadav@amazon.de" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708099055; a=rsa-sha256; cv=none; b=ZNa9h/iqkBMLYNFyyZRWsDTXhWxJ2t+jWEtSvufa4Jk6mzfNgLU5uRD2N6NBjcq2Nh58PV KTcrYbGQPJP+V0DszBjnKDG0TMrQoPDG0pYfil5KIfeWbqw7p1/y5B/wapVWwqyqpVs7/6 hJcEsa5G+Hd7lNurNQTA7REpfcOkldE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1708099056; x=1739635056; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=ySlk5EP+5EPRFvPn7fKspQz+Y/lmLyPoeT8Lylq3p9Y=; b=esgtJFPOGqd7/s4vB4xr5BY2dQcPERDVNXzREbeUbYK5iKoYLz1TZhTB 9oqeNOvA8w1NldqxJnm4+m9Hbgun6DudE2Xh56JnRUpEFpZSh/7XYb7LV /BPu0oTWtGyEqnuwop5daPtuGVAwTDSbxCijOQuS+0q0tKQULKFyWxvAA c=; X-IronPort-AV: E=Sophos;i="6.06,165,1705363200"; d="scan'208";a="327444091" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 15:57:26 +0000 Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:20286] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.58.150:2525] with esmtp (Farcaster) id 5a50e3a4-7605-4a6b-bd7b-2201142338a7; Fri, 16 Feb 2024 15:57:25 +0000 (UTC) X-Farcaster-Flow-ID: 5a50e3a4-7605-4a6b-bd7b-2201142338a7 Received: from EX19D008UEA002.ant.amazon.com (10.252.134.125) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 16 Feb 2024 15:57:10 +0000 Received: from EX19MTAUEA001.ant.amazon.com (10.252.134.203) by EX19D008UEA002.ant.amazon.com (10.252.134.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 16 Feb 2024 15:57:09 +0000 Received: from dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (10.15.11.255) by mail-relay.amazon.com (10.252.134.102) with Microsoft SMTP Server id 15.2.1118.40 via Frontend Transport; Fri, 16 Feb 2024 15:57:09 +0000 Received: by dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (Postfix, from userid 23027615) id 4FB1420D21; Fri, 16 Feb 2024 16:57:09 +0100 (CET) From: Pratyush Yadav To: Alexander Graf CC: , , , , , , , , Eric Biederman , "H . Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Steven Rostedt , Andrew Morton , "Mark Rutland" , Tom Lendacky , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , "David Woodhouse" , Benjamin Herrenschmidt , Rob Herring , "Krzysztof Kozlowski" Subject: Re: [PATCH v3 04/17] kexec: Add KHO parsing support In-Reply-To: <20240117144704.602-5-graf@amazon.com> (Alexander Graf's message of "Wed, 17 Jan 2024 14:46:51 +0000") References: <20240117144704.602-1-graf@amazon.com> <20240117144704.602-5-graf@amazon.com> Date: Fri, 16 Feb 2024 16:57:09 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 3680518001D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: da7f79xtyktfi4hwoxgjiwhuoxrgb6bc X-HE-Tag: 1708099054-6704 X-HE-Meta: U2FsdGVkX1+hPXp+uP/iKbM4iLcBkazfY0yr0pnWkjjOELwWo5ckdHFMeMONAQG5dC4X9ZjHuz0gsN4+4QjgDl7ubQG8d0tkf/2ZrqDe9cxcKIchmZHXEaTKySFxMuMQXVIUo2wQydeN0wbNMsaTzcwlR8oSCzrLpyZPKU9NZoQiK2wOvs651Xw2aAXIHQX5Sb3noJsTLuPMjWiKGkv/jUJh6wBV69RjWCo/wPhfBvFcavxZa7IaNEjWmdOJsEY33fQ+9KtwaIpuoGh+q96TkoSRojsdL3gGqLBfDwBfGOYWUVUelM/K5kBFt/OefhVt4dWwlEzxDeHEK5zWiNPhCuktGBb9KhSWhnKkXUUMWk57oix2Y/HNpxZhmOfCzTfxGbpJXHnYhDBdVI7BBX08ACgJ5iSuwersU5/o2NufN0EoZD98Kz/xMDzmqVnwCokrHO8wWT6w8n6jfbzufeIJdmF8VFRUvxLIL6cBjKF6uXfALjqSIrYvZd3hUotR9ynh+evhalazfgt2p6WHcfw/SQkfE0pVzc6lnx4WWSTwvpZ6xq52g8FELGtjMa0NywaNg6pzfLUsgmIOtkDgjNjS5hu4VTT3Vl+R5EjPB960PYz1TFrCeyd5DVdzCQLKxEDHcitqLSNF0PGqw0b9Ysp3zyy7WIMbvhXY/uUINM2/4slPhBoyz5tBecr51TGvVDQZCPgV5hYq6+ZbbT78jzKQQCzr9uRZH5XQWi7HbkxT4G71NHUayiqoKpf0yB+RROzp9hRDDJkgac6o4SESVxPgR8p1sKeA5EvmTjfmk0vOOjnVVzdKCvCOA4jNTD75dCQNDnkHEr2SlIMcP7tpQmtx8wwltohMpvZhBHQbYPN+bnCkZhrDXItW+WJa8X6sIbGw7eh2+q748fzaXTiylrOb2RmzE/xt/+F51AnXOskXlNG+a2lK/4PQOiTqOv2EsQuzE90AzDo0SxcBm7N/kRQ 0nGxhje4 0sknrufgC8CPUVMYJFnSTV1tfRXYg2lF2heCK9/mg6JMngwkLBfQ42O2DFHkj4ekfuVoxLUOl0fKyH90evSq7/YyGQLCC/IPNd+OnCwJU8EUozg6gn5crXD+pXXF6QiODkaMXLZ8bNWIXV8m1+9WoMo59x6+RRGwW3ZKOUDTpNJTtxFgqzRfmRbMGdk408CTBwITao8MyIebQhIfVc03HUg2+Ue8Rrp3M/N4psqiLzCMw0TK1QXJYcru1/6V5mENioy4Nwz7I1sk1G2gj65vFV+SAntQeqKmgJigSqggt12wRrIf2LDAuRc7IiYvnw/7/Bk4JRlY4ENclqax6LS51QqGJh9qbTxQ6sUlSwun1ciK530lx7dtnXWFYr3cBgf5rk4REhyM3YU9JaIH6XdqCaipc9J5Rqsc799VPKq5J2I5Qen0= 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: Hi, On Wed, Jan 17 2024, Alexander Graf wrote: > When we have a KHO kexec, we get a device tree, mem cache and scratch > region to populate the state of the system. Provide helper functions > that allow architecture code to easily handle memory reservations based > on them and give device drivers visibility into the KHO DT and memory > reservations so they can recover their own state. > > Signed-off-by: Alexander Graf > > --- > [...] > +/** > + * kho_return_mem - Notify the kernel that initially reserved memory is no > + * longer needed. When the last consumer of a page returns their mem, kho > + * returns the page to the buddy allocator as free page. > + */ > +void kho_return_mem(const struct kho_mem *mem) > +{ > + uint64_t start_pfn, end_pfn, pfn; > + > + start_pfn = PFN_DOWN(mem->addr); > + end_pfn = PFN_UP(mem->addr + mem->len); > + > + for (pfn = start_pfn; pfn < end_pfn; pfn++) > + kho_return_pfn(pfn); > +} > +EXPORT_SYMBOL_GPL(kho_return_mem); > + > +static void kho_claim_pfn(ulong pfn) > +{ > + struct page *page = pfn_to_page(pfn); > + > + WARN_ON(!page); > + if (WARN_ON(page_count(page) != 1)) > + pr_err("Claimed non kho pfn %lx", pfn); You do sanity checks but then never actually change anything on the page. kho_claim_mem()'s documentation says: "This function removes the reserved state for all pages that the mem spans". So this function should at the very least call ClearPageReserved(). Also, checking the page count is a very rough heuristic. There can be other non-KHO pages with page count == 1. Do you think it would make more sense to use one of the private pageflags bits to mark a page KHO-owned? If not, shouldn't you at least also check if the page is reserved? > +} > + > +/** > + * kho_claim_mem - Notify the kernel that a handed over memory range is now in > + * use by a kernel subsystem and considered an allocated page. This function > + * removes the reserved state for all pages that the mem spans. > + */ > +void *kho_claim_mem(const struct kho_mem *mem) > +{ > + u64 start_pfn, end_pfn, pfn; > + void *va = __va(mem->addr); > + > + start_pfn = PFN_DOWN(mem->addr); > + end_pfn = PFN_UP(mem->addr + mem->len); > + > + for (pfn = start_pfn; pfn < end_pfn; pfn++) > + kho_claim_pfn(pfn); > + > + return va; > +} > +EXPORT_SYMBOL_GPL(kho_claim_mem); > + [...] -- Regards, Pratyush Yadav Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879