Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp901158lqt; Fri, 7 Jun 2024 02:01:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8CZWm2uOPBoRE+3hVf1zpmuNtIZkGgq6FSY8RVt+GbbEIhS3t5/lVSKPYSOVswXLBVO5fxmJO5NCSkUMenyq8/6u7gb7ijxHx5mpZbA== X-Google-Smtp-Source: AGHT+IHlzp/oJk9huS1ZHcma/GZFYlTXyUDAvd4EPhKjLyLIBkpIfDX5LfSxUONdtWR37rC77aow X-Received: by 2002:a05:6358:7201:b0:196:ecaf:a54e with SMTP id e5c5f4694b2df-19f1ffa8d1bmr228246055d.29.1717750867166; Fri, 07 Jun 2024 02:01:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717750867; cv=pass; d=google.com; s=arc-20160816; b=NtCnIuNwNP8VDcsKn47VeNKnOpEtuVWjkil968FdAHxY8Q2OQO0fLaMt45L8Lbgo0x XbS7b+HYLfnhobaS+LTOveUzkq3P7LZMm+LzJ/sxfgDaJ+oWuAvVUxzsa3rzCN/PcjP0 3hh/hYxocwTSTZB/kA5ibGFWSerQNOaBLrb4JkMN4YlzkSEEwNdhMa8P0opWxSewltJZ EM+1p3LNamzETzoqTUa/SeS81SCo0OSHERdZyuOHE1XUTWcN9rriFIW3vwt9CFLET++W x4maxD8E9BQGxQWeG8Cp1N+Om82/6kIfRV+4a2OwpWRuYHL41H4EClatahBoH4Fm7JdG 9uzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=DBcoLUrX2L9eb2fV5NkylUMV+gvpxQM/JqT0hm0OtKQ=; fh=GKabnec7OI+muYGsjpwEH5wVfQiu0ul7JhZM7xxzV/w=; b=DKDHoV/ky6efpyZBDLbWsDve/8PGDfwhs9jwvWqytek66fgFpvPjxCRwBxcu97NA4f v/IUtRHasF6D+Nmdsq1M20MgIa3R7n9DlRgbgzwQI64LtBwQyUiyV47ae2qsnWcSWap1 7WG29ZkQT1z/sL9zJ5DVhD3v+n8TeG0MMfHkalq6ORXdI9s/RAAuOYoI6ERV6N7LUGj7 eqxVKca36jaPdqL6Y9UP6yXN6QP/0+6Fk8rhU3IHwvm764j0eW9Ame4Pe2XJVlSS9WEa dV5N57bt0pOD/1UdscS+tZImLjcyrXPeIRwoW4PLM6PFwWKpcofiaZGjti5SV1El9M9G RGhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QdoCsf54; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-205658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205658-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44038a6e8c5si15078951cf.31.2024.06.07.02.01.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 02:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QdoCsf54; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-205658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205658-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D81D41C214D1 for ; Fri, 7 Jun 2024 09:01:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 999AA15B13A; Fri, 7 Jun 2024 09:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QdoCsf54" Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D7C31BC23 for ; Fri, 7 Jun 2024 09:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717750853; cv=none; b=J3V06grvIr/WSPF83klBXJaPjqzvzNiCEAjYUYcmsMzxEM1LIUDpyjtW+VQCM6UHYHqm0Jb3sQf9QC7QSc3JPKqiLkPdxeDa/oLSxg5uiqUro9jJSaU7Y+o/IAs4NI3IKx/x5wWwGT8VJsJ+W+1y20RoSK3hhUynM/0SrbWkAtA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717750853; c=relaxed/simple; bh=hbH9FscCbenKyJOliecIL8HXiCKJO1fhxhChk9cPvPQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rAZ+JrSqn2cqBOFoQf7WEPMFpe59Q+PW5kDlx2V9iN0jdtolHJJgRYiWyGjirt5huG4M3Re/TnKbC+cjLpO8HRfvvkLb4Yu4FIATcEYDZtYR7iuQoFm6rlKiuAGGuT4ANwn0UrD7YQz5bwoH6rehUDi3vQoJwvUj9q2r9rt9r5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QdoCsf54; arc=none smtp.client-ip=209.85.221.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-4eb007a9f6fso585857e0c.2 for ; Fri, 07 Jun 2024 02:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717750851; x=1718355651; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DBcoLUrX2L9eb2fV5NkylUMV+gvpxQM/JqT0hm0OtKQ=; b=QdoCsf54zCcbgQ9pL2my7TNT0/jHAqdn6hkGE8x+yG3dzr6TngdKF8Go/1LIToUAzk yz9rMHhkvwZm+7MH5cb7HZMavYqMpGfrR4ZkCHOwiL/Ya0/jECPFq0o3XhSgkrFir1hE C2IEQO2m22GNGNMNB3q415OK6HfUQE7sahL4XIBi6Gq4g71fyRMP9TL1Io9vpHndZZz7 iE5LWaElmULQgOnGQ1+6/WmermRB6GdODZrZHKioU/N3t1n+NVSqq0urs/UyR5fV6Y6Q WtvPkbUdKmi5Ck7L/SUlnD+zbWXRwUifEi2mRYg14ieY8RwuZYa5JvkpyrWnqrUuMtTK QqAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717750851; x=1718355651; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DBcoLUrX2L9eb2fV5NkylUMV+gvpxQM/JqT0hm0OtKQ=; b=AaXs38fEjf9TUvaDbqGLYwwnry8ePOQcCfcev+Vf+7W5d5lx1YMctH9HjA28W1bB4P zbqRKN2MBJeZE3hV6oeVnWy/HYJ29OLd7RLhCNp/QWAw2aZW5Uf9OFVQXwXGtklqnA1t ZlCWDIwATlzFabHWr73v6++EQvRq9k+kh18yYMY05Sot3nWjdGMd93tUhLbTUoabj0e0 8Wu8Y1K8K4G1FYOgLSpsXmUXoaOCBBuedl05GUDtPoPQM6z3sfuvpMvLPRAlLCokgMlH zckjjhk1mw9wZmW4nsGQue3fav6tBOCq5P8MfHzRPZZ1Df/KiwnrODx/xnVVxydzeTia ztqg== X-Forwarded-Encrypted: i=1; AJvYcCVMc2xiZ9wMdRaudZi1GKn/ACnoUCXMopgzk+tAyhctwkkvajJ7eQfOvXyfippvp1b9f4JwEw3XFLQFsDQFzURM09cGpsJAVcsXGa9p X-Gm-Message-State: AOJu0YwMDYjH8nyld5k+UDR4D8wZNkyCmi36LLAk48FTOObcTL+mbeQp irzs7LhMk/fDvMYCIW9QySkC2cNMpqCGyqcquD/eqsVEjX+ZahgBLVYUg4+3fj3kYiC9Xk9MWCp WxuraFDrFfZEcCOyMOsxfBUteups= X-Received: by 2002:ac5:ccad:0:b0:4e4:eb50:fd57 with SMTP id 71dfb90a1353d-4eb562543bdmr2166514e0c.9.1717750850115; Fri, 07 Jun 2024 02:00:50 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240606034016.82559-1-21cnbao@gmail.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Fri, 7 Jun 2024 21:00:38 +1200 Message-ID: Subject: Re: [PATCH] mm: introduce pmd|pte_need_soft_dirty_wp helpers for softdirty write-protect To: David Hildenbrand Cc: akpm@linux-foundation.org, linux-mm@kvack.org, chrisl@kernel.org, kasong@tencent.com, linux-kernel@vger.kernel.org, minchan@kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 7, 2024 at 8:46=E2=80=AFPM David Hildenbrand = wrote: > > On 06.06.24 05:40, Barry Song wrote: > > From: Barry Song > > > > This patch introduces the pte_need_soft_dirty_wp and > > pmd_need_soft_dirty_wp helpers to determine if write protection is > > required for softdirty tracking. This can enhance code readability > > and improve its overall appearance. > > > > These new helpers are utilized in gup, huge_memory, and protect, > > and are particularly applied in do_swap_page() to optimize a > > softdirty scenario where mkwrite can still be performed. > > [...] > > > +static inline bool pmd_need_soft_dirty_wp(struct vm_area_struct *vma, = pmd_t pmd) > > +{ > > + return vma_soft_dirty_enabled(vma) && !pmd_soft_dirty(pmd); > > +} > > + > > +static inline bool pte_need_soft_dirty_wp(struct vm_area_struct *vma, = pte_t pte) > > +{ > > + return vma_soft_dirty_enabled(vma) && !pte_soft_dirty(pte); > > +} > > + > > Should these be "needs" ? I tend to like these names/semantics. yes. "needs" is better. Glad to know you have the common liking for these names. > > > > static inline void vma_iter_config(struct vma_iterator *vmi, > > unsigned long index, unsigned long last) > > { > > diff --git a/mm/memory.c b/mm/memory.c > > index db9130488231..6307c43796aa 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -4322,7 +4322,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > if (!folio_test_ksm(folio) && > > (exclusive || folio_ref_count(folio) =3D=3D 1)) { > > if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma= , pte) && > > - !vma_soft_dirty_enabled(vma)) { > > + !pte_need_soft_dirty_wp(vma, pte)) { > > pte =3D pte_mkwrite(pte, vma); > > I would move that into a separate patch, as it's not a simple conversion. > cool. will separate it in v2. > -- > Cheers, > > David / dhildenb > Thanks Barry