From patchwork Wed Sep 27 05:25:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13399933 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 6BAF2E80A89 for ; Wed, 27 Sep 2023 05:25:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAE808D007A; Wed, 27 Sep 2023 01:25:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E38D88D0002; Wed, 27 Sep 2023 01:25:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C62148D007A; Wed, 27 Sep 2023 01:25:13 -0400 (EDT) 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 B57CD8D0002 for ; Wed, 27 Sep 2023 01:25:13 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8901DB41EA for ; Wed, 27 Sep 2023 05:25:13 +0000 (UTC) X-FDA: 81281238906.27.7F6DA0A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id EF198120013 for ; Wed, 27 Sep 2023 05:25:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PxqTP9iT; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695792312; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3Yk0vVaBtqAZEgIGaPP794XvY+bzQS0FZH+cnfPYchQ=; b=X+3Yamht8qdqIm72nDvCfUnucr4Wheos2DJNw4Q+4NqtYj+rTz1ePtywZCae8O69w33BZu KYHvs6frM40DA8ssEfOqon8Hx9QlnclX4sYPsckQUWi+49sjrJwsJpYZR5n1f9cKEAw0tg +bONlnypgMJ4kUpyAExSlSdfiWTgpdI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PxqTP9iT; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695792312; a=rsa-sha256; cv=none; b=VNnsqziw1lvXyfKNO/5WKsX2Aol0dqMxQxSHjqykW9EDfL0GkhibXGpwXvf3o+Iwuq490F AJyYFnnCRRbsxEirWVR78b1ontn1SpGxR/Xjmh6UqbqyyFeBshAal+X1xJ3mVH0omZCtA/ NMVCQSIpXfeFjIeFSXnez2JNJ5bpvnU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=3Yk0vVaBtqAZEgIGaPP794XvY+bzQS0FZH+cnfPYchQ=; b=PxqTP9iTybWuc2gw9i0H0Bfmmz Q06CrSXhJl0/Zky87Af85WtzKt/i6dHt1bGBE+62LKdJeQO+PQar+XNkLsGXTIegJgJpgxWuIQjlp fewN8OSDOICNeOiH9ks5kc0COJJh5D36kkLBdacWDH4UaVYXsdi4vcmRXvu4p/3wY+9vJp+v6If6b yV44LiSuJLMFwaJ3EE9Ex61/TJsDj98uOBz5jFVR8ffeeWs0u0h9er+XuZBAoBR+sy2Shavcuh46l lYf97/cXvlahmp3A+CFexkiEbRb3JSuth36xGuxbSbZ08IMD86unZv6Ry35LOhky6TSjL1qNyXpBa dS2fteDw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qlN2o-00Bywu-QP; Wed, 27 Sep 2023 05:25:06 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Suren Baghdasaryan Subject: [PATCH 4/6] mm: Handle COW faults under the VMA lock Date: Wed, 27 Sep 2023 06:25:02 +0100 Message-Id: <20230927052505.2855872-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230927052505.2855872-1-willy@infradead.org> References: <20230927052505.2855872-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EF198120013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hk6bmkqdtetbe8yint5ob5h56f88ouiw X-HE-Tag: 1695792311-904856 X-HE-Meta: U2FsdGVkX18kgA7AAVu6rfcxGLrTCZwqp7dUrjCsy6ACJHY3WeWVi+cNLd/WuqsiDHQR/FLyteGd6LTLHdF/wLt5ahiwBua5I/RMWh6qGXxuZnphG5PrLQtbEvDgxjT0PgJhznJpNZJIR8MT7Jsa0W7vcWlRsWD2s9cWKnUJv/XusI1D8hl4DQB415CaKcBC3S0c5jtcVkU1+S0Z4cOsX0Vh8+RNCfAC6RjNTnu/01bBBT2jH1WiyeVVGZreoQ8DxzXYZNcLi6U2SsDMIVthzdPmagcQflQodYcdKdRGxZNuzKqc52I3IDC7EzHN2i4r7XxqX70hxkcKW5ZxSVdkWkdGMVOI692PTMnnAvzNELjw7b2+vqjwOYozuFhPhO2uTlkibjGNqcu0e+iyjaKhmAge4W+LMrrmxjLOhGZuMdp8aOBplnlho4F8ZJchU4fF3QZbxEnZl7WVEMT8pOqM6BMQ6IiOyJkZ0bFOMWOBmyA9Sc5qvqrE47fDqlVLq85HVYW7V2WHpm7H8yzRLSSjAVFA2X6vjNkV99cMUvKQYSIzYORuJcHxSpi3cTnz/EzCIXsTd+WpZuI2bPIEtPj7/Wn9M6gA2v7oPQh8b6BCLDKnjm9kOqQwynwBKwsfdZS7zWBiA+FWZEjOO4S8ctQDX5qeydN7YYA3Zw6gFDqtMobodIin6tReUGcqXn8u/6+s+jR9MtDyRT74QSv+Kw2ZsoFlGxBu66cHzpcv0hhS5CJbSDCKN+k9CcAnSJCHSR02PQXHFukQ10bkeWSQ27ipF32RpL0U5rggTt0ohuHTtxOUoeFqb4/JAc0hgcUW8s8h35Lmh0mrQMgSeVBlvcWoqA4FyFlstbygjUtEpbed2tvxLMurgvVLt7sW58CmAAYdJ057oXMBNTgJxzvukOtLJUnmg93597A6w2HBeafHB3lM4njDWV2trFdUSnU+4lEM8bfsnL4xqZCEE4hwiQ5 1WH8F78t 8MDMTTn2fjXvjIr76Wvc37MH/0jPohHAZptJ08VoasWBR13W8FrDWBoNkR8ugkh+bLKZRZehWwjTB0G+XnDnpjw4sQ6CsfoJO3ITUfN81LEo9ZkTlWYblCyyss5y5DmGMX+fn3Rjm5369zLjD8fSd4RFswJLCkOJLXSyjrlNWBECQlR/0zcHxI7rVTw== 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: If the page is not currently present in the page tables, we need to call the page fault handler to find out which page we're supposed to COW, so we need to both check that there is already an anon_vma and that the fault handler doesn't need the mmap_lock. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0f3da4889230..02231a9394ed 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4639,13 +4639,11 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; vm_fault_t ret; - if (vmf->flags & FAULT_FLAG_VMA_LOCK) { - vma_end_read(vma); - return VM_FAULT_RETRY; - } - - if (unlikely(anon_vma_prepare(vma))) - return VM_FAULT_OOM; + ret = vmf_maybe_unlock_vma(vmf); + if (!ret) + ret = vmf_anon_prepare(vmf); + if (ret) + return ret; vmf->cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); if (!vmf->cow_page)