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 B81E9C4332F for ; Wed, 23 Nov 2022 19:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A856B0071; Wed, 23 Nov 2022 14:31:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FA6F6B0072; Wed, 23 Nov 2022 14:31:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C3346B0074; Wed, 23 Nov 2022 14:31:24 -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 EFF776B0071 for ; Wed, 23 Nov 2022 14:31:23 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B4A641A01BE for ; Wed, 23 Nov 2022 19:31:23 +0000 (UTC) X-FDA: 80165700846.03.4E72403 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 4D403120015 for ; Wed, 23 Nov 2022 19:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669231882; 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; bh=of6BBewdTwcAl18GJoeXpGt0yO4qHxqQv2rqdT+vNQU=; b=Aiiwel9IUcBYlLaiixBFsy8n2Ehp+5yKR0ESThaAjIxMXMgM9dF5d7stavt2+YFhmVhZLz iYPvCwWU/SzKM+245i/CXwAN0uInIZzL08Ba8m0A1FAA85gpk4y+DJ4WsystcTyc+7r8Nt mfnlE8lylTwe+cl9eG4ikrMxinDJCY4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-5-QM8WLrhkO6SBCNxOBD5dRw-1; Wed, 23 Nov 2022 14:31:21 -0500 X-MC-Unique: QM8WLrhkO6SBCNxOBD5dRw-1 Received: by mail-wm1-f71.google.com with SMTP id u9-20020a05600c00c900b003cfb12839d6so1134300wmm.5 for ; Wed, 23 Nov 2022 11:31:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization: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=of6BBewdTwcAl18GJoeXpGt0yO4qHxqQv2rqdT+vNQU=; b=EICTuWCL+mCWncN3oWYfhLVZ8a13g/LJ89QkLqZV3F/yWPL3gqydlDhpXl4M/Uagpb F5rbunZYhco04Ee9qqr898/1JmoH4BylkaW/ERbhZqxrttiaqHcIAZByZwpnZ7we27g/ QqTwYpIFXhJrqM4oW8Bemtz+CtMI+ptLZNegxZRqg5ARfO/XJsZSBKGLDbR63JGShu7X H6dH3fwQhXcANk0ko8ZqQEIQVfro3jnzKVMOoBAg6R4XxbIXCvRG5gemm/ybtxcC2LRS TPxe3ZXqb3mW0eIg4OtQJ/UHYbB7kU9fakjB+zO1Z5yjQDRQO219/81FBpzJCBam2N4/ 8pJQ== X-Gm-Message-State: ANoB5pnlD6f6bUjkj4ZeFG8ruNSz17yWRFlT54dwxbh3iGtGBxKPngv/ TffadRwdNh5vCc+jbXdubT/gb0GDf5Xhky79Ft2uDLv680m/USKN/tgfrjKbnR7sHoUaqeiibC8 ah4f4aI5vzfU= X-Received: by 2002:a7b:c048:0:b0:3a8:3e58:bb9b with SMTP id u8-20020a7bc048000000b003a83e58bb9bmr11074608wmc.168.1669231880236; Wed, 23 Nov 2022 11:31:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Wp/b0j11VObTynBBu9QcnlwyPQSskAgXFOBT/I+1/dIPrJfEOGaLa02LYRHt8G6iE5vlpVw== X-Received: by 2002:a7b:c048:0:b0:3a8:3e58:bb9b with SMTP id u8-20020a7bc048000000b003a83e58bb9bmr11074594wmc.168.1669231879864; Wed, 23 Nov 2022 11:31:19 -0800 (PST) Received: from ?IPV6:2003:cb:c704:9f00:a98d:4026:7c44:40fd? (p200300cbc7049f00a98d40267c4440fd.dip0.t-ipconnect.de. [2003:cb:c704:9f00:a98d:4026:7c44:40fd]) by smtp.gmail.com with ESMTPSA id u12-20020adfdb8c000000b002367ad808a9sm17174818wri.30.2022.11.23.11.31.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Nov 2022 11:31:19 -0800 (PST) Message-ID: <6fc2066e-1386-5fc4-44c6-d84404c2ef25@redhat.com> Date: Wed, 23 Nov 2022 20:31:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH RFC v2 00/12] mm/hugetlb: Make huge_pte_offset() thread-safe for pmd unshare To: Peter Xu , Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Rik van Riel , Muchun Song , Andrew Morton , James Houghton , Nadav Amit , Andrea Arcangeli , Miaohe Lin References: <20221118011025.2178986-1-peterx@redhat.com> <70376d57-7924-8ac9-9e93-1831248115a0@redhat.com> From: David Hildenbrand 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: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669231883; a=rsa-sha256; cv=none; b=jSo6yiGunTkwAiv/+5DXqN2+8QA09taBi8j5eeIYHCEvhdF/Hu9L1w2yv4TFql/qqFYyPA fwnSUFmqbbS1EMkwC2UCZhyj6+X8SFtLZ5xAGrelG693lhe9Md9UM4279kcKEdydLCbQhW TntHw7SQDXU3qs0n+MNL4W5J+kvYexA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Aiiwel9I; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669231883; 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=of6BBewdTwcAl18GJoeXpGt0yO4qHxqQv2rqdT+vNQU=; b=oprRVPlgML7YSUJs0VV+Upqfai9fzwS08jeRxVjJXZz1fHnv5msmCINVvwug+BCT1CjBJN SEHIEdjt75gfG5s9tn+YoMnFaWVNaexuT/wLxTUzzs+tWlawDXxkqRI/dLeob7D0G51FgB 85o66j0UI5jwEOAHQEWu0arIxoLsmzg= X-Stat-Signature: jkg1ebb35jmpesnizydnnzw3gje4acgi X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4D403120015 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Aiiwel9I; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-HE-Tag: 1669231883-804139 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: On 23.11.22 19:56, Peter Xu wrote: > On Wed, Nov 23, 2022 at 10:21:30AM -0800, Mike Kravetz wrote: >> On 11/23/22 10:09, Peter Xu wrote: >>> On Wed, Nov 23, 2022 at 10:40:40AM +0100, David Hildenbrand wrote: >>>> Let me try understand the basic problem first: >>>> >>>> hugetlb walks page tables semi-lockless: while we hold the mmap lock, we >>>> don't grab the page table locks. That's very hugetlb specific handling and I >>>> assume hugetlb uses different mechanisms to sync against MADV_DONTNEED, >>>> concurrent page fault s... but that's no news. hugetlb is weird in many ways >>>> :) >>>> >>>> So, IIUC, you want a mechanism to synchronize against PMD unsharing. Can't >>>> we use some very basic locking for that? >>> >>> Yes we can in most cases. Please refer to above paragraph [1] where I >>> referred Mike's recent work on vma lock. That's the basic locking we need >>> so far to protect pmd unsharing. I'll attach the link too in the next >>> post, which is here: >>> >>> https://lore.kernel.org/r/20220914221810.95771-1-mike.kravetz@oracle.com >>> >>>> >>>> Using RCU / disabling local irqs seems a bit excessive because we *are* >>>> holding the mmap lock and only care about concurrent unsharing >>> >>> The series wanted to address where the vma lock is not easy to take. It >>> originates from when I was reading Mike's other patch, I forgot why I did >>> that but I just noticed there's some code path that we may not want to take >>> a sleepable lock, e.g. in follow page code. >> >> Yes, it was the patch suggested by David, >> >> https://lore.kernel.org/linux-mm/20221030225825.40872-1-mike.kravetz@oracle.com/ >> >> The issue was that FOLL_NOWAIT could be passed into follow_page_mask. If so, >> then we do not want potentially sleep on the mutex. >> >> Since you both are on this thread, I thought of/noticed a related issue. In >> follow_hugetlb_page, it looks like we can call hugetlb_fault if FOLL_NOWAIT >> is set. hugetlb_fault certainly has the potential for sleeping. Is this also >> a similar issue? > > Yeah maybe the clean way to do this is when FAULT_FLAG_RETRY_NOWAIT is set > we should always try to not sleep at all. hva_to_pfn_slow() that sets FOLL_NOWAIT calls get_user_pages_unlocked(), which will just do a straight mmap_read_lock(). The interpretation of FOLL_NOWAIT should not be "don't take any sleepable locks" but instead more like "don't wait for a page to get swapped in". #define FOLL_NOWAIT 0x20 /* if a disk transfer is needed, start the IO I did not read the full replies yet (sorry, busy hacking :) ) but *any* code path that already takes the mmap_read_lock() can just take whatever other lock we want -- IMHO. No need to over-complicate our code trying to avoid locks in that case. -- Thanks, David / dhildenb