Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1454817lqa; Mon, 29 Apr 2024 08:55:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1QRlCnIBqCB8lDyxGLamTCtg/fUEdk77McdXDNlsrocw5bNTXv1gBeS87B1cauAqtS6IdUbWSSM8UhCdYvylkjU1m+JQf18ffejWREg== X-Google-Smtp-Source: AGHT+IFMGlXhlo4djCJ2dsQUyNB4wAGnFyGSY8EEBKsEjsxf06g3odZQ76VI1p8mkXq/ioCnTifX X-Received: by 2002:a05:6e02:18c9:b0:36c:4bcc:8df6 with SMTP id s9-20020a056e0218c900b0036c4bcc8df6mr140758ilu.32.1714406122550; Mon, 29 Apr 2024 08:55:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714406122; cv=pass; d=google.com; s=arc-20160816; b=e9Irxb5pYH6c6tLwQuNnn3M2c/9kdBudEawk9tVzzLPzqiCAdk74+NGhewghxZNCpq xu4OvGTEp8Z435gtv+26DCOMB9NvlrudZtnC5YWmBsoIyxNQ2wzyuHdGM9FFcB0Ku15A PHusTc4XbGyBCyp9FU/kKCahcmOvvKcEBw9u50LsHx49PSK9QeiM21MqwtB34XCeSdAv +kVNMWYuMW+fmO+kYCTHx/XUq+SVa4P1h+HJSV0AxGe3Q6esr3xIk2tDeI1Tt0S0uAJE mdUgC3XPKn6LjoaBXBG/W9uI0qu5L840ATnmqXH8hU5Pro7mK5lXECAiX7we2IvWla/h B0fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=TsADpfM7lHvG9btsdEsS6e9mTqaInqqHFG11cOT5BLk=; fh=dN+VZcCLf/g7IPmyNoufi2JOvBS8b0N34GAxWp6QoxI=; b=N5ZzZwAUntAMP0Klg5ysvp0dgsHWbQGzdix+GfguAN3lrbEQqf7bsKo5w27lTHt/EG 4nd5MUFugOThkIFdMxsl8ZIRaCIh2BB/sDG8zIdT6N9F+ZB8veUgjVPd/sc5Qx1KVBkS /4vHJvmxd8ZSDx07KWonTVTMIm105FLMsdOS0uCRWFyTYmvDQ2f0X4XBV7GUkcvAuU6k PWBVMJk/XNbCnLCWmAdF0YF5kZUrENRKcp9vReN1J3wK6jsfOK78dVnMKBkpqt2+U89g qBLHfyBU465R+h3XNPJf7zgAD1qEKS6SPi0eCZN9QLPWxrJLg58qVguLwNHpN8n8DUQj BzRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-162623-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162623-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p8-20020a637408000000b005fcada7ca61si15431108pgc.8.2024.04.29.08.55.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 08:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162623-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-162623-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162623-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 2D04A280D06 for ; Mon, 29 Apr 2024 15:55:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB8D2839F4; Mon, 29 Apr 2024 15:55:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71ADB81741; Mon, 29 Apr 2024 15:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406113; cv=none; b=Id8vitEhmfzK4z+ODEGZEm8SSlrYUyEJpYOioo+C0mJYOOHrB42XbdKwDiFnUoqZDuMMux0pXl3MOyCRQCrDgzEBkIW9ZVdQqoUcxCyjAzH2uQOl5DGPgtx1O+AoxAH0GHs57w4M7KRoVPUZk9djnl7RkwKn25pqUlvA26uNP24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714406113; c=relaxed/simple; bh=QWhh71QKLkT8KLKHIg0Ia146hwmXeKdOgOf8k75gClg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZyfEuhNvT8CPf5scrYlBG+fKhbmSG14NYbxrXoShbSrAyWvwVNpf4A25uYq89fT2I2WtjLMojK4FEbVDSjx218GUtDRQYktBgRwj+1m8Hg9ovmk4NoWiLFmPPEkVzr1nWgrHByb2YXm8KyNZGiZyHpzq+Zrn/cQJBalnmzD8Bws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5F8352F4; Mon, 29 Apr 2024 08:55:37 -0700 (PDT) Received: from [10.57.65.53] (unknown [10.57.65.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B519B3F73F; Mon, 29 Apr 2024 08:55:09 -0700 (PDT) Message-ID: Date: Mon, 29 Apr 2024 16:55:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] fs/proc/task_mmu: Fix loss of young/dirty bits during pagemap scan Content-Language: en-GB To: Andrew Morton , David Hildenbrand , Muhammad Usama Anjum , Peter Xu Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <20240429114017.182570-1-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: <20240429114017.182570-1-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 29/04/2024 12:40, Ryan Roberts wrote: > make_uffd_wp_pte() was previously doing: > > pte = ptep_get(ptep); > ptep_modify_prot_start(ptep); > pte = pte_mkuffd_wp(pte); > ptep_modify_prot_commit(ptep, pte); > > But if another thread accessed or dirtied the pte between the first 2 > calls, this could lead to loss of that information. Since > ptep_modify_prot_start() gets and clears atomically, the following is > the correct pattern and prevents any possible race. Any access after the > first call would see an invalid pte and cause a fault: > > pte = ptep_modify_prot_start(ptep); > pte = pte_mkuffd_wp(pte); > ptep_modify_prot_commit(ptep, pte); > > Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs") > Signed-off-by: Ryan Roberts I guess this should have cc'ed stable but I forgot to add it. Are you able to fix this up when you take it, Andrew, or do I need to repost? > --- > fs/proc/task_mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 23fbab954c20..af4bc1da0c01 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1825,7 +1825,7 @@ static void make_uffd_wp_pte(struct vm_area_struct *vma, > pte_t old_pte; > > old_pte = ptep_modify_prot_start(vma, addr, pte); > - ptent = pte_mkuffd_wp(ptent); > + ptent = pte_mkuffd_wp(old_pte); > ptep_modify_prot_commit(vma, addr, pte, old_pte, ptent); > } else if (is_swap_pte(ptent)) { > ptent = pte_swp_mkuffd_wp(ptent); > -- > 2.25.1 >