Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp769432lqs; Fri, 14 Jun 2024 05:25:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+ObW7DYsvlWoo9W/kvlB1m6D09HH32KmIoQ7uxH+h7CfdngO5o2X9MYWcJEytUwij3e1S47E8L0OEuWoKMPgZXJoOOZvRnYmNHGHpog== X-Google-Smtp-Source: AGHT+IFYwB7p8wJpjcZz1HwDCiF1XYAv16VJ242BcEBrugA1qp7oBrTX554ps4FrWwHXOoqb6wqr X-Received: by 2002:a17:903:98d:b0:1f6:ee40:196b with SMTP id d9443c01a7336-1f8620bf880mr46875835ad.9.1718367917326; Fri, 14 Jun 2024 05:25:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718367917; cv=pass; d=google.com; s=arc-20160816; b=QDiKh62hI+o+ndB04RrL45oLmF4U2CUlAPrkkj3Q90q0ZNI1XpwQO1xVKnZp+uTPHt aqZYdTGmngHFMNIixAmadMSDBHq/zpdLlxE+YLPXzahTeJsKMeO2WOXeafOpzT60wnNc Qix+jVdBObcsF0LDYEjxlCqf7KJOGriOQ2OxhMdLjDl1nrF2MYajY35eMIKJYalQzedM qqBMeoo8bXiEoSoL1W9xP1Kipyz8C3r+ZEHhF2Us/m5bSyGt50cXe3/pSndHIQLCrryy 0eiLOzxmDIIdSItoWntGoJQEs9DyzxhASPkO8Rgfo45YCpojMa8DoDpdsDgbnG8Rc6TU FaAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=1WZn7TK/pv/WvKp2wtkXKQR5Vo98n+7t+N1EH/SAKWc=; fh=JzT/ol0Ox6RyaTPDQZgxdQTwhqWQI6QsAkqhm+cwAfc=; b=ogqx6ZbJvnDox4Su++teXfCATNYsJWQsNsGWMXSB12pJkNGFjkLbkw0EbVEg1OnKPD /H1t0bLyBXE4b/ZkgNM+7jFu42I5xMD13bMbpvysHUcieOiz5zmrJDjGUd8MAIHpEnvd NttcJEGe/m5SfBMOcKQlNnYoEGG24AFUrJS9t5W7fUSPGPwE5QQjfi7q83MyAL4rFfVU 5uAiK563iCm3pugVTJP4FVz6I8gyriwa44LZzpRgKgao6el2hl7MsOAsdBr51KNJn79l Cn7dzf3MB8zE7n6RaUL3miZxM6+Z4otPnAU7f7KzkZ1cs+5AK6KX9J8XQaProih/2Fv4 h5FA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-214885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214885-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. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f855ee368esi34247655ad.395.2024.06.14.05.25.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 05:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-214885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214885-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 03812B23975 for ; Fri, 14 Jun 2024 12:20:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A763B194A77; Fri, 14 Jun 2024 12:20:34 +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 32D65195F03 for ; Fri, 14 Jun 2024 12:20:34 +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=1718367634; cv=none; b=bPwf8lWjemkc98O+PTZ4JDogfKzB0h30tu372/SFTL1o1eO4YQf+iBS39CUnoMAYz5FHN2BN+SAi007CrpGvMR095IpF1rRHDghkdIS9HzZtpCF8Kq+lmWfS5TRYLHUcQhfLSlHUfRvin1NGEdZfhBKvgLIadtgQmrjVdh9ySqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718367634; c=relaxed/simple; bh=rF8IQJXE+F+fPTThN+RuBNY1i5eZMY2Xeb1eGXWtmso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dvKni18TiRunzXDLh1eQOccc4fKMACKUWU939cw/Hm6YC+IPnBIWbJDReHruhE8IH6MJg0gatAF4rdJCmdLJvf+U25BgdFoJFQzcTJxdEB9JvrqFF/6WsSU5MMRzU4sgDHRf7QscmEANAEOEm/dFbuxw2i1XySIgkFIC00w39NM= 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 91235C2BD10; Fri, 14 Jun 2024 12:20:32 +0000 (UTC) Date: Fri, 14 Jun 2024 13:20:30 +0100 From: Catalin Marinas To: Yang Shi Cc: will@kernel.org, anshuman.khandual@arm.com, scott@os.amperecomputing.com, cl@gentwo.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [v4 PATCH] arm64: mm: force write fault for atomic RMW instructions Message-ID: References: <20240605203723.643329-1-yang@os.amperecomputing.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240605203723.643329-1-yang@os.amperecomputing.com> On Wed, Jun 05, 2024 at 01:37:23PM -0700, Yang Shi wrote: > +static __always_inline bool aarch64_insn_is_class_cas(u32 insn) > +{ > + return aarch64_insn_is_cas(insn) || > + aarch64_insn_is_casp(insn); > +} > + > +/* > + * Exclude unallocated atomic instructions and LD64B/LDAPR. > + * The masks and values were generated by using Python sympy module. > + */ > +static __always_inline bool aarch64_atomic_insn_has_wr_perm(u32 insn) > +{ > + return ((insn & 0x3f207c00) == 0x38200000) || > + ((insn & 0x3f208c00) == 0x38200000) || > + ((insn & 0x7fe06c00) == 0x78202000) || > + ((insn & 0xbf204c00) == 0x38200000); > +} This is still pretty opaque if we want to modify it in the future. I guess we could add more tests on top but it would be nice to have a way to re-generate these masks. I'll think about, for now these tests would do. > @@ -511,6 +539,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > unsigned long addr = untagged_addr(far); > struct vm_area_struct *vma; > int si_code; > + bool may_force_write = false; > > if (kprobe_page_fault(regs, esr)) > return 0; > @@ -547,6 +576,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > /* If EPAN is absent then exec implies read */ > if (!alternative_has_cap_unlikely(ARM64_HAS_EPAN)) > vm_flags |= VM_EXEC; > + may_force_write = true; > } > > if (is_ttbr0_addr(addr) && is_el1_permission_fault(addr, esr, regs)) { > @@ -568,6 +598,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, > if (!vma) > goto lock_mmap; > > + if (may_force_write && (vma->vm_flags & VM_WRITE) && > + is_el0_atomic_instr(regs)) { > + vm_flags = VM_WRITE; > + mm_flags |= FAULT_FLAG_WRITE; > + } I think we can get rid of may_force_write and just test (vm_flags & VM_READ). -- Catalin