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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 B127FC433FE for ; Fri, 11 Dec 2020 10:01:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29B8F23F2A for ; Fri, 11 Dec 2020 10:01:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29B8F23F2A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+7aTGWOmxXsba/EWYMZruQYSJxvRGLuiGeBwSB+8gBs=; b=xvkMkTl5JULQ4vcVrcgrbrJ4x EEfcU4/ELGnKGRZ2Mnk/+6ontXkGgPmj1Km+lj89HLpiZJyMohi+3KL2WEWl03VaESmvevQ0ZHImb X+JDo02BCZpYunxO6WeiQhIv42fUGwd0C73fG+KPwXrYkEfwWUOlelrxUPNdteQ7u8b3HBpffGL8H CN211rWDQXHWOhgNFP+/0K7dhc6ZnXPzuASf8V8Lnn9+aa9wGS9MytXLwEEUFyHL9w7pMag9rMhAe oWem3FZs8gFszSK+02+GfqOF2ivO+QTxh0/cyb6TBVEahUXkA9hTY10rpwzmDQ2meWQjD8DYa3ej2 57xXFv93w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knfE4-00037i-OQ; Fri, 11 Dec 2020 10:00:36 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knfE2-00036w-IX for linux-arm-kernel@lists.infradead.org; Fri, 11 Dec 2020 10:00:35 +0000 Date: Fri, 11 Dec 2020 10:00:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607680833; bh=jFOIRQmF8QhbnoVrQUBYI2SL8ohUqFFx7/jNj606aGc=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=ECLlIotuaiZ4dGQjFw7VRauGeaiinR7H+nU6z0KrbpH1BBQDSMsprwcVPGqVVOamg u4DsAn+WXLS9N+hU83gF+q1RfVfyweBneFjKxqmfy6tP4joYToNhGHGTCE8PfY7SfA K0DZMBdeg+zFD0qsN+SZHHcvWrdNWvJvyN/EnHS2vv2VaYAQpr1dhYRbi2S14pEO3K NeFVSKA3vqhKAHMi0tIxXWJfvQa8Fjtk7k0NFgW7MQDdjlFGdWnOXFqsVby0Ku7bM7 vYeonkGRRqXtleLB61ma3hN2rFcUoHcmfzCpLO625rb++tNZ6UFaSNjhjUijxxJcPd Tp1P2H6BQwIrg== From: Will Deacon To: Marc Zyngier Subject: Re: [RFC PATCH] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler Message-ID: <20201211100026.GA11352@willie-the-truck> References: <20201211080115.21460-1-wangyanan55@huawei.com> <20201211080115.21460-2-wangyanan55@huawei.com> <8d006755e5afce7e49b03993316c4fcc@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8d006755e5afce7e49b03993316c4fcc@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201211_050034_739668_2887BEB6 X-CRM114-Status: GOOD ( 16.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jiangkunkun@huawei.com, Gavin Shan , Suzuki K Poulose , Catalin Marinas , wangjingyi11@huawei.com, Quentin Perret , lushenming@huawei.com, linux-kernel@vger.kernel.org, Yanan Wang , yezengruan@huawei.com, James Morse , linux-arm-kernel@lists.infradead.org, yuzenghui@huawei.com, wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Dec 11, 2020 at 09:49:28AM +0000, Marc Zyngier wrote: > On 2020-12-11 08:01, Yanan Wang wrote: > > @@ -461,25 +462,56 @@ static int stage2_map_set_prot_attr(enum > > kvm_pgtable_prot prot, > > return 0; > > } > > > > +static bool stage2_set_valid_leaf_pte_pre(u64 addr, u32 level, > > + kvm_pte_t *ptep, kvm_pte_t new, > > + struct stage2_map_data *data) > > +{ > > + kvm_pte_t old = *ptep, old_attr, new_attr; > > + > > + if ((old ^ new) & (~KVM_PTE_LEAF_ATTR_PERMS)) > > + return false; > > + > > + /* > > + * Skip updating if we are trying to recreate exactly the same mapping > > + * or to reduce the access permissions only. And update the valid leaf > > + * PTE without break-before-make if we are trying to add more access > > + * permissions only. > > + */ > > + old_attr = (old & KVM_PTE_LEAF_ATTR_PERMS) ^ > > KVM_PTE_LEAF_ATTR_HI_S2_XN; > > + new_attr = (new & KVM_PTE_LEAF_ATTR_PERMS) ^ > > KVM_PTE_LEAF_ATTR_HI_S2_XN; > > + if (new_attr <= old_attr) > > + return true; > > + > > + WRITE_ONCE(*ptep, new); > > + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level); > > I think what bothers me the most here is that we are turning a mapping into > a permission update, which makes the code really hard to read, and mixes > two things that were so far separate. > > I wonder whether we should instead abort the update and simply take the > fault > again, if we ever need to do it. That's a nice idea. If we could enforce that we don't alter permissions on the map path, and instead just return e.g. -EAGAIN then that would be a very neat solution and would cement the permission vs translation fault division. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel