From patchwork Tue Mar 26 02:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13603264 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 4C819C54E64 for ; Tue, 26 Mar 2024 02:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2BE16B0096; Mon, 25 Mar 2024 22:17:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB67D6B0098; Mon, 25 Mar 2024 22:17:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F9006B009A; Mon, 25 Mar 2024 22:17:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 826F66B0098 for ; Mon, 25 Mar 2024 22:17:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1DA2614029C for ; Tue, 26 Mar 2024 02:17:25 +0000 (UTC) X-FDA: 81937578450.05.2A56692 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by imf06.hostedemail.com (Postfix) with ESMTP id 1F9E8180013 for ; Tue, 26 Mar 2024 02:17:22 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fDo5v7yr; spf=pass (imf06.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711419443; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AQuO2+LY0NocTj5/TwPtd+fjpYBqmYsEXamkkmk+aWw=; b=EQ1PNBIXxfol3ltEBtj0uBlKz7BAU/1ws4JfqC3iO2BhNztBBVqk3yws/3fMxOfjt5/wo6 VBGdHm7JyT/goSzyuxhDWJNJpKvhigsWa37SbgCoDd7Th90U3Sj1F5aRLJH2g26+66n+ai 2L/cNrQ9lqQ0OcCp5LZnW0tcVacjWH0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711419443; a=rsa-sha256; cv=none; b=MtCO0nGPcG2k+HCoVC6zRLObpUR8WBGqraIPDyf/O8hOkvUDyDSsIbc4QBADI6prcDP92/ zZZ1LLjimrNNlcao52fWqedgJT0uJjolCuZ9L/oBO58Iy9P9wZT8bbbzlnw7+YucPnEiiZ y0fbXffJSgoycuypr4babWLWHoA79wY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fDo5v7yr; spf=pass (imf06.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711419443; x=1742955443; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BjoIXKt5bAU2p5uENJE46EVXE51w6Jj985k5TB+SvjQ=; b=fDo5v7yrPWxGzUR4dNsGTgKg4umlk/mlCBEF8KQQlR6Fj2hKhXqFUPf3 64HBX5rsydtFfaNSgNA+25vBKDKt3cM0BVhp1kVpypRElm2D+dj8auhVN /+sGnW5DvTz1biR6Jg7HhVkzWKCyl5n3FAziq/swRsQ5N+HRPSvZMCjB5 pdOI3so9teb+/7TtujYz+ISBGiQdOjfsRTw9lsng2f7wMLAoqCtnOKtjP ZRNUtnQOeNHqDnOr6AwUbAhaXlTxRv+LktCzC85DdX9snTnNDUqektNQs 26jZVA3ltaH76RsPKaI/O+vPhWFWqHrJDELBaGP5s2Fsr+AEKddfyXgo9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,11024"; a="6564320" X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="6564320" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:17:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,154,1708416000"; d="scan'208";a="20489901" Received: from rpwilson-mobl.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.251.11.187]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 19:17:16 -0700 From: Rick Edgecombe To: Liam.Howlett@oracle.com, akpm@linux-foundation.org, bp@alien8.de, broonie@kernel.org, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, debug@rivosinc.com, hpa@zytor.com, keescook@chromium.org, kirill.shutemov@linux.intel.com, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, x86@kernel.org Cc: rick.p.edgecombe@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K . V" , "Naveen N . Rao" , linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 09/14] powerpc: Use initializer for struct vm_unmapped_area_info Date: Mon, 25 Mar 2024 19:16:51 -0700 Message-Id: <20240326021656.202649-10-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326021656.202649-1-rick.p.edgecombe@intel.com> References: <20240326021656.202649-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Stat-Signature: c3z1pi77bw3jk4khxd5kc3ono6dpbkhb X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1F9E8180013 X-Rspam-User: X-HE-Tag: 1711419442-676713 X-HE-Meta: U2FsdGVkX1+vanDdA8I9b+Psd0+J5A1b7QSuCMuEX9lrf7GLfkNb0Fd3gFxk9f8efNG1Th98BxngCnj/dViaPIHcauiAt+4JHnEDHdXD2f2AzyJhRnHeGJW8tJgcKPZw4gm4L3bnzNwfu1Zb5gKb9nehq9Cj/KFfcNfO9CrzFmyOZb8cq1QCx2bD5mm8TjNPGcXBFbb7vRD6j41fdUElUYBFZ7PhRV7QS1jyi+eOupXYEcI1IbJQ0nK2NXoKT8twycY0WNp1ZWs1kkvMopvtllOXHMFOUc+qNFACxecAevrrPdXvFteqIDw9kRKSgGB2r4chxb62F4oLrc0ujxNcJI4j8/MoayoZGK/AIGU/+th4NbjCupVGA2PQqpY3wZTDdIHOGl9RpFHD56Jzse9NTP1pNCA0pI5KWDPaFma0yIZ314+EczSzRAZWedA0w29U5qYhhG99EInp0C9LR47kHg/AVgurGFAT334k6OQAzAb5xkiBd0sXZw8t85s0PD6vOFx9bgnHT4PcZdVkWaT8BRWstLtLfcE+YdBlN4jcP8ac7v5dhDwTw9WoM3OaD6wtMOWPXcGVgTQAG9iBMnSieFaIhc6wA47SmIPuepswsYjcqd4/2j/hWMTSxhUT/7pmfiZWYb7TZWd2N1XIFMe0Dy4JUu+esslvPwBHRpAOitGf/qq1SRszXUxC8Y30p6DSYxEfJ/r/2YA6n9nok67jEyGp3pWRNP+TltPRJfT43M/uO7B4T2KSgIAiSQYabfSoo3EGQI7eMDm6Y+wuJqUA27/w13G8Cx8B8PVhEqwoDvUez22lnx/5qhf49NpFbK832qlQ94d8aU+WTno34Q1VLwl0hlEW7tP1er97gH2qrDvZZVY4hHJMGPzmFBF14qdBK1CDovF9DcKE6jCnK91OtNvdqp+tV9y9y8OjzowOnwq9EwNrANibWPS1dNpLnnodX+nTYpN0VNrujPzDtMy toQS5b1/ 8u2g5Ad0wLg0xbjG26bOPtq4KhqltWSc8iuFKgtUXnM4mhQJZTvUW6q0uxv0S3VTZK4OH2LmE1+1ciVIgsgukpD7XoEVwL2N0stiMBVejOhZbVeJpZaH9ImLxK3UpBaWePJXVLyK4cZN0/ZbBrUB5A8N9HgcmDd4XYjXKdcZ5DKZLeFdBSBagfpUOjsftF7PsDRId+PiSM7TV4KZQ+esgJbJ3+yTqqwITMHeomICDoS6nixhzlOJkxwVpannEO2IMjAg7YeKySV6mGKH82ENj57Eq+/21IaRX93pWYULsxZ7a/QhwrJ5FTOV6hExAuNZfoaVSRxfdttVG4UIjJutjlhT2fW3p+XgOkvGl/r/qQuzrdrumgzo8RmqtF47tjp6eICGI/PpkxC5Ey3LROxV/4wYbJSndBdUkDIjScCH7GRQQ9X+nuyJV8iGHDw== 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: Future changes will need to add a new member to struct vm_unmapped_area_info. This would cause trouble for any call site that doesn't initialize the struct. Currently every caller sets each member manually, so if new members are added they will be uninitialized and the core code parsing the struct will see garbage in the new member. It could be possible to initialize the new member manually to 0 at each call site. This and a couple other options were discussed, and a working consensus (see links) was that in general the best way to accomplish this would be via static initialization with designated member initiators. Having some struct vm_unmapped_area_info instances not zero initialized will put those sites at risk of feeding garbage into vm_unmapped_area() if the convention is to zero initialize the struct and any new member addition misses a call site that initializes each member manually. It could be possible to leave the code mostly untouched, and just change the line: struct vm_unmapped_area_info info to: struct vm_unmapped_area_info info = {}; However, that would leave cleanup for the members that are manually set to zero, as it would no longer be required. So to be reduce the chance of bugs via uninitialized members, instead simply continue the process to initialize the struct this way tree wide. This will zero any unspecified members. Move the member initializers to the struct declaration when they are known at that time. Leave the members out that were manually initialized to zero, as this would be redundant for designated initializers. Signed-off-by: Rick Edgecombe Acked-by: Michael Ellerman Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Aneesh Kumar K.V Cc: Naveen N. Rao Cc: linuxppc-dev@lists.ozlabs.org Link: https://lore.kernel.org/lkml/202402280912.33AEE7A9CF@keescook/#t Link: https://lore.kernel.org/lkml/j7bfvig3gew3qruouxrh7z7ehjjafrgkbcmg6tcghhfh3rhmzi@wzlcoecgy5rs/ --- v4: - Remove designated zero initialization (Christophe Leroy) v3: - Fixed spelling errors in log - Be consistent about field vs member in log Hi, This patch was split and refactored out of a tree-wide change [0] to just zero-init each struct vm_unmapped_area_info. The overall goal of the series is to help shadow stack guard gaps. Currently, there is only one arch with shadow stacks, but two more are in progress. It is compile tested only. There was further discussion that this method of initializing the structs while nice in some ways has a greater risk of introducing bugs in some of the more complicated callers. Since this version was reviewed my arch maintainers already, leave it as was already acknowledged. Thanks, Rick [0] https://lore.kernel.org/lkml/20240226190951.3240433-6-rick.p.edgecombe@intel.com/ --- arch/powerpc/mm/book3s64/slice.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index c0b58afb9a47..ef3ce37f1bb3 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -282,12 +282,10 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); unsigned long found, next_end; - struct vm_unmapped_area_info info; - - info.flags = 0; - info.length = len; - info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); - info.align_offset = 0; + struct vm_unmapped_area_info info = { + .length = len, + .align_mask = PAGE_MASK & ((1ul << pshift) - 1), + }; /* * Check till the allow max value for this mmap request */ @@ -326,13 +324,13 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); unsigned long found, prev; - struct vm_unmapped_area_info info; + struct vm_unmapped_area_info info = { + .flags = VM_UNMAPPED_AREA_TOPDOWN, + .length = len, + .align_mask = PAGE_MASK & ((1ul << pshift) - 1), + }; unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr); - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); - info.align_offset = 0; /* * If we are trying to allocate above DEFAULT_MAP_WINDOW * Add the different to the mmap_base.