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=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 AD0CFC433DB for ; Fri, 15 Jan 2021 14:22:28 +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 6462F23772 for ; Fri, 15 Jan 2021 14:22:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6462F23772 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com 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.68140.121902 (Exim 4.92) (envelope-from ) id 1l0PzF-0000aM-Kk; Fri, 15 Jan 2021 14:22:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 68140.121902; Fri, 15 Jan 2021 14:22:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0PzF-0000aF-Hc; Fri, 15 Jan 2021 14:22:01 +0000 Received: by outflank-mailman (input) for mailman id 68140; Fri, 15 Jan 2021 14:22:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l0PzE-0000aA-Lg for xen-devel@lists.xenproject.org; Fri, 15 Jan 2021 14:22:00 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 430f0a15-4624-4fb2-a417-ece855ceba26; Fri, 15 Jan 2021 14:21:59 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9736EAC8F; Fri, 15 Jan 2021 14:21:58 +0000 (UTC) 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: 430f0a15-4624-4fb2-a417-ece855ceba26 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610720518; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9oqNTF4et6TgZ+0836/vWtYf6MKTLYnK0gSQLP+eu48=; b=tNJ295P1qOvbucsWNpql1j2E40Izv7YasQVKtgQH63hR8yzZoFmCkCGsmlcVMaDGaJfuvo 4AqvVA8tFv22KL5t06wqCJtc/zzU+qTyVKx/DgLvL9qQjGUDbdMbeLBVbfiqXOXpxu9dYt x3U1YlW3tvTfpbxEif4y3/hFga7gxBg= Subject: Re: [PATCH 1/3] gnttab: adjust pin count overflow checks To: Andrew Cooper Cc: George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu , "xen-devel@lists.xenproject.org" References: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> <38331526-5c24-08d4-b1b6-9baa16251c1d@suse.com> From: Jan Beulich Message-ID: <54c340a9-4515-e79c-84b7-44431c481fba@suse.com> Date: Fri, 15 Jan 2021 15:21:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 15.01.2021 14:35, Andrew Cooper wrote: > On 15/01/2021 13:26, Jan Beulich wrote: >> On 15.01.2021 14:09, Andrew Cooper wrote: >>> On 14/01/2021 15:23, Jan Beulich wrote: >>>> @@ -1052,19 +1063,19 @@ map_grant_ref( >>>> shah = shared_entry_header(rgt, ref); >>>> act = active_entry_acquire(rgt, ref); >>>> >>>> - /* Make sure we do not access memory speculatively */ >>>> - status = evaluate_nospec(rgt->gt_version == 1) ? &shah->flags >>>> - : &status_entry(rgt, ref); >>>> - >>>> /* If already pinned, check the active domid and avoid refcnt overflow. */ >>>> if ( act->pin && >>>> ((act->domid != ld->domain_id) || >>>> - (act->pin & 0x80808080U) != 0 || >>>> + (act->pin & (pin_incr << (GNTPIN_cntr_width - 1))) || >>> This, I'm afraid, is not an improvement.  What we want is: >>> >>> #define GNTPIN_overflow_mask 0x80808080U >>> >>> The reason for checking all at once is defence in depth (not strictly >>> necessary, but also not a problem), >> How is this not a problem? There is absolutely no reason to >> reject a request just because some unrelated field may be >> about to overflow. In fact I now think that I didn't even >> leverage the full potential - the "act->pin != old_pin" check >> could also be relaxed this way, I think. Just that it sits on >> a path we probably don't really care about very much. > > Hmm - I see your point.  I'd missed the fact that a previous operation > could leave this timebomb waiting for us.  (Probably wants a note to > this effect in the commit message). I've added half a sentence. > However we go about fixing it, "pin_incr << (GNTPIN_cntr_width - 1)" is > too obscure IMO.  Perhaps all we need is a > > #define GNTPIN_overflow_mask(x) ((x) << (GNTPIN_cntr_width - 1)) > > but it does occur to me that this logic only works to being with when > pin_incr is strictly 1 in the relevant bytes. Perhaps #define GNTPIN_overflow_mask(x) ({ \ ASSERT(!((x) & ~(GNTPIN_hstw_inc | GNTPIN_hstr_inc | \ GNTPIN_devw_inc | GNTPIN_devr_inc))); \ (x) << (GNTPIN_cntr_width - 1); \ }) ? And maybe name the whole thing e.g. GNTPIN_incr2oflow_mask() to clarify the input is an increment (which I personally take to mean consisting of only values of 1, but I realize views may vary)? Jan