Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1390409lqa; Mon, 29 Apr 2024 07:18:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVBg3XC8Tj6syxF8HNhIC1HIIKzj6QdPE72jeQKabZ+MH27I621jd8kybrD2zibUpJInChFEe/eMjtPICiAoPgAzComMZjAyrb3+0o1Q== X-Google-Smtp-Source: AGHT+IGWbIlnJpP4MWLulcT+CDwZa/eWckpF99IVhHeykXYjdgRcCw34Ir97sOad8NdkN9orLL0+ X-Received: by 2002:a05:6a00:2da9:b0:6ed:d5f5:869 with SMTP id fb41-20020a056a002da900b006edd5f50869mr13501215pfb.3.1714400338880; Mon, 29 Apr 2024 07:18:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714400338; cv=pass; d=google.com; s=arc-20160816; b=bhWUdq2kU0DkvojOvPyEmRylJdE4s5IW+nx5gDV8qFQ3dYXY+64mDIuyI2F0noBLSM OqdQeeVnxXbUGtJS7wcQg6HgrD1OXi66JhG40/yP58FBtpVlyghwcVLqIQx95KHhPYwY w/761DRLXpRuiE1g2GJ6H/v98/LtaFUAub0fa1ZTNyRhSCOV5yeIkd5ixUsU94kbM3ol gsqPweti1dnqChfCAkvNeVMB7xr2TwNhHiwSeE26hlmtqfISDKEqneTALbPbaA0hyqom uhvTjkCGWyKb865zYwCbf1Ht8H7vlUB5lFBpwAArjlFKj4eUMFC9zAeOHrNO5cCeg/ac pCMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=RJnaBJrpq3UxPqbFxbyRREn491sDcYdVfZ7jPb8KW6Q=; fh=JVqw+d9sr3BAaVRUAhrATqUG9oEJrdCNIHyy50p59QM=; b=Itpe1tRc3OHotbA+8+yhkeU+3AFl/WrfCeDbEmDARDqu3/5bI1j2gHPCa2RulVk4gG vkjNrgcrX5aZxPH3Sf1AyVBdmdO6sEc5Ft7QvZV0LiHOXcxA4bNza69uk4cbZDvdWHzJ 6Uu/KDp2h1owBQUan4sHVy/3jnSXyaAWEONB7WURSsU1fLRiyMhw0PI9CFkjzqYhP9/R zGKtsT7NflQ3TOtACM1edxcj7NpY4cq+aqe0U1HpxzXGTG0U79PSpXZ/HR3oH2R3V8Dq rGLhdf/mEl1ZYDHzBkv7GTQmfEcaNqBvuANbrfpRQ28dlweqFkZ7VWB5ubyQ5wC4yVSg XDBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-162432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162432-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gg6-20020a056a00630600b006ed95ed28c4si19555405pfb.360.2024.04.29.07.18.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 07:18:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-162432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162432-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CA3F92811B7 for ; Mon, 29 Apr 2024 14:18:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 747A078B63; Mon, 29 Apr 2024 14:18:51 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F23DE70CAA for ; Mon, 29 Apr 2024 14:18:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714400331; cv=none; b=N4Zd7D/p3AOC1O49qNVZG2DxXsMb1KvwaxsIhqijMK89Z2B7hBMXygTdQx+IMze8Hs7+OwVOJ38p7G5wNpeO+G+wqaJ8I9q8bwWB53k7lxbsUoHHd0WmHvrtH1XaSSg7vygfrDTI3nOY7VBJUpF2RVRiqvOS5nOLmDE0URp4ogU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714400331; c=relaxed/simple; bh=v+Pku9/2LJi/1kiMRZLKUDEXBo3uhWlC0VJJEBcfB4o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XJhjCORinZUY25YfQr7AkVU2EuqGU97UzKiPkB7ZEZjAc05XU5H8ay1Fl/f9Q5CtyRYWLYNjLLBD/NEZ8S6tt3VZF3eWfh4xZVFNICpZi39J01CFkx3Fm55oBFDxsLD+KGuBNelya4q5u9uAd/Bqya74RKosUluO3TuphKyb59s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 119BEC113CD; Mon, 29 Apr 2024 14:18:47 +0000 (UTC) Date: Mon, 29 Apr 2024 15:18:45 +0100 From: Catalin Marinas To: Ryan Roberts Cc: David Hildenbrand , Will Deacon , Joey Gouly , Ard Biesheuvel , Mark Rutland , Anshuman Khandual , Peter Xu , Mike Rapoport , Shivansh Vij , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/2] arm64/mm: Move PTE_PROT_NONE and PMD_PRESENT_INVALID Message-ID: References: <20240424111017.3160195-1-ryan.roberts@arm.com> <20240424111017.3160195-2-ryan.roberts@arm.com> <3ee07020-74d9-4f13-a3d0-4924a1aa69c6@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ee07020-74d9-4f13-a3d0-4924a1aa69c6@arm.com> On Mon, Apr 29, 2024 at 02:23:35PM +0100, Ryan Roberts wrote: > On 29/04/2024 14:01, Ryan Roberts wrote: > > On 29/04/2024 13:38, Catalin Marinas wrote: > >> On Mon, Apr 29, 2024 at 11:04:53AM +0100, Ryan Roberts wrote: > >>> On 26/04/2024 15:48, Catalin Marinas wrote: > >>>> On Thu, Apr 25, 2024 at 11:37:42AM +0100, Ryan Roberts wrote: > >>>>> Also, IMHO we shouldn't really need to reserve PMD_PRESENT_INVALID for swap > >>>>> ptes; it would be cleaner to have one bit that defines "present" when valid is > >>>>> clear (similar to PTE_PROT_NONE today) then another bit which is only defined > >>>>> when "present && !valid" which tells us if this is PTE_PROT_NONE or > >>>>> PMD_PRESENT_INVALID (I don't think you can ever have both at the same time?). > >>>> > >>>> I think this make sense, maybe rename the above to PTE_PRESENT_INVALID > >>>> and use it for both ptes and pmds. > >>> > >>> Yep, sounds good. I've already got a patch to do this, but it's exposed a bug in > >>> core-mm so will now fix that before I can validate my change. see > >>> https://lore.kernel.org/linux-arm-kernel/ZiuyGXt0XWwRgFh9@x1n/ > >>> > >>> With this in place, I'm proposing to remove PTE_PROT_NONE entirely and instead > >>> represent PROT_NONE as a present but invalid pte (PTE_VALID=0, PTE_INVALID=1) > >>> with both PTE_WRITE=0 and PTE_RDONLY=0. > >>> > >>> While the HW would interpret PTE_WRITE=0/PTE_RDONLY=0 as "RW without dirty bit > >>> modification", this is not a problem as the pte is invalid, so the HW doesn't > >>> interpret it. And SW always uses the PTE_WRITE bit to interpret the writability > >>> of the pte. So PTE_WRITE=0/PTE_RDONLY=0 was previously an unused combination > >>> that we now repurpose for PROT_NONE. > >> > >> Why not just keep the bits currently in PAGE_NONE (PTE_RDONLY would be > >> set) and check PTE_USER|PTE_UXN == 0b01 which is a unique combination > >> for PAGE_NONE (bar the kernel mappings). > > > > Yes I guess that works. I personally prefer my proposal because it is more > > intuitive; you have an R bit and a W bit, and you encode RO, WR, and NONE. But > > if you think reusing the kernel mapping check (PTE_USER|PTE_UXN == 0b01) is > > preferable, then I'll go with that. > > Ignore this - I looked at your proposed approach and agree it's better. I'll use > `PTE_USER|PTE_UXN==0b01`. Posting shortly... You nearly convinced me until I read your second reply ;). The PTE_WRITE|PTE_RDONLY == 0b00 still has the mkwrite problem if we care about (I don't think it can happen though). -- Catalin