From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8844CC27C6E for ; Fri, 14 Jun 2024 12:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1WZn7TK/pv/WvKp2wtkXKQR5Vo98n+7t+N1EH/SAKWc=; b=gYywwJuqA+DPSfhzY1kdUi5gd8 lCuofro/dvs05PzWH1wFm7GQXN7pT8YUXhrDfNsjd7a/W4psz2qMRmYVrbsf8DizroEHNbMg7xixj BMlDFcAb95xyPWymQ49zHblfmgGs6iP05WEqYZVF5vOwgIzaIC4Z12h6ZjxHQY1bwQFDo4Mlc0HF0 BarQheREz1lVf6BGhIhdFM8F3/YknjSB9AY3ucKHig7LF9b4Tym4ihY9HJRhZqoqNTwau8fyfexya PY9qObp/AVmQzvTXqaqhQ6mtvw8dqiPHARy160tOwFaqdwbR8YQ/WkjcOKa2sX7rcXIH4mjIRwq9u p9dpPMbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI5v6-00000002j0g-1oCF; Fri, 14 Jun 2024 12:20:40 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI5v3-00000002j06-0raB for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 12:20:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D2E20CE2A01; Fri, 14 Jun 2024 12:20:34 +0000 (UTC) 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240605203723.643329-1-yang@os.amperecomputing.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_052037_445097_5AF3332B X-CRM114-Status: GOOD ( 16.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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