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=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 A59DAC433E0 for ; Mon, 11 Jan 2021 21:23:21 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3324022CB2 for ; Mon, 11 Jan 2021 21:23:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3324022CB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cam.ac.uk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.65376.115809 (Exim 4.92) (envelope-from ) id 1kz4eM-0002ng-1y; Mon, 11 Jan 2021 21:22:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 65376.115809; Mon, 11 Jan 2021 21:22:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kz4eL-0002nZ-Um; Mon, 11 Jan 2021 21:22:53 +0000 Received: by outflank-mailman (input) for mailman id 65376; Mon, 11 Jan 2021 21:22:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kz4eI-0002nO-BU for xen-devel@lists.xenproject.org; Mon, 11 Jan 2021 21:22:51 +0000 Received: from ppsw-41.csi.cam.ac.uk (unknown [131.111.8.141]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1158a2d7-e561-4e34-8729-583f69a34b6a; Mon, 11 Jan 2021 21:22:49 +0000 (UTC) Received: from 88-111-124-141.dynamic.dsl.as9105.com ([88.111.124.141]:48882 helo=[192.168.1.219]) by ppsw-41.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.159]:465) with esmtpsa (PLAIN:amc96) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1kz4e8-000qTF-QO (Exim 4.92.3) (return-path ); Mon, 11 Jan 2021 21:22:40 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1158a2d7-e561-4e34-8729-583f69a34b6a DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cam.ac.uk; s=20180806.ppsw; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IEtjtzZ2aHxFB70Qf7INd8OoFuEgLWM0UWRISsMj7wQ=; b=TwLLNPrZLMNrpjfFhb238FbsTb NSurde/JbY/ZjulleSwo1KVEUaKiEWM4T1yBeYAhQdQIxfbrshbJ/5h0I8W38w8OMJpGvbQ76AZWq vo/+hJkFObzJWozUmg5EsLQ0AtyYflaNfbwq251P3TXZ4r++da3c87zWTMwz4uA8MSKg=; X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://help.uis.cam.ac.uk/email-scanner-virus Subject: Re: [PATCH v2 02/11] xen/gnttab: Rework resource acquisition To: paul@xen.org, 'Xen-devel' Cc: 'George Dunlap' , 'Ian Jackson' , 'Jan Beulich' , 'Stefano Stabellini' , 'Wei Liu' , 'Julien Grall' , =?UTF-8?B?J01pY2hhxYIgTGVzemN6ecWEc2tpJw==?= , 'Hubert Jasudowicz' , 'Tamas K Lengyel' , Andrew Cooper References: <20200922182444.12350-1-andrew.cooper3@citrix.com> <20200922182444.12350-3-andrew.cooper3@citrix.com> <001601d69258$4d6a7c90$e83f75b0$@xen.org> From: Andrew Cooper Message-ID: <835893e1-fcd0-efa1-86ce-02af70dd1101@cam.ac.uk> Date: Mon, 11 Jan 2021 21:22:39 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <001601d69258$4d6a7c90$e83f75b0$@xen.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-GB On 24/09/2020 10:51, Paul Durrant wrote: >> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c >> index a5d3ed8bda..912f07be47 100644 >> --- a/xen/common/grant_table.c >> +++ b/xen/common/grant_table.c >> @@ -4013,6 +4013,81 @@ static int gnttab_get_shared_frame_mfn(struct domain *d, >> return 0; >> } >> >> +int gnttab_acquire_resource( >> + struct domain *d, unsigned int id, unsigned long frame, >> + unsigned int nr_frames, xen_pfn_t mfn_list[]) >> +{ >> + struct grant_table *gt = d->grant_table; >> + unsigned int i = nr_frames, tot_frames; >> + mfn_t tmp; >> + void **vaddrs = NULL; >> + int rc; >> + >> + /* Input sanity. */ > Nit: inconsistency with full stops on single line comments. The whole point of relaxing the style was because feedback over minutia such as this was deemed detrimental to the community. If I ever see feedback like this, I will commit commit the patch there and then.  This is the only way upstream Xen is going to turn into a less toxic environment for contributors. >> + rc = -EINVAL; >> + break; >> + } >> + rc = gnttab_get_status_frame_mfn(d, tot_frames - 1, &tmp); >> + break; >> + } >> + > I think you could drop the write lock here... > >> + /* Any errors from growing the table? */ >> + if ( rc ) >> + goto out; >> + > ...and acquire it read here, since we know the table cannot shrink. You'd need to re-check the gt_version for safety though. And you've correctly identified why I didn't.  If we had a relax-write-to-read lock operation, that would also be fine, but we don't. Fundamentally, this is an operation made once during VM construction, to map one single frame.  It is not a hotpath in need of microptimising its locking pattern, and absolutely not something worth introducing a safety hazard for. ~Andrew