Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1066704lqj; Mon, 3 Jun 2024 09:10:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXi4xaMmP5B4xaii5Hz0W+9iU74Kd9HGaDtvksCpZw1z4htS67tvl2GH1BtB2u2XUhsuX4o0xyj8gm+CWGiPGb58HIDNZnIaesNp/wmPw== X-Google-Smtp-Source: AGHT+IEfQlK6vC5fXPQEUsejab40ITQedeo2pnmLJ3aaxjaStzZhJysAyMeNvj4KFL8Qygnu2HT4 X-Received: by 2002:a05:6e02:1a8c:b0:374:9e46:12a7 with SMTP id e9e14a558f8ab-3749e461521mr38833495ab.30.1717431025143; Mon, 03 Jun 2024 09:10:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717431025; cv=pass; d=google.com; s=arc-20160816; b=OYeRkiHaHOVzmr4jV2iWyNjEdaBkpuXagUVhil76iwLxKyjOBnfzwcB67sI4k+4HrY Cfc931UI4ScKf7BOhb3hipzpdxp7WewsMqIQuLIzGNObywxYV5TSz1/Hpp28kfCi6TWi HnL7RsFeq+6GMyWXwAvqiQWUVX7yk5cpwkvsQ9Ec1gVnl31TEAUPxiFYlIPlF0E+8CvZ sx1oHMMMFcxaxuhub9CKI0M4zl5/lMmVAyMLjGdhtuZ92Zy1nVAehzEQWlOeG6MXP6xn 7XiqkIwx6ml2tZZAkQVFWZbMnkGp1Si/qa9n7duaERCLdR/sM/5f/y88WEe7LJpgadES L1FQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=735D88fEGutt8e5eiGAfKX67pRG7q2pJJnsvh0+1/kY=; fh=Goar9Nq+LvrGlx4dfATq8yqOQ2rBlOw8fDF3cS1v0T4=; b=fOba4MVaK/7kHVwZBMSoIOws05r5km9t0vHVOWWWfVMpj8H9VtwnpUn+6P1lZ4UZRG u85Q/SKVNSJ2F0c7IfvtR/Tc/mD+v2mmuurlwA8KOWIARCum7II+uPlfgQWMdH30QbQc XNjHuogShhfDviDv9nyQDW3QZpbHWCmbUjXPLt2o/qfwSYhGcMTp7qNMTnnWIY+pbMXK QweQVCPGxv1JHRFubOAMs3TObHVWZWfupls6r83KX3TPijzKDoRirF0HI6OVVEeZQiQl mMcac1IR2Vp6+ykgH7Nzo19WfgWcWdfzyvoPgaeIJqEplWMOCXXY1pD7dhHqPzW1bbNY BWWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199414-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199414-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35d59f77dsi6650886a12.824.2024.06.03.09.10.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 09:10:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199414-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-199414-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199414-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E27ABB2318E for ; Mon, 3 Jun 2024 16:07:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2C68134414; Mon, 3 Jun 2024 16:06:37 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5E90812DDAF for ; Mon, 3 Jun 2024 16:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717430797; cv=none; b=kwZUwB36CNQyUvLVU0Ig0spCBRtIf1WIhhwglwKCFkGRgcQTGYr/OvbxkopH4CXhenfmvihKr0e8fL3I+P3TDX9EsqNm1T5a/R57vRtn4axD6QL0ZOn4kKUJmr8PklSTkeYDa5v+goWnIB7vqhTylFNcvzu21pjn7RcehsgGYAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717430797; c=relaxed/simple; bh=0UZs62B0uzeyHX9BtFQPsGHhAg28qGNYuN152C5hu24=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mMTQcUuPoBkaj2agdl1WZvoAXnyc1DnASZmjHvQp5eLcD3gh0txYP/BV6n/T7eRBpWxQSSuhjB67TeoOGS5+v3qYnZ0FkrJQ9QDoGTl04t5QzFyomwFIiOvGpzK7jmeLJFLvua7B44l0OMWXWh3f4ryrUSN8c3xYdRsYODyD9hk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9859DC2BD10; Mon, 3 Jun 2024 16:06:35 +0000 (UTC) Date: Mon, 3 Jun 2024 17:06:33 +0100 From: Catalin Marinas To: Yang Shi Cc: "Christoph Lameter (Ampere)" , will@kernel.org, anshuman.khandual@arm.com, scott@os.amperecomputing.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [v2 PATCH] arm64: mm: force write fault for atomic RMW instructions Message-ID: References: <20240520165636.802268-1-yang@os.amperecomputing.com> <640f8606-2757-4e82-721f-9625d48ded65@gentwo.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, May 23, 2024 at 03:13:23PM -0700, Yang Shi wrote: > On 5/23/24 2:34 PM, Catalin Marinas wrote: > > On Thu, May 23, 2024 at 12:43:34PM -0700, Christoph Lameter (Ampere) wrote: > > > On Thu, 23 May 2024, Catalin Marinas wrote: > > > > > > While this class includes all atomics that currently require write > > > > > > permission, there's some unallocated space in this range and we don't > > > > > > know what future architecture versions may introduce. Unfortunately we > > > > > > need to check each individual atomic op in this class (not sure what the > > > > > > overhead will be). > > > > > > > > > > Can you tell us which bits or pattern is not allocated? Maybe we can exclude > > > > > that from the pattern. > > > > > > > > Yes, it may be easier to exclude those patterns. See the Arm ARM K.a > > > > section C4.1.94.29 (page 791). > > > > > > Hmmm. We could consult an exception table once the pattern matches to reduce > > > the overhead. > > > > Yeah, check the atomic class first and then go into the finer-grained > > details. I think this would reduce the overhead for non-atomic > > instructions. > > If I read the instruction encoding correctly, the unallocated instructions > are decided by the below fields: > > ? - size > ? - VAR > ? - o3 > ? - opc > > To exclude them I think we can do something like: > > if atomic instructions { > ??? if V == 1 > ??????? return false; > ??? if o3 opc == 111x > ??????? return false; > ??? switch VAR { > ??????? 000 > ??????????? check o3 and opc > ??????? 001 > ??????????? check 03 and opc > ??????? 010 > ??????????? check o3 and opc > ??????? 011 > ??????????? check o3 and opc > ??????? default > ??????????? if size != 11 > ??????????????? check o3 and opc > ??? } > } > > So it may take 4 + the possible unallocated combos of o3 and opc branches > for the worst case. I saw 5 different combos for o3 and opc, so 9 branches > for worst cases. Or we have a sorted table of exclusions and do a binary search. Not sure which one is faster. > But if they will be allocated to non-atomic instructions, we have to do > fine-grained decoding, but it may be easier since we can just filter out > those non-atomic instructions? Anyway it depends on how they will be used. > Hopefully this won't happen. Actually, the atomics table has LD64B and LDAPR already which are load instructions, no write permission needed. So we need to exclude these and all the unallocated space in this range. -- Catalin