From mboxrd@z Thu Jan 1 00:00:00 1970 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 AD40ED3A66F for ; Tue, 29 Oct 2024 16:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340446B009C; Tue, 29 Oct 2024 12:22:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F20E6B009D; Tue, 29 Oct 2024 12:22:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B8716B009E; Tue, 29 Oct 2024 12:22:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id ED37F6B009C for ; Tue, 29 Oct 2024 12:22:49 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9BB1EC01B3 for ; Tue, 29 Oct 2024 16:22:49 +0000 (UTC) X-FDA: 82727157954.18.277AA03 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf10.hostedemail.com (Postfix) with ESMTP id E0BFBC0023 for ; Tue, 29 Oct 2024 16:22:36 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730218808; 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; bh=kl26WOdC+mDmLtRCsY1mpQj2hreo1lP49DeEz272vS0=; b=ng9Zs4In7BFyatLin//AhnKyiFj6PxyXPU3EA+LIKIw6YHSLqbDSkY8lwE9qY73wIvh29i RPmmSqKLAbV8la4/n0gnB9zz39ad4V+amxU4U2jy8eBiNspYosSSlwTdw60eDTJnc50hUD 1wIl2DzHtE31JqtmoP9TauJRR8D5S7U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730218808; a=rsa-sha256; cv=none; b=salETQ7CzGBiI9ZecZkacvClFA5d3L3DDz6ToliIlO2IA6+d2UWYvrU9+usWkdztEsdEGD dcA74wZ+IBo/+AFAxuKyMWpcK/2h1mWohZhMzkNGyuO/AcQOpblIMoBm0LlFlpYystRkmR z7wrxl8LSXlVV2I43oqBc8r4P6CDZqw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 4740FA42FAA; Tue, 29 Oct 2024 16:20:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82843C4CECD; Tue, 29 Oct 2024 16:22:44 +0000 (UTC) Date: Tue, 29 Oct 2024 16:22:42 +0000 From: Catalin Marinas To: Lorenzo Stoakes Cc: Vlastimil Babka , Linus Torvalds , "Liam R. Howlett" , Mark Brown , Andrew Morton , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , linux-arm-kernel@lists.infradead.org, Will Deacon , Aishwarya TCV Subject: Re: [PATCH hotfix 6.12 v2 4/8] mm: resolve faulty mmap_region() error path behaviour Message-ID: References: <57mgmdx7wgfwci3yo3ggkmcnm3ujamgkwcccm77ypvmer5tegn@opiq3ceh2uvy> <0b64edb9-491e-4dcd-8dc1-d3c8a336a49b@suse.cz> <1608957a-d138-4401-98ef-7fbe5fb7c387@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: ioxtfsh6mwqpniwxg5xqj9pqwdj6egd8 X-Rspamd-Queue-Id: E0BFBC0023 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1730218956-258574 X-HE-Meta: U2FsdGVkX19RErz/QrHmcdrR3M4itxYej+XJsORvSaz6zMwSs/rhW+lmFkZZyRwu4KWUl4Bxs9PNAZUr9WyIy7qyeeQdT0aM8MiwpcHwTDvc7QCsPRKNKXa4sVfxTo7avytD13UI4YqAHnKte+IRI2tSIVdeju+ibFCDVr8efnjtLln8pkFfcNJ3k7XObcSP1XK7bPB1SBzjMD0rqdOV9F4yAmmLIiOWoTS7Neei5BTKSOhD3F2I2m98OrMiDI9R4yHvLxy0Q2ayjdXO+x6Hk0+XfYX04VdMms7n4ZOFKaIZmcmuFNejL/PWGJGcKtB553pOriwZRDdwuyyGDvToyHUfUtgI111uA6JS0zCLf8r3+z0edT6onwcV+cEFmDgQKzNhCqoB+P+6wzHjqSH7TE9D565uGFQfcjOTjExNm46FuvphRrCnkRDl3LFPzIbjZJDFEWdFxzQimtc2Q57uvjZmWK5a2YC7BfEYPmPvZLYiz1T5hzR5K8umojtNKgpPn7SEd+PpWhHscjEUM20QaYLc+pppbAE3qraXm3R+f7wqCoUbFGvekW2Jd2CnSGOWyY69CQrRC8hYjh5IAV/Ah1QzJOh47yh0UQ5v1Lk+wFpZ480TYNti5Dctja470u8p31ux0ENI0k2HJ7purk7LdrXRTteXoNqBVLvILkdPe4uwaE/c42c9Uz/XqxdVO1Gj2lJC0OkGU7ZN1e5tlDDU39ZYywigHeDsR0H1piUM8OBjd12QIzqdSWwE5SdIK3d1WlaYU7sjiFTCRdrGVevqYymbRDvqcmgNHBINIWLbqAqNo7JENtybb8R7G9c/edbU7HVp9wRLh0wd2wfE/EM9QuT2I3FZ5Ij0TQmbhFOL855opf+c+UoxtezfQTtkk/oJdRFFntQTFcAscjytfoQoUuIhYswshFIK6As9DaaRV8M5uheAStYio6a1StekrpeSDH5ZdHoLp9EnyZRVsG/ pXKBQAlJ CCdPaS1hr2waIDIiDnhwCPA1trB7v+qGPlXXgUsqwCs1SK0ACaAsTT9WCEmLdb3u35clAOMgxrg3b3uvHulD9zriCeGvdavz/lCdV47WX/TfWEOOIsy90SVMjUhJzjkk1w5IahMziyXzgpHVFyBvnO9mgzoSClWNQd1toZEvSxgDUtckjUdxQ/NFMqKMu+Pqjl6tBkdT1dMtoJq4pHPL5Sj7CMuf2cVIM5owj81p8b+Z5O48IWui0vlBwQCOUVQj+rxGpQzh4Lf2konC2h253CblcM94Y7DX8aU5pugMzBesi01ie+zy/s+DcgfgTCkiLe8IbRsNXO3HXP3yItIC3/aUhpZxaX762ZoE+2huv90aV18swz6P+8tWf2eHz8WSPgPA3gpaBGYeCyag= 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: On Tue, Oct 29, 2024 at 03:16:00PM +0000, Lorenzo Stoakes wrote: > On Tue, Oct 29, 2024 at 03:04:41PM +0000, Catalin Marinas wrote: > > On Mon, Oct 28, 2024 at 10:14:50PM +0000, Lorenzo Stoakes wrote: > > > So continue to check VM_MTE_ALLOWED which arch_calc_vm_flag_bits() sets if > > > MAP_ANON. > > [...] > > > diff --git a/mm/shmem.c b/mm/shmem.c > > > index 4ba1d00fabda..e87f5d6799a7 100644 > > > --- a/mm/shmem.c > > > +++ b/mm/shmem.c > > > @@ -2733,9 +2733,6 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) > > > if (ret) > > > return ret; > > > > > > - /* arm64 - allow memory tagging on RAM-based files */ > > > - vm_flags_set(vma, VM_MTE_ALLOWED); > > > > This breaks arm64 KVM if the VMM uses shared mappings for the memory > > slots (which is possible). We have kvm_vma_mte_allowed() that checks for > > the VM_MTE_ALLOWED flag as the VMM may not use PROT_MTE/VM_MTE directly. > > Ugh yup missed that thanks. > > > I need to read this thread properly but why not pass the file argument > > to arch_calc_vm_flag_bits() and set VM_MTE_ALLOWED in there? > > Can't really do that as it is entangled in a bunch of other stuff, > e.g. calc_vm_prot_bits() would have to pass file and that's used in a bunch > of places including arch code and... etc. etc. Not calc_vm_prot_bits() but calc_vm_flag_bits(). arch_calc_vm_flag_bits() is only implemented by two architectures - arm64 and parisc and calc_vm_flag_bits() is only called from do_mmap(). Basically we want to set VM_MTE_ALLOWED early during the mmap() call and, at the time, my thinking was to do it in calc_vm_flag_bits(). The calc_vm_prot_bits() OTOH is also called on the mprotect() path and is responsible for translating PROT_MTE into a VM_MTE flag without any checks. arch_validate_flags() would check if VM_MTE comes together with VM_MTE_ALLOWED. But, as in the KVM case, that's not the only function checking VM_MTE_ALLOWED. Since calc_vm_flag_bits() did not take a file argument, the lazy approach was to add the flag explicitly for shmem (and hugetlbfs in -next). But I think it would be easier to just add the file argument to calc_vm_flag_bits() and do the check in the arch code to return VM_MTE_ALLOWED. AFAICT, this is called before mmap_region() and arch_validate_flags() (unless I missed something in the recent reworking). > I suggest instead we instead don't drop the yucky shmem thing, which will > set VM_MTE_ALLOWED for shmem, with arch_calc_vm_flag_bits() still setting > it for MAP_ANON, but the other changes will mean the arch_validate_flags() > will be fixed too. > > So this just means not dropping the mm/shmem.c bit basically and everything > should 'just work'? If we can't get the calc_vm_flag_bits() approach to work, I'm fine with this as a fix and we'll look to do it properly from 6.13. -- Catalin