Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp962142imp; Wed, 20 Feb 2019 12:20:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IYjR6V/UYMr0J3ouPJWY0FlbjSl+ucsTsJKYC+e2x2au8oh5elCQ4M65g7S6S0LAW8OPTMS X-Received: by 2002:a17:902:7782:: with SMTP id o2mr39165503pll.315.1550694049322; Wed, 20 Feb 2019 12:20:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550694049; cv=none; d=google.com; s=arc-20160816; b=gNx6kaGFswkpfmq6swaU+kWBETR9F1LrQWSek21ZecrGuITfSGctPBBbSTsXlpcR0D MLjzTO2Pm4eWaaGKYAWJDGDDMWuZZ29MODldz13GUPpPpeohDxAW2fZUGnJnH/JIq39M IPiNQoTJTMssrSff9Fg7zOSVvoa2jnBqWBen2mW6a0+b7nCRGEnqL1eo6+8FOc7zZg3P PQK+8pBpBzfHWOPGmuFTuXwwlxs1auKgbHwCeCkaG9wW/KU7qZ28fqAbl/e+3BybM1oJ pTSJkxUz4wmJGAQBRN7JCMR/fllGYBzw5J8Cqy3kV8q26eKAd/h58NIXNUbiJWSiw05Q T8Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0lg03zJLVaBGqwjLBLKs78/Wx7pcPDjqBK/bhI6FzTQ=; b=0/0GONQSboRqSTpTJBp1UPo47OGZpIdf3E/YRcM6pwfSGMjyCC7m+I0HXwii7tyJed r3AcKQYDQDl7jl5g969yggHQzNtGk2gjF3oGcbbvrh0KeCs33vfScVVAMAo0NKCIjSuG bBFReyEYKqV8b3Umr4UHU4XOz8CxTKl6e2062hiDshSoVo+BNiqzVp6/oMbvBYD8ccPn tyF8QBaAhYBBegOEXLXJqme55/aLx9FK5ip5rLkphB7RqJkcbvRYBaSbxdkMKoHv4Oxq feNGLzdrBwV1qd4sZCzVNFsJP1at9XaeN2XSCZPv4iHzV/Bz8DFzpPE2TgyeggXPLZaP UK0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="x4g9//Af"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si20570616ple.389.2019.02.20.12.20.34; Wed, 20 Feb 2019 12:20:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="x4g9//Af"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728146AbfBTUTF (ORCPT + 99 others); Wed, 20 Feb 2019 15:19:05 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36674 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbfBTUTC (ORCPT ); Wed, 20 Feb 2019 15:19:02 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1KK8X0D087279; Wed, 20 Feb 2019 20:18:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=0lg03zJLVaBGqwjLBLKs78/Wx7pcPDjqBK/bhI6FzTQ=; b=x4g9//AfL0MpMsu69Y6hq7AoBMds9YX5yL1OhI5AxZL/LQXRuWBUi0oC4WuGIcn1XAo1 UZns63sifFX/x0nuectoMd9FXjqfvTC8ozgAr0Q68jx9AFgpHOnECikWTYfRBePPglHG 0C197uIL8dwHMxhbal2FpqPbVplGnTrBs//LyMSWvmZZe9mdUNSTEKaQQwM/ayVgYgo8 E0oCP3+cQ/zk05FJF+QnUwbeAetFfXBnj/6/lwHrO1Yob5VTAG8PXdlOXAYgGQD0gT6k tIVFF0B2imyafuvg3fytEkSIOc/oWqE5udrUbeFcZ9U7C2e8mgm4kaZ/pbS+YiTKOqN4 0Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qpb5rktxa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:18:55 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1KKIsgM030964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:18:54 GMT Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1KKIs1D010292; Wed, 20 Feb 2019 20:18:54 GMT Received: from paddy.lan (/94.61.137.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Feb 2019 12:18:53 -0800 From: Joao Martins To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Ankur Arora , Boris Ostrovsky , Joao Martins , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH RFC 38/39] xen-blkback: xen_shim_domain() support Date: Wed, 20 Feb 2019 20:16:08 +0000 Message-Id: <20190220201609.28290-39-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190220201609.28290-1-joao.m.martins@oracle.com> References: <20190220201609.28290-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=810 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902200138 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With xen_shim_domain() enabled, the struct pages used for grant mappings are only valid in the interval between GNTTABOP_map_grant_ref and GNTTABOP_unmap_grant_ref. Ensure that we do not cache the struct page outside that duration. Also, update the struct page for the segment after GNTTABOP_map_grant_ref, for the subsequent tracking or when doing IO. In addition, we disable persistent grants for this configuration, since the map/unmap overhead is fairly small (in the fast path, page lookup, get_page() and put_page().) This reduces the memory usage in blkback/blkfront. Co-developed-by: Ankur Arora Signed-off-by: Joao Martins Signed-off-by: Ankur Arora --- drivers/block/xen-blkback/blkback.c | 19 ++++++++++++++++--- drivers/block/xen-blkback/xenbus.c | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index d51d88be88e1..20c15e6787b1 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c @@ -167,6 +167,15 @@ static inline void put_free_pages(struct xen_blkif_ring *ring, struct page **pag unsigned long flags; int i; + /* + * We don't own the struct page after unmap has been called. + * Reallocation is cheap anyway for the shim domain case, so free it. + */ + if (xen_shim_domain()) { + gnttab_free_pages(num, page); + return; + } + spin_lock_irqsave(&ring->free_pages_lock, flags); for (i = 0; i < num; i++) list_add(&page[i]->lru, &ring->free_pages); @@ -825,7 +834,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, */ again: for (i = map_until; i < num; i++) { - uint32_t flags; + uint32_t flags = 0; if (use_persistent_gnts) { persistent_gnt = get_persistent_gnt( @@ -846,7 +855,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, addr = vaddr(pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page; pages[i]->persistent_gnt = NULL; - flags = GNTMAP_host_map; + if (!xen_shim_domain()) + flags = GNTMAP_host_map; if (!use_persistent_gnts && ro) flags |= GNTMAP_readonly; gnttab_set_map_op(&map[segs_to_map++], addr, @@ -880,6 +890,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, goto next; } pages[seg_idx]->handle = map[new_map_idx].handle; + if (xen_shim_domain()) + pages[seg_idx]->page = pages_to_gnt[new_map_idx]; } else { continue; } @@ -1478,7 +1490,7 @@ static int __init xen_blkif_init(void) { int rc = 0; - if (!xen_domain()) + if (!xen_domain() && !xen_shim_domain_get()) return -ENODEV; if (xen_blkif_max_ring_order > XENBUS_MAX_RING_GRANT_ORDER) { @@ -1508,6 +1520,7 @@ static void __exit xen_blkif_exit(void) { xen_blkif_interface_exit(); xen_blkif_xenbus_exit(); + xen_shim_domain_put(); } module_exit(xen_blkif_exit); diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 424e2efebe85..11be0c052b77 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -871,7 +871,8 @@ static void connect(struct backend_info *be) xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support); - err = xenbus_printf(xbt, dev->nodename, "feature-persistent", "%u", 1); + err = xenbus_printf(xbt, dev->nodename, "feature-persistent", "%u", + !xen_shim_domain()); if (err) { xenbus_dev_fatal(dev, err, "writing %s/feature-persistent", dev->nodename); @@ -1059,7 +1060,7 @@ static int connect_ring(struct backend_info *be) } pers_grants = xenbus_read_unsigned(dev->otherend, "feature-persistent", 0); - be->blkif->vbd.feature_gnt_persistent = pers_grants; + be->blkif->vbd.feature_gnt_persistent = pers_grants && !xen_shim_domain(); be->blkif->vbd.overflow_max_grants = 0; /* -- 2.11.0