Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1977853pxb; Fri, 5 Mar 2021 04:37:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRW6LGg/yWyb/gURp51NR91riwNSoLLtmbjOCnzM9Qe5cMMf9XB+fHASfZym0erJIar73Q X-Received: by 2002:a17:906:9243:: with SMTP id c3mr1661779ejx.388.1614947844822; Fri, 05 Mar 2021 04:37:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947844; cv=none; d=google.com; s=arc-20160816; b=S4pTUDgPHHuEQWARSuvaoFBCKFoU7ncKtNP2mMuWz4oKsvtP9x5W5yDfmfaXH6ZPV6 GBTJ1qsC5SCxZ8J58wKUPPOFzJhFaHiPCXBIhFqrpDiBJBqU+0O5d0LrZLuP8aF5bEnG 5QzyfvH3eBukhmdO4uLpOrOjh1LZB7471Wz7cQxnLfEeL3MkN/ddYk69umVhW9UX01tm bgRqG0MzbM08FEatqM7aY9eZVi026pkH44RaNeFfYtBTJHL2LlSnq86IUGrzvFruo59O J1JDlAq+CWct9AyoBebrkC7jChfzU6fbHhHQd1I67hsHpwv0DKxcEDuTpCVt1E8BOGYO Dmgg== 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=gHX52HgJnD2zzbS02n+eaOHdu+LexQPUH2qWHg3NOkw=; b=w+iuAujg+f08BKS+amRXekYnncmWCPLGh4a/FvLZ2V9RUPfK+h8TsPUXK6C/BfEQEy /VJlyY7uXSwJnA8v3eGIcWYBAefNY8irpOS9OQsI9Qf/7RgDC5tj6/Uq3YeorZB8c/E5 sahHvLwAVEimGCBf7PQPuBwhzmbOeQdvurhRRBEe7AqSwnqwmhriTxY86O2BppwuufEP S64DxT9KwhxWw0adCecd6i12aCTZR5TgkOM0nvpCsxBlN31WYofbSgNcCaA61ZE//1t3 TrWY2V/kUVpjHSFi8ZNyBAoYlfCkJu1Yzt2OHn9ZaTp5x0VjAcRWj38opDq+ngNGVtyc WWUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FSFFwPaI; 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 r21si1282288ejo.123.2021.03.05.04.37.02; Fri, 05 Mar 2021 04:37:24 -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=FSFFwPaI; 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 S229781AbhCEMgG (ORCPT + 99 others); Fri, 5 Mar 2021 07:36:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:47644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232369AbhCEMfe (ORCPT ); Fri, 5 Mar 2021 07:35:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30D5064FF0; Fri, 5 Mar 2021 12:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947733; bh=mxwPGyoj6tHA9XoYB55UgVyqpSa9nyqswibdYJksJ8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FSFFwPaIyf+ocLW5vytlPuJdrG4qVMrC6uS5ZWNJtvDnh5/dH5pU3L0+/DFxW91I4 1w2QAsLWjXTiv2XJb45Ta41au7Ywb39EoT+j6PzstFQF79XDPIaA5jxk+UlHIryCHO cszlC7E/UltRJAG+FtZFye0J7MDXb1vc+zvrTNeA= 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.4 65/72] Xen/gnttab: handle p2m update errors on a per-slot basis Date: Fri, 5 Mar 2021 13:22:07 +0100 Message-Id: <20210305120900.521162855@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120857.341630346@linuxfoundation.org> References: <20210305120857.341630346@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 @@ -714,6 +714,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 || @@ -731,10 +733,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: