Message ID | 20240322114136.61386-1-21cnbao@gmail.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 77268C47DD9 for <linux-mm@archiver.kernel.org>; Fri, 22 Mar 2024 11:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8784D6B007B; Fri, 22 Mar 2024 07:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8284C6B0082; Fri, 22 Mar 2024 07:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7181A6B0083; Fri, 22 Mar 2024 07:42:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5E1266B007B for <linux-mm@kvack.org>; Fri, 22 Mar 2024 07:42:00 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 304D7A1EF3 for <linux-mm@kvack.org>; Fri, 22 Mar 2024 11:42:00 +0000 (UTC) X-FDA: 81924486000.26.8631917 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf03.hostedemail.com (Postfix) with ESMTP id 978A62000B for <linux-mm@kvack.org>; Fri, 22 Mar 2024 11:41:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ido85mXt; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711107717; a=rsa-sha256; cv=none; b=f5OnSrP1j7CKA+qbCjZfbj8SxxjzSBZ5k4IG7CapRULYje8OmObObWipnAeLIsrotOeqEs zBz3ah0++VmO0wBxi753bjyYSGzAGnEqOcv4a5+mm/+KguhLV980a86UG3lQOGm9kvDHDQ 4nAORJknwrnebSjbF8R5nP49y3xvBmM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ido85mXt; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711107717; 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:references:dkim-signature; bh=F9OutCqVZAxLYLcVQMTLlVzNDJwVicrj2Kc/nVp36kc=; b=v0vyoa32yElLYPyrBc47FkvcvWxxb4JyLHdCYUdvtL1xtW2m0xzemZdIzklLoSx2X+8fHB KpndhuAoqvgB8Xpg9W8SAG2tsibU4Dsb4/7eYF42LWpTfnxO0vOYFvVfIUrQlKuDVAkzc2 AtYtl9dYIsvA1DGSfwPD+68iAB6UR/k= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e0411c0a52so14997025ad.0 for <linux-mm@kvack.org>; Fri, 22 Mar 2024 04:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711107716; x=1711712516; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=F9OutCqVZAxLYLcVQMTLlVzNDJwVicrj2Kc/nVp36kc=; b=ido85mXtyRg1FvPEZDBez072vslo7E2+CP52PpEHfuOLSO1RHWU4Yf+WhMfpFapMNx FYi4ac2/P8s48bRQaYxLH7hZoMfljSiAfRF3l8rXanBqm7JWred3oYwVxyZkP3sjiTQ3 bCh8IceFISBgSwyN9KlYr8YqvWa3R8AOtVTKlCMuLWMZCQBj1fZDoHNp29bM/Ii+B6Vb GUYADlgb0zhhSkuu+o9+tCrIFUWemZp52rVhw8QuwTdtyU+MjbDMeWfs5U9F2xZgu0zV PTKamTbq/6TV5dlOoTR19uR3jmHXB8HulcdG6vdpERS7V74t9oQy6cJjY45K605IO8Fu 9qiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711107716; x=1711712516; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=F9OutCqVZAxLYLcVQMTLlVzNDJwVicrj2Kc/nVp36kc=; b=hRJO7zru1LQsfMS+tbmJQCnf8t7uLm3m7PtDhWANfcjZhl6OnbYUsx9nE/1421L5VF PSE7wnMS5KRaUKqHd5TJL260+jpfNqdjT7pL/09GsYIRJR2ibVxrczY89EihNV+KRvg8 h78ZWPAxxppF4166hFRpqOItqhFTGTE2WxpxUK5FWotwBOLp9m/a17cSV5uWdMERInU3 k8go1cx6TAS5pTFVdf4OrAwsfvnqiTOfG4G2S4JdB0f1JPgOVuxpFt2/1Ejiqa82x4ji 3dvvncnii9szM/q5HWBEL7g9172f1KPRDTt2M79A2Cq0v9lHbLlbdU8CHzqOTBQ0Fu0P wNlQ== X-Forwarded-Encrypted: i=1; AJvYcCUB4kKmNfVaKWzD+6tCsTUbyDeOFDK3Ap5qBcOBMWou9BUZm/fBRwNncvP7mp9AxCkpxBXVlTyXGvFYB87N8HPnoLw= X-Gm-Message-State: AOJu0Yx7bZVgPxfXd5IQHtKKFtQUUqo9ij/P2gSFzLXzDX5Gfj/P0PKq 21iT/QvYR9MIBx6XhYyBhCh8hm8K2aaIL1i+CcBTs1JIlKg49Xoz X-Google-Smtp-Source: AGHT+IECvbWHnvjqaHafErRwYVmEILP9NsOyshUhBo9Ba6zifkAAJRe8kjAppOJb1hnY/b/8WEIrCA== X-Received: by 2002:a17:902:bc47:b0:1dd:d40b:bd30 with SMTP id t7-20020a170902bc4700b001ddd40bbd30mr2247472plz.29.1711107716259; Fri, 22 Mar 2024 04:41:56 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id p14-20020a170902e74e00b001d92a58330csm1700209plf.145.2024.03.22.04.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 04:41:55 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, hughd@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: chrisl@kernel.org, mark.rutland@arm.com, ryan.roberts@arm.com, steven.price@arm.com, david@redhat.com, willy@infradead.org, Barry Song <v-songbaohua@oppo.com> Subject: [PATCH 0/1] THP_SWAP support for ARM64 SoC with MTE Date: Sat, 23 Mar 2024 00:41:35 +1300 Message-Id: <20240322114136.61386-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 978A62000B X-Stat-Signature: 157hknfobjhrqqmb1c86m6c8kyewupxz X-Rspam-User: X-HE-Tag: 1711107717-773751 X-HE-Meta: U2FsdGVkX18ed1HDpRUvvbLcox4gR1icEnDXVfSgnBKdJa+7qWSblIcOLlYUEiwgvdt8EaQlR4V6GjeeVRSkzUUYTn95JwLTWeIt09IFngWQNspeK8dYYSCppzW2HLKTnjUJh03VoDg6CwGwjsnwIca/E1SlYP4TIkJ33n6txDJpeVDzvqKlBtDkq/acmrM6L9kvoTeIWc9jtfeafo08UvwVN/Tc9256LJ+OJ4RpHKvZ9AnFT0ov+Gw57yWfmoW1PwqTmwQbM8CHdPvMjorLE2Tl2eoos+/dTR4U41pzjb64R4DWSMGMW5xTn8fyExWjndah8FwBObF9XdzGjnZFxGc3C2kH8gJ6HfCNJEoeF062hj3a3V74k6kw/dxCc3yQXgL8xpzpdR/r+bmjC9Zi5ZZkv6Bd1CfY4cSa7RMdbnXUxkZkkRFl2ArXzVn72pMR2tuFYn2RiAboLJDgADr8sRWpm9EwuDXBvFnMF5u9jzJoBKsvLXA7+3H0Gmu22rQpd2j28aRxsDZcDlF0j018QcimUONpKm9ittn2ueRNePAwSIuekDSXK/PkVrv6OqfcEzt6WyFshlikTJXqiGUof/QlKXN/ll55RUxpzIWktcLkm+kpeV5C00gauTJ0jqDxtRwYC/pOwvs3swbpUrlA28jjIoumx4sGjrOqh5MycVA6bP7b4F8+WyGqQXyyqxmUyca+mXSW303VqtegZjycl0WdqQNxAykwwlbIrOAOdOYE5jdo08fSSTRleyjIib4Cnl9U5JXMYSwTvDeHneaZymMu8CLiMp80lphkgv2l59tW/zEvXULc8qOv3NU9vL3EjOk63Eq3HE/+BGHYP76z2crXbs25cs34P+CPxtwsd0+0ip5uL1f68GAEr3tdB0WshqTngcgbgs3azR2+Tq0f7Yzv+B3cHnxYThRdqofGHVb976JOZkDv2ngeB6RHXJCV+OCbcUsOKOnP/VRabmd aaZanKD0 uvpxzrjs4N2a5+o48Q8Mja1rQ+W2TMxdjAgX828QJ5dM3+sF4ouck4tbbj1g6t8u48/4Hb4Exs7t03QqRS9qxXbjxQ3SK85Q1eXFClGqxXPraqgBmLJub4b1tNIOlGzPZGmwAaTCg+unaFzk67kUFROEEqaeB6JwHROlV 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
THP_SWAP support for ARM64 SoC with MTE
|
expand
|
From: Barry Song <v-songbaohua@oppo.com> The patch has been extracted from the larger folios swap-in series [1], incorporating some new modifications. Introducing THP_SWAP support for ARM64 SoCs with MTE is essential, particularly due to its significance for widely used ARM64 products in the market. Without this support, Ryan's mTHP swap-out without splitting series won't operate effectively on these SoCs. Therefore, it's imperative for this update to be implemented sooner rather than later. There are a couple of differences with the code in [1]: 1. minor code cleanup, Ryan 2. always pass the first swap entry of a folio to arch_swap_restore, Ryan [1] https://lore.kernel.org/linux-mm/20240304081348.197341-2-21cnbao@gmail.com/ Barry Song (1): arm64: mm: swap: support THP_SWAP on hardware with MTE arch/arm64/include/asm/pgtable.h | 19 ++------------ arch/arm64/mm/mteswap.c | 45 ++++++++++++++++++++++++++++++++ include/linux/huge_mm.h | 12 --------- include/linux/pgtable.h | 2 +- mm/internal.h | 14 ++++++++++ mm/memory.c | 2 +- mm/page_io.c | 2 +- mm/shmem.c | 2 +- mm/swap_slots.c | 2 +- mm/swapfile.c | 2 +- 10 files changed, 67 insertions(+), 35 deletions(-) Appendix I also have a small test program specifically designed for running MTE on a THP that I can share with those who are interested in this subject. /* * To be compiled with -march=armv8.5-a+memtag */ #include <errno.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/auxv.h> #include <sys/mman.h> #include <sys/prctl.h> /* * From arch/arm64/include/uapi/asm/hwcap.h */ #define HWCAP2_MTE (1 << 18) /* * From arch/arm64/include/uapi/asm/mman.h */ #define PROT_MTE 0x20 /* * From include/uapi/linux/prctl.h */ #define PR_SET_TAGGED_ADDR_CTRL 55 #define PR_GET_TAGGED_ADDR_CTRL 56 # define PR_TAGGED_ADDR_ENABLE (1UL << 0) # define PR_MTE_TCF_SHIFT 1 # define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) # define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) # define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) # define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT) # define PR_MTE_TAG_SHIFT 3 # define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) /* * Insert a random logical tag into the given pointer. */ #define insert_random_tag(ptr) ({ \ uint64_t __val; \ asm("irg %0, %1" : "=r" (__val) : "r" (ptr)); \ __val; \ }) /* * Set the allocation tag on the destination address. */ #define set_tag(tagged_addr) do { \ asm volatile("stg %0, [%0]" : : "r" (tagged_addr) : "memory"); \ } while (0) int main() { unsigned char *a, *p[512]; unsigned long page_sz = 4 * 1024UL; unsigned long mem_sz = 2 * 1024 * 1024UL; unsigned long hwcap2 = getauxval(AT_HWCAP2); int i; if (!(hwcap2 & HWCAP2_MTE)) return EXIT_FAILURE; if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC | (0xfffe << PR_MTE_TAG_SHIFT), 0, 0, 0)) { perror("prctl() failed"); return EXIT_FAILURE; } a = mmap(0, mem_sz * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (a == MAP_FAILED) { perror("mmap() failed"); return EXIT_FAILURE; } /* make sure a is aligned with 2MiB THP */ a = (unsigned char *)(((unsigned long)a + mem_sz - 1) & ~(mem_sz - 1)); madvise(a, mem_sz, MADV_HUGEPAGE); memset(a, 0x11, mem_sz); if (mprotect(a, mem_sz, PROT_READ | PROT_WRITE | PROT_MTE)) { perror("mprotect() failed"); return EXIT_FAILURE; } printf("set tag for each 4KiB page\n"); for (i = 0; i < 512; i++) { p[i] = a + i * page_sz; p[i] = (unsigned char *)insert_random_tag(p[i]); set_tag(p[i]); p[i][0] = 0x33; } printf("swap-out the whole THP\n"); madvise(a, mem_sz, MADV_PAGEOUT); printf("swap-in each page of the original THP\n"); for (i = 0; i < 512; i++) { if (p[i][0] != 0x33) { printf("test fails, unmatched value after swap-in\n"); return EXIT_FAILURE; } } printf("we should get here\n"); for (i = 0; i < 512; i++) { printf("page :%d val: expect segment fault, is %02x\n", i, p[i][16]); } printf("we shouldn't get here\n"); return EXIT_FAILURE; }