From patchwork Mon Jul 18 12:02:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12921681 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 01874C43334 for ; Mon, 18 Jul 2022 19:37:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 935CF6B0073; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DF966B0074; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 780CD6B0075; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6C11A6B0073 for ; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 416E360A2F for ; Mon, 18 Jul 2022 19:37:10 +0000 (UTC) X-FDA: 79701229020.17.3F39350 Received: from relay3.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by imf19.hostedemail.com (Postfix) with ESMTP id E091C1A0082 for ; Mon, 18 Jul 2022 19:37:09 +0000 (UTC) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6416D34E5C for ; Mon, 18 Jul 2022 19:37:07 +0000 (UTC) X-FDA: 79701228894.29.995F1F2 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf05.hostedemail.com (Postfix) with ESMTP id 0498110006C for ; Mon, 18 Jul 2022 19:37:06 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id s206so11532880pgs.3 for ; Mon, 18 Jul 2022 12:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IufP9Zf+LxI7/ja1tm+EfHoZ34yAqbNH4YNdr2fLKzg=; b=qG3NzQadQYCy4rNcC/00/m1k00Rdnq8ihunEXn9ko/dtWH2HiC/JLZcB0XE3Fmrnme 4uHW7JOvxcluNfpQxgbQVqeUgNSwGxPrf47yeAbr1vPKr2M8T3ojhSwKcIotbVOpuGpC 03vIgXyGqL1xqLnoRk6HZYGbEsfTuBQb3UTilxepLrrh6di54zWWHrvnUwafOcNixDvI mAiMqZJOgnaD3MYRYn1evGphPH12+idguFStTv1WGAkRhN95WV3+4haBwVkVtpdhUTwQ dAycGnGYVMeeHc5jfDHQcsMcyMaz2Yv5VlzLzbDlj5bMe2rXOZ12FUP7+Pdwyzf05Qjg mXxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IufP9Zf+LxI7/ja1tm+EfHoZ34yAqbNH4YNdr2fLKzg=; b=7FJX2ruEifV+H9qgXbmsK5fSIba+10B2XXyDZDbFgsRYxDQUuk+gUUKMKKuntzS/Hv /D6OT53u2ecf4fvaPlIea0cN2Njzr1+i4LSVHM62YdC1j3zEDgi+BLarABPJISwpGc1P dIf3GIsLJREyrqbReakFxAozhKi8vcRWp/dO3x0If/T3P4ghFicf/apGH5LoVSB3vUng Kej3ztZGXiXy0Z5KUqhRD0/HjLQI8y9sn55Nd6lQz3IoF9FYBxyGHmJAJG9DJ4EFZBpm E498afKAqcUPYCeUNLjHQEp0GS099uufcYUlwkgqEUWEIuQPMHHE4JbTfd52rtOEo6M8 pWkA== X-Gm-Message-State: AJIora9lhOCEvD+eq82f4zjdu6QZlbNmiNZMBIdeFq5V/NXxCh9OsK9g S+dvnmcorOQYAOci/Xzw8ziPQxuamrnvWQ== X-Google-Smtp-Source: AGRyM1s4dUG7omvru0Q+c8qc7tyPUfIKb/kzYGzarbIemngP+tEUPjt2ISjbd7jZhK5SI6J3kDZqpg== X-Received: by 2002:a63:504c:0:b0:419:d02e:f42a with SMTP id q12-20020a63504c000000b00419d02ef42amr17915418pgl.566.1658173025597; Mon, 18 Jul 2022 12:37:05 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b0016bc4a6ce28sm9907887plb.98.2022.07.18.12.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:37:05 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport , Axel Rasmussen , Nadav Amit , Andrea Arcangeli , Andrew Cooper , Andy Lutomirski , Dave Hansen , David Hildenbrand , Peter Xu , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin Subject: [RFC PATCH 02/14] userfaultfd: try to map write-unprotected pages Date: Mon, 18 Jul 2022 05:02:00 -0700 Message-Id: <20220718120212.3180-3-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718120212.3180-1-namit@vmware.com> References: <20220718120212.3180-1-namit@vmware.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=qG3NzQad; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf19.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.14) smtp.mailfrom=MAILER-DAEMON@hostedemail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658173029; 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=IufP9Zf+LxI7/ja1tm+EfHoZ34yAqbNH4YNdr2fLKzg=; b=gg4QBsSols5Rgq/RWL3bRH0mWubMRceLN5L6/9iwR4Y9Q67CZ7ToIlsqTc4q3RYFptfEXL vrT331I6U6UH4pxWGRN0OrpMBLJlO1xiYAiKHkRhCcKXznsm61F9L2uIJjZj59kB3XdmXC BC+MNK8ZfFtjUIGamqkzjO6ZJvzxkvE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658173029; a=rsa-sha256; cv=none; b=0t12F7UrxKkCgaFHqQfCPCGEx6/WE0qluaE0nGRBLJYpzkFeIHqI6ZAKzOjldqD64/A/zn c9wjSIjAVNlyJUJ6V5Otb8x1f6OUjm4QRhelKZ3i6RT95mVxFVvgIDtx5Od/jZF8wMDnse 5JVe4C1FgTCAXanJ+ICTpnI0P8/A/W0= X-Rspamd-Queue-Id: E091C1A0082 X-Rspam-User: X-HE-Tag-Orig: 1658173026-465922 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=qG3NzQad; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf19.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.14) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-Rspamd-Server: rspam11 X-Stat-Signature: fm1issdfb8qpdq56etyq5xsu8ia91znn X-HE-Tag: 1658173029-854845 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: From: Nadav Amit When using userfaultfd write-(un)protect ioctl, try to change the PTE to be writable. This would save a page-fault afterwards. Cc: Andrea Arcangeli Cc: Andrew Cooper Cc: Andrew Morton Cc: Andy Lutomirski Cc: Dave Hansen Cc: David Hildenbrand Cc: Peter Xu Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: Yu Zhao Cc: Nick Piggin Signed-off-by: Nadav Amit Acked-by: Peter Xu --- mm/userfaultfd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e0492f5f06a0..6013b217e9f3 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -799,6 +799,8 @@ int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start, cp_flags = enable_wp ? MM_CP_UFFD_WP : MM_CP_UFFD_WP_RESOLVE; if (uffd_flags & (UFFD_FLAGS_ACCESS_LIKELY|UFFD_FLAGS_WRITE_LIKELY)) cp_flags |= MM_CP_WILL_NEED; + if (!enable_wp && (uffd_flags & UFFD_FLAGS_WRITE_LIKELY)) + cp_flags |= MM_CP_TRY_CHANGE_WRITABLE; tlb_gather_mmu(&tlb, dst_mm); change_protection(&tlb, dst_vma, start, start + len, newprot, cp_flags);