From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com [52.28.197.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 523B42AE78; Fri, 6 Mar 2026 15:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.28.197.132 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772811718; cv=none; b=ZwFiFr9ZB31V8bmePgMPP42kulWoFzUGQtEUpxnuYNoeJ19QnTL2Y4urHwgj47+eqPLz35c8GEhvJduxc9jORuwwc+TGhAqpyE6GD0sPzTNuRlWxnt8UPqJTS58FdpQaiLdculSE3phIyM/FVmGP5X6UnMOFHEiKPTKjpTU4KxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772811718; c=relaxed/simple; bh=C+TIi3OVTHeU4/YpXmPN6ChBPTVFEYpeWN7RdHrTOB0=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=SAvzZ8OcWsGF8JYYqBkSw8QPFBPIvaXPQaXxJ9ez8frlcC49sADJzDw4kjDUsnjAa3cX/IbfEYWliC0RUnlnuLXUtEMeZ5FDi0jFsgnjW0NuU+G3PPdRmuibScAuoD48GvwSlWZt1nrrYQJYlLsuRBSGJD7NzYa6Jj2Qagb8n3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=Q70p8Ep7; arc=none smtp.client-ip=52.28.197.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="Q70p8Ep7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1772811717; x=1804347717; h=message-id:date:mime-version:reply-to:subject:to:cc: references:from:in-reply-to:content-transfer-encoding; bh=YnCR77bPkSJ3r6eLW+FO2o4FnCnPBwwukZtKN2qmask=; b=Q70p8Ep7xTsO1OjUkZDaSu/LtGmJkPOnsximK4zz8H5Hwc1tTSiDw7oH 9HPDs6IfqZ3oSYsICpF6Bsjv8TeXlTQ3wxuhrcLAq0iqYDJfvUZtGvq4/ 3Z/zcWbd+RFfstDg3YgQi/yEaPOoNe6/ANtf/FvfjZRYMhAaAj5kyCLwt 7B/7qhOI1F/o1FWGeUd3HyiPcX/YXNEuHM3wYWMgo+RvFnAUnTm13NLPA z5yjLKmmh850P1bus51dooK/hU6qY25VurrCLt4FCnjy3T/eflPoKk/iG pizqSDUVqydIAi0GV8PfBmg0/iqZVvCiQdzuu4UKgV/i+QHG4EgeF9D+U w==; X-CSE-ConnectionGUID: GwEkaMEOTMKbobqyy3yX9A== X-CSE-MsgGUID: di4IC+oOQpGwVPpG+YbSbA== X-IronPort-AV: E=Sophos;i="6.23,105,1770595200"; d="scan'208";a="10322839" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2026 15:41:52 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:9370] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.46.96:2525] with esmtp (Farcaster) id 5185657e-5145-4540-97b1-c86cd60d47dd; Fri, 6 Mar 2026 15:41:52 +0000 (UTC) X-Farcaster-Flow-ID: 5185657e-5145-4540-97b1-c86cd60d47dd Received: from EX19D005EUB003.ant.amazon.com (10.252.51.31) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 6 Mar 2026 15:41:52 +0000 Received: from [192.168.2.180] (10.106.83.26) by EX19D005EUB003.ant.amazon.com (10.252.51.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 6 Mar 2026 15:41:47 +0000 Message-ID: <5c322be7-ea81-4e6a-9689-978c35e93af6@amazon.com> Date: Fri, 6 Mar 2026 15:41:45 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: Subject: Re: [PATCH v10 02/15] set_memory: add folio_{zap, restore}_direct_map helpers To: "David Hildenbrand (Arm)" , "Kalyazin, Nikita" , "kvm@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "bpf@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "kernel@xen0n.name" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "loongarch@lists.linux.dev" CC: "pbonzini@redhat.com" , "corbet@lwn.net" , "maz@kernel.org" , "oupton@kernel.org" , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "catalin.marinas@arm.com" , "will@kernel.org" , "seanjc@google.com" , "tglx@kernel.org" , "mingo@redhat.com" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "hpa@zytor.com" , "luto@kernel.org" , "peterz@infradead.org" , "willy@infradead.org" , "akpm@linux-foundation.org" , "lorenzo.stoakes@oracle.com" , "vbabka@suse.cz" , "rppt@kernel.org" , "surenb@google.com" , "mhocko@suse.com" , "ast@kernel.org" , "daniel@iogearbox.net" , "andrii@kernel.org" , "martin.lau@linux.dev" , "eddyz87@gmail.com" , "song@kernel.org" , "yonghong.song@linux.dev" , "john.fastabend@gmail.com" , "kpsingh@kernel.org" , "sdf@fomichev.me" , "haoluo@google.com" , "jolsa@kernel.org" , "jgg@ziepe.ca" , "jhubbard@nvidia.com" , "peterx@redhat.com" , "jannh@google.com" , "pfalcato@suse.de" , "shuah@kernel.org" , "riel@surriel.com" , "ryan.roberts@arm.com" , "jgross@suse.com" , "yu-cheng.yu@intel.com" , "kas@kernel.org" , "coxu@redhat.com" , "kevin.brodsky@arm.com" , "ackerleytng@google.com" , "maobibo@loongson.cn" , "prsampat@amd.com" , "mlevitsk@redhat.com" , "jmattson@google.com" , "jthoughton@google.com" , "agordeev@linux.ibm.com" , "alex@ghiti.fr" , "aou@eecs.berkeley.edu" , "borntraeger@linux.ibm.com" , "chenhuacai@kernel.org" , "dev.jain@arm.com" , "gor@linux.ibm.com" , "hca@linux.ibm.com" , "palmer@dabbelt.com" , "pjw@kernel.org" , "shijie@os.amperecomputing.com" , "svens@linux.ibm.com" , "thuth@redhat.com" , "wyihan@google.com" , "yang@os.amperecomputing.com" , "Jonathan.Cameron@huawei.com" , "Liam.Howlett@oracle.com" , "urezki@gmail.com" , "zhengqi.arch@bytedance.com" , "gerald.schaefer@linux.ibm.com" , "jiayuan.chen@shopee.com" , "lenb@kernel.org" , "osalvador@suse.de" , "pavel@kernel.org" , "rafael@kernel.org" , "vannapurve@google.com" , "jackmanb@google.com" , "aneesh.kumar@kernel.org" , "patrick.roy@linux.dev" , "Thomson, Jack" , "Itazuri, Takahiro" , "Manwaring, Derek" , "Cali, Marco" References: <20260126164445.11867-1-kalyazin@amazon.com> <20260126164445.11867-3-kalyazin@amazon.com> <40bd6f9b-d5c0-4844-81bc-d221cd9b058f@kernel.org> <38deb26a-918c-4743-b35f-92a1330dbf40@amazon.com> Content-Language: en-US From: Nikita Kalyazin In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: EX19D007EUB003.ant.amazon.com (10.252.51.43) To EX19D005EUB003.ant.amazon.com (10.252.51.31) On 06/03/2026 15:17, David Hildenbrand (Arm) wrote: > On 3/6/26 15:48, Nikita Kalyazin wrote: >> >> >> On 06/03/2026 14:17, David Hildenbrand (Arm) wrote: >>> On 3/6/26 13:48, Nikita Kalyazin wrote: >>>> >>>> >>>> >>>> Will update, thanks. >>>> >>>> >>>> Absolutely! >>>> >>>> >>>> Yes, on x86 we need an explicit flush. Other architectures deal with it >>>> internally. >>> >>> So, we call a _noflush function and it performs a ... flush. What. >> >> Yeah, that's unfortunately the status quo as pointed by Aneesh [1] >> >> [1] https://lore.kernel.org/kvm/yq5ajz07czvz.fsf@kernel.org/ >> >>> >>> Take a look at secretmem_fault(), where we do an unconditional >>> flush_tlb_kernel_range(). >>> >>> Do we end up double-flushing in that case? >> >> Yes, looks like that. I'll remove the explicit flush and rely on >> folio_zap_direct_map(). >> >>> >>>> Do you propose a bespoke implementation for x86 and a >>>> "generic" one for others? >>> >>> We have to find a way to have a single set of functions for all archs >>> that support directmap removal. >> >> I believe Dave meant to address that with folio_{zap,restore} >> _direct_map() [2]. >> >> [2] https://lore.kernel.org/kvm/9409531b-589b-4a54- >> b122-06a3cf0846f3@intel.com/ >> >>> >>> One option might be to have some indication from the architecture that >>> no flush_tlb_kernel_range() is required. >>> >>> Could be a config option or some simple helper function. >> >> I'd be inclined to know what arch maintainers think because I don't have >> a strong opinion on that. > > You could also just perform a double flush, and let people that > implemented a _noflush() to perform a flush optimize that later. Do you propose to just universalise the one from x86? int folio_zap_direct_map(struct folio *folio) { const void *addr = folio_address(folio); int ret; ret = set_direct_map_valid_noflush(addr, folio_nr_pages(folio), false); flush_tlb_kernel_range((unsigned long)addr, (unsigned long)addr + folio_size(folio)); return ret; } I'm fine with that too. > > I mean, that's what secretmem did :) With the solution above, secretmem stays where it was: no optimisation so far :) > > -- > Cheers, > > David