Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1631523pxu; Sun, 6 Dec 2020 02:13:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfI25XfZivXdtyERVQknANd5Vh8+8w+k3V3L1JQsDMAb665iq1BL8tnSHXFftcb0zyNYnp X-Received: by 2002:a50:e00b:: with SMTP id e11mr15305745edl.303.1607249597386; Sun, 06 Dec 2020 02:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607249597; cv=none; d=google.com; s=arc-20160816; b=g23E9aDGF4qwO/subH02koddPqGRA25qLxJllFYsHh0QBwD7FKwp+jJbPm7dCGDbHj LaxTItRgzIQ77MnpoMz4i+jPbeH3EV5I1Zb1+LmOKPBV9hQ5pNIgPNrLHQGaR98i8GsR 9YTRxo+9PBafeccUCflDN6fhpRQP+iAZDAGW1b7XYkrV3fFOinBaPo8L56/kqGNQXN8o R27GNKhAVxojQitKNN+IpNrOzCm90brOf2/GeVCShd+e/nFLJp2gLzc4vOMB2x7cpET/ YeM00uJlvdiHVv9GumhXhNemf4Lo429zxlTxOUVobmBdmJA2EtMN9kX8bEpcUKlXrh83 S2Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=xji8+FhOghfu2/XZrvV9/OViBfo6B1ROea5bmQqV1JA=; b=fOIKRAZnMEpEg71j2dR9tns4uQwwFOowquk0Z88H0PveEfz5Tqmfiv03uGBpXKuL6y buftm7v3pZQtB+N5/poCg+5/nA4rEJqYJeyrvzao/cl/iFqeyhlBT7n0pTmxtksqh4ug FYscLg0ca2PFcvB+xkLDe3BcU3Vd3b5dqC0fELH0MY2mpp2+2Ym4/U9x98vBSNcg20b/ Dzcvuf6E2bCncRfQVLQRGp0wTWuezbuSdULhzGsdW9AdiCevmHhriBJ5kUsoABAc6YwI CpyHQSx9D5trrpTPwoctDtErZsf2AAPz/6R5PeCAb8kNpNIvn8U5ho0eDK9byef8oKUN aHIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CpzoQjxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si6317899ede.232.2020.12.06.02.12.53; Sun, 06 Dec 2020 02:13:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CpzoQjxu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbgLFKLQ (ORCPT + 99 others); Sun, 6 Dec 2020 05:11:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20337 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbgLFKLQ (ORCPT ); Sun, 6 Dec 2020 05:11:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607249389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xji8+FhOghfu2/XZrvV9/OViBfo6B1ROea5bmQqV1JA=; b=CpzoQjxutDWpL7kScYSvdSAFQxUOQ+VkokiVuNsKPDKdLi/J+XKcK2OU/P2zaO8zP0MT8v ykOLRTQlndkEzqKyyiivi8KuZVmej1AL0ICr86y/8DGmHgJQ2zV3D8e8bz7/j444gSUhjj E411jfyUtFjHBRhkc0Jn3c04vEz0xcg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-lvejHIBHOCWb1kWWVDAqyg-1; Sun, 06 Dec 2020 05:09:47 -0500 X-MC-Unique: lvejHIBHOCWb1kWWVDAqyg-1 Received: by mail-wr1-f69.google.com with SMTP id v1so4117716wri.16 for ; Sun, 06 Dec 2020 02:09:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xji8+FhOghfu2/XZrvV9/OViBfo6B1ROea5bmQqV1JA=; b=coNnMlz1dpqpM9DS7IRu2KZa4a9bQMfZ8avjwNe3zdu8QuQlBavcVttmU9TGPHRKm/ 7Y+oWqneAX+20ajWzdPi6MtM36/yu7hNR1bl9C1g6un+SvhlknF23St4/St/2y7yjv5I q5iVefVFoBL1+EK5OaHFzGkqp3tFJGHomDaKpC5GAS2ibBQczdTzjuqjGXFZysJWGdpI gyVlHSuwJYLKFLiWEYhunEFquR/Hl7Ljqf9Q+DHD0cIC1VpJS9nmraB8cYlC+yMuXHU5 /rUq4gEdjIXQ8vRimd3T1QFFEv38MPx/49/PbBfAWjrFaQUmvfYjNzLK546l3Cgi9G6n t/cA== X-Gm-Message-State: AOAM531sh+zCb7MVlHjMzgtnw+SkCwdBAByieZ693KmdZ1eCL4zMSStX bHQjqs0kD9aDMr7as67/dz/63tc1TJWHRDhoCvycK/N8MTptc/ZTpFUjDukspKRnBn2PNBPuDn2 lu6gwsy1H1hwISlOOR1pna95KZ1zasO0a/gvznrhCautlUhiZjVG6vMW/oCv7ocXHe19dPrC885 At X-Received: by 2002:adf:ec0c:: with SMTP id x12mr14416590wrn.307.1607249386043; Sun, 06 Dec 2020 02:09:46 -0800 (PST) X-Received: by 2002:adf:ec0c:: with SMTP id x12mr14416555wrn.307.1607249385766; Sun, 06 Dec 2020 02:09:45 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id d3sm10226839wrr.2.2020.12.06.02.09.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2020 02:09:45 -0800 (PST) Subject: Re: [PATCH] KVM: mmu: Fix SPTE encoding of MMIO generation upper half To: "Maciej S. Szmigiero" Cc: Sean Christopherson , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Jonathan Corbet , linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <156700708db2a5296c5ed7a8b9ac71f1e9765c85.1607129096.git.maciej.szmigiero@oracle.com> From: Paolo Bonzini Message-ID: <370db207-7216-ae26-0c33-dab61e0fdaab@redhat.com> Date: Sun, 6 Dec 2020 11:09:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <156700708db2a5296c5ed7a8b9ac71f1e9765c85.1607129096.git.maciej.szmigiero@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/12/20 01:48, Maciej S. Szmigiero wrote: > From: "Maciej S. Szmigiero" > > Commit cae7ed3c2cb0 ("KVM: x86: Refactor the MMIO SPTE generation handling") > cleaned up the computation of MMIO generation SPTE masks, however it > introduced a bug how the upper part was encoded: > SPTE bits 52-61 were supposed to contain bits 10-19 of the current > generation number, however a missing shift encoded bits 1-10 there instead > (mostly duplicating the lower part of the encoded generation number that > then consisted of bits 1-9). > > In the meantime, the upper part was shrunk by one bit and moved by > subsequent commits to become an upper half of the encoded generation number > (bits 9-17 of bits 0-17 encoded in a SPTE). > > In addition to the above, commit 56871d444bc4 ("KVM: x86: fix overlap between SPTE_MMIO_MASK and generation") > has changed the SPTE bit range assigned to encode the generation number and > the total number of bits encoded but did not update them in the comment > attached to their defines, nor in the KVM MMU doc. > Let's do it here, too, since it is too trivial thing to warrant a separate > commit. > > Fixes: cae7ed3c2cb0 ("KVM: x86: Refactor the MMIO SPTE generation handling") > Signed-off-by: Maciej S. Szmigiero > --- Good catch. What do you think about this alternative definition? It computes everything from the bit ranges. #define MMIO_SPTE_GEN_LOW_START 3 #define MMIO_SPTE_GEN_LOW_END 11 #define MMIO_SPTE_GEN_HIGH_START PT64_SECOND_AVAIL_BITS_SHIFT #define MMIO_SPTE_GEN_HIGH_END 62 #define MMIO_SPTE_GEN_LOW_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_END, \ MMIO_SPTE_GEN_LOW_START) #define MMIO_SPTE_GEN_HIGH_MASK GENMASK_ULL(MMIO_SPTE_GEN_HIGH_END, \ MMIO_SPTE_GEN_HIGH_START) #define MMIO_SPTE_GEN_LOW_BITS (MMIO_SPTE_GEN_LOW_END - MMIO_SPTE_GEN_LOW_START + 1) #define MMIO_SPTE_GEN_HIGH_BITS (MMIO_SPTE_GEN_HIGH_END - MMIO_SPTE_GEN_HIGH_START + 1) #define MMIO_SPTE_GEN_LOW_SHIFT (MMIO_SPTE_GEN_LOW_START - 0) #define MMIO_SPTE_GEN_HIGH_SHIFT (MMIO_SPTE_GEN_HIGH_START - MMIO_SPTE_GEN_LOW_BITS) #define MMIO_SPTE_GEN_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_BITS + MMIO_SPTE_GEN_HIGH_BITS - 1, 0) Thanks, Paolo