From patchwork Mon Jul 16 17:26:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142079 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677731ljj; Mon, 16 Jul 2018 10:29:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRKyZT04lSkznpqL36wjn0KLNCkZx6bgizUCIBXB8UnI8ABgFuMtl28TVlthgIsPGO44BM X-Received: by 2002:a24:874a:: with SMTP id f71-v6mr14271305ite.135.1531762183155; Mon, 16 Jul 2018 10:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762183; cv=none; d=google.com; s=arc-20160816; b=dJO40cMvlrKQxefb5CEUc+ZHsmfxoynBQGG8ig0cCXeIZwf4LtmLfopfjNW0DH7zld vpJV3XFCIeW+M/sY7YzRx1+QGbgqO6N0rkrKhhQpO4oT2GBWZGxx83al6fErsrVFsLqJ kASzUs9WodORMv3nAkXmLs3BbHY2KbN++jLAgWgy7Okhdd4kvzaIVBQfTxUYpQHkU0sQ H1wH/h+qgTMMnwCJR7Dz8+lQ3jN6VxVlATvHFIT/zVQ6PUMndAYKJbUaUHG0p0s788pH pTSPnYC+lkL6Z6aC6i5SWk927K6c0Rd6o7uMkOhDiS+vXGCEeMR5hXCzVfYKMqRTTy2P xQUg== 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=FVrZ7ysUP7Z1a5RtwoYw4Ld5XdzJdODcZPI3XmgeJL0=; b=VoEdUdmEc+KBxjTqvPDxs8eE/zbNUZhZhVcdL3vPq6wcksoSIo4iNMGwYqiAQKVbeB rmAcU41tbvhG3Qm7uMa9fnBR1NCoZnZ/rpQSVd/KJx2iR/zRLdHOvrdDfOTW4zee0nL6 uSp+252yVDQl1TredO2Bg0H7BwFcFcZ9CkQoNO++iA60aaxzbVok8bkcq+QyPdU8S5a6 okV3+YeLuyLtWW0FCNapKb5j/KtOkINO23KtYucBHNsbAj1769IrhBqDva2JnLiMs7xw aysI7ookvvIfd0/VIp1MlQMjT1opuY6ccKjQbuXV7RtjZGhz/fPPpsB/9zfU0L10RyMo /vVQ== 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 t64-v6si275221iod.271.2018.07.16.10.29.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:43 -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 1ff7HO-0006Ql-L6; Mon, 16 Jul 2018 17:27:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HN-0006QW-72 for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:21 +0000 X-Inumbo-ID: 83efdbc7-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 83efdbc7-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:29 +0000 (UTC) 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 01ABC15AD; Mon, 16 Jul 2018 10:27:20 -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 178233F5B1; Mon, 16 Jul 2018 10:27:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:26:58 +0100 Message-Id: <20180716172712.20294-2-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 01/15] xen/arm: cpregs: Allow HSR_CPREG* to receive more than 1 parameter 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, HSR_CPREG is expected to receive only the co-processor register name in parameter. Because the name is actually a define, this may have been expanded by a previous macro. Rather than imposing the use of _HSR_CPREG* in such cases, allow HSR_CPREG to receive more than 1 parameter. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/include/asm-arm/cpregs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/asm-arm/cpregs.h b/xen/include/asm-arm/cpregs.h index 8db65d5e2a..4c74e8161b 100644 --- a/xen/include/asm-arm/cpregs.h +++ b/xen/include/asm-arm/cpregs.h @@ -47,8 +47,8 @@ ((__HSR_CPREG_##op1) << HSR_CP64_OP1_SHIFT) /* Encode a register as per HSR ISS pattern */ -#define HSR_CPREG32(X) _HSR_CPREG32(X) -#define HSR_CPREG64(X) _HSR_CPREG64(X) +#define HSR_CPREG32(X...) _HSR_CPREG32(X) +#define HSR_CPREG64(X...) _HSR_CPREG64(X) /* * Order registers by Coprocessor-> CRn-> Opcode 1-> CRm-> Opcode 2 From patchwork Mon Jul 16 17:26:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142071 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677549ljj; Mon, 16 Jul 2018 10:29:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcr+b+2kx40v8/74R2W/OSyRhNDyLAuLRRXNerioBWfHuk9C+uzFzu/iF6cDnjTZE5LoR3b X-Received: by 2002:a6b:7e0a:: with SMTP id i10-v6mr26811018iom.16.1531762171401; Mon, 16 Jul 2018 10:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762171; cv=none; d=google.com; s=arc-20160816; b=AlQMcopBT+Zfta3PENaLPOPcGTWEv8S2MAQyGmJYJzA6GbeLOUI65j6gDtLlqmf8PU l4ioXyT6OKyijNUOR6N/7htzyaok0T1sjaqzlKkCTpvpONUD/H5U16GV2Q0/M9LjHjlQ PfJ8Xu44QIjqOFF/49dpzfuVxrOYHa2UCdt8yTmLjxRrHn8475awZrr6By1LzuOzm2rm dPSSgqvIUXzBg7b6i+osVXpixZpfRrQHs3lxKoBiMeHWep8MNh1ulfiOrp2zDo5TkK5F sMZUUOnIFPEU3J+vufXP8LhbFBosw9+kPJguNaWGJRpwcJmxsrIQnDITU0CRW/rxDORz vE7Q== 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=9xokgK1TCjPiKekvwna0M9HVdgyq01j+OIP7envXb7g=; b=CfBkvEozwMyjDUMURqs1NwWTOxf+T73krtfocEK6E/1FipjmgD4XFGz/bVT6R3/8Tn ZfB5cR1bEI0p1FH0KZ+HUjqBIXCqYpuf4nH9CZRInhhZSU0dgZO5m7UN7VjTqk3WQml1 5dLXTIR9D0aRTjtVbOQkOJnP3oeFEZhqETB8GrCqNIhGdWHxOTS+PwGNkwNv3zHLoYCC ql/AUXTnIXivxqsnzFlwytqKhvoJ7cp7XwNOtz8RswQMt9MHHHur2J6PnEvccmvD1GSA 1306BqxGys5reko1gApUmqvZJzjpci/aQCXJW0XyNSt1eYMLccF+uxRuZ41kDMmiiUFD Objw== 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 z52-v6si17055378jaj.43.2018.07.16.10.29.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:31 -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 1ff7HQ-0006R2-6f; Mon, 16 Jul 2018 17:27:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HO-0006Qg-DD for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:22 +0000 X-Inumbo-ID: 84a102cc-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 84a102cc-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:30 +0000 (UTC) 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 2CBCA7A9; Mon, 16 Jul 2018 10:27:21 -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 3FBEA3F5B1; Mon, 16 Jul 2018 10:27:20 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:26:59 +0100 Message-Id: <20180716172712.20294-3-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 02/15] xen/arm: cpregs: Fix typo in the documentation of TTBCR 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" Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/include/asm-arm/cpregs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/include/asm-arm/cpregs.h b/xen/include/asm-arm/cpregs.h index 4c74e8161b..07e5791983 100644 --- a/xen/include/asm-arm/cpregs.h +++ b/xen/include/asm-arm/cpregs.h @@ -141,7 +141,7 @@ #define HSTR p15,4,c1,c1,3 /* Hyp. System Trap Register */ /* CP15 CR2: Translation Table Base and Control Registers */ -#define TTBCR p15,0,c2,c0,2 /* Translatation Table Base Control Register */ +#define TTBCR p15,0,c2,c0,2 /* Translation Table Base Control Register */ #define TTBR0 p15,0,c2 /* Translation Table Base Reg. 0 */ #define TTBR1 p15,1,c2 /* Translation Table Base Reg. 1 */ #define HTTBR p15,4,c2 /* Hyp. Translation Table Base Register */ From patchwork Mon Jul 16 17:27:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142085 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677812ljj; Mon, 16 Jul 2018 10:29:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+lcTcqj45fIpme81sybXLc4x6uXDwcnv5YKdto1LfNEqQwQzurPRUbnyvz5DTLmUkJgEl X-Received: by 2002:a24:65d5:: with SMTP id u204-v6mr12747468itb.8.1531762187363; Mon, 16 Jul 2018 10:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762187; cv=none; d=google.com; s=arc-20160816; b=TqL5DRix5YRt5zPW6N6iYefAqCnLKEQ4P8gn4HoMGqQq5FqzyrGpDRZl7ggzz3DlRX AzQ04GVW7mgubEOKTk+K8ORwdot1sWPNRokKw/xzxpHzGIscx+B5YDJHWtlJ39NcGQQi hWax83xOBNsk80xR7XGxX0Fg2EhYz///vj7pU3lgJhE4AtrPuWIheT+BZmAnX01r3X+a /0yI2giBX0BAJzZzi/kuryFCXpQ+3Xhp8MddVkQf9JHeVn6KlTFQYvZLeIxzFGxv6mzz DXhhbtQJEFM6aOydDPRjIpaMocEzypQ/smqcGCRLgdnlWdcgXn2OTKvq2CNIVYbPLP3J +4ZQ== 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=BR7+ntI9F5am4IUPaBmhKUiuPhG4PNe8hz76fzEqA6I=; b=h3zvrOcUpLLwNEtKdlyDN5opWi03iFXco2ZaEV4Y3eCpjGnh0hc0vQqKZYzyZmRfhu WisFXbGOo7LFZ1mv4c2Ieg4KoylPOtfkAMup3PucqAeVmXsYp1ynPLVORbIlXOujMNFS HITfKu4wsdSiw5soffoRWrwb8N3TC+ru+iP8K+RfLUizboi7Dls5i7kE0+7oauTygHND b7Tr+nvxmPv9FbwyWoC1AA1jCrploWOGaavtvWFvlQu6hVwoNPOCwaN/cHraaRGfbE6c yAI6IPBzJ/oCSOtb8cAlFYSgCySPZ7HzWpr7mf7jZbDYaatzyB51vIV9UntN7gt169XP xSpw== 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 f23-v6si19678230ioh.21.2018.07.16.10.29.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:47 -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 1ff7HQ-0006R8-Gm; Mon, 16 Jul 2018 17:27:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HP-0006Qx-Ij for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:23 +0000 X-Inumbo-ID: 85541e5e-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 85541e5e-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:32 +0000 (UTC) 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 5764E15AD; Mon, 16 Jul 2018 10:27:22 -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 6ACFF3F5B1; Mon, 16 Jul 2018 10:27:21 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:00 +0100 Message-Id: <20180716172712.20294-4-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 03/15] xen/arm: Introduce helpers to clear/flags flags in HCR_EL2 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" A couple of places in the code will need to clear/set flags in HCR_EL2 for a given vCPU and then replicate into the hardware. Introduce helpers and replace open-coded version. Signed-off-by: Julien Grall --- I haven't find a good place for those new helpers so stick to processor.h at the moment. This require to use macro rather than inline helpers given that processor.h is usually the root of all headers. --- xen/arch/arm/traps.c | 3 +-- xen/include/asm-arm/processor.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 9ae64ae6fc..d1bf69b245 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -681,8 +681,7 @@ static void inject_vabt_exception(struct cpu_user_regs *regs) break; } - current->arch.hcr_el2 |= HCR_VA; - WRITE_SYSREG(current->arch.hcr_el2, HCR_EL2); + vcpu_hcr_set_flags(current, HCR_VA); } /* diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index 222a02dd99..7e695c2418 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -843,6 +843,24 @@ void abort_guest_exit_end(void); : : : "memory"); \ } while (0) +/* + * Clear/Set flags in HCR_EL2 for a given vCPU. It only supports the current + * vCPU for now. + */ +#define vcpu_hcr_clear_flags(v, flags) \ + do { \ + ASSERT((v) == current); \ + (v)->arch.hcr_el2 &= ~(flags); \ + WRITE_SYSREG((v)->arch.hcr_el2, HCR_EL2); \ + } while (0) + +#define vcpu_hcr_set_flags(v, flags) \ + do { \ + ASSERT((v) == current); \ + (v)->arch.hcr_el2 |= (flags); \ + WRITE_SYSREG((v)->arch.hcr_el2, HCR_EL2); \ + } while (0) + #endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_PROCESSOR_H */ /* From patchwork Mon Jul 16 17:27:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142073 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677597ljj; Mon, 16 Jul 2018 10:29:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcbrA13f8xk3sWMMjvoKnLW0mAL/J8cqwn0sU4lTn100s/FNxVl8nMrS8umMIIn1sZyrZwV X-Received: by 2002:a6b:6c0b:: with SMTP id a11-v6mr40145356ioh.175.1531762174715; Mon, 16 Jul 2018 10:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762174; cv=none; d=google.com; s=arc-20160816; b=DnISaBQVs4muef5aadvnMV4o2uH1pxobBclvbtSkY8hq44ahRlmJH2h7NJg7ruXQP7 /dhfEbEIsubG4IUJKaxYXLPiIuWOBovg8y002cX0D91rDRRQPpNS+Gew7Ncp5F6rX1pI SLIhKQLiyy4EL177PlCqU9B1t+mDLtnb64ZaZ28X+va+W5VdytDA44Rnj4Gu/UvPHb4l GHz187QjWpu1DlP1zAw4NDVhzGV6WD4+qxgdZwfdrH8tRz00hwAuV+6in7Vnke3uRmjz DG0E60VZelyRERzAX3sxMkvRfohNUtim2jvxXndByYn6sv63evqz0q+aDdGBpCxUgmv3 uovw== 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=v2ovJxw8nCFJlhCSZlaF4Ol6l0OcCHMaF9K0/b11+aY=; b=NUog+quE4rJIWEsuGKDDpbu+cbkUNs8TBbd1l4tXcKwxapu6yCkRiWBsV76AsM1KOr WlWKit5J+LOrEsrG/WfX9pXgJKjN+FY6jdwCP+9NQ6C5vI8PFMkkiH6xhdpYxL/GSxxw NNKNe2JVy8a/pw1w2Lz8uKL0CpVGznYxDhEFdMGgnTHVCZINFl0Ccvkogz2kFkT54NGG r32Ee38VfJhzHQz1A1TgQ2zHQYbWBwKbkpPuve/DOQNegRASVfkg2ejk+yjWGJ6b5oLU 4zmQNfu7usKvd3RgWfnHVaK4g/ESvq+veLjWMqdbvVHJ8LTA5jQmQnRH5jLqF8yiDsZm K+Kw== 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 r143-v6si9884292itb.122.2018.07.16.10.29.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:34 -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 1ff7HR-0006RJ-Pe; Mon, 16 Jul 2018 17:27:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HQ-0006RC-Op for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:24 +0000 X-Inumbo-ID: 85efcc13-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 85efcc13-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:33 +0000 (UTC) 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 5BB4C7A9; Mon, 16 Jul 2018 10:27:23 -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 9519D3F5B1; Mon, 16 Jul 2018 10:27:22 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:01 +0100 Message-Id: <20180716172712.20294-5-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 04/15] xen/arm: p2m: Reduce the locking section in get_page_from_gva 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The p2m lock is only necessary to prevent gvirt_to_maddr failing when break-before-make sequence is used in the P2M update concurrently on another pCPU. So reduce the locking section. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Note a newline has been dropped to keep the block together. --- xen/arch/arm/p2m.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 14791388ad..5ca7ffe41b 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1415,9 +1415,13 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, if ( v != current ) return NULL; + /* + * The lock is here to protect us against the break-before-make + * sequence used when updating the entry. + */ p2m_read_lock(p2m); - par = gvirt_to_maddr(va, &maddr, flags); + p2m_read_unlock(p2m); if ( par ) { @@ -1445,8 +1449,6 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, } err: - p2m_read_unlock(p2m); - if ( !page && p2m->mem_access_enabled ) page = p2m_mem_access_check_and_get_page(va, flags, v); From patchwork Mon Jul 16 17:27:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142077 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677688ljj; Mon, 16 Jul 2018 10:29:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfonDz2lGDJQ38+1UwMBezp4lXGQqxfhbwHNDzgjjI0Anr51tTAWrWAu4cA+/Juld5wJmcC X-Received: by 2002:a24:d80a:: with SMTP id b10-v6mr13349136itg.141.1531762180451; Mon, 16 Jul 2018 10:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762180; cv=none; d=google.com; s=arc-20160816; b=nK8alsQzq/JHt7SpGvnhnsNSOy2p46DAfRC1Sk1nfwOJLV7kxOzukWn6T82XYus3/p ehDoNgkD30YoGJ5KS1jg1qkXq924ZsqElJ7vVIx40XKHD/61U0jaA9a1Aj0rQGsKJcuE lbhAkEkHNTmnXPoW5V0Tz/X7RdgT0tSWItDTHjsYLTV8sao/K9U1SOPHURNNAgymrQ5B WmUkN21U2Dv5Fhs2XBQN4P06mFf67r5QV4QFoe5K9YhiyFNjrzHyF+IV0Iz13iOCmpOO 4/xM6JhlC0ezOudHjkIcjnxmwwrVrPBfUCuWp1FwFmDFor6DFStfUt4pySrQOd9l8Gnc s6hw== 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=iTFZLTmy8rqy8NmGHWQ/O2JbhTZXp13H+mM1kmb6P8o=; b=b5Gela0T26z6/t9wq7OzF2QWcwiddyqYF3kMVNMrUjQ5A69XtiTmAfdfRdM02RExSE 0cVMy6ZS4/4P0HtG9sKIV2TrgrpHbHEZH3xhHfQZMlcfBiIxETly/I9FnMPMTdPc/FSf H3FG73NrzUb+ly5dbqI+0OnxfXhDCoISKKhSROEeuknuXN29G6GISkeic7CeAFFXkF6A BPYG0jQJXyvEHTb4HiU2sTrH496fq21e3b3j543+fasDhXzEBGkP2FqlejwTFycMFSQW hpzle48d2WngYexLGWb4UVz6KB0QEFax9F9r16y5nFn5yAYNtETXpyf5QORBygdK29Z/ K6uw== 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 c10-v6si22222146ioh.248.2018.07.16.10.29.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:40 -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 1ff7HT-0006RV-3A; Mon, 16 Jul 2018 17:27:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HR-0006RM-UU for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:25 +0000 X-Inumbo-ID: 86b7cead-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 86b7cead-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:34 +0000 (UTC) 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 A7B0E15AD; Mon, 16 Jul 2018 10:27:24 -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 9A5183F5B1; Mon, 16 Jul 2018 10:27:23 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:02 +0100 Message-Id: <20180716172712.20294-6-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 05/15] xen/arm: p2m: Limit call to mem access code use in get_page_from_gva 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, Tamas K Lengyel , Razvan Cojocaru MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Mem access has only an impact on the hardware translation between a guest virtual address and the machine physical address. So it is not necessary to fallback to memaccess for all the other case (e.g when it is not possible to acquire the page behind the MFN). Signed-off-by: Julien Grall Acked-by: Razvan Cojocaru Reviewed-by: Stefano Stabellini --- Cc: Razvan Cojocaru Cc: Tamas K Lengyel --- xen/arch/arm/p2m.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 5ca7ffe41b..ebf74760fa 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1425,17 +1425,24 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, if ( par ) { + /* + * When memaccess is enabled, the translation GVA to MADDR may + * have failed because of a permission fault. + */ + if ( p2m->mem_access_enabled ) + return p2m_mem_access_check_and_get_page(va, flags, v); + dprintk(XENLOG_G_DEBUG, "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n", v, va, flags, par); - goto err; + return NULL; } if ( !mfn_valid(maddr_to_mfn(maddr)) ) { dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n", v, mfn_x(maddr_to_mfn(maddr))); - goto err; + return NULL; } page = mfn_to_page(maddr_to_mfn(maddr)); @@ -1445,13 +1452,9 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, { dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN %#"PRI_mfn"\n", v, mfn_x(maddr_to_mfn(maddr))); - page = NULL; + return NULL; } -err: - if ( !page && p2m->mem_access_enabled ) - page = p2m_mem_access_check_and_get_page(va, flags, v); - return page; } From patchwork Mon Jul 16 17:27:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142078 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677695ljj; Mon, 16 Jul 2018 10:29:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeMJ+Sd/Jf/xQiHSypIQr7MqopGSpYSiW+rAbZ8cKFpPwEF6SVdJzdO5XJxsUqJpm/dZfQ1 X-Received: by 2002:a24:4511:: with SMTP id y17-v6mr14220247ita.67.1531762181256; Mon, 16 Jul 2018 10:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762181; cv=none; d=google.com; s=arc-20160816; b=T5enJv/1M5Y9uGmeo6oIDmMY2xNWG4kKTLdIxwi5SesJTphIGbV9WH8iMR2g2xNoB4 QgQQSstuhxApsUNTKzRTAhYp9M/fomHGerveGABPfsBtWIJkMZN3Bz1nEd1PamQ7l0TR jUpJv3+ZIeubF1BNH7qNvHyBTBWgXC5IoF2OQOh3z82NweG+d+9xe8EhMudSUHzzj+MZ xEiS22gDYCWUcxdiMC7gTCHeJ+MHz5CAwmqd1pnGX6nNt7s4GIOwAnNsPKjTjEW897oy 0XnuAHBcdph1EoeiZ3Wv8nbPCMjKJJ+VcgwOxTMoPzpEHry6+vf5S55cNErK2lRYPoBp VZ3Q== 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=kwl3rfqgVAkbzitN1LSAn/ZnpgauZRzo+p5bYaT8Euw=; b=xRyoOjABU2t/Y522DOyjN+pU+zjbjPKJwQlwecwb8I4jv6W6PWvl2Yf0qSzcbFPTfl Z3gchd0of2ED8aamXY+rpgznFQnhCQBnhAaYeBbdN69+MpJtcPc/symNFiTR1CcWaM1o yC29Ks1E+gZ0XHJaOqDOdiAvhujV3SLG6JLZ6H/1YiNieGQFUT85DK8KeKtCSRi3467A JvuN4UtqEC8GXdtBXmu0pG3dcFWu4JI7fw771h9xoGjuswxEBRU+oSYjjVtiFrwJEuVZ izDIPGS0ij+6u6BqwaSkf+wa7iIyEFp2retCrGQJY/yGdR1cKH9IW3axvDaYkH9TORYT 6UaQ== 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 q14-v6si1161855itc.3.2018.07.16.10.29.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:41 -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 1ff7HT-0006Rn-Iz; Mon, 16 Jul 2018 17:27:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HT-0006RU-4B for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:27 +0000 X-Inumbo-ID: 87551e46-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 87551e46-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:35 +0000 (UTC) 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 AF1E07A9; Mon, 16 Jul 2018 10:27:25 -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 E880B3F5B1; Mon, 16 Jul 2018 10:27:24 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:03 +0100 Message-Id: <20180716172712.20294-7-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 06/15] xen/arm: Rework lpae_mapping 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, lpae_mapping can only work on entry from any level other than 3. Make it work with any level by extending the prototype to pass the level. At the same time, rename the function to lpae_is_mapping so naming stay consistent accross lpae_* helpers. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/p2m.c | 12 +++++++----- xen/include/asm-arm/lpae.h | 13 +++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ebf74760fa..72a84a33fd 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -241,7 +241,8 @@ static int p2m_create_table(struct p2m_domain *p2m, lpae_t *entry); * GUEST_TABLE_SUPER_PAGE: The next entry points to a superpage. */ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, - lpae_t **table, unsigned int offset) + unsigned int level, lpae_t **table, + unsigned int offset) { lpae_t *entry; int ret; @@ -260,7 +261,8 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, } /* The function p2m_next_level is never called at the 3rd level */ - if ( lpae_mapping(*entry) ) + ASSERT(level < 3); + if ( lpae_is_mapping(*entry, level) ) return GUEST_TABLE_SUPER_PAGE; mfn = _mfn(entry->p2m.base); @@ -331,7 +333,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, for ( level = P2M_ROOT_LEVEL; level < 3; level++ ) { - rc = p2m_next_level(p2m, true, &table, offsets[level]); + rc = p2m_next_level(p2m, true, level, &table, offsets[level]); if ( rc == GUEST_TABLE_MAP_FAILED ) goto out_unmap; else if ( rc != GUEST_TABLE_NORMAL_PAGE ) @@ -804,7 +806,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * is about to be removed (i.e mfn == INVALID_MFN). */ rc = p2m_next_level(p2m, mfn_eq(smfn, INVALID_MFN), - &table, offsets[level]); + level, &table, offsets[level]); if ( rc == GUEST_TABLE_MAP_FAILED ) { /* @@ -861,7 +863,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, /* then move to the level we want to make real changes */ for ( ; level < target; level++ ) { - rc = p2m_next_level(p2m, true, &table, offsets[level]); + rc = p2m_next_level(p2m, true, level, &table, offsets[level]); /* * The entry should be found and either be a table diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index b30853e79d..4cf188ff82 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -134,7 +134,7 @@ static inline bool lpae_valid(lpae_t pte) } /* - * These two can only be used on L0..L2 ptes because L3 mappings set + * This one can only be used on L0..L2 ptes because L3 mappings set * the table bit and therefore these would return the opposite to what * you would expect. */ @@ -143,14 +143,19 @@ static inline bool lpae_table(lpae_t pte) return lpae_valid(pte) && pte.walk.table; } -static inline bool lpae_mapping(lpae_t pte) +static inline bool lpae_is_mapping(lpae_t pte, unsigned int level) { - return lpae_valid(pte) && !pte.walk.table; + if ( !lpae_valid(pte) ) + return false; + else if ( level == 3 ) + return pte.walk.table; + else + return !pte.walk.table; } static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) { - return (level < 3) && lpae_mapping(pte); + return (level < 3) && lpae_is_mapping(pte, level); } static inline bool lpae_is_page(lpae_t pte, unsigned int level) From patchwork Mon Jul 16 17:27:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142072 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677568ljj; Mon, 16 Jul 2018 10:29:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe3sOqybWXErys/G7srKS4TN9AuDRXwFTBUR0/jbD+CzIOVWrEjGaBatR2TieDj45o8StuS X-Received: by 2002:a24:360b:: with SMTP id l11-v6mr14198455itl.42.1531762172499; Mon, 16 Jul 2018 10:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762172; cv=none; d=google.com; s=arc-20160816; b=RGEAs8MRjAdZEpBm78YrhUcy4CGUGzDtX95LDiqHyxgIo6I0YPzCYQlYtjg10aiqNX Sw3QLCRB/CypuK6f0vMRiEfzhwrQgytZDiWUHiSkGLcW9+R9jpfwhCF3TVqiVVNj24v+ fBDRHOuvWCCjG8HEsZXcQ8ONqRE2SUoJDlKPBeGFYX8RkwEG2ETTV+ojA9Lww6ZRUozz 4Sp9senF7lFnoEMkjwBxM3Dw9qE++jJNssP4jLeSwM8Piwl/t0TRW9vSb8iNBiuLYJrE /y8CUlFN3wyCR+U9nT7KZiZQVPs+pXtyzU3I+eTGLX2Mz7UdWOsOiZnAsE9m86G+8MEj 8SXA== 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=6bd/G95ckLOR40vWWOowT97PPtAESkPztTv/SpFtgNg=; b=y/Bjz0WXDwuinVWcW2p8SClFw3N9JRV3icxYB/NNAnSmD5VxhUzCy4yzkwkyBLKufI Herl2VyQlWA6bBSsxsIW8ilSrDLkUAyk3ZUs/a6hjFe/UQ2Y52TRXHE72jGEmdiSDIh8 dY2gK5V+7qtD6xPxIjfmde0A26sPABk9hjzMAC03b2iwNbZmL6kQZby4XE8I3/x7zHRA JX71tVyfcKd6BEssn62/+GjvRSIm/AZC30mMg9Tgr8X+hek52JNex/mcjrwlpyUyoNW8 bWrTa1FEzn/1ydE6QCJ/YKNbBm2oTZF3sks4N3aXHtr+9hWXMZsZIdPrlhNS33ZCw3n5 SA6Q== 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 x2-v6si22278888iof.146.2018.07.16.10.29.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:32 -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 1ff7HV-0006T0-Tr; Mon, 16 Jul 2018 17:27:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HU-0006Rv-9z for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:28 +0000 X-Inumbo-ID: 87eff18d-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 87eff18d-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:36 +0000 (UTC) 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 B33101650; Mon, 16 Jul 2018 10:27:26 -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 ECA603F5B1; Mon, 16 Jul 2018 10:27:25 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:04 +0100 Message-Id: <20180716172712.20294-8-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 07/15] xen/arm: Rework lpae_table 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, lpae_table can only work on entry from any level other than 3. Make it work with any level by extending the prototype to pass the level. At the same time, rename the function to lpae_is_mapping so naming stay consistent accross all lpae_* helpers. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/mm.c | 2 +- xen/include/asm-arm/lpae.h | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index d234c46e41..b7f2dabd05 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -996,7 +996,7 @@ static int create_xen_entries(enum xenmap_operation op, for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { entry = &xen_second[second_linear_offset(addr)]; - if ( !lpae_table(*entry) ) + if ( !lpae_is_table(*entry, 2) ) { rc = create_xen_table(entry); if ( rc < 0 ) { diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 4cf188ff82..c803569c2d 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -133,14 +133,9 @@ static inline bool lpae_valid(lpae_t pte) return pte.walk.valid; } -/* - * This one can only be used on L0..L2 ptes because L3 mappings set - * the table bit and therefore these would return the opposite to what - * you would expect. - */ -static inline bool lpae_table(lpae_t pte) +static inline bool lpae_is_table(lpae_t pte, unsigned int level) { - return lpae_valid(pte) && pte.walk.table; + return (level < 3) && lpae_valid(pte) && pte.walk.table; } static inline bool lpae_is_mapping(lpae_t pte, unsigned int level) From patchwork Mon Jul 16 17:27:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142075 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677677ljj; Mon, 16 Jul 2018 10:29:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpes2bwQoEWu+ygRkBjNKx5w8jfWtLAzW5srMSpNZkoyNwvBamn/VFqZ2RfA6AhiWxjmeO8R X-Received: by 2002:a24:b715:: with SMTP id h21-v6mr14138501itf.32.1531762179939; Mon, 16 Jul 2018 10:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762179; cv=none; d=google.com; s=arc-20160816; b=szde36ijSxRyWRzCsBvD4MiGlLrtC2KntZ88Ym+HjIOjtNlQiKZx2uQpQTrdxyW3pB cLMq8SO5RQ8L2yDsmYqjUNJAYS0PEfljUpcRKKJ7ziMh9zt3ntMP7ilifHCXuVNDwfWx ApXUueLaPQJwBLUHsGtv6rqVYjzmTY9vhgJk+RXFJ2i9liDZgWMWkxMkSebFl7nD3mRS fgz8yN2eJ6Vs5VO7tXHl+o6n2XosGyKEcwBxnNucoED2Hc9enaDJC1uK00E25mcgaBDc j7C8YFyJtnBUJjTYF+6n8GYbZowIwQru6PUuKL9MUJ3nOt0eQ3XaLTCLe7MK1I5/iyOc DFAA== 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=/JFp3D0uWWOI147H4mzZbrGA8WMyeuF3Zt/Lsh/J/sg=; b=rxZBvTTYTSDkuGIXDAYtX06MkFQKr4SLMsM2DINZmxOhynDaJPzhSyKH5kn3+81I9+ plHtI9kbG9yOrE5fEAAA2LHKuHZtCenaew+14Bu9HH1MxsA5WwPxmAoGt2oWaEdVjI6M hBOe27sUNU5Cm2KuSlO81Uk/0aXbt+m7ZDKGOgWjpNhpeCME+urljjxHctAVoRLWlKU0 f5WBaq1EDaOj41MGz/NNNXhsaPPrt4XAwuCWfLHgI7tj6Is/OqU9/tTAkGiVi2Sbo2Wb ec9bocKkNtUOcxt6ryoK/so1G99hgPJbzp2RmTH7kkbaIrDCxlk0QR40v3eMozakkGf4 BDsw== 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 k9-v6si16766918iop.135.2018.07.16.10.29.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:39 -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 1ff7HX-0006Ul-7a; Mon, 16 Jul 2018 17:27:31 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HV-0006SY-8b for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:29 +0000 X-Inumbo-ID: 77568929-891d-11e8-a8a5-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 77568929-891d-11e8-a8a5-bc764e045a96; Mon, 16 Jul 2018 19:27:08 +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 B7B0715AD; Mon, 16 Jul 2018 10:27:27 -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 F128C3F5B1; Mon, 16 Jul 2018 10:27:26 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:05 +0100 Message-Id: <20180716172712.20294-9-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 08/15] xen/arm: Rename lpae_valid to lpae_is_valid 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This will help to keep the naming consistent accross all lpae helpers. No functional change intended. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/guest_walk.c | 2 +- xen/arch/arm/mm.c | 6 +++--- xen/arch/arm/p2m.c | 20 ++++++++++---------- xen/include/asm-arm/lpae.h | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c index 4d1ea0cdc1..a7c7e05603 100644 --- a/xen/arch/arm/guest_walk.c +++ b/xen/arch/arm/guest_walk.c @@ -546,7 +546,7 @@ static int guest_walk_ld(const struct vcpu *v, * - The PTE is not valid. * - If (level < 3) and the PTE is valid, we found a block descriptor. */ - if ( level == 3 || !lpae_valid(pte) || lpae_is_superpage(pte, level) ) + if ( level == 3 || !lpae_is_valid(pte) || lpae_is_superpage(pte, level) ) break; /* diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b7f2dabd05..de9b965d2f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1005,7 +1005,7 @@ static int create_xen_entries(enum xenmap_operation op, } } - BUG_ON(!lpae_valid(*entry)); + BUG_ON(!lpae_is_valid(*entry)); third = __mfn_to_virt(entry->pt.base); entry = &third[third_table_offset(addr)]; @@ -1013,7 +1013,7 @@ static int create_xen_entries(enum xenmap_operation op, switch ( op ) { case INSERT: case RESERVE: - if ( lpae_valid(*entry) ) + if ( lpae_is_valid(*entry) ) { printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n", __func__, addr, mfn_x(mfn)); @@ -1030,7 +1030,7 @@ static int create_xen_entries(enum xenmap_operation op, break; case MODIFY: case REMOVE: - if ( !lpae_valid(*entry) ) + if ( !lpae_is_valid(*entry) ) { printk("%s: trying to %s a non-existing mapping addr=%lx\n", __func__, op == REMOVE ? "remove" : "modify", addr); diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 72a84a33fd..a80ac301c5 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -250,7 +250,7 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, entry = *table + offset; - if ( !lpae_valid(*entry) ) + if ( !lpae_is_valid(*entry) ) { if ( read_only ) return GUEST_TABLE_MAP_FAILED; @@ -342,7 +342,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, entry = table[offsets[level]]; - if ( lpae_valid(entry) ) + if ( lpae_is_valid(entry) ) { *t = entry.p2m.type; @@ -546,7 +546,7 @@ static int p2m_create_table(struct p2m_domain *p2m, lpae_t *entry) lpae_t *p; lpae_t pte; - ASSERT(!lpae_valid(*entry)); + ASSERT(!lpae_is_valid(*entry)); page = alloc_domheap_page(NULL, 0); if ( page == NULL ) @@ -610,7 +610,7 @@ static int p2m_mem_access_radix_set(struct p2m_domain *p2m, gfn_t gfn, */ static void p2m_put_l3_page(const lpae_t pte) { - ASSERT(lpae_valid(pte)); + ASSERT(lpae_is_valid(pte)); /* * TODO: Handle other p2m types @@ -638,7 +638,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, struct page_info *pg; /* Nothing to do if the entry is invalid. */ - if ( !lpae_valid(entry) ) + if ( !lpae_is_valid(entry) ) return; /* Nothing to do but updating the stats if the entry is a super-page. */ @@ -908,12 +908,12 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * sequence when updating the translation table (D4.7.1 in ARM DDI * 0487A.j). */ - if ( lpae_valid(orig_pte) ) + if ( lpae_is_valid(orig_pte) ) p2m_remove_pte(entry, p2m->clean_pte); if ( mfn_eq(smfn, INVALID_MFN) ) /* Flush can be deferred if the entry is removed */ - p2m->need_flush |= !!lpae_valid(orig_pte); + p2m->need_flush |= !!lpae_is_valid(orig_pte); else { lpae_t pte = mfn_to_p2m_entry(smfn, t, a); @@ -928,7 +928,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * Although, it could be defered when only the permissions are * changed (e.g in case of memaccess). */ - if ( lpae_valid(orig_pte) ) + if ( lpae_is_valid(orig_pte) ) { if ( likely(!p2m->mem_access_enabled) || P2M_CLEAR_PERM(pte) != P2M_CLEAR_PERM(orig_pte) ) @@ -950,11 +950,11 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * Free the entry only if the original pte was valid and the base * is different (to avoid freeing when permission is changed). */ - if ( lpae_valid(orig_pte) && entry->p2m.base != orig_pte.p2m.base ) + if ( lpae_is_valid(orig_pte) && entry->p2m.base != orig_pte.p2m.base ) p2m_free_entry(p2m, orig_pte, level); if ( need_iommu(p2m->domain) && - (lpae_valid(orig_pte) || lpae_valid(*entry)) ) + (lpae_is_valid(orig_pte) || lpae_is_valid(*entry)) ) rc = iommu_iotlb_flush(p2m->domain, gfn_x(sgfn), 1UL << page_order); else rc = 0; diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index c803569c2d..1d86020d07 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -128,19 +128,19 @@ typedef union { lpae_walk_t walk; } lpae_t; -static inline bool lpae_valid(lpae_t pte) +static inline bool lpae_is_valid(lpae_t pte) { return pte.walk.valid; } static inline bool lpae_is_table(lpae_t pte, unsigned int level) { - return (level < 3) && lpae_valid(pte) && pte.walk.table; + return (level < 3) && lpae_is_valid(pte) && pte.walk.table; } static inline bool lpae_is_mapping(lpae_t pte, unsigned int level) { - if ( !lpae_valid(pte) ) + if ( !lpae_is_valid(pte) ) return false; else if ( level == 3 ) return pte.walk.table; @@ -155,7 +155,7 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) static inline bool lpae_is_page(lpae_t pte, unsigned int level) { - return (level == 3) && lpae_valid(pte) && pte.walk.table; + return (level == 3) && lpae_is_valid(pte) && pte.walk.table; } /* From patchwork Mon Jul 16 17:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142074 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677615ljj; Mon, 16 Jul 2018 10:29:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpepYm7zoCnlMsSYKqRxYUZVzxojQmDIhmBjDSQwzmjzNeVzhLszpXP+Dfwjkf6fg9Iv5Jk7 X-Received: by 2002:a6b:7a05:: with SMTP id h5-v6mr26121911iom.238.1531762175864; Mon, 16 Jul 2018 10:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762175; cv=none; d=google.com; s=arc-20160816; b=IGokLtUGLLQ83S6N+7zP2q8KnYH6f89beqgxJiU/NcyNIT5VU/Ric7hihb+rKnYoGA vi73r4XoEMk4//3qFWHzOQMkEBxEt1iAl5rUs+EKD9+VVnlYogQxS8f08N8Nx9sCbuXj l4V1me+E3SBz5TKkPpGVe5+CS2gRrYZxZ0MpGKYsnblqE6j4ORghdh/sDKSzHmn+XKG3 Wg7k45us+dvQWOUh8cvPzVtYxpykYT0jA7306OpY47LQdHBl0rGbt4VQz2iz3MF0emMz R07UiEwg6FwzcGnAQqCKY44TUwCJjRuBBf4ZbTFjRCdf38ZKy6dMAt6iSWQbpYuXPUuf X98w== 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=HfHOj1wVOCuL4k6ZdCkorgxPB0D6nPvWL1eY22znD+g=; b=c8nBUJVzziAlDPg/6+Qgi8nGl10KQ1ZW9d5/D7xS2/Hb97j5E1TxmGbxIFheHPCetU 6p2PGpEanOibPM52rUszPKml+NbZ3SvGJvkAIyIQ6DWEd0unQQOPcYgaOSqQvXAoDOzs /c/AHoTG4tib0Ha5alu+dnNpDBoDf0q0xPjtxZo/p4X9r5BQGE4jyu1jaKyUlhJzqDcY a/oAXvpW7Ji/dZV4QTd5DS68uB545vcHzDnN3Wek9hAXx/QCPjL+yHD0sWcRfZTtSndB zmfbEgwK47gfAhaNZG30end39aOcDOwH1UHxtc003He8fqpwLhkkuy4+Enw8N4Bhrj48 qMHA== 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 s47-v6si9335465ite.123.2018.07.16.10.29.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:35 -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 1ff7HX-0006V9-JE; Mon, 16 Jul 2018 17:27:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HV-0006Sj-Fn for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:29 +0000 X-Inumbo-ID: 8926adef-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 8926adef-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:38 +0000 (UTC) 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 BC7907A9; Mon, 16 Jul 2018 10:27:28 -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 01AEA3F5B1; Mon, 16 Jul 2018 10:27:27 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:06 +0100 Message-Id: <20180716172712.20294-10-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 09/15] xen/arm: guest_walk: Use lpae_is_mapping to simplify the code 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" !lpae_is_page(pte, level) && !lpae_is_superpage(pte, level) is equivalent to !lpae_is_mapping(pte, level). At the same time drop lpae_is_page(pte, level) that is now unused. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/guest_walk.c | 2 +- xen/include/asm-arm/lpae.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c index a7c7e05603..e3e21bdad3 100644 --- a/xen/arch/arm/guest_walk.c +++ b/xen/arch/arm/guest_walk.c @@ -566,7 +566,7 @@ static int guest_walk_ld(const struct vcpu *v, * PTE is invalid or holds a reserved entry (PTE<1:0> == x0)) or if the PTE * maps a memory block at level 3 (PTE<1:0> == 01). */ - if ( !lpae_is_page(pte, level) && !lpae_is_superpage(pte, level) ) + if ( !lpae_is_mapping(pte, level) ) return -EFAULT; /* Make sure that the lower bits of the PTE's base address are zero. */ diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 1d86020d07..15595cd35c 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -153,11 +153,6 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) return (level < 3) && lpae_is_mapping(pte, level); } -static inline bool lpae_is_page(lpae_t pte, unsigned int level) -{ - return (level == 3) && lpae_is_valid(pte) && pte.walk.table; -} - /* * AArch64 supports pages with different sizes (4K, 16K, and 64K). To enable * page table walks for various configurations, the following helpers enable From patchwork Mon Jul 16 17:27:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142076 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677682ljj; Mon, 16 Jul 2018 10:29:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdUGvpZ1bIKN9lMJDR7QghQ6UIEddDZV0MnjhYTVR+Pp49HBIvRPH1of9gHLIC8yONK+po/ X-Received: by 2002:a6b:f814:: with SMTP id o20-v6mr22737835ioh.139.1531762180125; Mon, 16 Jul 2018 10:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762180; cv=none; d=google.com; s=arc-20160816; b=SfzPRAYbemMhs2H5RnNb6TcuaaF848E7MnpOtgPTroRRH3r3xYCfz+PWRudE0t+INQ vLBcQdyw+3OC/s82lSjDfhckvSpycBsaYddrc7NReO5adASrO74Kcj/tBJ5JMwQRWi7X /rvMs6+4L/Wk7+6L/CZ2zJ/QQ6XxPSvaGHEhEcS3XboGRCHPQ8tSB7Ef2uY2BIJp2kuK XRWCNEHazy+Xbya7Y516GwIzk4jRF8ahhnQVeGNiyvmHjQyF8Xgq49JuY7Igz3zX+ZA3 EbtNUwtJJYdh8XGsCMREgXChPw4Kcj0yn8uqwZI8vC38GdRuW2Dd9AabMsmTA9+m67Pi 0R5Q== 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=6ZnxcEDRQ8UqNAfSZoBwugGOe+9eANivJe+0kjXFdOM=; b=sud9zORUC+kvdA4T/CIOBVRDEJcdsF6zU4IGiEy0f7F8Ws/eeVY1dztkOP/yoIP19r 7iuUPq4dTgqDOl/M/cxUxmH0HjnaOKD5JCs053PQU0EvkkavMCSWGrRf8wF5KYWhabhO Ix0xVv3DSYbeLiYOPzQX/SYWG0xr13VeMrSW1SD75Oc88xHQHX8bw0gYWDnKtHdLvAkp wgfWaIJ1LhVJAQ63u18w7vYaWaNk8/RZ/Y+LmUlJPe76T0rZRwAY/mPi/sM6E/SvTsJp mLlYIJHZ0n/+yVmK2YzsWeDkHUfTW/M9O1+rs1RRdYk+YAWDiyN5F4jj2PwH6fMaLIX/ FRPg== 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 l18-v6si7091395jak.48.2018.07.16.10.29.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:40 -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 1ff7HX-0006Vi-Uy; Mon, 16 Jul 2018 17:27:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HW-0006TN-LP for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:30 +0000 X-Inumbo-ID: 89c2866e-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 89c2866e-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:39 +0000 (UTC) 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 C11F015AD; Mon, 16 Jul 2018 10:27:29 -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 066263F5B1; Mon, 16 Jul 2018 10:27:28 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:07 +0100 Message-Id: <20180716172712.20294-11-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 10/15] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The new helpers make easier to read the code by abstracting the way to set/get an MFN from/to an LPAE entry. The helpers is using "walk" as the bits are common for accross different LPAE stage. At the same time, use the new helpers to replace the various open-coding place. Signed-off-by: Julien Grall --- xen/arch/arm/mm.c | 10 +++++----- xen/arch/arm/p2m.c | 19 ++++++++++--------- xen/include/asm-arm/lpae.h | 3 +++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index de9b965d2f..e3dafe5fd7 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -238,7 +238,7 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, /* For next iteration */ unmap_domain_page(mapping); - mapping = map_domain_page(_mfn(pte.walk.base)); + mapping = map_domain_page(lpae_to_mfn(pte)); } unmap_domain_page(mapping); @@ -323,7 +323,7 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) ASSERT(!(mfn_to_maddr(mfn) & ~PADDR_MASK)); - e.pt.base = mfn_x(mfn); + lpae_set_mfn(e, mfn); return e; } @@ -490,7 +490,7 @@ mfn_t domain_page_map_to_mfn(const void *ptr) ASSERT(slot >= 0 && slot < DOMHEAP_ENTRIES); ASSERT(map[slot].pt.avail != 0); - return _mfn(map[slot].pt.base + offset); + return mfn_add(lpae_to_mfn(map[slot]), offset); } #endif @@ -851,7 +851,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, /* mfn_to_virt is not valid on the 1st 1st mfn, since it * is not within the xenheap. */ first = slot == xenheap_first_first_slot ? - xenheap_first_first : __mfn_to_virt(p->pt.base); + xenheap_first_first : mfn_to_virt(lpae_to_mfn(*p)); } else if ( xenheap_first_first_slot == -1) { @@ -1007,7 +1007,7 @@ static int create_xen_entries(enum xenmap_operation op, BUG_ON(!lpae_is_valid(*entry)); - third = __mfn_to_virt(entry->pt.base); + third = mfn_to_virt(lpae_to_mfn(*entry)); entry = &third[third_table_offset(addr)]; switch ( op ) { diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index a80ac301c5..ec3fdcb554 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -265,7 +265,7 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, if ( lpae_is_mapping(*entry, level) ) return GUEST_TABLE_SUPER_PAGE; - mfn = _mfn(entry->p2m.base); + mfn = lpae_to_mfn(*entry); unmap_domain_page(*table); *table = map_domain_page(mfn); @@ -349,7 +349,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, if ( a ) *a = p2m_mem_access_radix_get(p2m, gfn); - mfn = _mfn(entry.p2m.base); + mfn = lpae_to_mfn(entry); /* * The entry may point to a superpage. Find the MFN associated * to the GFN. @@ -519,7 +519,7 @@ static lpae_t mfn_to_p2m_entry(mfn_t mfn, p2m_type_t t, p2m_access_t a) ASSERT(!(mfn_to_maddr(mfn) & ~PADDR_MASK)); - e.p2m.base = mfn_x(mfn); + lpae_set_mfn(e, mfn); return e; } @@ -621,7 +621,7 @@ static void p2m_put_l3_page(const lpae_t pte) */ if ( p2m_is_foreign(pte.p2m.type) ) { - mfn_t mfn = _mfn(pte.p2m.base); + mfn_t mfn = lpae_to_mfn(pte); ASSERT(mfn_valid(mfn)); put_page(mfn_to_page(mfn)); @@ -655,7 +655,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, return; } - table = map_domain_page(_mfn(entry.p2m.base)); + table = map_domain_page(lpae_to_mfn(entry)); for ( i = 0; i < LPAE_ENTRIES; i++ ) p2m_free_entry(p2m, *(table + i), level + 1); @@ -669,7 +669,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, */ p2m_tlb_flush_sync(p2m); - mfn = _mfn(entry.p2m.base); + mfn = lpae_to_mfn(entry); ASSERT(mfn_valid(mfn)); pg = mfn_to_page(mfn); @@ -688,7 +688,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, bool rv = true; /* Convenience aliases */ - mfn_t mfn = _mfn(entry->p2m.base); + mfn_t mfn = lpae_to_mfn(*entry); unsigned int next_level = level + 1; unsigned int level_order = level_orders[next_level]; @@ -719,7 +719,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, * the necessary fields. So the correct permission are kept. */ pte = *entry; - pte.p2m.base = mfn_x(mfn_add(mfn, i << level_order)); + lpae_set_mfn(pte, mfn_add(mfn, i << level_order)); /* * First and second level pages set p2m.table = 0, but third @@ -950,7 +950,8 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * Free the entry only if the original pte was valid and the base * is different (to avoid freeing when permission is changed). */ - if ( lpae_is_valid(orig_pte) && entry->p2m.base != orig_pte.p2m.base ) + if ( lpae_is_valid(orig_pte) && + !mfn_eq(lpae_to_mfn(*entry), lpae_to_mfn(orig_pte)) ) p2m_free_entry(p2m, orig_pte, level); if ( need_iommu(p2m->domain) && diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 15595cd35c..05c87a8f48 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -153,6 +153,9 @@ static inline bool lpae_is_superpage(lpae_t pte, unsigned int level) return (level < 3) && lpae_is_mapping(pte, level); } +#define lpae_to_mfn(pte) (_mfn((pte).walk.base)) +#define lpae_set_mfn(pte, mfn) ((pte).walk.base = mfn_x(mfn)) + /* * AArch64 supports pages with different sizes (4K, 16K, and 64K). To enable * page table walks for various configurations, the following helpers enable From patchwork Mon Jul 16 17:27:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142080 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677785ljj; Mon, 16 Jul 2018 10:29:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpevJDDB+6fSyUzypB/8/UTFugwykKY+G9zdv+XggMDfKk2ZkkCpJzty3TZGYsFHKva5LyqK X-Received: by 2002:a24:64d6:: with SMTP id t205-v6mr13489922itc.138.1531762185708; Mon, 16 Jul 2018 10:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762185; cv=none; d=google.com; s=arc-20160816; b=vhcZso6r07iNLD/uGJpeb0muwfE69HQTuoe/FaX9Y8vmEFQk2ZZ8QUIBZ1UeXYEftJ qlee/lFZNH/AVXKHJdQbBwY32qmpFRoyRWhfhEpHhxNdMQZXo0E33rJDTUO0byrb8Qvv +tDEyn3D+qDNM6lw7H6QJRawB1/WPR9OU7bObErV8YuM4eBx2PkocaZ8bWDMyvjDuV6D k4klj33/nl+Wbem0AWV9AUkjYjedVALy26lT78krkiBdg3KxxF6CI9kRWEL/sbcq9m7n NCuew4993B8bJKDJKvbv6uYXSQOwFcF0Yw521fcZ/Mz7b5E52+fWoNdLZXJ6c96A1pcP +u2g== 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=FdrzFf4UqAsRHqfEsJ1MOYPjMGx27P/QSPXV1ynjhF8=; b=OOl3LOvxJg3kNUse8P8ZdbH5CbQXYSx+TU9FJpaGyYW8fsQ771ZUyz09NMCRvxXmvE YYe0I+smFbVniwp66ilpr6S4oyI2ifHK1CzfoZ78220XKVN8CRHGRY7MGvcl8Sred3kL zXm2bzhpH1ac5nqBApoyF332cHEbk6NVf1+qi2v4GZewQ7qwVm/eyraGN2Kkneoa5spA b5BMLxxiYqEf7kvULOdlefTKzrdfbnvfQYP3S8XBOaWrn2FiMjGUrW9W86hmJToEgiYj U7lDnJ+IRzcgUe+WwkLjzO3t2vkdRvL+JcBzhT7agbBwJ0l7VR7sPpFJWDa0efQ/i0gC h5JA== 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 g15-v6si9911701itf.85.2018.07.16.10.29.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:45 -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 1ff7HZ-0006XR-9r; Mon, 16 Jul 2018 17:27:33 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HY-0006Vs-4W for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:32 +0000 X-Inumbo-ID: 8a5dcb62-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 8a5dcb62-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:40 +0000 (UTC) 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 C60237A9; Mon, 16 Jul 2018 10:27:30 -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 0B3753F5B1; Mon, 16 Jul 2018 10:27:29 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:08 +0100 Message-Id: <20180716172712.20294-12-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 11/15] xen/arm: Allow lpae_is_{table, mapping} helpers to work on invalid entry 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, lpae_is_{table, mapping} helpers will always return false on entry with the valid bit unset. However, it would be useful to have them operating on any entry. For instance to store information in advance but still request a fault. With that change, the p2m is now providing an overlay for *_is_{table, mapping} that will check the valid bit of the entry. Signed-off-by: Julien Grall --- xen/arch/arm/guest_walk.c | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/arm/p2m.c | 22 ++++++++++++++++++---- xen/include/asm-arm/lpae.h | 11 +++++++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c index e3e21bdad3..4a1b4cf2c8 100644 --- a/xen/arch/arm/guest_walk.c +++ b/xen/arch/arm/guest_walk.c @@ -566,7 +566,7 @@ static int guest_walk_ld(const struct vcpu *v, * PTE is invalid or holds a reserved entry (PTE<1:0> == x0)) or if the PTE * maps a memory block at level 3 (PTE<1:0> == 01). */ - if ( !lpae_is_mapping(pte, level) ) + if ( !lpae_is_valid(pte) || !lpae_is_mapping(pte, level) ) return -EFAULT; /* Make sure that the lower bits of the PTE's base address are zero. */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index e3dafe5fd7..52e57fef2f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -996,7 +996,7 @@ static int create_xen_entries(enum xenmap_operation op, for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1)) { entry = &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_table(*entry, 2) ) + if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) { rc = create_xen_table(entry); if ( rc < 0 ) { diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index ec3fdcb554..07925a1be4 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -219,6 +219,20 @@ static p2m_access_t p2m_mem_access_radix_get(struct p2m_domain *p2m, gfn_t gfn) return radix_tree_ptr_to_int(ptr); } +/* + * lpae_is_* helpers don't check whether the valid bit is set in the + * PTE. Provide our own overlay to check the valid bit. + */ +static inline bool p2m_is_mapping(lpae_t pte, unsigned int level) +{ + return lpae_is_valid(pte) && lpae_is_mapping(pte, level); +} + +static inline bool p2m_is_superpage(lpae_t pte, unsigned int level) +{ + return lpae_is_valid(pte) && lpae_is_superpage(pte, level); +} + #define GUEST_TABLE_MAP_FAILED 0 #define GUEST_TABLE_SUPER_PAGE 1 #define GUEST_TABLE_NORMAL_PAGE 2 @@ -262,7 +276,7 @@ static int p2m_next_level(struct p2m_domain *p2m, bool read_only, /* The function p2m_next_level is never called at the 3rd level */ ASSERT(level < 3); - if ( lpae_is_mapping(*entry, level) ) + if ( p2m_is_mapping(*entry, level) ) return GUEST_TABLE_SUPER_PAGE; mfn = lpae_to_mfn(*entry); @@ -642,7 +656,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, return; /* Nothing to do but updating the stats if the entry is a super-page. */ - if ( lpae_is_superpage(entry, level) ) + if ( p2m_is_superpage(entry, level) ) { p2m->stats.mappings[level]--; return; @@ -697,7 +711,7 @@ static bool p2m_split_superpage(struct p2m_domain *p2m, lpae_t *entry, * a superpage. */ ASSERT(level < target); - ASSERT(lpae_is_superpage(*entry, level)); + ASSERT(p2m_is_superpage(*entry, level)); page = alloc_domheap_page(NULL, 0); if ( !page ) @@ -834,7 +848,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, /* We need to split the original page. */ lpae_t split_pte = *entry; - ASSERT(lpae_is_superpage(*entry, level)); + ASSERT(p2m_is_superpage(*entry, level)); if ( !p2m_split_superpage(p2m, &split_pte, level, target, offsets) ) { diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 05c87a8f48..88f30fc917 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -133,16 +133,19 @@ static inline bool lpae_is_valid(lpae_t pte) return pte.walk.valid; } +/* + * lpae_is_* don't check the valid bit. This gives an opportunity for the + * callers to operate on the entry even if they are not valid. For + * instance to store information in advance. + */ static inline bool lpae_is_table(lpae_t pte, unsigned int level) { - return (level < 3) && lpae_is_valid(pte) && pte.walk.table; + return (level < 3) && pte.walk.table; } static inline bool lpae_is_mapping(lpae_t pte, unsigned int level) { - if ( !lpae_is_valid(pte) ) - return false; - else if ( level == 3 ) + if ( level == 3 ) return pte.walk.table; else return !pte.walk.table; From patchwork Mon Jul 16 17:27:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142084 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677808ljj; Mon, 16 Jul 2018 10:29:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeR52yUwhGyp8YpAw5AS74+JsB8phZHYvvHMwx5mz6VlRfrxsqDqJUFIzS1T87FodSWcEkQ X-Received: by 2002:a24:53c3:: with SMTP id n186-v6mr13220240itb.11.1531762187067; Mon, 16 Jul 2018 10:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762187; cv=none; d=google.com; s=arc-20160816; b=h6DYzGRriZA5XNyr2xu8Fo3TUv16NXjw1xSE3OXURhXY9aph5r0JgdOVtYS5TzXsbg kbJPX+1elj6j1LUlJVdUTAWqTrEPOPWpBwqoAbwhP0Q5dqdrWkv05m4WDAHGA8UNfPIv eCOvbT+k6hCdpN8m2Ke1IpBA+mBlLSZqAKc1bs/Vef3Am3NHx/AC6hqh02f/fqkvN5eo LJjNqT+hqql7WI1OFEsCy00eTkF6qMc8nakE3teVnCf9GbOqlnkR2YZXa50fgjo4gA4H KtrXgAar89SLbZnQPzuwzMePf2TPw70FlFmuJhHl7cXt3aZ4Yq7vDEXLolmFWlSPr6bT V06w== 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=oRqg2+0k7BsPP0trlWmCgIMiIABYx7Vk6B5dmwr6eSE=; b=TEaqochdu1WyDSy1Dj7oC2pip6y4/tGyTFrvHOYaCcgIxXXdWo+vIGApD9nbPj7spq mcQG6ettOrpuMNC30FZtNDCHeegd7gfStehX+t9gdOkJgSWb+ZTq6HFFaJPOgTND+jEN /jS2k+OjMGODycvHTlI2I+GHDlPYlf2Qcbuw5+QOiMV1uvacziSUU6Jf/xXEgJmf3L0g zxz60iyOl5vKX4k9td+3Q+a9J4ubrMA1nabkeqiXGUawE6En9eN5ZAAfh1M8986B9OzI n/KMxbzZfVeAVuC4g+1IS/x2NhxgwSYRp6uehwTLutDzTR7AuFKIrLcd6smmNIrj97TW iA3A== 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 a26-v6si11646990jab.80.2018.07.16.10.29.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:46 -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 1ff7Ha-0006a1-RZ; Mon, 16 Jul 2018 17:27:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7HZ-0006XN-A4 for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:33 +0000 X-Inumbo-ID: 8b0f7402-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 8b0f7402-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:41 +0000 (UTC) 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 EDF1315AD; Mon, 16 Jul 2018 10:27:31 -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 100A73F5B1; Mon, 16 Jul 2018 10:27:30 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:09 +0100 Message-Id: <20180716172712.20294-13-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 12/15] xen/arm: p2m: Rename ret to mfn in p2m_lookup 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" Comestic change to make clearer what is the return ('ret' is a bit too generic). Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- xen/arch/arm/p2m.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 07925a1be4..66d58fabd7 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -383,14 +383,14 @@ out: mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t) { - mfn_t ret; + mfn_t mfn; struct p2m_domain *p2m = p2m_get_hostp2m(d); p2m_read_lock(p2m); - ret = p2m_get_entry(p2m, gfn, t, NULL, NULL); + mfn = p2m_get_entry(p2m, gfn, t, NULL, NULL); p2m_read_unlock(p2m); - return ret; + return mfn; } int guest_physmap_mark_populate_on_demand(struct domain *d, From patchwork Mon Jul 16 17:27:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142081 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677792ljj; Mon, 16 Jul 2018 10:29:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdCgZjy+x8/aYXL+FI+dpLK5tiPk1MIZ6RRbGxQ0OAscgxmWQof3VTOY71wswQNYKlE6N5k X-Received: by 2002:a24:35c8:: with SMTP id k191-v6mr13181690ita.81.1531762186106; Mon, 16 Jul 2018 10:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762186; cv=none; d=google.com; s=arc-20160816; b=ybuRaY/mhSUz40mSjaIb4fSDEWQxzRZ/7TCmdCAE0FbnpE74xAevdeR1a+k/oP29bP JKEQjETUB68Vncj7zQ/OriuyK/wBhOLxTyUn/Yz5XomhcX4rSITEO+zM2YU5Ao1aHBrN O9RRB0cFTUQBgIq5vv51yYDJFqx35JemI1qqwrCpd4G2pzmJniH2qbgwaT5S8CcY1gyc G9/ME1WdnMf4ZEc5yMfcLTysCtgCo/C7gkJD+KwUvHQ1MSPY0t2FVdfU/ITZMzEYhHf3 I0Y3ZQqELo0/S4YdqnN382CIaBjsyejATczVXIh+Y8D2x8g6OHoJlK2ZS4Y9SygJlJ43 /K1w== 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=czJe+kh95aFFHjXNvnM9u2HDL9cTRVYjGSZzs3Vj+3A=; b=BulTaTvGp7wR+excZ7lEzlmobr91ErtIpSSSm4LdfpjnJio65D0LIq0NlAA2hzlkd1 11wbuyKF6xTnQ/QTGszzTXw1U5z6PB89ZU9sCD/hCA2I5zBIWqVwFGmBvhg0TeJS2P7/ JzadPdYmNfNxiUA/S1DzLPdx6AqavseCmCtAMwrLl+5iOqFo5FDAN1qTsq5urwpZ8ehb RvjDJiNQsf1w2HI67jq0zCgdN1zLoI7ydgs3o7ybKbk4MQwuG9718vtpCPf+kFdoYT7H nRFDqWm++gpPgDamq7zdAYltWK7AwzIhBjqHdIOk3BLq3pI6lVt07RA+zQY2KIrAEVoY ZufQ== 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 l2-v6si7141771jam.126.2018.07.16.10.29.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:46 -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 1ff7Hc-0006bz-8b; Mon, 16 Jul 2018 17:27:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7Ha-0006Z5-FI for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:34 +0000 X-Inumbo-ID: 8bc22178-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 8bc22178-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:42 +0000 (UTC) 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 22B5B1650; Mon, 16 Jul 2018 10:27:33 -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 37D463F5B1; Mon, 16 Jul 2018 10:27:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:10 +0100 Message-Id: <20180716172712.20294-14-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 13/15] xen/arm: p2m: Introduce a new variable removing_mapping in __p2m_set_entry 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" This is making the code slightly easier to understand. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/p2m.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 66d58fabd7..e826f57842 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -792,6 +792,8 @@ static int __p2m_set_entry(struct p2m_domain *p2m, unsigned int target = 3 - (page_order / LPAE_SHIFT); lpae_t *entry, *table, orig_pte; int rc; + /* A mapping is removed if the MFN is invalid. */ + bool removing_mapping = mfn_eq(smfn, INVALID_MFN); /* Convenience aliases */ const unsigned int offsets[4] = { @@ -817,9 +819,9 @@ static int __p2m_set_entry(struct p2m_domain *p2m, { /* * Don't try to allocate intermediate page table if the mapping - * is about to be removed (i.e mfn == INVALID_MFN). + * is about to be removed. */ - rc = p2m_next_level(p2m, mfn_eq(smfn, INVALID_MFN), + rc = p2m_next_level(p2m, removing_mapping, level, &table, offsets[level]); if ( rc == GUEST_TABLE_MAP_FAILED ) { @@ -830,7 +832,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * when removing a mapping as it may not exist in the * page table. In this case, just ignore it. */ - rc = mfn_eq(smfn, INVALID_MFN) ? 0 : -ENOENT; + rc = removing_mapping ? 0 : -ENOENT; goto out; } else if ( rc != GUEST_TABLE_NORMAL_PAGE ) @@ -925,7 +927,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, if ( lpae_is_valid(orig_pte) ) p2m_remove_pte(entry, p2m->clean_pte); - if ( mfn_eq(smfn, INVALID_MFN) ) + if ( removing_mapping ) /* Flush can be deferred if the entry is removed */ p2m->need_flush |= !!lpae_is_valid(orig_pte); else 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 */ From patchwork Mon Jul 16 17:27:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 142082 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2677793ljj; Mon, 16 Jul 2018 10:29:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeqd+VQSSNsmzVmO58YAFyo3acEOTNklBVL0ZpaF32xarNkVlzOFoWJykWV8HEdMTWZCNu9 X-Received: by 2002:a24:d442:: with SMTP id x63-v6mr14196568itg.152.1531762186203; Mon, 16 Jul 2018 10:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531762186; cv=none; d=google.com; s=arc-20160816; b=hdVB0g3cn/AmUrtSkiCZrLtSW5RYxinKj0o7Jg83PyIUAdZAQFrkocq5TVQEpaPl9m q6IaFa76KkfU/sRkONUPc5msnAwcn3Y8MSnlqKiZltHw13fmOmy9A6d10wyr3XgkJ4T+ GVrXVJ94oAULFPVHZGuRv6X0UAZUlDIVDWnDigBEX4xQ44TObAlWWdV/8YK7eTesQGoC MTbvv9Ls37BTgK1Xs2DNympzg55VqaQHy2619Teactci240A95IQg6Y4RKTGOlLWqxUr 6QjeGx9IIHfAqqvNJPgaj4OWoFedimSNXdp9BsqmVNQRqX+2DQFfq1ZdQeZNdliQHrey 33qw== 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=j4VYrY5Ycp4iAWoKC7XLiqjnlAUNk9Pm224+VzH/F4c=; b=E/sh7+rQNAcPrui+6VjQEu76HWux5J+Cug4RnLDLzTdhivqZ2iiQuNEWQNJWAbvioL rEfA1yDMJkym94SviElVP+jo6uQOxlNLNGplhqlAiN/I/PQ8paoRrZn+gtLVcLJ2KmVO rk6mBvhrFLN6ClJ+vY1joqZ8bEQtRdjeLHrke+FPcI9dFZYA4w8IcR+xZMaFBZCbZr4+ K+Ut1MqXy4pNacrYGRTq7SHq9GjVzIHWMQYlHkdS4b6VjvNpczm0iOHPUM7dQ6KCmi5U gMoHf/XEG3TjMs6ebsXelO8XQ3anaeDSXfcwoSMo2G8qLRIe9p3XssRtgbICLjHyj95R uBcA== 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 94-v6si24577766iod.67.2018.07.16.10.29.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 10:29:46 -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 1ff7He-0006ee-2t; Mon, 16 Jul 2018 17:27:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ff7Hc-0006cS-Ml for xen-devel@lists.xenproject.org; Mon, 16 Jul 2018 17:27:36 +0000 X-Inumbo-ID: 8d3ad9f9-891d-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 8d3ad9f9-891d-11e8-a6a9-d7ebe60f679a; Mon, 16 Jul 2018 17:27:45 +0000 (UTC) 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 950BF15AD; Mon, 16 Jul 2018 10:27:35 -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 AB1453F5B1; Mon, 16 Jul 2018 10:27:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jul 2018 18:27:12 +0100 Message-Id: <20180716172712.20294-16-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 15/15] xen/arm: traps: Move the implementation of GUEST_BUG_ON in traps.h 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" GUEST_BUG_ON may be used in other files doing guest emulation. Signed-off-by: Julien Grall --- xen/arch/arm/traps.c | 24 ------------------------ xen/include/asm-arm/traps.h | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index d1bf69b245..6751e4d754 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -68,30 +68,6 @@ static inline void check_stack_alignment_constraints(void) { #endif } -/* - * GUEST_BUG_ON is intended for checking that the guest state has not been - * corrupted in hardware and/or that the hardware behaves as we - * believe it should (i.e. that certain traps can only occur when the - * guest is in a particular mode). - * - * The intention is to limit the damage such h/w bugs (or spec - * misunderstandings) can do by turning them into Denial of Service - * attacks instead of e.g. information leaks or privilege escalations. - * - * GUEST_BUG_ON *MUST* *NOT* be used to check for guest controllable state! - * - * Compared with regular BUG_ON it dumps the guest vcpu state instead - * of Xen's state. - */ -#define guest_bug_on_failed(p) \ -do { \ - show_execution_state(guest_cpu_user_regs()); \ - panic("Guest Bug: %pv: '%s', line %d, file %s\n", \ - current, p, __LINE__, __FILE__); \ -} while (0) -#define GUEST_BUG_ON(p) \ - do { if ( unlikely(p) ) guest_bug_on_failed(#p); } while (0) - #ifdef CONFIG_ARM_32 static int debug_stack_lines = 20; #define stack_words_per_line 8 diff --git a/xen/include/asm-arm/traps.h b/xen/include/asm-arm/traps.h index 70b52d1d16..0acf7de67d 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -9,6 +9,30 @@ # include #endif +/* + * GUEST_BUG_ON is intended for checking that the guest state has not been + * corrupted in hardware and/or that the hardware behaves as we + * believe it should (i.e. that certain traps can only occur when the + * guest is in a particular mode). + * + * The intention is to limit the damage such h/w bugs (or spec + * misunderstandings) can do by turning them into Denial of Service + * attacks instead of e.g. information leaks or privilege escalations. + * + * GUEST_BUG_ON *MUST* *NOT* be used to check for guest controllable state! + * + * Compared with regular BUG_ON it dumps the guest vcpu state instead + * of Xen's state. + */ +#define guest_bug_on_failed(p) \ +do { \ + show_execution_state(guest_cpu_user_regs()); \ + panic("Guest Bug: %pv: '%s', line %d, file %s\n", \ + current, p, __LINE__, __FILE__); \ +} while (0) +#define GUEST_BUG_ON(p) \ + do { if ( unlikely(p) ) guest_bug_on_failed(#p); } while (0) + int check_conditional_instr(struct cpu_user_regs *regs, const union hsr hsr); void advance_pc(struct cpu_user_regs *regs, const union hsr hsr);