Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1976502pxb; Fri, 5 Mar 2021 04:35:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRbqRF1R8A14MPYaYUzXQcNgCr8lLphImc2sabxtTulcxwXBhprN8Ch9UXS9WX8wEAWp72 X-Received: by 2002:a50:e14d:: with SMTP id i13mr8824642edl.106.1614947737586; Fri, 05 Mar 2021 04:35:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947737; cv=none; d=google.com; s=arc-20160816; b=F0z2z/sPdQDRauTfkofEmdKUmUZ0FgyuDBkmNMQuF4KL0rzBLioGtg8AZ8Wvtem381 1nugpOtxVKy/wUZ9OV4JSTGQUCsD3ZzuUd85C8bHxmzQUqVCBqJP5Cd5ZadWodNwFTX/ 0sfHc7tp97KkCmH7TavOj1v1igQyPcH64bdt/TBHP3WYOunjsIelZgrld93orvITfaPz HRHslYbAfWu4tddlhULc7OuuUYd/mDL5AWKfyN6unQBXSu36VygQqEXD490j5aDoJ0Te +U3IEqMH6+EfATGR14Dj02jsOKggLaOwTaUtqeqA1OQ3QOswkMOkXAsuDsy8uFOQli4x +ujg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+QFwpu/Z5Md0A5n07/tiPhVLiXTNcs07exyPkp5L3y4=; b=wLrflIObYK4aJS1XlIZRQQoctEOPiSEE8dDN3Z6JZMgRNMotl2aBTvEoFxQf/y1o6g 6h1rgqM64fn/y2Z2g4G7IL6bcs0SfEeOTRcIjnd7uy1Io3rZRVFMQLFMHlYonNKJvkCu BjJ6wfSvbYUCmZ/zyoq/i543nP0HI5W7++aCg+/aqg9XQr8rOzbwDSH/J2NRzwo5QJWv iua08W3cdNbRrW45qAj1xM/7PSAUL//qbQCd/ZgrrebvvKEe3i30vvkZk9wghyIJiSqk UWjvkhmHMVIu/7jbByBcPkDgjCqEmqSjAHztAWubfabEPb1Uan5ENIiaYkv7fJrlwSAc VXtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hi0M/OH8"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si1448251edp.20.2021.03.05.04.35.12; Fri, 05 Mar 2021 04:35:37 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="hi0M/OH8"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbhCEMcZ (ORCPT + 99 others); Fri, 5 Mar 2021 07:32:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:41926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231237AbhCEMbk (ORCPT ); Fri, 5 Mar 2021 07:31:40 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A96865045; Fri, 5 Mar 2021 12:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947499; bh=e/I7ecebu8lhCRwpzQcscC41Ud0NkyvmuWpdsP+3PBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hi0M/OH8paFkWbtbT5LzfTdz1JKREMpkwkoehlrWOZagy6EahK1k9wNO/nrR8AgMS ESSQAmwOTI9PSmXU0Kl+QY2k7915XkRctgrhQU5mCmcHq0NRcBG7pftmZhHP65Buwd 8rHgb4qGdZmKFjC31Nbulfc5Gih+h56RhORAS1Dk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Beulich , Juergen Gross Subject: [PATCH 5.10 086/102] Xen/gnttab: handle p2m update errors on a per-slot basis Date: Fri, 5 Mar 2021 13:21:45 +0100 Message-Id: <20210305120907.515988100@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120903.276489876@linuxfoundation.org> References: <20210305120903.276489876@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Beulich commit 8310b77b48c5558c140e7a57a702e7819e62f04e upstream. Bailing immediately from set_foreign_p2m_mapping() upon a p2m updating error leaves the full batch in an ambiguous state as far as the caller is concerned. Instead flags respective slots as bad, unmapping what was mapped there right away. HYPERVISOR_grant_table_op()'s return value and the individual unmap slots' status fields get used only for a one-time - there's not much we can do in case of a failure. Note that there's no GNTST_enomem or alike, so GNTST_general_error gets used. The map ops' handle fields get overwritten just to be on the safe side. This is part of XSA-367. Cc: Signed-off-by: Jan Beulich Reviewed-by: Juergen Gross Link: https://lore.kernel.org/r/96cccf5d-e756-5f53-b91a-ea269bfb9be0@suse.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- arch/arm/xen/p2m.c | 35 +++++++++++++++++++++++++++++++---- arch/x86/xen/p2m.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 7 deletions(-) --- a/arch/arm/xen/p2m.c +++ b/arch/arm/xen/p2m.c @@ -93,12 +93,39 @@ int set_foreign_p2m_mapping(struct gntta int i; for (i = 0; i < count; i++) { + struct gnttab_unmap_grant_ref unmap; + int rc; + if (map_ops[i].status) continue; - if (unlikely(!set_phys_to_machine(map_ops[i].host_addr >> XEN_PAGE_SHIFT, - map_ops[i].dev_bus_addr >> XEN_PAGE_SHIFT))) { - return -ENOMEM; - } + if (likely(set_phys_to_machine(map_ops[i].host_addr >> XEN_PAGE_SHIFT, + map_ops[i].dev_bus_addr >> XEN_PAGE_SHIFT))) + continue; + + /* + * Signal an error for this slot. This in turn requires + * immediate unmapping. + */ + map_ops[i].status = GNTST_general_error; + unmap.host_addr = map_ops[i].host_addr, + unmap.handle = map_ops[i].handle; + map_ops[i].handle = ~0; + if (map_ops[i].flags & GNTMAP_device_map) + unmap.dev_bus_addr = map_ops[i].dev_bus_addr; + else + unmap.dev_bus_addr = 0; + + /* + * Pre-populate the status field, to be recognizable in + * the log message below. + */ + unmap.status = 1; + + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, + &unmap, 1); + if (rc || unmap.status != GNTST_okay) + pr_err_once("gnttab unmap failed: rc=%d st=%d\n", + rc, unmap.status); } return 0; --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -710,6 +710,8 @@ int set_foreign_p2m_mapping(struct gntta for (i = 0; i < count; i++) { unsigned long mfn, pfn; + struct gnttab_unmap_grant_ref unmap[2]; + int rc; /* Do not add to override if the map failed. */ if (map_ops[i].status != GNTST_okay || @@ -727,10 +729,46 @@ int set_foreign_p2m_mapping(struct gntta WARN(pfn_to_mfn(pfn) != INVALID_P2M_ENTRY, "page must be ballooned"); - if (unlikely(!set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) { - ret = -ENOMEM; - goto out; + if (likely(set_phys_to_machine(pfn, FOREIGN_FRAME(mfn)))) + continue; + + /* + * Signal an error for this slot. This in turn requires + * immediate unmapping. + */ + map_ops[i].status = GNTST_general_error; + unmap[0].host_addr = map_ops[i].host_addr, + unmap[0].handle = map_ops[i].handle; + map_ops[i].handle = ~0; + if (map_ops[i].flags & GNTMAP_device_map) + unmap[0].dev_bus_addr = map_ops[i].dev_bus_addr; + else + unmap[0].dev_bus_addr = 0; + + if (kmap_ops) { + kmap_ops[i].status = GNTST_general_error; + unmap[1].host_addr = kmap_ops[i].host_addr, + unmap[1].handle = kmap_ops[i].handle; + kmap_ops[i].handle = ~0; + if (kmap_ops[i].flags & GNTMAP_device_map) + unmap[1].dev_bus_addr = kmap_ops[i].dev_bus_addr; + else + unmap[1].dev_bus_addr = 0; } + + /* + * Pre-populate both status fields, to be recognizable in + * the log message below. + */ + unmap[0].status = 1; + unmap[1].status = 1; + + rc = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, + unmap, 1 + !!kmap_ops); + if (rc || unmap[0].status != GNTST_okay || + unmap[1].status != GNTST_okay) + pr_err_once("gnttab unmap failed: rc=%d st0=%d st1=%d\n", + rc, unmap[0].status, unmap[1].status); } out: