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_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 6086AC388F7 for ; Thu, 22 Oct 2020 11:50:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 92A98222E9 for ; Thu, 22 Oct 2020 11:50:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GEQUyOt0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92A98222E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CAA606B005D; Thu, 22 Oct 2020 07:50:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE4796B0062; Thu, 22 Oct 2020 07:50:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5F366B0068; Thu, 22 Oct 2020 07:50:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 731646B005D for ; Thu, 22 Oct 2020 07:50:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1BFCB3625 for ; Thu, 22 Oct 2020 11:50:41 +0000 (UTC) X-FDA: 77399394282.23.able24_03070bb27250 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id D93A137606 for ; Thu, 22 Oct 2020 11:50:40 +0000 (UTC) X-HE-Tag: able24_03070bb27250 X-Filterd-Recvd-Size: 3685 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 22 Oct 2020 11:50:40 +0000 (UTC) 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: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.