Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6057878ybi; Wed, 29 May 2019 02:07:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDEaCm2p5dt62DeIUJLYWBKu0+V8wjnd78jM3PHvf2aQc/FivSWle6s3O5ezlFWP1ldhJ5 X-Received: by 2002:a63:1650:: with SMTP id 16mr43773227pgw.164.1559120840060; Wed, 29 May 2019 02:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559120840; cv=none; d=google.com; s=arc-20160816; b=CSzwtb+n7g6263wyH9MWf5cd1NU/ezzR6RyuA+V6cFGaSiMwX+oS22s+xLOzDqN2ce 4pEtAHBE05IYwKuUigpqB3oG8Ol+EoM3tHeBzkZ5yH6hSb6Z9LoZRMDZeaAm2itdKQer my8D3R1SsljHBQvPAnr7mauQa9HkXC77JD2PsKRkzNwWtybwHv2SfS1zH2b11LrJ5im5 qGhGrh9D/4K17lSPFsOnlAQ2YXwy764Lms/rKYJn/Hw85UaXjGyHejuN5lNtBMI4U2em byyNf/QGNqUK2QV7c2ildPgYHCUPlcLqzYx9aYhwKBHmSwBv330LVeSDJUzwUoVABSt/ trww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=hwWZV6Pn5crhy+xBqa0BTp4C1ecmxprGBqUnvsj7s2g=; b=ro2hoRvqynndh6DrRCnnAGWrfcT1HK2VcPzj0nksjPZsICUNhQ24Ci8nIu1JJvpX9V DG8Krhf1qDi2ge5jo+s9xOxjHxvJBng59fNMQHcumCrH8bfMkrpgEmKCkgzfAid/Ksfi dc22GQOm0w+t/lCJy7oE42MRCRwXdYetA3iDShZGfnx/c7p14IwjyjNki0fikpjRJLaR nY9M+26wx0oeoq8OIVaq6nJA+YKGfLYtpE0CZoWDKvgEvP9bP5y3p+ZKc48XqbT7cy7s H9IYCQt8Ko39DZr5xqcKKouG5Vmz9Tues18GJMO3o5fc3zB7vf6IrXq++HmMB3H/WuE5 dV8g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si24194221pgi.586.2019.05.29.02.07.02; Wed, 29 May 2019 02:07:20 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbfE2JEV (ORCPT + 99 others); Wed, 29 May 2019 05:04:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:46210 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726121AbfE2JEM (ORCPT ); Wed, 29 May 2019 05:04:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0AFA7AEFD; Wed, 29 May 2019 09:04:11 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Cc: Juergen Gross , Konrad Rzeszutek Wilk , Boris Ostrovsky , Stefano Stabellini , xen-devel@lists.xenproject.org Subject: [PATCH v2 3/3] xen/swiotlb: remember having called xen_create_contiguous_region() Date: Wed, 29 May 2019 11:04:07 +0200 Message-Id: <20190529090407.1225-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190529090407.1225-1-jgross@suse.com> References: <20190529090407.1225-1-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of always calling xen_destroy_contiguous_region() in case the memory is DMA-able for the used device, do so only in case it has been made DMA-able via xen_create_contiguous_region() before. This will avoid a lot of xen_destroy_contiguous_region() calls for 64-bit capable devices. As the memory in question is owned by swiotlb-xen the PG_owner_priv_1 flag of the first allocated page can be used for remembering. Signed-off-by: Juergen Gross --- V2: add PG_xen_remapped alias for PG_owner_priv_1 (Boris Ostrovsky) only clear page flag in case of sane conditions (Jan Beulich) --- drivers/xen/swiotlb-xen.c | 6 +++++- include/linux/page-flags.h | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index aba5247b9145..7e2d9d1b6f63 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -321,6 +321,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, xen_free_coherent_pages(hwdev, size, ret, (dma_addr_t)phys, attrs); return NULL; } + SetPageXenRemapped(virt_to_page(ret)); } memset(ret, 0, size); return ret; @@ -345,8 +346,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, size = 1UL << (order + XEN_PAGE_SHIFT); if (!WARN_ON((dev_addr + size - 1 > dma_mask) || - range_straddles_page_boundary(phys, size))) + range_straddles_page_boundary(phys, size)) && + PageXenRemapped(virt_to_page(vaddr))) { xen_destroy_contiguous_region(phys, order); + ClearPageXenRemapped(virt_to_page(vaddr)); + } xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 9f8712a4b1a5..296480e990f2 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -152,6 +152,8 @@ enum pageflags { PG_savepinned = PG_dirty, /* Has a grant mapping of another (foreign) domain's page. */ PG_foreign = PG_owner_priv_1, + /* Remapped by swiotlb-xen. */ + PG_xen_remapped = PG_owner_priv_1, /* SLOB */ PG_slob_free = PG_private, @@ -329,6 +331,7 @@ PAGEFLAG(Pinned, pinned, PF_NO_COMPOUND) TESTSCFLAG(Pinned, pinned, PF_NO_COMPOUND) PAGEFLAG(SavePinned, savepinned, PF_NO_COMPOUND); PAGEFLAG(Foreign, foreign, PF_NO_COMPOUND); +PAGEFLAG(XenRemapped, xen_remapped, PF_NO_COMPOUND); PAGEFLAG(Reserved, reserved, PF_NO_COMPOUND) __CLEARPAGEFLAG(Reserved, reserved, PF_NO_COMPOUND) -- 2.16.4