From patchwork Mon Jul 18 12:02:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12921682 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 9EDC1CCA481 for ; Mon, 18 Jul 2022 19:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D76BA6B0074; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFE986B0078; 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 BA77C6B0075; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 95C1F6B0075 for ; Mon, 18 Jul 2022 15:37:10 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6EFB6208B0 for ; Mon, 18 Jul 2022 19:37:10 +0000 (UTC) X-FDA: 79701229020.27.6B78DF0 Received: from relay3.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by imf08.hostedemail.com (Postfix) with ESMTP id 0E14616005D for ; Mon, 18 Jul 2022 19:37:09 +0000 (UTC) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 121C234EC3 for ; Mon, 18 Jul 2022 19:37:08 +0000 (UTC) X-FDA: 79701228978.17.7B59532 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 976354005E for ; Mon, 18 Jul 2022 19:37:08 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id x21so9962412plb.3 for ; Mon, 18 Jul 2022 12:37:08 -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=2Q49j7ZnjpJbe7tnNHIQw9SAVjFrSuB+lmoi9+DDawg=; b=bmUPVvdzZ44bZXvMXaJebmRi8Em4oQjsNDUw0UeAiKmw4D56qcZbcTGB0JlqUCsblt OEV1P1bs52wmG0gm8jY3wqSSUBITQIxayVYMmqk0JsmL+4pXoNVZ2FH1OsJW8kiZmEr5 o7V/37GKM2yOHpp0l6kahMySGW2vJQoZxf4VUu7MLfRdvtcC2k5ObYDHuP/XNyCSsW5v F/svHC9579Af/qJy3HoEVjxdNA4i/N87zD/iGJjAednCkdcRy5LqlQH1N6K6bzUuXkKo O+nHVRq37bCF+vMHywbE4q/ySw3g4zg984mjk3Zd66z+yPz9kQc8fmRVgs/2ZAhpyHge Nzfg== 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=2Q49j7ZnjpJbe7tnNHIQw9SAVjFrSuB+lmoi9+DDawg=; b=XQ6D7KBEccTRZG0A5cPQmLVEeY095wUTdEHKoxrCcg5Z9KpzDfnAKDOm09w9Sm1pOP bPN1NzWxms2G17C8BGGJdb1Hfx9pGmyXejfsbkN8IksQAZJM4WdeJ5wt+Om0gqde7ZDB b5z2BAHARzRwQ8st1/e/+7k7PWTExeeVm73oY72xdTjJNJwnvmMRuamW1aWUkR6sL0g8 zxN89eizYS4vGGsQMWA4TPK8F045fjF+h3w3GUtjf6jaRBiJ7J/38ZLYorgX48om+HG4 thw65vfaOrVWM5wg/q7amYUdO8gFf8KezZUkB75hYZ2xgza5FaA7EA9aUue1sL6mMkJw c00Q== X-Gm-Message-State: AJIora/KIuJMg8uv6jfRGcVTV34aZMpU6L/16SbvyjO03TqhJmx9wxVH rQfylhJXtp/UOie7XQ2JL1tlFyoQPdDugg== X-Google-Smtp-Source: AGRyM1tTWf0SQi53/iAko8YuS1u16C/ViaTRcBXow+cR8M+MN0AQg8swqeSra7RTo6Z8gZakiBjToQ== X-Received: by 2002:a17:90a:d195:b0:1ef:8eb2:4f4d with SMTP id fu21-20020a17090ad19500b001ef8eb24f4dmr39367516pjb.104.1658173027111; Mon, 18 Jul 2022 12:37:07 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:37:06 -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 03/14] mm/mprotect: allow exclusive anon pages to be writable Date: Mon, 18 Jul 2022 05:02:01 -0700 Message-Id: <20220718120212.3180-4-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658173030; 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=2Q49j7ZnjpJbe7tnNHIQw9SAVjFrSuB+lmoi9+DDawg=; b=TIWAfZtIdhTOciZJHvYUmG9PYg85RtNxSzt5NZ73gSHRjERbZDor5kRQyOAVo3FcJHZVg4 yDQcJfpDTDCaO0PQF48vUnTp8OSgq9HcA2Vd1rocSRh5FVOFsALbZgLH62F7gPfew87ifO LfZIQXZbx8s4Xz4kpv5QtZOSGNErEJc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658173030; a=rsa-sha256; cv=none; b=JsywnCUKaKGOalR8D0vWsvzhXk0TvBOgsDRv2cQACyMCZ/vNj0Gtl8mOOcBf2UEiKK/Klv 4p9aKXDeOE3ecluDjZ8yAxFBFU5Yl07lmRRPscLJo7Af5gQtiD7iTYPMIVnzCnnQHlWES8 pXlugIhm/XtuzFtp7yF8b8HZtRGSCZA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bmUPVvdz; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf08.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.13) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-Rspamd-Server: rspam10 X-Stat-Signature: o65rifqfj14paw46bwfpt5jgy4qsuht7 X-Rspam-User: X-Rspamd-Queue-Id: 0E14616005D X-HE-Tag-Orig: 1658173028-844299 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bmUPVvdz; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf08.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.13) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-HE-Tag: 1658173029-858071 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 Anonymous pages might have the dirty bit clear, but this should not prevent mprotect from making them writable if they are exclusive. Therefore, skip the test whether the page is dirty in this case. 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 --- mm/mprotect.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index 34c2dfb68c42..da5b9bf8204f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -45,7 +45,7 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, VM_BUG_ON(!(vma->vm_flags & VM_WRITE) || pte_write(pte)); - if (pte_protnone(pte) || !pte_dirty(pte)) + if (pte_protnone(pte)) return false; /* Do we need write faults for softdirty tracking? */ @@ -66,7 +66,8 @@ static inline bool can_change_pte_writable(struct vm_area_struct *vma, page = vm_normal_page(vma, addr, pte); if (!page || !PageAnon(page) || !PageAnonExclusive(page)) return false; - } + } else if (!pte_dirty(pte)) + return false; return true; }