Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1600093lqo; Sun, 12 May 2024 09:28:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVarEwEPIeDU2NdyGqa4D0T6aB6Ir9eQp6p222BsYqCGAt1tDst4CjWrpKfxPje+52ftiTpoSyj/Io2P8BlTne/xtq17pUWl7BmW0RLeA== X-Google-Smtp-Source: AGHT+IHxQ7U5gZ13Oz9DXaGeF4Fe44x0DOi4XqeLQUPbzUtRMcO1JjHU1jz1RGTSC6nL3/46whL/ X-Received: by 2002:a05:6512:1305:b0:51f:452f:927b with SMTP id 2adb3069b0e04-52210070208mr5710259e87.45.1715531297203; Sun, 12 May 2024 09:28:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715531297; cv=pass; d=google.com; s=arc-20160816; b=ccrKroezf0PkiVR0R1UE5nFeDvQmX2LQX/+ZyG8qYUcIsyt/EsdVKmbwaCy+RErBJH KlEgAed33RugkQjrMxAn8UlO54OxfZGG7qL3zKVBp0xWaOk/rG6BQMqILVTpAFHqXO4O LOz1Q2PWnKH8HWN9a2J1pBXldt8AVeKpiJUwadmmD680jJCQWguZWlvxFUK+Q0DAQ9C7 WoOlmQt7ZHXxGLPIAe6rnGNA/MydGsWNyj8ZRPycFfEyzjIHJmLDj6PlSLS/1UYQJb7q p4XN2xUFioHGb1K04LWDqiCF5oHKWrhr88yQDP1LjXccAEwE1lcKXgI78JSmbKJ4/US6 WwuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=owZnl9ML02VshyxfIm+YcaiDnEmXZzuAPVyC1eYhB4Q=; fh=tAELyelKdLPpJHiCXz/Zmt/B/1ekPWbwK4A9WYCiavo=; b=IREQj0a3ac5nCi+yqAcQkQbj5rPlBbqw8EMN3svgQdIHxiYISRphIQ5lx6rckC2SQj B05K3F/J6zFBXdyuTln5mE4Mpfu72DnxQgGtJtpevqiQcZ6B4zus5Wuof3TguB4I9+t3 jpTno6ZUBnRDB6U7ANWRMq1scoaT3qvXL1P44QSUcCqqEWYfkF4VqACwRq1W1JRymVUC Ucsf7OJD92WMt3w2a2PiiDVurEcM1To4rJtRJun/KKsEaW4t+ZiwYJ62OxeTG2eu8mcW 2+3wkjXoGw2HSvxXL48FuF2Is0JY/HV9ZjHyZF0HypKIH0yJhEqqBwR9vtTzNKaXo6W1 J4Dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-176936-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176936-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c327197si4217608a12.355.2024.05.12.09.28.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 09:28:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176936-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ghiti.fr); spf=pass (google.com: domain of linux-kernel+bounces-176936-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176936-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 E69DA1F2116C for ; Sun, 12 May 2024 16:28:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4FBC47F7F; Sun, 12 May 2024 16:28:06 +0000 (UTC) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 0921F17C95; Sun, 12 May 2024 16:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715531286; cv=none; b=OLwf353fCFYTYs+1JaVLsJZV4J8lVmEC7BdAg2xYHfVCobis4yTf7iDZ4OTZxmXJkGNQOgTVaN6VX5jLXBCKRDS42SVtUwXP3scxfvoDxguNsGJlrwmLQ+cn1JjqjxAYeFh+XRTG6GAsZG6HaFFbMI+CZluoZ1oUyoWni/gHvms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715531286; c=relaxed/simple; bh=UzQr1TNXnTNDAEn5uLA+4XARweS6x1GTyqCrZYGwiWI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SHR/8grwISW188rlvTDUGrCjdZgcOpLkxmHEu/mcF21qkJfCr13wpik3YAbI78z+BOhp+RAPnKbWQfIfsRubJNfuvu+OQRztIQl4nvS5lZF/h11S3DfHEzo8pn59L3qzhgnB2uz7j0F8Vlu8KxfW49EwzSf2cRb+zGbldz/+QD8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 3B45E60004; Sun, 12 May 2024 16:26:52 +0000 (UTC) Message-ID: <0ea4aff6-980f-4fc6-9ab7-9ca4c9d15d1e@ghiti.fr> Date: Sun, 12 May 2024 18:26:51 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 11/29] riscv mm: manufacture shadow stack pte Content-Language: en-US To: Deepak Gupta , 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, bjorn@rivosinc.com, alexghiti@rivosinc.com, samuel.holland@sifive.com, conor@kernel.org Cc: 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, corbet@lwn.net, 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, 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 References: <20240403234054.2020347-1-debug@rivosinc.com> <20240403234054.2020347-12-debug@rivosinc.com> From: Alexandre Ghiti In-Reply-To: <20240403234054.2020347-12-debug@rivosinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr On 04/04/2024 01:34, Deepak Gupta wrote: > This patch implements creating shadow stack pte (on riscv). Creating > shadow stack PTE on riscv means that clearing RWX and then setting W=1. > > Signed-off-by: Deepak Gupta > --- > arch/riscv/include/asm/pgtable.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index 4d5983bc6766..6362407f1e83 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -408,6 +408,12 @@ static inline pte_t pte_mkwrite_novma(pte_t pte) > return __pte(pte_val(pte) | _PAGE_WRITE); > } > > +static inline pte_t pte_mkwrite_shstk(pte_t pte) > +{ > + /* shadow stack on risc-v is XWR = 010. Clear everything and only set _PAGE_WRITE */ Nit: Not sure the comment is necessary > + return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); > +} > + > /* static inline pte_t pte_mkexec(pte_t pte) */ > > static inline pte_t pte_mkdirty(pte_t pte) > @@ -693,6 +699,12 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) > return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); > } > > +static inline pmd_t pmd_mkwrite_shstk(pmd_t pte) > +{ > + /* shadow stack on risc-v is XWR = 010. Clear everything and only set _PAGE_WRITE */ > + return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); > +} > + > static inline pmd_t pmd_wrprotect(pmd_t pmd) > { > return pte_pmd(pte_wrprotect(pmd_pte(pmd))); Otherwise: Reviewed-by: Alexandre Ghiti Thanks, Alex