Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp196864lqo; Wed, 15 May 2024 11:30:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUf3DumFenDErw9Khhn10xyk6bSaLzTzDgZLJyJ3ZDPVvohDGQzdgS3Kg/3E0+MSva1Gb4rVqyk+OF6Pst3l+4s/T/vhW7rfIy7ysT8tw== X-Google-Smtp-Source: AGHT+IGqDOGytGf2fhzLzHWq4/hZvsvfKanycNTOX+Lv+cwrYWnt3evM4IFWiwU03hpTi9XR7SDP X-Received: by 2002:a05:6214:590e:b0:6a0:b9aa:3160 with SMTP id 6a1803df08f44-6a1681b8f87mr201354986d6.18.1715797812966; Wed, 15 May 2024 11:30:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715797812; cv=pass; d=google.com; s=arc-20160816; b=skACQblTIyNwC8VDOle99IpiewadcWtRdc3lS6wCBbiKIFdZLsxhXn+MDxKNihHnHW gt6t8hoMRgwcVNrk0U7PIXf+52NBFG2/l/atjp4KCgJgHZztSC51/HfIjNvFivHCjDYA EzR9Qaq9KrfDt0099OANFj/tXU8z5mjkU5/HWZxGzRr7KDuRCqSBiJQXTuZDmmJVTv1A KXwGjWq/ax98PKWQJEmzl4zIdp0IGggIjSLAiPbQOW4BrfdV+mtgsv+UG6DpJbZ34njh +xfCQIbkMR6bovQNfJLObJS8vRoa29zrkHkk3QRRL/b5bhVqqAHl3h+GnUz1i8ULpHix U6yw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature; bh=YrJDrZniSkj7pjdJDmZV6RImb2UH2mu8lBTuDt6yO5g=; fh=cWhg9+ZEvq/E/wHPSP9oE2sR6E4IMo+JZd42dBVX5cM=; b=zT9/LmO5Jm2B46c/de16LVSufBQWQxEdEPDLh8x6KjmQGJixPWzKbVwJAE9EAuLRAN 4zdw8us4hef2gemOJfqIwYLxRAT7NAwkMQZOdG3051rYjiAiVLqoqxPZRVKH8VoQI+Kf eitu0sfgvIF2OCA/li9GyOY8g6fXj3uZ9YtTfG/pM/RGhMcqMH7puP/5GSzsIYcmTWrE x+Clex5dQeMoqT4iFPCxzg51+z+SuC+aJsKwJPqCc5eqL8YGxuCoff47Nbemb86oGQ6/ g39g6nDxUjukWhVoDheWP+j0QPZIsEjxQ1pak+XKr9NJn12aat7a81Sqz/VBsIAishvd frZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vGG8OjSI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2edae2si146125886d6.463.2024.05.15.11.30.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 11:30:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vGG8OjSI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A11D91C20F6C for ; Wed, 15 May 2024 18:30:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C928E3A1B7; Wed, 15 May 2024 18:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vGG8OjSI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E716A40858; Wed, 15 May 2024 18:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715797807; cv=none; b=qc5Z8XZfsPKziWKm939+ktqu3jGTcNOnmJtNBz+krmhKXG7kEwDQkVMRqRqcQEOP0XiiPz+AzZH0B69bhlCLsMDTRio+3DRxebvN2SoxZeWZ8a38a6TvwENIbieGRrzgEyAi6jIGOxQHbrLBi9IBTt5AyajKYdxWv3wYG2kcnLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715797807; c=relaxed/simple; bh=1H4ESRp4n7R82qzwLK63TMRqXzG39WJ6h6WdXq5tn0s=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=jMGATuMuxe7H+Ef7KFJSoFBNBJf2iZoD7HgXEJUfcBH/VTQYEwIuduj1C5ny5VQ0ysNj0OBm8R4zCEEAes/3uKmkinu3HOKQAbrcIcGc9/F/oFOrYePAw85917gyfbgT/vMjMjgf3O9DbmxjtD9V10Y6sLB79ZH9Cfp4zmx+oI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vGG8OjSI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E794C116B1; Wed, 15 May 2024 18:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715797806; bh=1H4ESRp4n7R82qzwLK63TMRqXzG39WJ6h6WdXq5tn0s=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=vGG8OjSIeW781V5I1Mq1XjN20oayTbfZUcvX7gFmSBIIuMekeMdERoqa1JMDoOIgE xrftDrj7q8wQI5PJ6WPuR7cQ0BEYYhG2d1NgrIBgTLFYLnMCsyGjc76CjoWgbbsP2T aPD2hmz3zViJSH2iwzvzuYtAvB7j/9BaH3xYsrgqtAdT+jn8iBzXx7DdEXgcrw8KWR ykTrGGn6/oOtyOAR8Mm+QB5zQ2U07ttTk5Y4FJoj9ZwyqJAAWtAmGXSIsRXjxNKfum 9naBJ+n07qxnNyK/y3DGPwI5aDiLGKwQjySQoaYYTdKR2eK97QjUnEaEtndpfNqyln xFM+cuR17Cm9Q== Date: Wed, 15 May 2024 11:30:06 -0700 From: Kees Cook To: Ard Biesheuvel , "Chaney, Ben" , Kees Cook CC: "gregkh@linuxfoundation.org" , "linux-efi@vger.kernel.org" , "stable@vger.kernel.org" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "linux-kernel@vger.kernel.org" , "mingo@redhat.com" , "tglx@linutronix.de" , "Tottenham, Max" , "Hunt, Joshua" , "Galaxy, Michael" Subject: Re: Regression in 6.1.81: Missing memory in pmem device User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <742E72A5-4792-4B72-B556-22929BBB1AD9@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On May 15, 2024 10:42:49 AM PDT, Ard Biesheuvel wrote: >(cc Kees) > >On Wed, 15 May 2024 at 19:32, Chaney, Ben wrote: >> >> Hello, >> I encountered an issue when upgrading to 6=2E1=2E89 fro= m 6=2E1=2E77=2E This upgrade caused a breakage in emulated persistent memor= y=2E Significant amounts of memory are missing from a pmem device: >> >> fdisk -l /dev/pmem* >> Disk /dev/pmem0: 355=2E9 GiB, 382117871616 bytes, 746323968 sectors >> Units: sectors of 1 * 512 =3D 512 bytes >> Sector size (logical/physical): 512 bytes / 4096 bytes >> I/O size (minimum/optimal): 4096 bytes / 4096 bytes >> >> Disk /dev/pmem1: 25=2E38 GiB, 27246198784 bytes, 53215232 sectors >> Units: sectors of 1 * 512 =3D 512 bytes >> Sector size (logical/physical): 512 bytes / 4096 bytes >> I/O size (minimum/optimal): 4096 bytes / 4096 bytes >> >> The memmap parameter that created these pmem devices is =E2=80= =9Cmemmap=3D364416M!28672M,367488M!419840M=E2=80=9D, which should cause a m= uch larger amount of memory to be allocated to /dev/pmem1=2E The amount of = missing memory and the device it is missing from is randomized on each rebo= ot=2E There is some amount of memory missing in almost all cases, but not 1= 00% of the time=2E Notably, the memory that is missing from these devices i= s not reclaimed by the system for general use=2E This system in question ha= s 768GB of memory split evenly across two NUMA nodes=2E >> >> When the error occurs, there are also the following error messa= ges showing up in dmesg: >> >> [ 5=2E318317] nd_pmem namespace1=2E0: [mem 0x5c2042c000-0x5ff7ffffff= flags 0x200] misaligned, unable to map >> [ 5=2E335073] nd_pmem: probe of namespace1=2E0 failed with error -95 >> >> Bisection implicates 2dfaeac3f38e4e550d215204eedd97a061fdc118 a= s the patch that first caused the issue=2E I believe the cause of the issue= is that the EFI stub is randomizing the location of the decompressed kerne= l without accounting for the memory map, and it is clobbering some of the m= emory that has been reserved for pmem=2E >> > >Does using 'nokaslr' on the kernel command line work around this? > >I think in this particular case, we could just disable physical KASLR >(but retain virtual KASLR) if memmap=3D appears on the kernel command >line, on the basis that emulated persistent memory is somewhat of a >niche use case, and physical KASLR is not as important as virtual >KASLR (which shouldn't be implicated in this)=2E Yeah, that seems reasonable to me=2E As long as we put a notice to dmesg t= hat physical ASLR was disabled due to memmap's physical reservation=2E If t= his usage becomes more common, we should find a better way, though=2E=20 This reminds me a bit of the work Steve has been exploring: https://lore=2Ekernel=2Eorg/all/20240509163310=2E2aa0b2e1@rorschach=2Eloca= l=2Ehome/ --=20 Kees Cook