From patchwork Sun Mar 22 16:14:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 11451881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FB296CA for ; Sun, 22 Mar 2020 16:16:14 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 764A220724 for ; Sun, 22 Mar 2020 16:16:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 764A220724 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass 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 1jG3FJ-0004ba-6H; Sun, 22 Mar 2020 16:14:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3FI-0004b4-EL for xen-devel@lists.xenproject.org; Sun, 22 Mar 2020 16:14:40 +0000 X-Inumbo-ID: 36de31cc-6c58-11ea-92cf-bc764e2007e4 Received: from mail-ed1-f66.google.com (unknown [209.85.208.66]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36de31cc-6c58-11ea-92cf-bc764e2007e4; Sun, 22 Mar 2020 16:14:32 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id b21so13476193edy.9 for ; Sun, 22 Mar 2020 09:14:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q0DjDcTGZuLAgG9ZdNmzRZsu9N7ZM1zKIaO4GQDqQOw=; b=HspJf153GXap7dOlACvUhnceLxDiisfXHVeB6BUMTRFM2aOnvEfp46zKISbtfITmEH 27GofipwIvqNDBKqhcd7ra/+kCwaPNtSc4FqSyBJ6uq7Nft1fo8bJPu3qbbaCvI6Yqn0 M0LT5fhMrg/Y/NILn+kDuDgsZadVg6DoqJwNSReSPp5iRtNtAQMkMtGrO9ZNRevEiddw FcWoBGaKLbFgRSbXEY40tdd9oGVZtXLhH/KdtKBFjBxS03q3mX6VUCkrvL6mTM3tP8JX iOX8K0SQ6EFWoT/BfeA1/0vr82ELVTW2oABwewvxxuDedi9AzRKtfNz17FEnMYWEWS8q uuVQ== X-Gm-Message-State: ANhLgQ1lr1jPznOxsFRR/qgZF9i0Gg2rTNoI+G4tZ1NBoamQa515LwLr oyjGfQZ7c7sXKmWt1PIzKv2hzSzl4eB8Cg== X-Google-Smtp-Source: ADFU+vvgTgEpJ8ob/YW7qtJesBCrWJv3xoArKcCEXeWNlhIZ+k+dpM4FZTqO0NuHdQDUFNqaMCt7Xg== X-Received: by 2002:a17:906:4e81:: with SMTP id v1mr5182103eju.259.1584893671540; Sun, 22 Mar 2020 09:14:31 -0700 (PDT) Received: from ufe34d9ed68d054.ant.amazon.com (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id v13sm106693edj.62.2020.03.22.09.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 09:14:30 -0700 (PDT) From: julien@xen.org To: xen-devel@lists.xenproject.org Date: Sun, 22 Mar 2020 16:14:08 +0000 Message-Id: <20200322161418.31606-8-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200322161418.31606-1-julien@xen.org> References: <20200322161418.31606-1-julien@xen.org> Subject: [Xen-devel] [PATCH 07/17] xen/x86: traps: Convert __page_fault_type() to use typesafe MFN 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@xen.org, Wei Liu , Andrew Cooper , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Note that the code is now using cr3_to_mfn() to get the MFN. This is slightly different as the top 12-bits will now be masked. No functional changes intended. Signed-off-by: Julien Grall --- xen/arch/x86/traps.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 04a3ebc0a2..4f524dc71e 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1232,7 +1232,8 @@ enum pf_type { static enum pf_type __page_fault_type(unsigned long addr, const struct cpu_user_regs *regs) { - unsigned long mfn, cr3 = read_cr3(); + mfn_t mfn; + unsigned long cr3 = read_cr3(); l4_pgentry_t l4e, *l4t; l3_pgentry_t l3e, *l3t; l2_pgentry_t l2e, *l2t; @@ -1264,20 +1265,20 @@ static enum pf_type __page_fault_type(unsigned long addr, page_user = _PAGE_USER; - mfn = cr3 >> PAGE_SHIFT; + mfn = cr3_to_mfn(cr3); - l4t = map_domain_page(_mfn(mfn)); + l4t = map_domain_page(mfn); l4e = l4e_read_atomic(&l4t[l4_table_offset(addr)]); - mfn = l4e_get_pfn(l4e); + mfn = l4e_get_mfn(l4e); unmap_domain_page(l4t); if ( ((l4e_get_flags(l4e) & required_flags) != required_flags) || (l4e_get_flags(l4e) & disallowed_flags) ) return real_fault; page_user &= l4e_get_flags(l4e); - l3t = map_domain_page(_mfn(mfn)); + l3t = map_domain_page(mfn); l3e = l3e_read_atomic(&l3t[l3_table_offset(addr)]); - mfn = l3e_get_pfn(l3e); + mfn = l3e_get_mfn(l3e); unmap_domain_page(l3t); if ( ((l3e_get_flags(l3e) & required_flags) != required_flags) || (l3e_get_flags(l3e) & disallowed_flags) ) @@ -1286,9 +1287,9 @@ static enum pf_type __page_fault_type(unsigned long addr, if ( l3e_get_flags(l3e) & _PAGE_PSE ) goto leaf; - l2t = map_domain_page(_mfn(mfn)); + l2t = map_domain_page(mfn); l2e = l2e_read_atomic(&l2t[l2_table_offset(addr)]); - mfn = l2e_get_pfn(l2e); + mfn = l2e_get_mfn(l2e); unmap_domain_page(l2t); if ( ((l2e_get_flags(l2e) & required_flags) != required_flags) || (l2e_get_flags(l2e) & disallowed_flags) ) @@ -1297,9 +1298,9 @@ static enum pf_type __page_fault_type(unsigned long addr, if ( l2e_get_flags(l2e) & _PAGE_PSE ) goto leaf; - l1t = map_domain_page(_mfn(mfn)); + l1t = map_domain_page(mfn); l1e = l1e_read_atomic(&l1t[l1_table_offset(addr)]); - mfn = l1e_get_pfn(l1e); + mfn = l1e_get_mfn(l1e); unmap_domain_page(l1t); if ( ((l1e_get_flags(l1e) & required_flags) != required_flags) || (l1e_get_flags(l1e) & disallowed_flags) )