Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp19139rdb; Thu, 1 Feb 2024 00:14:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjC+TUW+gUbfNQnCCenBMNFCmGs2sxYudxNEnQwRLRiHyQpS6xSORp61hCZqdxY3+J/RCm X-Received: by 2002:a05:6870:8556:b0:210:e14a:7a9c with SMTP id w22-20020a056870855600b00210e14a7a9cmr4639455oaj.58.1706775246051; Thu, 01 Feb 2024 00:14:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706775246; cv=pass; d=google.com; s=arc-20160816; b=Bm0MeVTYdFHlxFxVHUKHZG/2NDV/aS3o4uH+TARo21ZhxS8L0Bj+1WgOam85zYyUOY UuC9k6+LERgusZ6v+WmtmJk3q9gq4XnjfzCe4gNs8lqOcVElJrO1sWG3zGudvcUlZqyN WC45YBHwysQGGXpQtLQ4/X0CWNAMsxsnbUxYG1qHWKPGeElTmpqRCA+asqoQ5hzJItqy JLvbTn24EhFCq+h/glSYtfxwG4KcBNWu3br5FPA7AHR3acY5dC7LxPCi3b0Y7K/ubPcn oRoBgV/b62OzloBHghuAV/XVy95Oj/BTWN4TXtnsidrwcjvvr7p7AId2Q0jBp5x/2hym ekTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=4PBk0vA9FeLzNPh8YkTWL8EhVli5xhJSPJ91VWzihrc=; fh=ALKwfJfICQFWNp6Ye4z/pE3kojYqDPFW7pxKPaGpfmw=; b=TrFb8vC6impcdP3zj3BgrsC8xdcc5E8BJHVGhySd4TZS9M2n8rHE33ojzHoKDkYJln R28keSfKBVKyi8sTglc78T9QKYOxdptv/k2IjvcUa82zvWZ58slIJi3bEK6Bvaltjz4I FINvoeAY/+VXEcLTqTcluKtTjWfxEGB3jC65bN14fZRi/V2icV4cf6aEfaNc2sPbUWVG yiST2MI2DodF7cyjQeyt5DuEDCKEvZG/I8YHBy1MccQvrCY/bvBgu1mSaqGzMdQhI5ge m/k4gDopPpFTv3MuUdF5UmUuvFxc4IVIFbrXfvnNt5my7EVKe5v7zD18cRZtq5aVfyAg bfSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-47762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47762-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCVokjdLFO8+k4nvEYw0IP1F1durX+anfPyx1++YmLs4fSMMGxwLBOgF2QlaMIt7+F03sLpRW2kMekdK47OncQngJrfRBwNGgsHTjEjW4Q== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k66-20020a633d45000000b005d71b72c632si11575116pga.81.2024.02.01.00.14.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-47762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47762-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C8A70287608 for ; Thu, 1 Feb 2024 08:12:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49DB5159576; Thu, 1 Feb 2024 08:12:32 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A11031586D3; Thu, 1 Feb 2024 08:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775151; cv=none; b=e+tEzq9r2Q9+kbbb16auwBc1G1Dqi2dN4UteYbKU3Lzpz96Q+m6n8uf4ZLYYx5F2ALu+pJy3xPgBvh9cyuqbGeeutUh2jdi7LeX7Tk/UHmSKqJLemsynX4PnMjpLw4kpy6w1ElHOEyc7dF91/A65FYp/w1WIfOlgBQRuZiW+vo4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775151; c=relaxed/simple; bh=XWgkDI5LEjWrVN67JCy6YWdGvZ06tRRPL0Okk7aKAww=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gcLyjfYzqndazkpj8lafKfk/Dn9ulQQR3dSFd5n1Aev8tbRQ11nstL/5rQGHTW79DbUFW/7G/kAnGsPpZTrCH5LjyfPl0a5lU3KocrkU4XmmCrjCO4O4GBCX3S3zNhSKKU9LVz5jTDTbvoA66x7yQhH4j6g7TB4OWnP3JoSjfew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F301DA7; Thu, 1 Feb 2024 00:13:05 -0800 (PST) Received: from [10.162.42.11] (a077893.blr.arm.com [10.162.42.11]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8267D3F738; Thu, 1 Feb 2024 00:12:11 -0800 (PST) Message-ID: <599769c3-0aef-4c5b-ac98-f109649862f7@arm.com> Date: Thu, 1 Feb 2024 13:42:08 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v3 31/35] khugepaged: arm64: Don't collapse MTE enabled VMAs Content-Language: en-US To: Alexandru Elisei , catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com Cc: pcc@google.com, steven.price@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-32-alexandru.elisei@arm.com> From: Anshuman Khandual In-Reply-To: <20240125164256.4147-32-alexandru.elisei@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/25/24 22:12, Alexandru Elisei wrote: > copy_user_highpage() will do memory allocation if there are saved tags for > the destination page, and the page is missing tag storage. > > After commit a349d72fd9ef ("mm/pgtable: add rcu_read_lock() and > rcu_read_unlock()s"), collapse_huge_page() calls > __collapse_huge_page_copy() -> .. -> copy_user_highpage() with the RCU lock > held, which means that copy_user_highpage() can only allocate memory using > GFP_ATOMIC or equivalent. > > Get around this by refusing to collapse pages into a transparent huge page > if the VMA is MTE-enabled. Makes sense when copy_user_highpage() will allocate memory for tag storage. > > Signed-off-by: Alexandru Elisei > --- > > Changes since rfc v2: > > * New patch. I think an agreement on whether copy*_user_highpage() should be > always allowed to sleep, or should not be allowed, would be useful. This is a good question ! Even after preventing the collapse of MTE VMA here, there still might be more paths where a sleeping (i.e memory allocating) copy*_user_highpage() becomes problematic ? > > arch/arm64/include/asm/pgtable.h | 3 +++ > arch/arm64/kernel/mte_tag_storage.c | 5 +++++ > include/linux/khugepaged.h | 5 +++++ > mm/khugepaged.c | 4 ++++ > 4 files changed, 17 insertions(+) > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index 87ae59436162..d0473538c926 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -1120,6 +1120,9 @@ static inline bool arch_alloc_cma(gfp_t gfp_mask) > return true; > } > > +bool arch_hugepage_vma_revalidate(struct vm_area_struct *vma, unsigned long address); > +#define arch_hugepage_vma_revalidate arch_hugepage_vma_revalidate > + > #endif /* CONFIG_ARM64_MTE_TAG_STORAGE */ > #endif /* CONFIG_ARM64_MTE */ > > diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c > index ac7b9c9c585c..a99959b70573 100644 > --- a/arch/arm64/kernel/mte_tag_storage.c > +++ b/arch/arm64/kernel/mte_tag_storage.c > @@ -636,3 +636,8 @@ void arch_alloc_page(struct page *page, int order, gfp_t gfp) > if (tag_storage_enabled() && alloc_requires_tag_storage(gfp)) > reserve_tag_storage(page, order, gfp); > } > + > +bool arch_hugepage_vma_revalidate(struct vm_area_struct *vma, unsigned long address) > +{ > + return !(vma->vm_flags & VM_MTE); > +} > diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h > index f68865e19b0b..461e4322dff2 100644 > --- a/include/linux/khugepaged.h > +++ b/include/linux/khugepaged.h > @@ -38,6 +38,11 @@ static inline void khugepaged_exit(struct mm_struct *mm) > if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) > __khugepaged_exit(mm); > } > + > +#ifndef arch_hugepage_vma_revalidate > +#define arch_hugepage_vma_revalidate(vma, address) 1 Please replace s/1/true as arch_hugepage_vma_revalidate() returns bool ? > +#endif Right, above construct is much better than __HAVE_ARCH_XXXX based one. > + > #else /* CONFIG_TRANSPARENT_HUGEPAGE */ > static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) > { > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 2b219acb528e..cb9a9ddb4d86 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -935,6 +935,10 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, > */ > if (expect_anon && (!(*vmap)->anon_vma || !vma_is_anonymous(*vmap))) > return SCAN_PAGE_ANON; > + > + if (!arch_hugepage_vma_revalidate(vma, address)) > + return SCAN_VMA_CHECK; > + > return SCAN_SUCCEED; > } > Otherwise this LGTM.