Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1828895iob; Fri, 29 Apr 2022 13:56:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZkZspxHJzTz8MQR1s4ZLrbjX9vjZZ5n/se0/lW1DUFh+/kp1B7e97URVwvK4aMBluy3K6 X-Received: by 2002:a05:6a00:b41:b0:50d:35fa:476d with SMTP id p1-20020a056a000b4100b0050d35fa476dmr661625pfo.33.1651265779094; Fri, 29 Apr 2022 13:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651265779; cv=none; d=google.com; s=arc-20160816; b=pX7eCNO3Pv0P16aoj44xB8izH9Yoy2PsKCqDnmnlvi3AE/a8viGPwtz5N7Qlxey2Z5 2s9sqRXW6DSdKQlMiu86Ov5YhqWGy20vWJV4oVUCfzs/WP8GeOlVr/yxD7G3lNWmgESC 96n73cXZCnxAJUYQlF6Uu8+K2PTP9px+KnCk+Ja3DwJmLUk1oliUEIuOYvLIcCOUp++S OB7WfmQ1Mte87ZMYhmbvRrhTPg4Djria003+9yreBrBqLKvHaLp36Pp3drQ2sn4SgdUa aBcS9laaRJh+xY9gHhrD6DIXZJyfaJ5O/Nin6R6OaFMP60AFIsWuXDLiSUln0i2L6SZl Pkzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=reLN1pG1/CChgH6ozCSwMmfyN+LJMqKj0Ol22hvsDgw=; b=ADkM/ZbAwJ/Cdep6zIUMD1sd6YJplMYfTkFC2Jo7aKWzmottBtmf46q1RocBKJqV1r Geh9bkIfJPshbYImWpR8/e8MdyA7qqnyeHUlJS/WJhFH3vOqvTwOFkPv/ymO1LZhM9IR Uhqxy8AAQ9RC9caIchJYJiM0SCLnYgo82KiMLzOUB+7aT0Kr89uukvvtoFOlJSglXSkF 0fhIs45t3AiShuUpAtdRhgKePIRowdBKB3+h6E7o2NPriCby6Us2vbQZvx99hQd4+3MN aqvdB8XukEOUHMKDhtQC86xgkiNahqjSkoK1lpATfc/lXSMcRN0El1LRZBLn7aGNJypS Aqzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vpp4qT6P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a056a00240200b004fa3a8e005dsi8322338pfh.276.2022.04.29.13.56.03; Fri, 29 Apr 2022 13:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vpp4qT6P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1377769AbiD2Osc (ORCPT + 99 others); Fri, 29 Apr 2022 10:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377755AbiD2Os3 (ORCPT ); Fri, 29 Apr 2022 10:48:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A184635F for ; Fri, 29 Apr 2022 07:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651243509; 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=reLN1pG1/CChgH6ozCSwMmfyN+LJMqKj0Ol22hvsDgw=; b=Vpp4qT6PMzFJlWeMiynSYd74/XZKoPYXDfSSnQPMVDwK1rSf8IyfXfVmgiTvYzIQJQUiDV S19RYua3pYegIPuUO37ivfXYNKJmw0D0mSMP/pyMb4q/QAuz2wgBEiSX28BrmS6IEGnzBK ETSXFtX8V6H7DfdT9p/WBOVN8coOqps= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-605-jmi4oePoOtekRW4ReXOqQA-1; Fri, 29 Apr 2022 10:45:07 -0400 X-MC-Unique: jmi4oePoOtekRW4ReXOqQA-1 Received: by mail-ej1-f71.google.com with SMTP id l20-20020a170906795400b006f3f30daf18so1185071ejo.22 for ; Fri, 29 Apr 2022 07:45:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:subject:in-reply-to :content-transfer-encoding; bh=reLN1pG1/CChgH6ozCSwMmfyN+LJMqKj0Ol22hvsDgw=; b=BiDdbfJbf/4XhkCoqWWrgtuUANIxRpP6/BRl1I0htnrNtQ9sDoCSnNpub21U+pahRo FupWEMKTMGOIOFrDpdDdje9JAqsO7sBosgcdZOdcWX7qbALBXdVagKCKj8wl48tleupG wXGr8MV+DODoZCzdN9ruq+qLpxivmGuUo+H4Ke9mj24QtnVo9UELyBbzflUyi/40pZ1m ID7Tu9JU/0vtVc+QlQz3gos5SQZRgjFBgFopvoBRCL//YfMwD+AA2blFw+pMSR13LzKH BbdHGxqrVdzsAd1GL3b/GRsPz2BpVfeRrK3LEaTg1L4cPCfPKXUorNfjUN4iPfduTX4Z j0Rg== X-Gm-Message-State: AOAM530YgjrSY4tAQod46MucS078AS02pmBHUQP/mZBlP5aVLJEyFKF4 C7PjVHBUF9ElwpVwBuNC3v5CSaCQHveLVagV9TJwVvW/w8jFEu+sKzsAgEWhCAli+7b2Sptplko 9vWQUN/QIItEuDZiZsYjc3PPr X-Received: by 2002:a17:907:3f91:b0:6d7:16c0:ae1b with SMTP id hr17-20020a1709073f9100b006d716c0ae1bmr36173033ejc.74.1651243506537; Fri, 29 Apr 2022 07:45:06 -0700 (PDT) X-Received: by 2002:a17:907:3f91:b0:6d7:16c0:ae1b with SMTP id hr17-20020a1709073f9100b006d716c0ae1bmr36173012ejc.74.1651243506264; Fri, 29 Apr 2022 07:45:06 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:1c09:f536:3de6:228c? ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.googlemail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm3038883edr.76.2022.04.29.07.45.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Apr 2022 07:45:05 -0700 (PDT) Message-ID: <67222fe0-7bf0-ec7a-0791-a4d48391a15e@redhat.com> Date: Fri, 29 Apr 2022 16:45:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: Sean Christopherson Cc: Mingwei Zhang , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220429031757.2042406-1-mizhang@google.com> <4b0936bf-fd3e-950a-81af-fd393475553f@redhat.com> From: Paolo Bonzini Subject: Re: [PATCH] KVM: x86/mmu: fix potential races when walking host page table In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/29/22 16:35, Sean Christopherson wrote: > On Fri, Apr 29, 2022, Paolo Bonzini wrote: >>> +out: >>> + local_irq_restore(flags); >>> + return level; >>> +} >>> +EXPORT_SYMBOL_GPL(kvm_lookup_address_level_in_mm); >> >> Exporting is not needed. >> >> Thanks for writing the walk code though. I'll adapt it and integrate the >> patch. > > But why are we fixing this only in KVM? I liked the idea of stealing perf's > implementation because it was a seemlingly perfect fit and wouldn't introduce > new code (ignoring wrappers, etc...). > > We _know_ that at least one subsystem is misusing lookup_address_in_pgd() and > given that its wrappers are exported, I highly doubt KVM is the only offender. > It really feels like we're passing the buck here by burying the fix in KVM. There are two ways to do it: * having a generic function in mm/. The main issue there is the lack of a PG_LEVEL_{P4D,PUD,PMD,PTE} enum at the mm/ level. We could use (ctz(x) - 12) / 9 to go from size to level, but it's ugly and there could be architectures with heterogeneous page table sizes. * having a generic function in arch/x86/. In this case KVM seems to be the odd one that doesn't need the PTE. For example vc_slow_virt_to_phys needs the PTE, and needs the size rather than the "level" per se. So for now I punted, while keeping open the door for moving code from arch/x86/kvm/ to mm/ if anyone else (even other KVM ports) need the same logic. Paolo