Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6185865imb; Fri, 8 Mar 2019 11:12:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwBIj1fbuSaXINkhX8QK+79lztMbSCe4j5FxDApA/oDZhJxQxNx0i+NqkDJkp/ExNiQ1Rhj X-Received: by 2002:a63:e447:: with SMTP id i7mr18089743pgk.70.1552072362958; Fri, 08 Mar 2019 11:12:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552072362; cv=none; d=google.com; s=arc-20160816; b=YRjo/o3DCpBIb78tzChhJ5viG2IOGiVInDg1vZ+RuXFZ002BYDmYXU70OmeQkWaYo0 VGUSZXAkPq77Oyix0OiUv/4sxcL1jmwNB+7CGjzhGwb0l+UY9NPcVonYja2riMKaLOGy wuFlVW1ogHFoYeITXa9X/BbEejLO2SaSLVViSch/qCOPSn/aMRsFDS4ekGscev4kl4fo Kr5BLcWFhPKWndqMlDhwRqpetNw/aBliZA6V0XYfrBuxaogLbBP0q+dPW4GvXlLs2BXE qo1QdD4sHqTU2dyIyabYllopuklZdWT3LtyjWNnBR68FTy6v9zocDesvqyvf5edwTAYd e7sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/kAshcJVUFY8th2kNU5RPGLHDu41rQnev1whK2dp3F8=; b=CyH1jvBj9dEuId3LDvM6QZyQ6BussJdywByqnUBQMObNg9zA/+j0HMAdQ1N5Kk6TPk /g47z3r+XpSQHxJphbNpOqcacEa8s0s6B+m5hMRQQXvK9Pn9yBngdQS8AeQCcrTQziVG gPA8lLdVZNqBwtBssVAsof0EwHm5uNl7trwJ8pwTtatVdFpLwldEy3sSpGn/P7elNpCm Tc8/ym77hP/7zqolncI2Bbbv/VRU9OJlw5um0yJyNAP/XlPkVj+z4l7umY6CSh/KFV7F yhV8TSuzpW5JCFIrHQKWHdoFTQdut1pXhePsnpniQXPeHVSeLvZWScQmz2nDSHLkjIGw wDhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si7796324plg.320.2019.03.08.11.12.27; Fri, 08 Mar 2019 11:12:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbfCHTLQ (ORCPT + 99 others); Fri, 8 Mar 2019 14:11:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48336 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726294AbfCHTLP (ORCPT ); Fri, 8 Mar 2019 14:11:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8ED46C05D261; Fri, 8 Mar 2019 19:11:15 +0000 (UTC) Received: from sky.random (ovpn-121-1.rdu2.redhat.com [10.10.121.1]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDECF60856; Fri, 8 Mar 2019 19:11:08 +0000 (UTC) Date: Fri, 8 Mar 2019 14:11:08 -0500 From: Andrea Arcangeli To: Jason Wang Cc: Jerome Glisse , "Michael S. Tsirkin" , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, peterx@redhat.com, linux-mm@kvack.org, Jan Kara Subject: Re: [RFC PATCH V2 5/5] vhost: access vq metadata through kernel virtual address Message-ID: <20190308191108.GA26923@redhat.com> References: <1551856692-3384-1-git-send-email-jasowang@redhat.com> <1551856692-3384-6-git-send-email-jasowang@redhat.com> <20190306092837-mutt-send-email-mst@kernel.org> <15105894-4ec1-1ed0-1976-7b68ed9eeeda@redhat.com> <20190307101708-mutt-send-email-mst@kernel.org> <20190307190910.GE3835@redhat.com> <20190307193838.GQ23850@redhat.com> <20190307201722.GG3835@redhat.com> <20190307212717.GS23850@redhat.com> <671c4a98-4699-836e-79fc-0ce650c7f701@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <671c4a98-4699-836e-79fc-0ce650c7f701@redhat.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 08 Mar 2019 19:11:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 08, 2019 at 05:13:26PM +0800, Jason Wang wrote: > Actually not wrapping around,? the pages for used ring was marked as > dirty after a round of virtqueue processing when we're sure vhost wrote > something there. Thanks for the clarification. So we need to convert it to set_page_dirty and move it to the mmu notifier invalidate but in those cases where gup_fast was called with write=1 (1 out of 3). If using ->invalidate_range the page pin also must be removed immediately after get_user_pages returns (not ok to hold the pin in vmap until ->invalidate_range is called) to avoid false positive gup pin checks in things like KSM, or the pin must be released in invalidate_range_start (which is called before the pin checks). Here's why: /* * Check that no O_DIRECT or similar I/O is in progress on the * page */ if (page_mapcount(page) + 1 + swapped != page_count(page)) { set_pte_at(mm, pvmw.address, pvmw.pte, entry); goto out_unlock; } [..] set_pte_at_notify(mm, pvmw.address, pvmw.pte, entry); ^^^^^^^ too late release the pin here, the above already failed ->invalidate_range cannot be used with mutex anyway so you need to go back with invalidate_range_start/end anyway, just the pin must be released in _start at the latest in such case. My prefer is generally to call gup_fast() followed by immediate put_page() because I always want to drop FOLL_GET from gup_fast as a whole to avoid 2 useless atomic ops per gup_fast. I'll write more about vmap in answer to the other email. Thanks, Andrea