Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5868534pxu; Thu, 22 Oct 2020 13:10:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSB0MlsxkK0nahqYyO74s//o8gNhdWdD13PC6R1GHahZdTFjOi2CqqulBU0AAx3PVitHTM X-Received: by 2002:a17:906:26c6:: with SMTP id u6mr4166679ejc.349.1603397421520; Thu, 22 Oct 2020 13:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603397421; cv=none; d=google.com; s=arc-20160816; b=oBGJVOEXskPlL969uSJejbVqgBogh3I5y6Phi/2nQtQffBl0ab/0Kn0loaM2BLZzWM Fd2qXvOhYHqafW7qJSRBfhpfAHf5U2M/CuJ3Fl5eIMKcw1RGP0mh2qX+uWVu9iXT+fyZ O7d6YodJ27K5Zj4s8im9TY3n+lKqO+UmazaAXsbuf9SKMA1Jqvp7lfH9Y3/8IfUSEghl u+7rsrkdQ6az5W/AU5b5O/vb3AjKQuQH2Wg//0oIthOOQexi00P3qDgGoZWOn04SsQli sJxpGON/j4CyxDg3bck3v6qbBcG6I3jSQpDvrBLCN/baxp7zfyJZGykOmf6F50jk6xOJ 72bg== 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=DbTniUlZ4cwQM5ojHgxz8WDCNPislMvGHePJYXv0WFc=; b=XuhddDsHdNLkX24zpMbvV404beVdL9+r53+F8NscZDk13D0N5HRBHJSxu+BG2YcNHI mbP3/a5zg6JNgeJO3I2CiWO+kgVT4ivG7i7OkYUwvSvZy2w5p0c2MKUhZdpU8N2rQBbq YH8KUKRIBTSliiy6aLl/76k86UA3BaootdbVj9yytCuewmbRB8Muk96MGS9F+/awIDwR vq/dHrZlyFaBcCJrEhjmZWbfpYGVLGBQ15wtjLhYjwXTw2qKHR9rhk4K/V+9hgQBHih1 FIolMzd7Jc0ynsbBYbCWPp4309jsDsL/ir35PwRDf4Ug1i96LyHw2BbsIOsKB2Gzm+sa s1AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GEQUyOt0; 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 mc2si1471358ejb.634.2020.10.22.13.09.59; Thu, 22 Oct 2020 13:10:21 -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=@infradead.org header.s=casper.20170209 header.b=GEQUyOt0; 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 S2897590AbgJVLuh (ORCPT + 99 others); Thu, 22 Oct 2020 07:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503592AbgJVLuh (ORCPT ); Thu, 22 Oct 2020 07:50:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5720FC0613CE; Thu, 22 Oct 2020 04:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DbTniUlZ4cwQM5ojHgxz8WDCNPislMvGHePJYXv0WFc=; b=GEQUyOt0iJvv6z1z8sIv1u4YRi Kqh9xlCiWPOrKtlvbhdgrd+48/6sHrI9oZSW9MxmycXAtVGxDgJuP4GoVzZIlLUpxiVvL0cHRPZlZ 7dhWqV0fi8fF8JQtc4d7CJwUzvLEDH5ypBGSh3VPXM3JqBsETKQrCaRhNH2MKTw8SL9IzQvvASo4H Cw3M8+dEEG5Df8C+0cIG64wULnpVwQDF6AD6mxEvi65kPhWUgJaYiGsgDSBRbyFq7Id68Y9flS7Ax 7asD+3Xsusg3Vstvm8yLW2msEIcQzmAP/GN7hPhMevkLOPsb/H4VoeHWJFxd0uud18Bzk4iIeaIYD 2BQtVOKQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVZ6I-00078x-4X; Thu, 22 Oct 2020 11:49:46 +0000 Date: Thu, 22 Oct 2020 12:49:46 +0100 From: Matthew Wilcox To: John Hubbard Cc: "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Rientjes , Andrea Arcangeli , Kees Cook , Will Drewry , "Edgecombe, Rick P" , "Kleen, Andi" , Liran Alon , Mike Rapoport , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [RFCv2 08/16] KVM: Use GUP instead of copy_from/to_user() to access guest memory Message-ID: <20201022114946.GR20115@casper.infradead.org> References: <20201020061859.18385-1-kirill.shutemov@linux.intel.com> <20201020061859.18385-9-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2020 at 01:25:59AM -0700, John Hubbard wrote: > Should copy_to_guest() use pin_user_pages_unlocked() instead of gup_unlocked? > We wrote a "Case 5" in Documentation/core-api/pin_user_pages.rst, just for this > situation, I think: > > > CASE 5: Pinning in order to write to the data within the page > ------------------------------------------------------------- > Even though neither DMA nor Direct IO is involved, just a simple case of "pin, > write to a page's data, unpin" can cause a problem. Case 5 may be considered a > superset of Case 1, plus Case 2, plus anything that invokes that pattern. In > other words, if the code is neither Case 1 nor Case 2, it may still require > FOLL_PIN, for patterns like this: > > Correct (uses FOLL_PIN calls): > pin_user_pages() > write to the data within the pages > unpin_user_pages() Case 5 is crap though. That bug should have been fixed by getting the locking right. ie: get_user_pages_fast(); lock_page(); kmap(); set_bit(); kunmap(); set_page_dirty() unlock_page(); I should have vetoed that patch at the time, but I was busy with other things.