From patchwork Thu Nov 7 20:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13867067 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 5FDA7D5D688 for ; Thu, 7 Nov 2024 20:20:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F12D16B00AF; Thu, 7 Nov 2024 15:20:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E99116B00B0; Thu, 7 Nov 2024 15:20:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C79AF6B00B1; Thu, 7 Nov 2024 15:20:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9FE6F6B00AF for ; Thu, 7 Nov 2024 15:20:52 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4A36D1601CB for ; Thu, 7 Nov 2024 20:20:52 +0000 (UTC) X-FDA: 82760416830.16.1B66875 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf18.hostedemail.com (Postfix) with ESMTP id 8DDDF1C000A for ; Thu, 7 Nov 2024 20:20:34 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Y2R6K4Yf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3ISEtZwYKCFgOKP70E6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ISEtZwYKCFgOKP70E6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731010790; a=rsa-sha256; cv=none; b=IyP4gG1IzbvbRcGmWh17kgwZfXjIJ8zMx9sOhdm0ThzQhN+7Z24Zbk0cy/4JQC9a+fz30V e7YBLHzYVOEmsGLgUCSiXvC3f4J/KuC5W16xnhRTrfvcnm8YIF8jpd8/mcRYY+IR4TjOLT UQOLkWtCbBfK0L+iCTB8f/lHg8V1F3Q= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Y2R6K4Yf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3ISEtZwYKCFgOKP70E6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yuzhao.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ISEtZwYKCFgOKP70E6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731010790; 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=kshc+5TecBnElfjUZu5d6HS1cvMCCmL1E/fnjesi6Ow=; b=qO7aShSFMI2a3vIcfkN4HCvBle/R/zm5b5kA7NEh5ys0hVfycQg4EYRVlUwatXknlotVFj MjxM8LLhgzB5tv6QptXOF9XmU96XxXCFP25tCANc/j6jzdsmy2aFGKlm59oq72cHO2eWpZ XbMq0xaA5D5hECq60zM/QLrAZTxKSkY= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e6101877abso29087817b3.0 for ; Thu, 07 Nov 2024 12:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731010849; x=1731615649; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kshc+5TecBnElfjUZu5d6HS1cvMCCmL1E/fnjesi6Ow=; b=Y2R6K4YfCG4P7OHlsq8dLAM2WaDCOKzdauv2NslWcUloyl3zxO/VogI8mAM7IYk76q KDsz/tdoNQYmvz8H5thmV+NpdtKVJTiyS262rk8eh+lzWgkZeMOtJOiY7Xpae4pb4gd9 IHd5uufbW1DS19ZqpmOXTqefsoNbrob9Ub8J8cCQ6672a5rDUpBynoMPJLSkSgrntP7l 0G8wOegA+LdgdGgRKgwU60vKkD11C6FR2WdWd24RwpHSBu64CQAudvAuSXKx5R+NwhSg aRejnZM/g1ZPzQktPf4fS+VGeFWot2DQYTzSA7epGI8xKlbbxVkElM++9iMlrSNqfhBR 4RhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731010849; x=1731615649; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kshc+5TecBnElfjUZu5d6HS1cvMCCmL1E/fnjesi6Ow=; b=uClxOf61ZuEW/fwGw4cv9HwfC4Af3WGp4cGKnQtKW9nZBkHvkDoxigRb5AwP5qAIOk qIW9EEWcCphU8h23aK/5mQyy2c8ZMvN2UgGXDO7TmVtcFudZSVHA8TEwp6StzTGkXxw0 4XOLcZpynwNg2QSCTsfPpAFJdyn2L0WK2JolLex7ygn01gunDxHK8g4lQJowRi+0J9rN BIGpmP1GTAZKXRW5YVTc3HJFr6iaZPJ0zEAdnZ9Exntq0RQJNx6GBz16wdawCtbaYNrC TD9JUoSYFnI3HmWVcCYBg8hjHAgRM425MTypGEfUKMvZIyiWHEKyue7cizQd0Nyge+dL x/+A== X-Forwarded-Encrypted: i=1; AJvYcCW+GIAchnSueehx3fLzsPJrjL1Cb4gykj66PL1u++8IFshdQvomA1GmPfwcUzmxbrnQsnRMJFvMWw==@kvack.org X-Gm-Message-State: AOJu0YwOyk/ioxqT1b0/eDDNqI4I+OQ37vkkgQnBBEa8Nzn2HVnGJ84N +jIUTxcQHFXCzfsF9mJAoJpP11L+QHxpU0ilZP28mnGbKJpBHU2B/B7xH/tr/B8CHkxdjlI85Wm lBA== X-Google-Smtp-Source: AGHT+IEjIv/a3qKWak4A1Vn18DXvCmBDzVmrxwgOEzTP/K9OGHGZiWxXZlnHtaXBKDC55f0LUGtreAyzNRE= X-Received: from yuzhao2.bld.corp.google.com ([2a00:79e0:2e28:6:a4c0:c64f:6cdd:91f8]) (user=yuzhao job=sendgmr) by 2002:a05:690c:c08:b0:6c1:298e:5a7 with SMTP id 00721157ae682-6eaddfb88bcmr33137b3.5.1731010849660; Thu, 07 Nov 2024 12:20:49 -0800 (PST) Date: Thu, 7 Nov 2024 13:20:32 -0700 In-Reply-To: <20241107202033.2721681-1-yuzhao@google.com> Mime-Version: 1.0 References: <20241107202033.2721681-1-yuzhao@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Message-ID: <20241107202033.2721681-6-yuzhao@google.com> Subject: [PATCH v2 5/6] arm64: pause remote CPUs to update vmemmap From: Yu Zhao To: Andrew Morton , Catalin Marinas , Marc Zyngier , Muchun Song , Thomas Gleixner , Will Deacon Cc: Douglas Anderson , Mark Rutland , Nanyong Sun , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Yu Zhao X-Rspam-User: X-Rspamd-Queue-Id: 8DDDF1C000A X-Rspamd-Server: rspam11 X-Stat-Signature: p5pmpq93daxwoguwn4oinpohxxkrimty X-HE-Tag: 1731010834-113481 X-HE-Meta: U2FsdGVkX1+lw0VmRyiny9mRvGAGtzoptDuaRuyuWegdhDwC/7GLad8Bpe+x0vg/n9i1UMI+TAlR5VzJfmmoyNQtyYTgZ8y5tMkybo9Z6qX6hHY7zfR4OUh58hIJDuWhMjrAmGq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Br/6ZELAhaEqhSX4PNG41xhVa+wbedd94sJJeDvtuQhnPxGZk0+R2LA01SApBh3K/jD+7dN65rqRc6tvvm8es+lItqO8UsyvTn7/1yj1ptk4RGF/ubTqBhLsakbi6aW7BkwdQ/ZUxt0dFPcS17mJCL3feDT74cwQyCAoj7g8UjBa8HOct1HV5dDIggS9yMh6UuEU1k4xZg7ugqzvOmFn4zzUHhUJ/ow1W3m5rfDgQmNiDYJpmbSgZj/25DU7x44en65x8Rn2slgGASr+RPmOj9+TmWs+SZD1+ALsofu1lYJsdLlYinqdLNgjM9lQrhrCiGYa7SH/Y8UZxMQMYywIFztm+75b2koJDUtBumJo= 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: Pause remote CPUs so that the local CPU can follow the proper BBM sequence to safely update the vmemmap mapping `struct page` areas. While updating the vmemmap, it is guaranteed that neither the local CPU nor the remote ones will access the `struct page` area being updated, and therefore they should not trigger kernel PFs. Signed-off-by: Yu Zhao --- arch/arm64/include/asm/pgalloc.h | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 8ff5f2a2579e..f50f79f57c1e 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -12,6 +12,7 @@ #include #include #include +#include #define __HAVE_ARCH_PGD_FREE #define __HAVE_ARCH_PUD_FREE @@ -137,4 +138,72 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN); } +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + +#define VMEMMAP_ARCH_TLB_FLUSH_FLAGS (VMEMMAP_SPLIT_NO_TLB_FLUSH | VMEMMAP_REMAP_NO_TLB_FLUSH) + +#define vmemmap_update_supported vmemmap_update_supported +static inline bool vmemmap_update_supported(void) +{ + return system_uses_irq_prio_masking(); +} + +#define vmemmap_update_lock vmemmap_update_lock +static inline void vmemmap_update_lock(void) +{ + cpus_read_lock(); +} + +#define vmemmap_update_unlock vmemmap_update_unlock +static inline void vmemmap_update_unlock(void) +{ + cpus_read_unlock(); +} + +#define vmemmap_update_pte_range_start vmemmap_update_pte_range_start +static inline void vmemmap_update_pte_range_start(pte_t *pte, + unsigned long start, unsigned long end) +{ + unsigned long addr; + + local_irq_disable(); + pause_remote_cpus(); + + for (addr = start; addr != end; addr += PAGE_SIZE, pte++) + pte_clear(&init_mm, addr, pte); + + flush_tlb_kernel_range(start, end); +} + +#define vmemmap_update_pte_range_end vmemmap_update_pte_range_end +static inline void vmemmap_update_pte_range_end(void) +{ + resume_remote_cpus(); + local_irq_enable(); +} + +#define vmemmap_update_pmd_range_start vmemmap_update_pmd_range_start +static inline void vmemmap_update_pmd_range_start(pmd_t *pmd, + unsigned long start, unsigned long end) +{ + unsigned long addr; + + local_irq_disable(); + pause_remote_cpus(); + + for (addr = start; addr != end; addr += PMD_SIZE, pmd++) + pmd_clear(pmd); + + flush_tlb_kernel_range(start, end); +} + +#define vmemmap_update_pmd_range_end vmemmap_update_pmd_range_end +static inline void vmemmap_update_pmd_range_end(void) +{ + resume_remote_cpus(); + local_irq_enable(); +} + +#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */ + #endif