Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp867928lqh; Thu, 28 Mar 2024 21:47:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXV6eV0RKjKe0dXqzs5cY7nMGPz4svgyjLys8xMvXST0nI6BjNNnIA2SpU95K+Evje8bEiU629JxcewlCKiix5qHGIIl4B/3vCMGW3fng== X-Google-Smtp-Source: AGHT+IFQ0J3vXa8m2P9Kt1+HUcMJz9zQ8w8HWaXkQKHd86yUQvBG8kVp8VW+/vbMypggzfZfrxhv X-Received: by 2002:a5d:6d47:0:b0:341:865b:65c9 with SMTP id k7-20020a5d6d47000000b00341865b65c9mr744239wri.22.1711687636090; Thu, 28 Mar 2024 21:47:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711687636; cv=pass; d=google.com; s=arc-20160816; b=fPU84C7eUHiprRRxjhgiSeRUBj89u+8Ahf7N4tTwcbJKsiehr2DTRYqOCXvHBSKb8f /uAqOJ1KZJ9Y5mTQ8NVsic22hHRZxTMhcsrKng+rXE32Q0+8X1fAzBmrEkDF5NgLPHTM f7oOSteBvgHawgKtkEKmSlmXem6WXFipHztzKDAyqj3fVr8RopD22vuhItLOEsjIJoft RQ6+QV0jaGH6kxInwusJB32RzJrOtZDY8UVNMB7zbhvo8w2SbbNTI6ZnUMjziwhDowFA SB8zaKwwh0VOFKS7AThuKrKnNiPRq/Uz5PMjOaq6HQcJJunXbBLj4nX/lbAZ5W5/KdtE 6jvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=T4DMhRzx46RlnO0Cr4Xo2ac2UzARWIzMLM1MQTYcvtg=; fh=VtAVEhaitrHAYsbxYmkd2X6Btgly/3ZThmblpLuRi6w=; b=JdoMJvc3jPY0996E6b3ZplWDx+ONln+UoH1BPpIdbXEFz1OlARy13Au6mRD4VK9Sy3 tPxC351S9Y18Ar4nUEJOjfgNiMf/R4qT0DS2Kkeaybi5zrRjR8oB+LZSafX/1+4bLaIF Pv6KK3u4p14zs3sx6c/QOM05JRNJAWC9W5kyiLTpJKfUftHg86jrsTddCAqhhdrlRDL+ PPC1trxGoH92Dd4UCypQJ8zYC25BtuVLypKTJd03uhHgPR8y+JaruwvaiAGBe5Isyi3S L5bNeaGW8rMj1iTkxL4I56zXT+jrGaMUuaOzZlNHU0WDDaaoVqN1/EFKgB63OH7VgP8J RXwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ni3KCJcR; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-124124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124124-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cm19-20020a170906f59300b00a4720ded97dsi1478961ejd.185.2024.03.28.21.47.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ni3KCJcR; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-124124-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124124-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8EF1E1F21DD3 for ; Fri, 29 Mar 2024 04:47:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B06F03FB02; Fri, 29 Mar 2024 04:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="ni3KCJcR" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B6153B185 for ; Fri, 29 Mar 2024 04:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711687572; cv=none; b=Ls0iuNlFN+aIMeehe23hUFVyiq+98TC73gh/lJmcDnrpH4B1h2r7SIflW+D5B2zyrgJFt+VgtU5kUA2TNssVSIHpl016N75r3gAbOyo8bntoSV/rZa7hIdqVVepDAHRD8XBXXvsCEbJxfitmp57Iburhp6XGDWGLJHoe3MAYE9w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711687572; c=relaxed/simple; bh=cOSTrZrguK0vS2cg25DDGwmYtDVYXdvyWqvAYuObj3k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=At9jbA8Id/jt1cRwJXZi/jB4qkoiexYkZNOB8icqYaOdtpK6ULKmLbBL649DIy0THy5v6MjGEDzsyTBYv298J23eYm59T2ggHYTbVRypVHv4hk3KvV3Mi2DZ/gw+Et22CA9j20cjAa1Vshel57E+cuRk+e9mCiV6IY9PrJ7Xe44= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=ni3KCJcR; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso1196532b3a.1 for ; Thu, 28 Mar 2024 21:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711687570; x=1712292370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T4DMhRzx46RlnO0Cr4Xo2ac2UzARWIzMLM1MQTYcvtg=; b=ni3KCJcRqC3tr5D4tCmA1lEhmuiluqwTeU6Txh+75hZt3u+XjJiw4sPzLIRoB74ygd f+RE9T0fZDfNpGpI6DFynpSubrxleNE+NVctkJIM9hZr3N4b0O9Rzg84D+TH8aZNdfEn BERY4TzDYzwRLfnk4jLzgzrHm4/5IbcPD3c/DtzP+ADcud6RQVs2cgUOKRejFxRrBtwl y4dUYbSxfjImuDAcQZuRLfsrlEWhvg5BZED6HcxIqJLDDpyWqTY8w40l9CVylxHfTMwJ FD+EpEr9qOGZr10vTWylI4/BRUCdUNlwCIXF82OWg+jUwoYhtoku3n46VjiWJf2Rr5s5 3jvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711687570; x=1712292370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T4DMhRzx46RlnO0Cr4Xo2ac2UzARWIzMLM1MQTYcvtg=; b=DII8pQEfNShuPifAXHo8In0IXt48goP26TIK6wnCUgMyaVKc309Y5u03/rZprix4XA WP5ZTL7+aTQp8xwqYfyFuCxgDj2CDrdY+N+tagC+FDN2ag4LDn5QOBNy0A+snAkl0UqH zqYiAsUDX4/aq3NgICuLwYqkIYZXI5+CK9J+lDHpQGqeJyYDj/F8oEaqJLWolTXNfZhu bsJWJYPSzyHZlphYMtYTZoyyihVdE63ILrX6vWrPbs4rjc8DGjTT4ed4LujrJIaCT28c gjKLOFu+Qe4LpSwDDepboYx/gqda9j+UALnKcTkmeMqxQqUynjEAWMyRUlHfYVBxjDGj lm1w== X-Forwarded-Encrypted: i=1; AJvYcCUVGi/pR1dJmlY4cO/zv35zHhhaxFmKW+JFHtP4BgW8V/xc8RtO2CIaXGv+UPSdkhwkEbzTuoFmdHksm8LQP7f5jpoT/zKVcbiFi61k X-Gm-Message-State: AOJu0Yzu/eZIpm3rb0Mqe3w0JI3bS2vzDZ/VDfnCa0Kn2xS34hA1PNeS H9F21lXjd6yW75rLuGh4AQpz2zUtsvaUEW0HtfPU/AHBdWu5grPp4cRJ4Zd0kgQ= X-Received: by 2002:a05:6a00:4b49:b0:6ea:b606:6548 with SMTP id kr9-20020a056a004b4900b006eab6066548mr1848385pfb.7.1711687570371; Thu, 28 Mar 2024 21:46:10 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id i18-20020aa78b52000000b006ea7e972947sm2217120pfd.130.2024.03.28.21.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:46:09 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com, samuel.holland@sifive.com, palmer@sifive.com, conor@kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, tech-j-ext@lists.risc-v.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, Liam.Howlett@oracle.com, vbabka@suse.cz, lstoakes@gmail.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, hankuan.chen@sifive.com, greentime.hu@sifive.com, evan@rivosinc.com, xiao.w.wang@intel.com, charlie@rivosinc.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, dbarboza@ventanamicro.com, sameo@rivosinc.com, shikemeng@huaweicloud.com, willy@infradead.org, vincent.chen@sifive.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, gerg@kernel.org, heiko@sntech.de, bhe@redhat.com, jeeheng.sia@starfivetech.com, cyy@cyyself.name, maskray@google.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bgray@linux.ibm.com, mpe@ellerman.id.au, baruch@tkos.co.il, alx@kernel.org, david@redhat.com, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, shr@devkernel.io, deller@gmx.de, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com Subject: [PATCH v2 07/27] mm: Define VM_SHADOW_STACK for RISC-V Date: Thu, 28 Mar 2024 21:44:39 -0700 Message-Id: <20240329044459.3990638-8-debug@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240329044459.3990638-1-debug@rivosinc.com> References: <20240329044459.3990638-1-debug@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit VM_SHADOW_STACK is defined by x86 as vm flag to mark a shadow stack vma. x86 uses VM_HIGH_ARCH_5 bit but that limits shadow stack vma to 64bit only. arm64 follows same path https://lore.kernel.org/lkml/20231009-arm64-gcs-v6-12-78e55deaa4dd@kernel.org/#r To keep things simple, RISC-V follows the same. Signed-off-by: Deepak Gupta --- include/linux/mm.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f5a97dec5169..225af437ecba 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -352,7 +352,25 @@ extern unsigned int kobjsize(const void *objp); * for more details on the guard size. */ # define VM_SHADOW_STACK VM_HIGH_ARCH_5 -#else +#endif + +#ifdef CONFIG_RISCV_USER_CFI +/* + * On RISC-V pte encodings for shadow stack is R=0, W=1, X=0 and thus RISCV + * choosing to use similar mechanism on vm_flags where VM_WRITE only means + * VM_SHADOW_STACK. RISCV as well doesn't support VM_SHADOW_STACK to be set + * with VM_SHARED. + */ +#define VM_SHADOW_STACK VM_HIGH_ARCH_5 + +static inline bool arch_is_shadow_stack(vm_flags_t vm_flags) +{ + return (vm_flags & VM_SHADOW_STACK); +} + +#endif + +#ifndef VM_SHADOW_STACK # define VM_SHADOW_STACK VM_NONE #endif -- 2.43.2