Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp913081lqo; Wed, 8 May 2024 21:24:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZ9hi28+GOkYgekSXPPQ0m5eqZOQZ5rRmOmxZvdlq6I7+JYD9gWOO2Ne9mDacmFCLY0d9e5mCmmOann/X7eDz3E+0brV595lbqJj6MNQ== X-Google-Smtp-Source: AGHT+IHjm0UuXV50eFyV5UsFQ73O5R0g4hl35bLLW1kOvzjfWIbHI6dCMCsOW/n2N/Uvp6A8414z X-Received: by 2002:a05:6358:949d:b0:18a:78ad:2ee4 with SMTP id e5c5f4694b2df-192d2e41fe3mr567339655d.12.1715228647829; Wed, 08 May 2024 21:24:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715228647; cv=pass; d=google.com; s=arc-20160816; b=nuyokFFZR4ZciKEbBA/vF8p1tgkTea4cGyWH+PF+zFOkPBjTSDrwc8QfbVwUNksYfc jNRisCFbK/g60xqajbYTErwjtObdOH5QLeiJxyf+pbupRTIahOX6REe9J9kasN0dhHw+ clsNjJXwfajFaCOt0NTVZQ7EmwwLMwtPP7tVoBraSSQjuj4kLzW2HBfR5dXN9PIeZpZo 53wZPC+PAvK4TkWcsWAy/cjDkQvAL6ZdOz9oWyZQR51Z3aq26sfS2kZFHlK4GGqUbpyd c1RytbWg07zQ4cIwpuh237jk4oXsf3sr+T/wASPEHO9Ug4AGIJwRgNbgBkNtq2/vI38X Gmqg== 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=WA7MFBaq3UqOZLgGks2LxVoPabHBCsWWxJqSo3IXqIk=; fh=YV1rMzs38IwA4X7jf0fvgi9D/AXSZKi3eMkrVLIAsYc=; b=Xytk4HqO+LoSNNEavfHVhTjWUC8YQGoCuhIXepuezcMq+adrIw7CmIAzH6/QflZc18 tHpkmN6qkF8u7f7lxseP1VewqMp1+Y9CXavvx91OAm+8fAYC4+hCLHj09X81yirV6ihF f2YEOp0Y3rDq+YOnU/533s4f/t6PI6DQEu1xcFYUHFCTqcESCWvN4RotJ94Ks1t61Tit tdgVzJni3x72aSkHuNyXTgpD8WLoUwFbQrY7O9R0e3t0gRPf1GLozkRfXZOigjfy6uKa Q1POO2tSjI/XS9VkdrBXhsv+FM8vmfSmQGEwA8FCUfjlQPSVCzzeMyVZb63brNEV35ai pwHA==; 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-174121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174121-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d7295csi559048a12.848.2024.05.08.21.24.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 21:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-174121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174121-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 E2A23282EDC for ; Thu, 9 May 2024 04:24:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDE521487C3; Thu, 9 May 2024 04:24:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 481C71487C7 for ; Thu, 9 May 2024 04:23:59 +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=1715228642; cv=none; b=dZnHaWOwkNrGu6TqaCaYzVEGwRnHIRPuFthYowsI0Zvi+snsUKb/u8fd3PerFqmENg40lVOMYS+yyjUF7l+UEs2kXaqlHw2HZUwwMmuMgDwdDuWxN5ZQqqP+dy22ixQocVJQJrxhg6xbby6SaOtlvuyQOyqdqqM+s6iEhCugggE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715228642; c=relaxed/simple; bh=vHLv/5Bi0v1adLKSRnjB3dDVr6pKB8384v9uj8v0KsY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qz2BxkeaEHr9187nV7zfDHpM3/bKwk4WD4PrxNoYLdEgdOQVwYa42WqqOJDDlLrFPkZVPZoH7NGynpGf7w2tjJ/Nbdnv7U+WjYLtvor5XtS2GBPZi6lF4Cpg61E+Nq3b2JnNIXDYqDE9y+RfTGmExUrB1aanXi+bkkHP79SUarE= 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 EEBD3106F; Wed, 8 May 2024 21:24:23 -0700 (PDT) Received: from [10.163.37.187] (unknown [10.163.37.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2E1E93F6A8; Wed, 8 May 2024 21:23:54 -0700 (PDT) Message-ID: Date: Thu, 9 May 2024 09:53:58 +0530 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] arm64: mm: force write fault for atomic RMW instructions Content-Language: en-US To: "Christoph Lameter (Ampere)" Cc: Yang Shi , catalin.marinas@arm.com, will@kernel.org, scott@os.amperecomputing.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20240507223558.3039562-1-yang@os.amperecomputing.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/8/24 22:45, Christoph Lameter (Ampere) wrote: > On Wed, 8 May 2024, Anshuman Khandual wrote: > >>> The atomic RMW instructions, for example, ldadd, actually does load + >>> add + store in one instruction, it may trigger two page faults, the >>> first fault is a read fault, the second fault is a write fault. >> >> It may or it will definitely create two consecutive page faults. What >> if the second write fault never came about. In that case an writable >> page table entry would be created unnecessarily (or even wrongfully), >> thus breaking the CoW. > > An atomic RMV will always perform a write? If there is a read fault then write fault will follow. Alright, but the wording above in the commit message is bit misleading. > >>> Some applications use atomic RMW instructions to populate memory, for >>> example, openjdk uses atomic-add-0 to do pretouch (populate heap memory >> >> But why cannot normal store operation is sufficient for pre-touching >> the heap memory, why read-modify-write (RMW) is required instead ? > > Sure a regular write operation is sufficient but you would have to modify existing applications to get that done. x86 does not do a read fault on atomics so we have an issue htere. Understood, although not being able to change an application to optimize might not be a compelling argument on its own, but treating such atomic operations differently in page fault path for improved performance sounds feasible. But will probably let others weigh in on this and possible need for parity with x86 behaviour. > >> If the memory address has some valid data, it must have already reached there >> via a previous write access, which would have caused initial CoW transition ? >> If the memory address has no valid data to begin with, why even use RMW ? > > Because the application can reasonably assume that all uninitialized data is zero and therefore it is not necessary to have a prior write access. Alright, but again I wonder why an atomic operation is required to init or pre-touch uninitialized data, some how it does not make sense unless there is some more context here. > >>> Some other architectures also have code inspection in page fault path, >>> for example, SPARC and x86. >> >> Okay, I was about to ask, but is not calling get_user() for all data >> read page faults increase the cost for a hot code path in general for >> some potential savings for a very specific use case. Not sure if that >> is worth the trade-off. > > The instruction is cache hot since it must be present in the cpu cache for the fault. So the overhead is minimal. > But could not a pagefault_disable()-enable() window prevent concurring page faults for the current process thus degrading its performance.