From mboxrd@z Thu Jan 1 00:00:00 1970 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 2594E14F9DA; Thu, 22 Aug 2024 10:19:58 +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=1724321999; cv=none; b=l2YRJ95h3hknl/aJqDCA2EhBlIJ9bw4MY9qyB13uPCVCCMfFcAf0IY35PS4rPq6UW2J1Ld+RYvw5iOY3ZOjTKm5fU1HPlnGE6YYJ8LUTjSTJ4IJ5xNtS9fix6fgT24khryNaFmOIHN5GLE0VPshstDwEiJrok1M25GI5GYUk0zk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724321999; c=relaxed/simple; bh=EKZr39InrxJs348PMtmf9ETHw+B/7T2Vh8xHcpRmmoQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XJZSsnJ3imtC3alLBS6o1YozqRtyUrPTf6wnmua0z6lN/VOmmqFu2EBK68UL8CUm2UXiBto6OdhzO0AqSWDHJ/kukZjpWUDPEft9rlx59KlIhE6gnmg1e3/NMaopZZXoQrrc7+D1icKc4WpqSblmH7b7+abtFJ4TCw+/NAcDcro= 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 EEBE0C32782; Thu, 22 Aug 2024 10:19:52 +0000 (UTC) Date: Thu, 22 Aug 2024 11:19:50 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , Yury Khrustalev , Wilco Dijkstra , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v11 14/39] arm64/mm: Map pages for guarded control stack Message-ID: References: <20240822-arm64-gcs-v11-0-41b81947ecb5@kernel.org> <20240822-arm64-gcs-v11-14-41b81947ecb5@kernel.org> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240822-arm64-gcs-v11-14-41b81947ecb5@kernel.org> On Thu, Aug 22, 2024 at 02:15:17AM +0100, Mark Brown wrote: > diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h > index c21849ffdd88..37dfd2882f04 100644 > --- a/arch/arm64/include/asm/mman.h > +++ b/arch/arm64/include/asm/mman.h > @@ -61,6 +61,15 @@ static inline bool arch_validate_flags(unsigned long vm_flags) > return false; > } > > + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { > + /* An executable GCS isn't a good idea. */ > + if (vm_flags & VM_EXEC) > + return false; Later we should look at clear VM_MAYEXEC in the core code (if the x86 folk agree). > + > + /* The memory management core should prevent this */ > + VM_WARN_ON(vm_flags & VM_SHARED); > + } > + > return true; > > } > diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c > index 642bdf908b22..3ed63fc8cd0a 100644 > --- a/arch/arm64/mm/mmap.c > +++ b/arch/arm64/mm/mmap.c > @@ -83,9 +83,17 @@ arch_initcall(adjust_protection_map); > > pgprot_t vm_get_page_prot(unsigned long vm_flags) > { > - pteval_t prot = pgprot_val(protection_map[vm_flags & > + pteval_t prot; > + > + /* Short circuit GCS to avoid bloating the table. */ > + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { > + prot = _PAGE_GCS_RO; > + } else { > + prot = pgprot_val(protection_map[vm_flags & > (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]); > + } > > + /* VM_ARM64_BTI on a GCS is rejected in arch_validate_flags() */ Not anymore. > if (vm_flags & VM_ARM64_BTI) > prot |= PTE_GP; Other than the comment above, it looks good. Reviewed-by: Catalin Marinas 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 F3133C3DA4A for ; Thu, 22 Aug 2024 10:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iewnCoh9wdiv1oMp2c/JsMrF2dYhcxLiMUvd1pvTGv4=; b=l6z/5wV+xKnkpj 9qi+LPqMkcZaWV/d/E/B2Mqy44YDMCaD0DAntD5oqCk/4v4TorGfGW182dUcKgaI4lF323wNwK2Wz vPY4Y8XOEBXVo97i+yqcfLAKLvtx7jWyP6+BO+X3zkzAE3ISmqyROP9q3ZNStTWbLF1Cyte3mSK82 QyqdfVsmRd7zT2DO7ESS71j/IKNORyuEIFpBtYRszB9oIERwdZh/LugfHlqCy5opAVUv1FbEuXJ8X 2yl5V7YYbsBInw0vI/GJZfvMD683y+9K3ZXr2H7fgujowoo3HAzH1qUTXvoT+AjzkHBXz2HRNcOez LrhLnbMqNDOxF3p+eu9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh50S-0000000CQMX-1Lb9; Thu, 22 Aug 2024 10:25:28 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh4v9-0000000CP1I-24yg; Thu, 22 Aug 2024 10:20:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E27FA60FF3; Thu, 22 Aug 2024 10:19:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEBE0C32782; Thu, 22 Aug 2024 10:19:52 +0000 (UTC) Date: Thu, 22 Aug 2024 11:19:50 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , Yury Khrustalev , Wilco Dijkstra , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v11 14/39] arm64/mm: Map pages for guarded control stack Message-ID: References: <20240822-arm64-gcs-v11-0-41b81947ecb5@kernel.org> <20240822-arm64-gcs-v11-14-41b81947ecb5@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240822-arm64-gcs-v11-14-41b81947ecb5@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_031959_597898_5C22B139 X-CRM114-Status: GOOD ( 16.60 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Aug 22, 2024 at 02:15:17AM +0100, Mark Brown wrote: > diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h > index c21849ffdd88..37dfd2882f04 100644 > --- a/arch/arm64/include/asm/mman.h > +++ b/arch/arm64/include/asm/mman.h > @@ -61,6 +61,15 @@ static inline bool arch_validate_flags(unsigned long vm_flags) > return false; > } > > + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { > + /* An executable GCS isn't a good idea. */ > + if (vm_flags & VM_EXEC) > + return false; Later we should look at clear VM_MAYEXEC in the core code (if the x86 folk agree). > + > + /* The memory management core should prevent this */ > + VM_WARN_ON(vm_flags & VM_SHARED); > + } > + > return true; > > } > diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c > index 642bdf908b22..3ed63fc8cd0a 100644 > --- a/arch/arm64/mm/mmap.c > +++ b/arch/arm64/mm/mmap.c > @@ -83,9 +83,17 @@ arch_initcall(adjust_protection_map); > > pgprot_t vm_get_page_prot(unsigned long vm_flags) > { > - pteval_t prot = pgprot_val(protection_map[vm_flags & > + pteval_t prot; > + > + /* Short circuit GCS to avoid bloating the table. */ > + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { > + prot = _PAGE_GCS_RO; > + } else { > + prot = pgprot_val(protection_map[vm_flags & > (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]); > + } > > + /* VM_ARM64_BTI on a GCS is rejected in arch_validate_flags() */ Not anymore. > if (vm_flags & VM_ARM64_BTI) > prot |= PTE_GP; Other than the comment above, it looks good. Reviewed-by: Catalin Marinas _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv