Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4709169rwj; Tue, 20 Dec 2022 14:03:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BEuRSwvSLY1jRhEPQKuze6zQxziGB6zfglqbuAwq7b+SHp+QqdKiPIY1VxGMef2sjKCY0 X-Received: by 2002:a17:906:881:b0:7c0:ff72:e877 with SMTP id n1-20020a170906088100b007c0ff72e877mr39467435eje.63.1671573798650; Tue, 20 Dec 2022 14:03:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671573798; cv=none; d=google.com; s=arc-20160816; b=XlnpSZPKmIybFuJyPNcmzxa7LSK7nOyCUH3KWAkG8FHlL/6BFHtQp0tbVs4HVAIA2B wGhBCiGilMtEa4izpyQLcq7pTLel3iLrw7Vz3d9HsCvJ4Y1KthVoW/oPA00ZGVYIzoDu QjmRaPiE9q3sgd6Y60C3BqMI1o/fPAmTNO2AF4g0C5cZR89nB/armF68c0w18EjEgpbq eyPYkCByD9gDRuXN7OqIvBo7QBwv0E6LCEwKbQ7eRtUFVTZI/4Ur4Fb5Mu/p1jrsmM1S TCWw2fTy6FrSyxkwQj5TMn/gynbNMhCS/bWPc/c7kseq/vi1o8XhwKag1fPOBthN4ow4 ltoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=v9/xoJRbxbZ1eXDTI+dOLyl7gGf5dXshSBt7FGH5iiI=; b=Y/723mgIM9fWoFPWurIrUKBiyZnr9C5Q5wRvMPctEQR4DKVoPh6aIowRJ4B6dM2uEL nwuzmnOpaW9V7FVvF8pa8rMm7IRfTl5GARhW0LaWjjnJS76RwSPI+euUiLiQoeAeJ6YP Q2ZRqQefSG1dytskcoWXTE4ljLurpYmDoWviJ99D0UTM8hUg3L9NBTRklUinUve66lSe Qs4tta1D1bLpb7dlNXWAIztJn9yJeVRUUyPuuMnJ9Brfy2P97XAOgkescagY9BzqZRwc Hwg07bDulNd+SetO+7GweeWpD33uFrIULweDPB7LlC1wcEy5mdpReas5mDVvh1F3p6q4 05SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ImWmLIAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz14-20020a1709077d8e00b0082033822e26si194221ejc.487.2022.12.20.14.03.02; Tue, 20 Dec 2022 14:03:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ImWmLIAx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234144AbiLTV3V (ORCPT + 68 others); Tue, 20 Dec 2022 16:29:21 -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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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