From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PLING_QUERY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AB31C433E7 for ; Tue, 13 Oct 2020 20:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAE4720878 for ; Tue, 13 Oct 2020 20:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jQaesPSF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726186AbgJMUgp (ORCPT ); Tue, 13 Oct 2020 16:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725977AbgJMUgp (ORCPT ); Tue, 13 Oct 2020 16:36:45 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F28A5C061755 for ; Tue, 13 Oct 2020 13:36:44 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id l2so1249299lfk.0 for ; Tue, 13 Oct 2020 13:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NQjQ2k5Saht+0v/Nw1gJ06v1KosSim39Rrh/K70mE9E=; b=jQaesPSFTPRhdaJ/IqEXZZ70+scGkNb1HDPfK0KW1sqhP4cGHHqrqbj3R4XFat/hI6 kNzBtGPjo6gxc1fjnQPZzYfA351zCCY7KaRTj5adeqKSIUy55WSUP+UCmmBGd3DnVuTu hPBFcJENBJ6F49GIFfi8K8XoSuq0AptuOLd2jROZc9v9vK4o/ETSzfbBEWqQz237jgpk pA5GJyuGgTJaVa8EfxDL3DW91H+9zpBHVIFimRxOufQQu4ehrba7mwhg89+F42mUL2E6 SBmQLmz6PmQTa8LeUIMG5GalZy1R93WKzOHMUNFJHD1FnvYbIa3Yomn9KqLZAKE/nAKt mfDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NQjQ2k5Saht+0v/Nw1gJ06v1KosSim39Rrh/K70mE9E=; b=nU/c+C5H9mfllzuCtN/d9WgpX6IGj5I3Op0ARbuE1bq4E8rhStlPA25ElDMo2t55Wp yFMaCIlumSNFoOzOOWZH5bx7ihhhR+JndFJTZ187Xl0qq1oj9GdJbm6UaXi0S4eodrJi n5QZtVpWQqUzgK0a3LLHfwQnD2RuNhDiIqLP6TWa2uaocOMDXn/d/2q5Gh2O1ye7C25F aC4lPgfMUuCQ3k72Crv4lhWVTTr5kK9+nlRyt/TJp9dUeTbHu/vuXUaT62X8YkUanaiY 7UMC/Gz703zigLanEu0IdOZue0ATadwF6artVWttooaN5+ucLh4IozjPK0epWxbElmAL aAjA== X-Gm-Message-State: AOAM531IRZ1jK3cGcLEA0etLYVR+P96EgidACIWNO0U1iS97MYlM/4mR K4pRz3n1DLAmT1yr/Uyw7/nx0zDs26dG8kxiEAn4ogpNIDk= X-Google-Smtp-Source: ABdhPJyc4gYiGMgm7ccRbPjdTl523pIjBDmx0/crijD7nRyGalWIpfyK/BHYXHE1SSV/b2RI2rJ28LKu9QHjo9pCIdc= X-Received: by 2002:a19:8256:: with SMTP id e83mr332082lfd.530.1602621403376; Tue, 13 Oct 2020 13:36:43 -0700 (PDT) MIME-Version: 1.0 References: <47ead258320536d00f9f32891da3810040875aff.camel@redhat.com> <20201012165428.GD26135@linux.intel.com> <20201013045245.GA11344@linux.intel.com> In-Reply-To: From: harry harry Date: Tue, 13 Oct 2020 16:36:25 -0400 Message-ID: Subject: Re: Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks! To: Paolo Bonzini , Sean Christopherson Cc: Maxim Levitsky , qemu-devel@nongnu.org, mathieu.tarral@protonmail.com, stefanha@redhat.com, libvir-list@redhat.com, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Paolo and Sean, Thanks much for your prompt replies and clear explanations. On Tue, Oct 13, 2020 at 2:43 AM Paolo Bonzini wrote: > > No, the logic to find the HPA with a given HVA is the same as the > hardware logic to translate HVA -> HPA. That is it uses the host > "regular" page tables, not the nested page tables. > > In order to translate GPA to HPA, instead, KVM does not use the nested > page tables. I am curious why KVM does not directly use GPAs as HVAs and leverage nested page tables to translate HVAs (i.e., GPAs) to HPAs? Is that because 1) the hardware logic of ``GPA -> [extended/nested page tables] -> HPA[*]'' is different[**] from the hardware logic of ``HVA -> [host regular page tables] -> HPA''; 2) if 1) is true, it is natural to reuse Linux's original functionality to translate HVAs to HPAs through regular page tables. [*]: Here, the translation means the last step for MMU to translate a GVA's corresponding GPA to an HPA through the extended/nested page tables. [**]: To my knowledge, the hardware logic of ``GPA -> [extended/nested page tables] -> HPA'' seems to be the same as the hardware logic of ``HVA -> [host regular page tables] -> HPA''. I appreciate it if you could point out the differences I ignored. Thanks! Best, Harry From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PLING_QUERY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD53CC433DF for ; Tue, 13 Oct 2020 20:39:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 5123920878 for ; Tue, 13 Oct 2020 20:39:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jQaesPSF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5123920878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kSR53-0007RF-Rk for qemu-devel@archiver.kernel.org; Tue, 13 Oct 2020 16:39:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSR2N-0003cV-L7 for qemu-devel@nongnu.org; Tue, 13 Oct 2020 16:36:47 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]:41055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kSR2L-00013M-Gj for qemu-devel@nongnu.org; Tue, 13 Oct 2020 16:36:47 -0400 Received: by mail-lf1-x134.google.com with SMTP id d24so1190320lfa.8 for ; Tue, 13 Oct 2020 13:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NQjQ2k5Saht+0v/Nw1gJ06v1KosSim39Rrh/K70mE9E=; b=jQaesPSFTPRhdaJ/IqEXZZ70+scGkNb1HDPfK0KW1sqhP4cGHHqrqbj3R4XFat/hI6 kNzBtGPjo6gxc1fjnQPZzYfA351zCCY7KaRTj5adeqKSIUy55WSUP+UCmmBGd3DnVuTu hPBFcJENBJ6F49GIFfi8K8XoSuq0AptuOLd2jROZc9v9vK4o/ETSzfbBEWqQz237jgpk pA5GJyuGgTJaVa8EfxDL3DW91H+9zpBHVIFimRxOufQQu4ehrba7mwhg89+F42mUL2E6 SBmQLmz6PmQTa8LeUIMG5GalZy1R93WKzOHMUNFJHD1FnvYbIa3Yomn9KqLZAKE/nAKt mfDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NQjQ2k5Saht+0v/Nw1gJ06v1KosSim39Rrh/K70mE9E=; b=uSUC7n3jZpQ8hzSRlPa12xJsQvkKvnMHXW/Eytd8NOHvCY+SXs3WTX3LyGhoupcAXO FXgNzYntF2guIaJw3mqT/kv39WEPJwJx4V9WpFvDjfFh1oasdH+oZpz/2zRUxc1F9/+K 9ttK8VsBY+/ONv0CyQSWw0L9IuoORkpOJEJmmwXIV2vifaYrVuNVguj0+tjPw1FYAtNj als0HOMu4FsbrK2SQODZj5B04u0fFvF9mKIZORoTSVz19twM0uBpPjM2aWyjVfFhIYrX KgktavkD98Zek/AMoUFlrlRDZDM1wcgOdgqOETLQsZ84xfJdsYbft2Z1pvcauPGwYCxt OG6Q== X-Gm-Message-State: AOAM533IRYq4l+COsV9HL2/p32ih6rfVeZFpeGj33d0ShrrIUDyTYB4i ubuUXJnJd2vg1cdbKuOK2vwynL/b8LTinraCkKE= X-Google-Smtp-Source: ABdhPJyc4gYiGMgm7ccRbPjdTl523pIjBDmx0/crijD7nRyGalWIpfyK/BHYXHE1SSV/b2RI2rJ28LKu9QHjo9pCIdc= X-Received: by 2002:a19:8256:: with SMTP id e83mr332082lfd.530.1602621403376; Tue, 13 Oct 2020 13:36:43 -0700 (PDT) MIME-Version: 1.0 References: <47ead258320536d00f9f32891da3810040875aff.camel@redhat.com> <20201012165428.GD26135@linux.intel.com> <20201013045245.GA11344@linux.intel.com> In-Reply-To: From: harry harry Date: Tue, 13 Oct 2020 16:36:25 -0400 Message-ID: Subject: Re: Why guest physical addresses are not the same as the corresponding host virtual addresses in QEMU/KVM? Thanks! To: Paolo Bonzini , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=hiharryharryharry@gmail.com; helo=mail-lf1-x134.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PLING_QUERY=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, libvir-list@redhat.com, qemu-devel@nongnu.org, Maxim Levitsky , mathieu.tarral@protonmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hi Paolo and Sean, Thanks much for your prompt replies and clear explanations. On Tue, Oct 13, 2020 at 2:43 AM Paolo Bonzini wrote: > > No, the logic to find the HPA with a given HVA is the same as the > hardware logic to translate HVA -> HPA. That is it uses the host > "regular" page tables, not the nested page tables. > > In order to translate GPA to HPA, instead, KVM does not use the nested > page tables. I am curious why KVM does not directly use GPAs as HVAs and leverage nested page tables to translate HVAs (i.e., GPAs) to HPAs? Is that because 1) the hardware logic of ``GPA -> [extended/nested page tables] -> HPA[*]'' is different[**] from the hardware logic of ``HVA -> [host regular page tables] -> HPA''; 2) if 1) is true, it is natural to reuse Linux's original functionality to translate HVAs to HPAs through regular page tables. [*]: Here, the translation means the last step for MMU to translate a GVA's corresponding GPA to an HPA through the extended/nested page tables. [**]: To my knowledge, the hardware logic of ``GPA -> [extended/nested page tables] -> HPA'' seems to be the same as the hardware logic of ``HVA -> [host regular page tables] -> HPA''. I appreciate it if you could point out the differences I ignored. Thanks! Best, Harry