Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp636165pxy; Fri, 30 Apr 2021 12:55:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsoHfZhulqoF2KUEMtYJf1pfCOSNztoRY9PiyHfN07A/1PWCPH2m/R3LXs3oYRNku1hzOt X-Received: by 2002:a17:90a:d195:: with SMTP id fu21mr3757636pjb.208.1619812523409; Fri, 30 Apr 2021 12:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619812523; cv=none; d=google.com; s=arc-20160816; b=V2kUwrF+w+jI5UCPH0/fPPkQh0vmKpDkaKNq+mCoLnrm0bY4QYPFCqxJnE/imvVcMP mGrfZ8BL0U2ZTbdyoob2rQbYlm18usw9zZQaTCsERA+hQ/OLsn01YuyBOOmJXzM4f8Q4 8bSTUkFJUK9z6ZTdDeeK61j4c1M1eFMn+rK98ZvGIpkoiOON99/GKmg5QKe1dHTwR+FW U7WX1E3Culk+p3LvZIjnI9PWceJL8P4GJooX4tQNRF7kWkaCSRkwXeY6MPHWSpqxcm6V 8Rt/x1nHfsMcKXe90V89v3FSqpZF7o3fQo5O7a1CMfg9/agLwZhFIZ0x6GDTG0xoPhxr PEcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=AZMDU3YPUBP+A8E2sGu7mqnPCKXc6C4guT20cQnVLhI=; b=sV1jIBM9fPlaruVcFJM5Ckaxs5lrkh59/dQOtcIK0CYikS31gagRX7AiA08Su0/c+V wiu7LMMmT9irDcMgaGlmZiKIH7mTVeCNG+JRsZSfBKJc7ZT6QhrqdBk3v+rcO6CL1BJV hULk8Qj7ArfU2CI0Z8UEpaLUSLG4w1zd1TnRtr/dyNaqCg7hO6YpqhhENhE6tf/avs3z d7F1SwCkkPYsfxjJSBYvGhviiRJjCF7Qcc0m/b23z59qqSaCxCTH1qLDARLuccBQIBdy EnEd4Z3/o8HPL5f+gaW1xhrXMRk/D6kjwMH4pDWk+/YelQ7FesmYE9jdjcmVWhSIBkDu c1IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=ZkO9R1pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si4243614plp.148.2021.04.30.12.55.11; Fri, 30 Apr 2021 12:55:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=neutral (no key) header.i=@lespinasse.org; dkim=pass (test mode) header.i=@lespinasse.org header.s=srv-14-rsa header.b=ZkO9R1pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lespinasse.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233477AbhD3Tx5 (ORCPT + 99 others); Fri, 30 Apr 2021 15:53:57 -0400 Received: from server.lespinasse.org ([63.205.204.226]:37105 "EHLO server.lespinasse.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232370AbhD3TxY (ORCPT ); Fri, 30 Apr 2021 15:53:24 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-ed; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=AZMDU3YPUBP+A8E2sGu7mqnPCKXc6C4guT20cQnVLhI=; b=/pCAvRaOx2Si6FofNn8xF8A4WTxfnjNRKNUDSB8g0cwI/beqZTwY7cyDrJpAZu0D/iqo3 LQUWoCnxovEtWzLBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-14-rsa; t=1619812353; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=AZMDU3YPUBP+A8E2sGu7mqnPCKXc6C4guT20cQnVLhI=; b=ZkO9R1pq60ZomZNC7gBkDtC53nRGzuc/y5a8x0+AHLNqjySZhHkBI3MVnw/GNC4XOaKpz AuHxRAomu7xORLhD1hDjxg1DPb9z84v9e8VwekRDtkFt/w/d/cvL9Ga/JKkiGTXTtB4k3Xu nSS/6Q9uOT3hkIFe8dy2U/5rg4Wx02H2Oo+kbx3vaYoVMYzMuqZKTuR5GHKJsrGlZxq1C7N hDXG6idcwcAw43SyrQKhk7slDaGxm5XGk92fRHU8dyIrcsMSw4/mRw/h35DQjLrZKPL8+Fa DHmlnOgonJqUpHWSCLosdIeh3ActgiuBby9lV33SymfaV0UyGKoWtugQjxMg== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 61BFE160324; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id 5277D19F523; Fri, 30 Apr 2021 12:52:33 -0700 (PDT) From: Michel Lespinasse To: Linux-MM , Linux-Kernel Cc: Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Andy Lutomirski , Michel Lespinasse Subject: [PATCH 13/29] mm: add speculative_page_walk_begin() and speculative_page_walk_end() Date: Fri, 30 Apr 2021 12:52:14 -0700 Message-Id: <20210430195232.30491-14-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210430195232.30491-1-michel@lespinasse.org> References: <20210430195232.30491-1-michel@lespinasse.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Speculative page faults will use these to protect against races with page table reclamation. This could always be handled by disabling local IRQs as the fast GUP code does; however speculative page faults do not need to protect against races with THP page splitting, so a weaker rcu read lock is sufficient in the MMU_GATHER_RCU_TABLE_FREE case. Signed-off-by: Michel Lespinasse --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 8258ff93a055..b28047765de7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2566,6 +2566,28 @@ int apply_to_existing_page_range(struct mm_struct *mm, unsigned long addr, } EXPORT_SYMBOL_GPL(apply_to_existing_page_range); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + +/* + * speculative_page_walk_begin() ... speculative_page_walk_end() protects + * against races with page table reclamation. + * + * This is similar to what fast GUP does, but fast GUP also needs to + * protect against races with THP page splitting, so it always needs + * to disable interrupts. + * Speculative page faults only need to protect against page table reclamation, + * so rcu_read_lock() is sufficient in the MMU_GATHER_RCU_TABLE_FREE case. + */ +#ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE +#define speculative_page_walk_begin() rcu_read_lock() +#define speculative_page_walk_end() rcu_read_unlock() +#else +#define speculative_page_walk_begin() local_irq_disable() +#define speculative_page_walk_end() local_irq_enable() +#endif + +#endif /* CONFIG_SPECULATIVE_PAGE_FAULT */ + /* * handle_pte_fault chooses page fault handler according to an entry which was * read non-atomically. Before making any commitment, on those architectures -- 2.20.1