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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9FD1C4167B for ; Tue, 20 Dec 2022 21:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233971AbiLTV3U (ORCPT ); Tue, 20 Dec 2022 16:29:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234134AbiLTV3P (ORCPT ); Tue, 20 Dec 2022 16:29:15 -0500 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC841EAE0; Tue, 20 Dec 2022 13:29:14 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5517F1EC0559; Tue, 20 Dec 2022 22:29:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1671571753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=v9/xoJRbxbZ1eXDTI+dOLyl7gGf5dXshSBt7FGH5iiI=; b=ImWmLIAx5W2cB0d7M46w8fkIgLrn6ZbI/6eifVkfLTeSmEEK+ZGphTyC4UW7vXNHQdneB6 Lb6L/ZD1476fVEdqgYBXF7JrJ1LciLjQ3aoInU54tbbSEAdysBUKMBJzy5KKp+hlDrqvjR dm6dBunVddAsbid5FvKiQscE/xm5C60= Date: Tue, 20 Dec 2022 22:29:13 +0100 From: Borislav Petkov To: Rick Edgecombe Cc: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, Yu-cheng Yu Subject: Re: [PATCH v4 10/39] x86/mm: Introduce _PAGE_COW Message-ID: References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-11-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221203003606.6838-11-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Fri, Dec 02, 2022 at 04:35:37PM -0800, Rick Edgecombe wrote: > There are six bits left available to software in the 64-bit PTE after > consuming a bit for _PAGE_COW. No space is consumed in 32-bit kernels > because shadow stacks are not enabled there. > > This is a prepratory patch. Changes to actually start marking _PAGE_COW Unknown word [prepratory] in commit message. Suggestions: ['preparatory', > will follow once other pieces are in place. And regardless, you don't really need this sentence at all, AFAICT. ... > +/* > + * Normally COW memory can result in Dirty=1,Write=0 PTs. But in the case ^^^ PTEs. > + * of X86_FEATURE_USER_SHSTK, the software COW bit is used, since the > + * Dirty=1,Write=0 will result in the memory being treated as shaodw stack > + * by the HW. So when creating COW memory, a software bit is used > + * _PAGE_BIT_COW. The following functions pte_mkcow() and pte_clear_cow() > + * take a PTE marked conventially COW (Dirty=1) and transition it to the Unknown word [conventially] in comment. Suggestions: ['conventionally', ... > + * shadow stack compatible version of COW (Cow=1). > + */ > + ^ Superfluous newline. > +static inline pte_t pte_mkcow(pte_t pte) > +{ > + if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK)) > + return pte; > + > + pte = pte_clear_flags(pte, _PAGE_DIRTY); > + return pte_set_flags(pte, _PAGE_COW); > +} > + > +static inline pte_t pte_clear_cow(pte_t pte) > +{ > + /* > + * _PAGE_COW is unnecessary on !X86_FEATURE_USER_SHSTK kernels. I'm guessing this "unnecessary" is supposed to mean that on kernels not supporting shadow stack, a COW page uses the old bit flags? I.e., Dirty=1,Write=0? Might as well write it this way to be perfectly clear. > + * See the _PAGE_COW definition for more details. > + */ > + if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK)) > + return pte; > + > + /* > + * PTE is getting copied-on-write, so it will be dirtied > + * if writable, or made shadow stack if shadow stack and > + * being copied on access. Set they dirty bit for both "Set the dirty bit.." > + * cases. > + */ > + pte = pte_set_flags(pte, _PAGE_DIRTY); > + return pte_clear_flags(pte, _PAGE_COW); > +} Rest looks ok. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette