From nobody Fri May 3 23:55:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610637825; cv=none; d=zohomail.com; s=zohoarc; b=K57mFacJyC6CiD6bnsVl3iSIhgLFDSkWmVsxjsZKELZbDfpqMPdUr0e363TTH/CYcmvU+wRIEiyR3Y2fj5giFUtvdKFFjYuzyVIq1e3Xuc3jRwA5cXmTn8gC3ICvlJU3d1cYra9lO4fQaAy/1nIkE19ppql7XHET5qo7MA4BVo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610637825; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gDxKZJvVeCw6bI1HCjMqfPdjKwcrVa8JpjiVL8f6Rh0=; b=Dwyp68oLl6t1YEDZiuAPjE81h6pjbO4NUam+MEDp8Bp5ax7td+pP9KEyaOzS/+g6vHQ2ct3uWb7qHiypKSoPBSWWS8aVt9wz1zCNxGFwMxkGHf8lJ8ThQcOlZjU7lml+AyMvbLn+wCuJl9YIl0ed2R4QhOYdNsLsmL9a82z0RD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610637825193174.83103276222164; Thu, 14 Jan 2021 07:23:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67159.119613 (Exim 4.92) (envelope-from ) id 1l04TA-0000XW-8u; Thu, 14 Jan 2021 15:23:28 +0000 Received: by outflank-mailman (output) from mailman id 67159.119613; Thu, 14 Jan 2021 15:23:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04TA-0000XP-4J; Thu, 14 Jan 2021 15:23:28 +0000 Received: by outflank-mailman (input) for mailman id 67159; Thu, 14 Jan 2021 15:23:27 +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 1l04T9-0000XK-2N for xen-devel@lists.xenproject.org; Thu, 14 Jan 2021 15:23:27 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e704fada-4c4f-44c2-b0ea-03f459e5cfc0; Thu, 14 Jan 2021 15:23:25 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E8391AEAB; Thu, 14 Jan 2021 15:23:24 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: e704fada-4c4f-44c2-b0ea-03f459e5cfc0 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=1610637805; 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=gDxKZJvVeCw6bI1HCjMqfPdjKwcrVa8JpjiVL8f6Rh0=; b=ZzSkq6nsz+Scy3LhPyKuoVdqOxWS3qXBq0TnaR6pYcdHxuX2j8k5+nKBqpc+JUnuEJHmvq NUArRDQPF3HSQREoD2wmbhJhIFxr5VTlovo+njCIUTL2TcRqt9AnsD1vMMIQOia6bitVbM DkFt088WRjeg+sa3gSE66poo5EAGYvs= Subject: [PATCH 1/3] gnttab: adjust pin count overflow checks From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Message-ID: <38331526-5c24-08d4-b1b6-9baa16251c1d@suse.com> Date: Thu, 14 Jan 2021 16:23:25 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" It's at least odd to check counters which aren't going to be incremented. And it's also not helpful to use open-coded literal numbers in these checks. Calculate the increment values first and derive from them the mask to use in the checks. Also move the pin count checks ahead of the calculation of the status (and for copy also sha2) pointers: They're not needed in the failure cases, and this way the compiler may also have an easier time keeping the variables at least transiently in registers for the subsequent uses. Signed-off-by: Jan Beulich --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -323,22 +323,25 @@ shared_entry_header(struct grant_table * /* Active grant entry - used for shadowing GTF_permit_access grants. */ struct active_grant_entry { uint32_t pin; /* Reference count information: */ + /* Width of the individual counter fields. */ +#define GNTPIN_cntr_width 8 +#define GNTPIN_cntr_mask ((1U << GNTPIN_cntr_width) - 1) /* Count of writable host-CPU mappings. */ #define GNTPIN_hstw_shift 0 #define GNTPIN_hstw_inc (1U << GNTPIN_hstw_shift) -#define GNTPIN_hstw_mask (0xFFU << GNTPIN_hstw_shift) +#define GNTPIN_hstw_mask (GNTPIN_cntr_mask << GNTPIN_hstw_shift) /* Count of read-only host-CPU mappings. */ -#define GNTPIN_hstr_shift 8 +#define GNTPIN_hstr_shift (GNTPIN_hstw_shift + GNTPIN_cntr_width) #define GNTPIN_hstr_inc (1U << GNTPIN_hstr_shift) -#define GNTPIN_hstr_mask (0xFFU << GNTPIN_hstr_shift) +#define GNTPIN_hstr_mask (GNTPIN_cntr_mask << GNTPIN_hstr_shift) /* Count of writable device-bus mappings. */ -#define GNTPIN_devw_shift 16 +#define GNTPIN_devw_shift (GNTPIN_hstr_shift + GNTPIN_cntr_width) #define GNTPIN_devw_inc (1U << GNTPIN_devw_shift) -#define GNTPIN_devw_mask (0xFFU << GNTPIN_devw_shift) +#define GNTPIN_devw_mask (GNTPIN_cntr_mask << GNTPIN_devw_shift) /* Count of read-only device-bus mappings. */ -#define GNTPIN_devr_shift 24 +#define GNTPIN_devr_shift (GNTPIN_devw_shift + GNTPIN_cntr_width) #define GNTPIN_devr_inc (1U << GNTPIN_devr_shift) -#define GNTPIN_devr_mask (0xFFU << GNTPIN_devr_shift) +#define GNTPIN_devr_mask (GNTPIN_cntr_mask << GNTPIN_devr_shift) =20 domid_t domid; /* Domain being granted access. */ unsigned int start:15; /* For sub-page grants, the start offset @@ -988,7 +991,8 @@ map_grant_ref( mfn_t mfn; struct page_info *pg =3D NULL; int rc =3D GNTST_okay; - unsigned int cache_flags, clear_flags =3D 0, refcnt =3D 0, typecnt = =3D 0; + unsigned int cache_flags, clear_flags =3D 0, refcnt =3D 0, typecnt = =3D 0, + pin_incr =3D 0; bool host_map_created =3D false; struct active_grant_entry *act =3D NULL; struct grant_mapping *mt; @@ -998,7 +1002,14 @@ map_grant_ref( =20 ld =3D current->domain; =20 - if ( unlikely((op->flags & (GNTMAP_device_map|GNTMAP_host_map)) =3D=3D= 0) ) + if ( op->flags & GNTMAP_device_map ) + pin_incr +=3D (op->flags & GNTMAP_readonly) ? GNTPIN_devr_inc + : GNTPIN_devw_inc; + if ( op->flags & GNTMAP_host_map ) + pin_incr +=3D (op->flags & GNTMAP_readonly) ? GNTPIN_hstr_inc + : GNTPIN_hstw_inc; + + if ( unlikely(!pin_incr) ) { gdprintk(XENLOG_INFO, "Bad flags in grant map op: %x\n", op->flags= ); op->status =3D GNTST_bad_gntref; @@ -1052,19 +1063,19 @@ map_grant_ref( shah =3D shared_entry_header(rgt, ref); act =3D active_entry_acquire(rgt, ref); =20 - /* Make sure we do not access memory speculatively */ - status =3D evaluate_nospec(rgt->gt_version =3D=3D 1) ? &shah->flags - : &status_entry(rgt, ref); - /* If already pinned, check the active domid and avoid refcnt overflow= . */ if ( act->pin && ((act->domid !=3D ld->domain_id) || - (act->pin & 0x80808080U) !=3D 0 || + (act->pin & (pin_incr << (GNTPIN_cntr_width - 1))) || (act->is_sub_page)) ) PIN_FAIL(act_release_out, GNTST_general_error, "Bad domain (%d !=3D %d), or risk of counter overflow %08= x, or subpage %d\n", act->domid, ld->domain_id, act->pin, act->is_sub_page); =20 + /* Make sure we do not access memory speculatively */ + status =3D evaluate_nospec(rgt->gt_version =3D=3D 1) ? &shah->flags + : &status_entry(rgt, re= f); + if ( !act->pin || (!(op->flags & GNTMAP_readonly) && !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask))) ) @@ -1095,12 +1106,7 @@ map_grant_ref( } } =20 - if ( op->flags & GNTMAP_device_map ) - act->pin +=3D (op->flags & GNTMAP_readonly) ? - GNTPIN_devr_inc : GNTPIN_devw_inc; - if ( op->flags & GNTMAP_host_map ) - act->pin +=3D (op->flags & GNTMAP_readonly) ? - GNTPIN_hstr_inc : GNTPIN_hstw_inc; + act->pin +=3D pin_incr; =20 mfn =3D act->mfn; =20 @@ -1275,13 +1281,7 @@ map_grant_ref( grant_read_lock(rgt); =20 act =3D active_entry_acquire(rgt, op->ref); - - if ( op->flags & GNTMAP_device_map ) - act->pin -=3D (op->flags & GNTMAP_readonly) ? - GNTPIN_devr_inc : GNTPIN_devw_inc; - if ( op->flags & GNTMAP_host_map ) - act->pin -=3D (op->flags & GNTMAP_readonly) ? - GNTPIN_hstr_inc : GNTPIN_hstw_inc; + act->pin -=3D pin_incr; =20 unlock_out_clear: if ( !(op->flags & GNTMAP_readonly) && @@ -2516,6 +2516,7 @@ acquire_grant_for_copy( uint16_t trans_length; bool is_sub_page; s16 rc =3D GNTST_okay; + unsigned int pin_incr =3D readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc; unsigned int clear_flags =3D 0; =20 *page =3D NULL; @@ -2530,6 +2531,14 @@ acquire_grant_for_copy( shah =3D shared_entry_header(rgt, gref); act =3D active_entry_acquire(rgt, gref); =20 + /* If already pinned, check the active domid and avoid refcnt overflow= . */ + if ( act->pin && + ((act->domid !=3D ldom) || + (act->pin & (pin_incr << (GNTPIN_cntr_width - 1)))) ) + PIN_FAIL(unlock_out, GNTST_general_error, + "Bad domain (%d !=3D %d), or risk of counter overflow %08= x\n", + act->domid, ldom, act->pin); + if ( evaluate_nospec(rgt->gt_version =3D=3D 1) ) { sha2 =3D NULL; @@ -2541,12 +2550,6 @@ acquire_grant_for_copy( status =3D &status_entry(rgt, gref); } =20 - /* If already pinned, check the active domid and avoid refcnt overflow= . */ - if ( act->pin && ((act->domid !=3D ldom) || (act->pin & 0x80808080U) != =3D 0) ) - PIN_FAIL(unlock_out, GNTST_general_error, - "Bad domain (%d !=3D %d), or risk of counter overflow %08= x\n", - act->domid, ldom, act->pin); - old_pin =3D act->pin; if ( sha2 && (shah->flags & GTF_type_mask) =3D=3D GTF_transitive ) { @@ -2728,7 +2731,7 @@ acquire_grant_for_copy( } } =20 - act->pin +=3D readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc; + act->pin +=3D pin_incr; =20 *page_off =3D act->start; *length =3D act->length; From nobody Fri May 3 23:55:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610637850; cv=none; d=zohomail.com; s=zohoarc; b=E+mFG0VbU+uOHj84jZQoc0b/znE14nxfGXmlxBjHV5oVCuaGsUv8vS6CxeWINB1qNHwh8kb88aTUFkjgvHVc9CIlLQAiYHhi2qzJtUBeVd8TzO5qsHg9SPH6uLJBwAxuguV2qzS//q58ZlL9u48svzxMmRqyxQKrwxcR05rioR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610637850; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fNiAyk16ONrTzcmz1yqaPikcT/RPQ4kXmUtWKkq/WvA=; b=JCkKbfKJhfQqXtuZN4hW8QXr2unOQ7kk4B9xJTKS8YjYIQEkv4V1/qwyhbghURopJ4FR51qFituhibTbPZvmVYmnjQ52EDMAmiMKiA7IkQhtSJczjvQE3Z0d3+B3uOxguai+K9p3/q8uuvBIpBEGZhbg8gJZt4j0jdFo9z627xs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610637850754195.84205854233596; Thu, 14 Jan 2021 07:24:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67163.119624 (Exim 4.92) (envelope-from ) id 1l04TW-0000cs-Fi; Thu, 14 Jan 2021 15:23:50 +0000 Received: by outflank-mailman (output) from mailman id 67163.119624; Thu, 14 Jan 2021 15:23:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04TW-0000cl-CU; Thu, 14 Jan 2021 15:23:50 +0000 Received: by outflank-mailman (input) for mailman id 67163; Thu, 14 Jan 2021 15:23:49 +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 1l04TV-0000cd-HI for xen-devel@lists.xenproject.org; Thu, 14 Jan 2021 15:23:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7873b4be-a62e-4484-b1c7-c800cfe9f6eb; Thu, 14 Jan 2021 15:23:48 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 73EF9AC24; Thu, 14 Jan 2021 15:23:47 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7873b4be-a62e-4484-b1c7-c800cfe9f6eb 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=1610637827; 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=fNiAyk16ONrTzcmz1yqaPikcT/RPQ4kXmUtWKkq/WvA=; b=h3lDOjOHjMs6D4e1JWift7Ax49ulM6DdMMT08dy5atumaqpo6pJOZ8cdhWpJL6r5OnIxhd t9lNFaUAus37rwej7wWbCuRbCzeG4dc6l9/5jt6F1ZrkD9lngCSIUPyezOep7+wD4zRud0 Y7mOJbxq9/gJAU7/IA5t9sEefz4admQ= Subject: [PATCH 2/3] gnttab: consolidate pin-to-status syncing From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Message-ID: <5e84b80d-4b6f-118b-c2cb-071e6e774db5@suse.com> Date: Thu, 14 Jan 2021 16:23:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Forever since the fix for XSA-230 the 2nd of the comments ahead of fixup_status_for_copy_pin() has been stale - there's nothing specific to transitive grants there anymore. Move the function up, drop the "copy" part from its name again, add a "readonly" parameter, and use it also on other paths having decremented one (or not having got to increment any) of the pin counts. Signed-off-by: Jan Beulich --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -908,6 +908,25 @@ static int _set_status(const grant_entry return _set_status_v2(shah, status, rd, act, readonly, mapflag, ld= omid); } =20 +/* + * The status for a grant may indicate that we're taking more access than + * the pin requires. Fix up the status to match the pin. Called with the + * domain's grant table lock held at least in read mode and with the active + * entry lock held (iow act->pin can't change behind our backs). + */ +static void fixup_status_for_pin(struct domain *rd, + const struct active_grant_entry *act, + uint16_t *status, bool readonly) +{ + unsigned int clear_flags =3D act->pin ? 0 : GTF_reading; + + if ( !readonly && !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) + clear_flags |=3D GTF_writing; + + if ( clear_flags ) + gnttab_clear_flags(rd, clear_flags, status); +} + static struct active_grant_entry *grant_map_exists(const struct domain *ld, struct grant_table *rgt, mfn_t mfn, @@ -991,8 +1010,7 @@ map_grant_ref( mfn_t mfn; struct page_info *pg =3D NULL; int rc =3D GNTST_okay; - unsigned int cache_flags, clear_flags =3D 0, refcnt =3D 0, typecnt = =3D 0, - pin_incr =3D 0; + unsigned int cache_flags, refcnt =3D 0, typecnt =3D 0, pin_incr =3D = 0; bool host_map_created =3D false; struct active_grant_entry *act =3D NULL; struct grant_mapping *mt; @@ -1284,15 +1302,7 @@ map_grant_ref( act->pin -=3D pin_incr; =20 unlock_out_clear: - if ( !(op->flags & GNTMAP_readonly) && - !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) ) - clear_flags |=3D GTF_writing; - - if ( !act->pin ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); + fixup_status_for_pin(rd, act, status, op->flags & GNTMAP_readonly); =20 act_release_out: active_entry_release(act); @@ -1507,7 +1517,6 @@ unmap_common_complete(struct gnttab_unma grant_entry_header_t *sha; struct page_info *pg; uint16_t *status; - unsigned int clear_flags =3D 0; =20 if ( evaluate_nospec(!op->done) ) { @@ -1566,15 +1575,7 @@ unmap_common_complete(struct gnttab_unma act->pin -=3D GNTPIN_hstw_inc; } =20 - if ( ((act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0) && - !(op->done & GNTMAP_readonly) ) - clear_flags |=3D GTF_writing; - - if ( act->pin =3D=3D 0 ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); + fixup_status_for_pin(rd, act, status, op->done & GNTMAP_readonly); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2414,7 +2415,6 @@ release_grant_for_copy( uint16_t *status; grant_ref_t trans_gref; struct domain *td; - unsigned int clear_flags =3D 0; =20 grant_read_lock(rgt); =20 @@ -2444,15 +2444,9 @@ release_grant_for_copy( gnttab_mark_dirty(rd, mfn); =20 act->pin -=3D GNTPIN_hstw_inc; - if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) ) - clear_flags |=3D GTF_writing; } =20 - if ( !act->pin ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); + fixup_status_for_pin(rd, act, status, readonly); =20 active_entry_release(act); grant_read_unlock(rgt); @@ -2469,27 +2463,6 @@ release_grant_for_copy( } } =20 -/* The status for a grant indicates that we're taking more access than - the pin requires. Fix up the status to match the pin. Called - under the domain's grant table lock. */ -/* Only safe on transitive grants. Even then, note that we don't - attempt to drop any pin on the referent grant. */ -static void fixup_status_for_copy_pin(struct domain *rd, - const struct active_grant_entry *act, - uint16_t *status) -{ - unsigned int clear_flags =3D 0; - - if ( !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - clear_flags |=3D GTF_writing; - - if ( !act->pin ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); -} - /* * Grab a machine frame number from a grant entry and update the flags * and pin count as appropriate. If rc =3D=3D GNTST_okay, note that this *= does* @@ -2517,7 +2490,6 @@ acquire_grant_for_copy( bool is_sub_page; s16 rc =3D GNTST_okay; unsigned int pin_incr =3D readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc; - unsigned int clear_flags =3D 0; =20 *page =3D NULL; =20 @@ -2604,8 +2576,8 @@ acquire_grant_for_copy( =20 if ( rc !=3D GNTST_okay ) { - fixup_status_for_copy_pin(rd, act, status); rcu_unlock_domain(td); + fixup_status_for_pin(rd, act, status, readonly); active_entry_release(act); grant_read_unlock(rgt); return rc; @@ -2627,8 +2599,8 @@ acquire_grant_for_copy( !act->is_sub_page)) ) { release_grant_for_copy(td, trans_gref, readonly); - fixup_status_for_copy_pin(rd, act, status); rcu_unlock_domain(td); + fixup_status_for_pin(rd, act, status, readonly); active_entry_release(act); grant_read_unlock(rgt); put_page(*page); @@ -2742,15 +2714,7 @@ acquire_grant_for_copy( return rc; =20 unlock_out_clear: - if ( !(readonly) && - !(act->pin & (GNTPIN_hstw_mask | GNTPIN_devw_mask)) ) - clear_flags |=3D GTF_writing; - - if ( !act->pin ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); + fixup_status_for_pin(rd, act, status, readonly); =20 unlock_out: active_entry_release(act); @@ -3720,8 +3684,6 @@ gnttab_release_mappings( =20 for ( handle =3D 0; handle < gt->maptrack_limit; handle++ ) { - unsigned int clear_flags =3D 0; - map =3D &maptrack_entry(gt, handle); if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) ) continue; @@ -3794,16 +3756,9 @@ gnttab_release_mappings( put_page(pg); } } - - if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) =3D=3D 0= ) - clear_flags |=3D GTF_writing; } =20 - if ( act->pin =3D=3D 0 ) - clear_flags |=3D GTF_reading; - - if ( clear_flags ) - gnttab_clear_flags(rd, clear_flags, status); + fixup_status_for_pin(rd, act, status, map->flags & GNTMAP_readonly= ); =20 active_entry_release(act); grant_read_unlock(rgt); From nobody Fri May 3 23:55:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1610637910; cv=none; d=zohomail.com; s=zohoarc; b=RGBWRkkQO36Ir/Bd96iTUeKgxxc5jawzAdUHQnPOR9Hk7rpfQpw8ZfYex5qad4lYMI0M594HGql/1BmCOL412ODrUFGf2MIIXoZqhFRxiU5bEqTO1Vhtfa9XdeX82vsWOpgPpgx0Zzv1vtW16nRkoGaItnqz3xcgNfoXGN9QKoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610637910; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Lts7CySriGzaIuo7oOl66Ck1Wo/oUcoNPO4mvay9Lyw=; b=hBDDUuDCo7dvJVngsbfkoPh7ckRD4kKKDgnxjD6IOecgC36mRPt4JOoJYJxIuIE6yDEE5gCqHysUkJcn0UUW9UTN4qc+ttTqlCUCaMpuLqtHZgeg4Rjuu/AlsoumsfRqAL0gA549ig7iYfJjmq7yMDXspLyZZSCVwyPeh/OeUvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610637910581196.03231697952856; Thu, 14 Jan 2021 07:25:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.67172.119648 (Exim 4.92) (envelope-from ) id 1l04UV-0000tT-8S; Thu, 14 Jan 2021 15:24:51 +0000 Received: by outflank-mailman (output) from mailman id 67172.119648; Thu, 14 Jan 2021 15:24:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04UV-0000tM-55; Thu, 14 Jan 2021 15:24:51 +0000 Received: by outflank-mailman (input) for mailman id 67172; Thu, 14 Jan 2021 15:24:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l04UU-0000tF-7e for xen-devel@lists.xenproject.org; Thu, 14 Jan 2021 15:24:50 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5d64bccf-4697-40f1-9fa5-5421dfe3067e; Thu, 14 Jan 2021 15:24:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 97472AC24; Thu, 14 Jan 2021 15:24:48 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 5d64bccf-4697-40f1-9fa5-5421dfe3067e 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=1610637888; 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=Lts7CySriGzaIuo7oOl66Ck1Wo/oUcoNPO4mvay9Lyw=; b=NNussvVFVdHlAXlPtDqBwoNkz9+vF54NGR+LsLyjT4yzFQrKJ+fZd+7mVpQqVbDomXV0ZJ wDkt+TVMkVT432HE+0Oyov/bXBihGPFENGmpMqNFNvGqzeVbLrd3XPuWo1GLOM8rNKygzk 6K0pHPpKKXZ+9jiVyvahZnQslRRN1a4= Subject: [PATCH 3/3] Arm: don't hard-code grant table limits in create_domUs() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Julien Grall , Stefano Stabellini , George Dunlap References: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Message-ID: <90ddf638-500f-0697-dcf7-6e8026af6e02@suse.com> Date: Thu, 14 Jan 2021 16:24:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <556c42fd-d7f8-f09f-eb3a-6b724d2b467d@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" I can only assume that f2ae59bc4b9b ("Rationalize max_grant_frames and max_maptrack_frames handling") unintentionally left Arm's create_domUs() set limits to explicit values, as at least some of the same constraints apply here. Signed-off-by: Jan Beulich Acked-by: Stefano Stabellini --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2480,8 +2480,8 @@ void __init create_domUs(void) .arch.gic_version =3D XEN_DOMCTL_CONFIG_GIC_NATIVE, .flags =3D XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap, .max_evtchn_port =3D -1, - .max_grant_frames =3D 64, - .max_maptrack_frames =3D 1024, + .max_grant_frames =3D -1, + .max_maptrack_frames =3D -1, }; =20 if ( !dt_device_is_compatible(node, "xen,domain") )