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 X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75144C433DB for ; Thu, 21 Jan 2021 22:20:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC5D8221E5 for ; Thu, 21 Jan 2021 22:20:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC5D8221E5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3494B6B0006; Thu, 21 Jan 2021 17:20:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D0546B0007; Thu, 21 Jan 2021 17:20:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1996D6B0008; Thu, 21 Jan 2021 17:20:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 0157F6B0006 for ; Thu, 21 Jan 2021 17:20:03 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B8D8C181AF5C6 for ; Thu, 21 Jan 2021 22:20:03 +0000 (UTC) X-FDA: 77731201086.16.cough34_260b2fb27566 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 95517100E6903 for ; Thu, 21 Jan 2021 22:20:03 +0000 (UTC) X-HE-Tag: cough34_260b2fb27566 X-Filterd-Recvd-Size: 4601 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 22:20:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description; bh=POte/V20qtU3wIuQT3uNCJADUsZhh5FbVb9IWDUrrs4=; b=uyVCjfYfVTODCwxqk/A+E0IzDf uTCGX1kPCj0FSi4X0iiI3s1XaFSpaHk1pmrnJF55fdLum7tmdzkChJVzRzu2d/m4d1tUGB9bSJ7ip WJGc1tiKWTbsDvIDdYiZiHi5CDoSxDUsOX6epa8G41U9vRXnwHxErti7FH0q3QqirdDKhMgbOqu8F /+uMp9dXC7mR3lOu2iLAQctykCnmZFoI+asaBc52ukmyCwYCeS13Lbm0x9ORRI35UbCOtZQx7g8FE OzcwW3w+E5YuQX8WfBC66vEYuEEH8jx45XX66lsbKh2ZGA2QfojjjlFh/D8SCnmW0tTOfgFVIFowE 6WwQ+5MQ==; Received: from [2601:1c0:6280:3f0::9abc] by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2iIn-0006iw-1d; Thu, 21 Jan 2021 22:19:41 +0000 Subject: Re: [PATCH v17 08/26] x86/mm: Introduce _PAGE_COW To: David Laight , "'Yu, Yu-cheng'" , Borislav Petkov 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 , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu References: <20201229213053.16395-1-yu-cheng.yu@intel.com> <20201229213053.16395-9-yu-cheng.yu@intel.com> <20210121184405.GE32060@zn.tnic> From: Randy Dunlap Message-ID: <9344cd90-1818-a716-91d2-2b85df01347b@infradead.org> Date: Thu, 21 Jan 2021 14:19:28 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 1/21/21 2:16 PM, David Laight wrote: > From: Yu, Yu-cheng >> >> On 1/21/2021 10:44 AM, Borislav Petkov wrote: >>> On Tue, Dec 29, 2020 at 01:30:35PM -0800, Yu-cheng Yu wrote: >> [...] >>>> @@ -343,6 +349,16 @@ static inline pte_t pte_mkold(pte_t pte) >>>> >>>> static inline pte_t pte_wrprotect(pte_t pte) >>>> { >>>> + /* >>>> + * Blindly clearing _PAGE_RW might accidentally create >>>> + * a shadow stack PTE (RW=0, Dirty=1). Move the hardware >>>> + * dirty value to the software bit. >>>> + */ >>>> + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { >>>> + pte.pte |= (pte.pte & _PAGE_DIRTY) >> _PAGE_BIT_DIRTY << _PAGE_BIT_COW; >>> >>> Why the unreadable shifting when you can simply do: >>> >>> if (pte.pte & _PAGE_DIRTY) >>> pte.pte |= _PAGE_COW; >>> > >>> ? >> >> It clears _PAGE_DIRTY and sets _PAGE_COW. That is, >> >> if (pte.pte & _PAGE_DIRTY) { >> pte.pte &= ~_PAGE_DIRTY; >> pte.pte |= _PAGE_COW; >> } >> >> So, shifting makes resulting code more efficient. > > Does the compiler manage to do one shift? > > How can it clear anything? It could shift it off either end since there are both << and >>. > There is only an |= against the target. > > Something horrid with ^= might set and clear. -- ~Randy "He closes his eyes and drops the goggles. You can't get hurt by looking at a bitmap. Or can you?" (Neal Stephenson: Snow Crash)