Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2201763imm; Mon, 16 Jul 2018 04:10:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeyt3udXXlLfFQ2bJk9UlwaTDO0z6bJmacusZyYYe2a12AOJ7pwWJCmgXvgq7mGohF9aHQW X-Received: by 2002:a63:d011:: with SMTP id z17-v6mr14721012pgf.272.1531739445305; Mon, 16 Jul 2018 04:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531739445; cv=none; d=google.com; s=arc-20160816; b=rQfXQLHnafQcNN3KOrcIRpQQZKepQgbM6ympdvkAJhR67uwE4yiOWlUVNMNk0phaZ3 XrvYFj6Et+HEu0TzZ6W1X7zfmgtA7HKEXqlLHHFenmVgQh615zfI6m6NF3GMUKwNIzKL 340cg8NcFlMWP72Kv2Zg1xh8SwjJ0wdrohGK41jnq1WwDVcUGfuJlYNajH1/zWIczxq6 T7xVv8fqpvlfVc6/I0+C+AAIRQD2KZuyV6rQYT3Xc+PWwKpy7IGB3iTbWRdAKVnRwLQY 6ADrjHi/Wthzk5SgbVB9ABf1EqEMqMCFpYS0xnZJSJP3ppIeV4vlskir842HRYMZOIKW SVGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hW5T0kyDO1rEFIFqeGDKqJhCt6pgEKJfizSwrsr23vI=; b=wHDm45hWVdm6kAq4yeVb5D8JKd5UsQfbXGdKeDaRcEerb26G5F6c3rKbYUayu1vp8a KBNcNuO00CZqUr33UvjLO1v255K1SVT6oz7nSqRNu5uceqULGU/GNDlcFW8Ct0CwGhTZ FRMdqwGUAfFior/UwfpQCvjCQlwki2bTa63kVNOHraI0WXFLsP6/vL6oBkR1p+3TQhI8 1X3pG6OoHU3LTYE2Hr/mGVaV2cNj8ywzXKqTQ/ZZTgfb9fEU9Zeniw+71Z64xJPNOqjy tu/RCEEPLSmFZabVg15RsGO9tBXAuMkgaj6d8zf2mEqCBzJCzTNHtaXJIWZe3dCpvUQr TfzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11-v6si29513504plz.333.2018.07.16.04.10.30; Mon, 16 Jul 2018 04:10:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730209AbeGPLga (ORCPT + 99 others); Mon, 16 Jul 2018 07:36:30 -0400 Received: from foss.arm.com ([217.140.101.70]:57116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728324AbeGPLga (ORCPT ); Mon, 16 Jul 2018 07:36:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A8CAF15AD; Mon, 16 Jul 2018 04:09:35 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.206.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2A9273F589; Mon, 16 Jul 2018 04:09:35 -0700 (PDT) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Cc: Punit Agrawal , linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, christoffer.dall@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com, will.deacon@arm.com Subject: [PATCH v6 2/8] KVM: arm/arm64: Re-factor setting the Stage 2 entry to exec on fault Date: Mon, 16 Jul 2018 12:08:51 +0100 Message-Id: <20180716110857.19310-3-punit.agrawal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180716110857.19310-1-punit.agrawal@arm.com> References: <20180716110857.19310-1-punit.agrawal@arm.com> X-ARM-No-Footer: FoSSMail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Stage 2 fault handler marks a page as executable if it is handling an execution fault or if it was a permission fault in which case the executable bit needs to be preserved. The logic to decide if the page should be marked executable is duplicated for PMD and PTE entries. To avoid creating another copy when support for PUD hugepages is introduced refactor the code to share the checks needed to mark a page table entry as executable. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier --- virt/kvm/arm/mmu.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 1c8d407a92ce..ea3d992e4fb7 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1422,7 +1422,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, unsigned long fault_status) { int ret; - bool write_fault, exec_fault, writable, hugetlb = false, force_pte = false; + bool write_fault, writable, hugetlb = false, force_pte = false; + bool exec_fault, needs_exec; unsigned long mmu_seq; gfn_t gfn = fault_ipa >> PAGE_SHIFT; struct kvm *kvm = vcpu->kvm; @@ -1541,19 +1542,25 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (exec_fault) invalidate_icache_guest_page(pfn, vma_pagesize); + /* + * If we took an execution fault we have made the + * icache/dcache coherent above and should now let the s2 + * mapping be executable. + * + * Write faults (!exec_fault && FSC_PERM) are orthogonal to + * execute permissions, and we preserve whatever we have. + */ + needs_exec = exec_fault || + (fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa)); + if (hugetlb && vma_pagesize == PMD_SIZE) { pmd_t new_pmd = pfn_pmd(pfn, mem_type); new_pmd = pmd_mkhuge(new_pmd); if (writable) new_pmd = kvm_s2pmd_mkwrite(new_pmd); - if (exec_fault) { + if (needs_exec) new_pmd = kvm_s2pmd_mkexec(new_pmd); - } else if (fault_status == FSC_PERM) { - /* Preserve execute if XN was already cleared */ - if (stage2_is_exec(kvm, fault_ipa)) - new_pmd = kvm_s2pmd_mkexec(new_pmd); - } ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd); } else { @@ -1564,13 +1571,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, mark_page_dirty(kvm, gfn); } - if (exec_fault) { + if (needs_exec) new_pte = kvm_s2pte_mkexec(new_pte); - } else if (fault_status == FSC_PERM) { - /* Preserve execute if XN was already cleared */ - if (stage2_is_exec(kvm, fault_ipa)) - new_pte = kvm_s2pte_mkexec(new_pte); - } ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, flags); } -- 2.17.1