Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1313188ybt; Tue, 7 Jul 2020 12:33:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO4AhvVZ6JxbG4u7lpDAmoyrbjwOdZEI3ZwNopaiADZMJmRDm+xUyOwMSgktoPI9POETTe X-Received: by 2002:a17:906:3bd5:: with SMTP id v21mr46908529ejf.329.1594150434735; Tue, 07 Jul 2020 12:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594150434; cv=none; d=google.com; s=arc-20160816; b=h+dQXQRvPj48K8SoEMfyAWJbfbIFTr8YH5IktUN44tBLZDM+ROY+/bLGshUAdKMpni w9fZLPzf00FrT4VFFPeAnxPBmdURxStWAXHqJAGNHCf1ECMYhJj+MzbpbWPTnDnck6xi DEPvmJ7+rduuzujzJWM4+1bLnG534dWb5wK+uWaT0pVzOUFgJ8m8joW9HOsh1cod1oxZ LRtDa6HrvVdmycxOVO174FyBFp1gktgIt+AHtrOshqyHS4vP5E5uUAlarTwPdxSGZQhF Tb1I3SuyAqAWeZhVfI6dnMCXLCdqHZbAIOYAfOJnYg1lE94drVIZ/U29GxbT7M4S5mlX O9fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=dpqlDiB4hX+WGF7HO6/5EfWHYhPI+AkkSY6wCIzaoGI=; b=bSeukWSN4E6meyYSDPgD5imHX2kXA9K8rZ0ODINYDqsDqNg6zy13NQLRzOhpD8SzfA rmP7Sr4KE7hHlGvinpYi6yRFsDP1jdUfQQW//0a8ibT9U1ksKHnMcC4fXzMWdr1jMAt+ jPU5+n/XzhUf0i+t5SmEElME1xlLzDy3Tmta7F1M3wuZAh+qJsrlrR+iT2eS1xZHfINz rl1wiQE46S3SQSg/Qx3SIXBs/5ciLdtAOsgqlOZIjYGb1dOewIetPlZFugZqyWATtkkm JCAW1OWMcFJskOqH3YWA7aMt8orZe7wXvToZOVSvynCZ43+Iz2fSpTmI2Hx3nXI9Izzf nJhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=k7md7ayL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si14845781ejv.524.2020.07.07.12.33.30; Tue, 07 Jul 2020 12:33:54 -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=@nvidia.com header.s=n1 header.b=k7md7ayL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbgGGTa7 (ORCPT + 99 others); Tue, 7 Jul 2020 15:30:59 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4127 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbgGGTa6 (ORCPT ); Tue, 7 Jul 2020 15:30:58 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 07 Jul 2020 12:30:45 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 07 Jul 2020 12:30:58 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 07 Jul 2020 12:30:58 -0700 Received: from [10.2.50.36] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 7 Jul 2020 19:30:57 +0000 Subject: Re: [PATCH v2 2/3] xen/privcmd: Mark pages as dirty To: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= , Souptick Joarder CC: Boris Ostrovsky , , , , Paul Durrant References: <1594059372-15563-1-git-send-email-jrdr.linux@gmail.com> <1594059372-15563-3-git-send-email-jrdr.linux@gmail.com> <8fdd8c77-27dd-2847-7929-b5d3098b1b45@suse.com> <4abc0dd2-655c-16fa-dfc3-95904196c81f@suse.com> From: John Hubbard Message-ID: <4c6e52e7-1d33-132b-1d7e-e57963966dcc@nvidia.com> Date: Tue, 7 Jul 2020 12:30:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <4abc0dd2-655c-16fa-dfc3-95904196c81f@suse.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1594150245; bh=dpqlDiB4hX+WGF7HO6/5EfWHYhPI+AkkSY6wCIzaoGI=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=k7md7ayLM9GOFI11DNbkGz1E86R2aKIrNml3+R0dG1CxEQpyzJwxmDVWz4rsASK/I Tqdu9EMUjsfwzvxkxQfxYOw/cqRVNZH3vST7zs68eD2pn+JZyrRb9s8MHKsB8ODbYn HfgOfBluQzlyPE7gtGVbu740+lonybCMcXoEUlPyVNdwaUB6n1GlppmnknUS6S44pQ 53cO71d9AodweLvrmv422MJjRySe+0+CB34gdp7S0Oynv24TjAoeXoijmbpLzTfoNj MKtnXjDMTRCGqioDkQN7Dh+/amw/q/x0JeMhjvatfn/genCs/lSHd/LnBe1976d6Dd uiI+ffTpw6+og== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-07-07 04:43, J=C3=BCrgen Gro=C3=9F wrote: > On 07.07.20 13:30, Souptick Joarder wrote: >> On Tue, Jul 7, 2020 at 3:08 PM J=C3=BCrgen Gro=C3=9F w= rote: ... >>>> diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c >>>> index 33677ea..f6c1543 100644 >>>> --- a/drivers/xen/privcmd.c >>>> +++ b/drivers/xen/privcmd.c >>>> @@ -612,8 +612,11 @@ static void unlock_pages(struct page *pages[], un= signed int nr_pages) >>>> =C2=A0=C2=A0 { >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int i; >>>> >>>> -=C2=A0=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < nr_pages; i++) >>>> +=C2=A0=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < nr_pages; i++) { >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 if (!PageDirty(pages[i])) >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 set_page_dirty_lock(pag= es[i]); >>> >>> With put_page() directly following I think you should be able to use >>> set_page_dirty() instead, as there is obviously a reference to the page >>> existing. >> >> Patch [3/3] will convert above codes to use unpin_user_pages_dirty_lock(= ) >> which internally do the same check. So I thought to keep linux-stable an= d >> linux-next code in sync. John had a similar concern [1] and later agreed= to keep >> this check. >> >> Shall I keep this check ?=C2=A0 No ? It doesn't matter *too* much, because patch 3/3 fixes up everything by changing it all to unpin_user_pages_dirty_lock(). However, there is somethi= ng to be said for having correct interim patches, too. :) Details: >> >> [1] https://lore.kernel.org/xen-devel/a750e5e5-fd5d-663b-c5fd-261d7c939b= a7@nvidia.com/ >=20 > I wasn't referring to checking PageDirty(), but to the use of > set_page_dirty_lock(). >=20 > Looking at the comment just before the implementation of > set_page_dirty_lock() suggests that it is fine to use set_page_dirty() > instead (so not calling lock_page()). no no, that's a misreading of the comment. Unless this xen/privcmd code has somehow taken a reference on page->mapping->host (which I do *not* think is the case), then it is still racy to call set_page_dirty() here. Instead, set_page_dirty_lock() should be used. >=20 > Only the transition from get_user_pages_fast() to pin_user_pages_fast() > requires to use the locked version IMO. >=20 That's a different misunderstanding. :) pin_user_pages*() APIs are meant to= be functionally drop-in replacements for get_user_pages*(). Internally, pin_user_pages*() functions do some additional tracking, but from a caller'= s perspective, it should look the same. In other words, there is nothing about pin_user_pages_fast() that requires set_page_dirty_lock() upon releas= e. The reason set_page_dirty_lock() was chosen is that there are very few (none at all?) call sites that need to release and dirty a page, that also = meet the requirements to safely call set_page_dirty(). That's why there is a unpin_user_pages_dirty_lock(), but there is not a corresponding unpin_user_pages_dirty() call: the latter has not been requir= ed so far, even though the call site conversions are nearly done. thanks, --=20 John Hubbard NVIDIA