Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp282361pxm; Tue, 1 Mar 2022 20:54:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzmEwldZWHrCF+uv9+w/02djuj/yOxq8JGniW2Cj2o5lkuxPvuOgYC7XX7LLpnp6wlc5bk X-Received: by 2002:a65:5bc1:0:b0:373:ec8f:9f50 with SMTP id o1-20020a655bc1000000b00373ec8f9f50mr24508161pgr.289.1646196887443; Tue, 01 Mar 2022 20:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646196887; cv=none; d=google.com; s=arc-20160816; b=z4BK9ZacJ8UZIAjbb4kkRixER3xxZHWfW0F1X1iecCt8oBJ0Sq+JodTLZLpmSGwpzx HbyQHk2OVR2SXmTzwARJXlHnmxffEmAHbMbJI18Dc0Dq1a6vz3tyzU/tZhjGr9e2voeY FcN6gVSL1fOkqIAGD/WiwhsNQJUCmHhRf9NXHunQbw+zCeuOc+GHUL0sOcvFhPDXtYr2 mz8qGPAHooXiH6Ip7YCDkQ2ZlHr0xrPZjeSeR3f3cFAiOmSQSsVf0KD4KQPVGJGmxego Zt0asBRNjuw961qREB2k9N2dbbnGnCGgV5m9ECs+Ed77/TPEfuy4HnMwDOnb0atl9iqe oqkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=9CKWO6YS76fsOhI2TJF3CaRhUB6d9iznFO5QVuh4WpU=; b=N2B8kUOLvdb+vy3bXUypiRoJNER6dxT4yPTVzeQieg9QdnhaobFggMRpZ3kmgSV7eV ge7AqubWzRwSY8QG+IqSYOKYATfqvzwSGkEtMhnlhDwYUCwTBiBvTJkBIR2FGq/G9DXr afgccqxKjHLLSKvqJdjhn/53+r2+51F48Ct0QANwqqC5tXYbgMI6S2yN2w66o8mqupl3 jtQVaOPWhNRjUSF6P/7CaSux3LQNcgMmFXIXd7sYCRal+zqBZaXTP5379UpHUebC7Lqs j45LjTKZipPq+hZLq9my8r4IaZziHE8hQ3qmXu0YawrAx5dv7pryNPU4KefRo/l6Segj q0Ew== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a17090a460900b001bc3cdfced7si4338110pjg.183.2022.03.01.20.54.30; Tue, 01 Mar 2022 20:54:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239282AbiCBDQr (ORCPT + 99 others); Tue, 1 Mar 2022 22:16:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239280AbiCBDQp (ORCPT ); Tue, 1 Mar 2022 22:16:45 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A72F7B0A47; Tue, 1 Mar 2022 19:16:02 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2C1C9113E; Tue, 1 Mar 2022 19:16:02 -0800 (PST) Received: from [10.163.49.202] (unknown [10.163.49.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 091233F73D; Tue, 1 Mar 2022 19:15:54 -0800 (PST) Subject: Re: [PATCH V3 09/30] arm/mm: Enable ARCH_HAS_VM_GET_PAGE_PROT To: "Russell King (Oracle)" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, geert@linux-m68k.org, Christoph Hellwig , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linux-mips@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-s390@vger.kernel.org, linux-riscv@lists.infradead.org, linux-alpha@vger.kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-parisc@vger.kernel.org, openrisc@lists.librecores.org, linux-um@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-arch@vger.kernel.org, Arnd Bergmann References: <1646045273-9343-1-git-send-email-anshuman.khandual@arm.com> <1646045273-9343-10-git-send-email-anshuman.khandual@arm.com> <542fa048-131e-240b-cc3a-fd4fff7ce4ba@arm.com> From: Anshuman Khandual Message-ID: <2f995e2a-c00f-bc9c-6ac6-c783a21b007e@arm.com> Date: Wed, 2 Mar 2022 08:45:52 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,SUSPICIOUS_RECIPS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 3/1/22 6:01 AM, Russell King (Oracle) wrote: > On Tue, Mar 01, 2022 at 05:30:41AM +0530, Anshuman Khandual wrote: >> On 2/28/22 4:27 PM, Russell King (Oracle) wrote: >>> On Mon, Feb 28, 2022 at 04:17:32PM +0530, Anshuman Khandual wrote: >>>> This defines and exports a platform specific custom vm_get_page_prot() via >>>> subscribing ARCH_HAS_VM_GET_PAGE_PROT. Subsequently all __SXXX and __PXXX >>>> macros can be dropped which are no longer needed. >>> What I would really like to know is why having to run _code_ to work out >>> what the page protections need to be is better than looking it up in a >>> table. >>> >>> Not only is this more expensive in terms of CPU cycles, it also brings >>> additional code size with it. >>> >>> I'm struggling to see what the benefit is. >> Currently vm_get_page_prot() is also being _run_ to fetch required page >> protection values. Although that is being run in the core MM and from a >> platform perspective __SXXX, __PXXX are just being exported for a table. >> Looking it up in a table (and applying more constructs there after) is >> not much different than a clean switch case statement in terms of CPU >> usage. So this is not more expensive in terms of CPU cycles. > I disagree. > > However, let's base this disagreement on some evidence. Here is the > present 32-bit ARM implementation: > > 00000048 : > 48: e200000f and r0, r0, #15 > 4c: e3003000 movw r3, #0 > 4c: R_ARM_MOVW_ABS_NC .LANCHOR1 > 50: e3403000 movt r3, #0 > 50: R_ARM_MOVT_ABS .LANCHOR1 > 54: e7930100 ldr r0, [r3, r0, lsl #2] > 58: e12fff1e bx lr > > That is five instructions long. > > Please show that your new implementation is not more expensive on > 32-bit ARM. Please do so by building a 32-bit kernel, and providing > the disassembly. > > I think you will find way more than five instructions in your version - > the compiler will have to issue code to decode the protection bits, > probably using a table of branches or absolute PC values, or possibly > the worst case of using multiple comparisons and branches. It then has > to load constants that may be moved using movw on ARMv7, but on > older architectures would have to be created from multiple instructions > or loaded from the literal pool. Then there'll be instructions to load > the address of "user_pgprot", retrieve its value, and bitwise or that. > > Therefore, I fail to see how your approach of getting rid of the table > is somehow "better" than what we currently have in terms of the effect > on the resulting code. > > If you don't like the __P and __S stuff and two arch_* hooks, you could > move the table into arch code along with vm_get_page_prot() without the > additional unnecessary hooks, while keeping all the benefits of the > table lookup. Okay, will change the arm's vm_get_page_prot() implementation as suggested.