From patchwork Mon Aug 12 08:26:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 13760293 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 D2FF0C3DA7F for ; Mon, 12 Aug 2024 08:26:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D51DD6B00C8; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3D096B00CC; 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 81E706B00C8; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5CDE66B00CB for ; Mon, 12 Aug 2024 04:26:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 16A6B121B7F for ; Mon, 12 Aug 2024 08:26:17 +0000 (UTC) X-FDA: 82442911194.25.B1B582C Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by imf03.hostedemail.com (Postfix) with ESMTP id 0604920025 for ; Mon, 12 Aug 2024 08:26:14 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=fFPHXE1d; spf=pass (imf03.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723451106; 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=90PGWBEPImYbqdKWstTCR2/CnGQLSesaZNbFieveKuE=; b=cZJGZO4JbLNPPHeIvqZRl8vMfaZ0oc94KrDbVvvUYWKH/BRF4eJlIWMecnsqu6JypqxRGW pmo/hXpkl5yCBQJtypkmr+8fi15X2QaXALkFYsYARPopM2S1Y/8cq9VWS7oPf9mBn4ZSyf NWoYQJMLVyumsYbfU7qbvwjtCP2kWZ8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723451106; a=rsa-sha256; cv=none; b=FVcu4ZpkNIyypalMHof9MIC1O5aorSNtLNGGA08IHegdUe0BppojtNFtJ4P+GePtgO3nWl S890uwHOdyNLxzOugZ/O6JstXbOoISlAd7zXbAEq9JG36r/EXoWLHMU/rQAilcFVbWQPYE LXn0ZUj2Nar/lRBuGOO/OkIfZ24ipcA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=fFPHXE1d; spf=pass (imf03.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1723451171; bh=90PGWBEPImYbqdKWstTCR2/CnGQLSesaZNbFieveKuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fFPHXE1dOvj+bKatKB56csNqaldo10qmfdXwB1reponcEmik+TvrSRPKhatzXSHSx wSbXA5pkgkbvxhDr6zSSvFQvnSDu+1oJErPK+JPOsOUZur2lv/ndnIqPxMc8HyxMjH XN95VVCbSnJRNpFyLmuBWBUzmwADAyxkNtqaWmYpunfu4p5z7Zg0u5fPeMVuH5Hok/ mFcKZgybv4Zx8Q8guL83cj7gAwLZmUwBrL9ZzgTi64YSYhfhdZdn+TRgNvBMhtEpRn oUYqRjmf0fWRjTlu2BtTD5vHgOShzNnppXzHKFJvbRd7ZradwBPOHQNgO/ABDbGAKX nKLrIq6sdYBhQ== 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 4Wj6zl3y2Sz4x8w; Mon, 12 Aug 2024 18:26:11 +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 2/4] powerpc/mm: Handle VDSO unmapping via close() rather than arch_unmap() Date: Mon, 12 Aug 2024 18:26:03 +1000 Message-ID: <20240812082605.743814-2-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-Stat-Signature: fww595p5cbucrb8ojtwd4fgocrjaezj3 X-Rspamd-Queue-Id: 0604920025 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723451174-546237 X-HE-Meta: U2FsdGVkX18lk+NYWmzK0alQvhe0CAi2J/8Duu2B8X2rUXoJ5Z/r1LbUSoXScCdd4t0+kv0B+PK66IIaWugnWzRKGXBW4uGvycEztfCH045E1nUoeOhsZnL57zpX/1TBdYS4wdXzP41Fkgl/136heYt2ZF/71vkLc/3hEVn1UvqIOxJB08R1Ka9gvl9TMUUyc2aJ6wwUMupFuvIbZEApTZGGyF8PN2hjpjAsAYM1jXn+3WNKXhqXLslwSos1SdQBFcPQ2rQ6WydB2xQ7pjxfmP8OP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MMFRnYC+2GpX4bDYqGVHaycwqzwSr1Mxeb563cf7cDiIHmiGQ8KqP/15w0Z2zibl99xKSmuyGDHmJ+LqxHcdtuNmeABn+CBLyopc2auxVydLNk3viTHmPAbqKBspFJS3PTaJxjGH6R8CyY6zzFFkMbiSym+4JqCkCQBgHfYVTGtGUTezQ= 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: Add a close() callback to the VDSO special mapping to handle unmapping of the VDSO. That will make it possible to remove the arch_unmap() hook entirely in a subsequent patch. Suggested-by: Linus Torvalds Signed-off-by: Michael Ellerman Reviewed-by: David Hildenbrand --- arch/powerpc/include/asm/mmu_context.h | 4 ---- arch/powerpc/kernel/vdso.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) v2: Unchanged except for collecting tags. diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 37bffa0f7918..9b8c1555744e 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -263,10 +263,6 @@ extern void arch_exit_mmap(struct mm_struct *mm); static inline void arch_unmap(struct mm_struct *mm, unsigned long start, unsigned long end) { - unsigned long vdso_base = (unsigned long)mm->context.vdso; - - if (start <= vdso_base && vdso_base < end) - mm->context.vdso = NULL; } #ifdef CONFIG_PPC_MEM_KEYS diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c index 7a2ff9010f17..220a76cae7c1 100644 --- a/arch/powerpc/kernel/vdso.c +++ b/arch/powerpc/kernel/vdso.c @@ -81,6 +81,21 @@ static int vdso64_mremap(const struct vm_special_mapping *sm, struct vm_area_str return vdso_mremap(sm, new_vma, &vdso64_end - &vdso64_start); } +static void vdso_close(const struct vm_special_mapping *sm, struct vm_area_struct *vma) +{ + struct mm_struct *mm = vma->vm_mm; + + /* + * close() is called for munmap() but also for mremap(). In the mremap() + * case the vdso pointer has already been updated by the mremap() hook + * above, so it must not be set to NULL here. + */ + if (vma->vm_start != (unsigned long)mm->context.vdso) + return; + + mm->context.vdso = NULL; +} + static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf); @@ -92,11 +107,13 @@ static struct vm_special_mapping vvar_spec __ro_after_init = { static struct vm_special_mapping vdso32_spec __ro_after_init = { .name = "[vdso]", .mremap = vdso32_mremap, + .close = vdso_close, }; static struct vm_special_mapping vdso64_spec __ro_after_init = { .name = "[vdso]", .mremap = vdso64_mremap, + .close = vdso_close, }; #ifdef CONFIG_TIME_NS