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 63C5AC54E76 for ; Mon, 20 Nov 2023 09:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D99D56B0424; Mon, 20 Nov 2023 04:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D49A76B0425; Mon, 20 Nov 2023 04:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC2EA6B0426; Mon, 20 Nov 2023 04:12:08 -0500 (EST) 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 AAEC06B0424 for ; Mon, 20 Nov 2023 04:12:08 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6DC618083B for ; Mon, 20 Nov 2023 09:12:08 +0000 (UTC) X-FDA: 81477765936.22.9C17916 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id E415E18000E for ; Mon, 20 Nov 2023 09:12:05 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Dv2jceUM; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700471526; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=beWkdQyS0FTQqwAB6XSwh+RxrEzF4RE2H8cExXwzJjY=; b=WbRtreKwJ2SE9Y11N7BeneaRDBC4JMoLzUdXaagA3DuiSjXRY2sspYlh66xV1wD6IJOYRd tTWNfmlrtI4rSnaPYWQ/7nV115luLbQyXvgE05kynRu1slFxIux4OMY1hIUmq/nTozhGc6 5Xtms2hW3/6jiuH+/uxiyiJ8mLm0FmY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700471526; a=rsa-sha256; cv=none; b=c+tp2TZLFLyeosFMaousnLYShZrDruDsF8XVlz4sU4weBcV9i2qK+jvKU15IVH1J2jw8Y7 MniuuqKGcThBCJcvysm3XzoW9sfBkTEhaFTga5kzlderMmzNcc+25eF6Z9K5/CTuoU1S0a Q09CLOORcHGIXHuLFvmNkChddKSs6FY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Dv2jceUM; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700471525; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=beWkdQyS0FTQqwAB6XSwh+RxrEzF4RE2H8cExXwzJjY=; b=Dv2jceUMc4eGOIFCXI2Ynp0Cs7aOg7mbo7IZZ8ZKCxP4ESOHeCF/LsvPWr3tJsfKuka4Pg NkHPmiy8lLxilKa97lDt6s6sKFMzeTmPV3R3o8rbii1LhA5hiV7ib6JtFfVT5jTXiB9bXP CHfMXhPLm5pLEC6EuJTeomifWcGvQ14= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-320-879XTCz_Ms2Ho2BuOdkriA-1; Mon, 20 Nov 2023 04:12:03 -0500 X-MC-Unique: 879XTCz_Ms2Ho2BuOdkriA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9fcfa742e49so73211166b.2 for ; Mon, 20 Nov 2023 01:12:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700471522; x=1701076322; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=beWkdQyS0FTQqwAB6XSwh+RxrEzF4RE2H8cExXwzJjY=; b=wnOi4wikFY35bEvLnzJ9ON8ZMINsm/ZaDpgNDopod1ZzZMalF/VBlIRH4iBx2FN8Ez 6P+SKw3rvytpbeno+PMpcLIqrkttw+PtbszyEDovDWL79n+1RFYkMZfy1f+NlBmvSC6q EnD/p1qXwMQU2rSAF0OOTt5sLAh1mlTmfLyN9CkTn3Uwn1RoTWt9zPcF/ObgUG8Fwvlu rU3kpEDrD2Cn9+WwHlogWiwL6liEHdqfI0GW2eTm54CGRGIqFZdsnEinGS1UmoiwSr1I PoKQyVu+mQpW82o6rO/RVJID0yT9T3qmO/RjR+H1ShlDpXejbUkPBnZ8aR1M5kAJPZaI c+Jg== X-Gm-Message-State: AOJu0YzZANwoUigi1VwemyAjnvV0q5YMsO6k69oGtYpeNF2FKMxf2KGC 94PJx9cU+XQEQ1nxiOQnEcjj9laTZPi/FD+ku71vcAaWmFbrM5N3k69dQQCb2lAXddsHhII5Vy8 likSoVVpmsNw= X-Received: by 2002:a17:907:91cd:b0:9fe:6583:ce90 with SMTP id h13-20020a17090791cd00b009fe6583ce90mr1484295ejz.63.1700471522106; Mon, 20 Nov 2023 01:12:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmP4LtELFnMk1dcL/Xum6d57mrz5G9IGKPGqZvcxktXXJYD+xrbxi58y43IqFxdgi0u0DO7Q== X-Received: by 2002:a17:907:91cd:b0:9fe:6583:ce90 with SMTP id h13-20020a17090791cd00b009fe6583ce90mr1484279ejz.63.1700471521506; Mon, 20 Nov 2023 01:12:01 -0800 (PST) Received: from ?IPV6:2003:cb:c746:7700:9885:6589:b1e3:f74c? (p200300cbc746770098856589b1e3f74c.dip0.t-ipconnect.de. [2003:cb:c746:7700:9885:6589:b1e3:f74c]) by smtp.gmail.com with ESMTPSA id kg26-20020a17090776fa00b009fc8233fb66sm1614813ejc.36.2023.11.20.01.12.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 01:12:01 -0800 (PST) Message-ID: Date: Mon, 20 Nov 2023 10:11:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC V3 PATCH] arm64: mm: swap: save and restore mte tags for large folios To: Barry Song <21cnbao@gmail.com> Cc: steven.price@arm.com, akpm@linux-foundation.org, ryan.roberts@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.com, shy828301@gmail.com, v-songbaohua@oppo.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com References: <20231114014313.67232-1-v-songbaohua@oppo.com> <864489b3-5d85-4145-b5bb-5d8a74b9b92d@redhat.com> <8c7f1a2f-57d2-4f20-abb2-394c7980008e@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL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CGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E415E18000E X-Rspam-User: X-Stat-Signature: ux7t17entndrhhz5fiuttpuktpitutri X-Rspamd-Server: rspam03 X-HE-Tag: 1700471525-585362 X-HE-Meta: U2FsdGVkX1/NZ5tsIPEyFTuWHLHA6XLxq+PxgtBGIHpSAFuNp9iEG6sA4Uy3kJN90VLk4n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u6OT4WZm7GpsRXW8cDwHlkfUrkyAf0qMNhX1Z9/PQvC/EOgAbVjnJwsyZo4H6THvccl4xZz9AQF0ecRRduzBp1xy+o8KiW4OyaG4A2+RcjkWH2dxpKMGTJvzJRYdwdSxV1PpOko5kiQCWO9UwuftM1i1VwtB3KyR6W4Vx+CoDwYCcHmxlJwr6L3fOxeVP4Vz4vxBUUL8FYP/dwXlBgylT13M3J/aV3xU4DOc1/atrZ7aaxQ3AsXFsGsVNOWK0vnjTQX68/5ib+tLUZGZPRV9rW+COww+lBTtLZKibcv30zn6bIKauIPUXm5/zviZipOtbKRsltF+sSrwCMIjrNkNJm+9eBQxsTPAbhrtle431odZmiqanDvrMQTkQjFrUDBe0g== 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 17.11.23 19:41, Barry Song wrote: > On Fri, Nov 17, 2023 at 7:28 PM David Hildenbrand wrote: >> >> On 17.11.23 01:15, Barry Song wrote: >>> On Fri, Nov 17, 2023 at 7:47 AM Barry Song <21cnbao@gmail.com> wrote: >>>> >>>> On Thu, Nov 16, 2023 at 5:36 PM David Hildenbrand wrote: >>>>> >>>>> On 15.11.23 21:49, Barry Song wrote: >>>>>> On Wed, Nov 15, 2023 at 11:16 PM David Hildenbrand wrote: >>>>>>> >>>>>>> On 14.11.23 02:43, Barry Song wrote: >>>>>>>> This patch makes MTE tags saving and restoring support large folios, >>>>>>>> then we don't need to split them into base pages for swapping out >>>>>>>> on ARM64 SoCs with MTE. >>>>>>>> >>>>>>>> arch_prepare_to_swap() should take folio rather than page as parameter >>>>>>>> because we support THP swap-out as a whole. >>>>>>>> >>>>>>>> Meanwhile, arch_swap_restore() should use page parameter rather than >>>>>>>> folio as swap-in always works at the granularity of base pages right >>>>>>>> now. >>>>>>> >>>>>>> ... but then we always have order-0 folios and can pass a folio, or what >>>>>>> am I missing? >>>>>> >>>>>> Hi David, >>>>>> you missed the discussion here: >>>>>> >>>>>> https://lore.kernel.org/lkml/CAGsJ_4yXjex8txgEGt7+WMKp4uDQTn-fR06ijv4Ac68MkhjMDw@mail.gmail.com/ >>>>>> https://lore.kernel.org/lkml/CAGsJ_4xmBAcApyK8NgVQeX_Znp5e8D4fbbhGguOkNzmh1Veocg@mail.gmail.com/ >>>>> >>>>> Okay, so you want to handle the refault-from-swapcache case where you get a >>>>> large folio. >>>>> >>>>> I was mislead by your "folio as swap-in always works at the granularity of >>>>> base pages right now" comment. >>>>> >>>>> What you actually wanted to say is "While we always swap in small folios, we >>>>> might refault large folios from the swapcache, and we only want to restore >>>>> the tags for the page of the large folio we are faulting on." >>>>> >>>>> But, I do if we can't simply restore the tags for the whole thing at once >>>>> at make the interface page-free? >>>>> >>>>> Let me elaborate: >>>>> >>>>> IIRC, if we have a large folio in the swapcache, the swap entries/offset are >>>>> contiguous. If you know you are faulting on page[1] of the folio with a >>>>> given swap offset, you can calculate the swap offset for page[0] simply by >>>>> subtracting from the offset. >>>>> >>>>> See page_swap_entry() on how we perform this calculation. >>>>> >>>>> >>>>> So you can simply pass the large folio and the swap entry corresponding >>>>> to the first page of the large folio, and restore all tags at once. >>>>> >>>>> So the interface would be >>>>> >>>>> arch_prepare_to_swap(struct folio *folio); >>>>> void arch_swap_restore(struct page *folio, swp_entry_t start_entry); >>>>> >>>>> I'm sorry if that was also already discussed. >>>> >>>> This has been discussed. Steven, Ryan and I all don't think this is a good >>>> option. in case we have a large folio with 16 basepages, as do_swap_page >>>> can only map one base page for each page fault, that means we have >>>> to restore 16(tags we restore in each page fault) * 16(the times of page faults) >>>> for this large folio. >>>> >>>> and still the worst thing is the page fault in the Nth PTE of large folio >>>> might free swap entry as that swap has been in. >>>> do_swap_page() >>>> { >>>> /* >>>> * Remove the swap entry and conditionally try to free up the swapcache. >>>> * We're already holding a reference on the page but haven't mapped it >>>> * yet. >>>> */ >>>> swap_free(entry); >>>> } >>>> >>>> So in the page faults other than N, I mean 0~N-1 and N+1 to 15, you might access >>>> a freed tag. >>> >>> And David, one more information is that to keep the parameter of >>> arch_swap_restore() unchanged as folio, >>> i actually tried an ugly approach in rfc v2: >>> >>> +void arch_swap_restore(swp_entry_t entry, struct folio *folio) >>> +{ >>> + if (system_supports_mte()) { >>> + /* >>> + * We don't support large folios swap in as whole yet, but >>> + * we can hit a large folio which is still in swapcache >>> + * after those related processes' PTEs have been unmapped >>> + * but before the swapcache folio is dropped, in this case, >>> + * we need to find the exact page which "entry" is mapping >>> + * to. If we are not hitting swapcache, this folio won't be >>> + * large >>> + */ >>> + struct page *page = folio_file_page(folio, swp_offset(entry)); >>> + mte_restore_tags(entry, page); >>> + } >>> +} >>> >>> And obviously everybody in the discussion hated it :-) >>> >> >> I can relate :D >> >>> i feel the only way to keep API unchanged using folio is that we >>> support restoring PTEs >>> all together for the whole large folio and we support the swap-in of >>> large folios. This is >>> in my list to do, I will send a patchset based on Ryan's large anon >>> folios series after a >>> while. till that is really done, it seems using page rather than folio >>> is a better choice. >> >> I think just restoring all tags and remembering for a large folio that >> they have been restored might be the low hanging fruit. But as always, >> devil is in the detail :) > > Hi David, > thanks for all your suggestions though my feeling is this is too complex and > is not worth it for at least three reasons. Fair enough. > > 1. In multi-thread and particularly multi-processes, we need some locks to > protect and help know if one process is the first one to restore tags and if > someone else is restoring tags when one process wants to restore. there > is not this kind of fine-grained lock at all. We surely always hold the folio lock on swapin/swapout, no? So when these functions are called. So that might just work already -- unless I am missing something important. > > 2. folios are not always large, in many cases, they have just one base page > and there is no tail to remember. and it seems pretty ugly if we turn out have > to use different ways to remember restoring state for small folios and > large folios. if (folio_test_large(folio)) { } else { } Easy ;) Seriously, it's not that complicated and/or ugly. > > 3. there is nothing wrong to use page to restore tags since right now swap-in > is page. restoring tags and swapping-in become harmonious with each other > after this patch. I would argue what is really wrong is the current mainline. > > If eventually we are able to do_swap_page() for the whole large folio, we > move to folios for MTE tags as well. These two behaviours make a new > harmonious picture again. > Just making both functions consume folios is much cleaner and also more future proof. Consuming now a page where we used to consume a folio is a step backwards. -- Cheers, David / dhildenb