Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1341440pxk; Fri, 18 Sep 2020 09:52:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwglj4yUvJhJeh3NT3BXXY31smNM6wy+M2KY5hvpkySOwXTkGMhr49FmgokIcc90xCqseUc X-Received: by 2002:aa7:c707:: with SMTP id i7mr39708098edq.107.1600447921967; Fri, 18 Sep 2020 09:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600447921; cv=none; d=google.com; s=arc-20160816; b=PfI5imGR3S2ZnZiJfIyJ00kpL7CeWjzCT2tzL4wgvg1VFZuB17Y4IGheWWT6TkX0dX P4aDK7BElDzLYMxd7BboyD1Xbq05two8d9ZYCoRPRd30RO4apgKmRQNOIWf3xcVKCyuI 3PCsuH0TGHUtoryNj8O2D/byQ1wQ1nYPKW4J60BLOTXmt4JkHfycyiC5sghNeugolZmR Kq5+m591T++Cy1ZIncRMRFs51wi07r+8kZArv7eyhexoQNQAE/Hjo/texfG6eDlGZmWs U2UU3704Ogoi3n18fdfmFYomNqwPAoenvyEFeyQYr4TLU0Ic00CpLUJnpGF50wDBgeg4 x+Pg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UxCKXqRP/rysmc9RNpHAJ/UIhdxbXkB6cd/t5AXU7G8=; b=iHGP8nh2n8SGWGJ39IQBVkgx8vK+0k2AzJqO5iUkjvBu+76n+zO3JcWY3OgGWSIAit y4zBF9OqsDB/W/wc5L4ccg5Wd7bbQzNOY33En56rFkSjHuo7W6VnXUB+Ehi8WZe9Ne83 Go742SUjn6dui9Ag+180o3TtPQ2OytE4AIv1BR7tcayF84rokAEDxsIq/4188/TJsXvt uLR8mvRDUk/0Aidbi8fzPJeNYEOuJCgqpn8PhGBzdZhE+UPTsmRtQIF48bUSkjS5QakK MhaQ731BhYxbtx+CJfQBRFHpUIq1a8BaskuNbobL+55VtAXx6sEtCv44zWNbqsohlA7F XsaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cpCprZwn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si3267193edv.195.2020.09.18.09.51.37; Fri, 18 Sep 2020 09:52:01 -0700 (PDT) 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=@infradead.org header.s=casper.20170209 header.b=cpCprZwn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbgIRQuj (ORCPT + 99 others); Fri, 18 Sep 2020 12:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbgIRQuj (ORCPT ); Fri, 18 Sep 2020 12:50:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9247BC0613CE for ; Fri, 18 Sep 2020 09:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UxCKXqRP/rysmc9RNpHAJ/UIhdxbXkB6cd/t5AXU7G8=; b=cpCprZwn/AafJTn6MHEbaradk7 t/YIiBsf+ylm0zuSEvtQJJqSQ4lNxxXz65sGW+WcamVSPFNTyaoIwTXkXKE1Gh8glqiczJV2J/0Ze AVJM1fdUpkGwFGrNF3JaNgerTd951R06BJgp654l8tPfJvNhcQADyo0X3aR/tXbEiIykkE5RGf7JZ MoFxDTuhrUAHst0ZL1cwk7zQeYAxZD/azM9vvST9VjX3BCCT8szgChY0L89mIBv5In3yssxZv0ghd 4HxI47BxGE8GM2KL7O1rUjcNzYDg8CUmEmG0sOKSEV9Ie0eW0pyXfXTlmZP3sAtzT00mzvFELhMt9 62Kb7LMA==; Received: from 089144214092.atnat0023.highway.a1.net ([89.144.214.92] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJag-0007nv-Hp; Fri, 18 Sep 2020 16:50:30 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Peter Zijlstra , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Minchan Kim , Nitin Gupta , x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org Subject: [PATCH 5/6] xen/xenbus: use apply_to_page_range directly in xenbus_map_ring_pv Date: Fri, 18 Sep 2020 18:37:23 +0200 Message-Id: <20200918163724.2511-6-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918163724.2511-1-hch@lst.de> References: <20200918163724.2511-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing alloc_vm_area with get_vm_area_caller + apply_page_range allows to fill put the phys_addr values directly instead of doing another loop over all addresses. Signed-off-by: Christoph Hellwig --- drivers/xen/xenbus/xenbus_client.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 2690318ad50f48..fd80e318b99cc7 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -73,16 +73,13 @@ struct map_ring_valloc { struct xenbus_map_node *node; /* Why do we need two arrays? See comment of __xenbus_map_ring */ - union { - unsigned long addrs[XENBUS_MAX_RING_GRANTS]; - pte_t *ptes[XENBUS_MAX_RING_GRANTS]; - }; + unsigned long addrs[XENBUS_MAX_RING_GRANTS]; phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS]; struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS]; - unsigned int idx; /* HVM only. */ + unsigned int idx; }; static DEFINE_SPINLOCK(xenbus_valloc_lock); @@ -686,6 +683,14 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr) EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree); #ifdef CONFIG_XEN_PV +static int map_ring_apply(pte_t *pte, unsigned long addr, void *data) +{ + struct map_ring_valloc *info = data; + + info->phys_addrs[info->idx++] = arbitrary_virt_to_machine(pte).maddr; + return 0; +} + static int xenbus_map_ring_pv(struct xenbus_device *dev, struct map_ring_valloc *info, grant_ref_t *gnt_refs, @@ -694,18 +699,15 @@ static int xenbus_map_ring_pv(struct xenbus_device *dev, { struct xenbus_map_node *node = info->node; struct vm_struct *area; - int err = GNTST_okay; - int i; - bool leaked; + bool leaked = false; + int err = -ENOMEM; - area = alloc_vm_area(XEN_PAGE_SIZE * nr_grefs, info->ptes); + area = get_vm_area(XEN_PAGE_SIZE * nr_grefs, VM_IOREMAP); if (!area) return -ENOMEM; - - for (i = 0; i < nr_grefs; i++) - info->phys_addrs[i] = - arbitrary_virt_to_machine(info->ptes[i]).maddr; - + if (apply_to_page_range(&init_mm, (unsigned long)area->addr, + XEN_PAGE_SIZE * nr_grefs, map_ring_apply, info)) + goto failed; err = __xenbus_map_ring(dev, gnt_refs, nr_grefs, node->handles, info, GNTMAP_host_map | GNTMAP_contains_pte, &leaked); -- 2.28.0