From patchwork Mon Jul 16 17:27:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142070 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677429ljj; Mon, 16 Jul 2018 10:29:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8b0t7Hf4yaNqEokfbZcVRfmqkn+gebDQNVUZE7YA0OQBkLGrOWdNqvD5ZbvIgt0lET3YZ X-Received: by 2002:a24:cc07:: with SMTP id x7-v6mr13237138itf.3.1531762162083; Mon, 16 Jul 2018 10:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762162; cv=none; d=google.com; s=arc-20160816; b=IkBP6UFjFfecCTXXyMuoJqONNZ6XquPOKOuOm2hUZLEMp+ACeheXzqoOZvSi7/xEwo CcVOc4C3j8EJ10YjVcP0n/cZZzckDlcEkaFWOmk9mR7Nua4twMoYECtcU8sYVLgF/emh 9pTRWR9b0ZItzrgN5Y5Dvq0cesR3hEhlq+wGI+khEofe9r+Rf4tQHu5N1j4e5P5YBxTr C4G+BzaZJobWgqSgRAmlA1/ZJIZRn3tyIw7hFMblXpkFjx5GQudHW6IOtP0fA130NzH+ upXgEOnq7KvkdE/w6XGA3GoFAjf5ASlGITscgq8xl2kIrjzYyiAXEFNr5Td7ZCkxnOPF 47dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=uxFOrd8GGr/TDmufK8Siepg2A2qfHU4SdmxGyYZ2Uz4=; b=VT0clayvJjvWHl+Y07dB519ldjnitCiDtYYJTQyOmil/UNLkxxedOvE4r1nh2Ho++u ThTz9kL0Zklw5DOlViaHoUYeJQipVsJ3uATplLvWAXxRmePneumoWVcMHuA6bhWYtjiA QAI9tdGb9yz0Vxvy1Ms5K7Dy/TQSM4d1ybnbdbWWTEmeXtGDMr64zNFaKUtFCyEwz5hw bVOZWj3PYS/eriGTNejgquAnbF+hfuqzvjjJvYR5U8mNEmb7/B1G9Zgr/eXawRV0LfIT P/tuFVruwvdxdFBr66ZjhcmTr04BMur/Ey78oXHGQqAK9Nm6lxWBfZTuLvGi36A1+O9K zVQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id r8-v6si23690613jad.22.2018.07.16.10.29.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7Hd-0006dr-Kd; Mon, 16 Jul 2018 17:27:37 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7Hb-0006bB-P5 for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:35 +0000 X-Inumbo-ID: 7b54fe2c-891d-11e8-a8a5-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 7b54fe2c-891d-11e8-a8a5-bc764e045a96; Mon, 16 Jul 2018 19:27:15 +0200 (CEST) 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 6D28A7A9; Mon, 16 Jul 2018 10:27:34 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5FEDB3F5B1; Mon, 16 Jul 2018 10:27:33 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:11 +0100 Message-Id: <20180716172712.20294-15-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180716172712.20294-1-julien.grall@arm.com> References: <20180716172712.20294-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 14/15] xen/arm: guest_walk_tables: Switch the return to bool X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , sstabellini@kernel.org, Julien Grall MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, guest_walk_tables can either return 0, -EFAULT, -EINVAL. The use of the last 2 are not clearly defined and used inconsistently in the code. The current only caller does not care about the return value and the value of it seems very limited (no way to differentiate between the 15ish error paths). So switch to bool to simplify the return and make the developper life a bit easier. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/guest_walk.c | 50 ++++++++++++++++++++-------------------- xen/arch/arm/mem_access.c | 2 +- xen/include/asm-arm/guest_walk.h | 8 +++---- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c index 4a1b4cf2c8..7db7a7321b 100644 --- a/xen/arch/arm/guest_walk.c +++ b/xen/arch/arm/guest_walk.c @@ -28,9 +28,9 @@ * page table on a different vCPU, the following registers would need to be * loaded: TCR_EL1, TTBR0_EL1, TTBR1_EL1, and SCTLR_EL1. */ -static int guest_walk_sd(const struct vcpu *v, - vaddr_t gva, paddr_t *ipa, - unsigned int *perms) +static bool guest_walk_sd(const struct vcpu *v, + vaddr_t gva, paddr_t *ipa, + unsigned int *perms) { int ret; bool disabled = true; @@ -79,7 +79,7 @@ static int guest_walk_sd(const struct vcpu *v, } if ( disabled ) - return -EFAULT; + return false; /* * The address of the L1 descriptor for the initial lookup has the @@ -97,12 +97,12 @@ static int guest_walk_sd(const struct vcpu *v, /* Access the guest's memory to read only one PTE. */ ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(short_desc_t), false); if ( ret ) - return -EINVAL; + return false; switch ( pte.walk.dt ) { case L1DESC_INVALID: - return -EFAULT; + return false; case L1DESC_PAGE_TABLE: /* @@ -122,10 +122,10 @@ static int guest_walk_sd(const struct vcpu *v, /* Access the guest's memory to read only one PTE. */ ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(short_desc_t), false); if ( ret ) - return -EINVAL; + return false; if ( pte.walk.dt == L2DESC_INVALID ) - return -EFAULT; + return false; if ( pte.pg.page ) /* Small page. */ { @@ -175,7 +175,7 @@ static int guest_walk_sd(const struct vcpu *v, *perms |= GV2M_EXEC; } - return 0; + return true; } /* @@ -355,9 +355,9 @@ static bool check_base_size(unsigned int output_size, uint64_t base) * page table on a different vCPU, the following registers would need to be * loaded: TCR_EL1, TTBR0_EL1, TTBR1_EL1, and SCTLR_EL1. */ -static int guest_walk_ld(const struct vcpu *v, - vaddr_t gva, paddr_t *ipa, - unsigned int *perms) +static bool guest_walk_ld(const struct vcpu *v, + vaddr_t gva, paddr_t *ipa, + unsigned int *perms) { int ret; bool disabled = true; @@ -442,7 +442,7 @@ static int guest_walk_ld(const struct vcpu *v, */ if ( (input_size > TCR_EL1_IPS_48_BIT_VAL) || (input_size < TCR_EL1_IPS_MIN_VAL) ) - return -EFAULT; + return false; } else { @@ -487,7 +487,7 @@ static int guest_walk_ld(const struct vcpu *v, } if ( disabled ) - return -EFAULT; + return false; /* * The starting level is the number of strides (grainsizes[gran] - 3) @@ -498,12 +498,12 @@ static int guest_walk_ld(const struct vcpu *v, /* Get the IPA output_size. */ ret = get_ipa_output_size(d, tcr, &output_size); if ( ret ) - return -EFAULT; + return false; /* Make sure the base address does not exceed its configured size. */ ret = check_base_size(output_size, ttbr); if ( !ret ) - return -EFAULT; + return false; /* * Compute the base address of the first level translation table that is @@ -523,12 +523,12 @@ static int guest_walk_ld(const struct vcpu *v, /* Access the guest's memory to read only one PTE. */ ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(lpae_t), false); if ( ret ) - return -EFAULT; + return false; /* Make sure the base address does not exceed its configured size. */ ret = check_base_size(output_size, pfn_to_paddr(pte.walk.base)); if ( !ret ) - return -EFAULT; + return false; /* * If page granularity is 64K, make sure the address is aligned @@ -537,7 +537,7 @@ static int guest_walk_ld(const struct vcpu *v, if ( (output_size < TCR_EL1_IPS_52_BIT_VAL) && (gran == GRANULE_SIZE_INDEX_64K) && (pte.walk.base & 0xf) ) - return -EFAULT; + return false; /* * Break if one of the following conditions is true: @@ -567,7 +567,7 @@ static int guest_walk_ld(const struct vcpu *v, * maps a memory block at level 3 (PTE<1:0> == 01). */ if ( !lpae_is_valid(pte) || !lpae_is_mapping(pte, level) ) - return -EFAULT; + return false; /* Make sure that the lower bits of the PTE's base address are zero. */ mask = GENMASK_ULL(47, grainsizes[gran]); @@ -583,11 +583,11 @@ static int guest_walk_ld(const struct vcpu *v, if ( !pte.pt.xn && !xn_table ) *perms |= GV2M_EXEC; - return 0; + return true; } -int guest_walk_tables(const struct vcpu *v, vaddr_t gva, - paddr_t *ipa, unsigned int *perms) +bool guest_walk_tables(const struct vcpu *v, vaddr_t gva, + paddr_t *ipa, unsigned int *perms) { uint32_t sctlr = READ_SYSREG(SCTLR_EL1); register_t tcr = READ_SYSREG(TCR_EL1); @@ -595,7 +595,7 @@ int guest_walk_tables(const struct vcpu *v, vaddr_t gva, /* We assume that the domain is running on the currently active domain. */ if ( v != current ) - return -EFAULT; + return false; /* Allow perms to be NULL. */ perms = perms ?: &_perms; @@ -619,7 +619,7 @@ int guest_walk_tables(const struct vcpu *v, vaddr_t gva, /* Memory can be accessed without any restrictions. */ *perms = GV2M_READ|GV2M_WRITE|GV2M_EXEC; - return 0; + return true; } if ( is_32bit_domain(v->domain) && !(tcr & TTBCR_EAE) ) diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c index ae2686ffa2..57ec7872bb 100644 --- a/xen/arch/arm/mem_access.c +++ b/xen/arch/arm/mem_access.c @@ -125,7 +125,7 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag, * The software gva to ipa translation can still fail, e.g., if the gva * is not mapped. */ - if ( guest_walk_tables(v, gva, &ipa, &perms) < 0 ) + if ( !guest_walk_tables(v, gva, &ipa, &perms) ) return NULL; /* diff --git a/xen/include/asm-arm/guest_walk.h b/xen/include/asm-arm/guest_walk.h index 4ed8476e08..8768ac9894 100644 --- a/xen/include/asm-arm/guest_walk.h +++ b/xen/include/asm-arm/guest_walk.h @@ -2,10 +2,10 @@ #define _XEN_GUEST_WALK_H /* Walk the guest's page tables in software. */ -int guest_walk_tables(const struct vcpu *v, - vaddr_t gva, - paddr_t *ipa, - unsigned int *perms); +bool guest_walk_tables(const struct vcpu *v, + vaddr_t gva, + paddr_t *ipa, + unsigned int *perms); #endif /* _XEN_GUEST_WALK_H */