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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FF13C43334 for ; Mon, 25 Jul 2022 13:59:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA536B0072; Mon, 25 Jul 2022 09:59:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8597A6B0073; Mon, 25 Jul 2022 09:59:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FA446B0074; Mon, 25 Jul 2022 09:59:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5ED1E6B0072 for ; Mon, 25 Jul 2022 09:59:25 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 14E1C1604FE for ; Mon, 25 Jul 2022 13:59:25 +0000 (UTC) X-FDA: 79725779490.12.C53C5F8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 48D981000C4 for ; Mon, 25 Jul 2022 13:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658757563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sz4oM0IDHGPEgWtKcSAebAo6SpMhyBqLIAp4XwN/Ogo=; b=HsdVvmXl1aUp8ZBm49bQJjS4WC6IFJVZuPaPZIQyYrrXWf85Ez10DNh9DkSsQiFprm8ozw ygU/0yLb8tr3avJYRMQpLNdGZquRLLtzzIaPYHuoDO4NHX/vfxURiVaAUnho+0nzouIvHn /9E5jZgHiTf1BHUinEY11LoPn9rqUiM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-OYzxyJ3yP5aZEQS-zV7uvw-1; Mon, 25 Jul 2022 09:59:22 -0400 X-MC-Unique: OYzxyJ3yP5aZEQS-zV7uvw-1 Received: by mail-qv1-f72.google.com with SMTP id eq6-20020ad45966000000b0047405c4e6ffso7622756qvb.17 for ; Mon, 25 Jul 2022 06:59:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sz4oM0IDHGPEgWtKcSAebAo6SpMhyBqLIAp4XwN/Ogo=; b=7c4mmQK6/MZNpBKnLafLYXsF9+tOcRWNCtYG0nqYHF2dWecciP3czesAcuweObkqQ8 ppgU6myreBCKWLJp9QtEMR9cU1oR2StV2r2IIroUNbiyh+yywjkQ0d6v8vtxF8Z8/gkk UzMfTAj36kuWbs6LCwC9mXs0PmqFMX0En+Kyx3NU8+k3WMiCvO74ponC3eqGoy0UF6CA ezkj8CHvJ9E/44/es9E0UAySfAYElnvNhrQIz98qXcWRWJxILYpAhlgIZhgvMwVc/I/V QjARF0QUwGCZUPC9LldKbKSRhnTVmEbB/TAftBmDJwvpPcCwFH8tg6Y+zELYd7GSQZoe 8gyw== X-Gm-Message-State: AJIora8zTOPbAj1UTVlvFnJ/HoSpdOM7sGwbGt3Jji6JaTtEelnpAxxz 0Rz0HWs7lJMeTiDKvxVYSq2urG2V4sXbJO+eULVL0PCXBhefX6JGDeWK6uoKWTMvJ3t1+o09WYM OL4+EgFQWC5A= X-Received: by 2002:ac8:7e88:0:b0:31f:a54:c7c5 with SMTP id w8-20020ac87e88000000b0031f0a54c7c5mr10329559qtj.369.1658757561170; Mon, 25 Jul 2022 06:59:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sqSk4wFBDTtDsDvBWgWV1uumgTmnmG9ZtHQFKK8dfX4AsbLrchd50lM/ykeGmiZTJ7tb/P0w== X-Received: by 2002:ac8:7e88:0:b0:31f:a54:c7c5 with SMTP id w8-20020ac87e88000000b0031f0a54c7c5mr10329531qtj.369.1658757560726; Mon, 25 Jul 2022 06:59:20 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id h22-20020ac87156000000b0031ef622a6a2sm7282097qtp.17.2022.07.25.06.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 06:59:19 -0700 (PDT) Date: Mon, 25 Jul 2022 09:59:18 -0400 From: Peter Xu To: Nadav Amit Cc: David Hildenbrand , LKML , Linux MM , Andrew Morton , Andrea Arcangeli Subject: Re: [PATCH v3 1/3] mm/mprotect: Fix soft-dirty check in can_change_pte_writable() Message-ID: References: <20220721183338.27871-1-peterx@redhat.com> <20220721183338.27871-2-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658757564; a=rsa-sha256; cv=none; b=pjH+LW/KecWkukMYVyXbcweCPZ+TFhWL8Uq9HWhyrz1T4tYLrWMBRXF64xuaWXJErRMv5/ yOCWDH86XLLfnqRm4yeGFvzEezoaEjZ3kotKSzczvmD9uFsgT0YXCeoEqOpLZaSeExbLLS r7/Lzsh5WpOvLcbHwZAYT/aKp8BnN6w= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HsdVvmXl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf14.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658757564; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sz4oM0IDHGPEgWtKcSAebAo6SpMhyBqLIAp4XwN/Ogo=; b=LiyblWkWFxMLm7MBpb10aE0XgGWrZs8u+dH8Wgu7LX64K6r5kJEOrxKQO/I0LFQJWnU37p l/DNRQ9JxyjX7qFbl7V+749VgtRlZiBqbLIAoMVe3t5nxyqUk0VBMbjdFr7PK2t7Ps23Ro A1NSAAPines8wXDRhZoD49iq72DT1ek= X-Stat-Signature: fuwhrhap9ri1r165u7mtkxdfjqhrfnn9 X-Rspamd-Queue-Id: 48D981000C4 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HsdVvmXl; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf14.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam07 X-HE-Tag: 1658757564-936579 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 Fri, Jul 22, 2022 at 10:21:00AM -0700, Nadav Amit wrote: > On Jul 22, 2022, at 12:08 AM, David Hildenbrand wrote: > > >> +static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma) > >> +{ > >> + /* > >> + * NOTE: we must check this before VM_SOFTDIRTY on soft-dirty > >> + * enablements, because when without soft-dirty being compiled in, > >> + * VM_SOFTDIRTY is defined as 0x0, then !(vm_flags & VM_SOFTDIRTY) > >> + * will be constantly true. > >> + */ > >> + if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) > >> + return false; > >> + > >> + /* > >> + * Soft-dirty is kind of special: its tracking is enabled when the > >> + * vma flags not set. > >> + */ > >> + return !(vma->vm_flags & VM_SOFTDIRTY); > >> +} > > > > That will come in handy in other patches I'm cooking. > > clear_refs_write() also comes to mind as well (for consistency; I see no > correctness or performance issue). I explicitly didn't touch that because current code is better.. mas_for_each(&mas, vma, ULONG_MAX) { if (!(vma->vm_flags & VM_SOFTDIRTY)) continue; vma->vm_flags &= ~VM_SOFTDIRTY; vma_set_page_prot(vma); } It means when !CONFIG_MEM_SOFT_DIRTY the "if" will always be true and all vma will be jumped. If replaced with vma_soft_dirty_enabled() it'll be instead constantly false returned. We'll redo vma_set_page_prot() even if unnecessary. Here if we want to add the "CONFIG_MEM_SOFT_DIRTY" into equation it can be: diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f8cd58846a28..ab6f2913b5a5 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1290,6 +1290,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf, } if (type == CLEAR_REFS_SOFT_DIRTY) { + if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) + goto out_unlock; mas_for_each(&mas, vma, ULONG_MAX) { if (!(vma->vm_flags & VM_SOFTDIRTY)) continue; Or even at the entrance to not take the mm sem. But it's not anything important IMHO, so if no one asking for that I'll just leave it be. Thanks, -- Peter Xu