Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp219957imm; Mon, 1 Oct 2018 08:56:05 -0700 (PDT) X-Google-Smtp-Source: ACcGV63SaveXA0+38etphimZuRCXmM8YRxbyQ5Xi6gcBc/uESznOYCpT9URonwkfmDpuGKmB2zjM X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr238635plc.105.1538409365441; Mon, 01 Oct 2018 08:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538409365; cv=none; d=google.com; s=arc-20160816; b=FBvPmwUNXNmGkcm42MK4QtlhabaIKRu1HpxovprCPL8atnRUaC+qBbBeZkW8YpAA/h qMZTRW4pSQUnGZt7Z8oZ69Np7vU25I1RQlZwr4gEfTT73tQTOYkRqPTEh290Jw+6q0wt C1S5ZctOXiRXcPfxdxPuyvbUDKWmHp6neDURv22e6HtXC8PhR1musPe7jwIx2DFoii+0 HgDcliB3vm1JEYiuLDEiHHwzw+o4UVLe5lWML+T0+BpZyo0q42ckKHqRPE5xw8hdl2/J HurSkZks31/1Oe1msIuYelQFiEIqH71sHrhg/Zalz0EQXLdQMxR1lTpBlgA/xEnfMJWI kaHw== 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; bh=KpZ3k815IKzXxUoAN1enCMp8CexU9Ac9OZT12vLZ20Q=; b=IB28t0S1RA7dRqGuPbSuGRDyYEQ2I6953xa+epjLm4ON2GXdsqFtQu8Rl5QnLvMvcm X7iJh8lFt32xlEQsxFeZ1/cCYiwCn9sv7MiUdRo2JZEyp0RYsUu0wReQ/eibISxTFA2C bnyCZe/SK9AOTR7777StUbyBPMaZNxFjCxdbv0ffsPROrIwm5NeZROfBzgpW+owFaEI+ YKvVBryhW7OrffsjzV+qDCKZs2sBB4HoI0640k6jUdujcJvsqkDqy1xFD/bBB0p5sKex r3/V1uD1epUS7XRac3hE4zDpVTxlotJJFoSnDKl3y48Nm9lpwGE0p3JlS6MFh0FXHkve 2mUg== 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 b9-v6si12870922pfi.99.2018.10.01.08.55.51; Mon, 01 Oct 2018 08:56:05 -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 S1726458AbeJAWdu (ORCPT + 99 others); Mon, 1 Oct 2018 18:33:50 -0400 Received: from foss.arm.com ([217.140.101.70]:51820 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbeJAWdt (ORCPT ); Mon, 1 Oct 2018 18:33:49 -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 2DEBD15BF; Mon, 1 Oct 2018 08:55:23 -0700 (PDT) Received: from localhost (e105922-lin.emea.arm.com [10.4.13.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C370E3F5D3; Mon, 1 Oct 2018 08:55:22 -0700 (PDT) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Cc: Punit Agrawal , marc.zyngier@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com, Christoffer Dall Subject: [PATCH v8 3/9] KVM: arm/arm64: Re-factor setting the Stage 2 entry to exec on fault Date: Mon, 1 Oct 2018 16:54:37 +0100 Message-Id: <20181001155443.23032-4-punit.agrawal@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181001155443.23032-1-punit.agrawal@arm.com> References: <20181001155443.23032-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 Reviewed-by: Suzuki K Poulose 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 5b76ee204000..ec64d21c6571 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1481,7 +1481,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; @@ -1606,19 +1607,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 { @@ -1629,13 +1636,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.18.0