Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp589787pxu; Fri, 23 Oct 2020 08:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhAHevxJUIeBb4tdEOvjejoihZ0kZrhmbifFPNRRJ7lLjfchZE9pQCVG8prBFwb6ulbU51 X-Received: by 2002:a17:906:1643:: with SMTP id n3mr2456467ejd.459.1603467049869; Fri, 23 Oct 2020 08:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603467049; cv=none; d=google.com; s=arc-20160816; b=k0k74wAAk9K/CYN1dVJlai5ay/TxpguhHs9FCsNgT+cuslfAGFpg+kAJUCCuxHMqWo 3cUhJpPjgAXtngERT40rSQTEK6s/tgWbrY458zOZwLbNarrFAb7uGNqviKWLpcLY+Imu RqsdoROHgMtiqQObpaASPoexSDg1FWolW0fTjwLj2SG8Tpmkr4KHs649daffMy5g3JwU 9Uyf1puKZlA5HsQqJ+RiK8qqT14uJ1O9L8fFv/8JsLf4vxf2MrRev7m5w8VMvYVAq2gi ghA0FIt91KAq4WSGBLSojQZRh9RwZ0zSrEV71wlKwn6ebrGXjxGjZ+kg8NnTqxvM+0dr O4tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2qkq9CfQOJr8zJttsFKuFINhGnc+H3tDfc2bDWRdxKM=; b=ZG9xOLW1dfROTii7LVKf7X5KVTtUXI+hbpok9yABlL7NZzlqPBwXnTvlt4EdKmkdZX pUEXbjToOVB2QoUoQ20i8hWDOZEhZd+Y+RpHtZagnrRn+7M7mdemhKETYZW9Swl8s66Y +tfMSWJAiC6O6t+5SYNNQZCjsp728F5EI5ESO86ZXP/M0Du0T35GMPFcbe7nmGIyTCyW kGTT5I+CB6//9hLByqESsqkOFzquumPVWIZq47rBbb5xbIibHuktfVgGblsb2nFh4ihd AdG7Fz6PtlC1zVh37wkOaldusqLWCBDrj0UHVgP+dQ1lvLEGCUKXu0mrUzMu81qfwbYl 8viQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=fhbRPsyb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by18si1037245ejb.238.2020.10.23.08.30.26; Fri, 23 Oct 2020 08:30:49 -0700 (PDT) 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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=fhbRPsyb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S462352AbgJWKgN (ORCPT + 99 others); Fri, 23 Oct 2020 06:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S460818AbgJWKgN (ORCPT ); Fri, 23 Oct 2020 06:36:13 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D85C0613CE for ; Fri, 23 Oct 2020 03:36:12 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id c21so1003902ljn.13 for ; Fri, 23 Oct 2020 03:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=2qkq9CfQOJr8zJttsFKuFINhGnc+H3tDfc2bDWRdxKM=; b=fhbRPsyb8i9xNHMf4eL5ienqhn7upoD6FePa/IEF7DMBI6HisVrOD33691JnVkmeQi ET2W5Takymxk8FVZvUA5hEAmwX7HYwQurYbORAkttNqTL4VuRwkIkfZ0h/JLlpG+GR6u a6BWrna+MBVKLQ9UAl6mF4AeywD0FcFeHeltPhaw+5YZUumYlpF1v4IBLvpmcnJozg9Y mdYng2/8mGvFa8kUyHbVE6+aKlNVE+cfharL9bJyzKCwIk0S5XbJIlfVAvfrxBP5+Heo ouekvBs9rnWndDp/Nb7lQTKqSqykoCFGoOQ+zBx0i7e4ynHDUpbUISETkwzCkX6DMDnH 3oJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2qkq9CfQOJr8zJttsFKuFINhGnc+H3tDfc2bDWRdxKM=; b=FFuVFNh+yx2H8FWswTP9Ab+SoA6zssgL18hLeZ4ReyQBKm5rqJuLum8Gi4iuUvCVmP RkVGMZfxP68taW/HjTTx/th+YPePa3BJCRuVhKFVzKn00FlrOJPQGo8kowHjRn77huVk btXzzheq54Nqo5sgFbF+PPf6ng+Nb4xSkJGx7/grGaJGnPFdz2eW4in8Bky5Fa+8a6a3 18S51j2SC27I9Sam6RQl/wCwQTMoU5kzLt+3E1GMXYj4daUnx6tGMQby8X2vGiiv880o VyAqE/haBw3CHMn06yDTwHS4Blu5qgzuw625+eTrUpqpyDst69FXLMKteBA8GamZXGw0 XVgQ== X-Gm-Message-State: AOAM532W5zfMRgd1x3qVQuwZuKPAwDRKGh8Fq/WxLOJWUT53X0pQq3ju xGEEw/ICjhu4Y/bRJ03/wZ8GdQ== X-Received: by 2002:a2e:b889:: with SMTP id r9mr639609ljp.378.1603449371412; Fri, 23 Oct 2020 03:36:11 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id x18sm99408lfe.158.2020.10.23.03.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 03:36:10 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id D5683102F98; Fri, 23 Oct 2020 13:36:10 +0300 (+03) Date: Fri, 23 Oct 2020 13:36:10 +0300 From: "Kirill A. Shutemov" To: "Edgecombe, Rick P" Cc: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jmattson@google.com" , "peterz@infradead.org" , "kirill.shutemov@linux.intel.com" , "Christopherson, Sean J" , "vkuznets@redhat.com" , "linux-mm@kvack.org" , "dave.hansen@linux.intel.com" , "joro@8bytes.org" , "x86@kernel.org" , "aarcange@redhat.com" , "keescook@chromium.org" , "luto@kernel.org" , "pbonzini@redhat.com" , "rientjes@google.com" , "liran.alon@oracle.com" , "rppt@kernel.org" , "wad@chromium.org" , "wanpengli@tencent.com" , "Kleen, Andi" Subject: Re: [RFCv2 14/16] KVM: Handle protected memory in __kvm_map_gfn()/__kvm_unmap_gfn() Message-ID: <20201023103610.facpukoiodnj5v73@box> References: <20201020061859.18385-1-kirill.shutemov@linux.intel.com> <20201020061859.18385-15-kirill.shutemov@linux.intel.com> <8404a8802dbdbf81c8f75249039580f9e6942095.camel@intel.com> <20201022120645.vdmytvcmdoku73os@box> <4df3bb56f56f5a8d69b4b288317111046158cebb.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4df3bb56f56f5a8d69b4b288317111046158cebb.camel@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 22, 2020 at 04:59:49PM +0000, Edgecombe, Rick P wrote: > On Thu, 2020-10-22 at 15:06 +0300, Kirill A. Shutemov wrote: > > > I think the page could have got unmapped since the gup via the > > > hypercall on another CPU. It could be an avenue for the guest to > > > crash > > > the host. > > > > Hm.. I'm not sure I follow. Could you elaborate on what scenario you > > have > > in mind? > > Kind of similar scenario as the userspace triggered oops. My > understanding is that the protected status was gathered along with the > gup, but after the mm gets unlocked, nothing stops the page > transitioning to unmapped(?). At which point kmap() from a previous gup > with !protected, would go down the regular kmap() route and return an > address to an unmapped page. > > So the guest kernel could start with a page mapped as shared via the > hypercall. Then trigger one of the PV MSR's that kmap() on CPU0. On > CPU1, after the gup on CPU0, it could transitioned the page to > private/unmapped via the hypercall. So the hva_to_pfn() would find > !protected, but by the time the kmap() happened the page would have > been unmapped. Am I missing something? We need to fail protection enabling if a page is pinned. That's the only option I see. But it might be pain to debug. -- Kirill A. Shutemov