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 X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79083C433E7 for ; Thu, 15 Oct 2020 16:45:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 223AD22268 for ; Thu, 15 Oct 2020 16:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602780320; bh=hcNtK6AKBv/fh5gmhG4rYbU68RuyoYQE7oAmk1J8P3c=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=rBq8qxldwMHc3WjE99ZI0QlSSiT1c/gXz7fMe4q/CqLEOTiiHs4sx/ExHyk171DeW JwnNuk7S6/PjZdIsFoT4xXPtYdaAg0RzLn+eLyZIcLkFzeTnbZWMCSbmX9mnLDKMGt YGNFEpcGFNv2Gz9Zfkm3EaUVeFCuAAndYe8T07C8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389746AbgJOQpT (ORCPT ); Thu, 15 Oct 2020 12:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388946AbgJOQpT (ORCPT ); Thu, 15 Oct 2020 12:45:19 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04FB1C061755 for ; Thu, 15 Oct 2020 09:45:15 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id f21so3834035ljh.7 for ; Thu, 15 Oct 2020 09:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3tqw/3zrYvsNT6/LR4jSbjq5V2hTGEWhd2+Uj6nH5og=; b=bXA5S6h7u6rIO9U/8BCb6V/8Ll3Ohd0j+gGB1Jz+dDK0SLkxKak/vxGbO5EY80lQrl XTyn2JME8K25Dj3a827M7Z/SWLep/EKvRlhLCdwEtMCA+qf0iowvH/YmJnJ6asN3NR8z 4hY6Ae3XMIxJOCPu1McEBPI5tx2SllEcM2ifs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3tqw/3zrYvsNT6/LR4jSbjq5V2hTGEWhd2+Uj6nH5og=; b=fzh5Kk1tc8L9P1PD0lCOXxF9efMSj7TWQ+Atk4GKuDrKvHI2vMrvFPiw4EB3tCP44W tmcYcAbbw6pN04nx3e0/vQLlk+hL8T2lx1Dy1xnBSxtwGKkpiVQfEZUHQEeXDOyL6zHX GVi93OpA8Th9XQfiTHtwWGocEZrts65h1UHlsYo3NnVgQTRz8HgCQqfYcp5b6YDRHE8T cAXrQO45/mRaa27mmeafi5QtsGF5AgDDlZTxJg0/91KA7rZL8JZyj74ATo/fglBxZ5as QNgSltjLWB6hhpiJ7eFOIO+NG3vvmQlI5AJmaSyAvy/K130J7c38Ua64L16jHaEqI6qQ U/gg== X-Gm-Message-State: AOAM530RRJ3oiMTuUg+Mca7UX2CZ9cqhn9XPuSXgd0yUbCBG+TdhOx0W J8ggUdzAPxcST4czcE5Litkb8Hj3dkmZng== X-Google-Smtp-Source: ABdhPJw2oMM7x15Kv7ogIn/+fPKku1q+Btce/A6iyodGqGyWejJx4oMJTsOLNhKR58hR43xMhw/laQ== X-Received: by 2002:a05:651c:238:: with SMTP id z24mr1783757ljn.408.1602780313143; Thu, 15 Oct 2020 09:45:13 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id j17sm1480456ljg.82.2020.10.15.09.45.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2020 09:45:08 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id r127so4314559lff.12 for ; Thu, 15 Oct 2020 09:45:08 -0700 (PDT) X-Received: by 2002:a19:4186:: with SMTP id o128mr1291810lfa.148.1602780308013; Thu, 15 Oct 2020 09:45:08 -0700 (PDT) MIME-Version: 1.0 References: <20201014130555.kdbxyavqoyfnpos3@box> <20201015094344.pmvg2jxrb2bsoanr@box> In-Reply-To: <20201015094344.pmvg2jxrb2bsoanr@box> From: Linus Torvalds Date: Thu, 15 Oct 2020 09:44:51 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] Some more lock_page work.. To: "Kirill A. Shutemov" Cc: Hugh Dickins , Matthew Wilcox , Linux-MM , Andrew Morton , linux-fsdevel , Amir Goldstein Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu, Oct 15, 2020 at 2:43 AM Kirill A. Shutemov wrote: > > Okay, I see what you propose. > > But I don't think it addresses race with try_to_unmap(): I don't think it needs to. Remember: the map_pages() thing is called only for when the page tables are empty. So try_to_unmap() will never see the pte entry, and there is nothing to race with. So sure, it can "race" with try_to_unmap like you say, but who cares? The "race" is no different from taking the page lock _after_ try_to_unmap() already ran (and didn't see anything because the page hadn't been mapped yet). IOW I don't think try_to_unmap() really matters. The race you outline can already happen with the "trylock()" - no different from the trylock just succeeding after the unlock_page(). So you can think of map_pages() as all happening after try_to_unmap() has already succeeded - and didn't see the new pte that hasn't been filled in yet. I do think there is a real race, but it is is with "__remove_mapping()". That still happens under the page lock, but it doesn't actually _depend_ on the page lock as far as I can tell. Because I think the real protection there is that if (!page_ref_freeze(page, refcount)) goto cannot_free; it that code sees "oh, somebody else has a reference to the page, we can't remove the mapping". But it's entirely possible that I don't understand your worry, and I overlooked something. If so, can you explain using smaller words, please ;) Linus 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 X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 270DDC43457 for ; Thu, 15 Oct 2020 16:45:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C42B2226B for ; Thu, 15 Oct 2020 16:45:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="bXA5S6h7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C42B2226B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E1F926B005D; Thu, 15 Oct 2020 12:45:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD0776B006E; Thu, 15 Oct 2020 12:45:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBDB96B0070; Thu, 15 Oct 2020 12:45:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id A06A56B006E for ; Thu, 15 Oct 2020 12:45:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 41132180AD817 for ; Thu, 15 Oct 2020 16:45:16 +0000 (UTC) X-FDA: 77374735032.23.cause60_5a1726827216 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 1132B37608 for ; Thu, 15 Oct 2020 16:45:16 +0000 (UTC) X-HE-Tag: cause60_5a1726827216 X-Filterd-Recvd-Size: 5038 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 15 Oct 2020 16:45:15 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id 77so4380015lfl.2 for ; Thu, 15 Oct 2020 09:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3tqw/3zrYvsNT6/LR4jSbjq5V2hTGEWhd2+Uj6nH5og=; b=bXA5S6h7u6rIO9U/8BCb6V/8Ll3Ohd0j+gGB1Jz+dDK0SLkxKak/vxGbO5EY80lQrl XTyn2JME8K25Dj3a827M7Z/SWLep/EKvRlhLCdwEtMCA+qf0iowvH/YmJnJ6asN3NR8z 4hY6Ae3XMIxJOCPu1McEBPI5tx2SllEcM2ifs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3tqw/3zrYvsNT6/LR4jSbjq5V2hTGEWhd2+Uj6nH5og=; b=c5toK3FVIu+4yInVYoDZrA66B7zd0r0b2o5JefKtPs/47igH8j0DslTsg4wGLGRqAw CAXTOA6kNT3VF8b1Lo9j3/2wSdJJxt2SX5prqF3CIh3ELKg2tJeXkdxgLExBnIauhsTt lWQ9omSRNSLDV66tXQuDPyM7QBe2bp3yuhaLm162PPWaYqB6ZmM1wD2kmnAJHEaN+5g7 eaiOe+1nI0rB7HtFE+yKr+ctp6FEkckKgq7vw60YG2N8Y5J3gn11MGPYdkCH9hkNsrfH BhKd2L9DjAEyPm8V6ANAS6fMFIaaVk9exSHUOAoXbVZRlAb50/3audXz6dm1m1Rwd6wK VjxQ== X-Gm-Message-State: AOAM531zle9nYPDgl1kxH5MS9eGEIErDjeTtGoGI/ETrf8aMn+42IQ/x zgsoHgTbgeIPXSoa0JwAfgWiXzX5Q01H0A== X-Google-Smtp-Source: ABdhPJxclg2vUT+smJ0ezU3ZLQaXFOYiKnXLr+dlV4lMfm+Jf3C8DRRs6COUBEyneb5wFcSMJSUU+A== X-Received: by 2002:ac2:519a:: with SMTP id u26mr1491399lfi.73.1602780313088; Thu, 15 Oct 2020 09:45:13 -0700 (PDT) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com. [209.85.167.51]) by smtp.gmail.com with ESMTPSA id f26sm1464888ljo.96.2020.10.15.09.45.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2020 09:45:08 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id v6so4311652lfa.13 for ; Thu, 15 Oct 2020 09:45:08 -0700 (PDT) X-Received: by 2002:a19:4186:: with SMTP id o128mr1291810lfa.148.1602780308013; Thu, 15 Oct 2020 09:45:08 -0700 (PDT) MIME-Version: 1.0 References: <20201014130555.kdbxyavqoyfnpos3@box> <20201015094344.pmvg2jxrb2bsoanr@box> In-Reply-To: <20201015094344.pmvg2jxrb2bsoanr@box> From: Linus Torvalds Date: Thu, 15 Oct 2020 09:44:51 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] Some more lock_page work.. To: "Kirill A. Shutemov" Cc: Hugh Dickins , Matthew Wilcox , Linux-MM , Andrew Morton , linux-fsdevel , Amir Goldstein Content-Type: text/plain; charset="UTF-8" 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 Thu, Oct 15, 2020 at 2:43 AM Kirill A. Shutemov wrote: > > Okay, I see what you propose. > > But I don't think it addresses race with try_to_unmap(): I don't think it needs to. Remember: the map_pages() thing is called only for when the page tables are empty. So try_to_unmap() will never see the pte entry, and there is nothing to race with. So sure, it can "race" with try_to_unmap like you say, but who cares? The "race" is no different from taking the page lock _after_ try_to_unmap() already ran (and didn't see anything because the page hadn't been mapped yet). IOW I don't think try_to_unmap() really matters. The race you outline can already happen with the "trylock()" - no different from the trylock just succeeding after the unlock_page(). So you can think of map_pages() as all happening after try_to_unmap() has already succeeded - and didn't see the new pte that hasn't been filled in yet. I do think there is a real race, but it is is with "__remove_mapping()". That still happens under the page lock, but it doesn't actually _depend_ on the page lock as far as I can tell. Because I think the real protection there is that if (!page_ref_freeze(page, refcount)) goto cannot_free; it that code sees "oh, somebody else has a reference to the page, we can't remove the mapping". But it's entirely possible that I don't understand your worry, and I overlooked something. If so, can you explain using smaller words, please ;) Linus