Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp426433rdb; Mon, 29 Jan 2024 06:39:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoJZZEbi/Z1xka8fa+Ikks83FtdrvvBbKtgC6hiUBFV6anN2K4o8gl6S6fHx4qHFgpsgxc X-Received: by 2002:a17:902:6506:b0:1d8:ce7d:623b with SMTP id b6-20020a170902650600b001d8ce7d623bmr2065934plk.23.1706539157976; Mon, 29 Jan 2024 06:39:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706539157; cv=pass; d=google.com; s=arc-20160816; b=YW93Gmx8ITQqCwP3vQx29k32gHtp/fk1o874htb8iqHRa8KEccWRxU/wUdups8GN2J ZFY5QhMz71x1gu3RhFNI3YI/kWPYBamat43brzHb4wP/5lGe0p8JIGCtLEMdD6hyY3Bl KmLO1CJ/XFy3984UumsxKQ+irvgCe7YnG6Y7E0DrMt5204jG4NE6aHfByxtlro+zPZBj 6xN92Vxdzm9azuo7orBLnS2Dz5blRYgxFP17h0iyPnL0VpsFjhmca1C/2dWpB+1n0qWr JU87U0v9ECNBCKppAEWQl95/evulbeTp3jpglR3YB966dGuXBJqBAKbcY/Uk8/Qk5SG8 aNlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FNlnKqTU8a/1Fu37QrFx8MEnv7tH60nNAECNkKLkAAs=; fh=18RVDvllJ6L23pprpg+CRg5YQHffBN1k78GW6gBbnXE=; b=dpGzNgTeSYdwZufDQ9o1UQV2LbPTi9qG1XTnxC51snDgvnKiCg0TSkQSBQ0VaqIVgf +UlmxHYq/dvWdiLQDooU6V3aC7WLNMwNx8EAjHCd6UHDUx6JneCb9LP+g9s38kUDZREV UgzPB1aA86eNFM9Xve6z0a3acYfFlDUmDfZ2bnLYk2Xr0ICuQhoaR+LjBxibvxyN/OBT zTrwKcPU5d406NnEhgBkJ4NmdygU0lbzfprfJU3T94ii8p8H1DNYFGZsbkvdPXn9owXa RC2tjY/rzWTqUbxsFR1tkY80whU8VT5WAssBhvSE1NTL1jBwX4WnccW5XMz1WJsPGaAt envw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dlZY9/hn"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-42913-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f11-20020a170902ce8b00b001d756c3c469si5917837plg.308.2024.01.29.06.39.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:39:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42913-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dlZY9/hn"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-42913-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AC8EB289762 for ; Mon, 29 Jan 2024 14:33:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3F7E153BD1; Mon, 29 Jan 2024 14:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dlZY9/hn" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5516F152E05 for ; Mon, 29 Jan 2024 14:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706538770; cv=none; b=uNN/IHQMgue9pObq6G85E9ahpNLVOo7/ZYGuTNDzv20eYSUvTW0B3YwmXnQpm1On2FHFi6QM3IkzP7mGWWP7dAznaib6WzTqgnmrVxrzDOoUQypgqiQDf+eI19FUbj2MUA2G4CkSSjAWl9KFWQyci+AAcjoo5eu8cCeKcBhhD10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706538770; c=relaxed/simple; bh=ox+eQ1EXoBSzOjUFapo41STtCich4R5P1O+bP48vyb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sC2Y0okHHLrFcQlR++y4hTtXNIA0uVhV2EOre5byGzchBIvZd2/o5kRydgDBHBv+rH4UDEi4pdObq+bKdwUu86Bsy4xa/wtuP5bZULCdsalvmPtYUEyBnIWdD3b5LN6lhDNeRAD9/GACVuVS+NXvSr9yKeYcMlCosDd+07u5u1c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dlZY9/hn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706538768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FNlnKqTU8a/1Fu37QrFx8MEnv7tH60nNAECNkKLkAAs=; b=dlZY9/hnjnZceAb2FjAWaLhBT4yWwN+Wz8A0qXGMWmqrggv9tA11IJBDCMh9KI/3ggtaST +21nqDue6snZJA0b4cMG0NQOR7UADOoPtZmDIFNvnAkYf9CqdM+cXGSPWr+ZGJsHM4lOP6 q7f8FN53sj4/2EfVpvqFC4ujRUkCGWk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-unK-9W-5NjSJSLj6qcQ8jg-1; Mon, 29 Jan 2024 09:32:41 -0500 X-MC-Unique: unK-9W-5NjSJSLj6qcQ8jg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 902141C05137; Mon, 29 Jan 2024 14:32:37 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20796AD1; Mon, 29 Jan 2024 14:32:32 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Ryan Roberts , Catalin Marinas , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: [PATCH v1 2/9] mm/memory: handle !page case in zap_present_pte() separately Date: Mon, 29 Jan 2024 15:32:14 +0100 Message-ID: <20240129143221.263763-3-david@redhat.com> In-Reply-To: <20240129143221.263763-1-david@redhat.com> References: <20240129143221.263763-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 We don't need uptodate accessed/dirty bits, so in theory we could replace ptep_get_and_clear_full() by an optimized ptep_clear_full() function. Let's rely on the provided pte. Further, there is no scenario where we would have to insert uffd-wp markers when zapping something that is not a normal page (i.e., zeropage). Add a sanity check to make sure this remains true. should_zap_folio() no longer has to handle NULL pointers. This change replaces 2/3 "!page/!folio" checks by a single "!page" one. Signed-off-by: David Hildenbrand --- mm/memory.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 50a6c79c78fc..69502cdc0a7d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1497,10 +1497,6 @@ static inline bool should_zap_folio(struct zap_details *details, if (should_zap_cows(details)) return true; - /* E.g. the caller passes NULL for the case of a zero folio */ - if (!folio) - return true; - /* Otherwise we should only zap non-anon folios */ return !folio_test_anon(folio); } @@ -1543,19 +1539,23 @@ static inline void zap_present_pte(struct mmu_gather *tlb, struct page *page; page = vm_normal_page(vma, addr, ptent); - if (page) - folio = page_folio(page); + if (!page) { + /* We don't need up-to-date accessed/dirty bits. */ + ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); + arch_check_zapped_pte(vma, ptent); + tlb_remove_tlb_entry(tlb, pte, addr); + VM_WARN_ON_ONCE(userfaultfd_wp(vma)); + ksm_might_unmap_zero_page(mm, ptent); + return; + } + folio = page_folio(page); if (unlikely(!should_zap_folio(details, folio))) return; ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); arch_check_zapped_pte(vma, ptent); tlb_remove_tlb_entry(tlb, pte, addr); zap_install_uffd_wp_if_needed(vma, addr, pte, details, ptent); - if (unlikely(!page)) { - ksm_might_unmap_zero_page(mm, ptent); - return; - } if (!folio_test_anon(folio)) { if (pte_dirty(ptent)) { -- 2.43.0