From patchwork Mon Aug 12 08:26:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 13760291 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 9B0ACC3DA7F for ; Mon, 12 Aug 2024 08:26:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6548A6B00C5; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ABA76B00C9; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D8616B00C5; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 12DA16B00C6 for ; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BE419A13DB for ; Mon, 12 Aug 2024 08:26:16 +0000 (UTC) X-FDA: 82442911152.21.2224EEA Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by imf20.hostedemail.com (Postfix) with ESMTP id A1AD41C000B for ; Mon, 12 Aug 2024 08:26:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=GxaYRoj1; dmarc=none; spf=pass (imf20.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723451119; a=rsa-sha256; cv=none; b=tU4xo9IB4vphb7ch4dlaVDvwH58CW+zhlXm21hxCoiJlqy39WzUCYd78/iyTCQCKf13PLE k77ilAgAlLVw5KyySl3PG3HqQxOURPhEGbS0w5bEx0KmGsC5m4k3Q/V3bV+Dm4hblixxFx 8thFAcEO8gCBeBGP1q68ZKYbq4ydyWA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=GxaYRoj1; dmarc=none; spf=pass (imf20.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723451119; 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=pcjuiNWGJBthoyZQ3qFWTiFyzLganh8gT8cFhrjWhRE=; b=Uxh8IQVhkOeGxEEbVTGfVKrVConCssruyHp0oCoNbKebjWiA5TvMt6N/jdcXKT/sjn2cth ibZgfY4soBfB8DicUgLZRE4sInb4wTRVbYpI5JH6VkRu2f/bc6vyX350ztJo0dfhTh9hKK coLGeJo9sZacSzBIcdA3Jj3U1acOHFM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1723451172; bh=pcjuiNWGJBthoyZQ3qFWTiFyzLganh8gT8cFhrjWhRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxaYRoj1O/6aMLky2vBn7var5Mtg8nUn123C1LWdhey7cpaSrl22XRNgO3S74rjOT ZVdnqLzZpTrwc5zGQPLVlpOLrV5GY8SC9oNSfrz6d6o5hXos8HivWGEF5KH8y5yQ4H GgVBKrX93hPoPl2fq849JAdVmKJBjG7vY6KadJcvD56pHe4eEttCoqzO5swg8CnXL0 ci2cttEjTH/LdvJLKjKx1S5N8dD1O7LZL/N4R3yoAvnR2ZhhqRe4tMosg/0GMwVeGR 0w54rRaOGgz1DilunTkuNlHaC9cVrV+nI3hApdE0h+e32H+p10/bHiY7vuGu4w/lrR b5pZFaVZL6dVg== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Wj6zm3CHMz4x92; Mon, 12 Aug 2024 18:26:12 +1000 (AEST) From: Michael Ellerman To: Cc: , torvalds@linux-foundation.org, akpm@linux-foundation.org, christophe.leroy@csgroup.eu, jeffxu@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, npiggin@gmail.com, oliver.sang@intel.com, pedro.falcato@gmail.com Subject: [PATCH v2 4/4] powerpc/vdso: Refactor error handling Date: Mon, 12 Aug 2024 18:26:05 +1000 Message-ID: <20240812082605.743814-4-mpe@ellerman.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240812082605.743814-1-mpe@ellerman.id.au> References: <20240812082605.743814-1-mpe@ellerman.id.au> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A1AD41C000B X-Stat-Signature: k4efkozu58egzayzubrcfoxjwgu1s3zg X-Rspam-User: X-HE-Tag: 1723451174-724638 X-HE-Meta: U2FsdGVkX1/tbgSO/+91ylSrYuuSHHjN7TOBBdGDn5t1mLW3uWdGFkFHUB0UYRYyorZuC+Wq5yCrIDYYwSG4oWgZC1EAJ5VOv4cUfaZqX508z3mqAsrhNBNde7Orb80F1B2bkpYIz49pT6vDaRene1WgV3xVJiZdPm75uUorNo1QNYPXrSVP7KEQfJlZf13Dc053bK5UVX1KyEyanKY9qmm9iQpxDs4gDC9cRM2SGDlxXZ19md1sjQZU9Ih6yW+AvEHuLSCP1qv6aABBwi533SNk6FrSIh36ZSaN7arOP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5q/2Gz/wDRrP3LNi1qvw/iM2Q5q7zcuc7al1Nfha 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: Linus noticed that the error handling in __arch_setup_additional_pages() fails to clear the mm VDSO pointer if _install_special_mapping() fails. In practice there should be no actual bug, because if there's an error the VDSO pointer is cleared later in arch_setup_additional_pages(). However it's no longer necessary to set the pointer before installing the mapping. Commit c1bab64360e6 ("powerpc/vdso: Move to _install_special_mapping() and remove arch_vma_name()") reworked the code so that the VMA name comes from the vm_special_mapping.name, rather than relying on arch_vma_name(). So rework the code to only set the VDSO pointer once the mappings have been installed correctly, and remove the stale comment. Depends-on: c1bab64360e6 ("powerpc/vdso: Move to _install_special_mapping() and remove arch_vma_name()") Signed-off-by: Michael Ellerman --- arch/powerpc/kernel/vdso.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) v2: Unchanged. diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c index 220a76cae7c1..ee4b9d676cff 100644 --- a/arch/powerpc/kernel/vdso.c +++ b/arch/powerpc/kernel/vdso.c @@ -214,13 +214,6 @@ static int __arch_setup_additional_pages(struct linux_binprm *bprm, int uses_int /* Add required alignment. */ vdso_base = ALIGN(vdso_base, VDSO_ALIGNMENT); - /* - * Put vDSO base into mm struct. We need to do this before calling - * install_special_mapping or the perf counter mmap tracking code - * will fail to recognise it as a vDSO. - */ - mm->context.vdso = (void __user *)vdso_base + vvar_size; - vma = _install_special_mapping(mm, vdso_base, vvar_size, VM_READ | VM_MAYREAD | VM_IO | VM_DONTDUMP | VM_PFNMAP, &vvar_spec); @@ -240,10 +233,15 @@ static int __arch_setup_additional_pages(struct linux_binprm *bprm, int uses_int vma = _install_special_mapping(mm, vdso_base + vvar_size, vdso_size, VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, vdso_spec); - if (IS_ERR(vma)) + if (IS_ERR(vma)) { do_munmap(mm, vdso_base, vvar_size, NULL); + return PTR_ERR(vma); + } - return PTR_ERR_OR_ZERO(vma); + // Now that the mappings are in place, set the mm VDSO pointer + mm->context.vdso = (void __user *)vdso_base + vvar_size; + + return 0; } int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) @@ -257,8 +255,6 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) return -EINTR; rc = __arch_setup_additional_pages(bprm, uses_interp); - if (rc) - mm->context.vdso = NULL; mmap_write_unlock(mm); return rc;